Loading src/com/android/calculator2/Calculator.java +34 −21 Original line number Diff line number Diff line Loading @@ -153,11 +153,11 @@ public class Calculator extends Activity case KeyEvent.KEYCODE_DPAD_CENTER: mCurrentButton = mEqualButton; onEquals(); return true; break; case KeyEvent.KEYCODE_DEL: mCurrentButton = mDeleteButton; onDelete(); return true; break; default: cancelIfEvaluating(false); final int raw = keyEvent.getKeyCharacterMap() Loading @@ -180,7 +180,7 @@ public class Calculator extends Activity redisplayAfterFormulaChange(); } } return false; return true; } }; Loading Loading @@ -492,12 +492,18 @@ public class Calculator extends Activity // TODO: Could do this more incrementally. redisplayFormula(); setState(CalculatorState.INPUT); if (haveUnprocessed()) { mResultText.clear(); // Force reevaluation when text is deleted, even if expression is unchanged. mEvaluator.touch(); } else { if (mEvaluator.getExpr().hasInterestingOps()) { mEvaluator.evaluateAndShowResult(); } else { mResultText.clear(); } } } public void onButtonClick(View view) { // Any animation is ended before we get here. Loading Loading @@ -539,14 +545,20 @@ public class Calculator extends Activity onModeChanged(mode); setState(CalculatorState.INPUT); mResultText.clear(); if (mEvaluator.getExpr().hasInterestingOps()) { if (!haveUnprocessed() && mEvaluator.getExpr().hasInterestingOps()) { mEvaluator.evaluateAndShowResult(); } break; default: cancelIfEvaluating(false); if (haveUnprocessed()) { // For consistency, append as uninterpreted characters. // This may actually be useful for a left parenthesis. addChars(KeyMaps.toString(this, id), true); } else { addExplicitKeyToExpr(id); redisplayAfterFormulaChange(); } break; } } Loading Loading @@ -638,13 +650,21 @@ public class Calculator extends Activity } } private boolean haveUnprocessed() { return mUnprocessedChars != null && !mUnprocessedChars.isEmpty(); } private void onEquals() { // In non-INPUT state assume this was redundant and ignore it. if (mCurrentState == CalculatorState.INPUT && !mEvaluator.getExpr().isEmpty()) { setState(CalculatorState.EVALUATE); if (haveUnprocessed()) { onError(R.string.error_syntax); } else { mEvaluator.requireResult(); } } } private void onDelete() { // Delete works like backspace; remove the last character or operator from the expression. Loading @@ -655,18 +675,12 @@ public class Calculator extends Activity // If there is an in-progress explicit evaluation, just cancel it and return. if (cancelIfEvaluating(false)) return; setState(CalculatorState.INPUT); if (mUnprocessedChars != null) { int len = mUnprocessedChars.length(); if (len > 0) { mUnprocessedChars = mUnprocessedChars.substring(0, len-1); if (haveUnprocessed()) { mUnprocessedChars = mUnprocessedChars.substring(0, mUnprocessedChars.length() - 1); } else { mEvaluator.delete(); } } else { mEvaluator.delete(); } if (mEvaluator.getExpr().isEmpty() && (mUnprocessedChars == null || mUnprocessedChars.isEmpty())) { if (mEvaluator.getExpr().isEmpty() && !haveUnprocessed()) { // Resulting formula won't be announced, since it's empty. announceClearedForAccessibility(); } Loading @@ -685,7 +699,7 @@ public class Calculator extends Activity revealView.setBottom(displayRect.bottom); revealView.setLeft(displayRect.left); revealView.setRight(displayRect.right); revealView.setBackgroundColor(getResources().getColor(colorRes)); revealView.setBackgroundColor(getColor(colorRes)); groupOverlay.add(revealView); final int[] clearLocation = new int[2]; Loading Loading @@ -770,7 +784,6 @@ public class Calculator extends Activity } } // Animate movement of result into the top formula slot. // Result window now remains translated in the top slot while the result is displayed. // (We convert it back to formula use only when the user provides new input.) Loading src/com/android/calculator2/Evaluator.java +7 −0 Original line number Diff line number Diff line Loading @@ -1033,6 +1033,13 @@ class Evaluator { mChangedValue = true; } /** * Mark the expression as changed, preventing next evaluation request from being ignored. */ public void touch() { mChangedValue = true; } /** * Abbreviate current expression, and put result in mSaved. * mExpr is left alone. Return false if result is unavailable. Loading Loading
src/com/android/calculator2/Calculator.java +34 −21 Original line number Diff line number Diff line Loading @@ -153,11 +153,11 @@ public class Calculator extends Activity case KeyEvent.KEYCODE_DPAD_CENTER: mCurrentButton = mEqualButton; onEquals(); return true; break; case KeyEvent.KEYCODE_DEL: mCurrentButton = mDeleteButton; onDelete(); return true; break; default: cancelIfEvaluating(false); final int raw = keyEvent.getKeyCharacterMap() Loading @@ -180,7 +180,7 @@ public class Calculator extends Activity redisplayAfterFormulaChange(); } } return false; return true; } }; Loading Loading @@ -492,12 +492,18 @@ public class Calculator extends Activity // TODO: Could do this more incrementally. redisplayFormula(); setState(CalculatorState.INPUT); if (haveUnprocessed()) { mResultText.clear(); // Force reevaluation when text is deleted, even if expression is unchanged. mEvaluator.touch(); } else { if (mEvaluator.getExpr().hasInterestingOps()) { mEvaluator.evaluateAndShowResult(); } else { mResultText.clear(); } } } public void onButtonClick(View view) { // Any animation is ended before we get here. Loading Loading @@ -539,14 +545,20 @@ public class Calculator extends Activity onModeChanged(mode); setState(CalculatorState.INPUT); mResultText.clear(); if (mEvaluator.getExpr().hasInterestingOps()) { if (!haveUnprocessed() && mEvaluator.getExpr().hasInterestingOps()) { mEvaluator.evaluateAndShowResult(); } break; default: cancelIfEvaluating(false); if (haveUnprocessed()) { // For consistency, append as uninterpreted characters. // This may actually be useful for a left parenthesis. addChars(KeyMaps.toString(this, id), true); } else { addExplicitKeyToExpr(id); redisplayAfterFormulaChange(); } break; } } Loading Loading @@ -638,13 +650,21 @@ public class Calculator extends Activity } } private boolean haveUnprocessed() { return mUnprocessedChars != null && !mUnprocessedChars.isEmpty(); } private void onEquals() { // In non-INPUT state assume this was redundant and ignore it. if (mCurrentState == CalculatorState.INPUT && !mEvaluator.getExpr().isEmpty()) { setState(CalculatorState.EVALUATE); if (haveUnprocessed()) { onError(R.string.error_syntax); } else { mEvaluator.requireResult(); } } } private void onDelete() { // Delete works like backspace; remove the last character or operator from the expression. Loading @@ -655,18 +675,12 @@ public class Calculator extends Activity // If there is an in-progress explicit evaluation, just cancel it and return. if (cancelIfEvaluating(false)) return; setState(CalculatorState.INPUT); if (mUnprocessedChars != null) { int len = mUnprocessedChars.length(); if (len > 0) { mUnprocessedChars = mUnprocessedChars.substring(0, len-1); if (haveUnprocessed()) { mUnprocessedChars = mUnprocessedChars.substring(0, mUnprocessedChars.length() - 1); } else { mEvaluator.delete(); } } else { mEvaluator.delete(); } if (mEvaluator.getExpr().isEmpty() && (mUnprocessedChars == null || mUnprocessedChars.isEmpty())) { if (mEvaluator.getExpr().isEmpty() && !haveUnprocessed()) { // Resulting formula won't be announced, since it's empty. announceClearedForAccessibility(); } Loading @@ -685,7 +699,7 @@ public class Calculator extends Activity revealView.setBottom(displayRect.bottom); revealView.setLeft(displayRect.left); revealView.setRight(displayRect.right); revealView.setBackgroundColor(getResources().getColor(colorRes)); revealView.setBackgroundColor(getColor(colorRes)); groupOverlay.add(revealView); final int[] clearLocation = new int[2]; Loading Loading @@ -770,7 +784,6 @@ public class Calculator extends Activity } } // Animate movement of result into the top formula slot. // Result window now remains translated in the top slot while the result is displayed. // (We convert it back to formula use only when the user provides new input.) Loading
src/com/android/calculator2/Evaluator.java +7 −0 Original line number Diff line number Diff line Loading @@ -1033,6 +1033,13 @@ class Evaluator { mChangedValue = true; } /** * Mark the expression as changed, preventing next evaluation request from being ignored. */ public void touch() { mChangedValue = true; } /** * Abbreviate current expression, and put result in mSaved. * mExpr is left alone. Return false if result is unavailable. Loading