First weknowhowyoufeel version with new Affectiva SDK

This commit is contained in:
Ruben 2016-10-05 18:34:36 +02:00
parent 6b95c438bd
commit e297ff9922
8 changed files with 122 additions and 160 deletions

19
WeKnowHowYouFeel.iml Normal file
View File

@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<module external.linked.project.id="WeKnowHowYouFeel" external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$" external.system.id="GRADLE" type="JAVA_MODULE" version="4">
<component name="FacetManager">
<facet type="java-gradle" name="Java-Gradle">
<configuration>
<option name="BUILD_FOLDER_PATH" value="$MODULE_DIR$/build" />
<option name="BUILDABLE" value="false" />
</configuration>
</facet>
</component>
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_7" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<excludeFolder url="file://$MODULE_DIR$/.gradle" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

View File

@ -14,6 +14,10 @@
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<!--Kiosk Mode-->
<uses-permission android:name="android.permission.REORDER_TASKS" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-feature
android:name="android.hardware.camera"
android:required="false" />
@ -38,6 +42,9 @@
android:theme="@style/MainActivityTheme">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.HOME" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

View File

@ -497,9 +497,9 @@ public class DrawingView extends SurfaceView implements SurfaceHolder.Callback {
}
//Draw the bounding box.
if (config.isDrawPointsEnabled) {
drawBoundingBox(c, face, boundingRect);
}
// if (config.isDrawPointsEnabled) {
// drawBoundingBox(c, face, boundingRect);
// }
float heightOffset = findNecessaryHeightOffset(boundingRect, face);

View File

@ -6,6 +6,7 @@
package com.affectiva.affdexme;
import android.Manifest;
import android.app.ActivityManager;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
@ -16,6 +17,7 @@ import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Rect;
import android.graphics.Typeface;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.os.Environment;
import android.os.SystemClock;
@ -92,7 +94,7 @@ public class MainActivity extends AppCompatActivity
public static final int MAX_SUPPORTED_FACES = 3;
public static final boolean STORE_RAW_SCREENSHOTS = false; // setting to enable saving the raw images when taking screenshots
public static final int NUM_METRICS_DISPLAYED = 6;
public static final int NUM_METRICS_DISPLAYED = 7;
private static final String LOG_TAG = "AffdexMe";
private static final int CAMERA_PERMISSIONS_REQUEST = 42; //value is arbitrary (between 0 and 255)
private static final int EXTERNAL_STORAGE_PERMISSIONS_REQUEST = 73;
@ -117,9 +119,6 @@ public class MainActivity extends AppCompatActivity
private LinearLayout permissionsUnavailableLayout; //layout used to notify the user that not enough permissions have been granted to use the app
private SurfaceView cameraView; //SurfaceView used to display camera images
private DrawingView drawingView; //SurfaceView containing its own thread, used to draw facial tracking dots
private ImageButton settingsButton;
private ImageButton cameraButton;
private ImageButton screenshotButton;
private Frame mostRecentFrame;
private boolean isMenuVisible = false;
private boolean isFPSVisible = false;
@ -131,6 +130,8 @@ public class MainActivity extends AppCompatActivity
private boolean isBackFacingCameraDetected = true;
private boolean multiFaceModeEnabled = false;
private MediaPlayer mp;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@ -141,6 +142,8 @@ public class MainActivity extends AppCompatActivity
checkForCameraPermissions();
determineCameraAvailability();
initializeCameraDetector();
mp = MediaPlayer.create(this, R.raw.beyond_sleep_vo);
}
/**
@ -208,7 +211,7 @@ public class MainActivity extends AppCompatActivity
requestStoragePermissions();
}
} else {
takeScreenshot(screenshotButton);
}
}
@ -269,7 +272,7 @@ public class MainActivity extends AppCompatActivity
if (storagePermissionsAvailable) {
// resume taking the screenshot
takeScreenshot(screenshotButton);
}
}
@ -357,9 +360,6 @@ public class MainActivity extends AppCompatActivity
fpsName = (TextView) findViewById(R.id.fps_name);
cameraView = (SurfaceView) findViewById(R.id.camera_preview);
drawingView = (DrawingView) findViewById(R.id.drawing_view);
settingsButton = (ImageButton) findViewById(R.id.settings_button);
cameraButton = (ImageButton) findViewById(R.id.camera_button);
screenshotButton = (ImageButton) findViewById(R.id.screenshot_button);
progressBar = (ProgressBar) findViewById(R.id.progress_bar);
pleaseWaitTextView = (TextView) findViewById(R.id.please_wait_textview);
Button retryPermissionsButton = (Button) findViewById(R.id.retryPermissionsButton);
@ -372,6 +372,7 @@ public class MainActivity extends AppCompatActivity
metricNames[3] = (TextView) findViewById(R.id.metric_name_3);
metricNames[4] = (TextView) findViewById(R.id.metric_name_4);
metricNames[5] = (TextView) findViewById(R.id.metric_name_5);
metricNames[6] = (TextView) findViewById(R.id.metric_name_6);
metricDisplays = new MetricDisplay[NUM_METRICS_DISPLAYED];
metricDisplays[0] = (MetricDisplay) findViewById(R.id.metric_pct_0);
metricDisplays[1] = (MetricDisplay) findViewById(R.id.metric_pct_1);
@ -379,6 +380,7 @@ public class MainActivity extends AppCompatActivity
metricDisplays[3] = (MetricDisplay) findViewById(R.id.metric_pct_3);
metricDisplays[4] = (MetricDisplay) findViewById(R.id.metric_pct_4);
metricDisplays[5] = (MetricDisplay) findViewById(R.id.metric_pct_5);
metricDisplays[6] = (MetricDisplay) findViewById(R.id.metric_pct_6);
//Load Application Font and set UI Elements to use it
Typeface face = Typeface.createFromAsset(getAssets(), "fonts/Square.ttf");
@ -456,7 +458,7 @@ public class MainActivity extends AppCompatActivity
super.onResume();
checkForCameraPermissions();
restoreApplicationSettings();
setMenuVisible(true);
setMenuVisible(false);
isMenuShowingForFirstTime = true;
}
@ -497,37 +499,28 @@ public class MainActivity extends AppCompatActivity
detector.setMaxProcessRate(detectorProcessRate);
drawingView.invalidateDimensions();
if (sharedPreferences.getBoolean("fps", isFPSVisible)) { //restore isFPSMetricVisible
setFPSVisible(true);
} else {
setFPSVisible(false);
}
setFPSVisible(false);
setTrackPoints(true);
if (sharedPreferences.getBoolean("track", drawingView.getDrawPointsEnabled())) { //restore isTrackingDotsVisible
setTrackPoints(true);
} else {
setTrackPoints(false);
}
detector.setDetectAllAppearances(false);
setShowAppearance(false);
if (sharedPreferences.getBoolean("appearance", drawingView.getDrawAppearanceMarkersEnabled())) {
detector.setDetectAllAppearances(true);
setShowAppearance(true);
} else {
detector.setDetectAllAppearances(false);
setShowAppearance(false);
}
if (sharedPreferences.getBoolean("emoji", drawingView.getDrawEmojiMarkersEnabled())) {
detector.setDetectAllEmojis(true);
setShowEmoji(true);
} else {
detector.setDetectAllEmojis(false);
setShowEmoji(false);
}
detector.setDetectAllEmojis(false);
setShowEmoji(false);
//populate metric displays
for (int n = 0; n < NUM_METRICS_DISPLAYED; n++) {
activateMetric(n, PreferencesUtils.getMetricFromPrefs(sharedPreferences, n));
// for (int n = 0; n < NUM_METRICS_DISPLAYED; n++) {
// activateMetric(n, PreferencesUtils.getMetricFromPrefs(sharedPreferences, n));
// }
detector.setDetectAllEmotions(true);
int i=0;
for(MetricsManager.Emotions emotion: MetricsManager.Emotions.values()) {
if(emotion.equals(MetricsManager.Emotions.ENGAGEMENT) || emotion.equals(MetricsManager.Emotions.VALENCE)) {
continue;
}
activateMetric(i, emotion);
i++;
}
//if we are in multiface mode, we need to enable the detection of all emotions
@ -542,44 +535,23 @@ public class MainActivity extends AppCompatActivity
* -enable the corresponding metric in the Detector object by calling Detector.setDetect<MetricName>()
* -save the Method object that will be invoked on the Face object received in onImageResults() to get the metric score
*/
void activateMetric(int index, MetricsManager.Metrics metric) {
void activateMetric(int index, MetricsManager.Emotions metric) {
Method getFaceScoreMethod = null; //The method that will be used to get a metric score
try {
switch (metric.getType()) {
case Emotion:
Detector.class.getMethod("setDetect" + MetricsManager.getCamelCase(metric), boolean.class).invoke(detector, true);
metricNames[index].setText(MetricsManager.getUpperCaseName(metric));
getFaceScoreMethod = Face.Emotions.class.getMethod("get" + MetricsManager.getCamelCase(metric));
metricNames[index].setText(MetricsManager.getUpperCaseName(metric));
getFaceScoreMethod = Face.Emotions.class.getMethod("get" + MetricsManager.getCamelCase(metric));
//The MetricDisplay for Valence is unique; it shades it color depending on the metric value
if (metric == MetricsManager.Emotions.VALENCE) {
metricDisplays[index].setIsShadedMetricView(true);
} else {
metricDisplays[index].setIsShadedMetricView(false);
}
break;
case Expression:
Detector.class.getMethod("setDetect" + MetricsManager.getCamelCase(metric), boolean.class).invoke(detector, true);
metricNames[index].setText(MetricsManager.getUpperCaseName(metric));
getFaceScoreMethod = Face.Expressions.class.getMethod("get" + MetricsManager.getCamelCase(metric));
break;
case Emoji:
detector.setDetectAllEmojis(true);
MetricsManager.Emojis emoji = ((MetricsManager.Emojis) metric);
String metricTitle = emoji.getDisplayName(); // + " " + emoji.getUnicodeForEmoji();
metricNames[index].setText(metricTitle);
Log.d(LOG_TAG, "Getter Method: " + "get" + MetricsManager.getCamelCase(metric));
getFaceScoreMethod = Face.Emojis.class.getMethod("get" + MetricsManager.getCamelCase(metric));
break;
//The MetricDisplay for Valence is unique; it shades it color depending on the metric value
if (metric == MetricsManager.Emotions.VALENCE) {
metricDisplays[index].setIsShadedMetricView(true);
} else {
metricDisplays[index].setIsShadedMetricView(false);
}
} catch (NoSuchMethodException e) {
Log.e(LOG_TAG, String.format("No such method while using reflection to generate methods for %s", metric.toString()), e);
} catch (InvocationTargetException e) {
Log.e(LOG_TAG, String.format("Invocation error while using reflection to generate methods for %s", metric.toString()), e);
} catch (IllegalAccessException e) {
Log.e(LOG_TAG, String.format("Illegal access error while using reflection to generate methods for %s", metric.toString()), e);
}
metricDisplays[index].setMetricToDisplay(metric, getFaceScoreMethod);
@ -609,6 +581,12 @@ public class MainActivity extends AppCompatActivity
}
});
}
if(!hasFocus) {
// Close every kind of system dialog
// Intent closeDialog = new Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS);
// sendBroadcast(closeDialog);
}
}
void mainWindowResumedTasks() {
@ -655,6 +633,10 @@ public class MainActivity extends AppCompatActivity
rightMetricsLayout.animate().alpha(1);
resetFPSCalculations(); //Since the FPS may be different whether a face is being tracked or not, reset variables.
if(mp != null && !mp.isPlaying()) {
mp.start();
}
}
@Override
@ -865,6 +847,12 @@ public class MainActivity extends AppCompatActivity
super.onPause();
progressBarLayout.setVisibility(View.VISIBLE);
ActivityManager activityManager = (ActivityManager) getApplicationContext()
.getSystemService(Context.ACTIVITY_SERVICE);
activityManager.moveTaskToFront(getTaskId(), 0);
performFaceDetectionStoppedTasks();
stopDetector();
@ -890,31 +878,13 @@ public class MainActivity extends AppCompatActivity
* When the user taps the screen, hide the menu if it is visible and show it if it is hidden.
**/
void setMenuVisible(boolean b) {
isMenuShowingForFirstTime = false;
isMenuVisible = b;
if (b) {
settingsButton.setVisibility(View.VISIBLE);
cameraButton.setVisibility(View.VISIBLE);
screenshotButton.setVisibility(View.VISIBLE);
//We display the navigation bar again
getWindow().getDecorView().setSystemUiVisibility(
View.SYSTEM_UI_FLAG_LAYOUT_STABLE
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
} else {
//We hide the navigation bar
getWindow().getDecorView().setSystemUiVisibility(
View.SYSTEM_UI_FLAG_LAYOUT_STABLE
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_FULLSCREEN);
settingsButton.setVisibility(View.INVISIBLE);
cameraButton.setVisibility(View.INVISIBLE);
screenshotButton.setVisibility(View.INVISIBLE);
}
//We hide the navigation bar
getWindow().getDecorView().setSystemUiVisibility(
View.SYSTEM_UI_FLAG_LAYOUT_STABLE
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_FULLSCREEN);
}
/**
@ -963,9 +933,6 @@ public class MainActivity extends AppCompatActivity
return false;
}
public void settings_button_click(View view) {
startActivity(new Intent(this, SettingsActivity.class));
}
@SuppressWarnings("SuspiciousNameCombination")
@Override
@ -1019,10 +986,7 @@ public class MainActivity extends AppCompatActivity
}
public void camera_button_click(View view) {
//Toggle the camera setting
setCameraType(cameraType == CameraDetector.CameraType.CAMERA_FRONT ? CameraDetector.CameraType.CAMERA_BACK : CameraDetector.CameraType.CAMERA_FRONT);
}
private void setCameraType(CameraDetector.CameraType type) {
SharedPreferences.Editor preferencesEditor = PreferenceManager.getDefaultSharedPreferences(this).edit();
@ -1069,4 +1033,11 @@ public class MainActivity extends AppCompatActivity
}
});
}
@Override
public void onBackPressed() {
// nothing to do here
// really
}
}

View File

@ -30,46 +30,10 @@
<include
android:id="@+id/metric_view_group"
layout="@layout/metric_layout" />
<ImageButton
android:id="@+id/settings_button"
android:layout_width="@dimen/settings_button_size"
android:layout_height="@dimen/settings_button_size"
android:layout_alignParentRight="true"
android:layout_below="@id/metric_view_group"
android:layout_margin="@dimen/settings_button_margin"
android:background="@null"
android:contentDescription="@string/settings_content_description"
android:onClick="settings_button_click"
android:scaleType="fitCenter"
android:src="@drawable/settings_button_selector" />
<ImageButton
android:id="@+id/camera_button"
android:layout_width="@dimen/settings_button_size"
android:layout_height="@dimen/settings_button_size"
android:layout_alignParentRight="true"
android:layout_below="@id/settings_button"
android:layout_margin="@dimen/settings_button_margin"
android:background="@null"
android:contentDescription="Switch camera button"
android:onClick="camera_button_click"
android:scaleType="fitCenter"
android:src="@drawable/camera_button_selector" />
<ImageButton
android:id="@+id/screenshot_button"
android:layout_width="@dimen/settings_button_size"
android:layout_height="@dimen/settings_button_size"
android:layout_alignParentRight="true"
android:layout_below="@id/camera_button"
android:layout_margin="@dimen/settings_button_margin"
android:background="@null"
android:contentDescription="Take screenshot"
android:onClick="takeScreenshot"
android:scaleType="fitCenter"
android:src="@drawable/screenshot_button_selector" />
layout="@layout/metric_layout"
android:layout_height="170dp"
android:layout_width="match_parent"
android:layout_centerVertical="true" />
<include layout="@layout/insufficent_permissions_panel" />

View File

@ -2,21 +2,15 @@
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_height="@dimen/metric_viewgroup"
android:layout_height="170dp"
android:layout_width="match_parent"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:background="@color/transparent_overlay"
android:paddingBottom="@dimen/bottom_padding"
>
android:layout_centerInParent="false"
android:layout_centerVertical="false"
android:layout_gravity="center_vertical">
<!-- Logo-->
<ImageView
android:layout_height="wrap_content"
android:layout_width="@dimen/logo_width"
android:layout_centerInParent="true"
android:src="@drawable/affectiva_logo_clear_background"
android:contentDescription="@string/affectiva_logo_content_description"
android:id="@+id/affectiva_logo" />
<!-- Left MetricsManager-->
<LinearLayout
android:orientation="vertical"
@ -44,6 +38,13 @@
<com.affectiva.affdexme.MetricDisplay
style="@style/metricPct"
android:id="@+id/metric_pct_2" />
<TextView
style="@style/metricName"
android:id="@+id/metric_name_3" />
<com.affectiva.affdexme.MetricDisplay
style="@style/metricPct"
android:id="@+id/metric_pct_3" />
</LinearLayout>
<!-- FPS Counter-->
<LinearLayout
@ -77,14 +78,8 @@
android:layout_width="wrap_content"
android:layout_alignParentRight="true"
android:paddingRight="@dimen/metric_panel_padding"
android:layout_height="match_parent"
android:layout_height="130dp"
android:id="@+id/right_metrics">
<TextView
style="@style/metricName"
android:id="@+id/metric_name_3" />
<com.affectiva.affdexme.MetricDisplay
style="@style/metricPct"
android:id="@+id/metric_pct_3" />
<TextView
style="@style/metricName"
android:id="@+id/metric_name_4" />
@ -97,5 +92,11 @@
<com.affectiva.affdexme.MetricDisplay
style="@style/metricPct"
android:id="@+id/metric_pct_5" />
<TextView
style="@style/metricName"
android:id="@+id/metric_name_6" />
<com.affectiva.affdexme.MetricDisplay
style="@style/metricPct"
android:id="@+id/metric_pct_6" />
</LinearLayout>
</RelativeLayout>

Binary file not shown.

View File

@ -5,7 +5,7 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.1.3'
classpath 'com.android.tools.build:gradle:2.2.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files