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,6 +16,9 @@

package com.google.maps.android.clustering;

import android.content.Context;
import android.os.AsyncTask;

import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.model.CameraPosition;
import com.google.android.gms.maps.model.Marker;
Expand All @@ -28,9 +31,6 @@
import com.google.maps.android.clustering.view.DefaultClusterRenderer;
import com.google.maps.android.collections.MarkerManager;

import android.content.Context;
import android.os.AsyncTask;

import java.util.Collection;
import java.util.Set;
import java.util.concurrent.locks.ReadWriteLock;
Expand Down Expand Up @@ -61,7 +61,9 @@ public class ClusterManager<T extends ClusterItem> implements

private OnClusterItemClickListener<T> mOnClusterItemClickListener;
private OnClusterInfoWindowClickListener<T> mOnClusterInfoWindowClickListener;
private OnClusterInfoWindowLongClickListener<T> mOnClusterInfoWindowLongClickListener;
private OnClusterItemInfoWindowClickListener<T> mOnClusterItemInfoWindowClickListener;
private OnClusterItemInfoWindowLongClickListener<T> mOnClusterItemInfoWindowLongClickListener;
private OnClusterClickListener<T> mOnClusterClickListener;

public ClusterManager(Context context, GoogleMap map) {
Expand Down Expand Up @@ -103,8 +105,10 @@ public void setRenderer(ClusterRenderer<T> renderer) {
mRenderer.onAdd();
mRenderer.setOnClusterClickListener(mOnClusterClickListener);
mRenderer.setOnClusterInfoWindowClickListener(mOnClusterInfoWindowClickListener);
mRenderer.setOnClusterInfoWindowLongClickListener(mOnClusterInfoWindowLongClickListener);
mRenderer.setOnClusterItemClickListener(mOnClusterItemClickListener);
mRenderer.setOnClusterItemInfoWindowClickListener(mOnClusterItemInfoWindowClickListener);
mRenderer.setOnClusterItemInfoWindowLongClickListener(mOnClusterItemInfoWindowLongClickListener);
cluster();
}

Expand Down Expand Up @@ -314,14 +318,23 @@ public void setOnClusterClickListener(OnClusterClickListener<T> listener) {
}

/**
* Sets a callback that's invoked when a Cluster is tapped. Note: For this listener to function,
* Sets a callback that's invoked when a Cluster info window is tapped. Note: For this listener to function,
* the ClusterManager must be added as a info window click listener to the map.
*/
public void setOnClusterInfoWindowClickListener(OnClusterInfoWindowClickListener<T> listener) {
mOnClusterInfoWindowClickListener = listener;
mRenderer.setOnClusterInfoWindowClickListener(listener);
}

/**
* Sets a callback that's invoked when a Cluster info window is long-pressed. Note: For this listener to function,
* the ClusterManager must be added as a info window click listener to the map.
*/
public void setOnClusterInfoWindowLongClickListener(OnClusterInfoWindowLongClickListener<T> listener) {
mOnClusterInfoWindowLongClickListener = listener;
mRenderer.setOnClusterInfoWindowLongClickListener(listener);
}

/**
* Sets a callback that's invoked when an individual ClusterItem is tapped. Note: For this
* listener to function, the ClusterManager must be added as a click listener to the map.
Expand All @@ -340,6 +353,15 @@ public void setOnClusterItemInfoWindowClickListener(OnClusterItemInfoWindowClick
mRenderer.setOnClusterItemInfoWindowClickListener(listener);
}

/**
* Sets a callback that's invoked when an individual ClusterItem's Info Window is long-pressed. Note: For this
* listener to function, the ClusterManager must be added as a info window click listener to the map.
*/
public void setOnClusterItemInfoWindowLongClickListener(OnClusterItemInfoWindowLongClickListener<T> listener) {
mOnClusterItemInfoWindowLongClickListener = listener;
mRenderer.setOnClusterItemInfoWindowLongClickListener(listener);
}

/**
* Called when a Cluster is clicked.
*/
Expand All @@ -359,6 +381,13 @@ public interface OnClusterInfoWindowClickListener<T extends ClusterItem> {
void onClusterInfoWindowClick(Cluster<T> cluster);
}

/**
* Called when a Cluster's Info Window is long clicked.
*/
public interface OnClusterInfoWindowLongClickListener<T extends ClusterItem> {
void onClusterInfoWindowLongClick(Cluster<T> cluster);
}

/**
* Called when an individual ClusterItem is clicked.
*/
Expand All @@ -382,4 +411,11 @@ public interface OnClusterItemClickListener<T extends ClusterItem> {
public interface OnClusterItemInfoWindowClickListener<T extends ClusterItem> {
void onClusterItemInfoWindowClick(T item);
}

/**
* Called when an individual ClusterItem's Info Window is long clicked.
*/
public interface OnClusterItemInfoWindowLongClickListener<T extends ClusterItem> {
void onClusterItemInfoWindowLongClick(T item);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,14 @@ public interface ClusterRenderer<T extends ClusterItem> {

void setOnClusterInfoWindowClickListener(ClusterManager.OnClusterInfoWindowClickListener<T> listener);

void setOnClusterInfoWindowLongClickListener(ClusterManager.OnClusterInfoWindowLongClickListener<T> listener);

void setOnClusterItemClickListener(ClusterManager.OnClusterItemClickListener<T> listener);

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

void setOnClusterItemInfoWindowLongClickListener(ClusterManager.OnClusterItemInfoWindowLongClickListener<T> listener);

/**
* Called to set animation on or off
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,10 @@ public class DefaultClusterRenderer<T extends ClusterItem> implements ClusterRen

private ClusterManager.OnClusterClickListener<T> mClickListener;
private ClusterManager.OnClusterInfoWindowClickListener<T> mInfoWindowClickListener;
private ClusterManager.OnClusterInfoWindowLongClickListener<T> mInfoWindowLongClickListener;
private ClusterManager.OnClusterItemClickListener<T> mItemClickListener;
private ClusterManager.OnClusterItemInfoWindowClickListener<T> mItemInfoWindowClickListener;
private ClusterManager.OnClusterItemInfoWindowLongClickListener<T> mItemInfoWindowLongClickListener;

public DefaultClusterRenderer(Context context, GoogleMap map, ClusterManager<T> clusterManager) {
mMap = map;
Expand Down Expand Up @@ -155,6 +157,15 @@ public void onInfoWindowClick(Marker marker) {
}
});

mClusterManager.getMarkerCollection().setOnInfoWindowLongClickListener(new GoogleMap.OnInfoWindowLongClickListener() {
@Override
public void onInfoWindowLongClick(Marker marker) {
if (mItemInfoWindowLongClickListener != null) {
mItemInfoWindowLongClickListener.onClusterItemInfoWindowLongClick(mMarkerCache.get(marker));
}
}
});

mClusterManager.getClusterMarkerCollection().setOnMarkerClickListener(new GoogleMap.OnMarkerClickListener() {
@Override
public boolean onMarkerClick(Marker marker) {
Expand All @@ -170,14 +181,25 @@ public void onInfoWindowClick(Marker marker) {
}
}
});

mClusterManager.getClusterMarkerCollection().setOnInfoWindowLongClickListener(new GoogleMap.OnInfoWindowLongClickListener() {
@Override
public void onInfoWindowLongClick(Marker marker) {
if (mInfoWindowLongClickListener != null) {
mInfoWindowLongClickListener.onClusterInfoWindowLongClick(mClusterMarkerCache.get(marker));
}
}
});
}

@Override
public void onRemove() {
mClusterManager.getMarkerCollection().setOnMarkerClickListener(null);
mClusterManager.getMarkerCollection().setOnInfoWindowClickListener(null);
mClusterManager.getMarkerCollection().setOnInfoWindowLongClickListener(null);
mClusterManager.getClusterMarkerCollection().setOnMarkerClickListener(null);
mClusterManager.getClusterMarkerCollection().setOnInfoWindowClickListener(null);
mClusterManager.getClusterMarkerCollection().setOnInfoWindowLongClickListener(null);
}

private LayerDrawable makeClusterBackground() {
Expand Down Expand Up @@ -480,6 +502,11 @@ public void setOnClusterInfoWindowClickListener(ClusterManager.OnClusterInfoWind
mInfoWindowClickListener = listener;
}

@Override
public void setOnClusterInfoWindowLongClickListener(ClusterManager.OnClusterInfoWindowLongClickListener<T> listener) {
mInfoWindowLongClickListener = listener;
}

@Override
public void setOnClusterItemClickListener(ClusterManager.OnClusterItemClickListener<T> listener) {
mItemClickListener = listener;
Expand All @@ -490,6 +517,11 @@ public void setOnClusterItemInfoWindowClickListener(ClusterManager.OnClusterItem
mItemInfoWindowClickListener = listener;
}

@Override
public void setOnClusterItemInfoWindowLongClickListener(ClusterManager.OnClusterItemInfoWindowLongClickListener<T> listener) {
mItemInfoWindowLongClickListener = listener;
}

@Override
public void setAnimation(boolean animate) {
mAnimate = animate;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ public class MarkerManager extends MapObjectManager<Marker, MarkerManager.Collec
GoogleMap.OnInfoWindowClickListener,
GoogleMap.OnMarkerClickListener,
GoogleMap.OnMarkerDragListener,
GoogleMap.InfoWindowAdapter {
GoogleMap.InfoWindowAdapter,
GoogleMap.OnInfoWindowLongClickListener {

public MarkerManager(GoogleMap map) {
super(map);
Expand All @@ -43,6 +44,7 @@ public MarkerManager(GoogleMap map) {
void setListenersOnUiThread() {
if (mMap != null) {
mMap.setOnInfoWindowClickListener(this);
mMap.setOnInfoWindowLongClickListener(this);
mMap.setOnMarkerClickListener(this);
mMap.setOnMarkerDragListener(this);
mMap.setInfoWindowAdapter(this);
Expand Down Expand Up @@ -79,6 +81,14 @@ public void onInfoWindowClick(Marker marker) {
}
}

@Override
public void onInfoWindowLongClick(Marker marker) {
Collection collection = mAllObjects.get(marker);
if (collection != null && collection.mInfoWindowLongClickListener != null) {
collection.mInfoWindowLongClickListener.onInfoWindowLongClick(marker);
}
}

@Override
public boolean onMarkerClick(Marker marker) {
Collection collection = mAllObjects.get(marker);
Expand Down Expand Up @@ -119,6 +129,7 @@ protected void removeObjectFromMap(Marker object) {

public class Collection extends MapObjectManager.Collection {
private GoogleMap.OnInfoWindowClickListener mInfoWindowClickListener;
private GoogleMap.OnInfoWindowLongClickListener mInfoWindowLongClickListener;
private GoogleMap.OnMarkerClickListener mMarkerClickListener;
private GoogleMap.OnMarkerDragListener mMarkerDragListener;
private GoogleMap.InfoWindowAdapter mInfoWindowAdapter;
Expand Down Expand Up @@ -168,6 +179,10 @@ public void setOnInfoWindowClickListener(GoogleMap.OnInfoWindowClickListener inf
mInfoWindowClickListener = infoWindowClickListener;
}

public void setOnInfoWindowLongClickListener(GoogleMap.OnInfoWindowLongClickListener infoWindowLongClickListener) {
mInfoWindowLongClickListener = infoWindowLongClickListener;
}

public void setOnMarkerClickListener(GoogleMap.OnMarkerClickListener markerClickListener) {
mMarkerClickListener = markerClickListener;
}
Expand Down