Skip to content

Commit

Permalink
v0.2.3 1707191137 정민
Browse files Browse the repository at this point in the history
화면수정 소수점 자릿수 개선
  • Loading branch information
jungmin88 committed Jul 19, 2017
1 parent 3aa3ffc commit 0d3f07f
Show file tree
Hide file tree
Showing 3 changed files with 157 additions and 40 deletions.
2 changes: 0 additions & 2 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

85 changes: 72 additions & 13 deletions app/src/main/java/com/iot/caloriebox/BluetoothConnect_M.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,14 @@ public class BluetoothConnect_M extends Activity implements View.OnClickListener

// Layout
private Button button_Connect;
private TextView textViewWeight;
private TextView textViewCalorie;
private Button btn1;
private Button btn2;
private TextView textWeight;
private Button btn3;
private Button btn4;
private Button btn5;
private Button btn6;

private BluetoothService_M bluetoothService = null;

Expand Down Expand Up @@ -127,11 +132,10 @@ public void handleMessage(Message msg) {

readMessage = new String(readBuf);

textWeight.setText(readMessage);
textViewWeight.setText(readMessage);

foodWeight = Float.parseFloat(readMessage);


break;

case MESSAGE_WRITE:
Expand Down Expand Up @@ -174,11 +178,23 @@ protected void onCreate(Bundle savedInstanceState) {

button_Connect = (Button) findViewById(R.id.button_connect);
button_Connect.setOnClickListener(_clickListener);

textViewWeight = (TextView)findViewById(R.id.textViewWeight);
textViewCalorie = (TextView)findViewById(R.id.textViewCalorie);

btn1 = (Button) findViewById(R.id.btn1);
btn1.setOnClickListener(_clickListener);
btn2 = (Button) findViewById(R.id.btn2);
btn2.setOnClickListener(_clickListener);
textWeight = (TextView) findViewById(R.id.textWeight);
btn3 = (Button) findViewById(R.id.btn3);
btn3.setOnClickListener(_clickListener);
btn4 = (Button) findViewById(R.id.btn4);
btn4.setOnClickListener(_clickListener);
btn5 = (Button) findViewById(R.id.btn5);
btn5.setOnClickListener(_clickListener);
btn6 = (Button) findViewById(R.id.btn6);
btn6.setOnClickListener(_clickListener);


// BluetoothService 클래스 생성
if (bluetoothService == null) {
Expand Down Expand Up @@ -230,41 +246,84 @@ public void onClick(View v) {

//분기.
switch (v.getId()) {

case R.id.button_connect: //모든 블루투스의 활성화는 블루투스 서비스 객체를 통해 접근한다.

if (bluetoothService.getDeviceState()) { // 블루투스 기기의 지원여부가 true 일때
bluetoothService.enableBluetooth(); //블루투스 활성화 시작.
} else {
finish();
}
break;

case R.id.btn1:

foodCalorie = String.valueOf(foodWeight *109/100);

case R.id.btn1: // 육류
// foodCalorie = String.valueOf(foodWeight * 1.1);
foodCalorie = String.format("%.1f",(foodWeight * 1.09));
if (bluetoothService.getState() == BluetoothService_M.STATE_CONNECTED) { //연결된 상태에서만 값을 보낸다.
textViewCalorie.setText(foodCalorie);
sendMessage(foodCalorie, MODE_REQUEST);
_selectedButton = 1;
} else {
Toast.makeText(getApplicationContext(), "블루투스 연결을 먼저 해 주세요!! ", Toast.LENGTH_SHORT).show();
}

break;

case R.id.btn2: // 어류
// foodCalorie = String.valueOf(foodWeight * 1.3);
foodCalorie = String.format("%.1f",(foodWeight * 1.35));
if (bluetoothService.getState() == BluetoothService_M.STATE_CONNECTED) {
textViewCalorie.setText(foodCalorie);
sendMessage(foodCalorie, MODE_REQUEST);
_selectedButton = 2;
} else {
Toast.makeText(getApplicationContext(), "블루투스 연결을 먼저 해 주세요!! ", Toast.LENGTH_SHORT).show();
}
break;

case R.id.btn2:
case R.id.btn3: // 채소
// foodCalorie = String.valueOf(foodWeight * 0.2);
foodCalorie = String.format("%.1f",(foodWeight * 0.22));
if (bluetoothService.getState() == BluetoothService_M.STATE_CONNECTED) {
textViewCalorie.setText(foodCalorie);
sendMessage(foodCalorie, MODE_REQUEST);
_selectedButton = 2;
} else {
Toast.makeText(getApplicationContext(), "블루투스 연결을 먼저 해 주세요!! ", Toast.LENGTH_SHORT).show();
}
break;

foodCalorie = String.valueOf(foodWeight *11/100);
case R.id.btn4: // 쌀
// foodCalorie = String.valueOf(foodWeight * 1.5);
foodCalorie = String.format("%.1f",(foodWeight * 1.52));
if (bluetoothService.getState() == BluetoothService_M.STATE_CONNECTED) {
textViewCalorie.setText(foodCalorie);
sendMessage(foodCalorie, MODE_REQUEST);
_selectedButton = 2;
} else {
Toast.makeText(getApplicationContext(), "블루투스 연결을 먼저 해 주세요!! ", Toast.LENGTH_SHORT).show();
}
break;

case R.id.btn5: // 과일
// foodCalorie = String.valueOf(foodWeight * 0.5);
foodCalorie = String.format("%.1f",(foodWeight * 0.57));
if (bluetoothService.getState() == BluetoothService_M.STATE_CONNECTED) {
textViewCalorie.setText(foodCalorie);
sendMessage(foodCalorie, MODE_REQUEST);
_selectedButton = 2;
} else {
Toast.makeText(getApplicationContext(), "블루투스 연결을 먼저 해 주세요!! ", Toast.LENGTH_SHORT).show();
}
break;

case R.id.btn6: // 빵
// foodCalorie = String.valueOf(foodWeight * 1.9);
foodCalorie = String.format("%.1f",(foodWeight * 1.98));
if (bluetoothService.getState() == BluetoothService_M.STATE_CONNECTED) {
textViewCalorie.setText(foodCalorie);
sendMessage(foodCalorie, MODE_REQUEST);
_selectedButton = 2;
} else {
Toast.makeText(getApplicationContext(), "블루투스 연결을 먼저 해 주세요!! ", Toast.LENGTH_SHORT).show();
}
break;

default:
Expand Down
110 changes: 85 additions & 25 deletions app/src/main/res/layout/activity_bluetooth_connect__m.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ tools:context="com.iot.caloriebox.BluetoothConnect_M">

<TextView
android:id="@+id/textViewWeight"
android:layout_width="230dp"
android:layout_width="200dp"
android:layout_height="37dp"
android:text="무게를 받아옵니다..."
android:text="무게를 받아옵니다.."
android:textSize="20dp"
android:layout_marginTop="8dp"
app:layout_constraintTop_toBottomOf="@+id/button_connect"
Expand All @@ -35,19 +35,19 @@ tools:context="com.iot.caloriebox.BluetoothConnect_M">
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
android:layout_marginBottom="8dp"
app:layout_constraintVertical_bias="0.0"
app:layout_constraintVertical_bias="0.109"
android:gravity="center"
/>

<TextView
android:id="@+id/textViewCalorie"
android:layout_width="230dp"
android:layout_width="200dp"
android:layout_height="40dp"
android:text="아래 버튼을 눌러주세요"
android:text="버튼을 눌러주세요"
android:textSize="20dp"
android:layout_marginRight="8dp"
app:layout_constraintRight_toRightOf="parent"
android:layout_marginTop="8dp"
android:layout_marginTop="19dp"
app:layout_constraintTop_toBottomOf="@+id/textViewWeight"
android:layout_marginLeft="8dp"
app:layout_constraintLeft_toLeftOf="parent"
Expand Down Expand Up @@ -106,44 +106,104 @@ tools:context="com.iot.caloriebox.BluetoothConnect_M">

<Button
android:id="@+id/btn1"
android:layout_width="150dp"
android:layout_height="100dp"
android:layout_width="90dp"
android:layout_height="90dp"
android:gravity="center_horizontal|bottom"
android:background="@color/colorPrimary"
android:background="@drawable/meat2"
android:layout_centerVertical="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
app:layout_constraintBottom_toBottomOf="parent"
android:layout_marginBottom="8dp"
android:layout_marginLeft="16dp"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:layout_marginTop="8dp"
app:layout_constraintVertical_bias="0.45"
app:layout_constraintRight_toLeftOf="@+id/btn2"
android:layout_marginRight="8dp"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintHorizontal_bias="0.0" />
app:layout_constraintBaseline_toBaselineOf="@+id/btn2"
app:layout_constraintHorizontal_bias="0.515"/>

<Button
android:id="@+id/btn2"
android:text="2"
android:textColor="#FFFFFF"
android:layout_width="158dp"
android:layout_height="115dp"
android:layout_width="90dp"
android:layout_height="90dp"
android:gravity="center_horizontal|bottom"
android:background="@color/colorAccent"
android:background="@drawable/fish2"
android:layout_alignTop="@+id/btn1"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
android:layout_marginBottom="96dp"
android:layout_marginTop="8dp"
app:layout_constraintTop_toBottomOf="@+id/textViewCalorie"
android:layout_marginRight="8dp"
app:layout_constraintRight_toRightOf="parent"
android:layout_marginLeft="8dp"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintVertical_bias="0.405"/>

<Button
android:id="@+id/btn3"
android:layout_width="90dp"
android:layout_height="90dp"
android:gravity="center_horizontal|bottom"
android:background="@drawable/vege2"
android:layout_centerVertical="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginRight="16dp"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintLeft_toRightOf="@+id/btn2"
android:layout_marginLeft="0dp"
app:layout_constraintHorizontal_bias="0.512"
app:layout_constraintBaseline_toBaselineOf="@+id/btn2"/>

<Button
android:id="@+id/btn4"
android:layout_width="90dp"
android:layout_height="90dp"
android:gravity="center_horizontal|bottom"
android:background="@drawable/rice2"
android:layout_alignTop="@+id/btn1"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_marginLeft="8dp"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toLeftOf="@+id/btn5"
android:layout_marginRight="8dp"
app:layout_constraintBaseline_toBaselineOf="@+id/btn5"
app:layout_constraintHorizontal_bias="0.609"/>

<Button
android:id="@+id/btn5"
android:layout_width="90dp"
android:layout_height="90dp"
android:gravity="center_horizontal|bottom"
android:background="@drawable/fruit2"
android:layout_alignTop="@+id/btn1"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
app:layout_constraintBottom_toBottomOf="parent"
android:layout_marginBottom="8dp"
app:layout_constraintLeft_toRightOf="@+id/btn1"
android:layout_marginRight="8dp"
app:layout_constraintRight_toRightOf="parent"
android:layout_marginLeft="8dp"
app:layout_constraintLeft_toLeftOf="parent"
android:layout_marginTop="8dp"
app:layout_constraintTop_toBottomOf="@+id/btn2"
app:layout_constraintVertical_bias="0.433"/>

<Button
android:id="@+id/btn6"
android:layout_width="90dp"
android:layout_height="90dp"
android:gravity="center_horizontal|bottom"
android:background="@drawable/bread2"
android:layout_alignTop="@+id/btn1"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_marginRight="8dp"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintHorizontal_bias="0.444"
app:layout_constraintVertical_bias="0.45" />
app:layout_constraintLeft_toRightOf="@+id/btn5"
android:layout_marginLeft="8dp"
app:layout_constraintHorizontal_bias="0.317"
app:layout_constraintBaseline_toBaselineOf="@+id/btn5"/>

</android.support.constraint.ConstraintLayout>

0 comments on commit 0d3f07f

Please sign in to comment.