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:
parent
86a28db7f9
commit
dec599d172
4 changed files with 34 additions and 12 deletions
|
@ -382,7 +382,9 @@ public final class MainKeyboardView extends KeyboardView implements PointerTrack
|
||||||
mLanguageOnSpacebarTextSize = keyHeight * mLanguageOnSpacebarTextRatio;
|
mLanguageOnSpacebarTextSize = keyHeight * mLanguageOnSpacebarTextRatio;
|
||||||
|
|
||||||
if (AccessibilityUtils.getInstance().isAccessibilityEnabled()) {
|
if (AccessibilityUtils.getInstance().isAccessibilityEnabled()) {
|
||||||
mAccessibilityDelegate = new MainKeyboardAccessibilityDelegate(this, mKeyDetector);
|
if (mAccessibilityDelegate == null) {
|
||||||
|
mAccessibilityDelegate = new MainKeyboardAccessibilityDelegate(this, mKeyDetector);
|
||||||
|
}
|
||||||
mAccessibilityDelegate.setKeyboard(keyboard);
|
mAccessibilityDelegate.setKeyboard(keyboard);
|
||||||
} else {
|
} else {
|
||||||
mAccessibilityDelegate = null;
|
mAccessibilityDelegate = null;
|
||||||
|
|
|
@ -77,10 +77,13 @@ public class MoreKeysKeyboardView extends KeyboardView implements MoreKeysPanel
|
||||||
// discarded at {@link InputView#dispatchHoverEvent(MotionEvent)}. Because only a hover
|
// 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
|
// 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.
|
// {@link KeyDetector} that has no sliding allowance and no hysteresis.
|
||||||
mKeyDetector = new KeyDetector();
|
if (mAccessibilityDelegate == null) {
|
||||||
mAccessibilityDelegate = new MoreKeysKeyboardAccessibilityDelegate(this, mKeyDetector);
|
mKeyDetector = new KeyDetector();
|
||||||
mAccessibilityDelegate.setOpenAnnounce(R.string.spoken_open_more_keys_keyboard);
|
mAccessibilityDelegate = new MoreKeysKeyboardAccessibilityDelegate(
|
||||||
mAccessibilityDelegate.setCloseAnnounce(R.string.spoken_close_more_keys_keyboard);
|
this, mKeyDetector);
|
||||||
|
mAccessibilityDelegate.setOpenAnnounce(R.string.spoken_open_more_keys_keyboard);
|
||||||
|
mAccessibilityDelegate.setCloseAnnounce(R.string.spoken_close_more_keys_keyboard);
|
||||||
|
}
|
||||||
mAccessibilityDelegate.setKeyboard(keyboard);
|
mAccessibilityDelegate.setKeyboard(keyboard);
|
||||||
} else {
|
} else {
|
||||||
mKeyDetector = new MoreKeysDetector(getResources().getDimension(
|
mKeyDetector = new MoreKeysDetector(getResources().getDimension(
|
||||||
|
|
|
@ -55,7 +55,7 @@ final class EmojiPageKeyboardView extends KeyboardView implements
|
||||||
private OnKeyEventListener mListener = EMPTY_LISTENER;
|
private OnKeyEventListener mListener = EMPTY_LISTENER;
|
||||||
private final KeyDetector mKeyDetector = new KeyDetector();
|
private final KeyDetector mKeyDetector = new KeyDetector();
|
||||||
private final GestureDetector mGestureDetector;
|
private final GestureDetector mGestureDetector;
|
||||||
private final KeyboardAccessibilityDelegate<EmojiPageKeyboardView> mAccessibilityDelegate;
|
private KeyboardAccessibilityDelegate<EmojiPageKeyboardView> mAccessibilityDelegate;
|
||||||
|
|
||||||
public EmojiPageKeyboardView(final Context context, final AttributeSet attrs) {
|
public EmojiPageKeyboardView(final Context context, final AttributeSet attrs) {
|
||||||
this(context, attrs, R.attr.keyboardViewStyle);
|
this(context, attrs, R.attr.keyboardViewStyle);
|
||||||
|
@ -67,7 +67,6 @@ final class EmojiPageKeyboardView extends KeyboardView implements
|
||||||
mGestureDetector = new GestureDetector(context, this);
|
mGestureDetector = new GestureDetector(context, this);
|
||||||
mGestureDetector.setIsLongpressEnabled(false /* isLongpressEnabled */);
|
mGestureDetector.setIsLongpressEnabled(false /* isLongpressEnabled */);
|
||||||
mHandler = new Handler();
|
mHandler = new Handler();
|
||||||
mAccessibilityDelegate = new KeyboardAccessibilityDelegate<>(this, mKeyDetector);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setOnKeyEventListener(final OnKeyEventListener listener) {
|
public void setOnKeyEventListener(final OnKeyEventListener listener) {
|
||||||
|
@ -81,6 +80,14 @@ final class EmojiPageKeyboardView extends KeyboardView implements
|
||||||
public void setKeyboard(final Keyboard keyboard) {
|
public void setKeyboard(final Keyboard keyboard) {
|
||||||
super.setKeyboard(keyboard);
|
super.setKeyboard(keyboard);
|
||||||
mKeyDetector.setKeyboard(keyboard, 0 /* correctionX */, 0 /* correctionY */);
|
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
|
@Override
|
||||||
public boolean onHoverEvent(final MotionEvent event) {
|
public boolean onHoverEvent(final MotionEvent event) {
|
||||||
if (AccessibilityUtils.getInstance().isTouchExplorationEnabled()) {
|
final KeyboardAccessibilityDelegate<EmojiPageKeyboardView> accessibilityDelegate =
|
||||||
return mAccessibilityDelegate.onHoverEvent(event);
|
mAccessibilityDelegate;
|
||||||
|
if (accessibilityDelegate != null) {
|
||||||
|
return accessibilityDelegate.onHoverEvent(event);
|
||||||
}
|
}
|
||||||
return super.onHoverEvent(event);
|
return super.onHoverEvent(event);
|
||||||
}
|
}
|
||||||
|
|
|
@ -56,10 +56,18 @@ public final class MoreSuggestionsView extends MoreKeysKeyboardView {
|
||||||
super.setKeyboard(keyboard);
|
super.setKeyboard(keyboard);
|
||||||
// With accessibility mode off, {@link #mAccessibilityDelegate} is set to null at the
|
// With accessibility mode off, {@link #mAccessibilityDelegate} is set to null at the
|
||||||
// above {@link MoreKeysKeyboardView#setKeyboard(Keyboard)} call.
|
// 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()) {
|
if (AccessibilityUtils.getInstance().isAccessibilityEnabled()) {
|
||||||
mAccessibilityDelegate = new MoreSuggestionsAccessibilityDelegate(this, mKeyDetector);
|
if (!(mAccessibilityDelegate instanceof MoreSuggestionsAccessibilityDelegate)) {
|
||||||
mAccessibilityDelegate.setOpenAnnounce(R.string.spoken_open_more_suggestions);
|
mAccessibilityDelegate = new MoreSuggestionsAccessibilityDelegate(
|
||||||
mAccessibilityDelegate.setCloseAnnounce(R.string.spoken_close_more_suggestions);
|
this, mKeyDetector);
|
||||||
|
mAccessibilityDelegate.setOpenAnnounce(R.string.spoken_open_more_suggestions);
|
||||||
|
mAccessibilityDelegate.setCloseAnnounce(R.string.spoken_close_more_suggestions);
|
||||||
|
}
|
||||||
|
mAccessibilityDelegate.setKeyboard(keyboard);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue