diff options
author | Christopher Baines <cbaines8@gmail.com> | 2012-03-01 13:42:29 +0000 |
---|---|---|
committer | Christopher Baines <cbaines8@gmail.com> | 2012-03-01 13:42:29 +0000 |
commit | 7125dc4757c29dfe9f451e51078ff59ce1521a6c (patch) | |
tree | b1b300cce753daafebae5c961fc57c560b7a0491 | |
parent | 4619835948a40c3ecffe3c7001cab295e58e5bdd (diff) | |
download | southamptonuniversitymap-7125dc4757c29dfe9f451e51078ff59ce1521a6c.tar southamptonuniversitymap-7125dc4757c29dfe9f451e51078ff59ce1521a6c.tar.gz |
Fix the bus stop movement, havent fully tested this yet as the live bus data is not working...
Conflicts:
gen/net/cbaines/suma/R.java
-rw-r--r-- | gen/net/cbaines/suma/R.java | 6 | ||||
-rw-r--r-- | res/layout/bus_stop_activity.xml | 14 | ||||
-rw-r--r-- | src/net/cbaines/suma/BusRoute.java | 42 | ||||
-rw-r--r-- | src/net/cbaines/suma/BusStopActivity.java | 33 |
4 files changed, 46 insertions, 49 deletions
diff --git a/gen/net/cbaines/suma/R.java b/gen/net/cbaines/suma/R.java index 8a2fd53..7cbd954 100644 --- a/gen/net/cbaines/suma/R.java +++ b/gen/net/cbaines/suma/R.java @@ -73,11 +73,11 @@ public final class R { public static final int busStopID=0x7f0a001c; public static final int busStopListItems=0x7f0a0023; public static final int busStopLoadBar=0x7f0a0021; - public static final int busStopMessage=0x7f0a001e; + public static final int busStopMessage=0x7f0a0020; public static final int busStopName=0x7f0a0014; - public static final int busStopTimes=0x7f0a001f; + public static final int busStopTimes=0x7f0a001e; public static final int busTimeContentLayout=0x7f0a001d; - public static final int centerLoadBar=0x7f0a0020; + public static final int centerLoadBar=0x7f0a001f; public static final int check1=0x7f0a0035; public static final int childname=0x7f0a0034; public static final int donateBitcoinAddress=0x7f0a0029; diff --git a/res/layout/bus_stop_activity.xml b/res/layout/bus_stop_activity.xml index 3f4dc98..7875852 100644 --- a/res/layout/bus_stop_activity.xml +++ b/res/layout/bus_stop_activity.xml @@ -107,13 +107,6 @@ android:gravity="center" android:orientation="vertical" > - <TextView - android:id="@+id/busStopMessage" - android:layout_width="wrap_content" - android:layout_height="wrap_content" - android:text="" - android:textAppearance="?android:attr/textAppearanceLarge" /> - <ListView android:id="@+id/busStopTimes" android:layout_width="fill_parent" @@ -128,6 +121,13 @@ android:gravity="center" android:orientation="vertical" > + <TextView + android:id="@+id/busStopMessage" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:text="" + android:textAppearance="?android:attr/textAppearanceLarge" /> + <ProgressBar android:id="@+id/busStopLoadBar" style="?android:attr/progressBarStyleLarge" diff --git a/src/net/cbaines/suma/BusRoute.java b/src/net/cbaines/suma/BusRoute.java index ff80c66..e57e49c 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,7 +135,8 @@ public class BusRoute { } /** - * Untested? + * Return the set of bus stops that can be thought of moveAmount away from + * the busStop. The method returns a set as * * @param context * @param busStop @@ -165,7 +169,7 @@ public class BusRoute { for (RouteStop routeStop : routeStopsFound) { if (routeStop.busStop.id.equals(busStop.id)) { - stopIndexs.add(routeStop.sequence - 1); + stopIndexs.add(routeStop.sequence); } } @@ -174,24 +178,24 @@ public class BusRoute { if (moveAmount > 0) { Log.v(TAG, "Moving forward " + moveAmount + " stops from " + busStop + " (" + stopIndex + "/" + routeStopsFound.size() + ")"); - int stopWanted = stopIndex + moveAmount; - if ((stopWanted + 1) > routeStopsFound.size()) { + int stopWantedSeq = stopIndex + moveAmount; + if (stopWantedSeq > routeStopsFound.size()) { Log.v(TAG, "Off the end of the route"); - stopWanted = stopWanted % (routeStopsFound.size() - 1); + stopWantedSeq = ((stopWantedSeq - 1) % (routeStopsFound.size())) + 1; } - Log.v(TAG, " Stop wanted " + stopWanted); - BusStop busStopWanted = routeStopsFound.get(stopWanted).busStop; + Log.v(TAG, " Stop wanted " + stopWantedSeq); + BusStop busStopWanted = routeStopsFound.get(stopWantedSeq - 1).busStop; busStopDao.refresh(busStopWanted); - Log.v(TAG, " Moving to " + busStopWanted + " (" + stopWanted + ") in route " + this); + Log.v(TAG, " Moving to " + busStopWanted + " (" + stopWantedSeq + ") in route " + this); busStops.add(busStopWanted); } else { Log.v(TAG, "stopIndex " + stopIndex); int stopWanted = stopIndex + moveAmount; - if (stopWanted < 0) { - stopWanted = routeStopsFound.size() - (Math.abs(stopWanted) % routeStopsFound.size()); + if (stopWanted < 1) { + stopWanted = routeStopsFound.size() - (Math.abs(stopWanted - 1) % routeStopsFound.size()); } Log.v(TAG, "stopWanted " + stopWanted); busStopDao.refresh(routeStopsFound.get(stopWanted).busStop); @@ -377,11 +381,10 @@ 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 + 1) > routeStopsFound.size()) { + if (stopWanted > routeStopsFound.size()) { Log.v(TAG, "Off the end of the route"); stopWanted = stopWanted % (routeStopsFound.size() - 1); } @@ -402,8 +405,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/BusStopActivity.java b/src/net/cbaines/suma/BusStopActivity.java index cab81b1..81dbcc1 100644 --- a/src/net/cbaines/suma/BusStopActivity.java +++ b/src/net/cbaines/suma/BusStopActivity.java @@ -93,7 +93,7 @@ public class BusStopActivity extends OrmLiteBaseActivity<DatabaseHelper> impleme private CheckBox U9RouteRadioButton; private static final int POI_DIALOG_ID = 0; - private POIDialog busDialog; + private POIDialog busStopDialog; private HashSet<BusRoute> routes = new HashSet<BusRoute>(); @@ -398,15 +398,9 @@ public class BusStopActivity extends OrmLiteBaseActivity<DatabaseHelper> impleme if (busStops.size() == 1) { - BusStop stop = (BusStop) busStops.iterator().next(); - if (stop == null) { - Log.e(TAG, "stop == null"); - } - if (stop.id == null) { - Log.e(TAG, "stop.id == null"); - } + BusStop nextBusStop = (BusStop) busStops.iterator().next(); - Uri uri = Uri.parse("http://id.southampton.ac.uk/bus-stop/" + busStop.id); + Uri uri = Uri.parse("http://id.southampton.ac.uk/bus-stop/" + nextBusStop.id); Log.i(TAG, "Starting a activity for " + uri + " path " + uri.getPath()); @@ -415,14 +409,14 @@ public class BusStopActivity extends OrmLiteBaseActivity<DatabaseHelper> impleme } else { showDialog(POI_DIALOG_ID); - if (busDialog == null) { + if (busStopDialog == null) { Log.e(TAG, "Very wierd, just tried to launch the favourite's dialog, but its null?"); return false; } - busDialog.setMessage(""); - busDialog.setItems(busStops); - busDialog.setTitle("Choose Bus Stop"); + busStopDialog.setMessage(""); + busStopDialog.setItems(busStops); + busStopDialog.setTitle("Choose Bus Stop"); Log.i(TAG, "Showing dialog"); } @@ -505,9 +499,9 @@ public class BusStopActivity extends OrmLiteBaseActivity<DatabaseHelper> impleme protected Dialog onCreateDialog(int id) { switch (id) { case POI_DIALOG_ID: - busDialog = new POIDialog(instance); - busDialog.setOnItemClickListener(this); - return busDialog; + busStopDialog = new POIDialog(instance); + busStopDialog.setOnItemClickListener(this); + return busStopDialog; } return null; } @@ -515,16 +509,15 @@ public class BusStopActivity extends OrmLiteBaseActivity<DatabaseHelper> impleme public void onItemClick(AdapterView<?> parent, View view, int position, long id) { Log.i(TAG, "OnItemClick pos " + position + " id " + id); - String busId = busDialog.adapter.getItemStringId(position); + String busStopID = busStopDialog.adapter.getItemStringId(position); - Log.i(TAG, "Bus " + busId + " selected"); + Log.i(TAG, "Bus " + busStopID + " selected"); - Uri uri = Uri.parse("http://id.southampton.ac.uk/bus/" + busId); + Uri uri = Uri.parse("http://id.southampton.ac.uk/bus-stop/" + busStopID); Log.i(TAG, "Starting a activity for " + uri + " path " + uri.getPath()); Intent busStopIntent = new Intent(Intent.ACTION_VIEW, uri); - busStopIntent.putExtra("busStopID", busStop.id); startActivity(busStopIntent); } |