aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorChristopher Baines <cbaines8@gmail.com>2012-02-16 13:43:51 +0000
committerChristopher Baines <cbaines8@gmail.com>2012-02-16 13:43:51 +0000
commit86629c735d4f7c48e1562825ca63ba3335363cbb (patch)
tree87ff143b433350c531800428c6182e6568e44e9e /src
parente20303f3de0782c31a0a794d1be4a06e3b4a0c76 (diff)
downloadsouthamptonuniversitymap-86629c735d4f7c48e1562825ca63ba3335363cbb.tar
southamptonuniversitymap-86629c735d4f7c48e1562825ca63ba3335363cbb.tar.gz
ARRRRRRRGHH, bus routes dont work, the U6 route loops over the same ground twice by wessex lane, traveling in the same direction, breaking the BusRoute.moveInRoute code :(
Diffstat (limited to 'src')
-rw-r--r--src/net/cbaines/suma/BusActivity.java64
-rw-r--r--src/net/cbaines/suma/BusRoute.java36
-rw-r--r--src/net/cbaines/suma/BusSpecificStopView.java13
-rw-r--r--src/net/cbaines/suma/BusSpecificTimetableAdapter.java10
-rw-r--r--src/net/cbaines/suma/POI.java12
5 files changed, 59 insertions, 76 deletions
diff --git a/src/net/cbaines/suma/BusActivity.java b/src/net/cbaines/suma/BusActivity.java
index eb512f8..a71cbd3 100644
--- a/src/net/cbaines/suma/BusActivity.java
+++ b/src/net/cbaines/suma/BusActivity.java
@@ -4,11 +4,8 @@ import java.io.IOException;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.HashMap;
-import java.util.HashSet;
import java.util.List;
-import net.cbaines.suma.BusSpecificStopView.GetTimetableStopTask;
-
import org.apache.http.client.ClientProtocolException;
import org.json.JSONException;
@@ -39,11 +36,16 @@ public class BusActivity extends OrmLiteBaseActivity<DatabaseHelper> implements
private TextView busIDTextView;
- private ProgressBar progBar;
private TextView busContentMessage;
private LinearLayout busActivityContentLayout;
+ /**
+ * The bus this activity is focused on
+ */
private Bus bus;
+ /**
+ * The bus stop this activity is working from
+ */
private BusStop busStop;
private Runnable refreshData;
@@ -63,8 +65,6 @@ public class BusActivity extends OrmLiteBaseActivity<DatabaseHelper> implements
private Handler handler;
- int num = 20;
-
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.bus_activity);
@@ -105,7 +105,6 @@ public class BusActivity extends OrmLiteBaseActivity<DatabaseHelper> implements
busIDTextView = (TextView) findViewById(R.id.busActivityBusID);
- progBar = (ProgressBar) findViewById(R.id.busActivityLoadBar);
busContentMessage = (TextView) findViewById(R.id.busActivityMessage);
busActivityContentLayout = (LinearLayout) findViewById(R.id.busActivityContentLayout);
timetableView = (ListView) findViewById(R.id.busActivityTimes);
@@ -150,17 +149,21 @@ public class BusActivity extends OrmLiteBaseActivity<DatabaseHelper> implements
e.printStackTrace();
}
- busStops = new ArrayList<BusStop>(num);
+ busStops = new ArrayList<BusStop>();
busStops.add(busStop);
- for (int i = 0; i < num; i++) {
+ busStopsActive = new ArrayList<Boolean>();
+ busStopsActive.add(false);
+
+ for (int i = 0;; i++) {
BusStop nextStop = bus.route.moveInRoute(instance, busStops.get(i), bus.direction, 1);
- if (nextStop != null) {
- busStops.add(nextStop);
- } else {
- Log.e(TAG, "nextStop is null");
+ if (nextStop.equals(busStop) || (bus.destination != null && bus.destination.equals(nextStop))) {
+ break;
}
+
+ busStops.add(nextStop);
+ busStopsActive.add(false);
}
refreshData = new Runnable() {
@@ -207,17 +210,18 @@ public class BusActivity extends OrmLiteBaseActivity<DatabaseHelper> implements
if (timetable == null) {
Log.i(TAG, "No Previous timetable");
timetable = new Timetable();
- for (int i = 0; i < num; i++) {
+ for (int i = 0; i < busStops.size(); i++) {
timetable.add(new Stop(bus, busStops.get(i), null, null, false));
}
} else {
Log.i(TAG, "Displaying previous timetable");
- displayTimetable(timetable);
+
}
+ displayTimetable(timetable);
+ handler.post(refreshData);
} else {
Log.i(TAG, "Live Times Disabled");
- progBar.setVisibility(View.GONE);
busContentMessage.setText("Live bus times disabled");
busContentMessage.setVisibility(View.VISIBLE);
}
@@ -227,13 +231,12 @@ public class BusActivity extends OrmLiteBaseActivity<DatabaseHelper> implements
public void onPause() {
if (handler != null) { // BusTimes are enabled
handler.removeCallbacks(refreshData);
- if (timetableStopTasks != null) { // Could happen if the handler has not created the timetableTask yet
- for (GetTimetableStopTask task : timetableStopTasks.values()) {
- if (task != null) {
- task.cancel(true);
- }
+ for (GetTimetableStopTask task : tasks.values()) {
+ if (task != null) {
+ task.cancel(true);
}
}
+
Log.i(TAG, "Stoping refreshing timetable data");
}
@@ -257,9 +260,9 @@ public class BusActivity extends OrmLiteBaseActivity<DatabaseHelper> implements
try {
Log.i(TAG, "Fetching stop for busStop " + position);
- stop = DataManager.getStop(context, stop.bus, busStop);
+ stop = DataManager.getStop(instance, bus, busStop);
if (stop == null) {
- stop = new Stop(stop.bus, busStop, null, null, false);
+ stop = new Stop(bus, busStop, null, null, false);
}
Log.i(TAG, "Finished fetching stop for busStop " + position);
} catch (SQLException e) {
@@ -281,18 +284,17 @@ public class BusActivity extends OrmLiteBaseActivity<DatabaseHelper> implements
protected void onPostExecute(Stop stop) {
// Log.i(TAG, "Got timetable");
if (stop == null) {
+ Log.i(TAG, "Its null");
- // progBar.setVisibility(View.GONE);
- // busContentMessage.setText(errorMessage);
- // busContentMessage.setVisibility(View.VISIBLE);
+ busContentMessage.setText(errorMessage);
+ busContentMessage.setVisibility(View.VISIBLE);
} else {
- // progBar.setVisibility(View.GONE);
-
+ synchronized (timetable) {
+ timetable.set(position, stop);
+ displayTimetable(timetable);
+ }
}
}
- }
-
- void setStopUpdated(BusStop stop, boolean updated) {
}
diff --git a/src/net/cbaines/suma/BusRoute.java b/src/net/cbaines/suma/BusRoute.java
index 2dacfd2..0101ae4 100644
--- a/src/net/cbaines/suma/BusRoute.java
+++ b/src/net/cbaines/suma/BusRoute.java
@@ -41,6 +41,8 @@ import com.j256.ormlite.table.DatabaseTable;
@DatabaseTable(tableName = "busroutes")
public class BusRoute {
+ private static final String TAG = "BusRoute";
+
final static String ID_FIELD_NAME = "id";
final static String CODE_FIELD_NAME = "code";
final static String LABEL_FIELD_NAME = "label";
@@ -147,7 +149,6 @@ public class BusRoute {
PreparedQuery<RouteStops> routeStopsPreparedQuery = routeStopsQueryBuilder.prepare();
List<RouteStops> routeStopsFound = routeStopsDao.query(routeStopsPreparedQuery);
- Log.v("BusRoute", "Found " + routeStopsFound.size() + " stops");
int stopIndex = 0;
@@ -158,28 +159,33 @@ public class BusRoute {
}
if (moveAmount > 0) {
- Log.v("BusStop", "stopIndex " + stopIndex);
- int stopWanted = (stopIndex + moveAmount) % (routeStopsFound.size());
- Log.v("BusStop", "stopWanted " + stopWanted);
- busStopDao.refresh(routeStopsFound.get(stopWanted).stop);
+ Log.v(TAG,
+ "Moving forward in direction " + direction + " " + moveAmount + " stops from " + stop + " (" + stopIndex + "/" + routeStopsFound.size()
+ + ")");
+ int stopWanted = stopIndex + moveAmount;
+ if ((stopWanted + 1) > routeStopsFound.size()) {
+ Log.v(TAG, "Off the end of the route");
+ stopWanted = stopWanted % (routeStopsFound.size() - 1);
+ }
+ Log.v(TAG, "Stop wanted " + stopWanted);
+ BusStop busStopWanted = routeStopsFound.get(stopWanted).stop;
- Log.v("BusRoute",
- "Moving forward in direction " + direction + " " + moveAmount + " stops from " + stop + " to " + routeStopsFound.get(stopWanted).stop
- + " in route " + this);
+ busStopDao.refresh(busStopWanted);
- return routeStopsFound.get(stopWanted).stop;
+ Log.v(TAG, "Moving to " + busStopWanted + " (" + stopWanted + ") in route " + this);
+
+ return busStopWanted;
} else {
- Log.v("BusStop", "stopIndex " + stopIndex);
+ Log.v(TAG, "stopIndex " + stopIndex);
int stopWanted = stopIndex + moveAmount;
if (stopWanted < 0) {
stopWanted = routeStopsFound.size() - (Math.abs(stopWanted) % routeStopsFound.size());
}
- Log.v("BusStop", "stopWanted " + stopWanted);
+ Log.v(TAG, "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);
+ Log.v(TAG, "Moving backwards in direction " + direction + " " + moveAmount + " stops from " + stop + " to "
+ + routeStopsFound.get(stopWanted).stop + " in route " + this);
return routeStopsFound.get(stopWanted).stop;
}
@@ -187,7 +193,7 @@ public class BusRoute {
} catch (SQLException e) {
e.printStackTrace();
}
- Log.e("BusRoute", "Error moving in route");
+ Log.e(TAG, "Error moving in route");
return null;
}
diff --git a/src/net/cbaines/suma/BusSpecificStopView.java b/src/net/cbaines/suma/BusSpecificStopView.java
index 69b2aee..88a403c 100644
--- a/src/net/cbaines/suma/BusSpecificStopView.java
+++ b/src/net/cbaines/suma/BusSpecificStopView.java
@@ -19,19 +19,13 @@
package net.cbaines.suma;
-import java.io.IOException;
import java.sql.SQLException;
import java.text.DateFormat;
-import org.apache.http.client.ClientProtocolException;
-import org.json.JSONException;
-
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
-import android.os.AsyncTask;
import android.os.Handler;
-import android.util.Log;
import android.view.Gravity;
import android.view.View;
import android.view.View.OnClickListener;
@@ -45,7 +39,7 @@ import com.j256.ormlite.dao.Dao;
public class BusSpecificStopView extends LinearLayout implements OnClickListener, OnLongClickListener {
- private static final String TAG = "BusSpecificStopView";
+ // private static final String TAG = "BusSpecificStopView";
private Handler handler;
@@ -58,15 +52,12 @@ public class BusSpecificStopView extends LinearLayout implements OnClickListener
private String onClickMessage = "";
private final Context context;
- private GetTimetableStopTask task;
-
private Stop stop;
- public BusSpecificStopView(Context context, Stop newStop, Handler newHandler) {
+ public BusSpecificStopView(Context context, Stop newStop) {
super(context);
this.context = context;
- this.handler = newHandler;
this.setOrientation(HORIZONTAL);
diff --git a/src/net/cbaines/suma/BusSpecificTimetableAdapter.java b/src/net/cbaines/suma/BusSpecificTimetableAdapter.java
index c5b81d3..4cc894f 100644
--- a/src/net/cbaines/suma/BusSpecificTimetableAdapter.java
+++ b/src/net/cbaines/suma/BusSpecificTimetableAdapter.java
@@ -19,8 +19,6 @@
package net.cbaines.suma;
-import android.content.Context;
-import android.os.Handler;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.Animation;
@@ -33,14 +31,12 @@ public class BusSpecificTimetableAdapter extends BaseAdapter {
private Timetable timetable;
private final Animation a;
private boolean[] changed;
- private Handler handler;
- private static final String TAG = "BusSpecificTimetableAdapter";
+ // private static final String TAG = "BusSpecificTimetableAdapter";
- public BusSpecificTimetableAdapter(BusActivity context, Timetable timetable, Handler handler) {
+ public BusSpecificTimetableAdapter(BusActivity context, Timetable timetable) {
this.context = context;
this.timetable = timetable;
- this.handler = handler;
this.a = AnimationUtils.loadAnimation(context, R.anim.updated_stop_view);
}
@@ -49,7 +45,7 @@ public class BusSpecificTimetableAdapter extends BaseAdapter {
BusSpecificStopView stopView;
if (convertView == null) {
- stopView = new BusSpecificStopView(context, timetable.get(position), handler);
+ stopView = new BusSpecificStopView(context, timetable.get(position));
} else {
stopView = (BusSpecificStopView) convertView;
stopView.setStop(timetable.get(position));
diff --git a/src/net/cbaines/suma/POI.java b/src/net/cbaines/suma/POI.java
index dba7924..244198d 100644
--- a/src/net/cbaines/suma/POI.java
+++ b/src/net/cbaines/suma/POI.java
@@ -60,8 +60,6 @@ public abstract class POI {
final int prime = 31;
int result = 1;
result = prime * result + ((id == null) ? 0 : id.hashCode());
- result = prime * result + ((point == null) ? 0 : point.hashCode());
- result = prime * result + ((type == null) ? 0 : type.hashCode());
return result;
}
@@ -79,16 +77,6 @@ public abstract class POI {
return false;
} else if (!id.equals(other.id))
return false;
- if (point == null) {
- if (other.point != null)
- return false;
- } else if (!point.equals(other.point))
- return false;
- if (type == null) {
- if (other.type != null)
- return false;
- } else if (!type.equals(other.type))
- return false;
return true;
}
}