[android] reset location layer animators when render mode changes
This commit is contained in:
committed by
Łukasz Paczos
parent
e60b48eca9
commit
fe570fb206
@@ -347,6 +347,34 @@ final class LocationAnimatorCoordinator {
|
||||
createNewFloatAnimator(ANIMATOR_CAMERA_COMPASS_BEARING, previousCameraBearing, normalizedCameraBearing);
|
||||
}
|
||||
|
||||
void resetAllLayerAnimations() {
|
||||
MapboxLatLngAnimator latLngAnimator = (MapboxLatLngAnimator) animatorArray.get(ANIMATOR_LAYER_LATLNG);
|
||||
MapboxFloatAnimator gpsBearingAnimator = (MapboxFloatAnimator) animatorArray.get(ANIMATOR_LAYER_GPS_BEARING);
|
||||
MapboxFloatAnimator compassBearingAnimator =
|
||||
(MapboxFloatAnimator) animatorArray.get(ANIMATOR_LAYER_COMPASS_BEARING);
|
||||
|
||||
if (latLngAnimator != null && gpsBearingAnimator != null) {
|
||||
LatLng currentLatLng = (LatLng) latLngAnimator.getAnimatedValue();
|
||||
LatLng currentLatLngTarget = latLngAnimator.getTarget();
|
||||
createNewLatLngAnimator(ANIMATOR_LAYER_LATLNG, currentLatLng, currentLatLngTarget);
|
||||
|
||||
float currentGpsBearing = (float) gpsBearingAnimator.getAnimatedValue();
|
||||
float currentGpsBearingTarget = gpsBearingAnimator.getTarget();
|
||||
createNewFloatAnimator(ANIMATOR_LAYER_GPS_BEARING, currentGpsBearing, currentGpsBearingTarget);
|
||||
|
||||
playAnimators(getAnimationDuration(), ANIMATOR_LAYER_LATLNG, ANIMATOR_LAYER_GPS_BEARING);
|
||||
}
|
||||
|
||||
if (compassBearingAnimator != null) {
|
||||
float currentLayerBearing = getPreviousLayerCompassBearing();
|
||||
float currentLayerBearingTarget = compassBearingAnimator.getTarget();
|
||||
createNewFloatAnimator(ANIMATOR_LAYER_COMPASS_BEARING, currentLayerBearing, currentLayerBearingTarget);
|
||||
playAnimators(
|
||||
compassAnimationEnabled ? COMPASS_UPDATE_RATE_MS : 0,
|
||||
ANIMATOR_LAYER_COMPASS_BEARING);
|
||||
}
|
||||
}
|
||||
|
||||
void cancelZoomAnimation() {
|
||||
cancelAnimator(ANIMATOR_ZOOM);
|
||||
}
|
||||
|
||||
@@ -1393,6 +1393,9 @@ public final class LocationComponent {
|
||||
animationsValueChangeListeners.addAll(locationLayerController.getAnimationListeners());
|
||||
animationsValueChangeListeners.addAll(locationCameraController.getAnimationListeners());
|
||||
locationAnimatorCoordinator.updateAnimatorListenerHolders(animationsValueChangeListeners);
|
||||
locationAnimatorCoordinator.resetAllCameraAnimations(mapboxMap.getCameraPosition(),
|
||||
locationCameraController.getCameraMode() == CameraMode.TRACKING_GPS_NORTH);
|
||||
locationAnimatorCoordinator.resetAllLayerAnimations();
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@@ -1517,7 +1520,8 @@ public final class LocationComponent {
|
||||
}
|
||||
|
||||
@NonNull
|
||||
private OnCameraTrackingChangedListener cameraTrackingChangedListener = new OnCameraTrackingChangedListener() {
|
||||
@VisibleForTesting
|
||||
OnCameraTrackingChangedListener cameraTrackingChangedListener = new OnCameraTrackingChangedListener() {
|
||||
@Override
|
||||
public void onCameraTrackingDismissed() {
|
||||
for (OnCameraTrackingChangedListener listener : onCameraTrackingChangedListeners) {
|
||||
@@ -1530,8 +1534,6 @@ public final class LocationComponent {
|
||||
locationAnimatorCoordinator.cancelZoomAnimation();
|
||||
locationAnimatorCoordinator.cancelTiltAnimation();
|
||||
updateAnimatorListenerHolders();
|
||||
locationAnimatorCoordinator.resetAllCameraAnimations(mapboxMap.getCameraPosition(),
|
||||
locationCameraController.getCameraMode() == CameraMode.TRACKING_GPS_NORTH);
|
||||
for (OnCameraTrackingChangedListener listener : onCameraTrackingChangedListeners) {
|
||||
listener.onCameraTrackingChanged(currentMode);
|
||||
}
|
||||
@@ -1539,7 +1541,8 @@ public final class LocationComponent {
|
||||
};
|
||||
|
||||
@NonNull
|
||||
private OnRenderModeChangedListener renderModeChangedListener = new OnRenderModeChangedListener() {
|
||||
@VisibleForTesting
|
||||
OnRenderModeChangedListener renderModeChangedListener = new OnRenderModeChangedListener() {
|
||||
@Override
|
||||
public void onRenderModeChanged(int currentMode) {
|
||||
updateAnimatorListenerHolders();
|
||||
|
||||
@@ -402,6 +402,12 @@ class LocationAnimatorCoordinatorTest {
|
||||
assertTrue(locationAnimatorCoordinator.animatorArray.size() == 0)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun resetAllLayerAnimations_empty() {
|
||||
locationAnimatorCoordinator.resetAllLayerAnimations()
|
||||
assertTrue(locationAnimatorCoordinator.animatorArray.size() == 0)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun addNewListener() {
|
||||
val listener = Mockito.mock(AnimationsValueChangeListener::class.java)
|
||||
|
||||
@@ -396,4 +396,59 @@ class LocationComponentTest {
|
||||
}
|
||||
verify(locationCameraController).setCameraMode(eq(CameraMode.NONE), isNull<Location>(), eq(TRANSITION_ANIMATION_DURATION_MS), isNull<Double>(), isNull<Double>(), isNull<Double>(), any())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun internal_cameraTrackingChangedListener_onCameraTrackingDismissed() {
|
||||
locationComponent.activateLocationComponent(context, mockk(), locationEngine, locationEngineRequest, locationComponentOptions)
|
||||
locationComponent.isLocationComponentEnabled = true
|
||||
|
||||
val cameraChangeListener: OnCameraTrackingChangedListener = mock(OnCameraTrackingChangedListener::class.java)
|
||||
locationComponent.addOnCameraTrackingChangedListener(cameraChangeListener)
|
||||
|
||||
locationComponent.cameraTrackingChangedListener.onCameraTrackingDismissed()
|
||||
|
||||
verify(cameraChangeListener).onCameraTrackingDismissed()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun internal_cameraTrackingChangedListener_onCameraTrackingChanged() {
|
||||
locationComponent.activateLocationComponent(context, mockk(), locationEngine, locationEngineRequest, locationComponentOptions)
|
||||
locationComponent.isLocationComponentEnabled = true
|
||||
|
||||
val cameraValueListener: AnimatorListenerHolder = mock(AnimatorListenerHolder::class.java)
|
||||
val layerValueListener: AnimatorListenerHolder = mock(AnimatorListenerHolder::class.java)
|
||||
`when`(locationCameraController.animationListeners).thenReturn(setOf(cameraValueListener))
|
||||
`when`(locationLayerController.animationListeners).thenReturn(setOf(layerValueListener))
|
||||
val cameraChangeListener: OnCameraTrackingChangedListener = mock(OnCameraTrackingChangedListener::class.java)
|
||||
locationComponent.addOnCameraTrackingChangedListener(cameraChangeListener)
|
||||
|
||||
locationComponent.cameraTrackingChangedListener.onCameraTrackingChanged(CameraMode.TRACKING_GPS)
|
||||
|
||||
verify(locationAnimatorCoordinator).cancelZoomAnimation()
|
||||
verify(locationAnimatorCoordinator).cancelTiltAnimation()
|
||||
verify(locationAnimatorCoordinator).updateAnimatorListenerHolders(eq(setOf(cameraValueListener, layerValueListener)))
|
||||
verify(locationAnimatorCoordinator).resetAllCameraAnimations(any(), anyBoolean())
|
||||
verify(locationAnimatorCoordinator).resetAllLayerAnimations()
|
||||
verify(cameraChangeListener).onCameraTrackingChanged(CameraMode.TRACKING_GPS)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun internal_renderModeChangedListener_onRenderModeChanged() {
|
||||
locationComponent.activateLocationComponent(context, mockk(), locationEngine, locationEngineRequest, locationComponentOptions)
|
||||
locationComponent.isLocationComponentEnabled = true
|
||||
|
||||
val cameraListener: AnimatorListenerHolder = mock(AnimatorListenerHolder::class.java)
|
||||
val layerListener: AnimatorListenerHolder = mock(AnimatorListenerHolder::class.java)
|
||||
`when`(locationCameraController.animationListeners).thenReturn(setOf(cameraListener))
|
||||
`when`(locationLayerController.animationListeners).thenReturn(setOf(layerListener))
|
||||
val renderChangeListener: OnRenderModeChangedListener = mock(OnRenderModeChangedListener::class.java)
|
||||
locationComponent.addOnRenderModeChangedListener(renderChangeListener)
|
||||
|
||||
locationComponent.renderModeChangedListener.onRenderModeChanged(RenderMode.NORMAL)
|
||||
|
||||
verify(locationAnimatorCoordinator).updateAnimatorListenerHolders(eq(setOf(cameraListener, layerListener)))
|
||||
verify(locationAnimatorCoordinator).resetAllCameraAnimations(any(), anyBoolean())
|
||||
verify(locationAnimatorCoordinator).resetAllLayerAnimations()
|
||||
verify(renderChangeListener).onRenderModeChanged(RenderMode.NORMAL)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user