diff options
author | Ramin Mirsharifi <ramin@divar.ir> | 2017-10-07 13:33:44 +0330 |
---|---|---|
committer | Tobrun <tobrun@mapbox.com> | 2017-10-30 16:25:37 -0700 |
commit | c351f65c0923c2e21ea0467239d46a343af6aa9c (patch) | |
tree | 9929c7afa0f663a35f40c82e8e3c4848f4f53836 /platform/android/MapboxGLAndroidSDK | |
parent | 8c4e2f0886b090946e7c4c0210379080b6bd567c (diff) | |
download | qtlocation-mapboxgl-c351f65c0923c2e21ea0467239d46a343af6aa9c.tar.gz |
[android] - Add touch velocity effects on scale gesture. Fine tune.
Diffstat (limited to 'platform/android/MapboxGLAndroidSDK')
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 bdc0938456..95f34b9b70 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 @@ final class MapGestureDetector { return false; } - if (tiltGestureOccurred) { + if (tiltGestureOccurred || scaleGestureOccurred) { return false; } @@ -476,9 +476,14 @@ final class MapGestureDetector { @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 @@ final class MapGestureDetector { // 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 026564902c..e18e7f91c6 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 @@ final class Transform implements MapView.OnMapChangedListener { } } - 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 |