[android] - Config dismissing tracking modes with camera change (#7871)
* [android] - allow fine grained control over dismissing tracking modes while animating the camera position * update MyLocationView
This commit is contained in:
@@ -35,6 +35,7 @@ Mapbox welcomes participation and contributions from everyone. If you'd like to
|
||||
* Gesture handling bugs
|
||||
- Avoid calls to onFling when while pinch zooming [#7666](https://github.com/mapbox/mapbox-gl-native/issues/7666)
|
||||
* Support for style-wide transition animation duration and delay [#6779](https://github.com/mapbox/mapbox-gl-native/issues/6779)
|
||||
* Support for all animated camera changes to configure dismissing tracking modes [#7854](https://github.com/mapbox/mapbox-gl-native/issues/7854)
|
||||
|
||||
## 4.2.2 - January 27, 2017
|
||||
|
||||
|
||||
@@ -121,6 +121,7 @@ public class MapboxConstants {
|
||||
public static final String STATE_MY_BEARING_TRACKING_MODE = "myBearingTracking";
|
||||
public static final String STATE_MY_LOCATION_TRACKING_DISMISS = "myLocationTrackingDismiss";
|
||||
public static final String STATE_MY_BEARING_TRACKING_DISMISS = "myBearingTrackingDismiss";
|
||||
public static final String STATE_MY_TRACKING_MODE_DISMISS_FOR_CAMERA = "myBearingTrackingDismiss";
|
||||
public static final String STATE_COMPASS_ENABLED = "compassEnabled";
|
||||
public static final String STATE_COMPASS_GRAVITY = "compassGravity";
|
||||
public static final String STATE_COMPASS_MARGIN_LEFT = "compassMarginLeft";
|
||||
|
||||
@@ -615,7 +615,9 @@ public final class MapboxMap {
|
||||
* easing the camera stops. If {@link #getCameraPosition()} is called during the animation, it
|
||||
* will return the current location of the camera in flight.
|
||||
* <p>
|
||||
* Note that this will cancel location tracking mode if enabled.
|
||||
* Note that this will cancel location tracking mode if enabled. You can change this behaviour by calling
|
||||
* {@link TrackingSettings#setDismissTrackingModeForCameraPositionChange(boolean)} with false before invoking this
|
||||
* method and calling it with true in the {@link CancelableCallback#onFinish()}.
|
||||
* </p>
|
||||
*
|
||||
* @param update The change that should be applied to the camera.
|
||||
@@ -629,39 +631,12 @@ public final class MapboxMap {
|
||||
* Do not update or ease the camera from within onCancel().
|
||||
*/
|
||||
@UiThread
|
||||
public final void easeCamera(
|
||||
CameraUpdate update, int durationMs, boolean easingInterpolator, final MapboxMap.CancelableCallback callback) {
|
||||
// dismiss tracking, moving camera is equal to a gesture
|
||||
easeCamera(update, durationMs, easingInterpolator, true, callback);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gradually move the camera by a specified duration in milliseconds, zoom will not be affected
|
||||
* unless specified within {@link CameraUpdate}. A callback can be used to be notified when
|
||||
* easing the camera stops. If {@link #getCameraPosition()} is called during the animation, it
|
||||
* will return the current location of the camera in flight.
|
||||
* <p>
|
||||
* Note that this will cancel location tracking mode if enabled.
|
||||
* </p>
|
||||
*
|
||||
* @param update The change that should be applied to the camera.
|
||||
* @param durationMs The duration of the animation in milliseconds. This must be strictly
|
||||
* positive, otherwise an IllegalArgumentException will be thrown.
|
||||
* @param resetTrackingMode True to reset tracking modes if required, false to ignore
|
||||
* @param easingInterpolator True for easing interpolator, false for linear.
|
||||
* @param callback An optional callback to be notified from the main thread when the animation
|
||||
* stops. If the animation stops due to its natural completion, the callback
|
||||
* will be notified with onFinish(). If the animation stops due to interruption
|
||||
* by a later camera movement or a user gesture, onCancel() will be called.
|
||||
* Do not update or ease the camera from within onCancel().
|
||||
*/
|
||||
@UiThread
|
||||
public final void easeCamera(final CameraUpdate update, final int durationMs, final boolean easingInterpolator,
|
||||
final boolean resetTrackingMode, final MapboxMap.CancelableCallback callback) {
|
||||
final MapboxMap.CancelableCallback callback) {
|
||||
new Handler().post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
transform.easeCamera(MapboxMap.this, update, durationMs, easingInterpolator, resetTrackingMode, callback);
|
||||
transform.easeCamera(MapboxMap.this, update, durationMs, easingInterpolator, callback);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -33,6 +33,7 @@ public final class TrackingSettings {
|
||||
private boolean myLocationEnabled;
|
||||
private boolean dismissLocationTrackingOnGesture = true;
|
||||
private boolean dismissBearingTrackingOnGesture = true;
|
||||
private boolean isResetTrackingWithCameraPositionChange = true;
|
||||
|
||||
private MapboxMap.OnMyLocationTrackingModeChangeListener onMyLocationTrackingModeChangeListener;
|
||||
private MapboxMap.OnMyBearingTrackingModeChangeListener onMyBearingTrackingModeChangeListener;
|
||||
@@ -55,6 +56,8 @@ 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_MY_TRACKING_MODE_DISMISS_FOR_CAMERA,
|
||||
isDismissTrackingModesForCameraPositionChange());
|
||||
}
|
||||
|
||||
void onRestoreInstanceState(Bundle savedInstanceState) {
|
||||
@@ -73,6 +76,8 @@ public final class TrackingSettings {
|
||||
MapboxConstants.STATE_MY_LOCATION_TRACKING_DISMISS, true));
|
||||
setDismissBearingTrackingOnGesture(savedInstanceState.getBoolean(
|
||||
MapboxConstants.STATE_MY_BEARING_TRACKING_DISMISS, true));
|
||||
setDismissTrackingModeForCameraPositionChange(savedInstanceState.getBoolean(
|
||||
MapboxConstants.STATE_MY_TRACKING_MODE_DISMISS_FOR_CAMERA, true));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -271,8 +276,39 @@ public final class TrackingSettings {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Reset the tracking modes as necessary. Animated camera position changes can reset the underlying tracking modes.
|
||||
*
|
||||
* @param cameraPosition the changed camera position
|
||||
*/
|
||||
void resetTrackingModesIfRequired(CameraPosition cameraPosition) {
|
||||
resetTrackingModesIfRequired(cameraPosition.target != null, cameraPosition.bearing != -1);
|
||||
if (isDismissTrackingModesForCameraPositionChange()) {
|
||||
resetTrackingModesIfRequired(cameraPosition.target != null, cameraPosition.bearing != -1);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns if a animation allows to dismiss a tracking mode.
|
||||
* <p>
|
||||
* By default this is set to true.
|
||||
* </p>
|
||||
*
|
||||
* @return True if camera animations will allow to dismiss a tracking mode
|
||||
*/
|
||||
public boolean isDismissTrackingModesForCameraPositionChange() {
|
||||
return isResetTrackingWithCameraPositionChange;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a flag to allow animated camera position changes to dismiss a tracking mode.
|
||||
* <p>
|
||||
* <p>
|
||||
* </p>
|
||||
*
|
||||
* @param willAllowToDismiss True will allow animated camera changes dismiss a trackig mode
|
||||
*/
|
||||
public void setDismissTrackingModeForCameraPositionChange(boolean willAllowToDismiss) {
|
||||
isResetTrackingWithCameraPositionChange = willAllowToDismiss;
|
||||
}
|
||||
|
||||
Location getMyLocation() {
|
||||
|
||||
@@ -95,11 +95,9 @@ final class Transform implements MapView.OnMapChangedListener {
|
||||
|
||||
@UiThread
|
||||
final void easeCamera(MapboxMap mapboxMap, CameraUpdate update, int durationMs, boolean easingInterpolator,
|
||||
boolean resetTrackingMode, final MapboxMap.CancelableCallback callback) {
|
||||
final MapboxMap.CancelableCallback callback) {
|
||||
cameraPosition = update.getCameraPosition(mapboxMap);
|
||||
if (resetTrackingMode) {
|
||||
trackingSettings.resetTrackingModesIfRequired(cameraPosition);
|
||||
}
|
||||
trackingSettings.resetTrackingModesIfRequired(cameraPosition);
|
||||
|
||||
cancelTransitions();
|
||||
if (callback != null) {
|
||||
|
||||
@@ -478,8 +478,19 @@ public class MyLocationView extends View {
|
||||
if (location != null) {
|
||||
if (myLocationTrackingMode == MyLocationTracking.TRACKING_FOLLOW) {
|
||||
// center map directly
|
||||
mapboxMap.getTrackingSettings().setDismissTrackingModeForCameraPositionChange(false);
|
||||
mapboxMap.easeCamera(CameraUpdateFactory.newLatLng(new LatLng(location)), 0, false /*linear interpolator*/,
|
||||
false /*do not disable tracking*/, null);
|
||||
new MapboxMap.CancelableCallback() {
|
||||
@Override
|
||||
public void onCancel() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFinish() {
|
||||
mapboxMap.getTrackingSettings().setDismissTrackingModeForCameraPositionChange(true);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
// do not use interpolated location from tracking mode
|
||||
latLng = null;
|
||||
@@ -624,8 +635,19 @@ public class MyLocationView extends View {
|
||||
private void rotateCamera(float rotation) {
|
||||
CameraPosition.Builder builder = new CameraPosition.Builder();
|
||||
builder.bearing(rotation);
|
||||
mapboxMap.getTrackingSettings().setDismissTrackingModeForCameraPositionChange(false);
|
||||
mapboxMap.easeCamera(CameraUpdateFactory.newCameraPosition(builder.build()), COMPASS_UPDATE_RATE_MS,
|
||||
false /*linear interpolator*/, false /*do not disable tracking*/, null);
|
||||
false /*linear interpolator*/, new MapboxMap.CancelableCallback() {
|
||||
@Override
|
||||
public void onCancel() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFinish() {
|
||||
mapboxMap.getTrackingSettings().setDismissTrackingModeForCameraPositionChange(true);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -739,9 +761,20 @@ public class MyLocationView extends View {
|
||||
// accuracy
|
||||
updateAccuracy(location);
|
||||
|
||||
mapboxMap.getTrackingSettings().setDismissTrackingModeForCameraPositionChange(false);
|
||||
// ease to new camera position with a linear interpolator
|
||||
mapboxMap.easeCamera(CameraUpdateFactory.newCameraPosition(builder.build()), (int) animationDuration,
|
||||
false /*linear interpolator*/, false /*do not disable tracking*/, null);
|
||||
false /*linear interpolator*/, new MapboxMap.CancelableCallback() {
|
||||
@Override
|
||||
public void onCancel() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFinish() {
|
||||
mapboxMap.getTrackingSettings().setDismissTrackingModeForCameraPositionChange(true);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user