Skip to content

Commit 83835b1

Browse files
adampAndroid (Google) Code Review
authored andcommitted
Merge "Break flings with opposing velocities" into jb-mr1-dev
2 parents 81665b9 + cd66359 commit 83835b1

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

core/java/android/view/GestureDetector.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -482,6 +482,27 @@ public boolean onTouchEvent(MotionEvent ev) {
482482
case MotionEvent.ACTION_POINTER_UP:
483483
mDownFocusX = mLastFocusX = focusX;
484484
mDownFocusY = mLastFocusY = focusY;
485+
486+
// Check the dot product of current velocities.
487+
// If the pointer that left was opposing another velocity vector, clear.
488+
mVelocityTracker.computeCurrentVelocity(1000, mMaximumFlingVelocity);
489+
final int upIndex = ev.getActionIndex();
490+
final int id1 = ev.getPointerId(upIndex);
491+
final float x1 = mVelocityTracker.getXVelocity(id1);
492+
final float y1 = mVelocityTracker.getYVelocity(id1);
493+
for (int i = 0; i < count; i++) {
494+
if (i == upIndex) continue;
495+
496+
final int id2 = ev.getPointerId(i);
497+
final float x = x1 * mVelocityTracker.getXVelocity(id2);
498+
final float y = y1 * mVelocityTracker.getYVelocity(id2);
499+
500+
final float dot = x + y;
501+
if (dot < 0) {
502+
mVelocityTracker.clear();
503+
break;
504+
}
505+
}
485506
break;
486507

487508
case MotionEvent.ACTION_DOWN:

0 commit comments

Comments
 (0)