diff options
author | Christopher Baines <cbaines8@gmail.com> | 2012-03-09 12:35:17 +0000 |
---|---|---|
committer | Christopher Baines <cbaines8@gmail.com> | 2012-03-09 12:35:17 +0000 |
commit | 606d952ef33ee74dbb303a8870451252d7785f32 (patch) | |
tree | 1bf140512141ce8618105068b5152b231e9351d1 /src/net | |
parent | c2b3891c783dee1b4ef6fd70432aa7ef5e55c0d7 (diff) | |
download | southamptonuniversitymap-606d952ef33ee74dbb303a8870451252d7785f32.tar southamptonuniversitymap-606d952ef33ee74dbb303a8870451252d7785f32.tar.gz |
More search improvements.
Diffstat (limited to 'src/net')
-rw-r--r-- | src/net/cbaines/suma/MapActivity.java | 67 | ||||
-rw-r--r-- | src/net/cbaines/suma/MapContentProvider.java | 120 | ||||
-rw-r--r-- | src/net/cbaines/suma/SearchActivity.java | 12 |
3 files changed, 151 insertions, 48 deletions
diff --git a/src/net/cbaines/suma/MapActivity.java b/src/net/cbaines/suma/MapActivity.java index 8ed8e9e..3b8efe5 100644 --- a/src/net/cbaines/suma/MapActivity.java +++ b/src/net/cbaines/suma/MapActivity.java @@ -42,6 +42,7 @@ import org.osmdroid.views.util.constants.MapViewConstants; import android.app.AlertDialog; import android.app.Dialog; +import android.app.SearchManager; import android.content.DialogInterface; import android.content.Intent; import android.content.SharedPreferences; @@ -186,6 +187,19 @@ public class MapActivity extends ToastHelperActivity implements MapViewConstants instance = this; + Intent intent = getIntent(); + Bundle extras = intent.getExtras(); + + if (Intent.ACTION_SEARCH.equals(intent.getAction())) { + String query = intent.getStringExtra(SearchManager.QUERY); + + Intent searchIntent = new Intent(instance, SearchActivity.class); + searchIntent.setAction(Intent.ACTION_SEARCH); + searchIntent.putExtra(SearchManager.QUERY, query); + startActivity(searchIntent); + + } + Log.i(TAG, "Begining loading database " + (System.currentTimeMillis() - startTime)); DatabaseHelper helper = getHelper(); @@ -263,50 +277,59 @@ public class MapActivity extends ToastHelperActivity implements MapViewConstants mapController = mapView.getController(); mResourceProxy = new DefaultResourceProxyImpl(getApplicationContext()); - GeoPoint userLocation = null; + GeoPoint startLocation = null; - Bundle extras = getIntent().getExtras(); if (getIntent().getDataString() != null) { + String dataString = getIntent().getDataString(); - Log.i(TAG, "getIntent().getDataString() " + getIntent().getDataString()); + Log.i(TAG, "getIntent().getDataString() " + dataString); - String str = getIntent().getDataString().substring(4, getIntent().getDataString().length()); - String[] strParts = str.split(","); + if (dataString.startsWith("content")) { - int lat = Util.doubleToIntE6(Double.valueOf(strParts[0])); - int lng; + Uri data = intent.getData(); - 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)); + Log.i("Data: ", data.toString()); - mapController.setZoom(Integer.valueOf(zoom)); + 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); @@ -857,7 +880,7 @@ public class MapActivity extends ToastHelperActivity implements MapViewConstants // Handle item selection switch (item.getItemId()) { case R.id.menu_find: - onSearchRequested(); + onSearchRequested(); return true; case R.id.menu_preferences: Intent settingsActivity = new Intent(getBaseContext(), PreferencesActivity.class); 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/SearchActivity.java b/src/net/cbaines/suma/SearchActivity.java index f7f5e55..850996a 100644 --- a/src/net/cbaines/suma/SearchActivity.java +++ b/src/net/cbaines/suma/SearchActivity.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 SearchActivity extends OrmLiteBaseActivity<DatabaseHelper> implemen 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 SearchActivity extends OrmLiteBaseActivity<DatabaseHelper> implemen /** 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); |