diff options
Diffstat (limited to 'src/net')
-rw-r--r-- | src/net/cbaines/suma/Bus.java | 6 | ||||
-rw-r--r-- | src/net/cbaines/suma/BusRoutesView.java | 13 | ||||
-rw-r--r-- | src/net/cbaines/suma/BusStopActivity.java | 2 | ||||
-rw-r--r-- | src/net/cbaines/suma/DataManager.java | 110 | ||||
-rw-r--r-- | src/net/cbaines/suma/Stop.java | 22 |
5 files changed, 83 insertions, 70 deletions
diff --git a/src/net/cbaines/suma/Bus.java b/src/net/cbaines/suma/Bus.java index d8d96f3..bddba70 100644 --- a/src/net/cbaines/suma/Bus.java +++ b/src/net/cbaines/suma/Bus.java @@ -98,7 +98,11 @@ public class Bus { } String getName() { - return route.code + direction; + if (direction != null) { + return route.code + direction; + } else { + return route.code; + } } @Override diff --git a/src/net/cbaines/suma/BusRoutesView.java b/src/net/cbaines/suma/BusRoutesView.java index 05e51b2..b7c1095 100644 --- a/src/net/cbaines/suma/BusRoutesView.java +++ b/src/net/cbaines/suma/BusRoutesView.java @@ -1,11 +1,8 @@ package net.cbaines.suma; -import android.R.color; import android.content.Context; import android.view.View; import android.widget.LinearLayout; -import android.widget.TableLayout; -import android.widget.TableRow; import android.widget.TextView; public class BusRoutesView extends LinearLayout { @@ -25,27 +22,27 @@ public class BusRoutesView extends LinearLayout { u1 = new TextView(context); u1.setText(R.string.U1); u1.setBackgroundResource(R.drawable.u1_back_selected); - u1.setPadding(1, 1, 1, 1); + u1.setPadding(5, 1, 5, 1); u1n = new TextView(context); u1n.setText(R.string.U1N); u1n.setBackgroundResource(R.drawable.u1n_back_selected); - u1n.setPadding(1, 1, 1, 1); + u1n.setPadding(5, 1, 5, 1); u2 = new TextView(context); u2.setText(R.string.U2); u2.setBackgroundResource(R.drawable.u2_back_selected); - u2.setPadding(1, 1, 1, 1); + u2.setPadding(5, 1, 5, 1); u6 = new TextView(context); u6.setText(R.string.U6); u6.setBackgroundResource(R.drawable.u6_back_selected); - u6.setPadding(1, 1, 1, 1); + u6.setPadding(5, 1, 5, 1); u9 = new TextView(context); u9.setText(R.string.U9); u9.setBackgroundResource(R.drawable.u9_back_selected); - u9.setPadding(1, 1, 1, 1); + u9.setPadding(5, 1, 5, 1); this.setOrientation(LinearLayout.VERTICAL); diff --git a/src/net/cbaines/suma/BusStopActivity.java b/src/net/cbaines/suma/BusStopActivity.java index 52f1b92..421a0eb 100644 --- a/src/net/cbaines/suma/BusStopActivity.java +++ b/src/net/cbaines/suma/BusStopActivity.java @@ -313,7 +313,7 @@ public class BusStopActivity extends OrmLiteBaseActivity<DatabaseHelper> impleme if (THROW_ERROR_ON_EXCEPTION) { throw new RuntimeException(e.getMessage()); } else { - Log.e(TAG, e.getMessage()); + Log.e(TAG, e.getMessage(), e.getCause()); } } return newTimetable; diff --git a/src/net/cbaines/suma/DataManager.java b/src/net/cbaines/suma/DataManager.java index f642d56..84731ff 100644 --- a/src/net/cbaines/suma/DataManager.java +++ b/src/net/cbaines/suma/DataManager.java @@ -28,8 +28,10 @@ import java.util.Calendar; import java.util.Date; import java.util.GregorianCalendar; import java.util.HashMap; +import java.util.HashSet; import java.util.Iterator; import java.util.List; +import java.util.Set; import javax.xml.parsers.ParserConfigurationException; import javax.xml.parsers.SAXParser; @@ -68,7 +70,7 @@ public class DataManager { private final static String busStopUrl = "http://data.southampton.ac.uk/bus-stop/"; private static DatabaseHelper helper; - private static Dao<BusRoute, Integer> busRoutes; + private static Dao<BusRoute, Integer> busRouteDao; private static Dao<Bus, Integer> busDao; private static Dao<BusStop, String> busStopDao; @@ -424,12 +426,12 @@ public class DataManager { Log.i(TAG, "Loaded sites from csv"); } - private static Stop getStop(Context context, JSONObject stopObj, BusStop busStop) throws SQLException, JSONException { + private static Stop getStop(Context context, JSONObject stopObj, Set<BusRoute> routes, BusStop busStop) throws SQLException, JSONException { if (helper == null) helper = OpenHelperManager.getHelper(context, DatabaseHelper.class); - if (busRoutes == null) - busRoutes = helper.getBusRouteDao(); + if (busRouteDao == null) + busRouteDao = helper.getBusRouteDao(); if (busDao == null) busDao = helper.getBusDao(); if (busStopDao == null) @@ -458,53 +460,50 @@ public class DataManager { String name = stopObj.getString("name"); - BusRoute route; - String dir = null; + BusRoute route = null; + String dir = ""; - if (name.contains("U")) { - 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); - } else { - throw new RuntimeException("Error finding Uni-Link route " + name); - } - - if (route.forwardDirection.equals(name.substring(2))) { - dir = route.forwardDirection; - } else if (route.reverseDirection.equals(name.substring(2))) { - dir = route.reverseDirection; + for (BusRoute tempRoute : routes) { + if (name.contains("U")) { + if (name.equals("U1N")) { + if (tempRoute.code.equals(name)) { + route = tempRoute; + dir = null; + } } else { - throw new RuntimeException("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); + if (tempRoute.code.equals(name.substring(0, 2))) { + route = tempRoute; + 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); + dir = null; + return null; + } + } } - throw new RuntimeException("Found more than one non Uni-Link route?"); } else { - route = routes.get(0); - if (route == null) { - throw new RuntimeException("Could not find database entry for " + name); + if (tempRoute.code.equals(name)) { + route = tempRoute; + dir = null; } } } + if (route == null) { + Log.e(TAG, "Route not found (route == null) " + name); + return null; + } + + if (dir != null && dir.equals("")) { + Log.e(TAG, "Error detecting direction for " + name); + return null; + } + String destString = stopObj.getString("dest"); - BusStop destStop; + BusStop destStop = null; if (destString.equals("Central Station")) { destStop = busStopDao.queryForId("SNA19709"); @@ -528,8 +527,10 @@ public class DataManager { destStop = busStopDao.queryForId("SN121009"); } else if (destString.equals("General Hosp")) { destStop = busStopDao.queryForId("SNA19482"); + } else if (destString.equals("Wessex Lane")) { + destStop = busStopDao.queryForId("SNA19780"); } else { - throw new RuntimeException("Unknown end dest " + destString + " for route " + route.code); + Log.e(TAG, "Unknown end dest " + destString + " for route " + route.code); } Date now = new Date(System.currentTimeMillis()); @@ -571,8 +572,8 @@ public class DataManager { if (helper == null) helper = OpenHelperManager.getHelper(context, DatabaseHelper.class); - if (busRoutes == null) - busRoutes = helper.getBusRouteDao(); + if (busRouteDao == null) + busRouteDao = helper.getBusRouteDao(); if (busStopDao == null) busStopDao = helper.getBusStopDao(); @@ -581,8 +582,23 @@ public class DataManager { String file = getFileFromServer(busStopUrl + busStop + ".json"); JSONObject data = new JSONObject(file); - JSONArray stopsArray = data.getJSONArray("stops"); + JSONObject routesObject = data.getJSONObject("routes"); + + HashSet<BusRoute> busRoutes = new HashSet<BusRoute>(); + for (Iterator<String> keyIter = routesObject.keys(); keyIter.hasNext();) { + String key = keyIter.next(); + + Log.i(TAG, "Route Key: " + key); + + BusRoute route = busRouteDao.queryForId(Integer.parseInt(key.substring(key.length() - 3, key.length()))); + + if (route != null) { + busRoutes.add(route); + } else { + throw new RuntimeException("Route not found " + key.substring(key.length() - 3, key.length()) + " " + key); + } + } Log.i(TAG, "Number of entries " + data.length()); @@ -604,7 +620,7 @@ public class DataManager { Log.e(TAG, "BusStopObj == null"); } - Stop stop = getStop(context, stopObj, busStopObj); + Stop stop = getStop(context, stopObj, busRoutes, busStopObj); if (stop == null) { Log.w(TAG, "Null stop, skiping"); diff --git a/src/net/cbaines/suma/Stop.java b/src/net/cbaines/suma/Stop.java index 7947bed..b2452bd 100644 --- a/src/net/cbaines/suma/Stop.java +++ b/src/net/cbaines/suma/Stop.java @@ -31,16 +31,10 @@ import android.text.format.DateUtils; */ public class Stop { - public static final String ID_FIELD_NAME = "id"; - public static final String BUS_FIELD_NAME = "bus"; - public static final String BUS_STOP_FIELD_NAME = "busStop"; - public static final String ARIVAL_TIME_FIELD_NAME = "arivalTime"; - public static final String FETCH_TIME_FIELD_NAME = "timeOfFetch"; - - /** - * A generated id for the bus - */ - int id; + // public static final String BUS_FIELD_NAME = "bus"; + // public static final String BUS_STOP_FIELD_NAME = "busStop"; + // public static final String ARIVAL_TIME_FIELD_NAME = "arivalTime"; + // public static final String FETCH_TIME_FIELD_NAME = "timeOfFetch"; /** * The Bus stopping at the stop @@ -68,6 +62,11 @@ public class Stop { boolean live; /** + * Assumed to be the number of seconds since this data was fetched from the ROMANSE system? + */ + int age; + + /** * * @param bus * @param busStop @@ -101,7 +100,6 @@ public class Stop { result = prime * result + ((arivalTime == null) ? 0 : arivalTime.hashCode()); result = prime * result + ((bus == null) ? 0 : bus.hashCode()); result = prime * result + ((busStop == null) ? 0 : busStop.hashCode()); - result = prime * result + id; return result; } @@ -138,8 +136,6 @@ public class Stop { return false; } else if (!busStop.equals(other.busStop)) return false; - if (id != other.id) - return false; return true; } |