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

[android] feature - option to disable location change animation #9210

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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";

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -56,6 +57,7 @@ void onSaveInstanceState(Bundle outState) {
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) {
Expand All @@ -74,6 +76,8 @@ void onRestoreInstanceState(Bundle savedInstanceState) {
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));
}

/**
Expand All @@ -91,6 +95,7 @@ void onRestoreInstanceState(Bundle savedInstanceState) {
*/
@UiThread
public void setMyLocationTrackingMode(@MyLocationTracking.Mode int myLocationTrackingMode) {
myLocationView.setLocationChangeAnimationEnabled(isLocationChangeAnimationEnabled());
myLocationView.setMyLocationTrackingMode(myLocationTrackingMode);

if (myLocationTrackingMode == MyLocationTracking.TRACKING_FOLLOW) {
Expand Down Expand Up @@ -253,6 +258,26 @@ public boolean isScrollGestureCurrentlyEnabled() {
|| 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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -462,6 +463,10 @@ public void setLocation(Location location) {
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()) {
Expand Down Expand Up @@ -773,9 +778,14 @@ void updateLatLng(@NonNull Location location) {
// 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
Expand Down Expand Up @@ -817,7 +827,11 @@ void updateLatLng(@NonNull final Location location) {
}

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
));
Expand Down