aboutsummaryrefslogtreecommitdiff
path: root/src/net
diff options
context:
space:
mode:
authorChristopher Baines <cbaines8@gmail.com>2012-03-11 13:37:46 +0000
committerChristopher Baines <cbaines8@gmail.com>2012-03-11 13:37:46 +0000
commitacbff20cc3eb148621e1ffed9b06d17a2a1f53ce (patch)
treed249ffc6e531887760209b71cf4c3b0837b82dab /src/net
parent264b93bd42753d66dbcaea74ed2024ecb757b5f7 (diff)
parent120ca654b0476a628d2d53e709804066ecb73992 (diff)
downloadsouthamptonuniversitymap-acbff20cc3eb148621e1ffed9b06d17a2a1f53ce.tar
southamptonuniversitymap-acbff20cc3eb148621e1ffed9b06d17a2a1f53ce.tar.gz
Merge branch 'dev' of github.com:cbaines/SouthamptonUniversityMap into dev
Conflicts: AndroidManifest.xml src/net/cbaines/suma/MapActivity.java
Diffstat (limited to 'src/net')
-rw-r--r--src/net/cbaines/suma/MapActivity.java134
-rw-r--r--src/net/cbaines/suma/MapContentProvider.java120
-rw-r--r--src/net/cbaines/suma/POIArrayAdapter.java2
-rw-r--r--src/net/cbaines/suma/SearchResultsActivity.java12
4 files changed, 214 insertions, 54 deletions
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);