From c351f65c0923c2e21ea0467239d46a343af6aa9c Mon Sep 17 00:00:00 2001 From: Ramin Mirsharifi Date: Sat, 7 Oct 2017 13:33:44 +0330 Subject: [PATCH] [android] - Add touch velocity effects on scale gesture. Fine tune. --- .../mapbox/mapboxsdk/maps/MapGestureDetector.java | 13 +++++++++---- .../java/com/mapbox/mapboxsdk/maps/Transform.java | 4 ++-- 2 files changed, 11 insertions(+), 6 deletions(-) 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 bdc09384568..95f34b9b70e 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 @@ -419,7 +419,7 @@ public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float d return false; } - if (tiltGestureOccurred) { + if (tiltGestureOccurred || scaleGestureOccurred) { return false; } @@ -476,9 +476,14 @@ public boolean onScaleBegin(ScaleGestureDetector detector) { @Override public void onScaleEnd(ScaleGestureDetector detector) { double velocityXY = Math.abs(velocityTracker.getYVelocity()) + Math.abs(velocityTracker.getXVelocity()); - if (velocityXY > MapboxConstants.VELOCITY_THRESHOLD_IGNORE_FLING) { + if (velocityXY > MapboxConstants.VELOCITY_THRESHOLD_IGNORE_FLING / 2) { long animationTime = (long)(Math.log(velocityXY) * 66); - transform.zoom(wasZoomingIn, new PointF(detector.getFocusX(), detector.getFocusY()), animationTime); + double zoomAddition = (float) (Math.log(velocityXY) / 7.7); + if (!wasZoomingIn) { + zoomAddition = -zoomAddition; + } + scaleGestureOccurred = true; + transform.zoom(zoomAddition, new PointF(detector.getFocusX(), detector.getFocusY()), animationTime); handler.postDelayed(new Runnable() { @Override public void run() { @@ -509,7 +514,7 @@ public boolean onScale(ScaleGestureDetector detector) { // Also ignore small scales long time = detector.getEventTime(); long interval = time - scaleBeginTime; - if (!scaleGestureOccurred && (interval <= ViewConfiguration.getTapTimeout())) { + if (!scaleGestureOccurred && (interval <= ViewConfiguration.getTapTimeout() / 3)) { return false; } diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/Transform.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/Transform.java index 026564902c9..e18e7f91c6a 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/Transform.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/Transform.java @@ -221,10 +221,10 @@ void zoom(boolean zoomIn, @NonNull PointF focalPoint) { } } - void zoom(boolean zoomIn, @NonNull PointF focalPoint,long duration) { + void zoom(double zoomAddition, @NonNull PointF focalPoint,long duration) { CameraPosition cameraPosition = invalidateCameraPosition(); if (cameraPosition != null) { - int newZoom = (int) Math.round(cameraPosition.zoom + (zoomIn ? 1 : -1)); + int newZoom = (int) Math.round(cameraPosition.zoom + zoomAddition); setZoom(newZoom, focalPoint, duration); } else { // we are not transforming, notify about being idle