summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorŁukasz Paczos <lukas.paczos@gmail.com>2018-03-07 11:04:32 +0100
committerŁukasz Paczos <lukas.paczos@gmail.com>2018-03-07 11:04:32 +0100
commit63a8ba283963771d1f362e98f291e00c545e2ed9 (patch)
treec591ef317097cf60bb3388f139d633931e088632
parent990999402caca7e149e44a2ac73694d751ed7bc4 (diff)
downloadqtlocation-mapboxgl-63a8ba283963771d1f362e98f291e00c545e2ed9.tar.gz
[android] enable/disable velocity animations
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/MapGestureDetector.java26
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/maps/UiSettings.java69
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/maps/UiSettingsTest.java52
3 files changed, 140 insertions, 7 deletions
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..61fdae5678 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
@@ -367,11 +367,17 @@ final class MapGestureDetector {
@Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
- if ((!uiSettings.isScrollGesturesEnabled())) {
+ if (!uiSettings.isScrollGesturesEnabled()) {
// don't allow a fling is scroll is disabled
return false;
}
+ notifyOnFlingListeners();
+
+ if (!uiSettings.isFlingVelocityAnimationEnabled()) {
+ return false;
+ }
+
float screenDensity = uiSettings.getPixelRatio();
// calculate velocity vector for xy dimensions, independent from screen size
@@ -396,8 +402,6 @@ final class MapGestureDetector {
// update transformation
transform.moveBy(offsetX, offsetY, animationTime);
- notifyOnFlingListeners();
-
return true;
}
}
@@ -512,6 +516,12 @@ final class MapGestureDetector {
gesturesManager.getRotateGestureDetector().getDefaultAngleThreshold()
);
+ notifyOnScaleEndListeners(detector);
+
+ if (!uiSettings.isScaleVelocityAnimationEnabled()) {
+ return;
+ }
+
float velocityXY = Math.abs(velocityX) + Math.abs(velocityY);
if (velocityXY > minimumVelocity) {
double zoomAddition = calculateScale(velocityXY, detector.isScalingOut());
@@ -520,8 +530,6 @@ final class MapGestureDetector {
scaleAnimator = createScaleAnimator(currentZoom, zoomAddition, scaleFocalPoint, animationTime);
scheduleAnimator(scaleAnimator);
}
-
- notifyOnScaleEndListeners(detector);
}
private void setScaleFocalPoint(StandardScaleGestureDetector detector) {
@@ -620,6 +628,12 @@ final class MapGestureDetector {
gesturesManager.getStandardScaleGestureDetector().setSpanSinceStartThreshold(
gesturesManager.getStandardScaleGestureDetector().getDefaultSpanSinceStartThreshold());
+ notifyOnRotateEndListeners(detector);
+
+ if (!uiSettings.isRotateVelocityAnimationEnabled()) {
+ return;
+ }
+
if (Math.abs(angularVelocity) < minimumAngularVelocity) {
return;
}
@@ -637,8 +651,6 @@ final class MapGestureDetector {
rotateAnimator = createRotateAnimator(angularVelocity, animationTime);
scheduleAnimator(rotateAnimator);
-
- notifyOnRotateEndListeners(detector);
}
private void setRotateFocalPoint(RotateGestureDetector detector) {
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..a7448cd087 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
@@ -61,6 +61,10 @@ public final class UiSettings {
private boolean doubleTapGesturesEnabled = true;
private boolean doubleTapGestureChangeAllowed = true;
+ private boolean scaleVelocityAnimationEnabled = true;
+ private boolean rotateVelocityAnimationEnabled = true;
+ private boolean flingVelocityAnimationEnabled = true;
+
private boolean deselectMarkersOnTap = true;
private PointF userProvidedFocalPoint;
@@ -874,6 +878,71 @@ public final class UiSettings {
}
/**
+ * 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;
+ }
+
+ /**
+ * 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);
+ }
+
+ /**
* <p>
* Sets the preference for whether all gestures should be enabled or disabled.
* </p>
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..cbec0e569d 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
@@ -356,6 +356,58 @@ public class UiSettingsTest {
}
@Test
+ 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 testAllGesturesEnabled() {
uiSettings.setAllGesturesEnabled(true);
assertEquals("Rotate gesture should be enabled", true, uiSettings.isRotateGesturesEnabled());