diff options
author | Łukasz Paczos <lukas.paczos@gmail.com> | 2018-12-13 16:26:25 +0100 |
---|---|---|
committer | Łukasz Paczos <lukasz.paczos@mapbox.com> | 2018-12-14 10:26:24 +0100 |
commit | 9064c8e4a1349eea0a7a0e1d63bb53b425709635 (patch) | |
tree | 4e660be020e2219a90037bd3d68fb59f49763137 | |
parent | e86d1b2ac99452819396e2e617a77b2918cd5a04 (diff) | |
download | qtlocation-mapboxgl-9064c8e4a1349eea0a7a0e1d63bb53b425709635.tar.gz |
[android] option to disable smooth animation of compass and accuracy values
9 files changed, 215 insertions, 46 deletions
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/location/LocationAnimatorCoordinator.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/location/LocationAnimatorCoordinator.java index 8dd05c3f0c..4a9705a33b 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/location/LocationAnimatorCoordinator.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/location/LocationAnimatorCoordinator.java @@ -1,7 +1,6 @@ package com.mapbox.mapboxsdk.location; import android.animation.Animator; -import android.animation.AnimatorSet; import android.location.Location; import android.os.SystemClock; import android.support.annotation.NonNull; @@ -46,9 +45,13 @@ final class LocationAnimatorCoordinator { private float previousCompassBearing = -1; private long locationUpdateTimestamp = -1; private float durationMultiplier; + private final MapboxAnimatorSetProvider animatorSetProvider; + private boolean compassAnimationEnabled; + private boolean accuracyAnimationEnabled; - LocationAnimatorCoordinator(Projection projection) { + LocationAnimatorCoordinator(@NonNull Projection projection, @NonNull MapboxAnimatorSetProvider animatorSetProvider) { this.projection = projection; + this.animatorSetProvider = animatorSetProvider; } void addLayerListener(MapboxAnimator.OnLayerAnimationsValuesChangeListener listener) { @@ -103,7 +106,7 @@ final class LocationAnimatorCoordinator { float previousCameraBearing = (float) currentCameraPosition.bearing; updateCompassAnimators(targetCompassBearing, previousLayerBearing, previousCameraBearing); - playCompassAnimators(COMPASS_UPDATE_RATE_MS); + playCompassAnimators(compassAnimationEnabled ? COMPASS_UPDATE_RATE_MS : 0); previousCompassBearing = targetCompassBearing; } @@ -115,7 +118,7 @@ final class LocationAnimatorCoordinator { float previousAccuracyRadius = getPreviousAccuracyRadius(); updateAccuracyAnimators(targetAccuracyRadius, previousAccuracyRadius); - playAccuracyAnimator(noAnimation ? 0 : ACCURACY_RADIUS_ANIMATION_DURATION); + playAccuracyAnimator(noAnimation || !accuracyAnimationEnabled ? 0 : ACCURACY_RADIUS_ANIMATION_DURATION); this.previousAccuracyRadius = targetAccuracyRadius; } @@ -255,27 +258,20 @@ final class LocationAnimatorCoordinator { locationAnimators.add(animatorArray.get(ANIMATOR_LAYER_GPS_BEARING)); locationAnimators.add(animatorArray.get(ANIMATOR_CAMERA_LATLNG)); locationAnimators.add(animatorArray.get(ANIMATOR_CAMERA_GPS_BEARING)); - AnimatorSet locationAnimatorSet = new AnimatorSet(); - locationAnimatorSet.playTogether(locationAnimators); - locationAnimatorSet.setInterpolator(new LinearInterpolator()); - locationAnimatorSet.setDuration(duration); - locationAnimatorSet.start(); + animatorSetProvider.startAnimation(locationAnimators, new LinearInterpolator(), duration); } private void playCompassAnimators(long duration) { List<Animator> compassAnimators = new ArrayList<>(); compassAnimators.add(animatorArray.get(ANIMATOR_LAYER_COMPASS_BEARING)); compassAnimators.add(animatorArray.get(ANIMATOR_CAMERA_COMPASS_BEARING)); - AnimatorSet compassAnimatorSet = new AnimatorSet(); - compassAnimatorSet.playTogether(compassAnimators); - compassAnimatorSet.setDuration(duration); - compassAnimatorSet.start(); + animatorSetProvider.startAnimation(compassAnimators, new LinearInterpolator(), duration); } private void playAccuracyAnimator(long duration) { - MapboxAnimator animator = animatorArray.get(ANIMATOR_LAYER_ACCURACY); - animator.setDuration(duration); - animator.start(); + List<Animator> accuracyAnimators = new ArrayList<>(); + accuracyAnimators.add(animatorArray.get(ANIMATOR_LAYER_ACCURACY)); + animatorSetProvider.startAnimation(accuracyAnimators, new LinearInterpolator(), duration); } private void playZoomAnimator(long duration) { @@ -294,11 +290,7 @@ final class LocationAnimatorCoordinator { List<Animator> locationAnimators = new ArrayList<>(); locationAnimators.add(animatorArray.get(ANIMATOR_CAMERA_LATLNG)); locationAnimators.add(animatorArray.get(ANIMATOR_CAMERA_GPS_BEARING)); - AnimatorSet locationAnimatorSet = new AnimatorSet(); - locationAnimatorSet.playTogether(locationAnimators); - locationAnimatorSet.setInterpolator(new FastOutSlowInInterpolator()); - locationAnimatorSet.setDuration(duration); - locationAnimatorSet.start(); + animatorSetProvider.startAnimation(locationAnimators, new FastOutSlowInInterpolator(), duration); } void resetAllCameraAnimations(@NonNull CameraPosition currentCameraPosition, boolean isGpsNorth) { @@ -387,4 +379,12 @@ final class LocationAnimatorCoordinator { void setTrackingAnimationDurationMultiplier(float trackingAnimationDurationMultiplier) { this.durationMultiplier = trackingAnimationDurationMultiplier; } + + void setCompassAnimationEnabled(boolean compassAnimationEnabled) { + this.compassAnimationEnabled = compassAnimationEnabled; + } + + void setAccuracyAnimationEnabled(boolean accuracyAnimationEnabled) { + this.accuracyAnimationEnabled = accuracyAnimationEnabled; + } } diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/location/LocationComponent.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/location/LocationComponent.java index 66eb24acbc..07194cdc89 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/location/LocationComponent.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/location/LocationComponent.java @@ -550,6 +550,8 @@ public final class LocationComponent { staleStateManager.setEnabled(options.enableStaleState()); staleStateManager.setDelayTime(options.staleStateTimeout()); locationAnimatorCoordinator.setTrackingAnimationDurationMultiplier(options.trackingAnimationDurationMultiplier()); + locationAnimatorCoordinator.setCompassAnimationEnabled(options.compassAnimationEnabled()); + locationAnimatorCoordinator.setAccuracyAnimationEnabled(options.accuracyAnimationEnabled()); updateMapWithOptions(options); } } @@ -1015,7 +1017,10 @@ public final class LocationComponent { locationCameraController = new LocationCameraController( context, mapboxMap, cameraTrackingChangedListener, options, onCameraMoveInvalidateListener); - locationAnimatorCoordinator = new LocationAnimatorCoordinator(mapboxMap.getProjection()); + locationAnimatorCoordinator = new LocationAnimatorCoordinator( + mapboxMap.getProjection(), + MapboxAnimatorSetProvider.getInstance() + ); locationAnimatorCoordinator.addLayerListener(locationLayerController); locationAnimatorCoordinator.addCameraListener(locationCameraController); locationAnimatorCoordinator.setTrackingAnimationDurationMultiplier(options diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/location/LocationComponentConstants.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/location/LocationComponentConstants.java index 912141c627..093c91e799 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/location/LocationComponentConstants.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/location/LocationComponentConstants.java @@ -6,7 +6,7 @@ package com.mapbox.mapboxsdk.location; final class LocationComponentConstants { // Controls the compass update rate in milliseconds - static final int COMPASS_UPDATE_RATE_MS = 500; + static final long COMPASS_UPDATE_RATE_MS = 500; // Sets the transition animation duration when switching camera modes. static final long TRANSITION_ANIMATION_DURATION_MS = 750; diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/location/LocationComponentOptions.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/location/LocationComponentOptions.java index db86db925c..a7b83d7d9d 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/location/LocationComponentOptions.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/location/LocationComponentOptions.java @@ -110,6 +110,8 @@ public class LocationComponentOptions implements Parcelable { private float trackingMultiFingerMoveThreshold; private String layerBelow; private float trackingAnimationDurationMultiplier; + private boolean compassAnimationEnabled; + private boolean accuracyAnimationEnabled; public LocationComponentOptions( float accuracyAlpha, @@ -141,7 +143,9 @@ public class LocationComponentOptions implements Parcelable { float trackingInitialMoveThreshold, float trackingMultiFingerMoveThreshold, String layerBelow, - float trackingAnimationDurationMultiplier) { + float trackingAnimationDurationMultiplier, + boolean compassAnimationEnabled, + boolean accuracyAnimationEnabled) { this.accuracyAlpha = accuracyAlpha; this.accuracyColor = accuracyColor; this.backgroundDrawableStale = backgroundDrawableStale; @@ -175,6 +179,8 @@ public class LocationComponentOptions implements Parcelable { this.trackingMultiFingerMoveThreshold = trackingMultiFingerMoveThreshold; this.layerBelow = layerBelow; this.trackingAnimationDurationMultiplier = trackingAnimationDurationMultiplier; + this.compassAnimationEnabled = compassAnimationEnabled; + this.accuracyAnimationEnabled = accuracyAnimationEnabled; } /** @@ -281,6 +287,14 @@ public class LocationComponentOptions implements Parcelable { ); builder.trackingAnimationDurationMultiplier(trackingAnimationDurationMultiplier); + builder.compassAnimationEnabled = typedArray.getBoolean( + R.styleable.mapbox_LocationComponent_mapbox_compassAnimationEnabled, true + ); + + builder.accuracyAnimationEnabled = typedArray.getBoolean( + R.styleable.mapbox_LocationComponent_mapbox_accuracyAnimationEnabled, true + ); + typedArray.recycle(); return builder.build(); @@ -347,7 +361,7 @@ public class LocationComponentOptions implements Parcelable { /** * String image name, identical to one used in - * the first parameter of {@link com.mapbox.mapboxsdk.maps.MapboxMap#addImage(String, Bitmap)}, the + * the first parameter of {@link com.mapbox.mapboxsdk.maps.Style.Builder#addImage(String, Bitmap)}, the * component, will use this image in place of the provided or default mapbox_foregroundDrawableStale. * <p> * A maki-icon name (example: "circle-15") may also be provided. These are images that can be loaded @@ -374,7 +388,7 @@ public class LocationComponentOptions implements Parcelable { /** * String image name, identical to one used in - * the first parameter of {@link com.mapbox.mapboxsdk.maps.MapboxMap#addImage(String, Bitmap)}, the + * the first parameter of {@link com.mapbox.mapboxsdk.maps.Style.Builder#addImage(String, Bitmap)}, the * component, will used this image in place of the provided or default mapbox_foregroundDrawableStale. * <p> * A maki-icon name (example: "circle-15") may also be provided. These are images that can be loaded @@ -401,7 +415,7 @@ public class LocationComponentOptions implements Parcelable { /** * String image name, identical to one used in - * the first parameter of {@link com.mapbox.mapboxsdk.maps.MapboxMap#addImage(String, Bitmap)}, the + * the first parameter of {@link com.mapbox.mapboxsdk.maps.Style.Builder#addImage(String, Bitmap)}, the * component, will used this image in place of the provided or default mapbox_gpsDrawable. * <p> * A maki-icon name (example: "circle-15") may also be provided. These are images that can be loaded @@ -428,7 +442,7 @@ public class LocationComponentOptions implements Parcelable { /** * String image name, identical to one used in - * the first parameter of {@link com.mapbox.mapboxsdk.maps.MapboxMap#addImage(String, Bitmap)}, the + * the first parameter of {@link com.mapbox.mapboxsdk.maps.Style.Builder#addImage(String, Bitmap)}, the * component, will used this image in place of the provided or default mapbox_foregroundDrawable. * <p> * A maki-icon name (example: "circle-15") may also be provided. These are images that can be loaded @@ -455,7 +469,7 @@ public class LocationComponentOptions implements Parcelable { /** * String image name, identical to one used in - * the first parameter of {@link com.mapbox.mapboxsdk.maps.MapboxMap#addImage(String, Bitmap)}, the + * the first parameter of {@link com.mapbox.mapboxsdk.maps.Style.Builder#addImage(String, Bitmap)}, the * component, will used this image in place of the provided or default mapbox_backgroundDrawable. * <p> * A maki-icon name (example: "circle-15") may also be provided. These are images that can be loaded @@ -482,7 +496,7 @@ public class LocationComponentOptions implements Parcelable { /** * String image name, identical to one used in - * the first parameter of {@link com.mapbox.mapboxsdk.maps.MapboxMap#addImage(String, Bitmap)}, the + * the first parameter of {@link com.mapbox.mapboxsdk.maps.Style.Builder#addImage(String, Bitmap)}, the * component, will used this image in place of the provided or default mapbox_bearingDrawable. * <p> * A maki-icon name (example: "circle-15") may also be provided. These are images that can be loaded @@ -684,6 +698,25 @@ public class LocationComponentOptions implements Parcelable { return trackingAnimationDurationMultiplier; } + /** + * Enable or disable smooth animation of compass values for {@link com.mapbox.mapboxsdk.location.modes.CameraMode} + * and {@link com.mapbox.mapboxsdk.location.modes.RenderMode}. + * + * @return whether smooth compass animation is enabled + */ + public boolean compassAnimationEnabled() { + return compassAnimationEnabled; + } + + /** + * Enable or disable smooth animation of the accuracy circle around the user's position. + * + * @return whether smooth animation of the accuracy circle is enabled + */ + public boolean accuracyAnimationEnabled() { + return accuracyAnimationEnabled; + } + @NonNull @Override public String toString() { @@ -836,6 +869,10 @@ public class LocationComponentOptions implements Parcelable { h$ ^= Float.floatToIntBits(trackingMultiFingerMoveThreshold); h$ *= 1000003; h$ ^= Float.floatToIntBits(trackingAnimationDurationMultiplier); + h$ *= 1000003; + h$ ^= compassAnimationEnabled ? 1231 : 1237; + h$ *= 1000003; + h$ ^= accuracyAnimationEnabled ? 1231 : 1237; return h$; } @@ -873,7 +910,9 @@ public class LocationComponentOptions implements Parcelable { in.readFloat(), in.readFloat(), in.readString(), - in.readFloat() + in.readFloat(), + in.readInt() == 1, + in.readInt() == 1 ); } @@ -970,6 +1009,8 @@ public class LocationComponentOptions implements Parcelable { dest.writeFloat(trackingMultiFingerMoveThreshold()); dest.writeString(layerBelow()); dest.writeFloat(trackingAnimationDurationMultiplier); + dest.writeInt(compassAnimationEnabled() ? 1 : 0); + dest.writeInt(accuracyAnimationEnabled() ? 1 : 0); } @Override @@ -1045,6 +1086,8 @@ public class LocationComponentOptions implements Parcelable { private Float trackingMultiFingerMoveThreshold; private String layerBelow; private Float trackingAnimationDurationMultiplier; + private Boolean compassAnimationEnabled; + private Boolean accuracyAnimationEnabled; Builder() { } @@ -1080,6 +1123,8 @@ public class LocationComponentOptions implements Parcelable { this.trackingMultiFingerMoveThreshold = source.trackingMultiFingerMoveThreshold(); this.layerBelow = source.layerBelow(); this.trackingAnimationDurationMultiplier = source.trackingAnimationDurationMultiplier(); + this.compassAnimationEnabled = source.compassAnimationEnabled(); + this.accuracyAnimationEnabled = source.accuracyAnimationEnabled(); } /** @@ -1124,7 +1169,7 @@ public class LocationComponentOptions implements Parcelable { /** * Given a String image name, identical to one used in - * the first parameter of {@link com.mapbox.mapboxsdk.maps.MapboxMap#addImage(String, Bitmap)}, the + * the first parameter of {@link com.mapbox.mapboxsdk.maps.Style.Builder#addImage(String, Bitmap)}, the * component, will used this image in place of the provided or default mapbox_backgroundDrawableStale. * <p> * A maki-icon name (example: "circle-15") may also be provided. These are images that can be loaded @@ -1155,7 +1200,7 @@ public class LocationComponentOptions implements Parcelable { /** * Given a String image name, identical to one used in - * the first parameter of {@link com.mapbox.mapboxsdk.maps.MapboxMap#addImage(String, Bitmap)}, the + * the first parameter of {@link com.mapbox.mapboxsdk.maps.Style.Builder#addImage(String, Bitmap)}, the * component, will used this image in place of the provided or default mapbox_foregroundDrawableStale. * <p> * A maki-icon name (example: "circle-15") may also be provided. These are images that can be loaded @@ -1186,7 +1231,7 @@ public class LocationComponentOptions implements Parcelable { /** * Given a String image name, identical to one used in - * the first parameter of {@link com.mapbox.mapboxsdk.maps.MapboxMap#addImage(String, Bitmap)}, the + * the first parameter of {@link com.mapbox.mapboxsdk.maps.Style.Builder#addImage(String, Bitmap)}, the * component, will used this image in place of the provided or default mapbox_gpsDrawable. * <p> * A maki-icon name (example: "circle-15") may also be provided. These are images that can be loaded @@ -1217,7 +1262,7 @@ public class LocationComponentOptions implements Parcelable { /** * Given a String image name, identical to one used in - * the first parameter of {@link com.mapbox.mapboxsdk.maps.MapboxMap#addImage(String, Bitmap)}, the + * the first parameter of {@link com.mapbox.mapboxsdk.maps.Style.Builder#addImage(String, Bitmap)}, the * component, will used this image in place of the provided or default mapbox_foregroundDrawable. * <p> * A maki-icon name (example: "circle-15") may also be provided. These are images that can be loaded @@ -1248,7 +1293,7 @@ public class LocationComponentOptions implements Parcelable { /** * Given a String image name, identical to one used in - * the first parameter of {@link com.mapbox.mapboxsdk.maps.MapboxMap#addImage(String, Bitmap)}, the + * the first parameter of {@link com.mapbox.mapboxsdk.maps.Style.Builder#addImage(String, Bitmap)}, the * component, will used this image in place of the provided or default mapbox_backgroundDrawable. * <p> * A maki-icon name (example: "circle-15") may also be provided. These are images that can be loaded @@ -1279,7 +1324,7 @@ public class LocationComponentOptions implements Parcelable { /** * Given a String image name, identical to one used in - * the first parameter of {@link com.mapbox.mapboxsdk.maps.MapboxMap#addImage(String, Bitmap)}, the + * the first parameter of {@link com.mapbox.mapboxsdk.maps.Style.Builder#addImage(String, Bitmap)}, the * component, will used this image in place of the provided or default mapbox_bearingDrawable. * <p> * A maki-icon name (example: "circle-15") may also be provided. These are images that can be loaded @@ -1524,6 +1569,27 @@ public class LocationComponentOptions implements Parcelable { return this; } + /** + * Enable or disable smooth animation of compass values for {@link com.mapbox.mapboxsdk.location.modes.CameraMode} + * and {@link com.mapbox.mapboxsdk.location.modes.RenderMode}. + * + * @return whether smooth compass animation is enabled + */ + public LocationComponentOptions.Builder compassAnimationEnabled(Boolean compassAnimationEnabled) { + this.compassAnimationEnabled = compassAnimationEnabled; + return this; + } + + /** + * Enable or disable smooth animation of the accuracy circle around the user's position. + * + * @return whether smooth animation of the accuracy circle is enabled + */ + public Builder accuracyAnimationEnabled(Boolean accuracyAnimationEnabled) { + this.accuracyAnimationEnabled = accuracyAnimationEnabled; + return this; + } + @Nullable LocationComponentOptions autoBuild() { String missing = ""; @@ -1614,7 +1680,9 @@ public class LocationComponentOptions implements Parcelable { this.trackingInitialMoveThreshold, this.trackingMultiFingerMoveThreshold, this.layerBelow, - this.trackingAnimationDurationMultiplier); + this.trackingAnimationDurationMultiplier, + this.compassAnimationEnabled, + this.accuracyAnimationEnabled); } } } diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/location/MapboxAnimatorSetProvider.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/location/MapboxAnimatorSetProvider.java new file mode 100644 index 0000000000..1d09f8ae71 --- /dev/null +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/location/MapboxAnimatorSetProvider.java @@ -0,0 +1,32 @@ +package com.mapbox.mapboxsdk.location; + +import android.animation.Animator; +import android.animation.AnimatorSet; +import android.support.annotation.NonNull; +import android.view.animation.Interpolator; + +import java.util.List; + +class MapboxAnimatorSetProvider { + private static MapboxAnimatorSetProvider instance; + + private MapboxAnimatorSetProvider() { + // private constructor + } + + static MapboxAnimatorSetProvider getInstance() { + if (instance == null) { + instance = new MapboxAnimatorSetProvider(); + } + return instance; + } + + void startAnimation(@NonNull List<Animator> animators, @NonNull Interpolator interpolator, + long duration) { + AnimatorSet locationAnimatorSet = new AnimatorSet(); + locationAnimatorSet.playTogether(animators); + locationAnimatorSet.setInterpolator(interpolator); + locationAnimatorSet.setDuration(duration); + locationAnimatorSet.start(); + } +} diff --git a/platform/android/MapboxGLAndroidSDK/src/main/res-public/values/public.xml b/platform/android/MapboxGLAndroidSDK/src/main/res-public/values/public.xml index 75943e0aa2..b259b774da 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/res-public/values/public.xml +++ b/platform/android/MapboxGLAndroidSDK/src/main/res-public/values/public.xml @@ -143,4 +143,10 @@ <!-- Animation duration multiplier --> <public name="mapbox_trackingAnimationDurationMultiplier" format="float" type="attr" /> + + <!-- Compass animation --> + <public name="mapbox_compassAnimationEnabled" format="boolean" type="attr" /> + + <!-- Accuracy animation--> + <public name="mapbox_accuracyAnimationEnabled" format="boolean" type="attr" /> </resources> diff --git a/platform/android/MapboxGLAndroidSDK/src/main/res/values/attrs.xml b/platform/android/MapboxGLAndroidSDK/src/main/res/values/attrs.xml index cb1dff80a1..c1c9b91056 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/res/values/attrs.xml +++ b/platform/android/MapboxGLAndroidSDK/src/main/res/values/attrs.xml @@ -169,5 +169,11 @@ <!-- Animation duration multiplier --> <attr name="mapbox_trackingAnimationDurationMultiplier" format="float" /> + <!-- Compass animation --> + <attr name="mapbox_compassAnimationEnabled" format="boolean" /> + + <!-- Accuracy animation--> + <attr name="mapbox_accuracyAnimationEnabled" format="boolean" /> + </declare-styleable> </resources> diff --git a/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/location/LocationAnimatorCoordinatorTest.kt b/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/location/LocationAnimatorCoordinatorTest.kt index fad71237ab..b02b99edc7 100644 --- a/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/location/LocationAnimatorCoordinatorTest.kt +++ b/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/location/LocationAnimatorCoordinatorTest.kt @@ -1,19 +1,23 @@ package com.mapbox.mapboxsdk.location +import android.animation.Animator import android.location.Location +import android.view.animation.LinearInterpolator import com.mapbox.mapboxsdk.camera.CameraPosition import com.mapbox.mapboxsdk.geometry.LatLng import com.mapbox.mapboxsdk.location.LocationComponentConstants.DEFAULT_TRACKING_TILT_ANIM_DURATION import com.mapbox.mapboxsdk.location.LocationComponentConstants.DEFAULT_TRACKING_ZOOM_ANIM_DURATION import com.mapbox.mapboxsdk.location.MapboxAnimator.* import com.mapbox.mapboxsdk.maps.Projection +import io.mockk.every +import io.mockk.mockk +import io.mockk.verify import junit.framework.Assert.assertEquals import junit.framework.Assert.assertTrue import org.junit.Before import org.junit.Test import org.junit.runner.RunWith import org.mockito.Mockito -import org.mockito.Mockito.mock import org.robolectric.RobolectricTestRunner @RunWith(RobolectricTestRunner::class) @@ -22,9 +26,15 @@ class LocationAnimatorCoordinatorTest { private lateinit var locationAnimatorCoordinator: LocationAnimatorCoordinator private val cameraPosition: CameraPosition = CameraPosition.DEFAULT + private val animatorSetProvider: MapboxAnimatorSetProvider = mockk() + + private val projection: Projection = mockk() + @Before fun setUp() { - locationAnimatorCoordinator = LocationAnimatorCoordinator(mock(Projection::class.java)) + locationAnimatorCoordinator = LocationAnimatorCoordinator(projection, animatorSetProvider) + every { projection.getMetersPerPixelAtLatitude(any()) } answers { 1.0 } + every { animatorSetProvider.startAnimation(any(), any(), any()) } answers {} } @Test @@ -127,9 +137,6 @@ class LocationAnimatorCoordinatorTest { val layerAccuracy = locationAnimatorCoordinator.animatorArray[ANIMATOR_LAYER_ACCURACY]?.target as Float assertEquals(layerAccuracy, accuracy) - - val animationDuration = locationAnimatorCoordinator.animatorArray[ANIMATOR_LAYER_ACCURACY]?.duration as Long - assertEquals(LocationComponentConstants.ACCURACY_RADIUS_ANIMATION_DURATION, animationDuration) } @Test @@ -146,9 +153,6 @@ class LocationAnimatorCoordinatorTest { val layerAccuracy = locationAnimatorCoordinator.animatorArray[ANIMATOR_LAYER_ACCURACY]?.target as Float assertEquals(layerAccuracy, accuracy) - - val animationDuration = locationAnimatorCoordinator.animatorArray[ANIMATOR_LAYER_ACCURACY]?.duration as Long - assertEquals(0L, animationDuration) } @Test @@ -283,4 +287,50 @@ class LocationAnimatorCoordinatorTest { assertTrue(locationAnimatorCoordinator.cameraListeners.isEmpty()) } + + @Test + fun feedNewCompassBearing_withAnimation() { + locationAnimatorCoordinator.setCompassAnimationEnabled(true) + locationAnimatorCoordinator.feedNewCompassBearing(77f, cameraPosition) + + val animators = mutableListOf<Animator>( + locationAnimatorCoordinator.animatorArray[ANIMATOR_LAYER_COMPASS_BEARING], + locationAnimatorCoordinator.animatorArray[ANIMATOR_CAMERA_COMPASS_BEARING]) + + verify(exactly = 1) { animatorSetProvider.startAnimation(eq(animators), ofType(LinearInterpolator::class), eq(LocationComponentConstants.COMPASS_UPDATE_RATE_MS)) } + } + + @Test + fun feedNewCompassBearing_withoutAnimation() { + locationAnimatorCoordinator.setCompassAnimationEnabled(false) + locationAnimatorCoordinator.feedNewCompassBearing(77f, cameraPosition) + + val animators = mutableListOf<Animator>( + locationAnimatorCoordinator.animatorArray[ANIMATOR_LAYER_COMPASS_BEARING], + locationAnimatorCoordinator.animatorArray[ANIMATOR_CAMERA_COMPASS_BEARING]) + + verify(exactly = 1) { animatorSetProvider.startAnimation(eq(animators), ofType(LinearInterpolator::class), eq(0)) } + } + + @Test + fun feedNewAccuracy_withAnimation() { + locationAnimatorCoordinator.setAccuracyAnimationEnabled(true) + locationAnimatorCoordinator.feedNewAccuracyRadius(150f, false) + + val animators = mutableListOf<Animator>( + locationAnimatorCoordinator.animatorArray[ANIMATOR_LAYER_ACCURACY]) + + verify(exactly = 1) { animatorSetProvider.startAnimation(eq(animators), ofType(LinearInterpolator::class), eq(LocationComponentConstants.ACCURACY_RADIUS_ANIMATION_DURATION)) } + } + + @Test + fun feedNewAccuracy_withoutAnimation() { + locationAnimatorCoordinator.setAccuracyAnimationEnabled(false) + locationAnimatorCoordinator.feedNewAccuracyRadius(150f, false) + + val animators = mutableListOf<Animator>( + locationAnimatorCoordinator.animatorArray[ANIMATOR_LAYER_ACCURACY]) + + verify(exactly = 1) { animatorSetProvider.startAnimation(eq(animators), ofType(LinearInterpolator::class), eq(0)) } + } }
\ No newline at end of file diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/values/styles.xml b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/values/styles.xml index a0525171a5..faa994e978 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/values/styles.xml +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/main/res/values/styles.xml @@ -48,6 +48,8 @@ <item name="mapbox_accuracyColor">#FF82C6</item> <item name="mapbox_elevation">0dp</item> + <item name="mapbox_compassAnimationEnabled">false</item> + <item name="mapbox_accuracyAnimationEnabled">false</item> </style> </resources> |