From 12664cd4c42b20e513146ddab1f17d8c3da0a6e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Paczos?= Date: Wed, 7 Mar 2018 15:56:22 +0100 Subject: Expose more gestures settings (#11407) * [android] enable/disable velocity animations * [android] exposed a method to cancel ongoing velocity animations * [android] removed unused methods and constants * [android] fixed gestures manager initialization * [android] enable/disable increasing gesture thresholds * [android] saving/restoring new gestures options --- .../mapboxsdk/constants/MapboxConstants.java | 28 +-- .../mapbox/mapboxsdk/maps/MapGestureDetector.java | 129 +++++++++----- .../java/com/mapbox/mapboxsdk/maps/MapView.java | 10 +- .../java/com/mapbox/mapboxsdk/maps/MapboxMap.java | 32 +++- .../java/com/mapbox/mapboxsdk/maps/UiSettings.java | 193 +++++++++++++-------- .../com/mapbox/mapboxsdk/maps/UiSettingsTest.java | 148 ++++++++-------- 6 files changed, 325 insertions(+), 215 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 6f263e4635..640c70282c 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 @@ -121,23 +121,13 @@ public class MapboxConstants { public static final String STATE_HAS_SAVED_STATE = "mapbox_savedState"; public static final String STATE_CAMERA_POSITION = "mapbox_cameraPosition"; public static final String STATE_ZOOM_ENABLED = "mapbox_zoomEnabled"; - public static final String STATE_ZOOM_ENABLED_CHANGE = "mapbox_zoomEnabledChange"; public static final String STATE_SCROLL_ENABLED = "mapbox_scrollEnabled"; - public static final String STATE_SCROLL_ENABLED_CHANGE = "mapbox_scrollEnabledChange"; public static final String STATE_ROTATE_ENABLED = "mapbox_rotateEnabled"; - public static final String STATE_ROTATE_ENABLED_CHANGE = "mapbox_rotateEnabledChange"; public static final String STATE_TILT_ENABLED = "mapbox_tiltEnabled"; - public static final String STATE_TILT_ENABLED_CHANGE = "mapbox_tiltEnabledChange"; public static final String STATE_ZOOM_CONTROLS_ENABLED = "mapbox_zoomControlsEnabled"; public static final String STATE_DOUBLE_TAP_ENABLED = "mapbox_doubleTapEnabled"; - public static final String STATE_DOUBLE_TAP_ENABLED_CHANGE = "mapbox_doubleTapEnabledChange"; public static final String STATE_DEBUG_ACTIVE = "mapbox_debugActive"; public static final String STATE_STYLE_URL = "mapbox_styleUrl"; - public static final String STATE_MY_LOCATION_ENABLED = "mapbox_myLocationEnabled"; - public static final String STATE_MY_LOCATION_TRACKING_MODE = "mapbox_myLocationTracking"; - public static final String STATE_MY_BEARING_TRACKING_MODE = "mapbox_myBearingTracking"; - public static final String STATE_MY_LOCATION_TRACKING_DISMISS = "mapbox_myLocationTrackingDismiss"; - public static final String STATE_MY_BEARING_TRACKING_DISMISS = "mapbox_myBearingTrackingDismiss"; public static final String STATE_COMPASS_ENABLED = "mapbox_compassEnabled"; public static final String STATE_COMPASS_GRAVITY = "mapbox_compassGravity"; public static final String STATE_COMPASS_MARGIN_LEFT = "mapbox_compassMarginLeft"; @@ -158,20 +148,12 @@ public class MapboxConstants { public static final String STATE_ATTRIBUTION_MARGIN_RIGHT = "mapbox_attrMarginRight"; public static final String STATE_ATTRIBUTION_MARGIN_BOTTOM = "mapbox_atrrMarginBottom"; public static final String STATE_ATTRIBUTION_ENABLED = "mapbox_atrrEnabled"; - public static final String STATE_LOCATION_CHANGE_ANIMATION_ENABLED = "mapbox_locationChangeAnimationEnabled"; - public static final String STATE_USING_CUSTOM_LOCATION_SOURCE = "mapbox_usingCustomLocationSource"; - public static final String STATE_LOCATION_VIEW_ENABLED = "mapbox_locViewEnabled"; - public static final String STATE_LOCATION_VIEW_FOREGROUND_DRAWABLE = "mapbox_locViewForegroundDrawable"; - public static final String STATE_LOCATION_VIEW_FOREGROUND_BEARING_DRAWABLE = "mapbox_locViewBearingDrawable"; - public static final String STATE_LOCATION_VIEW_FOREGROUND_TINT_COLOR = "mapbox_locViewForegroundTintColor"; - public static final String STATE_LOCATION_VIEW_BACKGROUND_DRAWABLE = "mapbox_locViewBackgroundDrawable"; - public static final String STATE_LOCATION_VIEW_BACKGROUND_OFFSET = "mapbox_locViewBackgroundOffset"; - public static final String STATE_LOCATION_VIEW_BACKGROUND_TINT_COLOR = "mapbox_locViewBackgroundTintColor"; - public static final String STATE_LOCATION_VIEW_ACCURACY_ALPHA = "mapbox_locViewAccuracyAlpha"; - public static final String STATE_LOCATION_VIEW_ACCURACY_TINT_COLOR = "mapbox_locViewAccuracyTintColor"; - public static final String STATE_LOCATION_VIEW_ACCURACY_THRESHOLD = "mapbox_locViewAccuracyThreshold"; - public static final String STATE_LOCATION_VIEW_PADDING = "mapbox_locViewPadding"; public static final String STATE_DESELECT_MARKER_ON_TAP = "mapbox_deselectMarkerOnTap"; public static final String STATE_USER_FOCAL_POINT = "mapbox_userFocalPoint"; + public static final String STATE_SCALE_ANIMATION_ENABLED = "mapbox_scaleAnimationEnabled"; + public static final String STATE_ROTATE_ANIMATION_ENABLED = "mapbox_rotateAnimationEnabled"; + 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 d6bde6c481..865b3c97aa 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,6 +77,13 @@ final class MapGestureDetector { private final CopyOnWriteArrayList onShoveListenerList = new CopyOnWriteArrayList<>(); + private StandardGestureListener standardGestureListener; + private MoveGestureListener moveGestureListener; + private ScaleGestureListener scaleGestureListener; + private RotateGestureListener rotateGestureListener; + private ShoveGestureListener shoveGestureListener; + private TapGestureListener tapGestureListener; + /** * User-set focal point. */ @@ -105,8 +112,30 @@ final class MapGestureDetector { // Checking for context != null for testing purposes if (context != null) { - gesturesManager = new AndroidGesturesManager(context); + // Initialize gesture listeners + initializeGestureListeners(context); + // Initialize gestures manager + AndroidGesturesManager androidGesturesManager = new AndroidGesturesManager(context); + initializeGesturesManager(androidGesturesManager, true, true); + } + } + + private void initializeGestureListeners(Context context) { + standardGestureListener = new StandardGestureListener(); + moveGestureListener = new MoveGestureListener(); + scaleGestureListener = new ScaleGestureListener( + context.getResources().getDimension(R.dimen.mapbox_minimum_scale_velocity)); + rotateGestureListener = new RotateGestureListener( + context.getResources().getDimension(R.dimen.mapbox_minimum_scale_span_when_rotating), + context.getResources().getDimension(R.dimen.mapbox_minimum_angular_velocity)); + shoveGestureListener = new ShoveGestureListener(); + tapGestureListener = new TapGestureListener(); + } + + private void initializeGesturesManager(AndroidGesturesManager androidGesturesManager, + boolean attachDefaultListeners, boolean setDefaultMutuallyExclusives) { + if (setDefaultMutuallyExclusives) { Set shoveScaleSet = new HashSet<>(); shoveScaleSet.add(AndroidGesturesManager.GESTURE_TYPE_SHOVE); shoveScaleSet.add(AndroidGesturesManager.GESTURE_TYPE_SCALE); @@ -119,20 +148,19 @@ final class MapGestureDetector { ScaleLongPressSet.add(AndroidGesturesManager.GESTURE_TYPE_SCALE); ScaleLongPressSet.add(AndroidGesturesManager.GESTURE_TYPE_LONG_PRESS); - gesturesManager.setMutuallyExclusiveGestures(shoveScaleSet, shoveRotateSet, ScaleLongPressSet); - - gesturesManager.setStandardGestureListener(new StandardGestureListener()); - gesturesManager.setMoveGestureListener(new MoveGestureListener()); - gesturesManager.setStandardScaleGestureListener(new ScaleGestureListener( - context.getResources().getDimension(R.dimen.mapbox_minimum_scale_velocity) - )); - gesturesManager.setRotateGestureListener(new RotateGestureListener( - context.getResources().getDimension(R.dimen.mapbox_minimum_scale_span_when_rotating), - context.getResources().getDimension(R.dimen.mapbox_minimum_angular_velocity) - )); - gesturesManager.setShoveGestureListener(new ShoveGestureListener()); - gesturesManager.setMultiFingerTapGestureListener(new TapGestureListener()); + androidGesturesManager.setMutuallyExclusiveGestures(shoveScaleSet, shoveRotateSet, ScaleLongPressSet); + } + + if (attachDefaultListeners) { + androidGesturesManager.setStandardGestureListener(standardGestureListener); + androidGesturesManager.setMoveGestureListener(moveGestureListener); + androidGesturesManager.setStandardScaleGestureListener(scaleGestureListener); + androidGesturesManager.setRotateGestureListener(rotateGestureListener); + androidGesturesManager.setShoveGestureListener(shoveGestureListener); + androidGesturesManager.setMultiFingerTapGestureListener(tapGestureListener); } + + gesturesManager = androidGesturesManager; } /** @@ -367,8 +395,14 @@ final class MapGestureDetector { @Override public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) { - if ((!uiSettings.isScrollGesturesEnabled())) { - // don't allow a fling is scroll is disabled + if (!uiSettings.isScrollGesturesEnabled()) { + // don't allow a fling if scroll is disabled + return false; + } + + notifyOnFlingListeners(); + + if (!uiSettings.isFlingVelocityAnimationEnabled()) { return false; } @@ -396,8 +430,6 @@ final class MapGestureDetector { // update transformation transform.moveBy(offsetX, offsetY, animationTime); - notifyOnFlingListeners(); - return true; } } @@ -466,11 +498,13 @@ final class MapGestureDetector { gesturesManager.getMoveGestureDetector().setEnabled(false); } - // increase rotate angle threshold when scale is detected first - gesturesManager.getRotateGestureDetector().setAngleThreshold( - gesturesManager.getRotateGestureDetector().getDefaultAngleThreshold() - + MapboxConstants.ROTATION_THRESHOLD_INCREASE_WHEN_SCALING - ); + if (uiSettings.isIncreaseRotateThresholdWhenScaling()) { + // increase rotate angle threshold when scale is detected first + gesturesManager.getRotateGestureDetector().setAngleThreshold( + gesturesManager.getRotateGestureDetector().getDefaultAngleThreshold() + + MapboxConstants.ROTATION_THRESHOLD_INCREASE_WHEN_SCALING + ); + } // setting focalPoint in #onScaleBegin() as well, because #onScale() might not get called before #onScaleEnd() setScaleFocalPoint(detector); @@ -507,10 +541,18 @@ final class MapGestureDetector { gesturesManager.getMoveGestureDetector().setEnabled(true); } - // resetting default angle threshold - gesturesManager.getRotateGestureDetector().setAngleThreshold( - gesturesManager.getRotateGestureDetector().getDefaultAngleThreshold() - ); + if (uiSettings.isIncreaseRotateThresholdWhenScaling()) { + // resetting default angle threshold + gesturesManager.getRotateGestureDetector().setAngleThreshold( + gesturesManager.getRotateGestureDetector().getDefaultAngleThreshold() + ); + } + + notifyOnScaleEndListeners(detector); + + if (!uiSettings.isScaleVelocityAnimationEnabled()) { + return; + } float velocityXY = Math.abs(velocityX) + Math.abs(velocityY); if (velocityXY > minimumVelocity) { @@ -520,8 +562,6 @@ final class MapGestureDetector { scaleAnimator = createScaleAnimator(currentZoom, zoomAddition, scaleFocalPoint, animationTime); scheduleAnimator(scaleAnimator); } - - notifyOnScaleEndListeners(detector); } private void setScaleFocalPoint(StandardScaleGestureDetector detector) { @@ -578,10 +618,12 @@ final class MapGestureDetector { transform.cancelTransitions(); cameraChangeDispatcher.onCameraMoveStarted(REASON_API_GESTURE); - // when rotation starts, interrupting scale and increasing the threshold - // to make rotation without scaling easier - gesturesManager.getStandardScaleGestureDetector().setSpanSinceStartThreshold(minimumScaleSpanWhenRotating); - gesturesManager.getStandardScaleGestureDetector().interrupt(); + if (uiSettings.isIncreaseScaleThresholdWhenRotating()) { + // when rotation starts, interrupting scale and increasing the threshold + // to make rotation without scaling easier + gesturesManager.getStandardScaleGestureDetector().setSpanSinceStartThreshold(minimumScaleSpanWhenRotating); + gesturesManager.getStandardScaleGestureDetector().interrupt(); + } // setting in #onRotateBegin() as well, because #onRotate() might not get called before #onRotateEnd() setRotateFocalPoint(detector); @@ -616,9 +658,17 @@ final class MapGestureDetector { public void onRotateEnd(RotateGestureDetector detector, float velocityX, float velocityY, float angularVelocity) { cameraChangeDispatcher.onCameraIdle(); - // resetting default scale threshold values - gesturesManager.getStandardScaleGestureDetector().setSpanSinceStartThreshold( - gesturesManager.getStandardScaleGestureDetector().getDefaultSpanSinceStartThreshold()); + if (uiSettings.isIncreaseScaleThresholdWhenRotating()) { + // resetting default scale threshold values + gesturesManager.getStandardScaleGestureDetector().setSpanSinceStartThreshold( + gesturesManager.getStandardScaleGestureDetector().getDefaultSpanSinceStartThreshold()); + } + + notifyOnRotateEndListeners(detector); + + if (!uiSettings.isRotateVelocityAnimationEnabled()) { + return; + } if (Math.abs(angularVelocity) < minimumAngularVelocity) { return; @@ -637,8 +687,6 @@ final class MapGestureDetector { rotateAnimator = createRotateAnimator(angularVelocity, animationTime); scheduleAnimator(rotateAnimator); - - notifyOnRotateEndListeners(detector); } private void setRotateFocalPoint(RotateGestureDetector detector) { @@ -1059,7 +1107,8 @@ final class MapGestureDetector { return gesturesManager; } - void setGesturesManager(AndroidGesturesManager gesturesManager) { - this.gesturesManager = gesturesManager; + void setGesturesManager(AndroidGesturesManager gesturesManager, boolean attachDefaultListeners, + boolean setDefaultMutuallyExclusives) { + initializeGesturesManager(gesturesManager, attachDefaultListeners, setDefaultMutuallyExclusives); } } \ No newline at end of file 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 79d1abe398..9c8ed7de2b 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 @@ -1024,8 +1024,14 @@ public class MapView extends FrameLayout { } @Override - public void setGesturesManager(AndroidGesturesManager gesturesManager) { - mapGestureDetector.setGesturesManager(gesturesManager); + public void setGesturesManager(AndroidGesturesManager gesturesManager, boolean attachDefaultListeners, + boolean setDefaultMutuallyExclusives) { + mapGestureDetector.setGesturesManager(gesturesManager, attachDefaultListeners, setDefaultMutuallyExclusives); + } + + @Override + public void cancelAllVelocityAnimations() { + mapGestureDetector.cancelAnimators(); } } diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapboxMap.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapboxMap.java index a245c283bd..02264cace0 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapboxMap.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapboxMap.java @@ -1917,17 +1917,25 @@ public final class MapboxMap { } /** - * Sets a custom {@link AndroidGesturesManager} to handle {@link android.view.MotionEvent}s registered by the map. - * - * @param androidGesturesManager Gestures manager that interprets gestures based on the motion events. + * Sets a custom {@link AndroidGesturesManager} to handle {@link android.view.MotionEvent}s + * registered by the {@link MapView}. + * + * @param androidGesturesManager Gestures manager that interprets gestures based on the motion events. + * @param attachDefaultListeners If true, pre-defined listeners will be attach + * to change map based on {@link AndroidGesturesManager} callbacks. + * @param setDefaultMutuallyExclusives If true, pre-defined mutually exclusive gesture sets + * will be added to the passed gestures manager. * @see mapbox-gestures-android library */ - public void setGesturesManager(AndroidGesturesManager androidGesturesManager) { - onGesturesManagerInteractionListener.setGesturesManager(androidGesturesManager); + public void setGesturesManager(AndroidGesturesManager androidGesturesManager, boolean attachDefaultListeners, + boolean setDefaultMutuallyExclusives) { + onGesturesManagerInteractionListener.setGesturesManager( + androidGesturesManager, attachDefaultListeners, setDefaultMutuallyExclusives); } /** - * Get current {@link AndroidGesturesManager} that handles {@link android.view.MotionEvent}s registered by the map. + * Get current {@link AndroidGesturesManager} that handles {@link android.view.MotionEvent}s + * registered by the {@link MapView} * * @return Current gestures manager. */ @@ -1935,6 +1943,13 @@ public final class MapboxMap { return onGesturesManagerInteractionListener.getGesturesManager(); } + /** + * Interrupts any ongoing gesture velocity animations. + */ + public void cancelAllVelocityAnimations() { + onGesturesManagerInteractionListener.cancelAllVelocityAnimations(); + } + /** * Sets a callback that's invoked when the user clicks on the map view. * @@ -2352,7 +2367,10 @@ public final class MapboxMap { AndroidGesturesManager getGesturesManager(); - void setGesturesManager(AndroidGesturesManager gesturesManager); + void setGesturesManager(AndroidGesturesManager gesturesManager, boolean attachDefaultListeners, + boolean setDefaultMutuallyExclusives); + + void cancelAllVelocityAnimations(); } /** 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 2f6110d8b1..c1daebbe52 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 @@ -45,21 +45,23 @@ public final class UiSettings { private float pixelRatio; private boolean rotateGesturesEnabled = true; - private boolean rotateGestureChangeAllowed = true; private boolean tiltGesturesEnabled = true; - private boolean tiltGestureChangeAllowed = true; private boolean zoomGesturesEnabled = true; - private boolean zoomGestureChangeAllowed = true; private boolean scrollGesturesEnabled = true; - private boolean scrollGestureChangeAllowed = true; private boolean zoomControlsEnabled; private boolean doubleTapGesturesEnabled = true; - private boolean doubleTapGestureChangeAllowed = true; + + private boolean scaleVelocityAnimationEnabled = true; + private boolean rotateVelocityAnimationEnabled = true; + private boolean flingVelocityAnimationEnabled = true; + + private boolean increaseRotateThresholdWhenScaling = true; + private boolean increaseScaleThresholdWhenRotating = true; private boolean deselectMarkersOnTap = true; @@ -108,42 +110,39 @@ public final class UiSettings { private void initialiseGestures(MapboxMapOptions options) { setZoomGesturesEnabled(options.getZoomGesturesEnabled()); - setZoomGestureChangeAllowed(options.getZoomGesturesEnabled()); setScrollGesturesEnabled(options.getScrollGesturesEnabled()); - setScrollGestureChangeAllowed(options.getScrollGesturesEnabled()); setRotateGesturesEnabled(options.getRotateGesturesEnabled()); - setRotateGestureChangeAllowed(options.getRotateGesturesEnabled()); setTiltGesturesEnabled(options.getTiltGesturesEnabled()); - setTiltGestureChangeAllowed(options.getTiltGesturesEnabled()); setZoomControlsEnabled(options.getZoomControlsEnabled()); setDoubleTapGesturesEnabled(options.getDoubleTapGesturesEnabled()); - setDoubleTapGestureChangeAllowed(options.getDoubleTapGesturesEnabled()); } private void saveGestures(Bundle outState) { outState.putBoolean(MapboxConstants.STATE_ZOOM_ENABLED, isZoomGesturesEnabled()); - outState.putBoolean(MapboxConstants.STATE_ZOOM_ENABLED_CHANGE, isZoomGestureChangeAllowed()); outState.putBoolean(MapboxConstants.STATE_SCROLL_ENABLED, isScrollGesturesEnabled()); - outState.putBoolean(MapboxConstants.STATE_SCROLL_ENABLED_CHANGE, isScrollGestureChangeAllowed()); outState.putBoolean(MapboxConstants.STATE_ROTATE_ENABLED, isRotateGesturesEnabled()); - 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()); + outState.putBoolean(MapboxConstants.STATE_SCALE_ANIMATION_ENABLED, isScaleVelocityAnimationEnabled()); + outState.putBoolean(MapboxConstants.STATE_ROTATE_ANIMATION_ENABLED, isRotateVelocityAnimationEnabled()); + outState.putBoolean(MapboxConstants.STATE_FLING_ANIMATION_ENABLED, isFlingVelocityAnimationEnabled()); + outState.putBoolean(MapboxConstants.STATE_INCREASE_ROTATE_THRESHOLD, isIncreaseRotateThresholdWhenScaling()); + outState.putBoolean(MapboxConstants.STATE_INCREASE_SCALE_THRESHOLD, isIncreaseScaleThresholdWhenRotating()); } private void restoreGestures(Bundle savedInstanceState) { setZoomGesturesEnabled(savedInstanceState.getBoolean(MapboxConstants.STATE_ZOOM_ENABLED)); - setZoomGestureChangeAllowed(savedInstanceState.getBoolean(MapboxConstants.STATE_ZOOM_ENABLED_CHANGE)); setScrollGesturesEnabled(savedInstanceState.getBoolean(MapboxConstants.STATE_SCROLL_ENABLED)); - setScrollGestureChangeAllowed(savedInstanceState.getBoolean(MapboxConstants.STATE_SCROLL_ENABLED_CHANGE)); setRotateGesturesEnabled(savedInstanceState.getBoolean(MapboxConstants.STATE_ROTATE_ENABLED)); - 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)); + setScaleVelocityAnimationEnabled(savedInstanceState.getBoolean(MapboxConstants.STATE_SCALE_ANIMATION_ENABLED)); + setRotateVelocityAnimationEnabled(savedInstanceState.getBoolean(MapboxConstants.STATE_ROTATE_ANIMATION_ENABLED)); + setFlingVelocityAnimationEnabled(savedInstanceState.getBoolean(MapboxConstants.STATE_FLING_ANIMATION_ENABLED)); + setIncreaseRotateThresholdWhenScaling( + savedInstanceState.getBoolean(MapboxConstants.STATE_INCREASE_ROTATE_THRESHOLD)); + setIncreaseScaleThresholdWhenRotating( + savedInstanceState.getBoolean(MapboxConstants.STATE_INCREASE_SCALE_THRESHOLD)); } private void initialiseCompass(MapboxMapOptions options, Resources resources) { @@ -658,9 +657,7 @@ public final class UiSettings { * @param rotateGesturesEnabled If true, rotating is enabled. */ public void setRotateGesturesEnabled(boolean rotateGesturesEnabled) { - if (rotateGestureChangeAllowed) { - this.rotateGesturesEnabled = rotateGesturesEnabled; - } + this.rotateGesturesEnabled = rotateGesturesEnabled; } /** @@ -672,14 +669,6 @@ public final class UiSettings { return rotateGesturesEnabled; } - void setRotateGestureChangeAllowed(boolean rotateGestureChangeAllowed) { - this.rotateGestureChangeAllowed = rotateGestureChangeAllowed; - } - - boolean isRotateGestureChangeAllowed() { - return rotateGestureChangeAllowed; - } - /** *

* Changes whether the user may tilt the map. @@ -693,9 +682,8 @@ public final class UiSettings { * @param tiltGesturesEnabled If true, tilting is enabled. */ public void setTiltGesturesEnabled(boolean tiltGesturesEnabled) { - if (tiltGestureChangeAllowed) { - this.tiltGesturesEnabled = tiltGesturesEnabled; - } + this.tiltGesturesEnabled = tiltGesturesEnabled; + } /** @@ -707,14 +695,6 @@ public final class UiSettings { return tiltGesturesEnabled; } - void setTiltGestureChangeAllowed(boolean tiltGestureChangeAllowed) { - this.tiltGestureChangeAllowed = tiltGestureChangeAllowed; - } - - boolean isTiltGestureChangeAllowed() { - return tiltGestureChangeAllowed; - } - /** *

* Changes whether the user may zoom the map. @@ -728,9 +708,7 @@ public final class UiSettings { * @param zoomGesturesEnabled If true, zooming is enabled. */ public void setZoomGesturesEnabled(boolean zoomGesturesEnabled) { - if (zoomGestureChangeAllowed) { - this.zoomGesturesEnabled = zoomGesturesEnabled; - } + this.zoomGesturesEnabled = zoomGesturesEnabled; } /** @@ -742,14 +720,6 @@ public final class UiSettings { return zoomGesturesEnabled; } - void setZoomGestureChangeAllowed(boolean zoomGestureChangeAllowed) { - this.zoomGestureChangeAllowed = zoomGestureChangeAllowed; - } - - boolean isZoomGestureChangeAllowed() { - return zoomGestureChangeAllowed; - } - /** *

* Sets whether the zoom controls are enabled. @@ -788,9 +758,7 @@ public final class UiSettings { * @param doubleTapGesturesEnabled If true, zooming with a double tap is enabled. */ public void setDoubleTapGesturesEnabled(boolean doubleTapGesturesEnabled) { - if (doubleTapGestureChangeAllowed) { - this.doubleTapGesturesEnabled = doubleTapGesturesEnabled; - } + this.doubleTapGesturesEnabled = doubleTapGesturesEnabled; } /** @@ -802,14 +770,6 @@ public final class UiSettings { return doubleTapGesturesEnabled; } - void setDoubleTapGestureChangeAllowed(boolean doubleTapGestureChangeAllowed) { - this.doubleTapGestureChangeAllowed = doubleTapGestureChangeAllowed; - } - - boolean isDoubleTapGestureChangeAllowed() { - return doubleTapGestureChangeAllowed; - } - private void restoreDeselectMarkersOnTap(Bundle savedInstanceState) { setDeselectMarkersOnTap(savedInstanceState.getBoolean(MapboxConstants.STATE_DESELECT_MARKER_ON_TAP)); } @@ -851,9 +811,7 @@ public final class UiSettings { * @param scrollGesturesEnabled If true, scrolling is enabled. */ public void setScrollGesturesEnabled(boolean scrollGesturesEnabled) { - if (scrollGestureChangeAllowed) { - this.scrollGesturesEnabled = scrollGesturesEnabled; - } + this.scrollGesturesEnabled = scrollGesturesEnabled; } /** @@ -865,12 +823,105 @@ public final class UiSettings { return scrollGesturesEnabled; } - void setScrollGestureChangeAllowed(boolean scrollGestureChangeAllowed) { - this.scrollGestureChangeAllowed = scrollGestureChangeAllowed; + /** + * Returns whether scale velocity animation should execute after users finishes a gesture. + * + * @return If true, scale velocity animation is enabled. + */ + public boolean isScaleVelocityAnimationEnabled() { + return scaleVelocityAnimationEnabled; } - boolean isScrollGestureChangeAllowed() { - return scrollGestureChangeAllowed; + /** + * Set whether scale velocity animation should execute after users finishes a gesture. True by default. + * + * @param scaleVelocityAnimationEnabled If true, scale velocity animation will be enabled. + */ + public void setScaleVelocityAnimationEnabled(boolean scaleVelocityAnimationEnabled) { + this.scaleVelocityAnimationEnabled = scaleVelocityAnimationEnabled; + } + + /** + * Returns whether rotate velocity animation should execute after users finishes a gesture. + * + * @return If true, rotate velocity animation is enabled. + */ + public boolean isRotateVelocityAnimationEnabled() { + return rotateVelocityAnimationEnabled; + } + + /** + * Set whether rotate velocity animation should execute after users finishes a gesture. True by default. + * + * @param rotateVelocityAnimationEnabled If true, rotate velocity animation will be enabled. + */ + public void setRotateVelocityAnimationEnabled(boolean rotateVelocityAnimationEnabled) { + this.rotateVelocityAnimationEnabled = rotateVelocityAnimationEnabled; + } + + /** + * Returns whether fling velocity animation should execute after users finishes a gesture. + * + * @return If true, fling velocity animation is enabled. + */ + public boolean isFlingVelocityAnimationEnabled() { + return flingVelocityAnimationEnabled; + } + + /** + * Set whether fling velocity animation should execute after users finishes a gesture. True by default. + * + * @param flingVelocityAnimationEnabled If true, fling velocity animation will be enabled. + */ + public void setFlingVelocityAnimationEnabled(boolean flingVelocityAnimationEnabled) { + this.flingVelocityAnimationEnabled = flingVelocityAnimationEnabled; + } + + /** + * Set whether all velocity animations should execute after users finishes a gesture. + * + * @param allVelocityAnimationsEnabled If true, all velocity animations will be enabled. + */ + public void setAllVelocityAnimationsEnabled(boolean allVelocityAnimationsEnabled) { + setScaleVelocityAnimationEnabled(allVelocityAnimationsEnabled); + setRotateVelocityAnimationEnabled(allVelocityAnimationsEnabled); + setFlingVelocityAnimationEnabled(allVelocityAnimationsEnabled); + } + + /** + * Returns whether rotation threshold should be increase whenever scale is detected. + * + * @return If true, rotation threshold will be increased. + */ + public boolean isIncreaseRotateThresholdWhenScaling() { + return increaseRotateThresholdWhenScaling; + } + + /** + * Set whether rotation threshold should be increase whenever scale is detected. + * + * @param increaseRotateThresholdWhenScaling If true, rotation threshold will be increased. + */ + public void setIncreaseRotateThresholdWhenScaling(boolean increaseRotateThresholdWhenScaling) { + this.increaseRotateThresholdWhenScaling = increaseRotateThresholdWhenScaling; + } + + /** + * Returns whether scale threshold should be increase whenever rotation is detected. + * + * @return If true, scale threshold will be increased. + */ + public boolean isIncreaseScaleThresholdWhenRotating() { + return increaseScaleThresholdWhenRotating; + } + + /** + * set whether scale threshold should be increase whenever rotation is detected. + * + * @param increaseScaleThresholdWhenRotating If true, scale threshold will be increased. + */ + public void setIncreaseScaleThresholdWhenRotating(boolean increaseScaleThresholdWhenRotating) { + this.increaseScaleThresholdWhenRotating = increaseScaleThresholdWhenRotating; } /** diff --git a/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/maps/UiSettingsTest.java b/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/maps/UiSettingsTest.java index fbe00b4dce..cfce56e6e9 100644 --- a/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/maps/UiSettingsTest.java +++ b/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/maps/UiSettingsTest.java @@ -180,13 +180,6 @@ public class UiSettingsTest { assertEquals("Rotate gesture should be disabled", false, uiSettings.isRotateGesturesEnabled()); } - @Test - public void testRotateGestureChange() { - assertEquals("Default state should be true", true, uiSettings.isRotateGestureChangeAllowed()); - uiSettings.setRotateGestureChangeAllowed(false); - assertEquals("State should have been changed", false, uiSettings.isRotateGestureChangeAllowed()); - } - @Test public void testRotateGestureChangeAllowed() { uiSettings.setRotateGesturesEnabled(false); @@ -195,14 +188,6 @@ public class UiSettingsTest { assertEquals("Rotate gesture should be true", true, uiSettings.isRotateGesturesEnabled()); } - @Test - public void testRotateGestureChangeDisallowed() { - assertEquals("Rotate gesture should be true", true, uiSettings.isRotateGesturesEnabled()); - uiSettings.setRotateGestureChangeAllowed(false); - uiSettings.setRotateGesturesEnabled(false); - assertEquals("Rotate gesture change should be ignored", true, uiSettings.isRotateGesturesEnabled()); - } - @Test public void testTiltGesturesEnabled() { uiSettings.setTiltGesturesEnabled(true); @@ -215,13 +200,6 @@ public class UiSettingsTest { assertEquals("Tilt gesture should be disabled", false, uiSettings.isTiltGesturesEnabled()); } - @Test - public void testTiltGestureChange() { - assertEquals("Default state should be true", true, uiSettings.isTiltGestureChangeAllowed()); - uiSettings.setTiltGestureChangeAllowed(false); - assertEquals("State should have been changed", false, uiSettings.isTiltGestureChangeAllowed()); - } - @Test public void testTiltGestureChangeAllowed() { uiSettings.setTiltGesturesEnabled(false); @@ -230,14 +208,6 @@ public class UiSettingsTest { assertEquals("Tilt gesture should be true", true, uiSettings.isTiltGesturesEnabled()); } - @Test - public void testTiltGestureChangeDisallowed() { - assertEquals("Tilt gesture should be true", true, uiSettings.isTiltGesturesEnabled()); - uiSettings.setTiltGestureChangeAllowed(false); - uiSettings.setTiltGesturesEnabled(false); - assertEquals("Tilt gesture change should be ignored", true, uiSettings.isTiltGesturesEnabled()); - } - @Test public void testZoomGesturesEnabled() { uiSettings.setZoomGesturesEnabled(true); @@ -250,13 +220,6 @@ public class UiSettingsTest { assertEquals("Zoom gesture should be disabled", false, uiSettings.isZoomGesturesEnabled()); } - @Test - public void testZoomGestureChange() { - assertEquals("Default state should be true", true, uiSettings.isZoomGestureChangeAllowed()); - uiSettings.setZoomGestureChangeAllowed(false); - assertEquals("State should have been changed", false, uiSettings.isZoomGestureChangeAllowed()); - } - @Test public void testZoomGestureChangeAllowed() { uiSettings.setZoomGesturesEnabled(false); @@ -265,14 +228,6 @@ public class UiSettingsTest { assertEquals("Zoom gesture should be true", true, uiSettings.isZoomGesturesEnabled()); } - @Test - public void testZoomGestureChangeDisallowed() { - assertEquals("Zoom gesture should be true", true, uiSettings.isZoomGesturesEnabled()); - uiSettings.setZoomGestureChangeAllowed(false); - uiSettings.setZoomGesturesEnabled(false); - assertEquals("Zooom gesture change should be ignored", true, uiSettings.isZoomGesturesEnabled()); - } - @Test public void testZoomControlsEnabled() { uiSettings.setZoomControlsEnabled(true); @@ -297,13 +252,6 @@ public class UiSettingsTest { 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); @@ -312,14 +260,6 @@ public class UiSettingsTest { 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); @@ -332,13 +272,6 @@ public class UiSettingsTest { assertEquals("Scroll gesture should be disabled", false, uiSettings.isScrollGesturesEnabled()); } - @Test - public void testScrollGestureChange() { - assertEquals("Default state should be true", true, uiSettings.isScrollGestureChangeAllowed()); - uiSettings.setScrollGestureChangeAllowed(false); - assertEquals("State should have been changed", false, uiSettings.isScrollGestureChangeAllowed()); - } - @Test public void testScrollGestureChangeAllowed() { uiSettings.setScrollGesturesEnabled(false); @@ -348,11 +281,82 @@ public class UiSettingsTest { } @Test - public void testScrollGestureChangeDisallowed() { - assertEquals("Scroll gesture should be true", true, uiSettings.isScrollGesturesEnabled()); - uiSettings.setScrollGestureChangeAllowed(false); - uiSettings.setScrollGesturesEnabled(false); - assertEquals("Scroll gesture change should be ignored", true, uiSettings.isScrollGesturesEnabled()); + public void testScaleVelocityAnimationEnabled() { + uiSettings.setScaleVelocityAnimationEnabled(true); + assertEquals("Scale velocity animation should be enabled", true, uiSettings.isScaleVelocityAnimationEnabled()); + } + + @Test + public void testScaleVelocityAnimationDisabled() { + uiSettings.setScaleVelocityAnimationEnabled(false); + assertEquals("Scale velocity animation should be disabled", false, uiSettings.isScaleVelocityAnimationEnabled()); + } + + @Test + public void testRotateVelocityAnimationEnabled() { + uiSettings.setRotateVelocityAnimationEnabled(true); + assertEquals("Rotate velocity animation should be enabled", true, uiSettings.isRotateVelocityAnimationEnabled()); + } + + @Test + public void testRotateVelocityAnimationDisabled() { + uiSettings.setRotateVelocityAnimationEnabled(false); + assertEquals("Rotate velocity animation should be disabled", false, uiSettings.isRotateVelocityAnimationEnabled()); + } + + @Test + public void testFlingVelocityAnimationEnabled() { + uiSettings.setFlingVelocityAnimationEnabled(true); + assertEquals("Fling velocity animation should be enabled", true, uiSettings.isFlingVelocityAnimationEnabled()); + } + + @Test + public void testFlingVelocityAnimationDisabled() { + uiSettings.setFlingVelocityAnimationEnabled(false); + assertEquals("Fling velocity animation should be disabled", false, uiSettings.isFlingVelocityAnimationEnabled()); + } + + @Test + public void testAllVelocityAnimationsEnabled() { + uiSettings.setAllVelocityAnimationsEnabled(true); + assertEquals("Scale velocity animation should be enabled", true, uiSettings.isScaleVelocityAnimationEnabled()); + assertEquals("Rotate velocity animation should be enabled", true, uiSettings.isRotateVelocityAnimationEnabled()); + assertEquals("Fling velocity animation should be enabled", true, uiSettings.isFlingVelocityAnimationEnabled()); + } + + @Test + public void testAllVelocityAnimationsDisabled() { + uiSettings.setAllVelocityAnimationsEnabled(false); + assertEquals("Scale velocity animation should be disabled", false, uiSettings.isScaleVelocityAnimationEnabled()); + assertEquals("Rotate velocity animation should be disabled", false, uiSettings.isRotateVelocityAnimationEnabled()); + assertEquals("Fling velocity animation should be disabled", false, uiSettings.isFlingVelocityAnimationEnabled()); + } + + @Test + public void testIncreaseRotateThresholdWhenScalingEnabled() { + uiSettings.setIncreaseRotateThresholdWhenScaling(true); + assertEquals("Rotate threshold increase should be enabled", true, + uiSettings.isIncreaseRotateThresholdWhenScaling()); + } + + @Test + public void testIncreaseRotateThresholdWhenScalingDisabled() { + uiSettings.setIncreaseRotateThresholdWhenScaling(false); + assertEquals("Rotate threshold increase should be disabled", false, + uiSettings.isIncreaseRotateThresholdWhenScaling()); + } + + @Test + public void testIncreaseScaleThresholdWhenRotatingEnabled() { + uiSettings.setIncreaseScaleThresholdWhenRotating(true); + assertEquals("Scale threshold increase should be enabled", true, uiSettings.isIncreaseScaleThresholdWhenRotating()); + } + + @Test + public void testIncreaseScaleThresholdWhenRotatingDisabled() { + uiSettings.setIncreaseScaleThresholdWhenRotating(false); + assertEquals("Scale threshold increase should be disabled", false, + uiSettings.isIncreaseScaleThresholdWhenRotating()); } @Test -- cgit v1.2.1