diff --git a/AffdexMe/app/src/main/java/com/affectiva/affdexme/DrawingView.java b/AffdexMe/app/src/main/java/com/affectiva/affdexme/DrawingView.java index 7ac5175..4b902e0 100644 --- a/AffdexMe/app/src/main/java/com/affectiva/affdexme/DrawingView.java +++ b/AffdexMe/app/src/main/java/com/affectiva/affdexme/DrawingView.java @@ -26,6 +26,7 @@ import com.affectiva.android.affdex.sdk.detector.Face; public class DrawingView extends SurfaceView implements SurfaceHolder.Callback { class PointFArraySharer { + boolean isPointsMirrored = false; PointF[] nextPointsToDraw = null; } @@ -88,9 +89,10 @@ public class DrawingView extends SurfaceView implements SurfaceHolder.Callback { } //Updates thread with latest points returned by the onImageResults() event. - public void updatePoints(PointF[] pointList) { + public void updatePoints(PointF[] pointList, boolean isPointsMirrored) { synchronized (sharer) { sharer.nextPointsToDraw = pointList; + sharer.isPointsMirrored = isPointsMirrored; } } @@ -139,10 +141,12 @@ public class DrawingView extends SurfaceView implements SurfaceHolder.Callback { void draw(Canvas c) { PointF[] points; + boolean mirrorPoints; synchronized (sharer) { if (sharer.nextPointsToDraw == null) return; points = sharer.nextPointsToDraw; + mirrorPoints = sharer.isPointsMirrored; } //Coordinates around which to draw bounding box. @@ -155,7 +159,12 @@ public class DrawingView extends SurfaceView implements SurfaceHolder.Callback { //transform from the camera coordinates to our screen coordinates //The camera preview is displayed as a mirror, so X pts have to be mirrored back. - float x = (config.imageWidth - points[i].x - 1) * config.screenToImageRatio; + float x; + if (mirrorPoints) { + x = (config.imageWidth - points[i].x) * config.screenToImageRatio; + } else { + x = (points[i].x) * config.screenToImageRatio; + } float y = (points[i].y)* config.screenToImageRatio; //We determine the left-most, top-most, right-most, and bottom-most points to draw the bounding box around. @@ -394,8 +403,8 @@ public class DrawingView extends SurfaceView implements SurfaceHolder.Callback { drawingThread.setMetrics(roll,yaw,pitch,interOcDis,valence); } - public void updatePoints(PointF[] points) { - drawingThread.updatePoints(points); + public void updatePoints(PointF[] points, boolean isPointsMirrored) { + drawingThread.updatePoints(points, isPointsMirrored); } public void invalidatePoints(){ diff --git a/AffdexMe/app/src/main/java/com/affectiva/affdexme/MainActivity.java b/AffdexMe/app/src/main/java/com/affectiva/affdexme/MainActivity.java index 9490bc3..36ee2de 100644 --- a/AffdexMe/app/src/main/java/com/affectiva/affdexme/MainActivity.java +++ b/AffdexMe/app/src/main/java/com/affectiva/affdexme/MainActivity.java @@ -67,7 +67,7 @@ import com.affectiva.android.affdex.sdk.detector.Face; */ public class MainActivity extends Activity - implements Detector.FaceListener, Detector.ImageListener, View.OnTouchListener, CameraDetector.OnCameraEventListener { + implements Detector.FaceListener, Detector.ImageListener, View.OnTouchListener, CameraDetector.CameraEventListener { private static final String LOG_TAG = "Affectiva"; public static final int NUM_METRICS_DISPLAYED = 6; @@ -114,6 +114,7 @@ public class MainActivity extends Activity int cameraPreviewWidth = 0; int cameraPreviewHeight = 0; CameraDetector.CameraType cameraType; + boolean mirrorPoints = false; @Override protected void onCreate(Bundle savedInstanceState) { @@ -146,10 +147,14 @@ public class MainActivity extends Activity } //TODO: change this to be taken from settings - if (isBackFacingCameraDetected) + if (isBackFacingCameraDetected) { cameraType = CameraDetector.CameraType.CAMERA_BACK; - if (isFrontFacingCameraDetected) + mirrorPoints = false; + } + if (isFrontFacingCameraDetected) { cameraType = CameraDetector.CameraType.CAMERA_FRONT; + mirrorPoints = true; + } } void initializeUI() { @@ -257,6 +262,7 @@ public class MainActivity extends Activity restoreApplicationSettings(); setMenuVisible(true); isMenuShowingForFirstTime = true; + mainWindowResumedTasks(); } /* @@ -335,23 +341,6 @@ public class MainActivity extends Activity numberOfFrames = 0; } - /** - * We want to start the camera as late as possible, so it does not freeze the application before it has been visually resumed. - * We thus post a runnable that will take care of starting the camera. - * We also reset variables used to calculate the Processed Frames Per Second. - */ - @Override - public void onWindowFocusChanged(boolean hasFocus) { - if (hasFocus && isFrontFacingCameraDetected) { - cameraView.post(new Runnable() { - @Override - public void run() { - mainWindowResumedTasks(); - } - }); - } - } - void mainWindowResumedTasks() { startDetector(); @@ -360,6 +349,7 @@ public class MainActivity extends Activity progressBarLayout.setVisibility(View.GONE); } resetFPSCalculations(); + cameraView.postDelayed(new Runnable() { @Override public void run() { @@ -402,7 +392,6 @@ public class MainActivity extends Activity void performFaceDetectionStoppedTasks() { leftMetricsLayout.animate().alpha(0); //make left and right metrics disappear rightMetricsLayout.animate().alpha(0); - drawingView.updatePoints(null); resetFPSCalculations(); //Since the FPS may be different whether a face is being tracked or not, reset variables. } @@ -421,7 +410,7 @@ public class MainActivity extends Activity //If faces.size() is 0, we received a frame in which no face was detected if (faces.size() == 0) { - drawingView.updatePoints(null); //the drawingView takes null points to mean it doesn't have to draw anything + drawingView.updatePoints(null, mirrorPoints); //the drawingView takes null points to mean it doesn't have to draw anything return; } @@ -441,7 +430,7 @@ public class MainActivity extends Activity */ if (drawingView.getDrawPointsEnabled() || drawingView.getDrawMeasurementsEnabled()) { drawingView.setMetrics(face.measurements.orientation.getRoll(), face.measurements.orientation.getYaw(), face.measurements.orientation.getPitch(), face.measurements.getInterocularDistance(), face.emotions.getValence()); - drawingView.updatePoints(face.getFacePoints()); + drawingView.updatePoints(face.getFacePoints(),mirrorPoints); } } @@ -589,16 +578,15 @@ public class MainActivity extends Activity } public void settings_button_click(View view) { - startActivity(new Intent(this,SettingsActivity.class)); + startActivity(new Intent(this, SettingsActivity.class)); } - /* @Override public void onCameraStarted(boolean b, Throwable throwable) { if (throwable != null) { Toast.makeText(this,"Failed to start camera.",Toast.LENGTH_LONG).show(); } - }*/ + } @Override public void onCameraSizeSelected(int cameraWidth, int cameraHeight, ROTATE rotation) { @@ -653,12 +641,14 @@ public class MainActivity extends Activity if (cameraType == CameraDetector.CameraType.CAMERA_FRONT) { if (isBackFacingCameraDetected) { cameraType = CameraDetector.CameraType.CAMERA_BACK; + mirrorPoints = false; } else { Toast.makeText(this,"No back-facing camera found",Toast.LENGTH_LONG).show(); } } else if (cameraType == CameraDetector.CameraType.CAMERA_BACK) { if (isFrontFacingCameraDetected) { cameraType = CameraDetector.CameraType.CAMERA_FRONT; + mirrorPoints = true; } else { Toast.makeText(this,"No front-facing camera found",Toast.LENGTH_LONG).show(); } diff --git a/AffdexMe/app/src/main/res/drawable-hdpi/ic_more_vert_black_48dp.png b/AffdexMe/app/src/main/res/drawable-hdpi/ic_more_vert_black_48dp.png deleted file mode 100644 index 94d5ab9..0000000 Binary files a/AffdexMe/app/src/main/res/drawable-hdpi/ic_more_vert_black_48dp.png and /dev/null differ diff --git a/AffdexMe/app/src/main/res/drawable-hdpi/ic_more_vert_white_48dp.png b/AffdexMe/app/src/main/res/drawable-hdpi/ic_more_vert_white_48dp.png deleted file mode 100644 index d322813..0000000 Binary files a/AffdexMe/app/src/main/res/drawable-hdpi/ic_more_vert_white_48dp.png and /dev/null differ diff --git a/AffdexMe/app/src/main/res/drawable-hdpi/ic_switch_camera_black_48dp.png b/AffdexMe/app/src/main/res/drawable-hdpi/ic_switch_camera_black_48dp.png deleted file mode 100644 index 1f6be43..0000000 Binary files a/AffdexMe/app/src/main/res/drawable-hdpi/ic_switch_camera_black_48dp.png and /dev/null differ diff --git a/AffdexMe/app/src/main/res/drawable-hdpi/ic_switch_camera_white_48dp.png b/AffdexMe/app/src/main/res/drawable-hdpi/ic_switch_camera_white_48dp.png deleted file mode 100644 index bee95a1..0000000 Binary files a/AffdexMe/app/src/main/res/drawable-hdpi/ic_switch_camera_white_48dp.png and /dev/null differ diff --git a/AffdexMe/app/src/main/res/drawable-mdpi/ic_more_vert_black_48dp.png b/AffdexMe/app/src/main/res/drawable-mdpi/ic_more_vert_black_48dp.png deleted file mode 100644 index 9f10aa2..0000000 Binary files a/AffdexMe/app/src/main/res/drawable-mdpi/ic_more_vert_black_48dp.png and /dev/null differ diff --git a/AffdexMe/app/src/main/res/drawable-mdpi/ic_more_vert_white_48dp.png b/AffdexMe/app/src/main/res/drawable-mdpi/ic_more_vert_white_48dp.png deleted file mode 100644 index efab8a7..0000000 Binary files a/AffdexMe/app/src/main/res/drawable-mdpi/ic_more_vert_white_48dp.png and /dev/null differ diff --git a/AffdexMe/app/src/main/res/drawable-mdpi/ic_switch_camera_black_48dp.png b/AffdexMe/app/src/main/res/drawable-mdpi/ic_switch_camera_black_48dp.png deleted file mode 100644 index 3dfc224..0000000 Binary files a/AffdexMe/app/src/main/res/drawable-mdpi/ic_switch_camera_black_48dp.png and /dev/null differ diff --git a/AffdexMe/app/src/main/res/drawable-mdpi/ic_switch_camera_white_48dp.png b/AffdexMe/app/src/main/res/drawable-mdpi/ic_switch_camera_white_48dp.png deleted file mode 100644 index 9a5c966..0000000 Binary files a/AffdexMe/app/src/main/res/drawable-mdpi/ic_switch_camera_white_48dp.png and /dev/null differ diff --git a/AffdexMe/app/src/main/res/drawable-xhdpi/ic_more_vert_black_48dp.png b/AffdexMe/app/src/main/res/drawable-xhdpi/ic_more_vert_black_48dp.png deleted file mode 100644 index 4642a3b..0000000 Binary files a/AffdexMe/app/src/main/res/drawable-xhdpi/ic_more_vert_black_48dp.png and /dev/null differ diff --git a/AffdexMe/app/src/main/res/drawable-xhdpi/ic_more_vert_white_48dp.png b/AffdexMe/app/src/main/res/drawable-xhdpi/ic_more_vert_white_48dp.png deleted file mode 100644 index 2f2cb3d..0000000 Binary files a/AffdexMe/app/src/main/res/drawable-xhdpi/ic_more_vert_white_48dp.png and /dev/null differ diff --git a/AffdexMe/app/src/main/res/drawable-xhdpi/ic_switch_camera_black_48dp.png b/AffdexMe/app/src/main/res/drawable-xhdpi/ic_switch_camera_black_48dp.png deleted file mode 100644 index e88bbea..0000000 Binary files a/AffdexMe/app/src/main/res/drawable-xhdpi/ic_switch_camera_black_48dp.png and /dev/null differ diff --git a/AffdexMe/app/src/main/res/drawable-xhdpi/ic_switch_camera_white_48dp.png b/AffdexMe/app/src/main/res/drawable-xhdpi/ic_switch_camera_white_48dp.png deleted file mode 100644 index 1b679f1..0000000 Binary files a/AffdexMe/app/src/main/res/drawable-xhdpi/ic_switch_camera_white_48dp.png and /dev/null differ diff --git a/AffdexMe/app/src/main/res/drawable-xxhdpi/ic_more_vert_black_48dp.png b/AffdexMe/app/src/main/res/drawable-xxhdpi/ic_more_vert_black_48dp.png deleted file mode 100644 index cf0f8f3..0000000 Binary files a/AffdexMe/app/src/main/res/drawable-xxhdpi/ic_more_vert_black_48dp.png and /dev/null differ diff --git a/AffdexMe/app/src/main/res/drawable-xxhdpi/ic_more_vert_white_48dp.png b/AffdexMe/app/src/main/res/drawable-xxhdpi/ic_more_vert_white_48dp.png deleted file mode 100644 index b37b96f..0000000 Binary files a/AffdexMe/app/src/main/res/drawable-xxhdpi/ic_more_vert_white_48dp.png and /dev/null differ diff --git a/AffdexMe/app/src/main/res/drawable-xxhdpi/ic_switch_camera_black_48dp.png b/AffdexMe/app/src/main/res/drawable-xxhdpi/ic_switch_camera_black_48dp.png deleted file mode 100644 index 016ba6d..0000000 Binary files a/AffdexMe/app/src/main/res/drawable-xxhdpi/ic_switch_camera_black_48dp.png and /dev/null differ diff --git a/AffdexMe/app/src/main/res/drawable-xxhdpi/ic_switch_camera_white_48dp.png b/AffdexMe/app/src/main/res/drawable-xxhdpi/ic_switch_camera_white_48dp.png deleted file mode 100644 index 8cbb600..0000000 Binary files a/AffdexMe/app/src/main/res/drawable-xxhdpi/ic_switch_camera_white_48dp.png and /dev/null differ diff --git a/AffdexMe/app/src/main/res/drawable/camera_button_not_pressed.xml b/AffdexMe/app/src/main/res/drawable/camera_button_not_pressed.xml deleted file mode 100644 index ad2ebaa..0000000 --- a/AffdexMe/app/src/main/res/drawable/camera_button_not_pressed.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - \ No newline at end of file diff --git a/AffdexMe/app/src/main/res/drawable/camera_button_pressed.xml b/AffdexMe/app/src/main/res/drawable/camera_button_pressed.xml deleted file mode 100644 index 883b6aa..0000000 --- a/AffdexMe/app/src/main/res/drawable/camera_button_pressed.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - \ No newline at end of file diff --git a/AffdexMe/app/src/main/res/drawable/camera_button_selector.xml b/AffdexMe/app/src/main/res/drawable/camera_button_selector.xml index 669fc9e..2da78c1 100644 --- a/AffdexMe/app/src/main/res/drawable/camera_button_selector.xml +++ b/AffdexMe/app/src/main/res/drawable/camera_button_selector.xml @@ -1,5 +1,5 @@ - - + + \ No newline at end of file diff --git a/AffdexMe/app/src/main/res/drawable/settings_button_not_pressed.xml b/AffdexMe/app/src/main/res/drawable/settings_button_not_pressed.xml deleted file mode 100644 index 739dcec..0000000 --- a/AffdexMe/app/src/main/res/drawable/settings_button_not_pressed.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - \ No newline at end of file diff --git a/AffdexMe/app/src/main/res/drawable/settings_button_pressed.xml b/AffdexMe/app/src/main/res/drawable/settings_button_pressed.xml deleted file mode 100644 index a1922a5..0000000 --- a/AffdexMe/app/src/main/res/drawable/settings_button_pressed.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - \ No newline at end of file diff --git a/AffdexMe/app/src/main/res/drawable/settings_button_selector.xml b/AffdexMe/app/src/main/res/drawable/settings_button_selector.xml index f30d2af..9e079e8 100644 --- a/AffdexMe/app/src/main/res/drawable/settings_button_selector.xml +++ b/AffdexMe/app/src/main/res/drawable/settings_button_selector.xml @@ -1,5 +1,5 @@ - - + + \ No newline at end of file diff --git a/AffdexMe/app/src/main/res/drawable/transluscent_circle.xml b/AffdexMe/app/src/main/res/drawable/transluscent_circle.xml deleted file mode 100644 index 11a1121..0000000 --- a/AffdexMe/app/src/main/res/drawable/transluscent_circle.xml +++ /dev/null @@ -1,10 +0,0 @@ - - - - - - \ No newline at end of file