aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorChristopher Baines <cbaines8@gmail.com>2012-02-02 18:39:00 +0000
committerChristopher Baines <cbaines8@gmail.com>2012-02-02 18:39:00 +0000
commit6fe849cc34a06a3f5d7662ea6a4566a870b3edfa (patch)
treeb8a3afd2adff9341932f540801e1c80151d55de9 /src
parentb47ae24a17925619029500a56998860496ce308f (diff)
downloadsouthamptonuniversitymap-6fe849cc34a06a3f5d7662ea6a4566a870b3edfa.tar
southamptonuniversitymap-6fe849cc34a06a3f5d7662ea6a4566a870b3edfa.tar.gz
Improvements to the Preference management, begin allowing more bus data, need to rethink the data storage and retreval, perhaps using more semantic web stuff...
Diffstat (limited to 'src')
-rw-r--r--src/net/cbaines/suma/BuildingActivity.java88
-rw-r--r--src/net/cbaines/suma/BusStop.java6
-rw-r--r--src/net/cbaines/suma/BusStopActivity.java10
-rw-r--r--src/net/cbaines/suma/BusStopOverlay.java9
-rw-r--r--src/net/cbaines/suma/DataManager.java72
-rw-r--r--src/net/cbaines/suma/Preferences.java12
-rw-r--r--src/net/cbaines/suma/PreferencesActivity.java23
-rw-r--r--src/net/cbaines/suma/SouthamptonUniversityMapActivity.java42
8 files changed, 208 insertions, 54 deletions
diff --git a/src/net/cbaines/suma/BuildingActivity.java b/src/net/cbaines/suma/BuildingActivity.java
new file mode 100644
index 0000000..7637439
--- /dev/null
+++ b/src/net/cbaines/suma/BuildingActivity.java
@@ -0,0 +1,88 @@
+/*
+ * Southampton University Map App
+ * Copyright (C) 2011 Christopher Baines
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+package net.cbaines.suma;
+
+import java.io.InputStream;
+import java.util.HashSet;
+
+import android.content.Context;
+import android.os.Bundle;
+
+import com.hp.hpl.jena.rdf.model.Model;
+import com.hp.hpl.jena.rdf.model.ModelFactory;
+import com.hp.hpl.jena.util.FileManager;
+import com.j256.ormlite.android.apptools.OrmLiteBaseActivity;
+
+public class BuildingActivity extends OrmLiteBaseActivity<DatabaseHelper> {
+
+ final static String TAG = "BusTimeActivity";
+
+ private boolean dataChanged;
+
+ private Context instance;
+
+ private HashSet<BusRoute> routes = new HashSet<BusRoute>();
+
+ public void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.bustimes);
+
+ final DatabaseHelper helper = getHelper();
+
+ // create an empty model
+ Model model = ModelFactory.createDefaultModel();
+
+ // use the FileManager to find the input file
+ InputStream in = getResources().openRawResource(R.raw.u9);
+ if (in == null) {
+ throw new IllegalArgumentException("File not found");
+ }
+
+ // read the RDF/XML file
+ model.read(in, null);
+
+
+
+ instance = this;
+
+ }
+
+ public void onResume() {
+ super.onResume();
+
+ }
+
+ public void onPause() {
+
+ super.onPause();
+ }
+
+ public void finish() {
+ setResult(RESULT_OK, getIntent());
+
+ super.finish();
+ }
+
+ @Override
+ public Object onRetainNonConfigurationInstance() {
+ return null;
+ }
+
+}
diff --git a/src/net/cbaines/suma/BusStop.java b/src/net/cbaines/suma/BusStop.java
index c19e682..1e9faaa 100644
--- a/src/net/cbaines/suma/BusStop.java
+++ b/src/net/cbaines/suma/BusStop.java
@@ -35,6 +35,7 @@ public class BusStop extends POI {
public static final String DESCRIPTION_FIELD_NAME = "description";
public static final String BAY_FIELD_NAME = "bay";
public static final String ROUTES_FIELD_NAME = "bay";
+ public static final String UNI_LINK_FIELD_NAME = "uniLink";
/**
* Description e.g. "Bournemouth Rd os Asda S"
@@ -52,7 +53,10 @@ public class BusStop extends POI {
* Used to speed up accessing the relevent uni link routes for a bus stop, this is not a uni link stop
*/
@DatabaseField(canBeNull = false)
- public byte routes;
+ byte routes;
+
+ @DatabaseField(canBeNull = false)
+ boolean uniLink;
public BusStop(String location, String description, String bay, GeoPoint point) {
this.id = location;
diff --git a/src/net/cbaines/suma/BusStopActivity.java b/src/net/cbaines/suma/BusStopActivity.java
index 93f4ae6..d84bbdd 100644
--- a/src/net/cbaines/suma/BusStopActivity.java
+++ b/src/net/cbaines/suma/BusStopActivity.java
@@ -53,7 +53,7 @@ import com.j256.ormlite.dao.Dao;
import com.j256.ormlite.stmt.PreparedQuery;
import com.j256.ormlite.stmt.QueryBuilder;
-public class BusStopActivity extends OrmLiteBaseActivity<DatabaseHelper> implements OnCheckedChangeListener {
+public class BusStopActivity extends OrmLiteBaseActivity<DatabaseHelper> implements OnCheckedChangeListener, Preferences {
final static String TAG = "BusTimeActivity";
@@ -199,7 +199,7 @@ public class BusStopActivity extends OrmLiteBaseActivity<DatabaseHelper> impleme
super.onResume();
SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(this);
- if (sharedPrefs.getBoolean("liveBusTimesEnabled", false)) {
+ if (sharedPrefs.getBoolean(UNI_LINK_BUS_TIMES, false) || sharedPrefs.getBoolean(NON_UNI_LINK_BUS_TIMES, false)) {
Log.i(TAG, "Live Times enabled");
timetable = (Timetable) getLastNonConfigurationInstance();
@@ -287,7 +287,11 @@ public class BusStopActivity extends OrmLiteBaseActivity<DatabaseHelper> impleme
protected Timetable doInBackground(String... activity) {
Timetable newTimetable = null;
try {
- newTimetable = DataManager.getTimetable(instance, busStopID, true);
+ final SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(instance);
+
+ newTimetable = DataManager.getTimetable(instance, busStopID, sharedPrefs.getBoolean(SouthamptonUniversityMapActivity.UNI_LINK_BUS_TIMES,
+ SouthamptonUniversityMapActivity.UNI_LINK_BUS_TIMES_ENABLED_BY_DEFAULT), sharedPrefs.getBoolean(
+ SouthamptonUniversityMapActivity.NON_UNI_LINK_BUS_TIMES, SouthamptonUniversityMapActivity.NON_UNI_LINK_BUS_TIMES_ENABLED_BY_DEFAULT));
} catch (SQLException e) {
errorMessage = "Error message regarding SQL?";
e.printStackTrace();
diff --git a/src/net/cbaines/suma/BusStopOverlay.java b/src/net/cbaines/suma/BusStopOverlay.java
index 639f851..834b6dc 100644
--- a/src/net/cbaines/suma/BusStopOverlay.java
+++ b/src/net/cbaines/suma/BusStopOverlay.java
@@ -45,7 +45,7 @@ import com.j256.ormlite.dao.Dao;
public class BusStopOverlay extends Overlay implements RouteColorConstants {
- private List<BusStop> busStops;
+ List<BusStop> busStops;
private final Point mCurScreenCoords = new Point();
private final Point mTouchScreenPoint = new Point();
@@ -68,9 +68,8 @@ public class BusStopOverlay extends Overlay implements RouteColorConstants {
private boolean[] routes = new boolean[5];
- public BusStopOverlay(Context context) throws SQLException {
+ public BusStopOverlay(Context context, List<BusStop> busStops) throws SQLException {
super(context);
- final long startTime = System.currentTimeMillis();
this.context = context;
@@ -84,9 +83,7 @@ public class BusStopOverlay extends Overlay implements RouteColorConstants {
paint.setStyle(Style.FILL);
paint.setStrokeWidth(6);
- Log.i(TAG, "Begining to load bus stops in to overlay " + (System.currentTimeMillis() - startTime));
- busStops = busStopDao.queryForAll();
- Log.i(TAG, "Finished loading bus stops in to overlay " + (System.currentTimeMillis() - startTime));
+ this.busStops = busStops;
}
void setRoutes(int route, boolean visible) {
diff --git a/src/net/cbaines/suma/DataManager.java b/src/net/cbaines/suma/DataManager.java
index 9fd08c1..d4d0968 100644
--- a/src/net/cbaines/suma/DataManager.java
+++ b/src/net/cbaines/suma/DataManager.java
@@ -331,42 +331,42 @@ public class DataManager {
e.printStackTrace();
}
- // TODO: Seperate non unilink stuff in to a different table
- if (onlyUniLink) {
-
- long sizeBeforeRemoval = busStopDao.countOf();
-
- // Removing busstops not used by unilink busses
- for (Iterator<BusStop> busStopIter = busStopDao.iterator(); busStopIter.hasNext();) {
- BusStop stop = busStopIter.next();
- // Log.i(TAG, "Looking at stop " + stop.id);
-
- /*
- * QueryBuilder<RouteStops, Integer> routeStopsQueryBuilder = routeStopsDao.queryBuilder(); routeStopsQueryBuilder.where().eq(columnName, value)
- *
- * DeleteBuilder<BusStop, String> deleteBuilder = busStopDao.deleteBuilder(); // only delete the rows where password is null
- * deleteBuilder.where().in(RouteStops.STOP_ID_FIELD_NAME, objects) accountDao.delete(deleteBuilder.prepare());
- */
-
- QueryBuilder<RouteStops, Integer> routeStopsQueryBuilder = routeStopsDao.queryBuilder();
- routeStopsQueryBuilder.setCountOf(true);
- routeStopsQueryBuilder.where().eq(RouteStops.STOP_ID_FIELD_NAME, stop);
-
- PreparedQuery<RouteStops> routeStopsPreparedQuery = routeStopsQueryBuilder.prepare();
- long num = routeStopsDao.countOf(routeStopsPreparedQuery);
- // long num = routeStopsDao.query(routeStopsPreparedQuery).size();
- // Log.i(TAG, "Number is " + num);
- if (num == 0) {
- // Log.i(TAG, "Removing " + stop.id);
+ long sizeBeforeRemoval = busStopDao.countOf();
+
+ // Removing busstops not used by unilink busses
+ for (Iterator<BusStop> busStopIter = busStopDao.iterator(); busStopIter.hasNext();) {
+ BusStop stop = busStopIter.next();
+ // Log.i(TAG, "Looking at stop " + stop.id);
+
+ /*
+ * QueryBuilder<RouteStops, Integer> routeStopsQueryBuilder = routeStopsDao.queryBuilder(); routeStopsQueryBuilder.where().eq(columnName, value)
+ *
+ * DeleteBuilder<BusStop, String> deleteBuilder = busStopDao.deleteBuilder(); // only delete the rows where password is null
+ * deleteBuilder.where().in(RouteStops.STOP_ID_FIELD_NAME, objects) accountDao.delete(deleteBuilder.prepare());
+ */
+
+ QueryBuilder<RouteStops, Integer> routeStopsQueryBuilder = routeStopsDao.queryBuilder();
+ routeStopsQueryBuilder.setCountOf(true);
+ routeStopsQueryBuilder.where().eq(RouteStops.STOP_ID_FIELD_NAME, stop);
+
+ PreparedQuery<RouteStops> routeStopsPreparedQuery = routeStopsQueryBuilder.prepare();
+ long num = routeStopsDao.countOf(routeStopsPreparedQuery);
+ // long num = routeStopsDao.query(routeStopsPreparedQuery).size();
+ // Log.i(TAG, "Number is " + num);
+ if (num == 0) {
+ // Log.i(TAG, "Removing " + stop.id);
+ stop.uniLink = false;
+ if (onlyUniLink) {
busStopIter.remove();
}
+ } else {
+ stop.uniLink = true;
}
+ }
- long sizeAfterRemoval = busStopDao.countOf();
-
- Log.i(TAG, "Removed " + (sizeBeforeRemoval - sizeAfterRemoval) + " stops (from " + sizeBeforeRemoval + ") now have " + sizeAfterRemoval);
+ long sizeAfterRemoval = busStopDao.countOf();
- }
+ Log.i(TAG, "Removed " + (sizeBeforeRemoval - sizeAfterRemoval) + " stops (from " + sizeBeforeRemoval + ") now have " + sizeAfterRemoval);
Log.i(TAG, "Finished loading bus data");
}
@@ -546,8 +546,8 @@ public class DataManager {
}
- public static Timetable getTimetable(Context context, String busStop, boolean onlyUniLink) throws SQLException, ClientProtocolException, IOException,
- JSONException {
+ public static Timetable getTimetable(Context context, String busStop, boolean keepUniLink, boolean keepNonUniLink) throws SQLException,
+ ClientProtocolException, IOException, JSONException {
if (helper == null)
helper = OpenHelperManager.getHelper(context, DatabaseHelper.class);
@@ -571,7 +571,11 @@ public class DataManager {
for (int stopNum = 0; stopNum < stopsArray.length(); stopNum++) {
JSONObject stopObj = stopsArray.getJSONObject(stopNum);
- if (onlyUniLink && !stopObj.getString("name").startsWith("U")) {
+ if (!keepNonUniLink && !stopObj.getString("name").startsWith("U")) {
+ continue;
+ }
+
+ if (!keepUniLink && stopObj.getString("name").startsWith("U")) {
continue;
}
diff --git a/src/net/cbaines/suma/Preferences.java b/src/net/cbaines/suma/Preferences.java
new file mode 100644
index 0000000..e2c79a0
--- /dev/null
+++ b/src/net/cbaines/suma/Preferences.java
@@ -0,0 +1,12 @@
+package net.cbaines.suma;
+
+public interface Preferences {
+ static final String GPS_ENABLED = "GPSEnabled";
+ static final boolean GPS_ENABLED_BY_DEFAULT = true;
+ static final String UNI_LINK_BUS_TIMES = "uniLinkLiveBusTimesEnabled";
+ static final boolean UNI_LINK_BUS_TIMES_ENABLED_BY_DEFAULT = true;
+ static final String NON_UNI_LINK_BUS_TIMES = "nonUniLinkLiveBusTimesEnabled";
+ static final boolean NON_UNI_LINK_BUS_TIMES_ENABLED_BY_DEFAULT = false;
+ static final String NON_UNI_LINK_BUS_STOPS = "nonUniLinkBusStop";
+ static final boolean NON_UNI_LINK_BUS_STOPS_ENABLED_BY_DEFAULT = false;
+}
diff --git a/src/net/cbaines/suma/PreferencesActivity.java b/src/net/cbaines/suma/PreferencesActivity.java
index d5df6a1..0d61c6d 100644
--- a/src/net/cbaines/suma/PreferencesActivity.java
+++ b/src/net/cbaines/suma/PreferencesActivity.java
@@ -19,15 +19,34 @@
package net.cbaines.suma;
+import android.content.SharedPreferences;
+import android.content.SharedPreferences.Editor;
import android.os.Bundle;
import android.preference.PreferenceActivity;
+import android.preference.PreferenceManager;
-public class PreferencesActivity extends PreferenceActivity {
+public class PreferencesActivity extends PreferenceActivity implements Preferences {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
+
+ final SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(this);
+ final Editor editor = sharedPrefs.edit();
+ if (!sharedPrefs.contains(GPS_ENABLED)) {
+ editor.putBoolean(GPS_ENABLED, GPS_ENABLED_BY_DEFAULT);
+ }
+ if (!sharedPrefs.contains(UNI_LINK_BUS_TIMES)) {
+ editor.putBoolean(UNI_LINK_BUS_TIMES, UNI_LINK_BUS_TIMES_ENABLED_BY_DEFAULT);
+ }
+ if (!sharedPrefs.contains(NON_UNI_LINK_BUS_TIMES)) {
+ editor.putBoolean(NON_UNI_LINK_BUS_TIMES, NON_UNI_LINK_BUS_TIMES_ENABLED_BY_DEFAULT);
+ }
+ if (!sharedPrefs.contains(NON_UNI_LINK_BUS_STOPS)) {
+ editor.putBoolean(NON_UNI_LINK_BUS_STOPS, NON_UNI_LINK_BUS_STOPS_ENABLED_BY_DEFAULT);
+ }
+ editor.commit();
+
addPreferencesFromResource(R.xml.preferences);
}
-
} \ No newline at end of file
diff --git a/src/net/cbaines/suma/SouthamptonUniversityMapActivity.java b/src/net/cbaines/suma/SouthamptonUniversityMapActivity.java
index 52b3e1f..a5a255e 100644
--- a/src/net/cbaines/suma/SouthamptonUniversityMapActivity.java
+++ b/src/net/cbaines/suma/SouthamptonUniversityMapActivity.java
@@ -26,6 +26,7 @@ import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
+import java.util.List;
import org.osmdroid.DefaultResourceProxyImpl;
import org.osmdroid.ResourceProxy;
@@ -73,7 +74,7 @@ import com.j256.ormlite.android.apptools.OrmLiteBaseActivity;
import com.j256.ormlite.dao.Dao;
public class SouthamptonUniversityMapActivity extends OrmLiteBaseActivity<DatabaseHelper> implements MapViewConstants, Runnable, RouteColorConstants,
- OnChildClickListener, OnItemClickListener, OnItemLongClickListener, OnSharedPreferenceChangeListener {
+ OnChildClickListener, OnItemClickListener, OnItemLongClickListener, OnSharedPreferenceChangeListener, Preferences {
private boolean useBundledDatabase = true;
@@ -90,18 +91,18 @@ public class SouthamptonUniversityMapActivity extends OrmLiteBaseActivity<Databa
private HashMap<String, Overlay> pastOverlays;
private ScaleBarOverlay scaleBarOverlay;
- private final boolean SCALE_BAR_OVERLAY_ENABLED_BY_DEFAULT = true;
+ private static final boolean SCALE_BAR_OVERLAY_ENABLED_BY_DEFAULT = true;
private MyLocationOverlay myLocationOverlay;
private BuildingNumOverlay residentialBuildingOverlay;
- private final boolean NON_RESIDENTIAL_BUILDING_OVERLAY_ENABLED_BY_DEFAULT = true;
+ private static final boolean NON_RESIDENTIAL_BUILDING_OVERLAY_ENABLED_BY_DEFAULT = true;
private BuildingNumOverlay nonResidentialBuildingOverlay;
- private final boolean RESIDENTIAL_BUILDING_OVERLAY_ENABLED_BY_DEFAULT = true;
+ private static final boolean RESIDENTIAL_BUILDING_OVERLAY_ENABLED_BY_DEFAULT = true;
private BusStopOverlay busStopOverlay;
- private final boolean BUS_STOP_OVERLAY_ENABLED_BY_DEFAULT = true;
+ private static final boolean BUS_STOP_OVERLAY_ENABLED_BY_DEFAULT = true;
private HashMap<Site, PathOverlay> siteOverlays = new HashMap<Site, PathOverlay>(21);
- private final boolean SITE_OVERLAY_ENABLED_BY_DEFAULT = false;
+ private static final boolean SITE_OVERLAY_ENABLED_BY_DEFAULT = false;
private HashMap<BusRoute, PathOverlay> routeOverlays = new HashMap<BusRoute, PathOverlay>(5);
- private final boolean ROUTE_OVERLAY_ENABLED_BY_DEFAULT = true;
+ private static final boolean ROUTE_OVERLAY_ENABLED_BY_DEFAULT = true;
private String[] busRoutes;
private String[] buildingTypes;
@@ -686,7 +687,16 @@ public class SouthamptonUniversityMapActivity extends OrmLiteBaseActivity<Databa
Log.i(TAG, "Restored bus stop overlays");
} else {
try {
- busStopOverlay = new BusStopOverlay(instance);
+ List<BusStop> busStops;
+ Log.v(TAG, "Begin fetching BusStops at " + (System.currentTimeMillis() - startTime));
+ if (activityPrefs.getBoolean(NON_UNI_LINK_BUS_STOPS, NON_UNI_LINK_BUS_STOPS_ENABLED_BY_DEFAULT)) {
+ busStops = getHelper().getBusStopDao().queryForAll();
+ } else {
+ busStops = getHelper().getBusStopDao().queryForEq(BusStop.UNI_LINK_FIELD_NAME, true);
+ }
+ Log.v(TAG, "Finished fetching BusStops at " + (System.currentTimeMillis() - startTime));
+
+ busStopOverlay = new BusStopOverlay(instance, busStops);
} catch (SQLException e) {
e.printStackTrace();
}
@@ -1085,6 +1095,22 @@ public class SouthamptonUniversityMapActivity extends OrmLiteBaseActivity<Databa
} else {
Log.e(TAG, "Unhandled preference key " + key);
}
+ } else if (key.equals(NON_UNI_LINK_BUS_STOPS)) {
+
+ Log.v(TAG, "Begin fetching BusStops at " + (System.currentTimeMillis() - startTime));
+ try {
+ if (prefs.getBoolean(NON_UNI_LINK_BUS_STOPS, NON_UNI_LINK_BUS_STOPS_ENABLED_BY_DEFAULT)) {
+ busStopOverlay.busStops = getHelper().getBusStopDao().queryForAll();
+ } else {
+ busStopOverlay.busStops = getHelper().getBusStopDao().queryForEq(BusStop.UNI_LINK_FIELD_NAME, true);
+ }
+
+ Log.v(TAG, "Finished fetching BusStops at " + (System.currentTimeMillis() - startTime));
+
+ busStopOverlay.refresh();
+ } catch (SQLException e) {
+ e.printStackTrace();
+ }
} else {
Log.e(TAG, "Unhandled preference key " + key);
}