am 3903e0d6: Merge "Make AccessibleKeyboardViewProxy not singleton"

* commit '3903e0d6e88e21993d4b34977597bc40f6bbac14':
  Make AccessibleKeyboardViewProxy not singleton
main
Tadashi G. Takaoka 2014-05-01 03:32:00 +00:00 committed by Android Git Automerger
commit cc8d27e5c4
6 changed files with 27 additions and 86 deletions

View File

@ -68,7 +68,6 @@ public final class AccessibilityUtils {
// These only need to be initialized if the kill switch is off.
sInstance.initInternal(context);
KeyCodeDescriptionMapper.init();
AccessibleKeyboardViewProxy.init(context);
}
public static AccessibilityUtils getInstance() {

View File

@ -36,9 +36,7 @@ import com.android.inputmethod.keyboard.MainKeyboardView;
import com.android.inputmethod.latin.R;
import com.android.inputmethod.latin.utils.SubtypeLocaleUtils;
public final class AccessibleKeyboardViewProxy extends AccessibilityDelegateCompat {
private static final AccessibleKeyboardViewProxy sInstance = new AccessibleKeyboardViewProxy();
public final class MainKeyboardAccessibilityDelegate extends AccessibilityDelegateCompat {
/** Map of keyboard modes to resource IDs. */
private static final SparseIntArray KEYBOARD_MODE_RES_IDS = new SparseIntArray();
@ -54,9 +52,9 @@ public final class AccessibleKeyboardViewProxy extends AccessibilityDelegateComp
KEYBOARD_MODE_RES_IDS.put(KeyboardId.MODE_URL, R.string.keyboard_mode_url);
}
private MainKeyboardView mView;
private final MainKeyboardView mView;
private Keyboard mKeyboard;
private AccessibilityEntityProvider mAccessibilityNodeProvider;
private MainKeyboardAccessibilityNodeProvider mAccessibilityNodeProvider;
private Key mLastHoverKey = null;
@ -69,46 +67,14 @@ public final class AccessibleKeyboardViewProxy extends AccessibilityDelegateComp
private int mLastKeyboardMode = KEYBOARD_IS_HIDDEN;
private static final int KEYBOARD_IS_HIDDEN = -1;
public static void init(final Context context) {
sInstance.initInternal(context);
}
public static AccessibleKeyboardViewProxy getInstance() {
return sInstance;
}
private AccessibleKeyboardViewProxy() {
// Not publicly instantiable.
}
private void initInternal(final Context context) {
public MainKeyboardAccessibilityDelegate(final MainKeyboardView view) {
final Context context = view.getContext();
mEdgeSlop = context.getResources().getDimensionPixelSize(
R.dimen.config_accessibility_edge_slop);
}
/**
* Sets the view wrapped by this proxy.
*
* @param view The view to wrap.
*/
public void setView(final MainKeyboardView view) {
if (view == null) {
// Ignore null views.
return;
}
mView = view;
// Ensure that the view has an accessibility delegate.
ViewCompat.setAccessibilityDelegate(view, this);
if (mAccessibilityNodeProvider == null) {
return;
}
mAccessibilityNodeProvider.setView(view);
// Since this class is constructed lazily, we might not get a subsequent
// call to setKeyboard() and therefore need to call it now.
setKeyboard(view.getKeyboard());
}
/**
@ -156,9 +122,6 @@ public final class AccessibleKeyboardViewProxy extends AccessibilityDelegateComp
* Called when the keyboard is hidden and accessibility is enabled.
*/
public void onHideWindow() {
if (mView == null) {
return;
}
announceKeyboardHidden();
mLastKeyboardMode = KEYBOARD_IS_HIDDEN;
}
@ -264,7 +227,7 @@ public final class AccessibleKeyboardViewProxy extends AccessibilityDelegateComp
}
/**
* Proxy method for View.getAccessibilityNodeProvider(). This method is called in SDK
* Delegate method for View.getAccessibilityNodeProvider(). This method is called in SDK
* version 15 (Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1) and higher to obtain the virtual
* node hierarchy provider.
*
@ -272,10 +235,7 @@ public final class AccessibleKeyboardViewProxy extends AccessibilityDelegateComp
* @return The accessibility node provider for the current keyboard.
*/
@Override
public AccessibilityEntityProvider getAccessibilityNodeProvider(final View host) {
if (mView == null) {
return null;
}
public MainKeyboardAccessibilityNodeProvider getAccessibilityNodeProvider(final View host) {
return getAccessibilityNodeProvider();
}
@ -288,10 +248,6 @@ public final class AccessibleKeyboardViewProxy extends AccessibilityDelegateComp
* @return {@code true} if the event is handled
*/
public boolean dispatchHoverEvent(final MotionEvent event, final KeyDetector keyDetector) {
if (mView == null) {
return false;
}
final int x = (int) event.getX();
final int y = (int) event.getY();
final Key previousKey = mLastHoverKey;
@ -325,14 +281,14 @@ public final class AccessibleKeyboardViewProxy extends AccessibilityDelegateComp
}
/**
* @return A lazily-instantiated node provider for this view proxy.
* @return A lazily-instantiated node provider for this view delegate.
*/
private AccessibilityEntityProvider getAccessibilityNodeProvider() {
private MainKeyboardAccessibilityNodeProvider getAccessibilityNodeProvider() {
// Instantiate the provide only when requested. Since the system
// will call this method multiple times it is a good practice to
// cache the provider instance.
if (mAccessibilityNodeProvider == null) {
mAccessibilityNodeProvider = new AccessibilityEntityProvider(mView);
mAccessibilityNodeProvider = new MainKeyboardAccessibilityNodeProvider(mView);
}
return mAccessibilityNodeProvider;
}
@ -417,7 +373,7 @@ public final class AccessibleKeyboardViewProxy extends AccessibilityDelegateComp
if (key == null) {
return false;
}
final AccessibilityEntityProvider provider = getAccessibilityNodeProvider();
final MainKeyboardAccessibilityNodeProvider provider = getAccessibilityNodeProvider();
switch (event.getAction()) {
case MotionEvent.ACTION_HOVER_ENTER:

View File

@ -47,8 +47,8 @@ import java.util.List;
* virtual views, thus conveying their logical structure.
* </p>
*/
public final class AccessibilityEntityProvider extends AccessibilityNodeProviderCompat {
private static final String TAG = AccessibilityEntityProvider.class.getSimpleName();
public final class MainKeyboardAccessibilityNodeProvider extends AccessibilityNodeProviderCompat {
private static final String TAG = MainKeyboardAccessibilityNodeProvider.class.getSimpleName();
private static final int UNDEFINED = Integer.MIN_VALUE;
private final KeyCodeDescriptionMapper mKeyCodeDescriptionMapper;
@ -64,23 +64,14 @@ public final class AccessibilityEntityProvider extends AccessibilityNodeProvider
private int mAccessibilityFocusedView = UNDEFINED;
/** The current keyboard view. */
private KeyboardView mKeyboardView;
private final KeyboardView mKeyboardView;
/** The current keyboard. */
private Keyboard mKeyboard;
public AccessibilityEntityProvider(final KeyboardView keyboardView) {
public MainKeyboardAccessibilityNodeProvider(final KeyboardView keyboardView) {
mKeyCodeDescriptionMapper = KeyCodeDescriptionMapper.getInstance();
mAccessibilityUtils = AccessibilityUtils.getInstance();
setView(keyboardView);
}
/**
* Sets the keyboard view represented by this node provider.
*
* @param keyboardView The keyboard view to represent.
*/
public void setView(final KeyboardView keyboardView) {
mKeyboardView = keyboardView;
updateParentLocation();

View File

@ -26,7 +26,6 @@ import android.view.LayoutInflater;
import android.view.View;
import android.view.inputmethod.EditorInfo;
import com.android.inputmethod.accessibility.AccessibleKeyboardViewProxy;
import com.android.inputmethod.compat.InputMethodServiceCompatUtils;
import com.android.inputmethod.keyboard.KeyboardLayoutSet.KeyboardLayoutSetException;
import com.android.inputmethod.keyboard.internal.KeyboardState;
@ -148,6 +147,7 @@ public final class KeyboardSwitcher implements KeyboardState.SwitchActions {
public void onHideWindow() {
mIsAutoCorrectionActive = false;
mKeyboardView.onHideWindow();
}
private void setKeyboard(final Keyboard keyboard) {
@ -353,11 +353,6 @@ public final class KeyboardSwitcher implements KeyboardState.SwitchActions {
mEmojiPalettesView.setHardwareAcceleratedDrawingEnabled(
isHardwareAcceleratedDrawingEnabled);
mEmojiPalettesView.setKeyboardActionListener(mLatinIME);
// This always needs to be set since the accessibility state can
// potentially change without the input view being re-created.
AccessibleKeyboardViewProxy.getInstance().setView(mKeyboardView);
return mCurrentInputView;
}

View File

@ -39,7 +39,7 @@ import android.view.inputmethod.InputMethodSubtype;
import android.widget.TextView;
import com.android.inputmethod.accessibility.AccessibilityUtils;
import com.android.inputmethod.accessibility.AccessibleKeyboardViewProxy;
import com.android.inputmethod.accessibility.MainKeyboardAccessibilityDelegate;
import com.android.inputmethod.annotations.ExternallyReferenced;
import com.android.inputmethod.keyboard.internal.DrawingHandler;
import com.android.inputmethod.keyboard.internal.DrawingPreviewPlacerView;
@ -179,6 +179,8 @@ public final class MainKeyboardView extends KeyboardView implements PointerTrack
private final DrawingHandler mDrawingHandler =
new DrawingHandler(this);
private final MainKeyboardAccessibilityDelegate mAccessibilityDelegate;
public MainKeyboardView(final Context context, final AttributeSet attrs) {
this(context, attrs, R.attr.mainKeyboardViewStyle);
}
@ -278,6 +280,8 @@ public final class MainKeyboardView extends KeyboardView implements PointerTrack
mLanguageOnSpacebarHorizontalMargin = (int)getResources().getDimension(
R.dimen.config_language_on_spacebar_horizontal_margin);
mAccessibilityDelegate = new MainKeyboardAccessibilityDelegate(this);
}
@Override
@ -404,9 +408,7 @@ public final class MainKeyboardView extends KeyboardView implements PointerTrack
ResearchLogger.mainKeyboardView_setKeyboard(keyboard, orientation);
}
// This always needs to be set since the accessibility state can
// potentially change without the keyboard being set again.
AccessibleKeyboardViewProxy.getInstance().setKeyboard(keyboard);
mAccessibilityDelegate.setKeyboard(keyboard);
}
/**
@ -769,6 +771,10 @@ public final class MainKeyboardView extends KeyboardView implements PointerTrack
mMoreKeysKeyboardCache.clear();
}
public void onHideWindow() {
mAccessibilityDelegate.onHideWindow();
}
/**
* Receives hover events from the input framework.
*
@ -779,8 +785,7 @@ public final class MainKeyboardView extends KeyboardView implements PointerTrack
@Override
public boolean dispatchHoverEvent(final MotionEvent event) {
if (AccessibilityUtils.getInstance().isTouchExplorationEnabled()) {
return AccessibleKeyboardViewProxy.getInstance().dispatchHoverEvent(
event, mKeyDetector);
return mAccessibilityDelegate.dispatchHoverEvent(event, mKeyDetector);
}
// Reflection doesn't support calling superclass methods.

View File

@ -55,7 +55,6 @@ import android.view.inputmethod.EditorInfo;
import android.view.inputmethod.InputMethodSubtype;
import com.android.inputmethod.accessibility.AccessibilityUtils;
import com.android.inputmethod.accessibility.AccessibleKeyboardViewProxy;
import com.android.inputmethod.annotations.UsedForTesting;
import com.android.inputmethod.compat.InputMethodServiceCompatUtils;
import com.android.inputmethod.dictionarypack.DictionaryPackConstants;
@ -1002,10 +1001,6 @@ public class LatinIME extends InputMethodService implements KeyboardActionListen
LatinImeLogger.commit();
mKeyboardSwitcher.onHideWindow();
if (AccessibilityUtils.getInstance().isAccessibilityEnabled()) {
AccessibleKeyboardViewProxy.getInstance().onHideWindow();
}
if (TRACE) Debug.stopMethodTracing();
if (isShowingOptionDialog()) {
mOptionsDialog.dismiss();