aboutsummaryrefslogtreecommitdiff
path: root/src/net/cbaines/suma/BusStopOverlay.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/net/cbaines/suma/BusStopOverlay.java')
-rw-r--r--src/net/cbaines/suma/BusStopOverlay.java173
1 files changed, 106 insertions, 67 deletions
diff --git a/src/net/cbaines/suma/BusStopOverlay.java b/src/net/cbaines/suma/BusStopOverlay.java
index 639f851..06a1729 100644
--- a/src/net/cbaines/suma/BusStopOverlay.java
+++ b/src/net/cbaines/suma/BusStopOverlay.java
@@ -28,7 +28,6 @@ import org.osmdroid.views.MapView.Projection;
import org.osmdroid.views.overlay.Overlay;
import android.app.Activity;
-import android.content.Context;
import android.content.Intent;
import android.graphics.Canvas;
import android.graphics.Paint;
@@ -45,7 +44,7 @@ import com.j256.ormlite.dao.Dao;
public class BusStopOverlay extends Overlay implements RouteColorConstants {
- private List<BusStop> busStops;
+ List<BusStop> busStops;
private final Point mCurScreenCoords = new Point();
private final Point mTouchScreenPoint = new Point();
@@ -60,7 +59,7 @@ public class BusStopOverlay extends Overlay implements RouteColorConstants {
private static final String TAG = "BusStopOverlay";
- private final Context context;
+ private final MapActivity context;
private Dao<BusStop, String> busStopDao;
@@ -68,9 +67,8 @@ public class BusStopOverlay extends Overlay implements RouteColorConstants {
private boolean[] routes = new boolean[5];
- public BusStopOverlay(Context context) throws SQLException {
+ public BusStopOverlay(MapActivity context, List<BusStop> busStops) throws SQLException {
super(context);
- final long startTime = System.currentTimeMillis();
this.context = context;
@@ -84,9 +82,7 @@ public class BusStopOverlay extends Overlay implements RouteColorConstants {
paint.setStyle(Style.FILL);
paint.setStrokeWidth(6);
- Log.i(TAG, "Begining to load bus stops in to overlay " + (System.currentTimeMillis() - startTime));
- busStops = busStopDao.queryForAll();
- Log.i(TAG, "Finished loading bus stops in to overlay " + (System.currentTimeMillis() - startTime));
+ this.busStops = busStops;
}
void setRoutes(int route, boolean visible) {
@@ -122,20 +118,21 @@ public class BusStopOverlay extends Overlay implements RouteColorConstants {
boolean drawing = false;
- for (int i = 0; i < 5; i++) {
- if ((stopRoutes & (1 << i)) != 0) {
- routeNum++;
- if (routes[i]) {
- drawing = true;
+ if (stop.uniLink) {
+
+ for (int i = 0; i < 5; i++) {
+ if ((stopRoutes & (1 << i)) != 0) {
+ routeNum++;
+ if (routes[i]) {
+ drawing = true;
+ }
}
}
- }
- if (!drawing)
- continue;
+ if (!drawing)
+ continue;
- int yOfsetPerMarker = (int) (10 * scale);
- int markerYSize = (int) (8 * scale);
+ }
pj.toMapPixels(stop.point, mCurScreenCoords);
@@ -144,60 +141,86 @@ public class BusStopOverlay extends Overlay implements RouteColorConstants {
} else {
Overlay.drawAt(canvas, marker, mCurScreenCoords.x, mCurScreenCoords.y, false);
}
- // Log.i(TAG, "Got " + routes.size() + " routes " + routes);
- int makersPlaced = 0;
+ if (stop.uniLink) {
- float rectLeft = mCurScreenCoords.x + (8.8f * scale);
- float rectRight = rectLeft + markerYSize;
+ int makersPlaced = 0;
+ int yOfsetPerMarker = (int) (10 * scale);
+ int markerYSize = (int) (8 * scale);
- if (routeNum == 5) {
- markerYSize = (int) (5 * scale);
- yOfsetPerMarker = (int) (7 * scale);
- } else if (routeNum == 4) {
- markerYSize = (int) (6.5f * scale);
- yOfsetPerMarker = (int) (8 * scale);
- }
+ float rectLeft = mCurScreenCoords.x + (8.8f * scale);
+ float rectRight = rectLeft + markerYSize;
- for (int i = 0; i < 5; i++) {
- if ((stopRoutes & (1 << i)) != 0) {
-
- // Log.i(TAG, "Route " + route + " is " + routes.get(route));
-
- // Log.i(TAG, "Index is " + busRoutes.indexOf(route) + " busRoutes " + busRoutes);
-
- if (i == 0) {
- paint.setColor(U1);
- } else if (i == 1) {
- paint.setColor(U1N);
- } else if (i == 2) {
- paint.setColor(U2);
- } else if (i == 3) {
- paint.setColor(U6);
- } else if (i == 4) {
- paint.setColor(U9);
- } else {
- Log.e(TAG, "Unknown route code");
- }
+ if (routeNum == 5) {
+ markerYSize = (int) (5 * scale);
+ yOfsetPerMarker = (int) (7 * scale);
+ } else if (routeNum == 4) {
+ markerYSize = (int) (6.5f * scale);
+ yOfsetPerMarker = (int) (8 * scale);
+ }
+
+ for (int i = 0; i < 5; i++) {
+ if ((stopRoutes & (1 << i)) != 0) {
+
+ // Log.i(TAG, "Route " + route + " is " + routes.get(route));
+
+ // Log.i(TAG, "Index is " + busRoutes.indexOf(route) + " busRoutes " + busRoutes);
+
+ if (i == 0) {
+ paint.setColor(U1);
+ } else if (i == 1) {
+ paint.setColor(U1N);
+ } else if (i == 2) {
+ paint.setColor(U2);
+ } else if (i == 3) {
+ paint.setColor(U6);
+ } else if (i == 4) {
+ paint.setColor(U9);
+ } else {
+ Log.e(TAG, "Unknown route code");
+ }
- canvas.drawRect(rectLeft, mCurScreenCoords.y + ((yOfsetPerMarker * makersPlaced) - (45 * scale)), rectRight, mCurScreenCoords.y
- + (yOfsetPerMarker * makersPlaced) - ((45 * scale) - markerYSize), paint);
+ canvas.drawRect(rectLeft, mCurScreenCoords.y
+ + ((yOfsetPerMarker * makersPlaced) - (45 * scale)), rectRight, mCurScreenCoords.y
+ + (yOfsetPerMarker * makersPlaced) - ((45 * scale) - markerYSize), paint);
- makersPlaced++;
+ makersPlaced++;
+ }
}
}
}
-
}
@Override
- public boolean onSingleTapUp(final MotionEvent event, final MapView mapView) {
+ public boolean onSingleTapConfirmed(final MotionEvent event, final MapView mapView) {
BusStop busStop = getSelectedItem(event, mapView);
if (busStop == null) {
- Log.i(TAG, "No busStop pressed");
+ // Log.v(TAG, "No busStop pressed");
+ return false;
+ } else {
+ Log.i(TAG, "busStop Pressed " + busStop.id);
+
+ if (context.activityToast == null) {
+ context.activityToast = Toast.makeText(context, busStop.description + " (" + busStop.id + ")",
+ Toast.LENGTH_SHORT);
+ } else {
+ context.activityToast.setDuration(Toast.LENGTH_SHORT);
+ context.activityToast.setText(busStop.description + " (" + busStop.id + ")");
+ }
+ context.activityToast.show();
+
+ return true;
+ }
+ }
+ public boolean onDoubleTap(final MotionEvent event, final MapView mapView) {
+
+ BusStop busStop = getSelectedItem(event, mapView);
+
+ if (busStop == null) {
+ // Log.v(TAG, "No busStop pressed");
return false;
} else {
Log.i(TAG, "Pressed " + busStop.id);
@@ -214,10 +237,11 @@ public class BusStopOverlay extends Overlay implements RouteColorConstants {
@Override
public boolean onLongPress(final MotionEvent event, final MapView mapView) {
+
BusStop busStop = getSelectedItem(event, mapView);
if (busStop == null) {
- Log.i(TAG, "No busStop pressed");
+ // Log.v(TAG, "No busStop pressed");
return false;
} else {
Log.i(TAG, "Pressed " + busStop.id);
@@ -225,9 +249,23 @@ public class BusStopOverlay extends Overlay implements RouteColorConstants {
if (busStop.favourite) {
busStop.favourite = false;
- Toast.makeText(context, busStop.id + " removed from favourites", Toast.LENGTH_SHORT).show();
+ if (context.activityToast == null) {
+ context.activityToast = Toast.makeText(context, busStop.id + " removed from favourites",
+ Toast.LENGTH_SHORT);
+ } else {
+ context.activityToast.setDuration(Toast.LENGTH_SHORT);
+ context.activityToast.setText(busStop.id + " removed from favourites");
+ }
+ context.activityToast.show();
} else {
- Toast.makeText(context, busStop.id + " made a favourite", Toast.LENGTH_SHORT).show();
+ if (context.activityToast == null) {
+ context.activityToast = Toast.makeText(context, busStop.id + " made a favourite",
+ Toast.LENGTH_SHORT);
+ } else {
+ context.activityToast.setDuration(Toast.LENGTH_SHORT);
+ context.activityToast.setText(busStop.id + " made a favourite");
+ }
+ context.activityToast.show();
busStop.favourite = true;
}
@@ -244,7 +282,6 @@ public class BusStopOverlay extends Overlay implements RouteColorConstants {
return true;
}
-
}
public void refresh() {
@@ -291,17 +328,19 @@ public class BusStopOverlay extends Overlay implements RouteColorConstants {
pj.toPixels(busStop.point, mItemPoint);
if (marker.getBounds().contains(mTouchScreenPoint.x - mItemPoint.x, mTouchScreenPoint.y - mItemPoint.y)) {
- boolean drawing = false;
- for (int route = 0; route < 5; route++) {
- if ((busStop.routes & (1 << route)) != 0) {
- if (routes[route]) {
- drawing = true;
- break;
+ if (busStop.uniLink) {
+ boolean drawing = false;
+ for (int route = 0; route < 5; route++) {
+ if ((busStop.routes & (1 << route)) != 0) {
+ if (routes[route]) {
+ drawing = true;
+ break;
+ }
}
}
+ if (!drawing)
+ continue;
}
- if (!drawing)
- continue;
return busStop;
}