From f6033a42aa90367012ecb11977fe86ccdac54f54 Mon Sep 17 00:00:00 2001 From: Hans Boehm Date: Wed, 16 Sep 2015 16:33:47 -0700 Subject: 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 5d79d10734b45133be7753955afd9e5edec58a1d) --- src/com/android/calculator2/Calculator.java | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/src/com/android/calculator2/Calculator.java b/src/com/android/calculator2/Calculator.java index 99ef032..c7e14a4 100644 --- a/src/com/android/calculator2/Calculator.java +++ b/src/com/android/calculator2/Calculator.java @@ -445,19 +445,27 @@ public class Calculator extends Activity } } + /** + * 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(); + mEvaluator.clear(); + } + 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) { - if (KeyMaps.isBinary(id) || KeyMaps.isSuffix(id)) { - mEvaluator.collapse(); - } else { - announceClearedForAccessibility(); - mEvaluator.clear(); - } - setState(CalculatorState.INPUT); + 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); -- cgit v1.2.3