Loading src/com/android/calculator2/Calculator.java +11 −3 Original line number Diff line number Diff line Loading @@ -444,13 +444,13 @@ 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) { // FIXME: Other states? if (mCurrentState == CalculatorState.ERROR) { setState(CalculatorState.INPUT); } else if (mCurrentState == CalculatorState.RESULT) { if (KeyMaps.isBinary(id) || KeyMaps.isSuffix(id)) { mEvaluator.collapse(); } else { announceClearForAccessibility(); mEvaluator.clear(); } setState(CalculatorState.INPUT); Loading Loading @@ -544,9 +544,9 @@ public class Calculator extends Activity formatted.setSpan(new ForegroundColorSpan(Color.RED), formula.length(), formatted.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); mFormulaText.setText(formatted); mFormulaText.changeTextTo(formatted); } else { mFormulaText.setText(formula); mFormulaText.changeTextTo(formula); } } Loading Loading @@ -711,11 +711,16 @@ public class Calculator extends Activity animatorSet.start(); } private void announceClearForAccessibility() { mResultText.announceForAccessibility(getResources().getString(R.string.desc_clr)); } private void onClear() { if (mEvaluator.getExpr().isEmpty()) { return; } cancelIfEvaluating(true); announceClearForAccessibility(); reveal(mCurrentButton, R.color.calculator_accent_color, new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { Loading @@ -732,6 +737,7 @@ public class Calculator extends Activity void onError(final int errorResourceId) { if (mCurrentState == CalculatorState.EVALUATE) { setState(CalculatorState.ANIMATE); mResultText.announceForAccessibility(getResources().getString(errorResourceId)); reveal(mCurrentButton, R.color.calculator_error_color, new AnimatorListenerAdapter() { @Override Loading Loading @@ -783,6 +789,8 @@ public class Calculator extends Activity final int formulaTextColor = mFormulaText.getCurrentTextColor(); if (animate) { mResultText.announceForAccessibility(getResources().getString(R.string.desc_eq)); mResultText.announceForAccessibility(mResultText.getText()); setState(CalculatorState.ANIMATE); final AnimatorSet animatorSet = new AnimatorSet(); animatorSet.playTogether( Loading src/com/android/calculator2/CalculatorText.java +33 −0 Original line number Diff line number Diff line Loading @@ -204,6 +204,39 @@ public class CalculatorText extends AlignedTextView implements View.OnLongClickL return lastFitTextSize; } private static boolean startsWith(CharSequence whole, CharSequence prefix) { int wholeLen = whole.length(); int prefixLen = prefix.length(); if (prefixLen > wholeLen) { return false; } for (int i = 0; i < prefixLen; ++i) { if (prefix.charAt(i) != whole.charAt(i)) { return false; } } return true; } /** * Functionally equivalent to setText(), but explicitly announce changes. * If the new text is an extension of the old one, announce the addition. * Otherwise, e.g. after deletion, announce the entire new text. */ public void changeTextTo(CharSequence newText) { CharSequence oldText = getText(); if (startsWith(newText, oldText)) { int newLen = newText.length(); int oldLen = oldText.length(); if (oldLen != newLen) { announceForAccessibility(newText.subSequence(oldLen, newLen)); } } else { announceForAccessibility(newText); } setText(newText); } public boolean stopActionMode() { if (mActionMode != null) { mActionMode.finish(); Loading Loading
src/com/android/calculator2/Calculator.java +11 −3 Original line number Diff line number Diff line Loading @@ -444,13 +444,13 @@ 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) { // FIXME: Other states? if (mCurrentState == CalculatorState.ERROR) { setState(CalculatorState.INPUT); } else if (mCurrentState == CalculatorState.RESULT) { if (KeyMaps.isBinary(id) || KeyMaps.isSuffix(id)) { mEvaluator.collapse(); } else { announceClearForAccessibility(); mEvaluator.clear(); } setState(CalculatorState.INPUT); Loading Loading @@ -544,9 +544,9 @@ public class Calculator extends Activity formatted.setSpan(new ForegroundColorSpan(Color.RED), formula.length(), formatted.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); mFormulaText.setText(formatted); mFormulaText.changeTextTo(formatted); } else { mFormulaText.setText(formula); mFormulaText.changeTextTo(formula); } } Loading Loading @@ -711,11 +711,16 @@ public class Calculator extends Activity animatorSet.start(); } private void announceClearForAccessibility() { mResultText.announceForAccessibility(getResources().getString(R.string.desc_clr)); } private void onClear() { if (mEvaluator.getExpr().isEmpty()) { return; } cancelIfEvaluating(true); announceClearForAccessibility(); reveal(mCurrentButton, R.color.calculator_accent_color, new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { Loading @@ -732,6 +737,7 @@ public class Calculator extends Activity void onError(final int errorResourceId) { if (mCurrentState == CalculatorState.EVALUATE) { setState(CalculatorState.ANIMATE); mResultText.announceForAccessibility(getResources().getString(errorResourceId)); reveal(mCurrentButton, R.color.calculator_error_color, new AnimatorListenerAdapter() { @Override Loading Loading @@ -783,6 +789,8 @@ public class Calculator extends Activity final int formulaTextColor = mFormulaText.getCurrentTextColor(); if (animate) { mResultText.announceForAccessibility(getResources().getString(R.string.desc_eq)); mResultText.announceForAccessibility(mResultText.getText()); setState(CalculatorState.ANIMATE); final AnimatorSet animatorSet = new AnimatorSet(); animatorSet.playTogether( Loading
src/com/android/calculator2/CalculatorText.java +33 −0 Original line number Diff line number Diff line Loading @@ -204,6 +204,39 @@ public class CalculatorText extends AlignedTextView implements View.OnLongClickL return lastFitTextSize; } private static boolean startsWith(CharSequence whole, CharSequence prefix) { int wholeLen = whole.length(); int prefixLen = prefix.length(); if (prefixLen > wholeLen) { return false; } for (int i = 0; i < prefixLen; ++i) { if (prefix.charAt(i) != whole.charAt(i)) { return false; } } return true; } /** * Functionally equivalent to setText(), but explicitly announce changes. * If the new text is an extension of the old one, announce the addition. * Otherwise, e.g. after deletion, announce the entire new text. */ public void changeTextTo(CharSequence newText) { CharSequence oldText = getText(); if (startsWith(newText, oldText)) { int newLen = newText.length(); int oldLen = oldText.length(); if (oldLen != newLen) { announceForAccessibility(newText.subSequence(oldLen, newLen)); } } else { announceForAccessibility(newText); } setText(newText); } public boolean stopActionMode() { if (mActionMode != null) { mActionMode.finish(); Loading