[android] - option to disable camera animation while following position (#9210)
This commit is contained in:
@@ -133,5 +133,6 @@ public class MapboxConstants {
|
||||
public static final String STATE_ATTRIBUTION_MARGIN_RIGHT = "mapbox_attrMarginRight";
|
||||
public static final String STATE_ATTRIBUTION_MARGIN_BOTTOM = "mapbox_atrrMarginBottom";
|
||||
public static final String STATE_ATTRIBUTION_ENABLED = "mapbox_atrrEnabled";
|
||||
public static final String STATE_LOCATION_CHANGE_ANIMATION_ENABLED = "mapbox_locationChangeAnimationEnabled";
|
||||
|
||||
}
|
||||
|
||||
@@ -29,6 +29,7 @@ public final class TrackingSettings {
|
||||
private final CameraZoomInvalidator zoomInvalidator;
|
||||
private LocationEngine locationSource;
|
||||
private LocationEngineListener myLocationListener;
|
||||
private boolean locationChangeAnimationEnabled = true;
|
||||
|
||||
private boolean myLocationEnabled;
|
||||
private boolean dismissLocationTrackingOnGesture = true;
|
||||
@@ -56,6 +57,7 @@ public final class TrackingSettings {
|
||||
outState.putBoolean(MapboxConstants.STATE_MY_LOCATION_TRACKING_DISMISS, isDismissLocationTrackingOnGesture());
|
||||
outState.putBoolean(MapboxConstants.STATE_MY_BEARING_TRACKING_DISMISS, isDismissBearingTrackingOnGesture());
|
||||
outState.putBoolean(MapboxConstants.STATE_MY_LOCATION_ENABLED, isMyLocationEnabled());
|
||||
outState.putBoolean(MapboxConstants.STATE_LOCATION_CHANGE_ANIMATION_ENABLED, isLocationChangeAnimationEnabled());
|
||||
}
|
||||
|
||||
void onRestoreInstanceState(Bundle savedInstanceState) {
|
||||
@@ -74,6 +76,8 @@ public final class TrackingSettings {
|
||||
MapboxConstants.STATE_MY_LOCATION_TRACKING_DISMISS, true));
|
||||
setDismissBearingTrackingOnGesture(savedInstanceState.getBoolean(
|
||||
MapboxConstants.STATE_MY_BEARING_TRACKING_DISMISS, true));
|
||||
setLocationChangeAnimationEnabled(savedInstanceState.getBoolean(
|
||||
MapboxConstants.STATE_LOCATION_CHANGE_ANIMATION_ENABLED, true));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -91,6 +95,7 @@ public final class TrackingSettings {
|
||||
*/
|
||||
@UiThread
|
||||
public void setMyLocationTrackingMode(@MyLocationTracking.Mode int myLocationTrackingMode) {
|
||||
myLocationView.setLocationChangeAnimationEnabled(isLocationChangeAnimationEnabled());
|
||||
myLocationView.setMyLocationTrackingMode(myLocationTrackingMode);
|
||||
|
||||
if (myLocationTrackingMode == MyLocationTracking.TRACKING_FOLLOW) {
|
||||
@@ -253,6 +258,26 @@ public final class TrackingSettings {
|
||||
|| myLocationView.getMyLocationTrackingMode() == MyLocationTracking.TRACKING_NONE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether location change animation is applied for {@link MyLocationTracking#TRACKING_FOLLOW}.
|
||||
*
|
||||
* @return True if animation is applied, false otherwise.
|
||||
*/
|
||||
public boolean isLocationChangeAnimationEnabled() {
|
||||
return locationChangeAnimationEnabled;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set whether location change animation should be applied for {@link MyLocationTracking#TRACKING_FOLLOW}.
|
||||
*
|
||||
* @param locationChangeAnimationEnabled True if animation should be applied, false otherwise.
|
||||
*/
|
||||
public void setLocationChangeAnimationEnabled(boolean locationChangeAnimationEnabled) {
|
||||
this.locationChangeAnimationEnabled = locationChangeAnimationEnabled;
|
||||
|
||||
myLocationView.setLocationChangeAnimationEnabled(locationChangeAnimationEnabled);
|
||||
}
|
||||
|
||||
/**
|
||||
* Reset the tracking modes as necessary. Location tracking is reset if the map center is changed and not from
|
||||
* location, bearing tracking if there is a rotation.
|
||||
|
||||
@@ -68,6 +68,7 @@ public class MyLocationView extends View {
|
||||
private ValueAnimator locationChangeAnimator;
|
||||
private ValueAnimator accuracyAnimator;
|
||||
private ValueAnimator directionAnimator;
|
||||
private boolean locationChangeAnimationEnabled;
|
||||
|
||||
private ValueAnimator.AnimatorUpdateListener invalidateSelfOnUpdateListener =
|
||||
new ValueAnimator.AnimatorUpdateListener() {
|
||||
@@ -462,6 +463,10 @@ public class MyLocationView extends View {
|
||||
myLocationBehavior.updateLatLng(location);
|
||||
}
|
||||
|
||||
public void setLocationChangeAnimationEnabled(boolean locationChangeAnimationEnabled) {
|
||||
this.locationChangeAnimationEnabled = locationChangeAnimationEnabled;
|
||||
}
|
||||
|
||||
public void setMyBearingTrackingMode(@MyBearingTracking.Mode int myBearingTrackingMode) {
|
||||
this.myBearingTrackingMode = myBearingTrackingMode;
|
||||
if (myBearingTrackingMode == MyBearingTracking.COMPASS && compassListener.isSensorAvailable()) {
|
||||
@@ -773,9 +778,14 @@ public class MyLocationView extends View {
|
||||
// accuracy
|
||||
updateAccuracy(location);
|
||||
|
||||
// ease to new camera position with a linear interpolator
|
||||
mapboxMap.easeCamera(CameraUpdateFactory.newCameraPosition(builder.build()), animationDuration, false, null,
|
||||
true);
|
||||
if (locationChangeAnimationEnabled) {
|
||||
// ease to new camera position with a linear interpolator
|
||||
mapboxMap.easeCamera(CameraUpdateFactory.newCameraPosition(builder.build()), animationDuration, false, null,
|
||||
true);
|
||||
} else {
|
||||
mapboxMap.easeCamera(CameraUpdateFactory.newCameraPosition(builder.build()), 0, false, null,
|
||||
true);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -817,7 +827,11 @@ public class MyLocationView extends View {
|
||||
}
|
||||
|
||||
locationChangeAnimator = ValueAnimator.ofFloat(0.0f, 1.0f);
|
||||
locationChangeAnimator.setDuration(locationUpdateDuration);
|
||||
if (locationChangeAnimationEnabled) {
|
||||
locationChangeAnimator.setDuration(locationUpdateDuration);
|
||||
} else {
|
||||
locationChangeAnimator.setDuration(0);
|
||||
}
|
||||
locationChangeAnimator.addUpdateListener(new MarkerCoordinateAnimatorListener(this,
|
||||
latLng, newLocation
|
||||
));
|
||||
|
||||
Reference in New Issue
Block a user