aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristopher Baines <cbaines8@gmail.com>2012-02-14 11:42:58 +0000
committerChristopher Baines <cbaines8@gmail.com>2012-02-14 11:42:58 +0000
commit6805fb9c3ceb2d5973f7155022eeadf65fcd58cd (patch)
tree2aafd1f3e01dcc7ff759b3233a6d730e3deb561d
parent7e042d5406098591f3b0f8b94e47ffe3df40b34b (diff)
downloadsouthamptonuniversitymap-6805fb9c3ceb2d5973f7155022eeadf65fcd58cd.tar
southamptonuniversitymap-6805fb9c3ceb2d5973f7155022eeadf65fcd58cd.tar.gz
Stuff moving towards getting BusActivity working.
-rw-r--r--AndroidManifest.xml4
-rw-r--r--gen/net/cbaines/suma/R.java113
-rw-r--r--res/layout/bus_activity.xml114
-rw-r--r--src/net/cbaines/suma/Bus.java7
-rw-r--r--src/net/cbaines/suma/BusActivity.java247
-rw-r--r--src/net/cbaines/suma/BusSpecificStopView.java137
-rw-r--r--src/net/cbaines/suma/BusStopActivity.java7
-rw-r--r--src/net/cbaines/suma/DataManager.java72
-rw-r--r--src/net/cbaines/suma/DatabaseHelper.java2
-rw-r--r--src/net/cbaines/suma/Preferences.java3
-rw-r--r--src/net/cbaines/suma/StopView.java36
11 files changed, 675 insertions, 67 deletions
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index c606279..21e3c2a 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -27,7 +27,9 @@
</activity>
<activity android:name="FindActivity" >
</activity>
- <activity android:name=".BusStopActivity" >
+ <activity android:name="BusStopActivity" >
+ </activity>
+ <activity android:name="BusActivity" >
</activity>
<activity android:name="AboutActivity" >
</activity>
diff --git a/gen/net/cbaines/suma/R.java b/gen/net/cbaines/suma/R.java
index 27ce28c..5d5d3ee 100644
--- a/gen/net/cbaines/suma/R.java
+++ b/gen/net/cbaines/suma/R.java
@@ -54,63 +54,76 @@ public final class R {
public static final int u9_radio_button=0x7f02001d;
}
public static final class id {
- public static final int busStopID=0x7f0a000e;
- public static final int busStopListItems=0x7f0a0005;
- public static final int busStopLoadBar=0x7f0a0013;
- public static final int busStopMessage=0x7f0a0010;
- public static final int busStopName=0x7f0a0006;
- public static final int busStopTimes=0x7f0a0011;
- public static final int busTimeContentLayout=0x7f0a000f;
- public static final int centerLoadBar=0x7f0a0012;
- public static final int check1=0x7f0a0022;
- public static final int childname=0x7f0a0021;
- public static final int donateBitcoinAddress=0x7f0a0019;
+ public static final int busActivityBusID=0x7f0a0005;
+ public static final int busActivityCenterLoadBar=0x7f0a000e;
+ public static final int busActivityContentLayout=0x7f0a000b;
+ public static final int busActivityHeaderLayout=0x7f0a0004;
+ public static final int busActivityLoadBar=0x7f0a000f;
+ public static final int busActivityMessage=0x7f0a000c;
+ public static final int busActivityTimes=0x7f0a000d;
+ public static final int busActivityU1=0x7f0a0006;
+ public static final int busActivityU1N=0x7f0a0007;
+ 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 donateButton=0x7f0a0003;
- public static final int donateDialogErrorMessage=0x7f0a0018;
- public static final int donateDialogMessage=0x7f0a0015;
- public static final int donateDialogMessageLayout=0x7f0a0017;
- public static final int donateDialogProgress=0x7f0a0016;
- public static final int favouriteCheckBox=0x7f0a000d;
- public static final int favouriteDialogMessage=0x7f0a001f;
- public static final int favouriteListItems=0x7f0a0020;
- public static final int findContentLayout=0x7f0a001b;
- public static final int findListItems=0x7f0a001d;
- public static final int findLoadBar=0x7f0a001c;
+ 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 helpExpandableListView=0x7f0a0002;
- public static final int layout_root=0x7f0a0004;
- public static final int linearLayout1=0x7f0a0007;
- public static final int linearLayout2=0x7f0a0014;
- public static final int mapview=0x7f0a001e;
- public static final int menu_about=0x7f0a0028;
- public static final int menu_favourites=0x7f0a0029;
- public static final int menu_find=0x7f0a0024;
- public static final int menu_find_my_location=0x7f0a0026;
- public static final int menu_next_stop=0x7f0a002c;
- public static final int menu_preferences=0x7f0a0025;
- public static final int menu_previous_stop=0x7f0a002a;
- public static final int menu_refresh_stop=0x7f0a002b;
- public static final int menu_view=0x7f0a0027;
- public static final int radio_u1=0x7f0a0008;
- public static final int radio_u1n=0x7f0a0009;
- public static final int radio_u2=0x7f0a000a;
- public static final int radio_u6=0x7f0a000b;
- public static final int radio_u9=0x7f0a000c;
- public static final int searchBar=0x7f0a001a;
+ 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 textView1=0x7f0a0000;
public static final int textView2=0x7f0a0001;
- public static final int view_list=0x7f0a0023;
+ public static final int view_list=0x7f0a002f;
}
public static final class layout {
public static final int about_dialog=0x7f030000;
- public static final int bus_stop_dialog=0x7f030001;
- public static final int bustimes=0x7f030002;
- public static final int donate_dialog=0x7f030003;
- public static final int find=0x7f030004;
- public static final int main=0x7f030005;
- public static final int poi_dialog=0x7f030006;
- public static final int view_child_row=0x7f030007;
- public static final int view_dialog=0x7f030008;
- public static final int view_group_row=0x7f030009;
+ public static final int bus_activity=0x7f030001;
+ public static final int bus_stop_dialog=0x7f030002;
+ public static final int bustimes=0x7f030003;
+ public static final int donate_dialog=0x7f030004;
+ public static final int find=0x7f030005;
+ public static final int main=0x7f030006;
+ public static final int poi_dialog=0x7f030007;
+ public static final int view_child_row=0x7f030008;
+ public static final int view_dialog=0x7f030009;
+ public static final int view_group_row=0x7f03000a;
}
public static final class menu {
public static final int map_menu=0x7f090000;
diff --git a/res/layout/bus_activity.xml b/res/layout/bus_activity.xml
new file mode 100644
index 0000000..1468be5
--- /dev/null
+++ b/res/layout/bus_activity.xml
@@ -0,0 +1,114 @@
+<?xml version="1.0" encoding="utf-8"?>
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="fill_parent"
+ android:layout_height="fill_parent"
+ android:gravity="center|top"
+ android:orientation="vertical"
+ android:theme="@android:style/Theme.NoTitleBar" >
+
+ <LinearLayout
+ android:id="@+id/busActivityHeaderLayout"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ android:orientation="horizontal" >
+
+ <TextView
+ android:id="@+id/busActivityBusID"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:textAppearance="?android:attr/textAppearanceLarge" />
+
+ <TextView
+ android:id="@+id/busActivityU1"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:background="@drawable/u1_back_selected"
+ android:paddingLeft="5dp"
+ android:paddingRight="5dp"
+ android:text="@string/U1"
+ android:textAppearance="?android:attr/textAppearanceSmall"
+ android:textColor="#FFFFFF" />
+
+ <TextView
+ android:id="@+id/busActivityU1N"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:background="@drawable/u1n_back_selected"
+ android:paddingLeft="5dp"
+ android:paddingRight="5dp"
+ android:text="@string/U1N"
+ android:textAppearance="?android:attr/textAppearanceSmall"
+ android:textColor="#FFFFFF" />
+
+ <TextView
+ android:id="@+id/busActivityU2"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:background="@drawable/u2_back_selected"
+ android:paddingLeft="5dp"
+ android:paddingRight="5dp"
+ android:text="@string/U2"
+ android:textAppearance="?android:attr/textAppearanceSmall"
+ android:textColor="#FFFFFF" />
+
+ <TextView
+ android:id="@+id/busActivityU6"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:background="@drawable/u6_back_selected"
+ android:paddingLeft="5dp"
+ android:paddingRight="5dp"
+ android:text="@string/U6"
+ android:textAppearance="?android:attr/textAppearanceSmall"
+ android:textColor="#FFFFFF" />
+
+ <TextView
+ android:id="@+id/busActivityU9"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:background="@drawable/u9_back_selected"
+ android:paddingLeft="5dp"
+ android:paddingRight="5dp"
+ android:text="@string/U9"
+ android:textAppearance="?android:attr/textAppearanceSmall"
+ android:textColor="#FFFFFF" />
+ </LinearLayout>
+
+ <LinearLayout
+ xmlns:android="http://schemas.android.com/apk/res/android"
+ android:id="@+id/busActivityContentLayout"
+ android:layout_width="fill_parent"
+ android:layout_height="fill_parent"
+ android:gravity="center"
+ android:orientation="vertical" >
+
+ <TextView
+ android:id="@+id/busActivityMessage"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:text=""
+ android:textAppearance="?android:attr/textAppearanceLarge" />
+
+ <ListView
+ android:id="@+id/busActivityTimes"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content" >
+ </ListView>
+
+ <LinearLayout
+ xmlns:android="http://schemas.android.com/apk/res/android"
+ android:id="@+id/busActivityCenterLoadBar"
+ 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/Bus.java b/src/net/cbaines/suma/Bus.java
index bddba70..ac2d223 100644
--- a/src/net/cbaines/suma/Bus.java
+++ b/src/net/cbaines/suma/Bus.java
@@ -19,6 +19,9 @@
package net.cbaines.suma;
+import android.os.Parcel;
+import android.os.Parcelable;
+
import com.j256.ormlite.field.DatabaseField;
import com.j256.ormlite.table.DatabaseTable;
@@ -53,13 +56,13 @@ public class Bus {
/**
* The direction which the bus is travelling.
*/
- @DatabaseField(canBeNull = false)
+ @DatabaseField(canBeNull = true)
String direction;
/**
* The destination the bus is travelling towards.
*/
- @DatabaseField(canBeNull = false, foreign = true)
+ @DatabaseField(canBeNull = true, foreign = true)
BusStop destination;
Bus() {
diff --git a/src/net/cbaines/suma/BusActivity.java b/src/net/cbaines/suma/BusActivity.java
new file mode 100644
index 0000000..44faaa7
--- /dev/null
+++ b/src/net/cbaines/suma/BusActivity.java
@@ -0,0 +1,247 @@
+package net.cbaines.suma;
+
+import java.io.IOException;
+import java.sql.SQLException;
+import java.util.Iterator;
+import java.util.List;
+
+import org.apache.http.client.ClientProtocolException;
+import org.json.JSONException;
+
+import android.content.Context;
+import android.content.SharedPreferences;
+import android.os.AsyncTask;
+import android.os.Bundle;
+import android.preference.PreferenceManager;
+import android.util.Log;
+import android.view.Gravity;
+import android.view.View;
+import android.widget.CheckBox;
+import android.widget.LinearLayout;
+import android.widget.ProgressBar;
+import android.widget.TextView;
+
+import com.j256.ormlite.android.apptools.OrmLiteBaseActivity;
+
+public class BusActivity extends OrmLiteBaseActivity<DatabaseHelper> {
+ final static String TAG = "BusActivity";
+
+ private CheckBox U1RouteRadioButton;
+ private CheckBox U1NRouteRadioButton;
+ private CheckBox U2RouteRadioButton;
+ private CheckBox U6RouteRadioButton;
+ private CheckBox U9RouteRadioButton;
+
+ private TextView busIDTextView;
+
+ private ProgressBar progBar;
+ private TextView busContentMessage;
+ private LinearLayout busActivityContentLayout;
+
+ private Bus bus;
+ private BusStop busStop;
+
+ protected Timetable timetable;
+ private Timetable visibleTimetable;
+
+ private Context instance;
+
+ public void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.bus_activity);
+ instance = this;
+
+ String busID = getIntent().getExtras().getString("busID");
+ String busStopID = getIntent().getExtras().getString("busStopID");
+ final DatabaseHelper helper = getHelper();
+
+ try {
+ List<Bus> buses = helper.getBusDao().queryForEq(Bus.ID_FIELD_NAME, busID);
+ bus = null;
+ if (buses.size() == 0) {
+ Log.e(TAG, "Bus " + busID + " not found!");
+ } else if (buses.size() == 1) {
+ bus = buses.get(0);
+ } else if (buses.size() > 1) {
+ Log.e(TAG, "Found more than one bus? " + busID);
+ }
+
+ List<BusStop> busStops = helper.getBusStopDao().queryForEq(BusStop.ID_FIELD_NAME, busStopID);
+ busStop = null;
+ if (busStops.size() == 0) {
+ Log.e(TAG, "BusStop " + busStopID + " not found!");
+ } else if (busStops.size() == 1) {
+ busStop = busStops.get(0);
+ } else if (busStops.size() > 1) {
+ Log.e(TAG, "Found more than one busStop? " + busStopID);
+ }
+
+ U1RouteRadioButton = (CheckBox) findViewById(R.id.radio_u1);
+ U1NRouteRadioButton = (CheckBox) findViewById(R.id.radio_u1n);
+ U2RouteRadioButton = (CheckBox) findViewById(R.id.radio_u2);
+ U6RouteRadioButton = (CheckBox) findViewById(R.id.radio_u6);
+ U9RouteRadioButton = (CheckBox) findViewById(R.id.radio_u9);
+
+ busIDTextView = (TextView) findViewById(R.id.busActivityBusID);
+
+ progBar = (ProgressBar) findViewById(R.id.busActivityCenterLoadBar);
+ busContentMessage = (TextView) findViewById(R.id.busActivityMessage);
+ busActivityContentLayout = (LinearLayout) findViewById(R.id.busActivityContentLayout);
+
+ if (bus.id != null) {
+ Log.i(TAG, "Bus id is not null (" + bus.id + ") setting busIDTextView");
+ busIDTextView.setText(bus.id);
+ } else {
+ Log.w(TAG, "Bus id is null?");
+ // Might not ever happen
+ busIDTextView.setText("Unidentified");
+ }
+
+ if (bus.route.uniLink) {
+ Log.i(TAG, "Bus is uniLink");
+ if (bus.route.code.equals("U1")) {
+ U1RouteRadioButton.setVisibility(View.VISIBLE);
+ U1NRouteRadioButton.setVisibility(View.GONE);
+ U2RouteRadioButton.setVisibility(View.GONE);
+ U6RouteRadioButton.setVisibility(View.GONE);
+ U9RouteRadioButton.setVisibility(View.GONE);
+ } else if (bus.route.code.equals("U1N")) {
+ U1RouteRadioButton.setVisibility(View.GONE);
+ U1NRouteRadioButton.setVisibility(View.VISIBLE);
+ U2RouteRadioButton.setVisibility(View.GONE);
+ U6RouteRadioButton.setVisibility(View.GONE);
+ U9RouteRadioButton.setVisibility(View.GONE);
+ } else if (bus.route.code.equals("U2")) {
+ U1RouteRadioButton.setVisibility(View.GONE);
+ U1NRouteRadioButton.setVisibility(View.GONE);
+ U2RouteRadioButton.setVisibility(View.VISIBLE);
+ U6RouteRadioButton.setVisibility(View.GONE);
+ U9RouteRadioButton.setVisibility(View.GONE);
+ } else if (bus.route.code.equals("U6")) {
+ U1RouteRadioButton.setVisibility(View.GONE);
+ U1NRouteRadioButton.setVisibility(View.GONE);
+ U2RouteRadioButton.setVisibility(View.GONE);
+ U6RouteRadioButton.setVisibility(View.VISIBLE);
+ U9RouteRadioButton.setVisibility(View.GONE);
+ } else if (bus.route.code.equals("U9")) {
+ U1RouteRadioButton.setVisibility(View.GONE);
+ U1NRouteRadioButton.setVisibility(View.GONE);
+ U2RouteRadioButton.setVisibility(View.GONE);
+ U6RouteRadioButton.setVisibility(View.GONE);
+ U9RouteRadioButton.setVisibility(View.VISIBLE);
+ } else {
+ Log.e(TAG, "Route not found " + bus.route.code);
+ }
+ }
+
+ } catch (NumberFormatException e) {
+ e.printStackTrace();
+ } catch (SQLException e) {
+ e.printStackTrace();
+ }
+ }
+
+ private class GetTimetableTask extends AsyncTask<String, Integer, Timetable> {
+ String errorMessage;
+
+ protected void onPreExecute() {
+ progBar.setVisibility(View.VISIBLE);
+ }
+
+ protected Timetable doInBackground(String... busStopID) {
+ Timetable newTimetable = null;
+ try {
+ final SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(instance);
+
+ newTimetable = DataManager.getTimetable(instance, bus, busStop, 10);
+ } catch (SQLException e) {
+ errorMessage = "Error message regarding SQL?";
+ e.printStackTrace();
+ } catch (ClientProtocolException e) {
+ errorMessage = "ClientProtocolException!?!";
+ e.printStackTrace();
+ } catch (IOException e) {
+ errorMessage = "Error fetching bus times from server, are you connected to the internet?";
+ e.printStackTrace();
+ } catch (JSONException e) {
+ errorMessage = "Error parsing bus times";
+ e.printStackTrace();
+ } catch (Exception e) {
+ Log.e(TAG, e.getMessage(), e.getCause());
+ }
+ return newTimetable;
+ }
+
+ protected void onPostExecute(Timetable newTimetable) {
+ Log.i(TAG, "Got timetable");
+ if (newTimetable == null) {
+ Log.i(TAG, "Its null");
+
+ progBar.setVisibility(View.GONE);
+ busContentMessage.setText(errorMessage);
+ busContentMessage.setVisibility(View.VISIBLE);
+ } else {
+ progBar.setVisibility(View.GONE);
+ timetable = newTimetable;
+ displayTimetable(timetable);
+ }
+ }
+ }
+
+ private void displayTimetable(Timetable timetable) {
+ visibleTimetable = (Timetable) timetable.clone();
+
+ Log.i(TAG, "It contains " + visibleTimetable.size() + " stops");
+
+ if (timetable.size() == 0) {
+ busContentMessage.setText("No Busses");
+ busContentMessage.setVisibility(View.VISIBLE);
+ busActivityContentLayout.setGravity(Gravity.CENTER);
+ } else {
+
+ for (Iterator<Stop> stopIter = visibleTimetable.iterator(); stopIter.hasNext();) {
+ Stop stop = stopIter.next();
+ Log.i(TAG, "Begin filtering, looking at " + stop + " with route " + stop.bus.route.code);
+ if (stop.bus.route.code.equals("U1")) {
+ if (!U1RouteRadioButton.isChecked()) {
+ stopIter.remove();
+ }
+ } else if (stop.bus.route.code.equals("U1N")) {
+ if (!U1NRouteRadioButton.isChecked()) {
+ stopIter.remove();
+ }
+ } else if (stop.bus.route.code.equals("U2")) {
+ if (!U2RouteRadioButton.isChecked()) {
+ stopIter.remove();
+ }
+ } else if (stop.bus.route.code.equals("U6")) {
+ if (!U6RouteRadioButton.isChecked()) {
+ stopIter.remove();
+ }
+ } else if (stop.bus.route.code.equals("U9")) {
+ if (!U9RouteRadioButton.isChecked()) {
+ stopIter.remove();
+ }
+ }
+ }
+
+ if (visibleTimetable.size() == 0) {
+ busActivityContentLayout.setGravity(Gravity.CENTER);
+ busContentMessage.setText("No Busses (With the current enabled routes)");
+ busContentMessage.setVisibility(View.VISIBLE);
+ busTimeList.setVisibility(View.GONE);
+ } else {
+ busTimeList.setVisibility(View.VISIBLE);
+ busContentMessage.setVisibility(View.GONE);
+ TimetableAdapter adapter;
+ if ((adapter = (TimetableAdapter) busTimeList.getAdapter()) != null) {
+ adapter.updateTimetable(visibleTimetable);
+ } else {
+ adapter = new TimetableAdapter(this, visibleTimetable);
+ busTimeList.setAdapter(adapter);
+ }
+ busActivityContentLayout.setGravity(Gravity.TOP);
+ }
+ }
+ }
+}
diff --git a/src/net/cbaines/suma/BusSpecificStopView.java b/src/net/cbaines/suma/BusSpecificStopView.java
new file mode 100644
index 0000000..1997e4a
--- /dev/null
+++ b/src/net/cbaines/suma/BusSpecificStopView.java
@@ -0,0 +1,137 @@
+/*
+ * Southampton University Map App
+ * Copyright (C) 2011 Christopher Baines
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+package net.cbaines.suma;
+
+import java.sql.SQLException;
+import java.text.DateFormat;
+
+import android.app.Activity;
+import android.content.Context;
+import android.content.Intent;
+import android.view.Gravity;
+import android.view.View;
+import android.view.View.OnClickListener;
+import android.view.View.OnLongClickListener;
+import android.widget.LinearLayout;
+import android.widget.TextView;
+import android.widget.Toast;
+
+import com.j256.ormlite.android.apptools.OpenHelperManager;
+import com.j256.ormlite.dao.Dao;
+
+public class BusSpecificStopView extends LinearLayout implements OnClickListener, OnLongClickListener {
+
+ // private final ImageView icon;
+
+ // private static final String TAG = "StopView";
+
+ private final TextView location;
+ private final TextView time;
+ private String onClickMessage = "";
+ private final Context context;
+
+ private Stop stop;
+
+ public BusSpecificStopView(Context context, Stop stop) {
+ super(context);
+
+ this.context = context;
+
+ this.setOrientation(HORIZONTAL);
+
+ location = new TextView(context);
+ location.setTextSize(22f);
+
+ time = new TextView(context);
+ time.setTextSize(22f);
+ time.setGravity(Gravity.RIGHT);
+
+ setStop(stop);
+
+ addView(location, new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
+ addView(time, new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));
+ }
+
+ public void setStop(Stop stop) {
+
+ // Log.i(TAG, "Time of arival " + stop.arivalTime);
+
+ this.stop = stop;
+
+ location.setText(stop.busStop.description);
+ time.setText(stop.getTimeToArival());
+
+ DatabaseHelper helper = OpenHelperManager.getHelper(context, DatabaseHelper.class);
+
+ try {
+ Dao<Bus, Integer> busDao = helper.getBusDao();
+
+ busDao.refresh(stop.bus);
+
+ if (stop.bus.id != null) {
+ if (stop.live) {
+ onClickMessage = "Bus " + stop.bus.toString() + " at " + DateFormat.getTimeInstance(DateFormat.SHORT).format(stop.arivalTime);
+ } else {
+ onClickMessage = "Timetabled bus " + stop.bus.toString() + " at " + DateFormat.getTimeInstance(DateFormat.SHORT).format(stop.arivalTime);
+ }
+ } else {
+ if (stop.live) {
+ onClickMessage = "Unidentified bus (" + stop.bus.getName() + ") at " + DateFormat.getTimeInstance(DateFormat.SHORT).format(stop.arivalTime);
+ } else {
+ onClickMessage = "Timetabled bus (" + stop.bus.getName() + ") at " + DateFormat.getTimeInstance(DateFormat.SHORT).format(stop.arivalTime);
+ }
+ }
+ } catch (SQLException e) {
+ e.printStackTrace();
+ }
+
+ this.setOnClickListener(this);
+ this.setOnLongClickListener(this);
+ }
+
+ public void onClick(View v) {
+ Toast.makeText(context, onClickMessage, Toast.LENGTH_SHORT).show();
+
+ }
+
+ @Override
+ public boolean onLongClick(View v) {
+ DatabaseHelper helper = OpenHelperManager.getHelper(context, DatabaseHelper.class);
+
+ try {
+ Dao<Bus, Integer> busDao = helper.getBusDao();
+
+ busDao.refresh(stop.bus);
+
+ if (stop.bus.id != null) {
+ Intent i = new Intent(context, BusActivity.class);
+ i.putExtra("busID", stop.bus.id);
+ ((Activity) context).startActivityForResult(i, 0);
+ } else {
+ Toast.makeText(context, "Arival prediction not avalible for timetabled buses", Toast.LENGTH_SHORT).show();
+ }
+
+ } catch (SQLException e) {
+ e.printStackTrace();
+ }
+ return false;
+ }
+
+}
diff --git a/src/net/cbaines/suma/BusStopActivity.java b/src/net/cbaines/suma/BusStopActivity.java
index 421a0eb..5928033 100644
--- a/src/net/cbaines/suma/BusStopActivity.java
+++ b/src/net/cbaines/suma/BusStopActivity.java
@@ -310,12 +310,9 @@ public class BusStopActivity extends OrmLiteBaseActivity<DatabaseHelper> impleme
errorMessage = "Error parsing bus times";
e.printStackTrace();
} catch (Exception e) {
- if (THROW_ERROR_ON_EXCEPTION) {
- throw new RuntimeException(e.getMessage());
- } else {
- Log.e(TAG, e.getMessage(), e.getCause());
- }
+ Log.e(TAG, e.getMessage(), e.getCause());
}
+
return newTimetable;
}
diff --git a/src/net/cbaines/suma/DataManager.java b/src/net/cbaines/suma/DataManager.java
index 84731ff..634415d 100644
--- a/src/net/cbaines/suma/DataManager.java
+++ b/src/net/cbaines/suma/DataManager.java
@@ -24,6 +24,7 @@ import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.sql.SQLException;
+import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
@@ -550,18 +551,19 @@ public class DataManager {
if (bus == null) {
bus = new Bus(busID, route, dir);
bus.destination = destStop;
+ busDao.create(bus);
} else {
bus.destination = destStop;
bus.route = route;
bus.direction = dir;
+ busDao.update(bus);
}
} else {
bus = new Bus(null, route, dir);
+ busDao.create(bus);
}
- busDao.update(bus);
-
stop = new Stop(bus, busStop, calender.getTime(), now, live);
return stop;
@@ -636,6 +638,72 @@ public class DataManager {
return timetable;
}
+ public static Timetable getTimetable(Context context, Bus bus, BusStop startStop, int num) throws SQLException, ClientProtocolException, IOException,
+ JSONException {
+
+ if (helper == null)
+ helper = OpenHelperManager.getHelper(context, DatabaseHelper.class);
+ if (busRouteDao == null)
+ busRouteDao = helper.getBusRouteDao();
+ if (busStopDao == null)
+ busStopDao = helper.getBusStopDao();
+
+ Timetable timetable = new Timetable();
+
+ List<BusStop> busStops = new ArrayList<BusStop>(num);
+ busStops.add(startStop);
+
+ BusRoute route = bus.route;
+
+ for (int i = 0; i < num; i++) {
+ BusStop nextStop = route.moveInRoute(context, busStops.get(i), bus.direction, 1);
+
+ if (nextStop != null) {
+ busStops.add(nextStop);
+ } else {
+ Log.e(TAG, "nextStop is null");
+ }
+ }
+
+ for (BusStop busStop : busStops) {
+
+ String file = getFileFromServer(busStopUrl + busStop + ".json");
+
+ JSONObject data = new JSONObject(file);
+ JSONArray stopsArray = data.getJSONArray("stops");
+
+ HashSet<BusRoute> busRoutes = new HashSet<BusRoute>();
+ busRoutes.add(bus.route);
+
+ Log.i(TAG, "Number of entries " + data.length());
+
+ Log.i(TAG, "Stops: " + data.getJSONArray("stops"));
+
+ for (int stopNum = 0; stopNum < stopsArray.length(); stopNum++) {
+ JSONObject stopObj = stopsArray.getJSONObject(stopNum);
+
+ if (stopObj.getString("vehicle").equals(bus.id)) {
+
+ Stop stop = getStop(context, stopObj, busRoutes, busStop);
+
+ if (stop == null) {
+ Log.w(TAG, "Null stop, skiping");
+ continue;
+ }
+
+ Log.i(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;
+ }
+
static PathOverlay getRoutePath(InputStream routeResource, int colour, ResourceProxy resProxy) {
PathOverlay data = null;
diff --git a/src/net/cbaines/suma/DatabaseHelper.java b/src/net/cbaines/suma/DatabaseHelper.java
index a72faca..2d8f9d2 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 = 38;
+ private static final int DATABASE_VERSION = 39;
private static final String TAG = "DatabaseHelper";
diff --git a/src/net/cbaines/suma/Preferences.java b/src/net/cbaines/suma/Preferences.java
index df44729..d73d0ce 100644
--- a/src/net/cbaines/suma/Preferences.java
+++ b/src/net/cbaines/suma/Preferences.java
@@ -10,7 +10,4 @@ public interface Preferences {
static final boolean NON_UNI_LINK_BUS_TIMES_ENABLED_BY_DEFAULT = false;
static final String NON_UNI_LINK_BUS_STOPS = "nonUniLinkBusStops";
static final boolean NON_UNI_LINK_BUS_STOPS_ENABLED_BY_DEFAULT = false;
-
- static final boolean THROW_ERROR_ON_EXCEPTION = false;
-
}
diff --git a/src/net/cbaines/suma/StopView.java b/src/net/cbaines/suma/StopView.java
index 68be1f6..0fe3aa1 100644
--- a/src/net/cbaines/suma/StopView.java
+++ b/src/net/cbaines/suma/StopView.java
@@ -22,10 +22,13 @@ package net.cbaines.suma;
import java.sql.SQLException;
import java.text.DateFormat;
+import android.app.Activity;
import android.content.Context;
+import android.content.Intent;
import android.view.Gravity;
import android.view.View;
import android.view.View.OnClickListener;
+import android.view.View.OnLongClickListener;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;
@@ -33,7 +36,7 @@ import android.widget.Toast;
import com.j256.ormlite.android.apptools.OpenHelperManager;
import com.j256.ormlite.dao.Dao;
-public class StopView extends LinearLayout implements OnClickListener {
+public class StopView extends LinearLayout implements OnClickListener, OnLongClickListener {
// private final ImageView icon;
@@ -44,6 +47,8 @@ public class StopView extends LinearLayout implements OnClickListener {
private String onClickMessage = "";
private final Context context;
+ private Stop stop;
+
public StopView(Context context, Stop stop) {
super(context);
@@ -68,6 +73,8 @@ public class StopView extends LinearLayout implements OnClickListener {
// Log.i(TAG, "Time of arival " + stop.arivalTime);
+ this.stop = stop;
+
name.setText(stop.bus.getName());
time.setText(stop.getTimeToArival());
@@ -88,8 +95,7 @@ public class StopView extends LinearLayout implements OnClickListener {
if (stop.live) {
onClickMessage = "Unidentified bus (" + stop.bus.getName() + ") at " + DateFormat.getTimeInstance(DateFormat.SHORT).format(stop.arivalTime);
} else {
- onClickMessage = "Timetabled bus (" + stop.bus.getName() + ") at "
- + DateFormat.getTimeInstance(DateFormat.SHORT).format(stop.arivalTime);
+ onClickMessage = "Timetabled bus (" + stop.bus.getName() + ") at " + DateFormat.getTimeInstance(DateFormat.SHORT).format(stop.arivalTime);
}
}
} catch (SQLException e) {
@@ -97,6 +103,7 @@ public class StopView extends LinearLayout implements OnClickListener {
}
this.setOnClickListener(this);
+ this.setOnLongClickListener(this);
}
public void onClick(View v) {
@@ -104,4 +111,27 @@ public class StopView extends LinearLayout implements OnClickListener {
}
+ @Override
+ public boolean onLongClick(View v) {
+ DatabaseHelper helper = OpenHelperManager.getHelper(context, DatabaseHelper.class);
+
+ try {
+ Dao<Bus, Integer> busDao = helper.getBusDao();
+
+ busDao.refresh(stop.bus);
+
+ if (stop.bus.id != null) {
+ Intent i = new Intent(context, BusActivity.class);
+ i.putExtra("busID", stop.bus.id);
+ ((Activity) context).startActivityForResult(i, 0);
+ } else {
+ Toast.makeText(context, "Arival prediction not avalible for timetabled buses", Toast.LENGTH_SHORT).show();
+ }
+
+ } catch (SQLException e) {
+ e.printStackTrace();
+ }
+ return false;
+ }
+
}