diff options
6 files changed, 113 insertions, 1 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 048eda4322..d53216b811 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 @@ -114,6 +114,8 @@ public class MapboxConstants { public static final String STATE_TILT_ENABLED = "tiltEnabled"; public static final String STATE_TILT_ENABLED_CHANGE = "tiltEnabledChange"; public static final String STATE_ZOOM_CONTROLS_ENABLED = "zoomControlsEnabled"; + public static final String STATE_DOUBLE_TAP_ENABLED = "doubleTapEnabled"; + public static final String STATE_DOUBLE_TAP_ENABLED_CHANGE = "doubleTapEnabledChange"; public static final String STATE_DEBUG_ACTIVE = "debugActive"; public static final String STATE_STYLE_URL = "styleUrl"; public static final String STATE_MY_LOCATION_ENABLED = "myLocationEnabled"; 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 b73a74c433..0f4d3197cc 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 @@ -243,7 +243,7 @@ final class MapGestureDetector { @Override public boolean onDoubleTapEvent(MotionEvent e) { - if (!uiSettings.isZoomGesturesEnabled()) { + if (!uiSettings.isZoomGesturesEnabled() || !uiSettings.isDoubleTapGesturesEnabled()) { return false; } 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 9a5e336cf8..6467033ead 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 @@ -66,6 +66,7 @@ public class MapboxMapOptions implements Parcelable { private boolean tiltGesturesEnabled = true; private boolean zoomGesturesEnabled = true; private boolean zoomControlsEnabled = false; + private boolean doubleTapGesturesEnabled = true; private boolean myLocationEnabled; private Drawable myLocationForegroundDrawable; @@ -116,6 +117,7 @@ public class MapboxMapOptions implements Parcelable { tiltGesturesEnabled = in.readByte() != 0; zoomControlsEnabled = in.readByte() != 0; zoomGesturesEnabled = in.readByte() != 0; + doubleTapGesturesEnabled = in.readByte() != 0; myLocationEnabled = in.readByte() != 0; @@ -184,6 +186,8 @@ public class MapboxMapOptions implements Parcelable { typedArray.getBoolean(R.styleable.mapbox_MapView_mapbox_uiTiltGestures, true)); mapboxMapOptions.zoomControlsEnabled( typedArray.getBoolean(R.styleable.mapbox_MapView_mapbox_uiZoomControls, false)); + mapboxMapOptions.doubleTapGesturesEnabled( + typedArray.getBoolean(R.styleable.mapbox_MapView_mapbox_uiDoubleTapGestures, true)); mapboxMapOptions.maxZoomPreference(typedArray.getFloat(R.styleable.mapbox_MapView_mapbox_cameraZoomMax, MapboxConstants.MAXIMUM_ZOOM)); @@ -529,6 +533,17 @@ public class MapboxMapOptions implements Parcelable { } /** + * Specifies if the double tap gesture is enabled for a map view. + * + * @param enabled True and gesture will be enabled + * @return This + */ + public MapboxMapOptions doubleTapGesturesEnabled(boolean enabled) { + doubleTapGesturesEnabled = enabled; + return this; + } + + /** * Specifies if the user location view is enabled for a map view. * * @param locationEnabled True and gesture will be enabled @@ -809,6 +824,15 @@ public class MapboxMapOptions implements Parcelable { } /** + * Get the current configured double tap gesture state for a map view. + * + * @return True indicates gesture is enabled + */ + public boolean getDoubleTapGesturesEnabled() { + return doubleTapGesturesEnabled; + } + + /** * Get the current configured visibility state for attribution for a map view. * * @return Visibility state of the attribution @@ -987,6 +1011,7 @@ public class MapboxMapOptions implements Parcelable { dest.writeByte((byte) (tiltGesturesEnabled ? 1 : 0)); dest.writeByte((byte) (zoomControlsEnabled ? 1 : 0)); dest.writeByte((byte) (zoomGesturesEnabled ? 1 : 0)); + dest.writeByte((byte) (doubleTapGesturesEnabled ? 1 : 0)); dest.writeByte((byte) (myLocationEnabled ? 1 : 0)); @@ -1066,6 +1091,9 @@ public class MapboxMapOptions implements Parcelable { if (zoomControlsEnabled != options.zoomControlsEnabled) { return false; } + if (doubleTapGesturesEnabled != options.doubleTapGesturesEnabled) { + return false; + } if (myLocationEnabled != options.myLocationEnabled) { return false; } @@ -1146,6 +1174,7 @@ public class MapboxMapOptions implements Parcelable { result = 31 * result + (tiltGesturesEnabled ? 1 : 0); result = 31 * result + (zoomGesturesEnabled ? 1 : 0); result = 31 * result + (zoomControlsEnabled ? 1 : 0); + result = 31 * result + (doubleTapGesturesEnabled ? 1 : 0); result = 31 * result + (myLocationEnabled ? 1 : 0); result = 31 * result + (myLocationForegroundDrawable != null ? myLocationForegroundDrawable.hashCode() : 0); result = 31 * result + (myLocationForegroundBearingDrawable != null 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 bb5271313b..8a3ae1e4f3 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 @@ -48,6 +48,9 @@ public final class UiSettings { private boolean zoomControlsEnabled; + private boolean doubleTapGesturesEnabled = true; + private boolean doubleTapGestureChangeAllowed = true; + private boolean deselectMarkersOnTap = true; private PointF userProvidedFocalPoint; @@ -99,6 +102,8 @@ public final class UiSettings { setTiltGesturesEnabled(options.getTiltGesturesEnabled()); setTiltGestureChangeAllowed(options.getTiltGesturesEnabled()); setZoomControlsEnabled(options.getZoomControlsEnabled()); + setDoubleTapGesturesEnabled(options.getDoubleTapGesturesEnabled()); + setDoubleTapGestureChangeAllowed(options.getDoubleTapGesturesEnabled()); } private void saveGestures(Bundle outState) { @@ -110,6 +115,8 @@ public final class UiSettings { outState.putBoolean(MapboxConstants.STATE_ROTATE_ENABLED_CHANGE, isRotateGestureChangeAllowed()); outState.putBoolean(MapboxConstants.STATE_TILT_ENABLED, isTiltGesturesEnabled()); outState.putBoolean(MapboxConstants.STATE_TILT_ENABLED_CHANGE, isTiltGestureChangeAllowed()); + outState.putBoolean(MapboxConstants.STATE_DOUBLE_TAP_ENABLED, isDoubleTapGesturesEnabled()); + outState.putBoolean(MapboxConstants.STATE_DOUBLE_TAP_ENABLED_CHANGE, isDoubleTapGestureChangeAllowed()); } private void restoreGestures(Bundle savedInstanceState) { @@ -121,6 +128,8 @@ public final class UiSettings { setRotateGestureChangeAllowed(savedInstanceState.getBoolean(MapboxConstants.STATE_ROTATE_ENABLED_CHANGE)); setTiltGesturesEnabled(savedInstanceState.getBoolean(MapboxConstants.STATE_TILT_ENABLED)); setTiltGestureChangeAllowed(savedInstanceState.getBoolean(MapboxConstants.STATE_TILT_ENABLED_CHANGE)); + setDoubleTapGesturesEnabled(savedInstanceState.getBoolean(MapboxConstants.STATE_DOUBLE_TAP_ENABLED)); + setDoubleTapGestureChangeAllowed(savedInstanceState.getBoolean(MapboxConstants.STATE_DOUBLE_TAP_ENABLED_CHANGE)); } private void initialiseCompass(MapboxMapOptions options, Resources resources) { @@ -696,6 +705,41 @@ public final class UiSettings { } /** + * <p> + * Changes whether the user may zoom the map with a double tap. + * </p> + * <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 doubleTapGesturesEnabled If true, zooming with a double tap is enabled. + */ + public void setDoubleTapGesturesEnabled(boolean doubleTapGesturesEnabled) { + if (doubleTapGestureChangeAllowed) { + this.doubleTapGesturesEnabled = doubleTapGesturesEnabled; + } + } + + /** + * Returns whether the user may zoom the map with a double tap. + * + * @return If true, zooming with a double tap is enabled. + */ + public boolean isDoubleTapGesturesEnabled() { + return doubleTapGesturesEnabled; + } + + void setDoubleTapGestureChangeAllowed(boolean doubleTapGestureChangeAllowed) { + this.doubleTapGestureChangeAllowed = doubleTapGestureChangeAllowed; + } + + boolean isDoubleTapGestureChangeAllowed() { + return doubleTapGestureChangeAllowed; + } + + /** * Gets whether the markers are automatically deselected (and therefore, their infowindows * closed) when a map tap is detected. * @@ -771,6 +815,7 @@ public final class UiSettings { setRotateGesturesEnabled(enabled); setTiltGesturesEnabled(enabled); setZoomGesturesEnabled(enabled); + setDoubleTapGesturesEnabled(enabled); } /** diff --git a/platform/android/MapboxGLAndroidSDK/src/main/res/values/attrs.xml b/platform/android/MapboxGLAndroidSDK/src/main/res/values/attrs.xml index 12c395d46f..b027b1b5d3 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/res/values/attrs.xml +++ b/platform/android/MapboxGLAndroidSDK/src/main/res/values/attrs.xml @@ -22,6 +22,7 @@ <attr name="mapbox_uiScrollGestures" format="boolean" /> <attr name="mapbox_uiRotateGestures" format="boolean" /> <attr name="mapbox_uiTiltGestures" format="boolean" /> + <attr name="mapbox_uiDoubleTapGestures" format="boolean" /> <!--UI-Controls--> <attr name="mapbox_uiZoomControls" format="boolean" /> diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/test/java/com/mapbox/mapboxsdk/maps/UiSettingsTest.java b/platform/android/MapboxGLAndroidSDKTestApp/src/test/java/com/mapbox/mapboxsdk/maps/UiSettingsTest.java index 67213d5e18..fbe00b4dce 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/test/java/com/mapbox/mapboxsdk/maps/UiSettingsTest.java +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/test/java/com/mapbox/mapboxsdk/maps/UiSettingsTest.java @@ -286,6 +286,41 @@ public class UiSettingsTest { } @Test + public void testDoubleTapGesturesEnabled() { + uiSettings.setDoubleTapGesturesEnabled(true); + assertEquals("DoubleTap gesture should be enabled", true, uiSettings.isDoubleTapGesturesEnabled()); + } + + @Test + public void testDoubleTapGesturesDisabled() { + uiSettings.setDoubleTapGesturesEnabled(false); + assertEquals("DoubleTap gesture should be disabled", false, uiSettings.isDoubleTapGesturesEnabled()); + } + + @Test + public void testDoubleTapGestureChange() { + assertEquals("Default state should be true", true, uiSettings.isDoubleTapGestureChangeAllowed()); + uiSettings.setDoubleTapGestureChangeAllowed(false); + assertEquals("State should have been changed", false, uiSettings.isDoubleTapGestureChangeAllowed()); + } + + @Test + public void testDoubleTapGestureChangeAllowed() { + uiSettings.setDoubleTapGesturesEnabled(false); + assertEquals("DoubleTap gesture should be false", false, uiSettings.isDoubleTapGesturesEnabled()); + uiSettings.setDoubleTapGesturesEnabled(true); + assertEquals("DoubleTap gesture should be true", true, uiSettings.isDoubleTapGesturesEnabled()); + } + + @Test + public void testDoubleTapGestureChangeDisallowed() { + assertEquals("DoubleTap gesture should be true", true, uiSettings.isDoubleTapGesturesEnabled()); + uiSettings.setDoubleTapGestureChangeAllowed(false); + uiSettings.setDoubleTapGesturesEnabled(false); + assertEquals("DoubleTap gesture change should be ignored", true, uiSettings.isDoubleTapGesturesEnabled()); + } + + @Test public void testScrollGesturesEnabled() { uiSettings.setScrollGesturesEnabled(true); assertEquals("Scroll gesture should be enabled", true, uiSettings.isScrollGesturesEnabled()); |