Skip to content

Commit 4d61393

Browse files
authored
feat: setting animation on Cluster (#1458)
1 parent ed99d45 commit 4d61393

File tree

1 file changed

+52
-3
lines changed

1 file changed

+52
-3
lines changed

library/src/main/java/com/google/maps/android/clustering/view/ClusterRendererMultipleItems.java

Lines changed: 52 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,15 @@
3333
import android.os.MessageQueue;
3434
import android.util.SparseArray;
3535
import android.view.ViewGroup;
36+
import android.view.animation.AccelerateDecelerateInterpolator;
37+
import android.view.animation.AccelerateInterpolator;
38+
import android.view.animation.BounceInterpolator;
3639
import android.view.animation.DecelerateInterpolator;
40+
import android.view.animation.LinearInterpolator;
3741

3842
import androidx.annotation.NonNull;
3943
import androidx.annotation.StyleRes;
44+
import androidx.interpolator.view.animation.FastOutSlowInInterpolator;
4045

4146
import com.google.android.gms.maps.GoogleMap;
4247
import com.google.android.gms.maps.Projection;
@@ -59,7 +64,6 @@
5964
import java.util.ArrayList;
6065
import java.util.Collections;
6166
import java.util.HashMap;
62-
import java.util.Iterator;
6367
import java.util.LinkedList;
6468
import java.util.List;
6569
import 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

Comments
 (0)