diff --git a/java/src/com/android/inputmethod/keyboard/MainKeyboardView.java b/java/src/com/android/inputmethod/keyboard/MainKeyboardView.java index 77877143b7ef785ea000a3983e6523f2b8038c79..bcd0cd848ea7c593fcc1b81425f0cb75bbd32bc6 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 4ca4abec6bb634dcf87724b82b3f5d8f899b3c94..0f575d30ce77ccc0d62074e4e64316de0e7b1d00 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 0166802a457bf471fd20952d649ffc9817769b61..80ba60c82c44aeed40df660f5dada2ebf8320eaf 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<EmojiPageKeyboardView> mAccessibilityDelegate; + private KeyboardAccessibilityDelegate<EmojiPageKeyboardView> 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<EmojiPageKeyboardView> 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 79a735ad6a1657805ab787bfa797cc86ccb70445..528d500d2da10df626ab8bfb1998e83452b953fc 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); } }