From a7b4398c35eaf87fd00086f660af7710c071c369 Mon Sep 17 00:00:00 2001 From: Alan Viverette Date: Fri, 22 Mar 2013 11:53:12 -0700 Subject: [PATCH] Don't announce changes for A11y within the same keyboard mode. Bug: 8439108 Change-Id: If9f14bb65625468dcd399df47ad0d2123be30be7 --- .../AccessibleKeyboardViewProxy.java | 37 +++++++++---------- 1 file changed, 17 insertions(+), 20 deletions(-) diff --git a/java/src/com/android/inputmethod/accessibility/AccessibleKeyboardViewProxy.java b/java/src/com/android/inputmethod/accessibility/AccessibleKeyboardViewProxy.java index c0028e4cf..73896dfd3 100644 --- a/java/src/com/android/inputmethod/accessibility/AccessibleKeyboardViewProxy.java +++ b/java/src/com/android/inputmethod/accessibility/AccessibleKeyboardViewProxy.java @@ -64,6 +64,9 @@ public final class AccessibleKeyboardViewProxy extends AccessibilityDelegateComp */ private int mEdgeSlop; + /** The most recently set keyboard mode. */ + private int mLastKeyboardMode; + public static void init(final InputMethodService inputMethod) { sInstance.initInternal(inputMethod); } @@ -113,16 +116,19 @@ public final class AccessibleKeyboardViewProxy extends AccessibilityDelegateComp if (mView == null) { return; } - if (mAccessibilityNodeProvider != null) { mAccessibilityNodeProvider.setKeyboard(); } + final int keyboardMode = mView.getKeyboard().mId.mMode; // Since this method is called even when accessibility is off, make sure - // to check the state before announcing anything. - if (AccessibilityUtils.getInstance().isAccessibilityEnabled()) { - announceKeyboardMode(); + // to check the state before announcing anything. Also, don't announce + // changes within the same mode. + if (AccessibilityUtils.getInstance().isAccessibilityEnabled() + && (mLastKeyboardMode != keyboardMode)) { + announceKeyboardMode(keyboardMode); } + mLastKeyboardMode = keyboardMode; } /** @@ -132,25 +138,24 @@ public final class AccessibleKeyboardViewProxy extends AccessibilityDelegateComp if (mView == null) { return; } - announceKeyboardHidden(); + mLastKeyboardMode = -1; } /** * Announces which type of keyboard is being displayed. If the keyboard type * is unknown, no announcement is made. + * + * @param mode The new keyboard mode. */ - private void announceKeyboardMode() { - final Keyboard keyboard = mView.getKeyboard(); - final int resId = KEYBOARD_MODE_RES_IDS.get(keyboard.mId.mMode); + private void announceKeyboardMode(int mode) { + final int resId = KEYBOARD_MODE_RES_IDS.get(mode); if (resId == 0) { return; } - final Context context = mView.getContext(); final String keyboardMode = context.getString(resId); final String text = context.getString(R.string.announce_keyboard_mode, keyboardMode); - sendWindowStateChanged(text); } @@ -167,7 +172,7 @@ public final class AccessibleKeyboardViewProxy extends AccessibilityDelegateComp /** * Sends a window state change event with the specified text. * - * @param text + * @param text The text to send with the event. */ private void sendWindowStateChanged(final String text) { final AccessibilityEvent stateChange = AccessibilityEvent.obtain( @@ -195,7 +200,6 @@ public final class AccessibleKeyboardViewProxy extends AccessibilityDelegateComp if (mView == null) { return null; } - return getAccessibilityNodeProvider(); } @@ -248,11 +252,9 @@ public final class AccessibleKeyboardViewProxy extends AccessibilityDelegateComp case MotionEvent.ACTION_HOVER_MOVE: if (key != previousKey) { return onTransitionKey(key, previousKey, event); - } else { - return onHoverKey(key, event); } + return onHoverKey(key, event); } - return false; } @@ -294,18 +296,13 @@ public final class AccessibleKeyboardViewProxy extends AccessibilityDelegateComp private boolean onTransitionKey(final Key currentKey, final Key previousKey, final MotionEvent event) { final int savedAction = event.getAction(); - event.setAction(MotionEvent.ACTION_HOVER_EXIT); onHoverKey(previousKey, event); - event.setAction(MotionEvent.ACTION_HOVER_ENTER); onHoverKey(currentKey, event); - event.setAction(MotionEvent.ACTION_HOVER_MOVE); final boolean handled = onHoverKey(currentKey, event); - event.setAction(savedAction); - return handled; }