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
This commit is contained in:
Tadashi G. Takaoka 2014-06-07 23:28:13 +09:00
parent 86a28db7f9
commit dec599d172
4 changed files with 34 additions and 12 deletions

View file

@ -382,7 +382,9 @@ public final class MainKeyboardView extends KeyboardView implements PointerTrack
mLanguageOnSpacebarTextSize = keyHeight * mLanguageOnSpacebarTextRatio;
if (AccessibilityUtils.getInstance().isAccessibilityEnabled()) {
if (mAccessibilityDelegate == null) {
mAccessibilityDelegate = new MainKeyboardAccessibilityDelegate(this, mKeyDetector);
}
mAccessibilityDelegate.setKeyboard(keyboard);
} else {
mAccessibilityDelegate = null;

View file

@ -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.
if (mAccessibilityDelegate == null) {
mKeyDetector = new KeyDetector();
mAccessibilityDelegate = new MoreKeysKeyboardAccessibilityDelegate(this, mKeyDetector);
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(

View file

@ -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);
}

View file

@ -56,11 +56,19 @@ 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);
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);
}
}
@Override