Disable double tap gesture to zoom in (#7879)

This commit is contained in:
srabenja
2017-02-04 02:17:59 -05:00
committed by Tobrun
parent d9c055ad34
commit 1dead1d194
6 changed files with 113 additions and 1 deletions

View File

@@ -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";

View File

@@ -243,7 +243,7 @@ final class MapGestureDetector {
@Override
public boolean onDoubleTapEvent(MotionEvent e) {
if (!uiSettings.isZoomGesturesEnabled()) {
if (!uiSettings.isZoomGesturesEnabled() || !uiSettings.isDoubleTapGesturesEnabled()) {
return false;
}

View File

@@ -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));
@@ -528,6 +532,17 @@ public class MapboxMapOptions implements Parcelable {
return this;
}
/**
* 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.
*
@@ -808,6 +823,15 @@ public class MapboxMapOptions implements Parcelable {
return zoomGesturesEnabled;
}
/**
* 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.
*
@@ -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

View File

@@ -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) {
@@ -695,6 +704,41 @@ public final class UiSettings {
return zoomControlsEnabled;
}
/**
* <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);
}
/**

View File

@@ -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" />

View File

@@ -285,6 +285,41 @@ public class UiSettingsTest {
assertEquals("Zoom controls should be disabled", false, uiSettings.isZoomControlsEnabled());
}
@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);