From c59f47181a71fca3e4c20aed43552194f6333ccc Mon Sep 17 00:00:00 2001 From: Christopher Baines Date: Sat, 17 Mar 2012 19:31:06 +0000 Subject: Random commit. --- src/net/cbaines/suma/Bus.java | 2 +- src/net/cbaines/suma/BusActivity.java | 13 +++------ src/net/cbaines/suma/DataManager.java | 52 +++++++++++++++++++++++++---------- src/net/cbaines/suma/Preferences.java | 4 +-- 4 files changed, 45 insertions(+), 26 deletions(-) (limited to 'src/net/cbaines') diff --git a/src/net/cbaines/suma/Bus.java b/src/net/cbaines/suma/Bus.java index d971dac..b6986f7 100644 --- a/src/net/cbaines/suma/Bus.java +++ b/src/net/cbaines/suma/Bus.java @@ -85,7 +85,7 @@ public class Bus { } public String toString() { - return String.valueOf(id + " (" + route.code + direction + ")"); + return String.valueOf(id + " (" + getName() + ")"); } String getName() { diff --git a/src/net/cbaines/suma/BusActivity.java b/src/net/cbaines/suma/BusActivity.java index 1659c88..532b2ca 100644 --- a/src/net/cbaines/suma/BusActivity.java +++ b/src/net/cbaines/suma/BusActivity.java @@ -2,7 +2,6 @@ package net.cbaines.suma; import java.io.IOException; import java.sql.SQLException; -import java.util.ArrayList; import java.util.Date; import java.util.HashMap; import java.util.List; @@ -54,7 +53,6 @@ public class BusActivity extends ToastHelperActivity implements Preferences { // BusStops and if they are being updated by the handler List busStops; - ArrayList busStopRoutePositions; private HashMap tasks = new HashMap(); @@ -103,7 +101,7 @@ public class BusActivity extends ToastHelperActivity implements Preferences { // Log.i(TAG, "Bus id is not null (" + bus.id + // ") setting busIDTextView"); busRoute = getHelper().getBusRouteDao().queryForId(busRouteID); - busIDTextView.setText(busID + " " + busRoute.label); + busIDTextView.setText(busID + " " + busRoute.code); // if (bus.destinationString != null) { // // Log.i(TAG, "Bus destination string is " + @@ -118,10 +116,6 @@ public class BusActivity extends ToastHelperActivity implements Preferences { // } busStops = busRoute.getRouteBusStops(this); - busStopRoutePositions = new ArrayList(); - for (int i = 0; i < busStops.size(); i++) { - busStopRoutePositions.add(i); - } // Log.i(TAG, "Got " + busStops.size() + " bus stops for this bus"); refreshData = new Runnable() { @@ -268,7 +262,7 @@ public class BusActivity extends ToastHelperActivity implements Preferences { try { // Log.i(TAG, "Fetching stop for busStop " + busStop.description); - stop = DataManager.getStop(instance, busID, busRoute, busStopRoutePositions.get(busStopIndex)); + stop = DataManager.getStop(instance, busID, busRoute, busStopIndex); if (stop == null) { stop = new Stop(null, busStop, null, new Date(System.currentTimeMillis()), false); } @@ -291,7 +285,8 @@ public class BusActivity extends ToastHelperActivity implements Preferences { } protected void onPostExecute(Stop stop) { - if (isCancelled()) return; + if (isCancelled()) + return; synchronized (timetable) { timetable.set(busStopIndex, stop); diff --git a/src/net/cbaines/suma/DataManager.java b/src/net/cbaines/suma/DataManager.java index 1658cb5..4d948ed 100644 --- a/src/net/cbaines/suma/DataManager.java +++ b/src/net/cbaines/suma/DataManager.java @@ -24,6 +24,7 @@ import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.sql.SQLException; +import java.text.DateFormat; import java.util.ArrayList; import java.util.Calendar; import java.util.Date; @@ -314,7 +315,7 @@ public class DataManager { boolean uniLink; int id = Integer.parseInt(dataBits[0]); - if (id == 326 || id == 468 || id == 327 || id == 329 || id == 354) { + if (id == 326 || id == 468 || id == 327 || id == 329 || id == 354 || id == 999) { uniLink = true; } else { uniLink = false; @@ -331,6 +332,9 @@ public class DataManager { } else if (id == 327) { // U6 route.forwardDirection = "H"; route.reverseDirection = "C"; + } else if (id == 999) { // U6 + route.forwardDirection = "E"; + route.reverseDirection = "C"; } // Log.i(TAG, "Loaded route " + route.id + " " + route.code + @@ -394,6 +398,9 @@ public class DataManager { } else if (busRoute.id == 354) { // U9 busStop.routes = (byte) (busStop.routes | (1 << 4)); busStop.uniLink = true; + } else if (busRoute.id == 999) { // U1E + busStop.routes = (byte) (busStop.routes | (1 << 5)); + busStop.uniLink = true; } // Log.v(TAG, "Stop routes " + busStop.routes); @@ -526,11 +533,13 @@ public class DataManager { if (tempRoute.code.equals(name)) { route = tempRoute; dir = null; + break; } } else if (name.equals("U1E")) { - if (tempRoute.code.equals("U1")) { + if (tempRoute.code.equals(name)) { route = tempRoute; - dir = "E"; + dir = null; + break; } } else { if (tempRoute.code.equals(name.substring(0, 2))) { @@ -544,12 +553,14 @@ public class DataManager { dir = null; return null; } + break; } } } else { if (tempRoute.code.equals(name)) { route = tempRoute; dir = null; + break; } } } @@ -671,6 +682,10 @@ public class DataManager { if (route != null) { busRoutes.add(route); + + if (route.id == 326) { // U1 + busRoutes.add(busRouteDao.queryForId(999)); + } } else { Log.e(TAG, "Route not found " + key.substring(key.length() - 3, key.length()) + " " + key); throw new RuntimeException("Route not found " + key.substring(key.length() - 3, key.length()) + " " + key); @@ -863,19 +878,17 @@ public class DataManager { String direction = ""; if (route.id == 326) { // U1 - Log.i(TAG, "Direction for " + busStopRouteIndex + " is"); - if (busStopRouteIndex >= 0 && busStopRouteIndex <= 35) { + if (busStopRouteIndex >= 0 && busStopRouteIndex <= 34) { direction = route.forwardDirection; - } else if (busStopRouteIndex >= 52 && busStopRouteIndex <= 87) { + } else if (busStopRouteIndex >= 35 && busStopRouteIndex <= 73) { direction = route.reverseDirection; } else { Log.e(TAG, "For U1 route, error with busStopRouteIndex " + busStopRouteIndex + " " + busStop.description); } - Log.i(TAG, direction); } else if (route.id == 468) { // U1N // Nothing to do } else if (route.id == 329) { // U2 - if (busStopRouteIndex >= 1 && busStopRouteIndex <= 22) { + if (busStopRouteIndex >= 0 && busStopRouteIndex <= 22) { direction = route.forwardDirection; } else if (busStopRouteIndex >= 23 && busStopRouteIndex <= 43) { direction = route.reverseDirection; @@ -883,7 +896,7 @@ public class DataManager { Log.e(TAG, "For U2 route, error with busStopRouteIndex " + busStopRouteIndex); } } else if (route.id == 327) { // U6 - if (busStopRouteIndex >= 1 && busStopRouteIndex <= 44) { + if (busStopRouteIndex >= 0 && busStopRouteIndex <= 44) { direction = route.forwardDirection; } else if (busStopRouteIndex >= 45 && busStopRouteIndex <= 93) { direction = route.reverseDirection; @@ -892,6 +905,14 @@ public class DataManager { } } else if (route.id == 354) { // U9 // Arggghh!!!! + } else if (route.id == 999) { // U1E + if (busStopRouteIndex >= 0 && busStopRouteIndex <= 43) { + direction = route.forwardDirection; + } else if (busStopRouteIndex >= 45 && busStopRouteIndex <= 87) { + direction = route.reverseDirection; + } else { + Log.e(TAG, "For U1 route, error with busStopRouteIndex " + busStopRouteIndex + " " + busStop.description); + } } else { Log.e(TAG, "Error, unrecognised route " + route.id); } @@ -913,19 +934,22 @@ public class DataManager { for (int stopNum = 0; stopNum < stopsArray.length(); stopNum++) { JSONObject stopObj = stopsArray.getJSONObject(stopNum); - // Log.v(TAG, "stopObj: " + stopObj); + Log.v(TAG, busID + " " + route.code + direction + " stopObj: " + stopObj); if (stopObj.has("vehicle") && stopObj.getString("vehicle").equals(busID) && stopObj.getString("name").equals(route.code + direction)) { stop = getStop(context, stopObj, busRoutes, busStop, age); break; - - // Log.v(TAG, "Found stop for a unidentified " + - // stop.bus.toString() + " at " + stop.busStop.id + " at " - // + stop.arivalTime); } } + if (stop.arivalTime != null) { + Log.i(TAG, "Returning stop for " + stop.busStop.description + " at " + + DateFormat.getTimeInstance(DateFormat.SHORT).format(stop.arivalTime)); + } else { + Log.i(TAG, "Returning stop for " + stop.busStop.description + " at null"); + } + return stop; } diff --git a/src/net/cbaines/suma/Preferences.java b/src/net/cbaines/suma/Preferences.java index 8fc0cb8..368e75c 100644 --- a/src/net/cbaines/suma/Preferences.java +++ b/src/net/cbaines/suma/Preferences.java @@ -16,7 +16,7 @@ public interface Preferences { static final String APP_VERSION = "appVersion"; static final String APP_NOT_INSTALLED = ""; - static final String CURRENT_APP_VERSION = "0.9"; + static final String CURRENT_APP_VERSION = "0.9.1"; static final String FAVOURITES_PREFERENCES = "favourites"; @@ -29,5 +29,5 @@ public interface Preferences { * Enable to use the database in the assets folder, if its not enabled, the database is built from the csv files in the assets * folder */ - static final boolean USE_BUNDLED_DATABASE = false; + static final boolean USE_BUNDLED_DATABASE = true; } -- cgit v1.2.3