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:configChanges="screenSize|keyboardHidden|orientation"
android:label="@string/app_name"
android:screenOrientation="landscape"
android:theme="@style/MainActivityTheme">
<intent-filter>
<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 LinearLayout leftMetricsLayout;
private LinearLayout rightMetricsLayout;
private MetricDisplay[] metricDisplays;
private TextView[] metricDisplays;
private TextView[] metricNames;
private TextView fpsName;
private TextView fpsPct;
@ -129,6 +129,7 @@ public class MainActivity extends AppCompatActivity
private boolean isFrontFacingCameraDetected = true;
private boolean isBackFacingCameraDetected = true;
private boolean multiFaceModeEnabled = false;
private TextView showFaceText;
private MediaPlayer mp;
@ -356,8 +357,8 @@ public class MainActivity extends AppCompatActivity
leftMetricsLayout = (LinearLayout) findViewById(R.id.left_metrics);
rightMetricsLayout = (LinearLayout) findViewById(R.id.right_metrics);
mainLayout = (RelativeLayout) findViewById(R.id.main_layout);
fpsPct = (TextView) findViewById(R.id.fps_value);
fpsName = (TextView) findViewById(R.id.fps_name);
// fpsPct = (TextView) findViewById(R.id.fps_value);
// fpsName = (TextView) findViewById(R.id.fps_name);
cameraView = (SurfaceView) findViewById(R.id.camera_preview);
drawingView = (DrawingView) findViewById(R.id.drawing_view);
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[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);
metricDisplays[2] = (MetricDisplay) findViewById(R.id.metric_pct_2);
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);
metricDisplays = new TextView[NUM_METRICS_DISPLAYED];
metricDisplays[0] = (TextView) findViewById(R.id.metric_pct_0);
metricDisplays[1] = (TextView) findViewById(R.id.metric_pct_1);
metricDisplays[2] = (TextView) findViewById(R.id.metric_pct_2);
metricDisplays[3] = (TextView) findViewById(R.id.metric_pct_3);
metricDisplays[4] = (TextView) findViewById(R.id.metric_pct_4);
metricDisplays[5] = (TextView) findViewById(R.id.metric_pct_5);
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
Typeface face = Typeface.createFromAsset(getAssets(), "fonts/Square.ttf");
for (TextView textView : metricNames) {
textView.setTypeface(face);
}
for (MetricDisplay metricDisplay : metricDisplays) {
metricDisplay.setTypeface(face);
}
fpsPct.setTypeface(face);
fpsName.setTypeface(face);
// for (TextView textView : metricNames) {
// textView.setTypeface(face);
// }
// for (TextView metricDisplay : metricDisplays) {
// metricDisplay.setTypeface(face);
// }
// fpsPct.setTypeface(face);
// fpsName.setTypeface(face);
drawingView.setTypeface(face);
pleaseWaitTextView.setTypeface(face);
@ -515,18 +517,18 @@ public class MainActivity extends AppCompatActivity
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++;
}
// 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
if (multiFaceModeEnabled) {
detector.setDetectAllEmotions(true);
}
// if (multiFaceModeEnabled) {
// 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
try {
metricNames[index].setText(MetricsManager.getUpperCaseName(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);
}
// 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);
}
metricDisplays[index].setMetricToDisplay(metric, getFaceScoreMethod);
// metricDisplays[index].setMetricToDisplay(metric, getFaceScoreMethod);
}
/**
@ -617,7 +619,7 @@ public class MainActivity extends AppCompatActivity
if (!isBackFacingCameraDetected && !isFrontFacingCameraDetected)
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()) {
try {
detector.start();
@ -632,6 +634,8 @@ public class MainActivity extends AppCompatActivity
leftMetricsLayout.animate().alpha(1); //make left and right metrics appear
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.
if(mp != null && !mp.isPlaying()) {
@ -641,6 +645,7 @@ public class MainActivity extends AppCompatActivity
@Override
public void onFaceDetectionStopped() {
showFaceText.setVisibility(View.VISIBLE);
performFaceDetectionStoppedTasks();
}
@ -670,10 +675,36 @@ public class MainActivity extends AppCompatActivity
drawingView.invalidatePoints();
} else if (faces.size() == 1) {
metricViewLayout.setVisibility(View.VISIBLE);
//update metrics with latest face information. The metrics are displayed on a MetricView, a custom view with a .setScore() method.
for (MetricDisplay metricDisplay : metricDisplays) {
updateMetricScore(metricDisplay, faces.get(0));
int i = 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.
*/
void performFPSCalculations() {
numberOfFrames += 1;
long currentTime = SystemClock.elapsedRealtime();
if (currentTime > timeToUpdate) {
float framesPerSecond = (numberOfFrames / (float) (currentTime - firstSystemTime)) * 1000f;
fpsPct.setText(String.format(" %.1f", framesPerSecond));
timeToUpdate = currentTime + 1000L;
}
return;
// numberOfFrames += 1;
// long currentTime = SystemClock.elapsedRealtime();
// if (currentTime > timeToUpdate) {
// float framesPerSecond = (numberOfFrames / (float) (currentTime - firstSystemTime)) * 1000f;
// fpsPct.setText(String.format(" %.1f", framesPerSecond));
// timeToUpdate = currentTime + 1000L;
// }
}
/**
@ -915,14 +947,15 @@ public class MainActivity extends AppCompatActivity
void setFPSVisible(boolean b) {
isFPSVisible = b;
if (b) {
fpsName.setVisibility(View.VISIBLE);
fpsPct.setVisibility(View.VISIBLE);
} else {
fpsName.setVisibility(View.INVISIBLE);
fpsPct.setVisibility(View.INVISIBLE);
}
return;
// isFPSVisible = b;
// if (b) {
// fpsName.setVisibility(View.VISIBLE);
// fpsPct.setVisibility(View.VISIBLE);
// } else {
// fpsName.setVisibility(View.INVISIBLE);
// fpsPct.setVisibility(View.INVISIBLE);
// }
}
@Override

View file

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

View file

@ -1,8 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="horizontal"
android:layout_height="170dp"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
@ -12,91 +13,141 @@
android:layout_gravity="center_vertical">
<!-- Logo-->
<!-- Left MetricsManager-->
<!-- FPS Counter-->
<!-- Right MetricsManager-->
<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: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_width="wrap_content"
android:layout_height="match_parent"
android:id="@+id/left_metrics">
android:layout_alignParentStart="true">
<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_0"
/>
<com.affectiva.affdexme.MetricDisplay
style="@style/metricPct"
android:id="@+id/metric_pct_0" />
android:text="fear"/>
<TextView
style="@style/metricName"
android:id="@+id/metric_name_1" />
<com.affectiva.affdexme.MetricDisplay
style="@style/metricPct"
android:id="@+id/metric_pct_1" />
android:id="@+id/metric_pct_0"
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" />
<com.affectiva.affdexme.MetricDisplay
style="@style/metricPct"
android:id="@+id/metric_pct_2" />
android:id="@+id/metric_name_1"
android:text="joy"
android:paddingTop="15dp"/>
<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
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
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:orientation="horizontal">
<TextView
style="@style/metricName"
android:text="Please, show your face"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="right|bottom"
android:layout_weight="1"
android:id="@+id/fps_name"
android:text="@string/fps"
/>
<TextView
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>
android:id="@+id/no_face_found"
android:textColor="@color/white"
android:textSize="24sp"
android:textAlignment="center"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true" />
</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:gravity">center</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:shadowDy">2</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_height">wrap_content</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="metricBarLength">@dimen/metric_view_bar_length</item>
</style>