Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 14fdda31 authored by Adam Powell's avatar Adam Powell Committed by Android (Google) Code Review
Browse files

Merge "Fix bug 2988160 - Flinging broken in certain apps/widgets"

parents a78eca95 8ae0f3f6
Loading
Loading
Loading
Loading
+16 −2
Original line number Diff line number Diff line
@@ -41,6 +41,7 @@ public final class VelocityTracker implements Poolable<VelocityTracker> {
    private static final int MAX_AGE_MILLISECONDS = 200;
    
    private static final int POINTER_POOL_CAPACITY = 20;
    private static final int INVALID_POINTER = -1;

    private static final Pool<VelocityTracker> sPool = Pools.synchronizedPool(
            Pools.finitePool(new PoolableManager<VelocityTracker>() {
@@ -76,6 +77,7 @@ public final class VelocityTracker implements Poolable<VelocityTracker> {
    private Pointer mPointerListHead; // sorted by id in increasing order
    private int mLastTouchIndex;
    private int mGeneration;
    private int mActivePointerId;

    private VelocityTracker mNext;

@@ -125,6 +127,7 @@ public final class VelocityTracker implements Poolable<VelocityTracker> {
        
        mPointerListHead = null;
        mLastTouchIndex = 0;
        mActivePointerId = INVALID_POINTER;
    }
    
    /**
@@ -180,6 +183,10 @@ public final class VelocityTracker implements Poolable<VelocityTracker> {
                // Pointer went down.  Add it to the list.
                // Write a sentinel at the end of the pastTime trace so we will be able to
                // tell when the trace started.
                if (mActivePointerId == INVALID_POINTER) {
                    // Congratulations! You're the new active pointer!
                    mActivePointerId = pointerId;
                }
                pointer = obtainPointer();
                pointer.id = pointerId;
                pointer.pastTime[lastTouchIndex] = Long.MIN_VALUE;
@@ -214,6 +221,7 @@ public final class VelocityTracker implements Poolable<VelocityTracker> {
        previousPointer = null;
        for (Pointer pointer = mPointerListHead; pointer != null; ) {
            final Pointer nextPointer = pointer.next;
            final int pointerId = pointer.id;
            if (pointer.generation != generation) {
                // Pointer went up.  Remove it from the list.
                if (previousPointer == null) {
@@ -222,6 +230,12 @@ public final class VelocityTracker implements Poolable<VelocityTracker> {
                    previousPointer.next = nextPointer;
                }
                releasePointer(pointer);

                if (pointerId == mActivePointerId) {
                    // Pick a new active pointer. How is arbitrary.
                    mActivePointerId = mPointerListHead != null ?
                            mPointerListHead.id : INVALID_POINTER;
                }
            } else {
                previousPointer = pointer;
            }
@@ -334,7 +348,7 @@ public final class VelocityTracker implements Poolable<VelocityTracker> {
     * @return The previously computed X velocity.
     */
    public float getXVelocity() {
        Pointer pointer = getPointer(0);
        Pointer pointer = getPointer(mActivePointerId);
        return pointer != null ? pointer.xVelocity : 0;
    }
    
@@ -345,7 +359,7 @@ public final class VelocityTracker implements Poolable<VelocityTracker> {
     * @return The previously computed Y velocity.
     */
    public float getYVelocity() {
        Pointer pointer = getPointer(0);
        Pointer pointer = getPointer(mActivePointerId);
        return pointer != null ? pointer.yVelocity : 0;
    }