From 4fd2bae9d4c0cf014d3d6633948d102cebb935c6 Mon Sep 17 00:00:00 2001 From: Kevin DeLand Date: Wed, 12 Sep 2018 17:13:57 -0400 Subject: [PATCH] MATH: can animate all units at once; changed text color. --- .../assets/tutors/bigmath/animator_graph.json | 1 + .../assets/data/sw/bigmath_sample.json | 8 +- .../cmu/xprize/comp_bigmath/BM_CONST.java | 3 +- .../xprize/comp_bigmath/BigMathMechanic.java | 136 +++++++----------- .../comp_bigmath/CBigMath_Component.java | 13 ++ .../src/main/res/layout/bigmath_2d.xml | 4 +- comp_bigmath/src/main/res/values/colors.xml | 4 +- .../xprize/asm_component/CAsm_Component.java | 2 + 8 files changed, 76 insertions(+), 95 deletions(-) diff --git a/app/src/main/assets/tutors/bigmath/animator_graph.json b/app/src/main/assets/tutors/bigmath/animator_graph.json index a26c25c4f..924374532 100644 --- a/app/src/main/assets/tutors/bigmath/animator_graph.json +++ b/app/src/main/assets/tutors/bigmath/animator_graph.json @@ -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": ""} ] diff --git a/app/src/main/assets/tutors/bigmath/assets/data/sw/bigmath_sample.json b/app/src/main/assets/tutors/bigmath/assets/data/sw/bigmath_sample.json index 022247b16..b7c30042c 100644 --- a/app/src/main/assets/tutors/bigmath/assets/data/sw/bigmath_sample.json +++ b/app/src/main/assets/tutors/bigmath/assets/data/sw/bigmath_sample.json @@ -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": "+"}, diff --git a/comp_bigmath/src/main/java/cmu/xprize/comp_bigmath/BM_CONST.java b/comp_bigmath/src/main/java/cmu/xprize/comp_bigmath/BM_CONST.java index 5ceab6181..1ae5a3b2b 100644 --- a/comp_bigmath/src/main/java/cmu/xprize/comp_bigmath/BM_CONST.java +++ b/comp_bigmath/src/main/java/cmu/xprize/comp_bigmath/BM_CONST.java @@ -62,5 +62,6 @@ public enum ACTION_MAP { SET_VERSION, SET_DATASOURCE, NEXTNODE, NEXTSCENE } - + // various variables + static final int WATERFALL_DELAY = 100; } diff --git a/comp_bigmath/src/main/java/cmu/xprize/comp_bigmath/BigMathMechanic.java b/comp_bigmath/src/main/java/cmu/xprize/comp_bigmath/BigMathMechanic.java index 1471d380f..783f5bd60 100644 --- a/comp_bigmath/src/main/java/cmu/xprize/comp_bigmath/BigMathMechanic.java +++ b/comp_bigmath/src/main/java/cmu/xprize/comp_bigmath/BigMathMechanic.java @@ -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; @@ -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; @@ -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; @@ -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() { @@ -219,7 +224,7 @@ 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 @@ -227,7 +232,7 @@ private void initializeOnClickListeners() { 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 @@ -235,18 +240,18 @@ private void initializeOnClickListeners() { 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)); } @@ -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 { @@ -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. */ @@ -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): ""); @@ -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...) } } @@ -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; @@ -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. @@ -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 @@ -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 * diff --git a/comp_bigmath/src/main/java/cmu/xprize/comp_bigmath/CBigMath_Component.java b/comp_bigmath/src/main/java/cmu/xprize/comp_bigmath/CBigMath_Component.java index 158da6a78..e339696e3 100644 --- a/comp_bigmath/src/main/java/cmu/xprize/comp_bigmath/CBigMath_Component.java +++ b/comp_bigmath/src/main/java/cmu/xprize/comp_bigmath/CBigMath_Component.java @@ -16,6 +16,8 @@ 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; @@ -23,6 +25,7 @@ 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; /** @@ -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); @@ -159,6 +165,13 @@ public void nextDigit() { } + /** + * highlight all digits! + */ + public void highlightAll() { + _mechanic.highlightDigitColumn(ALL_DIGITS); + } + /** * Point at a view */ diff --git a/comp_bigmath/src/main/res/layout/bigmath_2d.xml b/comp_bigmath/src/main/res/layout/bigmath_2d.xml index f71f18630..99474265f 100644 --- a/comp_bigmath/src/main/res/layout/bigmath_2d.xml +++ b/comp_bigmath/src/main/res/layout/bigmath_2d.xml @@ -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" /> @@ -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"/> diff --git a/comp_bigmath/src/main/res/values/colors.xml b/comp_bigmath/src/main/res/values/colors.xml index ea382e9dc..ae7cfc25a 100644 --- a/comp_bigmath/src/main/res/values/colors.xml +++ b/comp_bigmath/src/main/res/values/colors.xml @@ -12,8 +12,8 @@ limitations under the License. --> - #333333 - #666666 + #FF000000 + #FF000000 #FFFACD #FFFF0000 diff --git a/comp_math/src/main/java/cmu/xprize/asm_component/CAsm_Component.java b/comp_math/src/main/java/cmu/xprize/asm_component/CAsm_Component.java index 74bdb2019..193f1617b 100644 --- a/comp_math/src/main/java/cmu/xprize/asm_component/CAsm_Component.java +++ b/comp_math/src/main/java/cmu/xprize/asm_component/CAsm_Component.java @@ -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;