Improve incremental gesture tracking.

Eliminates need to recreate batch InputPointers on each gesture move event.
Fixes issue where batch points from previous tapping input get mixed into next gesture.

Change-Id: I9ecac66db88f5a87c6dde2138408906dd3d11139
This commit is contained in:
Tom Ouyang 2012-07-19 21:53:42 +09:00
parent 9370ab9ada
commit 0c5f72e2bf
2 changed files with 20 additions and 11 deletions

View file

@ -121,6 +121,8 @@ public class PointerTracker {
private static boolean sConfigGestureInputEnabledByBuildConfig; private static boolean sConfigGestureInputEnabledByBuildConfig;
private static final ArrayList<PointerTracker> sTrackers = new ArrayList<PointerTracker>(); private static final ArrayList<PointerTracker> sTrackers = new ArrayList<PointerTracker>();
private static final InputPointers sAggregratedPointers = new InputPointers(
GestureStroke.DEFAULT_CAPACITY);
private static PointerTrackerQueue sPointerTrackerQueue; private static PointerTrackerQueue sPointerTrackerQueue;
// HACK: Change gesture detection criteria depending on this variable. // HACK: Change gesture detection criteria depending on this variable.
// TODO: Find more comprehensive ways to detect a gesture start. // TODO: Find more comprehensive ways to detect a gesture start.
@ -257,23 +259,19 @@ public class PointerTracker {
// TODO: To handle multi-touch gestures we may want to move this method to // TODO: To handle multi-touch gestures we may want to move this method to
// {@link PointerTrackerQueue}. // {@link PointerTrackerQueue}.
private static InputPointers getIncrementalBatchPoints() { private static InputPointers getIncrementalBatchPoints() {
// TODO: Avoid creating a new instance here?
final InputPointers pointers = new InputPointers(GestureStroke.DEFAULT_CAPACITY);
for (final PointerTracker tracker : sTrackers) { for (final PointerTracker tracker : sTrackers) {
tracker.mGestureStroke.appendIncrementalBatchPoints(pointers); tracker.mGestureStroke.appendIncrementalBatchPoints(sAggregratedPointers);
} }
return pointers; return sAggregratedPointers;
} }
// TODO: To handle multi-touch gestures we may want to move this method to // TODO: To handle multi-touch gestures we may want to move this method to
// {@link PointerTrackerQueue}. // {@link PointerTrackerQueue}.
private static InputPointers getAllBatchPoints() { private static InputPointers getAllBatchPoints() {
// TODO: Avoid creating a new instance here?
final InputPointers pointers = new InputPointers(GestureStroke.DEFAULT_CAPACITY);
for (final PointerTracker tracker : sTrackers) { for (final PointerTracker tracker : sTrackers) {
tracker.mGestureStroke.appendAllBatchPoints(pointers); tracker.mGestureStroke.appendAllBatchPoints(sAggregratedPointers);
} }
return pointers; return sAggregratedPointers;
} }
// TODO: To handle multi-touch gestures we may want to move this method to // TODO: To handle multi-touch gestures we may want to move this method to
@ -282,6 +280,7 @@ public class PointerTracker {
for (final PointerTracker tracker : sTrackers) { for (final PointerTracker tracker : sTrackers) {
tracker.mGestureStroke.reset(); tracker.mGestureStroke.reset();
} }
sAggregratedPointers.reset();
} }
private PointerTracker(int id, KeyEventHandler handler) { private PointerTracker(int id, KeyEventHandler handler) {
@ -645,6 +644,8 @@ public class PointerTracker {
if (sIsGestureEnabled && mIsAlphabetKeyboard && key != null if (sIsGestureEnabled && mIsAlphabetKeyboard && key != null
&& Keyboard.isLetterCode(key.mCode)) { && Keyboard.isLetterCode(key.mCode)) {
mIsPossibleGesture = true; mIsPossibleGesture = true;
// TODO: pointer times should be relative to first down even in entire batch input
// instead of resetting to 0 for each new down event.
mGestureStroke.addPoint(x, y, 0, false); mGestureStroke.addPoint(x, y, 0, false);
} }
} }
@ -869,7 +870,9 @@ public class PointerTracker {
} }
return; return;
} }
// This event will be recognized as a regular code input. Clear unused batch points so they
// are not mistakenly included in the next batch event.
clearBatchInputPointsOfAllPointerTrackers();
if (mKeyAlreadyProcessed) if (mKeyAlreadyProcessed)
return; return;
if (mCurrentKey != null && !mCurrentKey.isRepeatable()) { if (mCurrentKey != null && !mCurrentKey.isRepeatable()) {

View file

@ -27,6 +27,7 @@ public class GestureStroke {
private float mLength; private float mLength;
private float mAngle; private float mAngle;
private int mIncrementalRecognitionSize; private int mIncrementalRecognitionSize;
private int mLastIncrementalBatchSize;
private long mLastPointTime; private long mLastPointTime;
private int mLastPointX; private int mLastPointX;
private int mLastPointY; private int mLastPointY;
@ -73,6 +74,7 @@ public class GestureStroke {
mLength = 0; mLength = 0;
mAngle = 0; mAngle = 0;
mIncrementalRecognitionSize = 0; mIncrementalRecognitionSize = 0;
mLastIncrementalBatchSize = 0;
mLastPointTime = 0; mLastPointTime = 0;
mInputPointers.reset(); mInputPointers.reset();
} }
@ -126,11 +128,15 @@ public class GestureStroke {
} }
public void appendAllBatchPoints(final InputPointers out) { public void appendAllBatchPoints(final InputPointers out) {
out.append(mInputPointers, 0, mInputPointers.getPointerSize()); final int size = mInputPointers.getPointerSize();
out.append(mInputPointers, mLastIncrementalBatchSize, size - mLastIncrementalBatchSize);
mLastIncrementalBatchSize = size;
} }
public void appendIncrementalBatchPoints(final InputPointers out) { public void appendIncrementalBatchPoints(final InputPointers out) {
out.append(mInputPointers, 0, mIncrementalRecognitionSize); out.append(mInputPointers, mLastIncrementalBatchSize,
mIncrementalRecognitionSize - mLastIncrementalBatchSize);
mLastIncrementalBatchSize = mIncrementalRecognitionSize;
} }
private static float getDistance(final int p1x, final int p1y, private static float getDistance(final int p1x, final int p1y,