aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorChristopher Baines <cbaines8@gmail.com>2012-02-08 21:13:31 +0000
committerChristopher Baines <cbaines8@gmail.com>2012-02-08 21:13:31 +0000
commit6da7d86db934fcaf5877b725481c164b5321c2ca (patch)
tree6ba404f097c74bc97884f6f4b1a1593723999216 /src
parent574ea86a77bf4911ae6956c9127ea3bf862352a3 (diff)
downloadsouthamptonuniversitymap-6da7d86db934fcaf5877b725481c164b5321c2ca.tar
southamptonuniversitymap-6da7d86db934fcaf5877b725481c164b5321c2ca.tar.gz
Some more progress on adding non Uni-Link data.
Diffstat (limited to 'src')
-rw-r--r--src/net/cbaines/suma/BusStopActivity.java5
-rw-r--r--src/net/cbaines/suma/BusStopOverlay.java94
-rw-r--r--src/net/cbaines/suma/DataManager.java102
-rw-r--r--src/net/cbaines/suma/SouthamptonUniversityMapActivity.java30
4 files changed, 158 insertions, 73 deletions
diff --git a/src/net/cbaines/suma/BusStopActivity.java b/src/net/cbaines/suma/BusStopActivity.java
index f3f5cce..4c9ce52 100644
--- a/src/net/cbaines/suma/BusStopActivity.java
+++ b/src/net/cbaines/suma/BusStopActivity.java
@@ -170,10 +170,7 @@ public class BusStopActivity extends OrmLiteBaseActivity<DatabaseHelper> impleme
} else {
U9RouteRadioButton.setVisibility(View.GONE);
}
- } else {
- Log.e(TAG, "Error unknown route " + route.code);
- }
-
+ }
}
busStopDao = helper.getBusStopDao();
diff --git a/src/net/cbaines/suma/BusStopOverlay.java b/src/net/cbaines/suma/BusStopOverlay.java
index 834b6dc..59212ef 100644
--- a/src/net/cbaines/suma/BusStopOverlay.java
+++ b/src/net/cbaines/suma/BusStopOverlay.java
@@ -119,20 +119,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);
@@ -141,50 +142,53 @@ 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);
+ }
- canvas.drawRect(rectLeft, mCurScreenCoords.y + ((yOfsetPerMarker * makersPlaced) - (45 * scale)), rectRight, mCurScreenCoords.y
- + (yOfsetPerMarker * makersPlaced) - ((45 * scale) - markerYSize), paint);
+ 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");
+ }
- makersPlaced++;
+ canvas.drawRect(rectLeft, mCurScreenCoords.y + ((yOfsetPerMarker * makersPlaced) - (45 * scale)), rectRight, mCurScreenCoords.y
+ + (yOfsetPerMarker * makersPlaced) - ((45 * scale) - markerYSize), paint);
+
+ makersPlaced++;
+ }
}
}
}
-
}
@Override
diff --git a/src/net/cbaines/suma/DataManager.java b/src/net/cbaines/suma/DataManager.java
index 770e649..aad8b86 100644
--- a/src/net/cbaines/suma/DataManager.java
+++ b/src/net/cbaines/suma/DataManager.java
@@ -29,6 +29,7 @@ import java.util.Date;
import java.util.GregorianCalendar;
import java.util.HashMap;
import java.util.Iterator;
+import java.util.List;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.parsers.SAXParser;
@@ -263,11 +264,19 @@ public class DataManager {
uniLink = true;
}
- if (dataBits.length > 3) {
- route = new BusRoute(id, dataBits[1], dataBits[2].replace("\"", ""), dataBits[3], dataBits[4], uniLink);
- } else {
- route = new BusRoute(id, dataBits[1], dataBits[2].replace("\"", ""), uniLink);
+ route = new BusRoute(id, dataBits[1], dataBits[2].replace("\"", ""), uniLink);
+
+ if (id == 326) {
+ route.forwardDirection = "C";
+ route.reverseDirection = "A";
+ } else if (id == 329) {
+ route.forwardDirection = "C";
+ route.reverseDirection = "B";
+ } else if (id == 327) {
+ route.forwardDirection = "H";
+ route.reverseDirection = "C";
}
+
// Log.i(TAG, "Loaded route " + route.id + " " + route.code + " " + route.label);
busRouteDao.create(route);
@@ -340,6 +349,34 @@ public class DataManager {
e.printStackTrace();
}
+ for (Iterator<BusStop> busStopIter = busStopDao.iterator(); busStopIter.hasNext();) {
+ BusStop stop = busStopIter.next();
+ // Log.i(TAG, "Looking at stop " + stop.id);
+
+ /*
+ * QueryBuilder<RouteStops, Integer> routeStopsQueryBuilder = routeStopsDao.queryBuilder(); routeStopsQueryBuilder.where().eq(columnName, value)
+ *
+ * DeleteBuilder<BusStop, String> deleteBuilder = busStopDao.deleteBuilder(); // only delete the rows where password is null
+ * deleteBuilder.where().in(RouteStops.STOP_ID_FIELD_NAME, objects) accountDao.delete(deleteBuilder.prepare());
+ */
+
+ QueryBuilder<RouteStops, Integer> routeStopsQueryBuilder = routeStopsDao.queryBuilder();
+ routeStopsQueryBuilder.setCountOf(true);
+ routeStopsQueryBuilder.where().eq(RouteStops.STOP_ID_FIELD_NAME, stop);
+
+ PreparedQuery<RouteStops> routeStopsPreparedQuery = routeStopsQueryBuilder.prepare();
+ long num = routeStopsDao.countOf(routeStopsPreparedQuery);
+ // long num = routeStopsDao.query(routeStopsPreparedQuery).size();
+ // Log.i(TAG, "Number is " + num);
+ if (num == 0) {
+ // Log.i(TAG, "Removing " + stop.id);
+ stop.uniLink = false;
+ } else {
+ stop.uniLink = true;
+ }
+ busStopDao.update(stop);
+ }
+
Log.i(TAG, "Finished loading bus data");
}
@@ -425,29 +462,48 @@ public class DataManager {
BusRoute route;
String dir = null;
- if (name.equals("U1N")) {
- route = busRoutes.queryForId(468);
- } else if (name.startsWith("U9")) {
- route = busRoutes.queryForId(354);
- } else {
- if (name.startsWith("U1")) {
- route = busRoutes.queryForId(326);
- } else if (name.startsWith("U2")) {
- route = busRoutes.queryForId(329);
- } else if (name.startsWith("U6")) {
- route = busRoutes.queryForId(327);
+ if (name.contains("U")) {
+ if (name.equals("U1N")) {
+ route = busRoutes.queryForId(468);
+ } else if (name.startsWith("U9")) {
+ route = busRoutes.queryForId(354);
} else {
- Log.e(TAG, "Error detecting route " + name);
- return null;
+ if (name.startsWith("U1")) {
+ route = busRoutes.queryForId(326);
+ } else if (name.startsWith("U2")) {
+ route = busRoutes.queryForId(329);
+ } else if (name.startsWith("U6")) {
+ route = busRoutes.queryForId(327);
+ } else {
+ Log.e(TAG, "Error finding Uni-Link route " + name);
+ return null;
+ }
+
+ if (route.forwardDirection.equals(name.substring(2))) {
+ dir = route.forwardDirection;
+ } else if (route.reverseDirection.equals(name.substring(2))) {
+ dir = route.reverseDirection;
+ } else {
+ Log.e(TAG, "Error detecting direction for " + name);
+ return null;
+ }
}
- if (route.forwardDirection.equals(name.substring(2))) {
- dir = route.forwardDirection;
- } else if (route.reverseDirection.equals(name.substring(2))) {
- dir = route.reverseDirection;
- } else {
- Log.e(TAG, "Error detecting direction for " + name);
+ } else {
+ Log.v(TAG, "Route not Uni-Link");
+ List<BusRoute> routes = (List<BusRoute>) busRoutes.queryForEq(BusRoute.CODE_FIELD_NAME, name);
+ if (routes.size() != 1) {
+ Log.e(TAG, "Found more than one non Uni-Link route?");
+ for (BusRoute routeT : routes) {
+ Log.i(TAG, "Route: " + routeT);
+ }
return null;
+ } else {
+ route = routes.get(0);
+ if (route == null) {
+ Log.e(TAG, "Could not find database entry for " + name);
+ return null;
+ }
}
}
diff --git a/src/net/cbaines/suma/SouthamptonUniversityMapActivity.java b/src/net/cbaines/suma/SouthamptonUniversityMapActivity.java
index f624a43..323c7db 100644
--- a/src/net/cbaines/suma/SouthamptonUniversityMapActivity.java
+++ b/src/net/cbaines/suma/SouthamptonUniversityMapActivity.java
@@ -114,7 +114,7 @@ public class SouthamptonUniversityMapActivity extends OrmLiteBaseActivity<Databa
// Uni-Link Bus Stop Overlay
private BusStopOverlay nonUniLinkBusStopOverlay;
- private static final boolean NON_UNI_LINK_BUS_STOP_OVERLAY_ENABLED_BY_DEFAULT = true;
+ private static final boolean NON_UNI_LINK_BUS_STOP_OVERLAY_ENABLED_BY_DEFAULT = false;
// Site Overlays
private HashMap<Site, PathOverlay> siteOverlays = new HashMap<Site, PathOverlay>(21);
@@ -696,6 +696,34 @@ public class SouthamptonUniversityMapActivity extends OrmLiteBaseActivity<Databa
}
}
+ if (nonUniLinkBusStopOverlay == null && activityPrefs.getBoolean(NON_UNI_LINK_BUS_STOPS, NON_UNI_LINK_BUS_STOP_OVERLAY_ENABLED_BY_DEFAULT)) {
+ if (pastOverlays != null && (nonUniLinkBusStopOverlay = (BusStopOverlay) pastOverlays.get("NonUniLinkBusStops")) != null) {
+ Log.i(TAG, "Restored bus stop overlays");
+ } else {
+ try {
+ List<BusStop> busStops;
+ Log.v(TAG, "Begin fetching BusStops at " + (System.currentTimeMillis() - startTime));
+
+ busStops = getHelper().getBusStopDao().queryForEq(BusStop.UNI_LINK_FIELD_NAME, false);
+
+ Log.v(TAG, "Finished fetching BusStops at " + (System.currentTimeMillis() - startTime));
+
+ nonUniLinkBusStopOverlay = new BusStopOverlay(instance, busStops);
+ } catch (SQLException e) {
+ e.printStackTrace();
+ }
+ }
+
+ overlays.put("BusStops", nonUniLinkBusStopOverlay);
+
+ Log.v(TAG, "Applyed the site overlay, now sorting them");
+
+ synchronized (mapView.getOverlays()) {
+ mapView.getOverlays().add(nonUniLinkBusStopOverlay);
+ Collections.sort(mapView.getOverlays(), comparator);
+ }
+ }
+
uniLinkBusStopOverlay.setRoutes(0, activityPrefs.getBoolean("Bus Stops:U1", UNI_LINK_BUS_STOP_OVERLAY_ENABLED_BY_DEFAULT));
uniLinkBusStopOverlay.setRoutes(1, activityPrefs.getBoolean("Bus Stops:U1N", UNI_LINK_BUS_STOP_OVERLAY_ENABLED_BY_DEFAULT));
uniLinkBusStopOverlay.setRoutes(2, activityPrefs.getBoolean("Bus Stops:U2", UNI_LINK_BUS_STOP_OVERLAY_ENABLED_BY_DEFAULT));