[android] LocationComponent animator throttling tests and examples
This commit is contained in:
committed by
Łukasz Paczos
parent
953e6dca5b
commit
f897f128e6
@@ -5,11 +5,13 @@ import android.location.Location;
|
||||
import android.os.SystemClock;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.annotation.VisibleForTesting;
|
||||
import android.util.SparseArray;
|
||||
import android.view.animation.LinearInterpolator;
|
||||
|
||||
import com.mapbox.mapboxsdk.camera.CameraPosition;
|
||||
import com.mapbox.mapboxsdk.geometry.LatLng;
|
||||
import com.mapbox.mapboxsdk.log.Logger;
|
||||
import com.mapbox.mapboxsdk.maps.MapboxMap;
|
||||
import com.mapbox.mapboxsdk.maps.Projection;
|
||||
|
||||
@@ -34,6 +36,9 @@ import static com.mapbox.mapboxsdk.location.Utils.immediateAnimation;
|
||||
|
||||
final class LocationAnimatorCoordinator {
|
||||
|
||||
private static final String TAG = "Mbgl-LocationAnimatorCoordinator";
|
||||
|
||||
@VisibleForTesting
|
||||
final SparseArray<MapboxAnimator> animatorArray = new SparseArray<>();
|
||||
|
||||
private final Projection projection;
|
||||
@@ -42,29 +47,28 @@ final class LocationAnimatorCoordinator {
|
||||
private float previousCompassBearing = -1;
|
||||
private long locationUpdateTimestamp = -1;
|
||||
private float durationMultiplier;
|
||||
private final MapboxAnimatorProvider animatorProvider;
|
||||
private final MapboxAnimatorSetProvider animatorSetProvider;
|
||||
private boolean compassAnimationEnabled;
|
||||
private boolean accuracyAnimationEnabled;
|
||||
private int maxAnimationFps = Integer.MAX_VALUE;
|
||||
|
||||
private MapboxAnimator.AnimationsValueChangeListener[] listeners;
|
||||
@VisibleForTesting
|
||||
int maxAnimationFps = Integer.MAX_VALUE;
|
||||
|
||||
LocationAnimatorCoordinator(@NonNull Projection projection, @NonNull MapboxAnimatorSetProvider animatorSetProvider) {
|
||||
@VisibleForTesting
|
||||
final SparseArray<MapboxAnimator.AnimationsValueChangeListener> listeners = new SparseArray<>();
|
||||
|
||||
LocationAnimatorCoordinator(@NonNull Projection projection, @NonNull MapboxAnimatorSetProvider animatorSetProvider,
|
||||
@NonNull MapboxAnimatorProvider animatorProvider) {
|
||||
this.projection = projection;
|
||||
this.animatorProvider = animatorProvider;
|
||||
this.animatorSetProvider = animatorSetProvider;
|
||||
}
|
||||
|
||||
void updateAnimatorListenerHolders(@NonNull Set<AnimatorListenerHolder> listenerHolders) {
|
||||
int maxIndex = 0;
|
||||
listeners.clear();
|
||||
for (AnimatorListenerHolder holder : listenerHolders) {
|
||||
if (holder.getAnimatorType() > maxIndex) {
|
||||
maxIndex = holder.getAnimatorType();
|
||||
}
|
||||
}
|
||||
|
||||
listeners = new MapboxAnimator.AnimationsValueChangeListener[maxIndex + 1];
|
||||
for (AnimatorListenerHolder holder : listenerHolders) {
|
||||
listeners[holder.getAnimatorType()] = holder.getListener();
|
||||
listeners.append(holder.getAnimatorType(), holder.getListener());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -229,26 +233,26 @@ final class LocationAnimatorCoordinator {
|
||||
|
||||
private void createNewLatLngAnimator(@MapboxAnimator.Type int animatorType, LatLng previous, LatLng target) {
|
||||
cancelAnimator(animatorType);
|
||||
MapboxAnimator.AnimationsValueChangeListener listener = listeners[animatorType];
|
||||
MapboxAnimator.AnimationsValueChangeListener listener = listeners.get(animatorType);
|
||||
if (listener != null) {
|
||||
animatorArray.put(animatorType, new MapboxLatLngAnimator(previous, target, listener, maxAnimationFps));
|
||||
animatorArray.put(animatorType, animatorProvider.latLngAnimator(previous, target, listener, maxAnimationFps));
|
||||
}
|
||||
}
|
||||
|
||||
private void createNewFloatAnimator(@MapboxAnimator.Type int animatorType, float previous, float target) {
|
||||
cancelAnimator(animatorType);
|
||||
MapboxAnimator.AnimationsValueChangeListener listener = listeners[animatorType];
|
||||
MapboxAnimator.AnimationsValueChangeListener listener = listeners.get(animatorType);
|
||||
if (listener != null) {
|
||||
animatorArray.put(animatorType, new MapboxFloatAnimator(previous, target, listener, maxAnimationFps));
|
||||
animatorArray.put(animatorType, animatorProvider.floatAnimator(previous, target, listener, maxAnimationFps));
|
||||
}
|
||||
}
|
||||
|
||||
private void createNewCameraAdapterAnimator(@MapboxAnimator.Type int animatorType, float previous, float target,
|
||||
@Nullable MapboxMap.CancelableCallback cancelableCallback) {
|
||||
cancelAnimator(animatorType);
|
||||
MapboxAnimator.AnimationsValueChangeListener listener = listeners[animatorType];
|
||||
MapboxAnimator.AnimationsValueChangeListener listener = listeners.get(animatorType);
|
||||
if (listener != null) {
|
||||
animatorArray.put(animatorType, new MapboxCameraAnimatorAdapter(previous, target, listener, cancelableCallback));
|
||||
animatorArray.put(animatorType, animatorProvider.cameraAnimator(previous, target, listener, cancelableCallback));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -379,6 +383,7 @@ final class LocationAnimatorCoordinator {
|
||||
|
||||
void setMaxAnimationFps(int maxAnimationFps) {
|
||||
if (maxAnimationFps <= 0) {
|
||||
Logger.e(TAG, "Max animation FPS cannot be less or equal to 0.");
|
||||
return;
|
||||
}
|
||||
this.maxAnimationFps = maxAnimationFps;
|
||||
|
||||
@@ -1021,7 +1021,8 @@ public final class LocationComponent {
|
||||
|
||||
locationAnimatorCoordinator = new LocationAnimatorCoordinator(
|
||||
mapboxMap.getProjection(),
|
||||
MapboxAnimatorSetProvider.getInstance()
|
||||
MapboxAnimatorSetProvider.getInstance(),
|
||||
MapboxAnimatorProvider.getInstance()
|
||||
);
|
||||
locationAnimatorCoordinator.setTrackingAnimationDurationMultiplier(options
|
||||
.trackingAnimationDurationMultiplier());
|
||||
|
||||
@@ -45,7 +45,7 @@ abstract class MapboxAnimator<K> extends ValueAnimator implements ValueAnimator.
|
||||
private final K target;
|
||||
private K animatedValue;
|
||||
|
||||
private double minUpdateInterval;
|
||||
private final double minUpdateInterval;
|
||||
private long timeElapsed;
|
||||
|
||||
MapboxAnimator(@NonNull K previous, @NonNull K target, @NonNull AnimationsValueChangeListener<K> updateListener,
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
package com.mapbox.mapboxsdk.location;
|
||||
|
||||
import android.support.annotation.Nullable;
|
||||
|
||||
import com.mapbox.mapboxsdk.geometry.LatLng;
|
||||
import com.mapbox.mapboxsdk.maps.MapboxMap;
|
||||
|
||||
final class MapboxAnimatorProvider {
|
||||
|
||||
private static MapboxAnimatorProvider INSTANCE;
|
||||
|
||||
private MapboxAnimatorProvider() {
|
||||
// private constructor
|
||||
}
|
||||
|
||||
public static MapboxAnimatorProvider getInstance() {
|
||||
if (INSTANCE == null) {
|
||||
INSTANCE = new MapboxAnimatorProvider();
|
||||
}
|
||||
return INSTANCE;
|
||||
}
|
||||
|
||||
MapboxLatLngAnimator latLngAnimator(LatLng previous, LatLng target,
|
||||
MapboxAnimator.AnimationsValueChangeListener updateListener,
|
||||
int maxAnimationFps) {
|
||||
return new MapboxLatLngAnimator(previous, target, updateListener, maxAnimationFps);
|
||||
}
|
||||
|
||||
MapboxFloatAnimator floatAnimator(Float previous, Float target,
|
||||
MapboxAnimator.AnimationsValueChangeListener updateListener,
|
||||
int maxAnimationFps) {
|
||||
return new MapboxFloatAnimator(previous, target, updateListener, maxAnimationFps);
|
||||
}
|
||||
|
||||
MapboxCameraAnimatorAdapter cameraAnimator(Float previous, Float target,
|
||||
MapboxAnimator.AnimationsValueChangeListener updateListener,
|
||||
@Nullable MapboxMap.CancelableCallback cancelableCallback) {
|
||||
return new MapboxCameraAnimatorAdapter(previous, target, updateListener, cancelableCallback);
|
||||
}
|
||||
}
|
||||
@@ -2,16 +2,18 @@ package com.mapbox.mapboxsdk.location
|
||||
|
||||
import android.animation.Animator
|
||||
import android.location.Location
|
||||
import android.util.SparseArray
|
||||
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.location.modes.CameraMode
|
||||
import com.mapbox.mapboxsdk.location.modes.RenderMode
|
||||
import com.mapbox.mapboxsdk.maps.MapboxMap
|
||||
import com.mapbox.mapboxsdk.maps.Projection
|
||||
import io.mockk.every
|
||||
import io.mockk.mockk
|
||||
import io.mockk.verify
|
||||
import io.mockk.*
|
||||
import junit.framework.Assert.assertEquals
|
||||
import junit.framework.Assert.assertTrue
|
||||
import org.junit.Before
|
||||
@@ -26,15 +28,63 @@ class LocationAnimatorCoordinatorTest {
|
||||
private lateinit var locationAnimatorCoordinator: LocationAnimatorCoordinator
|
||||
private val cameraPosition: CameraPosition = CameraPosition.DEFAULT
|
||||
|
||||
private val animatorProvider: MapboxAnimatorProvider = mockk()
|
||||
private val animatorSetProvider: MapboxAnimatorSetProvider = mockk()
|
||||
|
||||
private val projection: Projection = mockk()
|
||||
|
||||
@Before
|
||||
fun setUp() {
|
||||
locationAnimatorCoordinator = LocationAnimatorCoordinator(projection, animatorSetProvider)
|
||||
locationAnimatorCoordinator = LocationAnimatorCoordinator(projection, animatorSetProvider, animatorProvider)
|
||||
configureAnimatorProvider()
|
||||
every { projection.getMetersPerPixelAtLatitude(any()) } answers { 1.0 }
|
||||
every { animatorSetProvider.startAnimation(any(), any(), any()) } answers {}
|
||||
locationAnimatorCoordinator.updateAnimatorListenerHolders(getListenerHoldersSet(
|
||||
ANIMATOR_LAYER_LATLNG,
|
||||
ANIMATOR_CAMERA_LATLNG,
|
||||
ANIMATOR_LAYER_GPS_BEARING,
|
||||
ANIMATOR_LAYER_COMPASS_BEARING,
|
||||
ANIMATOR_CAMERA_GPS_BEARING,
|
||||
ANIMATOR_CAMERA_COMPASS_BEARING,
|
||||
ANIMATOR_LAYER_ACCURACY,
|
||||
ANIMATOR_ZOOM,
|
||||
ANIMATOR_TILT
|
||||
))
|
||||
}
|
||||
|
||||
private fun configureAnimatorProvider() {
|
||||
// workaround https://github.com/mockk/mockk/issues/229#issuecomment-457816131
|
||||
registerInstanceFactory { AnimationsValueChangeListener<Float> {} }
|
||||
registerInstanceFactory { AnimationsValueChangeListener<LatLng> {} }
|
||||
val previousFloatSlot = slot<Float>()
|
||||
val targetFloatSlot = slot<Float>()
|
||||
val listenerSlot = slot<MapboxAnimator.AnimationsValueChangeListener<*>>()
|
||||
val maxFpsSlot = slot<Int>()
|
||||
every {
|
||||
animatorProvider.floatAnimator(capture(previousFloatSlot), capture(targetFloatSlot), capture(listenerSlot), capture(maxFpsSlot))
|
||||
} answers {
|
||||
MapboxFloatAnimator(previousFloatSlot.captured, targetFloatSlot.captured, listenerSlot.captured, maxFpsSlot.captured)
|
||||
}
|
||||
|
||||
val previousLatLngSlot = slot<LatLng>()
|
||||
val targetLatLngSlot = slot<LatLng>()
|
||||
every {
|
||||
animatorProvider.latLngAnimator(capture(previousLatLngSlot), capture(targetLatLngSlot), capture(listenerSlot), capture(maxFpsSlot))
|
||||
} answers {
|
||||
MapboxLatLngAnimator(previousLatLngSlot.captured, targetLatLngSlot.captured, listenerSlot.captured, maxFpsSlot.captured)
|
||||
}
|
||||
|
||||
val callback = slot<MapboxMap.CancelableCallback>()
|
||||
every {
|
||||
animatorProvider.cameraAnimator(capture(previousFloatSlot), capture(targetFloatSlot), capture(listenerSlot), capture(callback))
|
||||
} answers {
|
||||
MapboxCameraAnimatorAdapter(previousFloatSlot.captured, targetFloatSlot.captured, listenerSlot.captured, callback.captured)
|
||||
}
|
||||
every {
|
||||
animatorProvider.cameraAnimator(capture(previousFloatSlot), capture(targetFloatSlot), capture(listenerSlot), null)
|
||||
} answers {
|
||||
MapboxCameraAnimatorAdapter(previousFloatSlot.captured, targetFloatSlot.captured, listenerSlot.captured, null)
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -177,11 +227,9 @@ class LocationAnimatorCoordinatorTest {
|
||||
null
|
||||
)
|
||||
|
||||
val animationDuration = locationAnimatorCoordinator.animatorArray[ANIMATOR_ZOOM]?.duration as Long
|
||||
assertEquals(DEFAULT_TRACKING_ZOOM_ANIM_DURATION, animationDuration)
|
||||
|
||||
val target = locationAnimatorCoordinator.animatorArray[ANIMATOR_ZOOM]?.target as Float
|
||||
assertEquals(zoom, target)
|
||||
val animator = locationAnimatorCoordinator.animatorArray[ANIMATOR_ZOOM]
|
||||
assertEquals(zoom, animator.target)
|
||||
verify { animatorSetProvider.startAnimation(eq(listOf(animator)), any<LinearInterpolator>(), DEFAULT_TRACKING_ZOOM_ANIM_DURATION) }
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -206,11 +254,9 @@ class LocationAnimatorCoordinatorTest {
|
||||
null
|
||||
)
|
||||
|
||||
val animationDuration = locationAnimatorCoordinator.animatorArray[ANIMATOR_TILT]?.duration as Long
|
||||
assertEquals(DEFAULT_TRACKING_TILT_ANIM_DURATION, animationDuration)
|
||||
|
||||
val target = locationAnimatorCoordinator.animatorArray[ANIMATOR_TILT]?.target as Float
|
||||
assertEquals(tilt, target)
|
||||
val animator = locationAnimatorCoordinator.animatorArray[ANIMATOR_TILT]
|
||||
assertEquals(tilt, animator.target)
|
||||
verify { animatorSetProvider.startAnimation(eq(listOf(animator)), any<LinearInterpolator>(), DEFAULT_TRACKING_TILT_ANIM_DURATION) }
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -255,37 +301,39 @@ class LocationAnimatorCoordinatorTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
fun addLayerListener() {
|
||||
val layerListener = Mockito.mock(OnLayerAnimationsValuesChangeListener::class.java)
|
||||
locationAnimatorCoordinator.addLayerListener(layerListener)
|
||||
fun addNewListener() {
|
||||
val listener = Mockito.mock(AnimationsValueChangeListener::class.java)
|
||||
val holder = AnimatorListenerHolder(RenderMode.NORMAL, listener)
|
||||
val set = HashSet<AnimatorListenerHolder>().also {
|
||||
it.add(holder)
|
||||
}
|
||||
locationAnimatorCoordinator.updateAnimatorListenerHolders(set)
|
||||
|
||||
assertTrue(locationAnimatorCoordinator.layerListeners.contains(layerListener))
|
||||
assertTrue(locationAnimatorCoordinator.listeners.contains(listener))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun removeLayerListener() {
|
||||
val layerListener = Mockito.mock(OnLayerAnimationsValuesChangeListener::class.java)
|
||||
locationAnimatorCoordinator.addLayerListener(layerListener)
|
||||
locationAnimatorCoordinator.removeLayerListener(layerListener)
|
||||
fun updateListeners() {
|
||||
val listener = Mockito.mock(AnimationsValueChangeListener::class.java)
|
||||
val holder = AnimatorListenerHolder(RenderMode.NORMAL, listener)
|
||||
val set = HashSet<AnimatorListenerHolder>().also {
|
||||
it.add(holder)
|
||||
}
|
||||
locationAnimatorCoordinator.updateAnimatorListenerHolders(set)
|
||||
|
||||
assertTrue(locationAnimatorCoordinator.layerListeners.isEmpty())
|
||||
}
|
||||
val listener2 = Mockito.mock(AnimationsValueChangeListener::class.java)
|
||||
val holder2 = AnimatorListenerHolder(RenderMode.NORMAL, listener2)
|
||||
val listener3 = Mockito.mock(AnimationsValueChangeListener::class.java)
|
||||
val holder3 = AnimatorListenerHolder(CameraMode.TRACKING_GPS, listener3)
|
||||
val set2 = HashSet<AnimatorListenerHolder>().also {
|
||||
it.add(holder2)
|
||||
it.add(holder3)
|
||||
}
|
||||
locationAnimatorCoordinator.updateAnimatorListenerHolders(set2)
|
||||
|
||||
@Test
|
||||
fun addCameraListener() {
|
||||
val cameraListener = Mockito.mock(OnCameraAnimationsValuesChangeListener::class.java)
|
||||
locationAnimatorCoordinator.addCameraListener(cameraListener)
|
||||
|
||||
assertTrue(locationAnimatorCoordinator.cameraListeners.contains(cameraListener))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun removeCameraListener() {
|
||||
val cameraListener = Mockito.mock(OnCameraAnimationsValuesChangeListener::class.java)
|
||||
locationAnimatorCoordinator.addCameraListener(cameraListener)
|
||||
locationAnimatorCoordinator.removeCameraListener(cameraListener)
|
||||
|
||||
assertTrue(locationAnimatorCoordinator.cameraListeners.isEmpty())
|
||||
assertTrue(locationAnimatorCoordinator.listeners.size() == 2)
|
||||
assertTrue(locationAnimatorCoordinator.listeners.contains(listener2))
|
||||
assertTrue(locationAnimatorCoordinator.listeners.contains(listener3))
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -333,4 +381,44 @@ class LocationAnimatorCoordinatorTest {
|
||||
|
||||
verify(exactly = 1) { animatorSetProvider.startAnimation(eq(animators), ofType(LinearInterpolator::class), eq(0)) }
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun maxFps_setter() {
|
||||
locationAnimatorCoordinator.setMaxAnimationFps(5)
|
||||
assertEquals(5, locationAnimatorCoordinator.maxAnimationFps)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun maxFps_moreThanZeroRequired() {
|
||||
locationAnimatorCoordinator.setMaxAnimationFps(0)
|
||||
assertEquals(Int.MAX_VALUE, locationAnimatorCoordinator.maxAnimationFps)
|
||||
locationAnimatorCoordinator.setMaxAnimationFps(-1)
|
||||
assertEquals(Int.MAX_VALUE, locationAnimatorCoordinator.maxAnimationFps)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun maxFps_givenToAnimator() {
|
||||
locationAnimatorCoordinator.setMaxAnimationFps(5)
|
||||
locationAnimatorCoordinator.feedNewLocation(Location(""), cameraPosition, false)
|
||||
verify { animatorProvider.latLngAnimator(any(), any(), any(), 5) }
|
||||
verify { animatorProvider.floatAnimator(any(), any(), any(), 5) }
|
||||
}
|
||||
|
||||
private fun getListenerHoldersSet(vararg animatorTypes: Int): Set<AnimatorListenerHolder> {
|
||||
return HashSet<AnimatorListenerHolder>().also {
|
||||
for (type in animatorTypes) {
|
||||
it.add(AnimatorListenerHolder(type, mockk()))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun <E> SparseArray<E>.contains(listener: AnimationsValueChangeListener<*>?): Boolean {
|
||||
for (i in 0 until this.size()) {
|
||||
val element = this.get(this.keyAt(i))
|
||||
if (element == listener) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
@@ -9,7 +9,6 @@ import com.mapbox.mapboxsdk.camera.CameraPosition;
|
||||
import com.mapbox.mapboxsdk.camera.CameraUpdate;
|
||||
import com.mapbox.mapboxsdk.camera.CameraUpdateFactory;
|
||||
import com.mapbox.mapboxsdk.geometry.LatLng;
|
||||
import com.mapbox.mapboxsdk.location.modes.CameraMode;
|
||||
import com.mapbox.mapboxsdk.maps.MapboxMap;
|
||||
import com.mapbox.mapboxsdk.maps.Projection;
|
||||
import com.mapbox.mapboxsdk.maps.UiSettings;
|
||||
@@ -21,6 +20,21 @@ import org.mockito.ArgumentCaptor;
|
||||
import org.mockito.invocation.InvocationOnMock;
|
||||
import org.mockito.stubbing.Answer;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import static com.mapbox.mapboxsdk.location.MapboxAnimator.ANIMATOR_CAMERA_COMPASS_BEARING;
|
||||
import static com.mapbox.mapboxsdk.location.MapboxAnimator.ANIMATOR_CAMERA_GPS_BEARING;
|
||||
import static com.mapbox.mapboxsdk.location.MapboxAnimator.ANIMATOR_CAMERA_LATLNG;
|
||||
import static com.mapbox.mapboxsdk.location.MapboxAnimator.ANIMATOR_TILT;
|
||||
import static com.mapbox.mapboxsdk.location.MapboxAnimator.ANIMATOR_ZOOM;
|
||||
import static com.mapbox.mapboxsdk.location.modes.CameraMode.NONE;
|
||||
import static com.mapbox.mapboxsdk.location.modes.CameraMode.NONE_COMPASS;
|
||||
import static com.mapbox.mapboxsdk.location.modes.CameraMode.NONE_GPS;
|
||||
import static com.mapbox.mapboxsdk.location.modes.CameraMode.TRACKING;
|
||||
import static com.mapbox.mapboxsdk.location.modes.CameraMode.TRACKING_COMPASS;
|
||||
import static com.mapbox.mapboxsdk.location.modes.CameraMode.TRACKING_GPS;
|
||||
import static com.mapbox.mapboxsdk.location.modes.CameraMode.TRACKING_GPS_NORTH;
|
||||
import static junit.framework.Assert.assertNull;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.Mockito.doAnswer;
|
||||
@@ -38,7 +52,7 @@ public class LocationCameraControllerTest {
|
||||
LocationCameraController camera = buildCamera(mapboxMap);
|
||||
camera.initializeOptions(mock(LocationComponentOptions.class));
|
||||
|
||||
camera.setCameraMode(CameraMode.TRACKING_GPS);
|
||||
camera.setCameraMode(TRACKING_GPS);
|
||||
|
||||
verify(mapboxMap).cancelTransitions();
|
||||
}
|
||||
@@ -53,7 +67,7 @@ public class LocationCameraControllerTest {
|
||||
when(options.trackingGesturesManagement()).thenReturn(true);
|
||||
camera.initializeOptions(options);
|
||||
|
||||
camera.setCameraMode(CameraMode.TRACKING_GPS);
|
||||
camera.setCameraMode(TRACKING_GPS);
|
||||
|
||||
verify(moveGestureDetector).setMoveThreshold(moveThreshold);
|
||||
}
|
||||
@@ -68,7 +82,7 @@ public class LocationCameraControllerTest {
|
||||
when(options.trackingGesturesManagement()).thenReturn(false);
|
||||
camera.initializeOptions(options);
|
||||
|
||||
camera.setCameraMode(CameraMode.TRACKING_GPS);
|
||||
camera.setCameraMode(TRACKING_GPS);
|
||||
|
||||
verify(moveGestureDetector, times(0)).setMoveThreshold(moveThreshold);
|
||||
verify(moveGestureDetector, times(0)).setMoveThreshold(0f);
|
||||
@@ -82,7 +96,7 @@ public class LocationCameraControllerTest {
|
||||
when(options.trackingGesturesManagement()).thenReturn(true);
|
||||
camera.initializeOptions(options);
|
||||
|
||||
camera.setCameraMode(CameraMode.NONE);
|
||||
camera.setCameraMode(NONE);
|
||||
|
||||
verify(moveGestureDetector, times(2)).setMoveThreshold(0f); // one for initialization
|
||||
}
|
||||
@@ -94,8 +108,8 @@ public class LocationCameraControllerTest {
|
||||
LocationCameraController camera = buildCamera(mapboxMap);
|
||||
camera.initializeOptions(mock(LocationComponentOptions.class));
|
||||
|
||||
camera.setCameraMode(CameraMode.TRACKING_GPS);
|
||||
camera.setCameraMode(CameraMode.NONE);
|
||||
camera.setCameraMode(TRACKING_GPS);
|
||||
camera.setCameraMode(NONE);
|
||||
|
||||
verify(mapboxMap.getUiSettings()).setFocalPoint(null);
|
||||
}
|
||||
@@ -106,8 +120,8 @@ public class LocationCameraControllerTest {
|
||||
LocationCameraController camera = buildCamera(internalTrackingChangedListener);
|
||||
camera.initializeOptions(mock(LocationComponentOptions.class));
|
||||
|
||||
camera.setCameraMode(CameraMode.TRACKING_GPS);
|
||||
camera.setCameraMode(CameraMode.NONE);
|
||||
camera.setCameraMode(TRACKING_GPS);
|
||||
camera.setCameraMode(NONE);
|
||||
|
||||
verify(internalTrackingChangedListener).onCameraTrackingDismissed();
|
||||
}
|
||||
@@ -117,7 +131,7 @@ public class LocationCameraControllerTest {
|
||||
OnCameraTrackingChangedListener internalTrackingChangedListener = mock(OnCameraTrackingChangedListener.class);
|
||||
LocationCameraController camera = buildCamera(internalTrackingChangedListener);
|
||||
camera.initializeOptions(mock(LocationComponentOptions.class));
|
||||
int cameraMode = CameraMode.NONE;
|
||||
int cameraMode = NONE;
|
||||
|
||||
camera.setCameraMode(cameraMode);
|
||||
|
||||
@@ -132,22 +146,22 @@ public class LocationCameraControllerTest {
|
||||
LocationCameraController camera = buildCamera(mapboxMap);
|
||||
camera.initializeOptions(mock(LocationComponentOptions.class));
|
||||
|
||||
camera.setCameraMode(CameraMode.NONE_COMPASS);
|
||||
camera.setCameraMode(NONE_COMPASS);
|
||||
verify(mapboxMap, times(1)).cancelTransitions();
|
||||
|
||||
camera.setCameraMode(CameraMode.NONE_GPS);
|
||||
camera.setCameraMode(NONE_GPS);
|
||||
verify(mapboxMap, times(2)).cancelTransitions();
|
||||
|
||||
camera.setCameraMode(CameraMode.TRACKING);
|
||||
camera.setCameraMode(TRACKING);
|
||||
verify(mapboxMap, times(3)).cancelTransitions();
|
||||
|
||||
camera.setCameraMode(CameraMode.TRACKING_COMPASS);
|
||||
camera.setCameraMode(TRACKING_COMPASS);
|
||||
verify(mapboxMap, times(4)).cancelTransitions();
|
||||
|
||||
camera.setCameraMode(CameraMode.TRACKING_GPS);
|
||||
camera.setCameraMode(TRACKING_GPS);
|
||||
verify(mapboxMap, times(5)).cancelTransitions();
|
||||
|
||||
camera.setCameraMode(CameraMode.TRACKING_GPS_NORTH);
|
||||
camera.setCameraMode(TRACKING_GPS_NORTH);
|
||||
verify(mapboxMap, times(6)).cancelTransitions();
|
||||
}
|
||||
|
||||
@@ -159,7 +173,7 @@ public class LocationCameraControllerTest {
|
||||
LocationCameraController camera = buildCamera(mapboxMap);
|
||||
camera.initializeOptions(mock(LocationComponentOptions.class));
|
||||
|
||||
camera.setCameraMode(CameraMode.NONE);
|
||||
camera.setCameraMode(NONE);
|
||||
verify(mapboxMap, never()).cancelTransitions();
|
||||
}
|
||||
|
||||
@@ -170,10 +184,10 @@ public class LocationCameraControllerTest {
|
||||
when(mapboxMap.getProjection()).thenReturn(mock(Projection.class));
|
||||
LocationCameraController camera = buildCamera(mapboxMap);
|
||||
camera.initializeOptions(mock(LocationComponentOptions.class));
|
||||
camera.setCameraMode(CameraMode.TRACKING);
|
||||
camera.setCameraMode(TRACKING);
|
||||
LatLng latLng = mock(LatLng.class);
|
||||
|
||||
camera.onNewLatLngValue(latLng);
|
||||
getAnimationListener(ANIMATOR_CAMERA_LATLNG, camera.getAnimationListeners()).onNewAnimationValue(latLng);
|
||||
|
||||
verify(mapboxMap).moveCamera(any(CameraUpdate.class));
|
||||
}
|
||||
@@ -185,10 +199,10 @@ public class LocationCameraControllerTest {
|
||||
when(mapboxMap.getProjection()).thenReturn(mock(Projection.class));
|
||||
LocationCameraController camera = buildCamera(mapboxMap);
|
||||
camera.initializeOptions(mock(LocationComponentOptions.class));
|
||||
camera.setCameraMode(CameraMode.TRACKING_GPS_NORTH);
|
||||
camera.setCameraMode(TRACKING_GPS_NORTH);
|
||||
LatLng latLng = mock(LatLng.class);
|
||||
|
||||
camera.onNewLatLngValue(latLng);
|
||||
getAnimationListener(ANIMATOR_CAMERA_LATLNG, camera.getAnimationListeners()).onNewAnimationValue(latLng);
|
||||
|
||||
verify(mapboxMap).moveCamera(any(CameraUpdate.class));
|
||||
}
|
||||
@@ -200,10 +214,10 @@ public class LocationCameraControllerTest {
|
||||
when(mapboxMap.getProjection()).thenReturn(mock(Projection.class));
|
||||
LocationCameraController camera = buildCamera(mapboxMap);
|
||||
camera.initializeOptions(mock(LocationComponentOptions.class));
|
||||
camera.setCameraMode(CameraMode.TRACKING_GPS);
|
||||
camera.setCameraMode(TRACKING_GPS);
|
||||
LatLng latLng = mock(LatLng.class);
|
||||
|
||||
camera.onNewLatLngValue(latLng);
|
||||
getAnimationListener(ANIMATOR_CAMERA_LATLNG, camera.getAnimationListeners()).onNewAnimationValue(latLng);
|
||||
|
||||
verify(mapboxMap).moveCamera(any(CameraUpdate.class));
|
||||
}
|
||||
@@ -215,10 +229,10 @@ public class LocationCameraControllerTest {
|
||||
when(mapboxMap.getProjection()).thenReturn(mock(Projection.class));
|
||||
LocationCameraController camera = buildCamera(mapboxMap);
|
||||
camera.initializeOptions(mock(LocationComponentOptions.class));
|
||||
camera.setCameraMode(CameraMode.TRACKING_COMPASS);
|
||||
camera.setCameraMode(TRACKING_COMPASS);
|
||||
LatLng latLng = mock(LatLng.class);
|
||||
|
||||
camera.onNewLatLngValue(latLng);
|
||||
getAnimationListener(ANIMATOR_CAMERA_LATLNG, camera.getAnimationListeners()).onNewAnimationValue(latLng);
|
||||
|
||||
verify(mapboxMap).moveCamera(any(CameraUpdate.class));
|
||||
}
|
||||
@@ -230,11 +244,9 @@ public class LocationCameraControllerTest {
|
||||
when(mapboxMap.getProjection()).thenReturn(mock(Projection.class));
|
||||
LocationCameraController camera = buildCamera(mapboxMap);
|
||||
camera.initializeOptions(mock(LocationComponentOptions.class));
|
||||
camera.setCameraMode(CameraMode.NONE);
|
||||
LatLng latLng = mock(LatLng.class);
|
||||
|
||||
camera.onNewLatLngValue(latLng);
|
||||
camera.setCameraMode(NONE);
|
||||
|
||||
assertNull(getAnimationListener(ANIMATOR_CAMERA_LATLNG, camera.getAnimationListeners()));
|
||||
verify(mapboxMap, times(0)).moveCamera(any(CameraUpdate.class));
|
||||
}
|
||||
|
||||
@@ -251,10 +263,10 @@ public class LocationCameraControllerTest {
|
||||
LocationComponentOptions options = mock(LocationComponentOptions.class);
|
||||
when(options.trackingGesturesManagement()).thenReturn(true);
|
||||
camera.initializeOptions(options);
|
||||
camera.setCameraMode(CameraMode.TRACKING);
|
||||
camera.setCameraMode(TRACKING);
|
||||
LatLng latLng = mock(LatLng.class);
|
||||
|
||||
camera.onNewLatLngValue(latLng);
|
||||
getAnimationListener(ANIMATOR_CAMERA_LATLNG, camera.getAnimationListeners()).onNewAnimationValue(latLng);
|
||||
|
||||
verify(uiSettings).setFocalPoint(pointF);
|
||||
}
|
||||
@@ -264,10 +276,10 @@ public class LocationCameraControllerTest {
|
||||
MapboxMap mapboxMap = mock(MapboxMap.class);
|
||||
LocationCameraController camera = buildCamera(mapboxMap);
|
||||
camera.initializeOptions(mock(LocationComponentOptions.class));
|
||||
camera.setCameraMode(CameraMode.TRACKING_GPS);
|
||||
camera.setCameraMode(TRACKING_GPS);
|
||||
float gpsBearing = 5f;
|
||||
|
||||
camera.onNewGpsBearingValue(gpsBearing);
|
||||
getAnimationListener(ANIMATOR_CAMERA_GPS_BEARING, camera.getAnimationListeners()).onNewAnimationValue(gpsBearing);
|
||||
|
||||
verify(mapboxMap).moveCamera(any(CameraUpdate.class));
|
||||
}
|
||||
@@ -277,10 +289,10 @@ public class LocationCameraControllerTest {
|
||||
MapboxMap mapboxMap = mock(MapboxMap.class);
|
||||
LocationCameraController camera = buildCamera(mapboxMap);
|
||||
camera.initializeOptions(mock(LocationComponentOptions.class));
|
||||
camera.setCameraMode(CameraMode.NONE_GPS);
|
||||
camera.setCameraMode(NONE_GPS);
|
||||
float gpsBearing = 5f;
|
||||
|
||||
camera.onNewGpsBearingValue(gpsBearing);
|
||||
getAnimationListener(ANIMATOR_CAMERA_GPS_BEARING, camera.getAnimationListeners()).onNewAnimationValue(gpsBearing);
|
||||
|
||||
verify(mapboxMap).moveCamera(any(CameraUpdate.class));
|
||||
}
|
||||
@@ -292,10 +304,10 @@ public class LocationCameraControllerTest {
|
||||
when(mapboxMap.getCameraPosition()).thenReturn(cameraPosition);
|
||||
LocationCameraController camera = buildCamera(mapboxMap);
|
||||
camera.initializeOptions(mock(LocationComponentOptions.class));
|
||||
camera.setCameraMode(CameraMode.TRACKING_GPS_NORTH);
|
||||
camera.setCameraMode(TRACKING_GPS_NORTH);
|
||||
float gpsBearing = 5f;
|
||||
|
||||
camera.onNewGpsBearingValue(gpsBearing);
|
||||
getAnimationListener(ANIMATOR_CAMERA_GPS_BEARING, camera.getAnimationListeners()).onNewAnimationValue(gpsBearing);
|
||||
|
||||
verify(mapboxMap).moveCamera(any(CameraUpdate.class));
|
||||
}
|
||||
@@ -307,10 +319,10 @@ public class LocationCameraControllerTest {
|
||||
when(mapboxMap.getCameraPosition()).thenReturn(cameraPosition);
|
||||
LocationCameraController camera = buildCamera(mapboxMap);
|
||||
camera.initializeOptions(mock(LocationComponentOptions.class));
|
||||
camera.setCameraMode(CameraMode.TRACKING_GPS_NORTH);
|
||||
camera.setCameraMode(TRACKING_GPS_NORTH);
|
||||
float gpsBearing = 5f;
|
||||
|
||||
camera.onNewGpsBearingValue(gpsBearing);
|
||||
getAnimationListener(ANIMATOR_CAMERA_GPS_BEARING, camera.getAnimationListeners()).onNewAnimationValue(gpsBearing);
|
||||
|
||||
verify(mapboxMap, times(0)).moveCamera(any(CameraUpdate.class));
|
||||
}
|
||||
@@ -320,11 +332,9 @@ public class LocationCameraControllerTest {
|
||||
MapboxMap mapboxMap = mock(MapboxMap.class);
|
||||
LocationCameraController camera = buildCamera(mapboxMap);
|
||||
camera.initializeOptions(mock(LocationComponentOptions.class));
|
||||
camera.setCameraMode(CameraMode.NONE);
|
||||
float gpsBearing = 5f;
|
||||
|
||||
camera.onNewGpsBearingValue(gpsBearing);
|
||||
camera.setCameraMode(NONE);
|
||||
|
||||
assertNull(getAnimationListener(ANIMATOR_CAMERA_GPS_BEARING, camera.getAnimationListeners()));
|
||||
verify(mapboxMap, times(0)).moveCamera(any(CameraUpdate.class));
|
||||
}
|
||||
|
||||
@@ -333,10 +343,10 @@ public class LocationCameraControllerTest {
|
||||
MapboxMap mapboxMap = mock(MapboxMap.class);
|
||||
LocationCameraController camera = buildCamera(mapboxMap);
|
||||
camera.initializeOptions(mock(LocationComponentOptions.class));
|
||||
camera.setCameraMode(CameraMode.TRACKING_COMPASS);
|
||||
camera.setCameraMode(TRACKING_COMPASS);
|
||||
float compassBearing = 5f;
|
||||
|
||||
camera.onNewCompassBearingValue(compassBearing);
|
||||
getAnimationListener(ANIMATOR_CAMERA_COMPASS_BEARING, camera.getAnimationListeners()).onNewAnimationValue(compassBearing);
|
||||
|
||||
verify(mapboxMap).moveCamera(any(CameraUpdate.class));
|
||||
}
|
||||
@@ -346,10 +356,10 @@ public class LocationCameraControllerTest {
|
||||
MapboxMap mapboxMap = mock(MapboxMap.class);
|
||||
LocationCameraController camera = buildCamera(mapboxMap);
|
||||
camera.initializeOptions(mock(LocationComponentOptions.class));
|
||||
camera.setCameraMode(CameraMode.NONE_COMPASS);
|
||||
camera.setCameraMode(NONE_COMPASS);
|
||||
float compassBearing = 5f;
|
||||
|
||||
camera.onNewCompassBearingValue(compassBearing);
|
||||
getAnimationListener(ANIMATOR_CAMERA_COMPASS_BEARING, camera.getAnimationListeners()).onNewAnimationValue(compassBearing);
|
||||
|
||||
verify(mapboxMap).moveCamera(any(CameraUpdate.class));
|
||||
}
|
||||
@@ -359,11 +369,9 @@ public class LocationCameraControllerTest {
|
||||
MapboxMap mapboxMap = mock(MapboxMap.class);
|
||||
LocationCameraController camera = buildCamera(mapboxMap);
|
||||
camera.initializeOptions(mock(LocationComponentOptions.class));
|
||||
camera.setCameraMode(CameraMode.NONE);
|
||||
float compassBearing = 5f;
|
||||
|
||||
camera.onNewCompassBearingValue(compassBearing);
|
||||
camera.setCameraMode(NONE);
|
||||
|
||||
assertNull(getAnimationListener(ANIMATOR_CAMERA_COMPASS_BEARING, camera.getAnimationListeners()));
|
||||
verify(mapboxMap, times(0)).moveCamera(any(CameraUpdate.class));
|
||||
}
|
||||
|
||||
@@ -372,10 +380,23 @@ public class LocationCameraControllerTest {
|
||||
MapboxMap mapboxMap = mock(MapboxMap.class);
|
||||
LocationCameraController camera = buildCamera(mapboxMap);
|
||||
camera.initializeOptions(mock(LocationComponentOptions.class));
|
||||
camera.setCameraMode(CameraMode.TRACKING);
|
||||
camera.setCameraMode(TRACKING);
|
||||
float zoom = 5f;
|
||||
|
||||
camera.onNewZoomValue(zoom);
|
||||
getAnimationListener(ANIMATOR_ZOOM, camera.getAnimationListeners()).onNewAnimationValue(zoom);
|
||||
|
||||
verify(mapboxMap).moveCamera(any(CameraUpdate.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onNeTiltValue_cameraIsUpdated() {
|
||||
MapboxMap mapboxMap = mock(MapboxMap.class);
|
||||
LocationCameraController camera = buildCamera(mapboxMap);
|
||||
camera.initializeOptions(mock(LocationComponentOptions.class));
|
||||
camera.setCameraMode(TRACKING);
|
||||
float tilt = 5f;
|
||||
|
||||
getAnimationListener(ANIMATOR_TILT, camera.getAnimationListeners()).onNewAnimationValue(tilt);
|
||||
|
||||
verify(mapboxMap).moveCamera(any(CameraUpdate.class));
|
||||
}
|
||||
@@ -414,7 +435,7 @@ public class LocationCameraControllerTest {
|
||||
LocationCameraController camera = buildCamera(mapboxMap);
|
||||
camera.initializeOptions(mock(LocationComponentOptions.class));
|
||||
|
||||
camera.setCameraMode(CameraMode.NONE);
|
||||
camera.setCameraMode(NONE);
|
||||
camera.onMoveListener.onMove(moveGestureDetector);
|
||||
verify(mapboxMap, times(0)).cancelTransitions();
|
||||
verify(moveGestureDetector, times(0)).interrupt();
|
||||
@@ -433,7 +454,7 @@ public class LocationCameraControllerTest {
|
||||
LocationCameraController camera = buildCamera(mapboxMap);
|
||||
camera.initializeOptions(mock(LocationComponentOptions.class));
|
||||
|
||||
camera.setCameraMode(CameraMode.TRACKING);
|
||||
camera.setCameraMode(TRACKING);
|
||||
camera.onMoveListener.onMove(moveGestureDetector);
|
||||
verify(mapboxMap, times(1)).cancelTransitions();
|
||||
verify(moveGestureDetector, times(1)).interrupt();
|
||||
@@ -451,7 +472,7 @@ public class LocationCameraControllerTest {
|
||||
LocationCameraController camera = buildCamera(mapboxMap);
|
||||
camera.initializeOptions(mock(LocationComponentOptions.class));
|
||||
|
||||
camera.setCameraMode(CameraMode.NONE_COMPASS);
|
||||
camera.setCameraMode(NONE_COMPASS);
|
||||
camera.onMoveListener.onMove(moveGestureDetector);
|
||||
verify(mapboxMap, times(1)).cancelTransitions();
|
||||
verify(moveGestureDetector, times(1)).interrupt();
|
||||
@@ -469,9 +490,9 @@ public class LocationCameraControllerTest {
|
||||
camera.initializeOptions(mock(LocationComponentOptions.class));
|
||||
OnLocationCameraTransitionListener listener = mock(OnLocationCameraTransitionListener.class);
|
||||
|
||||
camera.setCameraMode(CameraMode.TRACKING, null, listener);
|
||||
Assert.assertEquals(CameraMode.TRACKING, camera.getCameraMode());
|
||||
verify(listener).onLocationCameraTransitionFinished(CameraMode.TRACKING);
|
||||
camera.setCameraMode(TRACKING, null, listener);
|
||||
Assert.assertEquals(TRACKING, camera.getCameraMode());
|
||||
verify(listener).onLocationCameraTransitionFinished(TRACKING);
|
||||
verify(mapboxMap, times(0))
|
||||
.animateCamera(any(CameraUpdate.class), any(Integer.class), any(MapboxMap.CancelableCallback.class));
|
||||
}
|
||||
@@ -484,8 +505,8 @@ public class LocationCameraControllerTest {
|
||||
OnLocationCameraTransitionListener listener = mock(OnLocationCameraTransitionListener.class);
|
||||
Location location = mock(Location.class);
|
||||
|
||||
camera.setCameraMode(CameraMode.NONE, location, listener);
|
||||
verify(listener, times(1)).onLocationCameraTransitionFinished(CameraMode.NONE);
|
||||
camera.setCameraMode(NONE, location, listener);
|
||||
verify(listener, times(1)).onLocationCameraTransitionFinished(NONE);
|
||||
verify(mapboxMap, times(0))
|
||||
.animateCamera(any(CameraUpdate.class), any(Integer.class), any(MapboxMap.CancelableCallback.class));
|
||||
}
|
||||
@@ -505,14 +526,14 @@ public class LocationCameraControllerTest {
|
||||
doAnswer(new Answer<Void>() {
|
||||
@Override
|
||||
public Void answer(InvocationOnMock invocation) throws Throwable {
|
||||
listener.onLocationCameraTransitionFinished(CameraMode.TRACKING);
|
||||
listener.onLocationCameraTransitionFinished(TRACKING);
|
||||
return null;
|
||||
}
|
||||
}).when(mapboxMap).animateCamera(any(CameraUpdate.class), any(Integer.class), any(MapboxMap.CancelableCallback
|
||||
.class));
|
||||
|
||||
camera.setCameraMode(CameraMode.TRACKING, location, listener);
|
||||
verify(listener).onLocationCameraTransitionFinished(CameraMode.TRACKING);
|
||||
camera.setCameraMode(TRACKING, location, listener);
|
||||
verify(listener).onLocationCameraTransitionFinished(TRACKING);
|
||||
verify(mapboxMap)
|
||||
.animateCamera(any(CameraUpdate.class), any(Integer.class), any(MapboxMap.CancelableCallback.class));
|
||||
}
|
||||
@@ -529,19 +550,19 @@ public class LocationCameraControllerTest {
|
||||
final OnLocationCameraTransitionListener listener = mock(OnLocationCameraTransitionListener.class);
|
||||
Location location = mock(Location.class);
|
||||
|
||||
camera.setCameraMode(CameraMode.TRACKING, location, listener);
|
||||
camera.setCameraMode(TRACKING, location, listener);
|
||||
|
||||
doAnswer(new Answer<Void>() {
|
||||
@Override
|
||||
public Void answer(InvocationOnMock invocation) throws Throwable {
|
||||
listener.onLocationCameraTransitionFinished(CameraMode.TRACKING_GPS_NORTH);
|
||||
listener.onLocationCameraTransitionFinished(TRACKING_GPS_NORTH);
|
||||
return null;
|
||||
}
|
||||
}).when(mapboxMap).animateCamera(any(CameraUpdate.class), any(Integer.class), any(MapboxMap.CancelableCallback
|
||||
.class));
|
||||
|
||||
camera.setCameraMode(CameraMode.TRACKING_GPS_NORTH, location, listener);
|
||||
verify(listener, times(1)).onLocationCameraTransitionFinished(CameraMode.TRACKING_GPS_NORTH);
|
||||
camera.setCameraMode(TRACKING_GPS_NORTH, location, listener);
|
||||
verify(listener, times(1)).onLocationCameraTransitionFinished(TRACKING_GPS_NORTH);
|
||||
verify(mapboxMap, times(1))
|
||||
.animateCamera(any(CameraUpdate.class), any(Integer.class), any(MapboxMap.CancelableCallback.class));
|
||||
}
|
||||
@@ -561,14 +582,14 @@ public class LocationCameraControllerTest {
|
||||
doAnswer(new Answer<Void>() {
|
||||
@Override
|
||||
public Void answer(InvocationOnMock invocation) throws Throwable {
|
||||
listener.onLocationCameraTransitionCanceled(CameraMode.TRACKING);
|
||||
listener.onLocationCameraTransitionCanceled(TRACKING);
|
||||
return null;
|
||||
}
|
||||
}).when(mapboxMap).animateCamera(any(CameraUpdate.class), any(Integer.class), any(MapboxMap.CancelableCallback
|
||||
.class));
|
||||
|
||||
camera.setCameraMode(CameraMode.TRACKING, location, listener);
|
||||
verify(listener).onLocationCameraTransitionCanceled(CameraMode.TRACKING);
|
||||
camera.setCameraMode(TRACKING, location, listener);
|
||||
verify(listener).onLocationCameraTransitionCanceled(TRACKING);
|
||||
verify(mapboxMap)
|
||||
.animateCamera(any(CameraUpdate.class), any(Integer.class), any(MapboxMap.CancelableCallback.class));
|
||||
}
|
||||
@@ -592,7 +613,7 @@ public class LocationCameraControllerTest {
|
||||
ArgumentCaptor<MapboxMap.CancelableCallback> callbackCaptor
|
||||
= ArgumentCaptor.forClass(MapboxMap.CancelableCallback.class);
|
||||
|
||||
camera.setCameraMode(CameraMode.TRACKING, location, listener);
|
||||
camera.setCameraMode(TRACKING, location, listener);
|
||||
|
||||
CameraPosition.Builder builder = new CameraPosition.Builder().target(new LatLng(location));
|
||||
verify(mapboxMap).animateCamera(
|
||||
@@ -606,7 +627,7 @@ public class LocationCameraControllerTest {
|
||||
|
||||
Assert.assertFalse(camera.isTransitioning());
|
||||
|
||||
verify(listener).onLocationCameraTransitionFinished(CameraMode.TRACKING);
|
||||
verify(listener).onLocationCameraTransitionFinished(TRACKING);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -628,7 +649,7 @@ public class LocationCameraControllerTest {
|
||||
ArgumentCaptor<MapboxMap.CancelableCallback> callbackCaptor
|
||||
= ArgumentCaptor.forClass(MapboxMap.CancelableCallback.class);
|
||||
|
||||
camera.setCameraMode(CameraMode.TRACKING, location, listener);
|
||||
camera.setCameraMode(TRACKING, location, listener);
|
||||
|
||||
CameraPosition.Builder builder = new CameraPosition.Builder().target(new LatLng(location));
|
||||
verify(mapboxMap).moveCamera(
|
||||
@@ -641,7 +662,7 @@ public class LocationCameraControllerTest {
|
||||
|
||||
Assert.assertFalse(camera.isTransitioning());
|
||||
|
||||
verify(listener).onLocationCameraTransitionFinished(CameraMode.TRACKING);
|
||||
verify(listener).onLocationCameraTransitionFinished(TRACKING);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -663,7 +684,7 @@ public class LocationCameraControllerTest {
|
||||
ArgumentCaptor<MapboxMap.CancelableCallback> callbackCaptor
|
||||
= ArgumentCaptor.forClass(MapboxMap.CancelableCallback.class);
|
||||
|
||||
camera.setCameraMode(CameraMode.TRACKING, location, listener);
|
||||
camera.setCameraMode(TRACKING, location, listener);
|
||||
|
||||
CameraPosition.Builder builder = new CameraPosition.Builder().target(new LatLng(location));
|
||||
verify(mapboxMap).animateCamera(
|
||||
@@ -677,7 +698,7 @@ public class LocationCameraControllerTest {
|
||||
|
||||
Assert.assertFalse(camera.isTransitioning());
|
||||
|
||||
verify(listener).onLocationCameraTransitionCanceled(CameraMode.TRACKING);
|
||||
verify(listener).onLocationCameraTransitionCanceled(TRACKING);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -696,7 +717,7 @@ public class LocationCameraControllerTest {
|
||||
when(location.getBearing()).thenReturn(30f);
|
||||
when(location.getAltitude()).thenReturn(0.0);
|
||||
|
||||
camera.setCameraMode(CameraMode.TRACKING_GPS, location, listener);
|
||||
camera.setCameraMode(TRACKING_GPS, location, listener);
|
||||
|
||||
CameraPosition.Builder builder = new CameraPosition.Builder().target(new LatLng(location)).bearing(30);
|
||||
verify(mapboxMap).animateCamera(
|
||||
@@ -721,7 +742,7 @@ public class LocationCameraControllerTest {
|
||||
when(location.getBearing()).thenReturn(30f);
|
||||
when(location.getAltitude()).thenReturn(0.0);
|
||||
|
||||
camera.setCameraMode(CameraMode.TRACKING_GPS_NORTH, location, listener);
|
||||
camera.setCameraMode(TRACKING_GPS_NORTH, location, listener);
|
||||
|
||||
CameraPosition.Builder builder = new CameraPosition.Builder().target(new LatLng(location)).bearing(0);
|
||||
verify(mapboxMap).animateCamera(
|
||||
@@ -745,27 +766,27 @@ public class LocationCameraControllerTest {
|
||||
ArgumentCaptor<MapboxMap.CancelableCallback> callbackCaptor
|
||||
= ArgumentCaptor.forClass(MapboxMap.CancelableCallback.class);
|
||||
|
||||
camera.setCameraMode(CameraMode.TRACKING_GPS, location, listener);
|
||||
camera.setCameraMode(TRACKING_GPS, location, listener);
|
||||
|
||||
verify(mapboxMap).animateCamera(
|
||||
any(CameraUpdate.class),
|
||||
eq((int) LocationComponentConstants.TRANSITION_ANIMATION_DURATION_MS),
|
||||
callbackCaptor.capture());
|
||||
|
||||
camera.onNewLatLngValue(new LatLng(10, 10));
|
||||
camera.onNewGpsBearingValue(10f);
|
||||
camera.onNewCompassBearingValue(10f);
|
||||
camera.onNewTiltValue(10f);
|
||||
camera.onNewZoomValue(10f);
|
||||
LatLng latLng = new LatLng(10, 10);
|
||||
getAnimationListener(ANIMATOR_CAMERA_LATLNG, camera.getAnimationListeners()).onNewAnimationValue(latLng);
|
||||
getAnimationListener(ANIMATOR_CAMERA_GPS_BEARING, camera.getAnimationListeners()).onNewAnimationValue(10f);
|
||||
getAnimationListener(ANIMATOR_TILT, camera.getAnimationListeners()).onNewAnimationValue(10f);
|
||||
getAnimationListener(ANIMATOR_ZOOM, camera.getAnimationListeners()).onNewAnimationValue(10f);
|
||||
|
||||
verify(mapboxMap, times(0)).moveCamera(any(CameraUpdate.class));
|
||||
|
||||
callbackCaptor.getValue().onFinish();
|
||||
|
||||
camera.onNewLatLngValue(new LatLng(10, 10));
|
||||
camera.onNewGpsBearingValue(10f);
|
||||
camera.onNewTiltValue(10f);
|
||||
camera.onNewZoomValue(10f);
|
||||
getAnimationListener(ANIMATOR_CAMERA_LATLNG, camera.getAnimationListeners()).onNewAnimationValue(latLng);
|
||||
getAnimationListener(ANIMATOR_CAMERA_GPS_BEARING, camera.getAnimationListeners()).onNewAnimationValue(10f);
|
||||
getAnimationListener(ANIMATOR_TILT, camera.getAnimationListeners()).onNewAnimationValue(10f);
|
||||
getAnimationListener(ANIMATOR_ZOOM, camera.getAnimationListeners()).onNewAnimationValue(10f);
|
||||
|
||||
verify(mapboxMap, times(4)).moveCamera(any(CameraUpdate.class));
|
||||
}
|
||||
@@ -816,4 +837,17 @@ public class LocationCameraControllerTest {
|
||||
return new LocationCameraController(mapboxMap, moveGestureDetector,
|
||||
onCameraTrackingChangedListener, onCameraMoveInvalidateListener, initialGesturesManager, internalGesturesManager);
|
||||
}
|
||||
|
||||
private <T> MapboxAnimator.AnimationsValueChangeListener<T> getAnimationListener(
|
||||
@MapboxAnimator.Type int animatorType,
|
||||
Set<AnimatorListenerHolder> holders) {
|
||||
for (AnimatorListenerHolder holder : holders) {
|
||||
@MapboxAnimator.Type int type = holder.getAnimatorType();
|
||||
if (type == animatorType) {
|
||||
return holder.getListener();
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,6 +16,8 @@ import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.mockito.Mockito;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import static com.mapbox.mapboxsdk.location.LocationComponentConstants.ACCURACY_LAYER;
|
||||
import static com.mapbox.mapboxsdk.location.LocationComponentConstants.BACKGROUND_ICON;
|
||||
import static com.mapbox.mapboxsdk.location.LocationComponentConstants.BACKGROUND_LAYER;
|
||||
@@ -33,6 +35,11 @@ import static com.mapbox.mapboxsdk.location.LocationComponentConstants.PROPERTY_
|
||||
import static com.mapbox.mapboxsdk.location.LocationComponentConstants.PROPERTY_SHADOW_ICON_OFFSET;
|
||||
import static com.mapbox.mapboxsdk.location.LocationComponentConstants.SHADOW_ICON;
|
||||
import static com.mapbox.mapboxsdk.location.LocationComponentConstants.SHADOW_LAYER;
|
||||
import static com.mapbox.mapboxsdk.location.MapboxAnimator.ANIMATOR_LAYER_ACCURACY;
|
||||
import static com.mapbox.mapboxsdk.location.MapboxAnimator.ANIMATOR_LAYER_COMPASS_BEARING;
|
||||
import static com.mapbox.mapboxsdk.location.MapboxAnimator.ANIMATOR_LAYER_GPS_BEARING;
|
||||
import static com.mapbox.mapboxsdk.location.MapboxAnimator.ANIMATOR_LAYER_LATLNG;
|
||||
import static junit.framework.Assert.assertNull;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.Mockito.mock;
|
||||
@@ -52,6 +59,7 @@ public class LocationLayerControllerTest {
|
||||
|
||||
@Test
|
||||
public void onInitialization_locationSourceIsAdded() {
|
||||
OnRenderModeChangedListener internalRenderModeChangedListener = mock(OnRenderModeChangedListener.class);
|
||||
LayerSourceProvider sourceProvider = buildLayerProvider();
|
||||
GeoJsonSource locationSource = mock(GeoJsonSource.class);
|
||||
when(sourceProvider.generateSource(any(Feature.class))).thenReturn(locationSource);
|
||||
@@ -59,13 +67,14 @@ public class LocationLayerControllerTest {
|
||||
LocationComponentOptions options = mock(LocationComponentOptions.class);
|
||||
|
||||
new LocationLayerController(mapboxMap, mapboxMap.getStyle(), sourceProvider, buildFeatureProvider(options),
|
||||
bitmapProvider, options);
|
||||
bitmapProvider, options, internalRenderModeChangedListener);
|
||||
|
||||
verify(style).addSource(locationSource);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onInitialization_shadowLayerIsAdded() {
|
||||
OnRenderModeChangedListener internalRenderModeChangedListener = mock(OnRenderModeChangedListener.class);
|
||||
LayerSourceProvider sourceProvider = buildLayerProvider();
|
||||
Layer shadowLayer = mock(Layer.class);
|
||||
when(sourceProvider.generateLayer(SHADOW_LAYER)).thenReturn(shadowLayer);
|
||||
@@ -75,13 +84,14 @@ public class LocationLayerControllerTest {
|
||||
LocationComponentOptions options = mock(LocationComponentOptions.class);
|
||||
|
||||
new LocationLayerController(mapboxMap, mapboxMap.getStyle(), sourceProvider, buildFeatureProvider(options),
|
||||
bitmapProvider, options);
|
||||
bitmapProvider, options, internalRenderModeChangedListener);
|
||||
|
||||
verify(style).addLayerBelow(shadowLayer, BACKGROUND_LAYER);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onInitialization_backgroundLayerIsAdded() {
|
||||
OnRenderModeChangedListener internalRenderModeChangedListener = mock(OnRenderModeChangedListener.class);
|
||||
LayerSourceProvider sourceProvider = buildLayerProvider();
|
||||
Layer backgroundLayer = mock(Layer.class);
|
||||
when(sourceProvider.generateLayer(BACKGROUND_LAYER)).thenReturn(backgroundLayer);
|
||||
@@ -91,13 +101,14 @@ public class LocationLayerControllerTest {
|
||||
LocationComponentOptions options = mock(LocationComponentOptions.class);
|
||||
|
||||
new LocationLayerController(mapboxMap, mapboxMap.getStyle(), sourceProvider, buildFeatureProvider(options),
|
||||
bitmapProvider, options);
|
||||
bitmapProvider, options, internalRenderModeChangedListener);
|
||||
|
||||
verify(style).addLayerBelow(backgroundLayer, FOREGROUND_LAYER);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onInitialization_foregroundLayerIsAdded() {
|
||||
OnRenderModeChangedListener internalRenderModeChangedListener = mock(OnRenderModeChangedListener.class);
|
||||
LayerSourceProvider sourceProvider = buildLayerProvider();
|
||||
Layer foregroundLayer = mock(Layer.class);
|
||||
when(sourceProvider.generateLayer(FOREGROUND_LAYER)).thenReturn(foregroundLayer);
|
||||
@@ -107,13 +118,14 @@ public class LocationLayerControllerTest {
|
||||
LocationComponentOptions options = mock(LocationComponentOptions.class);
|
||||
|
||||
new LocationLayerController(mapboxMap, mapboxMap.getStyle(), sourceProvider, buildFeatureProvider(options),
|
||||
bitmapProvider, options);
|
||||
bitmapProvider, options, internalRenderModeChangedListener);
|
||||
|
||||
verify(style).addLayerBelow(foregroundLayer, BEARING_LAYER);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onInitialization_bearingLayerIsAdded() {
|
||||
OnRenderModeChangedListener internalRenderModeChangedListener = mock(OnRenderModeChangedListener.class);
|
||||
LayerSourceProvider sourceProvider = buildLayerProvider();
|
||||
Layer bearingLayer = mock(Layer.class);
|
||||
when(sourceProvider.generateLayer(BEARING_LAYER)).thenReturn(bearingLayer);
|
||||
@@ -125,13 +137,14 @@ public class LocationLayerControllerTest {
|
||||
when(options.layerBelow()).thenReturn(layerBelow);
|
||||
|
||||
new LocationLayerController(mapboxMap, mapboxMap.getStyle(), sourceProvider, buildFeatureProvider(options),
|
||||
bitmapProvider, options);
|
||||
bitmapProvider, options, internalRenderModeChangedListener);
|
||||
|
||||
verify(style).addLayerBelow(bearingLayer, layerBelow);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onInitialization_accuracyLayerIsAdded() {
|
||||
OnRenderModeChangedListener internalRenderModeChangedListener = mock(OnRenderModeChangedListener.class);
|
||||
LayerSourceProvider sourceProvider = buildLayerProvider();
|
||||
Layer accuracyLayer = mock(Layer.class);
|
||||
when(sourceProvider.generateAccuracyLayer()).thenReturn(accuracyLayer);
|
||||
@@ -141,13 +154,14 @@ public class LocationLayerControllerTest {
|
||||
LocationComponentOptions options = mock(LocationComponentOptions.class);
|
||||
|
||||
new LocationLayerController(mapboxMap, mapboxMap.getStyle(), sourceProvider, buildFeatureProvider(options),
|
||||
bitmapProvider, options);
|
||||
bitmapProvider, options, internalRenderModeChangedListener);
|
||||
|
||||
verify(style).addLayerBelow(accuracyLayer, BACKGROUND_LAYER);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void applyStyle_styleShadowWithValidElevation() {
|
||||
OnRenderModeChangedListener internalRenderModeChangedListener = mock(OnRenderModeChangedListener.class);
|
||||
LayerSourceProvider sourceProvider = buildLayerProvider();
|
||||
when(sourceProvider.generateSource(any(Feature.class))).thenReturn(mock(GeoJsonSource.class));
|
||||
LayerBitmapProvider bitmapProvider = mock(LayerBitmapProvider.class);
|
||||
@@ -158,13 +172,14 @@ public class LocationLayerControllerTest {
|
||||
|
||||
// Style is applied on initialization
|
||||
new LocationLayerController(mapboxMap, mapboxMap.getStyle(), sourceProvider, buildFeatureProvider(options),
|
||||
bitmapProvider, options);
|
||||
bitmapProvider, options, internalRenderModeChangedListener);
|
||||
|
||||
verify(style).addImage(SHADOW_ICON, bitmap);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void applyStyle_ignoreStyleShadowWithInvalidElevation() {
|
||||
OnRenderModeChangedListener internalRenderModeChangedListener = mock(OnRenderModeChangedListener.class);
|
||||
LayerSourceProvider sourceProvider = buildLayerProvider();
|
||||
when(sourceProvider.generateSource(any(Feature.class))).thenReturn(mock(GeoJsonSource.class));
|
||||
LayerBitmapProvider bitmapProvider = mock(LayerBitmapProvider.class);
|
||||
@@ -174,13 +189,14 @@ public class LocationLayerControllerTest {
|
||||
when(options.elevation()).thenReturn(0f);
|
||||
|
||||
new LocationLayerController(mapboxMap, mapboxMap.getStyle(), sourceProvider, buildFeatureProvider(options),
|
||||
bitmapProvider, options);
|
||||
bitmapProvider, options, internalRenderModeChangedListener);
|
||||
|
||||
verify(style, times(0)).addImage(SHADOW_ICON, bitmap);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void applyStyle_styleForegroundFromOptions() {
|
||||
OnRenderModeChangedListener internalRenderModeChangedListener = mock(OnRenderModeChangedListener.class);
|
||||
LayerSourceProvider sourceProvider = buildLayerProvider();
|
||||
when(sourceProvider.generateSource(any(Feature.class))).thenReturn(mock(GeoJsonSource.class));
|
||||
LocationComponentOptions options = mock(LocationComponentOptions.class);
|
||||
@@ -193,13 +209,14 @@ public class LocationLayerControllerTest {
|
||||
when(bitmapProvider.generateBitmap(drawableResId, tintColor)).thenReturn(bitmap);
|
||||
|
||||
new LocationLayerController(mapboxMap, mapboxMap.getStyle(), sourceProvider, buildFeatureProvider(options),
|
||||
bitmapProvider, options);
|
||||
bitmapProvider, options, internalRenderModeChangedListener);
|
||||
|
||||
verify(style).addImage(FOREGROUND_ICON, bitmap);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void applyStyle_styleForegroundStaleFromOptions() {
|
||||
OnRenderModeChangedListener internalRenderModeChangedListener = mock(OnRenderModeChangedListener.class);
|
||||
LayerSourceProvider sourceProvider = buildLayerProvider();
|
||||
when(sourceProvider.generateSource(any(Feature.class))).thenReturn(mock(GeoJsonSource.class));
|
||||
LocationComponentOptions options = mock(LocationComponentOptions.class);
|
||||
@@ -212,13 +229,14 @@ public class LocationLayerControllerTest {
|
||||
when(bitmapProvider.generateBitmap(drawableResId, tintColor)).thenReturn(bitmap);
|
||||
|
||||
new LocationLayerController(mapboxMap, mapboxMap.getStyle(), sourceProvider, buildFeatureProvider(options),
|
||||
bitmapProvider, options);
|
||||
bitmapProvider, options, internalRenderModeChangedListener);
|
||||
|
||||
verify(style).addImage(FOREGROUND_STALE_ICON, bitmap);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void applyStyle_styleBackgroundFromOptions() {
|
||||
OnRenderModeChangedListener internalRenderModeChangedListener = mock(OnRenderModeChangedListener.class);
|
||||
LayerSourceProvider sourceProvider = buildLayerProvider();
|
||||
when(sourceProvider.generateSource(any(Feature.class))).thenReturn(mock(GeoJsonSource.class));
|
||||
LocationComponentOptions options = mock(LocationComponentOptions.class);
|
||||
@@ -231,13 +249,14 @@ public class LocationLayerControllerTest {
|
||||
when(bitmapProvider.generateBitmap(drawableResId, tintColor)).thenReturn(bitmap);
|
||||
|
||||
new LocationLayerController(mapboxMap, mapboxMap.getStyle(), sourceProvider, buildFeatureProvider(options),
|
||||
bitmapProvider, options);
|
||||
bitmapProvider, options, internalRenderModeChangedListener);
|
||||
|
||||
verify(style).addImage(BACKGROUND_ICON, bitmap);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void applyStyle_styleBackgroundStaleFromOptions() {
|
||||
OnRenderModeChangedListener internalRenderModeChangedListener = mock(OnRenderModeChangedListener.class);
|
||||
LayerSourceProvider sourceProvider = buildLayerProvider();
|
||||
when(sourceProvider.generateSource(any(Feature.class))).thenReturn(mock(GeoJsonSource.class));
|
||||
LocationComponentOptions options = mock(LocationComponentOptions.class);
|
||||
@@ -250,13 +269,14 @@ public class LocationLayerControllerTest {
|
||||
when(bitmapProvider.generateBitmap(drawableResId, tintColor)).thenReturn(bitmap);
|
||||
|
||||
new LocationLayerController(mapboxMap, mapboxMap.getStyle(), sourceProvider, buildFeatureProvider(options),
|
||||
bitmapProvider, options);
|
||||
bitmapProvider, options, internalRenderModeChangedListener);
|
||||
|
||||
verify(style).addImage(BACKGROUND_STALE_ICON, bitmap);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void applyStyle_styleBearingFromOptions() {
|
||||
OnRenderModeChangedListener internalRenderModeChangedListener = mock(OnRenderModeChangedListener.class);
|
||||
LayerSourceProvider sourceProvider = buildLayerProvider();
|
||||
when(sourceProvider.generateSource(any(Feature.class))).thenReturn(mock(GeoJsonSource.class));
|
||||
LocationComponentOptions options = mock(LocationComponentOptions.class);
|
||||
@@ -269,13 +289,14 @@ public class LocationLayerControllerTest {
|
||||
when(bitmapProvider.generateBitmap(drawableResId, tintColor)).thenReturn(bitmap);
|
||||
|
||||
new LocationLayerController(mapboxMap, mapboxMap.getStyle(), sourceProvider, buildFeatureProvider(options),
|
||||
bitmapProvider, options);
|
||||
bitmapProvider, options, internalRenderModeChangedListener);
|
||||
|
||||
verify(style).addImage(BEARING_ICON, bitmap);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void applyStyle_layerBelowChanged() {
|
||||
OnRenderModeChangedListener internalRenderModeChangedListener = mock(OnRenderModeChangedListener.class);
|
||||
LayerSourceProvider sourceProvider = buildLayerProvider();
|
||||
when(sourceProvider.generateSource(any(Feature.class))).thenReturn(mock(GeoJsonSource.class));
|
||||
|
||||
@@ -302,7 +323,7 @@ public class LocationLayerControllerTest {
|
||||
|
||||
LocationLayerController layerController =
|
||||
new LocationLayerController(mapboxMap, mapboxMap.getStyle(), sourceProvider, buildFeatureProvider(options),
|
||||
bitmapProvider, options);
|
||||
bitmapProvider, options, internalRenderModeChangedListener);
|
||||
|
||||
Layer bearingLayer2 = mock(Layer.class);
|
||||
when(sourceProvider.generateLayer(BEARING_LAYER)).thenReturn(bearingLayer2);
|
||||
@@ -334,6 +355,7 @@ public class LocationLayerControllerTest {
|
||||
|
||||
@Test
|
||||
public void applyStyle_layerBelowNotChanged() {
|
||||
OnRenderModeChangedListener internalRenderModeChangedListener = mock(OnRenderModeChangedListener.class);
|
||||
LayerSourceProvider sourceProvider = buildLayerProvider();
|
||||
when(sourceProvider.generateSource(any(Feature.class))).thenReturn(mock(GeoJsonSource.class));
|
||||
LocationComponentOptions options = mock(LocationComponentOptions.class);
|
||||
@@ -346,7 +368,7 @@ public class LocationLayerControllerTest {
|
||||
|
||||
LocationLayerController layerController =
|
||||
new LocationLayerController(mapboxMap, mapboxMap.getStyle(), sourceProvider, buildFeatureProvider(options),
|
||||
bitmapProvider, options);
|
||||
bitmapProvider, options, internalRenderModeChangedListener);
|
||||
|
||||
options = mock(LocationComponentOptions.class);
|
||||
layerBelow = "layer-below";
|
||||
@@ -359,6 +381,7 @@ public class LocationLayerControllerTest {
|
||||
|
||||
@Test
|
||||
public void applyStyle_layerBelowNotChangedNull() {
|
||||
OnRenderModeChangedListener internalRenderModeChangedListener = mock(OnRenderModeChangedListener.class);
|
||||
LayerSourceProvider sourceProvider = buildLayerProvider();
|
||||
when(sourceProvider.generateSource(any(Feature.class))).thenReturn(mock(GeoJsonSource.class));
|
||||
LocationComponentOptions options = mock(LocationComponentOptions.class);
|
||||
@@ -368,7 +391,7 @@ public class LocationLayerControllerTest {
|
||||
|
||||
LocationLayerController layerController =
|
||||
new LocationLayerController(mapboxMap, mapboxMap.getStyle(), sourceProvider, buildFeatureProvider(options),
|
||||
bitmapProvider, options);
|
||||
bitmapProvider, options, internalRenderModeChangedListener);
|
||||
|
||||
options = mock(LocationComponentOptions.class);
|
||||
layerController.applyStyle(options);
|
||||
@@ -379,6 +402,7 @@ public class LocationLayerControllerTest {
|
||||
|
||||
@Test
|
||||
public void updateForegroundOffset_foregroundIconPropertyIsUpdated() {
|
||||
OnRenderModeChangedListener internalRenderModeChangedListener = mock(OnRenderModeChangedListener.class);
|
||||
LayerSourceProvider sourceProvider = buildLayerProvider();
|
||||
GeoJsonSource locationSource = mock(GeoJsonSource.class);
|
||||
when(sourceProvider.generateSource(any(Feature.class))).thenReturn(locationSource);
|
||||
@@ -387,7 +411,7 @@ public class LocationLayerControllerTest {
|
||||
Feature locationFeature = mock(Feature.class);
|
||||
LocationLayerController layer = new LocationLayerController(
|
||||
mapboxMap, mapboxMap.getStyle(), sourceProvider, buildFeatureProvider(locationFeature, options),
|
||||
bitmapProvider, options
|
||||
bitmapProvider, options, internalRenderModeChangedListener
|
||||
);
|
||||
|
||||
layer.updateForegroundOffset(2d);
|
||||
@@ -397,6 +421,7 @@ public class LocationLayerControllerTest {
|
||||
|
||||
@Test
|
||||
public void updateForegroundOffset_shadowPropertyIsUpdated() {
|
||||
OnRenderModeChangedListener internalRenderModeChangedListener = mock(OnRenderModeChangedListener.class);
|
||||
LayerSourceProvider sourceProvider = buildLayerProvider();
|
||||
GeoJsonSource locationSource = mock(GeoJsonSource.class);
|
||||
when(sourceProvider.generateSource(any(Feature.class))).thenReturn(locationSource);
|
||||
@@ -405,7 +430,7 @@ public class LocationLayerControllerTest {
|
||||
Feature locationFeature = mock(Feature.class);
|
||||
LocationLayerController layer = new LocationLayerController(
|
||||
mapboxMap, mapboxMap.getStyle(), sourceProvider, buildFeatureProvider(locationFeature, options),
|
||||
bitmapProvider, options
|
||||
bitmapProvider, options, internalRenderModeChangedListener
|
||||
);
|
||||
layer.updateForegroundOffset(2d);
|
||||
|
||||
@@ -414,6 +439,7 @@ public class LocationLayerControllerTest {
|
||||
|
||||
@Test
|
||||
public void onNewLatLngValue_locationFeatureIsUpdated() {
|
||||
OnRenderModeChangedListener internalRenderModeChangedListener = mock(OnRenderModeChangedListener.class);
|
||||
GeoJsonSource locationSource = mock(GeoJsonSource.class);
|
||||
when(style.getSourceAs(LOCATION_SOURCE)).thenReturn(locationSource);
|
||||
LayerSourceProvider sourceProvider = buildLayerProvider();
|
||||
@@ -423,9 +449,10 @@ public class LocationLayerControllerTest {
|
||||
Feature locationFeature = mock(Feature.class);
|
||||
LocationLayerController layer = new LocationLayerController(
|
||||
mapboxMap, mapboxMap.getStyle(), sourceProvider, buildFeatureProvider(locationFeature, options),
|
||||
bitmapProvider, options
|
||||
bitmapProvider, options, internalRenderModeChangedListener
|
||||
);
|
||||
layer.onNewLatLngValue(new LatLng());
|
||||
|
||||
getAnimationListener(ANIMATOR_LAYER_LATLNG, layer.getAnimationListeners()).onNewAnimationValue(new LatLng());
|
||||
|
||||
// wanted twice (once for initialization)
|
||||
verify(locationSource, times(2)).setGeoJson(locationFeature);
|
||||
@@ -433,6 +460,7 @@ public class LocationLayerControllerTest {
|
||||
|
||||
@Test
|
||||
public void onNewGpsBearingValue_locationFeatureIsUpdated() {
|
||||
OnRenderModeChangedListener internalRenderModeChangedListener = mock(OnRenderModeChangedListener.class);
|
||||
GeoJsonSource locationSource = mock(GeoJsonSource.class);
|
||||
when(style.getSourceAs(LOCATION_SOURCE)).thenReturn(locationSource);
|
||||
LayerSourceProvider sourceProvider = buildLayerProvider();
|
||||
@@ -442,18 +470,19 @@ public class LocationLayerControllerTest {
|
||||
Feature locationFeature = mock(Feature.class);
|
||||
LocationLayerController layer = new LocationLayerController(
|
||||
mapboxMap, mapboxMap.getStyle(), sourceProvider, buildFeatureProvider(locationFeature, options),
|
||||
bitmapProvider, options
|
||||
bitmapProvider, options, internalRenderModeChangedListener
|
||||
);
|
||||
layer.setRenderMode(RenderMode.GPS);
|
||||
float gpsBearing = 2f;
|
||||
|
||||
layer.onNewGpsBearingValue(gpsBearing);
|
||||
getAnimationListener(ANIMATOR_LAYER_GPS_BEARING, layer.getAnimationListeners()).onNewAnimationValue(gpsBearing);
|
||||
|
||||
verify(locationFeature).addNumberProperty(PROPERTY_GPS_BEARING, gpsBearing);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onNewGpsBearingValue_updateIgnoredWithInvalidRenderMode() {
|
||||
OnRenderModeChangedListener internalRenderModeChangedListener = mock(OnRenderModeChangedListener.class);
|
||||
GeoJsonSource locationSource = mock(GeoJsonSource.class);
|
||||
when(style.getSourceAs(LOCATION_SOURCE)).thenReturn(locationSource);
|
||||
LayerSourceProvider sourceProvider = buildLayerProvider();
|
||||
@@ -463,18 +492,18 @@ public class LocationLayerControllerTest {
|
||||
Feature locationFeature = mock(Feature.class);
|
||||
LocationLayerController layer = new LocationLayerController(
|
||||
mapboxMap, mapboxMap.getStyle(), sourceProvider, buildFeatureProvider(locationFeature, options),
|
||||
bitmapProvider, options
|
||||
bitmapProvider, options, internalRenderModeChangedListener
|
||||
);
|
||||
layer.setRenderMode(RenderMode.COMPASS);
|
||||
float gpsBearing = 2f;
|
||||
|
||||
layer.onNewGpsBearingValue(gpsBearing);
|
||||
|
||||
assertNull(getAnimationListener(ANIMATOR_LAYER_GPS_BEARING, layer.getAnimationListeners()));
|
||||
verify(locationFeature, times(0)).addNumberProperty(PROPERTY_GPS_BEARING, gpsBearing);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onNewCompassBearingValue_locationFeatureIsUpdated() {
|
||||
OnRenderModeChangedListener internalRenderModeChangedListener = mock(OnRenderModeChangedListener.class);
|
||||
GeoJsonSource locationSource = mock(GeoJsonSource.class);
|
||||
when(style.getSourceAs(LOCATION_SOURCE)).thenReturn(locationSource);
|
||||
LayerSourceProvider sourceProvider = buildLayerProvider();
|
||||
@@ -484,18 +513,19 @@ public class LocationLayerControllerTest {
|
||||
Feature locationFeature = mock(Feature.class);
|
||||
LocationLayerController layer = new LocationLayerController(
|
||||
mapboxMap, mapboxMap.getStyle(), sourceProvider, buildFeatureProvider(locationFeature, options),
|
||||
bitmapProvider, options
|
||||
bitmapProvider, options, internalRenderModeChangedListener
|
||||
);
|
||||
layer.setRenderMode(RenderMode.COMPASS);
|
||||
float compassBearing = 2f;
|
||||
|
||||
layer.onNewCompassBearingValue(compassBearing);
|
||||
getAnimationListener(ANIMATOR_LAYER_COMPASS_BEARING, layer.getAnimationListeners()).onNewAnimationValue(compassBearing);
|
||||
|
||||
verify(locationFeature).addNumberProperty(PROPERTY_COMPASS_BEARING, compassBearing);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onNewCompassBearingValue_updateIgnoredWithInvalidRenderMode() {
|
||||
OnRenderModeChangedListener internalRenderModeChangedListener = mock(OnRenderModeChangedListener.class);
|
||||
GeoJsonSource locationSource = mock(GeoJsonSource.class);
|
||||
when(style.getSourceAs(LOCATION_SOURCE)).thenReturn(locationSource);
|
||||
LayerSourceProvider sourceProvider = buildLayerProvider();
|
||||
@@ -505,18 +535,18 @@ public class LocationLayerControllerTest {
|
||||
Feature locationFeature = mock(Feature.class);
|
||||
LocationLayerController layer = new LocationLayerController(
|
||||
mapboxMap, mapboxMap.getStyle(), sourceProvider, buildFeatureProvider(locationFeature, options),
|
||||
bitmapProvider, options
|
||||
bitmapProvider, options, internalRenderModeChangedListener
|
||||
);
|
||||
layer.setRenderMode(RenderMode.GPS);
|
||||
float compassBearing = 2f;
|
||||
|
||||
layer.onNewCompassBearingValue(compassBearing);
|
||||
|
||||
assertNull(getAnimationListener(ANIMATOR_LAYER_COMPASS_BEARING, layer.getAnimationListeners()));
|
||||
verify(locationFeature, times(0)).addNumberProperty(PROPERTY_COMPASS_BEARING, compassBearing);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onNewAccuracyRadiusValue_locationFeatureIsUpdated() {
|
||||
OnRenderModeChangedListener internalRenderModeChangedListener = mock(OnRenderModeChangedListener.class);
|
||||
GeoJsonSource locationSource = mock(GeoJsonSource.class);
|
||||
when(style.getSourceAs(LOCATION_SOURCE)).thenReturn(locationSource);
|
||||
LayerSourceProvider sourceProvider = buildLayerProvider();
|
||||
@@ -526,17 +556,19 @@ public class LocationLayerControllerTest {
|
||||
Feature locationFeature = mock(Feature.class);
|
||||
LocationLayerController layer = new LocationLayerController(
|
||||
mapboxMap, mapboxMap.getStyle(), sourceProvider, buildFeatureProvider(locationFeature, options),
|
||||
bitmapProvider, options
|
||||
bitmapProvider, options, internalRenderModeChangedListener
|
||||
);
|
||||
layer.setRenderMode(RenderMode.NORMAL);
|
||||
float accuracyRadiusValue = 2f;
|
||||
|
||||
layer.onNewAccuracyRadiusValue(accuracyRadiusValue);
|
||||
getAnimationListener(ANIMATOR_LAYER_ACCURACY, layer.getAnimationListeners()).onNewAnimationValue(accuracyRadiusValue);
|
||||
|
||||
verify(locationFeature).addNumberProperty(PROPERTY_ACCURACY_RADIUS, accuracyRadiusValue);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void onNewAccuracyRadiusValue_updateIgnoredWithInvalidRenderMode() {
|
||||
OnRenderModeChangedListener internalRenderModeChangedListener = mock(OnRenderModeChangedListener.class);
|
||||
GeoJsonSource locationSource = mock(GeoJsonSource.class);
|
||||
when(style.getSourceAs(LOCATION_SOURCE)).thenReturn(locationSource);
|
||||
LayerSourceProvider sourceProvider = buildLayerProvider();
|
||||
@@ -546,13 +578,12 @@ public class LocationLayerControllerTest {
|
||||
Feature locationFeature = mock(Feature.class);
|
||||
LocationLayerController layer = new LocationLayerController(
|
||||
mapboxMap, mapboxMap.getStyle(), sourceProvider, buildFeatureProvider(locationFeature, options),
|
||||
bitmapProvider, options
|
||||
bitmapProvider, options, internalRenderModeChangedListener
|
||||
);
|
||||
layer.setRenderMode(RenderMode.GPS);
|
||||
float accuracyRadiusValue = 2f;
|
||||
|
||||
layer.onNewAccuracyRadiusValue(accuracyRadiusValue);
|
||||
|
||||
assertNull(getAnimationListener(ANIMATOR_LAYER_ACCURACY, layer.getAnimationListeners()));
|
||||
verify(locationFeature, times(0)).addNumberProperty(PROPERTY_ACCURACY_RADIUS, accuracyRadiusValue);
|
||||
}
|
||||
|
||||
@@ -587,4 +618,16 @@ public class LocationLayerControllerTest {
|
||||
when(layerSourceProvider.generateAccuracyLayer()).thenReturn(accuracyLayer);
|
||||
return layerSourceProvider;
|
||||
}
|
||||
|
||||
private <T> MapboxAnimator.AnimationsValueChangeListener<T> getAnimationListener(
|
||||
@MapboxAnimator.Type int animatorType,
|
||||
Set<AnimatorListenerHolder> holders) {
|
||||
for (AnimatorListenerHolder holder : holders) {
|
||||
@MapboxAnimator.Type int type = holder.getAnimatorType();
|
||||
if (type == animatorType) {
|
||||
return holder.getListener();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
package com.mapbox.mapboxsdk.location
|
||||
|
||||
import android.animation.ValueAnimator
|
||||
import io.mockk.every
|
||||
import io.mockk.mockk
|
||||
import io.mockk.verify
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.robolectric.RobolectricTestRunner
|
||||
|
||||
@RunWith(RobolectricTestRunner::class)
|
||||
class MapboxAnimatorTest {
|
||||
|
||||
@Test
|
||||
fun fps_unlimited() {
|
||||
val valueAnimator = mockk<ValueAnimator>()
|
||||
every { valueAnimator.animatedValue } answers { 5f }
|
||||
val listener = mockk<MapboxAnimator.AnimationsValueChangeListener<Float>>()
|
||||
every { listener.onNewAnimationValue(any()) } answers {}
|
||||
val mapboxAnimator = MapboxFloatAnimator(0f, 10f, listener, Int.MAX_VALUE)
|
||||
|
||||
for (i in 0 until 5)
|
||||
mapboxAnimator.onAnimationUpdate(valueAnimator)
|
||||
|
||||
verify(exactly = 5) { listener.onNewAnimationValue(5f) }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun fps_limited() {
|
||||
val valueAnimator = mockk<ValueAnimator>()
|
||||
every { valueAnimator.animatedValue } answers { 5f }
|
||||
val listener = mockk<MapboxAnimator.AnimationsValueChangeListener<Float>>()
|
||||
every { listener.onNewAnimationValue(any()) } answers {}
|
||||
val mapboxAnimator = MapboxFloatAnimator(0f, 10f, listener, 5)
|
||||
|
||||
for (i in 0 until 5) {
|
||||
mapboxAnimator.onAnimationUpdate(valueAnimator)
|
||||
Thread.sleep(150)
|
||||
}
|
||||
|
||||
verify(exactly = 3) { listener.onNewAnimationValue(5f) }
|
||||
}
|
||||
}
|
||||
@@ -174,6 +174,10 @@ public class LocationModesActivity extends AppCompatActivity implements OnMapRea
|
||||
} else if (id == R.id.action_gestures_management_enabled) {
|
||||
enableGesturesManagement();
|
||||
return true;
|
||||
} else if (id == R.id.action_component_throttling_enabled) {
|
||||
locationComponent.setMaxAnimationFps(5);
|
||||
} else if (id == R.id.action_component_throttling_disabled) {
|
||||
locationComponent.setMaxAnimationFps(Integer.MAX_VALUE);
|
||||
}
|
||||
|
||||
return super.onOptionsItemSelected(item);
|
||||
|
||||
@@ -24,4 +24,12 @@
|
||||
<item android:id="@+id/action_gestures_management_disabled"
|
||||
android:title="Disable Gestures Management"
|
||||
app:showAsAction="never"/>
|
||||
|
||||
<item android:id="@+id/action_component_throttling_enabled"
|
||||
android:title="Enable animation throttling (5 FPS)"
|
||||
app:showAsAction="never"/>
|
||||
|
||||
<item android:id="@+id/action_component_throttling_disabled"
|
||||
android:title="Disable animation throttling"
|
||||
app:showAsAction="never"/>
|
||||
</menu>
|
||||
@@ -17,7 +17,7 @@ ext {
|
||||
leakCanary : '1.6.1',
|
||||
junit : '4.12',
|
||||
mockito : '2.23.4',
|
||||
mockk : '1.8.13.kotlin13',
|
||||
mockk : '1.9',
|
||||
robolectric : '3.8',
|
||||
timber : '4.7.1',
|
||||
okhttp : '3.11.0',
|
||||
|
||||
Reference in New Issue
Block a user