aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristopher Baines <cbaines8@gmail.com>2012-03-06 14:46:01 +0000
committerChristopher Baines <cbaines8@gmail.com>2012-03-06 14:46:01 +0000
commita722eac92e7154563bd144ad91b092d23dae8f2a (patch)
tree4bcd0901fe5fe9748c797119eec5045fbb33efcd
parent5dbed3a0fe85f0ed2a2763be0912f109bdee6c20 (diff)
downloadsouthamptonuniversitymap-a722eac92e7154563bd144ad91b092d23dae8f2a.tar
southamptonuniversitymap-a722eac92e7154563bd144ad91b092d23dae8f2a.tar.gz
Basic searchable stuff.
-rw-r--r--AndroidManifest.xml5
-rw-r--r--res/xml/searchable.xml9
-rw-r--r--src/net/cbaines/suma/Bus.java10
-rw-r--r--src/net/cbaines/suma/BusStopSpecificStopView.java3
-rw-r--r--src/net/cbaines/suma/DataManager.java95
-rw-r--r--src/net/cbaines/suma/MapContentProvider.java194
-rw-r--r--src/net/cbaines/suma/POI.java83
7 files changed, 267 insertions, 132 deletions
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index a9bccd3..4dfff99 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -169,6 +169,11 @@
android:name=".PreferencesActivity"
android:label="@string/preferences" >
</activity>
+
+ <!-- Provides search suggestions for words and their definitions. -->
+ <provider
+ android:name=".MapContentProvider"
+ android:authorities="net.cbaines.suma.provider" />
</application>
</manifest> \ No newline at end of file
diff --git a/res/xml/searchable.xml b/res/xml/searchable.xml
index e4602a5..7262b3d 100644
--- a/res/xml/searchable.xml
+++ b/res/xml/searchable.xml
@@ -1,6 +1,13 @@
<?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" >
+ android:includeInGlobalSearch="true"
+ android:label="@string/app_name"
+ android:searchSettingsDescription="@string/map_activity_search_hint"
+ 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" >
</searchable> \ No newline at end of file
diff --git a/src/net/cbaines/suma/Bus.java b/src/net/cbaines/suma/Bus.java
index 865384f..34e20a6 100644
--- a/src/net/cbaines/suma/Bus.java
+++ b/src/net/cbaines/suma/Bus.java
@@ -35,9 +35,6 @@ public class Bus {
final static String ROUTE_FIELD_NAME = "route";
final static String DIRECTION_FIELD_NAME = "direction";
- @DatabaseField(generatedId = true)
- int gid;
-
/**
* The identification number of the bus.
*/
@@ -115,7 +112,7 @@ public class Bus {
public int hashCode() {
final int prime = 31;
int result = 1;
- result = prime * result + gid;
+ result = prime * result + ((id == null) ? 0 : id.hashCode());
return result;
}
@@ -128,7 +125,10 @@ public class Bus {
if (getClass() != obj.getClass())
return false;
Bus other = (Bus) obj;
- if (id != other.id)
+ if (id == null) {
+ if (other.id != null)
+ return false;
+ } else if (!id.equals(other.id))
return false;
return true;
}
diff --git a/src/net/cbaines/suma/BusStopSpecificStopView.java b/src/net/cbaines/suma/BusStopSpecificStopView.java
index b7a16cb..eade3fe 100644
--- a/src/net/cbaines/suma/BusStopSpecificStopView.java
+++ b/src/net/cbaines/suma/BusStopSpecificStopView.java
@@ -149,7 +149,8 @@ public class BusStopSpecificStopView extends LinearLayout implements OnClickList
busDao.refresh(stop.bus);
busRouteDao.refresh(stop.bus.route);
- Log.i("StopView", "Bus route " + stop.bus.route + " Uni-Link " + stop.bus.route.uniLink + " Bus ID " + stop.bus.id);
+ Log.i("StopView", "Bus route " + stop.bus.route + " Uni-Link " + stop.bus.route.uniLink + " Bus ID "
+ + stop.bus.id);
if (stop.bus.id != null && stop.bus.route.uniLink) {
Uri uri = Uri.parse("http://id.southampton.ac.uk/bus/" + stop.bus.id);
diff --git a/src/net/cbaines/suma/DataManager.java b/src/net/cbaines/suma/DataManager.java
index ab1f3a7..fd47360 100644
--- a/src/net/cbaines/suma/DataManager.java
+++ b/src/net/cbaines/suma/DataManager.java
@@ -137,9 +137,13 @@ public class DataManager {
/*
* Polygon poly = buildingPolys.get(dataBits[1]);
*
- * if (poly != null) { bdg.outline = poly; // Log.i(TAG, "Adding building " + key + " " +
- * bdg.point.getLatitudeE6() + " " + bdg.point.getLongitudeE6() + " " + poly); } else { // Log.i(TAG,
- * "Adding building " + key + " " + bdg.point.getLatitudeE6() + " " + bdg.point.getLongitudeE6()); }
+ * if (poly != null) { bdg.outline = poly; // Log.i(TAG,
+ * "Adding building " + key + " " +
+ * bdg.point.getLatitudeE6() + " " +
+ * bdg.point.getLongitudeE6() + " " + poly); } else { //
+ * Log.i(TAG, "Adding building " + key + " " +
+ * bdg.point.getLatitudeE6() + " " +
+ * bdg.point.getLongitudeE6()); }
*/
// Log.i(TAG, "Creating building " + bdg.id + " " + bdg.name
@@ -163,9 +167,13 @@ public class DataManager {
/*
* Polygon poly = buildingPolys.get(dataBits[1]);
*
- * if (poly != null) { bdg.outline = poly; // Log.i(TAG, "Adding building " + key + " " +
- * bdg.point.getLatitudeE6() + " " + bdg.point.getLongitudeE6() + " " + poly); } else { // Log.i(TAG,
- * "Adding building " + key + " " + bdg.point.getLatitudeE6() + " " + bdg.point.getLongitudeE6()); }
+ * if (poly != null) { bdg.outline = poly; // Log.i(TAG,
+ * "Adding building " + key + " " +
+ * bdg.point.getLatitudeE6() + " " +
+ * bdg.point.getLongitudeE6() + " " + poly); } else { //
+ * Log.i(TAG, "Adding building " + key + " " +
+ * bdg.point.getLatitudeE6() + " " +
+ * bdg.point.getLongitudeE6()); }
*/
// Log.i(TAG, "Creating building " + bdg.id + " " + bdg.name
@@ -184,13 +192,17 @@ public class DataManager {
}
/*
- * for (Iterator<String> iter = buildingPoints.keySet().iterator(); iter.hasNext();) { String key = iter.next();
+ * for (Iterator<String> iter = buildingPoints.keySet().iterator();
+ * iter.hasNext();) { String key = iter.next();
*
- * Building bdg = new Building(key, buildingPoints.get(key), false); Polygon poly = buildingPolys.get(key);
+ * Building bdg = new Building(key, buildingPoints.get(key), false);
+ * Polygon poly = buildingPolys.get(key);
*
- * if (poly != null) { bdg.outline = poly; // Log.i(TAG, "Adding building " + key + " " + bdg.point.getLatitudeE6() + " "
- * + bdg.point.getLongitudeE6() + " " + poly); } else { // Log.i(TAG, "Adding building " + key + " " +
- * bdg.point.getLatitudeE6() + " " + bdg.point.getLongitudeE6()); }
+ * if (poly != null) { bdg.outline = poly; // Log.i(TAG,
+ * "Adding building " + key + " " + bdg.point.getLatitudeE6() + " " +
+ * bdg.point.getLongitudeE6() + " " + poly); } else { // Log.i(TAG,
+ * "Adding building " + key + " " + bdg.point.getLatitudeE6() + " " +
+ * bdg.point.getLongitudeE6()); }
*
* buildingDao.create(bdg); }
*/
@@ -227,18 +239,18 @@ public class DataManager {
// Log.i(TAG, "Whole " + dataBits[3] + " First bit " +
// quBitsLat[0] + " last bit " + quBitsLat[1]);
- double lat = Double.valueOf(quBitsLat[0]) + Double.valueOf(quBitsLat[1].substring(0, quBitsLat[1].length() - 1))
- / 60d;
+ double lat = Double.valueOf(quBitsLat[0])
+ + Double.valueOf(quBitsLat[1].substring(0, quBitsLat[1].length() - 1)) / 60d;
// Log.i(TAG, "Whole " + dataBits[4] + " First bit " +
// quBitsLng[0] + " last bit " + quBitsLng[1]);
- double lng = Double.valueOf(quBitsLng[0]) + Double.valueOf(quBitsLng[1].substring(0, quBitsLng[1].length() - 1))
- / 60d;
+ double lng = Double.valueOf(quBitsLng[0])
+ + Double.valueOf(quBitsLng[1].substring(0, quBitsLng[1].length() - 1)) / 60d;
GeoPoint point = new GeoPoint((int) (lat * 1e6), (int) (lng * -1e6));
// Log.i(TAG, "Lat " + point.getLatitudeE6() + " lng " +
// point.getLongitudeE6());
- busStopDao.create(new BusStop(dataBits[0].replace("\"", ""), dataBits[1].replace("\"", ""), dataBits[2].replace(
- "\"", ""), point));
+ busStopDao.create(new BusStop(dataBits[0].replace("\"", ""), dataBits[1].replace("\"", ""), dataBits[2]
+ .replace("\"", ""), point));
}
@@ -359,26 +371,36 @@ public class DataManager {
}
/*
- * for (Iterator<BusStop> busStopIter = busStopDao.iterator(); busStopIter.hasNext();) { BusStop stop =
- * busStopIter.next(); // Log.i(TAG, "Looking at stop " + stop.id);
+ * for (Iterator<BusStop> busStopIter = busStopDao.iterator();
+ * busStopIter.hasNext();) { BusStop stop = busStopIter.next(); //
+ * Log.i(TAG, "Looking at stop " + stop.id);
*
*
- * QueryBuilder<RouteStops, Integer> routeStopsQueryBuilder = routeStopsDao.queryBuilder();
+ * QueryBuilder<RouteStops, Integer> routeStopsQueryBuilder =
+ * routeStopsDao.queryBuilder();
* routeStopsQueryBuilder.where().eq(columnName, value)
*
- * DeleteBuilder<BusStop, String> deleteBuilder = busStopDao.deleteBuilder(); // only delete the rows where password is
- * null deleteBuilder.where().in(RouteStops.STOP_ID_FIELD_NAME, objects) accountDao.delete(deleteBuilder.prepare());
+ * DeleteBuilder<BusStop, String> deleteBuilder =
+ * busStopDao.deleteBuilder(); // only delete the rows where password is
+ * null deleteBuilder.where().in(RouteStops.STOP_ID_FIELD_NAME, objects)
+ * accountDao.delete(deleteBuilder.prepare());
*
*
- * QueryBuilder<RouteStops, Integer> routeStopsQueryBuilder = routeStopsDao.queryBuilder();
- * routeStopsQueryBuilder.setCountOf(true); routeStopsQueryBuilder.where().eq(RouteStops.STOP_ID_FIELD_NAME, stop);
+ * QueryBuilder<RouteStops, Integer> routeStopsQueryBuilder =
+ * routeStopsDao.queryBuilder();
+ * routeStopsQueryBuilder.setCountOf(true);
+ * routeStopsQueryBuilder.where().eq(RouteStops.STOP_ID_FIELD_NAME,
+ * stop);
*
- * PreparedQuery<RouteStops> routeStopsPreparedQuery = routeStopsQueryBuilder.prepare(); List<RouteStops> routeStops =
- * routeStopsDao.query(routeStopsPreparedQuery); // long num = routeStopsDao.query(routeStopsPreparedQuery).size(); //
- * Log.i(TAG, "Number is " + num);
+ * PreparedQuery<RouteStops> routeStopsPreparedQuery =
+ * routeStopsQueryBuilder.prepare(); List<RouteStops> routeStops =
+ * routeStopsDao.query(routeStopsPreparedQuery); // long num =
+ * routeStopsDao.query(routeStopsPreparedQuery).size(); // Log.i(TAG,
+ * "Number is " + num);
*
- * stop.uniLink = false; for (RouteStops routeStop : routeStops) { if (routeStop.busRoute.uniLink) { stop.uniLink = true;
- * } } busStopDao.update(stop); }
+ * stop.uniLink = false; for (RouteStops routeStop : routeStops) { if
+ * (routeStop.busRoute.uniLink) { stop.uniLink = true; } }
+ * busStopDao.update(stop); }
*/
Log.i(TAG, "Finished loading bus data");
@@ -438,8 +460,6 @@ public class DataManager {
Dao<RouteStop, Integer> routeStopsDao = null;
if (routeStopsDao == null)
routeStopsDao = helper.getRouteStopsDao();
- if (busDao == null)
- busDao = helper.getBusDao();
if (busStopDao == null)
busStopDao = helper.getBusStopDao();
@@ -554,9 +574,11 @@ public class DataManager {
List<RouteStop> routeStops = routeStopsDao.query(routeStopsPreparedQuery);
if (routeStops.size() > 0) {
- Log.i(TAG, "Found " + routeStops.size() + " stops matching the destStop " + destStop + " on route " + route.code);
+ Log.i(TAG, "Found " + routeStops.size() + " stops matching the destStop " + destStop + " on route "
+ + route.code);
} else {
- Log.w(TAG, "Found " + routeStops.size() + " stops matching the destStop " + destStop + " on route " + route.code);
+ Log.w(TAG, "Found " + routeStops.size() + " stops matching the destStop " + destStop + " on route "
+ + route.code);
}
}
@@ -642,7 +664,8 @@ public class DataManager {
if (route != null) {
busRoutes.add(route);
} else {
- throw new RuntimeException("Route not found " + key.substring(key.length() - 3, key.length()) + " " + key);
+ throw new RuntimeException("Route not found " + key.substring(key.length() - 3, key.length()) + " "
+ + key);
}
}
@@ -750,8 +773,8 @@ public class DataManager {
continue;
}
- Log.v(TAG, "Found stop for a unidentified " + stop.bus.toString() + " at " + stop.busStop.id + " at "
- + stop.arivalTime);
+ Log.v(TAG, "Found stop for a unidentified " + stop.bus.toString() + " at " + stop.busStop.id
+ + " at " + stop.arivalTime);
timetable.add(stop);
diff --git a/src/net/cbaines/suma/MapContentProvider.java b/src/net/cbaines/suma/MapContentProvider.java
index 46986ab..a2b42c3 100644
--- a/src/net/cbaines/suma/MapContentProvider.java
+++ b/src/net/cbaines/suma/MapContentProvider.java
@@ -16,7 +16,8 @@
package net.cbaines.suma;
-import com.j256.ormlite.android.apptools.OpenHelperManager;
+import java.sql.SQLException;
+import java.util.List;
import android.app.SearchManager;
import android.content.ContentProvider;
@@ -24,8 +25,17 @@ import android.content.ContentResolver;
import android.content.ContentValues;
import android.content.UriMatcher;
import android.database.Cursor;
+import android.database.MatrixCursor;
import android.net.Uri;
import android.provider.BaseColumns;
+import android.util.Log;
+
+import com.j256.ormlite.android.AndroidCompiledStatement;
+import com.j256.ormlite.android.apptools.OpenHelperManager;
+import com.j256.ormlite.dao.Dao;
+import com.j256.ormlite.stmt.PreparedQuery;
+import com.j256.ormlite.stmt.QueryBuilder;
+import com.j256.ormlite.stmt.StatementBuilder.StatementType;
/**
* Provides access to the dictionary database.
@@ -34,21 +44,40 @@ 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");
+ // 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";
+ 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
+ + "/vnd.net.cbaines.suma.provider.building";
+ public static final String BUS_STOPS_MIME_TYPE = ContentResolver.CURSOR_DIR_BASE_TYPE
+ + "/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";
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 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 UriMatcher sURIMatcher = buildUriMatcher();
/**
@@ -58,8 +87,15 @@ public class MapContentProvider extends ContentProvider {
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);
+ matcher.addURI(AUTHORITY, "building", SEARCH_BUILDINGS);
+ matcher.addURI(AUTHORITY, "building/*", GET_BUILDING);
+ matcher.addURI(AUTHORITY, "bus-stop", SEARCH_BUS_STOPS);
+ matcher.addURI(AUTHORITY, "bus-stop/*", GET_BUS_STOP);
+ matcher.addURI(AUTHORITY, "site", SEARCH_SITES);
+ matcher.addURI(AUTHORITY, "site/*", GET_SITE);
+ matcher.addURI(AUTHORITY, "bus", SEARCH_BUSES);
+ matcher.addURI(AUTHORITY, "bus/*", GET_BUS);
+
// to get suggestions...
matcher.addURI(AUTHORITY, SearchManager.SUGGEST_URI_PATH_QUERY, SEARCH_SUGGEST);
matcher.addURI(AUTHORITY, SearchManager.SUGGEST_URI_PATH_QUERY + "/*", SEARCH_SUGGEST);
@@ -100,50 +136,94 @@ public class MapContentProvider extends ContentProvider {
if (selectionArgs == null) {
throw new IllegalArgumentException("selectionArgs must be provided for the Uri: " + uri);
}
- return getSuggestions(selectionArgs[0]);
- case SEARCH_WORDS:
+ try {
+ return getSuggestions(selectionArgs[0]);
+ } catch (SQLException e1) {
+ e1.printStackTrace();
+ }
+ case SEARCH_BUILDINGS:
if (selectionArgs == null) {
throw new IllegalArgumentException("selectionArgs must be provided for the Uri: " + uri);
}
- return search(selectionArgs[0]);
- case GET_WORD:
- return getWord(uri);
+ try {
+ return searchBuildings(selectionArgs[0]);
+ } catch (SQLException e) {
+ e.printStackTrace();
+ }
+ case GET_BUILDING:
+ try {
+ return getBuilding(uri);
+ } catch (SQLException e) {
+ e.printStackTrace();
+ }
case REFRESH_SHORTCUT:
- return refreshShortcut(uri);
+ try {
+ return refreshShortcut(uri);
+ } catch (SQLException e) {
+ e.printStackTrace();
+ }
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 getSuggestions(String query) throws SQLException {
+ Log.v(TAG, "Got query for " + query);
+
+ Dao<Building, String> buildingDao = helper.getBuildingDao();
+
+ QueryBuilder<Building, String> qb = buildingDao.queryBuilder();
+ qb.where().like(Building.ID_FIELD_NAME, "%" + query + "%").or()
+ .like(Building.NAME_FIELD_NAME, "%" + query + "%");
+ PreparedQuery<Building> preparedQuery = qb.prepare();
+
+ 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 };
+ cursor.addRow(values);
+ }
+
+ return cursor;
}
- private Cursor search(String query) {
- query = query.toLowerCase();
- String[] columns = new String[] { BaseColumns._ID, DictionaryDatabase.KEY_WORD,
- DictionaryDatabase.KEY_DEFINITION };
+ private Cursor searchBuildings(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();
- return mDictionary.getWordMatches(query, columns);
+ AndroidCompiledStatement compiledStatement = (AndroidCompiledStatement) preparedQuery.compile(helper
+ .getConnectionSource().getReadOnlyConnection(), StatementType.SELECT);
+ Cursor cursor = compiledStatement.getCursor();
+
+ return cursor;
}
- private Cursor getWord(Uri uri) {
- String rowId = uri.getLastPathSegment();
- String[] columns = new String[] { DictionaryDatabase.KEY_WORD, DictionaryDatabase.KEY_DEFINITION };
+ private Cursor getBuilding(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 mDictionary.getWord(rowId, columns);
+ return cursor;
}
- private Cursor refreshShortcut(Uri uri) {
+ 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
@@ -153,12 +233,18 @@ public class MapContentProvider extends ContentProvider {
* 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 };
+ 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 mDictionary.getWord(rowId, columns);
+ return cursor;
}
/**
@@ -168,10 +254,22 @@ public class MapContentProvider extends ContentProvider {
@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_BUILDINGS:
+ return BUILDINGS_MIME_TYPE;
+ case GET_BUILDING:
+ return BUILDING_MIME_TYPE;
+ case SEARCH_BUS_STOPS:
+ return BUS_STOPS_MIME_TYPE;
+ case GET_BUS_STOP:
+ return BUS_STOP_MIME_TYPE;
+ case SEARCH_SITES:
+ return SITES_MIME_TYPE;
+ case GET_SITE:
+ return SITE_MIME_TYPE;
+ case SEARCH_BUSES:
+ return BUSES_MIME_TYPE;
+ case GET_BUS:
+ return BUS_MIME_TYPE;
case SEARCH_SUGGEST:
return SearchManager.SUGGEST_MIME_TYPE;
case REFRESH_SHORTCUT:
diff --git a/src/net/cbaines/suma/POI.java b/src/net/cbaines/suma/POI.java
index 485845c..f8c1f89 100644
--- a/src/net/cbaines/suma/POI.java
+++ b/src/net/cbaines/suma/POI.java
@@ -25,54 +25,55 @@ import com.j256.ormlite.field.DataType;
import com.j256.ormlite.field.DatabaseField;
public abstract class POI {
- public static final String BUS_STOP = "busstop";
- public static final String BUILDING = "building";
- public static final String WAYPOINT = "waypoint";
- public static final String SITE = "site";
+ public static final String BUS_STOP = "busstop";
+ public static final String BUILDING = "building";
+ public static final String WAYPOINT = "waypoint";
+ public static final String SITE = "site";
- public static final String ID_FIELD_NAME = "id";
- public static final String POINT_FIELD_NAME = "point";
+ public static final String ID_FIELD_NAME = "id";
+ public static final String POINT_FIELD_NAME = "point";
- POI() {
- }
+ POI() {
+ }
- public POI(String id, GeoPoint point) {
- this.id = id;
- this.point = point;
- }
+ public POI(String id, GeoPoint point) {
+ this.id = id;
+ this.point = point;
+ }
- @DatabaseField(dataType = DataType.SERIALIZABLE, canBeNull = false)
- public GeoPoint point;
+ @DatabaseField(dataType = DataType.SERIALIZABLE, canBeNull = false)
+ public GeoPoint point;
- @DatabaseField(id = true)
- public String id;
+ @DatabaseField(id = true)
+ public String id;
- public int distTo = -1; // Used by the comparator to store distances, then later by the gui to display them.
+ public int distTo = -1; // Used by the comparator to store distances, then
+ // later by the gui to display them.
- public String type;
+ public String type;
- @Override
- public int hashCode() {
- final int prime = 31;
- int result = 1;
- result = prime * result + ((id == null) ? 0 : id.hashCode());
- return result;
- }
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + ((id == null) ? 0 : id.hashCode());
+ return result;
+ }
- @Override
- public boolean equals(Object obj) {
- if (this == obj)
- return true;
- if (obj == null)
- return false;
- if (getClass() != obj.getClass())
- return false;
- POI other = (POI) obj;
- if (id == null) {
- if (other.id != null)
- return false;
- } else if (!id.equals(other.id))
- return false;
- return true;
- }
+ @Override
+ public boolean equals(Object obj) {
+ if (this == obj)
+ return true;
+ if (obj == null)
+ return false;
+ if (getClass() != obj.getClass())
+ return false;
+ POI other = (POI) obj;
+ if (id == null) {
+ if (other.id != null)
+ return false;
+ } else if (!id.equals(other.id))
+ return false;
+ return true;
+ }
}