Holding PointerTrackerQueue inside PointerTracker

Bug: 4768084
Change-Id: Id5006e549c4018a656abd088f14a209415baafed
This commit is contained in:
Tadashi G. Takaoka 2011-07-06 16:11:30 -07:00
parent 1bd62a5621
commit 906f03121b
3 changed files with 35 additions and 43 deletions

View file

@ -200,8 +200,8 @@ public class AccessibleKeyboardViewProxy {
}
private void fireKeyPressEvent(PointerTracker tracker, int x, int y, long eventTime) {
tracker.onDownEvent(x, y, eventTime, null);
tracker.onUpEvent(x, y, eventTime + DELAY_KEY_PRESS, null);
tracker.onDownEvent(x, y, eventTime);
tracker.onUpEvent(x, y, eventTime + DELAY_KEY_PRESS);
}
private class KeyboardFlickGestureDetector extends FlickGestureDetector {

View file

@ -74,7 +74,7 @@ public class LatinKeyboardBaseView extends KeyboardView {
private final ArrayList<PointerTracker> mPointerTrackers = new ArrayList<PointerTracker>();
// TODO: Let the PointerTracker class manage this pointer queue
private final PointerTrackerQueue mPointerQueue = new PointerTrackerQueue();
private final PointerTrackerQueue mPointerQueue;
private final boolean mHasDistinctMultitouch;
private int mOldPointerCount = 1;
@ -268,6 +268,8 @@ public class LatinKeyboardBaseView extends KeyboardView {
mHasDistinctMultitouch = context.getPackageManager()
.hasSystemFeature(PackageManager.FEATURE_TOUCHSCREEN_MULTITOUCH_DISTINCT);
mKeyRepeatInterval = res.getInteger(R.integer.config_key_repeat_interval);
mPointerQueue = mHasDistinctMultitouch ? new PointerTrackerQueue() : null;
}
public void startIgnoringDoubleTap() {
@ -365,20 +367,20 @@ public class LatinKeyboardBaseView extends KeyboardView {
boolean result = onLongPress(parentKey, tracker);
if (result) {
dismissAllKeyPreviews();
tracker.onLongPressed(mPointerQueue);
tracker.onLongPressed();
}
return result;
}
private void onLongPressShiftKey(PointerTracker tracker) {
tracker.onLongPressed(mPointerQueue);
tracker.onLongPressed();
mKeyboardActionListener.onCodeInput(Keyboard.CODE_CAPSLOCK, null, 0, 0);
}
private void onDoubleTapShiftKey(@SuppressWarnings("unused") PointerTracker tracker) {
// 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
// calling setAlreadyProcessed() nor remove the tracker from mPointerQueueueue.
// calling setAlreadyProcessed() nor remove the tracker from mPointerQueue.
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++) {
final PointerTracker tracker =
new PointerTracker(i, getContext(), mKeyTimerHandler, mKeyDetector, this,
mHasDistinctMultitouch);
mPointerQueue);
if (keyboard != null)
tracker.setKeyboard(keyboard, mKeyDetector);
if (listener != null)
@ -565,9 +567,9 @@ public class LatinKeyboardBaseView extends KeyboardView {
// previous key.
final int newKeyIndex = tracker.getKeyIndexOn(x, y);
if (mOldKeyIndex != newKeyIndex) {
tracker.onDownEvent(x, y, eventTime, null);
tracker.onDownEvent(x, y, eventTime);
if (action == MotionEvent.ACTION_UP)
tracker.onUpEvent(x, y, eventTime, null);
tracker.onUpEvent(x, y, eventTime);
}
} else if (pointerCount == 2 && oldPointerCount == 1) {
// Single-touch to multi-touch transition.
@ -575,9 +577,9 @@ public class LatinKeyboardBaseView extends KeyboardView {
final int lastX = tracker.getLastX();
final int lastY = tracker.getLastY();
mOldKeyIndex = tracker.getKeyIndexOn(lastX, lastY);
tracker.onUpEvent(lastX, lastY, eventTime, null);
tracker.onUpEvent(lastX, lastY, eventTime);
} else if (pointerCount == 1 && oldPointerCount == 1) {
tracker.onTouchEvent(action, x, y, eventTime, null);
tracker.onTouchEvent(action, x, y, eventTime);
} else {
Log.w(TAG, "Unknown touch panel behavior: pointer count is " + pointerCount
+ " (old " + oldPointerCount + ")");
@ -585,25 +587,24 @@ public class LatinKeyboardBaseView extends KeyboardView {
return true;
}
final PointerTrackerQueue queue = mPointerQueue;
if (action == MotionEvent.ACTION_MOVE) {
for (int i = 0; i < pointerCount; 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 {
final PointerTracker tracker = getPointerTracker(id);
switch (action) {
case MotionEvent.ACTION_DOWN:
case MotionEvent.ACTION_POINTER_DOWN:
tracker.onDownEvent(x, y, eventTime, queue);
tracker.onDownEvent(x, y, eventTime);
break;
case MotionEvent.ACTION_UP:
case MotionEvent.ACTION_POINTER_UP:
tracker.onUpEvent(x, y, eventTime, queue);
tracker.onUpEvent(x, y, eventTime);
break;
case MotionEvent.ACTION_CANCEL:
tracker.onCancelEvent(x, y, eventTime, queue);
tracker.onCancelEvent(x, y, eventTime);
break;
}
}

View file

@ -34,7 +34,6 @@ import java.util.List;
public class PointerTracker {
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_MOVE_EVENT = false;
private static final boolean DEBUG_LISTENER = false;
@ -56,10 +55,10 @@ public class PointerTracker {
private final DrawingProxy mDrawingProxy;
private final KeyTimerHandler mKeyTimerHandler;
private final PointerTrackerQueue mPointerTrackerQueue;
private KeyDetector mKeyDetector;
private KeyboardActionListener mListener = EMPTY_LISTENER;
private final KeyboardSwitcher mKeyboardSwitcher;
private final boolean mHasDistinctMultitouch;
private final boolean mConfigSlidingKeyInputEnabled;
private final int mTouchNoiseThresholdMillis;
@ -112,16 +111,16 @@ public class PointerTracker {
};
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)
throw new NullPointerException();
mPointerId = id;
mDrawingProxy = drawingProxy;
mKeyTimerHandler = keyTimerHandler;
mPointerTrackerQueue = queue; // This is null for non-distinct multi-touch device.
mKeyDetector = keyDetector;
mKeyboardSwitcher = KeyboardSwitcher.getInstance();
mKeyState = new PointerTrackerKeyState(keyDetector);
mHasDistinctMultitouch = hasDistinctMultitouch;
final Resources res = context.getResources();
mConfigSlidingKeyInputEnabled = res.getBoolean(R.bool.config_sliding_key_input_enabled);
mDelayBeforeKeyRepeatStart = res.getInteger(R.integer.config_delay_before_key_repeat_start);
@ -273,36 +272,26 @@ public class PointerTracker {
}
}
private void checkAssertion(PointerTrackerQueue queue) {
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) {
public void onTouchEvent(int action, int x, int y, long eventTime) {
switch (action) {
case MotionEvent.ACTION_MOVE:
onMoveEvent(x, y, eventTime, queue);
onMoveEvent(x, y, eventTime);
break;
case MotionEvent.ACTION_DOWN:
case MotionEvent.ACTION_POINTER_DOWN:
onDownEvent(x, y, eventTime, queue);
onDownEvent(x, y, eventTime);
break;
case MotionEvent.ACTION_UP:
case MotionEvent.ACTION_POINTER_UP:
onUpEvent(x, y, eventTime, queue);
onUpEvent(x, y, eventTime);
break;
case MotionEvent.ACTION_CANCEL:
onCancelEvent(x, y, eventTime, queue);
onCancelEvent(x, y, eventTime);
break;
}
}
public void onDownEvent(int x, int y, long eventTime, PointerTrackerQueue queue) {
if (ENABLE_ASSERTION) checkAssertion(queue);
public void onDownEvent(int x, int y, long eventTime) {
if (DEBUG_EVENT)
printTouchEvent("onDownEvent:", x, y, eventTime);
@ -321,6 +310,7 @@ public class PointerTracker {
}
}
final PointerTrackerQueue queue = mPointerTrackerQueue;
if (queue != null) {
if (isOnModifierKey(x, y)) {
// Before processing a down event of modifier key, all pointers already being
@ -364,8 +354,7 @@ public class PointerTracker {
mIsInSlidingKeyInput = true;
}
public void onMoveEvent(int x, int y, long eventTime, PointerTrackerQueue queue) {
if (ENABLE_ASSERTION) checkAssertion(queue);
public void onMoveEvent(int x, int y, long eventTime) {
if (DEBUG_MOVE_EVENT)
printTouchEvent("onMoveEvent:", x, y, eventTime);
if (mKeyAlreadyProcessed)
@ -449,6 +438,7 @@ public class PointerTracker {
keyboard.updateSpacebarPreviewIcon(diff);
// Display spacebar slide language switcher.
showKeyPreview(keyIndex);
final PointerTrackerQueue queue = mPointerTrackerQueue;
if (queue != null)
queue.releaseAllPointersExcept(this, eventTime, true);
}
@ -472,11 +462,11 @@ public class PointerTracker {
}
}
public void onUpEvent(int x, int y, long eventTime, PointerTrackerQueue queue) {
if (ENABLE_ASSERTION) checkAssertion(queue);
public void onUpEvent(int x, int y, long eventTime) {
if (DEBUG_EVENT)
printTouchEvent("onUpEvent :", x, y, eventTime);
final PointerTrackerQueue queue = mPointerTrackerQueue;
if (queue != null) {
if (isModifier()) {
// 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;
final PointerTrackerQueue queue = mPointerTrackerQueue;
if (queue != null) {
// TODO: Support chording + long-press input.
queue.releaseAllPointersExcept(this, SystemClock.uptimeMillis(), true);
@ -549,11 +540,11 @@ public class PointerTracker {
}
}
public void onCancelEvent(int x, int y, long eventTime, PointerTrackerQueue queue) {
if (ENABLE_ASSERTION) checkAssertion(queue);
public void onCancelEvent(int x, int y, long eventTime) {
if (DEBUG_EVENT)
printTouchEvent("onCancelEvt:", x, y, eventTime);
final PointerTrackerQueue queue = mPointerTrackerQueue;
if (queue != null) {
queue.releaseAllPointersExcept(this, eventTime, true);
queue.remove(this);