summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorŁukasz Paczos <lukas.paczos@gmail.com>2018-09-20 13:50:47 +0200
committerŁukasz Paczos <lukas.paczos@gmail.com>2018-09-20 13:50:47 +0200
commitb738c68e576aff7023434024e4ca37d7495c8749 (patch)
treecfa9c1370bb7371e14cd8c12e58775780e5c9abd
parent2f7a1475e0287f9ca62c2d838f71011595cdb526 (diff)
downloadqtlocation-mapboxgl-upstream/lp-port-plugins-694.tar.gz
[android] invalidate camera mode in LocationComponent for gestures initiated changes only if necessaryupstream/lp-port-plugins-694
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/location/LocationCameraController.java10
-rw-r--r--platform/android/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/location/LocationCameraControllerTest.java56
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));