Skip to content

Commit

Permalink
Disable animations (#334)
Browse files Browse the repository at this point in the history
* Added function setAnimation in ClusterRenderer and ClusterManager so animation can be turned on/off.

* Removed unnecessary comments.
  • Loading branch information
Libby713 authored and stephenmcd committed Dec 13, 2016
1 parent 087615d commit 27f7a5b
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,10 @@ public void setAlgorithm(Algorithm<T> algorithm) {
cluster();
}

public void setAnimation(boolean animate) {
mRenderer.setAnimation(animate);
}

public ClusterRenderer<T> getRenderer() {
return mRenderer;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ public interface ClusterRenderer<T extends ClusterItem> {

void setOnClusterItemInfoWindowClickListener(ClusterManager.OnClusterItemInfoWindowClickListener<T> listener);

/**
* Called to set animation on or off
*/
void setAnimation(boolean animate);

/**
* Called when the view is added.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ public class DefaultClusterRenderer<T extends ClusterItem> implements ClusterRen
private final IconGenerator mIconGenerator;
private final ClusterManager<T> mClusterManager;
private final float mDensity;
private boolean mAnimate;

private static final int[] BUCKETS = {10, 20, 50, 100, 200, 500, 1000};
private ShapeDrawable mColoredCircleBackground;
Expand Down Expand Up @@ -129,6 +130,7 @@ public class DefaultClusterRenderer<T extends ClusterItem> implements ClusterRen

public DefaultClusterRenderer(Context context, GoogleMap map, ClusterManager<T> clusterManager) {
mMap = map;
mAnimate = true;
mDensity = context.getResources().getDisplayMetrics().density;
mIconGenerator = new IconGenerator(context);
mIconGenerator.setContentView(makeSquareTextView(context));
Expand Down Expand Up @@ -395,7 +397,7 @@ public void run() {
if (zoomingIn && onScreen && SHOULD_ANIMATE) {
Point point = mSphericalMercatorProjection.toPoint(c.getPosition());
Point closest = findClosestCluster(existingClustersOnScreen, point);
if (closest != null) {
if (closest != null && mAnimate) {
LatLng animateTo = mSphericalMercatorProjection.toLatLng(closest);
markerModifier.add(true, new CreateMarkerTask(c, newMarkers, animateTo));
} else {
Expand Down Expand Up @@ -434,7 +436,7 @@ public void run() {
if (!zoomingIn && zoomDelta > -3 && onScreen && SHOULD_ANIMATE) {
final Point point = mSphericalMercatorProjection.toPoint(marker.position);
final Point closest = findClosestCluster(newClustersOnScreen, point);
if (closest != null) {
if (closest != null && mAnimate) {
LatLng animateTo = mSphericalMercatorProjection.toLatLng(closest);
markerModifier.animateThenRemove(marker, marker.position, animateTo);
} else {
Expand Down Expand Up @@ -480,6 +482,11 @@ public void setOnClusterItemInfoWindowClickListener(ClusterManager.OnClusterItem
mItemInfoWindowClickListener = listener;
}

@Override
public void setAnimation(boolean animate) {
mAnimate = animate;
}

private static double distanceSquared(Point a, Point b) {
return (a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y);
}
Expand Down

0 comments on commit 27f7a5b

Please sign in to comment.