aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--AndroidManifest.xml118
-rw-r--r--gen/net/cbaines/suma/R.java233
-rw-r--r--res/layout/building_activity.xml42
-rw-r--r--res/layout/bus_activity.xml55
-rw-r--r--res/layout/bus_route_activity.xml42
-rw-r--r--res/layout/bus_stop_activity.xml16
-rw-r--r--res/layout/find_activity.xml (renamed from res/layout/find.xml)0
-rw-r--r--res/layout/map_activity.xml (renamed from res/layout/main.xml)0
-rw-r--r--res/values/strings.xml6
-rw-r--r--res/xml/preferences.xml9
-rw-r--r--src/net/cbaines/suma/AboutActivity.java118
-rw-r--r--src/net/cbaines/suma/Building.java56
-rw-r--r--src/net/cbaines/suma/BuildingActivity.java159
-rw-r--r--src/net/cbaines/suma/BuildingNumOverlay.java60
-rw-r--r--src/net/cbaines/suma/BusActivity.java55
-rw-r--r--src/net/cbaines/suma/BusRoute.java901
-rw-r--r--src/net/cbaines/suma/BusRouteActivity.java178
-rw-r--r--src/net/cbaines/suma/BusRoutesView.java218
-rw-r--r--src/net/cbaines/suma/BusSpecificStopView.java10
-rw-r--r--src/net/cbaines/suma/BusSpecificTimetableAdapter.java114
-rw-r--r--src/net/cbaines/suma/BusStop.java69
-rw-r--r--src/net/cbaines/suma/BusStopActivity.java134
-rw-r--r--src/net/cbaines/suma/BusStopOverlay.java12
-rw-r--r--src/net/cbaines/suma/BusStopView.java12
-rw-r--r--src/net/cbaines/suma/DataHandler.java147
-rw-r--r--src/net/cbaines/suma/DataManager.java119
-rw-r--r--src/net/cbaines/suma/DatabaseConfigUtil.java6
-rw-r--r--src/net/cbaines/suma/DatabaseHelper.java379
-rw-r--r--src/net/cbaines/suma/DonateDialog.java89
-rw-r--r--src/net/cbaines/suma/FindActivity.java538
-rw-r--r--src/net/cbaines/suma/MapActivity.java63
-rw-r--r--src/net/cbaines/suma/POIArrayAdapter.java80
-rw-r--r--src/net/cbaines/suma/POIDialog.java86
-rw-r--r--src/net/cbaines/suma/POIDistanceComparator.java40
-rw-r--r--src/net/cbaines/suma/POIView.java165
-rw-r--r--src/net/cbaines/suma/Polygon.java36
-rw-r--r--src/net/cbaines/suma/Preferences.java23
-rw-r--r--src/net/cbaines/suma/PreferencesActivity.java43
-rw-r--r--src/net/cbaines/suma/RouteColorConstants.java10
-rw-r--r--src/net/cbaines/suma/RouteOverlayItem.java11
-rw-r--r--src/net/cbaines/suma/RouteStop.java63
-rw-r--r--src/net/cbaines/suma/RouteStops.java57
-rw-r--r--src/net/cbaines/suma/Site.java36
-rw-r--r--src/net/cbaines/suma/Stop.java239
-rw-r--r--src/net/cbaines/suma/StopView.java16
-rw-r--r--src/net/cbaines/suma/StringDistanceComparator.java163
-rw-r--r--src/net/cbaines/suma/Timetable.java64
-rw-r--r--src/net/cbaines/suma/TimetableAdapter.java100
-rw-r--r--src/net/cbaines/suma/Util.java108
-rw-r--r--src/net/cbaines/suma/ViewDialog.java16
-rw-r--r--src/net/cbaines/suma/Waypoint.java42
51 files changed, 2916 insertions, 2440 deletions
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index c796a99..5e61dd4 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="net.cbaines.suma"
- android:versionCode="7"
- android:versionName="0.4 (alpha)" >
+ android:versionCode="8"
+ android:versionName="0.5 (alpha)" >
<uses-sdk android:minSdkVersion="7" />
@@ -13,6 +13,12 @@
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
+ <supports-screens
+ android:anyDensity="true"
+ android:largeScreens="true"
+ android:normalScreens="true"
+ android:smallScreens="true" />
+
<application
android:icon="@drawable/icon"
android:label="@string/app_name" >
@@ -24,16 +30,124 @@
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
+ <intent-filter android:label="@string/app_name" >
+ <action android:name="android.intent.action.VIEW" />
+
+ <category android:name="android.intent.category.DEFAULT" />
+ <category android:name="android.intent.category.BROWSABLE" />
+
+ <data
+ android:host="opendatamap.ecs.soton.ac.uk"
+ android:scheme="http" />
+ </intent-filter>
+ <intent-filter android:label="@string/app_name" >
+ <action android:name="android.intent.action.VIEW" />
+
+ <category android:name="android.intent.category.DEFAULT" />
+ <category android:name="android.intent.category.BROWSABLE" />
+
+ <data android:scheme="geo" />
+ </intent-filter>
</activity>
<activity android:name="FindActivity" >
</activity>
<activity android:name="BusStopActivity" >
+ <intent-filter android:label="@string/app_name" >
+ <action android:name="android.intent.action.VIEW" />
+
+ <category android:name="android.intent.category.DEFAULT" />
+ <category android:name="android.intent.category.BROWSABLE" />
+
+ <data
+ android:host="id.southampton.ac.uk"
+ android:pathPrefix="/bus-stop/"
+ android:scheme="http" />
+ </intent-filter>
+ <intent-filter android:label="@string/app_name" >
+ <action android:name="android.intent.action.VIEW" />
+
+ <category android:name="android.intent.category.DEFAULT" />
+ <category android:name="android.intent.category.BROWSABLE" />
+
+ <data
+ android:host="data.southampton.ac.uk"
+ android:pathPrefix="/bus-stop/"
+ android:scheme="http" />
+ </intent-filter>
</activity>
<activity android:name="BusActivity" >
+ <intent-filter android:label="@string/app_name" >
+ <action android:name="android.intent.action.VIEW" />
+
+ <category android:name="android.intent.category.DEFAULT" />
+ <category android:name="android.intent.category.BROWSABLE" />
+
+ <data
+ android:host="id.southampton.ac.uk"
+ android:pathPrefix="/bus/"
+ android:scheme="http" />
+ </intent-filter>
+ <intent-filter android:label="@string/app_name" >
+ <action android:name="android.intent.action.VIEW" />
+
+ <category android:name="android.intent.category.DEFAULT" />
+ <category android:name="android.intent.category.BROWSABLE" />
+
+ <data
+ android:host="data.southampton.ac.uk"
+ android:pathPrefix="/bus/"
+ android:scheme="http" />
+ </intent-filter>
</activity>
<activity android:name="AboutActivity" >
</activity>
<activity android:name="BuildingActivity" >
+ <intent-filter android:label="@string/app_name" >
+ <action android:name="android.intent.action.VIEW" />
+
+ <category android:name="android.intent.category.DEFAULT" />
+ <category android:name="android.intent.category.BROWSABLE" />
+
+ <data
+ android:host="id.southampton.ac.uk"
+ android:pathPrefix="/building/"
+ android:scheme="http" />
+ </intent-filter>
+ <intent-filter android:label="@string/app_name" >
+ <action android:name="android.intent.action.VIEW" />
+
+ <category android:name="android.intent.category.DEFAULT" />
+ <category android:name="android.intent.category.BROWSABLE" />
+
+ <data
+ android:host="data.southampton.ac.uk"
+ android:pathPrefix="/building/"
+ android:scheme="http" />
+ </intent-filter>
+ </activity>
+ <activity android:name="BusRouteActivity" >
+ <intent-filter android:label="@string/app_name" >
+ <action android:name="android.intent.action.VIEW" />
+
+ <category android:name="android.intent.category.DEFAULT" />
+ <category android:name="android.intent.category.BROWSABLE" />
+
+ <data
+ android:host="id.southampton.ac.uk"
+ android:pathPrefix="/bus-route/"
+ android:scheme="http" />
+ </intent-filter>
+ <intent-filter android:label="@string/app_name" >
+ <action android:name="android.intent.action.VIEW" />
+
+ <category android:name="android.intent.category.DEFAULT" />
+ <category android:name="android.intent.category.BROWSABLE" />
+
+ <data
+ android:host="data.southampton.ac.uk"
+ android:pathPrefix="/bus-route/"
+ android:scheme="http" />
+ </intent-filter>
</activity>
<activity
android:name=".PreferencesActivity"
diff --git a/gen/net/cbaines/suma/R.java b/gen/net/cbaines/suma/R.java
index 06657e6..f7f3034 100644
--- a/gen/net/cbaines/suma/R.java
+++ b/gen/net/cbaines/suma/R.java
@@ -54,79 +54,82 @@ public final class R {
public static final int u9_radio_button=0x7f02001d;
}
public static final class id {
- public static final int buildingActivityFavouriteCheckBox=0x7f0a0006;
- public static final int buildingActivityID=0x7f0a0007;
- public static final int buildingActivityImage=0x7f0a0008;
+ public static final int buildingActivityFavouriteCheckBox=0x7f0a0005;
+ public static final int buildingActivityImage=0x7f0a0006;
+ public static final int buildingActivityLoadBar=0x7f0a0008;
+ public static final int buildingActivityLoadBarLayout=0x7f0a0007;
+ public static final int buildingActivityMessage=0x7f0a0009;
public static final int buildingActivityName=0x7f0a0004;
- public static final int busActivityBusID=0x7f0a000a;
- public static final int busActivityContentLayout=0x7f0a0010;
- public static final int busActivityHeaderLayout=0x7f0a0009;
- public static final int busActivityMessage=0x7f0a0011;
- public static final int busActivityTimes=0x7f0a0012;
- public static final int busActivityU1=0x7f0a000b;
- public static final int busActivityU1N=0x7f0a000c;
- public static final int busActivityU2=0x7f0a000d;
- public static final int busActivityU6=0x7f0a000e;
- public static final int busActivityU9=0x7f0a000f;
- public static final int busStopID=0x7f0a001a;
- public static final int busStopListItems=0x7f0a0021;
- public static final int busStopLoadBar=0x7f0a001f;
- public static final int busStopMessage=0x7f0a001c;
- public static final int busStopName=0x7f0a0013;
- public static final int busStopTimes=0x7f0a001d;
- public static final int busTimeContentLayout=0x7f0a001b;
- public static final int centerLoadBar=0x7f0a001e;
- public static final int check1=0x7f0a0030;
- public static final int childname=0x7f0a002f;
- public static final int donateBitcoinAddress=0x7f0a0027;
+ public static final int busActivityBusID=0x7f0a000b;
+ public static final int busActivityContentLayout=0x7f0a000c;
+ public static final int busActivityHeaderLayout=0x7f0a000a;
+ public static final int busActivityMessage=0x7f0a000d;
+ public static final int busActivityTimes=0x7f0a000e;
+ public static final int busRouteActivityCode=0x7f0a000f;
+ public static final int busRouteActivityHeaderLayout=0x7f0a0010;
+ public static final int busRouteActivityID=0x7f0a0012;
+ public static final int busRouteActivityLabel=0x7f0a0011;
+ public static final int busRouteBusStops=0x7f0a0013;
+ public static final int busStopID=0x7f0a001c;
+ public static final int busStopListItems=0x7f0a0023;
+ public static final int busStopLoadBar=0x7f0a0021;
+ public static final int busStopMessage=0x7f0a001e;
+ public static final int busStopName=0x7f0a0014;
+ public static final int busStopTimes=0x7f0a001f;
+ public static final int busTimeContentLayout=0x7f0a001d;
+ public static final int centerLoadBar=0x7f0a0020;
+ public static final int check1=0x7f0a0032;
+ public static final int childname=0x7f0a0031;
+ public static final int donateBitcoinAddress=0x7f0a0029;
public static final int donateButton=0x7f0a0003;
- public static final int donateDialogErrorMessage=0x7f0a0026;
- public static final int donateDialogMessage=0x7f0a0023;
- public static final int donateDialogMessageLayout=0x7f0a0025;
- public static final int donateDialogProgress=0x7f0a0024;
- public static final int favouriteCheckBox=0x7f0a0019;
- public static final int favouriteDialogMessage=0x7f0a002d;
- public static final int favouriteListItems=0x7f0a002e;
- public static final int findContentLayout=0x7f0a0029;
- public static final int findListItems=0x7f0a002b;
- public static final int findLoadBar=0x7f0a002a;
+ public static final int donateDialogErrorMessage=0x7f0a0028;
+ public static final int donateDialogMessage=0x7f0a0025;
+ public static final int donateDialogMessageLayout=0x7f0a0027;
+ public static final int donateDialogProgress=0x7f0a0026;
+ public static final int favouriteCheckBox=0x7f0a001b;
+ public static final int favouriteDialogMessage=0x7f0a002f;
+ public static final int favouriteListItems=0x7f0a0030;
+ public static final int findContentLayout=0x7f0a002b;
+ public static final int findListItems=0x7f0a002d;
+ public static final int findLoadBar=0x7f0a002c;
public static final int helpExpandableListView=0x7f0a0002;
- public static final int layout_root=0x7f0a0020;
- public static final int linearLayout1=0x7f0a0005;
- public static final int linearLayout2=0x7f0a0022;
- public static final int mapview=0x7f0a002c;
- public static final int menu_about=0x7f0a0036;
- public static final int menu_favourites=0x7f0a0037;
- public static final int menu_find=0x7f0a0032;
- public static final int menu_find_my_location=0x7f0a0034;
- public static final int menu_next_stop=0x7f0a003a;
- public static final int menu_preferences=0x7f0a0033;
- public static final int menu_previous_stop=0x7f0a0038;
- public static final int menu_refresh_stop=0x7f0a0039;
- public static final int menu_view=0x7f0a0035;
- public static final int radio_u1=0x7f0a0014;
- public static final int radio_u1n=0x7f0a0015;
- public static final int radio_u2=0x7f0a0016;
- public static final int radio_u6=0x7f0a0017;
- public static final int radio_u9=0x7f0a0018;
- public static final int searchBar=0x7f0a0028;
+ public static final int layout_root=0x7f0a0022;
+ public static final int linearLayout1=0x7f0a0015;
+ public static final int linearLayout2=0x7f0a0024;
+ public static final int mapview=0x7f0a002e;
+ public static final int menu_about=0x7f0a0038;
+ public static final int menu_favourites=0x7f0a0039;
+ public static final int menu_find=0x7f0a0034;
+ public static final int menu_find_my_location=0x7f0a0036;
+ public static final int menu_next_stop=0x7f0a003c;
+ public static final int menu_preferences=0x7f0a0035;
+ public static final int menu_previous_stop=0x7f0a003a;
+ public static final int menu_refresh_stop=0x7f0a003b;
+ public static final int menu_view=0x7f0a0037;
+ public static final int radio_u1=0x7f0a0016;
+ public static final int radio_u1n=0x7f0a0017;
+ public static final int radio_u2=0x7f0a0018;
+ public static final int radio_u6=0x7f0a0019;
+ public static final int radio_u9=0x7f0a001a;
+ public static final int searchBar=0x7f0a002a;
public static final int textView1=0x7f0a0000;
public static final int textView2=0x7f0a0001;
- public static final int view_list=0x7f0a0031;
+ public static final int view_list=0x7f0a0033;
}
public static final class layout {
public static final int about_dialog=0x7f030000;
public static final int building_activity=0x7f030001;
public static final int bus_activity=0x7f030002;
- public static final int bus_stop_activity=0x7f030003;
- public static final int bus_stop_dialog=0x7f030004;
- public static final int donate_dialog=0x7f030005;
- public static final int find=0x7f030006;
- public static final int main=0x7f030007;
- public static final int poi_dialog=0x7f030008;
- public static final int view_child_row=0x7f030009;
- public static final int view_dialog=0x7f03000a;
- public static final int view_group_row=0x7f03000b;
+ public static final int bus_route_activity=0x7f030003;
+ public static final int bus_stop_activity=0x7f030004;
+ public static final int bus_stop_dialog=0x7f030005;
+ public static final int donate_dialog=0x7f030006;
+ public static final int find_activity=0x7f030007;
+ public static final int map_activity=0x7f030008;
+ public static final int poi_dialog=0x7f030009;
+ public static final int view_child_row=0x7f03000a;
+ public static final int view_dialog=0x7f03000b;
+ public static final int view_group_row=0x7f03000c;
}
public static final class menu {
public static final int map_menu=0x7f090000;
@@ -150,47 +153,47 @@ public final class R {
public static final int U9=0x7f07000d;
/** About Strings
*/
- public static final int about=0x7f070034;
- public static final int about_android_market=0x7f070041;
- public static final int about_android_market_summary=0x7f070042;
- public static final int about_copyright=0x7f070037;
- public static final int about_copyright_summary=0x7f070038;
- public static final int about_data=0x7f07003f;
- public static final int about_data_summary=0x7f070040;
- public static final int about_database=0x7f07004b;
- public static final int about_database_summary=0x7f07004c;
- public static final int about_developer=0x7f07003d;
- public static final int about_developer_summary=0x7f07003e;
- public static final int about_donate=0x7f07004d;
- public static final int about_donate_summary=0x7f07004e;
+ public static final int about=0x7f070038;
+ public static final int about_android_market=0x7f070045;
+ public static final int about_android_market_summary=0x7f070046;
+ public static final int about_copyright=0x7f07003b;
+ public static final int about_copyright_summary=0x7f07003c;
+ public static final int about_data=0x7f070043;
+ public static final int about_data_summary=0x7f070044;
+ public static final int about_database=0x7f07004f;
+ public static final int about_database_summary=0x7f070050;
+ public static final int about_developer=0x7f070041;
+ public static final int about_developer_summary=0x7f070042;
+ public static final int about_donate=0x7f070051;
+ public static final int about_donate_summary=0x7f070052;
public static final int about_help_message=0x7f070016;
- public static final int about_license=0x7f070039;
- public static final int about_license_summary=0x7f07003a;
- public static final int about_map_data=0x7f070043;
- public static final int about_map_data_summary=0x7f070044;
- public static final int about_map_icons=0x7f070045;
- public static final int about_map_icons_summary=0x7f070046;
- public static final int about_map_tiles=0x7f070049;
- public static final int about_map_tiles_summary=0x7f07004a;
+ public static final int about_license=0x7f07003d;
+ public static final int about_license_summary=0x7f07003e;
+ public static final int about_map_data=0x7f070047;
+ public static final int about_map_data_summary=0x7f070048;
+ public static final int about_map_icons=0x7f070049;
+ public static final int about_map_icons_summary=0x7f07004a;
+ public static final int about_map_tiles=0x7f07004d;
+ public static final int about_map_tiles_summary=0x7f07004e;
/** About Messages
*/
- public static final int about_menu_instruction_text=0x7f07002d;
- public static final int about_osm_map=0x7f070047;
- public static final int about_osm_map_summary=0x7f070048;
- public static final int about_project=0x7f07003b;
- public static final int about_project_summary=0x7f07003c;
- public static final int about_version=0x7f070035;
- public static final int about_version_summary=0x7f070036;
+ public static final int about_menu_instruction_text=0x7f070031;
+ public static final int about_osm_map=0x7f07004b;
+ public static final int about_osm_map_summary=0x7f07004c;
+ public static final int about_project=0x7f07003f;
+ public static final int about_project_summary=0x7f070040;
+ public static final int about_version=0x7f070039;
+ public static final int about_version_summary=0x7f07003a;
public static final int app_name=0x7f070004;
public static final int bitcoin_error_message=0x7f07001b;
- public static final int buildingImageDescription=0x7f07004f;
+ public static final int buildingImageDescription=0x7f070053;
public static final int building_non_residential=0x7f070007;
public static final int building_residential=0x7f070006;
- public static final int bustimes_favourite_checkbox_label=0x7f07002e;
+ public static final int bustimes_favourite_checkbox_label=0x7f070032;
public static final int credits_help_message=0x7f070019;
public static final int donate_button=0x7f07001a;
- public static final int donate_dialog_error_title=0x7f070030;
- public static final int donate_dialog_message=0x7f07002f;
+ public static final int donate_dialog_error_title=0x7f070034;
+ public static final int donate_dialog_message=0x7f070033;
public static final int favourites_dialog_message=0x7f07001d;
public static final int favourites_dialog_title=0x7f070010;
public static final int favourites_help_message=0x7f070017;
@@ -205,31 +208,35 @@ public final class R {
public static final int menu_favourites=0x7f07000f;
public static final int menu_find=0x7f070000;
public static final int menu_find_my_location=0x7f070003;
- public static final int menu_next_stop=0x7f070032;
+ public static final int menu_next_stop=0x7f070036;
public static final int menu_preferences=0x7f070001;
- public static final int menu_previous_stop=0x7f070031;
- public static final int menu_refresh_stop=0x7f070033;
+ public static final int menu_previous_stop=0x7f070035;
+ public static final int menu_refresh_stop=0x7f070037;
public static final int menu_view=0x7f070002;
public static final int pref_bus_stop=0x7f070008;
public static final int preferences=0x7f07001c;
- public static final int preferences_catagory_data=0x7f070029;
- public static final int preferences_catagory_live_bus_times=0x7f070022;
/** Preferences Messages
*/
- public static final int preferences_catagory_positioning=0x7f07001e;
- public static final int preferences_gps=0x7f07001f;
- public static final int preferences_gps_disabled=0x7f070021;
- public static final int preferences_gps_enabled=0x7f070020;
+ public static final int preferences_catagory_appearance=0x7f07001e;
+ public static final int preferences_catagory_data=0x7f07002d;
+ public static final int preferences_catagory_live_bus_times=0x7f070026;
+ public static final int preferences_catagory_positioning=0x7f070022;
+ public static final int preferences_gps=0x7f070023;
+ public static final int preferences_gps_disabled=0x7f070025;
+ public static final int preferences_gps_enabled=0x7f070024;
public static final int preferences_help_message=0x7f070013;
- public static final int preferences_non_uni_link=0x7f07002a;
- public static final int preferences_non_uni_link_disabled=0x7f07002c;
- public static final int preferences_non_uni_link_enabled=0x7f07002b;
- public static final int preferences_non_uni_link_live_bus_times=0x7f070026;
- public static final int preferences_non_uni_link_live_bus_times_disabled=0x7f070028;
- public static final int preferences_non_uni_link_live_bus_times_enabled=0x7f070027;
- public static final int preferences_uni_link_live_bus_times=0x7f070023;
- public static final int preferences_uni_link_live_bus_times_disabled=0x7f070025;
- public static final int preferences_uni_link_live_bus_times_enabled=0x7f070024;
+ public static final int preferences_non_uni_link=0x7f07002e;
+ public static final int preferences_non_uni_link_disabled=0x7f070030;
+ public static final int preferences_non_uni_link_enabled=0x7f07002f;
+ public static final int preferences_non_uni_link_live_bus_times=0x7f07002a;
+ public static final int preferences_non_uni_link_live_bus_times_disabled=0x7f07002c;
+ public static final int preferences_non_uni_link_live_bus_times_enabled=0x7f07002b;
+ public static final int preferences_show_identifiers=0x7f07001f;
+ public static final int preferences_show_identifiers_disabled=0x7f070021;
+ public static final int preferences_show_identifiers_enabled=0x7f070020;
+ public static final int preferences_uni_link_live_bus_times=0x7f070027;
+ public static final int preferences_uni_link_live_bus_times_disabled=0x7f070029;
+ public static final int preferences_uni_link_live_bus_times_enabled=0x7f070028;
public static final int view_help_message=0x7f070015;
}
public static final class xml {
diff --git a/res/layout/building_activity.xml b/res/layout/building_activity.xml
index 6ed937f..777ad0a 100644
--- a/res/layout/building_activity.xml
+++ b/res/layout/building_activity.xml
@@ -10,31 +10,39 @@
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge" />
+ <CheckBox
+ android:id="@+id/buildingActivityFavouriteCheckBox"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:text="@string/bustimes_favourite_checkbox_label" />
+
+ <ImageButton
+ android:id="@+id/buildingActivityImage"
+ android:layout_width="fill_parent"
+ android:layout_height="fill_parent"
+ android:background="@null"
+ android:contentDescription="@string/buildingImageDescription" />
+
<LinearLayout
- android:id="@+id/linearLayout1"
+ xmlns:android="http://schemas.android.com/apk/res/android"
+ android:id="@+id/buildingActivityLoadBarLayout"
android:layout_width="fill_parent"
- android:layout_height="wrap_content" >
+ android:layout_height="fill_parent"
+ android:gravity="center"
+ android:orientation="vertical" >
- <CheckBox
- android:id="@+id/buildingActivityFavouriteCheckBox"
+ <ProgressBar
+ android:id="@+id/buildingActivityLoadBar"
+ style="?android:attr/progressBarStyleLarge"
android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:text="@string/bustimes_favourite_checkbox_label" />
+ android:layout_height="wrap_content" />
<TextView
- android:id="@+id/buildingActivityID"
+ android:id="@+id/buildingActivityMessage"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
- android:paddingLeft="5dp"
- android:paddingRight="5dp"
- android:textAppearance="?android:attr/textAppearanceSmall" />
+ android:text=""
+ android:textAppearance="?android:attr/textAppearanceLarge" />
</LinearLayout>
- <ImageButton
- android:id="@+id/buildingActivityImage"
- android:layout_width="fill_parent"
- android:layout_height="fill_parent"
- android:background="@null"
- android:contentDescription="@string/buildingImageDescription" />
-
</LinearLayout> \ No newline at end of file
diff --git a/res/layout/bus_activity.xml b/res/layout/bus_activity.xml
index 3037916..f8bbe59 100644
--- a/res/layout/bus_activity.xml
+++ b/res/layout/bus_activity.xml
@@ -17,61 +17,6 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge" />
-
- <TextView
- android:id="@+id/busActivityU1"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:background="@drawable/u1_back_selected"
- android:paddingLeft="5dp"
- android:paddingRight="5dp"
- android:text="@string/U1"
- android:textAppearance="?android:attr/textAppearanceSmall"
- android:textColor="#FFFFFF" />
-
- <TextView
- android:id="@+id/busActivityU1N"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:background="@drawable/u1n_back_selected"
- android:paddingLeft="5dp"
- android:paddingRight="5dp"
- android:text="@string/U1N"
- android:textAppearance="?android:attr/textAppearanceSmall"
- android:textColor="#FFFFFF" />
-
- <TextView
- android:id="@+id/busActivityU2"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:background="@drawable/u2_back_selected"
- android:paddingLeft="5dp"
- android:paddingRight="5dp"
- android:text="@string/U2"
- android:textAppearance="?android:attr/textAppearanceSmall"
- android:textColor="#FFFFFF" />
-
- <TextView
- android:id="@+id/busActivityU6"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:background="@drawable/u6_back_selected"
- android:paddingLeft="5dp"
- android:paddingRight="5dp"
- android:text="@string/U6"
- android:textAppearance="?android:attr/textAppearanceSmall"
- android:textColor="#FFFFFF" />
-
- <TextView
- android:id="@+id/busActivityU9"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:background="@drawable/u9_back_selected"
- android:paddingLeft="5dp"
- android:paddingRight="5dp"
- android:text="@string/U9"
- android:textAppearance="?android:attr/textAppearanceSmall"
- android:textColor="#FFFFFF" />
</LinearLayout>
<LinearLayout
diff --git a/res/layout/bus_route_activity.xml b/res/layout/bus_route_activity.xml
new file mode 100644
index 0000000..48cdadc
--- /dev/null
+++ b/res/layout/bus_route_activity.xml
@@ -0,0 +1,42 @@
+<?xml version="1.0" encoding="utf-8"?>
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="fill_parent"
+ android:layout_height="fill_parent"
+ android:gravity="center|top"
+ android:orientation="vertical"
+ android:theme="@android:style/Theme.NoTitleBar" >
+
+ <TextView
+ android:id="@+id/busRouteActivityCode"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ android:textAppearance="?android:attr/textAppearanceLarge" />
+
+ <LinearLayout
+ android:id="@+id/busRouteActivityHeaderLayout"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ android:orientation="horizontal" >
+
+ <TextView
+ android:id="@+id/busRouteActivityLabel"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:paddingRight="5dp"
+ android:textAppearance="?android:attr/textAppearanceMedium" />
+
+ <TextView
+ android:id="@+id/busRouteActivityID"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:textAppearance="?android:attr/textAppearanceMedium"
+ android:visibility="gone" />
+ </LinearLayout>
+
+ <ListView
+ android:id="@+id/busRouteBusStops"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content" >
+ </ListView>
+
+</LinearLayout> \ No newline at end of file
diff --git a/res/layout/bus_stop_activity.xml b/res/layout/bus_stop_activity.xml
index 24200c6..3f4dc98 100644
--- a/res/layout/bus_stop_activity.xml
+++ b/res/layout/bus_stop_activity.xml
@@ -27,7 +27,7 @@
android:paddingLeft="5dp"
android:paddingRight="5dp"
android:text="@string/U1"
- android:textAppearance="?android:attr/textAppearanceSmall"
+ android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#FFFFFF" />
<CheckBox
@@ -40,7 +40,7 @@
android:paddingLeft="5dp"
android:paddingRight="5dp"
android:text="@string/U1N"
- android:textAppearance="?android:attr/textAppearanceSmall"
+ android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#FFFFFF" />
<CheckBox
@@ -53,7 +53,7 @@
android:paddingLeft="5dp"
android:paddingRight="5dp"
android:text="@string/U2"
- android:textAppearance="?android:attr/textAppearanceSmall"
+ android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#FFFFFF" />
<CheckBox
@@ -66,7 +66,7 @@
android:paddingLeft="5dp"
android:paddingRight="5dp"
android:text="@string/U6"
- android:textAppearance="?android:attr/textAppearanceSmall"
+ android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#FFFFFF" />
<CheckBox
@@ -79,14 +79,15 @@
android:paddingLeft="5dp"
android:paddingRight="5dp"
android:text="@string/U9"
- android:textAppearance="?android:attr/textAppearanceSmall"
+ android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#FFFFFF" />
<CheckBox
android:id="@+id/favouriteCheckBox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
- android:text="@string/bustimes_favourite_checkbox_label" />
+ android:text="@string/bustimes_favourite_checkbox_label"
+ android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="@+id/busStopID"
@@ -94,7 +95,8 @@
android:layout_height="wrap_content"
android:paddingLeft="5dp"
android:paddingRight="5dp"
- android:textAppearance="?android:attr/textAppearanceSmall" />
+ android:textAppearance="?android:attr/textAppearanceSmall"
+ android:visibility="gone" />
</LinearLayout>
<LinearLayout
diff --git a/res/layout/find.xml b/res/layout/find_activity.xml
index 6b19c67..6b19c67 100644
--- a/res/layout/find.xml
+++ b/res/layout/find_activity.xml
diff --git a/res/layout/main.xml b/res/layout/map_activity.xml
index dff45bd..dff45bd 100644
--- a/res/layout/main.xml
+++ b/res/layout/map_activity.xml
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 6333664..f3850a3 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -74,6 +74,10 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.<
</string-array>
<!-- Preferences Messages -->
+ <string name="preferences_catagory_appearance">Appearance</string>
+ <string name="preferences_show_identifiers">Show Identifiers</string>
+ <string name="preferences_show_identifiers_enabled">Showing Identifiers</string>
+ <string name="preferences_show_identifiers_disabled">Hiding Identifiers</string>
<string name="preferences_catagory_positioning">Positioning</string>
<string name="preferences_gps">GPS</string>
<string name="preferences_gps_enabled">GPS Enabled</string>
@@ -102,7 +106,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.<
<!-- About Strings -->
<string name="about">About</string>
<string name="about_version">Version</string>
- <string name="about_version_summary">0.4 (alpha)</string>
+ <string name="about_version_summary">0.5 (alpha)</string>
<string name="about_copyright">Copyright</string>
<string name="about_copyright_summary">© 2012, Christopher Baines</string>
<string name="about_license">License</string>
diff --git a/res/xml/preferences.xml b/res/xml/preferences.xml
index 4a12e1c..9de3a61 100644
--- a/res/xml/preferences.xml
+++ b/res/xml/preferences.xml
@@ -3,6 +3,15 @@
<PreferenceCategory
android:orderingFromXml="true"
+ android:title="@string/preferences_catagory_appearance" >
+ <CheckBoxPreference
+ android:key="showIdentifiers"
+ android:summaryOff="@string/preferences_show_identifiers_disabled"
+ android:summaryOn="@string/preferences_show_identifiers_enabled"
+ android:title="@string/preferences_show_identifiers" />
+ </PreferenceCategory>
+ <PreferenceCategory
+ android:orderingFromXml="true"
android:title="@string/preferences_catagory_positioning" >
<CheckBoxPreference
android:key="GPSEnabled"
diff --git a/src/net/cbaines/suma/AboutActivity.java b/src/net/cbaines/suma/AboutActivity.java
index a455d70..74e0249 100644
--- a/src/net/cbaines/suma/AboutActivity.java
+++ b/src/net/cbaines/suma/AboutActivity.java
@@ -30,72 +30,74 @@ import android.util.Log;
public class AboutActivity extends PreferenceActivity {
- static final int DONATE_DIALOG_ID = 0;
+ static final int DONATE_DIALOG_ID = 0;
- private static final String KEY_ABOUT_LICENSE = "about_license";
- private static final String KEY_ABOUT_PROJECT = "about_project";
- private static final String KEY_ABOUT_DEVELOPER = "about_developer";
- private static final String KEY_ABOUT_DATA = "about_data";
- private static final String KEY_ABOUT_ANDROID_MARKET = "about_android_market";
- private static final String KEY_ABOUT_MAP_DATA = "about_map_data";
- private static final String KEY_ABOUT_MAP_ICONS = "about_map_icons";
- private static final String KEY_ABOUT_OSM_MAP = "about_osm_map";
- private static final String KEY_ABOUT_MAP_TILES = "about_map_tiles";
- private static final String KEY_ABOUT_DATABASE = "about_database";
- private static final String KEY_ABOUT_DONATE = "about_donate";
+ private static final String KEY_ABOUT_LICENSE = "about_license";
+ private static final String KEY_ABOUT_PROJECT = "about_project";
+ private static final String KEY_ABOUT_DEVELOPER = "about_developer";
+ private static final String KEY_ABOUT_DATA = "about_data";
+ private static final String KEY_ABOUT_ANDROID_MARKET = "about_android_market";
+ private static final String KEY_ABOUT_MAP_DATA = "about_map_data";
+ private static final String KEY_ABOUT_MAP_ICONS = "about_map_icons";
+ private static final String KEY_ABOUT_OSM_MAP = "about_osm_map";
+ private static final String KEY_ABOUT_MAP_TILES = "about_map_tiles";
+ private static final String KEY_ABOUT_DATABASE = "about_database";
+ private static final String KEY_ABOUT_DONATE = "about_donate";
- private static final String TAG = "AboutActivity";
+ private static final String TAG = "AboutActivity";
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
+ public void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
- addPreferencesFromResource(R.xml.about);
- }
+ addPreferencesFromResource(R.xml.about);
+ }
- @Override
- public boolean onPreferenceTreeClick(final PreferenceScreen preferenceScreen, final Preference preference) {
- try {
- final String key = preference.getKey();
- 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")));
- } 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" });
- emailIntent.setType("text/plain");
+ @Override
+ public boolean onPreferenceTreeClick(final PreferenceScreen preferenceScreen, final Preference preference) {
+ try {
+ final String key = preference.getKey();
+ 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")));
+ } 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" });
+ emailIntent.setType("text/plain");
- startActivity(Intent.createChooser(emailIntent, "Email the developer"));
- } else if (KEY_ABOUT_DATA.equals(key)) {
- startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://data.southampton.ac.uk/bus-routes.html")));
- } 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"))));
- } 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)) {
- startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.openstreetmap.org/")));
- } else if (KEY_ABOUT_MAP_TILES.equals(key)) {
- startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.mapquest.com/")));
- } else if (KEY_ABOUT_DATABASE.equals(key)) {
- startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(String.format("http://ormlite.com/"))));
- } else if (KEY_ABOUT_DONATE.equals(key)) {
- showDialog(DONATE_DIALOG_ID);
- }
- } catch (Exception e) {
- Log.e("Error opening one of the icons", TAG, e);
+ startActivity(Intent.createChooser(emailIntent, "Email the developer"));
+ } else if (KEY_ABOUT_DATA.equals(key)) {
+ startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://data.southampton.ac.uk/bus-routes.html")));
+ } 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"))));
+ } 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)) {
+ startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.openstreetmap.org/")));
+ } else if (KEY_ABOUT_MAP_TILES.equals(key)) {
+ startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.mapquest.com/")));
+ } else if (KEY_ABOUT_DATABASE.equals(key)) {
+ startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(String.format("http://ormlite.com/"))));
+ } else if (KEY_ABOUT_DONATE.equals(key)) {
+ showDialog(DONATE_DIALOG_ID);
+ }
+ } catch (Exception e) {
+ Log.e("Error opening one of the icons", TAG, e);
+ }
+ return false;
}
- return false;
- }
- protected Dialog onCreateDialog(int id) {
- switch (id) {
- case DONATE_DIALOG_ID:
- DonateDialog donateDialog = new DonateDialog(this);
- return donateDialog;
+ protected Dialog onCreateDialog(int id) {
+ switch (id) {
+ case DONATE_DIALOG_ID:
+ DonateDialog donateDialog = new DonateDialog(this);
+ return donateDialog;
+ }
+ return null;
}
- return null;
- }
}
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 6b03164..509bc41 100644
--- a/src/net/cbaines/suma/BuildingActivity.java
+++ b/src/net/cbaines/suma/BuildingActivity.java
@@ -28,6 +28,7 @@ import java.sql.SQLException;
import android.content.Context;
import android.content.SharedPreferences;
import android.graphics.drawable.Drawable;
+import android.os.AsyncTask;
import android.os.Bundle;
import android.util.Log;
import android.view.Display;
@@ -38,6 +39,7 @@ import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.ImageButton;
import android.widget.ImageView.ScaleType;
+import android.widget.ProgressBar;
import android.widget.TextView;
import com.j256.ormlite.android.apptools.OrmLiteBaseActivity;
@@ -52,10 +54,12 @@ public class BuildingActivity extends OrmLiteBaseActivity<DatabaseHelper> implem
private ImageButton imageButton;
private TextView buildingName;
- private TextView buildingID;
private Building building;
+ private ProgressBar progressBar;
+ private TextView message;
+
private CheckBox favouritesCheckBox;
public void onCreate(Bundle savedInstanceState) {
@@ -63,7 +67,19 @@ public class BuildingActivity extends OrmLiteBaseActivity<DatabaseHelper> implem
setContentView(R.layout.building_activity);
instance = this;
- String ID = getIntent().getExtras().getString("buildingID");
+ 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];
+ }
final SharedPreferences favouritesPrefs = instance.getSharedPreferences(FAVOURITES_PREFERENCES, 0);
@@ -72,7 +88,9 @@ public class BuildingActivity extends OrmLiteBaseActivity<DatabaseHelper> implem
favouritesCheckBox.setOnCheckedChangeListener(this);
buildingName = (TextView) findViewById(R.id.buildingActivityName);
- buildingID = (TextView) findViewById(R.id.buildingActivityID);
+
+ progressBar = (ProgressBar) findViewById(R.id.buildingActivityLoadBar);
+ message = (TextView) findViewById(R.id.buildingActivityMessage);
Log.i(TAG, "Building id " + ID);
@@ -81,83 +99,92 @@ public class BuildingActivity extends OrmLiteBaseActivity<DatabaseHelper> implem
building = buildingDao.queryForId(ID);
- buildingName.setText(building.name);
+ buildingName.setText("Building " + building.id + " - " + building.name);
} catch (SQLException e1) {
- // TODO Auto-generated catch block
e1.printStackTrace();
}
- buildingID.setText(ID);
- try {
+ GetBuildingImageTask buildingImageTask = new GetBuildingImageTask();
+ buildingImageTask.execute(building);
- /* First, get the Display from the WindowManager */
- Display display = ((WindowManager) getSystemService(WINDOW_SERVICE)).getDefaultDisplay();
-
- /* Now we can retrieve all display-related infos */
- int orientation = display.getOrientation();
- Log.i(TAG, "orientation " + orientation);
- Log.i(TAG, "width " + display.getWidth() + " height " + display.getHeight());
- int width;
- // if (orientation == 0) {
- width = display.getWidth();
- // } else {
- // width = display.getHeight();
- // }
-
- URL imageURL;
- Log.i(TAG, "Screen width " + width);
- if (width >= 1000) {
- imageURL = new URL("http://data.southampton.ac.uk/images/buildings/1000/" + ID + ".jpg");
- } else if (width >= 800) {
- imageURL = new URL("http://data.southampton.ac.uk/images/buildings/1000/" + ID + ".jpg");
- } else if (width >= 600) {
- imageURL = new URL("http://data.southampton.ac.uk/images/buildings/600/" + ID + ".jpg");
- } else if (width >= 400) {
- imageURL = new URL("http://data.southampton.ac.uk/images/buildings/600/" + ID + ".jpg");
- } else if (width >= 300) {
- imageURL = new URL("http://data.southampton.ac.uk/images/buildings/300/" + ID + ".jpg");
- } else if (width >= 200) {
- imageURL = new URL("http://data.southampton.ac.uk/images/buildings/200/" + ID + ".jpg");
- } else {
- imageURL = new URL("http://data.southampton.ac.uk/images/buildings/100/" + ID + ".jpg");
- }
- Log.i(TAG, "URL " + imageURL);
+ }
- InputStream is = (InputStream) imageURL.getContent();
- Drawable image = Drawable.createFromStream(is, "src");
+ class GetBuildingImageTask extends AsyncTask<Building, Integer, Drawable> {
+ String errorMessage;
+
+ @Override
+ protected Drawable doInBackground(Building... buildings) {
+ Building building = buildings[0];
+
+ Log.i(TAG, "Getting image for " + building);
+
+ try {
+
+ Display display = ((WindowManager) getSystemService(WINDOW_SERVICE)).getDefaultDisplay();
+
+ int orientation = display.getOrientation();
+ Log.i(TAG, "orientation " + orientation);
+ Log.i(TAG, "width " + display.getWidth() + " height " + display.getHeight());
+ int width;
+ width = display.getWidth();
+
+ URL imageURL;
+ Log.i(TAG, "Screen width " + width);
+ if (width >= 1000) {
+ imageURL = new URL("http://data.southampton.ac.uk/images/buildings/1000/" + building.id + ".jpg");
+ } else if (width >= 800) {
+ imageURL = new URL("http://data.southampton.ac.uk/images/buildings/1000/" + building.id + ".jpg");
+ } else if (width >= 600) {
+ imageURL = new URL("http://data.southampton.ac.uk/images/buildings/600/" + building.id + ".jpg");
+ } else if (width >= 400) {
+ imageURL = new URL("http://data.southampton.ac.uk/images/buildings/600/" + building.id + ".jpg");
+ } else if (width >= 300) {
+ imageURL = new URL("http://data.southampton.ac.uk/images/buildings/300/" + building.id + ".jpg");
+ } else if (width >= 200) {
+ imageURL = new URL("http://data.southampton.ac.uk/images/buildings/200/" + building.id + ".jpg");
+ } else {
+ imageURL = new URL("http://data.southampton.ac.uk/images/buildings/100/" + building.id + ".jpg");
+ }
+ Log.i(TAG, "URL " + imageURL);
- imageButton = new ImageButton(this);
- imageButton = (ImageButton) findViewById(R.id.buildingActivityImage);
- imageButton.setImageDrawable(image);
- imageButton.setScaleType(ScaleType.CENTER_INSIDE);
- imageButton.setOnClickListener(new View.OnClickListener() {
- public void onClick(View v) {
+ InputStream is = (InputStream) imageURL.getContent();
+ Drawable image = Drawable.createFromStream(is, "src");
- }
- });
-
- } catch (MalformedURLException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
+ return image;
+
+ } catch (MalformedURLException e) {
+ e.printStackTrace();
+ errorMessage = "MalformedURLException";
+ } catch (IOException e) {
+ e.printStackTrace();
+ errorMessage = "IOException";
+ }
+
+ return null;
}
- }
+ protected void onPostExecute(Drawable image) {
+ progressBar.setVisibility(View.GONE);
- public void onResume() {
- super.onResume();
- }
+ if (image != null) {
+ Log.i(TAG, "Got a image for " + building + ", now displaying it");
- public void onPause() {
- super.onPause();
- }
+ imageButton = (ImageButton) findViewById(R.id.buildingActivityImage);
+ imageButton.setImageDrawable(image);
+ imageButton.setScaleType(ScaleType.CENTER_INSIDE);
+ imageButton.setOnClickListener(new View.OnClickListener() {
+ public void onClick(View v) {
+
+ }
+ });
+ } else {
+ Log.e(TAG, "Error, null image, " + errorMessage);
- public void finish() {
- setResult(RESULT_OK, getIntent());
- super.finish();
+ message.setText(errorMessage);
+ message.setVisibility(View.VISIBLE);
+ }
+ }
}
@Override
diff --git a/src/net/cbaines/suma/BuildingNumOverlay.java b/src/net/cbaines/suma/BuildingNumOverlay.java
index cc20003..a4cf556 100644
--- a/src/net/cbaines/suma/BuildingNumOverlay.java
+++ b/src/net/cbaines/suma/BuildingNumOverlay.java
@@ -29,7 +29,6 @@ import org.osmdroid.views.MapView;
import org.osmdroid.views.MapView.Projection;
import org.osmdroid.views.overlay.Overlay;
-import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
@@ -40,6 +39,7 @@ import android.graphics.Paint.Style;
import android.graphics.Point;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
+import android.net.Uri;
import android.util.Log;
import android.view.MotionEvent;
import android.widget.Toast;
@@ -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 + ")");
@@ -221,9 +232,12 @@ public class BuildingNumOverlay extends Overlay implements Preferences, OnShared
} else {
Log.i(TAG, "Pressed " + building.id);
- Intent i = new Intent(context, BuildingActivity.class);
- i.putExtra("buildingID", building.id);
- ((Activity) context).startActivityForResult(i, 0);
+ Uri uri = Uri.parse("http://id.southampton.ac.uk/building/" + building.id);
+
+ Log.i(TAG, "Starting a activity for " + uri + " path " + uri.getPath());
+
+ Intent buildingIntent = new Intent(Intent.ACTION_VIEW, uri);
+ context.startActivity(buildingIntent);
return true;
}
@@ -249,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");
@@ -258,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");
@@ -268,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();
@@ -301,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/BusActivity.java b/src/net/cbaines/suma/BusActivity.java
index e7ddc30..5368bd4 100644
--- a/src/net/cbaines/suma/BusActivity.java
+++ b/src/net/cbaines/suma/BusActivity.java
@@ -27,12 +27,6 @@ import com.j256.ormlite.android.apptools.OrmLiteBaseActivity;
public class BusActivity extends OrmLiteBaseActivity<DatabaseHelper> implements Preferences {
final static String TAG = "BusActivity";
- private TextView U1RouteTextView;
- private TextView U1NRouteTextView;
- private TextView U2RouteTextView;
- private TextView U6RouteTextView;
- private TextView U9RouteTextView;
-
private TextView busIDTextView;
private TextView busContentMessage;
@@ -70,7 +64,23 @@ public class BusActivity extends OrmLiteBaseActivity<DatabaseHelper> implements
setContentView(R.layout.bus_activity);
instance = this;
- String busID = getIntent().getExtras().getString("busID");
+ Log.i(TAG, "getIntent().getDataString() " + getIntent().getDataString());
+
+ String busID;
+
+ if (getIntent().getDataString().startsWith("http://data")) {
+
+ String[] uriParts = getIntent().getDataString().split("/");
+
+ busID = uriParts[uriParts.length - 1].replace(".html", "");
+
+ } else {
+
+ String[] uriParts = getIntent().getDataString().split("/");
+
+ busID = uriParts[uriParts.length - 1];
+ }
+
String busStopID = getIntent().getExtras().getString("busStopID");
final DatabaseHelper helper = getHelper();
@@ -99,12 +109,6 @@ public class BusActivity extends OrmLiteBaseActivity<DatabaseHelper> implements
}
}
- U1RouteTextView = (TextView) findViewById(R.id.busActivityU1);
- U1NRouteTextView = (TextView) findViewById(R.id.busActivityU1N);
- U2RouteTextView = (TextView) findViewById(R.id.busActivityU2);
- U6RouteTextView = (TextView) findViewById(R.id.busActivityU6);
- U9RouteTextView = (TextView) findViewById(R.id.busActivityU9);
-
busIDTextView = (TextView) findViewById(R.id.busActivityBusID);
busContentMessage = (TextView) findViewById(R.id.busActivityMessage);
@@ -120,31 +124,6 @@ public class BusActivity extends OrmLiteBaseActivity<DatabaseHelper> implements
busIDTextView.setText("Unidentified");
}
- U1RouteTextView.setVisibility(View.GONE);
- U1NRouteTextView.setVisibility(View.GONE);
- U2RouteTextView.setVisibility(View.GONE);
- U6RouteTextView.setVisibility(View.GONE);
- U9RouteTextView.setVisibility(View.GONE);
-
- // if (bus.route.uniLink) {
- Log.i(TAG, "Bus is uniLink");
- if (bus.route.code.equals("U1")) {
- U1RouteTextView.setVisibility(View.VISIBLE);
- } else if (bus.route.code.equals("U1N")) {
- U1NRouteTextView.setVisibility(View.VISIBLE);
- } else if (bus.route.code.equals("U2")) {
- U2RouteTextView.setVisibility(View.VISIBLE);
- } else if (bus.route.code.equals("U6")) {
- U6RouteTextView.setVisibility(View.VISIBLE);
- } else if (bus.route.code.equals("U9")) {
- U9RouteTextView.setVisibility(View.VISIBLE);
- } else {
- Log.e(TAG, "Route not found " + bus.route.code);
- }
- // } else {
- // Log.i(TAG, "Bus is not uniLink");
- // }
-
} catch (NumberFormatException e) {
e.printStackTrace();
} catch (SQLException e) {
diff --git a/src/net/cbaines/suma/BusRoute.java b/src/net/cbaines/suma/BusRoute.java
index 4152605..ff80c66 100644
--- a/src/net/cbaines/suma/BusRoute.java
+++ b/src/net/cbaines/suma/BusRoute.java
@@ -22,6 +22,7 @@ package net.cbaines.suma;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Calendar;
+import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
@@ -45,456 +46,530 @@ import com.j256.ormlite.table.DatabaseTable;
@DatabaseTable(tableName = "busroutes")
public class BusRoute {
- private static final String TAG = "BusRoute";
-
- final static String ID_FIELD_NAME = "id";
- final static String CODE_FIELD_NAME = "code";
- final static String LABEL_FIELD_NAME = "label";
-
- @DatabaseField(id = true)
- public int id;
-
- /**
- * The route code (U1, U1N, ...)
- */
- @DatabaseField
- public String code;
-
- @DatabaseField(canBeNull = false)
- String label;
-
- /**
- * The direction the bus is travelling if it is moving through the route and sequence is increasing.
- * <ul>
- * <li>U1 = A</li>
- * <li>U2 = B</li>
- * <li>U6 = H</li>
- * </ul>
- */
- @DatabaseField(canBeNull = true)
- String forwardDirection;
-
- /**
- * The direction the bus is travelling if it is moving through the route and sequence is decreasing.
- * <ul>
- * <li>U1 = C</li>
- * <li>U2 = C</li>
- * <li>U6 = C</li>
- * </ul>
- */
- @DatabaseField(canBeNull = true)
- String reverseDirection;
-
- @DatabaseField(canBeNull = false)
- boolean uniLink;
-
- BusRoute() {
- }
-
- public BusRoute(Integer id, String code, String label, String forwardDirection, String reverseDirection,
- boolean uniLink) {
- this.id = id.intValue();
- this.code = code;
- this.label = label;
- this.forwardDirection = forwardDirection;
- this.reverseDirection = reverseDirection;
- this.uniLink = uniLink;
- }
-
- public BusRoute(Integer id, String code, String label, boolean uniLink) {
- this(id, code, label, null, null, uniLink);
- }
-
- public String toString() {
- return code;
- }
-
- /**
- * Untested?
- *
- * @param context
- * @param stop
- * @return
- */
- BusStop getBusStopBefore(Context context, BusStop stop, String dir) {
- return moveInRoute(context, stop, dir, -1);
- }
-
- /**
- * Untested?
- *
- * @param context
- * @param stop
- * @return
- */
- BusStop getStopAfter(Context context, BusStop stop, String dir) {
- return moveInRoute(context, stop, dir, 1);
- }
-
- /**
- * Untested?
- *
- * @param context
- * @param busStop
- * @param moveAmount
- * @return
- */
- Set<BusStop> moveInRoute(final Context context, final BusStop busStop, final int moveAmount) {
-
- Set<BusStop> busStops = new HashSet<BusStop>();
-
- if (moveAmount == 0) {
- busStops.add(busStop);
- return busStops;
+ private static final String TAG = "BusRoute";
+
+ final static String ID_FIELD_NAME = "id";
+ final static String CODE_FIELD_NAME = "code";
+ final static String LABEL_FIELD_NAME = "label";
+
+ @DatabaseField(id = true)
+ public int id;
+
+ /**
+ * The route code (U1, U1N, ...)
+ */
+ @DatabaseField
+ public String code;
+
+ @DatabaseField(canBeNull = false)
+ String label;
+
+ /**
+ * The direction the bus is travelling if it is moving through the route and sequence is increasing.
+ * <ul>
+ * <li>U1 = A</li>
+ * <li>U2 = B</li>
+ * <li>U6 = H</li>
+ * </ul>
+ */
+ @DatabaseField(canBeNull = true)
+ String forwardDirection;
+
+ /**
+ * The direction the bus is travelling if it is moving through the route and sequence is decreasing.
+ * <ul>
+ * <li>U1 = C</li>
+ * <li>U2 = C</li>
+ * <li>U6 = C</li>
+ * </ul>
+ */
+ @DatabaseField(canBeNull = true)
+ String reverseDirection;
+
+ @DatabaseField(canBeNull = false)
+ boolean uniLink;
+
+ BusRoute() {
}
- DatabaseHelper helper = OpenHelperManager.getHelper(context, DatabaseHelper.class);
+ public BusRoute(Integer id, String code, String label, String forwardDirection, String reverseDirection, boolean uniLink) {
+ this.id = id.intValue();
+ this.code = code;
+ this.label = label;
+ this.forwardDirection = forwardDirection;
+ this.reverseDirection = reverseDirection;
+ this.uniLink = uniLink;
+ }
- try {
- Dao<RouteStops, Integer> routeStopsDao = helper.getRouteStopsDao();
- Dao<BusStop, String> busStopDao = helper.getBusStopDao();
+ public BusRoute(Integer id, String code, String label, boolean uniLink) {
+ this(id, code, label, null, null, uniLink);
+ }
- QueryBuilder<RouteStops, Integer> routeStopsQueryBuilder = routeStopsDao.queryBuilder();
- routeStopsQueryBuilder.where().eq(RouteStops.ROUTE_ID_FIELD_NAME, this.id);
- PreparedQuery<RouteStops> routeStopsPreparedQuery = routeStopsQueryBuilder.prepare();
+ public String toString() {
+ return code;
+ }
- List<RouteStops> routeStopsFound = routeStopsDao.query(routeStopsPreparedQuery);
+ /**
+ * Untested?
+ *
+ * @param context
+ * @param stop
+ * @return
+ */
+ BusStop getBusStopBefore(Context context, BusStop stop, String dir) {
+ return moveInRoute(context, stop, dir, -1);
+ }
- ArrayList<Integer> stopIndexs = new ArrayList<Integer>();
+ /**
+ * Untested?
+ *
+ * @param context
+ * @param stop
+ * @return
+ */
+ BusStop getStopAfter(Context context, BusStop stop, String dir) {
+ return moveInRoute(context, stop, dir, 1);
+ }
- for (RouteStops routeStop : routeStopsFound) {
- if (routeStop.busStop.id.equals(busStop.id)) {
- stopIndexs.add(routeStop.sequence - 1);
- }
- }
-
- for (int stopIndex : stopIndexs) {
-
- if (moveAmount > 0) {
- Log.v(TAG, "Moving forward " + moveAmount + " stops from " + busStop + " (" + stopIndex + "/"
- + routeStopsFound.size() + ")");
- int stopWanted = stopIndex + moveAmount;
- if ((stopWanted + 1) > routeStopsFound.size()) {
- Log.v(TAG, "Off the end of the route");
- stopWanted = stopWanted % (routeStopsFound.size() - 1);
- }
- Log.v(TAG, " Stop wanted " + stopWanted);
- BusStop busStopWanted = routeStopsFound.get(stopWanted).busStop;
-
- busStopDao.refresh(busStopWanted);
-
- Log.v(TAG, " Moving to " + busStopWanted + " (" + stopWanted + ") in route " + this);
-
- busStops.add(busStopWanted);
- } else {
- Log.v(TAG, "stopIndex " + stopIndex);
- int stopWanted = stopIndex + moveAmount;
- if (stopWanted < 0) {
- stopWanted = routeStopsFound.size() - (Math.abs(stopWanted) % routeStopsFound.size());
- }
- Log.v(TAG, "stopWanted " + stopWanted);
- busStopDao.refresh(routeStopsFound.get(stopWanted).busStop);
-
- Log.v(TAG,
- "Moving backwards " + moveAmount + " stops from " + busStop + " to "
- + routeStopsFound.get(stopWanted).busStop + " in route " + this);
-
- busStops.add(routeStopsFound.get(stopWanted).busStop);
+ /**
+ * Untested?
+ *
+ * @param context
+ * @param busStop
+ * @param moveAmount
+ * @return
+ */
+ Set<BusStop> moveInRoute(final Context context, final BusStop busStop, final int moveAmount) {
+
+ Set<BusStop> busStops = new HashSet<BusStop>();
+
+ if (moveAmount == 0) {
+ busStops.add(busStop);
+ return busStops;
}
- }
- return busStops;
- } catch (SQLException e) {
- e.printStackTrace();
- }
- Log.e(TAG, "Error moving in route");
- return null;
- }
-
- /**
- * Untested?
- *
- * @param context
- * @param busStop
- * @param moveAmount
- * @return
- */
- BusStop moveInRoute(final Context context, final BusStop busStop, String direction, final int moveAmount) {
-
- if (moveAmount == 0) {
- return busStop;
- }
+ DatabaseHelper helper = OpenHelperManager.getHelper(context, DatabaseHelper.class);
+
+ try {
+ Dao<RouteStop, Integer> routeStopsDao = helper.getRouteStopsDao();
+ Dao<BusStop, String> busStopDao = helper.getBusStopDao();
+
+ QueryBuilder<RouteStop, Integer> routeStopsQueryBuilder = routeStopsDao.queryBuilder();
+ routeStopsQueryBuilder.where().eq(RouteStop.ROUTE_ID_FIELD_NAME, this.id);
+ PreparedQuery<RouteStop> routeStopsPreparedQuery = routeStopsQueryBuilder.prepare();
- DatabaseHelper helper = OpenHelperManager.getHelper(context, DatabaseHelper.class);
+ List<RouteStop> routeStopsFound = routeStopsDao.query(routeStopsPreparedQuery);
+ Collections.sort(routeStopsFound);
- if (forwardDirection != null) {
+ Set<Integer> stopIndexs = new HashSet<Integer>();
- if (direction != null) {
+ for (RouteStop routeStop : routeStopsFound) {
+ if (routeStop.busStop.id.equals(busStop.id)) {
+ stopIndexs.add(routeStop.sequence - 1);
+ }
+ }
+
+ for (int stopIndex : stopIndexs) {
+
+ if (moveAmount > 0) {
+ Log.v(TAG, "Moving forward " + moveAmount + " stops from " + busStop + " (" + stopIndex + "/"
+ + routeStopsFound.size() + ")");
+ int stopWanted = stopIndex + moveAmount;
+ if ((stopWanted + 1) > routeStopsFound.size()) {
+ Log.v(TAG, "Off the end of the route");
+ stopWanted = stopWanted % (routeStopsFound.size() - 1);
+ }
+ Log.v(TAG, " Stop wanted " + stopWanted);
+ BusStop busStopWanted = routeStopsFound.get(stopWanted).busStop;
+
+ busStopDao.refresh(busStopWanted);
+
+ Log.v(TAG, " Moving to " + busStopWanted + " (" + stopWanted + ") in route " + this);
+
+ busStops.add(busStopWanted);
+ } else {
+ Log.v(TAG, "stopIndex " + stopIndex);
+ int stopWanted = stopIndex + moveAmount;
+ if (stopWanted < 0) {
+ stopWanted = routeStopsFound.size() - (Math.abs(stopWanted) % routeStopsFound.size());
+ }
+ Log.v(TAG, "stopWanted " + stopWanted);
+ busStopDao.refresh(routeStopsFound.get(stopWanted).busStop);
+
+ Log.v(TAG,
+ "Moving backwards " + moveAmount + " stops from " + busStop + " to "
+ + routeStopsFound.get(stopWanted).busStop + " in route " + this);
+
+ busStops.add(routeStopsFound.get(stopWanted).busStop);
+ }
+ }
- if (direction.equals("E"))
- direction = "A"; // Quick hack for U1E
- } else {
- throw new NullPointerException("direction is null");
- }
+ return busStops;
+ } catch (SQLException e) {
+ e.printStackTrace();
+ }
+ Log.e(TAG, "Error moving in route");
+ return null;
}
- try {
- Dao<RouteStops, Integer> routeStopsDao = helper.getRouteStopsDao();
- Dao<BusStop, String> busStopDao = helper.getBusStopDao();
-
- QueryBuilder<RouteStops, Integer> routeStopsQueryBuilder = routeStopsDao.queryBuilder();
- routeStopsQueryBuilder.where().eq(RouteStops.ROUTE_ID_FIELD_NAME, this.id);
- PreparedQuery<RouteStops> routeStopsPreparedQuery = routeStopsQueryBuilder.prepare();
-
- List<RouteStops> routeStopsFound = routeStopsDao.query(routeStopsPreparedQuery);
-
- int stopIndex = -1;
-
- for (RouteStops routeStop : routeStopsFound) {
- if (routeStop.busStop.id.equals(busStop.id)) {
- if (stopIndex == -1) {
- stopIndex = routeStop.sequence - 1;
- } else { // ARGH, weird route
- if (busStop.id.equals("HAA13651") && id == 327) { // U6 by Wessex Lane
- if (direction.equals(forwardDirection)) {
- stopIndex = 23;
- } else {
- stopIndex = 68;
- }
- } else if (busStop.id.equals("SN120134") && id == 327) { // U6 opposite the Stile
- if (direction.equals(forwardDirection)) {
- stopIndex = 30;
- } else {
- stopIndex = 59;
- }
- } else if (busStop.id.equals("SN120163") && id == 327) { // U6 just up past wessex lane
- if (direction.equals(forwardDirection)) {
- stopIndex = 22;
- } else {
- stopIndex = 67;
- }
- } else if (busStop.id.equals("SNA19482") && id == 327) { // U6 General Hosp West Door
- if (moveAmount > 0) {
- stopIndex = 44;
- } else {
- stopIndex = 43;
- }
- } else if (busStop.id.equals("SN120134") && id == 329) { // U2 opposite the Stile
- if (direction.equals(forwardDirection)) {
- stopIndex = 13;
- } else {
- stopIndex = 30;
- }
- } else if (busStop.id.equals("SN120527") && id == 329) { // U2 Civic Centre Rd os stop AO Civic
- // Ctr E
- if (moveAmount > 0) {
- stopIndex = 0;
- } else {
- stopIndex = 42;
- }
- } else if (busStop.id.equals("SNA09298") && id == 329) { // U2 Bassett Green Rd nr Bassett Green
- // Cl SE
- if (moveAmount > 0) {
- stopIndex = 22;
- } else {
- stopIndex = 21;
- }
- } else if (busStop.id.equals("SN120520") && id == 326) { // U1 By the station
- if (direction.equals(forwardDirection)) {
- stopIndex = 7;
- } else {
- stopIndex = 80;
- }
- } else if (busStop.id.equals("HA030183") && id == 326) { // U1 Up past Wessex Lane
- if (direction.equals(forwardDirection)) {
- stopIndex = 35;
- } else {
- stopIndex = 50;
- }
- } else if (busStop.id.equals("HA030212") && id == 326) { // U1 At Eastleigh
- if (moveAmount > 0) {
- stopIndex = 43;
- } else {
- stopIndex = 42;
- }
- } else if (busStop.id.equals("SN120171") && id == 354) { // U9
- if (moveAmount > 0) {
- stopIndex = 0;
- } else {
- stopIndex = 73;
- }
+ /**
+ * Untested?
+ *
+ * @param context
+ * @param busStop
+ * @param moveAmount
+ * @return
+ */
+ BusStop moveInRoute(final Context context, final BusStop busStop, String direction, final int moveAmount) {
+
+ if (moveAmount == 0) {
+ return busStop;
+ }
+
+ DatabaseHelper helper = OpenHelperManager.getHelper(context, DatabaseHelper.class);
+
+ if (forwardDirection != null) {
+
+ if (direction != null) {
+
+ if (direction.equals("E"))
+ direction = "A"; // Quick hack for U1E
} else {
- Log.e(TAG, "Error, unknown bus stop " + busStop.id + " (" + busStop.description
- + ") that appears mutiple times in " + toString());
- throw new RuntimeException("Error, unknown bus stop " + busStop.id
- + " that appears mutiple times in " + toString());
+ throw new NullPointerException("direction is null");
}
- Log.v(TAG, "Selecting " + stopIndex + " for " + busStop.id + " as direction == " + direction);
- }
}
- }
-
- if (moveAmount > 0) {
- Log.v(TAG, "Moving forward " + moveAmount + " stops from " + busStop + " (" + stopIndex + "/"
- + routeStopsFound.size() + ")");
- int stopWanted = stopIndex + moveAmount;
- if ((stopWanted + 1) > routeStopsFound.size()) {
- Log.v(TAG, "Off the end of the route");
- stopWanted = stopWanted % (routeStopsFound.size() - 1);
+
+ try {
+ Dao<RouteStop, Integer> routeStopsDao = helper.getRouteStopsDao();
+ Dao<BusStop, String> busStopDao = helper.getBusStopDao();
+
+ QueryBuilder<RouteStop, Integer> routeStopsQueryBuilder = routeStopsDao.queryBuilder();
+ routeStopsQueryBuilder.where().eq(RouteStop.ROUTE_ID_FIELD_NAME, this.id);
+ PreparedQuery<RouteStop> routeStopsPreparedQuery = routeStopsQueryBuilder.prepare();
+
+ List<RouteStop> routeStopsFound = routeStopsDao.query(routeStopsPreparedQuery);
+ Collections.sort(routeStopsFound);
+
+ int stopIndex = -1;
+
+ for (RouteStop routeStop : routeStopsFound) {
+ if (routeStop.busStop.id.equals(busStop.id)) {
+ if (stopIndex == -1) {
+ stopIndex = routeStop.sequence - 1;
+ } else { // ARGH, weird route
+ if (busStop.id.equals("HAA13651") && id == 327) { // U6
+ // by
+ // Wessex
+ // Lane
+ if (direction.equals(forwardDirection)) {
+ stopIndex = 23;
+ } else {
+ stopIndex = 68;
+ }
+ } else if (busStop.id.equals("SN120134") && id == 327) { // U6
+ // opposite
+ // the
+ // Stile
+ if (direction.equals(forwardDirection)) {
+ stopIndex = 30;
+ } else {
+ stopIndex = 59;
+ }
+ } else if (busStop.id.equals("SN120163") && id == 327) { // U6
+ // just
+ // up
+ // past
+ // wessex
+ // lane
+ if (direction.equals(forwardDirection)) {
+ stopIndex = 22;
+ } else {
+ stopIndex = 67;
+ }
+ } else if (busStop.id.equals("SNA19482") && id == 327) { // U6
+ // General
+ // Hosp
+ // West
+ // Door
+ if (moveAmount > 0) {
+ stopIndex = 44;
+ } else {
+ stopIndex = 43;
+ }
+ } else if (busStop.id.equals("SN120134") && id == 329) { // U2
+ // opposite
+ // the
+ // Stile
+ if (direction.equals(forwardDirection)) {
+ stopIndex = 13;
+ } else {
+ stopIndex = 30;
+ }
+ } else if (busStop.id.equals("SN120527") && id == 329) { // U2
+ // Civic
+ // Centre
+ // Rd
+ // os
+ // stop
+ // AO
+ // Civic
+ // Ctr E
+ if (moveAmount > 0) {
+ stopIndex = 0;
+ } else {
+ stopIndex = 42;
+ }
+ } else if (busStop.id.equals("SNA09298") && id == 329) { // U2
+ // Bassett
+ // Green
+ // Rd
+ // nr
+ // Bassett
+ // Green
+ // Cl SE
+ if (moveAmount > 0) {
+ stopIndex = 22;
+ } else {
+ stopIndex = 21;
+ }
+ } else if (busStop.id.equals("SN120520") && id == 326) { // U1
+ // By
+ // the
+ // station
+ if (direction.equals(forwardDirection)) {
+ stopIndex = 7;
+ } else {
+ stopIndex = 80;
+ }
+ } else if (busStop.id.equals("HA030183") && id == 326) { // U1
+ // Up
+ // past
+ // Wessex
+ // Lane
+ if (direction.equals(forwardDirection)) {
+ stopIndex = 35;
+ } else {
+ stopIndex = 50;
+ }
+ } else if (busStop.id.equals("HA030212") && id == 326) { // U1
+ // At
+ // Eastleigh
+ if (moveAmount > 0) {
+ stopIndex = 43;
+ } else {
+ stopIndex = 42;
+ }
+ } else if (busStop.id.equals("SN120171") && id == 354) { // U9
+ if (moveAmount > 0) {
+ stopIndex = 0;
+ } else {
+ stopIndex = 73;
+ }
+ } else {
+ Log.e(TAG, "Error, unknown bus stop " + busStop.id + " (" + busStop.description
+ + ") that appears mutiple times in " + toString());
+ throw new RuntimeException("Error, unknown bus stop " + busStop.id
+ + " that appears mutiple times in " + toString());
+ }
+ Log.v(TAG, "Selecting " + stopIndex + " for " + busStop.id + " as direction == " + direction);
+ }
+ }
+ }
+
+ if (moveAmount > 0) {
+ Log.v(TAG,
+ "Moving forward " + moveAmount + " stops from " + busStop + " (" + stopIndex + "/"
+ + routeStopsFound.size() + ")");
+ int stopWanted = stopIndex + moveAmount;
+ if ((stopWanted + 1) > routeStopsFound.size()) {
+ Log.v(TAG, "Off the end of the route");
+ stopWanted = stopWanted % (routeStopsFound.size() - 1);
+ }
+ Log.v(TAG, " Stop wanted " + stopWanted);
+ BusStop busStopWanted = routeStopsFound.get(stopWanted).busStop;
+
+ busStopDao.refresh(busStopWanted);
+
+ Log.v(TAG, " Moving to " + busStopWanted + " (" + stopWanted + ") in route " + this);
+
+ return busStopWanted;
+ } else {
+ Log.v(TAG, "stopIndex " + stopIndex);
+ int stopWanted = stopIndex + moveAmount;
+ if (stopWanted < 0) {
+ stopWanted = routeStopsFound.size() - (Math.abs(stopWanted) % routeStopsFound.size());
+ }
+ Log.v(TAG, "stopWanted " + stopWanted);
+ busStopDao.refresh(routeStopsFound.get(stopWanted).busStop);
+
+ Log.v(TAG, "Moving backwards " + moveAmount + " stops from " + busStop + " to "
+ + routeStopsFound.get(stopWanted).busStop + " in route " + this);
+
+ return routeStopsFound.get(stopWanted).busStop;
+ }
+
+ } catch (SQLException e) {
+ e.printStackTrace();
}
- Log.v(TAG, " Stop wanted " + stopWanted);
- BusStop busStopWanted = routeStopsFound.get(stopWanted).busStop;
+ Log.e(TAG, "Error moving in route");
+ return null;
+ }
- busStopDao.refresh(busStopWanted);
+ /**
+ * Untested?
+ *
+ * @param context
+ * @param busStop
+ * @param moveAmount
+ * @return
+ */
+ List<BusStop> getRouteSection(final Context context, String direction) {
- Log.v(TAG, " Moving to " + busStopWanted + " (" + stopWanted + ") in route " + this);
+ DatabaseHelper helper = OpenHelperManager.getHelper(context, DatabaseHelper.class);
- return busStopWanted;
- } else {
- Log.v(TAG, "stopIndex " + stopIndex);
- int stopWanted = stopIndex + moveAmount;
- if (stopWanted < 0) {
- stopWanted = routeStopsFound.size() - (Math.abs(stopWanted) % routeStopsFound.size());
+ if (forwardDirection != null) {
+
+ if (direction != null) {
+
+ if (direction.equals("E"))
+ direction = "A"; // Quick hack for U1E
+ } else {
+ throw new NullPointerException("direction is null");
+ }
}
- Log.v(TAG, "stopWanted " + stopWanted);
- busStopDao.refresh(routeStopsFound.get(stopWanted).busStop);
- Log.v(TAG,
- "Moving backwards " + moveAmount + " stops from " + busStop + " to "
- + routeStopsFound.get(stopWanted).busStop + " in route " + this);
+ List<BusStop> busStops = new ArrayList<BusStop>();
+
+ try {
+
+ Dao<RouteStop, Integer> routeStopsDao = helper.getRouteStopsDao();
+ Dao<BusStop, String> busStopDao = helper.getBusStopDao();
+
+ QueryBuilder<RouteStop, Integer> routeStopsQueryBuilder = routeStopsDao.queryBuilder();
+ routeStopsQueryBuilder.where().eq(RouteStop.ROUTE_ID_FIELD_NAME, this.id);
+ PreparedQuery<RouteStop> routeStopsPreparedQuery = routeStopsQueryBuilder.prepare();
+
+ List<RouteStop> routeStopsFound = routeStopsDao.query(routeStopsPreparedQuery);
+ Collections.sort(routeStopsFound);
+
+ int startStopSeq = -1;
+ int endStopSeq = -1;
+
+ if (id == 326) { // U1
+ if (direction.equals(forwardDirection)) {
+ startStopSeq = 1;
+ endStopSeq = 43;
+ } else if (direction.equals(reverseDirection)) {
+ startStopSeq = 44;
+ endStopSeq = 88;
+ } else {
+ Log.e(TAG, "Error, unrecognised direction " + direction);
+ }
+ } else if (id == 468) { // U1N
+ startStopSeq = 1;
+ endStopSeq = 29;
+ } else if (id == 329) { // U2
+ if (direction.equals(forwardDirection)) {
+ startStopSeq = 1;
+ endStopSeq = 22;
+ } else if (direction.equals(reverseDirection)) {
+ startStopSeq = 23;
+ endStopSeq = 43;
+ } else {
+ Log.e(TAG, "Error, unrecognised direction " + direction);
+ }
+ } else if (id == 327) { // U6
+ if (direction.equals(forwardDirection)) {
+ startStopSeq = 1;
+ endStopSeq = 44;
+ } else if (direction.equals(reverseDirection)) {
+ startStopSeq = 45;
+ endStopSeq = 93;
+ } else {
+ Log.e(TAG, "Error, unrecognised direction " + direction);
+ }
+ } else if (id == 354) { // U9
+ Calendar rightNow = Calendar.getInstance();
+ if (rightNow.get(Calendar.HOUR_OF_DAY) < 12) {
+ startStopSeq = 1;
+ endStopSeq = 40; // TODO: Guess, and untested
+ } else {
+ startStopSeq = 41; // TODO: Guess, and untested
+ endStopSeq = 74;
+ }
+ } else {
+ Log.e(TAG, "Error, unrecognised route " + id);
+ }
+
+ for (RouteStop routeStop : routeStopsFound) {
+ if (routeStop.sequence >= startStopSeq && routeStop.sequence <= endStopSeq) {
+ busStopDao.refresh(routeStop.busStop);
+ busStops.add(routeStop.busStop);
+ }
+ }
- return routeStopsFound.get(stopWanted).busStop;
- }
+ return busStops;
+
+ } catch (SQLException e) {
+ e.printStackTrace();
+ }
+ Log.e(TAG, "Error moving in route");
+ return null;
- } catch (SQLException e) {
- e.printStackTrace();
- }
- Log.e(TAG, "Error moving in route");
- return null;
- }
-
- /**
- * Untested?
- *
- * @param context
- * @param busStop
- * @param moveAmount
- * @return
- */
- List<BusStop> getRouteSection(final Context context, String direction) {
-
- DatabaseHelper helper = OpenHelperManager.getHelper(context, DatabaseHelper.class);
-
- if (forwardDirection != null) {
-
- if (direction != null) {
-
- if (direction.equals("E"))
- direction = "A"; // Quick hack for U1E
- } else {
- throw new NullPointerException("direction is null");
- }
}
- List<BusStop> busStops = new ArrayList<BusStop>();
+ List<BusStop> getRouteBusStops(final Context context) {
- try {
+ DatabaseHelper helper = OpenHelperManager.getHelper(context, DatabaseHelper.class);
- Dao<RouteStops, Integer> routeStopsDao = helper.getRouteStopsDao();
- Dao<BusStop, String> busStopDao = helper.getBusStopDao();
+ List<BusStop> busStops = new ArrayList<BusStop>();
- QueryBuilder<RouteStops, Integer> routeStopsQueryBuilder = routeStopsDao.queryBuilder();
- routeStopsQueryBuilder.where().eq(RouteStops.ROUTE_ID_FIELD_NAME, this.id);
- PreparedQuery<RouteStops> routeStopsPreparedQuery = routeStopsQueryBuilder.prepare();
+ try {
- List<RouteStops> routeStopsFound = routeStopsDao.query(routeStopsPreparedQuery);
+ Dao<RouteStop, Integer> routeStopsDao = helper.getRouteStopsDao();
+ Dao<BusStop, String> busStopDao = helper.getBusStopDao();
- int startStopSeq = -1;
- int endStopSeq = -1;
+ QueryBuilder<RouteStop, Integer> routeStopsQueryBuilder = routeStopsDao.queryBuilder();
+ routeStopsQueryBuilder.where().eq(RouteStop.ROUTE_ID_FIELD_NAME, this.id);
+ PreparedQuery<RouteStop> routeStopsPreparedQuery = routeStopsQueryBuilder.prepare();
- if (id == 326) { // U1
- if (direction.equals(forwardDirection)) {
- startStopSeq = 1;
- endStopSeq = 43;
- } else if (direction.equals(reverseDirection)) {
- startStopSeq = 44;
- endStopSeq = 88;
- } else {
- Log.e(TAG, "Error, unrecognised direction " + direction);
- }
- } else if (id == 468) { // U1N
- startStopSeq = 1;
- endStopSeq = 29;
- } else if (id == 329) { // U2
- if (direction.equals(forwardDirection)) {
- startStopSeq = 1;
- endStopSeq = 22;
- } else if (direction.equals(reverseDirection)) {
- startStopSeq = 23;
- endStopSeq = 43;
- } else {
- Log.e(TAG, "Error, unrecognised direction " + direction);
- }
- } else if (id == 327) { // U6
- if (direction.equals(forwardDirection)) {
- startStopSeq = 1;
- endStopSeq = 44;
- } else if (direction.equals(reverseDirection)) {
- startStopSeq = 45;
- endStopSeq = 93;
- } else {
- Log.e(TAG, "Error, unrecognised direction " + direction);
- }
- } else if (id == 354) { // U9
- Calendar rightNow = Calendar.getInstance();
- if (rightNow.get(Calendar.HOUR_OF_DAY) < 12) {
- startStopSeq = 1;
- endStopSeq = 40; // TODO: Guess, and untested
- } else {
- startStopSeq = 41; // TODO: Guess, and untested
- endStopSeq = 74;
- }
- } else {
- Log.e(TAG, "Error, unrecognised route " + id);
- }
-
- for (RouteStops routeStop : routeStopsFound) {
- if (routeStop.sequence >= startStopSeq && routeStop.sequence <= endStopSeq) {
- busStopDao.refresh(routeStop.busStop);
- busStops.add(routeStop.busStop);
+ List<RouteStop> routeStopsFound = routeStopsDao.query(routeStopsPreparedQuery);
+ Collections.sort(routeStopsFound);
+
+ for (RouteStop routeStop : routeStopsFound) {
+ busStopDao.refresh(routeStop.busStop);
+ busStops.add(routeStop.busStop);
+ }
+
+ return busStops;
+ } catch (SQLException e) {
+ e.printStackTrace();
}
- }
+ Log.e(TAG, "Error moving in route");
+ return null;
- return busStops;
+ }
+
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + id;
+ return result;
+ }
- } catch (SQLException e) {
- e.printStackTrace();
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj)
+ return true;
+ if (obj == null)
+ return false;
+ if (getClass() != obj.getClass())
+ return false;
+ BusRoute other = (BusRoute) obj;
+ if (id != other.id)
+ return false;
+ return true;
}
- Log.e(TAG, "Error moving in route");
- return null;
-
- }
-
- @Override
- public int hashCode() {
- final int prime = 31;
- int result = 1;
- result = prime * result + id;
- return result;
- }
-
- @Override
- public boolean equals(Object obj) {
- if (this == obj)
- return true;
- if (obj == null)
- return false;
- if (getClass() != obj.getClass())
- return false;
- BusRoute other = (BusRoute) obj;
- if (id != other.id)
- return false;
- return true;
- }
}
diff --git a/src/net/cbaines/suma/BusRouteActivity.java b/src/net/cbaines/suma/BusRouteActivity.java
new file mode 100644
index 0000000..0a352ce
--- /dev/null
+++ b/src/net/cbaines/suma/BusRouteActivity.java
@@ -0,0 +1,178 @@
+package net.cbaines.suma;
+
+import java.sql.SQLException;
+
+import android.content.Context;
+import android.content.Intent;
+import android.content.SharedPreferences;
+import android.net.Uri;
+import android.os.Bundle;
+import android.preference.PreferenceManager;
+import android.util.Log;
+import android.view.View;
+import android.widget.AdapterView;
+import android.widget.AdapterView.OnItemClickListener;
+import android.widget.AdapterView.OnItemLongClickListener;
+import android.widget.ListView;
+import android.widget.TextView;
+import android.widget.Toast;
+
+import com.j256.ormlite.android.apptools.OrmLiteBaseActivity;
+
+public class BusRouteActivity extends OrmLiteBaseActivity<DatabaseHelper> implements Preferences, OnItemClickListener,
+ OnItemLongClickListener {
+ final static String TAG = "BusActivity";
+
+ private TextView busRouteLabel;
+ private TextView busRouteCode;
+ private TextView busRouteID;
+
+ Toast activityToast;
+
+ private ListView busRouteView;
+
+ private POIArrayAdapter arrayAdapter;
+
+ private Context instance;
+
+ public void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.bus_route_activity);
+ instance = this;
+
+ Log.i(TAG, "getIntent().getDataString() " + getIntent().getDataString());
+
+ String strBusRouteID;
+
+ if (getIntent().getDataString().startsWith("http://data")) {
+
+ String[] uriParts = getIntent().getDataString().split("/");
+
+ strBusRouteID = uriParts[uriParts.length - 1].replace(".html", "");
+
+ } else {
+
+ String[] uriParts = getIntent().getDataString().split("/");
+
+ strBusRouteID = uriParts[uriParts.length - 1];
+ }
+
+ final DatabaseHelper helper = getHelper();
+
+ BusRoute busRoute = null;
+
+ SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
+
+ try {
+ busRoute = helper.getBusRouteDao().queryForId(Integer.parseInt(strBusRouteID));
+
+ busRouteLabel = (TextView) findViewById(R.id.busRouteActivityLabel);
+ busRouteLabel.setText(busRoute.label);
+
+ busRouteCode = (TextView) findViewById(R.id.busRouteActivityCode);
+ busRouteCode.setText(busRoute.code);
+
+ if (prefs.getBoolean(SHOW_IDENTIFIERS, SHOW_IDENTIFIERS_ENABLED_BY_DEFAULT)) {
+ busRouteID = (TextView) findViewById(R.id.busRouteActivityID);
+ busRouteID.setText(String.valueOf(busRoute.id));
+ busRouteID.setVisibility(View.VISIBLE);
+ }
+
+ busRouteView = (ListView) findViewById(R.id.busRouteBusStops);
+
+ } catch (NumberFormatException e) {
+ e.printStackTrace();
+ } catch (SQLException e) {
+ e.printStackTrace();
+ }
+
+ arrayAdapter = new POIArrayAdapter(instance, busRoute.getRouteBusStops(instance));
+ busRouteView.setAdapter(arrayAdapter);
+ busRouteView.setOnItemClickListener(this);
+ busRouteView.setOnItemLongClickListener(this);
+ }
+
+ public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
+ Log.i(TAG, "OnItemClick pos " + position + " id " + id);
+
+ String poiId = arrayAdapter.getItemStringId(position);
+
+ Log.i(TAG, "POI " + poiId + " selected");
+
+ POI poi = null;
+
+ if (poiId != null) {
+ Log.i(TAG, "Got id " + poiId);
+ try {
+ poi = getHelper().getBusStopDao().queryForId(poiId);
+ } catch (SQLException e) {
+ e.printStackTrace();
+ }
+
+ if (poi == null) {
+ Log.e(TAG, "Could not find poi " + poiId + " in onActivityResult");
+ } else {
+
+ BusStop busStop = (BusStop) poi;
+
+ Log.i(TAG, "Pressed " + busStop.id);
+
+ Uri uri = Uri.parse("http://id.southampton.ac.uk/bus-stop/" + busStop.id);
+
+ Log.i(TAG, "Starting a activity for " + uri + " path " + uri.getPath());
+
+ Intent busStopIntent = new Intent(Intent.ACTION_VIEW, uri);
+ startActivity(busStopIntent);
+
+ return true;
+ }
+ } else {
+ Log.i(TAG, "Got null poi id");
+
+ // mapController.setZoom(15);
+ // mapController.setCenter(new GeoPoint(50935551, -1393488));
+ }
+
+ return false;
+ }
+
+ public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
+ Log.i(TAG, "OnItemClick pos " + position + " id " + id);
+
+ String poiId = arrayAdapter.getItemStringId(position);
+
+ Log.i(TAG, "POI " + poiId + " selected");
+
+ POI poi = null;
+
+ if (poiId != null) {
+ Log.i(TAG, "Got id " + poiId);
+ try {
+ poi = getHelper().getBusStopDao().queryForId(poiId);
+ } catch (SQLException e) {
+ e.printStackTrace();
+ }
+
+ if (poi == null) {
+ Log.e(TAG, "Could not find poi " + poiId + " in onActivityResult");
+ } else {
+
+ Log.i(TAG, "Pressed " + poi.id);
+
+ Uri uri = Uri.parse("geo:" + Util.E6IntToDouble(poi.point.getLatitudeE6()) + ","
+ + Util.E6IntToDouble(poi.point.getLongitudeE6()) + "?z=18");
+
+ Log.i(TAG, "Starting a activity for " + uri);
+
+ Intent mapIntent = new Intent(Intent.ACTION_VIEW, uri);
+ startActivity(mapIntent);
+
+ }
+ } else {
+ Log.i(TAG, "Got null poi id");
+
+ // mapController.setZoom(15);
+ // mapController.setCenter(new GeoPoint(50935551, -1393488));
+ }
+ }
+}
diff --git a/src/net/cbaines/suma/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 4cac19a..06bd267 100644
--- a/src/net/cbaines/suma/BusSpecificStopView.java
+++ b/src/net/cbaines/suma/BusSpecificStopView.java
@@ -108,7 +108,6 @@ public class BusSpecificStopView 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);
} else {
@@ -122,7 +121,6 @@ public class BusSpecificStopView extends LinearLayout implements OnClickListener
} else {
onClickMessage = "Timetabled bus (" + stop.bus.getName() + ") at "
+ DateFormat.getTimeInstance(DateFormat.SHORT).format(stop.arivalTime);
-
}
}
} else {
@@ -130,7 +128,6 @@ public class BusSpecificStopView extends LinearLayout implements OnClickListener
if (stop.live) {
onClickMessage = "Bus " + stop.bus.toString();
} else {
-
onClickMessage = "Timetabled bus " + stop.bus.toString();
}
} else {
@@ -138,7 +135,6 @@ public class BusSpecificStopView extends LinearLayout implements OnClickListener
onClickMessage = "Unidentified bus (" + stop.bus.getName() + ")";
} else {
onClickMessage = "Timetabled bus (" + stop.bus.getName() + ")";
-
}
}
}
@@ -152,9 +148,7 @@ public class BusSpecificStopView extends LinearLayout implements OnClickListener
public void onClick(View v) {
if (context.activityToast == null) {
-
context.activityToast = Toast.makeText(context, onClickMessage, Toast.LENGTH_SHORT);
-
} else {
context.activityToast.setText(onClickMessage);
context.activityToast.setDuration(Toast.LENGTH_SHORT);
@@ -163,7 +157,6 @@ public class BusSpecificStopView extends LinearLayout implements OnClickListener
}
public boolean onLongClick(View v) { // TODO
-
DatabaseHelper helper = OpenHelperManager.getHelper(context, DatabaseHelper.class);
try {
@@ -172,17 +165,16 @@ public class BusSpecificStopView extends LinearLayout implements OnClickListener
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);
} else {
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 07dd45c..bfcc13a 100644
--- a/src/net/cbaines/suma/BusStopActivity.java
+++ b/src/net/cbaines/suma/BusStopActivity.java
@@ -33,6 +33,7 @@ import android.app.Dialog;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
+import android.net.Uri;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Handler;
@@ -43,6 +44,7 @@ import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
+import android.view.View.OnLongClickListener;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.CheckBox;
@@ -60,7 +62,7 @@ import com.j256.ormlite.stmt.PreparedQuery;
import com.j256.ormlite.stmt.QueryBuilder;
public class BusStopActivity extends OrmLiteBaseActivity<DatabaseHelper> implements OnCheckedChangeListener, Preferences,
- OnItemClickListener {
+ OnItemClickListener, OnLongClickListener {
final static String TAG = "BusTimeActivity";
@@ -75,11 +77,6 @@ public class BusStopActivity extends OrmLiteBaseActivity<DatabaseHelper> impleme
protected Timetable timetable;
private Timetable visibleTimetable;
- protected String busStopID;
- private String busStopName;
-
- private Dao<BusStop, String> busStopDao;
-
private BusStop busStop;
private GetTimetableTask timetableTask;
@@ -106,15 +103,30 @@ public class BusStopActivity extends OrmLiteBaseActivity<DatabaseHelper> impleme
super.onCreate(savedInstanceState);
setContentView(R.layout.bus_stop_activity);
+ Log.i(TAG, "getIntent().getDataString() " + getIntent().getDataString());
+
+ String busStopID;
+
+ if (getIntent().getDataString().startsWith("http://data")) {
+
+ String[] uriParts = getIntent().getDataString().split("/");
+
+ busStopID = uriParts[uriParts.length - 1].replace(".html", "");
+
+ } else {
+
+ String[] uriParts = getIntent().getDataString().split("/");
+
+ busStopID = uriParts[uriParts.length - 1];
+ }
+
final DatabaseHelper helper = getHelper();
SharedPreferences favouritesPreferences = getSharedPreferences(FAVOURITES_PREFERENCES, 0);
+ SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
instance = this;
- busStopID = getIntent().getExtras().getString("busStopID");
- busStopName = getIntent().getExtras().getString("busStopName");
-
U1RouteRadioButton = (CheckBox) findViewById(R.id.radio_u1);
U1NRouteRadioButton = (CheckBox) findViewById(R.id.radio_u1n);
U2RouteRadioButton = (CheckBox) findViewById(R.id.radio_u2);
@@ -122,22 +134,35 @@ public class BusStopActivity extends OrmLiteBaseActivity<DatabaseHelper> impleme
U9RouteRadioButton = (CheckBox) findViewById(R.id.radio_u9);
U1RouteRadioButton.setOnCheckedChangeListener(this);
+ U1RouteRadioButton.setOnLongClickListener(this);
+
U1NRouteRadioButton.setOnCheckedChangeListener(this);
+ U1NRouteRadioButton.setOnLongClickListener(this);
+
U2RouteRadioButton.setOnCheckedChangeListener(this);
+ U2RouteRadioButton.setOnLongClickListener(this);
+
U6RouteRadioButton.setOnCheckedChangeListener(this);
+ U6RouteRadioButton.setOnLongClickListener(this);
+
U9RouteRadioButton.setOnCheckedChangeListener(this);
+ U9RouteRadioButton.setOnLongClickListener(this);
try {
+ Dao<BusStop, String> busStopDao = helper.getBusStopDao();
+
+ busStop = busStopDao.queryForId(busStopID);
+
Dao<BusRoute, Integer> busRouteDao = helper.getBusRouteDao();
- Dao<RouteStops, Integer> routeStopsDao = helper.getRouteStopsDao();
+ Dao<RouteStop, Integer> routeStopsDao = helper.getRouteStopsDao();
for (BusRoute route : busRouteDao) {
- QueryBuilder<RouteStops, Integer> queryBuilder = routeStopsDao.queryBuilder();
+ QueryBuilder<RouteStop, Integer> queryBuilder = routeStopsDao.queryBuilder();
- queryBuilder.where().eq(RouteStops.ROUTE_ID_FIELD_NAME, route.id).and()
- .eq(RouteStops.STOP_ID_FIELD_NAME, busStopID);
+ queryBuilder.where().eq(RouteStop.ROUTE_ID_FIELD_NAME, route.id).and()
+ .eq(RouteStop.STOP_ID_FIELD_NAME, busStopID);
queryBuilder.setCountOf(true);
- PreparedQuery<RouteStops> preparedQuery = queryBuilder.prepare();
+ PreparedQuery<RouteStop> preparedQuery = queryBuilder.prepare();
long count = routeStopsDao.countOf(preparedQuery);
@@ -179,10 +204,6 @@ public class BusStopActivity extends OrmLiteBaseActivity<DatabaseHelper> impleme
}
}
- busStopDao = helper.getBusStopDao();
-
- busStop = busStopDao.queryForId(busStopID);
-
busFavourite = (CheckBox) findViewById(R.id.favouriteCheckBox);
busFavourite.setChecked(favouritesPreferences.getBoolean(busStop.id, false));
busFavourite.setOnCheckedChangeListener(this);
@@ -192,7 +213,12 @@ public class BusStopActivity extends OrmLiteBaseActivity<DatabaseHelper> impleme
}
busName = (TextView) findViewById(R.id.busStopName);
- busID = (TextView) findViewById(R.id.busStopID);
+
+ if (prefs.getBoolean(SHOW_IDENTIFIERS, SHOW_IDENTIFIERS_ENABLED_BY_DEFAULT)) {
+ busID = (TextView) findViewById(R.id.busStopID);
+ busID.setText(busStopID);
+ busID.setVisibility(View.VISIBLE);
+ }
busStopMessage = (TextView) findViewById(R.id.busStopMessage);
progBar = (ProgressBar) findViewById(R.id.busStopLoadBar);
@@ -201,8 +227,7 @@ public class BusStopActivity extends OrmLiteBaseActivity<DatabaseHelper> impleme
Log.i(TAG, "Got busstop id " + busStopID);
- busName.setText(busStopName);
- busID.setText(busStopID);
+ busName.setText(busStop.description);
}
public void onResume() {
@@ -217,7 +242,7 @@ public class BusStopActivity extends OrmLiteBaseActivity<DatabaseHelper> impleme
refreshData = new Runnable() {
public void run() {
timetableTask = new GetTimetableTask();
- timetableTask.execute(busStopID);
+ timetableTask.execute(busStop.id);
mHandler.postDelayed(refreshData, 20000);
}
};
@@ -296,7 +321,7 @@ public class BusStopActivity extends OrmLiteBaseActivity<DatabaseHelper> impleme
final SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(instance);
newTimetable = DataManager
- .getTimetable(instance, busStopID, sharedPrefs.getBoolean(MapActivity.UNI_LINK_BUS_TIMES,
+ .getTimetable(instance, busStop.id, sharedPrefs.getBoolean(MapActivity.UNI_LINK_BUS_TIMES,
MapActivity.UNI_LINK_BUS_TIMES_ENABLED_BY_DEFAULT), sharedPrefs.getBoolean(
MapActivity.NON_UNI_LINK_BUS_TIMES, MapActivity.NON_UNI_LINK_BUS_TIMES_ENABLED_BY_DEFAULT));
} catch (SQLException e) {
@@ -319,7 +344,7 @@ public class BusStopActivity extends OrmLiteBaseActivity<DatabaseHelper> impleme
}
protected void onPostExecute(Timetable newTimetable) {
- Log.i(TAG, "Got timetable for " + busStopID);
+ Log.i(TAG, "Got timetable for " + busStop.id);
if (newTimetable == null) {
Log.i(TAG, "Its null");
@@ -355,9 +380,9 @@ public class BusStopActivity extends OrmLiteBaseActivity<DatabaseHelper> impleme
try {
Set<BusStop> tmpStops;
if (item.getItemId() == R.id.menu_next_stop) {
- tmpStops = route.moveInRoute(this, getHelper().getBusStopDao().queryForId(busStopID), 1);
+ tmpStops = route.moveInRoute(this, getHelper().getBusStopDao().queryForId(busStop.id), 1);
} else {
- tmpStops = route.moveInRoute(this, getHelper().getBusStopDao().queryForId(busStopID), -1);
+ tmpStops = route.moveInRoute(this, getHelper().getBusStopDao().queryForId(busStop.id), -1);
}
for (BusStop busStop : tmpStops) {
if (!busStops.contains(busStop)) {
@@ -371,7 +396,7 @@ public class BusStopActivity extends OrmLiteBaseActivity<DatabaseHelper> impleme
Log.i(TAG, "stops " + busStops);
if (busStops.size() == 1) {
- Intent i = new Intent(this, BusStopActivity.class);
+
BusStop stop = (BusStop) busStops.iterator().next();
if (stop == null) {
Log.e(TAG, "stop == null");
@@ -379,9 +404,14 @@ public class BusStopActivity extends OrmLiteBaseActivity<DatabaseHelper> impleme
if (stop.id == null) {
Log.e(TAG, "stop.id == null");
}
- i.putExtra("busStopID", stop.id);
- i.putExtra("busStopName", stop.description);
- startActivity(i);
+
+ Uri uri = Uri.parse("http://id.southampton.ac.uk/bus-stop/" + busStop.id);
+
+ Log.i(TAG, "Starting a activity for " + uri + " path " + uri.getPath());
+
+ Intent busStopIntent = new Intent(Intent.ACTION_VIEW, uri);
+ startActivity(busStopIntent);
+
} else {
showDialog(POI_DIALOG_ID);
if (busDialog == null) {
@@ -484,26 +514,38 @@ public class BusStopActivity extends OrmLiteBaseActivity<DatabaseHelper> impleme
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Log.i(TAG, "OnItemClick pos " + position + " id " + id);
- String poiId = busDialog.adapter.getItemStringId(position);
+ String busId = busDialog.adapter.getItemStringId(position);
- Log.i(TAG, "POI " + poiId + " selected");
+ Log.i(TAG, "Bus " + busId + " selected");
- Intent i = new Intent(this, BusStopActivity.class);
- try {
- busStop = busStopDao.queryForId(poiId);
+ Uri uri = Uri.parse("http://id.southampton.ac.uk/bus/" + busId);
- if (busStop == null) {
- Log.e(TAG, "stop == null");
- }
- if (busStop.id == null) {
- Log.e(TAG, "stop.id == null");
- }
- i.putExtra("busStopID", busStop.id);
- i.putExtra("busStopName", busStop.description);
- startActivity(i);
- } catch (SQLException e) {
- e.printStackTrace();
+ Log.i(TAG, "Starting a activity for " + uri + " path " + uri.getPath());
+
+ Intent busStopIntent = new Intent(Intent.ACTION_VIEW, uri);
+ busStopIntent.putExtra("busStopID", busStop.id);
+ startActivity(busStopIntent);
+ }
+
+ public boolean onLongClick(View v) {
+ Uri uri = null;
+ if (v.equals(U1RouteRadioButton)) {
+ uri = Uri.parse("http://id.southampton.ac.uk/bus-route/326");
+ } else if (v.equals(U1NRouteRadioButton)) {
+ uri = Uri.parse("http://id.southampton.ac.uk/bus-route/468");
+ } else if (v.equals(U2RouteRadioButton)) {
+ uri = Uri.parse("http://id.southampton.ac.uk/bus-route/329");
+ } else if (v.equals(U6RouteRadioButton)) {
+ uri = Uri.parse("http://id.southampton.ac.uk/bus-route/327");
+ } else if (v.equals(U9RouteRadioButton)) {
+ uri = Uri.parse("http://id.southampton.ac.uk/bus-route/354");
}
+ if (uri != null) {
+ Log.i(TAG, "Starting a activity for " + uri + " path " + uri.getPath());
+ Intent busStopIntent = new Intent(Intent.ACTION_VIEW, uri);
+ startActivity(busStopIntent);
+ }
+ return false;
}
}
diff --git a/src/net/cbaines/suma/BusStopOverlay.java b/src/net/cbaines/suma/BusStopOverlay.java
index 4705d1d..b8f1077 100644
--- a/src/net/cbaines/suma/BusStopOverlay.java
+++ b/src/net/cbaines/suma/BusStopOverlay.java
@@ -27,7 +27,6 @@ import org.osmdroid.views.MapView;
import org.osmdroid.views.MapView.Projection;
import org.osmdroid.views.overlay.Overlay;
-import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.Canvas;
@@ -36,6 +35,7 @@ import android.graphics.Paint.Style;
import android.graphics.Point;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
+import android.net.Uri;
import android.util.Log;
import android.view.MotionEvent;
import android.widget.Toast;
@@ -222,10 +222,12 @@ public class BusStopOverlay extends Overlay implements RouteColorConstants, Pref
} else {
Log.i(TAG, "Pressed " + busStop.id);
- Intent i = new Intent(context, BusStopActivity.class);
- i.putExtra("busStopID", busStop.id);
- i.putExtra("busStopName", busStop.description);
- ((Activity) context).startActivityForResult(i, 0);
+ Uri uri = Uri.parse("http://id.southampton.ac.uk/bus-stop/" + busStop.id);
+
+ Log.i(TAG, "Starting a activity for " + uri + " path " + uri.getPath());
+
+ Intent busStopIntent = new Intent(Intent.ACTION_VIEW, uri);
+ context.startActivity(busStopIntent);
return true;
}
diff --git a/src/net/cbaines/suma/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..5e8b195 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); }
*/
@@ -202,11 +214,11 @@ public class DataManager {
Dao<BusStop, String> busStopDao = helper.getBusStopDao();
Dao<BusRoute, Integer> busRouteDao = helper.getBusRouteDao();
- Dao<RouteStops, Integer> routeStopsDao = helper.getRouteStopsDao();
+ Dao<RouteStop, Integer> routeStopsDao = helper.getRouteStopsDao();
TableUtils.clearTable(helper.getConnectionSource(), BusStop.class);
TableUtils.clearTable(helper.getConnectionSource(), BusRoute.class);
- TableUtils.clearTable(helper.getConnectionSource(), RouteStops.class);
+ TableUtils.clearTable(helper.getConnectionSource(), RouteStop.class);
Log.i(TAG, "Loading busstops from csv");
@@ -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));
}
@@ -328,7 +340,7 @@ public class DataManager {
int sequence = Integer.parseInt(dataBits[1]);
Log.i(TAG, "Creating RouteStop " + busStop.id + " " + busRoute.code + " " + sequence);
- routeStopsDao.create(new RouteStops(busStop, busRoute, sequence));
+ routeStopsDao.create(new RouteStop(busStop, busRoute, sequence));
if (busRoute.id == 326) { // U1
busStop.routes = (byte) (busStop.routes | 1);
@@ -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,14 +450,14 @@ 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);
if (busRouteDao == null)
busRouteDao = helper.getBusRouteDao();
- Dao<RouteStops, Integer> routeStopsDao = null;
+ Dao<RouteStop, Integer> routeStopsDao = null;
if (routeStopsDao == null)
routeStopsDao = helper.getRouteStopsDao();
if (busDao == null)
@@ -546,16 +568,18 @@ public class DataManager {
if (destStop != null) {
- QueryBuilder<RouteStops, Integer> routeStopsQueryBuilder = routeStopsDao.queryBuilder();
- routeStopsQueryBuilder.where().eq(RouteStops.ROUTE_ID_FIELD_NAME, route.id).and()
- .eq(RouteStops.STOP_ID_FIELD_NAME, destStop.id);
- PreparedQuery<RouteStops> routeStopsPreparedQuery = routeStopsQueryBuilder.prepare();
+ QueryBuilder<RouteStop, Integer> routeStopsQueryBuilder = routeStopsDao.queryBuilder();
+ routeStopsQueryBuilder.where().eq(RouteStop.ROUTE_ID_FIELD_NAME, route.id).and()
+ .eq(RouteStop.STOP_ID_FIELD_NAME, destStop.id);
+ PreparedQuery<RouteStop> routeStopsPreparedQuery = routeStopsQueryBuilder.prepare();
- List<RouteStops> routeStops = routeStopsDao.query(routeStopsPreparedQuery);
+ List<RouteStop> 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);
@@ -830,7 +855,7 @@ public class DataManager {
public static void routeMovementTest(Context context) throws SQLException {
- Dao<RouteStops, Integer> routeStopsDao = null;
+ Dao<RouteStop, Integer> routeStopsDao = null;
if (helper == null)
helper = OpenHelperManager.getHelper(context, DatabaseHelper.class);
@@ -845,7 +870,7 @@ public class DataManager {
if (!busRoute.code.startsWith("U") || busRoute.code.equals("U9")) {
continue;
}
- List<RouteStops> routeStops = routeStopsDao.queryForEq(RouteStops.ROUTE_ID_FIELD_NAME, busRoute.id);
+ List<RouteStop> routeStops = routeStopsDao.queryForEq(RouteStop.ROUTE_ID_FIELD_NAME, busRoute.id);
ArrayList<String> directions = new ArrayList<String>();
if (busRoute.forwardDirection != null) {
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..facfe85 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<RouteStop, 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, RouteStop.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<RouteStop, Integer> getRouteStopsDao() throws SQLException {
+ if (routeStopsDao == null) {
+ routeStopsDao = getDao(RouteStop.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 be5cd41..59769a4 100644
--- a/src/net/cbaines/suma/DonateDialog.java
+++ b/src/net/cbaines/suma/DonateDialog.java
@@ -31,62 +31,65 @@ import android.widget.TextView;
public class DonateDialog extends Dialog implements Runnable {
- // private static final String TAG = "DonateDialog";
+ // private static final String TAG = "DonateDialog";
- private static final String bitcoinAddress = "1LFATViKkmbm6m4u1Ghi9wqrgVy2B6M412";
+ private static final String bitcoinAddress = "1LFATViKkmbm6m4u1Ghi9wqrgVy2B6M412";
- private final Context context;
+ private final Context context;
- private final TextView dialogMessage;
- private final ProgressBar progressBar;
+ private final TextView dialogMessage;
+ private final ProgressBar progressBar;
- private final LinearLayout errorLayout;
- private final TextView donateDialogErrorMessage;
- private final TextView donateBitcoinAddress;
+ private final LinearLayout errorLayout;
+ private final TextView donateDialogErrorMessage;
+ private final TextView donateBitcoinAddress;
- public DonateDialog(Context context) {
- super(context);
+ public DonateDialog(Context context) {
+ super(context);
- this.context = context;
+ this.context = context;
- setContentView(R.layout.donate_dialog);
- setTitle("Donate");
+ setContentView(R.layout.donate_dialog);
+ setTitle("Donate");
- dialogMessage = (TextView) findViewById(R.id.donateDialogMessage);
- progressBar = (ProgressBar) findViewById(R.id.donateDialogProgress);
+ dialogMessage = (TextView) findViewById(R.id.donateDialogMessage);
+ progressBar = (ProgressBar) findViewById(R.id.donateDialogProgress);
- errorLayout = (LinearLayout) findViewById(R.id.donateDialogMessageLayout);
- donateDialogErrorMessage = (TextView) findViewById(R.id.donateDialogErrorMessage);
- donateBitcoinAddress = (TextView) findViewById(R.id.donateBitcoinAddress);
+ errorLayout = (LinearLayout) findViewById(R.id.donateDialogMessageLayout);
+ donateDialogErrorMessage = (TextView) findViewById(R.id.donateDialogErrorMessage);
+ donateBitcoinAddress = (TextView) findViewById(R.id.donateBitcoinAddress);
- new Thread(this).start();
- }
-
- public void run() {
- try {
- Thread.sleep(3000);
- } catch (InterruptedException e) {
- e.printStackTrace();
+ new Thread(this).start();
}
- try {
-
- Intent donateIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("bitcoin:" + bitcoinAddress
- + "?label=Southampton%20Uni%20Map%20App&message=Donation%20for%20the%20Southampton%20University%20Map%20App"));
- context.startActivity(donateIntent);
-
- } catch (ActivityNotFoundException e) {
- errorLayout.post(new Runnable() {
- public void run() {
- dialogMessage.setText(R.string.donate_dialog_error_title);
- progressBar.setVisibility(View.GONE);
- errorLayout.setVisibility(View.VISIBLE);
- donateDialogErrorMessage.setVisibility(View.VISIBLE);
- donateBitcoinAddress.setText(bitcoinAddress);
- donateBitcoinAddress.setVisibility(View.VISIBLE);
+ public void run() {
+ try {
+ Thread.sleep(3000);
+ } catch (InterruptedException e) {
+ e.printStackTrace();
+ }
+
+ try {
+
+ Intent donateIntent = new Intent(
+ Intent.ACTION_VIEW,
+ Uri.parse("bitcoin:"
+ + bitcoinAddress
+ + "?label=Southampton%20Uni%20Map%20App&message=Donation%20for%20the%20Southampton%20University%20Map%20App"));
+ context.startActivity(donateIntent);
+
+ } catch (ActivityNotFoundException e) {
+ errorLayout.post(new Runnable() {
+ public void run() {
+ dialogMessage.setText(R.string.donate_dialog_error_title);
+ progressBar.setVisibility(View.GONE);
+ errorLayout.setVisibility(View.VISIBLE);
+ donateDialogErrorMessage.setVisibility(View.VISIBLE);
+ donateBitcoinAddress.setText(bitcoinAddress);
+ donateBitcoinAddress.setVisibility(View.VISIBLE);
+ }
+ });
}
- });
}
- }
}
diff --git a/src/net/cbaines/suma/FindActivity.java b/src/net/cbaines/suma/FindActivity.java
index 154cd64..669249c 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_activity);
- 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 07806fa..501e00d 100644
--- a/src/net/cbaines/suma/MapActivity.java
+++ b/src/net/cbaines/suma/MapActivity.java
@@ -50,6 +50,7 @@ import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
import android.graphics.Color;
import android.graphics.DashPathEffect;
import android.graphics.Paint;
+import android.net.Uri;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.util.Log;
@@ -192,7 +193,7 @@ public class MapActivity extends OrmLiteBaseActivity<DatabaseHelper> implements
Thread databaseThread = new Thread(this); // Start the database thread
databaseThread.start();
- setContentView(R.layout.main);
+ setContentView(R.layout.map_activity);
Log.i(TAG, "Finished setting content view " + (System.currentTimeMillis() - startTime));
@@ -235,7 +236,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);
@@ -360,7 +384,7 @@ public class MapActivity extends OrmLiteBaseActivity<DatabaseHelper> implements
Dao<BusStop, String> busStopDao = helper.getBusStopDao();
Dao<BusRoute, Integer> busRouteDao = helper.getBusRouteDao();
- Dao<RouteStops, Integer> routeStopsDao = helper.getRouteStopsDao();
+ Dao<RouteStop, Integer> routeStopsDao = helper.getRouteStopsDao();
long busStopCount = busStopDao.countOf();
long busRouteCount = busRouteDao.countOf();
@@ -1059,15 +1083,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:
@@ -1156,10 +1171,26 @@ 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;
+
+ } else if (poi.type == POI.BUILDING) {
+ Building building = (Building) poi;
+
+ Log.i(TAG, "Pressed " + building.id);
+
+ Uri uri = Uri.parse("http://id.southampton.ac.uk/building/" + building.id);
+
+ Log.i(TAG, "Starting a activity for " + uri + " path " + uri.getPath());
+
+ Intent buildingIntent = new Intent(Intent.ACTION_VIEW, uri);
+ startActivity(buildingIntent);
return true;
diff --git a/src/net/cbaines/suma/POIArrayAdapter.java b/src/net/cbaines/suma/POIArrayAdapter.java
index e35acf4..f9b5271 100644
--- a/src/net/cbaines/suma/POIArrayAdapter.java
+++ b/src/net/cbaines/suma/POIArrayAdapter.java
@@ -21,7 +21,6 @@ package net.cbaines.suma;
import java.util.List;
-
import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
@@ -29,51 +28,52 @@ import android.widget.BaseAdapter;
public class POIArrayAdapter extends BaseAdapter {
- private final Context context;
- private final List<POI> POIs;
-
- public POIArrayAdapter(Context context, List<POI> pois) {
- this.context = context;
- this.POIs = pois;
- }
+ private final Context context;
+ private final List<? extends POI> POIs;
- public View getView(int position, View convertView, ViewGroup parent) {
- POIView poiView;
- if (convertView == null) {
- if (POIs.get(position).distTo == -1) {
- poiView = new POIView(context, POIs.get(position));
- } else {
- poiView = new POIView(context, POIs.get(position), POIs.get(position).distTo);
- }
- } else {
- poiView = (POIView) convertView;
- if (POIs.get(position).distTo == -1) {
- poiView = new POIView(context, POIs.get(position));
- } else {
- poiView = new POIView(context, POIs.get(position), POIs.get(position).distTo);
- }
+ public POIArrayAdapter(Context context, List<? extends POI> pois) {
+ this.context = context;
+ this.POIs = pois;
}
- return poiView;
- }
+ public View getView(int position, View convertView, ViewGroup parent) {
+ POIView poiView;
+ POI poi = POIs.get(position);
+ if (convertView == null) {
+ if (poi.distTo == -1) {
+ poiView = new POIView(context, poi);
+ } else {
+ poiView = new POIView(context, poi, poi.distTo);
+ }
+ } else {
+ poiView = (POIView) convertView;
+ if (((POI) POIs.get(position)).distTo == -1) {
+ poiView = new POIView(context, poi);
+ } else {
+ poiView = new POIView(context, poi, poi.distTo);
+ }
+ }
- public int getCount() {
- return POIs.size();
- }
+ return poiView;
+ }
- public Object getItem(int position) {
- return position;
- }
+ public int getCount() {
+ return POIs.size();
+ }
- public POI getPOIItem(int position) {
- return POIs.get(position);
- }
+ public Object getItem(int position) {
+ return position;
+ }
- public long getItemId(int position) {
- return position;
- }
+ public POI getPOIItem(int position) {
+ return (POI) POIs.get(position);
+ }
+
+ public long getItemId(int position) {
+ return position;
+ }
- public String getItemStringId(int position) {
- return POIs.get(position).id;
- }
+ public String getItemStringId(int position) {
+ return ((POI) POIs.get(position)).id;
+ }
} \ No newline at end of file
diff --git a/src/net/cbaines/suma/POIDialog.java b/src/net/cbaines/suma/POIDialog.java
index 20304bb..dd871fd 100644
--- a/src/net/cbaines/suma/POIDialog.java
+++ b/src/net/cbaines/suma/POIDialog.java
@@ -31,62 +31,62 @@ import android.widget.TextView;
public class POIDialog extends Dialog {
- // private static final String TAG = "POIDialog";
- private ListView listItems;
+ // private static final String TAG = "POIDialog";
+ private ListView listItems;
- private final Context context;
+ private final Context context;
- private final TextView message;
+ private final TextView message;
- protected POIArrayAdapter adapter;
+ protected POIArrayAdapter adapter;
- public POIDialog(Context context) {
- super(context);
+ public POIDialog(Context context) {
+ super(context);
- this.context = context;
+ this.context = context;
- setContentView(R.layout.poi_dialog);
+ setContentView(R.layout.poi_dialog);
- message = (TextView) findViewById(R.id.favouriteDialogMessage);
- listItems = (ListView) findViewById(R.id.favouriteListItems);
+ message = (TextView) findViewById(R.id.favouriteDialogMessage);
+ listItems = (ListView) findViewById(R.id.favouriteListItems);
- }
+ }
- void setMessage(final String text) {
- message.post(new Runnable() {
- public void run() {
- if (text == null || text.length() == 0) {
- message.setVisibility(View.GONE);
- } else {
- message.setText(text);
- message.setVisibility(View.VISIBLE);
- }
- }
- });
- }
+ void setMessage(final String text) {
+ message.post(new Runnable() {
+ public void run() {
+ if (text == null || text.length() == 0) {
+ message.setVisibility(View.GONE);
+ } else {
+ message.setText(text);
+ message.setVisibility(View.VISIBLE);
+ }
+ }
+ });
+ }
- void setItems(final List<POI> items) {
- listItems.post(new Runnable() {
- public void run() {
- if (items != null) {
- adapter = new POIArrayAdapter(context, items);
+ void setItems(final List<POI> items) {
+ listItems.post(new Runnable() {
+ public void run() {
+ if (items != null) {
+ adapter = new POIArrayAdapter(context, items);
- listItems.setVisibility(View.VISIBLE);
- listItems.setAdapter(adapter);
- } else {
- listItems.setVisibility(View.GONE);
- }
- }
- });
- }
+ listItems.setVisibility(View.VISIBLE);
+ listItems.setAdapter(adapter);
+ } else {
+ listItems.setVisibility(View.GONE);
+ }
+ }
+ });
+ }
- void setOnItemClickListener(OnItemClickListener item) {
- listItems.setOnItemClickListener(item);
+ void setOnItemClickListener(OnItemClickListener item) {
+ listItems.setOnItemClickListener(item);
- }
+ }
- void setOnItemLongClickListener(OnItemLongClickListener item) {
- listItems.setOnItemLongClickListener(item);
- }
+ void setOnItemLongClickListener(OnItemLongClickListener item) {
+ listItems.setOnItemLongClickListener(item);
+ }
}
diff --git a/src/net/cbaines/suma/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/POIView.java b/src/net/cbaines/suma/POIView.java
index fb8a6c6..95c571c 100644
--- a/src/net/cbaines/suma/POIView.java
+++ b/src/net/cbaines/suma/POIView.java
@@ -20,6 +20,7 @@
package net.cbaines.suma;
import android.content.Context;
+import android.preference.PreferenceManager;
import android.util.Log;
import android.view.Display;
import android.view.Gravity;
@@ -27,98 +28,114 @@ import android.view.WindowManager;
import android.widget.LinearLayout;
import android.widget.TextView;
-public class POIView extends LinearLayout {
+public class POIView extends LinearLayout implements Preferences {
- private final static String TAG = "POIView";
+ private final static String TAG = "POIView";
- private final TextView name;
- private final TextView dist;
- private final BusRoutesView routes;
+ private final TextView name;
+ private final TextView dist;
+ private final BusRoutesView routes;
- private LayoutParams textLayoutParams;
+ private LayoutParams textLayoutParams;
- final int width;
+ private boolean identifiersEnabled;
- public POIView(Context context, POI poi) {
- this(context, poi, -1);
- }
+ final int width;
- public POIView(Context context, POI poi, int distInM) {
- super(context);
-
- Display display = ((WindowManager) context.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
- width = display.getWidth();
- // int height = display.getHeight();
-
- this.setOrientation(HORIZONTAL);
-
- name = new TextView(context);
- name.setTextSize(16f);
- name.setGravity(Gravity.LEFT);
-
- dist = new TextView(context);
- dist.setTextSize(16f);
- dist.setGravity(Gravity.RIGHT);
-
- routes = new BusRoutesView(context, (byte) 0);
-
- textLayoutParams = new LayoutParams(width - (width / 4), LayoutParams.WRAP_CONTENT);
- LayoutParams distLayoutParams = new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT);
- LayoutParams busRouteLayoutParams = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
-
- setPOIAndDist(poi, distInM);
-
- addView(routes, busRouteLayoutParams);
- addView(name, textLayoutParams);
- addView(dist, distLayoutParams);
- }
-
- public void setPOI(POI poi) {
- setPOIAndDist(poi, -1);
- }
-
- public void setPOIAndDist(POI poi, int distInM) {
+ public POIView(Context context, POI poi) {
+ this(context, poi, -1);
+ }
- // Log.i(TAG, "Looking at poi " + poi.id);
+ public POIView(Context context, POI poi, int distInM) {
+ super(context);
- if (poi.type == POI.BUILDING) {
- Building building = (Building) poi;
- // Log.i(TAG, "Its a building of name " + building.name);
+ identifiersEnabled = PreferenceManager.getDefaultSharedPreferences(context).getBoolean(SHOW_IDENTIFIERS,
+ SHOW_IDENTIFIERS_ENABLED_BY_DEFAULT);
- name.setText(building.name + " (" + building.id + ")");
- } else if (poi.type == POI.BUS_STOP) {
+ Display display = ((WindowManager) context.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
+ width = display.getWidth();
+ // int height = display.getHeight();
- BusStop busStop = (BusStop) poi;
- // Log.i(TAG, "Its a bus stop of description " + busStop.description);
+ this.setOrientation(HORIZONTAL);
- name.setText(busStop.description + " (" + busStop.id + ")");
+ name = new TextView(context);
+ name.setTextSize(16f);
+ name.setGravity(Gravity.LEFT);
- routes.setRoutes(busStop.routes);
+ dist = new TextView(context);
+ dist.setTextSize(16f);
+ dist.setGravity(Gravity.RIGHT);
- } else if (poi.type == POI.SITE) {
+ routes = new BusRoutesView(context, (byte) 0);
- Site site = (Site) poi;
- // Log.i(TAG, "Its a site of name " + site.name);
+ textLayoutParams = new LayoutParams(width - (width / 4), LayoutParams.WRAP_CONTENT);
+ LayoutParams distLayoutParams = new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT);
+ LayoutParams busRouteLayoutParams = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
- name.setText(site.name + " (" + site.id + ")");
- } else {
- Log.w(TAG, "Cant identify " + poi.type);
+ setPOIAndDist(poi, distInM);
- name.setText(poi.id);
+ addView(routes, busRouteLayoutParams);
+ addView(name, textLayoutParams);
+ addView(dist, distLayoutParams);
}
- textLayoutParams = new LayoutParams(width - (width / 4), LayoutParams.WRAP_CONTENT);
-
- if (distInM != -1) {
- textLayoutParams.width = width - (width / 4);
- name.requestLayout();
- dist.setText(String.valueOf(distInM) + "m");
- } else {
- textLayoutParams.width = LayoutParams.FILL_PARENT;
- name.requestLayout();
- dist.setText("");
- // Log.w("POIView", "No dist avalible for S" + poi.id);
+ public void setPOI(POI poi) {
+ setPOIAndDist(poi, -1);
}
- }
+ public void setPOIAndDist(POI poi, int distInM) {
+
+ // Log.i(TAG, "Looking at poi " + poi.id);
+
+ if (poi.type == POI.BUILDING) {
+ Building building = (Building) poi;
+ // Log.i(TAG, "Its a building of name " + building.name);
+
+ if (identifiersEnabled) {
+ name.setText(building.name + " (" + building.id + ")");
+ } else {
+ name.setText(building.name);
+ }
+ } else if (poi.type == POI.BUS_STOP) {
+
+ BusStop busStop = (BusStop) poi;
+ // Log.i(TAG, "Its a bus stop of description " +
+ // busStop.description);
+
+ if (identifiersEnabled) {
+ name.setText(busStop.description + " (" + busStop.id + ")");
+ } else {
+ name.setText(busStop.description);
+ }
+
+ routes.setRoutes(busStop.routes);
+
+ } else if (poi.type == POI.SITE) {
+
+ Site site = (Site) poi;
+ // Log.i(TAG, "Its a site of name " + site.name);
+ if (identifiersEnabled) {
+ name.setText(site.name + " (" + site.id + ")");
+ } else {
+ name.setText(site.name);
+ }
+ } else {
+ Log.w(TAG, "Cant identify " + poi.type);
+
+ name.setText(poi.id);
+ }
+
+ textLayoutParams = new LayoutParams(width - (width / 4), LayoutParams.WRAP_CONTENT);
+
+ if (distInM != -1) {
+ textLayoutParams.width = width - (width / 4);
+ name.requestLayout();
+ dist.setText(String.valueOf(distInM) + "m");
+ } else {
+ textLayoutParams.width = LayoutParams.FILL_PARENT;
+ name.requestLayout();
+ dist.setText("");
+ // Log.w("POIView", "No dist avalible for S" + poi.id);
+ }
+ }
} \ No newline at end of file
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..0508251 100644
--- a/src/net/cbaines/suma/Preferences.java
+++ b/src/net/cbaines/suma/Preferences.java
@@ -1,15 +1,18 @@
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 SHOW_IDENTIFIERS = "showIdentifiers";
+ static final boolean SHOW_IDENTIFIERS_ENABLED_BY_DEFAULT = false;
+
static final String FAVOURITES_PREFERENCES = "favourites";
}
diff --git a/src/net/cbaines/suma/PreferencesActivity.java b/src/net/cbaines/suma/PreferencesActivity.java
index d72d266..bab72bf 100644
--- a/src/net/cbaines/suma/PreferencesActivity.java
+++ b/src/net/cbaines/suma/PreferencesActivity.java
@@ -27,26 +27,29 @@ 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);
+ }
+ if (!sharedPrefs.contains(SHOW_IDENTIFIERS)) {
+ editor.putBoolean(SHOW_IDENTIFIERS, SHOW_IDENTIFIERS_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/RouteStop.java b/src/net/cbaines/suma/RouteStop.java
new file mode 100644
index 0000000..a19f4fa
--- /dev/null
+++ b/src/net/cbaines/suma/RouteStop.java
@@ -0,0 +1,63 @@
+/*
+ * Southampton University Map App
+ * Copyright (C) 2011 Christopher Baines
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+package net.cbaines.suma;
+
+import com.j256.ormlite.field.DatabaseField;
+import com.j256.ormlite.table.DatabaseTable;
+
+@DatabaseTable(tableName = "routestops")
+public class RouteStop implements Comparable<RouteStop> {
+ public final static String STOP_ID_FIELD_NAME = "stop_id";
+ public final static String ROUTE_ID_FIELD_NAME = "route_id";
+ public final static String SEQUENCE_ID_FIELD_NAME = "sequence";
+
+ /**
+ * This id is generated by the database and set on the object when it is passed to the create method. An id is needed in case
+ * we need to update or delete this object in the future.
+ */
+ @DatabaseField(generatedId = true)
+ int id;
+
+ @DatabaseField
+ int sequence;
+
+ // This is a foreign object which just stores the id from the User object in
+ // this table.
+ @DatabaseField(foreign = true, columnName = STOP_ID_FIELD_NAME, indexName = "routestops_routestop_idx")
+ BusStop busStop;
+
+ // This is a foreign object which just stores the id from the Post object in
+ // this table.
+ @DatabaseField(foreign = true, columnName = ROUTE_ID_FIELD_NAME, indexName = "routestops_routestop_idx")
+ BusRoute busRoute;
+
+ RouteStop() {
+ }
+
+ public RouteStop(BusStop stop, BusRoute route, int sequence) {
+ this.busStop = stop;
+ this.busRoute = route;
+ this.sequence = sequence;
+ }
+
+ public int compareTo(RouteStop routeStop) {
+ return this.sequence - routeStop.sequence;
+ }
+}
diff --git a/src/net/cbaines/suma/RouteStops.java b/src/net/cbaines/suma/RouteStops.java
deleted file mode 100644
index 29fb18c..0000000
--- a/src/net/cbaines/suma/RouteStops.java
+++ /dev/null
@@ -1,57 +0,0 @@
-/*
- * Southampton University Map App
- * Copyright (C) 2011 Christopher Baines
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-
-package net.cbaines.suma;
-
-import com.j256.ormlite.field.DatabaseField;
-import com.j256.ormlite.table.DatabaseTable;
-
-@DatabaseTable(tableName = "routestops")
-public class RouteStops {
- public final static String STOP_ID_FIELD_NAME = "stop_id";
- public final static String ROUTE_ID_FIELD_NAME = "route_id";
- public final static String SEQUENCE_ID_FIELD_NAME = "sequence";
-
- /**
- * This id is generated by the database and set on the object when it is passed to the create method. An id is needed in case we need to update or delete
- * this object in the future.
- */
- @DatabaseField(generatedId = true)
- int id;
-
- @DatabaseField
- int sequence;
-
- // This is a foreign object which just stores the id from the User object in this table.
- @DatabaseField(foreign = true, columnName = STOP_ID_FIELD_NAME, indexName = "routestops_routestop_idx")
- BusStop busStop;
-
- // This is a foreign object which just stores the id from the Post object in this table.
- @DatabaseField(foreign = true, columnName = ROUTE_ID_FIELD_NAME, indexName = "routestops_routestop_idx")
- BusRoute busRoute;
-
- RouteStops() {
- }
-
- public RouteStops(BusStop stop, BusRoute route, int sequence) {
- this.busStop = stop;
- this.busRoute = route;
- this.sequence = sequence;
- }
-}
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 27c3a4c..9a0dcd3 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;
@@ -87,7 +87,6 @@ public class StopView extends LinearLayout implements OnClickListener, OnLongCli
if (stop.bus.id != null) {
if (stop.live) {
-
onClickMessage = "Bus " + stop.bus.toString() + " at "
+ DateFormat.getTimeInstance(DateFormat.SHORT).format(stop.arivalTime);
} else {
@@ -113,7 +112,6 @@ public class StopView extends LinearLayout implements OnClickListener, OnLongCli
public void onClick(View v) {
if (context.activityToast == null) {
-
context.activityToast = Toast.makeText(context, onClickMessage, Toast.LENGTH_SHORT);
} else {
context.activityToast.setText(onClickMessage);
@@ -124,7 +122,6 @@ public class StopView extends LinearLayout implements OnClickListener, OnLongCli
}
public boolean onLongClick(View v) {
-
DatabaseHelper helper = OpenHelperManager.getHelper(context, DatabaseHelper.class);
try {
@@ -137,14 +134,14 @@ public class StopView extends LinearLayout implements OnClickListener, OnLongCli
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);
} else {
@@ -154,7 +151,6 @@ public class StopView extends LinearLayout implements OnClickListener, OnLongCli
context.activityToast.show();
} else {
if (context.activityToast == null) {
-
context.activityToast = Toast.makeText(context, "Bus schedules not avalible for unidentified buses",
Toast.LENGTH_SHORT);
} else {
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));
}
diff --git a/src/net/cbaines/suma/Waypoint.java b/src/net/cbaines/suma/Waypoint.java
deleted file mode 100644
index d56c05d..0000000
--- a/src/net/cbaines/suma/Waypoint.java
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * Southampton University Map App
- * Copyright (C) 2011 Christopher Baines
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
-
-package net.cbaines.suma;
-
-import org.osmdroid.util.GeoPoint;
-
-import com.j256.ormlite.table.DatabaseTable;
-
-@DatabaseTable(tableName = "routeWaypoints")
-public class Waypoint extends POI {
-
- Waypoint() {
- }
-
- int sequence;
-
- String route;
-
- public Waypoint(int sequence, GeoPoint point) {
- super(point.toDoubleString() + ":" + sequence, point);
- this.type = POI.WAYPOINT;
- this.sequence = sequence;
- }
-
-}