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.java280
1 files changed, 180 insertions, 100 deletions
diff --git a/src/net/cbaines/suma/MapActivity.java b/src/net/cbaines/suma/MapActivity.java
index 5db0a74..4d9eddc 100644
--- a/src/net/cbaines/suma/MapActivity.java
+++ b/src/net/cbaines/suma/MapActivity.java
@@ -65,10 +65,20 @@ import android.widget.Toast;
import com.j256.ormlite.android.apptools.OrmLiteBaseActivity;
import com.j256.ormlite.dao.Dao;
-public class MapActivity extends OrmLiteBaseActivity<DatabaseHelper> implements MapViewConstants, Runnable, RouteColorConstants, OnItemClickListener,
- OnItemLongClickListener, OnSharedPreferenceChangeListener, Preferences {
+/**
+ *
+ * @author Christopher Baines <cbaines8@gmail.com>
+ *
+ */
+public class MapActivity extends OrmLiteBaseActivity<DatabaseHelper> implements MapViewConstants, Runnable,
+ RouteColorConstants, OnItemClickListener, OnItemLongClickListener, OnSharedPreferenceChangeListener,
+ Preferences {
- private boolean useBundledDatabase = true;
+ /**
+ * Enable to use the database in the assets folder, if its not enabled, the database is built from the csv files in
+ * the assets folder
+ */
+ private boolean useBundledDatabase = false;
private MapView mapView;
private MapController mapController;
@@ -78,62 +88,98 @@ public class MapActivity extends OrmLiteBaseActivity<DatabaseHelper> implements
static final int VIEW_DIALOG_ID = 0;
static final int FAVOURITE_DIALOG_ID = 1;
+ private POIDialog favDialog;
private HashMap<String, Overlay> overlays = new HashMap<String, Overlay>();
private HashMap<String, Overlay> pastOverlays;
// Overlays
- // Scale Bar Overlay
- private static final String SCALE_BAR_OVERLAY = "scaleBarOverlay";
- private ScaleBarOverlay scaleBarOverlay;
- static final boolean SCALE_BAR_OVERLAY_ENABLED_BY_DEFAULT = true;
- private static final int SCALE_BAR_OVERLAY_RANK = 1;
-
- // My Location Overlay
- private static final String MY_LOCATION_OVERLAY = "myLocationOverlay";
- private MyLocationOverlay myLocationOverlay;
- static final boolean MY_LOCATION_OVERLAY_ENABLED_BY_DEFAULT = true;
- private static final int MY_LOCATION_OVERLAY_RANK = 1;
+ // -- Building Overlays
+ static final String BUILDING_OVERLAYS = "buildingOverlays:";
- // Residential Building Overlay
+ // ---- Residential Building Overlay
private static final String RESIDENTIAL_BUILDING_OVERLAY = "residentialBuildingOverlay";
private BuildingNumOverlay residentialBuildingOverlay;
static final boolean RESIDENTIAL_BUILDING_OVERLAY_ENABLED_BY_DEFAULT = true;
- private static final int RESIDENTIAL_BUILDING_OVERLAY_RANK = 1;
+ private static final int RESIDENTIAL_BUILDING_OVERLAY_RANK = 6;
- // Non-Residential Building Overlay
+ // ---- Non-Residential Building Overlay
private static final String NON_RESIDENTIAL_BUILDING_OVERLAY = "nonResidentialBuildingOverlay";
private BuildingNumOverlay nonResidentialBuildingOverlay;
static final boolean NON_RESIDENTIAL_BUILDING_OVERLAY_ENABLED_BY_DEFAULT = true;
- private static final int NON_RESIDENTIAL_BUILDING_OVERLAY_RANK = 1;
+ private static final int NON_RESIDENTIAL_BUILDING_OVERLAY_RANK = 5;
- // Uni-Link Bus Stop Overlay
+ static final String[] BUILDING_TYPES = { RESIDENTIAL_BUILDING_OVERLAY, NON_RESIDENTIAL_BUILDING_OVERLAY };
+
+ // -- Bus Stop Overlays
+ static final String BUS_STOP_OVERLAYS = "busStopOverlays:";
+
+ // ---- Uni-Link Bus Stop Overlay
private static final String UNI_LINK_BUS_STOP_OVERLAY = "uniLinkBusStopOverlay";
private BusStopOverlay uniLinkBusStopOverlay;
static final boolean UNI_LINK_BUS_STOP_OVERLAY_ENABLED_BY_DEFAULT = true;
- private static final int UNI_LINK_BUS_STOP_OVERLAY_RANK = 1;
+ private static final int UNI_LINK_BUS_STOP_OVERLAY_RANK = 3;
- // Uni-Link Bus Stop Overlay
+ // ---- Non Uni-Link Bus Stop Overlay
private static final String NON_UNI_LINK_BUS_STOP_OVERLAY = "nonUniLinkBusStopOverlay";
private BusStopOverlay nonUniLinkBusStopOverlay;
static final boolean NON_UNI_LINK_BUS_STOP_OVERLAY_ENABLED_BY_DEFAULT = true;
- private static final int NON_UNI_LINK_BUS_STOP_OVERLAY_RANK = 1;
+ private static final int NON_UNI_LINK_BUS_STOP_OVERLAY_RANK = 4;
- // Site Overlays
- private static final String SITE_OVERLAYS = "siteOverlays";
+ // -- 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",
+ "Montefiore Hall", "Stoneham Hall", "Erasmus Park" };
+
+ private static final String SITE_OVERLAYS = "siteOverlays:";
private HashMap<Site, PathOverlay> siteOverlays = new HashMap<Site, PathOverlay>(21);
static final boolean SITE_OVERLAYS_ENABLED_BY_DEFAULT = false;
- private static final int SITE_OVERLAYS_RANK = 1;
+ private static final int SITE_OVERLAYS_RANK = 8;
- // Route Overlays
- private static final String ROUTE_OVERLAYS = "routeOverlays";
- private HashMap<BusRoute, PathOverlay> routeOverlays = new HashMap<BusRoute, PathOverlay>(5);
- static final boolean ROUTE_OVERLAYS_ENABLED_BY_DEFAULT = true;
- private static final int ROUTE_OVERLAYS_RANK = 1;
+ // -- Route Overlays
+ private static final String BUS_ROUTE_OVERLAYS = "routeOverlays:";
+ private HashMap<BusRoute, PathOverlay> busRouteOverlays = new HashMap<BusRoute, PathOverlay>(5);
+ static final boolean BUS_ROUTE_OVERLAYS_ENABLED_BY_DEFAULT = true;
+ private static final int BUS_ROUTE_OVERLAYS_RANK = 7;
- private POIDialog favDialog;
+ // -- Other
+ static final String OTHER_OVERLAYS = "otherOverlay:";
+ // ---- Scale Bar Overlay
+ private static final String SCALE_BAR_OVERLAY = "scaleBarOverlay";
+ private ScaleBarOverlay scaleBarOverlay;
+ static final boolean SCALE_BAR_OVERLAY_ENABLED_BY_DEFAULT = true;
+ private static final int SCALE_BAR_OVERLAY_RANK = 1;
+
+ // ---- My Location Overlay
+ private static final String MY_LOCATION_OVERLAY = "myLocationOverlay";
+ private static final String MY_LOCATION_OVERLAY_COMPASS = "myLocationOverlayCompass";
+ private MyLocationOverlay myLocationOverlay;
+ static final boolean MY_LOCATION_OVERLAY_ENABLED_BY_DEFAULT = true;
+ 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 };
+
+ // Other bits
+
+ // 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_CHILDREN = { UNI_LINK_ROUTES, UNI_LINK_ROUTES, BUILDING_TYPES, SITE_NAMES,
+ OTHER_OVERLAY_NAMES };
+
+ /**
+ * The toast for this activity, storing the toast centrally allows it to be changed quickly, instead of a queue
+ * building up
+ */
Toast activityToast;
private MapActivity instance;
@@ -162,8 +208,10 @@ public class MapActivity extends OrmLiteBaseActivity<DatabaseHelper> implements
pastOverlays = (HashMap<String, Overlay>) getLastNonConfigurationInstance();
- // SensorManager mSensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE); This code in the following constructor causes problems in
- // some emulators, disable sensors to fix.
+ /*
+ * SensorManager mSensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE); This code in the
+ * following constructor causes problems in some emulators, disable sensors to fix.
+ */
Log.i(TAG, "Starting creating myLocationOverlay");
myLocationOverlay = new MyLocationOverlay(instance, mapView);
Log.i(TAG, "Finished creating myLocationOverlay");
@@ -220,13 +268,14 @@ public class MapActivity extends OrmLiteBaseActivity<DatabaseHelper> implements
final SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(this);
final SharedPreferences activityPrefs = getPreferences(0);
- if (activityPrefs.getBoolean("Other:Compass", false)) {
+ if (activityPrefs.getBoolean(OTHER_OVERLAYS + MY_LOCATION_OVERLAY_COMPASS, false)) {
myLocationOverlay.enableCompass();
} else {
myLocationOverlay.disableCompass();
}
- if (activityPrefs.getBoolean("Other:My Location", false) && sharedPrefs.getBoolean(GPS_ENABLED, false)) {
+ if (activityPrefs.getBoolean(OTHER_OVERLAYS + MY_LOCATION_OVERLAY, false)
+ && sharedPrefs.getBoolean(GPS_ENABLED, false)) {
myLocationOverlay.enableMyLocation();
} else {
myLocationOverlay.disableMyLocation();
@@ -360,7 +409,8 @@ public class MapActivity extends OrmLiteBaseActivity<DatabaseHelper> implements
}
while (true) {
- if ((buildingThread == null || !buildingThread.isAlive()) && (busStopThread == null || !busStopThread.isAlive())
+ if ((buildingThread == null || !buildingThread.isAlive())
+ && (busStopThread == null || !busStopThread.isAlive())
&& (siteThread == null || !siteThread.isAlive()))
break;
@@ -398,18 +448,21 @@ public class MapActivity extends OrmLiteBaseActivity<DatabaseHelper> implements
showNonUniLinkBusStopOverlays();
- if (activityPrefs.getBoolean("Buildings:Residential", true) || activityPrefs.getBoolean("Buildings:Non-Residential", true)) {
- // The argument currently dosent matter for this method.
+ if (activityPrefs.getBoolean(BUILDING_OVERLAYS + RESIDENTIAL_BUILDING_OVERLAY,
+ RESIDENTIAL_BUILDING_OVERLAY_ENABLED_BY_DEFAULT)
+ || activityPrefs.getBoolean(BUILDING_OVERLAYS + NON_RESIDENTIAL_BUILDING_OVERLAY,
+ NON_RESIDENTIAL_BUILDING_OVERLAY_ENABLED_BY_DEFAULT)) {
showBuildingOverlay();
}
Log.i(TAG, "Begining to show the route overlays at " + (System.currentTimeMillis() - startTime));
for (BusRoute busRoute : getHelper().getBusRouteDao()) {
if (!busRoute.uniLink) {
+ Log.v(TAG, "Bus route " + busRoute.code + "(" + busRoute.id + ") is not unilink");
continue;
}
Log.v(TAG, "Looking at showing " + busRoute.code + " route overlay");
- if (activityPrefs.getBoolean("Bus Routes:" + busRoute.code, ROUTE_OVERLAYS_ENABLED_BY_DEFAULT)) {
+ if (activityPrefs.getBoolean(BUS_ROUTE_OVERLAYS + busRoute.code, BUS_ROUTE_OVERLAYS_ENABLED_BY_DEFAULT)) {
showRouteOverlay(busRoute);
}
}
@@ -442,7 +495,8 @@ 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);
@@ -458,7 +512,8 @@ public class MapActivity extends OrmLiteBaseActivity<DatabaseHelper> implements
}
- scaleBarOverlay.setEnabled(activityPrefs.getBoolean(SCALE_BAR_OVERLAY, SCALE_BAR_OVERLAY_ENABLED_BY_DEFAULT));
+ scaleBarOverlay.setEnabled(activityPrefs.getBoolean(OTHER_OVERLAYS + SCALE_BAR_OVERLAY,
+ SCALE_BAR_OVERLAY_ENABLED_BY_DEFAULT));
mapView.postInvalidate();
@@ -470,20 +525,22 @@ 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));
PathOverlay routeOverlay;
- if ((routeOverlay = routeOverlays.get(route)) != null) {
+ if ((routeOverlay = busRouteOverlays.get(route)) != null) {
Log.v(TAG, route.code + " route overlay already existed");
} else {
- if (pastOverlays != null && (routeOverlay = (PathOverlay) pastOverlays.get(ROUTE_OVERLAYS + route.code)) != null) {
+ if (pastOverlays != null
+ && (routeOverlay = (PathOverlay) pastOverlays.get(BUS_ROUTE_OVERLAYS + route.code)) != null) {
Log.v(TAG, "Restored " + route.code + " route overlay");
if (route.code.equals("U1")) {
- PathOverlay routeOverlayU1E = (PathOverlay) pastOverlays.get(ROUTE_OVERLAYS + "U1E");
- overlays.put(ROUTE_OVERLAYS + "U1E", routeOverlayU1E);
+ PathOverlay routeOverlayU1E = (PathOverlay) pastOverlays.get(BUS_ROUTE_OVERLAYS + "U1E");
+ overlays.put(BUS_ROUTE_OVERLAYS + "U1E", routeOverlayU1E);
}
} else {
InputStream resource = null;
@@ -493,15 +550,16 @@ public class MapActivity extends OrmLiteBaseActivity<DatabaseHelper> implements
colour = U1;
// 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);
routeOverlayU1E.getPaint().setPathEffect(new DashPathEffect(new float[] { 20, 16 }, 0));
routeOverlayU1E.setEnabled(activityPrefs.getBoolean("Bus Routes:" + route.code, true));
- routeOverlays.put(new BusRoute(1000, "U1E", "U1E Route Label", true), routeOverlayU1E);
- overlays.put(ROUTE_OVERLAYS + route.code + "E", routeOverlayU1E);
+ busRouteOverlays.put(new BusRoute(1000, "U1E", "U1E Route Label", true), routeOverlayU1E);
+ overlays.put(BUS_ROUTE_OVERLAYS + route.code + "E", routeOverlayU1E);
} else if (route.code.equals("U1N")) {
resource = getResources().openRawResource(R.raw.u1n);
colour = U1N;
@@ -527,8 +585,8 @@ public class MapActivity extends OrmLiteBaseActivity<DatabaseHelper> implements
routeOverlay.getPaint().setStrokeWidth(12);
}
- routeOverlays.put(route, routeOverlay);
- overlays.put(ROUTE_OVERLAYS + route.code, routeOverlay);
+ busRouteOverlays.put(route, routeOverlay);
+ overlays.put(BUS_ROUTE_OVERLAYS + route.code, routeOverlay);
synchronized (mapView.getOverlays()) {
mapView.getOverlays().add(routeOverlay);
@@ -537,14 +595,17 @@ public class MapActivity extends OrmLiteBaseActivity<DatabaseHelper> implements
}
- routeOverlay.setEnabled(activityPrefs.getBoolean(ROUTE_OVERLAYS + route.code, ROUTE_OVERLAYS_ENABLED_BY_DEFAULT));
+ routeOverlay.setEnabled(activityPrefs.getBoolean(BUS_ROUTE_OVERLAYS + route.code,
+ BUS_ROUTE_OVERLAYS_ENABLED_BY_DEFAULT));
if (route.code.equals("U1")) {
- overlays.get(ROUTE_OVERLAYS + "U1E").setEnabled(activityPrefs.getBoolean(ROUTE_OVERLAYS + "U1", ROUTE_OVERLAYS_ENABLED_BY_DEFAULT));
+ overlays.get(BUS_ROUTE_OVERLAYS + "U1E").setEnabled(
+ activityPrefs.getBoolean(BUS_ROUTE_OVERLAYS + "U1", BUS_ROUTE_OVERLAYS_ENABLED_BY_DEFAULT));
}
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();
}
@@ -553,7 +614,8 @@ 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));
@@ -562,7 +624,8 @@ 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 {
@@ -588,11 +651,13 @@ 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();
}
@@ -608,8 +673,11 @@ public class MapActivity extends OrmLiteBaseActivity<DatabaseHelper> implements
if (residentialBuildingOverlay != null) {
} else {
- if (pastOverlays != null && (residentialBuildingOverlay = (BuildingNumOverlay) pastOverlays.get(RESIDENTIAL_BUILDING_OVERLAY)) != null) {
- nonResidentialBuildingOverlay = (BuildingNumOverlay) pastOverlays.get(NON_RESIDENTIAL_BUILDING_OVERLAY);
+ if (pastOverlays != null
+ && (residentialBuildingOverlay = (BuildingNumOverlay) pastOverlays
+ .get(RESIDENTIAL_BUILDING_OVERLAY)) != null) {
+ nonResidentialBuildingOverlay = (BuildingNumOverlay) pastOverlays
+ .get(NON_RESIDENTIAL_BUILDING_OVERLAY);
Log.i(TAG, "Restored building overlays");
} else {
@@ -660,7 +728,8 @@ public class MapActivity extends OrmLiteBaseActivity<DatabaseHelper> implements
}
}
- residentialBuildingOverlay.setEnabled(activityPrefs.getBoolean(RESIDENTIAL_BUILDING_OVERLAY, RESIDENTIAL_BUILDING_OVERLAY_ENABLED_BY_DEFAULT));
+ residentialBuildingOverlay.setEnabled(activityPrefs.getBoolean(RESIDENTIAL_BUILDING_OVERLAY,
+ RESIDENTIAL_BUILDING_OVERLAY_ENABLED_BY_DEFAULT));
nonResidentialBuildingOverlay.setEnabled(activityPrefs.getBoolean(RESIDENTIAL_BUILDING_OVERLAY,
NON_RESIDENTIAL_BUILDING_OVERLAY_ENABLED_BY_DEFAULT));
@@ -682,13 +751,15 @@ public class MapActivity extends OrmLiteBaseActivity<DatabaseHelper> implements
if (uniLinkBusStopOverlay != null) {
} else {
- if (pastOverlays != null && (uniLinkBusStopOverlay = (BusStopOverlay) pastOverlays.get(UNI_LINK_BUS_STOP_OVERLAY)) != null) {
+ if (pastOverlays != null
+ && (uniLinkBusStopOverlay = (BusStopOverlay) pastOverlays.get(UNI_LINK_BUS_STOP_OVERLAY)) != null) {
Log.i(TAG, "Restored bus stop overlays");
} else {
try {
List<BusStop> busStops;
Log.v(TAG, "Begin fetching BusStops at " + (System.currentTimeMillis() - startTime));
- if (activityPrefs.getBoolean(UNI_LINK_BUS_STOP_OVERLAY, UNI_LINK_BUS_STOP_OVERLAY_ENABLED_BY_DEFAULT)) {
+ if (activityPrefs.getBoolean(UNI_LINK_BUS_STOP_OVERLAY,
+ UNI_LINK_BUS_STOP_OVERLAY_ENABLED_BY_DEFAULT)) {
busStops = getHelper().getBusStopDao().queryForAll();
} else {
busStops = getHelper().getBusStopDao().queryForEq(BusStop.UNI_LINK_FIELD_NAME, true);
@@ -711,11 +782,16 @@ public class MapActivity extends OrmLiteBaseActivity<DatabaseHelper> implements
}
}
- uniLinkBusStopOverlay.setRoutes(0, activityPrefs.getBoolean("0,0", UNI_LINK_BUS_STOP_OVERLAY_ENABLED_BY_DEFAULT));
- uniLinkBusStopOverlay.setRoutes(1, activityPrefs.getBoolean("0,1", UNI_LINK_BUS_STOP_OVERLAY_ENABLED_BY_DEFAULT));
- uniLinkBusStopOverlay.setRoutes(2, activityPrefs.getBoolean("0,2", UNI_LINK_BUS_STOP_OVERLAY_ENABLED_BY_DEFAULT));
- uniLinkBusStopOverlay.setRoutes(3, activityPrefs.getBoolean("0,3", UNI_LINK_BUS_STOP_OVERLAY_ENABLED_BY_DEFAULT));
- uniLinkBusStopOverlay.setRoutes(4, activityPrefs.getBoolean("0,4", 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));
mapView.postInvalidate();
@@ -732,17 +808,22 @@ public class MapActivity extends OrmLiteBaseActivity<DatabaseHelper> implements
final SharedPreferences activityPrefs = getPreferences(0);
final OverlayRankComparator comparator = new OverlayRankComparator(getPreferences(0));
- if (nonUniLinkBusStopOverlay == null && activityPrefs.getBoolean(NON_UNI_LINK_BUS_STOPS, NON_UNI_LINK_BUS_STOP_OVERLAY_ENABLED_BY_DEFAULT)) {
- if (pastOverlays != null && (nonUniLinkBusStopOverlay = (BusStopOverlay) pastOverlays.get(NON_UNI_LINK_BUS_STOPS)) != null) {
+ if (nonUniLinkBusStopOverlay == null
+ && activityPrefs.getBoolean(NON_UNI_LINK_BUS_STOPS,
+ NON_UNI_LINK_BUS_STOP_OVERLAY_ENABLED_BY_DEFAULT)) {
+ if (pastOverlays != null
+ && (nonUniLinkBusStopOverlay = (BusStopOverlay) pastOverlays.get(NON_UNI_LINK_BUS_STOPS)) != 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);
- Log.v(TAG, "Finished fetching non Uni-Link BusStops at " + (System.currentTimeMillis() - startTime));
+ Log.v(TAG, "Finished fetching non Uni-Link BusStops at "
+ + (System.currentTimeMillis() - startTime));
nonUniLinkBusStopOverlay = new BusStopOverlay(instance, busStops);
} catch (SQLException e) {
@@ -750,7 +831,7 @@ public class MapActivity extends OrmLiteBaseActivity<DatabaseHelper> implements
}
}
- overlays.put(NON_UNI_LINK_BUS_STOPS, nonUniLinkBusStopOverlay);
+ overlays.put(NON_UNI_LINK_BUS_STOP_OVERLAY, nonUniLinkBusStopOverlay);
Log.v(TAG, "Applyed the site overlay, now sorting them");
@@ -762,7 +843,8 @@ 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();
}
@@ -813,8 +895,9 @@ 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;
@@ -921,7 +1004,8 @@ public class MapActivity extends OrmLiteBaseActivity<DatabaseHelper> implements
Log.v(TAG, "Got a busStop id back from the BusTimeActivity " + busStopID);
BusStop busStop = getHelper().getBusStopDao().queryForId(busStopID);
- uniLinkBusStopOverlay.refresh(busStop); // This does not invalidate the map, but it seems to make the changes appear
+ uniLinkBusStopOverlay.refresh(busStop); // This does not invalidate the map, but it seems to
+ // make the changes appear
}
} catch (SQLException e) {
e.printStackTrace();
@@ -938,7 +1022,8 @@ public class MapActivity extends OrmLiteBaseActivity<DatabaseHelper> implements
/*
* public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition, long id) {
*
- * mapView.post(new Runnable() { public void run() { // updateEnabledOverlays(); TODO Fix whatever this did? mapView.invalidate(); } });
+ * mapView.post(new Runnable() { public void run() { // updateEnabledOverlays(); TODO Fix whatever this did?
+ * mapView.invalidate(); } });
*
* return true; }
*/
@@ -1078,14 +1163,14 @@ public class MapActivity extends OrmLiteBaseActivity<DatabaseHelper> implements
return UNI_LINK_BUS_STOP_OVERLAY_RANK;
} else if (overlay == nonUniLinkBusStopOverlay) {
return NON_UNI_LINK_BUS_STOP_OVERLAY_RANK;
- } else if (overlay == residentialBuildingOverlay) {
+ } else if (overlay.equals(residentialBuildingOverlay)) {
return RESIDENTIAL_BUILDING_OVERLAY_RANK;
- } else if (overlay == nonResidentialBuildingOverlay) {
+ } else if (overlay.equals(nonResidentialBuildingOverlay)) {
return NON_RESIDENTIAL_BUILDING_OVERLAY_RANK;
} else if (siteOverlays != null && siteOverlays.values().contains(overlay)) {
return SITE_OVERLAYS_RANK;
- } else if (routeOverlays != null && routeOverlays.values().contains(overlay)) {
- return ROUTE_OVERLAYS_RANK;
+ } else if (busRouteOverlays != null && busRouteOverlays.values().contains(overlay)) {
+ return BUS_ROUTE_OVERLAYS_RANK;
} else {
Log.e(TAG, "Trying to rank unknown overlay " + overlay);
return -1;
@@ -1112,15 +1197,13 @@ public class MapActivity extends OrmLiteBaseActivity<DatabaseHelper> implements
// Noting to do here atm
} else if (key.equals(UNI_LINK_BUS_TIMES)) {
// Noting to do here atm
- } else if (key.equals(UNI_LINK_BUS_STOP_OVERLAY)) {
-
- } else if (key.equals(NON_UNI_LINK_BUS_STOP_OVERLAY)) { // Activity Preferences
+ } else if (key.startsWith(BUS_STOP_OVERLAYS)) {
showUniLinkBusStopOverlays();
- } else if (key.equals(NON_UNI_LINK_BUS_STOPS)) { // Activity Preferences
+ } else if (key.startsWith(NON_UNI_LINK_BUS_STOPS)) {
showNonUniLinkBusStopOverlays();
- } else if (key.contains(ROUTE_OVERLAYS)) {
+ } else if (key.startsWith(BUS_ROUTE_OVERLAYS)) {
try {
- String routeName = key.substring(ROUTE_OVERLAYS.length(), key.length());
+ String routeName = key.substring(BUS_ROUTE_OVERLAYS.length(), key.length());
for (BusRoute route : getHelper().getBusRouteDao()) {
Log.v(TAG, route.code + " " + routeName);
if (route.code.equals(routeName)) {
@@ -1130,9 +1213,9 @@ public class MapActivity extends OrmLiteBaseActivity<DatabaseHelper> implements
} catch (SQLException e) {
e.printStackTrace();
}
- } else if (key.equals(RESIDENTIAL_BUILDING_OVERLAY) || key.equals(NON_RESIDENTIAL_BUILDING_OVERLAY)) {
+ } else if (key.startsWith(BUILDING_OVERLAYS)) {
showBuildingOverlay();
- } else if (key.contains(SITE_OVERLAYS)) {
+ } else if (key.startsWith(SITE_OVERLAYS)) {
String siteName = key.substring(SITE_OVERLAYS.length(), key.length());
try {
for (Site site : getHelper().getSiteDao()) {
@@ -1143,23 +1226,20 @@ public class MapActivity extends OrmLiteBaseActivity<DatabaseHelper> implements
} catch (SQLException e) {
e.printStackTrace();
}
- } else if (key.startsWith("0")) {
- uniLinkBusStopOverlay.setRoutes(Integer.parseInt(Character.toString(key.charAt(2))),
- prefs.getBoolean(key, UNI_LINK_BUS_STOP_OVERLAY_ENABLED_BY_DEFAULT));
- mapView.postInvalidate();
- } else if (key.contains("Other")) {
- if (key.contains("Scale Bar")) {
+ } else if (key.startsWith(OTHER_OVERLAYS)) {
+ if (key.substring(OTHER_OVERLAYS.length(), key.length()).equals(SCALE_BAR_OVERLAY)) {
showUtilityOverlays();
- } else if (key.contains("Compass")) {
- if (prefs.getBoolean("Other:Compass", false)) {
+ } else if (key.substring(OTHER_OVERLAYS.length(), key.length()).equals(MY_LOCATION_OVERLAY_COMPASS)) {
+ if (prefs.getBoolean(key, MY_LOCATION_OVERLAY_COMPASS_ENABLED_BY_DEFAULT)) {
myLocationOverlay.enableCompass();
} else {
myLocationOverlay.disableCompass();
}
- } else if (key.contains("Other:My Location")) {
+ } else if (key.substring(OTHER_OVERLAYS.length(), key.length()).equals(MY_LOCATION_OVERLAY)) {
final SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(this);
- if (prefs.getBoolean("Other:Compass", false) && sharedPrefs.getBoolean("GPSEnabled", false)) {
+ if (prefs.getBoolean(key, MY_LOCATION_OVERLAY_ENABLED_BY_DEFAULT)
+ && sharedPrefs.getBoolean(GPS_ENABLED, GPS_ENABLED_BY_DEFAULT)) {
myLocationOverlay.enableMyLocation();
} else {
myLocationOverlay.disableMyLocation();