List of usage examples for android.graphics Rect setIntersect
@CheckResult public boolean setIntersect(Rect a, Rect b)
From source file:org.immopoly.android.widget.ImmoscoutPlacesOverlay.java
/** * clusterize flats based on their supposed marker position *//*from w ww . jav a2 s. c om*/ public void clusterize() { if (mFlats == null) return; final Flats flats = mFlats; final ArrayList<ClusterItem> items = tmpItems; final Projection projection = mMapView.getProjection(); final Point screenPos = new Point(); items.clear(); // create tmp items with flat, geopoint & screenBounds for (int i = 0; i < flats.size(); i++) { final Flat flat = flats.get(i); if (flat.lat == 0 && flat.lng == 0 || !flat.visible) continue; Rect itemBounds = new Rect(markerBounds); GeoPoint point = new GeoPoint((int) (flat.lat * 1E6), (int) (flat.lng * 1E6)); projection.toPixels(point, screenPos); itemBounds.offset(screenPos.x, screenPos.y); items.add(new ClusterItem(flat, point, itemBounds)); } // join ClusterItems if their markers would intersect ArrayList<ClusterItem> newItems = new ArrayList<ClusterItem>(); final Rect intersection = new Rect(); final int size = items.size(); for (int i = 0; i < size; i++) { final ClusterItem item = (ClusterItem) items.get(i); if (item.consumed) continue; for (int j = i + 1; j < size; j++) { final ClusterItem otherItem = (ClusterItem) items.get(j); if (!otherItem.consumed && intersection.setIntersect(item.screenBounds, otherItem.screenBounds) && intersection.width() * intersection.height() >= MIN_INTERSECTION_AREA) item.add(otherItem); } newItems.add(item); } tmpItems.clear(); tmpItems.addAll(newItems); // see http://groups.google.com/group/android-developers/browse_thread/thread/38b11314e34714c3 setLastFocusedIndex(-1); populate(); }