From 95ee81ab9be65ab7fc012e9d39b10d782890451e Mon Sep 17 00:00:00 2001 From: Tobrun Van Nuland Date: Tue, 19 Sep 2017 14:59:39 +0200 Subject: [PATCH] [android] - disable rotation gesture when pinch zooming --- .../TwoFingerGestureDetector.java | 5 ++- .../mapboxsdk/maps/MapGestureDetector.java | 33 ++++++++++++------- 2 files changed, 23 insertions(+), 15 deletions(-) diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/almeros/android/multitouch/gesturedetectors/TwoFingerGestureDetector.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/almeros/android/multitouch/gesturedetectors/TwoFingerGestureDetector.java index 71fb9aa168c..db492b65560 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/almeros/android/multitouch/gesturedetectors/TwoFingerGestureDetector.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/almeros/android/multitouch/gesturedetectors/TwoFingerGestureDetector.java @@ -54,8 +54,7 @@ public TwoFingerGestureDetector(Context context) { ViewConfiguration config = ViewConfiguration.get(context); - // We divide edge slop by 2 to make rotation gesture happen more easily #6870 - edgeSlop = config.getScaledEdgeSlop() / 2; + edgeSlop = config.getScaledEdgeSlop(); } @Override @@ -222,4 +221,4 @@ public float getFocusY() { return focus.y; } -} +} \ No newline at end of file diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapGestureDetector.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapGestureDetector.java index f456d3ef65b..2394e521936 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapGestureDetector.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapGestureDetector.java @@ -54,8 +54,10 @@ final class MapGestureDetector { private boolean quickZoom; private boolean tiltGestureOccurred; private boolean scrollGestureOccurred; + private boolean scaleGestureOccurred; private boolean recentScaleGestureOccurred; + private long scaleBeginTime; MapGestureDetector(Context context, Transform transform, Projection projection, UiSettings uiSettings, TrackingSettings trackingSettings, AnnotationManager annotationManager, @@ -144,8 +146,8 @@ boolean onTouchEvent(MotionEvent event) { } // Check two finger gestures first - rotateGestureDetector.onTouchEvent(event); scaleGestureDetector.onTouchEvent(event); + rotateGestureDetector.onTouchEvent(event); shoveGestureDetector.onTouchEvent(event); // Handle two finger tap @@ -428,8 +430,7 @@ public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float d */ private class ScaleGestureListener extends ScaleGestureDetector.SimpleOnScaleGestureListener { - long beginTime = 0; - float scaleFactor = 1.0f; + private float scaleFactor = 1.0f; // Called when two fingers first touch the screen @Override @@ -438,9 +439,8 @@ public boolean onScaleBegin(ScaleGestureDetector detector) { return false; } - scaleGestureOccurred = true; recentScaleGestureOccurred = true; - beginTime = detector.getEventTime(); + scaleBeginTime = detector.getEventTime(); MapboxTelemetry.getInstance().pushEvent(MapboxEventWrapper.buildMapClickEvent( getLocationFromGesture(detector.getFocusX(), detector.getFocusY()), MapboxEvent.GESTURE_PINCH_START, transform)); @@ -451,7 +451,7 @@ public boolean onScaleBegin(ScaleGestureDetector detector) { @Override public void onScaleEnd(ScaleGestureDetector detector) { scaleGestureOccurred = false; - beginTime = 0; + scaleBeginTime = 0; scaleFactor = 1.0f; cameraChangeDispatcher.onCameraIdle(); } @@ -471,7 +471,7 @@ public boolean onScale(ScaleGestureDetector detector) { // Ignore short touches in case it is a tap // Also ignore small scales long time = detector.getEventTime(); - long interval = time - beginTime; + long interval = time - scaleBeginTime; if (!scaleGestureOccurred && (interval <= ViewConfiguration.getTapTimeout())) { return false; } @@ -517,7 +517,6 @@ public boolean onScale(ScaleGestureDetector detector) { transform.zoomBy(Math.log(detector.getScaleFactor()) / Math.log(Math.PI / 2), detector.getFocusX(), detector.getFocusY()); } - return true; } } @@ -527,9 +526,11 @@ public boolean onScale(ScaleGestureDetector detector) { */ private class RotateGestureListener extends RotateGestureDetector.SimpleOnRotateGestureListener { - long beginTime = 0; - float totalAngle = 0.0f; - boolean started = false; + private static final long ROTATE_INVOKE_WAIT_TIME = 1500; + + private long beginTime = 0; + private float totalAngle = 0.0f; + private boolean started = false; // Called when two fingers first touch the screen @Override @@ -566,7 +567,7 @@ public boolean onRotate(RotateGestureDetector detector) { // Also ignore small rotate long time = detector.getEventTime(); long interval = time - beginTime; - if (!started && (interval <= ViewConfiguration.getTapTimeout())) { + if (!started && (interval <= ViewConfiguration.getTapTimeout() || isScaleGestureActive(time))) { return false; } @@ -583,6 +584,7 @@ public boolean onRotate(RotateGestureDetector detector) { if (!started) { return false; } + // rotation constitutes translation of anything except the center of // rotation, so cancel both location and bearing tracking if required trackingSettings.resetTrackingModesIfRequired(true, true, false); @@ -601,6 +603,13 @@ public boolean onRotate(RotateGestureDetector detector) { } return true; } + + private boolean isScaleGestureActive(long time) { + long scaleExecutionTime = time - scaleBeginTime; + boolean scaleGestureStarted = scaleBeginTime != 0; + boolean scaleOffsetTimeValid = scaleExecutionTime > ROTATE_INVOKE_WAIT_TIME; + return (scaleGestureStarted && scaleOffsetTimeValid) || scaleGestureOccurred; + } } /**