Skip to content
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 @@ -689,7 +689,7 @@ public void remove(boolean priority, Marker m) {
*/
public void animate(MarkerWithPosition marker, LatLng from, LatLng to) {
lock.lock();
AnimationTask task = new AnimationTask(marker, from, to);
AnimationTask task = new AnimationTask(marker, from, to, lock);

for (AnimationTask existingTask : ongoingAnimations) {
if (existingTask.marker.getId().equals(task.marker.getId())) {
Expand All @@ -713,7 +713,7 @@ public void animate(MarkerWithPosition marker, LatLng from, LatLng to) {
*/
public void animateThenRemove(MarkerWithPosition marker, LatLng from, LatLng to) {
lock.lock();
AnimationTask animationTask = new AnimationTask(marker, from, to);
AnimationTask animationTask = new AnimationTask(marker, from, to, lock);
for (AnimationTask existingTask : ongoingAnimations) {
if (existingTask.marker.getId().equals(animationTask.marker.getId())) {
existingTask.cancel();
Expand Down Expand Up @@ -1188,11 +1188,14 @@ private class AnimationTask extends AnimatorListenerAdapter implements ValueAnim
private MarkerManager mMarkerManager;
private ValueAnimator valueAnimator;

private AnimationTask(MarkerWithPosition markerWithPosition, LatLng from, LatLng to) {
private final Lock lock;

private AnimationTask(MarkerWithPosition markerWithPosition, LatLng from, LatLng to, Lock lock) {
this.markerWithPosition = markerWithPosition;
this.marker = markerWithPosition.marker;
this.from = from;
this.to = to;
this.lock = lock;
}

public void perform() {
Expand All @@ -1209,10 +1212,15 @@ public void cancel() {
new Handler(Looper.getMainLooper()).post(this::cancel);
return;
}
markerWithPosition.position = to;
mRemoveOnComplete = false;
valueAnimator.cancel();
ongoingAnimations.remove(this);
try {
markerWithPosition.position = to;
mRemoveOnComplete = false;
valueAnimator.cancel();
lock.lock();
ongoingAnimations.remove(this);
} finally {
lock.unlock();
}
}

@Override
Expand All @@ -1225,7 +1233,9 @@ public void onAnimationEnd(Animator animation) {
markerWithPosition.position = to;

// Remove the task from the queue
lock.lock();
ongoingAnimations.remove(this);
lock.unlock();
}

public void removeOnAnimationComplete(MarkerManager markerManager) {
Expand Down