aboutsummaryrefslogtreecommitdiff
path: root/src/net/cbaines/suma/BuildingNumOverlay.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/net/cbaines/suma/BuildingNumOverlay.java')
-rw-r--r--src/net/cbaines/suma/BuildingNumOverlay.java70
1 files changed, 50 insertions, 20 deletions
diff --git a/src/net/cbaines/suma/BuildingNumOverlay.java b/src/net/cbaines/suma/BuildingNumOverlay.java
index 4bd5f3a..32616a7 100644
--- a/src/net/cbaines/suma/BuildingNumOverlay.java
+++ b/src/net/cbaines/suma/BuildingNumOverlay.java
@@ -25,12 +25,10 @@ import java.util.Collections;
import java.util.Iterator;
import java.util.List;
-
import org.osmdroid.views.MapView;
import org.osmdroid.views.MapView.Projection;
import org.osmdroid.views.overlay.Overlay;
-import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
@@ -62,13 +60,13 @@ public class BuildingNumOverlay extends Overlay {
private static final String TAG = "BuildingNumOverlay";
- private final Context context;
+ private final MapActivity context;
private Dao<Building, String> buildingDao;
private float userScale = 1f;
- public BuildingNumOverlay(Context context, List<Building> buildings) throws SQLException {
+ public BuildingNumOverlay(MapActivity context, List<Building> buildings) throws SQLException {
super(context);
this.context = context;
@@ -93,25 +91,29 @@ public class BuildingNumOverlay extends Overlay {
/**
* Draw a marker on each of our items. populate() must have been called first.<br/>
* <br/>
- * The marker will be drawn twice for each Item in the Overlay--once in the shadow phase, skewed and darkened, then again in the non-shadow phase. The
- * bottom-center of the marker will be aligned with the geographical coordinates of the Item.<br/>
+ * The marker will be drawn twice for each Item in the Overlay--once in the shadow phase, skewed and darkened, then
+ * again in the non-shadow phase. The bottom-center of the marker will be aligned with the geographical coordinates
+ * of the Item.<br/>
* <br/>
- * The order of drawing may be changed by overriding the getIndexToDraw(int) method. An item may provide an alternate marker via its
- * OverlayItem.getMarker(int) method. If that method returns null, the default marker is used.<br/>
+ * The order of drawing may be changed by overriding the getIndexToDraw(int) method. An item may provide an
+ * alternate marker via its OverlayItem.getMarker(int) method. If that method returns null, the default marker is
+ * used.<br/>
* <br/>
* The focused item is always drawn last, which puts it visually on top of the other items.<br/>
*
* @param canvas
- * the Canvas upon which to draw. Note that this may already have a transformation applied, so be sure to leave it the way you found it
+ * the Canvas upon which to draw. Note that this may already have a transformation applied, so be sure to
+ * leave it the way you found it
* @param mapView
- * the MapView that requested the draw. Use MapView.getProjection() to convert between on-screen pixels and latitude/longitude pairs
+ * the MapView that requested the draw. Use MapView.getProjection() to convert between on-screen pixels
+ * and latitude/longitude pairs
* @param shadow
* if true, draw the shadow layer. If false, draw the overlay contents.
*/
@Override
public void draw(final Canvas canvas, final MapView mapView, final boolean shadow) {
- if (shadow) {
+ if (shadow || !isEnabled()) {
return;
}
@@ -180,43 +182,72 @@ public class BuildingNumOverlay extends Overlay {
}
@Override
- public boolean onSingleTapUp(final MotionEvent event, final MapView mapView) {
+ public boolean onSingleTapConfirmed(final MotionEvent event, final MapView mapView) {
+
if (!this.isEnabled())
return false;
final Building building = getSelectedItem(event, mapView);
if (building == null) {
- Log.i(TAG, "No building pressed");
+ // Log.v(TAG, "No building pressed");
return false;
} else {
- Log.i(TAG, "building Pressed " + building.id);
+ Log.v(TAG, "building Pressed " + building.id);
+
+ if (context.activityToast == null) {
+ context.activityToast = Toast.makeText(context, building.name + " (" + building.id + ")",
+ Toast.LENGTH_SHORT);
+ } else {
+ context.activityToast.setDuration(Toast.LENGTH_SHORT);
+ context.activityToast.setText(building.name + " (" + building.id + ")");
+ }
+ context.activityToast.show();
- Toast.makeText(context, building.name + " (" + building.id + ")", Toast.LENGTH_SHORT).show();
return true;
}
}
+ public boolean onDoubleTap(final MotionEvent e, final MapView mapView) {
+ return false;
+ }
+
@Override
public boolean onLongPress(final MotionEvent event, final MapView mapView) {
+
if (!this.isEnabled())
return false;
final Building building = getSelectedItem(event, mapView);
if (building == null) {
- Log.i(TAG, "No building pressed");
+ // Log.v(TAG, "No building pressed");
return false;
} else {
- Log.i(TAG, "building Pressed " + building.id);
+ Log.v(TAG, "building Pressed " + building.id);
if (building.favourite) {
building.favourite = false;
- Toast.makeText(context, building.id + " removed from favourites", Toast.LENGTH_SHORT).show();
+ if (context.activityToast == null) {
+ context.activityToast = Toast.makeText(context, building.id + " removed from favourites",
+ Toast.LENGTH_SHORT);
+ } else {
+ context.activityToast.setDuration(Toast.LENGTH_SHORT);
+ context.activityToast.setText(building.id + " removed from favourites");
+ }
+ context.activityToast.show();
+
} else {
- Toast.makeText(context, building.id + " made a favourite", Toast.LENGTH_SHORT).show();
+ if (context.activityToast == null) {
+ context.activityToast = Toast.makeText(context, building.id + " made a favourite",
+ Toast.LENGTH_SHORT);
+ } else {
+ context.activityToast.setDuration(Toast.LENGTH_SHORT);
+ context.activityToast.setText(building.id + " made a favourite");
+ }
+ context.activityToast.show();
building.favourite = true;
}
@@ -224,7 +255,6 @@ public class BuildingNumOverlay extends Overlay {
try {
buildingDao.update(building);
} catch (SQLException e) {
- // TODO Auto-generated catch block
e.printStackTrace();
}