Esempio n. 1
1
  @Override
  /**
   * - Capture the clicked cluster so we can use it in custom infoWindow - Check overall bounds of
   * items in cluster - If the bounds are empty (all hosts at same place) then let it pop the info
   * window - Otherwise, move the camera to show the bounds of the map
   */
  public boolean onClusterClick(Cluster<HostBriefInfo> cluster) {
    mLastClickedCluster = cluster; // remember for use later in the Adapter

    // Find out the bounds of the hosts currently in cluster
    LatLngBounds.Builder builder = new LatLngBounds.Builder();
    for (HostBriefInfo host : cluster.getItems()) {
      builder.include(host.getLatLng());
    }
    LatLngBounds bounds = builder.build();

    // If the hosts are not all at the same location, then change bounds of map.
    if (!bounds.southwest.equals(bounds.northeast)) {
      // Offset from edge of map in pixels when exploding cluster
      View mapView = findViewById(R.id.map_fragment);
      int padding_percent = getResources().getInteger(R.integer.cluster_explode_padding_percent);
      int padding = Math.min(mapView.getHeight(), mapView.getWidth()) * padding_percent / 100;
      CameraUpdate cu =
          CameraUpdateFactory.newLatLngBounds(
              bounds, mapView.getWidth(), mapView.getHeight(), padding);
      mMap.animateCamera(cu);
      return true;
    }
    showMultihostSelectDialog((ArrayList<HostBriefInfo>) cluster.getItems());
    return true;
  }
 @Override
 public boolean onClusterClick(Cluster<MarkerData> cluster) {
   String firstName = cluster.getItems().iterator().next().getName();
   Toast.makeText(this, cluster.getSize() + " (including " + firstName + ")", Toast.LENGTH_SHORT)
       .show();
   return true;
 }
Esempio n. 3
0
  @Override
  public boolean onClusterClick(Cluster<MyItem> cluster) {
    Collection<MyItem> collection = cluster.getItems();

    showIconDialog(collection);
    return true;
  }
Esempio n. 4
0
 @Override
 /** Start the Search tab with the members we have at this exact location. */
 public void onClusterInfoWindowClick(Cluster<HostBriefInfo> hostBriefInfoCluster) {
   Intent intent = new Intent(this, ListSearchTabActivity.class);
   intent.putParcelableArrayListExtra(
       "search_results", (ArrayList<HostBriefInfo>) hostBriefInfoCluster.getItems());
   startActivity(intent);
 }
Esempio n. 5
0
    /**
     * Attempt to determine the location status of items in the cluster, whether all in one location
     * or in a variety of locations.
     *
     * @param cluster
     * @return
     */
    protected ClusterStatus clusterLocationStatus(Cluster<HostBriefInfo> cluster) {

      HashSet<String> latLngs = new HashSet<String>();
      for (HostBriefInfo item : cluster.getItems()) {
        latLngs.add(item.getLatLng().toString());
      }

      // if cluster size and latLngs size are same, all are unique locations, so 'none'
      if (cluster.getSize() == latLngs.size()) {
        return ClusterStatus.none;
      }
      // If there is only one unique location, then all are in same location.
      else if (latLngs.size() == 1) {
        return ClusterStatus.all;
      }
      // Otherwise it's a mix of same and other location
      return ClusterStatus.some;
    }
    private void perform(MarkerModifier markerModifier) {
      // Don't show small clusters. Render the markers inside, instead.
      if (!shouldRenderAsCluster(cluster)) {
        for (T item : cluster.getItems()) {
          Marker marker = mMarkerCache.get(item);
          MarkerWithPosition markerWithPosition;
          if (marker == null) {
            MarkerOptions markerOptions = new MarkerOptions();
            if (animateFrom != null) {
              markerOptions.position(animateFrom);
            } else {
              markerOptions.position(item.getPosition());
            }
            onBeforeClusterItemRendered(item, markerOptions);
            marker = mClusterManager.getMarkerCollection().addMarker(markerOptions);
            markerWithPosition = new MarkerWithPosition(marker);
            mMarkerCache.put(item, marker);
            if (animateFrom != null) {
              markerModifier.animate(markerWithPosition, animateFrom, item.getPosition());
            }
          } else {
            markerWithPosition = new MarkerWithPosition(marker);
          }
          onClusterItemRendered(item, marker);
          newMarkers.add(markerWithPosition);
        }
        return;
      }

      MarkerOptions markerOptions =
          new MarkerOptions().position(animateFrom == null ? cluster.getPosition() : animateFrom);

      onBeforeClusterRendered(cluster, markerOptions);

      Marker marker = mClusterManager.getClusterMarkerCollection().addMarker(markerOptions);
      mMarkerToCluster.put(marker, cluster);
      mClusterToMarker.put(cluster, marker);
      MarkerWithPosition markerWithPosition = new MarkerWithPosition(marker);
      if (animateFrom != null) {
        markerModifier.animate(markerWithPosition, animateFrom, cluster.getPosition());
      }
      onClusterRendered(cluster, marker);
      newMarkers.add(markerWithPosition);
    }
    @Override
    protected void onBeforeClusterRendered(Cluster<Case> cluster, MarkerOptions markerOptions) {
      ArrayList<Case> case_array = new ArrayList<Case>(cluster.getItems());
      float avg = getAverageUnitPrice(case_array);
      int drawable_id = R.drawable.yellow_cluster_marker;

      if (avg <= average_unit_price_90p) {
        drawable_id = R.drawable.blue_cluster_marker;
      } else if (avg >= average_unit_price_110p) {
        drawable_id = R.drawable.red_cluster_marker;
      }

      DecimalFormat df = new DecimalFormat("0.0");
      float compare_value = Float.parseFloat(df.format(avg));

      if (Float.compare(avg, compare_value) > 0) {
        avg = Float.parseFloat(df.format(compare_value + 0.1f));
      } else {
        avg = compare_value;
      }

      Bitmap icon = generateMarkerIcon(drawable_id, String.valueOf(avg) + "萬/坪");
      markerOptions.icon(BitmapDescriptorFactory.fromBitmap(icon));
    }
    @Override
    protected void onBeforeClusterRendered(
        Cluster<MarkerData> cluster, MarkerOptions markerOptions) {
      super.onBeforeClusterRendered(cluster, markerOptions);
      List<Drawable> profilePhotos = new ArrayList<Drawable>(Math.min(4, cluster.getSize()));
      int width = dimension;
      int height = dimension;

      for (MarkerData markerData : cluster.getItems()) {
        // Draw 4 at most.
        if (profilePhotos.size() == 4) break;
        Drawable drawable =
            ContextCompat.getDrawable(getApplicationContext(), markerData.getProfilePhoto());
        //                        getResources().getDrawable(markerData.getProfilePhoto());
        drawable.setBounds(0, 0, width, height);
        profilePhotos.add(drawable);
      }
      MultiDrawable multiDrawable = new MultiDrawable(profilePhotos);
      multiDrawable.setBounds(0, 0, width, height);

      clusterImageView.setImageDrawable(multiDrawable);
      Bitmap icon = clusterIconGenerator.makeIcon(String.valueOf(cluster.getSize()));
      markerOptions.icon(BitmapDescriptorFactory.fromBitmap(icon));
    }
 @Override
 public Case getItem(int position) {
   return (Case) _cluster.getItems().toArray()[position];
 }