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

Commit 69f756fe authored by Daniel Sandler's avatar Daniel Sandler
Browse files

Drop simultaneous pointer events when tracking velocity.

They're not really simultaneous, but within 1ms of one
another, which is too close for getEventTime() to
distinguish; these events were causing the velocity
computation to become (understandably) confused and
resulting in failed panel flings.

Bug: 10246454
Change-Id: I3829192cdf9ad2a222ec8deca031d772d58de0da
parent 9955699d
Loading
Loading
Loading
Loading
+16 −7
Original line number Diff line number Diff line
@@ -118,7 +118,7 @@ public class PanelView extends FrameLayout {
            int i = 0;
            float totalweight = 0f;
            float weight = 10f;
            for (final Iterator<MotionEventCopy> iter = mEventBuf.descendingIterator();
            for (final Iterator<MotionEventCopy> iter = mEventBuf.iterator();
                    iter.hasNext();) {
                final MotionEventCopy event = iter.next();
                if (last != null) {
@@ -126,13 +126,22 @@ public class PanelView extends FrameLayout {
                    final float dx = (event.x - last.x);
                    final float dy = (event.y - last.y);
                    if (FlingTracker.DEBUG) {
                        Log.v("FlingTracker", String.format("   [%d] dx=%.1f dy=%.1f dt=%.0f vx=%.1f vy=%.1f",
                                i,
                        Log.v("FlingTracker", String.format(
                                "   [%d] (t=%d %.1f,%.1f) dx=%.1f dy=%.1f dt=%f vx=%.1f vy=%.1f",
                                i, event.t, event.x, event.y,
                                dx, dy, dt,
                                (dx/dt),
                                (dy/dt)
                                ));
                    }
                    if (event.t == last.t) {
                        // Really not sure what to do with events that happened at the same time,
                        // so we'll skip subsequent events.
                        if (DEBUG_NAN) {
                            Log.v("FlingTracker", "skipping simultaneous event at t=" + event.t);
                        }
                        continue;
                    }
                    mVX += weight * dx / dt;
                    mVY += weight * dy / dt;
                    totalweight += weight;
@@ -158,18 +167,18 @@ public class PanelView extends FrameLayout {
            }
        }
        public float getXVelocity() {
            if (Float.isNaN(mVX)) {
            if (Float.isNaN(mVX) || Float.isInfinite(mVX)) {
                if (DEBUG_NAN) {
                    Log.v("FlingTracker", "warning: vx=NaN");
                    Log.v("FlingTracker", "warning: vx=" + mVX);
                }
                mVX = 0;
            }
            return mVX;
        }
        public float getYVelocity() {
            if (Float.isNaN(mVY)) {
            if (Float.isNaN(mVY) || Float.isInfinite(mVX)) {
                if (DEBUG_NAN) {
                    Log.v("FlingTracker", "warning: vx=NaN");
                    Log.v("FlingTracker", "warning: vx=" + mVY);
                }
                mVY = 0;
            }