aboutsummaryrefslogtreecommitdiff
path: root/src/net/cbaines/suma/MapActivity.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/net/cbaines/suma/MapActivity.java')
-rw-r--r--src/net/cbaines/suma/MapActivity.java134
1 files changed, 106 insertions, 28 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 {