Skip to content
This repository has been archived by the owner on Jun 21, 2023. It is now read-only.

Commit

Permalink
Not changing location camera mode while disabled. (#440)
Browse files Browse the repository at this point in the history
* Not changing location camera mode while disabled.

* Make LocationCameraController cache enable state
  • Loading branch information
Kevin Li authored Jul 16, 2020
1 parent e443fe9 commit 2175252
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ final class LocationCameraController {

private boolean isTransitioning;
private LatLng lastLocation;
private boolean isEnabled;

LocationCameraController(
Context context,
Expand Down Expand Up @@ -133,7 +134,7 @@ private void transitionToCurrentLocation(boolean wasTracking, Location lastLocat
long transitionDuration,
Double zoom, Double bearing, Double tilt,
final OnLocationCameraTransitionListener internalTransitionListener) {
if (!wasTracking && isLocationTracking() && lastLocation != null) {
if (!wasTracking && isLocationTracking() && lastLocation != null && isEnabled) {
isTransitioning = true;
LatLng target = new LatLng(lastLocation);

Expand Down Expand Up @@ -320,6 +321,10 @@ boolean isConsumingCompass() {
|| cameraMode == CameraMode.NONE_COMPASS;
}

void setEnabled(boolean enabled) {
isEnabled = enabled;
}

private boolean isLocationTracking() {
return cameraMode == CameraMode.TRACKING
|| cameraMode == CameraMode.TRACKING_COMPASS
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -518,6 +518,7 @@ public void setLocationComponentEnabled(boolean isEnabled) {
} else {
disableLocationComponent();
}
locationCameraController.setEnabled(isEnabled);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public void setCameraMode_mapTransitionsAreCancelled() {
MapboxMap mapboxMap = mock(MapboxMap.class);
LocationCameraController camera = buildCamera(mapboxMap);
camera.initializeOptions(mock(LocationComponentOptions.class));

camera.setEnabled(true);
camera.setCameraMode(TRACKING_GPS);

verify(mapboxMap).cancelTransitions();
Expand Down Expand Up @@ -1142,6 +1142,32 @@ public void transition_customAnimation() {
.animateCamera(eq(mapboxMap), eq(cameraUpdate), eq(1200), any(MapboxMap.CancelableCallback.class));
}

@Test
public void transition_customAnimationDisabled() {
MapboxMap mapboxMap = mock(MapboxMap.class);
Transform transform = mock(Transform.class);
when(mapboxMap.getCameraPosition()).thenReturn(CameraPosition.DEFAULT);
Projection projection = mock(Projection.class);
when(mapboxMap.getProjection()).thenReturn(projection);
when(projection.getMetersPerPixelAtLatitude(any(Double.class))).thenReturn(Double.valueOf(1000));
LocationCameraController camera = buildCamera(mapboxMap, transform);
camera.initializeOptions(mock(LocationComponentOptions.class));
Location location = mock(Location.class);
CameraUpdate cameraUpdate = CameraUpdateFactory.newCameraPosition(
new CameraPosition.Builder()
.target(new LatLng(location))
.zoom(14.0)
.bearing(13.0)
.tilt(45.0)
.build()
);

camera.setEnabled(false);
camera.setCameraMode(TRACKING, location, 1200, 14.0, 13.0, 45.0, null);
verify(transform, times(0))
.animateCamera(eq(mapboxMap), eq(cameraUpdate), eq(1200), any(MapboxMap.CancelableCallback.class));
}

private LocationCameraController buildCamera(OnCameraTrackingChangedListener onCameraTrackingChangedListener) {
MapboxMap mapboxMap = mock(MapboxMap.class);
when(mapboxMap.getUiSettings()).thenReturn(mock(UiSettings.class));
Expand Down Expand Up @@ -1206,8 +1232,11 @@ private LocationCameraController buildCamera(MapboxMap mapboxMap, Transform tran
OnCameraMoveInvalidateListener onCameraMoveInvalidateListener = mock(OnCameraMoveInvalidateListener.class);
AndroidGesturesManager initialGesturesManager = mock(AndroidGesturesManager.class);
AndroidGesturesManager internalGesturesManager = mock(AndroidGesturesManager.class);
return new LocationCameraController(mapboxMap, transform, moveGestureDetector,
LocationCameraController locationCameraController =
new LocationCameraController(mapboxMap, transform, moveGestureDetector,
onCameraTrackingChangedListener, onCameraMoveInvalidateListener, initialGesturesManager, internalGesturesManager);
locationCameraController.setEnabled(true);
return locationCameraController;
}

private LocationCameraController buildCamera(MapboxMap mapboxMap, AndroidGesturesManager initialGesturesManager,
Expand Down

0 comments on commit 2175252

Please sign in to comment.