[android] refactored exposed api on MapboxMap
fix unit tests fixup comments
This commit is contained in:
committed by
Tobrun
parent
a4b0e2f30c
commit
3b72c288ad
@@ -2052,8 +2052,9 @@ public class MapView extends FrameLayout {
|
||||
// Called when two fingers first touch the screen
|
||||
@Override
|
||||
public boolean onRotateBegin(RotateGestureDetector detector) {
|
||||
if (destroyed || !mapboxMap.getTrackingSettings().isRotateGestureCurrentlyEnabled())
|
||||
if (destroyed || !mapboxMap.getTrackingSettings().isRotateGestureCurrentlyEnabled()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
beginTime = detector.getEventTime();
|
||||
trackGestureEvent(MapboxEvent.GESTURE_ROTATION_START, detector.getFocusX(), detector.getFocusY());
|
||||
@@ -2072,10 +2073,7 @@ public class MapView extends FrameLayout {
|
||||
// Called for rotation
|
||||
@Override
|
||||
public boolean onRotate(RotateGestureDetector detector) {
|
||||
if (destroyed || !mapboxMap.getTrackingSettings().isRotateGestureCurrentlyEnabled())
|
||||
return false;
|
||||
|
||||
if (dragStarted) {
|
||||
if (destroyed || !mapboxMap.getTrackingSettings().isRotateGestureCurrentlyEnabled() || dragStarted) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -2648,14 +2646,17 @@ public class MapView extends FrameLayout {
|
||||
TrackingSettings trackingSettings = mapboxMap.getTrackingSettings();
|
||||
|
||||
// if tracking is on, and we should dismiss tracking with gestures, and this is a scroll action, turn tracking off
|
||||
if (translate && !trackingSettings.isLocationTrackingDisabled() && trackingSettings.isDismissLocationTrackingOnGesture())
|
||||
if (translate && !trackingSettings.isLocationTrackingDisabled() && trackingSettings.isDismissLocationTrackingOnGesture()) {
|
||||
resetLocationTrackingMode();
|
||||
// reset bearing tracking only on rotate
|
||||
if (rotate && !trackingSettings.isBearingTrackingDisabled() && trackingSettings.isDismissBearingTrackingOnGesture())
|
||||
}
|
||||
|
||||
// reset bearing tracking only on rotate
|
||||
if (rotate && !trackingSettings.isBearingTrackingDisabled() && trackingSettings.isDismissBearingTrackingOnGesture()) {
|
||||
resetBearingTrackingMode();
|
||||
}
|
||||
}
|
||||
|
||||
void resetTrackingModesIfRequired(CameraPosition cameraPosition ) {
|
||||
void resetTrackingModesIfRequired(CameraPosition cameraPosition) {
|
||||
resetTrackingModesIfRequired(cameraPosition.target != null, cameraPosition.bearing != -1);
|
||||
}
|
||||
|
||||
|
||||
@@ -435,6 +435,7 @@ public class MapboxMap {
|
||||
* 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
|
||||
@@ -460,18 +461,18 @@ public class MapboxMap {
|
||||
public final void easeCamera(
|
||||
CameraUpdate update, int durationMs, boolean easingInterpolator, final MapboxMap.CancelableCallback callback) {
|
||||
// dismiss tracking, moving camera is equal to a gesture
|
||||
CameraPosition cameraPosition = update.getCameraPosition(this);
|
||||
mapView.resetTrackingModesIfRequired(cameraPosition);
|
||||
easeCameraInternal(cameraPosition, durationMs, easingInterpolator, callback);
|
||||
easeCamera(update, durationMs, easingInterpolator, true, callback);
|
||||
}
|
||||
|
||||
/**
|
||||
* Internal use only.
|
||||
* Used by tracking actions.
|
||||
*/
|
||||
@UiThread
|
||||
public final void easeCameraInternal(
|
||||
CameraPosition cameraPosition, int durationMs, boolean easingInterpolator, final MapboxMap.CancelableCallback callback) {
|
||||
public final void easeCamera(
|
||||
CameraUpdate update, int durationMs, boolean easingInterpolator, boolean resetTrackingMode, final MapboxMap.CancelableCallback callback) {
|
||||
// dismiss tracking, moving camera is equal to a gesture
|
||||
cameraPosition = update.getCameraPosition(this);
|
||||
if (resetTrackingMode) {
|
||||
mapView.resetTrackingModesIfRequired(cameraPosition);
|
||||
}
|
||||
|
||||
mapView.easeTo(cameraPosition.bearing, cameraPosition.target, getDurationNano(durationMs), cameraPosition.tilt,
|
||||
cameraPosition.zoom, easingInterpolator, new CancelableCallback() {
|
||||
@Override
|
||||
|
||||
@@ -181,7 +181,7 @@ public class TrackingSettings {
|
||||
}
|
||||
|
||||
/**
|
||||
* Is bearing tracking disabled?
|
||||
* Returns if bearing tracking disabled
|
||||
*
|
||||
* @return True if bearing tracking is disabled.
|
||||
*/
|
||||
@@ -190,26 +190,23 @@ public class TrackingSettings {
|
||||
}
|
||||
|
||||
/**
|
||||
* Is the map currently in a state where rotate gestures are recognised?
|
||||
* This requires both that the user interface has such gestures enabled,
|
||||
* and that they are not currently blocked by a bearing tracking mode.
|
||||
* Returns if rotate gesture are currently enabled.
|
||||
*
|
||||
* @return True if rotate gestures are currently enabled.
|
||||
*/
|
||||
|
||||
public boolean isRotateGestureCurrentlyEnabled() {
|
||||
// rotate gestures are recognised if:
|
||||
// The user settings are enabled AND;
|
||||
// EITHER bearing tracking is dismissed on gesture OR there is no bearing tracking
|
||||
|
||||
return uiSettings.isRotateGesturesEnabled() &&
|
||||
(dismissBearingTrackingOnGesture || myBearingTrackingMode == MyBearingTracking.NONE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Is the map currently in a state where scroll gestures are recognised?
|
||||
* This requires both that the user interface has such gestures enabled,
|
||||
* and that they are not currently blocked by a location tracking mode.
|
||||
* Returns if scroll gesture are currently enabled.
|
||||
*
|
||||
* @return True if scroll gestures are currently enabled.
|
||||
*/
|
||||
|
||||
public boolean isScrollGestureCurrentlyEnabled() {
|
||||
return uiSettings.isScrollGesturesEnabled() &&
|
||||
(dismissLocationTrackingOnGesture || myLocationTrackingMode == MyLocationTracking.TRACKING_NONE);
|
||||
|
||||
@@ -464,7 +464,7 @@ public class MyLocationView extends View {
|
||||
if (myLocationTrackingMode == MyLocationTracking.TRACKING_FOLLOW && location != null) {
|
||||
// center map directly if we have a location fix
|
||||
myLocationBehavior.updateLatLng(location);
|
||||
mapboxMap.easeCameraInternal(CameraUpdateFactory.newLatLng(new LatLng(location)).getCameraPosition(mapboxMap), 0, false, null);
|
||||
mapboxMap.easeCamera(CameraUpdateFactory.newLatLng(new LatLng(location)), 0, false /*linear interpolator*/, false /*do not disable tracking*/, null);
|
||||
}
|
||||
this.myLocationTrackingMode = myLocationTrackingMode;
|
||||
invalidate();
|
||||
@@ -586,7 +586,7 @@ public class MyLocationView extends View {
|
||||
private void rotateCamera() {
|
||||
CameraPosition.Builder builder = new CameraPosition.Builder();
|
||||
builder.bearing(currentDegree);
|
||||
mapboxMap.easeCameraInternal(CameraUpdateFactory.newCameraPosition(builder.build()).getCameraPosition(mapboxMap), COMPASS_UPDATE_RATE_MS, false /*linear interpolator*/, null);
|
||||
mapboxMap.easeCamera(CameraUpdateFactory.newCameraPosition(builder.build()), COMPASS_UPDATE_RATE_MS, false /*linear interpolator*/, false /*do not disable tracking*/, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -702,7 +702,7 @@ public class MyLocationView extends View {
|
||||
updateAccuracy(location);
|
||||
|
||||
// ease to new camera position with a linear interpolator
|
||||
mapboxMap.easeCameraInternal(CameraUpdateFactory.newCameraPosition(builder.build()).getCameraPosition(mapboxMap), (int) locationUpdateDuration, false /*linear interpolator*/, null);
|
||||
mapboxMap.easeCamera(CameraUpdateFactory.newCameraPosition(builder.build()), (int) locationUpdateDuration, false /*linear interpolator*/, false /*do not disable tracking*/, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -765,8 +765,9 @@ public class MyLocationView extends View {
|
||||
|
||||
@Override
|
||||
void invalidate() {
|
||||
if(latLng != null)
|
||||
if (latLng != null) {
|
||||
screenLocation = projection.toScreenLocation(latLng);
|
||||
}
|
||||
MyLocationView.this.invalidate();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user