aboutsummaryrefslogtreecommitdiff
path: root/src/net/cbaines/suma/BusStopActivity.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/net/cbaines/suma/BusStopActivity.java')
-rw-r--r--src/net/cbaines/suma/BusStopActivity.java134
1 files changed, 88 insertions, 46 deletions
diff --git a/src/net/cbaines/suma/BusStopActivity.java b/src/net/cbaines/suma/BusStopActivity.java
index 07dd45c..bfcc13a 100644
--- a/src/net/cbaines/suma/BusStopActivity.java
+++ b/src/net/cbaines/suma/BusStopActivity.java
@@ -33,6 +33,7 @@ import android.app.Dialog;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
+import android.net.Uri;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Handler;
@@ -43,6 +44,7 @@ import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
+import android.view.View.OnLongClickListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.CheckBox;
@@ -60,7 +62,7 @@ import com.j256.ormlite.stmt.PreparedQuery;
import com.j256.ormlite.stmt.QueryBuilder;
public class BusStopActivity extends OrmLiteBaseActivity<DatabaseHelper> implements OnCheckedChangeListener, Preferences,
- OnItemClickListener {
+ OnItemClickListener, OnLongClickListener {
final static String TAG = "BusTimeActivity";
@@ -75,11 +77,6 @@ public class BusStopActivity extends OrmLiteBaseActivity<DatabaseHelper> impleme
protected Timetable timetable;
private Timetable visibleTimetable;
- protected String busStopID;
- private String busStopName;
-
- private Dao<BusStop, String> busStopDao;
-
private BusStop busStop;
private GetTimetableTask timetableTask;
@@ -106,15 +103,30 @@ public class BusStopActivity extends OrmLiteBaseActivity<DatabaseHelper> impleme
super.onCreate(savedInstanceState);
setContentView(R.layout.bus_stop_activity);
+ Log.i(TAG, "getIntent().getDataString() " + getIntent().getDataString());
+
+ String busStopID;
+
+ if (getIntent().getDataString().startsWith("http://data")) {
+
+ String[] uriParts = getIntent().getDataString().split("/");
+
+ busStopID = uriParts[uriParts.length - 1].replace(".html", "");
+
+ } else {
+
+ String[] uriParts = getIntent().getDataString().split("/");
+
+ busStopID = uriParts[uriParts.length - 1];
+ }
+
final DatabaseHelper helper = getHelper();
SharedPreferences favouritesPreferences = getSharedPreferences(FAVOURITES_PREFERENCES, 0);
+ SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
instance = this;
- busStopID = getIntent().getExtras().getString("busStopID");
- busStopName = getIntent().getExtras().getString("busStopName");
-
U1RouteRadioButton = (CheckBox) findViewById(R.id.radio_u1);
U1NRouteRadioButton = (CheckBox) findViewById(R.id.radio_u1n);
U2RouteRadioButton = (CheckBox) findViewById(R.id.radio_u2);
@@ -122,22 +134,35 @@ public class BusStopActivity extends OrmLiteBaseActivity<DatabaseHelper> impleme
U9RouteRadioButton = (CheckBox) findViewById(R.id.radio_u9);
U1RouteRadioButton.setOnCheckedChangeListener(this);
+ U1RouteRadioButton.setOnLongClickListener(this);
+
U1NRouteRadioButton.setOnCheckedChangeListener(this);
+ U1NRouteRadioButton.setOnLongClickListener(this);
+
U2RouteRadioButton.setOnCheckedChangeListener(this);
+ U2RouteRadioButton.setOnLongClickListener(this);
+
U6RouteRadioButton.setOnCheckedChangeListener(this);
+ U6RouteRadioButton.setOnLongClickListener(this);
+
U9RouteRadioButton.setOnCheckedChangeListener(this);
+ U9RouteRadioButton.setOnLongClickListener(this);
try {
+ Dao<BusStop, String> busStopDao = helper.getBusStopDao();
+
+ busStop = busStopDao.queryForId(busStopID);
+
Dao<BusRoute, Integer> busRouteDao = helper.getBusRouteDao();
- Dao<RouteStops, Integer> routeStopsDao = helper.getRouteStopsDao();
+ Dao<RouteStop, Integer> routeStopsDao = helper.getRouteStopsDao();
for (BusRoute route : busRouteDao) {
- QueryBuilder<RouteStops, Integer> queryBuilder = routeStopsDao.queryBuilder();
+ QueryBuilder<RouteStop, Integer> queryBuilder = routeStopsDao.queryBuilder();
- queryBuilder.where().eq(RouteStops.ROUTE_ID_FIELD_NAME, route.id).and()
- .eq(RouteStops.STOP_ID_FIELD_NAME, busStopID);
+ queryBuilder.where().eq(RouteStop.ROUTE_ID_FIELD_NAME, route.id).and()
+ .eq(RouteStop.STOP_ID_FIELD_NAME, busStopID);
queryBuilder.setCountOf(true);
- PreparedQuery<RouteStops> preparedQuery = queryBuilder.prepare();
+ PreparedQuery<RouteStop> preparedQuery = queryBuilder.prepare();
long count = routeStopsDao.countOf(preparedQuery);
@@ -179,10 +204,6 @@ public class BusStopActivity extends OrmLiteBaseActivity<DatabaseHelper> impleme
}
}
- busStopDao = helper.getBusStopDao();
-
- busStop = busStopDao.queryForId(busStopID);
-
busFavourite = (CheckBox) findViewById(R.id.favouriteCheckBox);
busFavourite.setChecked(favouritesPreferences.getBoolean(busStop.id, false));
busFavourite.setOnCheckedChangeListener(this);
@@ -192,7 +213,12 @@ public class BusStopActivity extends OrmLiteBaseActivity<DatabaseHelper> impleme
}
busName = (TextView) findViewById(R.id.busStopName);
- busID = (TextView) findViewById(R.id.busStopID);
+
+ if (prefs.getBoolean(SHOW_IDENTIFIERS, SHOW_IDENTIFIERS_ENABLED_BY_DEFAULT)) {
+ busID = (TextView) findViewById(R.id.busStopID);
+ busID.setText(busStopID);
+ busID.setVisibility(View.VISIBLE);
+ }
busStopMessage = (TextView) findViewById(R.id.busStopMessage);
progBar = (ProgressBar) findViewById(R.id.busStopLoadBar);
@@ -201,8 +227,7 @@ public class BusStopActivity extends OrmLiteBaseActivity<DatabaseHelper> impleme
Log.i(TAG, "Got busstop id " + busStopID);
- busName.setText(busStopName);
- busID.setText(busStopID);
+ busName.setText(busStop.description);
}
public void onResume() {
@@ -217,7 +242,7 @@ public class BusStopActivity extends OrmLiteBaseActivity<DatabaseHelper> impleme
refreshData = new Runnable() {
public void run() {
timetableTask = new GetTimetableTask();
- timetableTask.execute(busStopID);
+ timetableTask.execute(busStop.id);
mHandler.postDelayed(refreshData, 20000);
}
};
@@ -296,7 +321,7 @@ public class BusStopActivity extends OrmLiteBaseActivity<DatabaseHelper> impleme
final SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(instance);
newTimetable = DataManager
- .getTimetable(instance, busStopID, sharedPrefs.getBoolean(MapActivity.UNI_LINK_BUS_TIMES,
+ .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) {
@@ -319,7 +344,7 @@ public class BusStopActivity extends OrmLiteBaseActivity<DatabaseHelper> impleme
}
protected void onPostExecute(Timetable newTimetable) {
- Log.i(TAG, "Got timetable for " + busStopID);
+ Log.i(TAG, "Got timetable for " + busStop.id);
if (newTimetable == null) {
Log.i(TAG, "Its null");
@@ -355,9 +380,9 @@ public class BusStopActivity extends OrmLiteBaseActivity<DatabaseHelper> impleme
try {
Set<BusStop> tmpStops;
if (item.getItemId() == R.id.menu_next_stop) {
- tmpStops = route.moveInRoute(this, getHelper().getBusStopDao().queryForId(busStopID), 1);
+ tmpStops = route.moveInRoute(this, getHelper().getBusStopDao().queryForId(busStop.id), 1);
} else {
- tmpStops = route.moveInRoute(this, getHelper().getBusStopDao().queryForId(busStopID), -1);
+ tmpStops = route.moveInRoute(this, getHelper().getBusStopDao().queryForId(busStop.id), -1);
}
for (BusStop busStop : tmpStops) {
if (!busStops.contains(busStop)) {
@@ -371,7 +396,7 @@ public class BusStopActivity extends OrmLiteBaseActivity<DatabaseHelper> impleme
Log.i(TAG, "stops " + busStops);
if (busStops.size() == 1) {
- Intent i = new Intent(this, BusStopActivity.class);
+
BusStop stop = (BusStop) busStops.iterator().next();
if (stop == null) {
Log.e(TAG, "stop == null");
@@ -379,9 +404,14 @@ public class BusStopActivity extends OrmLiteBaseActivity<DatabaseHelper> impleme
if (stop.id == null) {
Log.e(TAG, "stop.id == null");
}
- i.putExtra("busStopID", stop.id);
- i.putExtra("busStopName", stop.description);
- startActivity(i);
+
+ Uri uri = Uri.parse("http://id.southampton.ac.uk/bus-stop/" + busStop.id);
+
+ Log.i(TAG, "Starting a activity for " + uri + " path " + uri.getPath());
+
+ Intent busStopIntent = new Intent(Intent.ACTION_VIEW, uri);
+ startActivity(busStopIntent);
+
} else {
showDialog(POI_DIALOG_ID);
if (busDialog == null) {
@@ -484,26 +514,38 @@ public class BusStopActivity extends OrmLiteBaseActivity<DatabaseHelper> impleme
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Log.i(TAG, "OnItemClick pos " + position + " id " + id);
- String poiId = busDialog.adapter.getItemStringId(position);
+ String busId = busDialog.adapter.getItemStringId(position);
- Log.i(TAG, "POI " + poiId + " selected");
+ Log.i(TAG, "Bus " + busId + " selected");
- Intent i = new Intent(this, BusStopActivity.class);
- try {
- busStop = busStopDao.queryForId(poiId);
+ Uri uri = Uri.parse("http://id.southampton.ac.uk/bus/" + busId);
- if (busStop == null) {
- Log.e(TAG, "stop == null");
- }
- if (busStop.id == null) {
- Log.e(TAG, "stop.id == null");
- }
- i.putExtra("busStopID", busStop.id);
- i.putExtra("busStopName", busStop.description);
- startActivity(i);
- } catch (SQLException e) {
- e.printStackTrace();
+ Log.i(TAG, "Starting a activity for " + uri + " path " + uri.getPath());
+
+ Intent busStopIntent = new Intent(Intent.ACTION_VIEW, uri);
+ busStopIntent.putExtra("busStopID", busStop.id);
+ startActivity(busStopIntent);
+ }
+
+ public boolean onLongClick(View v) {
+ Uri uri = null;
+ if (v.equals(U1RouteRadioButton)) {
+ uri = Uri.parse("http://id.southampton.ac.uk/bus-route/326");
+ } else if (v.equals(U1NRouteRadioButton)) {
+ uri = Uri.parse("http://id.southampton.ac.uk/bus-route/468");
+ } else if (v.equals(U2RouteRadioButton)) {
+ uri = Uri.parse("http://id.southampton.ac.uk/bus-route/329");
+ } else if (v.equals(U6RouteRadioButton)) {
+ uri = Uri.parse("http://id.southampton.ac.uk/bus-route/327");
+ } else if (v.equals(U9RouteRadioButton)) {
+ uri = Uri.parse("http://id.southampton.ac.uk/bus-route/354");
}
+ if (uri != null) {
+ Log.i(TAG, "Starting a activity for " + uri + " path " + uri.getPath());
+ Intent busStopIntent = new Intent(Intent.ACTION_VIEW, uri);
+ startActivity(busStopIntent);
+ }
+ return false;
}
}