@@ -107,31 +107,19 @@ public enum AnimationType {
107
107
}
108
108
109
109
public void setAnimationType (AnimationType type ) {
110
- switch (type ) {
111
- case EASE_IN , ACCELERATE :
112
- animationInterp = new AccelerateInterpolator ();
113
- break ;
114
- case EASE_OUT :
115
- animationInterp = new DecelerateInterpolator ();
116
- break ;
117
- case EASE_IN_OUT :
118
- animationInterp = new AccelerateDecelerateInterpolator ();
119
- break ;
120
- case FAST_OUT_SLOW_IN :
121
- animationInterp = new FastOutSlowInInterpolator ();
122
- break ;
123
- case BOUNCE :
124
- animationInterp = new BounceInterpolator ();
125
- break ;
126
- case DECELERATE :
127
- animationInterp = new DecelerateInterpolator ();
128
- break ;
129
- default :
130
- animationInterp = new LinearInterpolator ();
131
- break ;
132
- }
110
+ animationInterp = switch (type ) {
111
+ case LINEAR -> new LinearInterpolator ();
112
+ case EASE_IN , ACCELERATE -> new AccelerateInterpolator ();
113
+ case EASE_OUT , DECELERATE -> new DecelerateInterpolator ();
114
+ case EASE_IN_OUT -> new AccelerateDecelerateInterpolator ();
115
+ case FAST_OUT_SLOW_IN -> new FastOutSlowInInterpolator ();
116
+ case BOUNCE -> new BounceInterpolator ();
117
+ };
133
118
}
134
119
120
+ public void setAnimationInterpolator (TimeInterpolator interpolator ) {
121
+ animationInterp = interpolator ;
122
+ }
135
123
136
124
/**
137
125
* Markers that are currently on the map.
@@ -459,6 +447,7 @@ public void setMapZoom(float zoom) {
459
447
}
460
448
461
449
@ SuppressLint ("NewApi" )
450
+ @ Override
462
451
public void run () {
463
452
final MarkerModifier markerModifier = new MarkerModifier ();
464
453
final float zoom = mMapZoom ;
@@ -687,13 +676,16 @@ private MarkerModifier() {
687
676
*/
688
677
public void add (boolean priority , CreateMarkerTask c ) {
689
678
lock .lock ();
690
- sendEmptyMessage (BLANK );
691
- if (priority ) {
692
- mOnScreenCreateMarkerTasks .add (c );
693
- } else {
694
- mCreateMarkerTasks .add (c );
679
+ try {
680
+ sendEmptyMessage (BLANK );
681
+ if (priority ) {
682
+ mOnScreenCreateMarkerTasks .add (c );
683
+ } else {
684
+ mCreateMarkerTasks .add (c );
685
+ }
686
+ } finally {
687
+ lock .unlock ();
695
688
}
696
- lock .unlock ();
697
689
}
698
690
699
691
/**
@@ -704,13 +696,16 @@ public void add(boolean priority, CreateMarkerTask c) {
704
696
*/
705
697
public void remove (boolean priority , Marker m ) {
706
698
lock .lock ();
707
- sendEmptyMessage (BLANK );
708
- if (priority ) {
709
- mOnScreenRemoveMarkerTasks .add (m );
710
- } else {
711
- mRemoveMarkerTasks .add (m );
699
+ try {
700
+ sendEmptyMessage (BLANK );
701
+ if (priority ) {
702
+ mOnScreenRemoveMarkerTasks .add (m );
703
+ } else {
704
+ mRemoveMarkerTasks .add (m );
705
+ }
706
+ } finally {
707
+ lock .unlock ();
712
708
}
713
- lock .unlock ();
714
709
}
715
710
716
711
/**
@@ -722,18 +717,21 @@ public void remove(boolean priority, Marker m) {
722
717
*/
723
718
public void animate (MarkerWithPosition marker , LatLng from , LatLng to ) {
724
719
lock .lock ();
725
- AnimationTask task = new AnimationTask (marker , from , to , lock );
720
+ try {
721
+ AnimationTask task = new AnimationTask (marker , from , to , lock );
726
722
727
- for (AnimationTask existingTask : ongoingAnimations ) {
728
- if (existingTask .marker .getId ().equals (task .marker .getId ())) {
729
- existingTask .cancel ();
730
- break ;
723
+ for (AnimationTask existingTask : ongoingAnimations ) {
724
+ if (existingTask .marker .getId ().equals (task .marker .getId ())) {
725
+ existingTask .cancel ();
726
+ break ;
727
+ }
731
728
}
732
- }
733
729
734
- mAnimationTasks .add (task );
735
- ongoingAnimations .add (task );
736
- lock .unlock ();
730
+ mAnimationTasks .add (task );
731
+ ongoingAnimations .add (task );
732
+ } finally {
733
+ lock .unlock ();
734
+ }
737
735
}
738
736
739
737
/**
@@ -746,18 +744,21 @@ public void animate(MarkerWithPosition marker, LatLng from, LatLng to) {
746
744
*/
747
745
public void animateThenRemove (MarkerWithPosition marker , LatLng from , LatLng to ) {
748
746
lock .lock ();
749
- AnimationTask animationTask = new AnimationTask (marker , from , to , lock );
750
- for (AnimationTask existingTask : ongoingAnimations ) {
751
- if (existingTask .marker .getId ().equals (animationTask .marker .getId ())) {
752
- existingTask .cancel ();
753
- break ;
747
+ try {
748
+ AnimationTask animationTask = new AnimationTask (marker , from , to , lock );
749
+ for (AnimationTask existingTask : ongoingAnimations ) {
750
+ if (existingTask .marker .getId ().equals (animationTask .marker .getId ())) {
751
+ existingTask .cancel ();
752
+ break ;
753
+ }
754
754
}
755
- }
756
755
757
- ongoingAnimations .add (animationTask );
758
- animationTask .removeOnAnimationComplete (mClusterManager .getMarkerManager ());
759
- mAnimationTasks .add (animationTask );
760
- lock .unlock ();
756
+ ongoingAnimations .add (animationTask );
757
+ animationTask .removeOnAnimationComplete (mClusterManager .getMarkerManager ());
758
+ mAnimationTasks .add (animationTask );
759
+ } finally {
760
+ lock .unlock ();
761
+ }
761
762
}
762
763
763
764
@ Override
@@ -821,9 +822,13 @@ private void removeMarker(Marker m) {
821
822
* @return true if there is still work to be processed.
822
823
*/
823
824
public boolean isBusy () {
825
+ lock .lock ();
824
826
try {
825
- lock .lock ();
826
- return !(mCreateMarkerTasks .isEmpty () && mOnScreenCreateMarkerTasks .isEmpty () && mOnScreenRemoveMarkerTasks .isEmpty () && mRemoveMarkerTasks .isEmpty () && mAnimationTasks .isEmpty ());
827
+ return !(mCreateMarkerTasks .isEmpty ()
828
+ && mOnScreenCreateMarkerTasks .isEmpty ()
829
+ && mOnScreenRemoveMarkerTasks .isEmpty ()
830
+ && mRemoveMarkerTasks .isEmpty ()
831
+ && mAnimationTasks .isEmpty ());
827
832
} finally {
828
833
lock .unlock ();
829
834
}
@@ -1257,11 +1262,11 @@ public void cancel() {
1257
1262
new Handler (Looper .getMainLooper ()).post (this ::cancel );
1258
1263
return ;
1259
1264
}
1265
+ lock .lock ();
1260
1266
try {
1261
1267
markerWithPosition .position = to ;
1262
1268
mRemoveOnComplete = false ;
1263
1269
valueAnimator .cancel ();
1264
- lock .lock ();
1265
1270
ongoingAnimations .remove (this );
1266
1271
} finally {
1267
1272
lock .unlock ();
@@ -1279,8 +1284,11 @@ public void onAnimationEnd(Animator animation) {
1279
1284
1280
1285
// Remove the task from the queue
1281
1286
lock .lock ();
1282
- ongoingAnimations .remove (this );
1283
- lock .unlock ();
1287
+ try {
1288
+ ongoingAnimations .remove (this );
1289
+ } finally {
1290
+ lock .unlock ();
1291
+ }
1284
1292
}
1285
1293
1286
1294
public void removeOnAnimationComplete (MarkerManager markerManager ) {
0 commit comments