diff options
author | Łukasz Paczos <lukas.paczos@gmail.com> | 2019-01-24 17:18:00 +0100 |
---|---|---|
committer | Łukasz Paczos <lukasz.paczos@mapbox.com> | 2019-01-25 15:07:22 +0100 |
commit | be94efa4024271cf6307baaa1e3317c3ec055b3b (patch) | |
tree | 7bfbd5929290e91bc7ecb177ccdd7d7d6103ffd2 /platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox | |
parent | 8fedfbf160ab7228c5a51d1f6d4586b1ea54bac3 (diff) | |
download | qtlocation-mapboxgl-be94efa4024271cf6307baaa1e3317c3ec055b3b.tar.gz |
[android] separate quick zoom gestures option
Diffstat (limited to 'platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox')
4 files changed, 75 insertions, 19 deletions
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/constants/MapboxConstants.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/constants/MapboxConstants.java index 2c063daa8f..73c8201454 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/constants/MapboxConstants.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/constants/MapboxConstants.java @@ -130,6 +130,7 @@ public class MapboxConstants { public static final String STATE_ROTATE_ENABLED = "mapbox_rotateEnabled"; public static final String STATE_TILT_ENABLED = "mapbox_tiltEnabled"; public static final String STATE_DOUBLE_TAP_ENABLED = "mapbox_doubleTapEnabled"; + public static final String STATE_QUICK_ZOOM_ENABLED = "mapbox_quickZoom"; public static final String STATE_DEBUG_ACTIVE = "mapbox_debugActive"; public static final String STATE_COMPASS_ENABLED = "mapbox_compassEnabled"; public static final String STATE_COMPASS_GRAVITY = "mapbox_compassGravity"; @@ -158,5 +159,4 @@ public class MapboxConstants { public static final String STATE_FLING_ANIMATION_ENABLED = "mapbox_flingAnimationEnabled"; public static final String STATE_INCREASE_ROTATE_THRESHOLD = "mapbox_increaseRotateThreshold"; public static final String STATE_INCREASE_SCALE_THRESHOLD = "mapbox_increaseScaleThreshold"; - } 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 852b3e8a4d..cf2d20179f 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 @@ -77,7 +77,6 @@ final class MapGestureDetector { private PointF focalPoint; private AndroidGesturesManager gesturesManager; - private boolean executeDoubleTap; private Animator scaleAnimator; private Animator rotateAnimator; @@ -208,13 +207,14 @@ final class MapGestureDetector { return false; } + if (motionEvent.getActionMasked() == MotionEvent.ACTION_DOWN) { + cancelAnimators(); + transform.setGestureInProgress(true); + } + boolean result = gesturesManager.onTouchEvent(motionEvent); switch (motionEvent.getActionMasked()) { - case MotionEvent.ACTION_DOWN: - cancelAnimators(); - transform.setGestureInProgress(true); - break; case MotionEvent.ACTION_UP: transform.setGestureInProgress(false); @@ -257,7 +257,7 @@ final class MapGestureDetector { * Posted on main thread with {@link #animationsTimeoutHandler}. Cancels all scheduled animators if needed. */ @NonNull - private Runnable cancelAnimatorsRunnable = new Runnable() { + private final Runnable cancelAnimatorsRunnable = new Runnable() { @Override public void run() { cancelAnimators(); @@ -353,16 +353,10 @@ final class MapGestureDetector { public boolean onDoubleTapEvent(MotionEvent motionEvent) { int action = motionEvent.getActionMasked(); if (action == MotionEvent.ACTION_DOWN) { - executeDoubleTap = true; - } - if (motionEvent.getActionMasked() == MotionEvent.ACTION_UP) { - if (!uiSettings.isZoomGesturesEnabled() || !uiSettings.isDoubleTapGesturesEnabled() || !executeDoubleTap) { + if (!uiSettings.isZoomGesturesEnabled() || !uiSettings.isDoubleTapGesturesEnabled()) { return false; } - transform.cancelTransitions(); - cameraChangeDispatcher.onCameraMoveStarted(REASON_API_GESTURE); - PointF zoomFocalPoint; // Single finger double tap if (focalPoint != null) { @@ -374,11 +368,13 @@ final class MapGestureDetector { } zoomInAnimated(zoomFocalPoint, false); + } + if (motionEvent.getActionMasked() == MotionEvent.ACTION_UP) { sendTelemetryEvent(TelemetryConstants.DOUBLE_TAP, new PointF(motionEvent.getX(), motionEvent.getY())); - return true; } + return super.onDoubleTapEvent(motionEvent); } @@ -482,15 +478,16 @@ final class MapGestureDetector { return false; } - cancelTransitionsIfRequired(); - quickZoom = detector.getPointersCount() == 1; if (quickZoom) { - // when quickzoom, dismiss double tap and disable move gesture - executeDoubleTap = false; + if (!uiSettings.isQuickZoomGesturesEnabled()) { + return false; + } gesturesManager.getMoveGestureDetector().setEnabled(false); } + cancelTransitionsIfRequired(); + if (uiSettings.isIncreaseRotateThresholdWhenScaling()) { // increase rotate angle threshold when scale is detected first gesturesManager.getRotateGestureDetector().setAngleThreshold( diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapboxMapOptions.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapboxMapOptions.java index 8c91ad9174..91895e64ad 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapboxMapOptions.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapboxMapOptions.java @@ -64,6 +64,7 @@ public class MapboxMapOptions implements Parcelable { private boolean tiltGesturesEnabled = true; private boolean zoomGesturesEnabled = true; private boolean doubleTapGesturesEnabled = true; + private boolean quickZoomGesturesEnabled = true; private boolean prefetchesTiles = true; private boolean zMediaOverlay = false; @@ -118,6 +119,7 @@ public class MapboxMapOptions implements Parcelable { tiltGesturesEnabled = in.readByte() != 0; zoomGesturesEnabled = in.readByte() != 0; doubleTapGesturesEnabled = in.readByte() != 0; + quickZoomGesturesEnabled = in.readByte() != 0; apiBaseUrl = in.readString(); textureMode = in.readByte() != 0; @@ -506,6 +508,18 @@ public class MapboxMapOptions implements Parcelable { } /** + * Specifies whether the user may zoom the map by tapping twice, holding and moving the pointer up and down. + * + * @param enabled True and gesture will be enabled + * @return This + */ + @NonNull + public MapboxMapOptions quickZoomGesturesEnabled(boolean enabled) { + quickZoomGesturesEnabled = enabled; + return this; + } + + /** * Enable {@link android.view.TextureView} as rendered surface. * <p> * Since the 5.2.0 release we replaced our TextureView with an {@link android.opengl.GLSurfaceView} @@ -791,6 +805,15 @@ public class MapboxMapOptions implements Parcelable { } /** + * Get whether the user may zoom the map by tapping twice, holding and moving the pointer up and down. + * + * @return True indicates gesture is enabled + */ + public boolean getQuickZoomGesturesEnabled() { + return quickZoomGesturesEnabled; + } + + /** * Get the current configured visibility state for attribution for a map view. * * @return Visibility state of the attribution @@ -922,6 +945,7 @@ public class MapboxMapOptions implements Parcelable { dest.writeByte((byte) (tiltGesturesEnabled ? 1 : 0)); dest.writeByte((byte) (zoomGesturesEnabled ? 1 : 0)); dest.writeByte((byte) (doubleTapGesturesEnabled ? 1 : 0)); + dest.writeByte((byte) (quickZoomGesturesEnabled ? 1 : 0)); dest.writeString(apiBaseUrl); dest.writeByte((byte) (textureMode ? 1 : 0)); @@ -998,6 +1022,9 @@ public class MapboxMapOptions implements Parcelable { if (doubleTapGesturesEnabled != options.doubleTapGesturesEnabled) { return false; } + if (quickZoomGesturesEnabled != options.quickZoomGesturesEnabled) { + return false; + } if (cameraPosition != null ? !cameraPosition.equals(options.cameraPosition) : options.cameraPosition != null) { return false; } @@ -1061,6 +1088,7 @@ public class MapboxMapOptions implements Parcelable { result = 31 * result + (tiltGesturesEnabled ? 1 : 0); result = 31 * result + (zoomGesturesEnabled ? 1 : 0); result = 31 * result + (doubleTapGesturesEnabled ? 1 : 0); + result = 31 * result + (quickZoomGesturesEnabled ? 1 : 0); result = 31 * result + (apiBaseUrl != null ? apiBaseUrl.hashCode() : 0); result = 31 * result + (textureMode ? 1 : 0); result = 31 * result + (translucentTextureSurface ? 1 : 0); diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/UiSettings.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/UiSettings.java index ab29b026f1..3e24b8c797 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/UiSettings.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/UiSettings.java @@ -58,6 +58,8 @@ public final class UiSettings { private boolean doubleTapGesturesEnabled = true; + private boolean quickZoomGesturesEnabled = true; + private boolean scaleVelocityAnimationEnabled = true; private boolean rotateVelocityAnimationEnabled = true; private boolean flingVelocityAnimationEnabled = true; @@ -113,6 +115,7 @@ public final class UiSettings { setRotateGesturesEnabled(options.getRotateGesturesEnabled()); setTiltGesturesEnabled(options.getTiltGesturesEnabled()); setDoubleTapGesturesEnabled(options.getDoubleTapGesturesEnabled()); + setQuickZoomGesturesEnabled(options.getQuickZoomGesturesEnabled()); } private void saveGestures(Bundle outState) { @@ -126,6 +129,7 @@ public final class UiSettings { outState.putBoolean(MapboxConstants.STATE_FLING_ANIMATION_ENABLED, isFlingVelocityAnimationEnabled()); outState.putBoolean(MapboxConstants.STATE_INCREASE_ROTATE_THRESHOLD, isIncreaseRotateThresholdWhenScaling()); outState.putBoolean(MapboxConstants.STATE_INCREASE_SCALE_THRESHOLD, isIncreaseScaleThresholdWhenRotating()); + outState.putBoolean(MapboxConstants.STATE_QUICK_ZOOM_ENABLED, isQuickZoomGesturesEnabled()); } private void restoreGestures(Bundle savedInstanceState) { @@ -141,6 +145,7 @@ public final class UiSettings { savedInstanceState.getBoolean(MapboxConstants.STATE_INCREASE_ROTATE_THRESHOLD)); setIncreaseScaleThresholdWhenRotating( savedInstanceState.getBoolean(MapboxConstants.STATE_INCREASE_SCALE_THRESHOLD)); + setQuickZoomGesturesEnabled(savedInstanceState.getBoolean(MapboxConstants.STATE_QUICK_ZOOM_ENABLED)); } private void initialiseCompass(MapboxMapOptions options, @NonNull Resources resources) { @@ -730,6 +735,29 @@ public final class UiSettings { return doubleTapGesturesEnabled; } + /** + * Returns whether the user may zoom the map by tapping twice, holding and moving the pointer up and down. + * + * @return If true, zooming by tapping twice and holding is enabled. + */ + public boolean isQuickZoomGesturesEnabled() { + return quickZoomGesturesEnabled; + } + + /** + * Changes whether the user may zoom the map by tapping twice, holding and moving the pointer up and down. + * <p> + * This setting controls only user interactions with the map. If you set the value to false, + * you may still change the map location programmatically. + * </p> + * The default value is true. + * + * @param quickZoomGesturesEnabled If true, zooming by tapping twice and holding is enabled. + */ + public void setQuickZoomGesturesEnabled(boolean quickZoomGesturesEnabled) { + this.quickZoomGesturesEnabled = quickZoomGesturesEnabled; + } + private void restoreDeselectMarkersOnTap(Bundle savedInstanceState) { setDeselectMarkersOnTap(savedInstanceState.getBoolean(MapboxConstants.STATE_DESELECT_MARKER_ON_TAP)); } @@ -899,6 +927,8 @@ public final class UiSettings { * @see #setScrollGesturesEnabled(boolean) * @see #setRotateGesturesEnabled(boolean) * @see #setTiltGesturesEnabled(boolean) + * @see #setDoubleTapGesturesEnabled(boolean) + * @see #setQuickZoomGesturesEnabled(boolean) */ public void setAllGesturesEnabled(boolean enabled) { setScrollGesturesEnabled(enabled); @@ -906,6 +936,7 @@ public final class UiSettings { setTiltGesturesEnabled(enabled); setZoomGesturesEnabled(enabled); setDoubleTapGesturesEnabled(enabled); + setQuickZoomGesturesEnabled(enabled); } private void saveFocalPoint(Bundle outState) { |