Skip to content

Commit

Permalink
Added an optional custom InfoWindowAdapter that passes the ClusterPoi…
Browse files Browse the repository at this point in the history
…nt to its methods.
  • Loading branch information
Sloy committed Sep 4, 2013
1 parent f6edd86 commit c03eb46
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 3 deletions.
42 changes: 40 additions & 2 deletions library/src/com/twotoasters/clusterkraf/Clusterkraf.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import android.os.Build;
import android.os.Handler;

import android.view.View;
import com.google.android.gms.maps.CameraUpdate;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
Expand Down Expand Up @@ -62,6 +63,7 @@ public Clusterkraf(GoogleMap map, Options options, ArrayList<InputPoint> points)
map.setOnCameraChangeListener(innerCallbackListener.clusteringOnCameraChangeListener);
map.setOnMarkerClickListener(innerCallbackListener);
map.setOnInfoWindowClickListener(innerCallbackListener);
map.setInfoWindowAdapter(innerCallbackListener);
}

showAllClusters();
Expand Down Expand Up @@ -265,7 +267,7 @@ public void onCancel() {
}

private static class InnerCallbackListener implements ClusteringOnCameraChangeListener.Host, ClusterTransitionsAnimation.Host, OnMarkerClickListener,
OnInfoWindowClickListener {
OnInfoWindowClickListener, GoogleMap.InfoWindowAdapter {

private final WeakReference<Clusterkraf> clusterkrafRef;

Expand Down Expand Up @@ -435,7 +437,43 @@ public void onInfoWindowClick(Marker marker) {
}

}
}

/**
* @see com.google.android.gms.maps.GoogleMap.InfoWindowAdapter
* getInfoWindow(com.google.android.gms.maps.model.Marker)
*/
@Override
public View getInfoWindow(Marker marker) {
View infoWindow = null;
Clusterkraf clusterkraf = clusterkrafRef.get();
if (clusterkraf != null) {
ClusterPoint clusterPoint = clusterkraf.currentClusterPointsByMarker.get(marker);
InfoWindowDownstreamAdapter infoWindowDownstreamAdapter = clusterkraf.options.getInfoWindowDownstreamAdapter();
if (infoWindowDownstreamAdapter != null) {
infoWindow = infoWindowDownstreamAdapter.getInfoWindow(marker, clusterPoint);
}
}
return infoWindow; // Google Map will handle it when null
}

/**
* @see com.google.android.gms.maps.GoogleMap.InfoWindowAdapter
* getInfoContents(com.google.android.gms.maps.model.Marker)
*/
@Override
public View getInfoContents(Marker marker) {
View infoWindow = null;
Clusterkraf clusterkraf = clusterkrafRef.get();
if (clusterkraf != null) {
ClusterPoint clusterPoint = clusterkraf.currentClusterPointsByMarker.get(marker);
InfoWindowDownstreamAdapter infoWindowDownstreamAdapter = clusterkraf.options.getInfoWindowDownstreamAdapter();
if (infoWindowDownstreamAdapter != null) {
infoWindow = infoWindowDownstreamAdapter.getInfoContents(marker, clusterPoint);
}
}
return infoWindow; // Google Map will handle it when null
}
}

abstract private class BaseClusteringTaskHost implements ClusteringTask.Host {

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.twotoasters.clusterkraf;

import android.view.View;
import com.google.android.gms.maps.model.Marker;

/**
* Created by rafa on 03/09/13.
*/
public interface InfoWindowDownstreamAdapter {

public View getInfoContents(Marker marker, ClusterPoint clusterPoint);

public View getInfoWindow(Marker marker, ClusterPoint clusterPoint);
}
23 changes: 22 additions & 1 deletion library/src/com/twotoasters/clusterkraf/Options.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,12 @@ public class Options {
*/
private OnInfoWindowClickDownstreamListener onInfoWindowClickDownstreamListener;

/**
* The InfoWindowDownstreamAdapter to receive callbacks when an info window
* needs to be displayed.
*/
private InfoWindowDownstreamAdapter infoWindowDownstreamAdapter;

/**
* When zooming to the bounds of a marker's backing ClusterPoint, zoom until
* all of the points are at least this far from the edge of the GoogleMap's
Expand Down Expand Up @@ -219,7 +225,22 @@ public void setOnInfoWindowClickDownstreamListener(OnInfoWindowClickDownstreamLi
this.onInfoWindowClickDownstreamListener = onInfoWindowClickDownstreamListener;
}

/**
/**
* @return the infoWindowDownstreamAdapter
*/
public InfoWindowDownstreamAdapter getInfoWindowDownstreamAdapter() {
return this.infoWindowDownstreamAdapter;
}

/**
* @param infoWindowDownstreamAdapter
* the infoWindowDownstreamAdapter to set
*/
public void setInfoWindowDownstreamAdapter(InfoWindowDownstreamAdapter infoWindowDownstreamAdapter) {
this.infoWindowDownstreamAdapter = infoWindowDownstreamAdapter;
}

/**
* @return the clusterClickBehavior
*/
ClusterClickBehavior getClusterClickBehavior() {
Expand Down

0 comments on commit c03eb46

Please sign in to comment.