Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 9c251df0 authored by Hans Boehm's avatar Hans Boehm Committed by Android (Google) Code Review
Browse files

Merge "Deal with small displays and a cancellation race" into ub-calculator-euler

parents 9f00a95d 64751001
Loading
Loading
Loading
Loading
+9 −1
Original line number Diff line number Diff line
@@ -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 */,
+4 −0
Original line number Diff line number Diff line
@@ -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