diff --git a/demo/src/main/AndroidManifest.xml b/demo/src/main/AndroidManifest.xml
index e6cb01240..a504a7619 100644
--- a/demo/src/main/AndroidManifest.xml
+++ b/demo/src/main/AndroidManifest.xml
@@ -91,6 +91,9 @@
+
diff --git a/demo/src/main/java/com/google/maps/android/utils/demo/ClusteringDiffDemoActivity.java b/demo/src/main/java/com/google/maps/android/utils/demo/ClusteringDiffDemoActivity.java
index f37d84dcb..cc532ffce 100644
--- a/demo/src/main/java/com/google/maps/android/utils/demo/ClusteringDiffDemoActivity.java
+++ b/demo/src/main/java/com/google/maps/android/utils/demo/ClusteringDiffDemoActivity.java
@@ -16,6 +16,7 @@
package com.google.maps.android.utils.demo;
+import android.annotation.SuppressLint;
import android.graphics.Bitmap;
import android.graphics.drawable.Drawable;
import android.os.Handler;
@@ -26,6 +27,7 @@
import android.widget.Toast;
import androidx.annotation.NonNull;
+import androidx.core.content.res.ResourcesCompat;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
@@ -70,6 +72,7 @@ public void onMapReady(@NonNull GoogleMap map) {
* Draws profile photos inside markers (using IconGenerator).
* When there are multiple people in the cluster, draw multiple photos (using MultiDrawable).
*/
+ @SuppressLint("InflateParams")
private class PersonRenderer extends ClusterRendererMultipleItems {
private final IconGenerator mIconGenerator = new IconGenerator(getApplicationContext());
private final IconGenerator mClusterIconGenerator = new IconGenerator(getApplicationContext());
@@ -92,13 +95,6 @@ public PersonRenderer() {
mIconGenerator.setContentView(mImageView);
}
- public void setUpdateMarker(Person person) {
- Marker marker = getMarker(person);
- if (marker != null) {
- marker.setIcon(getItemIcon(person));
- }
- }
-
@Override
protected void onBeforeClusterItemRendered(@NonNull Person person, @NonNull MarkerOptions markerOptions) {
// Draw a single person - show their profile photo and set the info window to show their name
@@ -155,8 +151,10 @@ private BitmapDescriptor getClusterIcon(Cluster cluster) {
for (Person p : cluster.getItems()) {
// Draw 4 at most.
if (profilePhotos.size() == 4) break;
- Drawable drawable = getResources().getDrawable(p.profilePhoto);
- drawable.setBounds(0, 0, width, height);
+ Drawable drawable = ResourcesCompat.getDrawable(getBaseContext().getResources(), p.profilePhoto, null);
+ if (drawable != null) {
+ drawable.setBounds(0, 0, width, height);
+ }
profilePhotos.add(drawable);
}
MultiDrawable multiDrawable = new MultiDrawable(profilePhotos);
diff --git a/demo/src/main/java/com/google/maps/android/utils/demo/MainActivity.java b/demo/src/main/java/com/google/maps/android/utils/demo/MainActivity.java
index 8cf7561fb..10ff9d5f7 100644
--- a/demo/src/main/java/com/google/maps/android/utils/demo/MainActivity.java
+++ b/demo/src/main/java/com/google/maps/android/utils/demo/MainActivity.java
@@ -47,6 +47,7 @@ protected void onCreate(Bundle savedInstanceState) {
addDemo("Clustering", ClusteringDemoActivity.class);
addDemo("Advanced Markers Clustering Example", CustomAdvancedMarkerClusteringDemoActivity.class);
addDemo("Clustering: Custom Look", CustomMarkerClusteringDemoActivity.class);
+ addDemo("Clustering: Diff", ClusteringDiffDemoActivity.class);
addDemo("Clustering: 2K markers", BigClusteringDemoActivity.class);
addDemo("Clustering: 20K only visible markers", VisibleClusteringDemoActivity.class);
addDemo("Clustering: ViewModel", ClusteringViewModelDemoActivity.class);
diff --git a/library/src/main/java/com/google/maps/android/clustering/ClusterManager.java b/library/src/main/java/com/google/maps/android/clustering/ClusterManager.java
index 37c6c2974..52474f2f5 100644
--- a/library/src/main/java/com/google/maps/android/clustering/ClusterManager.java
+++ b/library/src/main/java/com/google/maps/android/clustering/ClusterManager.java
@@ -219,7 +219,9 @@ public void diff(@Nullable Collection add, @Nullable Collection remove, @N
}
// Remove items
- algorithm.removeItems(remove);
+ if (remove != null) {
+ algorithm.removeItems(remove);
+ }
// Modify items
if (modify != null) {
diff --git a/library/src/main/java/com/google/maps/android/clustering/view/ClusterRendererMultipleItems.java b/library/src/main/java/com/google/maps/android/clustering/view/ClusterRendererMultipleItems.java
index 431dd36f2..f39d7bc1e 100644
--- a/library/src/main/java/com/google/maps/android/clustering/view/ClusterRendererMultipleItems.java
+++ b/library/src/main/java/com/google/maps/android/clustering/view/ClusterRendererMultipleItems.java
@@ -455,7 +455,6 @@ public void run() {
if (shouldRenderAsCluster(c) && visibleBounds.contains(c.getPosition())) {
Point point = mSphericalMercatorProjection.toPoint(c.getPosition());
existingClustersOnScreen.add(point);
- Log.d("ClusterTest","We added one point to the existingClustersOnScreen");
}
}
}
@@ -470,14 +469,11 @@ public void run() {
Point closest = findClosestCluster(existingClustersOnScreen, point);
if (closest != null) {
LatLng animateFrom = mSphericalMercatorProjection.toLatLng(closest);
- Log.d("ClusterTest","We added one markerModifier");
markerModifier.add(true, new CreateMarkerTask(c, newMarkers, animateFrom));
} else {
- Log.d("ALARM", "from not found");
markerModifier.add(true, new CreateMarkerTask(c, newMarkers, null));
}
} else {
- Log.d("ALARM", "from not found2");
markerModifier.add(onScreen, new CreateMarkerTask(c, newMarkers, null));
}
}
@@ -498,7 +494,6 @@ public void run() {
if (shouldRenderAsCluster(c) && visibleBounds.contains(c.getPosition())) {
Point p = mSphericalMercatorProjection.toPoint(c.getPosition());
- Log.d("ClusterTest","We are going to add a new cluster on the screen, located at " + c.getPosition().toString());
newClustersOnScreen.add(p);
}
}
@@ -514,14 +509,11 @@ public void run() {
final Point closest = findClosestCluster(newClustersOnScreen, point);
if (closest != null) {
LatLng animateTo = mSphericalMercatorProjection.toLatLng(closest);
- Log.d("ClusterTest","We are going to remove an item from the screen (anim) located at " + marker.position.toString());
markerModifier.animateThenRemove(marker, marker.position, animateTo);
} else {
- Log.d("ClusterTest","We are going to remove an item from the screen (no anim) located at " + marker.position.toString());
markerModifier.remove(true, marker.marker);
}
} else {
- Log.d("ClusterTest","We are going to remove an item from the screen (no anim2) located at " + marker.position.toString());
markerModifier.remove(onScreen, marker.marker);
}
}
diff --git a/library/src/main/java/com/google/maps/android/clustering/view/DefaultClusterRenderer.java b/library/src/main/java/com/google/maps/android/clustering/view/DefaultClusterRenderer.java
index 4d09c720d..f289c2796 100644
--- a/library/src/main/java/com/google/maps/android/clustering/view/DefaultClusterRenderer.java
+++ b/library/src/main/java/com/google/maps/android/clustering/view/DefaultClusterRenderer.java
@@ -145,19 +145,11 @@ public DefaultClusterRenderer(Context context, GoogleMap map, ClusterManager
@Override
public void onAdd() {
- mClusterManager.getMarkerCollection().setOnMarkerClickListener(new GoogleMap.OnMarkerClickListener() {
- @Override
- public boolean onMarkerClick(@NonNull Marker marker) {
- return mItemClickListener != null && mItemClickListener.onClusterItemClick(mMarkerCache.get(marker));
- }
- });
+ mClusterManager.getMarkerCollection().setOnMarkerClickListener(marker -> mItemClickListener != null && mItemClickListener.onClusterItemClick(mMarkerCache.get(marker)));
- mClusterManager.getMarkerCollection().setOnInfoWindowClickListener(new GoogleMap.OnInfoWindowClickListener() {
- @Override
- public void onInfoWindowClick(@NonNull Marker marker) {
- if (mItemInfoWindowClickListener != null) {
- mItemInfoWindowClickListener.onClusterItemInfoWindowClick(mMarkerCache.get(marker));
- }
+ mClusterManager.getMarkerCollection().setOnInfoWindowClickListener(marker -> {
+ if (mItemInfoWindowClickListener != null) {
+ mItemInfoWindowClickListener.onClusterItemInfoWindowClick(mMarkerCache.get(marker));
}
});
@@ -1168,7 +1160,7 @@ public void removeOnAnimationComplete(MarkerManager markerManager) {
@Override
public void onAnimationUpdate(ValueAnimator valueAnimator) {
if (to == null || from == null || marker == null) {
- return;
+ return;
}
float fraction = valueAnimator.getAnimatedFraction();