aboutsummaryrefslogtreecommitdiff
path: root/src/net/cbaines/suma/BusActivity.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/net/cbaines/suma/BusActivity.java')
-rw-r--r--src/net/cbaines/suma/BusActivity.java95
1 files changed, 43 insertions, 52 deletions
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() {