awebow

운동 UI 수정

...@@ -12,15 +12,19 @@ ...@@ -12,15 +12,19 @@
12 android:roundIcon="@mipmap/ic_launcher_round" 12 android:roundIcon="@mipmap/ic_launcher_round"
13 android:supportsRtl="true" 13 android:supportsRtl="true"
14 android:theme="@style/AppTheme"> 14 android:theme="@style/AppTheme">
15 - <activity android:name=".FirstActivity"> 15 + <activity android:name=".FirstActivity"
16 + android:screenOrientation="portrait">
16 <intent-filter> 17 <intent-filter>
17 <action android:name="android.intent.action.MAIN" /> 18 <action android:name="android.intent.action.MAIN" />
18 19
19 <category android:name="android.intent.category.LAUNCHER" /> 20 <category android:name="android.intent.category.LAUNCHER" />
20 </intent-filter> 21 </intent-filter>
21 </activity> 22 </activity>
22 - <activity android:name = ".ChoiceActivity"/> 23 + <activity android:name = ".ChoiceActivity"
23 - <activity android:name = ".ExerciseActivity"/> 24 + android:screenOrientation="portrait"/>
25 + <activity android:name = ".ExerciseActivity"
26 + android:screenOrientation="landscape"
27 + android:theme="@style/Theme.AppCompat.NoActionBar"/>
24 <activity android:name = ".ReportActivity"/> 28 <activity android:name = ".ReportActivity"/>
25 </application> 29 </application>
26 30
......
...@@ -26,6 +26,7 @@ import android.media.Image; ...@@ -26,6 +26,7 @@ import android.media.Image;
26 import android.media.ImageReader; 26 import android.media.ImageReader;
27 import android.os.Bundle; 27 import android.os.Bundle;
28 import android.util.Log; 28 import android.util.Log;
29 +import android.util.TypedValue;
29 import android.view.SurfaceHolder; 30 import android.view.SurfaceHolder;
30 import android.view.SurfaceView; 31 import android.view.SurfaceView;
31 import android.widget.TextView; 32 import android.widget.TextView;
...@@ -54,7 +55,6 @@ public class ExerciseActivity extends AppCompatActivity implements SurfaceHolder ...@@ -54,7 +55,6 @@ public class ExerciseActivity extends AppCompatActivity implements SurfaceHolder
54 private Interpreter interpreter; 55 private Interpreter interpreter;
55 private int count = 0; 56 private int count = 0;
56 private boolean up = true; 57 private boolean up = true;
57 - private TextView countView;
58 DBHelper dbHelper; 58 DBHelper dbHelper;
59 String getTime; 59 String getTime;
60 60
...@@ -72,8 +72,6 @@ public class ExerciseActivity extends AppCompatActivity implements SurfaceHolder ...@@ -72,8 +72,6 @@ public class ExerciseActivity extends AppCompatActivity implements SurfaceHolder
72 surfaceView = findViewById(R.id.surfaceView); 72 surfaceView = findViewById(R.id.surfaceView);
73 surfaceView.getHolder().addCallback(this); 73 surfaceView.getHolder().addCallback(this);
74 74
75 - countView = findViewById(R.id.count);
76 -
77 try { 75 try {
78 AssetFileDescriptor fileDescriptor = getAssets().openFd("pushup.tflite"); 76 AssetFileDescriptor fileDescriptor = getAssets().openFd("pushup.tflite");
79 FileInputStream is = new FileInputStream(fileDescriptor.getFileDescriptor()); 77 FileInputStream is = new FileInputStream(fileDescriptor.getFileDescriptor());
...@@ -242,6 +240,8 @@ public class ExerciseActivity extends AppCompatActivity implements SurfaceHolder ...@@ -242,6 +240,8 @@ public class ExerciseActivity extends AppCompatActivity implements SurfaceHolder
242 if(Math.abs(modelInputRatio - bitmapRatio) < maxDifference) 240 if(Math.abs(modelInputRatio - bitmapRatio) < maxDifference)
243 return croppedBitmap; 241 return croppedBitmap;
244 242
243 + Matrix rotate = new Matrix();
244 + rotate.postRotate(270);
245 if(modelInputRatio < bitmapRatio) { 245 if(modelInputRatio < bitmapRatio) {
246 // New image is taller so we are height constrained. 246 // New image is taller so we are height constrained.
247 float cropHeight = bitmap.getHeight() - bitmap.getWidth() / modelInputRatio; 247 float cropHeight = bitmap.getHeight() - bitmap.getWidth() / modelInputRatio;
...@@ -250,7 +250,8 @@ public class ExerciseActivity extends AppCompatActivity implements SurfaceHolder ...@@ -250,7 +250,8 @@ public class ExerciseActivity extends AppCompatActivity implements SurfaceHolder
250 0, 250 0,
251 (int) cropHeight / 2, 251 (int) cropHeight / 2,
252 bitmap.getWidth(), 252 bitmap.getWidth(),
253 - (int) (bitmap.getHeight() - cropHeight) 253 + (int) (bitmap.getHeight() - cropHeight),
254 + rotate, false
254 ); 255 );
255 } 256 }
256 else { 257 else {
...@@ -260,7 +261,8 @@ public class ExerciseActivity extends AppCompatActivity implements SurfaceHolder ...@@ -260,7 +261,8 @@ public class ExerciseActivity extends AppCompatActivity implements SurfaceHolder
260 (int) (cropWidth / 2), 261 (int) (cropWidth / 2),
261 0, 262 0,
262 (int) (bitmap.getWidth() - cropWidth), 263 (int) (bitmap.getWidth() - cropWidth),
263 - bitmap.getHeight() 264 + bitmap.getHeight(), rotate, false
265 +
264 ); 266 );
265 } 267 }
266 return croppedBitmap; 268 return croppedBitmap;
...@@ -280,9 +282,14 @@ public class ExerciseActivity extends AppCompatActivity implements SurfaceHolder ...@@ -280,9 +282,14 @@ public class ExerciseActivity extends AppCompatActivity implements SurfaceHolder
280 282
281 Paint paint = new Paint(); 283 Paint paint = new Paint();
282 Canvas canvas = surfaceView.getHolder().lockCanvas(); 284 Canvas canvas = surfaceView.getHolder().lockCanvas();
285 + canvas.drawRGB(0, 0, 0);
283 286
284 // 이미지 그리기 287 // 이미지 그리기
285 - canvas.drawBitmap(croppedBitmap, new Rect(0, 0, croppedBitmap.getWidth(), croppedBitmap.getHeight()), new Rect(0, 0, canvas.getWidth(), canvas.getWidth()), paint); 288 + //float scale = (float) canvas.getWidth() / bitmap.getWidth();
289 + //if(bitmap.getHeight() * scale > canvas.getHeight())
290 + // scale = (float) canvas.getHeight() / bitmap.getHeight();
291 + //canvas.drawBitmap(bitmap, new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight()), new Rect(0, 0, (int) (bitmap.getWidth() * scale), (int) (bitmap.getHeight() * scale)), paint);
292 + canvas.drawBitmap(croppedBitmap, new Rect(0, 0, croppedBitmap.getWidth(), croppedBitmap.getHeight()), new Rect(0, 0, canvas.getHeight(), canvas.getHeight()), paint);
286 293
287 float[][][] keyMap = new float[1][257][257]; 294 float[][][] keyMap = new float[1][257][257];
288 float[][] result = new float[1][2]; 295 float[][] result = new float[1][2];
...@@ -293,7 +300,7 @@ public class ExerciseActivity extends AppCompatActivity implements SurfaceHolder ...@@ -293,7 +300,7 @@ public class ExerciseActivity extends AppCompatActivity implements SurfaceHolder
293 if(keyPoint.getScore() < 0.7) 300 if(keyPoint.getScore() < 0.7)
294 continue; 301 continue;
295 302
296 - canvas.drawCircle((float) keyPoint.getPosition().getX() / scaledBitmap.getWidth() * canvas.getWidth(), (float) keyPoint.getPosition().getY() / scaledBitmap.getWidth() * canvas.getWidth(), 5, paint); 303 + canvas.drawCircle((float) keyPoint.getPosition().getX() / scaledBitmap.getWidth() * canvas.getHeight(), (float) keyPoint.getPosition().getY() / scaledBitmap.getWidth() * canvas.getHeight(), 5, paint);
297 if(keyPoint.getPosition().getX() >= 0 && keyPoint.getPosition().getX() < 257 && keyPoint.getPosition().getY() >= 0 && keyPoint.getPosition().getY() < 257) 304 if(keyPoint.getPosition().getX() >= 0 && keyPoint.getPosition().getX() < 257 && keyPoint.getPosition().getY() >= 0 && keyPoint.getPosition().getY() < 257)
298 keyMap[0][keyPoint.getPosition().getY()][keyPoint.getPosition().getX()] = i + 1; 305 keyMap[0][keyPoint.getPosition().getY()][keyPoint.getPosition().getX()] = i + 1;
299 } 306 }
...@@ -305,25 +312,26 @@ public class ExerciseActivity extends AppCompatActivity implements SurfaceHolder ...@@ -305,25 +312,26 @@ public class ExerciseActivity extends AppCompatActivity implements SurfaceHolder
305 if(result[0][0] >= 0.7) { 312 if(result[0][0] >= 0.7) {
306 if(!up) { 313 if(!up) {
307 count++; 314 count++;
308 - countView.setText("Count: " + count);
309 315
310 //db에 값 증가 316 //db에 값 증가
311 SQLiteDatabase db = dbHelper.getReadableDatabase(); 317 SQLiteDatabase db = dbHelper.getReadableDatabase();
312 - String sql = "SELECT pushup FROM reports WHERE date=" + getTime + ";";
313 - Cursor cs = db.rawQuery(sql, null);
314 - cs.moveToNext();
315 - int before = cs.getInt(0);
316 318
317 db = dbHelper.getWritableDatabase(); 319 db = dbHelper.getWritableDatabase();
318 - sql = "UPDATE reports SET pushup='" + before + 1 + "' WHERE date=" + getTime + ";"; 320 + String sql = "UPDATE reports SET pushup=pushup+1 WHERE date=" + getTime + ";";
319 db.execSQL(sql); 321 db.execSQL(sql);
320 } 322 }
321 323
322 up = true; 324 up = true;
323 } 325 }
324 - else if(result[0][1] >= 0.7) 326 + else if(result[0][1] >= 0.6)
325 up = false; 327 up = false;
326 328
329 + paint.setTextAlign(Paint.Align.LEFT);
330 + int fontSize = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, 24, getResources().getDisplayMetrics());
331 + paint.setTextSize(fontSize);
332 + int pad = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 16, getResources().getDisplayMetrics());
333 + canvas.drawText(String.format("Count: %d", count), canvas.getHeight() + pad, pad + fontSize, paint);
334 +
327 surfaceView.getHolder().unlockCanvasAndPost(canvas); 335 surfaceView.getHolder().unlockCanvasAndPost(canvas);
328 } 336 }
329 } 337 }
......
...@@ -12,12 +12,4 @@ ...@@ -12,12 +12,4 @@
12 android:layout_width="match_parent" 12 android:layout_width="match_parent"
13 android:layout_height="match_parent" /> 13 android:layout_height="match_parent" />
14 14
15 - <TextView
16 - android:id="@+id/count"
17 - android:layout_width="wrap_content"
18 - android:layout_height="wrap_content"
19 - android:text="Count: 0"
20 - android:textColor="#FF0000"
21 - android:textSize="18sp" />
22 -
23 </FrameLayout> 15 </FrameLayout>
...\ No newline at end of file ...\ No newline at end of file
......