Changed to look like the clearer old-school style as used in original WeKnowHowYouFeel

This commit is contained in:
Ruben 2016-10-30 21:28:13 +01:00
parent e297ff9922
commit 536aae6a5f
12 changed files with 224 additions and 139 deletions

View file

@ -39,6 +39,7 @@
android:name=".MainActivity" android:name=".MainActivity"
android:configChanges="screenSize|keyboardHidden|orientation" android:configChanges="screenSize|keyboardHidden|orientation"
android:label="@string/app_name" android:label="@string/app_name"
android:screenOrientation="landscape"
android:theme="@style/MainActivityTheme"> android:theme="@style/MainActivityTheme">
<intent-filter> <intent-filter>
<action android:name="android.intent.action.MAIN" /> <action android:name="android.intent.action.MAIN" />

Binary file not shown.

After

Width:  |  Height:  |  Size: 50 KiB

View file

@ -108,7 +108,7 @@ public class MainActivity extends AppCompatActivity
private RelativeLayout metricViewLayout; private RelativeLayout metricViewLayout;
private LinearLayout leftMetricsLayout; private LinearLayout leftMetricsLayout;
private LinearLayout rightMetricsLayout; private LinearLayout rightMetricsLayout;
private MetricDisplay[] metricDisplays; private TextView[] metricDisplays;
private TextView[] metricNames; private TextView[] metricNames;
private TextView fpsName; private TextView fpsName;
private TextView fpsPct; private TextView fpsPct;
@ -129,6 +129,7 @@ public class MainActivity extends AppCompatActivity
private boolean isFrontFacingCameraDetected = true; private boolean isFrontFacingCameraDetected = true;
private boolean isBackFacingCameraDetected = true; private boolean isBackFacingCameraDetected = true;
private boolean multiFaceModeEnabled = false; private boolean multiFaceModeEnabled = false;
private TextView showFaceText;
private MediaPlayer mp; private MediaPlayer mp;
@ -356,8 +357,8 @@ public class MainActivity extends AppCompatActivity
leftMetricsLayout = (LinearLayout) findViewById(R.id.left_metrics); leftMetricsLayout = (LinearLayout) findViewById(R.id.left_metrics);
rightMetricsLayout = (LinearLayout) findViewById(R.id.right_metrics); rightMetricsLayout = (LinearLayout) findViewById(R.id.right_metrics);
mainLayout = (RelativeLayout) findViewById(R.id.main_layout); mainLayout = (RelativeLayout) findViewById(R.id.main_layout);
fpsPct = (TextView) findViewById(R.id.fps_value); // fpsPct = (TextView) findViewById(R.id.fps_value);
fpsName = (TextView) findViewById(R.id.fps_name); // fpsName = (TextView) findViewById(R.id.fps_name);
cameraView = (SurfaceView) findViewById(R.id.camera_preview); cameraView = (SurfaceView) findViewById(R.id.camera_preview);
drawingView = (DrawingView) findViewById(R.id.drawing_view); drawingView = (DrawingView) findViewById(R.id.drawing_view);
progressBar = (ProgressBar) findViewById(R.id.progress_bar); progressBar = (ProgressBar) findViewById(R.id.progress_bar);
@ -373,25 +374,26 @@ public class MainActivity extends AppCompatActivity
metricNames[4] = (TextView) findViewById(R.id.metric_name_4); metricNames[4] = (TextView) findViewById(R.id.metric_name_4);
metricNames[5] = (TextView) findViewById(R.id.metric_name_5); metricNames[5] = (TextView) findViewById(R.id.metric_name_5);
metricNames[6] = (TextView) findViewById(R.id.metric_name_6); metricNames[6] = (TextView) findViewById(R.id.metric_name_6);
metricDisplays = new MetricDisplay[NUM_METRICS_DISPLAYED]; metricDisplays = new TextView[NUM_METRICS_DISPLAYED];
metricDisplays[0] = (MetricDisplay) findViewById(R.id.metric_pct_0); metricDisplays[0] = (TextView) findViewById(R.id.metric_pct_0);
metricDisplays[1] = (MetricDisplay) findViewById(R.id.metric_pct_1); metricDisplays[1] = (TextView) findViewById(R.id.metric_pct_1);
metricDisplays[2] = (MetricDisplay) findViewById(R.id.metric_pct_2); metricDisplays[2] = (TextView) findViewById(R.id.metric_pct_2);
metricDisplays[3] = (MetricDisplay) findViewById(R.id.metric_pct_3); metricDisplays[3] = (TextView) findViewById(R.id.metric_pct_3);
metricDisplays[4] = (MetricDisplay) findViewById(R.id.metric_pct_4); metricDisplays[4] = (TextView) findViewById(R.id.metric_pct_4);
metricDisplays[5] = (MetricDisplay) findViewById(R.id.metric_pct_5); metricDisplays[5] = (TextView) findViewById(R.id.metric_pct_5);
metricDisplays[6] = (MetricDisplay) findViewById(R.id.metric_pct_6); metricDisplays[6] = (TextView) findViewById(R.id.metric_pct_6);
showFaceText = (TextView) findViewById(R.id.no_face_found);
//Load Application Font and set UI Elements to use it //Load Application Font and set UI Elements to use it
Typeface face = Typeface.createFromAsset(getAssets(), "fonts/Square.ttf"); Typeface face = Typeface.createFromAsset(getAssets(), "fonts/Square.ttf");
for (TextView textView : metricNames) { // for (TextView textView : metricNames) {
textView.setTypeface(face); // textView.setTypeface(face);
} // }
for (MetricDisplay metricDisplay : metricDisplays) { // for (TextView metricDisplay : metricDisplays) {
metricDisplay.setTypeface(face); // metricDisplay.setTypeface(face);
} // }
fpsPct.setTypeface(face); // fpsPct.setTypeface(face);
fpsName.setTypeface(face); // fpsName.setTypeface(face);
drawingView.setTypeface(face); drawingView.setTypeface(face);
pleaseWaitTextView.setTypeface(face); pleaseWaitTextView.setTypeface(face);
@ -515,18 +517,18 @@ public class MainActivity extends AppCompatActivity
detector.setDetectAllEmotions(true); detector.setDetectAllEmotions(true);
int i=0; int i=0;
for(MetricsManager.Emotions emotion: MetricsManager.Emotions.values()) { // for(MetricsManager.Emotions emotion: MetricsManager.Emotions.values()) {
if(emotion.equals(MetricsManager.Emotions.ENGAGEMENT) || emotion.equals(MetricsManager.Emotions.VALENCE)) { // if(emotion.equals(MetricsManager.Emotions.ENGAGEMENT) || emotion.equals(MetricsManager.Emotions.VALENCE)) {
continue; // continue;
} // }
activateMetric(i, emotion); // activateMetric(i, emotion);
i++; // i++;
} // }
//if we are in multiface mode, we need to enable the detection of all emotions //if we are in multiface mode, we need to enable the detection of all emotions
if (multiFaceModeEnabled) { // if (multiFaceModeEnabled) {
detector.setDetectAllEmotions(true); // detector.setDetectAllEmotions(true);
} // }
} }
/** /**
@ -540,21 +542,21 @@ public class MainActivity extends AppCompatActivity
Method getFaceScoreMethod = null; //The method that will be used to get a metric score Method getFaceScoreMethod = null; //The method that will be used to get a metric score
try { try {
metricNames[index].setText(MetricsManager.getUpperCaseName(metric)); // metricNames[index].setText(MetricsManager.getUpperCaseName(metric));
getFaceScoreMethod = Face.Emotions.class.getMethod("get" + MetricsManager.getCamelCase(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 //The MetricDisplay for Valence is unique; it shades it color depending on the metric value
if (metric == MetricsManager.Emotions.VALENCE) { // if (metric == MetricsManager.Emotions.VALENCE) {
metricDisplays[index].setIsShadedMetricView(true); // metricDisplays[index].setIsShadedMetricView(true);
} else { // } else {
metricDisplays[index].setIsShadedMetricView(false); // metricDisplays[index].setIsShadedMetricView(false);
} // }
} catch (NoSuchMethodException e) { } catch (NoSuchMethodException e) {
Log.e(LOG_TAG, String.format("No such method while using reflection to generate methods for %s", metric.toString()), e); Log.e(LOG_TAG, String.format("No such method while using reflection to generate methods for %s", metric.toString()), e);
} }
metricDisplays[index].setMetricToDisplay(metric, getFaceScoreMethod); // metricDisplays[index].setMetricToDisplay(metric, getFaceScoreMethod);
} }
/** /**
@ -617,7 +619,7 @@ public class MainActivity extends AppCompatActivity
if (!isBackFacingCameraDetected && !isFrontFacingCameraDetected) if (!isBackFacingCameraDetected && !isFrontFacingCameraDetected)
return; //without any cameras detected, we cannot proceed return; //without any cameras detected, we cannot proceed
detector.setDetectValence(true); //this app will always detect valence detector.setDetectValence(false); //this app will always detect valence
if (!detector.isRunning()) { if (!detector.isRunning()) {
try { try {
detector.start(); detector.start();
@ -632,6 +634,8 @@ public class MainActivity extends AppCompatActivity
leftMetricsLayout.animate().alpha(1); //make left and right metrics appear leftMetricsLayout.animate().alpha(1); //make left and right metrics appear
rightMetricsLayout.animate().alpha(1); rightMetricsLayout.animate().alpha(1);
showFaceText.setVisibility(View.GONE);
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.
if(mp != null && !mp.isPlaying()) { if(mp != null && !mp.isPlaying()) {
@ -641,6 +645,7 @@ public class MainActivity extends AppCompatActivity
@Override @Override
public void onFaceDetectionStopped() { public void onFaceDetectionStopped() {
showFaceText.setVisibility(View.VISIBLE);
performFaceDetectionStoppedTasks(); performFaceDetectionStoppedTasks();
} }
@ -670,10 +675,36 @@ public class MainActivity extends AppCompatActivity
drawingView.invalidatePoints(); drawingView.invalidatePoints();
} else if (faces.size() == 1) { } else if (faces.size() == 1) {
metricViewLayout.setVisibility(View.VISIBLE); metricViewLayout.setVisibility(View.VISIBLE);
//update metrics with latest face information. The metrics are displayed on a MetricView, a custom view with a .setScore() method. //update metrics with latest face information. The metrics are displayed on a MetricView, a custom view with a .setScore() method.
for (MetricDisplay metricDisplay : metricDisplays) { int i = 0;
updateMetricScore(metricDisplay, faces.get(0)); for (TextView metricDisplay : metricDisplays) {
float score = 0;
switch (i){
case 4:
score = faces.get(0).emotions.getAnger();
break;
case 5:
score = faces.get(0).emotions.getContempt();
break;
case 6:
score = faces.get(0).emotions.getDisgust();
break;
case 0:
score = faces.get(0).emotions.getFear();
break;
case 1:
score = faces.get(0).emotions.getJoy();
break;
case 2:
score = faces.get(0).emotions.getSadness();
break;
case 3:
score = faces.get(0).emotions.getSurprise();
break;
}
i++;
metricDisplay.setText(String.format(Locale.US, "%.0f%%", score));
// updateMetricScore(metricDisplay, faces.get(0));
} }
/** /**
@ -828,13 +859,14 @@ public class MainActivity extends AppCompatActivity
* before numberOfFrames overflows. * before numberOfFrames overflows.
*/ */
void performFPSCalculations() { void performFPSCalculations() {
numberOfFrames += 1; return;
long currentTime = SystemClock.elapsedRealtime(); // numberOfFrames += 1;
if (currentTime > timeToUpdate) { // long currentTime = SystemClock.elapsedRealtime();
float framesPerSecond = (numberOfFrames / (float) (currentTime - firstSystemTime)) * 1000f; // if (currentTime > timeToUpdate) {
fpsPct.setText(String.format(" %.1f", framesPerSecond)); // float framesPerSecond = (numberOfFrames / (float) (currentTime - firstSystemTime)) * 1000f;
timeToUpdate = currentTime + 1000L; // fpsPct.setText(String.format(" %.1f", framesPerSecond));
} // timeToUpdate = currentTime + 1000L;
// }
} }
/** /**
@ -915,14 +947,15 @@ public class MainActivity extends AppCompatActivity
void setFPSVisible(boolean b) { void setFPSVisible(boolean b) {
isFPSVisible = b; return;
if (b) { // isFPSVisible = b;
fpsName.setVisibility(View.VISIBLE); // if (b) {
fpsPct.setVisibility(View.VISIBLE); // fpsName.setVisibility(View.VISIBLE);
} else { // fpsPct.setVisibility(View.VISIBLE);
fpsName.setVisibility(View.INVISIBLE); // } else {
fpsPct.setVisibility(View.INVISIBLE); // fpsName.setVisibility(View.INVISIBLE);
} // fpsPct.setVisibility(View.INVISIBLE);
// }
} }
@Override @Override

View file

@ -31,7 +31,7 @@
<include <include
android:id="@+id/metric_view_group" android:id="@+id/metric_view_group"
layout="@layout/metric_layout" layout="@layout/metric_layout"
android:layout_height="170dp" android:layout_height="match_parent"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_centerVertical="true" /> android:layout_centerVertical="true" />

View file

@ -1,8 +1,9 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout <RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android" xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="horizontal" android:orientation="horizontal"
android:layout_height="170dp" android:layout_height="match_parent"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_alignParentTop="true" android:layout_alignParentTop="true"
android:layout_centerHorizontal="true" android:layout_centerHorizontal="true"
@ -12,91 +13,141 @@
android:layout_gravity="center_vertical"> android:layout_gravity="center_vertical">
<!-- Logo--> <!-- Logo-->
<!-- Left MetricsManager--> <!-- Left MetricsManager-->
<!-- FPS Counter-->
<!-- Right MetricsManager-->
<LinearLayout <LinearLayout
android:orientation="vertical" android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_alignParentRight="true"
android:paddingRight="@dimen/metric_panel_padding"
android:paddingTop="15dp"
android:layout_height="wrap_content"
android:id="@+id/right_metrics">
<LinearLayout
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
style="@style/metricName"
android:id="@+id/metric_name_4"
android:text="anger"
android:paddingTop="15dp"/>
<TextView
style="@style/metricName"
android:id="@+id/metric_pct_4"
tools:text="10%" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
style="@style/metricName"
android:id="@+id/metric_name_5"
android:text="contempt" />
<TextView
style="@style/metricName"
android:id="@+id/metric_pct_5"
tools:text="10%" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
style="@style/metricName"
android:id="@+id/metric_name_6"
android:text="disgust"
android:paddingTop="15dp" />
<TextView
style="@style/metricName"
android:id="@+id/metric_pct_6"
tools:text="10%" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:paddingLeft="@dimen/metric_panel_padding" android:paddingLeft="@dimen/metric_panel_padding"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/left_metrics"
android:paddingBottom="15dp"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true" android:layout_alignParentLeft="true"
android:layout_width="wrap_content" android:layout_alignParentStart="true">
android:layout_height="match_parent" <LinearLayout
android:id="@+id/left_metrics"> android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView <TextView
style="@style/metricName" style="@style/metricName"
android:id="@+id/metric_name_0" android:id="@+id/metric_name_0"
/> android:text="fear"/>
<com.affectiva.affdexme.MetricDisplay
style="@style/metricPct"
android:id="@+id/metric_pct_0" />
<TextView <TextView
style="@style/metricName" style="@style/metricName"
android:id="@+id/metric_name_1" /> android:id="@+id/metric_pct_0"
<com.affectiva.affdexme.MetricDisplay tools:text="10%" />
style="@style/metricPct" </LinearLayout>
android:id="@+id/metric_pct_1" /> <LinearLayout
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView <TextView
style="@style/metricName" style="@style/metricName"
android:id="@+id/metric_name_2" /> android:id="@+id/metric_name_1"
<com.affectiva.affdexme.MetricDisplay android:text="joy"
style="@style/metricPct" android:paddingTop="15dp"/>
android:id="@+id/metric_pct_2" /> <TextView
style="@style/metricName"
android:id="@+id/metric_pct_1"
tools:text="10%" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
style="@style/metricName"
android:id="@+id/metric_name_2"
android:text="sadness"
android:paddingTop="15dp" />
<TextView
style="@style/metricName"
android:id="@+id/metric_pct_2"
tools:text="10%" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
style="@style/metricName"
android:id="@+id/metric_name_3"
android:text="surprise" />
<TextView
style="@style/metricName"
android:id="@+id/metric_pct_3"
tools:text="10%" />
</LinearLayout>
</LinearLayout>
<TextView <TextView
style="@style/metricName" android:text="Please, show your face"
android:id="@+id/metric_name_3" />
<com.affectiva.affdexme.MetricDisplay
style="@style/metricPct"
android:id="@+id/metric_pct_3" />
</LinearLayout>
<!-- FPS Counter-->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:orientation="horizontal">
<TextView
style="@style/metricName"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:gravity="right|bottom" android:id="@+id/no_face_found"
android:layout_weight="1" android:textColor="@color/white"
android:id="@+id/fps_name" android:textSize="24sp"
android:text="@string/fps" android:textAlignment="center"
/> android:layout_centerVertical="true"
<TextView android:layout_centerHorizontal="true" />
style="@style/metricPct"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="left|bottom"
android:id="@+id/fps_value"
android:textSize="@dimen/pct_text_size"
android:textColor="@color/letter_gray"
android:layout_weight="1"
/>
</LinearLayout>
<!-- Right MetricsManager-->
<LinearLayout
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_alignParentRight="true"
android:paddingRight="@dimen/metric_panel_padding"
android:layout_height="130dp"
android:id="@+id/right_metrics">
<TextView
style="@style/metricName"
android:id="@+id/metric_name_4" />
<com.affectiva.affdexme.MetricDisplay
style="@style/metricPct"
android:id="@+id/metric_pct_4" />
<TextView
style="@style/metricName"
android:id="@+id/metric_name_5" />
<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> </RelativeLayout>

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.9 KiB

After

Width:  |  Height:  |  Size: 4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.8 KiB

After

Width:  |  Height:  |  Size: 2.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.4 KiB

After

Width:  |  Height:  |  Size: 5.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 7.7 KiB

After

Width:  |  Height:  |  Size: 9.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 14 KiB

View file

@ -12,7 +12,7 @@
<item name="android:layout_height">wrap_content</item> <item name="android:layout_height">wrap_content</item>
<item name="android:gravity">center</item> <item name="android:gravity">center</item>
<item name="android:textStyle">bold</item> <item name="android:textStyle">bold</item>
<item name="android:textColor">@color/affectiva_orange</item> <item name="android:textColor">@color/white</item>
<item name="android:shadowColor">#000000</item> <item name="android:shadowColor">#000000</item>
<item name="android:shadowDy">2</item> <item name="android:shadowDy">2</item>
<item name="android:shadowRadius">1</item> <item name="android:shadowRadius">1</item>

View file

@ -11,7 +11,7 @@
<item name="android:layout_width">fill_parent</item> <item name="android:layout_width">fill_parent</item>
<item name="android:layout_height">wrap_content</item> <item name="android:layout_height">wrap_content</item>
<item name="android:layout_gravity">center</item> <item name="android:layout_gravity">center</item>
<item name="textColor">@color/letter_gray</item> <item name="textColor">@color/white</item>
<item name="textSize">@dimen/pct_text_size</item> <item name="textSize">@dimen/pct_text_size</item>
<item name="metricBarLength">@dimen/metric_view_bar_length</item> <item name="metricBarLength">@dimen/metric_view_bar_length</item>
</style> </style>