Android Open Source - clusterkraf Marker Options Chooser






From Project

Back to project page clusterkraf.

License

The source code is released under:

Apache License

If you think the Android project clusterkraf listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.twotoasters.clusterkraf;
/*from www  . j  a  v a 2  s .  co m*/
import java.lang.ref.WeakReference;

import android.graphics.Bitmap;

import com.google.android.gms.maps.model.BitmapDescriptorFactory;
import com.google.android.gms.maps.model.MarkerOptions;

/**
 * Implementations specify the icon and any other options to use on a
 * MarkerOptions object.
 * 
 * You can use one of the provided concrete classes and just implement its Host
 * interface, or if you need more sophisticated marker logic, you can extend
 * MarkerOptionsChooser.
 * 
 * For example, if you need to sometimes choose a bitmap and other times choose
 * a resource, you would need to extend the class.
 * 
 * If you always want to choose the same resource ID, you would implement the
 * ResourceChooser.Host such that it just returns the desired ID from your
 * R.drawable. `options.setMarkerOptionsChooser(new ResourceChooser(host));`
 * 
 * If you want to specify any other properties of the MarkerOptions beyond the
 * icon, such as the title or anchor, you will need to extend
 * MarkerOptionsChooser.
 * 
 * Subclasses do not need to set the position of the MarkerOptions object.
 * Clusterkraf handles that.
 */
public abstract class MarkerOptionsChooser {

  /**
   * Implementations set up the MarkerOptions object according to the
   * ClusterPoint
   * 
   * @param markerOptions
   *            The MarkerOptions object which will be used to add the Marker
   * @param clusterPoint
   *            The ClusterPoint object representing the InputPoint objects
   *            that have been clustered here due to pixel proximity
   */
  public abstract void choose(MarkerOptions markerOptions, ClusterPoint clusterPoint);

  /**
   * An example MarkerOptionsChooser that sets the MarkerOptions object's icon
   * using a bitmap from its host.
   */
  public static class BitmapChooser extends MarkerOptionsChooser {

    private final WeakReference<Host> hostRef;

    public BitmapChooser(Host host) {
      this.hostRef = new WeakReference<Host>(host);
    }

    @Override
    public void choose(MarkerOptions markerOptions, ClusterPoint clusterPoint) {
      Host host = hostRef.get();
      if (host != null) {
        Bitmap bitmap = host.getIconBitmap(clusterPoint);
        markerOptions.icon(BitmapDescriptorFactory.fromBitmap(bitmap));
      }
    }

    public interface Host {
      Bitmap getIconBitmap(ClusterPoint clusterPoint);
    }
  }

  /**
   * An example MarkerOptionsChooser that sets the MarkerOptions object's icon
   * using a resource ID from its host.
   */
  public static class ResourceChooser extends MarkerOptionsChooser {

    private final WeakReference<Host> hostRef;

    public ResourceChooser(Host host) {
      this.hostRef = new WeakReference<Host>(host);
    }

    @Override
    public void choose(MarkerOptions markerOptions, ClusterPoint clusterPoint) {
      Host host = hostRef.get();
      if (host != null) {
        int resource = host.getIconResource(clusterPoint);
        markerOptions.icon(BitmapDescriptorFactory.fromResource(resource));
      }
    }

    public interface Host {
      int getIconResource(ClusterPoint clusterPoint);
    }
  }

}




Java Source Code List

android.UnusedStub.java
com.twotoasters.clusterkraf.AnimatedTransition.java
com.twotoasters.clusterkraf.BasePoint.java
com.twotoasters.clusterkraf.ClusterPoint.java
com.twotoasters.clusterkraf.ClusterTransitionsAnimation.java
com.twotoasters.clusterkraf.ClusterTransitionsBuildingTask.java
com.twotoasters.clusterkraf.ClusterTransitions.java
com.twotoasters.clusterkraf.ClusteringOnCameraChangeListener.java
com.twotoasters.clusterkraf.ClusteringTask.java
com.twotoasters.clusterkraf.Clusterkraf.java
com.twotoasters.clusterkraf.ClustersBuilder.java
com.twotoasters.clusterkraf.InfoWindowDownstreamAdapter.java
com.twotoasters.clusterkraf.InputPoint.java
com.twotoasters.clusterkraf.MarkerOptionsChooser.java
com.twotoasters.clusterkraf.OnInfoWindowClickDownstreamListener.java
com.twotoasters.clusterkraf.OnMarkerClickDownstreamListener.java
com.twotoasters.clusterkraf.Options.java
com.twotoasters.clusterkraf.sample.AdvancedModeFragment.java
com.twotoasters.clusterkraf.sample.DelayedIndeterminateProgressBarRunnable.java
com.twotoasters.clusterkraf.sample.MainActivity.java
com.twotoasters.clusterkraf.sample.MarkerData.java
com.twotoasters.clusterkraf.sample.NormalModeFragment.java
com.twotoasters.clusterkraf.sample.RandomPointsProvider.java
com.twotoasters.clusterkraf.sample.SampleActivity.java
com.twotoasters.clusterkraf.sample.SingleChoiceDialogFragment.java
com.twotoasters.clusterkraf.sample.ToastedMarkerOptionsChooser.java
com.twotoasters.clusterkraf.sample.ToastedOnMarkerClickDownstreamListener.java
com.twotoasters.clusterkraf.sample.TwoToastersActivity.java
com.twotoasters.clusterkraf.util.Distance.java