diff options
author | Tobrun Van Nuland <tobrun.van.nuland@gmail.com> | 2017-10-05 15:04:50 +0200 |
---|---|---|
committer | Tobrun <tobrun@mapbox.com> | 2017-10-09 16:51:17 +0200 |
commit | 9048d6cfd0f794af3f3810a880adb0d2fc691552 (patch) | |
tree | c54109b985bda4f4801ecb7272b7a628535b9f37 | |
parent | a1aed6f095c6326fa9c8a8ecff591c5a03144070 (diff) | |
download | qtlocation-mapboxgl-9048d6cfd0f794af3f3810a880adb0d2fc691552.tar.gz |
[android] - fine tune gesture zoom & rotation
3 files changed, 19 insertions, 11 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 db492b6556..3d28c2295d 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,7 +54,9 @@ public abstract class TwoFingerGestureDetector extends BaseGestureDetector { ViewConfiguration config = ViewConfiguration.get(context); - edgeSlop = config.getScaledEdgeSlop(); + // lowering the edgeSlop allows to execute gesture faster + // https://github.com/mapbox/mapbox-gl-native/issues/10102 + edgeSlop = config.getScaledEdgeSlop() / 3.0f; } @Override 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 2394e52193..f309570a7b 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 @@ -526,10 +526,10 @@ final class MapGestureDetector { */ private class RotateGestureListener extends RotateGestureDetector.SimpleOnRotateGestureListener { - private static final long ROTATE_INVOKE_WAIT_TIME = 1500; + private static final long ROTATE_INVOKE_WAIT_TIME = 750; + private static final float ROTATE_INVOKE_ANGLE = 17.5f; private long beginTime = 0; - private float totalAngle = 0.0f; private boolean started = false; // Called when two fingers first touch the screen @@ -551,7 +551,6 @@ final class MapGestureDetector { public void onRotateEnd(RotateGestureDetector detector) { // notify camera change listener beginTime = 0; - totalAngle = 0.0f; started = false; } @@ -573,8 +572,8 @@ final class MapGestureDetector { // If rotate is large enough ignore a tap // Also is zoom already started, don't rotate - totalAngle += detector.getRotationDegreesDelta(); - if (totalAngle > 35.0f || totalAngle < -35.0f) { + float angle = detector.getRotationDegreesDelta(); + if (Math.abs(angle) >= ROTATE_INVOKE_ANGLE) { MapboxTelemetry.getInstance().pushEvent(MapboxEventWrapper.buildMapClickEvent( getLocationFromGesture(detector.getFocusX(), detector.getFocusY()), MapboxEvent.GESTURE_ROTATION_START, transform)); @@ -589,9 +588,8 @@ final class MapGestureDetector { // rotation, so cancel both location and bearing tracking if required trackingSettings.resetTrackingModesIfRequired(true, true, false); - // Get rotate value - double bearing = transform.getRawBearing(); - bearing += detector.getRotationDegreesDelta(); + // Calculate map bearing value + double bearing = transform.getRawBearing() + angle; // Rotate the map if (focalPoint != null) { diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapView.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapView.java index 12e4c675ee..a93d05eaed 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapView.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapView.java @@ -382,6 +382,10 @@ public class MapView extends FrameLayout { @Override public boolean onTouchEvent(MotionEvent event) { + if (!isMapInitialized()) { + return super.onTouchEvent(event); + } + if (event.getAction() == MotionEvent.ACTION_DOWN) { mapZoomButtonController.setVisible(true); } @@ -471,7 +475,7 @@ public class MapView extends FrameLayout { if (destroyed) { return; } - if (nativeMapView == null) { + if (!isMapInitialized()) { mapboxMapOptions.styleUrl(url); return; } @@ -488,7 +492,7 @@ public class MapView extends FrameLayout { return; } - if (!isInEditMode() && nativeMapView != null) { + if (!isInEditMode() && isMapInitialized()) { nativeMapView.resizeView(width, height); } } @@ -574,6 +578,10 @@ public class MapView extends FrameLayout { } } + private boolean isMapInitialized() { + return nativeMapView != null; + } + MapboxMap getMapboxMap() { return mapboxMap; } |