Skip to content

Commit

Permalink
feat: stop animation method in Cluster
Browse files Browse the repository at this point in the history
  • Loading branch information
kikoso committed Feb 4, 2025
1 parent 28b7e7c commit a9867dc
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -542,7 +542,7 @@ public void setAnimation(boolean animate) {
public void setAnimationDuration(long animationDurationMs) {
mAnimationDurationMs = animationDurationMs;
}

public void stopAnimation() {
for (AnimationTask animation : ongoingAnimations) {
animation.cancel();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ public class DefaultAdvancedMarkersClusterRenderer<T extends ClusterItem> implem
private boolean mAnimate;
private long mAnimationDurationMs;
private final Executor mExecutor = Executors.newSingleThreadExecutor();
private final Queue<AnimationTask> ongoingAnimations = new LinkedList<>();

private static final int[] BUCKETS = {10, 20, 50, 100, 200, 500, 1000};
private ShapeDrawable mColoredCircleBackground;
Expand Down Expand Up @@ -1153,7 +1152,6 @@ public void cancel() {
markerWithPosition.position = to;
mRemoveOnComplete = false;
valueAnimator.cancel();
ongoingAnimations.remove(this);
}

public void perform() {
Expand All @@ -1174,7 +1172,6 @@ public void onAnimationEnd(Animator animation) {
}
markerWithPosition.position = to;
valueAnimator.cancel();
ongoingAnimations.remove(this);
}

public void removeOnAnimationComplete(MarkerManager markerManager) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ public class DefaultClusterRenderer<T extends ClusterItem> implements ClusterRen
private boolean mAnimate;
private long mAnimationDurationMs;
private final Executor mExecutor = Executors.newSingleThreadExecutor();
private final Queue<AnimationTask> ongoingAnimations = new LinkedList<>();

private static final int[] BUCKETS = {10, 20, 50, 100, 200, 500, 1000};
private ShapeDrawable mColoredCircleBackground;
Expand Down Expand Up @@ -663,17 +662,7 @@ public void remove(boolean priority, Marker m) {
*/
public void animate(MarkerWithPosition marker, LatLng from, LatLng to) {
lock.lock();
AnimationTask task = new AnimationTask(marker, from, to);

for (AnimationTask existingTask : ongoingAnimations) {
if (existingTask.marker.getId().equals(task.marker.getId())) {
existingTask.cancel();
break;
}
}

mAnimationTasks.add(task);
ongoingAnimations.add(task);
mAnimationTasks.add(new AnimationTask(marker, from, to));
lock.unlock();
}

Expand All @@ -688,14 +677,6 @@ public void animate(MarkerWithPosition marker, LatLng from, LatLng to) {
public void animateThenRemove(MarkerWithPosition marker, LatLng from, LatLng to) {
lock.lock();
AnimationTask animationTask = new AnimationTask(marker, from, to);
for (AnimationTask existingTask : ongoingAnimations) {
if (existingTask.marker.getId().equals(animationTask.marker.getId())) {
existingTask.cancel();
break;
}
}

ongoingAnimations.add(animationTask);
animationTask.removeOnAnimationComplete(mClusterManager.getMarkerManager());
mAnimationTasks.add(animationTask);
lock.unlock();
Expand Down Expand Up @@ -1144,7 +1125,6 @@ private class AnimationTask extends AnimatorListenerAdapter implements ValueAnim
private final LatLng to;
private boolean mRemoveOnComplete;
private MarkerManager mMarkerManager;
private ValueAnimator valueAnimator;

private AnimationTask(MarkerWithPosition markerWithPosition, LatLng from, LatLng to) {
this.markerWithPosition = markerWithPosition;
Expand All @@ -1154,26 +1134,14 @@ private AnimationTask(MarkerWithPosition markerWithPosition, LatLng from, LatLng
}

public void perform() {
valueAnimator = ValueAnimator.ofFloat(0.0f, 1.0f);
ValueAnimator valueAnimator = ValueAnimator.ofFloat(0.0f, 1.0f);
valueAnimator.setInterpolator(ANIMATION_INTERP);
valueAnimator.setDuration(mAnimationDurationMs);
valueAnimator.addUpdateListener(this);
valueAnimator.addListener(this);
valueAnimator.start();
}

public void cancel() {
if (Looper.myLooper() != Looper.getMainLooper()) {
new Handler(Looper.getMainLooper()).post(this::cancel);
return;
}
markerWithPosition.position = to;
mRemoveOnComplete = false;
valueAnimator.cancel();
ongoingAnimations.remove(this);
}


@Override
public void onAnimationEnd(Animator animation) {
if (mRemoveOnComplete) {
Expand All @@ -1182,9 +1150,6 @@ public void onAnimationEnd(Animator animation) {
mMarkerManager.remove(marker);
}
markerWithPosition.position = to;

// Remove the task from the queue
ongoingAnimations.remove(this);
}

public void removeOnAnimationComplete(MarkerManager markerManager) {
Expand Down

0 comments on commit a9867dc

Please sign in to comment.