Commit 36fe131b authored by Hans Boehm's avatar Hans Boehm Committed by Android Git Automerger
Browse files

am 792e8388: am 63b08564: am a8f47d36: Merge "Have TalkBack announce results...

am 792e8388: am 63b08564: am a8f47d36: Merge "Have TalkBack announce results and formula changes" into mnc-dev

* commit '792e8388':
  Have TalkBack announce results and formula changes
parents a5636a98 792e8388
......@@ -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);
......@@ -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);
}
}
......@@ -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) {
......@@ -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
......@@ -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(
......
......@@ -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();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment