[android] separate quick zoom gestures option

This commit is contained in:
Łukasz Paczos
2019-01-24 17:18:00 +01:00
committed by Łukasz Paczos
parent 8fedfbf160
commit be94efa402
7 changed files with 182 additions and 66 deletions

View File

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

View File

@@ -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(

View File

@@ -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;
@@ -505,6 +507,18 @@ public class MapboxMapOptions implements Parcelable {
return this;
}
/**
* 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>
@@ -790,6 +804,15 @@ public class MapboxMapOptions implements Parcelable {
return doubleTapGesturesEnabled;
}
/**
* 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.
*
@@ -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);

View File

@@ -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) {