From b5d0db004eaf72e9eeff0dfd7f612591d670b139 Mon Sep 17 00:00:00 2001 From: Christopher Baines Date: Tue, 28 Feb 2012 14:01:42 +0000 Subject: Added a BusRoute activity, and moved more stuff over to the new uri system. --- src/net/cbaines/suma/BusStopActivity.java | 58 +++++++++++++++++++++++++------ 1 file changed, 48 insertions(+), 10 deletions(-) (limited to 'src/net/cbaines/suma/BusStopActivity.java') diff --git a/src/net/cbaines/suma/BusStopActivity.java b/src/net/cbaines/suma/BusStopActivity.java index dbed3ee..62a0f54 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; @@ -59,8 +61,8 @@ import com.j256.ormlite.dao.Dao; import com.j256.ormlite.stmt.PreparedQuery; import com.j256.ormlite.stmt.QueryBuilder; -public class BusStopActivity extends OrmLiteBaseActivity implements OnCheckedChangeListener, Preferences, - OnItemClickListener { +public class BusStopActivity extends OrmLiteBaseActivity implements OnCheckedChangeListener, + Preferences, OnItemClickListener, OnLongClickListener { final static String TAG = "BusTimeActivity"; @@ -133,10 +135,19 @@ public class BusStopActivity extends OrmLiteBaseActivity 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 busStopDao = helper.getBusStopDao(); @@ -310,10 +321,10 @@ public class BusStopActivity extends OrmLiteBaseActivity impleme 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(); @@ -387,7 +398,7 @@ public class BusStopActivity extends OrmLiteBaseActivity 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"); @@ -395,9 +406,14 @@ public class BusStopActivity extends OrmLiteBaseActivity 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) { @@ -522,4 +538,26 @@ public class BusStopActivity extends OrmLiteBaseActivity impleme } } + + 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; + } } -- cgit v1.2.3