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.java43
1 files changed, 34 insertions, 9 deletions
diff --git a/src/net/cbaines/suma/MapActivity.java b/src/net/cbaines/suma/MapActivity.java
index 14a1dd4..07806fa 100644
--- a/src/net/cbaines/suma/MapActivity.java
+++ b/src/net/cbaines/suma/MapActivity.java
@@ -159,7 +159,7 @@ public class MapActivity extends OrmLiteBaseActivity<DatabaseHelper> implements
static final boolean MY_LOCATION_OVERLAY_COMPASS_ENABLED_BY_DEFAULT = true;
private static final int MY_LOCATION_OVERLAY_RANK = 2;
- static final String[] OTHER_OVERLAY_NAMES = { SCALE_BAR_OVERLAY, MY_LOCATION_OVERLAY, MY_LOCATION_OVERLAY_COMPASS };
+ static final String[] OTHER_OVERLAY_NAMES = { SCALE_BAR_OVERLAY, MY_LOCATION_OVERLAY_COMPASS, MY_LOCATION_OVERLAY };
// Other bits
@@ -209,6 +209,7 @@ public class MapActivity extends OrmLiteBaseActivity<DatabaseHelper> implements
*/
Log.i(TAG, "Starting creating myLocationOverlay");
myLocationOverlay = new MyLocationOverlay(instance, mapView);
+ myLocationOverlay.setEnabled(true);
Log.i(TAG, "Finished creating myLocationOverlay");
while (databaseThread.isAlive()) {
@@ -263,14 +264,15 @@ public class MapActivity extends OrmLiteBaseActivity<DatabaseHelper> implements
final SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(this);
final SharedPreferences activityPrefs = getPreferences(0);
- if (activityPrefs.getBoolean(OTHER_OVERLAYS + MY_LOCATION_OVERLAY_COMPASS, false)) {
+ if (activityPrefs.getBoolean(OTHER_OVERLAYS + MY_LOCATION_OVERLAY_COMPASS,
+ MY_LOCATION_OVERLAY_COMPASS_ENABLED_BY_DEFAULT)) {
myLocationOverlay.enableCompass();
} else {
myLocationOverlay.disableCompass();
}
- if (activityPrefs.getBoolean(OTHER_OVERLAYS + MY_LOCATION_OVERLAY, false)
- && sharedPrefs.getBoolean(GPS_ENABLED, false)) {
+ if (activityPrefs.getBoolean(OTHER_OVERLAYS + MY_LOCATION_OVERLAY, MY_LOCATION_OVERLAY_ENABLED_BY_DEFAULT)
+ && sharedPrefs.getBoolean(GPS_ENABLED, GPS_ENABLED_BY_DEFAULT)) {
myLocationOverlay.enableMyLocation();
} else {
myLocationOverlay.disableMyLocation();
@@ -683,7 +685,7 @@ public class MapActivity extends OrmLiteBaseActivity<DatabaseHelper> implements
buildingDao = getHelper().getBuildingDao();
- final SharedPreferences favouritesPrefs = getSharedPreferences(FAVOURITES_PREFERENCES, 0);
+ final SharedPreferences favouritesPrefs = getSharedPreferences(FAVOURITES_PREFERENCES, MODE_PRIVATE);
for (Building building : buildingDao) {
if (building.residential == true) {
@@ -903,8 +905,10 @@ public class MapActivity extends OrmLiteBaseActivity<DatabaseHelper> implements
return true;
case R.id.menu_find_my_location:
final SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(this);
- if (sharedPrefs.getBoolean("GPSEnabled", false)) {
+ if (sharedPrefs.getBoolean(GPS_ENABLED, GPS_ENABLED_BY_DEFAULT)) {
+ myLocationOverlay.enableMyLocation();
GeoPoint userLocation = myLocationOverlay.getMyLocation();
+ sharedPrefs.edit().putBoolean(MY_LOCATION_OVERLAY, true).commit();
if (userLocation != null) {
Log.i(TAG, "Found user location, scrolling to " + userLocation);
mapController.animateTo(userLocation);
@@ -916,8 +920,17 @@ public class MapActivity extends OrmLiteBaseActivity<DatabaseHelper> implements
switch (which) {
case DialogInterface.BUTTON_POSITIVE:
Editor editor = sharedPrefs.edit();
- editor.putBoolean("GPSEnabled", true);
+ editor.putBoolean(GPS_ENABLED, true);
editor.commit();
+
+ myLocationOverlay.enableMyLocation();
+ GeoPoint userLocation = myLocationOverlay.getMyLocation();
+ sharedPrefs.edit().putBoolean(MY_LOCATION_OVERLAY, true).commit();
+ if (userLocation != null) {
+ Log.i(TAG, "Found user location, scrolling to " + userLocation);
+ mapController.animateTo(userLocation);
+ myLocationOverlay.enableFollowLocation();
+ }
break;
case DialogInterface.BUTTON_NEGATIVE:
@@ -966,8 +979,18 @@ public class MapActivity extends OrmLiteBaseActivity<DatabaseHelper> implements
Dao<Building, String> buildingDao = getHelper().getBuildingDao();
Dao<BusStop, String> busStopDao = getHelper().getBusStopDao();
- newFavouriteItems.addAll(buildingDao.queryForEq(POI.FAVOURITE_FIELD_NAME, true));
- newFavouriteItems.addAll(busStopDao.queryForEq(POI.FAVOURITE_FIELD_NAME, true));
+ 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();
}
@@ -1253,6 +1276,7 @@ public class MapActivity extends OrmLiteBaseActivity<DatabaseHelper> implements
} else {
myLocationOverlay.disableCompass();
}
+ mapView.invalidate();
} else if (key.substring(OTHER_OVERLAYS.length(), key.length()).equals(MY_LOCATION_OVERLAY)) {
final SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(this);
@@ -1262,6 +1286,7 @@ public class MapActivity extends OrmLiteBaseActivity<DatabaseHelper> implements
} else {
myLocationOverlay.disableMyLocation();
}
+ mapView.invalidate();
} else {
Log.e(TAG, "Unhandled preference key " + key);
}