diff options
author | Łukasz Paczos <lukas.paczos@gmail.com> | 2018-09-20 13:50:47 +0200 |
---|---|---|
committer | Łukasz Paczos <lukasz.paczos@mapbox.com> | 2018-09-25 11:52:35 +0200 |
commit | ba06161b2759fec36bba58127504805372a04d49 (patch) | |
tree | 7ccc3dc96128772d0cb1c438fab94abaadf57724 /platform/android/MapboxGLAndroidSDK | |
parent | d2661fc2981a2e31a9c27932febbf44a5c380218 (diff) | |
download | qtlocation-mapboxgl-ba06161b2759fec36bba58127504805372a04d49.tar.gz |
[android] invalidate camera mode in LocationComponent for gestures initiated changes only if necessary
Diffstat (limited to 'platform/android/MapboxGLAndroidSDK')
2 files changed, 64 insertions, 2 deletions
diff --git a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/location/LocationCameraController.java b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/location/LocationCameraController.java index 501bb95f8e..e3194df009 100644 --- a/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/location/LocationCameraController.java +++ b/platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/location/LocationCameraController.java @@ -3,6 +3,7 @@ package com.mapbox.mapboxsdk.location; import android.content.Context; import android.graphics.PointF; import android.support.annotation.NonNull; +import android.support.annotation.VisibleForTesting; import android.view.MotionEvent; import com.mapbox.android.gestures.AndroidGesturesManager; @@ -186,7 +187,8 @@ final class LocationCameraController implements MapboxAnimator.OnCameraAnimation } } - private MapboxMap.OnMoveListener onMoveListener = new MapboxMap.OnMoveListener() { + @VisibleForTesting + MapboxMap.OnMoveListener onMoveListener = new MapboxMap.OnMoveListener() { private boolean interrupt; @Override @@ -208,7 +210,11 @@ final class LocationCameraController implements MapboxAnimator.OnCameraAnimation detector.interrupt(); return; } - setCameraMode(CameraMode.NONE); + + if (isLocationTracking() || isBearingTracking()) { + setCameraMode(CameraMode.NONE); + detector.interrupt(); + } } @Override diff --git a/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/location/LocationCameraControllerTest.java b/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/location/LocationCameraControllerTest.java index 616e86bd78..9e26bb1a60 100644 --- a/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/location/LocationCameraControllerTest.java +++ b/platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/location/LocationCameraControllerTest.java @@ -357,6 +357,62 @@ public class LocationCameraControllerTest { verify(mapboxMap).setGesturesManager(initialGesturesManager, true, true); } + @Test + public void onMove_cancellingTransitionWhileNone() { + MapboxMap mapboxMap = mock(MapboxMap.class); + when(mapboxMap.getUiSettings()).thenReturn(mock(UiSettings.class)); + MoveGestureDetector moveGestureDetector = mock(MoveGestureDetector.class); + LocationCameraController camera = buildCamera(mapboxMap); + camera.initializeOptions(mock(LocationComponentOptions.class)); + + camera.setCameraMode(CameraMode.NONE); + camera.onMoveListener.onMove(moveGestureDetector); + verify(mapboxMap, times(1)).cancelTransitions(); + verify(moveGestureDetector, times(0)).interrupt(); + + // testing subsequent calls + camera.onMoveListener.onMove(moveGestureDetector); + verify(mapboxMap, times(1)).cancelTransitions(); + verify(moveGestureDetector, times(0)).interrupt(); + } + + @Test + public void onMove_cancellingTransitionWhileGps() { + MapboxMap mapboxMap = mock(MapboxMap.class); + when(mapboxMap.getUiSettings()).thenReturn(mock(UiSettings.class)); + MoveGestureDetector moveGestureDetector = mock(MoveGestureDetector.class); + LocationCameraController camera = buildCamera(mapboxMap); + camera.initializeOptions(mock(LocationComponentOptions.class)); + + camera.setCameraMode(CameraMode.TRACKING); + camera.onMoveListener.onMove(moveGestureDetector); + verify(mapboxMap, times(2)).cancelTransitions(); + verify(moveGestureDetector, times(1)).interrupt(); + + // testing subsequent calls + camera.onMoveListener.onMove(moveGestureDetector); + verify(mapboxMap, times(2)).cancelTransitions(); + verify(moveGestureDetector, times(1)).interrupt(); + } + + @Test + public void onMove_cancellingTransitionWhileBearing() { + MapboxMap mapboxMap = mock(MapboxMap.class); + MoveGestureDetector moveGestureDetector = mock(MoveGestureDetector.class); + LocationCameraController camera = buildCamera(mapboxMap); + camera.initializeOptions(mock(LocationComponentOptions.class)); + + camera.setCameraMode(CameraMode.NONE_COMPASS); + camera.onMoveListener.onMove(moveGestureDetector); + verify(mapboxMap, times(2)).cancelTransitions(); + verify(moveGestureDetector, times(1)).interrupt(); + + // testing subsequent calls + camera.onMoveListener.onMove(moveGestureDetector); + verify(mapboxMap, times(2)).cancelTransitions(); + verify(moveGestureDetector, times(1)).interrupt(); + } + private LocationCameraController buildCamera(OnCameraTrackingChangedListener onCameraTrackingChangedListener) { MapboxMap mapboxMap = mock(MapboxMap.class); when(mapboxMap.getUiSettings()).thenReturn(mock(UiSettings.class)); |