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

Post resetting tracking settings flag to avoid race condition #8738

Merged
merged 1 commit into from
Apr 18, 2017
Merged
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 @@ -321,7 +321,7 @@ public void setBearing(double bearing) {
setCompass(location.getBearing() - bearing);
}
} else if (myBearingTrackingMode == MyBearingTracking.COMPASS
&& compassListener.isSensorAvailable()) {
&& compassListener.isSensorAvailable()) {
setCompass(magneticHeading - bearing);
}
}
Expand All @@ -336,7 +336,7 @@ public void setCameraPosition(CameraPosition position) {

public void onStart() {
if (myBearingTrackingMode == MyBearingTracking.COMPASS
&& compassListener.isSensorAvailable()) {
&& compassListener.isSensorAvailable()) {
compassListener.onResume();
}
if (isEnabled()) {
Expand Down Expand Up @@ -461,7 +461,7 @@ public void setLocation(Location location) {
public void setMyBearingTrackingMode(@MyBearingTracking.Mode int myBearingTrackingMode) {
this.myBearingTrackingMode = myBearingTrackingMode;
if (myBearingTrackingMode == MyBearingTracking.COMPASS
&& compassListener.isSensorAvailable()) {
&& compassListener.isSensorAvailable()) {
compassListener.onResume();
} else {
compassListener.onPause();
Expand Down Expand Up @@ -741,7 +741,7 @@ void updateAccuracy(@NonNull Location location) {
abstract void invalidate();
}

private class MyLocationTrackingBehavior extends MyLocationBehavior {
private class MyLocationTrackingBehavior extends MyLocationBehavior implements MapboxMap.CancelableCallback {

@Override
void updateLatLng(@NonNull Location location) {
Expand All @@ -757,11 +757,11 @@ void updateLatLng(@NonNull Location location) {
locationUpdateTimestamp = SystemClock.elapsedRealtime();

// calculate animation duration
float animationDuration;
int animationDuration;
if (previousUpdateTimeStamp == 0) {
animationDuration = 0;
} else {
animationDuration = (locationUpdateTimestamp - previousUpdateTimeStamp) * 1.1f
animationDuration = (int) ((locationUpdateTimestamp - previousUpdateTimeStamp) * 1.1f)
/*make animation slightly longer*/;
}

Expand All @@ -780,20 +780,10 @@ void updateLatLng(@NonNull Location location) {
// accuracy
updateAccuracy(location);

// disable dismiss of tracking settings, enabled in #onFinish
mapboxMap.getTrackingSettings().setDismissTrackingModeForCameraPositionChange(false);
// ease to new camera position with a linear interpolator
mapboxMap.easeCamera(CameraUpdateFactory.newCameraPosition(builder.build()), (int) animationDuration,
false /*linear interpolator*/, new MapboxMap.CancelableCallback() {
@Override
public void onCancel() {

}

@Override
public void onFinish() {
mapboxMap.getTrackingSettings().setDismissTrackingModeForCameraPositionChange(true);
}
});
mapboxMap.easeCamera(CameraUpdateFactory.newCameraPosition(builder.build()), animationDuration, false, this);
}

@Override
Expand All @@ -804,6 +794,22 @@ void invalidate() {
screenLocation = new PointF(x, y);
MyLocationView.this.invalidate();
}

@Override
public void onCancel() {
//no op
}

@Override
public void onFinish() {
// Posting to end message queue to avoid race condition #8560
post(new Runnable() {
@Override
public void run() {
mapboxMap.getTrackingSettings().setDismissTrackingModeForCameraPositionChange(true);
}
});
}
}

private class MyLocationShowBehavior extends MyLocationBehavior {
Expand Down