From dec599d1723f4ff52f066bd2dd1a4457d30cd33c Mon Sep 17 00:00:00 2001 From: "Tadashi G. Takaoka" Date: Sat, 7 Jun 2014 23:28:13 +0900 Subject: [PATCH] Fix overwriting accessibility delegate in setKeyboard A keyboard accessibility delegate object should be a singleton for each keyboard view. Bug: 15437933 Bug: 15419386 Change-Id: Ia70853c644d950ea6130c1f209b89929b1cb1ee5 --- .../inputmethod/keyboard/MainKeyboardView.java | 4 +++- .../keyboard/MoreKeysKeyboardView.java | 11 +++++++---- .../keyboard/emoji/EmojiPageKeyboardView.java | 17 +++++++++++++---- .../latin/suggestions/MoreSuggestionsView.java | 14 +++++++++++--- 4 files changed, 34 insertions(+), 12 deletions(-) diff --git a/java/src/com/android/inputmethod/keyboard/MainKeyboardView.java b/java/src/com/android/inputmethod/keyboard/MainKeyboardView.java index 77877143b..bcd0cd848 100644 --- a/java/src/com/android/inputmethod/keyboard/MainKeyboardView.java +++ b/java/src/com/android/inputmethod/keyboard/MainKeyboardView.java @@ -382,7 +382,9 @@ public final class MainKeyboardView extends KeyboardView implements PointerTrack mLanguageOnSpacebarTextSize = keyHeight * mLanguageOnSpacebarTextRatio; if (AccessibilityUtils.getInstance().isAccessibilityEnabled()) { - mAccessibilityDelegate = new MainKeyboardAccessibilityDelegate(this, mKeyDetector); + if (mAccessibilityDelegate == null) { + mAccessibilityDelegate = new MainKeyboardAccessibilityDelegate(this, mKeyDetector); + } mAccessibilityDelegate.setKeyboard(keyboard); } else { mAccessibilityDelegate = null; diff --git a/java/src/com/android/inputmethod/keyboard/MoreKeysKeyboardView.java b/java/src/com/android/inputmethod/keyboard/MoreKeysKeyboardView.java index 4ca4abec6..0f575d30c 100644 --- a/java/src/com/android/inputmethod/keyboard/MoreKeysKeyboardView.java +++ b/java/src/com/android/inputmethod/keyboard/MoreKeysKeyboardView.java @@ -77,10 +77,13 @@ public class MoreKeysKeyboardView extends KeyboardView implements MoreKeysPanel // discarded at {@link InputView#dispatchHoverEvent(MotionEvent)}. Because only a hover // event that is on this view is dispatched by the platform, we should use a // {@link KeyDetector} that has no sliding allowance and no hysteresis. - mKeyDetector = new KeyDetector(); - mAccessibilityDelegate = new MoreKeysKeyboardAccessibilityDelegate(this, mKeyDetector); - mAccessibilityDelegate.setOpenAnnounce(R.string.spoken_open_more_keys_keyboard); - mAccessibilityDelegate.setCloseAnnounce(R.string.spoken_close_more_keys_keyboard); + if (mAccessibilityDelegate == null) { + mKeyDetector = new KeyDetector(); + mAccessibilityDelegate = new MoreKeysKeyboardAccessibilityDelegate( + this, mKeyDetector); + mAccessibilityDelegate.setOpenAnnounce(R.string.spoken_open_more_keys_keyboard); + mAccessibilityDelegate.setCloseAnnounce(R.string.spoken_close_more_keys_keyboard); + } mAccessibilityDelegate.setKeyboard(keyboard); } else { mKeyDetector = new MoreKeysDetector(getResources().getDimension( diff --git a/java/src/com/android/inputmethod/keyboard/emoji/EmojiPageKeyboardView.java b/java/src/com/android/inputmethod/keyboard/emoji/EmojiPageKeyboardView.java index 0166802a4..80ba60c82 100644 --- a/java/src/com/android/inputmethod/keyboard/emoji/EmojiPageKeyboardView.java +++ b/java/src/com/android/inputmethod/keyboard/emoji/EmojiPageKeyboardView.java @@ -55,7 +55,7 @@ final class EmojiPageKeyboardView extends KeyboardView implements private OnKeyEventListener mListener = EMPTY_LISTENER; private final KeyDetector mKeyDetector = new KeyDetector(); private final GestureDetector mGestureDetector; - private final KeyboardAccessibilityDelegate mAccessibilityDelegate; + private KeyboardAccessibilityDelegate mAccessibilityDelegate; public EmojiPageKeyboardView(final Context context, final AttributeSet attrs) { this(context, attrs, R.attr.keyboardViewStyle); @@ -67,7 +67,6 @@ final class EmojiPageKeyboardView extends KeyboardView implements mGestureDetector = new GestureDetector(context, this); mGestureDetector.setIsLongpressEnabled(false /* isLongpressEnabled */); mHandler = new Handler(); - mAccessibilityDelegate = new KeyboardAccessibilityDelegate<>(this, mKeyDetector); } public void setOnKeyEventListener(final OnKeyEventListener listener) { @@ -81,6 +80,14 @@ final class EmojiPageKeyboardView extends KeyboardView implements public void setKeyboard(final Keyboard keyboard) { super.setKeyboard(keyboard); mKeyDetector.setKeyboard(keyboard, 0 /* correctionX */, 0 /* correctionY */); + if (AccessibilityUtils.getInstance().isAccessibilityEnabled()) { + if (mAccessibilityDelegate == null) { + mAccessibilityDelegate = new KeyboardAccessibilityDelegate<>(this, mKeyDetector); + } + mAccessibilityDelegate.setKeyboard(keyboard); + } else { + mAccessibilityDelegate = null; + } } /** @@ -88,8 +95,10 @@ final class EmojiPageKeyboardView extends KeyboardView implements */ @Override public boolean onHoverEvent(final MotionEvent event) { - if (AccessibilityUtils.getInstance().isTouchExplorationEnabled()) { - return mAccessibilityDelegate.onHoverEvent(event); + final KeyboardAccessibilityDelegate accessibilityDelegate = + mAccessibilityDelegate; + if (accessibilityDelegate != null) { + return accessibilityDelegate.onHoverEvent(event); } return super.onHoverEvent(event); } diff --git a/java/src/com/android/inputmethod/latin/suggestions/MoreSuggestionsView.java b/java/src/com/android/inputmethod/latin/suggestions/MoreSuggestionsView.java index 79a735ad6..528d500d2 100644 --- a/java/src/com/android/inputmethod/latin/suggestions/MoreSuggestionsView.java +++ b/java/src/com/android/inputmethod/latin/suggestions/MoreSuggestionsView.java @@ -56,10 +56,18 @@ public final class MoreSuggestionsView extends MoreKeysKeyboardView { super.setKeyboard(keyboard); // With accessibility mode off, {@link #mAccessibilityDelegate} is set to null at the // above {@link MoreKeysKeyboardView#setKeyboard(Keyboard)} call. + // With accessibility mode on, {@link #mAccessibilityDelegate} is set to a + // {@link MoreKeysKeyboardAccessibilityDelegate} object at the above + // {@link MoreKeysKeyboardView#setKeyboard(Keyboard)} call. And the object has to be + // overwritten by a {@link MoreSuggestionsAccessibilityDelegate} object here. if (AccessibilityUtils.getInstance().isAccessibilityEnabled()) { - mAccessibilityDelegate = new MoreSuggestionsAccessibilityDelegate(this, mKeyDetector); - mAccessibilityDelegate.setOpenAnnounce(R.string.spoken_open_more_suggestions); - mAccessibilityDelegate.setCloseAnnounce(R.string.spoken_close_more_suggestions); + if (!(mAccessibilityDelegate instanceof MoreSuggestionsAccessibilityDelegate)) { + mAccessibilityDelegate = new MoreSuggestionsAccessibilityDelegate( + this, mKeyDetector); + mAccessibilityDelegate.setOpenAnnounce(R.string.spoken_open_more_suggestions); + mAccessibilityDelegate.setCloseAnnounce(R.string.spoken_close_more_suggestions); + } + mAccessibilityDelegate.setKeyboard(keyboard); } }