diff options
author | Christopher Baines <cbaines8@gmail.com> | 2012-03-15 13:42:44 +0000 |
---|---|---|
committer | Christopher Baines <cbaines8@gmail.com> | 2012-03-15 13:42:44 +0000 |
commit | e667851ae9869167677aa5e6e4c20707417cc687 (patch) | |
tree | 0854667b1ac699ed7752014706ba139a3a4ea4b8 | |
parent | 87fab59964901d5ddbae6e72cbb8064c5a301297 (diff) | |
download | southamptonuniversitymap-e667851ae9869167677aa5e6e4c20707417cc687.tar southamptonuniversitymap-e667851ae9869167677aa5e6e4c20707417cc687.tar.gz |
Progress with the Bus activiy.
-rw-r--r-- | src/net/cbaines/suma/BusActivity.java | 8 | ||||
-rw-r--r-- | src/net/cbaines/suma/BusRoute.java | 43 | ||||
-rw-r--r-- | src/net/cbaines/suma/BusSpecificStopView.java | 4 | ||||
-rw-r--r-- | src/net/cbaines/suma/DataManager.java | 52 |
4 files changed, 84 insertions, 23 deletions
diff --git a/src/net/cbaines/suma/BusActivity.java b/src/net/cbaines/suma/BusActivity.java index 8d7dcbe..c043687 100644 --- a/src/net/cbaines/suma/BusActivity.java +++ b/src/net/cbaines/suma/BusActivity.java @@ -115,7 +115,8 @@ public class BusActivity extends ToastHelperActivity implements Preferences { if (bus.id != null) { // Log.i(TAG, "Bus id is not null (" + bus.id + // ") setting busIDTextView"); - busIDTextView.setText(bus.id + " " + bus.getName()); + getHelper().getBusRouteDao().refresh(bus.route); + busIDTextView.setText(bus.id + " " + bus.route.label); } else { Log.w(TAG, "Bus id is null?"); // Might not ever happen @@ -279,9 +280,8 @@ public class BusActivity extends ToastHelperActivity implements Preferences { // Remove the old time from the timetable synchronized (timetable) { - timetable.set(num, - new StopLoading(bus, busStops.get(num), null, new Date( - System.currentTimeMillis() - 21000), false)); + timetable.set(num, new StopLoading(bus, busStops.get(num), timetable.get(num).arivalTime, + new Date(System.currentTimeMillis() - 21000), false)); displayTimetable(timetable); } diff --git a/src/net/cbaines/suma/BusRoute.java b/src/net/cbaines/suma/BusRoute.java index e38d06a..54f1340 100644 --- a/src/net/cbaines/suma/BusRoute.java +++ b/src/net/cbaines/suma/BusRoute.java @@ -65,7 +65,8 @@ public class BusRoute { String label; /** - * The direction the bus is travelling if it is moving through the route and sequence is increasing. + * The direction the bus is travelling if it is moving through the route and + * sequence is increasing. * <ul> * <li>U1 = A</li> * <li>U2 = B</li> @@ -76,7 +77,8 @@ public class BusRoute { String forwardDirection; /** - * The direction the bus is travelling if it is moving through the route and sequence is decreasing. + * The direction the bus is travelling if it is moving through the route and + * sequence is decreasing. * <ul> * <li>U1 = C</li> * <li>U2 = C</li> @@ -92,7 +94,8 @@ public class BusRoute { BusRoute() { } - public BusRoute(Integer id, String code, String label, String forwardDirection, String reverseDirection, boolean uniLink) { + public BusRoute(Integer id, String code, String label, String forwardDirection, String reverseDirection, + boolean uniLink) { this.id = id.intValue(); this.code = code; this.label = label; @@ -132,8 +135,9 @@ public class BusRoute { } /** - * Return the set of bus stops that can be thought of moveAmount away from the busStop. The method returns a set as for some - * movements, the destination stop is ambiguous. + * Return the set of bus stops that can be thought of moveAmount away from + * the busStop. The method returns a set as for some movements, the + * destination stop is ambiguous. * * @param context * @param busStop @@ -191,16 +195,27 @@ public class BusRoute { busStops.add(busStopWanted); } else { Log.v(TAG, "stopIndex " + stopIndex); - int stopWanted = stopIndex + moveAmount; // This will end up as the sequence number of the wanted stop + int stopWanted = stopIndex + moveAmount; // This will end up + // as the + // sequence + // number of the + // wanted stop if (stopWanted < 1) { stopWanted = routeStopsFound.size() - (Math.abs(stopWanted) % routeStopsFound.size()); } Log.v(TAG, "stopWanted " + stopWanted); - BusStop wantedBusStop = routeStopsFound.get(stopWanted - 1).busStop; // Need the -1 as sequence starts at 1 + BusStop wantedBusStop = routeStopsFound.get(stopWanted - 1).busStop; // Need + // the + // -1 + // as + // sequence + // starts + // at + // 1 busStopDao.refresh(wantedBusStop); - Log.v(TAG, "Moving backwards " + (-1 * moveAmount) + " stops from " + busStop + " to " + wantedBusStop - + " in route " + this); + Log.v(TAG, "Moving backwards " + (-1 * moveAmount) + " stops from " + busStop + " to " + + wantedBusStop + " in route " + this); busStops.add(wantedBusStop); } @@ -379,9 +394,8 @@ public class BusRoute { } if (moveAmount > 0) { - Log.v(TAG, - "Moving forward " + moveAmount + " stops from " + busStop + " (" + stopIndex + "/" - + routeStopsFound.size() + ")"); + Log.v(TAG, "Moving forward " + moveAmount + " stops from " + busStop + " (" + stopIndex + "/" + + routeStopsFound.size() + ")"); int stopWanted = stopIndex + moveAmount; if (stopWanted > routeStopsFound.size()) { Log.v(TAG, "Off the end of the route"); @@ -404,8 +418,9 @@ public class BusRoute { Log.v(TAG, "stopWanted " + stopWanted); busStopDao.refresh(routeStopsFound.get(stopWanted).busStop); - Log.v(TAG, "Moving backwards " + moveAmount + " stops from " + busStop + " to " - + routeStopsFound.get(stopWanted).busStop + " in route " + this); + Log.v(TAG, + "Moving backwards " + moveAmount + " stops from " + busStop + " to " + + routeStopsFound.get(stopWanted).busStop + " in route " + this); return routeStopsFound.get(stopWanted).busStop; } diff --git a/src/net/cbaines/suma/BusSpecificStopView.java b/src/net/cbaines/suma/BusSpecificStopView.java index 9832588..b140420 100644 --- a/src/net/cbaines/suma/BusSpecificStopView.java +++ b/src/net/cbaines/suma/BusSpecificStopView.java @@ -117,10 +117,10 @@ public class BusSpecificStopView extends LinearLayout implements OnClickListener if (stop.arivalTime != null) { if (stop.live) { - onClickMessage = stop.busStop.description + " at " + onClickMessage = stop.bus.getName() + " at " + DateFormat.getTimeInstance(DateFormat.SHORT).format(stop.arivalTime); } else { - onClickMessage = stop.busStop.description + " at " + onClickMessage = stop.bus.getName() + " at " + DateFormat.getTimeInstance(DateFormat.SHORT).format(stop.arivalTime) + " (timetabled)"; } } else { diff --git a/src/net/cbaines/suma/DataManager.java b/src/net/cbaines/suma/DataManager.java index bdfedb5..99da450 100644 --- a/src/net/cbaines/suma/DataManager.java +++ b/src/net/cbaines/suma/DataManager.java @@ -890,8 +890,8 @@ public class DataManager { return stop; } - public static Stop getStop(Context context, Bus bus, int busStopRouteIndex) throws SQLException, ClientProtocolException, - IOException, JSONException { + public static Stop getStop(Context context, Bus bus, int busStopRouteIndex) throws SQLException, + ClientProtocolException, IOException, JSONException { if (helper == null) helper = OpenHelperManager.getHelper(context, DatabaseHelper.class); @@ -900,8 +900,53 @@ public class DataManager { if (busStopDao == null) busStopDao = helper.getBusStopDao(); + busRouteDao.refresh(bus.route); + BusRoute route = bus.route; + + List<BusStop> busStops = route.getRouteBusStops(context); + + BusStop busStop = busStops.get(busStopRouteIndex); + String file = getFileFromServer(busStopUrl + busStop.id + ".json"); + String direction = ""; + + if (route.id == 326) { // U1 + if (bus.direction.equals("E")) { + direction = "E"; + } else { + if (busStopRouteIndex >= 1 && busStopRouteIndex <= 36) { + direction = route.forwardDirection; + } else if (busStopRouteIndex >= 51 && busStopRouteIndex <= 88) { + direction = route.reverseDirection; + } else { + Log.e(TAG, "For U1 route, error with busStopRouteIndex " + busStopRouteIndex); + } + } + } else if (route.id == 468) { // U1N + // Nothing to do + } else if (route.id == 329) { // U2 + if (busStopRouteIndex >= 1 && busStopRouteIndex <= 22) { + direction = route.forwardDirection; + } else if (busStopRouteIndex >= 23 && busStopRouteIndex <= 43) { + direction = route.reverseDirection; + } else { + Log.e(TAG, "For U2 route, error with busStopRouteIndex " + busStopRouteIndex); + } + } else if (route.id == 327) { // U6 + if (busStopRouteIndex >= 1 && busStopRouteIndex <= 44) { + direction = route.forwardDirection; + } else if (busStopRouteIndex >= 45 && busStopRouteIndex <= 93) { + direction = route.reverseDirection; + } else { + Log.e(TAG, "For U6 route, error with busStopRouteIndex " + busStopRouteIndex); + } + } else if (route.id == 354) { // U9 + // Arggghh!!!! + } else { + Log.e(TAG, "Error, unrecognised route " + route.id); + } + JSONObject data = new JSONObject(file); JSONArray stopsArray = data.getJSONArray("stops"); @@ -921,7 +966,8 @@ public class DataManager { JSONObject stopObj = stopsArray.getJSONObject(stopNum); // Log.v(TAG, "stopObj: " + stopObj); - if (stopObj.has("vehicle") && stopObj.getString("vehicle").equals(bus.id)) { + if (stopObj.has("vehicle") && stopObj.getString("vehicle").equals(bus.id) + && stopObj.getString("name").equals(bus.route.code + direction)) { stop = getStop(context, stopObj, busRoutes, busStop, age); break; |