Implement "lift-to-type" interaction. Fix event text.

Bug: 6456970
Change-Id: Idd6b84fc7a730a1e78d9c1157e3b5f22e5d49fc4
This commit is contained in:
alanv 2012-05-10 11:33:31 -07:00
parent 7c23ad92fc
commit 6662e2a40d
4 changed files with 34 additions and 5 deletions

View file

@ -90,6 +90,7 @@ public class AccessibilityEntityProvider extends AccessibilityNodeProviderCompat
final AccessibilityEvent event = AccessibilityEvent.obtain(eventType);
event.setPackageName(mKeyboardView.getContext().getPackageName());
event.setClassName(key.getClass().getName());
event.setContentDescription(keyDescription);
event.setEnabled(true);
final AccessibilityRecordCompat record = new AccessibilityRecordCompat(event);
@ -158,12 +159,12 @@ public class AccessibilityEntityProvider extends AccessibilityNodeProviderCompat
info = AccessibilityNodeInfoCompat.obtain();
info.setPackageName(mKeyboardView.getContext().getPackageName());
info.setClassName(key.getClass().getName());
info.setContentDescription(keyDescription);
info.setBoundsInParent(boundsInParent);
info.setBoundsInScreen(boundsInScreen);
info.setParent(mKeyboardView);
info.setSource(mKeyboardView, virtualViewId);
info.setBoundsInScreen(boundsInScreen);
info.setText(keyDescription);
info.setEnabled(true);
}

View file

@ -23,6 +23,7 @@ import android.support.v4.view.ViewCompat;
import android.support.v4.view.accessibility.AccessibilityEventCompat;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewConfiguration;
import android.view.accessibility.AccessibilityEvent;
import com.android.inputmethod.keyboard.Key;
@ -41,6 +42,12 @@ public class AccessibleKeyboardViewProxy extends AccessibilityDelegateCompat {
private Key mLastHoverKey = null;
/**
* Inset in pixels to look for keys when the user's finger exits the
* keyboard area. See {@link ViewConfiguration#getScaledEdgeSlop()}.
*/
private int mEdgeSlop;
public static void init(InputMethodService inputMethod) {
sInstance.initInternal(inputMethod);
}
@ -55,6 +62,7 @@ public class AccessibleKeyboardViewProxy extends AccessibilityDelegateCompat {
private void initInternal(InputMethodService inputMethod) {
mInputMethod = inputMethod;
mEdgeSlop = ViewConfiguration.get(inputMethod).getScaledEdgeSlop();
}
/**
@ -108,8 +116,14 @@ public class AccessibleKeyboardViewProxy extends AccessibilityDelegateCompat {
mLastHoverKey = key;
switch (event.getAction()) {
case MotionEvent.ACTION_HOVER_ENTER:
case MotionEvent.ACTION_HOVER_EXIT:
// Make sure we're not getting an EXIT event because the user slid
// off the keyboard area, then force a key press.
if (pointInView(x, y)) {
tracker.onRegisterKey(key);
}
//$FALL-THROUGH$
case MotionEvent.ACTION_HOVER_ENTER:
return onHoverKey(key, event);
case MotionEvent.ACTION_HOVER_MOVE:
if (key != previousKey) {
@ -122,6 +136,20 @@ public class AccessibleKeyboardViewProxy extends AccessibilityDelegateCompat {
return false;
}
/**
* Utility method to determine whether the given point, in local
* coordinates, is inside the view, where the area of the view is contracted
* by the edge slop factor.
*
* @param localX The local x-coordinate.
* @param localY The local y-coordinate.
*/
private boolean pointInView(int localX, int localY) {
return (localX >= mEdgeSlop) && (localY >= mEdgeSlop)
&& (localX < (mView.getWidth() - mEdgeSlop))
&& (localY < (mView.getHeight() - mEdgeSlop));
}
/**
* Simulates a transition between two {@link Key}s by sending a HOVER_EXIT
* on the previous key, a HOVER_ENTER on the current key, and a HOVER_MOVE

View file

@ -140,7 +140,7 @@ public class LatinKeyboardView extends KeyboardView implements PointerTracker.Ke
final PointerTracker tracker = (PointerTracker) msg.obj;
switch (msg.what) {
case MSG_REPEAT_KEY:
tracker.onRepeatKey(tracker.getKey());
tracker.onRegisterKey(tracker.getKey());
startKeyRepeatTimer(tracker, mParams.mKeyRepeatInterval);
break;
case MSG_LONGPRESS_KEY:

View file

@ -714,7 +714,7 @@ public class PointerTracker {
private void startRepeatKey(Key key) {
if (key != null && key.isRepeatable()) {
onRepeatKey(key);
onRegisterKey(key);
mTimerProxy.startKeyRepeatTimer(this);
mIsRepeatableKey = true;
} else {
@ -722,7 +722,7 @@ public class PointerTracker {
}
}
public void onRepeatKey(Key key) {
public void onRegisterKey(Key key) {
if (key != null) {
detectAndSendKey(key, key.mX, key.mY);
if (!key.altCodeWhileTyping() && !key.isModifier()) {