diff options
author | Christopher Baines <cbaines8@gmail.com> | 2012-02-28 15:29:26 +0000 |
---|---|---|
committer | Christopher Baines <cbaines8@gmail.com> | 2012-02-28 15:29:26 +0000 |
commit | ed7638698d439d75ada5120121a137f8e6f09bf8 (patch) | |
tree | 623e1211bb6b61200cb693ab0f9c61ec00716f68 /src/net/cbaines/suma | |
parent | b5d0db004eaf72e9eeff0dfd7f612591d670b139 (diff) | |
download | southamptonuniversitymap-ed7638698d439d75ada5120121a137f8e6f09bf8.tar southamptonuniversitymap-ed7638698d439d75ada5120121a137f8e6f09bf8.tar.gz |
Improved URI stuff, and formating.
Diffstat (limited to 'src/net/cbaines/suma')
32 files changed, 1429 insertions, 1449 deletions
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<DatabaseHelper> implements OnCheckedChangeListener, Preferences { +public class BuildingActivity extends OrmLiteBaseActivity<DatabaseHelper> implements OnCheckedChangeListener, + Preferences { final static String TAG = "BusTimeActivity"; @@ -63,25 +64,20 @@ public class BuildingActivity extends OrmLiteBaseActivity<DatabaseHelper> 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.<br/> + * Draw a marker on each of our items. populate() must have been called + * first.<br/> * <br/> - * 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.<br/> + * 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.<br/> * <br/> - * 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.<br/> + * 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.<br/> * <br/> - * The focused item is always drawn last, which puts it visually on top of the other items.<br/> + * The focused item is always drawn last, which puts it visually on top of + * the other items.<br/> * * @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<Building> 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<Bus, Integer> 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<Bus, Integer> 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<DatabaseHelper> impleme protected Timetable timetable; private Timetable visibleTimetable; - private Dao<BusStop, String> busStopDao; - private BusStop busStop; private GetTimetableTask timetableTask; @@ -205,10 +203,6 @@ public class BusStopActivity extends OrmLiteBaseActivity<DatabaseHelper> impleme } } - busStopDao = helper.getBusStopDao(); - - busStop = busStopDao.queryForId(busStopID); - busFavourite = (CheckBox) findViewById(R.id.favouriteCheckBox); busFavourite.setChecked(favouritesPreferences.getBoolean(busStop.id, false)); busFavourite.setOnCheckedChangeListener(this); @@ -516,27 +510,17 @@ public class BusStopActivity extends OrmLiteBaseActivity<DatabaseHelper> impleme public void onItemClick(AdapterView<?> parent, View view, int position, long id) { Log.i(TAG, "OnItemClick pos " + position + " id " + id); - String poiId = busDialog.adapter.getItemStringId(position); + String busId = busDialog.adapter.getItemStringId(position); - Log.i(TAG, "POI " + poiId + " selected"); + Log.i(TAG, "Bus " + busId + " selected"); - Intent i = new Intent(this, BusStopActivity.class); - try { - busStop = busStopDao.queryForId(poiId); + Uri uri = Uri.parse("http://id.southampton.ac.uk/bus/" + busId); - if (busStop == null) { - Log.e(TAG, "stop == null"); - } - if (busStop.id == null) { - Log.e(TAG, "stop.id == null"); - } - i.putExtra("busStopID", busStop.id); - i.putExtra("busStopName", busStop.description); - startActivity(i); - } catch (SQLException e) { - e.printStackTrace(); - } + Log.i(TAG, "Starting a activity for " + uri + " path " + uri.getPath()); + Intent busStopIntent = new Intent(Intent.ACTION_VIEW, uri); + busStopIntent.putExtra("busStopID", busStop.id); + startActivity(busStopIntent); } public boolean onLongClick(View v) { 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<String> iter = buildingPoints.keySet().iterator(); iter.hasNext();) { String key = iter.next(); + * for (Iterator<String> 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<BusStop> busStopIter = busStopDao.iterator(); busStopIter.hasNext();) { BusStop stop = - * busStopIter.next(); // Log.i(TAG, "Looking at stop " + stop.id); + * for (Iterator<BusStop> busStopIter = busStopDao.iterator(); + * busStopIter.hasNext();) { BusStop stop = busStopIter.next(); // + * Log.i(TAG, "Looking at stop " + stop.id); * * - * QueryBuilder<RouteStops, Integer> routeStopsQueryBuilder = routeStopsDao.queryBuilder(); + * QueryBuilder<RouteStops, Integer> routeStopsQueryBuilder = + * routeStopsDao.queryBuilder(); * routeStopsQueryBuilder.where().eq(columnName, value) * - * DeleteBuilder<BusStop, String> 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<BusStop, String> 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<RouteStops, Integer> routeStopsQueryBuilder = routeStopsDao.queryBuilder(); - * routeStopsQueryBuilder.setCountOf(true); routeStopsQueryBuilder.where().eq(RouteStops.STOP_ID_FIELD_NAME, stop); + * QueryBuilder<RouteStops, Integer> routeStopsQueryBuilder = + * routeStopsDao.queryBuilder(); + * routeStopsQueryBuilder.setCountOf(true); + * routeStopsQueryBuilder.where().eq(RouteStops.STOP_ID_FIELD_NAME, + * stop); * - * PreparedQuery<RouteStops> routeStopsPreparedQuery = routeStopsQueryBuilder.prepare(); List<RouteStops> routeStops = - * routeStopsDao.query(routeStopsPreparedQuery); // long num = routeStopsDao.query(routeStopsPreparedQuery).size(); // - * Log.i(TAG, "Number is " + num); + * PreparedQuery<RouteStops> routeStopsPreparedQuery = + * routeStopsQueryBuilder.prepare(); List<RouteStops> 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<BusRoute> routes, BusStop busStop) throws SQLException, - JSONException { + private static Stop getStop(Context context, JSONObject stopObj, Set<BusRoute> routes, BusStop busStop) + throws SQLException, JSONException { if (helper == null) helper = OpenHelperManager.getHelper(context, DatabaseHelper.class); @@ -553,9 +575,11 @@ public class DataManager { List<RouteStops> 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<Building, String> buildingDao = null; - private Dao<BusStop, String> busStopDao = null; - private Dao<BusRoute, Integer> busRouteDao = null; - private Dao<RouteStops, Integer> routeStopsDao = null; - private Dao<Site, String> siteDao = null; - private Dao<Bus, Integer> 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<Building, String> buildingDao = null; + private Dao<BusStop, String> busStopDao = null; + private Dao<BusRoute, Integer> busRouteDao = null; + private Dao<RouteStops, Integer> routeStopsDao = null; + private Dao<Site, String> siteDao = null; + private Dao<Bus, Integer> 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<Building, String> 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<BusStop, String> 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<Building, String> 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<BusRoute, Integer> 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<BusStop, String> 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<RouteStops, Integer> 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<BusRoute, Integer> 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<Site, String> 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<RouteStops, Integer> 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<Bus, Integer> 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<Site, String> 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<Bus, Integer> 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<DatabaseHelper> implements Runnable, TextWatcher, OnItemClickListener, LocationListener, - OnItemLongClickListener { +public class FindActivity extends OrmLiteBaseActivity<DatabaseHelper> 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<Building, String> buildingDao; - private Dao<BusStop, String> busStopDao; - private Dao<Site, String> siteDao; + private Dao<Building, String> buildingDao; + private Dao<BusStop, String> busStopDao; + private Dao<Site, String> siteDao; - private POIArrayAdapter adapter; - // private ArrayList<POI> POIsFound = new ArrayList<POI>(); + private POIArrayAdapter adapter; - private boolean dataChanged; + private GeoPoint userLocation; - private GeoPoint userLocation; + private Thread searchThread; - private Thread searchThread; - - ArrayList<POI> getNearestPOIs(int distance) { - Log.i(TAG, "Getting nearest POI's"); - ArrayList<POI> nearestPOIs = new ArrayList<POI>(); - for (Iterator<Building> 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<POI> getNearestPOIs(int distance) { + Log.i(TAG, "Getting nearest POI's"); + ArrayList<POI> nearestPOIs = new ArrayList<POI>(); + for (Iterator<Building> 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<BusStop> 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<BusStop> 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<POI> foundPOIsArray = null; + ArrayList<POI> 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<POI>(); + + 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<Building, String> buildingQueryBuilder = buildingDao.queryBuilder(); + buildingQueryBuilder.where().like(Building.ID_FIELD_NAME, "%" + thisSearchTerm + "%").or() + .like(Building.NAME_FIELD_NAME, "%" + thisSearchTerm + "%"); + PreparedQuery<Building> buildingPreparedQuery = buildingQueryBuilder.prepare(); + List<Building> 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<Site, String> siteQueryBuilder = siteDao.queryBuilder(); + siteQueryBuilder.where().like(Site.ID_FIELD_NAME, "%" + thisSearchTerm + "%").or() + .like(Site.NAME_FIELD_NAME, "%" + thisSearchTerm + "%"); + PreparedQuery<Site> sitePreparedQuery = siteQueryBuilder.prepare(); + List<Site> 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<BusStop, String> busStopQueryBuilder = busStopDao.queryBuilder(); + busStopQueryBuilder.where().like(BusStop.ID_FIELD_NAME, "%" + thisSearchTerm + "%").or() + .like(BusStop.DESCRIPTION_FIELD_NAME, "%" + thisSearchTerm + "%"); + PreparedQuery<BusStop> busStopPreparedQuery = busStopQueryBuilder.prepare(); + List<BusStop> 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<POI>(); + 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<Building, String> buildingQueryBuilder = buildingDao.queryBuilder(); - buildingQueryBuilder.where().like(Building.ID_FIELD_NAME, "%" + thisSearchTerm + "%").or() - .like(Building.NAME_FIELD_NAME, "%" + thisSearchTerm + "%"); - PreparedQuery<Building> buildingPreparedQuery = buildingQueryBuilder.prepare(); - List<Building> 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<Site, String> siteQueryBuilder = siteDao.queryBuilder(); - siteQueryBuilder.where().like(Site.ID_FIELD_NAME, "%" + thisSearchTerm + "%").or() - .like(Site.NAME_FIELD_NAME, "%" + thisSearchTerm + "%"); - PreparedQuery<Site> sitePreparedQuery = siteQueryBuilder.prepare(); - List<Site> 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<BusStop, String> busStopQueryBuilder = busStopDao.queryBuilder(); - busStopQueryBuilder.where().like(BusStop.ID_FIELD_NAME, "%" + thisSearchTerm + "%").or() - .like(BusStop.DESCRIPTION_FIELD_NAME, "%" + thisSearchTerm + "%"); - PreparedQuery<BusStop> busStopPreparedQuery = busStopQueryBuilder.prepare(); - List<BusStop> 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<DatabaseHelper> 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<DatabaseHelper> 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<DatabaseHelper> 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<POI> { - 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<? extends POI> route; + ArrayList<? extends POI> route; - public RouteOverlayItem(String aTitle, String aDescription, ArrayList<? extends POI> route) { - super(aTitle, aDescription, new GeoPoint(0, 0)); - this.route = route; + public RouteOverlayItem(String aTitle, String aDescription, ArrayList<? extends POI> 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<Bus, Integer> 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<Bus, Integer> 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<POI> { - 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<Stop> { - /** + /** * */ - 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<GeoPoint> geoPoints = new ArrayList<GeoPoint>(); + public static Polygon csPolygonToPolygon(String str) { + // Log.i(TAG, "Getting poly from " + str); + ArrayList<GeoPoint> geoPoints = new ArrayList<GeoPoint>(); - 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)); } |