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

Commit f6033a42 authored by Hans Boehm's avatar Hans Boehm
Browse files

Implicitly clear on incomplete keyboard input

Bug: 22931305

When the calculator is in result mode, cause a typed function name to
clear the display, just as touching the function on the screen would.

Change-Id: I77c69737a571ad8d2e6396fa3f34d5ada324fee4
(cherry picked from commit 5d79d107)
parent b7bd3488
Loading
Loading
Loading
Loading
+19 −7
Original line number Diff line number Diff line
@@ -445,13 +445,12 @@ public class Calculator extends Activity
        }
    }

    // Add the given button id to input expression.
    // If appropriate, clear the expression before doing so.
    private void addKeyToExpr(int id) {
        if (mCurrentState == CalculatorState.ERROR) {
            setState(CalculatorState.INPUT);
        } else if (mCurrentState == CalculatorState.RESULT) {
            if (KeyMaps.isBinary(id) || KeyMaps.isSuffix(id)) {
    /**
     * Switch to INPUT from RESULT state in response to input of the specified button_id.
     * View.NO_ID is treated as an incomplete function id.
     */
    private void switchToInput(int button_id) {
        if (KeyMaps.isBinary(button_id) || KeyMaps.isSuffix(button_id)) {
            mEvaluator.collapse();
        } else {
            announceClearedForAccessibility();
@@ -459,6 +458,15 @@ public class Calculator extends Activity
        }
        setState(CalculatorState.INPUT);
    }

    // Add the given button id to input expression.
    // If appropriate, clear the expression before doing so.
    private void addKeyToExpr(int id) {
        if (mCurrentState == CalculatorState.ERROR) {
            setState(CalculatorState.INPUT);
        } else if (mCurrentState == CalculatorState.RESULT) {
            switchToInput(id);
        }
        if (!mEvaluator.append(id)) {
            // TODO: Some user visible feedback?
        }
@@ -916,6 +924,10 @@ public class Calculator extends Activity
        int current = 0;
        int len = moreChars.length();
        boolean lastWasDigit = false;
        if (mCurrentState == CalculatorState.RESULT && len != 0) {
            // Clear display immediately for incomplete function name.
            switchToInput(KeyMaps.keyForChar(moreChars.charAt(current)));
        }
        while (current < len) {
            char c = moreChars.charAt(current);
            int k = KeyMaps.keyForChar(c);