Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,16 @@

package com.google.maps.android.clustering.algo;

import androidx.collection.LruCache;

import com.google.maps.android.clustering.Cluster;
import com.google.maps.android.clustering.ClusterItem;

import java.util.Collection;
import java.util.Set;
import java.util.concurrent.Executor;
import java.util.concurrent.Executors;
import java.util.concurrent.locks.ReadWriteLock;
import java.util.concurrent.locks.ReentrantReadWriteLock;

import androidx.collection.LruCache;

/**
* Optimistically fetch clusters for adjacent zoom levels, caching them as necessary.
*/
Expand All @@ -37,7 +35,6 @@ public class PreCachingAlgorithmDecorator<T extends ClusterItem> extends Abstrac
// TODO: evaluate maxSize parameter for LruCache.
private final LruCache<Integer, Set<? extends Cluster<T>>> mCache = new LruCache<Integer, Set<? extends Cluster<T>>>(5);
private final ReadWriteLock mCacheLock = new ReentrantReadWriteLock();
private final Executor mExecutor = Executors.newCachedThreadPool();

public PreCachingAlgorithmDecorator(Algorithm<T> algorithm) {
mAlgorithm = algorithm;
Expand Down Expand Up @@ -104,10 +101,12 @@ public Set<? extends Cluster<T>> getClusters(float zoom) {
Set<? extends Cluster<T>> results = getClustersInternal(discreteZoom);
// TODO: Check if requests are already in-flight.
if (mCache.get(discreteZoom + 1) == null) {
mExecutor.execute(new PrecacheRunnable(discreteZoom + 1));
// It seems this cannot use a thread pool due to thread locking issues (#660)
new Thread(new PrecacheRunnable(discreteZoom + 1)).start();
}
if (mCache.get(discreteZoom - 1) == null) {
mExecutor.execute(new PrecacheRunnable(discreteZoom - 1));
// It seems this cannot use a thread pool due to thread locking issues (#660)
new Thread(new PrecacheRunnable(discreteZoom - 1)).start();
}
return results;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,6 @@

package com.google.maps.android.clustering.view;

import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.Projection;
import com.google.android.gms.maps.model.BitmapDescriptor;
import com.google.android.gms.maps.model.BitmapDescriptorFactory;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.LatLngBounds;
import com.google.android.gms.maps.model.Marker;
import com.google.android.gms.maps.model.MarkerOptions;
import com.google.maps.android.R;
import com.google.maps.android.clustering.Cluster;
import com.google.maps.android.clustering.ClusterItem;
import com.google.maps.android.clustering.ClusterManager;
import com.google.maps.android.collections.MarkerManager;
import com.google.maps.android.geometry.Point;
import com.google.maps.android.projection.SphericalMercatorProjection;
import com.google.maps.android.ui.IconGenerator;
import com.google.maps.android.ui.SquareTextView;

import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.animation.TimeInterpolator;
Expand All @@ -55,6 +37,24 @@
import android.view.ViewGroup;
import android.view.animation.DecelerateInterpolator;

import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.Projection;
import com.google.android.gms.maps.model.BitmapDescriptor;
import com.google.android.gms.maps.model.BitmapDescriptorFactory;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.LatLngBounds;
import com.google.android.gms.maps.model.Marker;
import com.google.android.gms.maps.model.MarkerOptions;
import com.google.maps.android.R;
import com.google.maps.android.clustering.Cluster;
import com.google.maps.android.clustering.ClusterItem;
import com.google.maps.android.clustering.ClusterManager;
import com.google.maps.android.collections.MarkerManager;
import com.google.maps.android.geometry.Point;
import com.google.maps.android.projection.SphericalMercatorProjection;
import com.google.maps.android.ui.IconGenerator;
import com.google.maps.android.ui.SquareTextView;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
Expand All @@ -64,8 +64,6 @@
import java.util.Queue;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.Executor;
import java.util.concurrent.Executors;
import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;
Expand All @@ -79,7 +77,6 @@ public class DefaultClusterRenderer<T extends ClusterItem> implements ClusterRen
private final ClusterManager<T> mClusterManager;
private final float mDensity;
private boolean mAnimate;
private final Executor mExecutor = Executors.newSingleThreadExecutor();

private static final int[] BUCKETS = {10, 20, 50, 100, 200, 500, 1000};
private ShapeDrawable mColoredCircleBackground;
Expand Down Expand Up @@ -292,7 +289,8 @@ public void run() {
});
renderTask.setProjection(projection);
renderTask.setMapZoom(mMap.getCameraPosition().zoom);
mExecutor.execute(renderTask);
// It seems this cannot use a thread pool due to thread locking issues (#660)
new Thread(renderTask).start();
}

public void queue(Set<? extends Cluster<T>> clusters) {
Expand Down