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

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

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

* commit 'a8f47d36':
  Have TalkBack announce results and formula changes
parents 5ebef09a a8f47d36
Loading
Loading
Loading
Loading
+11 −3
Original line number Diff line number Diff line
@@ -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(
+33 −0
Original line number Diff line number Diff line
@@ -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();