diff options
author | Łukasz Paczos <lukas.paczos@gmail.com> | 2019-08-14 13:22:35 +0200 |
---|---|---|
committer | Łukasz Paczos <lukasz.paczos@mapbox.com> | 2019-08-15 18:08:29 +0300 |
commit | eab3fbf5bfc35772eba9786844f497e550a72381 (patch) | |
tree | f2423711eb49f800848d2ef1caee41802696458a | |
parent | acc6079b088c75d279b4e55bd8687edf8916144c (diff) | |
download | qtlocation-mapboxgl-eab3fbf5bfc35772eba9786844f497e550a72381.tar.gz |
[android] bring back scale delta span threshold when rotation is started first
4 files changed, 41 insertions, 6 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 015260322c..d2694b5b8a 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 @@ -74,6 +74,14 @@ public class MapboxConstants { public static final long VELOCITY_THRESHOLD_IGNORE_FLING = 1000; /** + * Value by which the default rotation threshold will be increased when scaling + * + * @deprecated unused, see {@link com.mapbox.mapboxsdk.maps.UiSettings#setDisableRotateWhenScaling(boolean)} + */ + @Deprecated + public static final float ROTATION_THRESHOLD_INCREASE_WHEN_SCALING = 25f; + + /** * Maximum absolute zoom change for multi-pointer scale velocity animation */ public static final double MAX_ABSOLUTE_SCALE_VELOCITY_CHANGE = 2.5; @@ -84,6 +92,14 @@ public class MapboxConstants { public static final double SCALE_VELOCITY_ANIMATION_DURATION_MULTIPLIER = 150; /** + * Minimum angular velocity for rotation animation + * + * @deprecated unused, see {@link #ROTATE_VELOCITY_RATIO_THRESHOLD} + */ + @Deprecated + public static final float MINIMUM_ANGULAR_VELOCITY = 1.5f; + + /** * Last scale span delta to XY velocity ratio required to execute scale velocity animation. */ public static final double SCALE_VELOCITY_RATIO_THRESHOLD = 4 * 1e-3; 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 80b1e32413..0b28c669af 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 @@ -123,9 +123,12 @@ final class MapGestureDetector { context.getResources().getDimension(R.dimen.mapbox_minimum_scale_velocity) ); RotateGestureListener rotateGestureListener = new RotateGestureListener( + context.getResources().getDimension(R.dimen.mapbox_minimum_scale_span_when_rotating), context.getResources().getDimension(R.dimen.mapbox_density_constant), context.getResources().getDimension(R.dimen.mapbox_angular_velocity_multiplier), - context.getResources().getDimension(R.dimen.mapbox_minimum_angular_velocity)); + context.getResources().getDimension(R.dimen.mapbox_minimum_angular_velocity), + context.getResources().getDimension( + com.mapbox.android.gestures.R.dimen.mapbox_defaultScaleSpanSinceStartThreshold)); ShoveGestureListener shoveGestureListener = new ShoveGestureListener(); TapGestureListener tapGestureListener = new TapGestureListener(); @@ -641,14 +644,19 @@ final class MapGestureDetector { } private final class RotateGestureListener extends RotateGestureDetector.SimpleOnRotateGestureListener { + private final float minimumScaleSpanWhenRotating; private final float angularVelocityMultiplier; private final float minimumAngularVelocity; private final double rotateVelocityRatioThreshold; + private final float defaultSpanSinceStartThreshold; - RotateGestureListener(double densityMultiplier, float angularVelocityMultiplier, float minimumAngularVelocity) { + RotateGestureListener(float minimumScaleSpanWhenRotating, double densityMultiplier, float angularVelocityMultiplier, + float minimumAngularVelocity, float defaultSpanSinceStartThreshold) { + this.minimumScaleSpanWhenRotating = minimumScaleSpanWhenRotating; this.angularVelocityMultiplier = angularVelocityMultiplier; this.minimumAngularVelocity = minimumAngularVelocity; this.rotateVelocityRatioThreshold = ROTATE_VELOCITY_RATIO_THRESHOLD * densityMultiplier; + this.defaultSpanSinceStartThreshold = defaultSpanSinceStartThreshold; } @Override @@ -675,6 +683,13 @@ final class MapGestureDetector { return false; } + 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(); + } + cancelTransitionsIfRequired(); notifyOnRotateBeginListeners(detector); @@ -703,6 +718,11 @@ final class MapGestureDetector { @Override public void onRotateEnd(@NonNull RotateGestureDetector detector, float velocityX, float velocityY, float angularVelocity) { + if (uiSettings.isIncreaseScaleThresholdWhenRotating()) { + // resetting default scale threshold values + gesturesManager.getStandardScaleGestureDetector().setSpanSinceStartThreshold(defaultSpanSinceStartThreshold); + } + notifyOnRotateEndListeners(detector); angularVelocity = angularVelocity * angularVelocityMultiplier; 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 4c4ced8804..9e72be8e9b 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 @@ -962,9 +962,7 @@ public final class UiSettings { * Returns whether scale threshold should be increase whenever rotation is detected. * * @return If true, scale threshold will be increased. - * @deprecated unused */ - @Deprecated public boolean isIncreaseScaleThresholdWhenRotating() { return increaseScaleThresholdWhenRotating; } @@ -973,9 +971,7 @@ public final class UiSettings { * set whether scale threshold should be increase whenever rotation is detected. * * @param increaseScaleThresholdWhenRotating If true, scale threshold will be increased. - * @deprecated unused */ - @Deprecated public void setIncreaseScaleThresholdWhenRotating(boolean increaseScaleThresholdWhenRotating) { this.increaseScaleThresholdWhenRotating = increaseScaleThresholdWhenRotating; } diff --git a/platform/android/MapboxGLAndroidSDK/src/main/res/values/dimens.xml b/platform/android/MapboxGLAndroidSDK/src/main/res/values/dimens.xml index b2a0061c5b..012e46cc07 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/res/values/dimens.xml +++ b/platform/android/MapboxGLAndroidSDK/src/main/res/values/dimens.xml @@ -12,6 +12,9 @@ <!--Minimum scale velocity required to start animation--> <dimen name="mapbox_minimum_scale_velocity">225dp</dimen> + <!--Minimum scale span delta required to execute scale gesture when rotating--> + <dimen name="mapbox_minimum_scale_span_when_rotating">75dp</dimen> + <!--Minimum angular velocity required to start rotation animation--> <dimen name="mapbox_minimum_angular_velocity">0.10dp</dimen> |