From 73d8fca6ba1991dbcbcd4686212d087a5ae8de2d Mon Sep 17 00:00:00 2001 From: Adam Powell Date: Fri, 12 Feb 2010 16:50:19 -0800 Subject: VelocityTracker now uses pointer id instead of index when referring to multiple pointers. VelocityTracker now correctly handles multitouch. Addresses http://b/issue?id=2439030 --- core/java/android/view/VelocityTracker.java | 59 ++++++++++++++++++----------- 1 file changed, 37 insertions(+), 22 deletions(-) diff --git a/core/java/android/view/VelocityTracker.java b/core/java/android/view/VelocityTracker.java index 9a8ee02a8077..91fd6f1a509c 100644 --- a/core/java/android/view/VelocityTracker.java +++ b/core/java/android/view/VelocityTracker.java @@ -124,24 +124,37 @@ public final class VelocityTracker implements Poolable { * @param ev The MotionEvent you received and would like to track. */ public void addMovement(MotionEvent ev) { - long time = ev.getEventTime(); final int N = ev.getHistorySize(); final int pointerCount = ev.getPointerCount(); - for (int p = 0; p < pointerCount; p++) { - for (int i=0; i { // find oldest acceptable time int oldestTouch = lastTouch; if (pastTime[lastTouch] > 0) { // cleared ? - oldestTouch = (lastTouch + 1) % NUM_PAST; final float acceptableTime = pastTime[lastTouch] - LONGEST_PAST_TIME; - while (pastTime[oldestTouch] < acceptableTime) { - oldestTouch = (oldestTouch + 1) % NUM_PAST; + int nextOldestTouch = (NUM_PAST + oldestTouch - 1) % NUM_PAST; + while (pastTime[nextOldestTouch] >= acceptableTime && + nextOldestTouch != lastTouch) { + oldestTouch = nextOldestTouch; + nextOldestTouch = (NUM_PAST + oldestTouch - 1) % NUM_PAST; } } @@ -241,25 +256,25 @@ public final class VelocityTracker implements Poolable { * Retrieve the last computed X velocity. You must first call * {@link #computeCurrentVelocity(int)} before calling this function. * - * @param pos Which pointer's velocity to return. + * @param id Which pointer's velocity to return. * @return The previously computed X velocity. * * @hide Pending API approval */ - public float getXVelocity(int pos) { - return mXVelocity[pos]; + public float getXVelocity(int id) { + return mXVelocity[id]; } /** * Retrieve the last computed Y velocity. You must first call * {@link #computeCurrentVelocity(int)} before calling this function. * - * @param pos Which pointer's velocity to return. + * @param id Which pointer's velocity to return. * @return The previously computed Y velocity. * * @hide Pending API approval */ - public float getYVelocity(int pos) { - return mYVelocity[pos]; + public float getYVelocity(int id) { + return mYVelocity[id]; } } -- cgit v1.2.3-59-g8ed1b