diff options
author | Christopher Baines <cbaines8@gmail.com> | 2012-01-30 16:19:11 +0000 |
---|---|---|
committer | Christopher Baines <cbaines8@gmail.com> | 2012-01-30 16:19:11 +0000 |
commit | d38c32e3cabc5126b68f7a2a54101298696ee68f (patch) | |
tree | 40dcc271dd6e9ed4517f302086a2abe7aae7f9ae | |
parent | 7d6d2399e3e750a215f191c2f0d77319e3eb46f2 (diff) | |
download | southamptonuniversitymap-d38c32e3cabc5126b68f7a2a54101298696ee68f.tar southamptonuniversitymap-d38c32e3cabc5126b68f7a2a54101298696ee68f.tar.gz |
Route movement improment stuff, need to regenerate the database.
-rw-r--r-- | assets/routes.csv | 2 | ||||
-rw-r--r-- | src/net/cbaines/suma/BusRoute.java | 28 | ||||
-rw-r--r-- | src/net/cbaines/suma/BusStopActivity.java | 106 |
3 files changed, 114 insertions, 22 deletions
diff --git a/assets/routes.csv b/assets/routes.csv index 4c48bb4..5f25362 100644 --- a/assets/routes.csv +++ b/assets/routes.csv @@ -2,5 +2,5 @@ 326,U1,"NOC - Parkway - Eastleigh",C,A 468,U1N,"Leisure World - City Centre -" 329,U2,"Civic Centre - Highfield Campus",C,B -327,U6,"Dock Gate 4 - General Hospital",C,H +327,U6,"Dock Gate 4 - General Hospital",H,C 354,U9,"Townhill Park - General Hospital" diff --git a/src/net/cbaines/suma/BusRoute.java b/src/net/cbaines/suma/BusRoute.java index e3acddf..5af89e7 100644 --- a/src/net/cbaines/suma/BusRoute.java +++ b/src/net/cbaines/suma/BusRoute.java @@ -147,23 +147,39 @@ public class BusRoute { List<RouteStops> routeStopsFound = routeStopsDao.query(routeStopsPreparedQuery); Log.v("BusRoute", "Found " + routeStopsFound.size() + " stops"); + + int stopIndex = 0; + + for (RouteStops routeStop : routeStopsFound) { + if (routeStop.stop.id.equals(stop.id)) { + stopIndex = routeStop.sequence -1; + } + } if (moveAmount > 0) { - Log.v("BusRoute", "Moving forward in direction " + direction + " " + moveAmount + " stops"); - - int stopWanted = (routeStopsFound.indexOf(stop) + moveAmount) % (routeStopsFound.size() + 1); + Log.v("BusStop", "stopIndex " + stopIndex); + int stopWanted = (stopIndex + moveAmount) % (routeStopsFound.size() + 1); + Log.v("BusStop", "stopWanted " + stopWanted); busStopDao.refresh(routeStopsFound.get(stopWanted).stop); + Log.v("BusRoute", + "Moving forward in direction " + direction + " " + moveAmount + " stops from " + stop + " to " + routeStopsFound.get(stopWanted).stop + + " in route " + this); + return routeStopsFound.get(stopWanted).stop; } else { - Log.v("BusRoute", "Moving backwards in direction " + direction + " " + moveAmount + " stops"); - - int stopWanted = routeStopsFound.indexOf(stop) + moveAmount; + Log.v("BusStop", "stopIndex " + stopIndex); + int stopWanted = stopIndex + moveAmount; if (stopWanted < 0) { stopWanted = routeStopsFound.size() - (Math.abs(stopWanted) % routeStopsFound.size()); } + Log.v("BusStop", "stopWanted " + stopWanted); busStopDao.refresh(routeStopsFound.get(stopWanted).stop); + Log.v("BusRoute", + "Moving backwards in direction " + direction + " " + moveAmount + " stops from " + stop + " to " + routeStopsFound.get(stopWanted).stop + + " in route " + this); + return routeStopsFound.get(stopWanted).stop; } diff --git a/src/net/cbaines/suma/BusStopActivity.java b/src/net/cbaines/suma/BusStopActivity.java index d97baa4..ad26c41 100644 --- a/src/net/cbaines/suma/BusStopActivity.java +++ b/src/net/cbaines/suma/BusStopActivity.java @@ -30,6 +30,7 @@ import org.json.JSONException; import android.content.Context; import android.content.Intent; import android.content.SharedPreferences; +import android.graphics.Path.Direction; import android.os.AsyncTask; import android.os.Bundle; import android.os.Handler; @@ -327,31 +328,39 @@ public class BusStopActivity extends OrmLiteBaseActivity<DatabaseHelper> impleme Log.v(TAG, "Got a request for the stop movement"); if (visibleTimetable.size() != 0) { HashSet<BusRoute> routes = new HashSet<BusRoute>(); + HashSet<String> directions = new HashSet<String>(); for (Stop stop : visibleTimetable) { routes.add(stop.bus.route); } + Log.i(TAG, "routes " + routes); Log.v(TAG, routes.size() + " routes in the visible timetable"); - if (routes.size() == 1) { - HashSet<String> directions = new HashSet<String>(); + for (Stop stop : visibleTimetable) { + directions.add(stop.bus.direction); + } - for (Stop stop : visibleTimetable) { - directions.add(stop.bus.direction); - } + Log.i(TAG, "directions " + directions); + + if (routes.size() == 1) { Log.v(TAG, directions.size() + " directions in the visible timetable"); + String direction; if (directions.size() <= 1) { + if (directions.size() == 0) { + direction = null; + } else { + direction = directions.iterator().next(); + } + try { BusStop stop; if (item.getItemId() == R.id.menu_next_stop) { - stop = routes.iterator().next() - .moveInRoute(this, getHelper().getBusStopDao().queryForId(busStopID), directions.iterator().next(), 1); + stop = routes.iterator().next().moveInRoute(this, getHelper().getBusStopDao().queryForId(busStopID), direction, 1); } else { - stop = routes.iterator().next() - .moveInRoute(this, getHelper().getBusStopDao().queryForId(busStopID), directions.iterator().next(), -1); + stop = routes.iterator().next().moveInRoute(this, getHelper().getBusStopDao().queryForId(busStopID), direction, -1); } Intent i = new Intent(this, BusStopActivity.class); if (stop.id == null) { @@ -363,14 +372,81 @@ public class BusStopActivity extends OrmLiteBaseActivity<DatabaseHelper> impleme } catch (SQLException e) { e.printStackTrace(); } - } else { - // Show dialog + } else { // Same route, different directions? + // ATM, this is not considered possible? + Log.e(TAG, "Big mistake in onOptionsItemSelected in BusStopActivity"); } } else { - // if (all routes point to the same (next/previous) stop) { - // move to that stop - // else - // Show dialog + HashSet<BusStop> stops = new HashSet<BusStop>(); + + if (directions.size() <= 1) { + + for (BusRoute route : routes) { + try { + if (item.getItemId() == R.id.menu_next_stop) { + stops.add(route.moveInRoute(this, getHelper().getBusStopDao().queryForId(busStopID), directions.iterator().next(), 1)); + } else { + stops.add(route.moveInRoute(this, getHelper().getBusStopDao().queryForId(busStopID), directions.iterator().next(), -1)); + } + } catch (SQLException e) { + e.printStackTrace(); + } + } + + Log.i(TAG, "stops " + stops); + + if (stops.size() == 1) { + Intent i = new Intent(this, BusStopActivity.class); + BusStop stop = stops.iterator().next(); + if (stop.id == null) { + Log.e(TAG, "next.id == null"); + } + i.putExtra("busStopID", stop.id); + i.putExtra("busStopName", stop.description); + startActivity(i); + } else { + // Show dialog + Log.i(TAG, "Showing dialog"); + } + + } else { + + for (String direction : directions) { + + for (BusRoute route : routes) { + try { + BusStop stop; + if (item.getItemId() == R.id.menu_next_stop) { + stop = route.moveInRoute(this, getHelper().getBusStopDao().queryForId(busStopID), direction, 1); + } else { + stop = route.moveInRoute(this, getHelper().getBusStopDao().queryForId(busStopID), direction, -1); + } + if (stop != null) { + stops.add(stop); + } + } catch (SQLException e) { + e.printStackTrace(); + } + } + } + + Log.i(TAG, "stops " + stops); + + if (stops.size() == 1) { + Intent i = new Intent(this, BusStopActivity.class); + BusStop stop = stops.iterator().next(); + if (stop.id == null) { + Log.e(TAG, "next.id == null"); + } + i.putExtra("busStopID", stop.id); + i.putExtra("busStopName", stop.description); + startActivity(i); + } else { + // Show dialog + Log.i(TAG, "Showing dialog"); + } + + } } } } else if (item.getItemId() == R.id.menu_refresh_stop) { |