aboutsummaryrefslogtreecommitdiff
path: root/src/net/cbaines/suma
diff options
context:
space:
mode:
authorChristopher Baines <cbaines8@gmail.com>2012-03-16 11:38:33 +0000
committerChristopher Baines <cbaines8@gmail.com>2012-03-16 11:38:33 +0000
commit915d0b3a72c5b6ed298b3984ca0224ad473b9899 (patch)
treeb37a8feb8897142a9ff7552f0790c56cfee438ce /src/net/cbaines/suma
parenta7a29da3b13d83952b65e6d97ec3588e2c023051 (diff)
downloadsouthamptonuniversitymap-915d0b3a72c5b6ed298b3984ca0224ad473b9899.tar
southamptonuniversitymap-915d0b3a72c5b6ed298b3984ca0224ad473b9899.tar.gz
More changes.
Diffstat (limited to 'src/net/cbaines/suma')
-rw-r--r--src/net/cbaines/suma/Bus.java3
-rw-r--r--src/net/cbaines/suma/BusActivity.java49
-rw-r--r--src/net/cbaines/suma/BusSpecificStopView.java10
-rw-r--r--src/net/cbaines/suma/BusStopActivity.java16
-rw-r--r--src/net/cbaines/suma/BusStopSpecificStopView.java11
-rw-r--r--src/net/cbaines/suma/BusStopSpecificTimetableAdapter.java15
-rw-r--r--src/net/cbaines/suma/DataManager.java10
7 files changed, 50 insertions, 64 deletions
diff --git a/src/net/cbaines/suma/Bus.java b/src/net/cbaines/suma/Bus.java
index 5cbf375..d971dac 100644
--- a/src/net/cbaines/suma/Bus.java
+++ b/src/net/cbaines/suma/Bus.java
@@ -56,9 +56,6 @@ public class Bus {
*/
String destinationString;
- Bus() {
- }
-
/**
* Create a bus.
*
diff --git a/src/net/cbaines/suma/BusActivity.java b/src/net/cbaines/suma/BusActivity.java
index 368d514..1659c88 100644
--- a/src/net/cbaines/suma/BusActivity.java
+++ b/src/net/cbaines/suma/BusActivity.java
@@ -131,12 +131,19 @@ public class BusActivity extends ToastHelperActivity implements Preferences {
for (int num = timetableView.getFirstVisiblePosition(); num <= timetableView.getLastVisiblePosition(); num++) {
final Stop stop = timetable.get(num);
- if (System.currentTimeMillis() - stop.timeOfFetch.getTime() > 20000) {
+ GetTimetableStopTask task = tasks.get(num);
+
+ if (task != null) { // If there is a task
+ if (task.getStatus() == AsyncTask.Status.FINISHED) {
+ task = null; // Delete it
+ }
+ }
+
+ if (System.currentTimeMillis() - stop.timeOfFetch.getTime() > 20000 && task == null) {
refreshBusStop(num);
} else {
// Log.v(TAG, "Not updating " + busStops.get(num));
}
-
}
handler.postDelayed(refreshData, 50000);
}
@@ -147,30 +154,20 @@ public class BusActivity extends ToastHelperActivity implements Preferences {
}
private void refreshBusStop(int index) {
- GetTimetableStopTask task = tasks.get(index);
- if (task != null) { // If there is a taks
- if (task.getStatus() == AsyncTask.Status.FINISHED) { // If
- // its
- // finished
- task = null; // Delete it
- }
+ // Remove the old time from the timetable
+ synchronized (timetable) {
+ timetable.set(index, new StopLoading(timetable.get(index).bus, busStops.get(index), timetable.get(index).arivalTime,
+ new Date(System.currentTimeMillis() - 21000), false));
+ displayTimetable();
}
- if (task == null) { // If there is now no task
- // Log.v(TAG, "Updating " + busStops.get(num));
-
- // Remove the old time from the timetable
- synchronized (timetable) {
- timetable.set(index, new StopLoading(timetable.get(index).bus, busStops.get(index),
- timetable.get(index).arivalTime, new Date(System.currentTimeMillis() - 21000), false));
- displayTimetable();
- }
-
- task = new GetTimetableStopTask();
- task.execute(index);
+ GetTimetableStopTask task = new GetTimetableStopTask();
+ task.execute(index);
+ synchronized (tasks) {
tasks.put(index, task);
}
+
}
@Override
@@ -262,16 +259,10 @@ public class BusActivity extends ToastHelperActivity implements Preferences {
private class GetTimetableStopTask extends AsyncTask<Integer, Integer, Stop> {
// private String errorMessage;
- private BusStop busStop;
-
private int busStopIndex;
- protected void onPreExecute() {
- // progBar.setVisibility(View.VISIBLE);
- }
-
protected Stop doInBackground(Integer... busStopIndexs) {
- busStop = busStops.get(busStopIndexs[0]);
+ BusStop busStop = busStops.get(busStopIndexs[0]);
busStopIndex = busStopIndexs[0];
Stop stop = null;
@@ -300,7 +291,7 @@ public class BusActivity extends ToastHelperActivity implements Preferences {
}
protected void onPostExecute(Stop stop) {
- // Log.i(TAG, "Got timetable");
+ if (isCancelled()) return;
synchronized (timetable) {
timetable.set(busStopIndex, stop);
diff --git a/src/net/cbaines/suma/BusSpecificStopView.java b/src/net/cbaines/suma/BusSpecificStopView.java
index ca8cdbb..df77d46 100644
--- a/src/net/cbaines/suma/BusSpecificStopView.java
+++ b/src/net/cbaines/suma/BusSpecificStopView.java
@@ -97,12 +97,7 @@ public class BusSpecificStopView extends LinearLayout implements OnClickListener
if (stop.arivalTime != null) { // Time available
time.setText(stop.getShortTimeToArival());
time.setVisibility(View.VISIBLE);
- } else { // No time available (yet) and not currently loading
- time.setVisibility(View.GONE);
- time.setText("");
- }
- if (stop.arivalTime != null) {
if (stop.live) {
onClickMessage = stop.bus.getName() + " at " + stop.busStop.description + " at "
+ DateFormat.getTimeInstance(DateFormat.SHORT).format(stop.arivalTime);
@@ -110,7 +105,10 @@ public class BusSpecificStopView extends LinearLayout implements OnClickListener
onClickMessage = stop.bus.getName() + " at " + stop.busStop.description + " at "
+ DateFormat.getTimeInstance(DateFormat.SHORT).format(stop.arivalTime) + " (timetabled)";
}
- } else {
+ } else { // No time available (yet) and not currently loading
+ time.setVisibility(View.GONE);
+ time.setText("");
+
onClickMessage = stop.busStop.description + " on route, but arival time is not avalible";
}
diff --git a/src/net/cbaines/suma/BusStopActivity.java b/src/net/cbaines/suma/BusStopActivity.java
index e28086a..4c4699f 100644
--- a/src/net/cbaines/suma/BusStopActivity.java
+++ b/src/net/cbaines/suma/BusStopActivity.java
@@ -59,10 +59,10 @@ import com.j256.ormlite.dao.Dao;
import com.j256.ormlite.stmt.PreparedQuery;
import com.j256.ormlite.stmt.QueryBuilder;
-public class BusStopActivity extends ToastHelperActivity implements OnCheckedChangeListener, Preferences,
- OnItemClickListener, OnLongClickListener {
+public class BusStopActivity extends ToastHelperActivity implements OnCheckedChangeListener, Preferences, OnItemClickListener,
+ OnLongClickListener {
- final static String TAG = "BusTimeActivity";
+ final static String TAG = "BusStopActivity";
private ListView busTimeList;
private TextView busName;
@@ -308,7 +308,7 @@ public class BusStopActivity extends ToastHelperActivity implements OnCheckedCha
return timetable;
}
- private class GetTimetableTask extends AsyncTask<String, Integer, Timetable> {
+ private class GetTimetableTask extends AsyncTask<String, Integer, Timetable> {
String errorMessage;
protected void onPreExecute() {
@@ -320,10 +320,10 @@ public class BusStopActivity extends ToastHelperActivity implements OnCheckedCha
try {
final SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(instance);
- newTimetable = DataManager.getTimetable(instance, busStop.id, sharedPrefs.getBoolean(
- MapActivity.UNI_LINK_BUS_TIMES, MapActivity.UNI_LINK_BUS_TIMES_ENABLED_BY_DEFAULT), sharedPrefs
- .getBoolean(MapActivity.NON_UNI_LINK_BUS_TIMES,
- MapActivity.NON_UNI_LINK_BUS_TIMES_ENABLED_BY_DEFAULT));
+ newTimetable = DataManager
+ .getTimetable(instance, busStop.id, sharedPrefs.getBoolean(MapActivity.UNI_LINK_BUS_TIMES,
+ MapActivity.UNI_LINK_BUS_TIMES_ENABLED_BY_DEFAULT), sharedPrefs.getBoolean(
+ MapActivity.NON_UNI_LINK_BUS_TIMES, MapActivity.NON_UNI_LINK_BUS_TIMES_ENABLED_BY_DEFAULT));
} catch (SQLException e) {
errorMessage = "Error message regarding SQL?";
e.printStackTrace();
diff --git a/src/net/cbaines/suma/BusStopSpecificStopView.java b/src/net/cbaines/suma/BusStopSpecificStopView.java
index 2124308..f266464 100644
--- a/src/net/cbaines/suma/BusStopSpecificStopView.java
+++ b/src/net/cbaines/suma/BusStopSpecificStopView.java
@@ -41,7 +41,7 @@ public class BusStopSpecificStopView extends LinearLayout implements OnClickList
// private final ImageView icon;
- private static final String TAG = "StopView";
+ private static final String TAG = "BusStopSpecificStopView";
private final TextView name;
private final TextView time;
@@ -112,11 +112,11 @@ public class BusStopSpecificStopView extends LinearLayout implements OnClickList
public void onClick(View v) {
Log.v(TAG, "onClick");
- if (stop.bus != null) {
- Log.v(TAG, "stop.bus != null");
+ if (stop.bus.id != null && stop.bus.route.uniLink) {
+ // Log.v(TAG, "stop.bus != null");
context.makeToast(onClickMessage, onClickHelpMessage, Toast.LENGTH_SHORT);
} else {
- Log.v(TAG, "stop.bus == null");
+ // Log.v(TAG, "stop.bus == null");
context.makeToast(onClickMessage, Toast.LENGTH_SHORT);
}
}
@@ -126,12 +126,11 @@ public class BusStopSpecificStopView extends LinearLayout implements OnClickList
try {
Dao<BusRoute, Integer> busRouteDao = helper.getBusRouteDao();
-
busRouteDao.refresh(stop.bus.route);
Log.i("StopView", "Bus route " + stop.bus.route + " Uni-Link " + stop.bus.route.uniLink + " Bus ID " + stop.bus.id);
- if (stop.bus != null && stop.bus.route.uniLink) {
+ if (stop.bus.id != null && stop.bus.route.uniLink) {
Uri uri = Uri.parse("http://id.southampton.ac.uk/bus/" + stop.bus.id);
Intent busIntent = new Intent(Intent.ACTION_VIEW, uri);
diff --git a/src/net/cbaines/suma/BusStopSpecificTimetableAdapter.java b/src/net/cbaines/suma/BusStopSpecificTimetableAdapter.java
index 511f427..cd2a5cf 100644
--- a/src/net/cbaines/suma/BusStopSpecificTimetableAdapter.java
+++ b/src/net/cbaines/suma/BusStopSpecificTimetableAdapter.java
@@ -19,7 +19,6 @@
package net.cbaines.suma;
-import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.Animation;
@@ -33,7 +32,7 @@ public class BusStopSpecificTimetableAdapter extends BaseAdapter {
private final Animation a;
private boolean[] changed;
- private static final String TAG = "TimetableAdapter";
+ // private static final String TAG = "BusStopSpecificTimetableAdapter";
public BusStopSpecificTimetableAdapter(BusStopActivity context, Timetable timetable) {
this.context = context;
@@ -42,7 +41,7 @@ public class BusStopSpecificTimetableAdapter extends BaseAdapter {
}
public View getView(int position, View convertView, ViewGroup parent) {
- Log.i(TAG, "Returning stop " + position + " " + timetable.get(position));
+ // Log.i(TAG, "Returning stop " + position + " " + timetable.get(position));
BusStopSpecificStopView stopView;
if (convertView == null) {
@@ -55,7 +54,7 @@ public class BusStopSpecificTimetableAdapter extends BaseAdapter {
if (changed == null || changed[position]) {
a.reset();
stopView.startAnimation(a);
- Log.i(TAG, "Animating it");
+ // Log.i(TAG, "Animating it");
}
return stopView;
@@ -74,15 +73,15 @@ public class BusStopSpecificTimetableAdapter extends BaseAdapter {
}
public void updateTimetable(Timetable newTimetable) {
- Log.v(TAG, "Old timetable " + timetable);
- Log.v(TAG, "Adaptor loading new timetable");
+ // Log.v(TAG, "Old timetable " + timetable);
+ // Log.v(TAG, "Adaptor loading new timetable");
changed = new boolean[newTimetable.size()];
for (int i = 0; i < newTimetable.size(); i++) {
if (!timetable.contains(newTimetable.get(i), true)) {
changed[i] = true;
- Log.i(TAG, "Old timetable does not contain: " + newTimetable.get(i));
+ // Log.i(TAG, "Old timetable does not contain: " + newTimetable.get(i));
} else {
- Log.i(TAG, "Old timetable contains: " + newTimetable.get(i));
+ // Log.i(TAG, "Old timetable contains: " + newTimetable.get(i));
changed[i] = false;
}
}
diff --git a/src/net/cbaines/suma/DataManager.java b/src/net/cbaines/suma/DataManager.java
index 97ebb54..1658cb5 100644
--- a/src/net/cbaines/suma/DataManager.java
+++ b/src/net/cbaines/suma/DataManager.java
@@ -683,6 +683,7 @@ public class DataManager {
for (int stopNum = 0; stopNum < stopsArray.length(); stopNum++) {
JSONObject stopObj = stopsArray.getJSONObject(stopNum);
+ Log.v(TAG, stopObj.toString());
if (!keepNonUniLink && !stopObj.getString("name").startsWith("U")) {
// Log.v(TAG, "Skipping non uni-link stop " +
@@ -863,12 +864,12 @@ public class DataManager {
if (route.id == 326) { // U1
Log.i(TAG, "Direction for " + busStopRouteIndex + " is");
- if (busStopRouteIndex >= 0 && busStopRouteIndex <= 36) {
+ if (busStopRouteIndex >= 0 && busStopRouteIndex <= 35) {
direction = route.forwardDirection;
- } else if (busStopRouteIndex >= 50 && busStopRouteIndex <= 87) {
+ } else if (busStopRouteIndex >= 52 && busStopRouteIndex <= 87) {
direction = route.reverseDirection;
} else {
- Log.e(TAG, "For U1 route, error with busStopRouteIndex " + busStopRouteIndex);
+ Log.e(TAG, "For U1 route, error with busStopRouteIndex " + busStopRouteIndex + " " + busStop.description);
}
Log.i(TAG, direction);
} else if (route.id == 468) { // U1N
@@ -957,12 +958,13 @@ public class DataManager {
}
public static String getFileFromServer(String request) throws ClientProtocolException, IOException {
+ long requestStartTime = System.currentTimeMillis();
StringBuilder builder = new StringBuilder();
HttpClient client = new DefaultHttpClient();
HttpGet httpGet = new HttpGet(request);
- // Log.v("Util.getFileFromServer", "Request used: " + request);
HttpResponse response = client.execute(httpGet);
+ Log.v("Util.getFileFromServer", request + " request took " + (System.currentTimeMillis() - requestStartTime));
StatusLine statusLine = response.getStatusLine();
int statusCode = statusLine.getStatusCode();
if (statusCode == 200) {