From a6dcb82b21325934ae3f4df9cfc5aad04d414653 Mon Sep 17 00:00:00 2001 From: Christopher Baines Date: Mon, 27 Feb 2012 23:26:34 +0000 Subject: Really cool uri stuff, needs more thinking about, but its really cool :) --- AndroidManifest.xml | 72 +++++++++++++++++ src/net/cbaines/suma/AboutActivity.java | 117 ++++++++++++++------------- src/net/cbaines/suma/BuildingActivity.java | 19 ++++- src/net/cbaines/suma/BuildingNumOverlay.java | 11 ++- src/net/cbaines/suma/BusActivity.java | 75 ++++++++--------- src/net/cbaines/suma/BusStopActivity.java | 39 ++++++--- src/net/cbaines/suma/BusStopOverlay.java | 12 +-- src/net/cbaines/suma/DonateDialog.java | 86 ++++++++++---------- 8 files changed, 268 insertions(+), 163 deletions(-) diff --git a/AndroidManifest.xml b/AndroidManifest.xml index 6355013..0445178 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -13,6 +13,12 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + implem setContentView(R.layout.building_activity); instance = this; - String ID = getIntent().getExtras().getString("buildingID"); + String ID; + + Log.i(TAG, "getIntent().getDataString() " + getIntent().getDataString()); + + if (getIntent().getDataString().startsWith("http://data")) { + + String[] uriParts = getIntent().getDataString().split("/"); + + ID = uriParts[uriParts.length - 1].replace(".html", ""); + + } else { + + String[] uriParts = getIntent().getDataString().split("/"); + + ID = uriParts[uriParts.length - 1]; + } + + Log.i(TAG, "ID " + ID); final SharedPreferences favouritesPrefs = instance.getSharedPreferences(FAVOURITES_PREFERENCES, 0); diff --git a/src/net/cbaines/suma/BuildingNumOverlay.java b/src/net/cbaines/suma/BuildingNumOverlay.java index cc20003..87d4156 100644 --- a/src/net/cbaines/suma/BuildingNumOverlay.java +++ b/src/net/cbaines/suma/BuildingNumOverlay.java @@ -29,7 +29,6 @@ import org.osmdroid.views.MapView; import org.osmdroid.views.MapView.Projection; import org.osmdroid.views.overlay.Overlay; -import android.app.Activity; import android.content.Intent; import android.content.SharedPreferences; import android.content.SharedPreferences.OnSharedPreferenceChangeListener; @@ -40,6 +39,7 @@ import android.graphics.Paint.Style; import android.graphics.Point; import android.graphics.Rect; import android.graphics.drawable.Drawable; +import android.net.Uri; import android.util.Log; import android.view.MotionEvent; import android.widget.Toast; @@ -221,9 +221,12 @@ public class BuildingNumOverlay extends Overlay implements Preferences, OnShared } else { Log.i(TAG, "Pressed " + building.id); - Intent i = new Intent(context, BuildingActivity.class); - i.putExtra("buildingID", building.id); - ((Activity) context).startActivityForResult(i, 0); + Uri uri = Uri.parse("http://id.southampton.ac.uk/building/" + building.id); + + Log.i(TAG, "Starting a activity for " + uri + " path " + uri.getPath()); + + Intent buildingIntent = new Intent(Intent.ACTION_VIEW, uri); + context.startActivity(buildingIntent); return true; } diff --git a/src/net/cbaines/suma/BusActivity.java b/src/net/cbaines/suma/BusActivity.java index 2b76176..f4edc3f 100644 --- a/src/net/cbaines/suma/BusActivity.java +++ b/src/net/cbaines/suma/BusActivity.java @@ -24,8 +24,7 @@ import android.widget.Toast; import com.j256.ormlite.android.apptools.OrmLiteBaseActivity; -public class BusActivity extends OrmLiteBaseActivity implements - Preferences { +public class BusActivity extends OrmLiteBaseActivity implements Preferences { final static String TAG = "BusActivity"; private TextView U1RouteTextView; @@ -71,13 +70,28 @@ public class BusActivity extends OrmLiteBaseActivity implements setContentView(R.layout.bus_activity); instance = this; - String busID = getIntent().getExtras().getString("busID"); + Log.i(TAG, "getIntent().getDataString() " + getIntent().getDataString()); + + String busID; + + if (getIntent().getDataString().startsWith("http://data")) { + + String[] uriParts = getIntent().getDataString().split("/"); + + busID = uriParts[uriParts.length - 1].replace(".html", ""); + + } else { + + String[] uriParts = getIntent().getDataString().split("/"); + + busID = uriParts[uriParts.length - 1]; + } + String busStopID = getIntent().getExtras().getString("busStopID"); final DatabaseHelper helper = getHelper(); try { - List buses = helper.getBusDao().queryForEq(Bus.ID_FIELD_NAME, - busID); + List buses = helper.getBusDao().queryForEq(Bus.ID_FIELD_NAME, busID); bus = null; if (buses.size() == 0) { Log.e(TAG, "Bus " + busID + " not found!"); @@ -91,8 +105,7 @@ public class BusActivity extends OrmLiteBaseActivity implements busStop = null; if (busStopID != null) { - List busStops = helper.getBusStopDao().queryForEq( - BusStop.ID_FIELD_NAME, busStopID); + List busStops = helper.getBusStopDao().queryForEq(BusStop.ID_FIELD_NAME, busStopID); if (busStops.size() == 0) { Log.e(TAG, "BusStop " + busStopID + " not found!"); } else if (busStops.size() == 1) { @@ -115,8 +128,7 @@ public class BusActivity extends OrmLiteBaseActivity implements timetableView = (ListView) findViewById(R.id.busActivityTimes); if (bus.id != null) { - Log.i(TAG, "Bus id is not null (" + bus.id - + ") setting busIDTextView"); + Log.i(TAG, "Bus id is not null (" + bus.id + ") setting busIDTextView"); busIDTextView.setText(bus.id + " " + bus.getName()); } else { Log.w(TAG, "Bus id is null?"); @@ -165,29 +177,23 @@ public class BusActivity extends OrmLiteBaseActivity implements } /* - * for (int i = 0;; i++) { BusStop nextStop = - * bus.route.moveInRoute(instance, busStops.get(i), bus.direction, 1); + * for (int i = 0;; i++) { BusStop nextStop = bus.route.moveInRoute(instance, busStops.get(i), bus.direction, 1); * - * if (nextStop.equals(busStop) || (bus.destination != null && - * bus.destination.equals(nextStop))) { break; } + * if (nextStop.equals(busStop) || (bus.destination != null && bus.destination.equals(nextStop))) { break; } * * busStops.add(nextStop); busStopsActive.add(false); * - * if (busStops.size() > 50) { Log.e(TAG, "Got more than 50 bus stops"); - * break; } } + * if (busStops.size() > 50) { Log.e(TAG, "Got more than 50 bus stops"); break; } } */ refreshData = new Runnable() { public void run() { - for (int num = timetableView.getFirstVisiblePosition(); num < timetableView - .getLastVisiblePosition(); num++) { + for (int num = timetableView.getFirstVisiblePosition(); num < timetableView.getLastVisiblePosition(); num++) { Stop stop = timetable.get(num); GetTimetableStopTask task = tasks.get(busStops.get(num)); - if (stop.timeOfFetch == null - || (stop.timeOfFetch.getTime() - System - .currentTimeMillis()) > 20000) { + if (stop.timeOfFetch == null || (stop.timeOfFetch.getTime() - System.currentTimeMillis()) > 20000) { if (task != null) { if (task.getStatus() == AsyncTask.Status.FINISHED) { task = null; @@ -212,12 +218,9 @@ public class BusActivity extends OrmLiteBaseActivity implements public void onResume() { super.onResume(); - SharedPreferences sharedPrefs = PreferenceManager - .getDefaultSharedPreferences(this); - if (sharedPrefs.getBoolean(UNI_LINK_BUS_TIMES, - UNI_LINK_BUS_TIMES_ENABLED_BY_DEFAULT) - || sharedPrefs.getBoolean(NON_UNI_LINK_BUS_TIMES, - NON_UNI_LINK_BUS_TIMES_ENABLED_BY_DEFAULT)) { + SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(this); + if (sharedPrefs.getBoolean(UNI_LINK_BUS_TIMES, UNI_LINK_BUS_TIMES_ENABLED_BY_DEFAULT) + || sharedPrefs.getBoolean(NON_UNI_LINK_BUS_TIMES, NON_UNI_LINK_BUS_TIMES_ENABLED_BY_DEFAULT)) { Log.i(TAG, "Live Times enabled"); timetable = (Timetable) getLastNonConfigurationInstance(); @@ -227,8 +230,7 @@ public class BusActivity extends OrmLiteBaseActivity implements Log.i(TAG, "No Previous timetable"); timetable = new Timetable(); for (int i = 0; i < busStops.size(); i++) { - timetable.add(new Stop(bus, busStops.get(i), null, null, - false)); + timetable.add(new Stop(bus, busStops.get(i), null, null, false)); } Log.v(TAG, "Finished adding placeholder stops"); } else { @@ -261,8 +263,7 @@ public class BusActivity extends OrmLiteBaseActivity implements super.onPause(); } - private class GetTimetableStopTask extends - AsyncTask { + private class GetTimetableStopTask extends AsyncTask { private String errorMessage; private BusStop busStop; @@ -331,26 +332,20 @@ public class BusActivity extends OrmLiteBaseActivity implements } else { if (visibleTimetable.size() == 0) { busActivityContentLayout.setGravity(Gravity.CENTER); - busContentMessage - .setText("No Busses (With the current enabled routes)"); + busContentMessage.setText("No Busses (With the current enabled routes)"); busContentMessage.setVisibility(View.VISIBLE); timetableView.setVisibility(View.GONE); } else { timetableView.setVisibility(View.VISIBLE); busContentMessage.setVisibility(View.GONE); BusSpecificTimetableAdapter adapter; - if ((adapter = (BusSpecificTimetableAdapter) timetableView - .getAdapter()) != null) { + if ((adapter = (BusSpecificTimetableAdapter) timetableView.getAdapter()) != null) { adapter.updateTimetable(visibleTimetable); } else { - adapter = new BusSpecificTimetableAdapter(this, - visibleTimetable); + adapter = new BusSpecificTimetableAdapter(this, visibleTimetable); timetableView.setAdapter(adapter); if (busStop != null) { - Log.i(TAG, - "Moving to position of " + busStop.description - + " which is " - + busStops.indexOf(busStop)); + Log.i(TAG, "Moving to position of " + busStop.description + " which is " + busStops.indexOf(busStop)); timetableView.setSelection(busStops.indexOf(busStop)); } } diff --git a/src/net/cbaines/suma/BusStopActivity.java b/src/net/cbaines/suma/BusStopActivity.java index bc8e22e..dbed3ee 100644 --- a/src/net/cbaines/suma/BusStopActivity.java +++ b/src/net/cbaines/suma/BusStopActivity.java @@ -75,9 +75,6 @@ public class BusStopActivity extends OrmLiteBaseActivity impleme protected Timetable timetable; private Timetable visibleTimetable; - protected String busStopID; - private String busStopName; - private Dao busStopDao; private BusStop busStop; @@ -106,15 +103,29 @@ public class BusStopActivity extends OrmLiteBaseActivity 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); 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); @@ -128,6 +139,10 @@ public class BusStopActivity extends OrmLiteBaseActivity impleme U9RouteRadioButton.setOnCheckedChangeListener(this); try { + Dao busStopDao = helper.getBusStopDao(); + + busStop = busStopDao.queryForId(busStopID); + Dao busRouteDao = helper.getBusRouteDao(); Dao routeStopsDao = helper.getRouteStopsDao(); @@ -201,7 +216,7 @@ public class BusStopActivity extends OrmLiteBaseActivity impleme Log.i(TAG, "Got busstop id " + busStopID); - busName.setText(busStopName); + busName.setText(busStop.description); busID.setText(busStopID); } @@ -217,7 +232,7 @@ public class BusStopActivity extends OrmLiteBaseActivity impleme refreshData = new Runnable() { public void run() { timetableTask = new GetTimetableTask(); - timetableTask.execute(busStopID); + timetableTask.execute(busStop.id); mHandler.postDelayed(refreshData, 20000); } }; @@ -296,7 +311,7 @@ public class BusStopActivity extends OrmLiteBaseActivity 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 +334,7 @@ public class BusStopActivity extends OrmLiteBaseActivity 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 +370,9 @@ public class BusStopActivity extends OrmLiteBaseActivity impleme try { Set 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)) { diff --git a/src/net/cbaines/suma/BusStopOverlay.java b/src/net/cbaines/suma/BusStopOverlay.java index 4705d1d..b8f1077 100644 --- a/src/net/cbaines/suma/BusStopOverlay.java +++ b/src/net/cbaines/suma/BusStopOverlay.java @@ -27,7 +27,6 @@ import org.osmdroid.views.MapView; import org.osmdroid.views.MapView.Projection; import org.osmdroid.views.overlay.Overlay; -import android.app.Activity; import android.content.Intent; import android.content.SharedPreferences; import android.graphics.Canvas; @@ -36,6 +35,7 @@ import android.graphics.Paint.Style; import android.graphics.Point; import android.graphics.Rect; import android.graphics.drawable.Drawable; +import android.net.Uri; import android.util.Log; import android.view.MotionEvent; import android.widget.Toast; @@ -222,10 +222,12 @@ public class BusStopOverlay extends Overlay implements RouteColorConstants, Pref } else { Log.i(TAG, "Pressed " + busStop.id); - Intent i = new Intent(context, BusStopActivity.class); - i.putExtra("busStopID", busStop.id); - i.putExtra("busStopName", busStop.description); - ((Activity) context).startActivityForResult(i, 0); + 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); + context.startActivity(busStopIntent); return true; } diff --git a/src/net/cbaines/suma/DonateDialog.java b/src/net/cbaines/suma/DonateDialog.java index be5cd41..a364104 100644 --- a/src/net/cbaines/suma/DonateDialog.java +++ b/src/net/cbaines/suma/DonateDialog.java @@ -31,62 +31,62 @@ import android.widget.TextView; public class DonateDialog extends Dialog implements Runnable { - // private static final String TAG = "DonateDialog"; + // private static final String TAG = "DonateDialog"; - private static final String bitcoinAddress = "1LFATViKkmbm6m4u1Ghi9wqrgVy2B6M412"; + private static final String bitcoinAddress = "1LFATViKkmbm6m4u1Ghi9wqrgVy2B6M412"; - private final Context context; + private final Context context; - private final TextView dialogMessage; - private final ProgressBar progressBar; + private final TextView dialogMessage; + private final ProgressBar progressBar; - private final LinearLayout errorLayout; - private final TextView donateDialogErrorMessage; - private final TextView donateBitcoinAddress; + private final LinearLayout errorLayout; + private final TextView donateDialogErrorMessage; + private final TextView donateBitcoinAddress; - public DonateDialog(Context context) { - super(context); + public DonateDialog(Context context) { + super(context); - this.context = context; + this.context = context; - setContentView(R.layout.donate_dialog); - setTitle("Donate"); + setContentView(R.layout.donate_dialog); + setTitle("Donate"); - dialogMessage = (TextView) findViewById(R.id.donateDialogMessage); - progressBar = (ProgressBar) findViewById(R.id.donateDialogProgress); + dialogMessage = (TextView) findViewById(R.id.donateDialogMessage); + progressBar = (ProgressBar) findViewById(R.id.donateDialogProgress); - errorLayout = (LinearLayout) findViewById(R.id.donateDialogMessageLayout); - donateDialogErrorMessage = (TextView) findViewById(R.id.donateDialogErrorMessage); - donateBitcoinAddress = (TextView) findViewById(R.id.donateBitcoinAddress); + errorLayout = (LinearLayout) findViewById(R.id.donateDialogMessageLayout); + donateDialogErrorMessage = (TextView) findViewById(R.id.donateDialogErrorMessage); + donateBitcoinAddress = (TextView) findViewById(R.id.donateBitcoinAddress); - new Thread(this).start(); - } - - public void run() { - try { - Thread.sleep(3000); - } catch (InterruptedException e) { - e.printStackTrace(); + new Thread(this).start(); } - try { - - Intent donateIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("bitcoin:" + bitcoinAddress - + "?label=Southampton%20Uni%20Map%20App&message=Donation%20for%20the%20Southampton%20University%20Map%20App")); - context.startActivity(donateIntent); - - } catch (ActivityNotFoundException e) { - errorLayout.post(new Runnable() { - public void run() { - dialogMessage.setText(R.string.donate_dialog_error_title); - progressBar.setVisibility(View.GONE); - errorLayout.setVisibility(View.VISIBLE); - donateDialogErrorMessage.setVisibility(View.VISIBLE); - donateBitcoinAddress.setText(bitcoinAddress); - donateBitcoinAddress.setVisibility(View.VISIBLE); + public void run() { + try { + Thread.sleep(3000); + } catch (InterruptedException e) { + e.printStackTrace(); + } + + try { + + Intent donateIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("bitcoin:" + bitcoinAddress + + "?label=Southampton%20Uni%20Map%20App&message=Donation%20for%20the%20Southampton%20University%20Map%20App")); + context.startActivity(donateIntent); + + } catch (ActivityNotFoundException e) { + errorLayout.post(new Runnable() { + public void run() { + dialogMessage.setText(R.string.donate_dialog_error_title); + progressBar.setVisibility(View.GONE); + errorLayout.setVisibility(View.VISIBLE); + donateDialogErrorMessage.setVisibility(View.VISIBLE); + donateBitcoinAddress.setText(bitcoinAddress); + donateBitcoinAddress.setVisibility(View.VISIBLE); + } + }); } - }); } - } } -- cgit v1.2.3