aboutsummaryrefslogtreecommitdiff
path: root/src/net/cbaines
diff options
context:
space:
mode:
authorChristopher Baines <cbaines8@gmail.com>2012-03-01 20:36:22 +0000
committerChristopher Baines <cbaines8@gmail.com>2012-03-01 20:36:22 +0000
commit75dc55b83cf983872f3f84b8950da27738f46b3e (patch)
treeeb502cf963ce67a837477b1e04ec7c74aa20b57e /src/net/cbaines
parent8e2005fa2650b142b89799249b07ea72bdbcc906 (diff)
downloadsouthamptonuniversitymap-75dc55b83cf983872f3f84b8950da27738f46b3e.tar
southamptonuniversitymap-75dc55b83cf983872f3f84b8950da27738f46b3e.tar.gz
Better toasts in the BusStopActivity, many other improvements.
Diffstat (limited to 'src/net/cbaines')
-rw-r--r--src/net/cbaines/suma/Bus.java194
-rw-r--r--src/net/cbaines/suma/BusActivity.java95
-rw-r--r--src/net/cbaines/suma/BusSpecificStopView.java11
-rw-r--r--src/net/cbaines/suma/BusStopActivity.java15
-rw-r--r--src/net/cbaines/suma/DataManager.java148
-rw-r--r--src/net/cbaines/suma/DatabaseHelper.java2
-rw-r--r--src/net/cbaines/suma/MapActivity.java2
-rw-r--r--src/net/cbaines/suma/StopView.java41
8 files changed, 242 insertions, 266 deletions
diff --git a/src/net/cbaines/suma/Bus.java b/src/net/cbaines/suma/Bus.java
index b36dd89..865384f 100644
--- a/src/net/cbaines/suma/Bus.java
+++ b/src/net/cbaines/suma/Bus.java
@@ -31,100 +31,106 @@ import com.j256.ormlite.table.DatabaseTable;
@DatabaseTable(tableName = "buses")
public class Bus {
- final static String ID_FIELD_NAME = "id";
- final static String ROUTE_FIELD_NAME = "route";
- final static String DIRECTION_FIELD_NAME = "direction";
-
- @DatabaseField(generatedId = true)
- int gid;
-
- /**
- * The identification number of the bus.
- */
- @DatabaseField(canBeNull = true)
- String id;
-
- /**
- * The route the bus is travelling.
- */
- @DatabaseField(canBeNull = false, foreign = true)
- BusRoute route;
-
- /**
- * The direction which the bus is travelling.
- */
- @DatabaseField(canBeNull = true)
- String direction;
-
- /**
- * The destination the bus is travelling towards.
- */
- @DatabaseField(canBeNull = true, foreign = true)
- BusStop destination;
-
- Bus() {
- }
-
- /**
- * Create a bus.
- *
- * @param id
- * The identification number of the bus.
- * @param route
- * The route the bus is travelling.
- * @param dir
- * The direction which the bus is travelling.
- */
- Bus(String id, BusRoute route, String direction) {
- this.id = id;
- this.route = route;
- this.direction = direction;
- }
-
- /**
- * Create a bus.
- *
- * @param id
- * The identification number of the bus.
- * @param route
- * The route the bus is travelling.
- */
- Bus(String id, BusRoute route) {
- this(id, route, null);
- }
-
- public String toString() {
- return String.valueOf(id + " (" + route.code + direction + ")");
- }
-
- String getName() {
- if (direction != null) {
- return route.code + direction;
- } else {
- return route.code;
+ final static String ID_FIELD_NAME = "id";
+ final static String ROUTE_FIELD_NAME = "route";
+ final static String DIRECTION_FIELD_NAME = "direction";
+
+ @DatabaseField(generatedId = true)
+ int gid;
+
+ /**
+ * The identification number of the bus.
+ */
+ @DatabaseField(canBeNull = true)
+ String id;
+
+ /**
+ * The route the bus is travelling.
+ */
+ @DatabaseField(canBeNull = false, foreign = true)
+ BusRoute route;
+
+ /**
+ * The direction which the bus is travelling.
+ */
+ @DatabaseField(canBeNull = true)
+ String direction;
+
+ /**
+ * The destination the bus is travelling towards.
+ */
+ @DatabaseField(canBeNull = true, foreign = true)
+ BusStop destination;
+
+ /**
+ * The destination the bus is travelling towards.
+ */
+ @DatabaseField(canBeNull = true)
+ String destinationString;
+
+ Bus() {
+ }
+
+ /**
+ * Create a bus.
+ *
+ * @param id
+ * The identification number of the bus.
+ * @param route
+ * The route the bus is travelling.
+ * @param dir
+ * The direction which the bus is travelling.
+ */
+ Bus(String id, BusRoute route, String direction) {
+ this.id = id;
+ this.route = route;
+ this.direction = direction;
+ }
+
+ /**
+ * Create a bus.
+ *
+ * @param id
+ * The identification number of the bus.
+ * @param route
+ * The route the bus is travelling.
+ */
+ Bus(String id, BusRoute route) {
+ this(id, route, null);
+ }
+
+ public String toString() {
+ return String.valueOf(id + " (" + route.code + direction + ")");
+ }
+
+ String getName() {
+ if (direction != null) {
+ return route.code + direction;
+ } else {
+ return route.code;
+ }
+ }
+
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + gid;
+ return result;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj)
+ return true;
+ if (obj == null)
+ return false;
+ if (getClass() != obj.getClass())
+ return false;
+ Bus other = (Bus) obj;
+ if (id != other.id)
+ return false;
+ return true;
}
- }
-
- @Override
- public int hashCode() {
- final int prime = 31;
- int result = 1;
- result = prime * result + gid;
- return result;
- }
-
- @Override
- public boolean equals(Object obj) {
- if (this == obj)
- return true;
- if (obj == null)
- return false;
- if (getClass() != obj.getClass())
- return false;
- Bus other = (Bus) obj;
- if (id != other.id)
- return false;
- return true;
- }
}
diff --git a/src/net/cbaines/suma/BusActivity.java b/src/net/cbaines/suma/BusActivity.java
index 1a8baf9..c1519ec 100644
--- a/src/net/cbaines/suma/BusActivity.java
+++ b/src/net/cbaines/suma/BusActivity.java
@@ -28,6 +28,7 @@ public class BusActivity extends OrmLiteBaseActivity<DatabaseHelper> implements
final static String TAG = "BusActivity";
private TextView busIDTextView;
+ private TextView busDestTextView;
private TextView busContentMessage;
private LinearLayout busActivityContentLayout;
@@ -64,28 +65,22 @@ public class BusActivity extends OrmLiteBaseActivity<DatabaseHelper> implements
setContentView(R.layout.bus_activity);
instance = this;
- Log.i(TAG, "getIntent().getDataString() " + getIntent().getDataString());
-
String busID;
if (getIntent().getDataString().startsWith("http://data")) {
-
String[] uriParts = getIntent().getDataString().split("/");
-
busID = uriParts[uriParts.length - 1].replace(".html", "");
-
} else {
-
String[] uriParts = getIntent().getDataString().split("/");
-
busID = uriParts[uriParts.length - 1];
}
String busStopID = getIntent().getExtras().getString("busStopID");
- final DatabaseHelper helper = getHelper();
try {
+ final DatabaseHelper helper = getHelper();
List<Bus> buses = helper.getBusDao().queryForEq(Bus.ID_FIELD_NAME, busID);
+
bus = null;
if (buses.size() == 0) {
Log.e(TAG, "Bus " + busID + " not found!");
@@ -110,6 +105,7 @@ public class BusActivity extends OrmLiteBaseActivity<DatabaseHelper> implements
}
busIDTextView = (TextView) findViewById(R.id.busActivityBusID);
+ busDestTextView = (TextView) findViewById(R.id.busActivityBusDestination);
busContentMessage = (TextView) findViewById(R.id.busActivityMessage);
busActivityContentLayout = (LinearLayout) findViewById(R.id.busActivityContentLayout);
@@ -124,58 +120,53 @@ public class BusActivity extends OrmLiteBaseActivity<DatabaseHelper> implements
busIDTextView.setText("Unidentified");
}
- } catch (NumberFormatException e) {
- e.printStackTrace();
- } catch (SQLException e) {
- e.printStackTrace();
- }
+ if (bus.destinationString != null) {
+ Log.i(TAG, "Bus destination string is " + bus.destinationString);
+ busDestTextView.setText(bus.destinationString);
+ busDestTextView.setVisibility(View.VISIBLE);
+ } else {
+ Log.i(TAG, "Bus destination string is null");
+ busDestTextView.setVisibility(View.GONE);
+ }
- busStops = bus.route.getRouteSection(instance, bus.direction);
- Log.i(TAG, "Got " + busStops.size() + " bus stops for this bus");
+ busStops = bus.route.getRouteSection(instance, bus.direction);
+ Log.i(TAG, "Got " + busStops.size() + " bus stops for this bus");
- if (bus.destination != null) {
- Log.i(TAG, "Bus destination is " + bus.destination);
- } else {
- Log.i(TAG, "Bus destination is null");
- }
+ if (bus.destination != null) {
+ Log.i(TAG, "Bus destination is " + bus.destination);
+ } else {
+ Log.i(TAG, "Bus destination is null");
+ }
+
+ refreshData = new Runnable() {
+ public void run() {
+ for (int num = timetableView.getFirstVisiblePosition(); num < timetableView.getLastVisiblePosition(); num++) {
+ Stop stop = timetable.get(num);
- /*
- * for (int i = 0;; i++) { BusStop nextStop = bus.route.moveInRoute(instance, busStops.get(i), bus.direction, 1);
- *
- * if (nextStop.equals(busStop) || (bus.destination != null && bus.destination.equals(nextStop))) { break; }
- *
- * busStops.add(nextStop); busStopsActive.add(false);
- *
- * if (busStops.size() > 50) { Log.e(TAG, "Got more than 50 bus stops"); break; } }
- */
-
- refreshData = new Runnable() {
- public void run() {
- for (int num = timetableView.getFirstVisiblePosition(); num < timetableView.getLastVisiblePosition(); num++) {
- Stop stop = timetable.get(num);
-
- GetTimetableStopTask task = tasks.get(busStops.get(num));
-
- if (stop.timeOfFetch == null || (stop.timeOfFetch.getTime() - System.currentTimeMillis()) > 20000) {
- if (task != null) {
- if (task.getStatus() == AsyncTask.Status.FINISHED) {
- task = null;
+ GetTimetableStopTask task = tasks.get(busStops.get(num));
+
+ if (stop.timeOfFetch == null || (stop.timeOfFetch.getTime() - System.currentTimeMillis()) > 20000) {
+ if (task != null) {
+ if (task.getStatus() == AsyncTask.Status.FINISHED) {
+ task = null;
+ }
}
- }
- if (task == null) {
- task = new GetTimetableStopTask();
- BusStop[] str = { stop.busStop };
- task.execute(str);
- tasks.put(stop.busStop, task);
+ if (task == null) {
+ task = new GetTimetableStopTask();
+ BusStop[] str = { stop.busStop };
+ task.execute(str);
+ tasks.put(stop.busStop, task);
+ }
}
- }
+ }
+ handler.postDelayed(refreshData, 50000);
}
- handler.postDelayed(refreshData, 50000);
- }
- };
-
+ };
+ } catch (SQLException e) {
+ e.printStackTrace();
+ }
}
public void onResume() {
diff --git a/src/net/cbaines/suma/BusSpecificStopView.java b/src/net/cbaines/suma/BusSpecificStopView.java
index 610ee76..deaf932 100644
--- a/src/net/cbaines/suma/BusSpecificStopView.java
+++ b/src/net/cbaines/suma/BusSpecificStopView.java
@@ -24,7 +24,6 @@ import java.text.DateFormat;
import android.app.Activity;
import android.content.Intent;
-import android.util.Log;
import android.view.Gravity;
import android.view.View;
import android.view.View.OnClickListener;
@@ -76,16 +75,6 @@ public class BusSpecificStopView extends LinearLayout implements OnClickListener
this.stop = stop;
- if (stop == null) {
- Log.e(TAG, "stop == null");
- }
- if (stop.busStop == null) {
- Log.e(TAG, "stop.busStop == null");
- }
- if (stop.busStop.description == null) {
- Log.e(TAG, "stop.busStop.description == null");
- }
-
if (stop.busStop.description.length() > 20) {
location.setText(stop.busStop.description.substring(0, 20)); // TODO
} else {
diff --git a/src/net/cbaines/suma/BusStopActivity.java b/src/net/cbaines/suma/BusStopActivity.java
index 81dbcc1..9f422af 100644
--- a/src/net/cbaines/suma/BusStopActivity.java
+++ b/src/net/cbaines/suma/BusStopActivity.java
@@ -54,15 +54,13 @@ import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.ProgressBar;
import android.widget.TextView;
-import android.widget.Toast;
-import com.j256.ormlite.android.apptools.OrmLiteBaseActivity;
import com.j256.ormlite.dao.Dao;
import com.j256.ormlite.stmt.PreparedQuery;
import com.j256.ormlite.stmt.QueryBuilder;
-public class BusStopActivity extends OrmLiteBaseActivity<DatabaseHelper> implements OnCheckedChangeListener, Preferences,
- OnItemClickListener, OnLongClickListener {
+public class BusStopActivity extends ToastHelperActivity implements OnCheckedChangeListener, Preferences, OnItemClickListener,
+ OnLongClickListener {
final static String TAG = "BusTimeActivity";
@@ -97,8 +95,6 @@ public class BusStopActivity extends OrmLiteBaseActivity<DatabaseHelper> impleme
private HashSet<BusRoute> routes = new HashSet<BusRoute>();
- Toast activityToast;
-
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.bus_stop_activity);
@@ -214,14 +210,18 @@ public class BusStopActivity extends OrmLiteBaseActivity<DatabaseHelper> impleme
busName = (TextView) findViewById(R.id.busStopName);
+ busID = (TextView) findViewById(R.id.busStopID);
if (prefs.getBoolean(SHOW_IDENTIFIERS, SHOW_IDENTIFIERS_ENABLED_BY_DEFAULT)) {
- busID = (TextView) findViewById(R.id.busStopID);
busID.setText(busStopID);
busID.setVisibility(View.VISIBLE);
+ } else {
+ busID.setVisibility(View.GONE);
}
busStopMessage = (TextView) findViewById(R.id.busStopMessage);
+ busStopMessage.setVisibility(View.GONE);
progBar = (ProgressBar) findViewById(R.id.busStopLoadBar);
+ progBar.setVisibility(View.GONE);
busTimeList = (ListView) findViewById(R.id.busStopTimes);
busTimeContentLayout = (LinearLayout) findViewById(R.id.busTimeContentLayout);
@@ -353,6 +353,7 @@ public class BusStopActivity extends OrmLiteBaseActivity<DatabaseHelper> impleme
busStopMessage.setVisibility(View.VISIBLE);
} else {
progBar.setVisibility(View.GONE);
+ busStopMessage.setVisibility(View.GONE);
timetable = newTimetable;
displayTimetable(timetable);
}
diff --git a/src/net/cbaines/suma/DataManager.java b/src/net/cbaines/suma/DataManager.java
index 5e8b195..ab1f3a7 100644
--- a/src/net/cbaines/suma/DataManager.java
+++ b/src/net/cbaines/suma/DataManager.java
@@ -137,13 +137,9 @@ public class DataManager {
/*
* Polygon poly = buildingPolys.get(dataBits[1]);
*
- * if (poly != null) { bdg.outline = poly; // Log.i(TAG,
- * "Adding building " + key + " " +
- * bdg.point.getLatitudeE6() + " " +
- * bdg.point.getLongitudeE6() + " " + poly); } else { //
- * Log.i(TAG, "Adding building " + key + " " +
- * bdg.point.getLatitudeE6() + " " +
- * bdg.point.getLongitudeE6()); }
+ * if (poly != null) { bdg.outline = poly; // Log.i(TAG, "Adding building " + key + " " +
+ * bdg.point.getLatitudeE6() + " " + bdg.point.getLongitudeE6() + " " + poly); } else { // Log.i(TAG,
+ * "Adding building " + key + " " + bdg.point.getLatitudeE6() + " " + bdg.point.getLongitudeE6()); }
*/
// Log.i(TAG, "Creating building " + bdg.id + " " + bdg.name
@@ -167,13 +163,9 @@ public class DataManager {
/*
* Polygon poly = buildingPolys.get(dataBits[1]);
*
- * if (poly != null) { bdg.outline = poly; // Log.i(TAG,
- * "Adding building " + key + " " +
- * bdg.point.getLatitudeE6() + " " +
- * bdg.point.getLongitudeE6() + " " + poly); } else { //
- * Log.i(TAG, "Adding building " + key + " " +
- * bdg.point.getLatitudeE6() + " " +
- * bdg.point.getLongitudeE6()); }
+ * if (poly != null) { bdg.outline = poly; // Log.i(TAG, "Adding building " + key + " " +
+ * bdg.point.getLatitudeE6() + " " + bdg.point.getLongitudeE6() + " " + poly); } else { // Log.i(TAG,
+ * "Adding building " + key + " " + bdg.point.getLatitudeE6() + " " + bdg.point.getLongitudeE6()); }
*/
// Log.i(TAG, "Creating building " + bdg.id + " " + bdg.name
@@ -192,17 +184,13 @@ public class DataManager {
}
/*
- * for (Iterator<String> iter = buildingPoints.keySet().iterator();
- * iter.hasNext();) { String key = iter.next();
+ * for (Iterator<String> iter = buildingPoints.keySet().iterator(); iter.hasNext();) { String key = iter.next();
*
- * Building bdg = new Building(key, buildingPoints.get(key), false);
- * Polygon poly = buildingPolys.get(key);
+ * Building bdg = new Building(key, buildingPoints.get(key), false); Polygon poly = buildingPolys.get(key);
*
- * if (poly != null) { bdg.outline = poly; // Log.i(TAG,
- * "Adding building " + key + " " + bdg.point.getLatitudeE6() + " " +
- * bdg.point.getLongitudeE6() + " " + poly); } else { // Log.i(TAG,
- * "Adding building " + key + " " + bdg.point.getLatitudeE6() + " " +
- * bdg.point.getLongitudeE6()); }
+ * if (poly != null) { bdg.outline = poly; // Log.i(TAG, "Adding building " + key + " " + bdg.point.getLatitudeE6() + " "
+ * + bdg.point.getLongitudeE6() + " " + poly); } else { // Log.i(TAG, "Adding building " + key + " " +
+ * bdg.point.getLatitudeE6() + " " + bdg.point.getLongitudeE6()); }
*
* buildingDao.create(bdg); }
*/
@@ -239,18 +227,18 @@ public class DataManager {
// Log.i(TAG, "Whole " + dataBits[3] + " First bit " +
// quBitsLat[0] + " last bit " + quBitsLat[1]);
- double lat = Double.valueOf(quBitsLat[0])
- + Double.valueOf(quBitsLat[1].substring(0, quBitsLat[1].length() - 1)) / 60d;
+ double lat = Double.valueOf(quBitsLat[0]) + Double.valueOf(quBitsLat[1].substring(0, quBitsLat[1].length() - 1))
+ / 60d;
// Log.i(TAG, "Whole " + dataBits[4] + " First bit " +
// quBitsLng[0] + " last bit " + quBitsLng[1]);
- double lng = Double.valueOf(quBitsLng[0])
- + Double.valueOf(quBitsLng[1].substring(0, quBitsLng[1].length() - 1)) / 60d;
+ double lng = Double.valueOf(quBitsLng[0]) + Double.valueOf(quBitsLng[1].substring(0, quBitsLng[1].length() - 1))
+ / 60d;
GeoPoint point = new GeoPoint((int) (lat * 1e6), (int) (lng * -1e6));
// Log.i(TAG, "Lat " + point.getLatitudeE6() + " lng " +
// point.getLongitudeE6());
- busStopDao.create(new BusStop(dataBits[0].replace("\"", ""), dataBits[1].replace("\"", ""), dataBits[2]
- .replace("\"", ""), point));
+ busStopDao.create(new BusStop(dataBits[0].replace("\"", ""), dataBits[1].replace("\"", ""), dataBits[2].replace(
+ "\"", ""), point));
}
@@ -371,36 +359,26 @@ public class DataManager {
}
/*
- * for (Iterator<BusStop> busStopIter = busStopDao.iterator();
- * busStopIter.hasNext();) { BusStop stop = busStopIter.next(); //
- * Log.i(TAG, "Looking at stop " + stop.id);
+ * for (Iterator<BusStop> busStopIter = busStopDao.iterator(); busStopIter.hasNext();) { BusStop stop =
+ * busStopIter.next(); // Log.i(TAG, "Looking at stop " + stop.id);
*
*
- * QueryBuilder<RouteStops, Integer> routeStopsQueryBuilder =
- * routeStopsDao.queryBuilder();
+ * QueryBuilder<RouteStops, Integer> routeStopsQueryBuilder = routeStopsDao.queryBuilder();
* routeStopsQueryBuilder.where().eq(columnName, value)
*
- * DeleteBuilder<BusStop, String> deleteBuilder =
- * busStopDao.deleteBuilder(); // only delete the rows where password is
- * null deleteBuilder.where().in(RouteStops.STOP_ID_FIELD_NAME, objects)
- * accountDao.delete(deleteBuilder.prepare());
+ * DeleteBuilder<BusStop, String> deleteBuilder = busStopDao.deleteBuilder(); // only delete the rows where password is
+ * null deleteBuilder.where().in(RouteStops.STOP_ID_FIELD_NAME, objects) accountDao.delete(deleteBuilder.prepare());
*
*
- * QueryBuilder<RouteStops, Integer> routeStopsQueryBuilder =
- * routeStopsDao.queryBuilder();
- * routeStopsQueryBuilder.setCountOf(true);
- * routeStopsQueryBuilder.where().eq(RouteStops.STOP_ID_FIELD_NAME,
- * stop);
+ * QueryBuilder<RouteStops, Integer> routeStopsQueryBuilder = routeStopsDao.queryBuilder();
+ * routeStopsQueryBuilder.setCountOf(true); routeStopsQueryBuilder.where().eq(RouteStops.STOP_ID_FIELD_NAME, stop);
*
- * PreparedQuery<RouteStops> routeStopsPreparedQuery =
- * routeStopsQueryBuilder.prepare(); List<RouteStops> routeStops =
- * routeStopsDao.query(routeStopsPreparedQuery); // long num =
- * routeStopsDao.query(routeStopsPreparedQuery).size(); // Log.i(TAG,
- * "Number is " + num);
+ * PreparedQuery<RouteStops> routeStopsPreparedQuery = routeStopsQueryBuilder.prepare(); List<RouteStops> routeStops =
+ * routeStopsDao.query(routeStopsPreparedQuery); // long num = routeStopsDao.query(routeStopsPreparedQuery).size(); //
+ * Log.i(TAG, "Number is " + num);
*
- * stop.uniLink = false; for (RouteStops routeStop : routeStops) { if
- * (routeStop.busRoute.uniLink) { stop.uniLink = true; } }
- * busStopDao.update(stop); }
+ * stop.uniLink = false; for (RouteStops routeStop : routeStops) { if (routeStop.busRoute.uniLink) { stop.uniLink = true;
+ * } } busStopDao.update(stop); }
*/
Log.i(TAG, "Finished loading bus data");
@@ -450,7 +428,7 @@ public class DataManager {
Log.i(TAG, "Loaded sites from csv");
}
- private static Stop getStop(Context context, JSONObject stopObj, Set<BusRoute> routes, BusStop busStop)
+ private static Stop getStop(Context context, JSONObject stopObj, Set<BusRoute> routes, BusStop busStop, int age)
throws SQLException, JSONException {
if (helper == null)
@@ -484,6 +462,7 @@ public class DataManager {
// + " for min");
calender.add(Calendar.MINUTE, Integer.parseInt(time.substring(0, time.length() - 1)));
}
+ calender.add(Calendar.SECOND, age);
// Log.v(TAG, "Date: " + calender.getTime());
}
@@ -575,11 +554,9 @@ public class DataManager {
List<RouteStop> routeStops = routeStopsDao.query(routeStopsPreparedQuery);
if (routeStops.size() > 0) {
- Log.i(TAG, "Found " + routeStops.size() + " stops matching the destStop " + destStop + " on route "
- + route.code);
+ Log.i(TAG, "Found " + routeStops.size() + " stops matching the destStop " + destStop + " on route " + route.code);
} else {
- Log.w(TAG, "Found " + routeStops.size() + " stops matching the destStop " + destStop + " on route "
- + route.code);
+ Log.w(TAG, "Found " + routeStops.size() + " stops matching the destStop " + destStop + " on route " + route.code);
}
}
@@ -600,9 +577,11 @@ public class DataManager {
if (bus == null) {
bus = new Bus(busID, route, dir);
bus.destination = destStop;
+ bus.destinationString = destString;
busDao.create(bus);
} else {
bus.destination = destStop;
+ bus.destinationString = destString;
bus.route = route;
bus.direction = dir;
busDao.update(bus);
@@ -610,6 +589,8 @@ public class DataManager {
} else {
bus = new Bus(null, route, dir);
+ bus.destinationString = destString;
+ bus.destination = destStop;
busDao.create(bus);
}
@@ -618,6 +599,19 @@ public class DataManager {
return stop;
}
+ /**
+ * Get the timetable for the bus stop.
+ *
+ * @param context
+ * @param busStop
+ * @param keepUniLink
+ * @param keepNonUniLink
+ * @return
+ * @throws SQLException
+ * @throws ClientProtocolException
+ * @throws IOException
+ * @throws JSONException
+ */
public static Timetable getTimetable(Context context, String busStop, boolean keepUniLink, boolean keepNonUniLink)
throws SQLException, ClientProtocolException, IOException, JSONException {
@@ -637,7 +631,8 @@ public class DataManager {
JSONObject routesObject = data.getJSONObject("routes");
HashSet<BusRoute> busRoutes = new HashSet<BusRoute>();
- for (Iterator<String> keyIter = routesObject.keys(); keyIter.hasNext();) {
+ for (@SuppressWarnings("unchecked")
+ Iterator<String> keyIter = routesObject.keys(); keyIter.hasNext();) {
String key = keyIter.next();
Log.v(TAG, "Route Key: " + key);
@@ -647,14 +642,13 @@ public class DataManager {
if (route != null) {
busRoutes.add(route);
} else {
- throw new RuntimeException("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);
}
}
- Log.i(TAG, "Number of entries " + data.length());
+ int age = Integer.parseInt(data.getString("age"));
- Log.i(TAG, "Stops: " + data.getJSONArray("stops"));
+ Log.v(TAG, "Stops: " + data.getJSONArray("stops"));
for (int stopNum = 0; stopNum < stopsArray.length(); stopNum++) {
JSONObject stopObj = stopsArray.getJSONObject(stopNum);
@@ -674,23 +668,33 @@ public class DataManager {
Log.e(TAG, "BusStopObj == null");
}
- Stop stop = getStop(context, stopObj, busRoutes, busStopObj);
+ Stop stop = getStop(context, stopObj, busRoutes, busStopObj, age);
if (stop == null) {
- Log.w(TAG, "Null stop, skiping");
+ Log.e(TAG, "Null stop, skiping");
continue;
}
- Log.v(TAG, "Found stop for a unidentified " + stop.bus.toString() + " at " + stop.busStop.id + " at "
- + stop.arivalTime);
-
timetable.add(stop);
}
timetable.fetchTime = new Date(System.currentTimeMillis());
+
return timetable;
}
+ /**
+ *
+ * @param context
+ * @param bus
+ * @param startStop
+ * @param num
+ * @return
+ * @throws SQLException
+ * @throws ClientProtocolException
+ * @throws IOException
+ * @throws JSONException
+ */
public static Timetable getTimetable(Context context, Bus bus, BusStop startStop, int num) throws SQLException,
ClientProtocolException, IOException, JSONException {
@@ -725,6 +729,8 @@ public class DataManager {
JSONObject data = new JSONObject(file);
JSONArray stopsArray = data.getJSONArray("stops");
+ int age = Integer.parseInt(data.getString("age"));
+
HashSet<BusRoute> busRoutes = new HashSet<BusRoute>();
busRoutes.add(bus.route);
@@ -737,15 +743,15 @@ public class DataManager {
if (stopObj.getString("vehicle").equals(bus.id)) {
- Stop stop = getStop(context, stopObj, busRoutes, busStop);
+ Stop stop = getStop(context, stopObj, busRoutes, busStop, age);
if (stop == null) {
Log.w(TAG, "Null stop, skiping");
continue;
}
- Log.v(TAG, "Found stop for a unidentified " + stop.bus.toString() + " at " + stop.busStop.id
- + " at " + stop.arivalTime);
+ Log.v(TAG, "Found stop for a unidentified " + stop.bus.toString() + " at " + stop.busStop.id + " at "
+ + stop.arivalTime);
timetable.add(stop);
@@ -777,6 +783,8 @@ public class DataManager {
busRouteDao.refresh(bus.route);
busRoutes.add(bus.route);
+ int age = Integer.parseInt(data.getString("age"));
+
Stop stop = null;
// Log.v(TAG, "Number of entries " + data.length());
@@ -789,7 +797,7 @@ public class DataManager {
// Log.v(TAG, "stopObj: " + stopObj);
if (stopObj.has("vehicle") && stopObj.getString("vehicle").equals(bus.id)) {
- stop = getStop(context, stopObj, busRoutes, busStop);
+ stop = getStop(context, stopObj, busRoutes, busStop, age);
break;
// Log.v(TAG, "Found stop for a unidentified " +
diff --git a/src/net/cbaines/suma/DatabaseHelper.java b/src/net/cbaines/suma/DatabaseHelper.java
index facfe85..73f4c79 100644
--- a/src/net/cbaines/suma/DatabaseHelper.java
+++ b/src/net/cbaines/suma/DatabaseHelper.java
@@ -40,7 +40,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
private static final String DATABASE_PATH = "/data/data/net.cbaines.suma/databases/";
private static final String DATABASE_NAME = "data.db";
- private static final int DATABASE_VERSION = 40;
+ private static final int DATABASE_VERSION = 41;
private static final String TAG = "DatabaseHelper";
diff --git a/src/net/cbaines/suma/MapActivity.java b/src/net/cbaines/suma/MapActivity.java
index 9dd927a..1dde4be 100644
--- a/src/net/cbaines/suma/MapActivity.java
+++ b/src/net/cbaines/suma/MapActivity.java
@@ -76,7 +76,7 @@ public class MapActivity extends ToastHelperActivity implements MapViewConstants
* 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
*/
- private boolean useBundledDatabase = true;
+ private boolean useBundledDatabase = false;
private MapView mapView;
private MapController mapController;
diff --git a/src/net/cbaines/suma/StopView.java b/src/net/cbaines/suma/StopView.java
index afe8664..fa76131 100644
--- a/src/net/cbaines/suma/StopView.java
+++ b/src/net/cbaines/suma/StopView.java
@@ -23,6 +23,7 @@ import java.sql.SQLException;
import java.text.DateFormat;
import android.content.Intent;
+import android.content.res.Resources;
import android.net.Uri;
import android.util.Log;
import android.view.Gravity;
@@ -49,6 +50,9 @@ public class StopView extends LinearLayout implements OnClickListener, OnLongCli
private Stop stop;
+ private String onClickHelpMessage;
+ private String onClickUnidentifiedMessage;
+
public StopView(BusStopActivity context, Stop stop) {
super(context);
@@ -63,6 +67,10 @@ public class StopView extends LinearLayout implements OnClickListener, OnLongCli
time.setTextSize(22f);
time.setGravity(Gravity.RIGHT);
+ Resources resources = context.getResources();
+ onClickHelpMessage = resources.getString(R.string.stop_view_on_click_toast_help_message);
+ onClickUnidentifiedMessage = resources.getString(R.string.stop_view_on_click_toast_unidentified_message);
+
setStop(stop);
addView(name, new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
@@ -111,14 +119,7 @@ public class StopView extends LinearLayout implements OnClickListener, OnLongCli
}
public void onClick(View v) {
- if (context.activityToast == null) {
- context.activityToast = Toast.makeText(context, onClickMessage, Toast.LENGTH_SHORT);
- } else {
- context.activityToast.setText(onClickMessage);
- context.activityToast.setDuration(Toast.LENGTH_SHORT);
- }
- context.activityToast.show();
-
+ context.makeToast(onClickMessage, onClickHelpMessage, Toast.LENGTH_SHORT);
}
public boolean onLongClick(View v) {
@@ -131,8 +132,7 @@ public class StopView extends LinearLayout implements OnClickListener, OnLongCli
busDao.refresh(stop.bus);
busRouteDao.refresh(stop.bus.route);
- Log.i("StopView", "Bus route " + stop.bus.route + " Uni-Link " + stop.bus.route.uniLink + " Bus ID "
- + stop.bus.id);
+ Log.i("StopView", "Bus route " + stop.bus.route + " Uni-Link " + stop.bus.route.uniLink + " Bus ID " + stop.bus.id);
if (stop.bus.id != null && stop.bus.route.uniLink) {
Uri uri = Uri.parse("http://id.southampton.ac.uk/bus/" + stop.bus.id);
@@ -141,27 +141,8 @@ public class StopView extends LinearLayout implements OnClickListener, OnLongCli
busStopIntent.putExtra("busStopID", stop.busStop.id);
context.startActivity(busStopIntent);
} else {
- if (!stop.bus.route.uniLink) {
- if (context.activityToast == null) {
- context.activityToast = Toast.makeText(context,
- "Bus schedules only avalible for Uni-Link buses", Toast.LENGTH_SHORT);
- } else {
- context.activityToast.setText("Bus schedules only avalible for Uni-Link buses");
- context.activityToast.setDuration(Toast.LENGTH_SHORT);
- }
- context.activityToast.show();
- } else {
- if (context.activityToast == null) {
- context.activityToast = Toast.makeText(context,
- "Bus schedules not avalible for unidentified buses", Toast.LENGTH_SHORT);
- } else {
- context.activityToast.setText("Bus schedules not avalible for unidentified buses");
- context.activityToast.setDuration(Toast.LENGTH_SHORT);
- }
- context.activityToast.show();
- }
+ context.makeToast(onClickUnidentifiedMessage, Toast.LENGTH_SHORT);
}
-
} catch (SQLException e) {
e.printStackTrace();
}