diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 6a30b6b..03b6a6a 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -13,7 +13,8 @@ android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:supportsRtl="true" - android:theme="@style/AppTheme"> + android:theme="@style/AppTheme" + android:hardwareAccelerated="true"> getTargets() { + return targets; + } - float sec_height = canvas.getHeight() * (float) 0.2; // each second is 20% of canvas height - float diff_y; + /** + * Get the time within the scenario (so since start() has been called) + */ + public float getTime() { // if not started, don't move the labels, if started, move them by diff_y if(startTime == 0) { - diff_y = 0; - start(); + return 0; } else { float diff_t = ((System.currentTimeMillis() - startTime)) / (float) 1000; - Log.d("TIME", Float.toString(diff_t)); if(diff_t > duration) { // never larger than scenario duration - diff_t = duration; + return duration; } - diff_y = sec_height * diff_t; + return diff_t; } - -// bottom at 80%; - float bottomline_height = height * (float) 0.8; - - canvas.drawLine(0, bottomline_height, canvas.getWidth(), bottomline_height, paint); - canvas.drawLine(0, bottomline_height+1, canvas.getWidth(), bottomline_height+1, paint); - - for(Target target: targets) { - float y_pos = bottomline_height - (target.timestamp * sec_height); - String target_text = target.emotion.toString() + " " + target.value + "%"; - canvas.drawText(target_text, canvas.getWidth()/2, y_pos + diff_y , paint); - - } - } public void start() @@ -169,6 +152,8 @@ abstract public class Scenario { startTime = System.currentTimeMillis(); } + // TODO: create a 'tick' that checks all current values with requirements and increases the timer etc + // TODO: ... if scenario is running. This internal times makes it easier to pause etc. } class ScenarioAnger extends Scenario{ @@ -180,5 +165,9 @@ class ScenarioAnger extends Scenario{ setTarget(Emotion.ANGER, 40, 3); setTarget(Emotion.ANGER, 70, 4); setTarget(Emotion.ANGER, 100, 5); + setTarget(Emotion.JOY, 100, 8); + setTarget(Emotion.ANGER, 100, 10); + setTarget(Emotion.JOY, 100, 15); + setTarget(Emotion.ANGER, 100, 20); } } \ No newline at end of file diff --git a/app/src/main/java/com/rubenvandeven/emotionhero/ScenarioView.java b/app/src/main/java/com/rubenvandeven/emotionhero/ScenarioView.java index 7448bc5..b3ac382 100644 --- a/app/src/main/java/com/rubenvandeven/emotionhero/ScenarioView.java +++ b/app/src/main/java/com/rubenvandeven/emotionhero/ScenarioView.java @@ -2,13 +2,20 @@ package com.rubenvandeven.emotionhero; import android.content.Context; import android.graphics.Canvas; +import android.graphics.Color; import android.graphics.Paint; +import android.graphics.Path; import android.graphics.PixelFormat; import android.util.AttributeSet; import android.util.Log; import android.view.SurfaceHolder; import android.view.SurfaceView; +import com.affectiva.android.affdex.sdk.detector.Face; + +import java.util.HashMap; +import java.util.Map; + /** * Created by ruben on 16/08/16. */ @@ -19,6 +26,12 @@ public class ScenarioView extends SurfaceView implements SurfaceHolder.Callback private Scenario _scenario; + /** + * The scorres in this moment, as to draw them on the screen. + * Indexes are Emotion ordinals + */ + private Map currentAttributeScores = new HashMap<>(); + // see: http://blog.danielnadeau.io/2012/01/android-canvas-beginners-tutorial.html class PanelThread extends Thread { @@ -69,15 +82,92 @@ public class ScenarioView extends SurfaceView implements SurfaceHolder.Callback @Override public void onDraw(Canvas canvas) { //do drawing stuff here. -// Log.e("TEST2", "Jaa!"); - _scenario.drawOnCanvas(canvas); + + float height = canvas.getHeight(); + float width = canvas.getWidth(); + + // bottom at 80%; + float bottomline_height = height * (float) 0.8; + + + // draw current scores: + float used_width = (float) 0.8; // 0.7: only use center + float padding_left = canvas.getWidth() * (1-used_width) / 2; + float step_y = (canvas.getWidth() * used_width) / Emotion.values().length; + float max_ball_radius = step_y * (float) 0.8 / 2; + + +// bottom at 80%; + Paint mainPaint = new Paint(); + mainPaint.setColor(Color.GRAY); + + + Paint linePaint = new Paint(); + linePaint.setColor(Color.GRAY); + linePaint.setStrokeWidth(5); +// canvas.drawLine(0, bottomline_height, width, bottomline_height, linePaint); + + for(Emotion emotion: Emotion.values()) + { + float value = 0; + if(currentAttributeScores.containsKey(emotion)) { + value = currentAttributeScores.get(emotion); + } + if(value < 5) { + value = 5; + } + Paint emoPaint = new Paint(); + Paint emoPaintOutline = new Paint(); + emoPaint.setColor(emotion.getColor()); + emoPaintOutline.setColor(emotion.getColor()); + emoPaintOutline.setStyle(Paint.Style.STROKE); + emoPaintOutline.setStrokeWidth(2); + + float cx = padding_left + (step_y * emotion.ordinal() + step_y / 2); + float cy = bottomline_height; + + + canvas.drawCircle(cx, cy, max_ball_radius, mainPaint); + canvas.drawCircle(cx, cy, max_ball_radius, emoPaintOutline); + + canvas.drawCircle(cx, cy, max_ball_radius * value/100, emoPaint); + + + canvas.drawText(emotion.toString(), cx, cy + max_ball_radius * (float) 1.3, emoPaint); + } + + // Draw targets: + float sec_height = height * (float) 0.2; // each second is 20% of canvas height + // current moved position + float diff_y = sec_height * _scenario.getTime(); + + for(Scenario.Target target: _scenario.getTargets()) { + Paint emoPaint = new Paint(); + emoPaint.setColor(target.emotion.getColor()); + + float cy = bottomline_height - (target.timestamp * sec_height) + diff_y; + + float cx = padding_left + (step_y * target.emotion.ordinal() + step_y / 2); + + canvas.drawCircle(cx, cy, max_ball_radius * target.value/100, emoPaint); + +// String target_text = target.emotion.toString() + " " + target.value + "%"; +// canvas.drawText(target_text, cx, y_pos + diff_y , emoPaint); + } + + } + + public void setCurrentAttributeScoresForFace(Face face) + { + for(Emotion emotion: Emotion.values()) { + currentAttributeScores.put(emotion, emotion.getValueFromFace(face)); + } } @Override public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) { - } @Override @@ -105,6 +195,4 @@ public class ScenarioView extends SurfaceView implements SurfaceHolder.Callback } - } - diff --git a/app/src/main/res/layout/activity_gaming.xml b/app/src/main/res/layout/activity_gaming.xml index 42f8651..15eb326 100644 --- a/app/src/main/res/layout/activity_gaming.xml +++ b/app/src/main/res/layout/activity_gaming.xml @@ -37,6 +37,16 @@ + + + + + + + + + + - +