BusStopOverlay.java :  » App » uconn-map-project » com » example » helloAndroid » Android Open Source

Android Open Source » App » uconn map project 
uconn map project » com » example » helloAndroid » BusStopOverlay.java
package com.example.helloAndroid;

import java.util.ArrayList;

import android.content.Context;
import android.content.Intent;
import android.graphics.Point;
import android.graphics.drawable.Drawable;

import com.google.android.maps.GeoPoint;
import com.google.android.maps.ItemizedOverlay;
import com.google.android.maps.MapView;
import com.google.android.maps.OverlayItem;
import com.google.android.maps.Projection;

public class BusStopOverlay extends ItemizedOverlay<OverlayItem> {
  
  ArrayList<OverlayItem> mOverlays;
  Context mContext;
  
  public BusStopOverlay(Drawable defaultMarker) {
    super(boundCenter(defaultMarker));
  }
  
  public BusStopOverlay(Drawable defaultMarker, Context c) {
    super(boundCenter(defaultMarker));
    mOverlays = new ArrayList<OverlayItem>();
    mContext = c;
  }
  
  @Override
  protected OverlayItem createItem(int i) {
    return mOverlays.get(i);
  }
  
  public void addOverlay(OverlayItem o) {
    mOverlays.add(o);
    populate();
  }

  @Override
  public int size() {
    return mOverlays.size();
  }
  
  @Override
  protected boolean onTap(int i) {
    /*
    OverlayItem item = mOverlays.get(i);
    
    AlertDialog.Builder dialog = new AlertDialog.Builder(mContext);
    dialog.setTitle(item.getTitle());
    dialog.setMessage(item.getSnippet());
    dialog.show();
    
    Toast.makeText(mContext, item.getSnippet(), Toast.LENGTH_SHORT).show();
    
    Intent intent = new Intent();
    
    intent.setClassName("com.team6.utility", "com.team6.utility.TimeListActivity");
    
    mContext.startActivity(intent);
    */
    
    Intent myIntent = new Intent();
    myIntent.setClassName("com.team6.utility", "com.team6.utility.TimeListActivity");
    //myIntent.putExtra("com.android.samples.SpecialValue", "Hello, Joe!"); // key/value pair, where key needs current package prefix.
    mContext.startActivity(myIntent); 
    
    return true;
  }
  
  @Override
  public boolean onTap(GeoPoint p, MapView mapView) {
    Projection proj = mapView.getProjection();
    
    Point tPoint = proj.toPixels(p, null);
    Point oPoint = new Point();
    
    for(int i = 0; i < size(); i++) {
      proj.toPixels(mOverlays.get(i).getPoint(), oPoint);
      
      if( Math.abs(oPoint.x - tPoint.x) < 25 &&
        Math.abs(oPoint.y - tPoint.y) < 25) {
        onTap(i);
        return true;
      }  
    }
    return false;
  }
}
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.