aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--gen/net/cbaines/suma/R.java84
-rw-r--r--res/layout/bus_activity.xml15
-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
7 files changed, 100 insertions, 134 deletions
diff --git a/gen/net/cbaines/suma/R.java b/gen/net/cbaines/suma/R.java
index 963c682..d8cc3af 100644
--- a/gen/net/cbaines/suma/R.java
+++ b/gen/net/cbaines/suma/R.java
@@ -57,8 +57,6 @@ public final class R {
public static final int busActivityBusID=0x7f0a0005;
public static final int busActivityContentLayout=0x7f0a000b;
public static final int busActivityHeaderLayout=0x7f0a0004;
- public static final int busActivityLoadBar=0x7f0a000f;
- public static final int busActivityLoadBarLayout=0x7f0a000e;
public static final int busActivityMessage=0x7f0a000c;
public static final int busActivityTimes=0x7f0a000d;
public static final int busActivityU1=0x7f0a0006;
@@ -66,51 +64,51 @@ public final class R {
public static final int busActivityU2=0x7f0a0008;
public static final int busActivityU6=0x7f0a0009;
public static final int busActivityU9=0x7f0a000a;
- public static final int busStopID=0x7f0a001a;
- public static final int busStopListItems=0x7f0a0011;
- public static final int busStopLoadBar=0x7f0a001f;
- public static final int busStopMessage=0x7f0a001c;
- public static final int busStopName=0x7f0a0012;
- public static final int busStopTimes=0x7f0a001d;
- public static final int busTimeContentLayout=0x7f0a001b;
- public static final int centerLoadBar=0x7f0a001e;
- public static final int check1=0x7f0a002e;
- public static final int childname=0x7f0a002d;
- public static final int donateBitcoinAddress=0x7f0a0025;
+ public static final int busStopID=0x7f0a0018;
+ public static final int busStopListItems=0x7f0a000f;
+ public static final int busStopLoadBar=0x7f0a001d;
+ public static final int busStopMessage=0x7f0a001a;
+ public static final int busStopName=0x7f0a0010;
+ public static final int busStopTimes=0x7f0a001b;
+ public static final int busTimeContentLayout=0x7f0a0019;
+ public static final int centerLoadBar=0x7f0a001c;
+ public static final int check1=0x7f0a002c;
+ public static final int childname=0x7f0a002b;
+ public static final int donateBitcoinAddress=0x7f0a0023;
public static final int donateButton=0x7f0a0003;
- public static final int donateDialogErrorMessage=0x7f0a0024;
- public static final int donateDialogMessage=0x7f0a0021;
- public static final int donateDialogMessageLayout=0x7f0a0023;
- public static final int donateDialogProgress=0x7f0a0022;
- public static final int favouriteCheckBox=0x7f0a0019;
- public static final int favouriteDialogMessage=0x7f0a002b;
- public static final int favouriteListItems=0x7f0a002c;
- public static final int findContentLayout=0x7f0a0027;
- public static final int findListItems=0x7f0a0029;
- public static final int findLoadBar=0x7f0a0028;
+ public static final int donateDialogErrorMessage=0x7f0a0022;
+ public static final int donateDialogMessage=0x7f0a001f;
+ public static final int donateDialogMessageLayout=0x7f0a0021;
+ public static final int donateDialogProgress=0x7f0a0020;
+ public static final int favouriteCheckBox=0x7f0a0017;
+ public static final int favouriteDialogMessage=0x7f0a0029;
+ public static final int favouriteListItems=0x7f0a002a;
+ public static final int findContentLayout=0x7f0a0025;
+ public static final int findListItems=0x7f0a0027;
+ public static final int findLoadBar=0x7f0a0026;
public static final int helpExpandableListView=0x7f0a0002;
- public static final int layout_root=0x7f0a0010;
- public static final int linearLayout1=0x7f0a0013;
- public static final int linearLayout2=0x7f0a0020;
- public static final int mapview=0x7f0a002a;
- public static final int menu_about=0x7f0a0034;
- public static final int menu_favourites=0x7f0a0035;
- public static final int menu_find=0x7f0a0030;
- public static final int menu_find_my_location=0x7f0a0032;
- public static final int menu_next_stop=0x7f0a0038;
- public static final int menu_preferences=0x7f0a0031;
- public static final int menu_previous_stop=0x7f0a0036;
- public static final int menu_refresh_stop=0x7f0a0037;
- public static final int menu_view=0x7f0a0033;
- public static final int radio_u1=0x7f0a0014;
- public static final int radio_u1n=0x7f0a0015;
- public static final int radio_u2=0x7f0a0016;
- public static final int radio_u6=0x7f0a0017;
- public static final int radio_u9=0x7f0a0018;
- public static final int searchBar=0x7f0a0026;
+ public static final int layout_root=0x7f0a000e;
+ public static final int linearLayout1=0x7f0a0011;
+ public static final int linearLayout2=0x7f0a001e;
+ public static final int mapview=0x7f0a0028;
+ public static final int menu_about=0x7f0a0032;
+ public static final int menu_favourites=0x7f0a0033;
+ public static final int menu_find=0x7f0a002e;
+ public static final int menu_find_my_location=0x7f0a0030;
+ public static final int menu_next_stop=0x7f0a0036;
+ public static final int menu_preferences=0x7f0a002f;
+ public static final int menu_previous_stop=0x7f0a0034;
+ public static final int menu_refresh_stop=0x7f0a0035;
+ public static final int menu_view=0x7f0a0031;
+ public static final int radio_u1=0x7f0a0012;
+ public static final int radio_u1n=0x7f0a0013;
+ public static final int radio_u2=0x7f0a0014;
+ public static final int radio_u6=0x7f0a0015;
+ public static final int radio_u9=0x7f0a0016;
+ public static final int searchBar=0x7f0a0024;
public static final int textView1=0x7f0a0000;
public static final int textView2=0x7f0a0001;
- public static final int view_list=0x7f0a002f;
+ public static final int view_list=0x7f0a002d;
}
public static final class layout {
public static final int about_dialog=0x7f030000;
diff --git a/res/layout/bus_activity.xml b/res/layout/bus_activity.xml
index b78f78a..3037916 100644
--- a/res/layout/bus_activity.xml
+++ b/res/layout/bus_activity.xml
@@ -94,21 +94,6 @@
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
</ListView>
-
- <LinearLayout
- xmlns:android="http://schemas.android.com/apk/res/android"
- android:id="@+id/busActivityLoadBarLayout"
- android:layout_width="fill_parent"
- android:layout_height="fill_parent"
- android:gravity="center"
- android:orientation="vertical" >
-
- <ProgressBar
- android:id="@+id/busActivityLoadBar"
- style="?android:attr/progressBarStyleLarge"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content" />
- </LinearLayout>
</LinearLayout>
</LinearLayout> \ No newline at end of file
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;
}
}