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.java195
1 files changed, 64 insertions, 131 deletions
diff --git a/src/net/cbaines/suma/MapActivity.java b/src/net/cbaines/suma/MapActivity.java
index 334f4d2..33b12cd 100644
--- a/src/net/cbaines/suma/MapActivity.java
+++ b/src/net/cbaines/suma/MapActivity.java
@@ -70,9 +70,8 @@ import com.j256.ormlite.dao.Dao;
* @author Christopher Baines <cbaines8@gmail.com>
*
*/
-public class MapActivity extends OrmLiteBaseActivity<DatabaseHelper> implements MapViewConstants, Runnable,
- RouteColorConstants, OnItemClickListener, OnItemLongClickListener, OnSharedPreferenceChangeListener,
- Preferences {
+public class MapActivity extends OrmLiteBaseActivity<DatabaseHelper> implements MapViewConstants, Runnable, RouteColorConstants,
+ OnItemClickListener, OnItemLongClickListener, OnSharedPreferenceChangeListener, Preferences {
/**
* Enable to use the database in the assets folder, if its not enabled, the
@@ -126,11 +125,10 @@ public class MapActivity extends OrmLiteBaseActivity<DatabaseHelper> implements
private static final int NON_UNI_LINK_BUS_STOP_OVERLAY_RANK = 4;
// -- Site Overlays
- static final String[] SITE_NAMES = { "Highfield Campus", "Boldrewood Campus", "Avenue Campus",
- "Winchester School of Art", "The University of Southampton Science Park",
- "National Oceanography Centre Campus", "Boat House", "Southampton General Hospital",
- "Royal South Hants Hospital", "Belgrave Industrial Site", "Highfield Hall", "Glen Eyre Hall",
- "South Hill Hall", "Chamberlain Hall", "Hartley Grove", "Bencraft Hall", "Connaught Hall",
+ static final String[] SITE_NAMES = { "Highfield Campus", "Boldrewood Campus", "Avenue Campus", "Winchester School of Art",
+ "The University of Southampton Science Park", "National Oceanography Centre Campus", "Boat House",
+ "Southampton General Hospital", "Royal South Hants Hospital", "Belgrave Industrial Site", "Highfield Hall",
+ "Glen Eyre Hall", "South Hill Hall", "Chamberlain Hall", "Hartley Grove", "Bencraft Hall", "Connaught Hall",
"Montefiore Hall", "Stoneham Hall", "Erasmus Park" };
private static final String SITE_OVERLAYS = "siteOverlays:";
@@ -168,8 +166,8 @@ public class MapActivity extends OrmLiteBaseActivity<DatabaseHelper> implements
// Uni-Link routes
static final String[] UNI_LINK_ROUTES = { "U1", "U1N", "U2", "U6", "U9" };
- static final String[] PREFERENCES_GROUPS = { BUS_STOP_OVERLAYS, BUS_ROUTE_OVERLAYS, BUILDING_OVERLAYS,
- SITE_OVERLAYS, OTHER_OVERLAYS };
+ static final String[] PREFERENCES_GROUPS = { BUS_STOP_OVERLAYS, BUS_ROUTE_OVERLAYS, BUILDING_OVERLAYS, SITE_OVERLAYS,
+ OTHER_OVERLAYS };
static final String[][] PREFERENCES_CHILDREN = { UNI_LINK_ROUTES, UNI_LINK_ROUTES, BUILDING_TYPES, SITE_NAMES,
OTHER_OVERLAY_NAMES };
@@ -259,12 +257,6 @@ public class MapActivity extends OrmLiteBaseActivity<DatabaseHelper> implements
mapController.setCenter(userLocation);
Log.i(TAG, "Finished onCreate " + (System.currentTimeMillis() - startTime));
-
- new Thread() {
- public void run() {
- DataManager.loadBuildingPhotos(instance);
- }
- }.start();
}
public void onResume() {
@@ -503,8 +495,7 @@ public class MapActivity extends OrmLiteBaseActivity<DatabaseHelper> implements
if (scaleBarOverlay != null) {
Log.v(TAG, "ScaleBarOverlay is already created");
} else {
- if (pastOverlays != null
- && (scaleBarOverlay = (ScaleBarOverlay) pastOverlays.get(SCALE_BAR_OVERLAY)) != null) {
+ if (pastOverlays != null && (scaleBarOverlay = (ScaleBarOverlay) pastOverlays.get(SCALE_BAR_OVERLAY)) != null) {
Log.i(TAG, "Finished restoring utility overlays " + (System.currentTimeMillis() - startTime));
} else {
scaleBarOverlay = new ScaleBarOverlay(instance);
@@ -533,8 +524,7 @@ public class MapActivity extends OrmLiteBaseActivity<DatabaseHelper> implements
private void showRouteOverlay(final BusRoute route) {
new Thread(new Runnable() {
public void run() {
- Log.i(TAG, "Begining showing route " + route.code + " overlay at "
- + (System.currentTimeMillis() - startTime));
+ Log.i(TAG, "Begining showing route " + route.code + " overlay at " + (System.currentTimeMillis() - startTime));
final SharedPreferences activityPrefs = getPreferences(0);
final OverlayRankComparator comparator = new OverlayRankComparator(getPreferences(0));
@@ -559,8 +549,8 @@ public class MapActivity extends OrmLiteBaseActivity<DatabaseHelper> implements
// TODO Is this a route like U1N or, something else,
// this hack works somewhat for now?
- PathOverlay routeOverlayU1E = DataManager.getRoutePath(
- getResources().openRawResource(R.raw.u1e), colour, mResourceProxy);
+ PathOverlay routeOverlayU1E = DataManager.getRoutePath(getResources().openRawResource(R.raw.u1e),
+ colour, mResourceProxy);
routeOverlayU1E.getPaint().setAntiAlias(true);
routeOverlayU1E.getPaint().setAlpha(145);
routeOverlayU1E.getPaint().setStrokeWidth(12);
@@ -613,8 +603,7 @@ public class MapActivity extends OrmLiteBaseActivity<DatabaseHelper> implements
mapView.postInvalidate();
- Log.i(TAG, "Finished showing route " + route.code + " overlay at "
- + (System.currentTimeMillis() - startTime));
+ Log.i(TAG, "Finished showing route " + route.code + " overlay at " + (System.currentTimeMillis() - startTime));
}
}).start();
}
@@ -623,8 +612,7 @@ public class MapActivity extends OrmLiteBaseActivity<DatabaseHelper> implements
new Thread(new Runnable() {
public void run() {
- Log.i(TAG, "Begining showing site " + site.name + " overlay at "
- + (System.currentTimeMillis() - startTime));
+ Log.i(TAG, "Begining showing site " + site.name + " overlay at " + (System.currentTimeMillis() - startTime));
final SharedPreferences activityPrefs = getPreferences(0);
final OverlayRankComparator comparator = new OverlayRankComparator(getPreferences(0));
@@ -633,8 +621,7 @@ public class MapActivity extends OrmLiteBaseActivity<DatabaseHelper> implements
if ((siteOverlay = siteOverlays.get(site)) != null) {
} else {
- if (pastOverlays != null
- && (siteOverlay = (PathOverlay) pastOverlays.get(SITE_OVERLAYS + site.name)) != null) {
+ if (pastOverlays != null && (siteOverlay = (PathOverlay) pastOverlays.get(SITE_OVERLAYS + site.name)) != null) {
Log.i(TAG, "Restored " + site.name + " site overlay");
} else {
@@ -660,13 +647,11 @@ public class MapActivity extends OrmLiteBaseActivity<DatabaseHelper> implements
}
}
- siteOverlay.setEnabled(activityPrefs.getBoolean(SITE_OVERLAYS + site.name,
- SITE_OVERLAYS_ENABLED_BY_DEFAULT));
+ siteOverlay.setEnabled(activityPrefs.getBoolean(SITE_OVERLAYS + site.name, SITE_OVERLAYS_ENABLED_BY_DEFAULT));
mapView.postInvalidate();
- Log.i(TAG, "Finished showing site " + site.name + " overlay at "
- + (System.currentTimeMillis() - startTime));
+ Log.i(TAG, "Finished showing site " + site.name + " overlay at " + (System.currentTimeMillis() - startTime));
}
}).start();
}
@@ -683,10 +668,8 @@ public class MapActivity extends OrmLiteBaseActivity<DatabaseHelper> implements
} else {
if (pastOverlays != null
- && (residentialBuildingOverlay = (BuildingNumOverlay) pastOverlays
- .get(RESIDENTIAL_BUILDING_OVERLAY)) != null) {
- nonResidentialBuildingOverlay = (BuildingNumOverlay) pastOverlays
- .get(NON_RESIDENTIAL_BUILDING_OVERLAY);
+ && (residentialBuildingOverlay = (BuildingNumOverlay) pastOverlays.get(RESIDENTIAL_BUILDING_OVERLAY)) != null) {
+ nonResidentialBuildingOverlay = (BuildingNumOverlay) pastOverlays.get(NON_RESIDENTIAL_BUILDING_OVERLAY);
Log.i(TAG, "Restored building overlays");
} else {
@@ -701,15 +684,17 @@ public class MapActivity extends OrmLiteBaseActivity<DatabaseHelper> implements
buildingDao = getHelper().getBuildingDao();
+ final SharedPreferences favouritesPrefs = getSharedPreferences(FAVOURITES_PREFERENCES, 0);
+
for (Building building : buildingDao) {
if (building.residential == true) {
- if (building.favourite) {
+ if (favouritesPrefs.getBoolean(building.id, false)) {
residentialBuildings.add(building);
} else {
residentialBuildings.add(0, building);
}
} else {
- if (building.favourite) {
+ if (favouritesPrefs.getBoolean(building.id, false)) {
nonResidentialBuildings.add(building);
} else {
nonResidentialBuildings.add(0, building);
@@ -737,8 +722,8 @@ public class MapActivity extends OrmLiteBaseActivity<DatabaseHelper> implements
}
}
- residentialBuildingOverlay.setEnabled(activityPrefs.getBoolean(BUILDING_OVERLAYS
- + RESIDENTIAL_BUILDING_OVERLAY, RESIDENTIAL_BUILDING_OVERLAY_ENABLED_BY_DEFAULT));
+ residentialBuildingOverlay.setEnabled(activityPrefs.getBoolean(BUILDING_OVERLAYS + RESIDENTIAL_BUILDING_OVERLAY,
+ RESIDENTIAL_BUILDING_OVERLAY_ENABLED_BY_DEFAULT));
nonResidentialBuildingOverlay.setEnabled(activityPrefs.getBoolean(BUILDING_OVERLAYS
+ NON_RESIDENTIAL_BUILDING_OVERLAY, NON_RESIDENTIAL_BUILDING_OVERLAY_ENABLED_BY_DEFAULT));
@@ -758,16 +743,11 @@ public class MapActivity extends OrmLiteBaseActivity<DatabaseHelper> implements
final OverlayRankComparator comparator = new OverlayRankComparator(getPreferences(0));
if (uniLinkBusStopOverlay != null) {
- if (!activityPrefs.getBoolean(BUS_STOP_OVERLAYS + "U1",
- UNI_LINK_BUS_STOP_OVERLAY_ENABLED_BY_DEFAULT)
- && !activityPrefs.getBoolean(BUS_STOP_OVERLAYS + "U1N",
- UNI_LINK_BUS_STOP_OVERLAY_ENABLED_BY_DEFAULT)
- && !activityPrefs.getBoolean(BUS_STOP_OVERLAYS + "U2",
- UNI_LINK_BUS_STOP_OVERLAY_ENABLED_BY_DEFAULT)
- && !activityPrefs.getBoolean(BUS_STOP_OVERLAYS + "U6",
- UNI_LINK_BUS_STOP_OVERLAY_ENABLED_BY_DEFAULT)
- && !activityPrefs.getBoolean(BUS_STOP_OVERLAYS + "U9",
- UNI_LINK_BUS_STOP_OVERLAY_ENABLED_BY_DEFAULT)) {
+ if (!activityPrefs.getBoolean(BUS_STOP_OVERLAYS + "U1", UNI_LINK_BUS_STOP_OVERLAY_ENABLED_BY_DEFAULT)
+ && !activityPrefs.getBoolean(BUS_STOP_OVERLAYS + "U1N", UNI_LINK_BUS_STOP_OVERLAY_ENABLED_BY_DEFAULT)
+ && !activityPrefs.getBoolean(BUS_STOP_OVERLAYS + "U2", UNI_LINK_BUS_STOP_OVERLAY_ENABLED_BY_DEFAULT)
+ && !activityPrefs.getBoolean(BUS_STOP_OVERLAYS + "U6", UNI_LINK_BUS_STOP_OVERLAY_ENABLED_BY_DEFAULT)
+ && !activityPrefs.getBoolean(BUS_STOP_OVERLAYS + "U9", UNI_LINK_BUS_STOP_OVERLAY_ENABLED_BY_DEFAULT)) {
Log.i(TAG, "Uni-Link bus stop overlay not needed");
overlays.remove(UNI_LINK_BUS_STOP_OVERLAY);
@@ -778,31 +758,25 @@ public class MapActivity extends OrmLiteBaseActivity<DatabaseHelper> implements
uniLinkBusStopOverlay = null;
} else {
- uniLinkBusStopOverlay.setRoutes(0, activityPrefs.getBoolean(BUS_STOP_OVERLAYS + "U1",
- UNI_LINK_BUS_STOP_OVERLAY_ENABLED_BY_DEFAULT));
- uniLinkBusStopOverlay.setRoutes(1, activityPrefs.getBoolean(BUS_STOP_OVERLAYS + "U1N",
- UNI_LINK_BUS_STOP_OVERLAY_ENABLED_BY_DEFAULT));
- uniLinkBusStopOverlay.setRoutes(2, activityPrefs.getBoolean(BUS_STOP_OVERLAYS + "U2",
- UNI_LINK_BUS_STOP_OVERLAY_ENABLED_BY_DEFAULT));
- uniLinkBusStopOverlay.setRoutes(3, activityPrefs.getBoolean(BUS_STOP_OVERLAYS + "U6",
- UNI_LINK_BUS_STOP_OVERLAY_ENABLED_BY_DEFAULT));
- uniLinkBusStopOverlay.setRoutes(4, activityPrefs.getBoolean(BUS_STOP_OVERLAYS + "U9",
- UNI_LINK_BUS_STOP_OVERLAY_ENABLED_BY_DEFAULT));
+ uniLinkBusStopOverlay.setRoutes(0,
+ activityPrefs.getBoolean(BUS_STOP_OVERLAYS + "U1", UNI_LINK_BUS_STOP_OVERLAY_ENABLED_BY_DEFAULT));
+ uniLinkBusStopOverlay.setRoutes(1,
+ activityPrefs.getBoolean(BUS_STOP_OVERLAYS + "U1N", UNI_LINK_BUS_STOP_OVERLAY_ENABLED_BY_DEFAULT));
+ uniLinkBusStopOverlay.setRoutes(2,
+ activityPrefs.getBoolean(BUS_STOP_OVERLAYS + "U2", UNI_LINK_BUS_STOP_OVERLAY_ENABLED_BY_DEFAULT));
+ uniLinkBusStopOverlay.setRoutes(3,
+ activityPrefs.getBoolean(BUS_STOP_OVERLAYS + "U6", UNI_LINK_BUS_STOP_OVERLAY_ENABLED_BY_DEFAULT));
+ uniLinkBusStopOverlay.setRoutes(4,
+ activityPrefs.getBoolean(BUS_STOP_OVERLAYS + "U9", UNI_LINK_BUS_STOP_OVERLAY_ENABLED_BY_DEFAULT));
}
} else {
- if (activityPrefs
- .getBoolean(BUS_STOP_OVERLAYS + "U1", UNI_LINK_BUS_STOP_OVERLAY_ENABLED_BY_DEFAULT)
- || activityPrefs.getBoolean(BUS_STOP_OVERLAYS + "U1N",
- UNI_LINK_BUS_STOP_OVERLAY_ENABLED_BY_DEFAULT)
- || activityPrefs.getBoolean(BUS_STOP_OVERLAYS + "U2",
- UNI_LINK_BUS_STOP_OVERLAY_ENABLED_BY_DEFAULT)
- || activityPrefs.getBoolean(BUS_STOP_OVERLAYS + "U6",
- UNI_LINK_BUS_STOP_OVERLAY_ENABLED_BY_DEFAULT)
- || activityPrefs.getBoolean(BUS_STOP_OVERLAYS + "U9",
- UNI_LINK_BUS_STOP_OVERLAY_ENABLED_BY_DEFAULT)) {
+ if (activityPrefs.getBoolean(BUS_STOP_OVERLAYS + "U1", UNI_LINK_BUS_STOP_OVERLAY_ENABLED_BY_DEFAULT)
+ || activityPrefs.getBoolean(BUS_STOP_OVERLAYS + "U1N", UNI_LINK_BUS_STOP_OVERLAY_ENABLED_BY_DEFAULT)
+ || activityPrefs.getBoolean(BUS_STOP_OVERLAYS + "U2", UNI_LINK_BUS_STOP_OVERLAY_ENABLED_BY_DEFAULT)
+ || activityPrefs.getBoolean(BUS_STOP_OVERLAYS + "U6", UNI_LINK_BUS_STOP_OVERLAY_ENABLED_BY_DEFAULT)
+ || activityPrefs.getBoolean(BUS_STOP_OVERLAYS + "U9", UNI_LINK_BUS_STOP_OVERLAY_ENABLED_BY_DEFAULT)) {
if (pastOverlays != null
- && (uniLinkBusStopOverlay = (BusStopOverlay) pastOverlays
- .get(UNI_LINK_BUS_STOP_OVERLAY)) != null) {
+ && (uniLinkBusStopOverlay = (BusStopOverlay) pastOverlays.get(UNI_LINK_BUS_STOP_OVERLAY)) != null) {
Log.i(TAG, "Restored Uni-Link bus stop overlay");
} else {
@@ -820,16 +794,16 @@ public class MapActivity extends OrmLiteBaseActivity<DatabaseHelper> implements
}
}
- uniLinkBusStopOverlay.setRoutes(0, activityPrefs.getBoolean(BUS_STOP_OVERLAYS + "U1",
- UNI_LINK_BUS_STOP_OVERLAY_ENABLED_BY_DEFAULT));
- uniLinkBusStopOverlay.setRoutes(1, activityPrefs.getBoolean(BUS_STOP_OVERLAYS + "U1N",
- UNI_LINK_BUS_STOP_OVERLAY_ENABLED_BY_DEFAULT));
- uniLinkBusStopOverlay.setRoutes(2, activityPrefs.getBoolean(BUS_STOP_OVERLAYS + "U2",
- UNI_LINK_BUS_STOP_OVERLAY_ENABLED_BY_DEFAULT));
- uniLinkBusStopOverlay.setRoutes(3, activityPrefs.getBoolean(BUS_STOP_OVERLAYS + "U6",
- UNI_LINK_BUS_STOP_OVERLAY_ENABLED_BY_DEFAULT));
- uniLinkBusStopOverlay.setRoutes(4, activityPrefs.getBoolean(BUS_STOP_OVERLAYS + "U9",
- UNI_LINK_BUS_STOP_OVERLAY_ENABLED_BY_DEFAULT));
+ uniLinkBusStopOverlay.setRoutes(0,
+ activityPrefs.getBoolean(BUS_STOP_OVERLAYS + "U1", UNI_LINK_BUS_STOP_OVERLAY_ENABLED_BY_DEFAULT));
+ uniLinkBusStopOverlay.setRoutes(1,
+ activityPrefs.getBoolean(BUS_STOP_OVERLAYS + "U1N", UNI_LINK_BUS_STOP_OVERLAY_ENABLED_BY_DEFAULT));
+ uniLinkBusStopOverlay.setRoutes(2,
+ activityPrefs.getBoolean(BUS_STOP_OVERLAYS + "U2", UNI_LINK_BUS_STOP_OVERLAY_ENABLED_BY_DEFAULT));
+ uniLinkBusStopOverlay.setRoutes(3,
+ activityPrefs.getBoolean(BUS_STOP_OVERLAYS + "U6", UNI_LINK_BUS_STOP_OVERLAY_ENABLED_BY_DEFAULT));
+ uniLinkBusStopOverlay.setRoutes(4,
+ activityPrefs.getBoolean(BUS_STOP_OVERLAYS + "U9", UNI_LINK_BUS_STOP_OVERLAY_ENABLED_BY_DEFAULT));
overlays.put(UNI_LINK_BUS_STOP_OVERLAY, uniLinkBusStopOverlay);
@@ -852,8 +826,7 @@ public class MapActivity extends OrmLiteBaseActivity<DatabaseHelper> implements
private void showNonUniLinkBusStopOverlay() {
new Thread(new Runnable() {
public void run() {
- Log.i(TAG, "Begining showing non uni link bus stop overlays at "
- + (System.currentTimeMillis() - startTime));
+ Log.i(TAG, "Begining showing non uni link bus stop overlays at " + (System.currentTimeMillis() - startTime));
// final SharedPreferences activityPrefs = getPreferences(0);
final SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(instance);
@@ -870,14 +843,12 @@ public class MapActivity extends OrmLiteBaseActivity<DatabaseHelper> implements
} else if (sharedPrefs.getBoolean(NON_UNI_LINK_BUS_STOPS_OVERLAY,
NON_UNI_LINK_BUS_STOP_OVERLAY_ENABLED_BY_DEFAULT)) {
if (pastOverlays != null
- && (nonUniLinkBusStopOverlay = (BusStopOverlay) pastOverlays
- .get(NON_UNI_LINK_BUS_STOPS_OVERLAY)) != null) {
+ && (nonUniLinkBusStopOverlay = (BusStopOverlay) pastOverlays.get(NON_UNI_LINK_BUS_STOPS_OVERLAY)) != null) {
Log.i(TAG, "Restored non Uni-Link bus stop overlays");
} else {
try {
List<BusStop> busStops;
- Log.v(TAG, "Begin fetching non Uni-Link BusStops at "
- + (System.currentTimeMillis() - startTime));
+ Log.v(TAG, "Begin fetching non Uni-Link BusStops at " + (System.currentTimeMillis() - startTime));
busStops = getHelper().getBusStopDao().queryForEq(BusStop.UNI_LINK_FIELD_NAME, false);
@@ -907,8 +878,7 @@ public class MapActivity extends OrmLiteBaseActivity<DatabaseHelper> implements
mapView.postInvalidate();
- Log.i(TAG, "Finished showing non Uni-Link bus stop overlays at "
- + (System.currentTimeMillis() - startTime));
+ Log.i(TAG, "Finished showing non Uni-Link bus stop overlays at " + (System.currentTimeMillis() - startTime));
}
}).start();
}
@@ -959,9 +929,8 @@ public class MapActivity extends OrmLiteBaseActivity<DatabaseHelper> implements
};
AlertDialog.Builder builder = new AlertDialog.Builder(this);
- builder.setMessage("GPS is not enabled, do you wish to enable it?")
- .setPositiveButton("Yes", dialogClickListener).setNegativeButton("No", dialogClickListener)
- .show();
+ builder.setMessage("GPS is not enabled, do you wish to enable it?").setPositiveButton("Yes", dialogClickListener)
+ .setNegativeButton("No", dialogClickListener).show();
}
return true;
@@ -1056,49 +1025,13 @@ public class MapActivity extends OrmLiteBaseActivity<DatabaseHelper> implements
}
} else {
Log.i(TAG, "Got null poi id");
-
- // mapController.setZoom(15);
- // mapController.setCenter(new GeoPoint(50935551,
- // -1393488));
- }
-
- // This handles the possible change in favourite state caused by
- // the user within the BusTimeActivity
- try {
- String busStopID = bundle.getString("busStopChanged");
- if (busStopID != null && busStopID.length() != 0) {
- Log.v(TAG, "Got a busStop id back from the BusTimeActivity " + busStopID);
- BusStop busStop = getHelper().getBusStopDao().queryForId(busStopID);
-
- if (busStop.uniLink) {
- uniLinkBusStopOverlay.refresh(busStop); // This does
- // not
- // invalidate
- // the map,
- // but it
- // seems to
- // make the changes appear
- } else {
- nonUniLinkBusStopOverlay.refresh(busStop); // This
- // does
- // not
- // invalidate
- // the
- // map,
- // but
- // it
- // seems
- // to
- // make the changes appear
- }
- }
- } catch (SQLException e) {
- e.printStackTrace();
}
if (favDialog != null) {
refreshFavouriteDialog();
}
+
+ mapView.invalidate();
}
}