summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorHans Boehm <hboehm@google.com>2015-07-14 15:40:52 -0700
committerHans Boehm <hboehm@google.com>2015-07-14 15:40:52 -0700
commitae807e1d4d5764d74fcbc44556945ff345c27157 (patch)
tree9c972316efc7363866376b372d68461fa9769b7e /src
parent0b9806f624f25e7e0302da4cf55eda21f8c28163 (diff)
downloadandroid_packages_apps_ExactCalculator-ae807e1d4d5764d74fcbc44556945ff345c27157.tar.gz
android_packages_apps_ExactCalculator-ae807e1d4d5764d74fcbc44556945ff345c27157.tar.bz2
android_packages_apps_ExactCalculator-ae807e1d4d5764d74fcbc44556945ff345c27157.zip
Force reevaluation if mChangedValue is true
Bug: 22481292 This could result in display of an old result. Factor out code to start a result evaluation. Change-Id: I651d4386323c0abd7a86176b386072093345a1b1
Diffstat (limited to 'src')
-rw-r--r--src/com/android/calculator2/Evaluator.java23
1 files changed, 15 insertions, 8 deletions
diff --git a/src/com/android/calculator2/Evaluator.java b/src/com/android/calculator2/Evaluator.java
index 4bdc56f..a97d946 100644
--- a/src/com/android/calculator2/Evaluator.java
+++ b/src/com/android/calculator2/Evaluator.java
@@ -787,6 +787,18 @@ class Evaluator {
clearCache();
}
+ /**
+ * Start asynchronous result evaluation of formula.
+ * Will result in display on completion.
+ * @param required result was explicitly requested by user.
+ */
+ private void reevaluateResult(boolean required) {
+ clearCache();
+ mEvaluator = new AsyncDisplayResult(mDegreeMode, required);
+ mEvaluator.execute();
+ mChangedValue = false;
+ }
+
// Begin evaluation of result and display when ready.
// We assume this is called after each insertion and deletion.
// Thus if we are called twice with the same effective end of
@@ -796,13 +808,10 @@ class Evaluator {
// Already done or in progress.
return;
}
- clearCache();
// In very odd cases, there can be significant latency to evaluate.
// Don't show obsolete result.
mResult.clear();
- mEvaluator = new AsyncDisplayResult(mDegreeMode, false);
- mEvaluator.execute();
- mChangedValue = false;
+ reevaluateResult(false);
}
// Ensure that we either display a result or complain.
@@ -810,12 +819,10 @@ class Evaluator {
// We presume that any prior result was computed using the same
// expression.
void requireResult() {
- if (mCache == null) {
+ if (mCache == null || mChangedValue) {
// Restart evaluator in requested mode, i.e. with longer timeout.
cancelAll(true);
- clearCache();
- mEvaluator = new AsyncDisplayResult(mDegreeMode, true);
- mEvaluator.execute();
+ reevaluateResult(true);
} else {
// Notify immediately, reusing existing result.
int dotPos = mCache.indexOf('.');