diff options
author | Hans Boehm <hboehm@google.com> | 2015-06-09 18:04:26 -0700 |
---|---|---|
committer | Hans Boehm <hboehm@google.com> | 2015-06-09 18:14:23 -0700 |
commit | 187d3e93b13bf0d8711ad5ecaab2deb9909b5f23 (patch) | |
tree | e28dab0fe835faa4557bb41419e4bdf8566641f1 /src | |
parent | 7c07c19e9c81569362233dfd0b9aa12536c198cb (diff) | |
download | android_packages_apps_ExactCalculator-187d3e93b13bf0d8711ad5ecaab2deb9909b5f23.tar.gz android_packages_apps_ExactCalculator-187d3e93b13bf0d8711ad5ecaab2deb9909b5f23.tar.bz2 android_packages_apps_ExactCalculator-187d3e93b13bf0d8711ad5ecaab2deb9909b5f23.zip |
Improve logic for when to display instant result
Bug: 21497671
Fix mChangedValue handling, so that it is only reset after an actual
evaluation, and is set when an expression is "collapsed".
Consistently produce instant results for solitary pre-evaluated
expressions if and only if they involve an abbreviation.
Change-Id: I4e1f824e2353cbe78b1827f3930c72666832cff4
Diffstat (limited to 'src')
-rw-r--r-- | src/com/android/calculator2/CalculatorExpr.java | 15 | ||||
-rw-r--r-- | src/com/android/calculator2/Evaluator.java | 13 |
2 files changed, 17 insertions, 11 deletions
diff --git a/src/com/android/calculator2/CalculatorExpr.java b/src/com/android/calculator2/CalculatorExpr.java index c5ad301..8b3cb40 100644 --- a/src/com/android/calculator2/CalculatorExpr.java +++ b/src/com/android/calculator2/CalculatorExpr.java @@ -305,7 +305,12 @@ class CalculatorExpr { return KeyMaps.translateResult(mShortRep); } @Override - TokenKind kind() { return TokenKind.PRE_EVAL; } + TokenKind kind() { + return TokenKind.PRE_EVAL; + } + boolean hasEllipsis() { + return mShortRep.lastIndexOf(KeyMaps.ELLIPSIS) != -1; + } } static Token newToken(DataInput in) throws IOException { @@ -916,10 +921,10 @@ class CalculatorExpr { } for (int i = first; i < last; ++i) { Token t1 = mExpr.get(i); - if (!(t1 instanceof Constant)) return true; - // We consider preevaluated expressions "interesting", - // since the evaluation will usually result in more precision - // than the "short representation". + if (t1 instanceof Operator + || t1 instanceof PreEval && ((PreEval)t1).hasEllipsis()) { + return true; + } } return false; } diff --git a/src/com/android/calculator2/Evaluator.java b/src/com/android/calculator2/Evaluator.java index 16121f5..8d10210 100644 --- a/src/com/android/calculator2/Evaluator.java +++ b/src/com/android/calculator2/Evaluator.java @@ -188,9 +188,8 @@ class Evaluator { // Currently running expression evaluator, if any. private boolean mChangedValue; - // Last insertion or deletion may have changed the display value - // of the expression. - // We handle deletions very conservatively. + // The expression may have changed since the last evaluation in ways that would + // affect its value. Evaluator(Calculator calculator, CalculatorResult resultDisplay) { @@ -791,6 +790,7 @@ class Evaluator { clearCache(); mEvaluator = new AsyncDisplayResult(mDegreeMode, false); mEvaluator.execute(); + mChangedValue = false; } // Ensure that we either display a result or complain. @@ -835,6 +835,7 @@ class Evaluator { // Approximation of constructive reals should be thread-safe, // so we can let that continue until it notices the cancellation. mEvaluator = null; + mChangedValue = true; // Didn't do the expected evaluation. return true; } return false; @@ -874,9 +875,8 @@ class Evaluator { add10pow(); // Handled as macro expansion. return true; } else { - mChangedValue = (KeyMaps.digVal(id) != KeyMaps.NOT_DIGIT - || KeyMaps.isSuffix(id) - || id == R.id.const_pi || id == R.id.const_e); + mChangedValue = mChangedValue || (KeyMaps.digVal(id) != KeyMaps.NOT_DIGIT + || KeyMaps.isSuffix(id) || id == R.id.const_pi || id == R.id.const_e); return mExpr.add(id); } } @@ -918,6 +918,7 @@ class Evaluator { final CalculatorExpr abbrvExpr = getResultExpr(); clear(); mExpr.append(abbrvExpr); + mChangedValue = true; } // Same as above, but put result in mSaved, leaving mExpr alone. |