am b99788c3: Merge "Update keyboard view used by node provider. Remove global layout listener." into jb-dev

* commit 'b99788c3b8382d81dfa4353312c3c4828ac30557':
  Update keyboard view used by node provider. Remove global layout listener.
main
Charles Chen 2012-05-31 11:14:11 -07:00 committed by Android Git Automerger
commit c764fd80b5
2 changed files with 20 additions and 16 deletions

View File

@ -29,7 +29,6 @@ import android.util.Log;
import android.util.SparseArray; import android.util.SparseArray;
import android.view.MotionEvent; import android.view.MotionEvent;
import android.view.View; import android.view.View;
import android.view.ViewTreeObserver.OnGlobalLayoutListener;
import android.view.accessibility.AccessibilityEvent; import android.view.accessibility.AccessibilityEvent;
import android.view.inputmethod.EditorInfo; import android.view.inputmethod.EditorInfo;
@ -51,7 +50,6 @@ public class AccessibilityEntityProvider extends AccessibilityNodeProviderCompat
private static final String TAG = AccessibilityEntityProvider.class.getSimpleName(); private static final String TAG = AccessibilityEntityProvider.class.getSimpleName();
private static final int UNDEFINED = Integer.MIN_VALUE; private static final int UNDEFINED = Integer.MIN_VALUE;
private final KeyboardView mKeyboardView;
private final InputMethodService mInputMethodService; private final InputMethodService mInputMethodService;
private final KeyCodeDescriptionMapper mKeyCodeDescriptionMapper; private final KeyCodeDescriptionMapper mKeyCodeDescriptionMapper;
private final AccessibilityUtils mAccessibilityUtils; private final AccessibilityUtils mAccessibilityUtils;
@ -68,18 +66,28 @@ public class AccessibilityEntityProvider extends AccessibilityNodeProviderCompat
/** The virtual view identifier for the focused node. */ /** The virtual view identifier for the focused node. */
private int mAccessibilityFocusedView = UNDEFINED; private int mAccessibilityFocusedView = UNDEFINED;
/** The current keyboard view. */
private KeyboardView mKeyboardView;
public AccessibilityEntityProvider(KeyboardView keyboardView, InputMethodService inputMethod) { public AccessibilityEntityProvider(KeyboardView keyboardView, InputMethodService inputMethod) {
mKeyboardView = keyboardView;
mInputMethodService = inputMethod; mInputMethodService = inputMethod;
mKeyCodeDescriptionMapper = KeyCodeDescriptionMapper.getInstance(); mKeyCodeDescriptionMapper = KeyCodeDescriptionMapper.getInstance();
mAccessibilityUtils = AccessibilityUtils.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(KeyboardView keyboardView) {
mKeyboardView = keyboardView;
assignVirtualViewIds(); assignVirtualViewIds();
updateParentLocation(); updateParentLocation();
// Ensure that the on-screen bounds are cleared when the layout changes.
mKeyboardView.getViewTreeObserver().addOnGlobalLayoutListener(mGlobalLayoutListener);
} }
/** /**
@ -196,8 +204,8 @@ public class AccessibilityEntityProvider extends AccessibilityNodeProviderCompat
* @param key The key to press. * @param key The key to press.
*/ */
void simulateKeyPress(Key key) { void simulateKeyPress(Key key) {
final int x = key.mX + (key.mWidth / 2); final int x = key.mHitBox.centerX();
final int y = key.mY + (key.mHeight / 2); final int y = key.mHitBox.centerY();
final long downTime = SystemClock.uptimeMillis(); final long downTime = SystemClock.uptimeMillis();
final MotionEvent downEvent = MotionEvent.obtain( final MotionEvent downEvent = MotionEvent.obtain(
downTime, downTime, MotionEvent.ACTION_DOWN, x, y, 0); downTime, downTime, MotionEvent.ACTION_DOWN, x, y, 0);
@ -331,12 +339,4 @@ public class AccessibilityEntityProvider extends AccessibilityNodeProviderCompat
// left-half of the integer and OR'ing with the y-coordinate. // left-half of the integer and OR'ing with the y-coordinate.
return ((0xFFFF & key.mX) << (Integer.SIZE / 2)) | (0xFFFF & key.mY); return ((0xFFFF & key.mX) << (Integer.SIZE / 2)) | (0xFFFF & key.mY);
} }
private final OnGlobalLayoutListener mGlobalLayoutListener = new OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
assignVirtualViewIds();
updateParentLocation();
}
};
} }

View File

@ -80,6 +80,10 @@ public class AccessibleKeyboardViewProxy extends AccessibilityDelegateCompat {
// Ensure that the view has an accessibility delegate. // Ensure that the view has an accessibility delegate.
ViewCompat.setAccessibilityDelegate(view, this); ViewCompat.setAccessibilityDelegate(view, this);
if (mAccessibilityNodeProvider != null) {
mAccessibilityNodeProvider.setView(view);
}
} }
/** /**