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

Commit e5567fd0 authored by Annie Chin's avatar Annie Chin
Browse files

Silently cancel evaluation on history pulldown.

Fixes: 33500983

-Suppress cancel message if quiet=true even if reevaluation is in
progress
-Remove existing timeout callbacks before posting another

Change-Id: Iee8e69307f2d5ee97307d5e0769123ea7118ce45
parent 12874e38
Loading
Loading
Loading
Loading
+6 −2
Original line number Diff line number Diff line
@@ -1296,8 +1296,12 @@ public class Calculator extends Activity
    private boolean prepareForHistory() {
        if (mCurrentState == CalculatorState.ANIMATE) {
            throw new AssertionError("onUserInteraction should have ended animation");
        } else if (mCurrentState == CalculatorState.EVALUATE
                || mCurrentState == CalculatorState.INIT) {
        } else if (mCurrentState == CalculatorState.EVALUATE) {
            // Cancel current evaluation
            cancelIfEvaluating(true /* quiet */ );
            setState(CalculatorState.INPUT);
            return true;
        } else if (mCurrentState == CalculatorState.INIT) {
            // Easiest to just refuse.  Otherwise we can see a state change
            // while in history mode, which causes all sorts of problems.
            // TODO: Consider other alternatives. If we're just doing the decimal conversion
+5 −6
Original line number Diff line number Diff line
@@ -29,11 +29,9 @@ import android.util.Log;
import com.hp.creals.CR;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.DataInput;
import java.io.DataInputStream;
import java.io.DataOutput;
import java.io.DataOutputStream;
import java.io.IOException;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
@@ -526,6 +524,7 @@ public class Evaluator implements CalculatorExpr.ExprResolver {
                    handleTimeout();
                }
            };
            mTimeoutHandler.removeCallbacks(mTimeoutRunnable);
            mTimeoutHandler.postDelayed(mTimeoutRunnable, timeout);
        }

@@ -1216,17 +1215,17 @@ public class Evaluator implements CalculatorExpr.ExprResolver {
     */
    private boolean cancel(ExprInfo expr, boolean quiet) {
        if (expr.mEvaluator != null) {
            if (quiet) {
                ((AsyncEvaluator)(expr.mEvaluator)).suppressCancelMessage();
            }
            // Reevaluation in progress.
            if (expr.mVal != null) {
            if (expr.mVal.get() != null) {
                expr.mEvaluator.cancel(true);
                expr.mResultStringOffsetReq = expr.mResultStringOffset;
                // Backgound computation touches only constructive reals.
                // OK not to wait.
                expr.mEvaluator = null;
            } else {
                if (quiet) {
                    ((AsyncEvaluator)(expr.mEvaluator)).suppressCancelMessage();
                }
                expr.mEvaluator.cancel(true);
                if (expr == mMainExpr) {
                    // The expression is modifiable, and the AsyncTask is reading it.