From 19e189ef9ed67f382fea00e48f997ce8e979f030 Mon Sep 17 00:00:00 2001 From: Christopher Baines Date: Wed, 14 Mar 2012 01:00:56 +0000 Subject: Update for beta release. --- src/net/cbaines/suma/Building.java | 2 +- src/net/cbaines/suma/BusStop.java | 2 +- src/net/cbaines/suma/DataManager.java | 5 +- src/net/cbaines/suma/FavouritesDialog.java | 11 + src/net/cbaines/suma/MapActivity.java | 249 ++++++++++----------- src/net/cbaines/suma/MapContentProvider.java | 141 ++++++------ src/net/cbaines/suma/Preferences.java | 6 +- src/net/cbaines/suma/SearchResultsDialog.java | 10 + src/net/cbaines/suma/StringDistanceComparator.java | 134 ----------- .../cbaines/suma/StringPOIDistanceComparator.java | 134 +++++++++++ src/net/cbaines/suma/WelcomeDialog.java | 2 +- 11 files changed, 362 insertions(+), 334 deletions(-) create mode 100644 src/net/cbaines/suma/FavouritesDialog.java create mode 100644 src/net/cbaines/suma/SearchResultsDialog.java delete mode 100644 src/net/cbaines/suma/StringDistanceComparator.java create mode 100644 src/net/cbaines/suma/StringPOIDistanceComparator.java (limited to 'src') diff --git a/src/net/cbaines/suma/Building.java b/src/net/cbaines/suma/Building.java index 84c9b6c..38c8265 100644 --- a/src/net/cbaines/suma/Building.java +++ b/src/net/cbaines/suma/Building.java @@ -59,6 +59,6 @@ public class Building extends POI { } public String toString() { - return name + " (" + id + ")"; + return name; } } diff --git a/src/net/cbaines/suma/BusStop.java b/src/net/cbaines/suma/BusStop.java index 85f6d01..3bfd9a4 100644 --- a/src/net/cbaines/suma/BusStop.java +++ b/src/net/cbaines/suma/BusStop.java @@ -71,6 +71,6 @@ public class BusStop extends POI { } public String toString() { - return description + " (" + id + ")"; + return description; } } diff --git a/src/net/cbaines/suma/DataManager.java b/src/net/cbaines/suma/DataManager.java index ca27672..8b04928 100644 --- a/src/net/cbaines/suma/DataManager.java +++ b/src/net/cbaines/suma/DataManager.java @@ -457,9 +457,10 @@ public class DataManager { GeoPoint point = null; if (dataBits[2].length() > 1 && dataBits[3].length() > 1) { - point = Util.csLatLongToGeoPoint(dataBits[2], dataBits[3]); + point = Util.csLatLongToGeoPoint(dataBits[3], dataBits[2]); } else { - point = new GeoPoint(0, 0); + Log.e(TAG, "Missing point for site " + dataBits[1]); + throw new RuntimeException(); } Polygon poly = Util.csPolygonToPolygon(strLine.split("\"")[1]); diff --git a/src/net/cbaines/suma/FavouritesDialog.java b/src/net/cbaines/suma/FavouritesDialog.java new file mode 100644 index 0000000..0884b63 --- /dev/null +++ b/src/net/cbaines/suma/FavouritesDialog.java @@ -0,0 +1,11 @@ +package net.cbaines.suma; + +import android.content.Context; + +public class FavouritesDialog extends POIDialog implements Preferences { + + public FavouritesDialog(Context context) { + super(context); + } + +} diff --git a/src/net/cbaines/suma/MapActivity.java b/src/net/cbaines/suma/MapActivity.java index effd9b4..58c7918 100644 --- a/src/net/cbaines/suma/MapActivity.java +++ b/src/net/cbaines/suma/MapActivity.java @@ -92,7 +92,7 @@ public class MapActivity extends ToastHelperActivity implements MapViewConstants private ArrayList searchResults = null; - private POIDialog favDialog; + private FavouritesDialog favDialog; private HashMap overlays = new HashMap(); private HashMap pastOverlays; @@ -179,7 +179,7 @@ public class MapActivity extends ToastHelperActivity implements MapViewConstants private MapActivity instance; - private POIDialog searchResultsDialog; + private SearchResultsDialog searchResultsDialog; private static final String TAG = "MapActivity"; @@ -297,11 +297,30 @@ public class MapActivity extends ToastHelperActivity implements MapViewConstants searchResults.addAll(busStops); busStops = null; + Dao siteDao = getHelper().getSiteDao(); + + QueryBuilder siteQueryBuilder = siteDao.queryBuilder(); + siteQueryBuilder.where().like(Site.NAME_FIELD_NAME, "%" + query + "%").or() + .like(Site.ID_FIELD_NAME, "%" + query + "%"); + PreparedQuery sitePreparedQuery = siteQueryBuilder.prepare(); + List sites = siteDao.query(sitePreparedQuery); + searchResults.addAll(sites); + sites = null; + + Collections.sort(searchResults, new StringPOIDistanceComparator(query)); + startLocation = new GeoPoint(50935551, -1393488); mapController.setZoom(15); showDialog(SEARCH_RESULTS_DIALOG_ID); + searchResultsDialog.setTitle(getResources().getString(R.string.search_results_dialog_title) + query); + if (searchResults.size() == 0) { + searchResultsDialog.setMessage("No results found"); + } else { + searchResultsDialog.setItems(searchResults); + } + } catch (SQLException e) { e.printStackTrace(); } @@ -967,8 +986,6 @@ public class MapActivity extends ToastHelperActivity implements MapViewConstants return false; } - refreshFavouriteDialog(); - return false; case R.id.menu_about: Intent aboutIntent = new Intent(MapActivity.this, AboutActivity.class); @@ -980,40 +997,6 @@ public class MapActivity extends ToastHelperActivity implements MapViewConstants } } - private void refreshFavouriteDialog() { - ArrayList newFavouriteItems = new ArrayList(); - - try { - Dao buildingDao = getHelper().getBuildingDao(); - Dao busStopDao = getHelper().getBusStopDao(); - - final SharedPreferences favouritesPrefs = getSharedPreferences(FAVOURITES_PREFERENCES, MODE_PRIVATE); - for (String id : favouritesPrefs.getAll().keySet()) { - Building building; - BusStop busStop; - if ((building = buildingDao.queryForId(id)) != null) { - newFavouriteItems.add(building); - } else if ((busStop = busStopDao.queryForId(id)) != null) { - newFavouriteItems.add(busStop); - } else { - Log.e(TAG, "Item in favourites " + id + " cannot be found"); - } - } - } catch (SQLException e) { - e.printStackTrace(); - } - - Log.i(TAG, "There are " + newFavouriteItems.size() + " favourites"); - if (newFavouriteItems.size() == 0) { - Log.i(TAG, "Favourite dialog has no favourites, displaying message"); - favDialog.setMessage(getResources().getString(R.string.favourites_dialog_message)); - favDialog.setItems(null); - } else { - favDialog.setMessage(""); - favDialog.setItems(newFavouriteItems); - } - } - protected void onActivityResult(int requestCode, int resultCode, Intent data) { Log.i(TAG, "Got activity result"); if (resultCode == RESULT_OK) { @@ -1050,10 +1033,6 @@ public class MapActivity extends ToastHelperActivity implements MapViewConstants Log.i(TAG, "Got null poi id"); } - if (favDialog != null) { - refreshFavouriteDialog(); - } - mapView.invalidate(); } } @@ -1066,17 +1045,15 @@ public class MapActivity extends ToastHelperActivity implements MapViewConstants ViewDialog viewDialog = new ViewDialog(instance); return viewDialog; case FAVOURITE_DIALOG_ID: - favDialog = new POIDialog(instance); + favDialog = new FavouritesDialog(instance); favDialog.setOnItemClickListener(this); favDialog.setOnItemLongClickListener(this); favDialog.setTitle(R.string.favourites_dialog_title); return favDialog; case SEARCH_RESULTS_DIALOG_ID: - searchResultsDialog = new POIDialog(instance); + searchResultsDialog = new SearchResultsDialog(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); @@ -1085,54 +1062,75 @@ public class MapActivity extends ToastHelperActivity implements MapViewConstants return null; } - public void onItemClick(AdapterView parent, View view, int position, long id) { - Log.i(TAG, "OnItemClick pos " + position + " id " + id); + protected void onPrepareDialog(int id, Dialog dialog) { + if (dialog instanceof FavouritesDialog) { + favDialog = (FavouritesDialog) dialog; - String poiId = null; - if (favDialog != null) { - poiId = favDialog.adapter.getItemStringId(position); - } else if (searchResultsDialog != null) { - poiId = searchResultsDialog.adapter.getItemStringId(position); - } + ArrayList newFavouriteItems = new ArrayList(); - Log.i(TAG, "POI " + poiId + " selected"); - - POI poi = null; - - if (poiId != null) { - Log.i(TAG, "Got id " + poiId); try { - poi = getHelper().getBuildingDao().queryForId(poiId); - if (poi == null) { - poi = getHelper().getBusStopDao().queryForId(poiId); + Dao buildingDao = getHelper().getBuildingDao(); + Dao busStopDao = getHelper().getBusStopDao(); + + final SharedPreferences favouritesPrefs = getSharedPreferences(FAVOURITES_PREFERENCES, 0); + for (String idStr : favouritesPrefs.getAll().keySet()) { + Building building; + BusStop busStop; + if ((building = buildingDao.queryForId(idStr)) != null) { + newFavouriteItems.add(building); + } else if ((busStop = busStopDao.queryForId(idStr)) != null) { + newFavouriteItems.add(busStop); + } else { + Log.e(TAG, "Item in favourites " + idStr + " cannot be found"); + } } } catch (SQLException e) { e.printStackTrace(); } - if (poi == null) { - Log.e(TAG, "Could not find poi " + poiId + " in onActivityResult"); + Log.i(TAG, "There are " + newFavouriteItems.size() + " favourites"); + if (newFavouriteItems.size() == 0) { + Log.i(TAG, "Favourite dialog has no favourites, displaying message"); + favDialog.setMessage(getResources().getString(R.string.favourites_dialog_message)); + favDialog.setItems(null); } else { - if (myLocationOverlay != null) { - myLocationOverlay.disableFollowLocation(); - } - mapController.setZoom(20); - mapController.setCenter(poi.point); + favDialog.setMessage(""); + favDialog.setItems(newFavouriteItems); + } + } else if (dialog instanceof SearchResultsDialog) { + searchResultsDialog = (SearchResultsDialog) dialog; + } + } - if (favDialog != null) { - favDialog.dismiss(); - favDialog = null; - } else if (searchResultsDialog != null) { - searchResultsDialog.dismiss(); - searchResultsDialog = null; - } + public void onItemClick(AdapterView parent, View view, int position, long id) { + Log.i(TAG, "OnItemClick pos " + position + " id " + id); + + POI poi = null; + if (favDialog != null) { + poi = favDialog.adapter.getPOIItem(position); + } else if (searchResultsDialog != null) { + poi = searchResultsDialog.adapter.getPOIItem(position); + } + + if (poi != null) { + Log.i(TAG, "Got id " + poi.id); + if (myLocationOverlay != null) { + myLocationOverlay.disableFollowLocation(); + } + mapController.setZoom(20); + mapController.setCenter(poi.point); + + if (favDialog != null) { + favDialog.dismiss(); + favDialog = null; + } else if (searchResultsDialog != null) { + searchResultsDialog.dismiss(); + searchResultsDialog = null; } + } else { Log.i(TAG, "Got null poi id"); - - // mapController.setZoom(15); - // mapController.setCenter(new GeoPoint(50935551, -1393488)); } } @@ -1144,77 +1142,76 @@ public class MapActivity extends ToastHelperActivity implements MapViewConstants Log.i(TAG, "OnItemClick pos " + position + " id " + id); - String poiId = null; + POI poi = null; if (favDialog != null) { - poiId = favDialog.adapter.getItemStringId(position); + poi = favDialog.adapter.getPOIItem(position); } else if (searchResultsDialog != null) { - poiId = searchResultsDialog.adapter.getItemStringId(position); + poi = searchResultsDialog.adapter.getPOIItem(position); } - Log.i(TAG, "POI " + poiId + " selected"); + if (poi != null) { + Log.i(TAG, "Got id " + poi.id); - POI poi = null; + if (poi.type == POI.BUS_STOP) { + BusStop busStop = (BusStop) poi; - if (poiId != null) { - Log.i(TAG, "Got id " + poiId); - try { - poi = getHelper().getBuildingDao().queryForId(poiId); - if (poi == null) { - poi = getHelper().getBusStopDao().queryForId(poiId); - } - } catch (SQLException e) { - e.printStackTrace(); - } + Log.i(TAG, "Pressed " + busStop.id); - if (poi == null) { - Log.e(TAG, "Could not find poi " + poiId + " in onActivityResult"); - } else { - if (poi.type == POI.BUS_STOP) { - BusStop busStop = (BusStop) poi; + Uri uri = Uri.parse("http://id.southampton.ac.uk/bus-stop/" + busStop.id); - Log.i(TAG, "Pressed " + busStop.id); + Log.i(TAG, "Starting a activity for " + uri + " path " + uri.getPath()); - Uri uri = Uri.parse("http://id.southampton.ac.uk/bus-stop/" + busStop.id); + Intent busStopIntent = new Intent(Intent.ACTION_VIEW, uri); + startActivity(busStopIntent); - Log.i(TAG, "Starting a activity for " + uri + " path " + uri.getPath()); + return true; - Intent busStopIntent = new Intent(Intent.ACTION_VIEW, uri); - startActivity(busStopIntent); + } else if (poi.type == POI.BUILDING) { + Building building = (Building) poi; - return true; + Log.i(TAG, "Pressed " + building.id); - } else if (poi.type == POI.BUILDING) { - Building building = (Building) poi; + Uri uri = Uri.parse("http://id.southampton.ac.uk/building/" + building.id); - Log.i(TAG, "Pressed " + building.id); + Log.i(TAG, "Starting a activity for " + uri + " path " + uri.getPath()); - Uri uri = Uri.parse("http://id.southampton.ac.uk/building/" + building.id); + Intent buildingIntent = new Intent(Intent.ACTION_VIEW, uri); + startActivity(buildingIntent); - Log.i(TAG, "Starting a activity for " + uri + " path " + uri.getPath()); + return true; - Intent buildingIntent = new Intent(Intent.ACTION_VIEW, uri); - startActivity(buildingIntent); + } else if (poi.type == POI.SITE) { + Site site = (Site) poi; - return true; + Log.i(TAG, "Pressed " + site.id); - } else { + Uri uri = Uri.parse("http://id.southampton.ac.uk/site/" + site.id); - myLocationOverlay.disableFollowLocation(); - mapController.setZoom(20); - mapController.setCenter(poi.point); + Log.i(TAG, "Starting a activity for " + uri + " path " + uri.getPath()); - if (favDialog != null) { - favDialog.dismiss(); - favDialog = null; - } else if (searchResultsDialog != null) { - searchResultsDialog.dismiss(); - searchResultsDialog = null; - } + Intent siteIntent = new Intent(Intent.ACTION_VIEW, uri); + startActivity(siteIntent); + + return true; + + } else { + + myLocationOverlay.disableFollowLocation(); + mapController.setZoom(20); + mapController.setCenter(poi.point); + if (favDialog != null) { + favDialog.dismiss(); + favDialog = null; + } else if (searchResultsDialog != null) { + searchResultsDialog.dismiss(); + searchResultsDialog = null; } + } + } else { - Log.i(TAG, "Got null poi id"); + Log.i(TAG, "Got null poi"); // mapController.setZoom(15); // mapController.setCenter(new GeoPoint(50935551, -1393488)); diff --git a/src/net/cbaines/suma/MapContentProvider.java b/src/net/cbaines/suma/MapContentProvider.java index d920b21..efbdf2f 100644 --- a/src/net/cbaines/suma/MapContentProvider.java +++ b/src/net/cbaines/suma/MapContentProvider.java @@ -17,6 +17,8 @@ package net.cbaines.suma; import java.sql.SQLException; +import java.util.ArrayList; +import java.util.Collections; import java.util.List; import android.app.SearchManager; @@ -48,10 +50,8 @@ 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 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 @@ -60,14 +60,10 @@ public class MapContentProvider extends ContentProvider { + "/vnd.net.cbaines.suma.provider.bus-stop"; public static final String BUS_STOP_MIME_TYPE = ContentResolver.CURSOR_ITEM_BASE_TYPE + "/vnd.net.cbaines.suma.provider.bus-stop"; - public static final String SITES_MIME_TYPE = ContentResolver.CURSOR_DIR_BASE_TYPE - + "/vnd.net.cbaines.suma.provider.site"; - public static final String SITE_MIME_TYPE = ContentResolver.CURSOR_ITEM_BASE_TYPE - + "/vnd.net.cbaines.suma.provider.site"; - public static final String BUSES_MIME_TYPE = ContentResolver.CURSOR_DIR_BASE_TYPE - + "/vnd.net.cbaines.suma.provider.bus"; - public static final String BUS_MIME_TYPE = ContentResolver.CURSOR_ITEM_BASE_TYPE - + "/vnd.net.cbaines.suma.provider.bus"; + public static final String SITES_MIME_TYPE = ContentResolver.CURSOR_DIR_BASE_TYPE + "/vnd.net.cbaines.suma.provider.site"; + public static final String SITE_MIME_TYPE = ContentResolver.CURSOR_ITEM_BASE_TYPE + "/vnd.net.cbaines.suma.provider.site"; + public static final String BUSES_MIME_TYPE = ContentResolver.CURSOR_DIR_BASE_TYPE + "/vnd.net.cbaines.suma.provider.bus"; + public static final String BUS_MIME_TYPE = ContentResolver.CURSOR_ITEM_BASE_TYPE + "/vnd.net.cbaines.suma.provider.bus"; private DatabaseHelper helper; @@ -87,8 +83,7 @@ public class MapContentProvider extends ContentProvider { private static final UriMatcher sURIMatcher = buildUriMatcher(); /** - * Builds up a UriMatcher for search suggestion and shortcut refresh - * queries. + * Builds up a UriMatcher for search suggestion and shortcut refresh queries. */ private static UriMatcher buildUriMatcher() { UriMatcher matcher = new UriMatcher(UriMatcher.NO_MATCH); @@ -109,12 +104,10 @@ public class MapContentProvider extends ContentProvider { 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. + * 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); @@ -128,11 +121,9 @@ public class MapContentProvider extends ContentProvider { } /** - * 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. + * 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) { @@ -193,9 +184,10 @@ 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 }; + String[] columnNames = { BaseColumns._ID, SearchManager.SUGGEST_COLUMN_ICON_1, SearchManager.SUGGEST_COLUMN_TEXT_1, + SearchManager.SUGGEST_COLUMN_TEXT_2, SearchManager.SUGGEST_COLUMN_INTENT_DATA }; + + List results = new ArrayList(); MatrixCursor cursor = new MatrixCursor(columnNames); int id = 0; @@ -203,24 +195,10 @@ public class MapContentProvider extends ContentProvider { Dao buildingDao = helper.getBuildingDao(); QueryBuilder qb = buildingDao.queryBuilder(); - qb.where().like(Building.ID_FIELD_NAME, "%" + query + "%").or() - .like(Building.NAME_FIELD_NAME, "%" + query + "%"); + qb.where().like(Building.ID_FIELD_NAME, "%" + query + "%").or().like(Building.NAME_FIELD_NAME, "%" + query + "%"); PreparedQuery preparedQuery = qb.prepare(); - List buildings = buildingDao.query(preparedQuery); - Log.v(TAG, "Returning " + buildings.size() + " buildings"); - - for (Building building : buildings) { - // 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); - } + results.addAll(buildingDao.query(preparedQuery)); Dao busStopDao = helper.getBusStopDao(); @@ -229,19 +207,52 @@ public class MapContentProvider extends ContentProvider { .like(BusStop.DESCRIPTION_FIELD_NAME, "%" + query + "%"); PreparedQuery busStopPreparedQuery = busStopQB.prepare(); - List 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); + results.addAll(busStopDao.query(busStopPreparedQuery)); + + Dao siteDao = helper.getSiteDao(); + + QueryBuilder siteQB = siteDao.queryBuilder(); + siteQB.where().like(Site.NAME_FIELD_NAME, "%" + query + "%").or().like(Site.ID_FIELD_NAME, "%" + query + "%"); + PreparedQuery sitePreparedQuery = siteQB.prepare(); + + results.addAll(siteDao.query(sitePreparedQuery)); + + Collections.sort(results, new StringPOIDistanceComparator(query)); + + for (POI poi : results) { + if (poi instanceof Site) { + Site site = (Site) poi; + Object[] values = { + id++, + R.drawable.empty, + site.name, + site.id, + "geo:" + Util.E6IntToDouble(site.point.getLatitudeE6()) + "," + + Util.E6IntToDouble(site.point.getLongitudeE6()) + "?z=18" }; + cursor.addRow(values); + } else if (poi instanceof Building) { + Building building = (Building) poi; + 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); + } else if (poi instanceof BusStop) { + BusStop busStop = (BusStop) poi; + 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); + } else { + Log.e(TAG, "Error, unexpected class"); + } } return cursor; @@ -307,13 +318,11 @@ public class MapContentProvider extends ContentProvider { private Cursor refreshShortcut(Uri uri) throws SQLException { /* - * 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. + * 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 buildingID = uri.getLastPathSegment(); Dao buildingDao = helper.getBuildingDao(); @@ -330,8 +339,8 @@ public class MapContentProvider extends ContentProvider { } /** - * 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. + * 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) { diff --git a/src/net/cbaines/suma/Preferences.java b/src/net/cbaines/suma/Preferences.java index 9f2eaca..791aad8 100644 --- a/src/net/cbaines/suma/Preferences.java +++ b/src/net/cbaines/suma/Preferences.java @@ -16,18 +16,18 @@ public interface Preferences { static final String APP_VERSION = "appVersion"; static final String APP_NOT_INSTALLED = ""; - static final String CURRENT_APP_VERSION = "0.8"; + static final String CURRENT_APP_VERSION = "0.9"; static final String FAVOURITES_PREFERENCES = "favourites"; static final String DATABASE_PATH = "/data/data/net.cbaines.suma/databases/"; static final String DATABASE_NAME = "data.db"; - static final int DATABASE_VERSION = 41; + static final int DATABASE_VERSION = 42; /** * 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 */ - static final boolean USE_BUNDLED_DATABASE = false; + static final boolean USE_BUNDLED_DATABASE = true; } diff --git a/src/net/cbaines/suma/SearchResultsDialog.java b/src/net/cbaines/suma/SearchResultsDialog.java new file mode 100644 index 0000000..43fa206 --- /dev/null +++ b/src/net/cbaines/suma/SearchResultsDialog.java @@ -0,0 +1,10 @@ +package net.cbaines.suma; + +import android.content.Context; + +public class SearchResultsDialog extends POIDialog implements Preferences { + + public SearchResultsDialog(Context context) { + super(context); + } +} diff --git a/src/net/cbaines/suma/StringDistanceComparator.java b/src/net/cbaines/suma/StringDistanceComparator.java deleted file mode 100644 index d42451f..0000000 --- a/src/net/cbaines/suma/StringDistanceComparator.java +++ /dev/null @@ -1,134 +0,0 @@ -/* - * Southampton University Map App - * Copyright (C) 2011 Christopher Baines - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License - * as published by the Free Software Foundation; either version 2 - * of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ - -package net.cbaines.suma; - -import java.util.Comparator; - -public class StringDistanceComparator implements Comparator { - private String userString; - - // private static final String TAG = "StringDistanceComparator"; - - public StringDistanceComparator(String userString) { - super(); - this.userString = userString; - } - - public int compare(POI poi1, POI poi2) { - int distTo1 = LD(userString, poi1.toString()); - // Log.i(TAG, "Comparing " + userString + " and " + poi1.toString() + - // " got dist " + distTo1); - int distTo2 = LD(userString, poi2.toString()); - // Log.i(TAG, "Comparing " + userString + " and " + poi2.toString() + - // " got dist " + distTo2); - return distTo1 - distTo2; - } - - // Below is public domain code from http://www.merriampark.com/ld.htm - - // **************************** - // Get minimum of three values - // **************************** - - private int Minimum(int a, int b, int c) { - int mi; - - mi = a; - if (b < mi) { - mi = b; - } - if (c < mi) { - mi = c; - } - return mi; - - } - - // ***************************** - // Compute Levenshtein distance - // ***************************** - - public int LD(String s, String t) { - int d[][]; // matrix - int n; // length of s - int m; // length of t - int i; // iterates through s - int j; // iterates through t - char s_i; // ith character of s - char t_j; // jth character of t - int cost; // cost - - // Step 1 - - n = s.length(); - m = t.length(); - if (n == 0) { - return m; - } - if (m == 0) { - return n; - } - d = new int[n + 1][m + 1]; - - // Step 2 - - for (i = 0; i <= n; i++) { - d[i][0] = i; - } - - for (j = 0; j <= m; j++) { - d[0][j] = j; - } - - // Step 3 - - for (i = 1; i <= n; i++) { - - s_i = s.charAt(i - 1); - - // Step 4 - - for (j = 1; j <= m; j++) { - - t_j = t.charAt(j - 1); - - // Step 5 - - if (s_i == t_j) { - cost = 0; - } else { - cost = 1; - } - - // Step 6 - - d[i][j] = Minimum(d[i - 1][j] + 1, d[i][j - 1] + 1, d[i - 1][j - 1] + cost); - - } - - } - - // Step 7 - - return d[n][m]; - - } - -} diff --git a/src/net/cbaines/suma/StringPOIDistanceComparator.java b/src/net/cbaines/suma/StringPOIDistanceComparator.java new file mode 100644 index 0000000..e8a7539 --- /dev/null +++ b/src/net/cbaines/suma/StringPOIDistanceComparator.java @@ -0,0 +1,134 @@ +/* + * Southampton University Map App + * Copyright (C) 2011 Christopher Baines + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +package net.cbaines.suma; + +import java.util.Comparator; + +public class StringPOIDistanceComparator implements Comparator { + private String userString; + + // private static final String TAG = "StringDistanceComparator"; + + public StringPOIDistanceComparator(String userString) { + super(); + this.userString = userString; + } + + public int compare(POI poi1, POI poi2) { + int distTo1 = Math.min(LD(userString, poi1.toString()), LD(userString, poi1.id)); + // Log.i(TAG, "Comparing " + userString + " and " + poi1.toString() + + // " got dist " + distTo1); + int distTo2 = Math.min(LD(userString, poi2.toString()), LD(userString, poi2.id)); + // Log.i(TAG, "Comparing " + userString + " and " + poi2.toString() + + // " got dist " + distTo2); + return distTo1 - distTo2; + } + + // Below is public domain code from http://www.merriampark.com/ld.htm + + // **************************** + // Get minimum of three values + // **************************** + + private int Minimum(int a, int b, int c) { + int mi; + + mi = a; + if (b < mi) { + mi = b; + } + if (c < mi) { + mi = c; + } + return mi; + + } + + // ***************************** + // Compute Levenshtein distance + // ***************************** + + public int LD(String s, String t) { + int d[][]; // matrix + int n; // length of s + int m; // length of t + int i; // iterates through s + int j; // iterates through t + char s_i; // ith character of s + char t_j; // jth character of t + int cost; // cost + + // Step 1 + + n = s.length(); + m = t.length(); + if (n == 0) { + return m; + } + if (m == 0) { + return n; + } + d = new int[n + 1][m + 1]; + + // Step 2 + + for (i = 0; i <= n; i++) { + d[i][0] = i; + } + + for (j = 0; j <= m; j++) { + d[0][j] = j; + } + + // Step 3 + + for (i = 1; i <= n; i++) { + + s_i = s.charAt(i - 1); + + // Step 4 + + for (j = 1; j <= m; j++) { + + t_j = t.charAt(j - 1); + + // Step 5 + + if (s_i == t_j) { + cost = 0; + } else { + cost = 1; + } + + // Step 6 + + d[i][j] = Minimum(d[i - 1][j] + 1, d[i][j - 1] + 1, d[i - 1][j - 1] + cost); + + } + + } + + // Step 7 + + return d[n][m]; + + } + +} diff --git a/src/net/cbaines/suma/WelcomeDialog.java b/src/net/cbaines/suma/WelcomeDialog.java index 7262f48..7afec03 100644 --- a/src/net/cbaines/suma/WelcomeDialog.java +++ b/src/net/cbaines/suma/WelcomeDialog.java @@ -46,7 +46,7 @@ public class WelcomeDialog extends Dialog implements OnClickListener, Preference sharedPrefs = PreferenceManager.getDefaultSharedPreferences(context); String appVersion = sharedPrefs.getString(APP_VERSION, APP_NOT_INSTALLED); - if (!appVersion.equals(CURRENT_APP_VERSION)) { + if (!appVersion.equals(APP_NOT_INSTALLED)) { TextView welcomeDialogMessage = (TextView) findViewById(R.id.welcomeDialogMessage); welcomeDialogMessage.setText(R.string.welcome_dialog_upgrade_message); } -- cgit v1.2.3