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 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. --- AndroidManifest.xml | 34 ++ gen/net/cbaines/suma/R.java | Bin 12914 -> 13305 bytes res/layout/bus_route_activity.xml | 40 ++ src/net/cbaines/suma/BusRoute.java | 899 ++++++++++++++++------------- src/net/cbaines/suma/BusRouteActivity.java | 76 +++ src/net/cbaines/suma/BusStopActivity.java | 58 +- src/net/cbaines/suma/MapActivity.java | 180 +++--- src/net/cbaines/suma/POIArrayAdapter.java | 80 +-- src/net/cbaines/suma/POIDialog.java | 86 +-- src/net/cbaines/suma/POIView.java | 129 +++-- src/net/cbaines/suma/Waypoint.java | 42 -- 11 files changed, 946 insertions(+), 678 deletions(-) create mode 100644 res/layout/bus_route_activity.xml create mode 100644 src/net/cbaines/suma/BusRouteActivity.java delete mode 100644 src/net/cbaines/suma/Waypoint.java diff --git a/AndroidManifest.xml b/AndroidManifest.xml index 0445178..1c046f6 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -31,6 +31,16 @@ + + + + + + + + @@ -108,6 +118,30 @@ android:scheme="http" /> + + + + + + + + + + + + + + + + + + diff --git a/gen/net/cbaines/suma/R.java b/gen/net/cbaines/suma/R.java index 06657e6..20027e0 100644 Binary files a/gen/net/cbaines/suma/R.java and b/gen/net/cbaines/suma/R.java differ diff --git a/res/layout/bus_route_activity.xml b/res/layout/bus_route_activity.xml new file mode 100644 index 0000000..fde127c --- /dev/null +++ b/res/layout/bus_route_activity.xml @@ -0,0 +1,40 @@ + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/net/cbaines/suma/BusRoute.java b/src/net/cbaines/suma/BusRoute.java index 4152605..b4dd603 100644 --- a/src/net/cbaines/suma/BusRoute.java +++ b/src/net/cbaines/suma/BusRoute.java @@ -45,456 +45,529 @@ 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"; - - @DatabaseField(id = true) - public int id; - - /** - * The route code (U1, U1N, ...) - */ - @DatabaseField - public String code; - - @DatabaseField(canBeNull = false) - String label; - - /** - * The direction the bus is travelling if it is moving through the route and sequence is increasing. - *
    - *
  • U1 = A
  • - *
  • U2 = B
  • - *
  • U6 = H
  • - *
- */ - @DatabaseField(canBeNull = true) - String forwardDirection; - - /** - * The direction the bus is travelling if it is moving through the route and sequence is decreasing. - *
    - *
  • U1 = C
  • - *
  • U2 = C
  • - *
  • U6 = C
  • - *
- */ - @DatabaseField(canBeNull = true) - String reverseDirection; - - @DatabaseField(canBeNull = false) - boolean uniLink; - - BusRoute() { - } - - public BusRoute(Integer id, String code, String label, String forwardDirection, String reverseDirection, - boolean uniLink) { - this.id = id.intValue(); - this.code = code; - this.label = label; - this.forwardDirection = forwardDirection; - this.reverseDirection = reverseDirection; - this.uniLink = uniLink; - } - - public BusRoute(Integer id, String code, String label, boolean uniLink) { - this(id, code, label, null, null, uniLink); - } - - public String toString() { - return code; - } - - /** - * Untested? - * - * @param context - * @param stop - * @return - */ - BusStop getBusStopBefore(Context context, BusStop stop, String dir) { - return moveInRoute(context, stop, dir, -1); - } - - /** - * Untested? - * - * @param context - * @param stop - * @return - */ - BusStop getStopAfter(Context context, BusStop stop, String dir) { - return moveInRoute(context, stop, dir, 1); - } - - /** - * Untested? - * - * @param context - * @param busStop - * @param moveAmount - * @return - */ - Set moveInRoute(final Context context, final BusStop busStop, final int moveAmount) { - - Set busStops = new HashSet(); - - if (moveAmount == 0) { - busStops.add(busStop); - return busStops; + 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"; + + @DatabaseField(id = true) + public int id; + + /** + * The route code (U1, U1N, ...) + */ + @DatabaseField + public String code; + + @DatabaseField(canBeNull = false) + String label; + + /** + * The direction the bus is travelling if it is moving through the route and + * sequence is increasing. + *
    + *
  • U1 = A
  • + *
  • U2 = B
  • + *
  • U6 = H
  • + *
+ */ + @DatabaseField(canBeNull = true) + String forwardDirection; + + /** + * The direction the bus is travelling if it is moving through the route and + * sequence is decreasing. + *
    + *
  • U1 = C
  • + *
  • U2 = C
  • + *
  • U6 = C
  • + *
+ */ + @DatabaseField(canBeNull = true) + String reverseDirection; + + @DatabaseField(canBeNull = false) + boolean uniLink; + + BusRoute() { } - DatabaseHelper helper = OpenHelperManager.getHelper(context, DatabaseHelper.class); + public BusRoute(Integer id, String code, String label, String forwardDirection, String reverseDirection, + boolean uniLink) { + this.id = id.intValue(); + this.code = code; + this.label = label; + this.forwardDirection = forwardDirection; + this.reverseDirection = reverseDirection; + this.uniLink = uniLink; + } - try { - Dao routeStopsDao = helper.getRouteStopsDao(); - Dao busStopDao = helper.getBusStopDao(); + public BusRoute(Integer id, String code, String label, boolean uniLink) { + this(id, code, label, null, null, uniLink); + } - QueryBuilder routeStopsQueryBuilder = routeStopsDao.queryBuilder(); - routeStopsQueryBuilder.where().eq(RouteStops.ROUTE_ID_FIELD_NAME, this.id); - PreparedQuery routeStopsPreparedQuery = routeStopsQueryBuilder.prepare(); + public String toString() { + return code; + } - List routeStopsFound = routeStopsDao.query(routeStopsPreparedQuery); + /** + * Untested? + * + * @param context + * @param stop + * @return + */ + BusStop getBusStopBefore(Context context, BusStop stop, String dir) { + return moveInRoute(context, stop, dir, -1); + } - ArrayList stopIndexs = new ArrayList(); + /** + * Untested? + * + * @param context + * @param stop + * @return + */ + BusStop getStopAfter(Context context, BusStop stop, String dir) { + return moveInRoute(context, stop, dir, 1); + } - for (RouteStops routeStop : routeStopsFound) { - if (routeStop.busStop.id.equals(busStop.id)) { - stopIndexs.add(routeStop.sequence - 1); - } - } - - for (int stopIndex : stopIndexs) { - - if (moveAmount > 0) { - Log.v(TAG, "Moving forward " + moveAmount + " stops from " + busStop + " (" + 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).busStop; - - busStopDao.refresh(busStopWanted); - - Log.v(TAG, " Moving to " + busStopWanted + " (" + stopWanted + ") in route " + this); - - busStops.add(busStopWanted); - } else { - Log.v(TAG, "stopIndex " + stopIndex); - int stopWanted = stopIndex + moveAmount; - if (stopWanted < 0) { - stopWanted = routeStopsFound.size() - (Math.abs(stopWanted) % routeStopsFound.size()); - } - Log.v(TAG, "stopWanted " + stopWanted); - busStopDao.refresh(routeStopsFound.get(stopWanted).busStop); - - Log.v(TAG, - "Moving backwards " + moveAmount + " stops from " + busStop + " to " - + routeStopsFound.get(stopWanted).busStop + " in route " + this); - - busStops.add(routeStopsFound.get(stopWanted).busStop); + /** + * Untested? + * + * @param context + * @param busStop + * @param moveAmount + * @return + */ + Set moveInRoute(final Context context, final BusStop busStop, final int moveAmount) { + + Set busStops = new HashSet(); + + if (moveAmount == 0) { + busStops.add(busStop); + return busStops; } - } - return busStops; - } catch (SQLException e) { - e.printStackTrace(); - } - Log.e(TAG, "Error moving in route"); - return null; - } - - /** - * Untested? - * - * @param context - * @param busStop - * @param moveAmount - * @return - */ - BusStop moveInRoute(final Context context, final BusStop busStop, String direction, final int moveAmount) { - - if (moveAmount == 0) { - return busStop; - } + DatabaseHelper helper = OpenHelperManager.getHelper(context, DatabaseHelper.class); + + try { + Dao routeStopsDao = helper.getRouteStopsDao(); + Dao busStopDao = helper.getBusStopDao(); + + QueryBuilder routeStopsQueryBuilder = routeStopsDao.queryBuilder(); + routeStopsQueryBuilder.where().eq(RouteStops.ROUTE_ID_FIELD_NAME, this.id); + PreparedQuery routeStopsPreparedQuery = routeStopsQueryBuilder.prepare(); - DatabaseHelper helper = OpenHelperManager.getHelper(context, DatabaseHelper.class); + List routeStopsFound = routeStopsDao.query(routeStopsPreparedQuery); - if (forwardDirection != null) { + ArrayList stopIndexs = new ArrayList(); - if (direction != null) { + for (RouteStops routeStop : routeStopsFound) { + if (routeStop.busStop.id.equals(busStop.id)) { + stopIndexs.add(routeStop.sequence - 1); + } + } + + for (int stopIndex : stopIndexs) { + + if (moveAmount > 0) { + Log.v(TAG, "Moving forward " + moveAmount + " stops from " + busStop + " (" + 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).busStop; + + busStopDao.refresh(busStopWanted); + + Log.v(TAG, " Moving to " + busStopWanted + " (" + stopWanted + ") in route " + this); + + busStops.add(busStopWanted); + } else { + Log.v(TAG, "stopIndex " + stopIndex); + int stopWanted = stopIndex + moveAmount; + if (stopWanted < 0) { + stopWanted = routeStopsFound.size() - (Math.abs(stopWanted) % routeStopsFound.size()); + } + Log.v(TAG, "stopWanted " + stopWanted); + busStopDao.refresh(routeStopsFound.get(stopWanted).busStop); + + Log.v(TAG, + "Moving backwards " + moveAmount + " stops from " + busStop + " to " + + routeStopsFound.get(stopWanted).busStop + " in route " + this); + + busStops.add(routeStopsFound.get(stopWanted).busStop); + } + } - if (direction.equals("E")) - direction = "A"; // Quick hack for U1E - } else { - throw new NullPointerException("direction is null"); - } + return busStops; + } catch (SQLException e) { + e.printStackTrace(); + } + Log.e(TAG, "Error moving in route"); + return null; } - try { - Dao routeStopsDao = helper.getRouteStopsDao(); - Dao busStopDao = helper.getBusStopDao(); - - QueryBuilder routeStopsQueryBuilder = routeStopsDao.queryBuilder(); - routeStopsQueryBuilder.where().eq(RouteStops.ROUTE_ID_FIELD_NAME, this.id); - PreparedQuery routeStopsPreparedQuery = routeStopsQueryBuilder.prepare(); - - List routeStopsFound = routeStopsDao.query(routeStopsPreparedQuery); - - int stopIndex = -1; - - for (RouteStops routeStop : routeStopsFound) { - if (routeStop.busStop.id.equals(busStop.id)) { - if (stopIndex == -1) { - stopIndex = routeStop.sequence - 1; - } else { // ARGH, weird route - if (busStop.id.equals("HAA13651") && id == 327) { // U6 by Wessex Lane - if (direction.equals(forwardDirection)) { - stopIndex = 23; - } else { - stopIndex = 68; - } - } else if (busStop.id.equals("SN120134") && id == 327) { // U6 opposite the Stile - if (direction.equals(forwardDirection)) { - stopIndex = 30; - } else { - stopIndex = 59; - } - } else if (busStop.id.equals("SN120163") && id == 327) { // U6 just up past wessex lane - if (direction.equals(forwardDirection)) { - stopIndex = 22; - } else { - stopIndex = 67; - } - } else if (busStop.id.equals("SNA19482") && id == 327) { // U6 General Hosp West Door - if (moveAmount > 0) { - stopIndex = 44; - } else { - stopIndex = 43; - } - } else if (busStop.id.equals("SN120134") && id == 329) { // U2 opposite the Stile - if (direction.equals(forwardDirection)) { - stopIndex = 13; - } else { - stopIndex = 30; - } - } else if (busStop.id.equals("SN120527") && id == 329) { // U2 Civic Centre Rd os stop AO Civic - // Ctr E - if (moveAmount > 0) { - stopIndex = 0; - } else { - stopIndex = 42; - } - } else if (busStop.id.equals("SNA09298") && id == 329) { // U2 Bassett Green Rd nr Bassett Green - // Cl SE - if (moveAmount > 0) { - stopIndex = 22; - } else { - stopIndex = 21; - } - } else if (busStop.id.equals("SN120520") && id == 326) { // U1 By the station - if (direction.equals(forwardDirection)) { - stopIndex = 7; - } else { - stopIndex = 80; - } - } else if (busStop.id.equals("HA030183") && id == 326) { // U1 Up past Wessex Lane - if (direction.equals(forwardDirection)) { - stopIndex = 35; - } else { - stopIndex = 50; - } - } else if (busStop.id.equals("HA030212") && id == 326) { // U1 At Eastleigh - if (moveAmount > 0) { - stopIndex = 43; - } else { - stopIndex = 42; - } - } else if (busStop.id.equals("SN120171") && id == 354) { // U9 - if (moveAmount > 0) { - stopIndex = 0; - } else { - stopIndex = 73; - } + /** + * Untested? + * + * @param context + * @param busStop + * @param moveAmount + * @return + */ + BusStop moveInRoute(final Context context, final BusStop busStop, String direction, final int moveAmount) { + + if (moveAmount == 0) { + return busStop; + } + + DatabaseHelper helper = OpenHelperManager.getHelper(context, DatabaseHelper.class); + + if (forwardDirection != null) { + + if (direction != null) { + + if (direction.equals("E")) + direction = "A"; // Quick hack for U1E } else { - Log.e(TAG, "Error, unknown bus stop " + busStop.id + " (" + busStop.description - + ") that appears mutiple times in " + toString()); - throw new RuntimeException("Error, unknown bus stop " + busStop.id - + " that appears mutiple times in " + toString()); + throw new NullPointerException("direction is null"); } - Log.v(TAG, "Selecting " + stopIndex + " for " + busStop.id + " as direction == " + direction); - } } - } - - if (moveAmount > 0) { - Log.v(TAG, "Moving forward " + moveAmount + " stops from " + busStop + " (" + 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); + + try { + Dao routeStopsDao = helper.getRouteStopsDao(); + Dao busStopDao = helper.getBusStopDao(); + + QueryBuilder routeStopsQueryBuilder = routeStopsDao.queryBuilder(); + routeStopsQueryBuilder.where().eq(RouteStops.ROUTE_ID_FIELD_NAME, this.id); + PreparedQuery routeStopsPreparedQuery = routeStopsQueryBuilder.prepare(); + + List routeStopsFound = routeStopsDao.query(routeStopsPreparedQuery); + + int stopIndex = -1; + + for (RouteStops routeStop : routeStopsFound) { + if (routeStop.busStop.id.equals(busStop.id)) { + if (stopIndex == -1) { + stopIndex = routeStop.sequence - 1; + } else { // ARGH, weird route + if (busStop.id.equals("HAA13651") && id == 327) { // U6 + // by + // Wessex + // Lane + if (direction.equals(forwardDirection)) { + stopIndex = 23; + } else { + stopIndex = 68; + } + } else if (busStop.id.equals("SN120134") && id == 327) { // U6 + // opposite + // the + // Stile + if (direction.equals(forwardDirection)) { + stopIndex = 30; + } else { + stopIndex = 59; + } + } else if (busStop.id.equals("SN120163") && id == 327) { // U6 + // just + // up + // past + // wessex + // lane + if (direction.equals(forwardDirection)) { + stopIndex = 22; + } else { + stopIndex = 67; + } + } else if (busStop.id.equals("SNA19482") && id == 327) { // U6 + // General + // Hosp + // West + // Door + if (moveAmount > 0) { + stopIndex = 44; + } else { + stopIndex = 43; + } + } else if (busStop.id.equals("SN120134") && id == 329) { // U2 + // opposite + // the + // Stile + if (direction.equals(forwardDirection)) { + stopIndex = 13; + } else { + stopIndex = 30; + } + } else if (busStop.id.equals("SN120527") && id == 329) { // U2 + // Civic + // Centre + // Rd + // os + // stop + // AO + // Civic + // Ctr E + if (moveAmount > 0) { + stopIndex = 0; + } else { + stopIndex = 42; + } + } else if (busStop.id.equals("SNA09298") && id == 329) { // U2 + // Bassett + // Green + // Rd + // nr + // Bassett + // Green + // Cl SE + if (moveAmount > 0) { + stopIndex = 22; + } else { + stopIndex = 21; + } + } else if (busStop.id.equals("SN120520") && id == 326) { // U1 + // By + // the + // station + if (direction.equals(forwardDirection)) { + stopIndex = 7; + } else { + stopIndex = 80; + } + } else if (busStop.id.equals("HA030183") && id == 326) { // U1 + // Up + // past + // Wessex + // Lane + if (direction.equals(forwardDirection)) { + stopIndex = 35; + } else { + stopIndex = 50; + } + } else if (busStop.id.equals("HA030212") && id == 326) { // U1 + // At + // Eastleigh + if (moveAmount > 0) { + stopIndex = 43; + } else { + stopIndex = 42; + } + } else if (busStop.id.equals("SN120171") && id == 354) { // U9 + if (moveAmount > 0) { + stopIndex = 0; + } else { + stopIndex = 73; + } + } else { + Log.e(TAG, "Error, unknown bus stop " + busStop.id + " (" + busStop.description + + ") that appears mutiple times in " + toString()); + throw new RuntimeException("Error, unknown bus stop " + busStop.id + + " that appears mutiple times in " + toString()); + } + Log.v(TAG, "Selecting " + stopIndex + " for " + busStop.id + " as direction == " + direction); + } + } + } + + if (moveAmount > 0) { + Log.v(TAG, "Moving forward " + moveAmount + " stops from " + busStop + " (" + 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).busStop; + + busStopDao.refresh(busStopWanted); + + Log.v(TAG, " Moving to " + busStopWanted + " (" + stopWanted + ") in route " + this); + + return busStopWanted; + } else { + Log.v(TAG, "stopIndex " + stopIndex); + int stopWanted = stopIndex + moveAmount; + if (stopWanted < 0) { + stopWanted = routeStopsFound.size() - (Math.abs(stopWanted) % routeStopsFound.size()); + } + Log.v(TAG, "stopWanted " + stopWanted); + busStopDao.refresh(routeStopsFound.get(stopWanted).busStop); + + Log.v(TAG, + "Moving backwards " + moveAmount + " stops from " + busStop + " to " + + routeStopsFound.get(stopWanted).busStop + " in route " + this); + + return routeStopsFound.get(stopWanted).busStop; + } + + } catch (SQLException e) { + e.printStackTrace(); } - Log.v(TAG, " Stop wanted " + stopWanted); - BusStop busStopWanted = routeStopsFound.get(stopWanted).busStop; + Log.e(TAG, "Error moving in route"); + return null; + } - busStopDao.refresh(busStopWanted); + /** + * Untested? + * + * @param context + * @param busStop + * @param moveAmount + * @return + */ + List getRouteSection(final Context context, String direction) { - Log.v(TAG, " Moving to " + busStopWanted + " (" + stopWanted + ") in route " + this); + DatabaseHelper helper = OpenHelperManager.getHelper(context, DatabaseHelper.class); - return busStopWanted; - } else { - Log.v(TAG, "stopIndex " + stopIndex); - int stopWanted = stopIndex + moveAmount; - if (stopWanted < 0) { - stopWanted = routeStopsFound.size() - (Math.abs(stopWanted) % routeStopsFound.size()); + if (forwardDirection != null) { + + if (direction != null) { + + if (direction.equals("E")) + direction = "A"; // Quick hack for U1E + } else { + throw new NullPointerException("direction is null"); + } } - Log.v(TAG, "stopWanted " + stopWanted); - busStopDao.refresh(routeStopsFound.get(stopWanted).busStop); - Log.v(TAG, - "Moving backwards " + moveAmount + " stops from " + busStop + " to " - + routeStopsFound.get(stopWanted).busStop + " in route " + this); + List busStops = new ArrayList(); + + try { + + Dao routeStopsDao = helper.getRouteStopsDao(); + Dao busStopDao = helper.getBusStopDao(); + + QueryBuilder routeStopsQueryBuilder = routeStopsDao.queryBuilder(); + routeStopsQueryBuilder.where().eq(RouteStops.ROUTE_ID_FIELD_NAME, this.id); + PreparedQuery routeStopsPreparedQuery = routeStopsQueryBuilder.prepare(); + + List routeStopsFound = routeStopsDao.query(routeStopsPreparedQuery); + + int startStopSeq = -1; + int endStopSeq = -1; + + if (id == 326) { // U1 + if (direction.equals(forwardDirection)) { + startStopSeq = 1; + endStopSeq = 43; + } else if (direction.equals(reverseDirection)) { + startStopSeq = 44; + endStopSeq = 88; + } else { + Log.e(TAG, "Error, unrecognised direction " + direction); + } + } else if (id == 468) { // U1N + startStopSeq = 1; + endStopSeq = 29; + } else if (id == 329) { // U2 + if (direction.equals(forwardDirection)) { + startStopSeq = 1; + endStopSeq = 22; + } else if (direction.equals(reverseDirection)) { + startStopSeq = 23; + endStopSeq = 43; + } else { + Log.e(TAG, "Error, unrecognised direction " + direction); + } + } else if (id == 327) { // U6 + if (direction.equals(forwardDirection)) { + startStopSeq = 1; + endStopSeq = 44; + } else if (direction.equals(reverseDirection)) { + startStopSeq = 45; + endStopSeq = 93; + } else { + Log.e(TAG, "Error, unrecognised direction " + direction); + } + } else if (id == 354) { // U9 + Calendar rightNow = Calendar.getInstance(); + if (rightNow.get(Calendar.HOUR_OF_DAY) < 12) { + startStopSeq = 1; + endStopSeq = 40; // TODO: Guess, and untested + } else { + startStopSeq = 41; // TODO: Guess, and untested + endStopSeq = 74; + } + } else { + Log.e(TAG, "Error, unrecognised route " + id); + } + + for (RouteStops routeStop : routeStopsFound) { + if (routeStop.sequence >= startStopSeq && routeStop.sequence <= endStopSeq) { + busStopDao.refresh(routeStop.busStop); + busStops.add(routeStop.busStop); + } + } - return routeStopsFound.get(stopWanted).busStop; - } + return busStops; + + } catch (SQLException e) { + e.printStackTrace(); + } + Log.e(TAG, "Error moving in route"); + return null; - } catch (SQLException e) { - e.printStackTrace(); - } - Log.e(TAG, "Error moving in route"); - return null; - } - - /** - * Untested? - * - * @param context - * @param busStop - * @param moveAmount - * @return - */ - List getRouteSection(final Context context, String direction) { - - DatabaseHelper helper = OpenHelperManager.getHelper(context, DatabaseHelper.class); - - if (forwardDirection != null) { - - if (direction != null) { - - if (direction.equals("E")) - direction = "A"; // Quick hack for U1E - } else { - throw new NullPointerException("direction is null"); - } } - List busStops = new ArrayList(); + List getRouteBusStops(final Context context) { - try { + DatabaseHelper helper = OpenHelperManager.getHelper(context, DatabaseHelper.class); - Dao routeStopsDao = helper.getRouteStopsDao(); - Dao busStopDao = helper.getBusStopDao(); + List busStops = new ArrayList(); - QueryBuilder routeStopsQueryBuilder = routeStopsDao.queryBuilder(); - routeStopsQueryBuilder.where().eq(RouteStops.ROUTE_ID_FIELD_NAME, this.id); - PreparedQuery routeStopsPreparedQuery = routeStopsQueryBuilder.prepare(); + try { - List routeStopsFound = routeStopsDao.query(routeStopsPreparedQuery); + Dao routeStopsDao = helper.getRouteStopsDao(); + Dao busStopDao = helper.getBusStopDao(); - int startStopSeq = -1; - int endStopSeq = -1; + QueryBuilder routeStopsQueryBuilder = routeStopsDao.queryBuilder(); + routeStopsQueryBuilder.where().eq(RouteStops.ROUTE_ID_FIELD_NAME, this.id); + PreparedQuery routeStopsPreparedQuery = routeStopsQueryBuilder.prepare(); - if (id == 326) { // U1 - if (direction.equals(forwardDirection)) { - startStopSeq = 1; - endStopSeq = 43; - } else if (direction.equals(reverseDirection)) { - startStopSeq = 44; - endStopSeq = 88; - } else { - Log.e(TAG, "Error, unrecognised direction " + direction); - } - } else if (id == 468) { // U1N - startStopSeq = 1; - endStopSeq = 29; - } else if (id == 329) { // U2 - if (direction.equals(forwardDirection)) { - startStopSeq = 1; - endStopSeq = 22; - } else if (direction.equals(reverseDirection)) { - startStopSeq = 23; - endStopSeq = 43; - } else { - Log.e(TAG, "Error, unrecognised direction " + direction); - } - } else if (id == 327) { // U6 - if (direction.equals(forwardDirection)) { - startStopSeq = 1; - endStopSeq = 44; - } else if (direction.equals(reverseDirection)) { - startStopSeq = 45; - endStopSeq = 93; - } else { - Log.e(TAG, "Error, unrecognised direction " + direction); - } - } else if (id == 354) { // U9 - Calendar rightNow = Calendar.getInstance(); - if (rightNow.get(Calendar.HOUR_OF_DAY) < 12) { - startStopSeq = 1; - endStopSeq = 40; // TODO: Guess, and untested - } else { - startStopSeq = 41; // TODO: Guess, and untested - endStopSeq = 74; - } - } else { - Log.e(TAG, "Error, unrecognised route " + id); - } - - for (RouteStops routeStop : routeStopsFound) { - if (routeStop.sequence >= startStopSeq && routeStop.sequence <= endStopSeq) { - busStopDao.refresh(routeStop.busStop); - busStops.add(routeStop.busStop); + List routeStopsFound = routeStopsDao.query(routeStopsPreparedQuery); + + for (RouteStops routeStop : routeStopsFound) { + busStopDao.refresh(routeStop.busStop); + busStops.add(routeStop.busStop); + } + + return busStops; + } catch (SQLException e) { + e.printStackTrace(); } - } + Log.e(TAG, "Error moving in route"); + return null; - return busStops; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + id; + return result; + } - } catch (SQLException e) { - e.printStackTrace(); + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + BusRoute other = (BusRoute) obj; + if (id != other.id) + return false; + return true; } - Log.e(TAG, "Error moving in route"); - return null; - - } - - @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + id; - return result; - } - - @Override - public boolean equals(Object obj) { - if (this == obj) - return true; - if (obj == null) - return false; - if (getClass() != obj.getClass()) - return false; - BusRoute other = (BusRoute) obj; - if (id != other.id) - return false; - return true; - } } diff --git a/src/net/cbaines/suma/BusRouteActivity.java b/src/net/cbaines/suma/BusRouteActivity.java new file mode 100644 index 0000000..3670c68 --- /dev/null +++ b/src/net/cbaines/suma/BusRouteActivity.java @@ -0,0 +1,76 @@ +package net.cbaines.suma; + +import java.sql.SQLException; + +import android.content.Context; +import android.os.Bundle; +import android.util.Log; +import android.widget.ListView; +import android.widget.TextView; +import android.widget.Toast; + +import com.j256.ormlite.android.apptools.OrmLiteBaseActivity; + +public class BusRouteActivity extends OrmLiteBaseActivity implements Preferences { + final static String TAG = "BusActivity"; + + private TextView busRouteLabel; + private TextView busRouteCode; + private TextView busRouteID; + + Toast activityToast; + + private ListView busRouteView; + + private Context instance; + + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.bus_route_activity); + instance = this; + + Log.i(TAG, "getIntent().getDataString() " + getIntent().getDataString()); + + String strBusRouteID; + + if (getIntent().getDataString().startsWith("http://data")) { + + String[] uriParts = getIntent().getDataString().split("/"); + + strBusRouteID = uriParts[uriParts.length - 1].replace(".html", ""); + + } else { + + String[] uriParts = getIntent().getDataString().split("/"); + + strBusRouteID = uriParts[uriParts.length - 1]; + } + + final DatabaseHelper helper = getHelper(); + + BusRoute busRoute = null; + + try { + busRoute = helper.getBusRouteDao().queryForId(Integer.parseInt(strBusRouteID)); + + busRouteLabel = (TextView) findViewById(R.id.busRouteActivityLabel); + busRouteLabel.setText(busRoute.label); + + busRouteCode = (TextView) findViewById(R.id.busRouteActivityCode); + busRouteCode.setText(busRoute.code); + + busRouteID = (TextView) findViewById(R.id.busRouteActivityID); + busRouteID.setText(String.valueOf(busRoute.id)); + + busRouteView = (ListView) findViewById(R.id.busRouteBusStops); + + } catch (NumberFormatException e) { + e.printStackTrace(); + } catch (SQLException e) { + e.printStackTrace(); + } + + POIArrayAdapter arrayAdapter = new POIArrayAdapter(instance, busRoute.getRouteBusStops(instance)); + busRouteView.setAdapter(arrayAdapter); + } +} 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; + } } diff --git a/src/net/cbaines/suma/MapActivity.java b/src/net/cbaines/suma/MapActivity.java index 07806fa..59c8505 100644 --- a/src/net/cbaines/suma/MapActivity.java +++ b/src/net/cbaines/suma/MapActivity.java @@ -50,6 +50,7 @@ import android.content.SharedPreferences.OnSharedPreferenceChangeListener; import android.graphics.Color; import android.graphics.DashPathEffect; import android.graphics.Paint; +import android.net.Uri; import android.os.Bundle; import android.preference.PreferenceManager; import android.util.Log; @@ -70,12 +71,13 @@ import com.j256.ormlite.dao.Dao; * @author Christopher Baines * */ -public class MapActivity extends OrmLiteBaseActivity implements MapViewConstants, Runnable, RouteColorConstants, - OnItemClickListener, OnItemLongClickListener, OnSharedPreferenceChangeListener, Preferences { +public class MapActivity extends OrmLiteBaseActivity implements MapViewConstants, Runnable, + RouteColorConstants, OnItemClickListener, OnItemLongClickListener, OnSharedPreferenceChangeListener, + Preferences { /** - * Enable to use the database in the assets folder, if its not enabled, the database is built from the csv files in the assets - * folder + * Enable to use the database in the assets folder, if its not enabled, the + * database is built from the csv files in the assets folder */ private boolean useBundledDatabase = true; @@ -125,10 +127,11 @@ public class MapActivity extends OrmLiteBaseActivity implements private static final int NON_UNI_LINK_BUS_STOP_OVERLAY_RANK = 4; // -- Site Overlays - static final String[] SITE_NAMES = { "Highfield Campus", "Boldrewood Campus", "Avenue Campus", "Winchester School of Art", - "The University of Southampton Science Park", "National Oceanography Centre Campus", "Boat House", - "Southampton General Hospital", "Royal South Hants Hospital", "Belgrave Industrial Site", "Highfield Hall", - "Glen Eyre Hall", "South Hill Hall", "Chamberlain Hall", "Hartley Grove", "Bencraft Hall", "Connaught Hall", + static final String[] SITE_NAMES = { "Highfield Campus", "Boldrewood Campus", "Avenue Campus", + "Winchester School of Art", "The University of Southampton Science Park", + "National Oceanography Centre Campus", "Boat House", "Southampton General Hospital", + "Royal South Hants Hospital", "Belgrave Industrial Site", "Highfield Hall", "Glen Eyre Hall", + "South Hill Hall", "Chamberlain Hall", "Hartley Grove", "Bencraft Hall", "Connaught Hall", "Montefiore Hall", "Stoneham Hall", "Erasmus Park" }; private static final String SITE_OVERLAYS = "siteOverlays:"; @@ -166,14 +169,15 @@ public class MapActivity extends OrmLiteBaseActivity implements // Uni-Link routes static final String[] UNI_LINK_ROUTES = { "U1", "U1N", "U2", "U6", "U9" }; - static final String[] PREFERENCES_GROUPS = { BUS_STOP_OVERLAYS, BUS_ROUTE_OVERLAYS, BUILDING_OVERLAYS, SITE_OVERLAYS, - OTHER_OVERLAYS }; + static final String[] PREFERENCES_GROUPS = { BUS_STOP_OVERLAYS, BUS_ROUTE_OVERLAYS, BUILDING_OVERLAYS, + SITE_OVERLAYS, OTHER_OVERLAYS }; static final String[][] PREFERENCES_CHILDREN = { UNI_LINK_ROUTES, UNI_LINK_ROUTES, BUILDING_TYPES, SITE_NAMES, OTHER_OVERLAY_NAMES }; /** - * The toast for this activity, storing the toast centrally allows it to be changed quickly, instead of a queue building up + * The toast for this activity, storing the toast centrally allows it to be + * changed quickly, instead of a queue building up */ Toast activityToast; @@ -204,8 +208,10 @@ public class MapActivity extends OrmLiteBaseActivity implements pastOverlays = (HashMap) getLastNonConfigurationInstance(); /* - * SensorManager mSensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE); This code in the following - * constructor causes problems in some emulators, disable sensors to fix. + * SensorManager mSensorManager = (SensorManager) + * getSystemService(Context.SENSOR_SERVICE); This code in the following + * constructor causes problems in some emulators, disable sensors to + * fix. */ Log.i(TAG, "Starting creating myLocationOverlay"); myLocationOverlay = new MyLocationOverlay(instance, mapView); @@ -494,7 +500,8 @@ public class MapActivity extends OrmLiteBaseActivity implements if (scaleBarOverlay != null) { Log.v(TAG, "ScaleBarOverlay is already created"); } else { - if (pastOverlays != null && (scaleBarOverlay = (ScaleBarOverlay) pastOverlays.get(SCALE_BAR_OVERLAY)) != null) { + if (pastOverlays != null + && (scaleBarOverlay = (ScaleBarOverlay) pastOverlays.get(SCALE_BAR_OVERLAY)) != null) { Log.i(TAG, "Finished restoring utility overlays " + (System.currentTimeMillis() - startTime)); } else { scaleBarOverlay = new ScaleBarOverlay(instance); @@ -523,7 +530,8 @@ public class MapActivity extends OrmLiteBaseActivity implements private void showRouteOverlay(final BusRoute route) { new Thread(new Runnable() { public void run() { - Log.i(TAG, "Begining showing route " + route.code + " overlay at " + (System.currentTimeMillis() - startTime)); + Log.i(TAG, "Begining showing route " + route.code + " overlay at " + + (System.currentTimeMillis() - startTime)); final SharedPreferences activityPrefs = getPreferences(0); final OverlayRankComparator comparator = new OverlayRankComparator(getPreferences(0)); @@ -548,8 +556,8 @@ public class MapActivity extends OrmLiteBaseActivity implements // TODO Is this a route like U1N or, something else, // this hack works somewhat for now? - PathOverlay routeOverlayU1E = DataManager.getRoutePath(getResources().openRawResource(R.raw.u1e), - colour, mResourceProxy); + PathOverlay routeOverlayU1E = DataManager.getRoutePath( + getResources().openRawResource(R.raw.u1e), colour, mResourceProxy); routeOverlayU1E.getPaint().setAntiAlias(true); routeOverlayU1E.getPaint().setAlpha(145); routeOverlayU1E.getPaint().setStrokeWidth(12); @@ -604,7 +612,8 @@ public class MapActivity extends OrmLiteBaseActivity implements mapView.postInvalidate(); - Log.i(TAG, "Finished showing route " + route.code + " overlay at " + (System.currentTimeMillis() - startTime)); + Log.i(TAG, "Finished showing route " + route.code + " overlay at " + + (System.currentTimeMillis() - startTime)); } }).start(); } @@ -613,7 +622,8 @@ public class MapActivity extends OrmLiteBaseActivity implements new Thread(new Runnable() { public void run() { - Log.i(TAG, "Begining showing site " + site.name + " overlay at " + (System.currentTimeMillis() - startTime)); + Log.i(TAG, "Begining showing site " + site.name + " overlay at " + + (System.currentTimeMillis() - startTime)); final SharedPreferences activityPrefs = getPreferences(0); final OverlayRankComparator comparator = new OverlayRankComparator(getPreferences(0)); @@ -622,7 +632,8 @@ public class MapActivity extends OrmLiteBaseActivity implements if ((siteOverlay = siteOverlays.get(site)) != null) { } else { - if (pastOverlays != null && (siteOverlay = (PathOverlay) pastOverlays.get(SITE_OVERLAYS + site.name)) != null) { + if (pastOverlays != null + && (siteOverlay = (PathOverlay) pastOverlays.get(SITE_OVERLAYS + site.name)) != null) { Log.i(TAG, "Restored " + site.name + " site overlay"); } else { @@ -648,11 +659,13 @@ public class MapActivity extends OrmLiteBaseActivity implements } } - siteOverlay.setEnabled(activityPrefs.getBoolean(SITE_OVERLAYS + site.name, SITE_OVERLAYS_ENABLED_BY_DEFAULT)); + siteOverlay.setEnabled(activityPrefs.getBoolean(SITE_OVERLAYS + site.name, + SITE_OVERLAYS_ENABLED_BY_DEFAULT)); mapView.postInvalidate(); - Log.i(TAG, "Finished showing site " + site.name + " overlay at " + (System.currentTimeMillis() - startTime)); + Log.i(TAG, "Finished showing site " + site.name + " overlay at " + + (System.currentTimeMillis() - startTime)); } }).start(); } @@ -669,8 +682,10 @@ public class MapActivity extends OrmLiteBaseActivity implements } else { if (pastOverlays != null - && (residentialBuildingOverlay = (BuildingNumOverlay) pastOverlays.get(RESIDENTIAL_BUILDING_OVERLAY)) != null) { - nonResidentialBuildingOverlay = (BuildingNumOverlay) pastOverlays.get(NON_RESIDENTIAL_BUILDING_OVERLAY); + && (residentialBuildingOverlay = (BuildingNumOverlay) pastOverlays + .get(RESIDENTIAL_BUILDING_OVERLAY)) != null) { + nonResidentialBuildingOverlay = (BuildingNumOverlay) pastOverlays + .get(NON_RESIDENTIAL_BUILDING_OVERLAY); Log.i(TAG, "Restored building overlays"); } else { @@ -685,7 +700,8 @@ public class MapActivity extends OrmLiteBaseActivity implements buildingDao = getHelper().getBuildingDao(); - final SharedPreferences favouritesPrefs = getSharedPreferences(FAVOURITES_PREFERENCES, MODE_PRIVATE); + final SharedPreferences favouritesPrefs = getSharedPreferences(FAVOURITES_PREFERENCES, + MODE_PRIVATE); for (Building building : buildingDao) { if (building.residential == true) { @@ -723,8 +739,8 @@ public class MapActivity extends OrmLiteBaseActivity implements } } - residentialBuildingOverlay.setEnabled(activityPrefs.getBoolean(BUILDING_OVERLAYS + RESIDENTIAL_BUILDING_OVERLAY, - RESIDENTIAL_BUILDING_OVERLAY_ENABLED_BY_DEFAULT)); + residentialBuildingOverlay.setEnabled(activityPrefs.getBoolean(BUILDING_OVERLAYS + + RESIDENTIAL_BUILDING_OVERLAY, RESIDENTIAL_BUILDING_OVERLAY_ENABLED_BY_DEFAULT)); nonResidentialBuildingOverlay.setEnabled(activityPrefs.getBoolean(BUILDING_OVERLAYS + NON_RESIDENTIAL_BUILDING_OVERLAY, NON_RESIDENTIAL_BUILDING_OVERLAY_ENABLED_BY_DEFAULT)); @@ -744,11 +760,16 @@ public class MapActivity extends OrmLiteBaseActivity implements final OverlayRankComparator comparator = new OverlayRankComparator(getPreferences(0)); if (uniLinkBusStopOverlay != null) { - if (!activityPrefs.getBoolean(BUS_STOP_OVERLAYS + "U1", UNI_LINK_BUS_STOP_OVERLAY_ENABLED_BY_DEFAULT) - && !activityPrefs.getBoolean(BUS_STOP_OVERLAYS + "U1N", UNI_LINK_BUS_STOP_OVERLAY_ENABLED_BY_DEFAULT) - && !activityPrefs.getBoolean(BUS_STOP_OVERLAYS + "U2", UNI_LINK_BUS_STOP_OVERLAY_ENABLED_BY_DEFAULT) - && !activityPrefs.getBoolean(BUS_STOP_OVERLAYS + "U6", UNI_LINK_BUS_STOP_OVERLAY_ENABLED_BY_DEFAULT) - && !activityPrefs.getBoolean(BUS_STOP_OVERLAYS + "U9", UNI_LINK_BUS_STOP_OVERLAY_ENABLED_BY_DEFAULT)) { + if (!activityPrefs.getBoolean(BUS_STOP_OVERLAYS + "U1", + UNI_LINK_BUS_STOP_OVERLAY_ENABLED_BY_DEFAULT) + && !activityPrefs.getBoolean(BUS_STOP_OVERLAYS + "U1N", + UNI_LINK_BUS_STOP_OVERLAY_ENABLED_BY_DEFAULT) + && !activityPrefs.getBoolean(BUS_STOP_OVERLAYS + "U2", + UNI_LINK_BUS_STOP_OVERLAY_ENABLED_BY_DEFAULT) + && !activityPrefs.getBoolean(BUS_STOP_OVERLAYS + "U6", + UNI_LINK_BUS_STOP_OVERLAY_ENABLED_BY_DEFAULT) + && !activityPrefs.getBoolean(BUS_STOP_OVERLAYS + "U9", + UNI_LINK_BUS_STOP_OVERLAY_ENABLED_BY_DEFAULT)) { Log.i(TAG, "Uni-Link bus stop overlay not needed"); overlays.remove(UNI_LINK_BUS_STOP_OVERLAY); @@ -759,25 +780,31 @@ public class MapActivity extends OrmLiteBaseActivity implements uniLinkBusStopOverlay = null; } else { - uniLinkBusStopOverlay.setRoutes(0, - activityPrefs.getBoolean(BUS_STOP_OVERLAYS + "U1", UNI_LINK_BUS_STOP_OVERLAY_ENABLED_BY_DEFAULT)); - uniLinkBusStopOverlay.setRoutes(1, - activityPrefs.getBoolean(BUS_STOP_OVERLAYS + "U1N", UNI_LINK_BUS_STOP_OVERLAY_ENABLED_BY_DEFAULT)); - uniLinkBusStopOverlay.setRoutes(2, - activityPrefs.getBoolean(BUS_STOP_OVERLAYS + "U2", UNI_LINK_BUS_STOP_OVERLAY_ENABLED_BY_DEFAULT)); - uniLinkBusStopOverlay.setRoutes(3, - activityPrefs.getBoolean(BUS_STOP_OVERLAYS + "U6", UNI_LINK_BUS_STOP_OVERLAY_ENABLED_BY_DEFAULT)); - uniLinkBusStopOverlay.setRoutes(4, - activityPrefs.getBoolean(BUS_STOP_OVERLAYS + "U9", UNI_LINK_BUS_STOP_OVERLAY_ENABLED_BY_DEFAULT)); + uniLinkBusStopOverlay.setRoutes(0, activityPrefs.getBoolean(BUS_STOP_OVERLAYS + "U1", + UNI_LINK_BUS_STOP_OVERLAY_ENABLED_BY_DEFAULT)); + uniLinkBusStopOverlay.setRoutes(1, activityPrefs.getBoolean(BUS_STOP_OVERLAYS + "U1N", + UNI_LINK_BUS_STOP_OVERLAY_ENABLED_BY_DEFAULT)); + uniLinkBusStopOverlay.setRoutes(2, activityPrefs.getBoolean(BUS_STOP_OVERLAYS + "U2", + UNI_LINK_BUS_STOP_OVERLAY_ENABLED_BY_DEFAULT)); + uniLinkBusStopOverlay.setRoutes(3, activityPrefs.getBoolean(BUS_STOP_OVERLAYS + "U6", + UNI_LINK_BUS_STOP_OVERLAY_ENABLED_BY_DEFAULT)); + uniLinkBusStopOverlay.setRoutes(4, activityPrefs.getBoolean(BUS_STOP_OVERLAYS + "U9", + UNI_LINK_BUS_STOP_OVERLAY_ENABLED_BY_DEFAULT)); } } else { - if (activityPrefs.getBoolean(BUS_STOP_OVERLAYS + "U1", UNI_LINK_BUS_STOP_OVERLAY_ENABLED_BY_DEFAULT) - || activityPrefs.getBoolean(BUS_STOP_OVERLAYS + "U1N", UNI_LINK_BUS_STOP_OVERLAY_ENABLED_BY_DEFAULT) - || activityPrefs.getBoolean(BUS_STOP_OVERLAYS + "U2", UNI_LINK_BUS_STOP_OVERLAY_ENABLED_BY_DEFAULT) - || activityPrefs.getBoolean(BUS_STOP_OVERLAYS + "U6", UNI_LINK_BUS_STOP_OVERLAY_ENABLED_BY_DEFAULT) - || activityPrefs.getBoolean(BUS_STOP_OVERLAYS + "U9", UNI_LINK_BUS_STOP_OVERLAY_ENABLED_BY_DEFAULT)) { + if (activityPrefs + .getBoolean(BUS_STOP_OVERLAYS + "U1", UNI_LINK_BUS_STOP_OVERLAY_ENABLED_BY_DEFAULT) + || activityPrefs.getBoolean(BUS_STOP_OVERLAYS + "U1N", + UNI_LINK_BUS_STOP_OVERLAY_ENABLED_BY_DEFAULT) + || activityPrefs.getBoolean(BUS_STOP_OVERLAYS + "U2", + UNI_LINK_BUS_STOP_OVERLAY_ENABLED_BY_DEFAULT) + || activityPrefs.getBoolean(BUS_STOP_OVERLAYS + "U6", + UNI_LINK_BUS_STOP_OVERLAY_ENABLED_BY_DEFAULT) + || activityPrefs.getBoolean(BUS_STOP_OVERLAYS + "U9", + UNI_LINK_BUS_STOP_OVERLAY_ENABLED_BY_DEFAULT)) { if (pastOverlays != null - && (uniLinkBusStopOverlay = (BusStopOverlay) pastOverlays.get(UNI_LINK_BUS_STOP_OVERLAY)) != null) { + && (uniLinkBusStopOverlay = (BusStopOverlay) pastOverlays + .get(UNI_LINK_BUS_STOP_OVERLAY)) != null) { Log.i(TAG, "Restored Uni-Link bus stop overlay"); } else { @@ -795,16 +822,16 @@ public class MapActivity extends OrmLiteBaseActivity implements } } - uniLinkBusStopOverlay.setRoutes(0, - activityPrefs.getBoolean(BUS_STOP_OVERLAYS + "U1", UNI_LINK_BUS_STOP_OVERLAY_ENABLED_BY_DEFAULT)); - uniLinkBusStopOverlay.setRoutes(1, - activityPrefs.getBoolean(BUS_STOP_OVERLAYS + "U1N", UNI_LINK_BUS_STOP_OVERLAY_ENABLED_BY_DEFAULT)); - uniLinkBusStopOverlay.setRoutes(2, - activityPrefs.getBoolean(BUS_STOP_OVERLAYS + "U2", UNI_LINK_BUS_STOP_OVERLAY_ENABLED_BY_DEFAULT)); - uniLinkBusStopOverlay.setRoutes(3, - activityPrefs.getBoolean(BUS_STOP_OVERLAYS + "U6", UNI_LINK_BUS_STOP_OVERLAY_ENABLED_BY_DEFAULT)); - uniLinkBusStopOverlay.setRoutes(4, - activityPrefs.getBoolean(BUS_STOP_OVERLAYS + "U9", UNI_LINK_BUS_STOP_OVERLAY_ENABLED_BY_DEFAULT)); + uniLinkBusStopOverlay.setRoutes(0, activityPrefs.getBoolean(BUS_STOP_OVERLAYS + "U1", + UNI_LINK_BUS_STOP_OVERLAY_ENABLED_BY_DEFAULT)); + uniLinkBusStopOverlay.setRoutes(1, activityPrefs.getBoolean(BUS_STOP_OVERLAYS + "U1N", + UNI_LINK_BUS_STOP_OVERLAY_ENABLED_BY_DEFAULT)); + uniLinkBusStopOverlay.setRoutes(2, activityPrefs.getBoolean(BUS_STOP_OVERLAYS + "U2", + UNI_LINK_BUS_STOP_OVERLAY_ENABLED_BY_DEFAULT)); + uniLinkBusStopOverlay.setRoutes(3, activityPrefs.getBoolean(BUS_STOP_OVERLAYS + "U6", + UNI_LINK_BUS_STOP_OVERLAY_ENABLED_BY_DEFAULT)); + uniLinkBusStopOverlay.setRoutes(4, activityPrefs.getBoolean(BUS_STOP_OVERLAYS + "U9", + UNI_LINK_BUS_STOP_OVERLAY_ENABLED_BY_DEFAULT)); overlays.put(UNI_LINK_BUS_STOP_OVERLAY, uniLinkBusStopOverlay); @@ -827,7 +854,8 @@ public class MapActivity extends OrmLiteBaseActivity implements private void showNonUniLinkBusStopOverlay() { new Thread(new Runnable() { public void run() { - Log.i(TAG, "Begining showing non uni link bus stop overlays at " + (System.currentTimeMillis() - startTime)); + Log.i(TAG, "Begining showing non uni link bus stop overlays at " + + (System.currentTimeMillis() - startTime)); // final SharedPreferences activityPrefs = getPreferences(0); final SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(instance); @@ -844,12 +872,14 @@ public class MapActivity extends OrmLiteBaseActivity implements } else if (sharedPrefs.getBoolean(NON_UNI_LINK_BUS_STOPS_OVERLAY, NON_UNI_LINK_BUS_STOP_OVERLAY_ENABLED_BY_DEFAULT)) { if (pastOverlays != null - && (nonUniLinkBusStopOverlay = (BusStopOverlay) pastOverlays.get(NON_UNI_LINK_BUS_STOPS_OVERLAY)) != null) { + && (nonUniLinkBusStopOverlay = (BusStopOverlay) pastOverlays + .get(NON_UNI_LINK_BUS_STOPS_OVERLAY)) != null) { Log.i(TAG, "Restored non Uni-Link bus stop overlays"); } else { try { List busStops; - Log.v(TAG, "Begin fetching non Uni-Link BusStops at " + (System.currentTimeMillis() - startTime)); + Log.v(TAG, "Begin fetching non Uni-Link BusStops at " + + (System.currentTimeMillis() - startTime)); busStops = getHelper().getBusStopDao().queryForEq(BusStop.UNI_LINK_FIELD_NAME, false); @@ -879,7 +909,8 @@ public class MapActivity extends OrmLiteBaseActivity implements mapView.postInvalidate(); - Log.i(TAG, "Finished showing non Uni-Link bus stop overlays at " + (System.currentTimeMillis() - startTime)); + Log.i(TAG, "Finished showing non Uni-Link bus stop overlays at " + + (System.currentTimeMillis() - startTime)); } }).start(); } @@ -941,8 +972,9 @@ public class MapActivity extends OrmLiteBaseActivity implements }; AlertDialog.Builder builder = new AlertDialog.Builder(this); - builder.setMessage("GPS is not enabled, do you wish to enable it?").setPositiveButton("Yes", dialogClickListener) - .setNegativeButton("No", dialogClickListener).show(); + builder.setMessage("GPS is not enabled, do you wish to enable it?") + .setPositiveButton("Yes", dialogClickListener).setNegativeButton("No", dialogClickListener) + .show(); } return true; @@ -1060,9 +1092,11 @@ public class MapActivity extends OrmLiteBaseActivity implements } /* - * public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition, long id) { + * public boolean onChildClick(ExpandableListView parent, View v, int + * groupPosition, int childPosition, long id) { * - * mapView.post(new Runnable() { public void run() { // updateEnabledOverlays(); TODO Fix whatever this did? + * mapView.post(new Runnable() { public void run() { // + * updateEnabledOverlays(); TODO Fix whatever this did? * mapView.invalidate(); } }); * * return true; } @@ -1163,6 +1197,20 @@ public class MapActivity extends OrmLiteBaseActivity implements return true; + } else if (poi.type == POI.BUILDING) { + Building building = (Building) poi; + + Log.i(TAG, "Pressed " + building.id); + + 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); + startActivity(buildingIntent); + + return true; + } else { myLocationOverlay.disableFollowLocation(); diff --git a/src/net/cbaines/suma/POIArrayAdapter.java b/src/net/cbaines/suma/POIArrayAdapter.java index e35acf4..f9b5271 100644 --- a/src/net/cbaines/suma/POIArrayAdapter.java +++ b/src/net/cbaines/suma/POIArrayAdapter.java @@ -21,7 +21,6 @@ package net.cbaines.suma; import java.util.List; - import android.content.Context; import android.view.View; import android.view.ViewGroup; @@ -29,51 +28,52 @@ import android.widget.BaseAdapter; public class POIArrayAdapter extends BaseAdapter { - private final Context context; - private final List POIs; - - public POIArrayAdapter(Context context, List pois) { - this.context = context; - this.POIs = pois; - } + private final Context context; + private final List POIs; - public View getView(int position, View convertView, ViewGroup parent) { - POIView poiView; - if (convertView == null) { - if (POIs.get(position).distTo == -1) { - poiView = new POIView(context, POIs.get(position)); - } else { - poiView = new POIView(context, POIs.get(position), POIs.get(position).distTo); - } - } else { - poiView = (POIView) convertView; - if (POIs.get(position).distTo == -1) { - poiView = new POIView(context, POIs.get(position)); - } else { - poiView = new POIView(context, POIs.get(position), POIs.get(position).distTo); - } + public POIArrayAdapter(Context context, List pois) { + this.context = context; + this.POIs = pois; } - return poiView; - } + public View getView(int position, View convertView, ViewGroup parent) { + POIView poiView; + POI poi = POIs.get(position); + if (convertView == null) { + if (poi.distTo == -1) { + poiView = new POIView(context, poi); + } else { + poiView = new POIView(context, poi, poi.distTo); + } + } else { + poiView = (POIView) convertView; + if (((POI) POIs.get(position)).distTo == -1) { + poiView = new POIView(context, poi); + } else { + poiView = new POIView(context, poi, poi.distTo); + } + } - public int getCount() { - return POIs.size(); - } + return poiView; + } - public Object getItem(int position) { - return position; - } + public int getCount() { + return POIs.size(); + } - public POI getPOIItem(int position) { - return POIs.get(position); - } + public Object getItem(int position) { + return position; + } - public long getItemId(int position) { - return position; - } + public POI getPOIItem(int position) { + return (POI) POIs.get(position); + } + + public long getItemId(int position) { + return position; + } - public String getItemStringId(int position) { - return POIs.get(position).id; - } + public String getItemStringId(int position) { + return ((POI) POIs.get(position)).id; + } } \ No newline at end of file diff --git a/src/net/cbaines/suma/POIDialog.java b/src/net/cbaines/suma/POIDialog.java index 20304bb..dd871fd 100644 --- a/src/net/cbaines/suma/POIDialog.java +++ b/src/net/cbaines/suma/POIDialog.java @@ -31,62 +31,62 @@ import android.widget.TextView; public class POIDialog extends Dialog { - // private static final String TAG = "POIDialog"; - private ListView listItems; + // private static final String TAG = "POIDialog"; + private ListView listItems; - private final Context context; + private final Context context; - private final TextView message; + private final TextView message; - protected POIArrayAdapter adapter; + protected POIArrayAdapter adapter; - public POIDialog(Context context) { - super(context); + public POIDialog(Context context) { + super(context); - this.context = context; + this.context = context; - setContentView(R.layout.poi_dialog); + setContentView(R.layout.poi_dialog); - message = (TextView) findViewById(R.id.favouriteDialogMessage); - listItems = (ListView) findViewById(R.id.favouriteListItems); + message = (TextView) findViewById(R.id.favouriteDialogMessage); + listItems = (ListView) findViewById(R.id.favouriteListItems); - } + } - void setMessage(final String text) { - message.post(new Runnable() { - public void run() { - if (text == null || text.length() == 0) { - message.setVisibility(View.GONE); - } else { - message.setText(text); - message.setVisibility(View.VISIBLE); - } - } - }); - } + void setMessage(final String text) { + message.post(new Runnable() { + public void run() { + if (text == null || text.length() == 0) { + message.setVisibility(View.GONE); + } else { + message.setText(text); + message.setVisibility(View.VISIBLE); + } + } + }); + } - void setItems(final List items) { - listItems.post(new Runnable() { - public void run() { - if (items != null) { - adapter = new POIArrayAdapter(context, items); + void setItems(final List items) { + listItems.post(new Runnable() { + public void run() { + if (items != null) { + adapter = new POIArrayAdapter(context, items); - listItems.setVisibility(View.VISIBLE); - listItems.setAdapter(adapter); - } else { - listItems.setVisibility(View.GONE); - } - } - }); - } + listItems.setVisibility(View.VISIBLE); + listItems.setAdapter(adapter); + } else { + listItems.setVisibility(View.GONE); + } + } + }); + } - void setOnItemClickListener(OnItemClickListener item) { - listItems.setOnItemClickListener(item); + void setOnItemClickListener(OnItemClickListener item) { + listItems.setOnItemClickListener(item); - } + } - void setOnItemLongClickListener(OnItemLongClickListener item) { - listItems.setOnItemLongClickListener(item); - } + void setOnItemLongClickListener(OnItemLongClickListener item) { + listItems.setOnItemLongClickListener(item); + } } diff --git a/src/net/cbaines/suma/POIView.java b/src/net/cbaines/suma/POIView.java index fb8a6c6..b27b4f3 100644 --- a/src/net/cbaines/suma/POIView.java +++ b/src/net/cbaines/suma/POIView.java @@ -29,96 +29,97 @@ import android.widget.TextView; public class POIView extends LinearLayout { - private final static String TAG = "POIView"; + private final static String TAG = "POIView"; - private final TextView name; - private final TextView dist; - private final BusRoutesView routes; + private final TextView name; + private final TextView dist; + private final BusRoutesView routes; - private LayoutParams textLayoutParams; + private LayoutParams textLayoutParams; - final int width; + final int width; - public POIView(Context context, POI poi) { - this(context, poi, -1); - } + public POIView(Context context, POI poi) { + this(context, poi, -1); + } - public POIView(Context context, POI poi, int distInM) { - super(context); + public POIView(Context context, POI poi, int distInM) { + super(context); - Display display = ((WindowManager) context.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay(); - width = display.getWidth(); - // int height = display.getHeight(); + Display display = ((WindowManager) context.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay(); + width = display.getWidth(); + // int height = display.getHeight(); - this.setOrientation(HORIZONTAL); + this.setOrientation(HORIZONTAL); - name = new TextView(context); - name.setTextSize(16f); - name.setGravity(Gravity.LEFT); + name = new TextView(context); + name.setTextSize(16f); + name.setGravity(Gravity.LEFT); - dist = new TextView(context); - dist.setTextSize(16f); - dist.setGravity(Gravity.RIGHT); + dist = new TextView(context); + dist.setTextSize(16f); + dist.setGravity(Gravity.RIGHT); - routes = new BusRoutesView(context, (byte) 0); + routes = new BusRoutesView(context, (byte) 0); - textLayoutParams = new LayoutParams(width - (width / 4), LayoutParams.WRAP_CONTENT); - LayoutParams distLayoutParams = new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT); - LayoutParams busRouteLayoutParams = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); + textLayoutParams = new LayoutParams(width - (width / 4), LayoutParams.WRAP_CONTENT); + LayoutParams distLayoutParams = new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT); + LayoutParams busRouteLayoutParams = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); - setPOIAndDist(poi, distInM); + setPOIAndDist(poi, distInM); - addView(routes, busRouteLayoutParams); - addView(name, textLayoutParams); - addView(dist, distLayoutParams); - } + addView(routes, busRouteLayoutParams); + addView(name, textLayoutParams); + addView(dist, distLayoutParams); + } - public void setPOI(POI poi) { - setPOIAndDist(poi, -1); - } + public void setPOI(POI poi) { + setPOIAndDist(poi, -1); + } - public void setPOIAndDist(POI poi, int distInM) { + public void setPOIAndDist(POI poi, int distInM) { - // Log.i(TAG, "Looking at poi " + poi.id); + // Log.i(TAG, "Looking at poi " + poi.id); - if (poi.type == POI.BUILDING) { - Building building = (Building) poi; - // Log.i(TAG, "Its a building of name " + building.name); + if (poi.type == POI.BUILDING) { + Building building = (Building) poi; + // Log.i(TAG, "Its a building of name " + building.name); - name.setText(building.name + " (" + building.id + ")"); - } else if (poi.type == POI.BUS_STOP) { + name.setText(building.name + " (" + building.id + ")"); + } else if (poi.type == POI.BUS_STOP) { - BusStop busStop = (BusStop) poi; - // Log.i(TAG, "Its a bus stop of description " + busStop.description); + BusStop busStop = (BusStop) poi; + // Log.i(TAG, "Its a bus stop of description " + + // busStop.description); - name.setText(busStop.description + " (" + busStop.id + ")"); + name.setText(busStop.description + " (" + busStop.id + ")"); - routes.setRoutes(busStop.routes); + routes.setRoutes(busStop.routes); - } else if (poi.type == POI.SITE) { + } else if (poi.type == POI.SITE) { - Site site = (Site) poi; - // Log.i(TAG, "Its a site of name " + site.name); + Site site = (Site) poi; + // Log.i(TAG, "Its a site of name " + site.name); - name.setText(site.name + " (" + site.id + ")"); - } else { - Log.w(TAG, "Cant identify " + poi.type); + name.setText(site.name + " (" + site.id + ")"); + } else { + Log.w(TAG, "Cant identify " + poi.type); - name.setText(poi.id); - } + name.setText(poi.id); + } + + textLayoutParams = new LayoutParams(width - (width / 4), LayoutParams.WRAP_CONTENT); - textLayoutParams = new LayoutParams(width - (width / 4), LayoutParams.WRAP_CONTENT); - - if (distInM != -1) { - textLayoutParams.width = width - (width / 4); - name.requestLayout(); - dist.setText(String.valueOf(distInM) + "m"); - } else { - textLayoutParams.width = LayoutParams.FILL_PARENT; - name.requestLayout(); - dist.setText(""); - // Log.w("POIView", "No dist avalible for S" + poi.id); + if (distInM != -1) { + textLayoutParams.width = width - (width / 4); + name.requestLayout(); + dist.setText(String.valueOf(distInM) + "m"); + } else { + textLayoutParams.width = LayoutParams.FILL_PARENT; + name.requestLayout(); + dist.setText(""); + // Log.w("POIView", "No dist avalible for S" + poi.id); + } } - } } \ No newline at end of file diff --git a/src/net/cbaines/suma/Waypoint.java b/src/net/cbaines/suma/Waypoint.java deleted file mode 100644 index d56c05d..0000000 --- a/src/net/cbaines/suma/Waypoint.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * 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 org.osmdroid.util.GeoPoint; - -import com.j256.ormlite.table.DatabaseTable; - -@DatabaseTable(tableName = "routeWaypoints") -public class Waypoint extends POI { - - Waypoint() { - } - - int sequence; - - String route; - - public Waypoint(int sequence, GeoPoint point) { - super(point.toDoubleString() + ":" + sequence, point); - this.type = POI.WAYPOINT; - this.sequence = sequence; - } - -} -- cgit v1.2.3 From ed7638698d439d75ada5120121a137f8e6f09bf8 Mon Sep 17 00:00:00 2001 From: Christopher Baines Date: Tue, 28 Feb 2012 15:29:26 +0000 Subject: Improved URI stuff, and formating. --- AndroidManifest.xml | 8 + src/net/cbaines/suma/AboutActivity.java | 7 +- src/net/cbaines/suma/Building.java | 56 +-- src/net/cbaines/suma/BuildingActivity.java | 10 +- src/net/cbaines/suma/BuildingNumOverlay.java | 49 +- src/net/cbaines/suma/BusRoutesView.java | 218 ++++----- src/net/cbaines/suma/BusSpecificStopView.java | 66 +-- .../cbaines/suma/BusSpecificTimetableAdapter.java | 114 ++--- src/net/cbaines/suma/BusStop.java | 69 +-- src/net/cbaines/suma/BusStopActivity.java | 30 +- src/net/cbaines/suma/BusStopView.java | 12 +- src/net/cbaines/suma/DataHandler.java | 147 +++--- src/net/cbaines/suma/DataManager.java | 97 ++-- src/net/cbaines/suma/DatabaseConfigUtil.java | 6 +- src/net/cbaines/suma/DatabaseHelper.java | 379 ++++++++------- src/net/cbaines/suma/DonateDialog.java | 7 +- src/net/cbaines/suma/FindActivity.java | 538 ++++++++++----------- src/net/cbaines/suma/MapActivity.java | 46 +- src/net/cbaines/suma/POIDistanceComparator.java | 40 +- src/net/cbaines/suma/Polygon.java | 36 +- src/net/cbaines/suma/Preferences.java | 20 +- src/net/cbaines/suma/PreferencesActivity.java | 40 +- src/net/cbaines/suma/RouteColorConstants.java | 10 +- src/net/cbaines/suma/RouteOverlayItem.java | 11 +- src/net/cbaines/suma/RouteStops.java | 63 +-- src/net/cbaines/suma/Site.java | 36 +- src/net/cbaines/suma/Stop.java | 239 ++++----- src/net/cbaines/suma/StopView.java | 81 ++-- src/net/cbaines/suma/StringDistanceComparator.java | 163 +++---- src/net/cbaines/suma/Timetable.java | 64 +-- src/net/cbaines/suma/TimetableAdapter.java | 100 ++-- src/net/cbaines/suma/Util.java | 108 ++--- src/net/cbaines/suma/ViewDialog.java | 16 +- 33 files changed, 1437 insertions(+), 1449 deletions(-) diff --git a/AndroidManifest.xml b/AndroidManifest.xml index 1c046f6..1eb5c8a 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -41,6 +41,14 @@ android:host="opendatamap.ecs.soton.ac.uk" android:scheme="http" /> + + + + + + + +
diff --git a/src/net/cbaines/suma/AboutActivity.java b/src/net/cbaines/suma/AboutActivity.java index d245352..74e0249 100644 --- a/src/net/cbaines/suma/AboutActivity.java +++ b/src/net/cbaines/suma/AboutActivity.java @@ -59,7 +59,8 @@ public class AboutActivity extends PreferenceActivity { if (KEY_ABOUT_LICENSE.equals(key)) { startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://www.gnu.org/licenses/gpl-2.0.html"))); } else if (KEY_ABOUT_PROJECT.equals(key)) { - startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://github.com/cbaines/SouthamptonUniversityMap"))); + startActivity(new Intent(Intent.ACTION_VIEW, + Uri.parse("https://github.com/cbaines/SouthamptonUniversityMap"))); } else if (KEY_ABOUT_DEVELOPER.equals(key)) { Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND); emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[] { "cbaines8@gmail.com" }); @@ -71,8 +72,8 @@ public class AboutActivity extends PreferenceActivity { } else if (KEY_ABOUT_ANDROID_MARKET.equals(key)) { startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=net.cbaines.suma"))); } else if (KEY_ABOUT_MAP_DATA.equals(key)) { - startActivity(new Intent(Intent.ACTION_VIEW, - Uri.parse(String.format("http://data.southampton.ac.uk/places.html")))); + startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(String + .format("http://data.southampton.ac.uk/places.html")))); } else if (KEY_ABOUT_MAP_ICONS.equals(key)) { startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://mapicons.nicolasmollet.com/"))); } else if (KEY_ABOUT_OSM_MAP.equals(key)) { diff --git a/src/net/cbaines/suma/Building.java b/src/net/cbaines/suma/Building.java index 8747a78..84c9b6c 100644 --- a/src/net/cbaines/suma/Building.java +++ b/src/net/cbaines/suma/Building.java @@ -27,38 +27,38 @@ import com.j256.ormlite.table.DatabaseTable; @DatabaseTable(tableName = "buildings") public class Building extends POI { - public static final String NAME_FIELD_NAME = "name"; - public static final String RESIDENTIAL_FIELD_NAME = "residential"; - public static final String OUTLINE_FIELD_NAME = "outline"; + public static final String NAME_FIELD_NAME = "name"; + public static final String RESIDENTIAL_FIELD_NAME = "residential"; + public static final String OUTLINE_FIELD_NAME = "outline"; - @DatabaseField(canBeNull = false) - public String name; - @DatabaseField(canBeNull = false) - public boolean residential; - @DatabaseField(dataType = DataType.SERIALIZABLE, canBeNull = true) - Polygon outline; + @DatabaseField(canBeNull = false) + public String name; + @DatabaseField(canBeNull = false) + public boolean residential; + @DatabaseField(dataType = DataType.SERIALIZABLE, canBeNull = true) + Polygon outline; - Building(String id, GeoPoint point, boolean residential, String name, Polygon outline) { - super(id, point); - this.residential = residential; - this.name = name; - this.outline = outline; - this.type = POI.BUILDING; - } + Building(String id, GeoPoint point, boolean residential, String name, Polygon outline) { + super(id, point); + this.residential = residential; + this.name = name; + this.outline = outline; + this.type = POI.BUILDING; + } - public Building(String id, GeoPoint point, boolean residential, String name) { - this(id, point, residential, name, null); - } + public Building(String id, GeoPoint point, boolean residential, String name) { + this(id, point, residential, name, null); + } - Building(String id, GeoPoint point, boolean residential) { - this(id, point, residential, ""); - } + Building(String id, GeoPoint point, boolean residential) { + this(id, point, residential, ""); + } - Building() { - this.type = POI.BUILDING; - } + Building() { + this.type = POI.BUILDING; + } - public String toString() { - return name + " (" + id + ")"; - } + public String toString() { + return name + " (" + id + ")"; + } } diff --git a/src/net/cbaines/suma/BuildingActivity.java b/src/net/cbaines/suma/BuildingActivity.java index fdfa49d..d9baa95 100644 --- a/src/net/cbaines/suma/BuildingActivity.java +++ b/src/net/cbaines/suma/BuildingActivity.java @@ -43,7 +43,8 @@ import android.widget.TextView; import com.j256.ormlite.android.apptools.OrmLiteBaseActivity; import com.j256.ormlite.dao.Dao; -public class BuildingActivity extends OrmLiteBaseActivity implements OnCheckedChangeListener, Preferences { +public class BuildingActivity extends OrmLiteBaseActivity implements OnCheckedChangeListener, + Preferences { final static String TAG = "BusTimeActivity"; @@ -63,25 +64,20 @@ public class BuildingActivity extends OrmLiteBaseActivity implem setContentView(R.layout.building_activity); instance = this; - String ID; + String ID; // The identifier of the Building 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); favouritesCheckBox = (CheckBox) findViewById(R.id.buildingActivityFavouriteCheckBox); diff --git a/src/net/cbaines/suma/BuildingNumOverlay.java b/src/net/cbaines/suma/BuildingNumOverlay.java index 87d4156..a4cf556 100644 --- a/src/net/cbaines/suma/BuildingNumOverlay.java +++ b/src/net/cbaines/suma/BuildingNumOverlay.java @@ -88,24 +88,33 @@ public class BuildingNumOverlay extends Overlay implements Preferences, OnShared } /** - * Draw a marker on each of our items. populate() must have been called first.
+ * Draw a marker on each of our items. populate() must have been called + * first.
*
- * The marker will be drawn twice for each Item in the Overlay--once in the shadow phase, skewed and darkened, then again in - * the non-shadow phase. The bottom-center of the marker will be aligned with the geographical coordinates of the Item.
+ * The marker will be drawn twice for each Item in the Overlay--once in the + * shadow phase, skewed and darkened, then again in the non-shadow phase. + * The bottom-center of the marker will be aligned with the geographical + * coordinates of the Item.
*
- * The order of drawing may be changed by overriding the getIndexToDraw(int) method. An item may provide an alternate marker - * via its OverlayItem.getMarker(int) method. If that method returns null, the default marker is used.
+ * The order of drawing may be changed by overriding the getIndexToDraw(int) + * method. An item may provide an alternate marker via its + * OverlayItem.getMarker(int) method. If that method returns null, the + * default marker is used.
*
- * The focused item is always drawn last, which puts it visually on top of the other items.
+ * The focused item is always drawn last, which puts it visually on top of + * the other items.
* * @param canvas - * the Canvas upon which to draw. Note that this may already have a transformation applied, so be sure to leave it - * the way you found it + * the Canvas upon which to draw. Note that this may already have + * a transformation applied, so be sure to leave it the way you + * found it * @param mapView - * the MapView that requested the draw. Use MapView.getProjection() to convert between on-screen pixels and - * latitude/longitude pairs + * the MapView that requested the draw. Use + * MapView.getProjection() to convert between on-screen pixels + * and latitude/longitude pairs * @param shadow - * if true, draw the shadow layer. If false, draw the overlay contents. + * if true, draw the shadow layer. If false, draw the overlay + * contents. */ @Override public void draw(final Canvas canvas, final MapView mapView, final boolean shadow) { @@ -129,7 +138,8 @@ public class BuildingNumOverlay extends Overlay implements Preferences, OnShared final SharedPreferences favouritesPrefs = context.getSharedPreferences(FAVOURITES_PREFERENCES, 0); /* - * Draw in backward cycle, so the items with the least index are on the front. + * Draw in backward cycle, so the items with the least index are on the + * front. */ for (Iterator buildingIter = buildings.iterator(); buildingIter.hasNext();) { final Building building = buildingIter.next(); @@ -200,7 +210,8 @@ public class BuildingNumOverlay extends Overlay implements Preferences, OnShared Log.v(TAG, "building Pressed " + building.id); if (context.activityToast == null) { - context.activityToast = Toast.makeText(context, building.name + " (" + building.id + ")", Toast.LENGTH_SHORT); + context.activityToast = Toast.makeText(context, building.name + " (" + building.id + ")", + Toast.LENGTH_SHORT); } else { context.activityToast.setDuration(Toast.LENGTH_SHORT); context.activityToast.setText(building.name + " (" + building.id + ")"); @@ -252,7 +263,8 @@ public class BuildingNumOverlay extends Overlay implements Preferences, OnShared favouritesPrefs.edit().remove(building.id).commit(); if (context.activityToast == null) { - context.activityToast = Toast.makeText(context, building.id + " removed from favourites", Toast.LENGTH_SHORT); + context.activityToast = Toast.makeText(context, building.id + " removed from favourites", + Toast.LENGTH_SHORT); } else { context.activityToast.setDuration(Toast.LENGTH_SHORT); context.activityToast.setText(building.id + " removed from favourites"); @@ -261,7 +273,8 @@ public class BuildingNumOverlay extends Overlay implements Preferences, OnShared } else { if (context.activityToast == null) { - context.activityToast = Toast.makeText(context, building.id + " made a favourite", Toast.LENGTH_SHORT); + context.activityToast = Toast.makeText(context, building.id + " made a favourite", + Toast.LENGTH_SHORT); } else { context.activityToast.setDuration(Toast.LENGTH_SHORT); context.activityToast.setText(building.id + " made a favourite"); @@ -271,7 +284,8 @@ public class BuildingNumOverlay extends Overlay implements Preferences, OnShared favouritesPrefs.edit().putBoolean(building.id, true).commit(); } - Collections.sort(buildings, new POIFavouriteComparator(context.getSharedPreferences(FAVOURITES_PREFERENCES, 0))); + Collections.sort(buildings, + new POIFavouriteComparator(context.getSharedPreferences(FAVOURITES_PREFERENCES, 0))); mapView.invalidate(); @@ -304,7 +318,8 @@ public class BuildingNumOverlay extends Overlay implements Preferences, OnShared public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) { Log.i(TAG, "Got a favourites change in the BuildingNumOverlay for key " + key); - Collections.sort(buildings, new POIFavouriteComparator(context.getSharedPreferences(FAVOURITES_PREFERENCES, 0))); + Collections + .sort(buildings, new POIFavouriteComparator(context.getSharedPreferences(FAVOURITES_PREFERENCES, 0))); } } diff --git a/src/net/cbaines/suma/BusRoutesView.java b/src/net/cbaines/suma/BusRoutesView.java index 32226b0..1ec70c7 100644 --- a/src/net/cbaines/suma/BusRoutesView.java +++ b/src/net/cbaines/suma/BusRoutesView.java @@ -26,115 +26,115 @@ import android.widget.TextView; public class BusRoutesView extends LinearLayout { - private TextView u1; - private TextView u1n; - private TextView u2; - private TextView u6; - private TextView u9; - - private LinearLayout bottomRow; - private LinearLayout topRow; - - public BusRoutesView(Context context, final byte routes) { - super(context); - - u1 = new TextView(context); - u1.setText(R.string.U1); - u1.setBackgroundResource(R.drawable.u1_back_selected); - u1.setPadding(5, 1, 5, 1); - - u1n = new TextView(context); - u1n.setText(R.string.U1N); - u1n.setBackgroundResource(R.drawable.u1n_back_selected); - u1n.setPadding(5, 1, 5, 1); - - u2 = new TextView(context); - u2.setText(R.string.U2); - u2.setBackgroundResource(R.drawable.u2_back_selected); - u2.setPadding(5, 1, 5, 1); - - u6 = new TextView(context); - u6.setText(R.string.U6); - u6.setBackgroundResource(R.drawable.u6_back_selected); - u6.setPadding(5, 1, 5, 1); - - u9 = new TextView(context); - u9.setText(R.string.U9); - u9.setBackgroundResource(R.drawable.u9_back_selected); - u9.setPadding(5, 1, 5, 1); - - this.setOrientation(LinearLayout.VERTICAL); - - topRow = new LinearLayout(context); - bottomRow = new LinearLayout(context); - - addView(topRow); - addView(bottomRow); - - } - - void setRoutes(byte routes) { - - topRow.removeView(u1); - topRow.removeView(u1n); - topRow.removeView(u2); - topRow.removeView(u6); - topRow.removeView(u9); - - bottomRow.removeView(u1); - bottomRow.removeView(u1n); - bottomRow.removeView(u2); - bottomRow.removeView(u6); - bottomRow.removeView(u9); - - boolean top = true; - - LayoutParams busRouteLayoutParams = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); - - if ((routes & (1 << 0)) != 0) { - if (top) { - topRow.addView(u1, busRouteLayoutParams); - } else { - bottomRow.addView(u1, busRouteLayoutParams); - } - u1.setVisibility(View.VISIBLE); - top = !top; - } - if ((routes & (1 << 1)) != 0) { - if (top) { - topRow.addView(u1n, busRouteLayoutParams); - } else { - bottomRow.addView(u1n, busRouteLayoutParams); - } - u1n.setVisibility(View.VISIBLE); - top = !top; - } - if ((routes & (1 << 2)) != 0) { - if (top) { - topRow.addView(u2, busRouteLayoutParams); - } else { - bottomRow.addView(u2, busRouteLayoutParams); - } - u2.setVisibility(View.VISIBLE); - top = !top; - } - if ((routes & (1 << 3)) != 0) { - if (top) { - topRow.addView(u6, busRouteLayoutParams); - } else { - bottomRow.addView(u6, busRouteLayoutParams); - } - u6.setVisibility(View.VISIBLE); - top = !top; + private TextView u1; + private TextView u1n; + private TextView u2; + private TextView u6; + private TextView u9; + + private LinearLayout bottomRow; + private LinearLayout topRow; + + public BusRoutesView(Context context, final byte routes) { + super(context); + + u1 = new TextView(context); + u1.setText(R.string.U1); + u1.setBackgroundResource(R.drawable.u1_back_selected); + u1.setPadding(5, 1, 5, 1); + + u1n = new TextView(context); + u1n.setText(R.string.U1N); + u1n.setBackgroundResource(R.drawable.u1n_back_selected); + u1n.setPadding(5, 1, 5, 1); + + u2 = new TextView(context); + u2.setText(R.string.U2); + u2.setBackgroundResource(R.drawable.u2_back_selected); + u2.setPadding(5, 1, 5, 1); + + u6 = new TextView(context); + u6.setText(R.string.U6); + u6.setBackgroundResource(R.drawable.u6_back_selected); + u6.setPadding(5, 1, 5, 1); + + u9 = new TextView(context); + u9.setText(R.string.U9); + u9.setBackgroundResource(R.drawable.u9_back_selected); + u9.setPadding(5, 1, 5, 1); + + this.setOrientation(LinearLayout.VERTICAL); + + topRow = new LinearLayout(context); + bottomRow = new LinearLayout(context); + + addView(topRow); + addView(bottomRow); + } - if ((routes & (1 << 4)) != 0) { - if (top) { - topRow.addView(u9, busRouteLayoutParams); - } else { - bottomRow.addView(u9, busRouteLayoutParams); - } - u9.setVisibility(View.VISIBLE); - top = !top; + + void setRoutes(byte routes) { + + topRow.removeView(u1); + topRow.removeView(u1n); + topRow.removeView(u2); + topRow.removeView(u6); + topRow.removeView(u9); + + bottomRow.removeView(u1); + bottomRow.removeView(u1n); + bottomRow.removeView(u2); + bottomRow.removeView(u6); + bottomRow.removeView(u9); + + boolean top = true; + + LayoutParams busRouteLayoutParams = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); + + if ((routes & (1 << 0)) != 0) { + if (top) { + topRow.addView(u1, busRouteLayoutParams); + } else { + bottomRow.addView(u1, busRouteLayoutParams); + } + u1.setVisibility(View.VISIBLE); + top = !top; + } + if ((routes & (1 << 1)) != 0) { + if (top) { + topRow.addView(u1n, busRouteLayoutParams); + } else { + bottomRow.addView(u1n, busRouteLayoutParams); + } + u1n.setVisibility(View.VISIBLE); + top = !top; + } + if ((routes & (1 << 2)) != 0) { + if (top) { + topRow.addView(u2, busRouteLayoutParams); + } else { + bottomRow.addView(u2, busRouteLayoutParams); + } + u2.setVisibility(View.VISIBLE); + top = !top; + } + if ((routes & (1 << 3)) != 0) { + if (top) { + topRow.addView(u6, busRouteLayoutParams); + } else { + bottomRow.addView(u6, busRouteLayoutParams); + } + u6.setVisibility(View.VISIBLE); + top = !top; + } + if ((routes & (1 << 4)) != 0) { + if (top) { + topRow.addView(u9, busRouteLayoutParams); + } else { + bottomRow.addView(u9, busRouteLayoutParams); + } + u9.setVisibility(View.VISIBLE); + top = !top; + } } - } } diff --git a/src/net/cbaines/suma/BusSpecificStopView.java b/src/net/cbaines/suma/BusSpecificStopView.java index bdebcba..610ee76 100644 --- a/src/net/cbaines/suma/BusSpecificStopView.java +++ b/src/net/cbaines/suma/BusSpecificStopView.java @@ -36,8 +36,7 @@ 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 { +public class BusSpecificStopView extends LinearLayout implements OnClickListener, OnLongClickListener { private static final String TAG = "BusSpecificStopView"; @@ -66,10 +65,8 @@ public class BusSpecificStopView extends LinearLayout implements setStop(stop); - addView(location, new LayoutParams(LayoutParams.WRAP_CONTENT, - LayoutParams.WRAP_CONTENT)); - addView(time, new LayoutParams(LayoutParams.FILL_PARENT, - LayoutParams.WRAP_CONTENT)); + addView(location, new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)); + addView(time, new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT)); } @@ -100,8 +97,7 @@ public class BusSpecificStopView extends LinearLayout implements time.setText(""); } - DatabaseHelper helper = OpenHelperManager.getHelper(context, - DatabaseHelper.class); + DatabaseHelper helper = OpenHelperManager.getHelper(context, DatabaseHelper.class); try { Dao busDao = helper.getBusDao(); @@ -112,31 +108,19 @@ public class BusSpecificStopView extends LinearLayout implements if (stop.bus.id != null) { if (stop.live) { - onClickMessage = "Bus " - + stop.bus.toString() - + " at " - + DateFormat.getTimeInstance(DateFormat.SHORT) - .format(stop.arivalTime); + 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); + 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); + 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); } } } else { @@ -144,16 +128,13 @@ public class BusSpecificStopView extends LinearLayout implements if (stop.live) { onClickMessage = "Bus " + stop.bus.toString(); } else { - onClickMessage = "Timetabled bus " - + stop.bus.toString(); + onClickMessage = "Timetabled bus " + stop.bus.toString(); } } else { if (stop.live) { - onClickMessage = "Unidentified bus (" - + stop.bus.getName() + ")"; + onClickMessage = "Unidentified bus (" + stop.bus.getName() + ")"; } else { - onClickMessage = "Timetabled bus (" - + stop.bus.getName() + ")"; + onClickMessage = "Timetabled bus (" + stop.bus.getName() + ")"; } } } @@ -167,8 +148,7 @@ public class BusSpecificStopView extends LinearLayout implements public void onClick(View v) { if (context.activityToast == null) { - context.activityToast = Toast.makeText(context, onClickMessage, - Toast.LENGTH_SHORT); + context.activityToast = Toast.makeText(context, onClickMessage, Toast.LENGTH_SHORT); } else { context.activityToast.setText(onClickMessage); context.activityToast.setDuration(Toast.LENGTH_SHORT); @@ -177,8 +157,7 @@ public class BusSpecificStopView extends LinearLayout implements } public boolean onLongClick(View v) { // TODO - DatabaseHelper helper = OpenHelperManager.getHelper(context, - DatabaseHelper.class); + DatabaseHelper helper = OpenHelperManager.getHelper(context, DatabaseHelper.class); try { Dao busDao = helper.getBusDao(); @@ -186,19 +165,16 @@ public class BusSpecificStopView extends LinearLayout implements busDao.refresh(stop.bus); if (stop.bus.id != null) { + // TODO Change to URI Intent i = new Intent(context, MapActivity.class); i.putExtra("poiPoint", stop.busStop.point.toDoubleString()); ((Activity) context).startActivityForResult(i, 0); } else { if (context.activityToast == null) { - context.activityToast = Toast - .makeText( - context, - "Arival prediction not avalible for timetabled buses", - Toast.LENGTH_SHORT); + context.activityToast = Toast.makeText(context, + "Arival prediction not avalible for timetabled buses", Toast.LENGTH_SHORT); } else { - context.activityToast - .setText("Arival prediction not avalible for timetabled buses"); + context.activityToast.setText("Arival prediction not avalible for timetabled buses"); context.activityToast.setDuration(Toast.LENGTH_SHORT); } context.activityToast.show(); diff --git a/src/net/cbaines/suma/BusSpecificTimetableAdapter.java b/src/net/cbaines/suma/BusSpecificTimetableAdapter.java index c115fea..7bcb560 100644 --- a/src/net/cbaines/suma/BusSpecificTimetableAdapter.java +++ b/src/net/cbaines/suma/BusSpecificTimetableAdapter.java @@ -27,72 +27,74 @@ import android.widget.BaseAdapter; public class BusSpecificTimetableAdapter extends BaseAdapter { - private final BusActivity context; - private Timetable timetable; - private final Animation a; - private boolean[] changed; + private final BusActivity context; + private Timetable timetable; + private final Animation a; + private boolean[] changed; - private long timeOfLastForcedUpdate = System.currentTimeMillis(); + private long timeOfLastForcedUpdate = System.currentTimeMillis(); - // private static final String TAG = "BusSpecificTimetableAdapter"; + // private static final String TAG = "BusSpecificTimetableAdapter"; - public BusSpecificTimetableAdapter(BusActivity context, Timetable timetable) { - this.context = context; - this.timetable = timetable; - this.a = AnimationUtils.loadAnimation(context, R.anim.updated_stop_view); - } + public BusSpecificTimetableAdapter(BusActivity context, Timetable timetable) { + this.context = context; + this.timetable = timetable; + this.a = AnimationUtils.loadAnimation(context, R.anim.updated_stop_view); + } - public View getView(int position, View convertView, ViewGroup parent) { - // Log.i(TAG, "Returning stop " + position + " " + timetable.get(position)); + public View getView(int position, View convertView, ViewGroup parent) { + // Log.i(TAG, "Returning stop " + position + " " + + // timetable.get(position)); + + if (timeOfLastForcedUpdate + 1000 < System.currentTimeMillis()) { + context.handler.post(context.refreshData); + timeOfLastForcedUpdate = System.currentTimeMillis(); + } + + BusSpecificStopView stopView; + if (convertView == null) { + stopView = new BusSpecificStopView(context, timetable.get(position)); + } else { + stopView = (BusSpecificStopView) convertView; + stopView.setStop(timetable.get(position)); + } + + if (changed == null || changed[position]) { + a.reset(); + stopView.startAnimation(a); + // Log.i(TAG, "Animating it"); + } + + return stopView; + } - if (timeOfLastForcedUpdate + 1000 < System.currentTimeMillis()) { - context.handler.post(context.refreshData); - timeOfLastForcedUpdate = System.currentTimeMillis(); + public int getCount() { + return timetable.size(); } - BusSpecificStopView stopView; - if (convertView == null) { - stopView = new BusSpecificStopView(context, timetable.get(position)); - } else { - stopView = (BusSpecificStopView) convertView; - stopView.setStop(timetable.get(position)); + public Object getItem(int position) { + return position; } - if (changed == null || changed[position]) { - a.reset(); - stopView.startAnimation(a); - // Log.i(TAG, "Animating it"); + public long getItemId(int position) { + return position; } - return stopView; - } - - public int getCount() { - return timetable.size(); - } - - public Object getItem(int position) { - return position; - } - - public long getItemId(int position) { - return position; - } - - public void updateTimetable(Timetable newTimetable) { - // Log.v(TAG, "Old timetable " + timetable); - // Log.v(TAG, "Adaptor loading new timetable"); - changed = new boolean[newTimetable.size()]; - for (int i = 0; i < newTimetable.size(); i++) { - if (newTimetable.get(i).arivalTime != null && !timetable.contains(newTimetable.get(i), true)) { - changed[i] = true; - // Log.i(TAG, "Old timetable does not contain: " + newTimetable.get(i)); - } else { - // Log.i(TAG, "Old timetable contains: " + newTimetable.get(i)); - changed[i] = false; - } + public void updateTimetable(Timetable newTimetable) { + // Log.v(TAG, "Old timetable " + timetable); + // Log.v(TAG, "Adaptor loading new timetable"); + changed = new boolean[newTimetable.size()]; + for (int i = 0; i < newTimetable.size(); i++) { + if (newTimetable.get(i).arivalTime != null && !timetable.contains(newTimetable.get(i), true)) { + changed[i] = true; + // Log.i(TAG, "Old timetable does not contain: " + + // newTimetable.get(i)); + } else { + // Log.i(TAG, "Old timetable contains: " + newTimetable.get(i)); + changed[i] = false; + } + } + timetable = newTimetable; + this.notifyDataSetChanged(); } - timetable = newTimetable; - this.notifyDataSetChanged(); - } } diff --git a/src/net/cbaines/suma/BusStop.java b/src/net/cbaines/suma/BusStop.java index 1e9faaa..750f2d1 100644 --- a/src/net/cbaines/suma/BusStop.java +++ b/src/net/cbaines/suma/BusStop.java @@ -32,45 +32,46 @@ import com.j256.ormlite.table.DatabaseTable; */ @DatabaseTable(tableName = "busstops") public class BusStop extends POI { - public static final String DESCRIPTION_FIELD_NAME = "description"; - public static final String BAY_FIELD_NAME = "bay"; - public static final String ROUTES_FIELD_NAME = "bay"; - public static final String UNI_LINK_FIELD_NAME = "uniLink"; + public static final String DESCRIPTION_FIELD_NAME = "description"; + public static final String BAY_FIELD_NAME = "bay"; + public static final String ROUTES_FIELD_NAME = "bay"; + public static final String UNI_LINK_FIELD_NAME = "uniLink"; - /** - * Description e.g. "Bournemouth Rd os Asda S" - */ - @DatabaseField(canBeNull = true) - String description; + /** + * Description e.g. "Bournemouth Rd os Asda S" + */ + @DatabaseField(canBeNull = true) + String description; - /** - * Unknown, "" for all UniLink stops - */ - @DatabaseField(canBeNull = true) - String bay; + /** + * Unknown, "" for all UniLink stops + */ + @DatabaseField(canBeNull = true) + String bay; - /** - * Used to speed up accessing the relevent uni link routes for a bus stop, this is not a uni link stop - */ - @DatabaseField(canBeNull = false) - byte routes; + /** + * Used to speed up accessing the relevent uni link routes for a bus stop, + * this is not a uni link stop + */ + @DatabaseField(canBeNull = false) + byte routes; - @DatabaseField(canBeNull = false) - boolean uniLink; + @DatabaseField(canBeNull = false) + boolean uniLink; - public BusStop(String location, String description, String bay, GeoPoint point) { - this.id = location; - this.description = description; - this.bay = bay; - this.point = point; - this.type = POI.BUS_STOP; - } + public BusStop(String location, String description, String bay, GeoPoint point) { + this.id = location; + this.description = description; + this.bay = bay; + this.point = point; + this.type = POI.BUS_STOP; + } - BusStop() { - this.type = POI.BUS_STOP; - } + BusStop() { + this.type = POI.BUS_STOP; + } - public String toString() { - return description + " (" + id + ")"; - } + public String toString() { + return description + " (" + id + ")"; + } } diff --git a/src/net/cbaines/suma/BusStopActivity.java b/src/net/cbaines/suma/BusStopActivity.java index 62a0f54..55a0bd6 100644 --- a/src/net/cbaines/suma/BusStopActivity.java +++ b/src/net/cbaines/suma/BusStopActivity.java @@ -77,8 +77,6 @@ public class BusStopActivity extends OrmLiteBaseActivity impleme protected Timetable timetable; private Timetable visibleTimetable; - private Dao busStopDao; - private BusStop busStop; private GetTimetableTask timetableTask; @@ -205,10 +203,6 @@ public class BusStopActivity extends OrmLiteBaseActivity impleme } } - busStopDao = helper.getBusStopDao(); - - busStop = busStopDao.queryForId(busStopID); - busFavourite = (CheckBox) findViewById(R.id.favouriteCheckBox); busFavourite.setChecked(favouritesPreferences.getBoolean(busStop.id, false)); busFavourite.setOnCheckedChangeListener(this); @@ -516,27 +510,17 @@ public class BusStopActivity extends OrmLiteBaseActivity 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) { diff --git a/src/net/cbaines/suma/BusStopView.java b/src/net/cbaines/suma/BusStopView.java index d76198b..8659c36 100644 --- a/src/net/cbaines/suma/BusStopView.java +++ b/src/net/cbaines/suma/BusStopView.java @@ -23,12 +23,12 @@ import android.content.Context; public class BusStopView extends POIView { - public BusStopView(Context context, BusStop busStop) { - this(context, busStop, -1); - } + public BusStopView(Context context, BusStop busStop) { + this(context, busStop, -1); + } - public BusStopView(Context context, BusStop busStop, int dist) { - super(context, (POI) busStop, dist); - } + public BusStopView(Context context, BusStop busStop, int dist) { + super(context, (POI) busStop, dist); + } } diff --git a/src/net/cbaines/suma/DataHandler.java b/src/net/cbaines/suma/DataHandler.java index 25f66ff..852f035 100644 --- a/src/net/cbaines/suma/DataHandler.java +++ b/src/net/cbaines/suma/DataHandler.java @@ -27,88 +27,91 @@ import org.xml.sax.helpers.DefaultHandler; public class DataHandler extends DefaultHandler { - // this holds the data - private PathOverlay _data; + // this holds the data + private PathOverlay _data; - private int colour; - private ResourceProxy resProxy; + private int colour; + private ResourceProxy resProxy; - public DataHandler(int colour, ResourceProxy resProxy) { - this.colour = colour; - this.resProxy = resProxy; - } + public DataHandler(int colour, ResourceProxy resProxy) { + this.colour = colour; + this.resProxy = resProxy; + } - /** - * Returns the data object - * - * @return - */ - public PathOverlay getData() { - return _data; - } + /** + * Returns the data object + * + * @return + */ + public PathOverlay getData() { + return _data; + } - /** - * This gets called when the xml document is first opened - * - * @throws SAXException - */ - @Override - public void startDocument() throws SAXException { - _data = new PathOverlay(colour, resProxy); - } + /** + * This gets called when the xml document is first opened + * + * @throws SAXException + */ + @Override + public void startDocument() throws SAXException { + _data = new PathOverlay(colour, resProxy); + } - /** - * Called when it's finished handling the document - * - * @throws SAXException - */ - @Override - public void endDocument() throws SAXException { + /** + * Called when it's finished handling the document + * + * @throws SAXException + */ + @Override + public void endDocument() throws SAXException { - } + } - /** - * This gets called at the start of an element. Here we're also setting the booleans to true if it's at that - * specific tag. (so we know where we are) - * - * @param namespaceURI - * @param localName - * @param qName - * @param atts - * @throws SAXException - */ - @Override - public void startElement(String namespaceURI, String localName, String qName, Attributes atts) throws SAXException { - if (localName.equals("trkpt")) { - // Log.v("DataHandler", "Adding point to route overlay " + atts.getValue("lat") + " " + - // atts.getValue("lon")); - _data.addPoint(Util.csLatLongToGeoPoint(atts.getValue("lat"), atts.getValue("lon"))); + /** + * This gets called at the start of an element. Here we're also setting the + * booleans to true if it's at that specific tag. (so we know where we are) + * + * @param namespaceURI + * @param localName + * @param qName + * @param atts + * @throws SAXException + */ + @Override + public void startElement(String namespaceURI, String localName, String qName, Attributes atts) throws SAXException { + if (localName.equals("trkpt")) { + // Log.v("DataHandler", "Adding point to route overlay " + + // atts.getValue("lat") + " " + + // atts.getValue("lon")); + _data.addPoint(Util.csLatLongToGeoPoint(atts.getValue("lat"), atts.getValue("lon"))); + } } - } - /** - * Called at the end of the element. Setting the booleans to false, so we know that we've just left that tag. - * - * @param namespaceURI - * @param localName - * @param qName - * @throws SAXException - */ - @Override - public void endElement(String namespaceURI, String localName, String qName) throws SAXException { + /** + * Called at the end of the element. Setting the booleans to false, so we + * know that we've just left that tag. + * + * @param namespaceURI + * @param localName + * @param qName + * @throws SAXException + */ + @Override + public void endElement(String namespaceURI, String localName, String qName) throws SAXException { - } + } - /** - * Calling when we're within an element. Here we're checking to see if there is any content in the tags that we're - * interested in and populating it in the Config object. - * - * @param ch - * @param start - * @param length - */ - @Override - public void characters(char ch[], int start, int length) { + /** + * Calling when we're within an element. Here we're checking to see if there + * is any content in the tags that we're interested in and populating it in + * the Config object. + * + * @param ch + * @param start + * @param length + */ + @Override + public void characters(char ch[], int start, int length) { - } + } } diff --git a/src/net/cbaines/suma/DataManager.java b/src/net/cbaines/suma/DataManager.java index 2234328..3a550a7 100644 --- a/src/net/cbaines/suma/DataManager.java +++ b/src/net/cbaines/suma/DataManager.java @@ -137,9 +137,13 @@ public class DataManager { /* * Polygon poly = buildingPolys.get(dataBits[1]); * - * if (poly != null) { bdg.outline = poly; // Log.i(TAG, "Adding building " + key + " " + - * bdg.point.getLatitudeE6() + " " + bdg.point.getLongitudeE6() + " " + poly); } else { // Log.i(TAG, - * "Adding building " + key + " " + bdg.point.getLatitudeE6() + " " + bdg.point.getLongitudeE6()); } + * if (poly != null) { bdg.outline = poly; // Log.i(TAG, + * "Adding building " + key + " " + + * bdg.point.getLatitudeE6() + " " + + * bdg.point.getLongitudeE6() + " " + poly); } else { // + * Log.i(TAG, "Adding building " + key + " " + + * bdg.point.getLatitudeE6() + " " + + * bdg.point.getLongitudeE6()); } */ // Log.i(TAG, "Creating building " + bdg.id + " " + bdg.name @@ -163,9 +167,13 @@ public class DataManager { /* * Polygon poly = buildingPolys.get(dataBits[1]); * - * if (poly != null) { bdg.outline = poly; // Log.i(TAG, "Adding building " + key + " " + - * bdg.point.getLatitudeE6() + " " + bdg.point.getLongitudeE6() + " " + poly); } else { // Log.i(TAG, - * "Adding building " + key + " " + bdg.point.getLatitudeE6() + " " + bdg.point.getLongitudeE6()); } + * if (poly != null) { bdg.outline = poly; // Log.i(TAG, + * "Adding building " + key + " " + + * bdg.point.getLatitudeE6() + " " + + * bdg.point.getLongitudeE6() + " " + poly); } else { // + * Log.i(TAG, "Adding building " + key + " " + + * bdg.point.getLatitudeE6() + " " + + * bdg.point.getLongitudeE6()); } */ // Log.i(TAG, "Creating building " + bdg.id + " " + bdg.name @@ -184,13 +192,17 @@ public class DataManager { } /* - * for (Iterator iter = buildingPoints.keySet().iterator(); iter.hasNext();) { String key = iter.next(); + * for (Iterator iter = buildingPoints.keySet().iterator(); + * iter.hasNext();) { String key = iter.next(); * - * Building bdg = new Building(key, buildingPoints.get(key), false); Polygon poly = buildingPolys.get(key); + * Building bdg = new Building(key, buildingPoints.get(key), false); + * Polygon poly = buildingPolys.get(key); * - * if (poly != null) { bdg.outline = poly; // Log.i(TAG, "Adding building " + key + " " + bdg.point.getLatitudeE6() + " " - * + bdg.point.getLongitudeE6() + " " + poly); } else { // Log.i(TAG, "Adding building " + key + " " + - * bdg.point.getLatitudeE6() + " " + bdg.point.getLongitudeE6()); } + * if (poly != null) { bdg.outline = poly; // Log.i(TAG, + * "Adding building " + key + " " + bdg.point.getLatitudeE6() + " " + + * bdg.point.getLongitudeE6() + " " + poly); } else { // Log.i(TAG, + * "Adding building " + key + " " + bdg.point.getLatitudeE6() + " " + + * bdg.point.getLongitudeE6()); } * * buildingDao.create(bdg); } */ @@ -227,18 +239,18 @@ public class DataManager { // Log.i(TAG, "Whole " + dataBits[3] + " First bit " + // quBitsLat[0] + " last bit " + quBitsLat[1]); - double lat = Double.valueOf(quBitsLat[0]) + Double.valueOf(quBitsLat[1].substring(0, quBitsLat[1].length() - 1)) - / 60d; + double lat = Double.valueOf(quBitsLat[0]) + + Double.valueOf(quBitsLat[1].substring(0, quBitsLat[1].length() - 1)) / 60d; // Log.i(TAG, "Whole " + dataBits[4] + " First bit " + // quBitsLng[0] + " last bit " + quBitsLng[1]); - double lng = Double.valueOf(quBitsLng[0]) + Double.valueOf(quBitsLng[1].substring(0, quBitsLng[1].length() - 1)) - / 60d; + double lng = Double.valueOf(quBitsLng[0]) + + Double.valueOf(quBitsLng[1].substring(0, quBitsLng[1].length() - 1)) / 60d; GeoPoint point = new GeoPoint((int) (lat * 1e6), (int) (lng * -1e6)); // Log.i(TAG, "Lat " + point.getLatitudeE6() + " lng " + // point.getLongitudeE6()); - busStopDao.create(new BusStop(dataBits[0].replace("\"", ""), dataBits[1].replace("\"", ""), dataBits[2].replace( - "\"", ""), point)); + busStopDao.create(new BusStop(dataBits[0].replace("\"", ""), dataBits[1].replace("\"", ""), dataBits[2] + .replace("\"", ""), point)); } @@ -359,26 +371,36 @@ public class DataManager { } /* - * for (Iterator busStopIter = busStopDao.iterator(); busStopIter.hasNext();) { BusStop stop = - * busStopIter.next(); // Log.i(TAG, "Looking at stop " + stop.id); + * for (Iterator busStopIter = busStopDao.iterator(); + * busStopIter.hasNext();) { BusStop stop = busStopIter.next(); // + * Log.i(TAG, "Looking at stop " + stop.id); * * - * QueryBuilder routeStopsQueryBuilder = routeStopsDao.queryBuilder(); + * QueryBuilder routeStopsQueryBuilder = + * routeStopsDao.queryBuilder(); * routeStopsQueryBuilder.where().eq(columnName, value) * - * DeleteBuilder deleteBuilder = busStopDao.deleteBuilder(); // only delete the rows where password is - * null deleteBuilder.where().in(RouteStops.STOP_ID_FIELD_NAME, objects) accountDao.delete(deleteBuilder.prepare()); + * DeleteBuilder deleteBuilder = + * busStopDao.deleteBuilder(); // only delete the rows where password is + * null deleteBuilder.where().in(RouteStops.STOP_ID_FIELD_NAME, objects) + * accountDao.delete(deleteBuilder.prepare()); * * - * QueryBuilder routeStopsQueryBuilder = routeStopsDao.queryBuilder(); - * routeStopsQueryBuilder.setCountOf(true); routeStopsQueryBuilder.where().eq(RouteStops.STOP_ID_FIELD_NAME, stop); + * QueryBuilder routeStopsQueryBuilder = + * routeStopsDao.queryBuilder(); + * routeStopsQueryBuilder.setCountOf(true); + * routeStopsQueryBuilder.where().eq(RouteStops.STOP_ID_FIELD_NAME, + * stop); * - * PreparedQuery routeStopsPreparedQuery = routeStopsQueryBuilder.prepare(); List routeStops = - * routeStopsDao.query(routeStopsPreparedQuery); // long num = routeStopsDao.query(routeStopsPreparedQuery).size(); // - * Log.i(TAG, "Number is " + num); + * PreparedQuery routeStopsPreparedQuery = + * routeStopsQueryBuilder.prepare(); List routeStops = + * routeStopsDao.query(routeStopsPreparedQuery); // long num = + * routeStopsDao.query(routeStopsPreparedQuery).size(); // Log.i(TAG, + * "Number is " + num); * - * stop.uniLink = false; for (RouteStops routeStop : routeStops) { if (routeStop.busRoute.uniLink) { stop.uniLink = true; - * } } busStopDao.update(stop); } + * stop.uniLink = false; for (RouteStops routeStop : routeStops) { if + * (routeStop.busRoute.uniLink) { stop.uniLink = true; } } + * busStopDao.update(stop); } */ Log.i(TAG, "Finished loading bus data"); @@ -428,8 +450,8 @@ public class DataManager { Log.i(TAG, "Loaded sites from csv"); } - private static Stop getStop(Context context, JSONObject stopObj, Set routes, BusStop busStop) throws SQLException, - JSONException { + private static Stop getStop(Context context, JSONObject stopObj, Set routes, BusStop busStop) + throws SQLException, JSONException { if (helper == null) helper = OpenHelperManager.getHelper(context, DatabaseHelper.class); @@ -553,9 +575,11 @@ public class DataManager { List routeStops = routeStopsDao.query(routeStopsPreparedQuery); if (routeStops.size() > 0) { - Log.i(TAG, "Found " + routeStops.size() + " stops matching the destStop " + destStop + " on route " + route.code); + Log.i(TAG, "Found " + routeStops.size() + " stops matching the destStop " + destStop + " on route " + + route.code); } else { - Log.w(TAG, "Found " + routeStops.size() + " stops matching the destStop " + destStop + " on route " + route.code); + Log.w(TAG, "Found " + routeStops.size() + " stops matching the destStop " + destStop + " on route " + + route.code); } } @@ -623,7 +647,8 @@ public class DataManager { if (route != null) { busRoutes.add(route); } else { - throw new RuntimeException("Route not found " + key.substring(key.length() - 3, key.length()) + " " + key); + throw new RuntimeException("Route not found " + key.substring(key.length() - 3, key.length()) + " " + + key); } } @@ -719,8 +744,8 @@ public class DataManager { continue; } - Log.v(TAG, "Found stop for a unidentified " + stop.bus.toString() + " at " + stop.busStop.id + " at " - + stop.arivalTime); + Log.v(TAG, "Found stop for a unidentified " + stop.bus.toString() + " at " + stop.busStop.id + + " at " + stop.arivalTime); timetable.add(stop); diff --git a/src/net/cbaines/suma/DatabaseConfigUtil.java b/src/net/cbaines/suma/DatabaseConfigUtil.java index 831e8cb..08a54b0 100644 --- a/src/net/cbaines/suma/DatabaseConfigUtil.java +++ b/src/net/cbaines/suma/DatabaseConfigUtil.java @@ -22,7 +22,7 @@ package net.cbaines.suma; import com.j256.ormlite.android.apptools.OrmLiteConfigUtil; public class DatabaseConfigUtil extends OrmLiteConfigUtil { - public static void main(String[] args) throws Exception { - writeConfigFile("ormlite_config.txt"); - } + public static void main(String[] args) throws Exception { + writeConfigFile("ormlite_config.txt"); + } } diff --git a/src/net/cbaines/suma/DatabaseHelper.java b/src/net/cbaines/suma/DatabaseHelper.java index 4563d7c..13f4957 100644 --- a/src/net/cbaines/suma/DatabaseHelper.java +++ b/src/net/cbaines/suma/DatabaseHelper.java @@ -37,218 +37,229 @@ import com.j256.ormlite.table.TableUtils; 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 = 40; - - private static final String TAG = "DatabaseHelper"; - - // the DAO object we use to access the SimpleData table - private Dao buildingDao = null; - private Dao busStopDao = null; - private Dao busRouteDao = null; - private Dao routeStopsDao = null; - private Dao siteDao = null; - private Dao busDao = null; - - private Context context; - - public DatabaseHelper(Context context) { - super(context, DATABASE_NAME, null, DATABASE_VERSION); - Log.i(TAG, "Database Helper created"); - this.context = context; - } - - @Override - public void onCreate(SQLiteDatabase database, ConnectionSource connectionSource) { - try { - Log.i(DatabaseHelper.class.getName(), "onCreate"); - TableUtils.createTable(connectionSource, Building.class); - TableUtils.createTable(connectionSource, BusStop.class); - TableUtils.createTable(connectionSource, BusRoute.class); - TableUtils.createTable(connectionSource, RouteStops.class); - TableUtils.createTable(connectionSource, Site.class); - TableUtils.createTable(connectionSource, Bus.class); - } catch (SQLException e) { - Log.e(DatabaseHelper.class.getName(), "Can't create database", e); - throw new RuntimeException(e); - } - } + 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 = 40; + + private static final String TAG = "DatabaseHelper"; - @Override - public void onUpgrade(SQLiteDatabase database, ConnectionSource connectionSource, int oldVersion, int newVersion) { - try { - Log.i(DatabaseHelper.class.getName(), "onUpgrade"); - copyDataBase(); + // the DAO object we use to access the SimpleData table + private Dao buildingDao = null; + private Dao busStopDao = null; + private Dao busRouteDao = null; + private Dao routeStopsDao = null; + private Dao siteDao = null; + private Dao busDao = null; - } catch (IOException e) { - e.printStackTrace(); + private Context context; + + public DatabaseHelper(Context context) { + super(context, DATABASE_NAME, null, DATABASE_VERSION); + Log.i(TAG, "Database Helper created"); + this.context = context; } - } + @Override + public void onCreate(SQLiteDatabase database, ConnectionSource connectionSource) { + try { + Log.i(DatabaseHelper.class.getName(), "onCreate"); + TableUtils.createTable(connectionSource, Building.class); + TableUtils.createTable(connectionSource, BusStop.class); + TableUtils.createTable(connectionSource, BusRoute.class); + TableUtils.createTable(connectionSource, RouteStops.class); + TableUtils.createTable(connectionSource, Site.class); + TableUtils.createTable(connectionSource, Bus.class); + } catch (SQLException e) { + Log.e(DatabaseHelper.class.getName(), "Can't create database", e); + throw new RuntimeException(e); + } + } + + @Override + public void onUpgrade(SQLiteDatabase database, ConnectionSource connectionSource, int oldVersion, int newVersion) { + try { + Log.i(DatabaseHelper.class.getName(), "onUpgrade"); + copyDataBase(); + + } catch (IOException e) { + e.printStackTrace(); + } - /** - * Returns the Database Access Object (DAO) for our SimpleData class. It will create it or just give the cached value. - */ - public Dao getBuildingDao() throws SQLException { - if (buildingDao == null) { - buildingDao = getDao(Building.class); } - return buildingDao; - } - - /** - * Returns the Database Access Object (DAO) for our SimpleData class. It will create it or just give the cached value. - */ - public Dao getBusStopDao() throws SQLException { - if (busStopDao == null) { - busStopDao = getDao(BusStop.class); + + /** + * Returns the Database Access Object (DAO) for our SimpleData class. It + * will create it or just give the cached value. + */ + public Dao getBuildingDao() throws SQLException { + if (buildingDao == null) { + buildingDao = getDao(Building.class); + } + return buildingDao; } - return busStopDao; - } - - /** - * Returns the Database Access Object (DAO) for our SimpleData class. It will create it or just give the cached value. - */ - public Dao getBusRouteDao() throws SQLException { - if (busRouteDao == null) { - busRouteDao = getDao(BusRoute.class); + + /** + * Returns the Database Access Object (DAO) for our SimpleData class. It + * will create it or just give the cached value. + */ + public Dao getBusStopDao() throws SQLException { + if (busStopDao == null) { + busStopDao = getDao(BusStop.class); + } + return busStopDao; } - return busRouteDao; - } - - /** - * Returns the Database Access Object (DAO) for our SimpleData class. It will create it or just give the cached value. - */ - public Dao getRouteStopsDao() throws SQLException { - if (routeStopsDao == null) { - routeStopsDao = getDao(RouteStops.class); + + /** + * Returns the Database Access Object (DAO) for our SimpleData class. It + * will create it or just give the cached value. + */ + public Dao getBusRouteDao() throws SQLException { + if (busRouteDao == null) { + busRouteDao = getDao(BusRoute.class); + } + return busRouteDao; } - return routeStopsDao; - } - - /** - * Returns the Database Access Object (DAO) for our SimpleData class. It will create it or just give the cached value. - */ - public Dao getSiteDao() throws SQLException { - if (siteDao == null) { - siteDao = getDao(Site.class); + + /** + * Returns the Database Access Object (DAO) for our SimpleData class. It + * will create it or just give the cached value. + */ + public Dao getRouteStopsDao() throws SQLException { + if (routeStopsDao == null) { + routeStopsDao = getDao(RouteStops.class); + } + return routeStopsDao; } - return siteDao; - } - - /** - * Returns the Database Access Object (DAO) for our SimpleData class. It will create it or just give the cached value. - */ - public Dao getBusDao() throws SQLException { - if (busDao == null) { - busDao = getDao(Bus.class); + + /** + * Returns the Database Access Object (DAO) for our SimpleData class. It + * will create it or just give the cached value. + */ + public Dao getSiteDao() throws SQLException { + if (siteDao == null) { + siteDao = getDao(Site.class); + } + return siteDao; } - return busDao; - } - - /** - * Check if the database already exist to avoid re-copying the file each time you open the application. - * - * @return true if it exists, false if it doesn't - */ - public boolean checkDataBase() { - Log.i(TAG, "Check database"); - - /* - * SQLiteDatabase checkDB = null; - * - * try { String myPath = DATABASE_PATH + DATABASE_NAME; checkDB = SQLiteDatabase.openDatabase(myPath, null, SQLiteDatabase.OPEN_READONLY); } catch - * (SQLiteException e) { - * - * // database does't exist yet. - * - * } - * - * if (checkDB != null) { - * - * checkDB.close(); - * - * } + + /** + * Returns the Database Access Object (DAO) for our SimpleData class. It + * will create it or just give the cached value. + */ + public Dao getBusDao() throws SQLException { + if (busDao == null) { + busDao = getDao(Bus.class); + } + return busDao; + } + + /** + * Check if the database already exist to avoid re-copying the file each + * time you open the application. * - * Log.i(TAG, "Finished checking database"); return checkDB != null ? true : false; + * @return true if it exists, false if it doesn't */ + public boolean checkDataBase() { + Log.i(TAG, "Check database"); + + /* + * SQLiteDatabase checkDB = null; + * + * try { String myPath = DATABASE_PATH + DATABASE_NAME; checkDB = + * SQLiteDatabase.openDatabase(myPath, null, + * SQLiteDatabase.OPEN_READONLY); } catch (SQLiteException e) { + * + * // database does't exist yet. + * + * } + * + * if (checkDB != null) { + * + * checkDB.close(); + * + * } + * + * Log.i(TAG, "Finished checking database"); return checkDB != null ? + * true : false; + */ + + File dbFile = new File(DATABASE_PATH + DATABASE_NAME); + return dbFile.exists(); + } - File dbFile = new File(DATABASE_PATH + DATABASE_NAME); - return dbFile.exists(); - } + /** + * Copies your database from your local assets-folder to the just created + * empty database in the system folder, from where it can be accessed and + * handled. This is done by transfering bytestream. + * */ + public void copyDataBase() throws IOException { + Log.i(TAG, "Begining copy database"); - /** - * Copies your database from your local assets-folder to the just created empty database in the system folder, from where it can be accessed and handled. - * This is done by transfering bytestream. - * */ - public void copyDataBase() throws IOException { - Log.i(TAG, "Begining copy database"); + InputStream myInput = context.getAssets().open(DATABASE_NAME); - InputStream myInput = context.getAssets().open(DATABASE_NAME); + // Path to the just created empty db + String outFileName = DATABASE_PATH + DATABASE_NAME; - // Path to the just created empty db - String outFileName = DATABASE_PATH + DATABASE_NAME; + File database = new File(outFileName); + if (database.exists()) { + database.delete(); + } - File database = new File(outFileName); - if (database.exists()) { - database.delete(); - } + // Open the empty db as the output stream + OutputStream myOutput = new FileOutputStream(outFileName); - // Open the empty db as the output stream - OutputStream myOutput = new FileOutputStream(outFileName); + // transfer bytes from the inputfile to the outputfile + byte[] buffer = new byte[1024]; + int length; + while ((length = myInput.read(buffer)) > 0) { + myOutput.write(buffer, 0, length); + } - // transfer bytes from the inputfile to the outputfile - byte[] buffer = new byte[1024]; - int length; - while ((length = myInput.read(buffer)) > 0) { - myOutput.write(buffer, 0, length); - } + // Close the streams + myOutput.flush(); + myOutput.close(); + myInput.close(); - // Close the streams - myOutput.flush(); - myOutput.close(); - myInput.close(); + // getWritableDatabase().close(); - // getWritableDatabase().close(); + Log.i(TAG, "Finished copying db"); - Log.i(TAG, "Finished copying db"); + } - } + /** + * Creates a empty database on the system and rewrites it with your own + * database. + * */ + public void createDataBase() throws IOException { - /** - * Creates a empty database on the system and rewrites it with your own database. - * */ - public void createDataBase() throws IOException { + boolean dbExist = checkDataBase(); - boolean dbExist = checkDataBase(); + if (dbExist) { + // do nothing - database already exist + } else { - if (dbExist) { - // do nothing - database already exist - } else { + try { + Log.i(TAG, "Copy database"); + copyDataBase(); + } catch (IOException e) { + throw new Error("Error copying database"); + } + } - try { - Log.i(TAG, "Copy database"); - copyDataBase(); - } catch (IOException e) { - throw new Error("Error copying database"); - } } - } - - /** - * Close the database connections and clear any cached DAOs. - */ - @Override - public void close() { - super.close(); - buildingDao = null; - busStopDao = null; - busRouteDao = null; - routeStopsDao = null; - siteDao = null; - busDao = null; - } + /** + * Close the database connections and clear any cached DAOs. + */ + @Override + public void close() { + super.close(); + buildingDao = null; + busStopDao = null; + busRouteDao = null; + routeStopsDao = null; + siteDao = null; + busDao = null; + } } \ No newline at end of file diff --git a/src/net/cbaines/suma/DonateDialog.java b/src/net/cbaines/suma/DonateDialog.java index a364104..59769a4 100644 --- a/src/net/cbaines/suma/DonateDialog.java +++ b/src/net/cbaines/suma/DonateDialog.java @@ -71,8 +71,11 @@ public class DonateDialog extends Dialog implements Runnable { 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")); + 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) { diff --git a/src/net/cbaines/suma/FindActivity.java b/src/net/cbaines/suma/FindActivity.java index 154cd64..1af350a 100644 --- a/src/net/cbaines/suma/FindActivity.java +++ b/src/net/cbaines/suma/FindActivity.java @@ -32,6 +32,7 @@ import android.content.Intent; import android.location.Location; import android.location.LocationListener; import android.location.LocationManager; +import android.net.Uri; import android.os.Bundle; import android.text.Editable; import android.text.TextWatcher; @@ -51,353 +52,316 @@ import com.j256.ormlite.dao.Dao; import com.j256.ormlite.stmt.PreparedQuery; import com.j256.ormlite.stmt.QueryBuilder; -public class FindActivity extends OrmLiteBaseActivity implements Runnable, TextWatcher, OnItemClickListener, LocationListener, - OnItemLongClickListener { +public class FindActivity extends OrmLiteBaseActivity implements Runnable, TextWatcher, + OnItemClickListener, LocationListener, OnItemLongClickListener { - final static String TAG = "FindActivity"; + final static String TAG = "FindActivity"; - private EditText searchBar; - private ListView listItems; - private ProgressBar progBar; - private LinearLayout findContentLayout; + private EditText searchBar; + private ListView listItems; + private ProgressBar progBar; + private LinearLayout findContentLayout; - private String searchTerm = ""; + private String searchTerm = ""; - private Dao buildingDao; - private Dao busStopDao; - private Dao siteDao; + private Dao buildingDao; + private Dao busStopDao; + private Dao siteDao; - private POIArrayAdapter adapter; - // private ArrayList POIsFound = new ArrayList(); + private POIArrayAdapter adapter; - private boolean dataChanged; + private GeoPoint userLocation; - private GeoPoint userLocation; + private Thread searchThread; - private Thread searchThread; - - ArrayList getNearestPOIs(int distance) { - Log.i(TAG, "Getting nearest POI's"); - ArrayList nearestPOIs = new ArrayList(); - for (Iterator buildingDaoIter = buildingDao.iterator(); buildingDaoIter.hasNext();) { - POI poi = buildingDaoIter.next(); - int dist = poi.point.distanceTo(userLocation); - if (dist < distance) { - poi.distTo = dist; - nearestPOIs.add(poi); - } - } + ArrayList getNearestPOIs(int distance) { + Log.i(TAG, "Getting nearest POI's"); + ArrayList nearestPOIs = new ArrayList(); + for (Iterator buildingDaoIter = buildingDao.iterator(); buildingDaoIter.hasNext();) { + POI poi = buildingDaoIter.next(); + int dist = poi.point.distanceTo(userLocation); + if (dist < distance) { + poi.distTo = dist; + nearestPOIs.add(poi); + } + } - for (Iterator busStopDaoIter = busStopDao.iterator(); busStopDaoIter.hasNext();) { - POI poi = busStopDaoIter.next(); - int dist = poi.point.distanceTo(userLocation); - if (dist < distance) { - poi.distTo = dist; - nearestPOIs.add(poi); - } - } + for (Iterator busStopDaoIter = busStopDao.iterator(); busStopDaoIter.hasNext();) { + POI poi = busStopDaoIter.next(); + int dist = poi.point.distanceTo(userLocation); + if (dist < distance) { + poi.distTo = dist; + nearestPOIs.add(poi); + } + } - Collections.sort(nearestPOIs, new POIDistanceComparator(userLocation, true)); + Collections.sort(nearestPOIs, new POIDistanceComparator(userLocation, true)); - Log.i(TAG, "Got " + nearestPOIs.size() + " nearest POI's"); - return nearestPOIs; - } + Log.i(TAG, "Got " + nearestPOIs.size() + " nearest POI's"); + return nearestPOIs; + } - // Search thread - public void run() { - POIArrayAdapter tempAdaptor; - GeoPoint thisUserLocation = userLocation; + // Search thread + public void run() { + POIArrayAdapter tempAdaptor; + GeoPoint thisUserLocation = userLocation; - Log.i(TAG, "Search thread started"); - String thisSearchTerm = searchTerm; + Log.i(TAG, "Search thread started"); + String thisSearchTerm = searchTerm; - ArrayList foundPOIsArray = null; + ArrayList foundPOIsArray = null; - Log.i(TAG, "Search term length " + thisSearchTerm.length() + " userLocation == null " + (thisUserLocation == null)); - if (thisSearchTerm.length() == 0 && thisUserLocation != null) { - foundPOIsArray = getNearestPOIs(200); + Log.i(TAG, "Search term length " + thisSearchTerm.length() + " userLocation == null " + + (thisUserLocation == null)); + if (thisSearchTerm.length() == 0 && thisUserLocation != null) { + foundPOIsArray = getNearestPOIs(200); - } + } - if (foundPOIsArray != null && foundPOIsArray.size() != 0) { + if (foundPOIsArray != null && foundPOIsArray.size() != 0) { - tempAdaptor = new POIArrayAdapter(this, foundPOIsArray); - } else { + tempAdaptor = new POIArrayAdapter(this, foundPOIsArray); + } else { - try { + try { + + foundPOIsArray = new ArrayList(); + + if (thisSearchTerm.length() == 0) { + for (Building building : buildingDao) { + foundPOIsArray.add(building); + } + + if (!thisSearchTerm.equals(searchTerm)) + return; + + for (BusStop busStop : busStopDao) { + foundPOIsArray.add(busStop); + } + + if (!thisSearchTerm.equals(searchTerm)) + return; + + for (Site site : siteDao) { + foundPOIsArray.add(site); + } + + } else { + + QueryBuilder buildingQueryBuilder = buildingDao.queryBuilder(); + buildingQueryBuilder.where().like(Building.ID_FIELD_NAME, "%" + thisSearchTerm + "%").or() + .like(Building.NAME_FIELD_NAME, "%" + thisSearchTerm + "%"); + PreparedQuery buildingPreparedQuery = buildingQueryBuilder.prepare(); + List buildings = buildingDao.query(buildingPreparedQuery); + for (Building building : buildings) { + foundPOIsArray.add(building); + } + buildings = null; + + if (!thisSearchTerm.equals(searchTerm)) + return; + + if (thisSearchTerm.contains("site")) { + for (Site site : siteDao) { + foundPOIsArray.add(site); + } + } else { + QueryBuilder siteQueryBuilder = siteDao.queryBuilder(); + siteQueryBuilder.where().like(Site.ID_FIELD_NAME, "%" + thisSearchTerm + "%").or() + .like(Site.NAME_FIELD_NAME, "%" + thisSearchTerm + "%"); + PreparedQuery sitePreparedQuery = siteQueryBuilder.prepare(); + List sites = siteDao.query(sitePreparedQuery); + for (Site site : sites) { + foundPOIsArray.add(site); + } + sites = null; + } + + if (!thisSearchTerm.equals(searchTerm)) + return; + + // if (thisSearchTerm.contains("bus")) { + // for (BusStop busStop : busStopDao) { + // foundPOIsArray.add(busStop); + // } + // } else { + QueryBuilder busStopQueryBuilder = busStopDao.queryBuilder(); + busStopQueryBuilder.where().like(BusStop.ID_FIELD_NAME, "%" + thisSearchTerm + "%").or() + .like(BusStop.DESCRIPTION_FIELD_NAME, "%" + thisSearchTerm + "%"); + PreparedQuery busStopPreparedQuery = busStopQueryBuilder.prepare(); + List busStops = busStopDao.query(busStopPreparedQuery); + for (BusStop busStop : busStops) { + foundPOIsArray.add(busStop); + } + busStops = null; + // } + + if (!thisSearchTerm.equals(searchTerm)) + return; + + Log.i(TAG, "Found " + foundPOIsArray.size() + " pois"); + + if (thisUserLocation != null) { + Collections.sort(foundPOIsArray, new POIDistanceComparator(userLocation)); + } else { + Collections.sort(foundPOIsArray, new StringDistanceComparator(thisSearchTerm)); + } + + } + + if (!thisSearchTerm.equals(searchTerm)) + return; + + tempAdaptor = new POIArrayAdapter(this, foundPOIsArray); + + } catch (SQLException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + return; + } + } - foundPOIsArray = new ArrayList(); + if (thisSearchTerm.equals(searchTerm)) { + Log.i(TAG, "Search terms still equal, starting post"); + adapter = tempAdaptor; + listItems.post(new Runnable() { + public void run() { + listItems.setAdapter(adapter); + if (progBar.getVisibility() != View.GONE) { + progBar.setVisibility(View.GONE); + findContentLayout.setGravity(Gravity.TOP); + } + } + }); + } else { + Log.i(TAG, "Search terms no longer equal, exiting"); + } + } - if (thisSearchTerm.length() == 0) { - for (Building building : buildingDao) { - foundPOIsArray.add(building); - } + /** Called when the activity is first created. */ + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.find); - if (!thisSearchTerm.equals(searchTerm)) - return; + searchBar = (EditText) findViewById(R.id.searchBar); + searchBar.addTextChangedListener(this); - for (BusStop busStop : busStopDao) { - foundPOIsArray.add(busStop); - } + listItems = (ListView) findViewById(R.id.findListItems); + listItems.setOnItemClickListener(this); + listItems.setOnItemLongClickListener(this); - if (!thisSearchTerm.equals(searchTerm)) - return; + progBar = (ProgressBar) findViewById(R.id.findLoadBar); + findContentLayout = (LinearLayout) findViewById(R.id.findContentLayout); - for (Site site : siteDao) { - foundPOIsArray.add(site); - } + try { + buildingDao = getHelper().getBuildingDao(); + busStopDao = getHelper().getBusStopDao(); + siteDao = getHelper().getSiteDao(); + } catch (SQLException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + // Acquire a reference to the system Location Manager + LocationManager locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE); + Location lastKnownLocation = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER); + if (lastKnownLocation != null) { + userLocation = Util.locationToGeoPoint(lastKnownLocation); } else { + lastKnownLocation = locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER); + if (lastKnownLocation != null) { + userLocation = Util.locationToGeoPoint(lastKnownLocation); - QueryBuilder buildingQueryBuilder = buildingDao.queryBuilder(); - buildingQueryBuilder.where().like(Building.ID_FIELD_NAME, "%" + thisSearchTerm + "%").or() - .like(Building.NAME_FIELD_NAME, "%" + thisSearchTerm + "%"); - PreparedQuery buildingPreparedQuery = buildingQueryBuilder.prepare(); - List buildings = buildingDao.query(buildingPreparedQuery); - for (Building building : buildings) { - foundPOIsArray.add(building); - } - buildings = null; - - if (!thisSearchTerm.equals(searchTerm)) - return; - - if (thisSearchTerm.contains("site")) { - for (Site site : siteDao) { - foundPOIsArray.add(site); - } - } else { - QueryBuilder siteQueryBuilder = siteDao.queryBuilder(); - siteQueryBuilder.where().like(Site.ID_FIELD_NAME, "%" + thisSearchTerm + "%").or() - .like(Site.NAME_FIELD_NAME, "%" + thisSearchTerm + "%"); - PreparedQuery sitePreparedQuery = siteQueryBuilder.prepare(); - List sites = siteDao.query(sitePreparedQuery); - for (Site site : sites) { - foundPOIsArray.add(site); } - sites = null; - } - - if (!thisSearchTerm.equals(searchTerm)) - return; - - // if (thisSearchTerm.contains("bus")) { - // for (BusStop busStop : busStopDao) { - // foundPOIsArray.add(busStop); - // } - // } else { - QueryBuilder busStopQueryBuilder = busStopDao.queryBuilder(); - busStopQueryBuilder.where().like(BusStop.ID_FIELD_NAME, "%" + thisSearchTerm + "%").or() - .like(BusStop.DESCRIPTION_FIELD_NAME, "%" + thisSearchTerm + "%"); - PreparedQuery busStopPreparedQuery = busStopQueryBuilder.prepare(); - List busStops = busStopDao.query(busStopPreparedQuery); - for (BusStop busStop : busStops) { - foundPOIsArray.add(busStop); - } - busStops = null; - // } - - if (!thisSearchTerm.equals(searchTerm)) - return; - - Log.i(TAG, "Found " + foundPOIsArray.size() + " pois"); - - if (thisUserLocation != null) { - Collections.sort(foundPOIsArray, new POIDistanceComparator(userLocation)); - } else { - Collections.sort(foundPOIsArray, new StringDistanceComparator(thisSearchTerm)); - } - + } + // Register the listener with the Location Manager to receive location + // updates + locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 10000, 10, this); + try { + locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 10000, 10, this); + } catch (Exception e) { + // Ignore anything that goes wrong here... } - if (!thisSearchTerm.equals(searchTerm)) - return; - - tempAdaptor = new POIArrayAdapter(this, foundPOIsArray); + searchThread = new Thread(this); + searchThread.start(); - } catch (SQLException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - return; - } } - if (thisSearchTerm.equals(searchTerm)) { - Log.i(TAG, "Search terms still equal, starting post"); - adapter = tempAdaptor; - listItems.post(new Runnable() { - public void run() { - listItems.setAdapter(adapter); - if (progBar.getVisibility() != View.GONE) { - progBar.setVisibility(View.GONE); - findContentLayout.setGravity(Gravity.TOP); - } - } - }); - } else { - Log.i(TAG, "Search terms no longer equal, exiting"); - } - } - - /** Called when the activity is first created. */ - public void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - setContentView(R.layout.find); - - searchBar = (EditText) findViewById(R.id.searchBar); - searchBar.addTextChangedListener(this); - - listItems = (ListView) findViewById(R.id.findListItems); - listItems.setOnItemClickListener(this); - listItems.setOnItemLongClickListener(this); - - progBar = (ProgressBar) findViewById(R.id.findLoadBar); - findContentLayout = (LinearLayout) findViewById(R.id.findContentLayout); - - try { - buildingDao = getHelper().getBuildingDao(); - busStopDao = getHelper().getBusStopDao(); - siteDao = getHelper().getSiteDao(); - } catch (SQLException e) { - // TODO Auto-generated catch block - e.printStackTrace(); + public void afterTextChanged(Editable s) { + searchTerm = s.toString(); + Log.i(TAG, "Text changed " + searchTerm + " starting search thread"); + new Thread(this).start(); } - // Acquire a reference to the system Location Manager - LocationManager locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE); - Location lastKnownLocation = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER); - if (lastKnownLocation != null) { - userLocation = Util.locationToGeoPoint(lastKnownLocation); - } else { - lastKnownLocation = locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER); - if (lastKnownLocation != null) { - userLocation = Util.locationToGeoPoint(lastKnownLocation); - - } + public void beforeTextChanged(CharSequence s, int start, int count, int after) { } - // Register the listener with the Location Manager to receive location updates - locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 10000, 10, this); - try { - locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 10000, 10, this); - } catch (Exception e) { - // Ignore anything that goes wrong here... - } - - // SotonBusData.getTimetable("SN120128"); - - // Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("bitcoin:1F8fHWmWhqUJGhXUvY57mUof41wMUaeKH7?amount=1X8&label=SUC")); - // startActivity(browserIntent); - // 1F8fHWmWhqUJGhXUvY57mUof41wMUaeKH7 - searchThread = new Thread(this); - searchThread.start(); + public void onTextChanged(CharSequence s, int start, int before, int count) { + } - } + public void onItemClick(AdapterView parent, View view, int position, long id) { + Log.i(TAG, "OnItemClick pos " + position + " id " + id); - public void afterTextChanged(Editable s) { - searchTerm = s.toString(); - Log.i(TAG, "Text changed " + searchTerm + " starting search thread"); - new Thread(this).start(); - } + POI poi = adapter.getPOIItem(position); - public void beforeTextChanged(CharSequence s, int start, int count, int after) { - // TODO Auto-generated method stub + Uri uri = Uri.parse("geo:" + Util.E6IntToDouble(poi.point.getLatitudeE6()) + "," + + Util.E6IntToDouble(poi.point.getLongitudeE6()) + "?z=18"); - } + Log.i(TAG, "Starting a activity for " + uri); - public void onTextChanged(CharSequence s, int start, int before, int count) { - // TODO Auto-generated method stub + Intent mapIntent = new Intent(Intent.ACTION_VIEW, uri); + startActivity(mapIntent); + } - } + public boolean onItemLongClick(AdapterView parent, View view, int position, long id) { - public void onItemClick(AdapterView parent, View view, int position, long id) { - Log.i(TAG, "OnItemClick pos " + position + " id " + id); + POI poi = adapter.getPOIItem(position); - String poiId = adapter.getItemStringId(position); + Log.i(TAG, "Long Click Event ID: " + poi.id); + Uri uri = null; - Log.i(TAG, "POI " + poiId + " selected"); + if (poi.type.equals(POI.BUS_STOP)) { + Log.i(TAG, "Its a bus stop"); - // Intent i = new Intent(FindActivity.this, SouthamptonUniversityMapActivity.class); - getIntent().putExtra("poi", poiId); - // startActivity(i); + BusStop busStop = (BusStop) poi; - setResult(RESULT_OK, getIntent()); - finish(); - } + uri = Uri.parse("http://id.southampton.ac.uk/bus-stop/" + busStop.id); - public boolean onItemLongClick(AdapterView parent, View view, int position, long id) { + } else if (poi.type.equals(POI.BUILDING)) { + Log.i(TAG, "Its a buildings"); - POI poi = adapter.getPOIItem(position); + Building building = (Building) poi; - Log.i(TAG, "Long Click Event ID: " + poi.id); + uri = Uri.parse("http://id.southampton.ac.uk/building/" + building.id); + } else { + Log.e(TAG, "Error in onItemLongClick"); + return false; + } - if (poi.type.equals(POI.BUS_STOP)) { - Log.i(TAG, "Its a bus stop"); + Log.i(TAG, "Starting a activity for " + uri + " path " + uri.getPath()); - BusStop busStop = (BusStop) poi; + Intent busStopIntent = new Intent(Intent.ACTION_VIEW, uri); + startActivity(busStopIntent); - Intent i = new Intent(FindActivity.this, BusStopActivity.class); - i.putExtra("busStopID", busStop.id); - i.putExtra("busStopName", busStop.description); - startActivityForResult(i, 0); + return true; } - return false; - } - - public void finish() { - getIntent().putExtra("dataChanged", dataChanged); - // startActivity(i); - - setResult(RESULT_OK, getIntent()); - - super.finish(); - } - - public void onLocationChanged(Location location) { - Log.i(TAG, "Got location update for FindActivity"); - userLocation = Util.locationToGeoPoint(location); - if (!searchThread.isAlive()) { - searchThread = new Thread(this); - searchThread.start(); + public void onLocationChanged(Location location) { + Log.i(TAG, "Got location update for FindActivity"); + userLocation = Util.locationToGeoPoint(location); + if (!searchThread.isAlive()) { + searchThread = new Thread(this); + searchThread.start(); + } } - } - public void onProviderDisabled(String arg0) { - // TODO Auto-generated method stub - - } - - public void onProviderEnabled(String provider) { - // TODO Auto-generated method stub - - } - - public void onStatusChanged(String provider, int status, Bundle extras) { - // TODO Auto-generated method stub - - } - - protected void onActivityResult(int requestCode, int resultCode, Intent data) { - Log.i(TAG, "Got activity result"); - if (resultCode == RESULT_OK) { - // A contact was picked. Here we will just display it - // to the user. - - boolean dataChangedInBusTimeActivity = false; - - Bundle bundle = data.getExtras(); - if (bundle == null) { - Log.i(TAG, "Bundle is null"); - } else { - dataChangedInBusTimeActivity = bundle.getBoolean("dataChanged"); - } - - if (dataChangedInBusTimeActivity == true) { - dataChanged = true; - } + public void onProviderDisabled(String arg0) { + } + public void onProviderEnabled(String provider) { } - } + public void onStatusChanged(String provider, int status, Bundle extras) { + } } \ No newline at end of file diff --git a/src/net/cbaines/suma/MapActivity.java b/src/net/cbaines/suma/MapActivity.java index 59c8505..8f555da 100644 --- a/src/net/cbaines/suma/MapActivity.java +++ b/src/net/cbaines/suma/MapActivity.java @@ -241,7 +241,30 @@ public class MapActivity extends OrmLiteBaseActivity implements GeoPoint userLocation = null; Bundle extras = getIntent().getExtras(); - if (extras != null && extras.containsKey("poiPoint")) { + if (getIntent().getDataString() != null) { + + Log.i(TAG, "getIntent().getDataString() " + getIntent().getDataString()); + + String str = getIntent().getDataString().substring(4, getIntent().getDataString().length()); + String[] strParts = str.split(","); + + int lat = Util.doubleToIntE6(Double.valueOf(strParts[0])); + int lng; + + if (strParts[1].contains("?")) { + String zoom = strParts[1].substring(strParts[1].indexOf("?") + 3, strParts[1].length()); + String strLng = strParts[1].substring(0, strParts[1].indexOf("?") - 1); + lng = Util.doubleToIntE6(Double.valueOf(strLng)); + + mapController.setZoom(Integer.valueOf(zoom)); + } else { + lng = Util.doubleToIntE6(Double.valueOf(strParts[1])); + mapController.setZoom(15); + } + + userLocation = new GeoPoint(lat, lng); + + } else if (extras != null && extras.containsKey("poiPoint")) { String poiPoint = getIntent().getExtras().getString("poiPoint"); Log.i(TAG, "poiPoint " + poiPoint); @@ -1091,17 +1114,6 @@ public class MapActivity extends OrmLiteBaseActivity implements } - /* - * public boolean onChildClick(ExpandableListView parent, View v, int - * groupPosition, int childPosition, long id) { - * - * mapView.post(new Runnable() { public void run() { // - * updateEnabledOverlays(); TODO Fix whatever this did? - * mapView.invalidate(); } }); - * - * return true; } - */ - protected Dialog onCreateDialog(int id) { switch (id) { case VIEW_DIALOG_ID: @@ -1190,10 +1202,12 @@ public class MapActivity extends OrmLiteBaseActivity implements Log.i(TAG, "Pressed " + busStop.id); - Intent i = new Intent(this, BusStopActivity.class); - i.putExtra("busStopID", busStop.id); - i.putExtra("busStopName", busStop.description); - 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); + startActivity(busStopIntent); return true; diff --git a/src/net/cbaines/suma/POIDistanceComparator.java b/src/net/cbaines/suma/POIDistanceComparator.java index ef35112..c342d3d 100644 --- a/src/net/cbaines/suma/POIDistanceComparator.java +++ b/src/net/cbaines/suma/POIDistanceComparator.java @@ -24,27 +24,27 @@ import java.util.Comparator; import org.osmdroid.util.GeoPoint; public class POIDistanceComparator implements Comparator { - private final GeoPoint userLocation; - private final boolean useExistingData; - - public POIDistanceComparator(GeoPoint userLocation) { - this(userLocation, false); - } - - public POIDistanceComparator(GeoPoint userLocation, boolean useData) { - super(); - this.userLocation = userLocation; - this.useExistingData = useData; - } - - public int compare(POI poi1, POI poi2) { - if (poi1.distTo == -1 || !useExistingData) { - poi1.distTo = userLocation.distanceTo(poi1.point); + private final GeoPoint userLocation; + private final boolean useExistingData; + + public POIDistanceComparator(GeoPoint userLocation) { + this(userLocation, false); + } + + public POIDistanceComparator(GeoPoint userLocation, boolean useData) { + super(); + this.userLocation = userLocation; + this.useExistingData = useData; } - if (poi2.distTo == -1 || !useExistingData) { - poi2.distTo = userLocation.distanceTo(poi2.point); + + public int compare(POI poi1, POI poi2) { + if (poi1.distTo == -1 || !useExistingData) { + poi1.distTo = userLocation.distanceTo(poi1.point); + } + if (poi2.distTo == -1 || !useExistingData) { + poi2.distTo = userLocation.distanceTo(poi2.point); + } + return poi1.distTo - poi2.distTo; } - return poi1.distTo - poi2.distTo; - } } diff --git a/src/net/cbaines/suma/Polygon.java b/src/net/cbaines/suma/Polygon.java index b10fbc4..55828cb 100644 --- a/src/net/cbaines/suma/Polygon.java +++ b/src/net/cbaines/suma/Polygon.java @@ -24,30 +24,30 @@ import java.io.Serializable; import org.osmdroid.util.GeoPoint; public class Polygon implements Serializable { - /** + /** * */ - private static final long serialVersionUID = 3029139596630651715L; + private static final long serialVersionUID = 3029139596630651715L; - public final GeoPoint[] points; + public final GeoPoint[] points; - Polygon() { - points = null; - } + Polygon() { + points = null; + } + + public Polygon(GeoPoint[] points) { + this.points = points; + } - public Polygon(GeoPoint[] points) { - this.points = points; - } + @Override + public String toString() { + StringBuilder builder = new StringBuilder(); + builder.append("Polygon "); - @Override - public String toString() { - StringBuilder builder = new StringBuilder(); - builder.append("Polygon "); + for (GeoPoint point : points) { + builder.append(point.getLatitudeE6() + " " + point.getLongitudeE6()); + } - for (GeoPoint point : points) { - builder.append(point.getLatitudeE6() + " " + point.getLongitudeE6()); + return builder.toString(); } - - return builder.toString(); - } } diff --git a/src/net/cbaines/suma/Preferences.java b/src/net/cbaines/suma/Preferences.java index 84e1d27..ff8f366 100644 --- a/src/net/cbaines/suma/Preferences.java +++ b/src/net/cbaines/suma/Preferences.java @@ -1,15 +1,15 @@ package net.cbaines.suma; public interface Preferences { - // Preferences - static final String GPS_ENABLED = "GPSEnabled"; - static final boolean GPS_ENABLED_BY_DEFAULT = true; - static final String UNI_LINK_BUS_TIMES = "uniLinkLiveBusTimesEnabled"; - static final boolean UNI_LINK_BUS_TIMES_ENABLED_BY_DEFAULT = true; - static final String NON_UNI_LINK_BUS_TIMES = "nonUniLinkLiveBusTimesEnabled"; - static final boolean NON_UNI_LINK_BUS_TIMES_ENABLED_BY_DEFAULT = false; - static final String NON_UNI_LINK_BUS_STOPS_OVERLAY = "nonUniLinkBusStops"; - static final boolean NON_UNI_LINK_BUS_STOP_OVERLAY_ENABLED_BY_DEFAULT = false; - + // Preferences + static final String GPS_ENABLED = "GPSEnabled"; + static final boolean GPS_ENABLED_BY_DEFAULT = true; + static final String UNI_LINK_BUS_TIMES = "uniLinkLiveBusTimesEnabled"; + static final boolean UNI_LINK_BUS_TIMES_ENABLED_BY_DEFAULT = true; + static final String NON_UNI_LINK_BUS_TIMES = "nonUniLinkLiveBusTimesEnabled"; + static final boolean NON_UNI_LINK_BUS_TIMES_ENABLED_BY_DEFAULT = false; + static final String NON_UNI_LINK_BUS_STOPS_OVERLAY = "nonUniLinkBusStops"; + static final boolean NON_UNI_LINK_BUS_STOP_OVERLAY_ENABLED_BY_DEFAULT = false; + static final String FAVOURITES_PREFERENCES = "favourites"; } diff --git a/src/net/cbaines/suma/PreferencesActivity.java b/src/net/cbaines/suma/PreferencesActivity.java index d72d266..39e6bb2 100644 --- a/src/net/cbaines/suma/PreferencesActivity.java +++ b/src/net/cbaines/suma/PreferencesActivity.java @@ -27,26 +27,26 @@ import android.preference.PreferenceManager; public class PreferencesActivity extends PreferenceActivity implements Preferences { - @Override - protected void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); - final SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(this); - final Editor editor = sharedPrefs.edit(); - if (!sharedPrefs.contains(GPS_ENABLED)) { - editor.putBoolean(GPS_ENABLED, GPS_ENABLED_BY_DEFAULT); - } - if (!sharedPrefs.contains(UNI_LINK_BUS_TIMES)) { - editor.putBoolean(UNI_LINK_BUS_TIMES, UNI_LINK_BUS_TIMES_ENABLED_BY_DEFAULT); - } - if (!sharedPrefs.contains(NON_UNI_LINK_BUS_TIMES)) { - editor.putBoolean(NON_UNI_LINK_BUS_TIMES, NON_UNI_LINK_BUS_TIMES_ENABLED_BY_DEFAULT); - } - if (!sharedPrefs.contains(NON_UNI_LINK_BUS_STOPS_OVERLAY)) { - editor.putBoolean(NON_UNI_LINK_BUS_STOPS_OVERLAY, NON_UNI_LINK_BUS_STOP_OVERLAY_ENABLED_BY_DEFAULT); - } - editor.commit(); + final SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(this); + final Editor editor = sharedPrefs.edit(); + if (!sharedPrefs.contains(GPS_ENABLED)) { + editor.putBoolean(GPS_ENABLED, GPS_ENABLED_BY_DEFAULT); + } + if (!sharedPrefs.contains(UNI_LINK_BUS_TIMES)) { + editor.putBoolean(UNI_LINK_BUS_TIMES, UNI_LINK_BUS_TIMES_ENABLED_BY_DEFAULT); + } + if (!sharedPrefs.contains(NON_UNI_LINK_BUS_TIMES)) { + editor.putBoolean(NON_UNI_LINK_BUS_TIMES, NON_UNI_LINK_BUS_TIMES_ENABLED_BY_DEFAULT); + } + if (!sharedPrefs.contains(NON_UNI_LINK_BUS_STOPS_OVERLAY)) { + editor.putBoolean(NON_UNI_LINK_BUS_STOPS_OVERLAY, NON_UNI_LINK_BUS_STOP_OVERLAY_ENABLED_BY_DEFAULT); + } + editor.commit(); - addPreferencesFromResource(R.xml.preferences); - } + addPreferencesFromResource(R.xml.preferences); + } } \ No newline at end of file diff --git a/src/net/cbaines/suma/RouteColorConstants.java b/src/net/cbaines/suma/RouteColorConstants.java index ba4fa36..683031b 100644 --- a/src/net/cbaines/suma/RouteColorConstants.java +++ b/src/net/cbaines/suma/RouteColorConstants.java @@ -22,9 +22,9 @@ package net.cbaines.suma; import android.graphics.Color; public interface RouteColorConstants { - public final int U1 = Color.rgb(0, 139, 208); - public final int U1N = Color.rgb(0, 47, 107); // Dark blue - public final int U2 = Color.rgb(226, 0, 26); - public final int U6 = Color.rgb(247, 168, 0); - public final int U9 = Color.rgb(231, 82, 148); // Pink + public final int U1 = Color.rgb(0, 139, 208); + public final int U1N = Color.rgb(0, 47, 107); // Dark blue + public final int U2 = Color.rgb(226, 0, 26); + public final int U6 = Color.rgb(247, 168, 0); + public final int U9 = Color.rgb(231, 82, 148); // Pink } diff --git a/src/net/cbaines/suma/RouteOverlayItem.java b/src/net/cbaines/suma/RouteOverlayItem.java index 98c4d28..2fce941 100644 --- a/src/net/cbaines/suma/RouteOverlayItem.java +++ b/src/net/cbaines/suma/RouteOverlayItem.java @@ -21,18 +21,17 @@ package net.cbaines.suma; import java.util.ArrayList; - import org.osmdroid.util.GeoPoint; import org.osmdroid.views.overlay.OverlayItem; public class RouteOverlayItem extends OverlayItem { - ArrayList route; + ArrayList route; - public RouteOverlayItem(String aTitle, String aDescription, ArrayList route) { - super(aTitle, aDescription, new GeoPoint(0, 0)); - this.route = route; + public RouteOverlayItem(String aTitle, String aDescription, ArrayList route) { + super(aTitle, aDescription, new GeoPoint(0, 0)); + this.route = route; - } + } } diff --git a/src/net/cbaines/suma/RouteStops.java b/src/net/cbaines/suma/RouteStops.java index 29fb18c..2f6c00a 100644 --- a/src/net/cbaines/suma/RouteStops.java +++ b/src/net/cbaines/suma/RouteStops.java @@ -24,34 +24,37 @@ import com.j256.ormlite.table.DatabaseTable; @DatabaseTable(tableName = "routestops") public class RouteStops { - public final static String STOP_ID_FIELD_NAME = "stop_id"; - public final static String ROUTE_ID_FIELD_NAME = "route_id"; - public final static String SEQUENCE_ID_FIELD_NAME = "sequence"; - - /** - * This id is generated by the database and set on the object when it is passed to the create method. An id is needed in case we need to update or delete - * this object in the future. - */ - @DatabaseField(generatedId = true) - int id; - - @DatabaseField - int sequence; - - // This is a foreign object which just stores the id from the User object in this table. - @DatabaseField(foreign = true, columnName = STOP_ID_FIELD_NAME, indexName = "routestops_routestop_idx") - BusStop busStop; - - // This is a foreign object which just stores the id from the Post object in this table. - @DatabaseField(foreign = true, columnName = ROUTE_ID_FIELD_NAME, indexName = "routestops_routestop_idx") - BusRoute busRoute; - - RouteStops() { - } - - public RouteStops(BusStop stop, BusRoute route, int sequence) { - this.busStop = stop; - this.busRoute = route; - this.sequence = sequence; - } + public final static String STOP_ID_FIELD_NAME = "stop_id"; + public final static String ROUTE_ID_FIELD_NAME = "route_id"; + public final static String SEQUENCE_ID_FIELD_NAME = "sequence"; + + /** + * This id is generated by the database and set on the object when it is + * passed to the create method. An id is needed in case we need to update or + * delete this object in the future. + */ + @DatabaseField(generatedId = true) + int id; + + @DatabaseField + int sequence; + + // This is a foreign object which just stores the id from the User object in + // this table. + @DatabaseField(foreign = true, columnName = STOP_ID_FIELD_NAME, indexName = "routestops_routestop_idx") + BusStop busStop; + + // This is a foreign object which just stores the id from the Post object in + // this table. + @DatabaseField(foreign = true, columnName = ROUTE_ID_FIELD_NAME, indexName = "routestops_routestop_idx") + BusRoute busRoute; + + RouteStops() { + } + + public RouteStops(BusStop stop, BusRoute route, int sequence) { + this.busStop = stop; + this.busRoute = route; + this.sequence = sequence; + } } diff --git a/src/net/cbaines/suma/Site.java b/src/net/cbaines/suma/Site.java index b13b9ae..f22f666 100644 --- a/src/net/cbaines/suma/Site.java +++ b/src/net/cbaines/suma/Site.java @@ -28,28 +28,28 @@ import com.j256.ormlite.table.DatabaseTable; @DatabaseTable(tableName = "sites") public class Site extends POI { - public static final String NAME_FIELD_NAME = "name"; - public static final String OUTLINE_FIELD_NAME = "outline"; + public static final String NAME_FIELD_NAME = "name"; + public static final String OUTLINE_FIELD_NAME = "outline"; - @DatabaseField(canBeNull = false) - public String name; + @DatabaseField(canBeNull = false) + public String name; - @DatabaseField(dataType = DataType.SERIALIZABLE, canBeNull = true) - public Polygon outline; + @DatabaseField(dataType = DataType.SERIALIZABLE, canBeNull = true) + public Polygon outline; - public Site(String id, String name, GeoPoint point, Polygon outline) { - super(id, point); - this.name = name; - this.outline = outline; - this.type = POI.SITE; - } + public Site(String id, String name, GeoPoint point, Polygon outline) { + super(id, point); + this.name = name; + this.outline = outline; + this.type = POI.SITE; + } - Site() { - this.type = POI.SITE; - } + Site() { + this.type = POI.SITE; + } - public String toString() { - return name; - } + public String toString() { + return name; + } } diff --git a/src/net/cbaines/suma/Stop.java b/src/net/cbaines/suma/Stop.java index 94fc908..3221ed5 100644 --- a/src/net/cbaines/suma/Stop.java +++ b/src/net/cbaines/suma/Stop.java @@ -31,126 +31,127 @@ import android.text.format.DateUtils; */ public class Stop { - // public static final String BUS_FIELD_NAME = "bus"; - // public static final String BUS_STOP_FIELD_NAME = "busStop"; - // public static final String ARIVAL_TIME_FIELD_NAME = "arivalTime"; - // public static final String FETCH_TIME_FIELD_NAME = "timeOfFetch"; - - /** - * The Bus stopping at the stop - */ - Bus bus; - - /** - * The busStop that the bus is stopping at - */ - BusStop busStop; - - /** - * The time that the bus is estimated to arrive - */ - Date arivalTime; - - /** - * The time this data was fetched from the server - */ - Date timeOfFetch; - - /** - * Is the time live, or just expected - */ - boolean live; - - /** - * Assumed to be the number of seconds since this data was fetched from the ROMANSE system? - */ - int age; - - /** - * - * @param bus - * @param busStop - * @param arivalTime - * @param timeOfFetch - */ - public Stop(Bus bus, BusStop busStop, Date arivalTime, Date timeOfFetch, boolean live) { - this.busStop = busStop; - this.bus = bus; - this.arivalTime = arivalTime; - this.timeOfFetch = timeOfFetch; - this.live = live; - } - - /** - * - * @return - */ - public String getTimeToArival() { - if (arivalTime.getTime() - System.currentTimeMillis() <= 60000) { - return "Due"; - } else { - return (String) DateUtils.getRelativeTimeSpanString(arivalTime.getTime(), System.currentTimeMillis(), - DateUtils.MINUTE_IN_MILLIS); + // public static final String BUS_FIELD_NAME = "bus"; + // public static final String BUS_STOP_FIELD_NAME = "busStop"; + // public static final String ARIVAL_TIME_FIELD_NAME = "arivalTime"; + // public static final String FETCH_TIME_FIELD_NAME = "timeOfFetch"; + + /** + * The Bus stopping at the stop + */ + Bus bus; + + /** + * The busStop that the bus is stopping at + */ + BusStop busStop; + + /** + * The time that the bus is estimated to arrive + */ + Date arivalTime; + + /** + * The time this data was fetched from the server + */ + Date timeOfFetch; + + /** + * Is the time live, or just expected + */ + boolean live; + + /** + * Assumed to be the number of seconds since this data was fetched from the + * ROMANSE system? + */ + int age; + + /** + * + * @param bus + * @param busStop + * @param arivalTime + * @param timeOfFetch + */ + public Stop(Bus bus, BusStop busStop, Date arivalTime, Date timeOfFetch, boolean live) { + this.busStop = busStop; + this.bus = bus; + this.arivalTime = arivalTime; + this.timeOfFetch = timeOfFetch; + this.live = live; } - } - - public String getShortTimeToArival() { - if (arivalTime.getTime() - System.currentTimeMillis() <= 60000) { - return "Due"; - } else { - String time = (String) DateUtils.getRelativeTimeSpanString(arivalTime.getTime(), - System.currentTimeMillis(), DateUtils.MINUTE_IN_MILLIS); - time = time.replace("in ", ""); - time = time.replace(" minutes", "m"); - time = time.replace(" minute", "m"); - return time; + + /** + * + * @return + */ + public String getTimeToArival() { + if (arivalTime.getTime() - System.currentTimeMillis() <= 60000) { + return "Due"; + } else { + return (String) DateUtils.getRelativeTimeSpanString(arivalTime.getTime(), System.currentTimeMillis(), + DateUtils.MINUTE_IN_MILLIS); + } + } + + public String getShortTimeToArival() { + if (arivalTime.getTime() - System.currentTimeMillis() <= 60000) { + return "Due"; + } else { + String time = (String) DateUtils.getRelativeTimeSpanString(arivalTime.getTime(), + System.currentTimeMillis(), DateUtils.MINUTE_IN_MILLIS); + time = time.replace("in ", ""); + time = time.replace(" minutes", "m"); + time = time.replace(" minute", "m"); + return time; + } + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((arivalTime == null) ? 0 : arivalTime.hashCode()); + result = prime * result + ((bus == null) ? 0 : bus.hashCode()); + result = prime * result + ((busStop == null) ? 0 : busStop.hashCode()); + return result; + } + + /** + * A printout of the stop data for debugging + */ + @Override + public String toString() { + return "Stop [bus=" + bus + ", busStop=" + busStop + ", arivalTime=" + arivalTime + "]"; + } + + @Override + // TODO: If this is used, the paramaters need to be checked? + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + Stop other = (Stop) obj; + if (arivalTime == null) { + if (other.arivalTime != null) + return false; + } else if (!arivalTime.equals(other.arivalTime)) + return false; + if (bus == null) { + if (other.bus != null) + return false; + } else if (!bus.equals(other.bus)) + return false; + if (busStop == null) { + if (other.busStop != null) + return false; + } else if (!busStop.equals(other.busStop)) + return false; + return true; } - } - - @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + ((arivalTime == null) ? 0 : arivalTime.hashCode()); - result = prime * result + ((bus == null) ? 0 : bus.hashCode()); - result = prime * result + ((busStop == null) ? 0 : busStop.hashCode()); - return result; - } - - /** - * A printout of the stop data for debugging - */ - @Override - public String toString() { - return "Stop [bus=" + bus + ", busStop=" + busStop + ", arivalTime=" + arivalTime + "]"; - } - - @Override - // TODO: If this is used, the paramaters need to be checked? - public boolean equals(Object obj) { - if (this == obj) - return true; - if (obj == null) - return false; - if (getClass() != obj.getClass()) - return false; - Stop other = (Stop) obj; - if (arivalTime == null) { - if (other.arivalTime != null) - return false; - } else if (!arivalTime.equals(other.arivalTime)) - return false; - if (bus == null) { - if (other.bus != null) - return false; - } else if (!bus.equals(other.bus)) - return false; - if (busStop == null) { - if (other.busStop != null) - return false; - } else if (!busStop.equals(other.busStop)) - return false; - return true; - } } diff --git a/src/net/cbaines/suma/StopView.java b/src/net/cbaines/suma/StopView.java index f942137..afe8664 100644 --- a/src/net/cbaines/suma/StopView.java +++ b/src/net/cbaines/suma/StopView.java @@ -22,8 +22,8 @@ package net.cbaines.suma; import java.sql.SQLException; import java.text.DateFormat; -import android.app.Activity; import android.content.Intent; +import android.net.Uri; import android.util.Log; import android.view.Gravity; import android.view.View; @@ -36,8 +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, - OnLongClickListener { +public class StopView extends LinearLayout implements OnClickListener, OnLongClickListener { // private final ImageView icon; @@ -66,10 +65,8 @@ public class StopView extends LinearLayout implements OnClickListener, setStop(stop); - addView(name, new LayoutParams(LayoutParams.WRAP_CONTENT, - LayoutParams.WRAP_CONTENT)); - addView(time, new LayoutParams(LayoutParams.FILL_PARENT, - LayoutParams.WRAP_CONTENT)); + addView(name, new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)); + addView(time, new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT)); } public void setStop(Stop stop) { @@ -81,8 +78,7 @@ public class StopView extends LinearLayout implements OnClickListener, name.setText(stop.bus.getName()); time.setText(stop.getTimeToArival()); - DatabaseHelper helper = OpenHelperManager.getHelper(context, - DatabaseHelper.class); + DatabaseHelper helper = OpenHelperManager.getHelper(context, DatabaseHelper.class); try { Dao busDao = helper.getBusDao(); @@ -91,31 +87,19 @@ public class StopView extends LinearLayout implements OnClickListener, if (stop.bus.id != null) { if (stop.live) { - onClickMessage = "Bus " - + stop.bus.toString() - + " at " - + DateFormat.getTimeInstance(DateFormat.SHORT) - .format(stop.arivalTime); + 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); + 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); + 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) { @@ -128,8 +112,7 @@ public class StopView extends LinearLayout implements OnClickListener, public void onClick(View v) { if (context.activityToast == null) { - context.activityToast = Toast.makeText(context, onClickMessage, - Toast.LENGTH_SHORT); + context.activityToast = Toast.makeText(context, onClickMessage, Toast.LENGTH_SHORT); } else { context.activityToast.setText(onClickMessage); context.activityToast.setDuration(Toast.LENGTH_SHORT); @@ -139,8 +122,7 @@ public class StopView extends LinearLayout implements OnClickListener, } public boolean onLongClick(View v) { - DatabaseHelper helper = OpenHelperManager.getHelper(context, - DatabaseHelper.class); + DatabaseHelper helper = OpenHelperManager.getHelper(context, DatabaseHelper.class); try { Dao busDao = helper.getBusDao(); @@ -149,38 +131,31 @@ public class StopView extends LinearLayout implements OnClickListener, busDao.refresh(stop.bus); busRouteDao.refresh(stop.bus.route); - Log.i("StopView", "Bus route " + stop.bus.route + " Uni-Link " - + stop.bus.route.uniLink + " Bus ID " + stop.bus.id); + Log.i("StopView", "Bus route " + stop.bus.route + " Uni-Link " + stop.bus.route.uniLink + " Bus ID " + + stop.bus.id); if (stop.bus.id != null && stop.bus.route.uniLink) { - Intent i = new Intent(context, BusActivity.class); - i.putExtra("busID", stop.bus.id); - i.putExtra("busStopID", stop.busStop.id); - ((Activity) context).startActivityForResult(i, 0); + Uri uri = Uri.parse("http://id.southampton.ac.uk/bus/" + stop.bus.id); + + Intent busStopIntent = new Intent(Intent.ACTION_VIEW, uri); + busStopIntent.putExtra("busStopID", stop.busStop.id); + context.startActivity(busStopIntent); } else { if (!stop.bus.route.uniLink) { if (context.activityToast == null) { - context.activityToast = Toast - .makeText( - context, - "Bus schedules only avalible for Uni-Link buses", - Toast.LENGTH_SHORT); + context.activityToast = Toast.makeText(context, + "Bus schedules only avalible for Uni-Link buses", Toast.LENGTH_SHORT); } else { - context.activityToast - .setText("Bus schedules only avalible for Uni-Link buses"); + context.activityToast.setText("Bus schedules only avalible for Uni-Link buses"); context.activityToast.setDuration(Toast.LENGTH_SHORT); } context.activityToast.show(); } else { if (context.activityToast == null) { - context.activityToast = Toast - .makeText( - context, - "Bus schedules not avalible for unidentified buses", - Toast.LENGTH_SHORT); + context.activityToast = Toast.makeText(context, + "Bus schedules not avalible for unidentified buses", Toast.LENGTH_SHORT); } else { - context.activityToast - .setText("Bus schedules not avalible for unidentified buses"); + context.activityToast.setText("Bus schedules not avalible for unidentified buses"); context.activityToast.setDuration(Toast.LENGTH_SHORT); } context.activityToast.show(); diff --git a/src/net/cbaines/suma/StringDistanceComparator.java b/src/net/cbaines/suma/StringDistanceComparator.java index 9230f1c..d42451f 100644 --- a/src/net/cbaines/suma/StringDistanceComparator.java +++ b/src/net/cbaines/suma/StringDistanceComparator.java @@ -21,113 +21,114 @@ package net.cbaines.suma; import java.util.Comparator; - public class StringDistanceComparator implements Comparator { - private String userString; + private String userString; - // private static final String TAG = "StringDistanceComparator"; + // private static final String TAG = "StringDistanceComparator"; - public StringDistanceComparator(String userString) { - super(); - this.userString = userString; - } + public StringDistanceComparator(String userString) { + super(); + this.userString = userString; + } - public int compare(POI poi1, POI poi2) { - int distTo1 = LD(userString, poi1.toString()); - // Log.i(TAG, "Comparing " + userString + " and " + poi1.toString() + " got dist " + distTo1); - int distTo2 = LD(userString, poi2.toString()); - // Log.i(TAG, "Comparing " + userString + " and " + poi2.toString() + " got dist " + distTo2); - return distTo1 - distTo2; - } + public int compare(POI poi1, POI poi2) { + int distTo1 = LD(userString, poi1.toString()); + // Log.i(TAG, "Comparing " + userString + " and " + poi1.toString() + + // " got dist " + distTo1); + int distTo2 = LD(userString, poi2.toString()); + // Log.i(TAG, "Comparing " + userString + " and " + poi2.toString() + + // " got dist " + distTo2); + return distTo1 - distTo2; + } - // Below is public domain code from http://www.merriampark.com/ld.htm + // Below is public domain code from http://www.merriampark.com/ld.htm - // **************************** - // Get minimum of three values - // **************************** + // **************************** + // Get minimum of three values + // **************************** - private int Minimum(int a, int b, int c) { - int mi; + private int Minimum(int a, int b, int c) { + int mi; + + mi = a; + if (b < mi) { + mi = b; + } + if (c < mi) { + mi = c; + } + return mi; - mi = a; - if (b < mi) { - mi = b; - } - if (c < mi) { - mi = c; - } - return mi; - - } - - // ***************************** - // Compute Levenshtein distance - // ***************************** - - public int LD(String s, String t) { - int d[][]; // matrix - int n; // length of s - int m; // length of t - int i; // iterates through s - int j; // iterates through t - char s_i; // ith character of s - char t_j; // jth character of t - int cost; // cost - - // Step 1 - - n = s.length(); - m = t.length(); - if (n == 0) { - return m; - } - if (m == 0) { - return n; } - d = new int[n + 1][m + 1]; - // Step 2 + // ***************************** + // Compute Levenshtein distance + // ***************************** + + public int LD(String s, String t) { + int d[][]; // matrix + int n; // length of s + int m; // length of t + int i; // iterates through s + int j; // iterates through t + char s_i; // ith character of s + char t_j; // jth character of t + int cost; // cost + + // Step 1 + + n = s.length(); + m = t.length(); + if (n == 0) { + return m; + } + if (m == 0) { + return n; + } + d = new int[n + 1][m + 1]; + + // Step 2 - for (i = 0; i <= n; i++) { - d[i][0] = i; - } + for (i = 0; i <= n; i++) { + d[i][0] = i; + } - for (j = 0; j <= m; j++) { - d[0][j] = j; - } + for (j = 0; j <= m; j++) { + d[0][j] = j; + } - // Step 3 + // Step 3 - for (i = 1; i <= n; i++) { + for (i = 1; i <= n; i++) { - s_i = s.charAt(i - 1); + s_i = s.charAt(i - 1); - // Step 4 + // Step 4 - for (j = 1; j <= m; j++) { + for (j = 1; j <= m; j++) { - t_j = t.charAt(j - 1); + t_j = t.charAt(j - 1); - // Step 5 + // Step 5 - if (s_i == t_j) { - cost = 0; - } else { - cost = 1; - } + if (s_i == t_j) { + cost = 0; + } else { + cost = 1; + } - // Step 6 + // Step 6 - d[i][j] = Minimum(d[i - 1][j] + 1, d[i][j - 1] + 1, d[i - 1][j - 1] + cost); + d[i][j] = Minimum(d[i - 1][j] + 1, d[i][j - 1] + 1, d[i - 1][j - 1] + cost); - } + } - } + } - // Step 7 + // Step 7 - return d[n][m]; + return d[n][m]; - } + } } diff --git a/src/net/cbaines/suma/Timetable.java b/src/net/cbaines/suma/Timetable.java index 93c8e8d..5b26d24 100644 --- a/src/net/cbaines/suma/Timetable.java +++ b/src/net/cbaines/suma/Timetable.java @@ -24,46 +24,46 @@ import java.util.Date; public class Timetable extends ArrayList { - /** + /** * */ - private static final long serialVersionUID = -9021303378059511643L; + private static final long serialVersionUID = -9021303378059511643L; - Date fetchTime; + Date fetchTime; - public String toString() { - StringBuilder sb = new StringBuilder(); - for (Stop stop : this) { - sb.append(stop + "\n"); + public String toString() { + StringBuilder sb = new StringBuilder(); + for (Stop stop : this) { + sb.append(stop + "\n"); + } + return sb.toString(); } - return sb.toString(); - } - public boolean contains(Stop otherStop, boolean toTheMinute) { - if (otherStop == null) - return false; - if (toTheMinute) { - for (Stop stop : this) { - if (otherStop.bus != null && stop.bus != null && otherStop.bus.equals(stop.bus)) { - if (Math.abs(otherStop.arivalTime.getTime() - stop.arivalTime.getTime()) < 60000) { - return true; - } - } else if (otherStop.busStop.equals(stop.busStop)) { - if (otherStop.arivalTime == null && stop.arivalTime == null) { - return true; - } else { - if (otherStop.arivalTime == null || stop.arivalTime == null) { - return false; - } else if (Math.abs(otherStop.arivalTime.getTime() - stop.arivalTime.getTime()) < 60000) { - return true; + public boolean contains(Stop otherStop, boolean toTheMinute) { + if (otherStop == null) + return false; + if (toTheMinute) { + for (Stop stop : this) { + if (otherStop.bus != null && stop.bus != null && otherStop.bus.equals(stop.bus)) { + if (Math.abs(otherStop.arivalTime.getTime() - stop.arivalTime.getTime()) < 60000) { + return true; + } + } else if (otherStop.busStop.equals(stop.busStop)) { + if (otherStop.arivalTime == null && stop.arivalTime == null) { + return true; + } else { + if (otherStop.arivalTime == null || stop.arivalTime == null) { + return false; + } else if (Math.abs(otherStop.arivalTime.getTime() - stop.arivalTime.getTime()) < 60000) { + return true; + } + } + } } - } + return false; + } else { + return this.contains(otherStop); } - } - return false; - } else { - return this.contains(otherStop); } - } } diff --git a/src/net/cbaines/suma/TimetableAdapter.java b/src/net/cbaines/suma/TimetableAdapter.java index 9ec7a72..16b3ac9 100644 --- a/src/net/cbaines/suma/TimetableAdapter.java +++ b/src/net/cbaines/suma/TimetableAdapter.java @@ -28,65 +28,65 @@ import android.widget.BaseAdapter; public class TimetableAdapter extends BaseAdapter { - private final BusStopActivity context; - private Timetable timetable; - private final Animation a; - private boolean[] changed; + private final BusStopActivity context; + private Timetable timetable; + private final Animation a; + private boolean[] changed; - private static final String TAG = "TimetableAdapter"; + private static final String TAG = "TimetableAdapter"; - public TimetableAdapter(BusStopActivity context, Timetable timetable) { - this.context = context; - this.timetable = timetable; - this.a = AnimationUtils.loadAnimation(context, R.anim.updated_stop_view); - } + public TimetableAdapter(BusStopActivity context, Timetable timetable) { + this.context = context; + this.timetable = timetable; + this.a = AnimationUtils.loadAnimation(context, R.anim.updated_stop_view); + } - public View getView(int position, View convertView, ViewGroup parent) { - Log.i(TAG, "Returning stop " + position + " " + timetable.get(position)); + public View getView(int position, View convertView, ViewGroup parent) { + Log.i(TAG, "Returning stop " + position + " " + timetable.get(position)); - StopView stopView; - if (convertView == null) { - stopView = new StopView(context, timetable.get(position)); - } else { - stopView = (StopView) convertView; - stopView.setStop(timetable.get(position)); - } + StopView stopView; + if (convertView == null) { + stopView = new StopView(context, timetable.get(position)); + } else { + stopView = (StopView) convertView; + stopView.setStop(timetable.get(position)); + } - if (changed == null || changed[position]) { - a.reset(); - stopView.startAnimation(a); - Log.i(TAG, "Animating it"); - } + if (changed == null || changed[position]) { + a.reset(); + stopView.startAnimation(a); + Log.i(TAG, "Animating it"); + } - return stopView; - } + return stopView; + } - public int getCount() { - return timetable.size(); - } + public int getCount() { + return timetable.size(); + } - public Object getItem(int position) { - return position; - } + public Object getItem(int position) { + return position; + } - public long getItemId(int position) { - return position; - } + public long getItemId(int position) { + return position; + } - public void updateTimetable(Timetable newTimetable) { - Log.v(TAG, "Old timetable " + timetable); - Log.v(TAG, "Adaptor loading new timetable"); - changed = new boolean[newTimetable.size()]; - for (int i = 0; i < newTimetable.size(); i++) { - if (!timetable.contains(newTimetable.get(i), true)) { - changed[i] = true; - Log.i(TAG, "Old timetable does not contain: " + newTimetable.get(i)); - } else { - Log.i(TAG, "Old timetable contains: " + newTimetable.get(i)); - changed[i] = false; - } + public void updateTimetable(Timetable newTimetable) { + Log.v(TAG, "Old timetable " + timetable); + Log.v(TAG, "Adaptor loading new timetable"); + changed = new boolean[newTimetable.size()]; + for (int i = 0; i < newTimetable.size(); i++) { + if (!timetable.contains(newTimetable.get(i), true)) { + changed[i] = true; + Log.i(TAG, "Old timetable does not contain: " + newTimetable.get(i)); + } else { + Log.i(TAG, "Old timetable contains: " + newTimetable.get(i)); + changed[i] = false; + } + } + timetable = newTimetable; + this.notifyDataSetChanged(); } - timetable = newTimetable; - this.notifyDataSetChanged(); - } } diff --git a/src/net/cbaines/suma/Util.java b/src/net/cbaines/suma/Util.java index 420d848..89a9e07 100644 --- a/src/net/cbaines/suma/Util.java +++ b/src/net/cbaines/suma/Util.java @@ -21,7 +21,6 @@ package net.cbaines.suma; import java.util.ArrayList; - import org.osmdroid.util.GeoPoint; import android.location.Location; @@ -29,68 +28,69 @@ import android.util.Log; public class Util { - private static final String TAG = "Util"; - - public static GeoPoint csLatLongToGeoPoint(String lat, String lng) { - try { - double dLat = Double.valueOf(lat).doubleValue(); - double dLng = Double.valueOf(lng).doubleValue(); - int iLat = (int) (dLat * 1e6); - int iLng = (int) (dLng * 1e6); - return new GeoPoint(iLat, iLng); - } catch (NumberFormatException e) { - Log.e(TAG, "Error formating " + lat + " " + lng, e); - throw e; + private static final String TAG = "Util"; + + public static GeoPoint csLatLongToGeoPoint(String lat, String lng) { + try { + double dLat = Double.valueOf(lat).doubleValue(); + double dLng = Double.valueOf(lng).doubleValue(); + int iLat = (int) (dLat * 1e6); + int iLng = (int) (dLng * 1e6); + return new GeoPoint(iLat, iLng); + } catch (NumberFormatException e) { + Log.e(TAG, "Error formating " + lat + " " + lng, e); + throw e; + } } - } - - public static GeoPoint ssLatLongToGeoPoint(String lat, String lng) { - try { - - double dLat = Double.valueOf(lat).doubleValue(); - double dLng = Double.valueOf(lng).doubleValue(); - int iLat = (int) (dLat * 1e6); - int iLng = (int) (dLng * 1e6); - return new GeoPoint(iLat, iLng); - } catch (NumberFormatException e) { - Log.e(TAG, "Error formating " + lat + " " + lng, e); - throw e; + + public static GeoPoint ssLatLongToGeoPoint(String lat, String lng) { + try { + + double dLat = Double.valueOf(lat).doubleValue(); + double dLng = Double.valueOf(lng).doubleValue(); + int iLat = (int) (dLat * 1e6); + int iLng = (int) (dLng * 1e6); + return new GeoPoint(iLat, iLng); + } catch (NumberFormatException e) { + Log.e(TAG, "Error formating " + lat + " " + lng, e); + throw e; + } } - } - public static Polygon csPolygonToPolygon(String str) { - // Log.i(TAG, "Getting poly from " + str); - ArrayList geoPoints = new ArrayList(); + public static Polygon csPolygonToPolygon(String str) { + // Log.i(TAG, "Getting poly from " + str); + ArrayList geoPoints = new ArrayList(); - String[] latLongPoints = str.split(","); - for (int point = 0; point < latLongPoints.length; point++) { - // Log.i(TAG, "LatLong point " + point + " " + latLongPoints[point]); + String[] latLongPoints = str.split(","); + for (int point = 0; point < latLongPoints.length; point++) { + // Log.i(TAG, "LatLong point " + point + " " + + // latLongPoints[point]); - String[] latLongs = latLongPoints[point].split(" "); - GeoPoint geoPoint = ssLatLongToGeoPoint(latLongs[1], latLongs[0]); - geoPoints.add(geoPoint); - } + String[] latLongs = latLongPoints[point].split(" "); + GeoPoint geoPoint = ssLatLongToGeoPoint(latLongs[1], latLongs[0]); + geoPoints.add(geoPoint); + } - return new Polygon(geoPoints.toArray(new GeoPoint[0])); - } + return new Polygon(geoPoints.toArray(new GeoPoint[0])); + } - public static int doubleToIntE6(double dub) { - return (int) (dub * 1e6); - } + public static int doubleToIntE6(double dub) { + return (int) (dub * 1e6); + } - public static double E6IntToDouble(int integer) { - return (double) (integer / 1e6); - } + public static double E6IntToDouble(int integer) { + return (double) (integer / 1e6); + } - public static GeoPoint locationToGeoPoint(Location loc) { - return new GeoPoint(doubleToIntE6(loc.getLatitude()), doubleToIntE6(loc.getLongitude())); - } + public static GeoPoint locationToGeoPoint(Location loc) { + return new GeoPoint(doubleToIntE6(loc.getLatitude()), doubleToIntE6(loc.getLongitude())); + } - public static Location geoPointToLocation(GeoPoint point) { - Location loc = new Location(""); - loc.setLatitude(E6IntToDouble(point.getLatitudeE6())); - loc.setLongitude(E6IntToDouble(point.getLongitudeE6())); - return loc; - } + public static Location geoPointToLocation(GeoPoint point) { + Location loc = new Location(""); + loc.setLatitude(E6IntToDouble(point.getLatitudeE6())); + loc.setLongitude(E6IntToDouble(point.getLongitudeE6())); + return loc; + } } diff --git a/src/net/cbaines/suma/ViewDialog.java b/src/net/cbaines/suma/ViewDialog.java index e97cbdf..572ac8a 100644 --- a/src/net/cbaines/suma/ViewDialog.java +++ b/src/net/cbaines/suma/ViewDialog.java @@ -61,7 +61,9 @@ class ViewDialog extends Dialog implements OnChildClickListener { buildingTypes = context.getResources().getStringArray(R.array.buildingTypes); other = context.getResources().getStringArray(R.array.utilityOverlays); groupHeadings = context.getResources().getStringArray(R.array.preferencesHeadings); - siteNames = MapActivity.SITE_NAMES; // TODO: Temp hack, should be included in the strings res for translation + siteNames = MapActivity.SITE_NAMES; // TODO: Temp hack, should be + // included in the strings res for + // translation // purposes? setContentView(R.layout.view_dialog); @@ -156,7 +158,8 @@ class ViewDialog extends Dialog implements OnChildClickListener { return groupPosition * 50 + childPosition; } - public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent) { + public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView, + ViewGroup parent) { View v = null; if (convertView != null) v = convertView; @@ -183,9 +186,11 @@ class ViewDialog extends Dialog implements OnChildClickListener { cb.setChecked(activityPrefs.getBoolean(str, MapActivity.BUS_ROUTE_OVERLAYS_ENABLED_BY_DEFAULT)); } else if (groupPosition == 2) { if (childPosition == 0) { - cb.setChecked(activityPrefs.getBoolean(str, MapActivity.RESIDENTIAL_BUILDING_OVERLAY_ENABLED_BY_DEFAULT)); + cb.setChecked(activityPrefs.getBoolean(str, + MapActivity.RESIDENTIAL_BUILDING_OVERLAY_ENABLED_BY_DEFAULT)); } else { - cb.setChecked(activityPrefs.getBoolean(str, MapActivity.NON_RESIDENTIAL_BUILDING_OVERLAY_ENABLED_BY_DEFAULT)); + cb.setChecked(activityPrefs.getBoolean(str, + MapActivity.NON_RESIDENTIAL_BUILDING_OVERLAY_ENABLED_BY_DEFAULT)); } } else if (groupPosition == 3) { cb.setChecked(activityPrefs.getBoolean(str, MapActivity.SITE_OVERLAYS_ENABLED_BY_DEFAULT)); @@ -193,7 +198,8 @@ class ViewDialog extends Dialog implements OnChildClickListener { if (childPosition == 0) { cb.setChecked(activityPrefs.getBoolean(str, MapActivity.SCALE_BAR_OVERLAY_ENABLED_BY_DEFAULT)); } else if (childPosition == 1) { - cb.setChecked(activityPrefs.getBoolean(str, MapActivity.MY_LOCATION_OVERLAY_COMPASS_ENABLED_BY_DEFAULT)); + cb.setChecked(activityPrefs.getBoolean(str, + MapActivity.MY_LOCATION_OVERLAY_COMPASS_ENABLED_BY_DEFAULT)); } else if (childPosition == 2) { cb.setChecked(activityPrefs.getBoolean(str, MapActivity.MY_LOCATION_OVERLAY_ENABLED_BY_DEFAULT)); } -- cgit v1.2.3 From 0b5aefbe0ff01638dd264222c5368ad02a0fe1ee Mon Sep 17 00:00:00 2001 From: Christopher Baines Date: Tue, 28 Feb 2012 19:09:23 +0000 Subject: Fixed two bugs relating to the query on the database not being ordered?, and implemented a new preference option. --- AndroidManifest.xml | 4 +- gen/net/cbaines/suma/R.java | Bin 13305 -> 13617 bytes project.properties | 2 +- res/layout/bus_route_activity.xml | 16 +++--- res/layout/bus_stop_activity.xml | 13 ++--- res/values/strings.xml | 4 ++ res/xml/preferences.xml | 9 ++++ src/net/cbaines/suma/BusRoute.java | 74 +++++++++++++------------- src/net/cbaines/suma/BusStopActivity.java | 10 ++-- src/net/cbaines/suma/DataManager.java | 22 ++++---- src/net/cbaines/suma/DatabaseHelper.java | 8 +-- src/net/cbaines/suma/MapActivity.java | 2 +- src/net/cbaines/suma/POIView.java | 28 +++++++--- src/net/cbaines/suma/Preferences.java | 3 ++ src/net/cbaines/suma/PreferencesActivity.java | 3 ++ src/net/cbaines/suma/RouteStop.java | 63 ++++++++++++++++++++++ src/net/cbaines/suma/RouteStops.java | 60 --------------------- 17 files changed, 182 insertions(+), 139 deletions(-) create mode 100644 src/net/cbaines/suma/RouteStop.java delete mode 100644 src/net/cbaines/suma/RouteStops.java diff --git a/AndroidManifest.xml b/AndroidManifest.xml index 1eb5c8a..42adfec 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -4,7 +4,9 @@ android:versionCode="7" android:versionName="0.4 (alpha)" > - + diff --git a/gen/net/cbaines/suma/R.java b/gen/net/cbaines/suma/R.java index 20027e0..aec5afc 100644 Binary files a/gen/net/cbaines/suma/R.java and b/gen/net/cbaines/suma/R.java differ diff --git a/project.properties b/project.properties index 5a70945..f049142 100644 --- a/project.properties +++ b/project.properties @@ -8,4 +8,4 @@ # project structure. # Project target. -target=android-7 +target=android-10 diff --git a/res/layout/bus_route_activity.xml b/res/layout/bus_route_activity.xml index fde127c..94a0d07 100644 --- a/res/layout/bus_route_activity.xml +++ b/res/layout/bus_route_activity.xml @@ -6,6 +6,12 @@ android:orientation="vertical" android:theme="@android:style/Theme.NoTitleBar" > + + - - + android:textAppearance="?android:attr/textAppearanceMedium" /> + android:textAppearance="?android:attr/textAppearanceMedium" /> + android:text="@string/bustimes_favourite_checkbox_label" + android:textAppearance="?android:attr/textAppearanceMedium" /> + Appearance + Show Identifiers + Showing Identifiers + Hiding Identifiers Positioning GPS GPS Enabled diff --git a/res/xml/preferences.xml b/res/xml/preferences.xml index 4a12e1c..9de3a61 100644 --- a/res/xml/preferences.xml +++ b/res/xml/preferences.xml @@ -1,6 +1,15 @@ + + + diff --git a/src/net/cbaines/suma/BusRoute.java b/src/net/cbaines/suma/BusRoute.java index b4dd603..ff80c66 100644 --- a/src/net/cbaines/suma/BusRoute.java +++ b/src/net/cbaines/suma/BusRoute.java @@ -22,6 +22,7 @@ package net.cbaines.suma; import java.sql.SQLException; import java.util.ArrayList; import java.util.Calendar; +import java.util.Collections; import java.util.HashSet; import java.util.List; import java.util.Set; @@ -64,8 +65,7 @@ public class BusRoute { String label; /** - * The direction the bus is travelling if it is moving through the route and - * sequence is increasing. + * The direction the bus is travelling if it is moving through the route and sequence is increasing. *
    *
  • U1 = A
  • *
  • U2 = B
  • @@ -76,8 +76,7 @@ public class BusRoute { String forwardDirection; /** - * The direction the bus is travelling if it is moving through the route and - * sequence is decreasing. + * The direction the bus is travelling if it is moving through the route and sequence is decreasing. *
      *
    • U1 = C
    • *
    • U2 = C
    • @@ -93,8 +92,7 @@ public class BusRoute { BusRoute() { } - public BusRoute(Integer id, String code, String label, String forwardDirection, String reverseDirection, - boolean uniLink) { + public BusRoute(Integer id, String code, String label, String forwardDirection, String reverseDirection, boolean uniLink) { this.id = id.intValue(); this.code = code; this.label = label; @@ -153,18 +151,19 @@ public class BusRoute { DatabaseHelper helper = OpenHelperManager.getHelper(context, DatabaseHelper.class); try { - Dao routeStopsDao = helper.getRouteStopsDao(); + Dao routeStopsDao = helper.getRouteStopsDao(); Dao busStopDao = helper.getBusStopDao(); - QueryBuilder routeStopsQueryBuilder = routeStopsDao.queryBuilder(); - routeStopsQueryBuilder.where().eq(RouteStops.ROUTE_ID_FIELD_NAME, this.id); - PreparedQuery routeStopsPreparedQuery = routeStopsQueryBuilder.prepare(); + QueryBuilder routeStopsQueryBuilder = routeStopsDao.queryBuilder(); + routeStopsQueryBuilder.where().eq(RouteStop.ROUTE_ID_FIELD_NAME, this.id); + PreparedQuery routeStopsPreparedQuery = routeStopsQueryBuilder.prepare(); - List routeStopsFound = routeStopsDao.query(routeStopsPreparedQuery); + List routeStopsFound = routeStopsDao.query(routeStopsPreparedQuery); + Collections.sort(routeStopsFound); - ArrayList stopIndexs = new ArrayList(); + Set stopIndexs = new HashSet(); - for (RouteStops routeStop : routeStopsFound) { + for (RouteStop routeStop : routeStopsFound) { if (routeStop.busStop.id.equals(busStop.id)) { stopIndexs.add(routeStop.sequence - 1); } @@ -241,18 +240,19 @@ public class BusRoute { } try { - Dao routeStopsDao = helper.getRouteStopsDao(); + Dao routeStopsDao = helper.getRouteStopsDao(); Dao busStopDao = helper.getBusStopDao(); - QueryBuilder routeStopsQueryBuilder = routeStopsDao.queryBuilder(); - routeStopsQueryBuilder.where().eq(RouteStops.ROUTE_ID_FIELD_NAME, this.id); - PreparedQuery routeStopsPreparedQuery = routeStopsQueryBuilder.prepare(); + QueryBuilder routeStopsQueryBuilder = routeStopsDao.queryBuilder(); + routeStopsQueryBuilder.where().eq(RouteStop.ROUTE_ID_FIELD_NAME, this.id); + PreparedQuery routeStopsPreparedQuery = routeStopsQueryBuilder.prepare(); - List routeStopsFound = routeStopsDao.query(routeStopsPreparedQuery); + List routeStopsFound = routeStopsDao.query(routeStopsPreparedQuery); + Collections.sort(routeStopsFound); int stopIndex = -1; - for (RouteStops routeStop : routeStopsFound) { + for (RouteStop routeStop : routeStopsFound) { if (routeStop.busStop.id.equals(busStop.id)) { if (stopIndex == -1) { stopIndex = routeStop.sequence - 1; @@ -377,8 +377,9 @@ public class BusRoute { } if (moveAmount > 0) { - Log.v(TAG, "Moving forward " + moveAmount + " stops from " + busStop + " (" + stopIndex + "/" - + routeStopsFound.size() + ")"); + Log.v(TAG, + "Moving forward " + moveAmount + " stops from " + busStop + " (" + stopIndex + "/" + + routeStopsFound.size() + ")"); int stopWanted = stopIndex + moveAmount; if ((stopWanted + 1) > routeStopsFound.size()) { Log.v(TAG, "Off the end of the route"); @@ -401,9 +402,8 @@ public class BusRoute { Log.v(TAG, "stopWanted " + stopWanted); busStopDao.refresh(routeStopsFound.get(stopWanted).busStop); - Log.v(TAG, - "Moving backwards " + moveAmount + " stops from " + busStop + " to " - + routeStopsFound.get(stopWanted).busStop + " in route " + this); + Log.v(TAG, "Moving backwards " + moveAmount + " stops from " + busStop + " to " + + routeStopsFound.get(stopWanted).busStop + " in route " + this); return routeStopsFound.get(stopWanted).busStop; } @@ -442,14 +442,15 @@ public class BusRoute { try { - Dao routeStopsDao = helper.getRouteStopsDao(); + Dao routeStopsDao = helper.getRouteStopsDao(); Dao busStopDao = helper.getBusStopDao(); - QueryBuilder routeStopsQueryBuilder = routeStopsDao.queryBuilder(); - routeStopsQueryBuilder.where().eq(RouteStops.ROUTE_ID_FIELD_NAME, this.id); - PreparedQuery routeStopsPreparedQuery = routeStopsQueryBuilder.prepare(); + QueryBuilder routeStopsQueryBuilder = routeStopsDao.queryBuilder(); + routeStopsQueryBuilder.where().eq(RouteStop.ROUTE_ID_FIELD_NAME, this.id); + PreparedQuery routeStopsPreparedQuery = routeStopsQueryBuilder.prepare(); - List routeStopsFound = routeStopsDao.query(routeStopsPreparedQuery); + List routeStopsFound = routeStopsDao.query(routeStopsPreparedQuery); + Collections.sort(routeStopsFound); int startStopSeq = -1; int endStopSeq = -1; @@ -500,7 +501,7 @@ public class BusRoute { Log.e(TAG, "Error, unrecognised route " + id); } - for (RouteStops routeStop : routeStopsFound) { + for (RouteStop routeStop : routeStopsFound) { if (routeStop.sequence >= startStopSeq && routeStop.sequence <= endStopSeq) { busStopDao.refresh(routeStop.busStop); busStops.add(routeStop.busStop); @@ -525,16 +526,17 @@ public class BusRoute { try { - Dao routeStopsDao = helper.getRouteStopsDao(); + Dao routeStopsDao = helper.getRouteStopsDao(); Dao busStopDao = helper.getBusStopDao(); - QueryBuilder routeStopsQueryBuilder = routeStopsDao.queryBuilder(); - routeStopsQueryBuilder.where().eq(RouteStops.ROUTE_ID_FIELD_NAME, this.id); - PreparedQuery routeStopsPreparedQuery = routeStopsQueryBuilder.prepare(); + QueryBuilder routeStopsQueryBuilder = routeStopsDao.queryBuilder(); + routeStopsQueryBuilder.where().eq(RouteStop.ROUTE_ID_FIELD_NAME, this.id); + PreparedQuery routeStopsPreparedQuery = routeStopsQueryBuilder.prepare(); - List routeStopsFound = routeStopsDao.query(routeStopsPreparedQuery); + List routeStopsFound = routeStopsDao.query(routeStopsPreparedQuery); + Collections.sort(routeStopsFound); - for (RouteStops routeStop : routeStopsFound) { + for (RouteStop routeStop : routeStopsFound) { busStopDao.refresh(routeStop.busStop); busStops.add(routeStop.busStop); } diff --git a/src/net/cbaines/suma/BusStopActivity.java b/src/net/cbaines/suma/BusStopActivity.java index 55a0bd6..8bded40 100644 --- a/src/net/cbaines/suma/BusStopActivity.java +++ b/src/net/cbaines/suma/BusStopActivity.java @@ -153,15 +153,15 @@ public class BusStopActivity extends OrmLiteBaseActivity impleme busStop = busStopDao.queryForId(busStopID); Dao busRouteDao = helper.getBusRouteDao(); - Dao routeStopsDao = helper.getRouteStopsDao(); + Dao routeStopsDao = helper.getRouteStopsDao(); for (BusRoute route : busRouteDao) { - QueryBuilder queryBuilder = routeStopsDao.queryBuilder(); + QueryBuilder 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 preparedQuery = queryBuilder.prepare(); + PreparedQuery preparedQuery = queryBuilder.prepare(); long count = routeStopsDao.countOf(preparedQuery); diff --git a/src/net/cbaines/suma/DataManager.java b/src/net/cbaines/suma/DataManager.java index 3a550a7..5e8b195 100644 --- a/src/net/cbaines/suma/DataManager.java +++ b/src/net/cbaines/suma/DataManager.java @@ -214,11 +214,11 @@ public class DataManager { Dao busStopDao = helper.getBusStopDao(); Dao busRouteDao = helper.getBusRouteDao(); - Dao routeStopsDao = helper.getRouteStopsDao(); + Dao routeStopsDao = helper.getRouteStopsDao(); TableUtils.clearTable(helper.getConnectionSource(), BusStop.class); TableUtils.clearTable(helper.getConnectionSource(), BusRoute.class); - TableUtils.clearTable(helper.getConnectionSource(), RouteStops.class); + TableUtils.clearTable(helper.getConnectionSource(), RouteStop.class); Log.i(TAG, "Loading busstops from csv"); @@ -340,7 +340,7 @@ public class DataManager { int sequence = Integer.parseInt(dataBits[1]); Log.i(TAG, "Creating RouteStop " + busStop.id + " " + busRoute.code + " " + sequence); - routeStopsDao.create(new RouteStops(busStop, busRoute, sequence)); + routeStopsDao.create(new RouteStop(busStop, busRoute, sequence)); if (busRoute.id == 326) { // U1 busStop.routes = (byte) (busStop.routes | 1); @@ -457,7 +457,7 @@ public class DataManager { helper = OpenHelperManager.getHelper(context, DatabaseHelper.class); if (busRouteDao == null) busRouteDao = helper.getBusRouteDao(); - Dao routeStopsDao = null; + Dao routeStopsDao = null; if (routeStopsDao == null) routeStopsDao = helper.getRouteStopsDao(); if (busDao == null) @@ -568,12 +568,12 @@ public class DataManager { if (destStop != null) { - QueryBuilder routeStopsQueryBuilder = routeStopsDao.queryBuilder(); - routeStopsQueryBuilder.where().eq(RouteStops.ROUTE_ID_FIELD_NAME, route.id).and() - .eq(RouteStops.STOP_ID_FIELD_NAME, destStop.id); - PreparedQuery routeStopsPreparedQuery = routeStopsQueryBuilder.prepare(); + QueryBuilder routeStopsQueryBuilder = routeStopsDao.queryBuilder(); + routeStopsQueryBuilder.where().eq(RouteStop.ROUTE_ID_FIELD_NAME, route.id).and() + .eq(RouteStop.STOP_ID_FIELD_NAME, destStop.id); + PreparedQuery routeStopsPreparedQuery = routeStopsQueryBuilder.prepare(); - List routeStops = routeStopsDao.query(routeStopsPreparedQuery); + List routeStops = routeStopsDao.query(routeStopsPreparedQuery); if (routeStops.size() > 0) { Log.i(TAG, "Found " + routeStops.size() + " stops matching the destStop " + destStop + " on route " + route.code); @@ -855,7 +855,7 @@ public class DataManager { public static void routeMovementTest(Context context) throws SQLException { - Dao routeStopsDao = null; + Dao routeStopsDao = null; if (helper == null) helper = OpenHelperManager.getHelper(context, DatabaseHelper.class); @@ -870,7 +870,7 @@ public class DataManager { if (!busRoute.code.startsWith("U") || busRoute.code.equals("U9")) { continue; } - List routeStops = routeStopsDao.queryForEq(RouteStops.ROUTE_ID_FIELD_NAME, busRoute.id); + List routeStops = routeStopsDao.queryForEq(RouteStop.ROUTE_ID_FIELD_NAME, busRoute.id); ArrayList directions = new ArrayList(); if (busRoute.forwardDirection != null) { diff --git a/src/net/cbaines/suma/DatabaseHelper.java b/src/net/cbaines/suma/DatabaseHelper.java index 13f4957..facfe85 100644 --- a/src/net/cbaines/suma/DatabaseHelper.java +++ b/src/net/cbaines/suma/DatabaseHelper.java @@ -48,7 +48,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { private Dao buildingDao = null; private Dao busStopDao = null; private Dao busRouteDao = null; - private Dao routeStopsDao = null; + private Dao routeStopsDao = null; private Dao siteDao = null; private Dao busDao = null; @@ -67,7 +67,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { TableUtils.createTable(connectionSource, Building.class); TableUtils.createTable(connectionSource, BusStop.class); TableUtils.createTable(connectionSource, BusRoute.class); - TableUtils.createTable(connectionSource, RouteStops.class); + TableUtils.createTable(connectionSource, RouteStop.class); TableUtils.createTable(connectionSource, Site.class); TableUtils.createTable(connectionSource, Bus.class); } catch (SQLException e) { @@ -125,9 +125,9 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { * Returns the Database Access Object (DAO) for our SimpleData class. It * will create it or just give the cached value. */ - public Dao getRouteStopsDao() throws SQLException { + public Dao getRouteStopsDao() throws SQLException { if (routeStopsDao == null) { - routeStopsDao = getDao(RouteStops.class); + routeStopsDao = getDao(RouteStop.class); } return routeStopsDao; } diff --git a/src/net/cbaines/suma/MapActivity.java b/src/net/cbaines/suma/MapActivity.java index 8f555da..e2b9d66 100644 --- a/src/net/cbaines/suma/MapActivity.java +++ b/src/net/cbaines/suma/MapActivity.java @@ -389,7 +389,7 @@ public class MapActivity extends OrmLiteBaseActivity implements Dao busStopDao = helper.getBusStopDao(); Dao busRouteDao = helper.getBusRouteDao(); - Dao routeStopsDao = helper.getRouteStopsDao(); + Dao routeStopsDao = helper.getRouteStopsDao(); long busStopCount = busStopDao.countOf(); long busRouteCount = busRouteDao.countOf(); diff --git a/src/net/cbaines/suma/POIView.java b/src/net/cbaines/suma/POIView.java index b27b4f3..95c571c 100644 --- a/src/net/cbaines/suma/POIView.java +++ b/src/net/cbaines/suma/POIView.java @@ -20,6 +20,7 @@ package net.cbaines.suma; import android.content.Context; +import android.preference.PreferenceManager; import android.util.Log; import android.view.Display; import android.view.Gravity; @@ -27,7 +28,7 @@ import android.view.WindowManager; import android.widget.LinearLayout; import android.widget.TextView; -public class POIView extends LinearLayout { +public class POIView extends LinearLayout implements Preferences { private final static String TAG = "POIView"; @@ -37,6 +38,8 @@ public class POIView extends LinearLayout { private LayoutParams textLayoutParams; + private boolean identifiersEnabled; + final int width; public POIView(Context context, POI poi) { @@ -46,6 +49,9 @@ public class POIView extends LinearLayout { public POIView(Context context, POI poi, int distInM) { super(context); + identifiersEnabled = PreferenceManager.getDefaultSharedPreferences(context).getBoolean(SHOW_IDENTIFIERS, + SHOW_IDENTIFIERS_ENABLED_BY_DEFAULT); + Display display = ((WindowManager) context.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay(); width = display.getWidth(); // int height = display.getHeight(); @@ -85,14 +91,22 @@ public class POIView extends LinearLayout { Building building = (Building) poi; // Log.i(TAG, "Its a building of name " + building.name); - name.setText(building.name + " (" + building.id + ")"); + if (identifiersEnabled) { + name.setText(building.name + " (" + building.id + ")"); + } else { + name.setText(building.name); + } } else if (poi.type == POI.BUS_STOP) { BusStop busStop = (BusStop) poi; // Log.i(TAG, "Its a bus stop of description " + // busStop.description); - name.setText(busStop.description + " (" + busStop.id + ")"); + if (identifiersEnabled) { + name.setText(busStop.description + " (" + busStop.id + ")"); + } else { + name.setText(busStop.description); + } routes.setRoutes(busStop.routes); @@ -100,8 +114,11 @@ public class POIView extends LinearLayout { Site site = (Site) poi; // Log.i(TAG, "Its a site of name " + site.name); - - name.setText(site.name + " (" + site.id + ")"); + if (identifiersEnabled) { + name.setText(site.name + " (" + site.id + ")"); + } else { + name.setText(site.name); + } } else { Log.w(TAG, "Cant identify " + poi.type); @@ -121,5 +138,4 @@ public class POIView extends LinearLayout { // Log.w("POIView", "No dist avalible for S" + poi.id); } } - } \ No newline at end of file diff --git a/src/net/cbaines/suma/Preferences.java b/src/net/cbaines/suma/Preferences.java index ff8f366..0508251 100644 --- a/src/net/cbaines/suma/Preferences.java +++ b/src/net/cbaines/suma/Preferences.java @@ -11,5 +11,8 @@ public interface Preferences { static final String NON_UNI_LINK_BUS_STOPS_OVERLAY = "nonUniLinkBusStops"; static final boolean NON_UNI_LINK_BUS_STOP_OVERLAY_ENABLED_BY_DEFAULT = false; + static final String SHOW_IDENTIFIERS = "showIdentifiers"; + static final boolean SHOW_IDENTIFIERS_ENABLED_BY_DEFAULT = false; + static final String FAVOURITES_PREFERENCES = "favourites"; } diff --git a/src/net/cbaines/suma/PreferencesActivity.java b/src/net/cbaines/suma/PreferencesActivity.java index 39e6bb2..bab72bf 100644 --- a/src/net/cbaines/suma/PreferencesActivity.java +++ b/src/net/cbaines/suma/PreferencesActivity.java @@ -45,6 +45,9 @@ public class PreferencesActivity extends PreferenceActivity implements Preferenc if (!sharedPrefs.contains(NON_UNI_LINK_BUS_STOPS_OVERLAY)) { editor.putBoolean(NON_UNI_LINK_BUS_STOPS_OVERLAY, NON_UNI_LINK_BUS_STOP_OVERLAY_ENABLED_BY_DEFAULT); } + if (!sharedPrefs.contains(SHOW_IDENTIFIERS)) { + editor.putBoolean(SHOW_IDENTIFIERS, SHOW_IDENTIFIERS_ENABLED_BY_DEFAULT); + } editor.commit(); addPreferencesFromResource(R.xml.preferences); diff --git a/src/net/cbaines/suma/RouteStop.java b/src/net/cbaines/suma/RouteStop.java new file mode 100644 index 0000000..a19f4fa --- /dev/null +++ b/src/net/cbaines/suma/RouteStop.java @@ -0,0 +1,63 @@ +/* + * 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 com.j256.ormlite.field.DatabaseField; +import com.j256.ormlite.table.DatabaseTable; + +@DatabaseTable(tableName = "routestops") +public class RouteStop implements Comparable { + public final static String STOP_ID_FIELD_NAME = "stop_id"; + public final static String ROUTE_ID_FIELD_NAME = "route_id"; + public final static String SEQUENCE_ID_FIELD_NAME = "sequence"; + + /** + * This id is generated by the database and set on the object when it is passed to the create method. An id is needed in case + * we need to update or delete this object in the future. + */ + @DatabaseField(generatedId = true) + int id; + + @DatabaseField + int sequence; + + // This is a foreign object which just stores the id from the User object in + // this table. + @DatabaseField(foreign = true, columnName = STOP_ID_FIELD_NAME, indexName = "routestops_routestop_idx") + BusStop busStop; + + // This is a foreign object which just stores the id from the Post object in + // this table. + @DatabaseField(foreign = true, columnName = ROUTE_ID_FIELD_NAME, indexName = "routestops_routestop_idx") + BusRoute busRoute; + + RouteStop() { + } + + public RouteStop(BusStop stop, BusRoute route, int sequence) { + this.busStop = stop; + this.busRoute = route; + this.sequence = sequence; + } + + public int compareTo(RouteStop routeStop) { + return this.sequence - routeStop.sequence; + } +} diff --git a/src/net/cbaines/suma/RouteStops.java b/src/net/cbaines/suma/RouteStops.java deleted file mode 100644 index 2f6c00a..0000000 --- a/src/net/cbaines/suma/RouteStops.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * 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 com.j256.ormlite.field.DatabaseField; -import com.j256.ormlite.table.DatabaseTable; - -@DatabaseTable(tableName = "routestops") -public class RouteStops { - public final static String STOP_ID_FIELD_NAME = "stop_id"; - public final static String ROUTE_ID_FIELD_NAME = "route_id"; - public final static String SEQUENCE_ID_FIELD_NAME = "sequence"; - - /** - * This id is generated by the database and set on the object when it is - * passed to the create method. An id is needed in case we need to update or - * delete this object in the future. - */ - @DatabaseField(generatedId = true) - int id; - - @DatabaseField - int sequence; - - // This is a foreign object which just stores the id from the User object in - // this table. - @DatabaseField(foreign = true, columnName = STOP_ID_FIELD_NAME, indexName = "routestops_routestop_idx") - BusStop busStop; - - // This is a foreign object which just stores the id from the Post object in - // this table. - @DatabaseField(foreign = true, columnName = ROUTE_ID_FIELD_NAME, indexName = "routestops_routestop_idx") - BusRoute busRoute; - - RouteStops() { - } - - public RouteStops(BusStop stop, BusRoute route, int sequence) { - this.busStop = stop; - this.busRoute = route; - this.sequence = sequence; - } -} -- cgit v1.2.3 From 5f2b8712079aeb5b7cee476b06b36013edac4fb3 Mon Sep 17 00:00:00 2001 From: Christopher Baines Date: Tue, 28 Feb 2012 22:22:27 +0000 Subject: Next release, many improvements. --- AndroidManifest.xml | 8 +- gen/net/cbaines/suma/R.java | Bin 13617 -> 13490 bytes project.properties | 2 +- res/layout/building_activity.xml | 42 ++++---- res/layout/bus_activity.xml | 55 ----------- res/layout/bus_route_activity.xml | 6 +- res/layout/bus_stop_activity.xml | 3 +- res/layout/find.xml | 36 ------- res/layout/find_activity.xml | 36 +++++++ res/layout/main.xml | 15 --- res/layout/map_activity.xml | 15 +++ res/values/strings.xml | 2 +- src/net/cbaines/suma/BuildingActivity.java | 148 ++++++++++++++++------------- src/net/cbaines/suma/BusActivity.java | 37 -------- src/net/cbaines/suma/BusRouteActivity.java | 110 ++++++++++++++++++++- src/net/cbaines/suma/BusStopActivity.java | 21 ++-- src/net/cbaines/suma/FindActivity.java | 2 +- src/net/cbaines/suma/MapActivity.java | 2 +- 18 files changed, 289 insertions(+), 251 deletions(-) delete mode 100644 res/layout/find.xml create mode 100644 res/layout/find_activity.xml delete mode 100644 res/layout/main.xml create mode 100644 res/layout/map_activity.xml diff --git a/AndroidManifest.xml b/AndroidManifest.xml index 42adfec..af78fdb 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -1,12 +1,10 @@ + android:versionCode="8" + android:versionName="0.5 (alpha)" > - + diff --git a/gen/net/cbaines/suma/R.java b/gen/net/cbaines/suma/R.java index aec5afc..f7f3034 100644 Binary files a/gen/net/cbaines/suma/R.java and b/gen/net/cbaines/suma/R.java differ diff --git a/project.properties b/project.properties index f049142..5a70945 100644 --- a/project.properties +++ b/project.properties @@ -8,4 +8,4 @@ # project structure. # Project target. -target=android-10 +target=android-7 diff --git a/res/layout/building_activity.xml b/res/layout/building_activity.xml index 6ed937f..777ad0a 100644 --- a/res/layout/building_activity.xml +++ b/res/layout/building_activity.xml @@ -10,31 +10,39 @@ android:layout_height="wrap_content" android:textAppearance="?android:attr/textAppearanceLarge" /> + + + + + android:layout_height="fill_parent" + android:gravity="center" + android:orientation="vertical" > - + android:layout_height="wrap_content" /> + android:text="" + android:textAppearance="?android:attr/textAppearanceLarge" /> - - \ No newline at end of file diff --git a/res/layout/bus_activity.xml b/res/layout/bus_activity.xml index 3037916..f8bbe59 100644 --- a/res/layout/bus_activity.xml +++ b/res/layout/bus_activity.xml @@ -17,61 +17,6 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:textAppearance="?android:attr/textAppearanceLarge" /> - - - - - - - - - - @@ -22,13 +22,15 @@ android:id="@+id/busRouteActivityLabel" android:layout_width="wrap_content" android:layout_height="wrap_content" + android:paddingRight="5dp" android:textAppearance="?android:attr/textAppearanceMedium" /> + android:textAppearance="?android:attr/textAppearanceMedium" + android:visibility="gone" /> + android:textAppearance="?android:attr/textAppearanceSmall" + android:visibility="gone" /> - - - - - - - - - - - - - \ No newline at end of file diff --git a/res/layout/find_activity.xml b/res/layout/find_activity.xml new file mode 100644 index 0000000..6b19c67 --- /dev/null +++ b/res/layout/find_activity.xml @@ -0,0 +1,36 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/res/layout/main.xml b/res/layout/main.xml deleted file mode 100644 index dff45bd..0000000 --- a/res/layout/main.xml +++ /dev/null @@ -1,15 +0,0 @@ - - - - - - - \ No newline at end of file diff --git a/res/layout/map_activity.xml b/res/layout/map_activity.xml new file mode 100644 index 0000000..dff45bd --- /dev/null +++ b/res/layout/map_activity.xml @@ -0,0 +1,15 @@ + + + + + + + \ No newline at end of file diff --git a/res/values/strings.xml b/res/values/strings.xml index e0f62e0..f3850a3 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -106,7 +106,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.< About Version - 0.4 (alpha) + 0.5 (alpha) Copyright © 2012, Christopher Baines License diff --git a/src/net/cbaines/suma/BuildingActivity.java b/src/net/cbaines/suma/BuildingActivity.java index d9baa95..509bc41 100644 --- a/src/net/cbaines/suma/BuildingActivity.java +++ b/src/net/cbaines/suma/BuildingActivity.java @@ -28,6 +28,7 @@ import java.sql.SQLException; import android.content.Context; import android.content.SharedPreferences; import android.graphics.drawable.Drawable; +import android.os.AsyncTask; import android.os.Bundle; import android.util.Log; import android.view.Display; @@ -38,13 +39,13 @@ import android.widget.CompoundButton; import android.widget.CompoundButton.OnCheckedChangeListener; import android.widget.ImageButton; import android.widget.ImageView.ScaleType; +import android.widget.ProgressBar; import android.widget.TextView; import com.j256.ormlite.android.apptools.OrmLiteBaseActivity; import com.j256.ormlite.dao.Dao; -public class BuildingActivity extends OrmLiteBaseActivity implements OnCheckedChangeListener, - Preferences { +public class BuildingActivity extends OrmLiteBaseActivity implements OnCheckedChangeListener, Preferences { final static String TAG = "BusTimeActivity"; @@ -53,10 +54,12 @@ public class BuildingActivity extends OrmLiteBaseActivity implem private ImageButton imageButton; private TextView buildingName; - private TextView buildingID; private Building building; + private ProgressBar progressBar; + private TextView message; + private CheckBox favouritesCheckBox; public void onCreate(Bundle savedInstanceState) { @@ -85,7 +88,9 @@ public class BuildingActivity extends OrmLiteBaseActivity implem favouritesCheckBox.setOnCheckedChangeListener(this); buildingName = (TextView) findViewById(R.id.buildingActivityName); - buildingID = (TextView) findViewById(R.id.buildingActivityID); + + progressBar = (ProgressBar) findViewById(R.id.buildingActivityLoadBar); + message = (TextView) findViewById(R.id.buildingActivityMessage); Log.i(TAG, "Building id " + ID); @@ -94,83 +99,92 @@ public class BuildingActivity extends OrmLiteBaseActivity implem building = buildingDao.queryForId(ID); - buildingName.setText(building.name); + buildingName.setText("Building " + building.id + " - " + building.name); } catch (SQLException e1) { - // TODO Auto-generated catch block e1.printStackTrace(); } - buildingID.setText(ID); - try { + GetBuildingImageTask buildingImageTask = new GetBuildingImageTask(); + buildingImageTask.execute(building); - /* First, get the Display from the WindowManager */ - Display display = ((WindowManager) getSystemService(WINDOW_SERVICE)).getDefaultDisplay(); - - /* Now we can retrieve all display-related infos */ - int orientation = display.getOrientation(); - Log.i(TAG, "orientation " + orientation); - Log.i(TAG, "width " + display.getWidth() + " height " + display.getHeight()); - int width; - // if (orientation == 0) { - width = display.getWidth(); - // } else { - // width = display.getHeight(); - // } - - URL imageURL; - Log.i(TAG, "Screen width " + width); - if (width >= 1000) { - imageURL = new URL("http://data.southampton.ac.uk/images/buildings/1000/" + ID + ".jpg"); - } else if (width >= 800) { - imageURL = new URL("http://data.southampton.ac.uk/images/buildings/1000/" + ID + ".jpg"); - } else if (width >= 600) { - imageURL = new URL("http://data.southampton.ac.uk/images/buildings/600/" + ID + ".jpg"); - } else if (width >= 400) { - imageURL = new URL("http://data.southampton.ac.uk/images/buildings/600/" + ID + ".jpg"); - } else if (width >= 300) { - imageURL = new URL("http://data.southampton.ac.uk/images/buildings/300/" + ID + ".jpg"); - } else if (width >= 200) { - imageURL = new URL("http://data.southampton.ac.uk/images/buildings/200/" + ID + ".jpg"); - } else { - imageURL = new URL("http://data.southampton.ac.uk/images/buildings/100/" + ID + ".jpg"); - } - Log.i(TAG, "URL " + imageURL); + } + + class GetBuildingImageTask extends AsyncTask { + String errorMessage; + + @Override + protected Drawable doInBackground(Building... buildings) { + Building building = buildings[0]; + + Log.i(TAG, "Getting image for " + building); + + try { + + Display display = ((WindowManager) getSystemService(WINDOW_SERVICE)).getDefaultDisplay(); + + int orientation = display.getOrientation(); + Log.i(TAG, "orientation " + orientation); + Log.i(TAG, "width " + display.getWidth() + " height " + display.getHeight()); + int width; + width = display.getWidth(); + + URL imageURL; + Log.i(TAG, "Screen width " + width); + if (width >= 1000) { + imageURL = new URL("http://data.southampton.ac.uk/images/buildings/1000/" + building.id + ".jpg"); + } else if (width >= 800) { + imageURL = new URL("http://data.southampton.ac.uk/images/buildings/1000/" + building.id + ".jpg"); + } else if (width >= 600) { + imageURL = new URL("http://data.southampton.ac.uk/images/buildings/600/" + building.id + ".jpg"); + } else if (width >= 400) { + imageURL = new URL("http://data.southampton.ac.uk/images/buildings/600/" + building.id + ".jpg"); + } else if (width >= 300) { + imageURL = new URL("http://data.southampton.ac.uk/images/buildings/300/" + building.id + ".jpg"); + } else if (width >= 200) { + imageURL = new URL("http://data.southampton.ac.uk/images/buildings/200/" + building.id + ".jpg"); + } else { + imageURL = new URL("http://data.southampton.ac.uk/images/buildings/100/" + building.id + ".jpg"); + } + Log.i(TAG, "URL " + imageURL); - InputStream is = (InputStream) imageURL.getContent(); - Drawable image = Drawable.createFromStream(is, "src"); + InputStream is = (InputStream) imageURL.getContent(); + Drawable image = Drawable.createFromStream(is, "src"); - imageButton = new ImageButton(this); - imageButton = (ImageButton) findViewById(R.id.buildingActivityImage); - imageButton.setImageDrawable(image); - imageButton.setScaleType(ScaleType.CENTER_INSIDE); - imageButton.setOnClickListener(new View.OnClickListener() { - public void onClick(View v) { + return image; - } - }); - - } catch (MalformedURLException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } catch (IOException e) { - // TODO Auto-generated catch block - e.printStackTrace(); + } catch (MalformedURLException e) { + e.printStackTrace(); + errorMessage = "MalformedURLException"; + } catch (IOException e) { + e.printStackTrace(); + errorMessage = "IOException"; + } + + return null; } - } + protected void onPostExecute(Drawable image) { + progressBar.setVisibility(View.GONE); - public void onResume() { - super.onResume(); - } + if (image != null) { + Log.i(TAG, "Got a image for " + building + ", now displaying it"); - public void onPause() { - super.onPause(); - } + imageButton = (ImageButton) findViewById(R.id.buildingActivityImage); + imageButton.setImageDrawable(image); + imageButton.setScaleType(ScaleType.CENTER_INSIDE); + imageButton.setOnClickListener(new View.OnClickListener() { + public void onClick(View v) { - public void finish() { - setResult(RESULT_OK, getIntent()); - super.finish(); + } + }); + } else { + Log.e(TAG, "Error, null image, " + errorMessage); + + message.setText(errorMessage); + message.setVisibility(View.VISIBLE); + } + } } @Override diff --git a/src/net/cbaines/suma/BusActivity.java b/src/net/cbaines/suma/BusActivity.java index f4edc3f..1a8baf9 100644 --- a/src/net/cbaines/suma/BusActivity.java +++ b/src/net/cbaines/suma/BusActivity.java @@ -27,12 +27,6 @@ import com.j256.ormlite.android.apptools.OrmLiteBaseActivity; public class BusActivity extends OrmLiteBaseActivity implements Preferences { final static String TAG = "BusActivity"; - private TextView U1RouteTextView; - private TextView U1NRouteTextView; - private TextView U2RouteTextView; - private TextView U6RouteTextView; - private TextView U9RouteTextView; - private TextView busIDTextView; private TextView busContentMessage; @@ -115,12 +109,6 @@ public class BusActivity extends OrmLiteBaseActivity implements } } - U1RouteTextView = (TextView) findViewById(R.id.busActivityU1); - U1NRouteTextView = (TextView) findViewById(R.id.busActivityU1N); - U2RouteTextView = (TextView) findViewById(R.id.busActivityU2); - U6RouteTextView = (TextView) findViewById(R.id.busActivityU6); - U9RouteTextView = (TextView) findViewById(R.id.busActivityU9); - busIDTextView = (TextView) findViewById(R.id.busActivityBusID); busContentMessage = (TextView) findViewById(R.id.busActivityMessage); @@ -136,31 +124,6 @@ public class BusActivity extends OrmLiteBaseActivity implements busIDTextView.setText("Unidentified"); } - U1RouteTextView.setVisibility(View.GONE); - U1NRouteTextView.setVisibility(View.GONE); - U2RouteTextView.setVisibility(View.GONE); - U6RouteTextView.setVisibility(View.GONE); - U9RouteTextView.setVisibility(View.GONE); - - // if (bus.route.uniLink) { - Log.i(TAG, "Bus is uniLink"); - if (bus.route.code.equals("U1")) { - U1RouteTextView.setVisibility(View.VISIBLE); - } else if (bus.route.code.equals("U1N")) { - U1NRouteTextView.setVisibility(View.VISIBLE); - } else if (bus.route.code.equals("U2")) { - U2RouteTextView.setVisibility(View.VISIBLE); - } else if (bus.route.code.equals("U6")) { - U6RouteTextView.setVisibility(View.VISIBLE); - } else if (bus.route.code.equals("U9")) { - U9RouteTextView.setVisibility(View.VISIBLE); - } else { - Log.e(TAG, "Route not found " + bus.route.code); - } - // } else { - // Log.i(TAG, "Bus is not uniLink"); - // } - } catch (NumberFormatException e) { e.printStackTrace(); } catch (SQLException e) { diff --git a/src/net/cbaines/suma/BusRouteActivity.java b/src/net/cbaines/suma/BusRouteActivity.java index 3670c68..0a352ce 100644 --- a/src/net/cbaines/suma/BusRouteActivity.java +++ b/src/net/cbaines/suma/BusRouteActivity.java @@ -3,15 +3,24 @@ package net.cbaines.suma; import java.sql.SQLException; import android.content.Context; +import android.content.Intent; +import android.content.SharedPreferences; +import android.net.Uri; import android.os.Bundle; +import android.preference.PreferenceManager; import android.util.Log; +import android.view.View; +import android.widget.AdapterView; +import android.widget.AdapterView.OnItemClickListener; +import android.widget.AdapterView.OnItemLongClickListener; import android.widget.ListView; import android.widget.TextView; import android.widget.Toast; import com.j256.ormlite.android.apptools.OrmLiteBaseActivity; -public class BusRouteActivity extends OrmLiteBaseActivity implements Preferences { +public class BusRouteActivity extends OrmLiteBaseActivity implements Preferences, OnItemClickListener, + OnItemLongClickListener { final static String TAG = "BusActivity"; private TextView busRouteLabel; @@ -22,6 +31,8 @@ public class BusRouteActivity extends OrmLiteBaseActivity implem private ListView busRouteView; + private POIArrayAdapter arrayAdapter; + private Context instance; public void onCreate(Bundle savedInstanceState) { @@ -50,6 +61,8 @@ public class BusRouteActivity extends OrmLiteBaseActivity implem BusRoute busRoute = null; + SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); + try { busRoute = helper.getBusRouteDao().queryForId(Integer.parseInt(strBusRouteID)); @@ -59,8 +72,11 @@ public class BusRouteActivity extends OrmLiteBaseActivity implem busRouteCode = (TextView) findViewById(R.id.busRouteActivityCode); busRouteCode.setText(busRoute.code); - busRouteID = (TextView) findViewById(R.id.busRouteActivityID); - busRouteID.setText(String.valueOf(busRoute.id)); + if (prefs.getBoolean(SHOW_IDENTIFIERS, SHOW_IDENTIFIERS_ENABLED_BY_DEFAULT)) { + busRouteID = (TextView) findViewById(R.id.busRouteActivityID); + busRouteID.setText(String.valueOf(busRoute.id)); + busRouteID.setVisibility(View.VISIBLE); + } busRouteView = (ListView) findViewById(R.id.busRouteBusStops); @@ -70,7 +86,93 @@ public class BusRouteActivity extends OrmLiteBaseActivity implem e.printStackTrace(); } - POIArrayAdapter arrayAdapter = new POIArrayAdapter(instance, busRoute.getRouteBusStops(instance)); + arrayAdapter = new POIArrayAdapter(instance, busRoute.getRouteBusStops(instance)); busRouteView.setAdapter(arrayAdapter); + busRouteView.setOnItemClickListener(this); + busRouteView.setOnItemLongClickListener(this); + } + + public boolean onItemLongClick(AdapterView parent, View view, int position, long id) { + Log.i(TAG, "OnItemClick pos " + position + " id " + id); + + String poiId = arrayAdapter.getItemStringId(position); + + Log.i(TAG, "POI " + poiId + " selected"); + + POI poi = null; + + if (poiId != null) { + Log.i(TAG, "Got id " + poiId); + try { + poi = getHelper().getBusStopDao().queryForId(poiId); + } catch (SQLException e) { + e.printStackTrace(); + } + + if (poi == null) { + Log.e(TAG, "Could not find poi " + poiId + " in onActivityResult"); + } else { + + BusStop busStop = (BusStop) poi; + + Log.i(TAG, "Pressed " + busStop.id); + + 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); + + return true; + } + } else { + Log.i(TAG, "Got null poi id"); + + // mapController.setZoom(15); + // mapController.setCenter(new GeoPoint(50935551, -1393488)); + } + + return false; + } + + public void onItemClick(AdapterView parent, View view, int position, long id) { + Log.i(TAG, "OnItemClick pos " + position + " id " + id); + + String poiId = arrayAdapter.getItemStringId(position); + + Log.i(TAG, "POI " + poiId + " selected"); + + POI poi = null; + + if (poiId != null) { + Log.i(TAG, "Got id " + poiId); + try { + poi = getHelper().getBusStopDao().queryForId(poiId); + } catch (SQLException e) { + e.printStackTrace(); + } + + if (poi == null) { + Log.e(TAG, "Could not find poi " + poiId + " in onActivityResult"); + } else { + + Log.i(TAG, "Pressed " + poi.id); + + Uri uri = Uri.parse("geo:" + Util.E6IntToDouble(poi.point.getLatitudeE6()) + "," + + Util.E6IntToDouble(poi.point.getLongitudeE6()) + "?z=18"); + + Log.i(TAG, "Starting a activity for " + uri); + + Intent mapIntent = new Intent(Intent.ACTION_VIEW, uri); + startActivity(mapIntent); + + } + } else { + Log.i(TAG, "Got null poi id"); + + // mapController.setZoom(15); + // mapController.setCenter(new GeoPoint(50935551, -1393488)); + } } } diff --git a/src/net/cbaines/suma/BusStopActivity.java b/src/net/cbaines/suma/BusStopActivity.java index 8bded40..cab81b1 100644 --- a/src/net/cbaines/suma/BusStopActivity.java +++ b/src/net/cbaines/suma/BusStopActivity.java @@ -61,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, OnLongClickListener { +public class BusStopActivity extends OrmLiteBaseActivity implements OnCheckedChangeListener, Preferences, + OnItemClickListener, OnLongClickListener { final static String TAG = "BusTimeActivity"; @@ -123,6 +123,7 @@ public class BusStopActivity extends OrmLiteBaseActivity impleme final DatabaseHelper helper = getHelper(); SharedPreferences favouritesPreferences = getSharedPreferences(FAVOURITES_PREFERENCES, 0); + SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); instance = this; @@ -212,7 +213,12 @@ public class BusStopActivity extends OrmLiteBaseActivity 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); @@ -222,7 +228,6 @@ public class BusStopActivity extends OrmLiteBaseActivity impleme Log.i(TAG, "Got busstop id " + busStopID); busName.setText(busStop.description); - busID.setText(busStopID); } public void onResume() { @@ -315,10 +320,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(); diff --git a/src/net/cbaines/suma/FindActivity.java b/src/net/cbaines/suma/FindActivity.java index 1af350a..669249c 100644 --- a/src/net/cbaines/suma/FindActivity.java +++ b/src/net/cbaines/suma/FindActivity.java @@ -241,7 +241,7 @@ public class FindActivity extends OrmLiteBaseActivity implements /** Called when the activity is first created. */ public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - setContentView(R.layout.find); + setContentView(R.layout.find_activity); searchBar = (EditText) findViewById(R.id.searchBar); searchBar.addTextChangedListener(this); diff --git a/src/net/cbaines/suma/MapActivity.java b/src/net/cbaines/suma/MapActivity.java index e2b9d66..8a7a39a 100644 --- a/src/net/cbaines/suma/MapActivity.java +++ b/src/net/cbaines/suma/MapActivity.java @@ -196,7 +196,7 @@ public class MapActivity extends OrmLiteBaseActivity implements Thread databaseThread = new Thread(this); // Start the database thread databaseThread.start(); - setContentView(R.layout.main); + setContentView(R.layout.map_activity); Log.i(TAG, "Finished setting content view " + (System.currentTimeMillis() - startTime)); -- cgit v1.2.3