Holding PointerTrackerQueue inside PointerTracker
Bug: 4768084 Change-Id: Id5006e549c4018a656abd088f14a209415baafed
This commit is contained in:
parent
1bd62a5621
commit
906f03121b
3 changed files with 35 additions and 43 deletions
|
@ -200,8 +200,8 @@ public class AccessibleKeyboardViewProxy {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void fireKeyPressEvent(PointerTracker tracker, int x, int y, long eventTime) {
|
private void fireKeyPressEvent(PointerTracker tracker, int x, int y, long eventTime) {
|
||||||
tracker.onDownEvent(x, y, eventTime, null);
|
tracker.onDownEvent(x, y, eventTime);
|
||||||
tracker.onUpEvent(x, y, eventTime + DELAY_KEY_PRESS, null);
|
tracker.onUpEvent(x, y, eventTime + DELAY_KEY_PRESS);
|
||||||
}
|
}
|
||||||
|
|
||||||
private class KeyboardFlickGestureDetector extends FlickGestureDetector {
|
private class KeyboardFlickGestureDetector extends FlickGestureDetector {
|
||||||
|
|
|
@ -74,7 +74,7 @@ public class LatinKeyboardBaseView extends KeyboardView {
|
||||||
private final ArrayList<PointerTracker> mPointerTrackers = new ArrayList<PointerTracker>();
|
private final ArrayList<PointerTracker> mPointerTrackers = new ArrayList<PointerTracker>();
|
||||||
|
|
||||||
// TODO: Let the PointerTracker class manage this pointer queue
|
// TODO: Let the PointerTracker class manage this pointer queue
|
||||||
private final PointerTrackerQueue mPointerQueue = new PointerTrackerQueue();
|
private final PointerTrackerQueue mPointerQueue;
|
||||||
|
|
||||||
private final boolean mHasDistinctMultitouch;
|
private final boolean mHasDistinctMultitouch;
|
||||||
private int mOldPointerCount = 1;
|
private int mOldPointerCount = 1;
|
||||||
|
@ -268,6 +268,8 @@ public class LatinKeyboardBaseView extends KeyboardView {
|
||||||
mHasDistinctMultitouch = context.getPackageManager()
|
mHasDistinctMultitouch = context.getPackageManager()
|
||||||
.hasSystemFeature(PackageManager.FEATURE_TOUCHSCREEN_MULTITOUCH_DISTINCT);
|
.hasSystemFeature(PackageManager.FEATURE_TOUCHSCREEN_MULTITOUCH_DISTINCT);
|
||||||
mKeyRepeatInterval = res.getInteger(R.integer.config_key_repeat_interval);
|
mKeyRepeatInterval = res.getInteger(R.integer.config_key_repeat_interval);
|
||||||
|
|
||||||
|
mPointerQueue = mHasDistinctMultitouch ? new PointerTrackerQueue() : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void startIgnoringDoubleTap() {
|
public void startIgnoringDoubleTap() {
|
||||||
|
@ -365,20 +367,20 @@ public class LatinKeyboardBaseView extends KeyboardView {
|
||||||
boolean result = onLongPress(parentKey, tracker);
|
boolean result = onLongPress(parentKey, tracker);
|
||||||
if (result) {
|
if (result) {
|
||||||
dismissAllKeyPreviews();
|
dismissAllKeyPreviews();
|
||||||
tracker.onLongPressed(mPointerQueue);
|
tracker.onLongPressed();
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void onLongPressShiftKey(PointerTracker tracker) {
|
private void onLongPressShiftKey(PointerTracker tracker) {
|
||||||
tracker.onLongPressed(mPointerQueue);
|
tracker.onLongPressed();
|
||||||
mKeyboardActionListener.onCodeInput(Keyboard.CODE_CAPSLOCK, null, 0, 0);
|
mKeyboardActionListener.onCodeInput(Keyboard.CODE_CAPSLOCK, null, 0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void onDoubleTapShiftKey(@SuppressWarnings("unused") PointerTracker tracker) {
|
private void onDoubleTapShiftKey(@SuppressWarnings("unused") PointerTracker tracker) {
|
||||||
// When shift key is double tapped, the first tap is correctly processed as usual tap. And
|
// When shift key is double tapped, the first tap is correctly processed as usual tap. And
|
||||||
// the second tap is treated as this double tap event, so that we need not mark tracker
|
// the second tap is treated as this double tap event, so that we need not mark tracker
|
||||||
// calling setAlreadyProcessed() nor remove the tracker from mPointerQueueueue.
|
// calling setAlreadyProcessed() nor remove the tracker from mPointerQueue.
|
||||||
mKeyboardActionListener.onCodeInput(Keyboard.CODE_CAPSLOCK, null, 0, 0);
|
mKeyboardActionListener.onCodeInput(Keyboard.CODE_CAPSLOCK, null, 0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -482,7 +484,7 @@ public class LatinKeyboardBaseView extends KeyboardView {
|
||||||
for (int i = pointers.size(); i <= id; i++) {
|
for (int i = pointers.size(); i <= id; i++) {
|
||||||
final PointerTracker tracker =
|
final PointerTracker tracker =
|
||||||
new PointerTracker(i, getContext(), mKeyTimerHandler, mKeyDetector, this,
|
new PointerTracker(i, getContext(), mKeyTimerHandler, mKeyDetector, this,
|
||||||
mHasDistinctMultitouch);
|
mPointerQueue);
|
||||||
if (keyboard != null)
|
if (keyboard != null)
|
||||||
tracker.setKeyboard(keyboard, mKeyDetector);
|
tracker.setKeyboard(keyboard, mKeyDetector);
|
||||||
if (listener != null)
|
if (listener != null)
|
||||||
|
@ -565,9 +567,9 @@ public class LatinKeyboardBaseView extends KeyboardView {
|
||||||
// previous key.
|
// previous key.
|
||||||
final int newKeyIndex = tracker.getKeyIndexOn(x, y);
|
final int newKeyIndex = tracker.getKeyIndexOn(x, y);
|
||||||
if (mOldKeyIndex != newKeyIndex) {
|
if (mOldKeyIndex != newKeyIndex) {
|
||||||
tracker.onDownEvent(x, y, eventTime, null);
|
tracker.onDownEvent(x, y, eventTime);
|
||||||
if (action == MotionEvent.ACTION_UP)
|
if (action == MotionEvent.ACTION_UP)
|
||||||
tracker.onUpEvent(x, y, eventTime, null);
|
tracker.onUpEvent(x, y, eventTime);
|
||||||
}
|
}
|
||||||
} else if (pointerCount == 2 && oldPointerCount == 1) {
|
} else if (pointerCount == 2 && oldPointerCount == 1) {
|
||||||
// Single-touch to multi-touch transition.
|
// Single-touch to multi-touch transition.
|
||||||
|
@ -575,9 +577,9 @@ public class LatinKeyboardBaseView extends KeyboardView {
|
||||||
final int lastX = tracker.getLastX();
|
final int lastX = tracker.getLastX();
|
||||||
final int lastY = tracker.getLastY();
|
final int lastY = tracker.getLastY();
|
||||||
mOldKeyIndex = tracker.getKeyIndexOn(lastX, lastY);
|
mOldKeyIndex = tracker.getKeyIndexOn(lastX, lastY);
|
||||||
tracker.onUpEvent(lastX, lastY, eventTime, null);
|
tracker.onUpEvent(lastX, lastY, eventTime);
|
||||||
} else if (pointerCount == 1 && oldPointerCount == 1) {
|
} else if (pointerCount == 1 && oldPointerCount == 1) {
|
||||||
tracker.onTouchEvent(action, x, y, eventTime, null);
|
tracker.onTouchEvent(action, x, y, eventTime);
|
||||||
} else {
|
} else {
|
||||||
Log.w(TAG, "Unknown touch panel behavior: pointer count is " + pointerCount
|
Log.w(TAG, "Unknown touch panel behavior: pointer count is " + pointerCount
|
||||||
+ " (old " + oldPointerCount + ")");
|
+ " (old " + oldPointerCount + ")");
|
||||||
|
@ -585,25 +587,24 @@ public class LatinKeyboardBaseView extends KeyboardView {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
final PointerTrackerQueue queue = mPointerQueue;
|
|
||||||
if (action == MotionEvent.ACTION_MOVE) {
|
if (action == MotionEvent.ACTION_MOVE) {
|
||||||
for (int i = 0; i < pointerCount; i++) {
|
for (int i = 0; i < pointerCount; i++) {
|
||||||
final PointerTracker tracker = getPointerTracker(me.getPointerId(i));
|
final PointerTracker tracker = getPointerTracker(me.getPointerId(i));
|
||||||
tracker.onMoveEvent((int)me.getX(i), (int)me.getY(i), eventTime, queue);
|
tracker.onMoveEvent((int)me.getX(i), (int)me.getY(i), eventTime);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
final PointerTracker tracker = getPointerTracker(id);
|
final PointerTracker tracker = getPointerTracker(id);
|
||||||
switch (action) {
|
switch (action) {
|
||||||
case MotionEvent.ACTION_DOWN:
|
case MotionEvent.ACTION_DOWN:
|
||||||
case MotionEvent.ACTION_POINTER_DOWN:
|
case MotionEvent.ACTION_POINTER_DOWN:
|
||||||
tracker.onDownEvent(x, y, eventTime, queue);
|
tracker.onDownEvent(x, y, eventTime);
|
||||||
break;
|
break;
|
||||||
case MotionEvent.ACTION_UP:
|
case MotionEvent.ACTION_UP:
|
||||||
case MotionEvent.ACTION_POINTER_UP:
|
case MotionEvent.ACTION_POINTER_UP:
|
||||||
tracker.onUpEvent(x, y, eventTime, queue);
|
tracker.onUpEvent(x, y, eventTime);
|
||||||
break;
|
break;
|
||||||
case MotionEvent.ACTION_CANCEL:
|
case MotionEvent.ACTION_CANCEL:
|
||||||
tracker.onCancelEvent(x, y, eventTime, queue);
|
tracker.onCancelEvent(x, y, eventTime);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,7 +34,6 @@ import java.util.List;
|
||||||
|
|
||||||
public class PointerTracker {
|
public class PointerTracker {
|
||||||
private static final String TAG = PointerTracker.class.getSimpleName();
|
private static final String TAG = PointerTracker.class.getSimpleName();
|
||||||
private static final boolean ENABLE_ASSERTION = false;
|
|
||||||
private static final boolean DEBUG_EVENT = false;
|
private static final boolean DEBUG_EVENT = false;
|
||||||
private static final boolean DEBUG_MOVE_EVENT = false;
|
private static final boolean DEBUG_MOVE_EVENT = false;
|
||||||
private static final boolean DEBUG_LISTENER = false;
|
private static final boolean DEBUG_LISTENER = false;
|
||||||
|
@ -56,10 +55,10 @@ public class PointerTracker {
|
||||||
|
|
||||||
private final DrawingProxy mDrawingProxy;
|
private final DrawingProxy mDrawingProxy;
|
||||||
private final KeyTimerHandler mKeyTimerHandler;
|
private final KeyTimerHandler mKeyTimerHandler;
|
||||||
|
private final PointerTrackerQueue mPointerTrackerQueue;
|
||||||
private KeyDetector mKeyDetector;
|
private KeyDetector mKeyDetector;
|
||||||
private KeyboardActionListener mListener = EMPTY_LISTENER;
|
private KeyboardActionListener mListener = EMPTY_LISTENER;
|
||||||
private final KeyboardSwitcher mKeyboardSwitcher;
|
private final KeyboardSwitcher mKeyboardSwitcher;
|
||||||
private final boolean mHasDistinctMultitouch;
|
|
||||||
private final boolean mConfigSlidingKeyInputEnabled;
|
private final boolean mConfigSlidingKeyInputEnabled;
|
||||||
|
|
||||||
private final int mTouchNoiseThresholdMillis;
|
private final int mTouchNoiseThresholdMillis;
|
||||||
|
@ -112,16 +111,16 @@ public class PointerTracker {
|
||||||
};
|
};
|
||||||
|
|
||||||
public PointerTracker(int id, Context context, KeyTimerHandler keyTimerHandler,
|
public PointerTracker(int id, Context context, KeyTimerHandler keyTimerHandler,
|
||||||
KeyDetector keyDetector, DrawingProxy drawingProxy, boolean hasDistinctMultitouch) {
|
KeyDetector keyDetector, DrawingProxy drawingProxy, PointerTrackerQueue queue) {
|
||||||
if (drawingProxy == null || keyTimerHandler == null || keyDetector == null)
|
if (drawingProxy == null || keyTimerHandler == null || keyDetector == null)
|
||||||
throw new NullPointerException();
|
throw new NullPointerException();
|
||||||
mPointerId = id;
|
mPointerId = id;
|
||||||
mDrawingProxy = drawingProxy;
|
mDrawingProxy = drawingProxy;
|
||||||
mKeyTimerHandler = keyTimerHandler;
|
mKeyTimerHandler = keyTimerHandler;
|
||||||
|
mPointerTrackerQueue = queue; // This is null for non-distinct multi-touch device.
|
||||||
mKeyDetector = keyDetector;
|
mKeyDetector = keyDetector;
|
||||||
mKeyboardSwitcher = KeyboardSwitcher.getInstance();
|
mKeyboardSwitcher = KeyboardSwitcher.getInstance();
|
||||||
mKeyState = new PointerTrackerKeyState(keyDetector);
|
mKeyState = new PointerTrackerKeyState(keyDetector);
|
||||||
mHasDistinctMultitouch = hasDistinctMultitouch;
|
|
||||||
final Resources res = context.getResources();
|
final Resources res = context.getResources();
|
||||||
mConfigSlidingKeyInputEnabled = res.getBoolean(R.bool.config_sliding_key_input_enabled);
|
mConfigSlidingKeyInputEnabled = res.getBoolean(R.bool.config_sliding_key_input_enabled);
|
||||||
mDelayBeforeKeyRepeatStart = res.getInteger(R.integer.config_delay_before_key_repeat_start);
|
mDelayBeforeKeyRepeatStart = res.getInteger(R.integer.config_delay_before_key_repeat_start);
|
||||||
|
@ -273,36 +272,26 @@ public class PointerTracker {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void checkAssertion(PointerTrackerQueue queue) {
|
public void onTouchEvent(int action, int x, int y, long eventTime) {
|
||||||
if (mHasDistinctMultitouch && queue == null)
|
|
||||||
throw new RuntimeException(
|
|
||||||
"PointerTrackerQueue must be passed on distinct multi touch device");
|
|
||||||
if (!mHasDistinctMultitouch && queue != null)
|
|
||||||
throw new RuntimeException(
|
|
||||||
"PointerTrackerQueue must be null on non-distinct multi touch device");
|
|
||||||
}
|
|
||||||
|
|
||||||
public void onTouchEvent(int action, int x, int y, long eventTime, PointerTrackerQueue queue) {
|
|
||||||
switch (action) {
|
switch (action) {
|
||||||
case MotionEvent.ACTION_MOVE:
|
case MotionEvent.ACTION_MOVE:
|
||||||
onMoveEvent(x, y, eventTime, queue);
|
onMoveEvent(x, y, eventTime);
|
||||||
break;
|
break;
|
||||||
case MotionEvent.ACTION_DOWN:
|
case MotionEvent.ACTION_DOWN:
|
||||||
case MotionEvent.ACTION_POINTER_DOWN:
|
case MotionEvent.ACTION_POINTER_DOWN:
|
||||||
onDownEvent(x, y, eventTime, queue);
|
onDownEvent(x, y, eventTime);
|
||||||
break;
|
break;
|
||||||
case MotionEvent.ACTION_UP:
|
case MotionEvent.ACTION_UP:
|
||||||
case MotionEvent.ACTION_POINTER_UP:
|
case MotionEvent.ACTION_POINTER_UP:
|
||||||
onUpEvent(x, y, eventTime, queue);
|
onUpEvent(x, y, eventTime);
|
||||||
break;
|
break;
|
||||||
case MotionEvent.ACTION_CANCEL:
|
case MotionEvent.ACTION_CANCEL:
|
||||||
onCancelEvent(x, y, eventTime, queue);
|
onCancelEvent(x, y, eventTime);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onDownEvent(int x, int y, long eventTime, PointerTrackerQueue queue) {
|
public void onDownEvent(int x, int y, long eventTime) {
|
||||||
if (ENABLE_ASSERTION) checkAssertion(queue);
|
|
||||||
if (DEBUG_EVENT)
|
if (DEBUG_EVENT)
|
||||||
printTouchEvent("onDownEvent:", x, y, eventTime);
|
printTouchEvent("onDownEvent:", x, y, eventTime);
|
||||||
|
|
||||||
|
@ -321,6 +310,7 @@ public class PointerTracker {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
final PointerTrackerQueue queue = mPointerTrackerQueue;
|
||||||
if (queue != null) {
|
if (queue != null) {
|
||||||
if (isOnModifierKey(x, y)) {
|
if (isOnModifierKey(x, y)) {
|
||||||
// Before processing a down event of modifier key, all pointers already being
|
// Before processing a down event of modifier key, all pointers already being
|
||||||
|
@ -364,8 +354,7 @@ public class PointerTracker {
|
||||||
mIsInSlidingKeyInput = true;
|
mIsInSlidingKeyInput = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onMoveEvent(int x, int y, long eventTime, PointerTrackerQueue queue) {
|
public void onMoveEvent(int x, int y, long eventTime) {
|
||||||
if (ENABLE_ASSERTION) checkAssertion(queue);
|
|
||||||
if (DEBUG_MOVE_EVENT)
|
if (DEBUG_MOVE_EVENT)
|
||||||
printTouchEvent("onMoveEvent:", x, y, eventTime);
|
printTouchEvent("onMoveEvent:", x, y, eventTime);
|
||||||
if (mKeyAlreadyProcessed)
|
if (mKeyAlreadyProcessed)
|
||||||
|
@ -449,6 +438,7 @@ public class PointerTracker {
|
||||||
keyboard.updateSpacebarPreviewIcon(diff);
|
keyboard.updateSpacebarPreviewIcon(diff);
|
||||||
// Display spacebar slide language switcher.
|
// Display spacebar slide language switcher.
|
||||||
showKeyPreview(keyIndex);
|
showKeyPreview(keyIndex);
|
||||||
|
final PointerTrackerQueue queue = mPointerTrackerQueue;
|
||||||
if (queue != null)
|
if (queue != null)
|
||||||
queue.releaseAllPointersExcept(this, eventTime, true);
|
queue.releaseAllPointersExcept(this, eventTime, true);
|
||||||
}
|
}
|
||||||
|
@ -472,11 +462,11 @@ public class PointerTracker {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onUpEvent(int x, int y, long eventTime, PointerTrackerQueue queue) {
|
public void onUpEvent(int x, int y, long eventTime) {
|
||||||
if (ENABLE_ASSERTION) checkAssertion(queue);
|
|
||||||
if (DEBUG_EVENT)
|
if (DEBUG_EVENT)
|
||||||
printTouchEvent("onUpEvent :", x, y, eventTime);
|
printTouchEvent("onUpEvent :", x, y, eventTime);
|
||||||
|
|
||||||
|
final PointerTrackerQueue queue = mPointerTrackerQueue;
|
||||||
if (queue != null) {
|
if (queue != null) {
|
||||||
if (isModifier()) {
|
if (isModifier()) {
|
||||||
// Before processing an up event of modifier key, all pointers already being
|
// Before processing an up event of modifier key, all pointers already being
|
||||||
|
@ -540,8 +530,9 @@ public class PointerTracker {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onLongPressed(PointerTrackerQueue queue) {
|
public void onLongPressed() {
|
||||||
mKeyAlreadyProcessed = true;
|
mKeyAlreadyProcessed = true;
|
||||||
|
final PointerTrackerQueue queue = mPointerTrackerQueue;
|
||||||
if (queue != null) {
|
if (queue != null) {
|
||||||
// TODO: Support chording + long-press input.
|
// TODO: Support chording + long-press input.
|
||||||
queue.releaseAllPointersExcept(this, SystemClock.uptimeMillis(), true);
|
queue.releaseAllPointersExcept(this, SystemClock.uptimeMillis(), true);
|
||||||
|
@ -549,11 +540,11 @@ public class PointerTracker {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onCancelEvent(int x, int y, long eventTime, PointerTrackerQueue queue) {
|
public void onCancelEvent(int x, int y, long eventTime) {
|
||||||
if (ENABLE_ASSERTION) checkAssertion(queue);
|
|
||||||
if (DEBUG_EVENT)
|
if (DEBUG_EVENT)
|
||||||
printTouchEvent("onCancelEvt:", x, y, eventTime);
|
printTouchEvent("onCancelEvt:", x, y, eventTime);
|
||||||
|
|
||||||
|
final PointerTrackerQueue queue = mPointerTrackerQueue;
|
||||||
if (queue != null) {
|
if (queue != null) {
|
||||||
queue.releaseAllPointersExcept(this, eventTime, true);
|
queue.releaseAllPointersExcept(this, eventTime, true);
|
||||||
queue.remove(this);
|
queue.remove(this);
|
||||||
|
|
Loading…
Reference in a new issue