Skip to content

Commit

Permalink
Merge pull request #390 from synaptek/ALPHA_MASK
Browse files Browse the repository at this point in the history
Added click mask for feedback tap suppression
  • Loading branch information
synaptek authored Jun 7, 2017
2 parents 8831871 + 95ef986 commit 66c3e33
Show file tree
Hide file tree
Showing 9 changed files with 165 additions and 38 deletions.
3 changes: 3 additions & 0 deletions app/src/main/assets/tutors/bubble_pop/animator_graph.json
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,7 @@
{"name": "LOG_EVENT", "type": "QUEUEDCOMMAND", "id": "SBubblePop", "method": "logState", "parms": "type#node,value#PLAYWRONG_PAUSE:String", "features":""},

{"type": "COMMAND", "id": "SBubblePop", "method": "postEvent", "parms": "PAUSE_ANIMATION:String" ,"features":""},
{"type": "COMMAND", "id": "SBubblePop", "method": "postEvent", "parms": "SHOW_MASK:String" ,"features":""},

{"type": "AUDIO", "command": "PLAY", "soundsource": "wrong.mp3", "soundpackage":"tutor_effect", "volume": 0.05, "mode":"event", "features": ""},

Expand All @@ -282,11 +283,13 @@
{"type": "AUDIO", "command": "PLAY", "soundsource": "{{SBubblePop.questValue}}.mp3", "soundpackage":"letters", "volume": 1.0, "mode":"flow", "features": "!FTR_LASTATTEMPT&FTR_LETTERS"},
{"type": "AUDIO", "command": "PLAY", "soundsource": "{{SBubblePop.questValue}}.mp3", "soundpackage":"shapes", "volume": 1.0, "mode":"flow", "features": "!FTR_LASTATTEMPT&FTR_SHAPES"},

{"type": "COMMAND", "id": "SBubblePop", "method": "postEvent", "parms": "HIDE_MASK:String" ,"features":"!FTR_LASTATTEMPT"},
{"type": "COMMAND", "id": "SBubblePop", "method": "postEvent", "parms": "RESUME_ANIMATION:String" ,"features":"!FTR_LASTATTEMPT"},

{"type": "COMMAND", "id": "SBubblePop", "method": "setVolatileBehavior", "parms": "BUBBLES_CLEARED:String|NEXTNODE:String" ,"features":"FTR_LASTATTEMPT"},
{"type": "COMMAND", "id": "SBubblePop", "method": "postEvent", "parms": "CLEAR_CONTENT:String" ,"features":"FTR_LASTATTEMPT"},
{"type": "COMMAND", "cmd": "WAIT" ,"features":"FTR_LASTATTEMPT" },
{"type": "COMMAND", "id": "SBubblePop", "method": "postEvent", "parms": "HIDE_MASK:String" ,"features":"FTR_LASTATTEMPT"},

{"type": "TIMER", "id":"nextDelayTimer", "startdelay":"0", "period":"750", "repeat":"false", "action":"CREATEANDSTART", "ontimer":"NEXTNODE", "features": "" },
{"type": "COMMAND", "cmd": "WAIT" }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
package cmu.xprize.robotutor.tutorengine.widgets.core;

import android.content.Context;
import android.content.Intent;
import android.graphics.PointF;
import android.util.AttributeSet;
import android.util.Log;

Expand All @@ -35,6 +37,7 @@
import cmu.xprize.bp_component.CBP_Component;
import cmu.xprize.bp_component.CBp_Data;
import cmu.xprize.bp_component.CBubble;
import cmu.xprize.comp_clickmask.CM_CONST;
import cmu.xprize.comp_logging.ITutorLogger;
import cmu.xprize.robotutor.RoboTutor;
import cmu.xprize.robotutor.tutorengine.CMediaController;
Expand All @@ -59,6 +62,16 @@
import cmu.xprize.util.JSON_Helper;
import cmu.xprize.util.TCONST;

import static cmu.xprize.comp_clickmask.CM_CONST.EXCLUDE_CIRCLE;
import static cmu.xprize.comp_clickmask.CM_CONST.MASK_ADDEXCL;
import static cmu.xprize.comp_clickmask.CM_CONST.MASK_ALPHA;
import static cmu.xprize.comp_clickmask.CM_CONST.MASK_CLREXCL;
import static cmu.xprize.comp_clickmask.CM_CONST.MASK_R;
import static cmu.xprize.comp_clickmask.CM_CONST.MASK_SETALPHA;
import static cmu.xprize.comp_clickmask.CM_CONST.MASK_SHOWHIDE;
import static cmu.xprize.comp_clickmask.CM_CONST.MASK_TYPE;
import static cmu.xprize.comp_clickmask.CM_CONST.MASK_X;
import static cmu.xprize.comp_clickmask.CM_CONST.MASK_Y;
import static cmu.xprize.util.TCONST.QGRAPH_MSG;
import static cmu.xprize.util.TCONST.TUTOR_STATE_MSG;

Expand Down Expand Up @@ -255,6 +268,71 @@ public void setButtonBehavior(String command) {
}


/**
* Broadcast bubble exclusion and mask the screen during feedback
*
*/
public void maskBubble() {

int[] screenCoord = new int[2];
PointF centerPoint = _touchedBubble.getCenterPosition();

getLocationOnScreen(screenCoord);

PointF centerPt = new PointF(screenCoord[0] + centerPoint.x, screenCoord[1] + centerPoint.y);

PointF center = Scontent.localToGlobal(centerPt);


// Add an exclusion around the bubble the (incorrect) user tapped
//
Intent msg = new Intent(MASK_ADDEXCL);

msg.putExtra(MASK_TYPE, EXCLUDE_CIRCLE);
msg.putExtra(MASK_X, (int)center.x);
msg.putExtra(MASK_Y, (int)center.y);
msg.putExtra(MASK_R, (int)(_touchedBubble.getScaledWidth()/2.0 * 1.15));

bManager.sendBroadcast(msg);


// Set the mask transparency
//
msg = new Intent(MASK_SETALPHA);
msg.putExtra(MASK_ALPHA, mask_alpha);

bManager.sendBroadcast(msg);


// Show the mask while the feedback is in progress
//
msg = new Intent(MASK_SHOWHIDE);
msg.putExtra(MASK_SHOWHIDE, true);

bManager.sendBroadcast(msg);
}


/**
* Clear the feedback mask
*/
public void clearMask() {

Intent msg = new Intent(MASK_CLREXCL);
bManager.sendBroadcast(msg);

// Hide the mask
//
msg = new Intent(MASK_SHOWHIDE);
msg.putExtra(MASK_SHOWHIDE, false);

bManager.sendBroadcast(msg);
}





//**********************************************************
//**********************************************************
//***************** Scripting Interface
Expand All @@ -265,13 +343,25 @@ public void postEvent(String event) {
switch (event) {

case BP_CONST.PAUSE_ANIMATION:

post(BP_CONST.PAUSE_ANIMATION);
break;

case BP_CONST.RESUME_ANIMATION:

post(BP_CONST.RESUME_ANIMATION);
break;

case BP_CONST.SHOW_MASK:

maskBubble();
break;

case BP_CONST.HIDE_MASK:

clearMask();
break;

case BP_CONST.SHOW_SCORE:
post(BP_CONST.SHOW_SCORE, new Integer(correct_Count));
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,9 @@ public class BP_CONST {
public static final String QUEST_VAR = ".questValue";
public static final String ANSWER_VAR = ".ansValue";

public static final String SHOW_MASK = "SHOW_MASK";
public static final String HIDE_MASK = "HIDE_MASK";


static public HashMap<String, Integer> bubbleMap = new HashMap<String, Integer>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import android.graphics.Canvas;
import android.os.Handler;
import android.os.Looper;
import android.support.v4.content.LocalBroadcastManager;
import android.util.AttributeSet;
import android.util.Log;
import android.widget.FrameLayout;
Expand Down Expand Up @@ -77,6 +78,9 @@ public class CBP_Component extends FrameLayout implements IEventDispatcher, ILoa
private HashMap queueMap = new HashMap();
private boolean _qDisabled = false;

protected LocalBroadcastManager bManager;


// Working data sets
public ArrayList<String> wrk_responseSet = null; // set of response tems
public ArrayList<String> wrk_respTypeSet = null; // text/reference - for mixed response sets
Expand All @@ -91,7 +95,6 @@ public class CBP_Component extends FrameLayout implements IEventDispatcher, ILoa
public ArrayList<String[]> wrk_stimulus_script = null; // List of uttereances describing each question



// Note: Having independent response sets and answer sets means that the response sets are not limited to the
// set of answers to questions.
//
Expand Down Expand Up @@ -122,6 +125,7 @@ public class CBP_Component extends FrameLayout implements IEventDispatcher, ILoa

public CBpBackground view_background = null; // Set specific background
public String banner_color = null; // Set specific banner color
public int mask_alpha = 205; // Mask alpha


static final String TAG = "CBP_Component";
Expand Down Expand Up @@ -179,6 +183,10 @@ public void init(Context context, AttributeSet attrs) {
//
Scontent = (CBP_LetterBoxLayout) findViewById(R.id.Scontent);

// Capture the local broadcast manager
//
bManager = LocalBroadcastManager.getInstance(mContext);

// Allow onDraw to be called to start animations
//
setWillNotDraw(false);
Expand Down
19 changes: 17 additions & 2 deletions comp_bubblepop/src/main/java/cmu/xprize/bp_component/CBubble.java
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,15 @@ public void setScale(float newScale) {
setScaleY(mScale);
}

public float getScaledWidth() {
return getWidth() * mScale;
}

public float getScaledHeight() {
return getHeight() * mScale;
}


@Override
public void setScaleX(float newScale) {
super.setScaleX(newScale * mScaleCorrection);
Expand Down Expand Up @@ -276,8 +285,14 @@ public void setCenterPosition(int x, int y) {
public PointF getCenterPosition() {
PointF nPosition = new PointF();

nPosition.x = getX() + (getWidth() / 2);
nPosition.y = getY() + (getHeight() / 2);
nPosition.x = getX();
nPosition.y = getY();

float w = (getWidth() / 2);
float h = (getHeight() / 2);

nPosition.x += w;
nPosition.y += h;

return nPosition;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,24 +53,22 @@ public class CClickMask extends View implements View.OnTouchListener {
private Path mask;
private RectF border = new RectF();
private ArrayList<CExclusion> exclusions;
private int[] _screenCoord = new int[2];

private LocalBroadcastManager bManager;
private ChangeReceiver bReceiver;


public CClickMask(Context context) {
super(context);
init(context, null);
}

public CClickMask(Context context, @Nullable AttributeSet attrs) {
super(context, attrs);
init(context, attrs);
}

public CClickMask(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
init(context, attrs);
}

protected void init(Context context, AttributeSet attrs) {
Expand All @@ -87,10 +85,10 @@ protected void init(Context context, AttributeSet attrs) {
// Capture the local broadcast manager
bManager = LocalBroadcastManager.getInstance(getContext());

IntentFilter filter = new IntentFilter(TCONST.MASK_SHOWHIDE);
filter.addAction(TCONST.MASK_ADDEXCL);
filter.addAction(TCONST.MASK_CLREXCL);
filter.addAction(TCONST.MASK_SETALPHA);
IntentFilter filter = new IntentFilter(MASK_SHOWHIDE);
filter.addAction(MASK_ADDEXCL);
filter.addAction(MASK_CLREXCL);
filter.addAction(MASK_SETALPHA);

bReceiver = new ChangeReceiver();

Expand All @@ -115,6 +113,9 @@ public void setMaskColor(int newColor) {

public void setMaskAlpha(int _alpha) {

if(_alpha > 255) _alpha = 255;
if(_alpha < 0) _alpha = 0;

mPaint.setAlpha(_alpha);
}

Expand All @@ -135,43 +136,48 @@ class ChangeReceiver extends BroadcastReceiver {

public void onReceive (Context context, Intent intent) {

float[] point = intent.getFloatArrayExtra(TCONST.SCREENPOINT);

switch(intent.getAction()) {
case TCONST.MASK_SHOWHIDE:
Boolean showmask = intent.getBooleanExtra(TCONST.MASK_SHOWHIDE, false);
case MASK_SHOWHIDE:
Boolean showmask = intent.getBooleanExtra(MASK_SHOWHIDE, false);

showHide(showmask);
break;

case TCONST.MASK_ADDEXCL:
String exclusiontype = intent.getStringExtra(TCONST.MASK_TYPE);
case MASK_ADDEXCL:
String exclusiontype = intent.getStringExtra(MASK_TYPE);

switch(exclusiontype) {
case EXCLUDE_CIRCLE:
int exclusionx = intent.getIntExtra(TCONST.MASK_X, 0);
int exclusiony = intent.getIntExtra(TCONST.MASK_Y, 0);
int exclusionr = intent.getIntExtra(TCONST.MASK_R, 0);
int exclusionx = intent.getIntExtra(MASK_X, 0);
int exclusiony = intent.getIntExtra(MASK_Y, 0);
int exclusionr = intent.getIntExtra(MASK_R, 0);

// Translate to local coordinate space - i.e. relative to view
//
getLocationOnScreen(_screenCoord);

exclusionx -= _screenCoord[0];
exclusiony -= _screenCoord[1];

addExclusion(new CExclusion(exclusiontype, exclusionx, exclusiony, exclusionr));
break;
}
break;

case TCONST.MASK_CLREXCL:
case MASK_CLREXCL:
clearExclusions();
break;

case TCONST.MASK_SETCOLOR:
int maskColor = intent.getIntExtra(TCONST.MASK_COLOR, 0);
case MASK_SETCOLOR:
int maskColor = intent.getIntExtra(MASK_COLOR, 0);

setMaskColor(maskColor);
break;

case TCONST.MASK_SETALPHA:
int maskAlpha = intent.getIntExtra(TCONST.MASK_ALPHA, 128);
case MASK_SETALPHA:
int maskAlpha = intent.getIntExtra(MASK_ALPHA, 128);

setMaskColor(maskAlpha);
setMaskAlpha(maskAlpha);
break;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,17 @@

public class CM_CONST {

public static final String MASK_SHOWHIDE = "MASK_SHOWHIDE";
public static final String MASK_ADDEXCL = "MASK_ADDEXCL";
public static final String MASK_CLREXCL = "MASK_CLREXCL";
public static final String MASK_SETCOLOR = "MASK_SETCOLOR";
public static final String MASK_SETALPHA = "MASK_SETALPHA";
public static final String MASK_TYPE = "MASK_TYPE";
public static final String MASK_X = "MASK_X";
public static final String MASK_Y = "MASK_Y";
public static final String MASK_R = "MASK_R";
public static final String MASK_COLOR = "MASK_COLOR";
public static final String MASK_ALPHA = "MASK_ALPHA";

public static final String EXCLUDE_CIRCLE = "EXCLUDE_CIRCLE";
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@
package cmu.xprize.comp_clickmask;


import android.graphics.PointF;

public interface IMaskOwner {

public void setMasked(boolean _mask);

}
}
Loading

0 comments on commit 66c3e33

Please sign in to comment.