@@ -117,6 +117,11 @@ public void setAnimationType(AnimationType type) {
117
117
};
118
118
}
119
119
120
+ /**
121
+ * Sets the interpolator for the animation.
122
+ *
123
+ * @param interpolator the interpolator to use for the animation.
124
+ */
120
125
public void setAnimationInterpolator (TimeInterpolator interpolator ) {
121
126
animationInterp = interpolator ;
122
127
}
@@ -665,6 +670,15 @@ private class MarkerModifier extends Handler implements MessageQueue.IdleHandler
665
670
*/
666
671
private boolean mListenerAdded ;
667
672
673
+ private void withLock (Runnable runnable ) {
674
+ lock .lock ();
675
+ try {
676
+ runnable .run ();
677
+ } finally {
678
+ lock .unlock ();
679
+ }
680
+ }
681
+
668
682
private MarkerModifier () {
669
683
super (Looper .getMainLooper ());
670
684
}
@@ -675,17 +689,14 @@ private MarkerModifier() {
675
689
* @param priority whether this operation should have priority.
676
690
*/
677
691
public void add (boolean priority , CreateMarkerTask c ) {
678
- lock .lock ();
679
- try {
692
+ withLock (() -> {
680
693
sendEmptyMessage (BLANK );
681
694
if (priority ) {
682
695
mOnScreenCreateMarkerTasks .add (c );
683
696
} else {
684
697
mCreateMarkerTasks .add (c );
685
698
}
686
- } finally {
687
- lock .unlock ();
688
- }
699
+ });
689
700
}
690
701
691
702
/**
@@ -695,17 +706,14 @@ public void add(boolean priority, CreateMarkerTask c) {
695
706
* @param m the markerWithPosition to remove.
696
707
*/
697
708
public void remove (boolean priority , Marker m ) {
698
- lock .lock ();
699
- try {
709
+ withLock (() -> {
700
710
sendEmptyMessage (BLANK );
701
711
if (priority ) {
702
712
mOnScreenRemoveMarkerTasks .add (m );
703
713
} else {
704
714
mRemoveMarkerTasks .add (m );
705
715
}
706
- } finally {
707
- lock .unlock ();
708
- }
716
+ });
709
717
}
710
718
711
719
/**
@@ -716,8 +724,7 @@ public void remove(boolean priority, Marker m) {
716
724
* @param to the position to animate to.
717
725
*/
718
726
public void animate (MarkerWithPosition marker , LatLng from , LatLng to ) {
719
- lock .lock ();
720
- try {
727
+ withLock (() -> {
721
728
AnimationTask task = new AnimationTask (marker , from , to , lock );
722
729
723
730
for (AnimationTask existingTask : ongoingAnimations ) {
@@ -729,9 +736,7 @@ public void animate(MarkerWithPosition marker, LatLng from, LatLng to) {
729
736
730
737
mAnimationTasks .add (task );
731
738
ongoingAnimations .add (task );
732
- } finally {
733
- lock .unlock ();
734
- }
739
+ });
735
740
}
736
741
737
742
/**
@@ -743,8 +748,7 @@ public void animate(MarkerWithPosition marker, LatLng from, LatLng to) {
743
748
* @param to the position to animate to.
744
749
*/
745
750
public void animateThenRemove (MarkerWithPosition marker , LatLng from , LatLng to ) {
746
- lock .lock ();
747
- try {
751
+ withLock (() -> {
748
752
AnimationTask animationTask = new AnimationTask (marker , from , to , lock );
749
753
for (AnimationTask existingTask : ongoingAnimations ) {
750
754
if (existingTask .marker .getId ().equals (animationTask .marker .getId ())) {
@@ -756,9 +760,7 @@ public void animateThenRemove(MarkerWithPosition marker, LatLng from, LatLng to)
756
760
ongoingAnimations .add (animationTask );
757
761
animationTask .removeOnAnimationComplete (mClusterManager .getMarkerManager ());
758
762
mAnimationTasks .add (animationTask );
759
- } finally {
760
- lock .unlock ();
761
- }
763
+ });
762
764
}
763
765
764
766
@ Override
0 commit comments