diff options
author | Łukasz Paczos <lukas.paczos@gmail.com> | 2018-09-06 17:07:54 +0200 |
---|---|---|
committer | Łukasz Paczos <lukasz.paczos@mapbox.com> | 2018-09-12 13:59:11 +0200 |
commit | b2d4b82cdfeb0e3807b2b3027398fbeeda751b03 (patch) | |
tree | 6d3e02d9c73a2213522784941bfe4849d97e609e /platform/android | |
parent | d625993da2b43c1168e946de498197da2c4e9678 (diff) | |
download | qtlocation-mapboxgl-b2d4b82cdfeb0e3807b2b3027398fbeeda751b03.tar.gz |
[android] updated location tracking gestures management tests
Diffstat (limited to 'platform/android')
4 files changed, 81 insertions, 13 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 50fb829fcc..501bb95f8e 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 @@ -54,13 +54,14 @@ final class LocationCameraController implements MapboxAnimator.OnCameraAnimation MoveGestureDetector moveGestureDetector, OnCameraTrackingChangedListener internalCameraTrackingChangedListener, OnCameraMoveInvalidateListener onCameraMoveInvalidateListener, - AndroidGesturesManager androidGesturesManager) { + AndroidGesturesManager initialGesturesManager, + AndroidGesturesManager internalGesturesManager) { this.mapboxMap = mapboxMap; this.moveGestureDetector = moveGestureDetector; this.internalCameraTrackingChangedListener = internalCameraTrackingChangedListener; this.onCameraMoveInvalidateListener = onCameraMoveInvalidateListener; - this.internalGesturesManager = androidGesturesManager; - this.initialGesturesManager = androidGesturesManager; + this.internalGesturesManager = internalGesturesManager; + this.initialGesturesManager = initialGesturesManager; } void initializeOptions(LocationComponentOptions options) { 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 bcd9e68509..616e86bd78 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 @@ -40,6 +40,7 @@ public class LocationCameraControllerTest { LocationComponentOptions options = mock(LocationComponentOptions.class); float moveThreshold = 5f; when(options.trackingInitialMoveThreshold()).thenReturn(moveThreshold); + when(options.trackingGesturesManagement()).thenReturn(true); camera.initializeOptions(options); camera.setCameraMode(CameraMode.TRACKING_GPS); @@ -48,14 +49,32 @@ public class LocationCameraControllerTest { } @Test + public void setCameraMode_gestureThresholdNotAdjustedWhenDisabled() { + MoveGestureDetector moveGestureDetector = mock(MoveGestureDetector.class); + LocationCameraController camera = buildCamera(moveGestureDetector); + LocationComponentOptions options = mock(LocationComponentOptions.class); + float moveThreshold = 5f; + when(options.trackingInitialMoveThreshold()).thenReturn(moveThreshold); + when(options.trackingGesturesManagement()).thenReturn(false); + camera.initializeOptions(options); + + camera.setCameraMode(CameraMode.TRACKING_GPS); + + verify(moveGestureDetector, times(0)).setMoveThreshold(moveThreshold); + verify(moveGestureDetector, times(0)).setMoveThreshold(0f); + } + + @Test public void setCameraMode_gestureThresholdIsResetWhenNotTracking() { MoveGestureDetector moveGestureDetector = mock(MoveGestureDetector.class); LocationCameraController camera = buildCamera(moveGestureDetector); - camera.initializeOptions(mock(LocationComponentOptions.class)); + LocationComponentOptions options = mock(LocationComponentOptions.class); + when(options.trackingGesturesManagement()).thenReturn(true); + camera.initializeOptions(options); camera.setCameraMode(CameraMode.NONE); - verify(moveGestureDetector).setMoveThreshold(0f); + verify(moveGestureDetector, times(2)).setMoveThreshold(0f); // one for initialization } @Test @@ -180,7 +199,9 @@ public class LocationCameraControllerTest { when(projection.toScreenLocation(any(LatLng.class))).thenReturn(pointF); when(mapboxMap.getProjection()).thenReturn(projection); LocationCameraController camera = buildCamera(mapboxMap); - camera.initializeOptions(mock(LocationComponentOptions.class)); + LocationComponentOptions options = mock(LocationComponentOptions.class); + when(options.trackingGesturesManagement()).thenReturn(true); + camera.initializeOptions(options); camera.setCameraMode(CameraMode.TRACKING); LatLng latLng = mock(LatLng.class); @@ -310,14 +331,41 @@ public class LocationCameraControllerTest { verify(mapboxMap).moveCamera(any(CameraUpdate.class)); } + @Test + public void gesturesManagement_enabled() { + MapboxMap mapboxMap = mock(MapboxMap.class); + AndroidGesturesManager initialGesturesManager = mock(AndroidGesturesManager.class); + AndroidGesturesManager internalGesturesManager = mock(AndroidGesturesManager.class); + LocationCameraController camera = buildCamera(mapboxMap, initialGesturesManager, internalGesturesManager); + LocationComponentOptions options = mock(LocationComponentOptions.class); + when(options.trackingGesturesManagement()).thenReturn(true); + camera.initializeOptions(options); + + verify(mapboxMap).setGesturesManager(internalGesturesManager, true, true); + } + + @Test + public void gesturesManagement_disabled() { + MapboxMap mapboxMap = mock(MapboxMap.class); + AndroidGesturesManager initialGesturesManager = mock(AndroidGesturesManager.class); + AndroidGesturesManager internalGesturesManager = mock(AndroidGesturesManager.class); + LocationCameraController camera = buildCamera(mapboxMap, initialGesturesManager, internalGesturesManager); + LocationComponentOptions options = mock(LocationComponentOptions.class); + when(options.trackingGesturesManagement()).thenReturn(false); + camera.initializeOptions(options); + + verify(mapboxMap).setGesturesManager(initialGesturesManager, true, true); + } + private LocationCameraController buildCamera(OnCameraTrackingChangedListener onCameraTrackingChangedListener) { MapboxMap mapboxMap = mock(MapboxMap.class); when(mapboxMap.getUiSettings()).thenReturn(mock(UiSettings.class)); MoveGestureDetector moveGestureDetector = mock(MoveGestureDetector.class); OnCameraMoveInvalidateListener onCameraMoveInvalidateListener = mock(OnCameraMoveInvalidateListener.class); - AndroidGesturesManager androidGesturesManager = mock(AndroidGesturesManager.class); + AndroidGesturesManager initialGesturesManager = mock(AndroidGesturesManager.class); + AndroidGesturesManager internalGesturesManager = mock(AndroidGesturesManager.class); return new LocationCameraController(mapboxMap, moveGestureDetector, - onCameraTrackingChangedListener, onCameraMoveInvalidateListener, androidGesturesManager); + onCameraTrackingChangedListener, onCameraMoveInvalidateListener, initialGesturesManager, internalGesturesManager); } private LocationCameraController buildCamera(MoveGestureDetector moveGestureDetector) { @@ -325,17 +373,28 @@ public class LocationCameraControllerTest { when(mapboxMap.getUiSettings()).thenReturn(mock(UiSettings.class)); OnCameraTrackingChangedListener onCameraTrackingChangedListener = mock(OnCameraTrackingChangedListener.class); OnCameraMoveInvalidateListener onCameraMoveInvalidateListener = mock(OnCameraMoveInvalidateListener.class); - AndroidGesturesManager androidGesturesManager = mock(AndroidGesturesManager.class); + AndroidGesturesManager initialGesturesManager = mock(AndroidGesturesManager.class); + AndroidGesturesManager internalGesturesManager = mock(AndroidGesturesManager.class); return new LocationCameraController(mapboxMap, moveGestureDetector, - onCameraTrackingChangedListener, onCameraMoveInvalidateListener, androidGesturesManager); + onCameraTrackingChangedListener, onCameraMoveInvalidateListener, initialGesturesManager, internalGesturesManager); } private LocationCameraController buildCamera(MapboxMap mapboxMap) { MoveGestureDetector moveGestureDetector = mock(MoveGestureDetector.class); OnCameraTrackingChangedListener onCameraTrackingChangedListener = mock(OnCameraTrackingChangedListener.class); OnCameraMoveInvalidateListener onCameraMoveInvalidateListener = mock(OnCameraMoveInvalidateListener.class); - AndroidGesturesManager androidGesturesManager = mock(AndroidGesturesManager.class); + AndroidGesturesManager initialGesturesManager = mock(AndroidGesturesManager.class); + AndroidGesturesManager internalGesturesManager = mock(AndroidGesturesManager.class); + return new LocationCameraController(mapboxMap, moveGestureDetector, + onCameraTrackingChangedListener, onCameraMoveInvalidateListener, initialGesturesManager, internalGesturesManager); + } + + private LocationCameraController buildCamera(MapboxMap mapboxMap, AndroidGesturesManager initialGesturesManager, + AndroidGesturesManager internalGesturesManager) { + MoveGestureDetector moveGestureDetector = mock(MoveGestureDetector.class); + OnCameraTrackingChangedListener onCameraTrackingChangedListener = mock(OnCameraTrackingChangedListener.class); + OnCameraMoveInvalidateListener onCameraMoveInvalidateListener = mock(OnCameraMoveInvalidateListener.class); return new LocationCameraController(mapboxMap, moveGestureDetector, - onCameraTrackingChangedListener, onCameraMoveInvalidateListener, androidGesturesManager); + onCameraTrackingChangedListener, onCameraMoveInvalidateListener, initialGesturesManager, internalGesturesManager); } } diff --git a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/location/LocationComponentTest.kt b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/location/LocationComponentTest.kt index 1d4c4af149..53054dfe0e 100644 --- a/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/location/LocationComponentTest.kt +++ b/platform/android/MapboxGLAndroidSDKTestApp/src/androidTest/java/com/mapbox/mapboxsdk/location/LocationComponentTest.kt @@ -210,6 +210,7 @@ class LocationComponentTest : BaseActivityTest() { override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap, uiController: UiController, context: Context) { component.activateLocationComponent(context, + null, LocationComponentOptions.builder(context) .staleStateTimeout(200) .enableStaleState(false) @@ -238,6 +239,7 @@ class LocationComponentTest : BaseActivityTest() { override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap, uiController: UiController, context: Context) { component.activateLocationComponent(context, + null, LocationComponentOptions.builder(context) .foregroundName("custom-foreground-bitmap") .backgroundName("custom-background-bitmap") @@ -278,6 +280,7 @@ class LocationComponentTest : BaseActivityTest() { override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap, uiController: UiController, context: Context) { component.activateLocationComponent(context, + null, LocationComponentOptions.builder(context) .foregroundName("custom-foreground-bitmap") .gpsName("custom-gps-bitmap") @@ -307,6 +310,7 @@ class LocationComponentTest : BaseActivityTest() { override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap, uiController: UiController, context: Context) { component.activateLocationComponent(context, + null, LocationComponentOptions.builder(context) .foregroundName("custom-foreground-bitmap") .gpsName("custom-gps-bitmap") @@ -338,6 +342,7 @@ class LocationComponentTest : BaseActivityTest() { uiController: UiController, context: Context) { component.activateLocationComponent(context, + null, LocationComponentOptions.builder(context) .gpsName("custom-gps-bitmap") .build()) @@ -367,6 +372,7 @@ class LocationComponentTest : BaseActivityTest() { override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap, uiController: UiController, context: Context) { component.activateLocationComponent(context, + null, LocationComponentOptions.builder(context) .staleStateTimeout(200) .build()) @@ -421,6 +427,7 @@ class LocationComponentTest : BaseActivityTest() { override fun onLocationComponentAction(component: LocationComponent, mapboxMap: MapboxMap, uiController: UiController, context: Context) { component.activateLocationComponent(context, + null, LocationComponentOptions.builder(context) .accuracyColor(color) .build()) diff --git a/platform/android/scripts/exclude-activity-gen.json b/platform/android/scripts/exclude-activity-gen.json index e4418bdc53..2a1fbec496 100644 --- a/platform/android/scripts/exclude-activity-gen.json +++ b/platform/android/scripts/exclude-activity-gen.json @@ -36,5 +36,6 @@ "TextureViewTransparentBackgroundActivity", "SimpleMapActivity", "RenderTestActivity", - "SymbolLayerActivity" + "SymbolLayerActivity", + "LocationFragmentActivity" ] |