Android Open Source - SmartNavi Itemized Overlay With Bubble






From Project

Back to project page SmartNavi.

License

The source code is released under:

Apache License

If you think the Android project SmartNavi 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 org.osmdroid.bonuspack.overlays;
//from w w w  .j  a v  a 2s. c  o m
import java.util.ArrayList;
import java.util.List;
import org.osmdroid.bonuspack.utils.BonusPackHelper;
import org.osmdroid.util.BoundingBoxE6;
import org.osmdroid.util.GeoPoint;
import org.osmdroid.views.MapView;
import org.osmdroid.views.Projection;
import org.osmdroid.views.overlay.ItemizedIconOverlay;
import org.osmdroid.views.overlay.OverlayItem;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Point;
import android.util.Log;

/**
 * A collection of icons placed at particular points on the map's surface. 
 * When the user taps on an icon, an InfoWindow or "bubble" will open and display item attributes. <br>
 * Items must be ExtendedOverlayItem. <br>
 * 
 * @see ExtendedOverlayItem
 * @see InfoWindow
 * @deprecated now use Marker instead. 
 * @author M.Kergall
 */
@Deprecated public class ItemizedOverlayWithBubble<Item extends OverlayItem> extends ItemizedIconOverlay<Item> {
  //protected List<Item> mItemsList;
  protected InfoWindow mBubble; //only one for all items of this overlay => one at a time
  protected OverlayItem mItemWithBubble; //the item currently showing the bubble. Null if none. 

  static int layoutResId = 0;
  
  public ItemizedOverlayWithBubble(final Context context, final List<Item> aList, 
      final MapView mapView, final InfoWindow bubble) {
    super(context, aList, new OnItemGestureListener<Item>() {
            @Override public boolean onItemSingleTapUp(final int index, final OverlayItem item) {
                    return false;
            }
            @Override public boolean onItemLongPress(final int index, final OverlayItem item) {
                    return false;
            }
      } );
    //mItemsList = aList;
    if (bubble != null){
      mBubble = bubble;
    } else {
      //build default bubble:
      if (layoutResId == 0){
        String packageName = context.getPackageName();
        layoutResId = context.getResources().getIdentifier("layout/bonuspack_bubble", null, packageName);
        if (layoutResId == 0)
          Log.e(BonusPackHelper.LOG_TAG, "ItemizedOverlayWithBubble: layout/bonuspack_bubble not found in "+packageName);
      }
      mBubble = new DefaultInfoWindow(layoutResId, mapView);
    }
    mItemWithBubble = null;
  }

  public ItemizedOverlayWithBubble(final Context context, final List<Item> aList, 
      final MapView mapView) {
    this(context, aList, mapView, null);
  }

  public void showBubbleOnItem(final ExtendedOverlayItem eItem, final MapView mapView, boolean panIntoView) {
    mItemWithBubble = eItem;
    if (eItem != null){
      eItem.showBubble(mBubble, mapView, panIntoView);
      //setFocus((Item)eItem);
    }
  }
  
  public BoundingBoxE6 getBoundingBoxE6(){
    ArrayList<GeoPoint> points = new ArrayList<GeoPoint>(mItemList.size());
    for (Item item:mItemList){
      points.add(item.getPoint());
    }
    return BoundingBoxE6.fromGeoPoints(points);
  }
  
  /**
   * Opens the bubble on the item. 
   * For each ItemizedOverlay, only one bubble is opened at a time. 
   * If you want more bubbles opened simultaneously, use many ItemizedOverlays. 
   * 
   * @param index of the overlay item to show
   * @param mapView
   * @param panIntoView true if you want the map view to be centered on it. 
   */
  public void showBubbleOnItem(final int index, final MapView mapView, boolean panIntoView) {
    ExtendedOverlayItem eItem = (ExtendedOverlayItem)(getItem(index));
    showBubbleOnItem(eItem, mapView, panIntoView);
  }
  
  /**
   * Close the bubble (if it's opened). 
   */
  public void hideBubble(){
    mBubble.close();
    mItemWithBubble = null;
  }
  
  @Override protected boolean onSingleTapUpHelper(final int index, final Item item, final MapView mapView) {
    showBubbleOnItem(index, mapView, true);
    return true;
  }
  
  /** @return the item currently showing the bubble, or null if none.  */
  public OverlayItem getBubbledItem(){
    if (mBubble.isOpen())
      return mItemWithBubble;
    else
      return null;
  }
  
  /** @return the index of the item currently showing the bubble, or -1 if none.  */
  public int getBubbledItemId(){
    OverlayItem item = getBubbledItem();
    if (item == null)
      return -1;
    else
      return mItemList.indexOf(item);
  }
  
  @Override public synchronized Item removeItem(final int position){
    Item result = super.removeItem(position);
    if (mItemWithBubble == result){
      hideBubble();
    }
    return result;
  }
  
  @Override public synchronized boolean removeItem(final Item item){
    boolean result = super.removeItem(item);
    if (mItemWithBubble == item){
      hideBubble();
    }
    return result;
  }
  
  @Override public synchronized void removeAllItems(){
    super.removeAllItems();
    hideBubble();
  }

  @Override public synchronized void draw(final Canvas canvas, final MapView mapView, final boolean shadow) {
    //1. Fixing drawing focused item on top in ItemizedOverlay (osmdroid issue 354):
    //2. Fixing lack of synchronization on mItemList
    if (shadow) {
            return;
    }
    final Projection pj = mapView.getProjection();
    final int size = mItemList.size() - 1;
    final Point mCurScreenCoords = new Point();
    
    /* Draw in backward cycle, so the items with the least index are on the front. */
    for (int i = size; i >= 0; i--) {
          final Item item = getItem(i);
      if (item != mItemWithBubble){
            pj.toPixels(item.getPoint(), mCurScreenCoords);
            onDrawItem(canvas, item, mCurScreenCoords, mapView.getMapOrientation());
      }
    }
    //draw focused item last:
    if (mItemWithBubble != null){
          pj.toPixels(mItemWithBubble.getPoint(), mCurScreenCoords);
          onDrawItem(canvas, (Item)mItemWithBubble, mCurScreenCoords, mapView.getMapOrientation());
    }
    }
  
}




Java Source Code List

com.ilm.sandwich.BuildConfig.java
com.ilm.sandwich.Config.java
com.ilm.sandwich.GoogleMapActivity.java
com.ilm.sandwich.Info.java
com.ilm.sandwich.MySupportMapFragment.java
com.ilm.sandwich.OsmMapActivity.java
com.ilm.sandwich.Settings.java
com.ilm.sandwich.Smartgeo.java
com.ilm.sandwich.StartChooser.java
com.ilm.sandwich.TouchableWrapper.java
com.ilm.sandwich.helferklassen.HttpRequests.java
com.ilm.sandwich.helferklassen.Locationer.java
com.ilm.sandwich.helferklassen.MapDownload.java
com.ilm.sandwich.helferklassen.MyItemizedOverlay.java
com.ilm.sandwich.helferklassen.PlacesAutoComplete.java
com.ilm.sandwich.helferklassen.PlacesTextSearch.java
com.ilm.sandwich.helferklassen.Rechnung.java
com.ilm.sandwich.helferklassen.SuggestionsAdapter.java
org.osmdroid.bonuspack.BuildConfig.java
org.osmdroid.bonuspack.BuildConfig.java
org.osmdroid.bonuspack.cachemanager.CacheManager.java
org.osmdroid.bonuspack.clustering.GridMarkerClusterer.java
org.osmdroid.bonuspack.clustering.MarkerClusterer.java
org.osmdroid.bonuspack.clustering.StaticCluster.java
org.osmdroid.bonuspack.kml.ColorStyle.java
org.osmdroid.bonuspack.kml.IconStyle.java
org.osmdroid.bonuspack.kml.KmlDocument.java
org.osmdroid.bonuspack.kml.KmlFeature.java
org.osmdroid.bonuspack.kml.KmlFolder.java
org.osmdroid.bonuspack.kml.KmlGeometry.java
org.osmdroid.bonuspack.kml.KmlGroundOverlay.java
org.osmdroid.bonuspack.kml.KmlLineString.java
org.osmdroid.bonuspack.kml.KmlMultiGeometry.java
org.osmdroid.bonuspack.kml.KmlPlacemark.java
org.osmdroid.bonuspack.kml.KmlPoint.java
org.osmdroid.bonuspack.kml.KmlPolygon.java
org.osmdroid.bonuspack.kml.LineStyle.java
org.osmdroid.bonuspack.kml.Style.java
org.osmdroid.bonuspack.location.FlickrPOIProvider.java
org.osmdroid.bonuspack.location.GeoNamesPOIProvider.java
org.osmdroid.bonuspack.location.GeocoderGisgraphy.java
org.osmdroid.bonuspack.location.GeocoderNominatimOld.java
org.osmdroid.bonuspack.location.GeocoderNominatim.java
org.osmdroid.bonuspack.location.NominatimPOIProvider.java
org.osmdroid.bonuspack.location.POI.java
org.osmdroid.bonuspack.location.PicasaPOIProvider.java
org.osmdroid.bonuspack.mapsforge.GenericMapView.java
org.osmdroid.bonuspack.mapsforge.MapsForgeTileModuleProvider.java
org.osmdroid.bonuspack.mapsforge.MapsForgeTileProvider.java
org.osmdroid.bonuspack.mapsforge.MapsForgeTileSource.java
org.osmdroid.bonuspack.overlays.DefaultInfoWindow.java
org.osmdroid.bonuspack.overlays.ExtendedOverlayItem.java
org.osmdroid.bonuspack.overlays.FolderOverlay.java
org.osmdroid.bonuspack.overlays.GroundOverlay.java
org.osmdroid.bonuspack.overlays.InfoWindow.java
org.osmdroid.bonuspack.overlays.ItemizedOverlayWithBubble.java
org.osmdroid.bonuspack.overlays.MapEventsOverlay.java
org.osmdroid.bonuspack.overlays.MapEventsReceiver.java
org.osmdroid.bonuspack.overlays.MarkerInfoWindow.java
org.osmdroid.bonuspack.overlays.Marker.java
org.osmdroid.bonuspack.overlays.Polygon.java
org.osmdroid.bonuspack.overlays.Polyline.java
org.osmdroid.bonuspack.routing.GoogleRoadManager.java
org.osmdroid.bonuspack.routing.MapQuestRoadManager.java
org.osmdroid.bonuspack.routing.OSRMRoadManager.java
org.osmdroid.bonuspack.routing.RoadLeg.java
org.osmdroid.bonuspack.routing.RoadManager.java
org.osmdroid.bonuspack.routing.RoadNode.java
org.osmdroid.bonuspack.routing.Road.java
org.osmdroid.bonuspack.utils.BonusPackHelper.java
org.osmdroid.bonuspack.utils.DouglasPeuckerReducer.java
org.osmdroid.bonuspack.utils.HttpConnection.java
org.osmdroid.bonuspack.utils.PolylineEncoder.java
org.osmdroid.bonuspack.utils.WebImageCache.java