aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristopher Baines <cbaines8@gmail.com>2012-03-06 11:42:24 +0000
committerChristopher Baines <cbaines8@gmail.com>2012-03-06 11:42:24 +0000
commit5dbed3a0fe85f0ed2a2763be0912f109bdee6c20 (patch)
tree849b3b07222c7ee0cf24247479c9adb3ca7c4faf
parent783024e364648171ae8848bb29b6dd71a84a2f40 (diff)
downloadsouthamptonuniversitymap-5dbed3a0fe85f0ed2a2763be0912f109bdee6c20.tar
southamptonuniversitymap-5dbed3a0fe85f0ed2a2763be0912f109bdee6c20.tar.gz
New Search stuff.
-rw-r--r--AndroidManifest.xml14
-rw-r--r--gen/net/cbaines/suma/R.java184
-rw-r--r--res/values/strings.xml1
-rw-r--r--res/xml/searchable.xml6
-rw-r--r--src/net/cbaines/suma/FindActivity.java13
-rw-r--r--src/net/cbaines/suma/MapActivity.java169
-rw-r--r--src/net/cbaines/suma/MapContentProvider.java201
7 files changed, 427 insertions, 161 deletions
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index c9efb4a..a9bccd3 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -50,8 +50,22 @@
<data android:scheme="geo" />
</intent-filter>
+ <intent-filter>
+ <action android:name="android.intent.action.SEARCH" />
+ </intent-filter>
+
+ <meta-data
+ android:name="android.app.searchable"
+ android:resource="@xml/searchable" />
</activity>
<activity android:name="FindActivity" >
+ <intent-filter>
+ <action android:name="android.intent.action.SEARCH" />
+ </intent-filter>
+
+ <meta-data
+ android:name="android.app.searchable"
+ android:resource="@xml/searchable" />
</activity>
<activity android:name="BusStopActivity" >
<intent-filter android:label="@string/app_name" >
diff --git a/gen/net/cbaines/suma/R.java b/gen/net/cbaines/suma/R.java
index 49cba3e..e1704a7 100644
--- a/gen/net/cbaines/suma/R.java
+++ b/gen/net/cbaines/suma/R.java
@@ -151,114 +151,116 @@ public final class R {
public static final int u9=0x7f060007;
}
public static final class string {
- public static final int U1=0x7f070009;
- public static final int U1N=0x7f07000a;
- public static final int U2=0x7f07000b;
- public static final int U6=0x7f07000c;
- public static final int U9=0x7f07000d;
+ public static final int U1=0x7f07000a;
+ public static final int U1N=0x7f07000b;
+ public static final int U2=0x7f07000c;
+ public static final int U6=0x7f07000d;
+ public static final int U9=0x7f07000e;
/** About Strings
*/
- 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=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;
+ public static final int about=0x7f070039;
+ public static final int about_android_market=0x7f070046;
+ public static final int about_android_market_summary=0x7f070047;
+ public static final int about_copyright=0x7f07003c;
+ public static final int about_copyright_summary=0x7f07003d;
+ public static final int about_data=0x7f070044;
+ public static final int about_data_summary=0x7f070045;
+ public static final int about_database=0x7f070050;
+ public static final int about_database_summary=0x7f070051;
+ public static final int about_developer=0x7f070042;
+ public static final int about_developer_summary=0x7f070043;
+ public static final int about_donate=0x7f070052;
+ public static final int about_donate_summary=0x7f070053;
+ public static final int about_help_message=0x7f070017;
+ public static final int about_license=0x7f07003e;
+ public static final int about_license_summary=0x7f07003f;
+ public static final int about_map_data=0x7f070048;
+ public static final int about_map_data_summary=0x7f070049;
+ public static final int about_map_icons=0x7f07004a;
+ public static final int about_map_icons_summary=0x7f07004b;
+ public static final int about_map_tiles=0x7f07004e;
+ public static final int about_map_tiles_summary=0x7f07004f;
/** About Messages
*/
- 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=0x7f070053;
- public static final int building_non_residential=0x7f070007;
- public static final int building_residential=0x7f070006;
+ public static final int about_menu_instruction_text=0x7f070032;
+ public static final int about_osm_map=0x7f07004c;
+ public static final int about_osm_map_summary=0x7f07004d;
+ public static final int about_project=0x7f070040;
+ public static final int about_project_summary=0x7f070041;
+ public static final int about_version=0x7f07003a;
+ public static final int about_version_summary=0x7f07003b;
+ public static final int app_name=0x7f070005;
+ public static final int bitcoin_error_message=0x7f07001c;
+ public static final int buildingImageDescription=0x7f070054;
+ public static final int building_non_residential=0x7f070008;
+ public static final int building_residential=0x7f070007;
/** Bus Activity
*/
- public static final int bus_activity_destination_label=0x7f070059;
- public static final int bus_activity_no_destination_message=0x7f07005a;
+ public static final int bus_activity_destination_label=0x7f07005a;
+ public static final int bus_activity_no_destination_message=0x7f07005b;
/** Bus Stop Specific Stop View Strings
*/
- public static final int bus_stop_stop_view_on_click_toast_help_message=0x7f070055;
- public static final int bus_stop_stop_view_on_click_toast_unidentified_message=0x7f070056;
+ public static final int bus_stop_stop_view_on_click_toast_help_message=0x7f070056;
+ public static final int bus_stop_stop_view_on_click_toast_unidentified_message=0x7f070057;
/** Bus Specific Stop View Strings
*/
- public static final int bus_stop_view_on_click_toast_help_message=0x7f070057;
- public static final int bus_stop_view_on_click_toast_unidentified_message=0x7f070058;
- 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=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;
- public static final int find_help_message=0x7f070012;
- public static final int findmylocation_help_message=0x7f070014;
- public static final int legal_message=0x7f070005;
- public static final int licence_help_message=0x7f070018;
- public static final int map_activity_toast_help_message=0x7f070054;
+ public static final int bus_stop_view_on_click_toast_help_message=0x7f070058;
+ public static final int bus_stop_view_on_click_toast_unidentified_message=0x7f070059;
+ public static final int bustimes_favourite_checkbox_label=0x7f070033;
+ public static final int credits_help_message=0x7f07001a;
+ public static final int donate_button=0x7f07001b;
+ public static final int donate_dialog_error_title=0x7f070035;
+ public static final int donate_dialog_message=0x7f070034;
+ public static final int favourites_dialog_message=0x7f07001e;
+ public static final int favourites_dialog_title=0x7f070011;
+ public static final int favourites_help_message=0x7f070018;
+ public static final int find_help_message=0x7f070013;
+ public static final int findmylocation_help_message=0x7f070015;
+ public static final int legal_message=0x7f070006;
+ public static final int licence_help_message=0x7f070019;
+ public static final int map_activity_search_hint=0x7f070000;
+ public static final int map_activity_toast_help_message=0x7f070055;
/** Help Messages
*/
- public static final int map_help_message=0x7f070011;
- public static final int menu_about=0x7f07000e;
- 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=0x7f070036;
- public static final int menu_preferences=0x7f070001;
- 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 map_help_message=0x7f070012;
+ public static final int menu_about=0x7f07000f;
+ public static final int menu_favourites=0x7f070010;
+ public static final int menu_find=0x7f070001;
+ public static final int menu_find_my_location=0x7f070004;
+ public static final int menu_next_stop=0x7f070037;
+ public static final int menu_preferences=0x7f070002;
+ public static final int menu_previous_stop=0x7f070036;
+ public static final int menu_refresh_stop=0x7f070038;
+ public static final int menu_view=0x7f070003;
+ public static final int pref_bus_stop=0x7f070009;
+ public static final int preferences=0x7f07001d;
/** Preferences Messages
*/
- 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=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 int preferences_catagory_appearance=0x7f07001f;
+ public static final int preferences_catagory_data=0x7f07002e;
+ public static final int preferences_catagory_live_bus_times=0x7f070027;
+ public static final int preferences_catagory_positioning=0x7f070023;
+ public static final int preferences_gps=0x7f070024;
+ public static final int preferences_gps_disabled=0x7f070026;
+ public static final int preferences_gps_enabled=0x7f070025;
+ public static final int preferences_help_message=0x7f070014;
+ public static final int preferences_non_uni_link=0x7f07002f;
+ public static final int preferences_non_uni_link_disabled=0x7f070031;
+ public static final int preferences_non_uni_link_enabled=0x7f070030;
+ public static final int preferences_non_uni_link_live_bus_times=0x7f07002b;
+ public static final int preferences_non_uni_link_live_bus_times_disabled=0x7f07002d;
+ public static final int preferences_non_uni_link_live_bus_times_enabled=0x7f07002c;
+ public static final int preferences_show_identifiers=0x7f070020;
+ public static final int preferences_show_identifiers_disabled=0x7f070022;
+ public static final int preferences_show_identifiers_enabled=0x7f070021;
+ public static final int preferences_uni_link_live_bus_times=0x7f070028;
+ public static final int preferences_uni_link_live_bus_times_disabled=0x7f07002a;
+ public static final int preferences_uni_link_live_bus_times_enabled=0x7f070029;
+ public static final int view_help_message=0x7f070016;
}
public static final class xml {
public static final int about=0x7f050000;
public static final int preferences=0x7f050001;
+ public static final int searchable=0x7f050002;
}
}
diff --git a/res/values/strings.xml b/res/values/strings.xml
index e17ab11..6126937 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -1,6 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
+ <string name="map_activity_search_hint">Search</string>
<string name="menu_find">Find</string>
<string name="menu_preferences">Preferences</string>
<string name="menu_view">View</string>
diff --git a/res/xml/searchable.xml b/res/xml/searchable.xml
new file mode 100644
index 0000000..e4602a5
--- /dev/null
+++ b/res/xml/searchable.xml
@@ -0,0 +1,6 @@
+<?xml version="1.0" encoding="utf-8"?>
+<searchable xmlns:android="http://schemas.android.com/apk/res/android"
+ android:hint="@string/map_activity_search_hint"
+ android:label="@string/app_name" >
+
+</searchable> \ No newline at end of file
diff --git a/src/net/cbaines/suma/FindActivity.java b/src/net/cbaines/suma/FindActivity.java
index 669249c..5a07807 100644
--- a/src/net/cbaines/suma/FindActivity.java
+++ b/src/net/cbaines/suma/FindActivity.java
@@ -27,6 +27,7 @@ import java.util.List;
import org.osmdroid.util.GeoPoint;
+import android.app.SearchManager;
import android.content.Context;
import android.content.Intent;
import android.location.Location;
@@ -57,6 +58,9 @@ public class FindActivity extends OrmLiteBaseActivity<DatabaseHelper> implements
final static String TAG = "FindActivity";
+ public static final String ORIGIN = "o";
+ public static final int MAP_ACTIVITY = 0;
+
private EditText searchBar;
private ListView listItems;
private ProgressBar progBar;
@@ -243,9 +247,18 @@ public class FindActivity extends OrmLiteBaseActivity<DatabaseHelper> implements
super.onCreate(savedInstanceState);
setContentView(R.layout.find_activity);
+ Log.i(TAG, "FindActivity started");
+
searchBar = (EditText) findViewById(R.id.searchBar);
searchBar.addTextChangedListener(this);
+ Intent intent = getIntent();
+ if (Intent.ACTION_SEARCH.equals(intent.getAction())) {
+ String query = intent.getStringExtra(SearchManager.QUERY);
+ Log.i(TAG, "Searching for " + query);
+ searchBar.setText(query);
+ }
+
listItems = (ListView) findViewById(R.id.findListItems);
listItems.setOnItemClickListener(this);
listItems.setOnItemLongClickListener(this);
diff --git a/src/net/cbaines/suma/MapActivity.java b/src/net/cbaines/suma/MapActivity.java
index 01e8ec6..6c4664e 100644
--- a/src/net/cbaines/suma/MapActivity.java
+++ b/src/net/cbaines/suma/MapActivity.java
@@ -73,8 +73,8 @@ public class MapActivity extends ToastHelperActivity implements MapViewConstants
OnItemClickListener, OnItemLongClickListener, OnSharedPreferenceChangeListener, Preferences {
/**
- * Enable to use the database in the assets folder, if its not enabled, the database is built from the csv files in the assets
- * folder
+ * Enable to use the database in the assets folder, if its not enabled, the
+ * database is built from the csv files in the assets folder
*/
private boolean useBundledDatabase = true;
@@ -124,10 +124,11 @@ public class MapActivity extends ToastHelperActivity implements MapViewConstants
private static final int NON_UNI_LINK_BUS_STOP_OVERLAY_RANK = 4;
// -- Site Overlays
- static final String[] SITE_NAMES = { "Highfield Campus", "Boldrewood Campus", "Avenue Campus", "Winchester School of Art",
- "The University of Southampton Science Park", "National Oceanography Centre Campus", "Boat House",
- "Southampton General Hospital", "Royal South Hants Hospital", "Belgrave Industrial Site", "Highfield Hall",
- "Glen Eyre Hall", "South Hill Hall", "Chamberlain Hall", "Hartley Grove", "Bencraft Hall", "Connaught Hall",
+ static final String[] SITE_NAMES = { "Highfield Campus", "Boldrewood Campus", "Avenue Campus",
+ "Winchester School of Art", "The University of Southampton Science Park",
+ "National Oceanography Centre Campus", "Boat House", "Southampton General Hospital",
+ "Royal South Hants Hospital", "Belgrave Industrial Site", "Highfield Hall", "Glen Eyre Hall",
+ "South Hill Hall", "Chamberlain Hall", "Hartley Grove", "Bencraft Hall", "Connaught Hall",
"Montefiore Hall", "Stoneham Hall", "Erasmus Park" };
private static final String SITE_OVERLAYS = "siteOverlays:";
@@ -165,8 +166,8 @@ public class MapActivity extends ToastHelperActivity implements MapViewConstants
// Uni-Link routes
static final String[] UNI_LINK_ROUTES = { "U1", "U1N", "U2", "U6", "U9" };
- static final String[] PREFERENCES_GROUPS = { BUS_STOP_OVERLAYS, BUS_ROUTE_OVERLAYS, BUILDING_OVERLAYS, SITE_OVERLAYS,
- OTHER_OVERLAYS };
+ static final String[] PREFERENCES_GROUPS = { BUS_STOP_OVERLAYS, BUS_ROUTE_OVERLAYS, BUILDING_OVERLAYS,
+ SITE_OVERLAYS, OTHER_OVERLAYS };
static final String[][] PREFERENCES_CHILDREN = { UNI_LINK_ROUTES, UNI_LINK_ROUTES, BUILDING_TYPES, SITE_NAMES,
OTHER_OVERLAY_NAMES };
@@ -198,8 +199,10 @@ public class MapActivity extends ToastHelperActivity implements MapViewConstants
pastOverlays = (HashMap<String, Overlay>) getLastNonConfigurationInstance();
/*
- * SensorManager mSensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE); This code in the following
- * constructor causes problems in some emulators, disable sensors to fix.
+ * SensorManager mSensorManager = (SensorManager)
+ * getSystemService(Context.SENSOR_SERVICE); This code in the following
+ * constructor causes problems in some emulators, disable sensors to
+ * fix.
*/
Log.i(TAG, "Starting creating myLocationOverlay");
myLocationOverlay = new MyLocationOverlay(instance, mapView);
@@ -320,6 +323,14 @@ public class MapActivity extends ToastHelperActivity implements MapViewConstants
return overlays;
}
+ @Override
+ public boolean onSearchRequested() {
+ Bundle appData = new Bundle();
+ appData.putInt(FindActivity.ORIGIN, FindActivity.MAP_ACTIVITY);
+ startSearch(null, false, appData, false);
+ return true;
+ }
+
public void run() {
Log.i(TAG, "Begining loading database " + (System.currentTimeMillis() - startTime));
@@ -513,7 +524,8 @@ public class MapActivity extends ToastHelperActivity implements MapViewConstants
if (scaleBarOverlay != null) {
Log.v(TAG, "ScaleBarOverlay is already created");
} else {
- if (pastOverlays != null && (scaleBarOverlay = (ScaleBarOverlay) pastOverlays.get(SCALE_BAR_OVERLAY)) != null) {
+ if (pastOverlays != null
+ && (scaleBarOverlay = (ScaleBarOverlay) pastOverlays.get(SCALE_BAR_OVERLAY)) != null) {
Log.i(TAG, "Finished restoring utility overlays " + (System.currentTimeMillis() - startTime));
} else {
scaleBarOverlay = new ScaleBarOverlay(instance);
@@ -542,7 +554,8 @@ public class MapActivity extends ToastHelperActivity implements MapViewConstants
private void showRouteOverlay(final BusRoute route) {
new Thread(new Runnable() {
public void run() {
- Log.i(TAG, "Begining showing route " + route.code + " overlay at " + (System.currentTimeMillis() - startTime));
+ Log.i(TAG, "Begining showing route " + route.code + " overlay at "
+ + (System.currentTimeMillis() - startTime));
final SharedPreferences activityPrefs = getPreferences(0);
final OverlayRankComparator comparator = new OverlayRankComparator(getPreferences(0));
@@ -567,8 +580,8 @@ public class MapActivity extends ToastHelperActivity implements MapViewConstants
// TODO Is this a route like U1N or, something else,
// this hack works somewhat for now?
- PathOverlay routeOverlayU1E = DataManager.getRoutePath(getResources().openRawResource(R.raw.u1e),
- colour, mResourceProxy);
+ PathOverlay routeOverlayU1E = DataManager.getRoutePath(
+ getResources().openRawResource(R.raw.u1e), colour, mResourceProxy);
routeOverlayU1E.getPaint().setAntiAlias(true);
routeOverlayU1E.getPaint().setAlpha(145);
routeOverlayU1E.getPaint().setStrokeWidth(12);
@@ -623,7 +636,8 @@ public class MapActivity extends ToastHelperActivity implements MapViewConstants
mapView.postInvalidate();
- Log.i(TAG, "Finished showing route " + route.code + " overlay at " + (System.currentTimeMillis() - startTime));
+ Log.i(TAG, "Finished showing route " + route.code + " overlay at "
+ + (System.currentTimeMillis() - startTime));
}
}).start();
}
@@ -632,7 +646,8 @@ public class MapActivity extends ToastHelperActivity implements MapViewConstants
new Thread(new Runnable() {
public void run() {
- Log.i(TAG, "Begining showing site " + site.name + " overlay at " + (System.currentTimeMillis() - startTime));
+ Log.i(TAG, "Begining showing site " + site.name + " overlay at "
+ + (System.currentTimeMillis() - startTime));
final SharedPreferences activityPrefs = getPreferences(0);
final OverlayRankComparator comparator = new OverlayRankComparator(getPreferences(0));
@@ -641,7 +656,8 @@ public class MapActivity extends ToastHelperActivity implements MapViewConstants
if ((siteOverlay = siteOverlays.get(site)) != null) {
} else {
- if (pastOverlays != null && (siteOverlay = (PathOverlay) pastOverlays.get(SITE_OVERLAYS + site.name)) != null) {
+ if (pastOverlays != null
+ && (siteOverlay = (PathOverlay) pastOverlays.get(SITE_OVERLAYS + site.name)) != null) {
Log.i(TAG, "Restored " + site.name + " site overlay");
} else {
@@ -667,11 +683,13 @@ public class MapActivity extends ToastHelperActivity implements MapViewConstants
}
}
- siteOverlay.setEnabled(activityPrefs.getBoolean(SITE_OVERLAYS + site.name, SITE_OVERLAYS_ENABLED_BY_DEFAULT));
+ siteOverlay.setEnabled(activityPrefs.getBoolean(SITE_OVERLAYS + site.name,
+ SITE_OVERLAYS_ENABLED_BY_DEFAULT));
mapView.postInvalidate();
- Log.i(TAG, "Finished showing site " + site.name + " overlay at " + (System.currentTimeMillis() - startTime));
+ Log.i(TAG, "Finished showing site " + site.name + " overlay at "
+ + (System.currentTimeMillis() - startTime));
}
}).start();
}
@@ -688,8 +706,10 @@ public class MapActivity extends ToastHelperActivity implements MapViewConstants
} else {
if (pastOverlays != null
- && (residentialBuildingOverlay = (BuildingNumOverlay) pastOverlays.get(RESIDENTIAL_BUILDING_OVERLAY)) != null) {
- nonResidentialBuildingOverlay = (BuildingNumOverlay) pastOverlays.get(NON_RESIDENTIAL_BUILDING_OVERLAY);
+ && (residentialBuildingOverlay = (BuildingNumOverlay) pastOverlays
+ .get(RESIDENTIAL_BUILDING_OVERLAY)) != null) {
+ nonResidentialBuildingOverlay = (BuildingNumOverlay) pastOverlays
+ .get(NON_RESIDENTIAL_BUILDING_OVERLAY);
Log.i(TAG, "Restored building overlays");
} else {
@@ -704,7 +724,8 @@ public class MapActivity extends ToastHelperActivity implements MapViewConstants
buildingDao = getHelper().getBuildingDao();
- final SharedPreferences favouritesPrefs = getSharedPreferences(FAVOURITES_PREFERENCES, MODE_PRIVATE);
+ final SharedPreferences favouritesPrefs = getSharedPreferences(FAVOURITES_PREFERENCES,
+ MODE_PRIVATE);
for (Building building : buildingDao) {
if (building.residential == true) {
@@ -742,8 +763,8 @@ public class MapActivity extends ToastHelperActivity implements MapViewConstants
}
}
- residentialBuildingOverlay.setEnabled(activityPrefs.getBoolean(BUILDING_OVERLAYS + RESIDENTIAL_BUILDING_OVERLAY,
- RESIDENTIAL_BUILDING_OVERLAY_ENABLED_BY_DEFAULT));
+ residentialBuildingOverlay.setEnabled(activityPrefs.getBoolean(BUILDING_OVERLAYS
+ + RESIDENTIAL_BUILDING_OVERLAY, RESIDENTIAL_BUILDING_OVERLAY_ENABLED_BY_DEFAULT));
nonResidentialBuildingOverlay.setEnabled(activityPrefs.getBoolean(BUILDING_OVERLAYS
+ NON_RESIDENTIAL_BUILDING_OVERLAY, NON_RESIDENTIAL_BUILDING_OVERLAY_ENABLED_BY_DEFAULT));
@@ -763,11 +784,16 @@ public class MapActivity extends ToastHelperActivity implements MapViewConstants
final OverlayRankComparator comparator = new OverlayRankComparator(getPreferences(0));
if (uniLinkBusStopOverlay != null) {
- if (!activityPrefs.getBoolean(BUS_STOP_OVERLAYS + "U1", UNI_LINK_BUS_STOP_OVERLAY_ENABLED_BY_DEFAULT)
- && !activityPrefs.getBoolean(BUS_STOP_OVERLAYS + "U1N", UNI_LINK_BUS_STOP_OVERLAY_ENABLED_BY_DEFAULT)
- && !activityPrefs.getBoolean(BUS_STOP_OVERLAYS + "U2", UNI_LINK_BUS_STOP_OVERLAY_ENABLED_BY_DEFAULT)
- && !activityPrefs.getBoolean(BUS_STOP_OVERLAYS + "U6", UNI_LINK_BUS_STOP_OVERLAY_ENABLED_BY_DEFAULT)
- && !activityPrefs.getBoolean(BUS_STOP_OVERLAYS + "U9", UNI_LINK_BUS_STOP_OVERLAY_ENABLED_BY_DEFAULT)) {
+ if (!activityPrefs.getBoolean(BUS_STOP_OVERLAYS + "U1",
+ UNI_LINK_BUS_STOP_OVERLAY_ENABLED_BY_DEFAULT)
+ && !activityPrefs.getBoolean(BUS_STOP_OVERLAYS + "U1N",
+ UNI_LINK_BUS_STOP_OVERLAY_ENABLED_BY_DEFAULT)
+ && !activityPrefs.getBoolean(BUS_STOP_OVERLAYS + "U2",
+ UNI_LINK_BUS_STOP_OVERLAY_ENABLED_BY_DEFAULT)
+ && !activityPrefs.getBoolean(BUS_STOP_OVERLAYS + "U6",
+ UNI_LINK_BUS_STOP_OVERLAY_ENABLED_BY_DEFAULT)
+ && !activityPrefs.getBoolean(BUS_STOP_OVERLAYS + "U9",
+ UNI_LINK_BUS_STOP_OVERLAY_ENABLED_BY_DEFAULT)) {
Log.i(TAG, "Uni-Link bus stop overlay not needed");
overlays.remove(UNI_LINK_BUS_STOP_OVERLAY);
@@ -778,25 +804,31 @@ public class MapActivity extends ToastHelperActivity implements MapViewConstants
uniLinkBusStopOverlay = null;
} else {
- uniLinkBusStopOverlay.setRoutes(0,
- activityPrefs.getBoolean(BUS_STOP_OVERLAYS + "U1", UNI_LINK_BUS_STOP_OVERLAY_ENABLED_BY_DEFAULT));
- uniLinkBusStopOverlay.setRoutes(1,
- activityPrefs.getBoolean(BUS_STOP_OVERLAYS + "U1N", UNI_LINK_BUS_STOP_OVERLAY_ENABLED_BY_DEFAULT));
- uniLinkBusStopOverlay.setRoutes(2,
- activityPrefs.getBoolean(BUS_STOP_OVERLAYS + "U2", UNI_LINK_BUS_STOP_OVERLAY_ENABLED_BY_DEFAULT));
- uniLinkBusStopOverlay.setRoutes(3,
- activityPrefs.getBoolean(BUS_STOP_OVERLAYS + "U6", UNI_LINK_BUS_STOP_OVERLAY_ENABLED_BY_DEFAULT));
- uniLinkBusStopOverlay.setRoutes(4,
- activityPrefs.getBoolean(BUS_STOP_OVERLAYS + "U9", UNI_LINK_BUS_STOP_OVERLAY_ENABLED_BY_DEFAULT));
+ uniLinkBusStopOverlay.setRoutes(0, activityPrefs.getBoolean(BUS_STOP_OVERLAYS + "U1",
+ UNI_LINK_BUS_STOP_OVERLAY_ENABLED_BY_DEFAULT));
+ uniLinkBusStopOverlay.setRoutes(1, activityPrefs.getBoolean(BUS_STOP_OVERLAYS + "U1N",
+ UNI_LINK_BUS_STOP_OVERLAY_ENABLED_BY_DEFAULT));
+ uniLinkBusStopOverlay.setRoutes(2, activityPrefs.getBoolean(BUS_STOP_OVERLAYS + "U2",
+ UNI_LINK_BUS_STOP_OVERLAY_ENABLED_BY_DEFAULT));
+ uniLinkBusStopOverlay.setRoutes(3, activityPrefs.getBoolean(BUS_STOP_OVERLAYS + "U6",
+ UNI_LINK_BUS_STOP_OVERLAY_ENABLED_BY_DEFAULT));
+ uniLinkBusStopOverlay.setRoutes(4, activityPrefs.getBoolean(BUS_STOP_OVERLAYS + "U9",
+ UNI_LINK_BUS_STOP_OVERLAY_ENABLED_BY_DEFAULT));
}
} else {
- if (activityPrefs.getBoolean(BUS_STOP_OVERLAYS + "U1", UNI_LINK_BUS_STOP_OVERLAY_ENABLED_BY_DEFAULT)
- || activityPrefs.getBoolean(BUS_STOP_OVERLAYS + "U1N", UNI_LINK_BUS_STOP_OVERLAY_ENABLED_BY_DEFAULT)
- || activityPrefs.getBoolean(BUS_STOP_OVERLAYS + "U2", UNI_LINK_BUS_STOP_OVERLAY_ENABLED_BY_DEFAULT)
- || activityPrefs.getBoolean(BUS_STOP_OVERLAYS + "U6", UNI_LINK_BUS_STOP_OVERLAY_ENABLED_BY_DEFAULT)
- || activityPrefs.getBoolean(BUS_STOP_OVERLAYS + "U9", UNI_LINK_BUS_STOP_OVERLAY_ENABLED_BY_DEFAULT)) {
+ if (activityPrefs
+ .getBoolean(BUS_STOP_OVERLAYS + "U1", UNI_LINK_BUS_STOP_OVERLAY_ENABLED_BY_DEFAULT)
+ || activityPrefs.getBoolean(BUS_STOP_OVERLAYS + "U1N",
+ UNI_LINK_BUS_STOP_OVERLAY_ENABLED_BY_DEFAULT)
+ || activityPrefs.getBoolean(BUS_STOP_OVERLAYS + "U2",
+ UNI_LINK_BUS_STOP_OVERLAY_ENABLED_BY_DEFAULT)
+ || activityPrefs.getBoolean(BUS_STOP_OVERLAYS + "U6",
+ UNI_LINK_BUS_STOP_OVERLAY_ENABLED_BY_DEFAULT)
+ || activityPrefs.getBoolean(BUS_STOP_OVERLAYS + "U9",
+ UNI_LINK_BUS_STOP_OVERLAY_ENABLED_BY_DEFAULT)) {
if (pastOverlays != null
- && (uniLinkBusStopOverlay = (BusStopOverlay) pastOverlays.get(UNI_LINK_BUS_STOP_OVERLAY)) != null) {
+ && (uniLinkBusStopOverlay = (BusStopOverlay) pastOverlays
+ .get(UNI_LINK_BUS_STOP_OVERLAY)) != null) {
Log.i(TAG, "Restored Uni-Link bus stop overlay");
} else {
@@ -814,16 +846,16 @@ public class MapActivity extends ToastHelperActivity implements MapViewConstants
}
}
- uniLinkBusStopOverlay.setRoutes(0,
- activityPrefs.getBoolean(BUS_STOP_OVERLAYS + "U1", UNI_LINK_BUS_STOP_OVERLAY_ENABLED_BY_DEFAULT));
- uniLinkBusStopOverlay.setRoutes(1,
- activityPrefs.getBoolean(BUS_STOP_OVERLAYS + "U1N", UNI_LINK_BUS_STOP_OVERLAY_ENABLED_BY_DEFAULT));
- uniLinkBusStopOverlay.setRoutes(2,
- activityPrefs.getBoolean(BUS_STOP_OVERLAYS + "U2", UNI_LINK_BUS_STOP_OVERLAY_ENABLED_BY_DEFAULT));
- uniLinkBusStopOverlay.setRoutes(3,
- activityPrefs.getBoolean(BUS_STOP_OVERLAYS + "U6", UNI_LINK_BUS_STOP_OVERLAY_ENABLED_BY_DEFAULT));
- uniLinkBusStopOverlay.setRoutes(4,
- activityPrefs.getBoolean(BUS_STOP_OVERLAYS + "U9", UNI_LINK_BUS_STOP_OVERLAY_ENABLED_BY_DEFAULT));
+ uniLinkBusStopOverlay.setRoutes(0, activityPrefs.getBoolean(BUS_STOP_OVERLAYS + "U1",
+ UNI_LINK_BUS_STOP_OVERLAY_ENABLED_BY_DEFAULT));
+ uniLinkBusStopOverlay.setRoutes(1, activityPrefs.getBoolean(BUS_STOP_OVERLAYS + "U1N",
+ UNI_LINK_BUS_STOP_OVERLAY_ENABLED_BY_DEFAULT));
+ uniLinkBusStopOverlay.setRoutes(2, activityPrefs.getBoolean(BUS_STOP_OVERLAYS + "U2",
+ UNI_LINK_BUS_STOP_OVERLAY_ENABLED_BY_DEFAULT));
+ uniLinkBusStopOverlay.setRoutes(3, activityPrefs.getBoolean(BUS_STOP_OVERLAYS + "U6",
+ UNI_LINK_BUS_STOP_OVERLAY_ENABLED_BY_DEFAULT));
+ uniLinkBusStopOverlay.setRoutes(4, activityPrefs.getBoolean(BUS_STOP_OVERLAYS + "U9",
+ UNI_LINK_BUS_STOP_OVERLAY_ENABLED_BY_DEFAULT));
overlays.put(UNI_LINK_BUS_STOP_OVERLAY, uniLinkBusStopOverlay);
@@ -846,7 +878,8 @@ public class MapActivity extends ToastHelperActivity implements MapViewConstants
private void showNonUniLinkBusStopOverlay() {
new Thread(new Runnable() {
public void run() {
- Log.i(TAG, "Begining showing non uni link bus stop overlays at " + (System.currentTimeMillis() - startTime));
+ Log.i(TAG, "Begining showing non uni link bus stop overlays at "
+ + (System.currentTimeMillis() - startTime));
// final SharedPreferences activityPrefs = getPreferences(0);
final SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(instance);
@@ -863,12 +896,14 @@ public class MapActivity extends ToastHelperActivity implements MapViewConstants
} else if (sharedPrefs.getBoolean(NON_UNI_LINK_BUS_STOPS_OVERLAY,
NON_UNI_LINK_BUS_STOP_OVERLAY_ENABLED_BY_DEFAULT)) {
if (pastOverlays != null
- && (nonUniLinkBusStopOverlay = (BusStopOverlay) pastOverlays.get(NON_UNI_LINK_BUS_STOPS_OVERLAY)) != null) {
+ && (nonUniLinkBusStopOverlay = (BusStopOverlay) pastOverlays
+ .get(NON_UNI_LINK_BUS_STOPS_OVERLAY)) != null) {
Log.i(TAG, "Restored non Uni-Link bus stop overlays");
} else {
try {
List<BusStop> busStops;
- Log.v(TAG, "Begin fetching non Uni-Link BusStops at " + (System.currentTimeMillis() - startTime));
+ Log.v(TAG, "Begin fetching non Uni-Link BusStops at "
+ + (System.currentTimeMillis() - startTime));
busStops = getHelper().getBusStopDao().queryForEq(BusStop.UNI_LINK_FIELD_NAME, false);
@@ -898,7 +933,8 @@ public class MapActivity extends ToastHelperActivity implements MapViewConstants
mapView.postInvalidate();
- Log.i(TAG, "Finished showing non Uni-Link bus stop overlays at " + (System.currentTimeMillis() - startTime));
+ Log.i(TAG, "Finished showing non Uni-Link bus stop overlays at "
+ + (System.currentTimeMillis() - startTime));
}
}).start();
}
@@ -915,8 +951,7 @@ public class MapActivity extends ToastHelperActivity implements MapViewConstants
// Handle item selection
switch (item.getItemId()) {
case R.id.menu_find:
- Intent i = new Intent(MapActivity.this, FindActivity.class);
- startActivityForResult(i, 0);
+ onSearchRequested();
return true;
case R.id.menu_preferences:
Intent settingsActivity = new Intent(getBaseContext(), PreferencesActivity.class);
@@ -950,8 +985,9 @@ public class MapActivity extends ToastHelperActivity implements MapViewConstants
};
AlertDialog.Builder builder = new AlertDialog.Builder(this);
- builder.setMessage("GPS is not enabled, do you wish to enable it?").setPositiveButton("Yes", dialogClickListener)
- .setNegativeButton("No", dialogClickListener).show();
+ builder.setMessage("GPS is not enabled, do you wish to enable it?")
+ .setPositiveButton("Yes", dialogClickListener).setNegativeButton("No", dialogClickListener)
+ .show();
}
return true;
@@ -1015,13 +1051,6 @@ public class MapActivity extends ToastHelperActivity implements MapViewConstants
}
}
- @Override
- public boolean onSearchRequested() {
- Intent i = new Intent(MapActivity.this, FindActivity.class);
- startActivityForResult(i, 0);
- return false;
- }
-
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
Log.i(TAG, "Got activity result");
if (resultCode == RESULT_OK) {
diff --git a/src/net/cbaines/suma/MapContentProvider.java b/src/net/cbaines/suma/MapContentProvider.java
new file mode 100644
index 0000000..46986ab
--- /dev/null
+++ b/src/net/cbaines/suma/MapContentProvider.java
@@ -0,0 +1,201 @@
+/*
+ * Copyright (C) 2010 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package net.cbaines.suma;
+
+import com.j256.ormlite.android.apptools.OpenHelperManager;
+
+import android.app.SearchManager;
+import android.content.ContentProvider;
+import android.content.ContentResolver;
+import android.content.ContentValues;
+import android.content.UriMatcher;
+import android.database.Cursor;
+import android.net.Uri;
+import android.provider.BaseColumns;
+
+/**
+ * Provides access to the dictionary database.
+ */
+public class MapContentProvider extends ContentProvider {
+ String TAG = "MapContentProvider";
+
+ public static String AUTHORITY = "net.cbaines.suma.provider";
+ public static final Uri CONTENT_URI = Uri.parse("content://" + AUTHORITY + "/building");
+
+ // MIME types used for searching words or looking up a single definition
+ public static final String WORDS_MIME_TYPE = ContentResolver.CURSOR_DIR_BASE_TYPE
+ + "/vnd.example.android.searchabledict";
+ public static final String DEFINITION_MIME_TYPE = ContentResolver.CURSOR_ITEM_BASE_TYPE
+ + "/vnd.example.android.searchabledict";
+
+ private DatabaseHelper helper;
+
+ // UriMatcher stuff
+ private static final int SEARCH_WORDS = 0;
+ private static final int GET_WORD = 1;
+ private static final int SEARCH_SUGGEST = 2;
+ private static final int REFRESH_SHORTCUT = 3;
+ private static final UriMatcher sURIMatcher = buildUriMatcher();
+
+ /**
+ * Builds up a UriMatcher for search suggestion and shortcut refresh
+ * queries.
+ */
+ private static UriMatcher buildUriMatcher() {
+ UriMatcher matcher = new UriMatcher(UriMatcher.NO_MATCH);
+ // to get definitions...
+ matcher.addURI(AUTHORITY, "dictionary", SEARCH_WORDS);
+ matcher.addURI(AUTHORITY, "dictionary/#", GET_WORD);
+ // to get suggestions...
+ matcher.addURI(AUTHORITY, SearchManager.SUGGEST_URI_PATH_QUERY, SEARCH_SUGGEST);
+ matcher.addURI(AUTHORITY, SearchManager.SUGGEST_URI_PATH_QUERY + "/*", SEARCH_SUGGEST);
+
+ /*
+ * The following are unused in this implementation, but if we include
+ * {@link SearchManager#SUGGEST_COLUMN_SHORTCUT_ID} as a column in our
+ * suggestions table, we could expect to receive refresh queries when a
+ * shortcutted suggestion is displayed in Quick Search Box, in which
+ * case, the following Uris would be provided and we would return a
+ * cursor with a single item representing the refreshed suggestion data.
+ */
+ matcher.addURI(AUTHORITY, SearchManager.SUGGEST_URI_PATH_SHORTCUT, REFRESH_SHORTCUT);
+ matcher.addURI(AUTHORITY, SearchManager.SUGGEST_URI_PATH_SHORTCUT + "/*", REFRESH_SHORTCUT);
+ return matcher;
+ }
+
+ @Override
+ public boolean onCreate() {
+ helper = OpenHelperManager.getHelper(this.getContext(), DatabaseHelper.class);
+ return true;
+ }
+
+ /**
+ * Handles all the dictionary searches and suggestion queries from the
+ * Search Manager. When requesting a specific word, the uri alone is
+ * required. When searching all of the dictionary for matches, the
+ * selectionArgs argument must carry the search query as the first element.
+ * All other arguments are ignored.
+ */
+ @Override
+ public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) {
+
+ // Use the UriMatcher to see what kind of query we have and format the
+ // db query accordingly
+ switch (sURIMatcher.match(uri)) {
+ case SEARCH_SUGGEST:
+ if (selectionArgs == null) {
+ throw new IllegalArgumentException("selectionArgs must be provided for the Uri: " + uri);
+ }
+ return getSuggestions(selectionArgs[0]);
+ case SEARCH_WORDS:
+ if (selectionArgs == null) {
+ throw new IllegalArgumentException("selectionArgs must be provided for the Uri: " + uri);
+ }
+ return search(selectionArgs[0]);
+ case GET_WORD:
+ return getWord(uri);
+ case REFRESH_SHORTCUT:
+ return refreshShortcut(uri);
+ default:
+ throw new IllegalArgumentException("Unknown Uri: " + uri);
+ }
+ }
+
+ private Cursor getSuggestions(String query) {
+ query = query.toLowerCase();
+ String[] columns = new String[] { BaseColumns._ID, DictionaryDatabase.KEY_WORD,
+ DictionaryDatabase.KEY_DEFINITION,
+ /*
+ * SearchManager.SUGGEST_COLUMN_SHORTCUT_ID, (only if you want
+ * to refresh shortcuts)
+ */
+ SearchManager.SUGGEST_COLUMN_INTENT_DATA_ID };
+
+ return mDictionary.getWordMatches(query, columns);
+ }
+
+ private Cursor search(String query) {
+ query = query.toLowerCase();
+ String[] columns = new String[] { BaseColumns._ID, DictionaryDatabase.KEY_WORD,
+ DictionaryDatabase.KEY_DEFINITION };
+
+ return mDictionary.getWordMatches(query, columns);
+ }
+
+ private Cursor getWord(Uri uri) {
+ String rowId = uri.getLastPathSegment();
+ String[] columns = new String[] { DictionaryDatabase.KEY_WORD, DictionaryDatabase.KEY_DEFINITION };
+
+ return mDictionary.getWord(rowId, columns);
+ }
+
+ private Cursor refreshShortcut(Uri uri) {
+ /*
+ * This won't be called with the current implementation, but if we
+ * include {@link SearchManager#SUGGEST_COLUMN_SHORTCUT_ID} as a column
+ * in our suggestions table, we could expect to receive refresh queries
+ * when a shortcutted suggestion is displayed in Quick Search Box. In
+ * which case, this method will query the table for the specific word,
+ * using the given item Uri and provide all the columns originally
+ * provided with the suggestion query.
+ */
+ String rowId = uri.getLastPathSegment();
+ String[] columns = new String[] { BaseColumns._ID, DictionaryDatabase.KEY_WORD,
+ DictionaryDatabase.KEY_DEFINITION, SearchManager.SUGGEST_COLUMN_SHORTCUT_ID,
+ SearchManager.SUGGEST_COLUMN_INTENT_DATA_ID };
+
+ return mDictionary.getWord(rowId, columns);
+ }
+
+ /**
+ * This method is required in order to query the supported types. It's also
+ * useful in our own query() method to determine the type of Uri received.
+ */
+ @Override
+ public String getType(Uri uri) {
+ switch (sURIMatcher.match(uri)) {
+ case SEARCH_WORDS:
+ return WORDS_MIME_TYPE;
+ case GET_WORD:
+ return DEFINITION_MIME_TYPE;
+ case SEARCH_SUGGEST:
+ return SearchManager.SUGGEST_MIME_TYPE;
+ case REFRESH_SHORTCUT:
+ return SearchManager.SHORTCUT_MIME_TYPE;
+ default:
+ throw new IllegalArgumentException("Unknown URL " + uri);
+ }
+ }
+
+ // Other required implementations...
+
+ @Override
+ public Uri insert(Uri uri, ContentValues values) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public int delete(Uri uri, String selection, String[] selectionArgs) {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public int update(Uri uri, ContentValues values, String selection, String[] selectionArgs) {
+ throw new UnsupportedOperationException();
+ }
+
+}