diff options
-rw-r--r-- | AndroidManifest.xml | 8 | ||||
-rw-r--r-- | gen/net/cbaines/suma/R.java | 224 | ||||
-rw-r--r-- | res/layout/search_activity.xml (renamed from res/layout/find_activity.xml) | 6 | ||||
-rw-r--r-- | res/values/strings.xml | 3 | ||||
-rw-r--r-- | res/xml/searchable.xml | 5 | ||||
-rw-r--r-- | src/net/cbaines/suma/MapActivity.java | 134 | ||||
-rw-r--r-- | src/net/cbaines/suma/MapContentProvider.java | 120 | ||||
-rw-r--r-- | src/net/cbaines/suma/POIArrayAdapter.java | 2 | ||||
-rw-r--r-- | src/net/cbaines/suma/SearchResultsActivity.java | 12 |
9 files changed, 337 insertions, 177 deletions
diff --git a/AndroidManifest.xml b/AndroidManifest.xml index 3d47148..04e0d73 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -60,6 +60,8 @@ </activity> <activity android:name=".SearchResultsActivity" > </activity> + <activity android:name=".SearchResultsActivity" > + </activity> <activity android:name="BusStopActivity" > <intent-filter android:label="@string/app_name" > <action android:name="android.intent.action.VIEW" /> @@ -166,7 +168,11 @@ <!-- Provides search suggestions for words and their definitions. --> <provider android:name=".MapContentProvider" - android:authorities="net.cbaines.suma.provider" /> + android:authorities="net.cbaines.suma.provider" > + <path-permission + android:pathPrefix="/search_suggest_query" + android:readPermission="android.permission.GLOBAL_SEARCH" /> + </provider> </application> </manifest>
\ No newline at end of file diff --git a/gen/net/cbaines/suma/R.java b/gen/net/cbaines/suma/R.java index 7f232e9..1572f39 100644 --- a/gen/net/cbaines/suma/R.java +++ b/gen/net/cbaines/suma/R.java @@ -83,8 +83,8 @@ public final class R { public static final int busStopTimes=0x7f0a0023; public static final int busTimeContentLayout=0x7f0a0022; public static final int centerLoadBar=0x7f0a0024; - public static final int check1=0x7f0a003a; - public static final int childname=0x7f0a0039; + public static final int check1=0x7f0a0039; + public static final int childname=0x7f0a0038; public static final int donateBitcoinAddress=0x7f0a002e; public static final int donateButton=0x7f0a0003; public static final int donateDialogErrorMessage=0x7f0a002d; @@ -92,42 +92,41 @@ public final class R { public static final int donateDialogMessageLayout=0x7f0a002c; public static final int donateDialogProgress=0x7f0a002b; public static final int favouriteCheckBox=0x7f0a0020; - public static final int favouriteDialogMessage=0x7f0a0034; - public static final int favouriteListItems=0x7f0a0035; - public static final int findContentLayout=0x7f0a0030; - public static final int findListItems=0x7f0a0032; - public static final int findLoadBar=0x7f0a0031; + public static final int favouriteDialogMessage=0x7f0a0030; + public static final int favouriteListItems=0x7f0a0031; + public static final int findContentLayout=0x7f0a0032; + public static final int findListItems=0x7f0a0034; + public static final int findLoadBar=0x7f0a0033; public static final int helpExpandableListView=0x7f0a0002; public static final int layout_root=0x7f0a0027; public static final int linearLayout1=0x7f0a001a; public static final int linearLayout2=0x7f0a0029; - public static final int mapview=0x7f0a0033; - public static final int menu_about=0x7f0a0048; - public static final int menu_favourites=0x7f0a0049; - public static final int menu_find=0x7f0a0044; - public static final int menu_find_my_location=0x7f0a0046; - public static final int menu_next_stop=0x7f0a0043; - public static final int menu_preferences=0x7f0a0045; - public static final int menu_previous_stop=0x7f0a0041; - public static final int menu_refresh_bus=0x7f0a0040; - public static final int menu_refresh_stop=0x7f0a0042; - public static final int menu_view=0x7f0a0047; + public static final int mapview=0x7f0a002f; + public static final int menu_about=0x7f0a0047; + public static final int menu_favourites=0x7f0a0048; + public static final int menu_find=0x7f0a0043; + public static final int menu_find_my_location=0x7f0a0045; + public static final int menu_next_stop=0x7f0a0042; + public static final int menu_preferences=0x7f0a0044; + public static final int menu_previous_stop=0x7f0a0040; + public static final int menu_refresh_bus=0x7f0a003f; + public static final int menu_refresh_stop=0x7f0a0041; + public static final int menu_view=0x7f0a0046; public static final int radio_u1=0x7f0a001b; public static final int radio_u1n=0x7f0a001c; public static final int radio_u2=0x7f0a001d; public static final int radio_u6=0x7f0a001e; public static final int radio_u9=0x7f0a001f; - public static final int searchBar=0x7f0a002f; public static final int textView1=0x7f0a0000; public static final int textView2=0x7f0a0001; - public static final int textView3=0x7f0a003d; - public static final int textView4=0x7f0a003e; - public static final int toastViewLinearLayout=0x7f0a0036; - public static final int toastViewSubMessage=0x7f0a0038; - public static final int toastViewText=0x7f0a0037; - public static final int view_list=0x7f0a003b; - public static final int welcomeDialogButton=0x7f0a003c; - public static final int welcomeDialogMessage=0x7f0a003f; + public static final int textView3=0x7f0a003c; + public static final int textView4=0x7f0a003d; + public static final int toastViewLinearLayout=0x7f0a0035; + public static final int toastViewSubMessage=0x7f0a0037; + public static final int toastViewText=0x7f0a0036; + public static final int view_list=0x7f0a003a; + public static final int welcomeDialogButton=0x7f0a003b; + public static final int welcomeDialogMessage=0x7f0a003e; } public static final class layout { public static final int about_dialog=0x7f030000; @@ -138,9 +137,9 @@ public final class R { public static final int bus_stop_activity=0x7f030005; public static final int bus_stop_dialog=0x7f030006; public static final int donate_dialog=0x7f030007; - public static final int find_activity=0x7f030008; - public static final int map_activity=0x7f030009; - public static final int poi_dialog=0x7f03000a; + public static final int map_activity=0x7f030008; + public static final int poi_dialog=0x7f030009; + public static final int search_activity=0x7f03000a; public static final int toast_view=0x7f03000b; public static final int view_child_row=0x7f03000c; public static final int view_dialog=0x7f03000d; @@ -171,114 +170,115 @@ public final class R { public static final int U9=0x7f070005; /** About Strings */ - public static final int about=0x7f07003a; - public static final int about_android_market=0x7f070047; - public static final int about_android_market_summary=0x7f070048; - public static final int about_copyright=0x7f07003d; - public static final int about_copyright_summary=0x7f07003e; - public static final int about_data=0x7f070045; - public static final int about_data_summary=0x7f070046; - public static final int about_database=0x7f070051; - public static final int about_database_summary=0x7f070052; - public static final int about_developer=0x7f070043; - public static final int about_developer_summary=0x7f070044; - public static final int about_donate=0x7f070053; - public static final int about_donate_summary=0x7f070054; - public static final int about_help_message=0x7f070018; - public static final int about_license=0x7f07003f; - public static final int about_license_summary=0x7f070040; - public static final int about_map_data=0x7f070049; - public static final int about_map_data_summary=0x7f07004a; - public static final int about_map_icons=0x7f07004b; - public static final int about_map_icons_summary=0x7f07004c; - public static final int about_map_tiles=0x7f07004f; - public static final int about_map_tiles_summary=0x7f070050; + public static final int about=0x7f07003b; + public static final int about_android_market=0x7f070048; + public static final int about_android_market_summary=0x7f070049; + public static final int about_copyright=0x7f07003e; + public static final int about_copyright_summary=0x7f07003f; + public static final int about_data=0x7f070046; + public static final int about_data_summary=0x7f070047; + public static final int about_database=0x7f070052; + public static final int about_database_summary=0x7f070053; + public static final int about_developer=0x7f070044; + public static final int about_developer_summary=0x7f070045; + public static final int about_donate=0x7f070054; + public static final int about_donate_summary=0x7f070055; + public static final int about_help_message=0x7f070019; + public static final int about_license=0x7f070040; + public static final int about_license_summary=0x7f070041; + public static final int about_map_data=0x7f07004a; + public static final int about_map_data_summary=0x7f07004b; + public static final int about_map_icons=0x7f07004c; + public static final int about_map_icons_summary=0x7f07004d; + public static final int about_map_tiles=0x7f070050; + public static final int about_map_tiles_summary=0x7f070051; /** About Messages */ - public static final int about_menu_instruction_text=0x7f070032; - public static final int about_osm_map=0x7f07004d; - public static final int about_osm_map_summary=0x7f07004e; - public static final int about_project=0x7f070041; - public static final int about_project_summary=0x7f070042; - public static final int about_version=0x7f07003b; - public static final int about_version_summary=0x7f07003c; + public static final int about_menu_instruction_text=0x7f070033; + public static final int about_osm_map=0x7f07004e; + public static final int about_osm_map_summary=0x7f07004f; + public static final int about_project=0x7f070042; + public static final int about_project_summary=0x7f070043; + public static final int about_version=0x7f07003c; + public static final int about_version_summary=0x7f07003d; public static final int app_name=0x7f070000; - public static final int bitcoin_error_message=0x7f07001c; - public static final int buildingImageDescription=0x7f070055; + public static final int bitcoin_error_message=0x7f07001d; + public static final int buildingImageDescription=0x7f070056; /** Bus Activity */ - public static final int bus_activity_destination_label=0x7f07005b; - public static final int bus_activity_no_destination_message=0x7f07005c; + public static final int bus_activity_destination_label=0x7f07005c; + public static final int bus_activity_no_destination_message=0x7f07005d; /** Bus Stop Specific Stop View Strings */ - public static final int bus_stop_stop_view_on_click_toast_help_message=0x7f070057; - public static final int bus_stop_stop_view_on_click_toast_unidentified_message=0x7f070058; + public static final int bus_stop_stop_view_on_click_toast_help_message=0x7f070058; + public static final int bus_stop_stop_view_on_click_toast_unidentified_message=0x7f070059; /** Bus Specific Stop View Strings */ - public static final int bus_stop_view_on_click_toast_help_message=0x7f070059; - public static final int bus_stop_view_on_click_toast_unidentified_message=0x7f07005a; - 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 bus_stop_view_on_click_toast_help_message=0x7f07005a; + public static final int bus_stop_view_on_click_toast_unidentified_message=0x7f07005b; + public static final int bustimes_favourite_checkbox_label=0x7f070034; + public static final int credits_help_message=0x7f07001b; + public static final int donate_button=0x7f07001c; + public static final int donate_dialog_error_title=0x7f070036; + public static final int donate_dialog_message=0x7f070035; + public static final int favourites_dialog_message=0x7f07001f; /** Favourites Dialog */ - public static final int favourites_dialog_title=0x7f07005d; - public static final int favourites_help_message=0x7f070019; - public static final int find_help_message=0x7f070014; - public static final int findmylocation_help_message=0x7f070016; - public static final int map_activity_search_hint=0x7f07000d; - public static final int map_activity_toast_help_message=0x7f070056; + public static final int favourites_dialog_title=0x7f07005e; + public static final int favourites_help_message=0x7f07001a; + public static final int find_help_message=0x7f070015; + public static final int findmylocation_help_message=0x7f070017; + public static final int map_activity_toast_help_message=0x7f070057; /** Help Messages */ - public static final int map_help_message=0x7f070013; + public static final int map_help_message=0x7f070014; public static final int menu_about=0x7f07000b; public static final int menu_favourites=0x7f07000c; /** Map Activity */ public static final int menu_find=0x7f070006; public static final int menu_find_my_location=0x7f070009; - public static final int menu_next_stop=0x7f070037; + public static final int menu_next_stop=0x7f070038; public static final int menu_preferences=0x7f070007; - public static final int menu_previous_stop=0x7f070036; - public static final int menu_refresh_stop=0x7f070038; - public static final int menu_refresh_stops=0x7f070039; + public static final int menu_previous_stop=0x7f070037; + public static final int menu_refresh_stop=0x7f070039; + public static final int menu_refresh_stops=0x7f07003a; public static final int menu_view=0x7f070008; public static final int pref_bus_stop=0x7f07000a; - public static final int preferences=0x7f07001d; + public static final int preferences=0x7f07001e; /** Preferences Messages */ - 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=0x7f070015; - 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=0x7f070017; - public static final int welcome_dialog_button_text=0x7f07005e; - public static final int welcome_dialog_copyright=0x7f070010; - public static final int welcome_dialog_install_message=0x7f070012; + public static final int preferences_catagory_appearance=0x7f070020; + public static final int preferences_catagory_data=0x7f07002f; + public static final int preferences_catagory_live_bus_times=0x7f070028; + public static final int preferences_catagory_positioning=0x7f070024; + public static final int preferences_gps=0x7f070025; + public static final int preferences_gps_disabled=0x7f070027; + public static final int preferences_gps_enabled=0x7f070026; + public static final int preferences_help_message=0x7f070016; + public static final int preferences_non_uni_link=0x7f070030; + public static final int preferences_non_uni_link_disabled=0x7f070032; + public static final int preferences_non_uni_link_enabled=0x7f070031; + public static final int preferences_non_uni_link_live_bus_times=0x7f07002c; + public static final int preferences_non_uni_link_live_bus_times_disabled=0x7f07002e; + public static final int preferences_non_uni_link_live_bus_times_enabled=0x7f07002d; + public static final int preferences_show_identifiers=0x7f070021; + public static final int preferences_show_identifiers_disabled=0x7f070023; + public static final int preferences_show_identifiers_enabled=0x7f070022; + public static final int preferences_uni_link_live_bus_times=0x7f070029; + public static final int preferences_uni_link_live_bus_times_disabled=0x7f07002b; + public static final int preferences_uni_link_live_bus_times_enabled=0x7f07002a; + public static final int search_results_dialog_title=0x7f07000e; + public static final int search_settings_description=0x7f07000d; + public static final int view_help_message=0x7f070018; + public static final int welcome_dialog_button_text=0x7f07005f; + public static final int welcome_dialog_copyright=0x7f070011; + public static final int welcome_dialog_install_message=0x7f070013; /** Welcome Dialog */ - public static final int welcome_dialog_title=0x7f07000e; - public static final int welcome_dialog_upgrade_message=0x7f070011; - public static final int welcome_dialog_version=0x7f07000f; + public static final int welcome_dialog_title=0x7f07000f; + public static final int welcome_dialog_upgrade_message=0x7f070012; + public static final int welcome_dialog_version=0x7f070010; } public static final class xml { public static final int about=0x7f050000; diff --git a/res/layout/find_activity.xml b/res/layout/search_activity.xml index 6b19c67..6e6bcd3 100644 --- a/res/layout/find_activity.xml +++ b/res/layout/search_activity.xml @@ -6,12 +6,6 @@ android:orientation="vertical" android:theme="@android:style/Theme.NoTitleBar" > - <EditText - android:id="@+id/searchBar" - android:layout_width="fill_parent" - android:layout_height="wrap_content" - android:inputType="textNoSuggestions" /> - <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/findContentLayout" diff --git a/res/values/strings.xml b/res/values/strings.xml index 1009d3f..7a62ceb 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -18,7 +18,8 @@ <string name="pref_bus_stop">Bus Stops</string> <string name="menu_about">About</string> <string name="menu_favourites">Favourites</string> - <string name="map_activity_search_hint">Search for buildings, and bus stops</string> + <string name="search_settings_description">Southampton University Map</string> + <string name="search_results_dialog_title">Search Results</string> <!-- Welcome Dialog --> <string name="welcome_dialog_title">Southampton University Map App</string> diff --git a/res/xml/searchable.xml b/res/xml/searchable.xml index 7262b3d..d6dedc8 100644 --- a/res/xml/searchable.xml +++ b/res/xml/searchable.xml @@ -1,12 +1,11 @@ <?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:hint="@string/search_settings_description" android:includeInGlobalSearch="true" android:label="@string/app_name" - android:searchSettingsDescription="@string/map_activity_search_hint" + android:searchSettingsDescription="@string/search_settings_description" android:searchSuggestAuthority="net.cbaines.suma.provider" android:searchSuggestIntentAction="android.intent.action.VIEW" - android:searchSuggestIntentData="content://net.cbaines.suma.provider/building" android:searchSuggestSelection=" ?" android:searchSuggestThreshold="1" > diff --git a/src/net/cbaines/suma/MapActivity.java b/src/net/cbaines/suma/MapActivity.java index 12fdeeb..2bdc3d7 100644 --- a/src/net/cbaines/suma/MapActivity.java +++ b/src/net/cbaines/suma/MapActivity.java @@ -64,6 +64,8 @@ import android.widget.AdapterView.OnItemClickListener; import android.widget.AdapterView.OnItemLongClickListener; import com.j256.ormlite.dao.Dao; +import com.j256.ormlite.stmt.PreparedQuery; +import com.j256.ormlite.stmt.QueryBuilder; /** * @@ -88,6 +90,9 @@ public class MapActivity extends ToastHelperActivity implements MapViewConstants static final int VIEW_DIALOG_ID = 0; static final int FAVOURITE_DIALOG_ID = 1; static final int WELCOME_DIALOG_ID = 2; + static final int SEARCH_RESULTS_DIALOG_ID = 3; + + private ArrayList<POI> searchResults = null; private POIDialog favDialog; @@ -176,6 +181,8 @@ public class MapActivity extends ToastHelperActivity implements MapViewConstants private MapActivity instance; + private POIDialog searchResultsDialog; + private static final String TAG = "MapActivity"; @SuppressWarnings("unchecked") @@ -261,55 +268,97 @@ public class MapActivity extends ToastHelperActivity implements MapViewConstants mapController = mapView.getController(); mResourceProxy = new DefaultResourceProxyImpl(getApplicationContext()); - GeoPoint userLocation = null; + GeoPoint startLocation = null; Intent intent = getIntent(); Bundle extras = intent.getExtras(); + if (Intent.ACTION_SEARCH.equals(intent.getAction())) { String query = intent.getStringExtra(SearchManager.QUERY); - Log.i(TAG, "Searching for " + query); - - } else if (getIntent().getDataString() != null) { - Log.i(TAG, "getIntent().getDataString() " + getIntent().getDataString()); + searchResults = new ArrayList<POI>(); + + try { + Dao<Building, String> buildingDao = getHelper().getBuildingDao(); + + QueryBuilder<Building, String> buildingQueryBuilder = buildingDao.queryBuilder(); + buildingQueryBuilder.where().like(Building.ID_FIELD_NAME, "%" + query + "%").or() + .like(Building.NAME_FIELD_NAME, "%" + query + "%"); + PreparedQuery<Building> buildingPreparedQuery = buildingQueryBuilder.prepare(); + List<Building> buildings = buildingDao.query(buildingPreparedQuery); + searchResults.addAll(buildings); + buildings = null; + + Dao<BusStop, String> busStopDao = getHelper().getBusStopDao(); + + QueryBuilder<BusStop, String> busStopQueryBuilder = busStopDao.queryBuilder(); + busStopQueryBuilder.where().like(BusStop.ID_FIELD_NAME, "%" + query + "%").or() + .like(BusStop.DESCRIPTION_FIELD_NAME, "%" + query + "%"); + PreparedQuery<BusStop> busStopPreparedQuery = busStopQueryBuilder.prepare(); + List<BusStop> busStops = busStopDao.query(busStopPreparedQuery); + searchResults.addAll(busStops); + busStops = null; + + startLocation = new GeoPoint(50935551, -1393488); + mapController.setZoom(15); + + showDialog(SEARCH_RESULTS_DIALOG_ID); + + } catch (SQLException e) { + e.printStackTrace(); + } + + } else if (intent.getDataString() != null) { + String dataString = getIntent().getDataString(); - String str = getIntent().getDataString().substring(4, getIntent().getDataString().length()); - String[] strParts = str.split(","); + Log.i(TAG, "getIntent().getDataString() " + dataString); - int lat = Util.doubleToIntE6(Double.valueOf(strParts[0])); - int lng; + if (dataString.startsWith("content")) { - 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)); + Uri data = intent.getData(); - mapController.setZoom(Integer.valueOf(zoom)); + Log.i("Data: ", data.toString()); + + startLocation = new GeoPoint(50935551, -1393488); } else { - lng = Util.doubleToIntE6(Double.valueOf(strParts[1])); - mapController.setZoom(15); - } - userLocation = new GeoPoint(lat, lng); + 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); + } + + startLocation = new GeoPoint(lat, lng); + } } else if (extras != null && extras.containsKey("poiPoint")) { String poiPoint = getIntent().getExtras().getString("poiPoint"); Log.i(TAG, "poiPoint " + poiPoint); String[] bits = poiPoint.split(","); - userLocation = new GeoPoint(Double.valueOf(bits[0]), Double.valueOf(bits[1])); + startLocation = new GeoPoint(Double.valueOf(bits[0]), Double.valueOf(bits[1])); mapController.setZoom(20); } else { - userLocation = myLocationOverlay.getMyLocation(); - if (userLocation == null) { - userLocation = new GeoPoint(50935551, -1393488); // ECS + startLocation = myLocationOverlay.getMyLocation(); + if (startLocation == null) { + startLocation = new GeoPoint(50935551, -1393488); // ECS } mapController.setZoom(15); } - mapController.setCenter(userLocation); + mapController.setCenter(startLocation); final SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(this); String appVersion = sharedPrefs.getString(APP_VERSION, APP_NOT_INSTALLED); @@ -991,6 +1040,13 @@ public class MapActivity extends ToastHelperActivity implements MapViewConstants favDialog.setOnItemLongClickListener(this); favDialog.setTitle(R.string.favourites_dialog_title); return favDialog; + case SEARCH_RESULTS_DIALOG_ID: + searchResultsDialog = new POIDialog(instance); + searchResultsDialog.setOnItemClickListener(this); + searchResultsDialog.setOnItemLongClickListener(this); + searchResultsDialog.setTitle(R.string.search_results_dialog_title); + searchResultsDialog.setItems(searchResults); + return searchResultsDialog; case WELCOME_DIALOG_ID: WelcomeDialog welcomeDialog = new WelcomeDialog(instance); return welcomeDialog; @@ -1001,7 +1057,12 @@ public class MapActivity extends ToastHelperActivity implements MapViewConstants public void onItemClick(AdapterView<?> parent, View view, int position, long id) { Log.i(TAG, "OnItemClick pos " + position + " id " + id); - String poiId = favDialog.adapter.getItemStringId(position); + String poiId = null; + if (favDialog != null) { + poiId = favDialog.adapter.getItemStringId(position); + } else if (searchResultsDialog != null) { + poiId = searchResultsDialog.adapter.getItemStringId(position); + } Log.i(TAG, "POI " + poiId + " selected"); @@ -1027,7 +1088,13 @@ public class MapActivity extends ToastHelperActivity implements MapViewConstants mapController.setZoom(20); mapController.setCenter(poi.point); - favDialog.dismiss(); + if (favDialog != null) { + favDialog.dismiss(); + favDialog = null; + } else if (searchResultsDialog != null) { + searchResultsDialog.dismiss(); + searchResultsDialog = null; + } } } else { @@ -1046,7 +1113,12 @@ public class MapActivity extends ToastHelperActivity implements MapViewConstants Log.i(TAG, "OnItemClick pos " + position + " id " + id); - String poiId = favDialog.adapter.getItemStringId(position); + String poiId = null; + if (favDialog != null) { + poiId = favDialog.adapter.getItemStringId(position); + } else if (searchResultsDialog != null) { + poiId = searchResultsDialog.adapter.getItemStringId(position); + } Log.i(TAG, "POI " + poiId + " selected"); @@ -1100,8 +1172,14 @@ public class MapActivity extends ToastHelperActivity implements MapViewConstants mapController.setZoom(20); mapController.setCenter(poi.point); - favDialog.dismiss(); - favDialog = null; + if (favDialog != null) { + favDialog.dismiss(); + favDialog = null; + } else if (searchResultsDialog != null) { + searchResultsDialog.dismiss(); + searchResultsDialog = null; + } + } } } else { diff --git a/src/net/cbaines/suma/MapContentProvider.java b/src/net/cbaines/suma/MapContentProvider.java index a2b42c3..d920b21 100644 --- a/src/net/cbaines/suma/MapContentProvider.java +++ b/src/net/cbaines/suma/MapContentProvider.java @@ -48,6 +48,10 @@ public class MapContentProvider extends ContentProvider { // + "/building"); // MIME types used for searching words or looking up a single definition + public static final String ALLS_MIME_TYPE = ContentResolver.CURSOR_DIR_BASE_TYPE + + "/vnd.net.cbaines.suma.provider.all"; + public static final String ALL_MIME_TYPE = ContentResolver.CURSOR_ITEM_BASE_TYPE + + "/vnd.net.cbaines.suma.provider.all"; public static final String BUILDINGS_MIME_TYPE = ContentResolver.CURSOR_DIR_BASE_TYPE + "/vnd.net.cbaines.suma.provider.building"; public static final String BUILDING_MIME_TYPE = ContentResolver.CURSOR_ITEM_BASE_TYPE @@ -68,16 +72,18 @@ public class MapContentProvider extends ContentProvider { private DatabaseHelper helper; // UriMatcher stuff - private static final int SEARCH_BUILDINGS = 0; - private static final int GET_BUILDING = 1; - private static final int SEARCH_BUS_STOPS = 2; - private static final int GET_BUS_STOP = 3; - private static final int SEARCH_SITES = 4; - private static final int GET_SITE = 5; - private static final int SEARCH_BUSES = 6; - private static final int GET_BUS = 7; - private static final int SEARCH_SUGGEST = 8; - private static final int REFRESH_SHORTCUT = 9; + private static final int SEARCH_ALL = 0; + private static final int GET_ALL = 1; + private static final int SEARCH_BUILDINGS = 2; + private static final int GET_BUILDING = 3; + private static final int SEARCH_BUS_STOPS = 4; + private static final int GET_BUS_STOP = 5; + private static final int SEARCH_SITES = 6; + private static final int GET_SITE = 7; + private static final int SEARCH_BUSES = 8; + private static final int GET_BUS = 9; + private static final int SEARCH_SUGGEST = 10; + private static final int REFRESH_SHORTCUT = 11; private static final UriMatcher sURIMatcher = buildUriMatcher(); /** @@ -87,6 +93,8 @@ public class MapContentProvider extends ContentProvider { private static UriMatcher buildUriMatcher() { UriMatcher matcher = new UriMatcher(UriMatcher.NO_MATCH); // to get definitions... + matcher.addURI(AUTHORITY, "all", SEARCH_BUILDINGS); + matcher.addURI(AUTHORITY, "all/*", GET_BUILDING); matcher.addURI(AUTHORITY, "building", SEARCH_BUILDINGS); matcher.addURI(AUTHORITY, "building/*", GET_BUILDING); matcher.addURI(AUTHORITY, "bus-stop", SEARCH_BUS_STOPS); @@ -141,6 +149,21 @@ public class MapContentProvider extends ContentProvider { } catch (SQLException e1) { e1.printStackTrace(); } + case SEARCH_ALL: + if (selectionArgs == null) { + throw new IllegalArgumentException("selectionArgs must be provided for the Uri: " + uri); + } + try { + return searchAll(selectionArgs[0]); + } catch (SQLException e) { + e.printStackTrace(); + } + case GET_ALL: + try { + return getAll(uri); + } catch (SQLException e) { + e.printStackTrace(); + } case SEARCH_BUILDINGS: if (selectionArgs == null) { throw new IllegalArgumentException("selectionArgs must be provided for the Uri: " + uri); @@ -170,6 +193,13 @@ public class MapContentProvider extends ContentProvider { private Cursor getSuggestions(String query) throws SQLException { Log.v(TAG, "Got query for " + query); + String[] columnNames = { BaseColumns._ID, SearchManager.SUGGEST_COLUMN_ICON_1, + SearchManager.SUGGEST_COLUMN_TEXT_1, SearchManager.SUGGEST_COLUMN_TEXT_2, + SearchManager.SUGGEST_COLUMN_INTENT_DATA }; + + MatrixCursor cursor = new MatrixCursor(columnNames); + int id = 0; + Dao<Building, String> buildingDao = helper.getBuildingDao(); QueryBuilder<Building, String> qb = buildingDao.queryBuilder(); @@ -180,14 +210,37 @@ public class MapContentProvider extends ContentProvider { List<Building> buildings = buildingDao.query(preparedQuery); Log.v(TAG, "Returning " + buildings.size() + " buildings"); - String[] columnNames = { BaseColumns._ID, SearchManager.SUGGEST_COLUMN_TEXT_1 }; - - MatrixCursor cursor = new MatrixCursor(columnNames, buildings.size()); - - int id = 0; for (Building building : buildings) { - Log.v(TAG, "Building " + id + ", " + building.name); - Object[] values = { id++, building.name }; + // Log.v(TAG, "Building " + id + ", " + building.name); + Object[] values = { + id++, + R.drawable.building, + building.name, + building.id, + "geo:" + Util.E6IntToDouble(building.point.getLatitudeE6()) + "," + + Util.E6IntToDouble(building.point.getLongitudeE6()) + "?z=18" }; + cursor.addRow(values); + } + + Dao<BusStop, String> busStopDao = helper.getBusStopDao(); + + QueryBuilder<BusStop, String> busStopQB = busStopDao.queryBuilder(); + busStopQB.where().like(BusStop.ID_FIELD_NAME, "%" + query + "%").or() + .like(BusStop.DESCRIPTION_FIELD_NAME, "%" + query + "%"); + PreparedQuery<BusStop> busStopPreparedQuery = busStopQB.prepare(); + + List<BusStop> busStops = busStopDao.query(busStopPreparedQuery); + Log.v(TAG, "Returning " + busStops.size() + " busStops"); + + for (BusStop busStop : busStops) { + // Log.v(TAG, "Building " + id + ", " + building.name); + Object[] values = { + id++, + R.drawable.busstop, + busStop.description, + busStop.id, + "geo:" + Util.E6IntToDouble(busStop.point.getLatitudeE6()) + "," + + Util.E6IntToDouble(busStop.point.getLongitudeE6()) + "?z=18" }; cursor.addRow(values); } @@ -223,6 +276,35 @@ public class MapContentProvider extends ContentProvider { return cursor; } + private Cursor searchAll(String query) throws SQLException { + Dao<Building, String> buildingDao = helper.getBuildingDao(); + + QueryBuilder<Building, String> qb = buildingDao.queryBuilder(); + qb.where().eq(Building.ID_FIELD_NAME, "%" + query + "%").or().eq(Building.NAME_FIELD_NAME, "%" + query + "%"); + PreparedQuery<Building> preparedQuery = qb.prepare(); + + AndroidCompiledStatement compiledStatement = (AndroidCompiledStatement) preparedQuery.compile(helper + .getConnectionSource().getReadOnlyConnection(), StatementType.SELECT); + Cursor cursor = compiledStatement.getCursor(); + + return cursor; + } + + private Cursor getAll(Uri uri) throws SQLException { + String buildingID = uri.getLastPathSegment(); + Dao<Building, String> buildingDao = helper.getBuildingDao(); + + QueryBuilder<Building, String> qb = buildingDao.queryBuilder(); + qb.where().eq(Building.ID_FIELD_NAME, buildingID); + PreparedQuery<Building> preparedQuery = qb.prepare(); + + AndroidCompiledStatement compiledStatement = (AndroidCompiledStatement) preparedQuery.compile(helper + .getConnectionSource().getReadOnlyConnection(), StatementType.SELECT); + Cursor cursor = compiledStatement.getCursor(); + + return cursor; + } + private Cursor refreshShortcut(Uri uri) throws SQLException { /* * This won't be called with the current implementation, but if we @@ -254,6 +336,10 @@ public class MapContentProvider extends ContentProvider { @Override public String getType(Uri uri) { switch (sURIMatcher.match(uri)) { + case SEARCH_ALL: + return ALLS_MIME_TYPE; + case GET_ALL: + return ALL_MIME_TYPE; case SEARCH_BUILDINGS: return BUILDINGS_MIME_TYPE; case GET_BUILDING: diff --git a/src/net/cbaines/suma/POIArrayAdapter.java b/src/net/cbaines/suma/POIArrayAdapter.java index f9b5271..028f659 100644 --- a/src/net/cbaines/suma/POIArrayAdapter.java +++ b/src/net/cbaines/suma/POIArrayAdapter.java @@ -22,6 +22,7 @@ package net.cbaines.suma; import java.util.List; import android.content.Context; +import android.util.Log; import android.view.View; import android.view.ViewGroup; import android.widget.BaseAdapter; @@ -74,6 +75,7 @@ public class POIArrayAdapter extends BaseAdapter { } public String getItemStringId(int position) { + Log.v("POIArrayAdapter", POIs.get(position).toString()); return ((POI) POIs.get(position)).id; } }
\ No newline at end of file diff --git a/src/net/cbaines/suma/SearchResultsActivity.java b/src/net/cbaines/suma/SearchResultsActivity.java index a7b5a55..503c876 100644 --- a/src/net/cbaines/suma/SearchResultsActivity.java +++ b/src/net/cbaines/suma/SearchResultsActivity.java @@ -43,7 +43,6 @@ import android.view.View; import android.widget.AdapterView; import android.widget.AdapterView.OnItemClickListener; import android.widget.AdapterView.OnItemLongClickListener; -import android.widget.EditText; import android.widget.LinearLayout; import android.widget.ListView; import android.widget.ProgressBar; @@ -61,7 +60,6 @@ public class SearchResultsActivity extends OrmLiteBaseActivity<DatabaseHelper> i public static final String ORIGIN = "o"; public static final int MAP_ACTIVITY = 0; - private EditText searchBar; private ListView listItems; private ProgressBar progBar; private LinearLayout findContentLayout; @@ -245,18 +243,14 @@ public class SearchResultsActivity extends OrmLiteBaseActivity<DatabaseHelper> i /** Called when the activity is first created. */ public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); - setContentView(R.layout.find_activity); + setContentView(R.layout.search_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); + searchTerm = intent.getStringExtra(SearchManager.QUERY); + Log.i(TAG, "Searching for " + searchTerm); } listItems = (ListView) findViewById(R.id.findListItems); |