Permalink
Browse files

Rewrote the overlay class; squashed a bug. Victory is near!

  • Loading branch information...
1 parent c803b01 commit 025a92daa12b51823ff3a09c7124b09c0d3b0d76 @bravelittlescientist bravelittlescientist committed Mar 24, 2012
Showing with 37 additions and 75 deletions.
  1. +12 −14 src/com/teamsexy/helloTabs/FelixMapActivity.java
  2. +25 −61 src/com/teamsexy/helloTabs/FelixOverlay.java
@@ -24,12 +24,11 @@
*/
public class FelixMapActivity extends MapActivity {
- private MapController mapController;
private MapView mapView;
- private LocationManager locationManager;
private FelixOverlay itemizedoverlay;
+ private MapController mapController;
+ private LocationManager locationManager;
private MyLocationOverlay myLocationOverlay;
- //private GeoPoint homebase = new GeoPoint(34, -118);
public void onCreate(Bundle bundle) {
super.onCreate(bundle);
@@ -38,9 +37,14 @@ public void onCreate(Bundle bundle) {
// Configure the Map
mapView = (MapView) findViewById(R.id.mapview);
mapView.setBuiltInZoomControls(true);
+
+ Drawable drawable = this.getResources().getDrawable(R.drawable.add_spot);
+ itemizedoverlay = new FelixOverlay(drawable, this);
+
mapView.setSatellite(true);
mapController = mapView.getController();
- mapController.setZoom(14); // Zoon 1 is world view
+ mapController.setZoom(14);
+
locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0,
0, new GeoUpdateHandler());
@@ -54,10 +58,6 @@ public void run() {
myLocationOverlay.getMyLocation());
}
});
-
- Drawable drawable = this.getResources().getDrawable(R.drawable.add_spot);
- itemizedoverlay = new FelixOverlay(this, drawable);
- createMarker();
}
@Override
@@ -72,9 +72,8 @@ public void onLocationChanged(Location location) {
int lat = (int) (location.getLatitude() * 1E6);
int lng = (int) (location.getLongitude() * 1E6);
GeoPoint point = new GeoPoint(lat, lng);
- createMarker();
- mapController.animateTo(point); // mapController.setCenter(point);
-
+ createMarker(point, "Test", "Test2");
+ mapController.animateTo(point);
}
@Override
@@ -90,9 +89,8 @@ public void onStatusChanged(String provider, int status, Bundle extras) {
}
}
- private void createMarker() {
- GeoPoint p = mapView.getMapCenter();
- OverlayItem overlayitem = new OverlayItem(p, "", "");
+ private void createMarker(GeoPoint p, String t1, String t2) {
+ OverlayItem overlayitem = new OverlayItem(p, t1, t2);
itemizedoverlay.addOverlay(overlayitem);
if (itemizedoverlay.size() > 0) {
mapView.getOverlays().add(itemizedoverlay);
@@ -1,11 +1,10 @@
package com.teamsexy.helloTabs;
+import java.util.ArrayList;
+
import android.app.AlertDialog;
-import android.app.AlertDialog.Builder;
import android.content.Context;
-import android.content.DialogInterface;
import android.graphics.drawable.Drawable;
-import android.widget.Toast;
import com.google.android.maps.ItemizedOverlay;
import com.google.android.maps.OverlayItem;
@@ -16,74 +15,39 @@
* @author genia / Lars Vogel
*
*/
-public class FelixOverlay extends ItemizedOverlay<OverlayItem> {
- private static int maxNum = 5;
- private OverlayItem overlays[] = new OverlayItem[maxNum];
- private int index = 0;
- private boolean full = false;
- private Context context;
- private OverlayItem previousoverlay;
+public class FelixOverlay extends ItemizedOverlay<OverlayItem> {
- public FelixOverlay(Context context, Drawable defaultMarker) {
+ private ArrayList<OverlayItem> mOverlays = new ArrayList<OverlayItem>();
+ private Context mContext;
+
+ public FelixOverlay(Drawable defaultMarker, Context context) {
super(boundCenterBottom(defaultMarker));
- this.context = context;
+ mContext = context;
}
-
+
+ public void addOverlay(OverlayItem overlay) {
+ mOverlays.add(overlay);
+ populate();
+ }
+
@Override
protected OverlayItem createItem(int i) {
- return overlays[i];
+ return mOverlays.get(i);
}
-
+
@Override
public int size() {
- if (full) {
- return overlays.length;
- } else {
- return index;
- }
-
+ return mOverlays.size();
}
-
- public void addOverlay(OverlayItem overlay) {
- if (previousoverlay != null) {
- if (index < maxNum) {
- overlays[index] = previousoverlay;
- } else {
- index = 0;
- full = true;
- overlays[index] = previousoverlay;
- }
- index++;
- populate();
- }
- this.previousoverlay = overlay;
- }
-
+
+ @Override
protected boolean onTap(int index) {
- OverlayItem overlayItem = overlays[index];
- Builder builder = new AlertDialog.Builder(context);
- builder.setMessage("This will end the activity");
- builder.setCancelable(true);
- builder.setPositiveButton("I agree", new OkOnClickListener());
- builder.setNegativeButton("No, no", new CancelOnClickListener());
- AlertDialog dialog = builder.create();
- dialog.show();
- return true;
- };
-
- private final class CancelOnClickListener implements
- DialogInterface.OnClickListener {
- public void onClick(DialogInterface dialog, int which) {
- Toast.makeText(context, "You clicked yes", Toast.LENGTH_LONG)
- .show();
- }
- }
-
- private final class OkOnClickListener implements
- DialogInterface.OnClickListener {
- public void onClick(DialogInterface dialog, int which) {
- Toast.makeText(context, "You clicked no", Toast.LENGTH_LONG).show();
- }
+ OverlayItem item = mOverlays.get(index);
+ AlertDialog.Builder dialog = new AlertDialog.Builder(mContext);
+ dialog.setTitle(item.getTitle());
+ dialog.setMessage(item.getSnippet());
+ dialog.show();
+ return true;
}
}

0 comments on commit 025a92d

Please sign in to comment.