Added image files for UI update and removed unused ones

This commit is contained in:
acasallas 2015-08-28 15:10:43 -04:00
parent 7081e7fbea
commit 9d71cf0b5e
25 changed files with 33 additions and 76 deletions

View file

@ -26,6 +26,7 @@ import com.affectiva.android.affdex.sdk.detector.Face;
public class DrawingView extends SurfaceView implements SurfaceHolder.Callback { public class DrawingView extends SurfaceView implements SurfaceHolder.Callback {
class PointFArraySharer { class PointFArraySharer {
boolean isPointsMirrored = false;
PointF[] nextPointsToDraw = null; 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. //Updates thread with latest points returned by the onImageResults() event.
public void updatePoints(PointF[] pointList) { public void updatePoints(PointF[] pointList, boolean isPointsMirrored) {
synchronized (sharer) { synchronized (sharer) {
sharer.nextPointsToDraw = pointList; sharer.nextPointsToDraw = pointList;
sharer.isPointsMirrored = isPointsMirrored;
} }
} }
@ -139,10 +141,12 @@ public class DrawingView extends SurfaceView implements SurfaceHolder.Callback {
void draw(Canvas c) { void draw(Canvas c) {
PointF[] points; PointF[] points;
boolean mirrorPoints;
synchronized (sharer) { synchronized (sharer) {
if (sharer.nextPointsToDraw == null) if (sharer.nextPointsToDraw == null)
return; return;
points = sharer.nextPointsToDraw; points = sharer.nextPointsToDraw;
mirrorPoints = sharer.isPointsMirrored;
} }
//Coordinates around which to draw bounding box. //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 //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. //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; 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. //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); drawingThread.setMetrics(roll,yaw,pitch,interOcDis,valence);
} }
public void updatePoints(PointF[] points) { public void updatePoints(PointF[] points, boolean isPointsMirrored) {
drawingThread.updatePoints(points); drawingThread.updatePoints(points, isPointsMirrored);
} }
public void invalidatePoints(){ public void invalidatePoints(){

View file

@ -67,7 +67,7 @@ import com.affectiva.android.affdex.sdk.detector.Face;
*/ */
public class MainActivity extends Activity 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"; private static final String LOG_TAG = "Affectiva";
public static final int NUM_METRICS_DISPLAYED = 6; public static final int NUM_METRICS_DISPLAYED = 6;
@ -114,6 +114,7 @@ public class MainActivity extends Activity
int cameraPreviewWidth = 0; int cameraPreviewWidth = 0;
int cameraPreviewHeight = 0; int cameraPreviewHeight = 0;
CameraDetector.CameraType cameraType; CameraDetector.CameraType cameraType;
boolean mirrorPoints = false;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
@ -146,10 +147,14 @@ public class MainActivity extends Activity
} }
//TODO: change this to be taken from settings //TODO: change this to be taken from settings
if (isBackFacingCameraDetected) if (isBackFacingCameraDetected) {
cameraType = CameraDetector.CameraType.CAMERA_BACK; cameraType = CameraDetector.CameraType.CAMERA_BACK;
if (isFrontFacingCameraDetected) mirrorPoints = false;
}
if (isFrontFacingCameraDetected) {
cameraType = CameraDetector.CameraType.CAMERA_FRONT; cameraType = CameraDetector.CameraType.CAMERA_FRONT;
mirrorPoints = true;
}
} }
void initializeUI() { void initializeUI() {
@ -257,6 +262,7 @@ public class MainActivity extends Activity
restoreApplicationSettings(); restoreApplicationSettings();
setMenuVisible(true); setMenuVisible(true);
isMenuShowingForFirstTime = true; isMenuShowingForFirstTime = true;
mainWindowResumedTasks();
} }
/* /*
@ -335,23 +341,6 @@ public class MainActivity extends Activity
numberOfFrames = 0; 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() { void mainWindowResumedTasks() {
startDetector(); startDetector();
@ -360,6 +349,7 @@ public class MainActivity extends Activity
progressBarLayout.setVisibility(View.GONE); progressBarLayout.setVisibility(View.GONE);
} }
resetFPSCalculations(); resetFPSCalculations();
cameraView.postDelayed(new Runnable() { cameraView.postDelayed(new Runnable() {
@Override @Override
public void run() { public void run() {
@ -402,7 +392,6 @@ public class MainActivity extends Activity
void performFaceDetectionStoppedTasks() { void performFaceDetectionStoppedTasks() {
leftMetricsLayout.animate().alpha(0); //make left and right metrics disappear leftMetricsLayout.animate().alpha(0); //make left and right metrics disappear
rightMetricsLayout.animate().alpha(0); rightMetricsLayout.animate().alpha(0);
drawingView.updatePoints(null);
resetFPSCalculations(); //Since the FPS may be different whether a face is being tracked or not, reset variables. 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() is 0, we received a frame in which no face was detected
if (faces.size() == 0) { 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; return;
} }
@ -441,7 +430,7 @@ public class MainActivity extends Activity
*/ */
if (drawingView.getDrawPointsEnabled() || drawingView.getDrawMeasurementsEnabled()) { 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.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) { public void settings_button_click(View view) {
startActivity(new Intent(this,SettingsActivity.class)); startActivity(new Intent(this, SettingsActivity.class));
} }
/*
@Override @Override
public void onCameraStarted(boolean b, Throwable throwable) { public void onCameraStarted(boolean b, Throwable throwable) {
if (throwable != null) { if (throwable != null) {
Toast.makeText(this,"Failed to start camera.",Toast.LENGTH_LONG).show(); Toast.makeText(this,"Failed to start camera.",Toast.LENGTH_LONG).show();
} }
}*/ }
@Override @Override
public void onCameraSizeSelected(int cameraWidth, int cameraHeight, ROTATE rotation) { 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 (cameraType == CameraDetector.CameraType.CAMERA_FRONT) {
if (isBackFacingCameraDetected) { if (isBackFacingCameraDetected) {
cameraType = CameraDetector.CameraType.CAMERA_BACK; cameraType = CameraDetector.CameraType.CAMERA_BACK;
mirrorPoints = false;
} else { } else {
Toast.makeText(this,"No back-facing camera found",Toast.LENGTH_LONG).show(); Toast.makeText(this,"No back-facing camera found",Toast.LENGTH_LONG).show();
} }
} else if (cameraType == CameraDetector.CameraType.CAMERA_BACK) { } else if (cameraType == CameraDetector.CameraType.CAMERA_BACK) {
if (isFrontFacingCameraDetected) { if (isFrontFacingCameraDetected) {
cameraType = CameraDetector.CameraType.CAMERA_FRONT; cameraType = CameraDetector.CameraType.CAMERA_FRONT;
mirrorPoints = true;
} else { } else {
Toast.makeText(this,"No front-facing camera found",Toast.LENGTH_LONG).show(); Toast.makeText(this,"No front-facing camera found",Toast.LENGTH_LONG).show();
} }

Binary file not shown.

Before

Width:  |  Height:  |  Size: 205 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 216 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 365 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 379 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 155 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 158 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 248 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 259 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 272 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 305 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 451 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 472 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 411 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 472 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 674 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 713 B

View file

@ -1,8 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/transluscent_circle"
android:maxLevel="0"/>
<item android:drawable="@drawable/ic_switch_camera_black_48dp"
android:maxLevel="1"
/>
</layer-list>

View file

@ -1,8 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/transluscent_circle"
android:maxLevel="0"/>
<item android:drawable="@drawable/ic_switch_camera_white_48dp"
android:maxLevel="1"
/>
</layer-list>

View file

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android"> <selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true" android:drawable="@drawable/camera_button_pressed"/> <item android:state_pressed="true" android:drawable="@drawable/switch_camera_button"/>
<item android:drawable="@drawable/camera_button_not_pressed" /> <item android:drawable="@drawable/switch_camera_button_pressed" />
</selector> </selector>

View file

@ -1,8 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/transluscent_circle"
android:maxLevel="0"/>
<item android:drawable="@drawable/ic_more_vert_black_48dp"
android:maxLevel="1"
/>
</layer-list>

View file

@ -1,8 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/transluscent_circle"
android:maxLevel="0"/>
<item android:drawable="@drawable/ic_more_vert_white_48dp"
android:maxLevel="1"
/>
</layer-list>

View file

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android"> <selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true" android:drawable="@drawable/settings_button_pressed"/> <item android:state_pressed="true" android:drawable="@drawable/settings_button_pressed_1"/>
<item android:drawable="@drawable/settings_button_not_pressed" /> <item android:drawable="@drawable/settings_button" />
</selector> </selector>

View file

@ -1,10 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">
<solid
android:color="#88FFFFFF"/>
<corners
android:radius="24dp"/>
<size android:height="48dp"
android:width="48dp"/>
</shape>