package com.mymap;

//import android.app.Activity;
import android.os.Bundle;
import android.view.*;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import java.util.ArrayList;
import java.util.List;
import android.widget.LinearLayout;
import android.graphics.Canvas;
import android.graphics.drawable.Drawable;
import com.google.android.maps.GeoPoint;
import com.google.android.maps.ItemizedOverlay;
import com.google.android.maps.OverlayItem;
import com.google.android.maps.MapView;
import com.google.android.maps.MapActivity;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.widget.Toast;

public class HelloGoogleMaps extends MapActivity {
    /** Called when the activity is first created. */
	
	MapView mapView ;
	
	//Initialize this in onCreateOptions
	Menu myMenu = null;
	
	/* Use the LocationManager class to obtain GPS locations */

   // LocationManager mlocManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
	
	
	@Override
	protected boolean isRouteDisplayed() {
	return false;
	}
	@Override
	protected boolean isLocationDisplayed() {
	return false;
	}
	
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.mapview);
        mapView = (MapView) findViewById(R.id.mapview);
		mapView.setBuiltInZoomControls(true);
		
		Drawable marker=getResources().getDrawable(R.drawable.icon);
		marker.setBounds(0, 0, marker.getIntrinsicWidth(),
		marker.getIntrinsicHeight());
		InterestingLocations funPlaces = new InterestingLocations(marker);
		mapView.getOverlays().add(funPlaces);
		GeoPoint pt = funPlaces.getCenter(); // get the first-ranked point
		mapView.getController().setCenter(pt);
		mapView.getController().setZoom(13);
	    }
      
    public void myClickHandler(View target) {
		/** This method contains all tasks to be performed on button click event */
			
		switch(target.getId()) {
		
		case R.id.myloc:
			mapView.setSatellite(true);
			break;
		
		case R.id.desti:
			mapView.setStreetView(true);
			break;
		
		case R.id.calc:
			mapView.setSatellite(false);
			mapView.setStreetView(false);
			break;
		}
    }
    
    @Override
    public boolean onCreateOptionsMenu(Menu menu)
    {
    //call the parent to attach any system level menus
    super.onCreateOptionsMenu(menu);
    this.myMenu = menu;
    //add a few normal menus
    int base=Menu.FIRST; // value is 1
    
    menu.add(base,base,base,"Satellite View");
    menu.add(base,base+1,base+1,"Street View");
    menu.add(base,base+2,base+2,"Traffic View");
    menu.add(base,base+3,base+3,"Normal View");
    menu.add(base,base+4,base+4,"Hi!");
    return true;
    }
    
    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
    if (item.getItemId() == 1) {
    	mapView.setSatellite(true);
    }
    else if (item.getItemId() == 2) {
    	mapView.setStreetView(true);
    }
    else if (item.getItemId() == 3) {
    	mapView.setTraffic(true);
    }
    else if (item.getItemId() == 4) {
    	mapView.setSatellite(false);
    	mapView.setStreetView(false);
    	mapView.setTraffic(false);
    }
    else {
        myMenu.close();
    }
    //should return true if the menu item
    //is handled
    return true;
    }
        
} // HelloGoogleMap Ends

class InterestingLocations extends ItemizedOverlay {
	private List<OverlayItem> locations = new ArrayList<OverlayItem>();
	private Drawable marker;
	public InterestingLocations(Drawable marker)
	{
	super(marker);
	this.marker=marker;
	// create locations of interest
	GeoPoint sagar = new
	//GeoPoint((int)(28.418971*1000000),(int)(-81.581436*1000000));
	GeoPoint((int)(19.90972916019336*1000000),(int)( 75.35743474960327*1000000));
	GeoPoint bongo = new
	//GeoPoint((int)(28.410067*1000000),(int)(-81.583699*1000000));
	GeoPoint((int)(19.89985311418143*1000000),(int)( 75.3545218706131*1000000));
	//GeoPoint amar = new
	//GeoPoint((int)(28.410067*1000000),(int)(-81.583699*1000000));
	//GeoPoint((int)(19.85946487472614*1000000),(int)( 75.30402660369873*1000000));
	
	locations.add(new OverlayItem(sagar ,
	"Sagar Home", "Sagar Home"));
	locations.add(new OverlayItem(bongo,
	"Bongo Home", "Bongo Home"));
//	locations.add(new OverlayItem(amar,
//	"Amar Hostel","Amar Hostel"));
	populate();
	}
	@Override
	public void draw(Canvas canvas, MapView mapView, boolean shadow) {
	super.draw(canvas, mapView, shadow);
	boundCenterBottom(marker);
	}
	@Override
	protected OverlayItem createItem(int i) {
	return locations.get(i);
	}
	@Override
	public int size() {
	return locations.size();
	}
	}

