Bug 756474 - Harden the SimpleScaleGestureDectector against missed events [r=kats]

This commit is contained in:
Matt Brubeck 2012-06-19 12:01:44 -07:00
parent e84af3afd0
commit aa807b4225
2 changed files with 11 additions and 11 deletions

View File

@ -251,16 +251,7 @@ public final class TouchEventHandler implements Tabs.OnTabsChangedListener {
*/
private void dispatchEvent(MotionEvent event) {
if (mGestureDetector.onTouchEvent(event)) {
// An up/cancel event should get passed to both detectors, in
// case it comes from a pointer the scale detector is tracking.
switch (event.getAction() & MotionEvent.ACTION_MASK) {
case MotionEvent.ACTION_POINTER_UP:
case MotionEvent.ACTION_UP:
case MotionEvent.ACTION_CANCEL:
break;
default:
return;
}
return;
}
mScaleGestureDetector.onTouchEvent(event);
if (mScaleGestureDetector.isInProgress()) {

View File

@ -51,6 +51,12 @@ public class SimpleScaleGestureDetector {
public void onTouchEvent(MotionEvent event) {
switch (event.getAction() & MotionEvent.ACTION_MASK) {
case MotionEvent.ACTION_DOWN:
// If we get ACTION_DOWN while still tracking any pointers,
// something is wrong. Cancel the current gesture and start over.
if (getPointersDown() > 0)
onTouchEnd(event);
onTouchStart(event);
break;
case MotionEvent.ACTION_POINTER_DOWN:
onTouchStart(event);
break;
@ -99,7 +105,10 @@ public class SimpleScaleGestureDetector {
private void onTouchEnd(MotionEvent event) {
mLastEventTime = event.getEventTime();
boolean isCancel = (event.getAction() & MotionEvent.ACTION_MASK) == MotionEvent.ACTION_CANCEL;
int action = event.getAction() & MotionEvent.ACTION_MASK;
boolean isCancel = (action == MotionEvent.ACTION_CANCEL ||
action == MotionEvent.ACTION_DOWN);
int id = event.getPointerId(getActionIndex(event));
ListIterator<PointerInfo> iterator = mPointerInfo.listIterator();
while (iterator.hasNext()) {