diff options
author | Hans Boehm <hboehm@google.com> | 2017-02-03 19:05:50 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2017-02-03 19:05:51 +0000 |
commit | 9c251df085228ed76a6abad4d28d504d15b5fa56 (patch) | |
tree | ae4f3fc01e6787421669b9dd5576a286db04b0be | |
parent | 9f00a95dbd76036553275295b90a69815d3ac87e (diff) | |
parent | 64751001161307c9342d8b0578dec9c6750d4b86 (diff) | |
download | ExactCalculator-9c251df085228ed76a6abad4d28d504d15b5fa56.tar.gz |
Merge "Deal with small displays and a cancellation race" into ub-calculator-euler
-rw-r--r-- | src/com/android/calculator2/CalculatorResult.java | 10 | ||||
-rw-r--r-- | src/com/android/calculator2/Evaluator.java | 4 |
2 files changed, 13 insertions, 1 deletions
diff --git a/src/com/android/calculator2/CalculatorResult.java b/src/com/android/calculator2/CalculatorResult.java index 1eede10..d2ba9a8 100644 --- a/src/com/android/calculator2/CalculatorResult.java +++ b/src/com/android/calculator2/CalculatorResult.java @@ -744,6 +744,10 @@ public class CalculatorResult extends AlignedTextView implements MenuItem.OnMenu ++exponent; } } + if (dropDigits >= result.length() - 1) { + // Display too small to show meaningful result. + return KeyMaps.ELLIPSIS + "E" + KeyMaps.ELLIPSIS; + } result = result.substring(0, result.length() - dropDigits); if (lastDisplayedOffset != null) { lastDisplayedOffset[0] -= dropDigits; @@ -918,11 +922,15 @@ public class CalculatorResult extends AlignedTextView implements MenuItem.OnMenu } public void redisplay() { + int maxChars = getMaxChars(); + if (maxChars < 4) { + // Display currently too small to display a reasonable result. Punt to avoid crash. + return; + } if (mScroller.isFinished() && length() > 0) { setAccessibilityLiveRegion(ACCESSIBILITY_LIVE_REGION_POLITE); } int currentCharOffset = getCharOffset(mCurrentPos); - int maxChars = getMaxChars(); int lastDisplayedOffset[] = new int[1]; String result = getFormattedResult(currentCharOffset, maxChars, lastDisplayedOffset, mAppendExponent /* forcePrecision; preserve entire result */, diff --git a/src/com/android/calculator2/Evaluator.java b/src/com/android/calculator2/Evaluator.java index 472cd34..655aa70 100644 --- a/src/com/android/calculator2/Evaluator.java +++ b/src/com/android/calculator2/Evaluator.java @@ -574,6 +574,10 @@ public class Evaluator implements CalculatorExpr.ExprResolver { if (res == null) { try { res = mExprInfo.mExpr.eval(mDm, Evaluator.this); + if (isCancelled()) { + // TODO: This remains very slightly racey. Fix this. + throw new CR.AbortedException(); + } res = putResultIfAbsent(mIndex, res); } catch (StackOverflowError e) { // Absurdly large integer exponents can cause this. There might be other |