@@ -689,7 +689,7 @@ public void remove(boolean priority, Marker m) {
689689 */
690690 public void animate (MarkerWithPosition marker , LatLng from , LatLng to ) {
691691 lock .lock ();
692- AnimationTask task = new AnimationTask (marker , from , to );
692+ AnimationTask task = new AnimationTask (marker , from , to , lock );
693693
694694 for (AnimationTask existingTask : ongoingAnimations ) {
695695 if (existingTask .marker .getId ().equals (task .marker .getId ())) {
@@ -713,7 +713,7 @@ public void animate(MarkerWithPosition marker, LatLng from, LatLng to) {
713713 */
714714 public void animateThenRemove (MarkerWithPosition marker , LatLng from , LatLng to ) {
715715 lock .lock ();
716- AnimationTask animationTask = new AnimationTask (marker , from , to );
716+ AnimationTask animationTask = new AnimationTask (marker , from , to , lock );
717717 for (AnimationTask existingTask : ongoingAnimations ) {
718718 if (existingTask .marker .getId ().equals (animationTask .marker .getId ())) {
719719 existingTask .cancel ();
@@ -1188,11 +1188,14 @@ private class AnimationTask extends AnimatorListenerAdapter implements ValueAnim
11881188 private MarkerManager mMarkerManager ;
11891189 private ValueAnimator valueAnimator ;
11901190
1191- private AnimationTask (MarkerWithPosition markerWithPosition , LatLng from , LatLng to ) {
1191+ private final Lock lock ;
1192+
1193+ private AnimationTask (MarkerWithPosition markerWithPosition , LatLng from , LatLng to , Lock lock ) {
11921194 this .markerWithPosition = markerWithPosition ;
11931195 this .marker = markerWithPosition .marker ;
11941196 this .from = from ;
11951197 this .to = to ;
1198+ this .lock = lock ;
11961199 }
11971200
11981201 public void perform () {
@@ -1209,10 +1212,15 @@ public void cancel() {
12091212 new Handler (Looper .getMainLooper ()).post (this ::cancel );
12101213 return ;
12111214 }
1212- markerWithPosition .position = to ;
1213- mRemoveOnComplete = false ;
1214- valueAnimator .cancel ();
1215- ongoingAnimations .remove (this );
1215+ try {
1216+ markerWithPosition .position = to ;
1217+ mRemoveOnComplete = false ;
1218+ valueAnimator .cancel ();
1219+ lock .lock ();
1220+ ongoingAnimations .remove (this );
1221+ } finally {
1222+ lock .unlock ();
1223+ }
12161224 }
12171225
12181226 @ Override
@@ -1225,7 +1233,9 @@ public void onAnimationEnd(Animator animation) {
12251233 markerWithPosition .position = to ;
12261234
12271235 // Remove the task from the queue
1236+ lock .lock ();
12281237 ongoingAnimations .remove (this );
1238+ lock .unlock ();
12291239 }
12301240
12311241 public void removeOnAnimationComplete (MarkerManager markerManager ) {
0 commit comments