diff --git a/core/java/android/view/VelocityTracker.java b/core/java/android/view/VelocityTracker.java index 9a8ee02a80779..91fd6f1a509c4 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]; } }