From fc899e038a7026461cf1fafd145f0463a4e35d13 Mon Sep 17 00:00:00 2001 From: Wes Johnston Date: Wed, 25 Jan 2012 01:31:33 +0100 Subject: [PATCH] Bug 719240 - Delay sending touchmove events until touches have moved a minimum distance. r=mfinkle --- mobile/android/base/gfx/LayerController.java | 11 +++++++++++ mobile/android/base/ui/PanZoomController.java | 2 +- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/mobile/android/base/gfx/LayerController.java b/mobile/android/base/gfx/LayerController.java index cfc47b7415a..7b13c388102 100644 --- a/mobile/android/base/gfx/LayerController.java +++ b/mobile/android/base/gfx/LayerController.java @@ -112,6 +112,7 @@ public class LayerController { private boolean allowDefaultActions = true; private Timer allowDefaultTimer = null; private boolean inTouchSession = false; + private PointF initialTouchLocation = null; public LayerController(Context context) { mContext = context; @@ -362,7 +363,9 @@ public class LayerController { */ public boolean onTouchEvent(MotionEvent event) { int action = event.getAction(); + PointF point = new PointF(event.getX(), event.getY()); if ((action & MotionEvent.ACTION_MASK) == MotionEvent.ACTION_DOWN) { + initialTouchLocation = point; post(new Runnable() { public void run() { mView.clearEventQueue(); @@ -371,6 +374,14 @@ public class LayerController { }); } + if (initialTouchLocation != null && (action & MotionEvent.ACTION_MASK) == MotionEvent.ACTION_MOVE) { + if (PointUtils.subtract(point, initialTouchLocation).length() > PanZoomController.PAN_THRESHOLD * 240) { + initialTouchLocation = null; + } else { + return !allowDefaultActions; + } + } + if (mOnTouchListener != null) mOnTouchListener.onTouch(mView, event); diff --git a/mobile/android/base/ui/PanZoomController.java b/mobile/android/base/ui/PanZoomController.java index 12abcce4d99..01f639d38a0 100644 --- a/mobile/android/base/ui/PanZoomController.java +++ b/mobile/android/base/ui/PanZoomController.java @@ -79,7 +79,7 @@ public class PanZoomController private static final float FLING_STOPPED_THRESHOLD = 0.1f; // The distance the user has to pan before we recognize it as such (e.g. to avoid // 1-pixel pans between the touch-down and touch-up of a click). In units of inches. - private static final float PAN_THRESHOLD = 0.1f; + public static final float PAN_THRESHOLD = 0.1f; // Angle from axis within which we stay axis-locked private static final double AXIS_LOCK_ANGLE = Math.PI / 6.0; // 30 degrees // The maximum amount we allow you to zoom into a page