From e8553769f4b06650da0ca22a1bf741d0aad96e74 Mon Sep 17 00:00:00 2001 From: Hans Boehm Date: Fri, 26 Jun 2015 17:56:52 -0700 Subject: Make trailing operator handling consistent with L Bug: 246391 Only ignore trailing BINARY operators when computing instant results. We used to be much more aggressive. Also ignore trailing binary operators when the user hits "=". This makes us consistent with the L design and ensures that instant results don't turn into errors when the user hits "=". Change-Id: I260e95d152168b70774330ac95d5bc567cf79b3d --- src/com/android/calculator2/Evaluator.java | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) (limited to 'src/com/android/calculator2/Evaluator.java') diff --git a/src/com/android/calculator2/Evaluator.java b/src/com/android/calculator2/Evaluator.java index afde752..9c4346e 100644 --- a/src/com/android/calculator2/Evaluator.java +++ b/src/com/android/calculator2/Evaluator.java @@ -382,7 +382,7 @@ class Evaluator { @Override protected InitialResult doInBackground(Void... nothing) { try { - CalculatorExpr.EvalResult res = mExpr.eval(mDm, mRequired); + CalculatorExpr.EvalResult res = mExpr.eval(mDm); int prec = INIT_PREC; String initCache = res.mVal.toString(prec); int msd = getMsdPos(initCache); @@ -810,9 +810,8 @@ class Evaluator { // We presume that any prior result was computed using the same // expression. void requireResult() { - if (mCache == null || mExpr.hasTrailingOperators()) { - // Restart evaluator in requested mode, i.e. with - // longer timeout, not ignoring trailing operators. + if (mCache == null) { + // Restart evaluator in requested mode, i.e. with longer timeout. cancelAll(true); clearCache(); mEvaluator = new AsyncDisplayResult(mDegreeMode, true); @@ -895,8 +894,7 @@ class Evaluator { add10pow(); // Handled as macro expansion. return true; } else { - mChangedValue = mChangedValue || (KeyMaps.digVal(id) != KeyMaps.NOT_DIGIT - || KeyMaps.isSuffix(id) || id == R.id.const_pi || id == R.id.const_e); + mChangedValue = mChangedValue || !KeyMaps.isBinary(id); return mExpr.add(id); } } -- cgit v1.2.3