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

Commit

Permalink
[android] - post resetting invalidation flag to avoid race condition (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
tobrun authored Apr 18, 2017
1 parent 8e9eaaa commit 589d71d
Showing 1 changed file with 24 additions and 18 deletions.
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

0 comments on commit 589d71d

Please sign in to comment.