Skip to content

Commit

Permalink
MATH: can animate all units at once; changed text color.
Browse files Browse the repository at this point in the history
  • Loading branch information
kevindeland committed Sep 12, 2018
1 parent 7795bba commit 4fd2bae
Show file tree
Hide file tree
Showing 8 changed files with 76 additions and 95 deletions.
1 change: 1 addition & 0 deletions app/src/main/assets/tutors/bigmath/animator_graph.json
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,7 @@
"COMMENT": "???",
"tracks": [
{"name": "LOG_EVENT", "type": "QUEUEDCOMMAND", "id": "SBigMath", "method": "logState", "parms": "type#node,value#PROBLEMCORRECT:String", "features":""},
{"name": "LOG_EVENT", "type": "QUEUEDCOMMAND", "id": "SBigMath", "method": "highlightAll", "features":""},

{"type": "AUDIO", "command": "PLAY", "soundsource": "Good.mp3", "soundpackage":"temp", "volume": 1.0, "mode":"flow", "features": ""}
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,17 @@

"dataSource": [

{"type": "CBigMath_Data", "level": "demo", "task": "Count up by 1", "dataset": [18, 13, 31], "operation": "+"},
{"type": "CBigMath_Data", "level": "demo", "task": "Count up by 1", "dataset": [14,1,15], "operation": "+"},

{"type": "CBigMath_Data", "level": "demo", "task": "Count up by 1", "dataset": [38, 43, 81], "operation": "+"},

{"type": "CBigMath_Data", "level": "demo", "task": "Count up by 1", "dataset": [28, 14, 42], "operation": "+"},
{"type": "CBigMath_Data", "level": "demo", "task": "Count up by 1", "dataset": [48, 24, 72], "operation": "+"},

{"type": "CBigMath_Data", "level": "demo", "task": "Count up by 1", "dataset": [29, 27, 56], "operation": "+"},

{"type": "CBigMath_Data", "level": "demo", "task": "Count up by 1", "dataset": [19, 27, 46], "operation": "+"},

{"type": "CBigMath_Data", "level": "demo", "task": "Count up by 1", "dataset": [14,1,15], "operation": "+"},


{"type": "CBigMath_Data", "level": "demo", "task": "Count up by 1", "dataset": [15,1,16], "operation": "+"},

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,5 +62,6 @@ public enum ACTION_MAP {
SET_VERSION, SET_DATASOURCE, NEXTNODE, NEXTSCENE
}


// various variables
static final int WATERFALL_DELAY = 100;
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.drawable.Drawable;
import android.os.Handler;
import android.os.Looper;
import android.support.annotation.Nullable;
import android.util.Log;
import android.view.View;
Expand All @@ -32,6 +34,7 @@
import static cmu.xprize.comp_bigmath.BM_CONST.RESULT_LOCATION;
import static cmu.xprize.comp_bigmath.BM_CONST.TEN_CARRY_DIGIT;
import static cmu.xprize.comp_bigmath.BM_CONST.TEN_DIGIT;
import static cmu.xprize.comp_bigmath.BM_CONST.WATERFALL_DELAY;
import static cmu.xprize.util.MathUtil.getHunsDigit;
import static cmu.xprize.util.MathUtil.getOnesDigit;
import static cmu.xprize.util.MathUtil.getTensDigit;
Expand Down Expand Up @@ -61,7 +64,8 @@ public class BigMathMechanic {
private int _numDigits;

//
boolean EXPAND_HIT_BOX = false; // MATH_FEEDBACK (9) tap within the containing box to add/subtract. Do not tap units. // MATH_TODO fix
private boolean EXPAND_HIT_BOX = true; // MATH_FEEDBACK (9) tap within the containing box to add/subtract. Do not tap units. // MATH_TODO fix
private boolean ALL_AT_ONCE = true; // MATH_FEEDBACK (9) whether to animate all dots at once

// used to track UI state
private int currentOpAHun;
Expand Down Expand Up @@ -207,6 +211,7 @@ private void initializeLayout() {
/**
* Initialize the OnClick performance of the Views
* TODO these could be significantly refactored
* MATH_FEEDBACK (9) should be dependent on EXPAND_HIT_BOX and ALL_AT_ONCE
*/
private void initializeOnClickListeners() {

Expand All @@ -219,34 +224,34 @@ private void initializeOnClickListeners() {
for (int i=1; i <= 10; i++) {

MovableImageView oneView = _layout.getBaseTenConcreteUnitView(numLoc, ONE_DIGIT, i);
oneView.setOnClickListener(new BaseTenOnClickAnimateMe(ONE_DIGIT)); // MATH_FEEDBACK (9) should animate everything instead
oneView.setOnClickListener(ALL_AT_ONCE ? new BaseTenOnClickAnimateWaterfall(numLoc, ONE_DIGIT) : new BaseTenOnClickAnimateMe(ONE_DIGIT)); // MATH_FEEDBACK √√√ (9) should animate everything instead
}

// add listeners to Tens
if (_numDigits >= 2)
for (int i=1; i <= 10; i++) {

MovableImageView tenView = _layout.getBaseTenConcreteUnitView(numLoc, TEN_DIGIT, i);
tenView.setOnClickListener(new BaseTenOnClickAnimateMe(TEN_DIGIT)); // MATH_FEEDBACK (9) should animate everything instead
tenView.setOnClickListener(ALL_AT_ONCE ? new BaseTenOnClickAnimateWaterfall(numLoc, TEN_DIGIT) : new BaseTenOnClickAnimateMe(TEN_DIGIT)); // MATH_FEEDBACK √√√ (9) should animate everything instead
}

// add listeners to Hundreds
if (_numDigits >=3)
for (int i=1; i <= 5; i++) {

MovableImageView hunView = _layout.getBaseTenConcreteUnitView(numLoc, HUN_DIGIT, i);
hunView.setOnClickListener(new BaseTenOnClickAnimateMe(HUN_DIGIT)); // MATH_FEEDBACK (9) should animate everything instead
hunView.setOnClickListener(ALL_AT_ONCE ? new BaseTenOnClickAnimateWaterfall(numLoc, HUN_DIGIT) : new BaseTenOnClickAnimateMe(HUN_DIGIT)); // MATH_FEEDBACK √√√ (9) should animate everything instead
}


// PART 2 (BOX) for (one, ten, hun) will move sequential ones. These may or may not (but probably will) be used.
_layout.getContainingBox(numLoc, ONE_DIGIT).setOnClickListener(new BaseTenOnClickAnimateSequential(ONE_DIGIT));
_layout.getContainingBox(numLoc, ONE_DIGIT).setOnClickListener(ALL_AT_ONCE ? new BaseTenOnClickAnimateWaterfall(numLoc, ONE_DIGIT) : new BaseTenOnClickAnimateSequential(ONE_DIGIT)); // MATH_FEEDBACK (9) s

if (_numDigits >= 2)
_layout.getContainingBox(numLoc, TEN_DIGIT).setOnClickListener(new BaseTenOnClickAnimateSequential(TEN_DIGIT));
_layout.getContainingBox(numLoc, TEN_DIGIT).setOnClickListener(ALL_AT_ONCE ? new BaseTenOnClickAnimateWaterfall(numLoc, TEN_DIGIT) : new BaseTenOnClickAnimateSequential(TEN_DIGIT));

if (_numDigits >= 3)
_layout.getContainingBox(numLoc, HUN_DIGIT).setOnClickListener(new BaseTenOnClickAnimateSequential(HUN_DIGIT));
_layout.getContainingBox(numLoc, HUN_DIGIT).setOnClickListener(ALL_AT_ONCE ? new BaseTenOnClickAnimateWaterfall(numLoc, HUN_DIGIT) : new BaseTenOnClickAnimateSequential(HUN_DIGIT));

}

Expand Down Expand Up @@ -360,6 +365,7 @@ public void onClick(View v) {

/**
* Click Listener that moves next available View to next available space.
* MATH_FEEDBACK (9) make a new one that does everything at once
*/
class BaseTenOnClickAnimateSequential implements View.OnClickListener {

Expand All @@ -374,6 +380,22 @@ public void onClick(View v) {
}
}

class BaseTenOnClickAnimateWaterfall implements View.OnClickListener {

private final String _numLoc;
private final String _digit;

public BaseTenOnClickAnimateWaterfall(String _numLoc, String _digit) {
this._numLoc = _numLoc;
this._digit = _digit;
}

@Override
public void onClick(View view) {
waterfall(_numLoc, _digit);
}
}

/**
* Define and initialize the WriteBox inputs.
*/
Expand Down Expand Up @@ -605,7 +627,6 @@ public void onClick(View v) {
if (_numDigits >= 1) ((TextView) findViewById(R.id.symbol_opA_one)).setText(digitsInOpA >= 1 ? String.valueOf(currentOpAOne) : "");

int digitsInOpB = String.valueOf(_data.dataset[1]).length();
Log.wtf("IAMTIRED", "opB=" + _data.dataset[1] + " numDigits=" + digitsInOpB);
if (_numDigits >= 3) ((TextView) findViewById(R.id.symbol_opB_hun)).setText(digitsInOpB >= 3 ? String.valueOf(currentOpBHun): "");
if (_numDigits >= 2) ((TextView) findViewById(R.id.symbol_opB_ten)).setText(digitsInOpB >= 2 ? String.valueOf(currentOpBTen): "");
if (_numDigits >= 1) ((TextView) findViewById(R.id.symbol_opB_one)).setText(digitsInOpB >= 1 ? String.valueOf(currentOpBOne): "");
Expand Down Expand Up @@ -812,6 +833,7 @@ public void highlightDigitColumn(String digit) {
}

_layout.getBaseTenDigitView(numberLoc, column).setAlpha(floatPacity);
_layout.getBaseTenDigitView(numberLoc, column).setTextColor(Color.BLACK); // idk why it's not already black? (see "addSubtractDigitColor" in colors.xml...)
}

}
Expand Down Expand Up @@ -864,7 +886,7 @@ public void disableConcreteUnitTappingForOtherRows(String digit) {
public void animateMe(String digit, MovableImageView v) {

Log.wtf("YELLOW", "y u no move?");
if (EXPAND_HIT_BOX) return;
if (EXPAND_HIT_BOX) return; // MATH_FEEDBACK (9) might be redundant?

Log.wtf("YELLOW", "y u no move?");
if (v.isMoving || !v.isMovable) return;
Expand All @@ -887,12 +909,29 @@ public void animateMe(String digit, MovableImageView v) {
*/
public void animateNextSequential(String digit, View v) {

if (!EXPAND_HIT_BOX) return;
if (!EXPAND_HIT_BOX) return; // MATH_FEEDBACK (9) might be redundant?

String numberLoc = v.getTag().toString();
moveSequential(numberLoc, digit);
}


/**
* this animation is lit
* @param digit
*/
private void waterfall(final String numLoc, final String digit) {

// try this???
for (int i = 0; i < getOnesDigit(_data.dataset[0]); i++)
(new Handler(Looper.getMainLooper())).postDelayed(new Runnable() {
@Override
public void run() {
moveSequential(numLoc, digit);
}
}, WATERFALL_DELAY * i);
}

/**
*
* Move this view to the next available location in the tens column of the sum row.
Expand Down Expand Up @@ -1618,36 +1657,6 @@ private MovableImageView determineNextTopView(String numberLoc, String digit) {

/* DEBUG BUTTONS */

/**
*
* Debug button for Highlight hundreds.
*
*/
public void highlightPvHuns() {
highlightUnits(OPA_LOCATION, HUN_DIGIT, true);
highlightUnits(OPB_LOCATION, HUN_DIGIT, true);
highlightUnits(RESULT_LOCATION, HUN_DIGIT, true);
}

/**
*
*/
public void highlightPvTens() {
highlightUnits(OPA_LOCATION, TEN_DIGIT, true);
highlightUnits(OPB_LOCATION, TEN_DIGIT, true);
highlightUnits(RESULT_LOCATION, TEN_DIGIT, true);
}

/**
*
*/
public void highlightPvOnes() {
highlightUnits(OPA_LOCATION, ONE_DIGIT, true);
highlightUnits(OPB_LOCATION, ONE_DIGIT, true);
highlightUnits(RESULT_LOCATION, ONE_DIGIT, true);
}


/**
*
* Show the carry option for hundreds
Expand Down Expand Up @@ -2006,53 +2015,6 @@ public void onAnimationRepeat(Animator animation) {
animSet.start();
}

/**
* Highlight the concrete unit and digit associated with a unit.
*
* @param numberLoc location of the number e.g. top, bottom, left, or right
* @param digit one, ten, or hun
* @param suppressOthers un-highlight other digits
*/
private void highlightUnits(String numberLoc, @Nullable String digit, boolean suppressOthers) {




// cycle through each digit
String[] allDigits = {ONE_DIGIT, TEN_DIGIT, HUN_DIGIT};
for (String d : allDigits) {

// only perform highlight if it's the digit we're changing
// remove highlight if suppressOthers is true
if(d.equals(digit) || suppressOthers) {

Log.d("HIGHLIGHT", numberLoc + " " + digit);

ImageView[] ndUnits = new ImageView[d.equals(HUN_DIGIT) ? 6 : 11];
for (int i = 1; i < ndUnits.length; i++) {

ndUnits[i] = _layout.getBaseTenConcreteUnitView(numberLoc, d, i);
if (ndUnits[i].getVisibility() == View.VISIBLE) {
// either highlight or remove highlight
// just the background
// ndUnits[i].setBackgroundColor(d.equals(digit) ? getResources().getColor(R.color.bigMathHighlightColor) : Color.TRANSPARENT);
}
}


TextView ndSymbolic = _layout.getBaseTenDigitView(numberLoc, d);
// either highlight or remove highlight
ndSymbolic.setBackgroundColor(d.equals(digit) ? _activity.getResources().getColor(R.color.bigMathHighlightColor): Color.TRANSPARENT);

String boxId = d + "_" + numberLoc + "_box";
int resID = _activity.getResources().getIdentifier(boxId, "id", _activity.getPackageName());
findViewById(resID).setBackgroundColor(d.equals(digit) ? _activity.getResources().getColor(R.color.bigMathHighlightColor) : Color.TRANSPARENT);
//findViewById(resID).setBackground(getDrawable(R.drawable.inner_rectangle));
}
}

}

/**
* A helper so i don't have to rewrite all these references
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,16 @@
import java.util.HashMap;

import cmu.xprize.comp_logging.CErrorManager;
import cmu.xprize.ltkplus.CRecognizerPlus;
import cmu.xprize.ltkplus.GCONST;
import cmu.xprize.util.IBehaviorManager;
import cmu.xprize.util.ILoadableObject;
import cmu.xprize.util.IPublisher;
import cmu.xprize.util.IScope;
import cmu.xprize.util.JSON_Helper;
import cmu.xprize.util.TCONST;

import static cmu.xprize.comp_bigmath.BM_CONST.ALL_DIGITS;
import static cmu.xprize.comp_bigmath.BM_CONST.HUN_DIGIT;

/**
Expand Down Expand Up @@ -93,6 +96,9 @@ protected void init(Context context, AttributeSet attrs) {

mContext = context;

// force write input to a digit
CRecognizerPlus.getInstance().setClassBoost(GCONST.FORCE_DIGIT);

// inflate(getContext(), R.layout.bigmath_layout, this);

Scontent = (RelativeLayout) findViewById(R.id.Scontent);
Expand Down Expand Up @@ -159,6 +165,13 @@ public void nextDigit() {

}

/**
* highlight all digits!
*/
public void highlightAll() {
_mechanic.highlightDigitColumn(ALL_DIGITS);
}

/**
* Point at a view
*/
Expand Down
4 changes: 2 additions & 2 deletions comp_bigmath/src/main/res/layout/bigmath_2d.xml
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,7 @@
android:layout_width="@dimen/add_subtract_digit_width"
android:layout_height="fill_parent"
android:text="@string/operator_placeholder"
android:textColor="@color/addSubtractDigitColor"
android:textColor="@android:color/black"
android:textSize="@dimen/add_subtract_digit_size"
android:gravity="center"
/>
Expand Down Expand Up @@ -612,7 +612,7 @@
app:layout_constraintTop_toBottomOf="@id/guideline_top_of_bottom"
app:layout_constraintLeft_toLeftOf="@id/guideline_vertical_0"
app:layout_constraintRight_toRightOf="@id/guideline_vertical_1"
android:background="@color/addSubtractDigitColor"/>
android:background="@android:color/black"/>

<!-- Third Row, result (sum or difference) -->
<!-- an all-encompassing box -->
Expand Down
4 changes: 2 additions & 2 deletions comp_bigmath/src/main/res/values/colors.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
limitations under the License.
-->
<resources>
<color name="addSubtractDigitColor">#333333</color>
<color name="addSubtractDigitCarryColor">#666666</color>
<color name="addSubtractDigitColor">#FF000000</color>
<color name="addSubtractDigitCarryColor">#FF000000</color>

<color name="bigMathHighlightColor">#FFFACD</color>
<color name="incorrectDigit">#FFFF0000</color>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
import cmu.xprize.asm_component.ui.CAsm_LayoutManager_NewMath;
import cmu.xprize.comp_logging.CErrorManager;
import cmu.xprize.comp_writebox.ICharRecListener_Simple;
import cmu.xprize.ltkplus.CRecognizerPlus;
import cmu.xprize.ltkplus.GCONST;
import cmu.xprize.util.CAnimatorUtil;
import cmu.xprize.util.IBehaviorManager;
import cmu.xprize.util.ILoadableObject;
Expand Down

0 comments on commit 4fd2bae

Please sign in to comment.