Skip to content

Instantly share code, notes, and snippets.

@CallumCarmicheal
Last active April 19, 2020 17:17
Show Gist options
  • Save CallumCarmicheal/6810e48b837020adfb7f32b27df212e6 to your computer and use it in GitHub Desktop.
Save CallumCarmicheal/6810e48b837020adfb7f32b27df212e6 to your computer and use it in GitHub Desktop.
Fix for fragment null string comparison inside DefaultClusterRenderer Java
public class GmapClusterRendererFixedNullRef extends DefaultClusterRenderer<GmapClusterItem>
{
// ....
@Override
protected void onClusterItemUpdated(GmapClusterItem item, Marker marker)
{
//super.onClusterItemUpdated(item, marker);
/// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
//
// // Source / Credits: https://gist.github.com/CallumCarmicheal/6810e48b837020adfb7f32b27df212e6
//
// Replaced logic with a fix due to a bug where the marker .getTitle is null!
// This is the code from inside the com.google.maps.android.clustering.view.DefaultClusterRenderer class licensed under apache
//
// I REPEAT THIS IS NOT MY ORIGINAL WORK, THE COPYRIGHT HOLDER FOR THE FOLLOWING CODE IS GOOGLE 2013 LICENSED UNDER APACHE !!!!
//
// ==== TERMS OF APACHE LICENSE ====
//
// Permissions:
// - Commercial use
// - Distribution
// - Modification
// - Patent use
// - Private use
//
// Conditions:
// - License and copyright notice
// - State changes
//
// Limitations:
// - Liability
// - Trademark use
// - Warranty
//
/// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
boolean changed = false;
// Update marker text if the item text changed - same logic as adding marker in CreateMarkerTask.perform()
if (item.getTitle() != null || item.getSnippet() != null)
{
// FIX: FIX for issue where marker.getTitle is null
if (marker.getTitle() == null || !marker.getTitle().equals(item.getTitle()))
{
marker.setTitle(item.getTitle());
changed = true;
}
// FIX: FIX for issue where marker.getSnippet is null
if (marker.getSnippet() == null || !marker.getSnippet().equals(item.getSnippet()))
{
marker.setSnippet(item.getSnippet());
changed = true;
}
}
else if (item.getSnippet() != null && !item.getSnippet().equals(marker.getTitle()))
{
marker.setTitle(item.getSnippet());
changed = true;
}
else if (item.getTitle() != null && !item.getTitle().equals(marker.getTitle()))
{
marker.setTitle(item.getTitle());
changed = true;
}
// Update marker position if the item changed position
if (!marker.getPosition().equals(item.getPosition()))
{
marker.setPosition(item.getPosition());
changed = true;
}
if (changed && marker.isInfoWindowShown())
{
// Force a refresh of marker info window contents
marker.showInfoWindow();
}
}
// ....
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment