3333import android .os .MessageQueue ;
3434import android .util .SparseArray ;
3535import android .view .ViewGroup ;
36+ import android .view .animation .AccelerateDecelerateInterpolator ;
37+ import android .view .animation .AccelerateInterpolator ;
38+ import android .view .animation .BounceInterpolator ;
3639import android .view .animation .DecelerateInterpolator ;
40+ import android .view .animation .LinearInterpolator ;
3741
3842import androidx .annotation .NonNull ;
3943import androidx .annotation .StyleRes ;
44+ import androidx .interpolator .view .animation .FastOutSlowInInterpolator ;
4045
4146import com .google .android .gms .maps .GoogleMap ;
4247import com .google .android .gms .maps .Projection ;
5964import java .util .ArrayList ;
6065import java .util .Collections ;
6166import java .util .HashMap ;
62- import java .util .Iterator ;
6367import java .util .LinkedList ;
6468import java .util .List ;
6569import java .util .Map ;
@@ -85,10 +89,55 @@ public class ClusterRendererMultipleItems<T extends ClusterItem> implements Clus
8589 private long mAnimationDurationMs ;
8690 private final Executor mExecutor = Executors .newSingleThreadExecutor ();
8791 private final Queue <AnimationTask > ongoingAnimations = new LinkedList <>();
92+ private static TimeInterpolator animationInterp = new DecelerateInterpolator ();
8893
8994 private static final int [] BUCKETS = {10 , 20 , 50 , 100 , 200 , 500 , 1000 };
9095 private ShapeDrawable mColoredCircleBackground ;
9196
97+ enum AnimationType {
98+ LINEAR ,
99+ EASE_IN ,
100+ EASE_OUT ,
101+ EASE_IN_OUT ,
102+ FAST_OUT_SLOW_IN ,
103+ BOUNCE ,
104+ ACCELERATE ,
105+ DECELERATE
106+ }
107+
108+ void setAnimationType (AnimationType type ) {
109+ switch (type ) {
110+ case LINEAR :
111+ animationInterp = new LinearInterpolator ();
112+ break ;
113+ case EASE_IN :
114+ animationInterp = new AccelerateInterpolator ();
115+ break ;
116+ case EASE_OUT :
117+ animationInterp = new DecelerateInterpolator ();
118+ break ;
119+ case EASE_IN_OUT :
120+ animationInterp = new AccelerateDecelerateInterpolator ();
121+ break ;
122+ case FAST_OUT_SLOW_IN :
123+ animationInterp = new FastOutSlowInInterpolator ();
124+ break ;
125+ case BOUNCE :
126+ animationInterp = new BounceInterpolator ();
127+ break ;
128+ case ACCELERATE :
129+ animationInterp = new AccelerateInterpolator ();
130+ break ;
131+ case DECELERATE :
132+ animationInterp = new DecelerateInterpolator ();
133+ break ;
134+ default :
135+ animationInterp = new LinearInterpolator ();
136+ break ;
137+ }
138+ }
139+
140+
92141 /**
93142 * Markers that are currently on the map.
94143 */
@@ -281,6 +330,7 @@ private class ViewModifier extends Handler {
281330 public ViewModifier (Looper looper ) {
282331 super (looper );
283332 }
333+
284334 private static final int RUN_TASK = 0 ;
285335 private static final int TASK_FINISHED = 1 ;
286336 private boolean mViewModificationInProgress = false ;
@@ -1121,7 +1171,6 @@ public int hashCode() {
11211171 }
11221172 }
11231173
1124- private static final TimeInterpolator ANIMATION_INTERP = new DecelerateInterpolator ();
11251174
11261175 /**
11271176 * Animates a markerWithPosition from one position to another. TODO: improve performance for
@@ -1145,7 +1194,7 @@ private AnimationTask(MarkerWithPosition markerWithPosition, LatLng from, LatLng
11451194
11461195 public void perform () {
11471196 valueAnimator = ValueAnimator .ofFloat (0.0f , 1.0f );
1148- valueAnimator .setInterpolator (ANIMATION_INTERP );
1197+ valueAnimator .setInterpolator (animationInterp );
11491198 valueAnimator .setDuration (mAnimationDurationMs );
11501199 valueAnimator .addUpdateListener (this );
11511200 valueAnimator .addListener (this );
0 commit comments