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

Commit

Permalink
[android] - option to disable camera animation while following positi…
Browse files Browse the repository at this point in the history
…on (#9210)
  • Loading branch information
LukasPaczos authored and tobrun committed Jun 7, 2017
1 parent ae837f4 commit 78eca86
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 4 deletions.
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

0 comments on commit 78eca86

Please sign in to comment.