aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristopher Baines <cbaines8@gmail.com>2012-01-25 15:48:42 +0000
committerChristopher Baines <cbaines8@gmail.com>2012-01-25 15:48:42 +0000
commitda433913ec08182e9f14292021025d271e3c5dd6 (patch)
treeb98c6b9be680b8602cca1bab6f71f056858e2c60
parent2451a88be960786ec790e719e77964c51476cefe (diff)
downloadsouthamptonuniversitymap-da433913ec08182e9f14292021025d271e3c5dd6.tar
southamptonuniversitymap-da433913ec08182e9f14292021025d271e3c5dd6.tar.gz
New database, and lots of changes.
-rw-r--r--assets/data.dbbin142336 -> 142336 bytes
-rw-r--r--src/net/cbaines/suma/BusRoute.java4
-rw-r--r--src/net/cbaines/suma/BusStop.java11
-rw-r--r--src/net/cbaines/suma/BusStopOverlay.java83
-rw-r--r--src/net/cbaines/suma/DataManager.java29
-rw-r--r--src/net/cbaines/suma/DatabaseHelper.java38
-rw-r--r--src/net/cbaines/suma/Direction.java26
-rw-r--r--src/net/cbaines/suma/RouteStops.java1
-rw-r--r--src/net/cbaines/suma/SouthamptonUniversityMapActivity.java18
9 files changed, 123 insertions, 87 deletions
diff --git a/assets/data.db b/assets/data.db
index b12d907..afbda79 100644
--- a/assets/data.db
+++ b/assets/data.db
Binary files differ
diff --git a/src/net/cbaines/suma/BusRoute.java b/src/net/cbaines/suma/BusRoute.java
index f095fb1..8c5d955 100644
--- a/src/net/cbaines/suma/BusRoute.java
+++ b/src/net/cbaines/suma/BusRoute.java
@@ -20,7 +20,7 @@
package net.cbaines.suma;
import java.sql.SQLException;
-import java.util.HashSet;
+import java.util.Collection;
import java.util.List;
import android.content.Context;
@@ -59,7 +59,7 @@ public class BusRoute {
String label;
@ForeignCollectionField(eager = false)
- HashSet<Direction> directions;
+ Collection<Direction> directions;
BusRoute() {
}
diff --git a/src/net/cbaines/suma/BusStop.java b/src/net/cbaines/suma/BusStop.java
index 5ed208f..c19e682 100644
--- a/src/net/cbaines/suma/BusStop.java
+++ b/src/net/cbaines/suma/BusStop.java
@@ -19,12 +19,9 @@
package net.cbaines.suma;
-import java.util.HashSet;
-
import org.osmdroid.util.GeoPoint;
import com.j256.ormlite.field.DatabaseField;
-import com.j256.ormlite.field.ForeignCollectionField;
import com.j256.ormlite.table.DatabaseTable;
/**
@@ -43,19 +40,19 @@ public class BusStop extends POI {
* Description e.g. "Bournemouth Rd os Asda S"
*/
@DatabaseField(canBeNull = true)
- public String description;
+ String description;
/**
* Unknown, "" for all UniLink stops
*/
@DatabaseField(canBeNull = true)
- public String bay;
+ String bay;
/**
* Used to speed up accessing the relevent uni link routes for a bus stop, this is not a uni link stop
*/
- @ForeignCollectionField(eager = false)
- public HashSet<BusRoute> routes;
+ @DatabaseField(canBeNull = false)
+ public byte routes;
public BusStop(String location, String description, String bay, GeoPoint point) {
this.id = location;
diff --git a/src/net/cbaines/suma/BusStopOverlay.java b/src/net/cbaines/suma/BusStopOverlay.java
index bc315cb..639f851 100644
--- a/src/net/cbaines/suma/BusStopOverlay.java
+++ b/src/net/cbaines/suma/BusStopOverlay.java
@@ -21,8 +21,6 @@ package net.cbaines.suma;
import java.sql.SQLException;
import java.util.Collections;
-import java.util.HashMap;
-import java.util.Iterator;
import java.util.List;
import org.osmdroid.views.MapView;
@@ -68,7 +66,7 @@ public class BusStopOverlay extends Overlay implements RouteColorConstants {
private float userScale = 1f;
- private HashMap<BusRoute, Boolean> routes = new HashMap<BusRoute, Boolean>();
+ private boolean[] routes = new boolean[5];
public BusStopOverlay(Context context) throws SQLException {
super(context);
@@ -91,8 +89,8 @@ public class BusStopOverlay extends Overlay implements RouteColorConstants {
Log.i(TAG, "Finished loading bus stops in to overlay " + (System.currentTimeMillis() - startTime));
}
- void setRoutes(BusRoute route, boolean visible) {
- routes.put(route, visible);
+ void setRoutes(int route, boolean visible) {
+ routes[route] = visible;
}
@Override
@@ -120,15 +118,22 @@ public class BusStopOverlay extends Overlay implements RouteColorConstants {
BusStop stop = busStops.get(stopNum);
byte routeNum = 0;
+ final byte stopRoutes = stop.routes;
- for (Iterator<BusRoute> busRouteIter = stop.routes.iterator(); busRouteIter.hasNext();) {
- BusRoute route = busRouteIter.next();
- if (routes.get(route)) {
- break;
+ boolean drawing = false;
+
+ for (int i = 0; i < 5; i++) {
+ if ((stopRoutes & (1 << i)) != 0) {
+ routeNum++;
+ if (routes[i]) {
+ drawing = true;
+ }
}
- continue;
}
+ if (!drawing)
+ continue;
+
int yOfsetPerMarker = (int) (10 * scale);
int markerYSize = (int) (8 * scale);
@@ -154,30 +159,32 @@ public class BusStopOverlay extends Overlay implements RouteColorConstants {
yOfsetPerMarker = (int) (8 * scale);
}
- for (BusRoute route : stop.routes) {
-
- // Log.i(TAG, "Route " + route + " is " + routes.get(route));
+ for (int i = 0; i < 5; i++) {
+ if ((stopRoutes & (1 << i)) != 0) {
+
+ // Log.i(TAG, "Route " + route + " is " + routes.get(route));
+
+ // Log.i(TAG, "Index is " + busRoutes.indexOf(route) + " busRoutes " + busRoutes);
+
+ if (i == 0) {
+ paint.setColor(U1);
+ } else if (i == 1) {
+ paint.setColor(U1N);
+ } else if (i == 2) {
+ paint.setColor(U2);
+ } else if (i == 3) {
+ paint.setColor(U6);
+ } else if (i == 4) {
+ paint.setColor(U9);
+ } else {
+ Log.e(TAG, "Unknown route code");
+ }
- // Log.i(TAG, "Index is " + busRoutes.indexOf(route) + " busRoutes " + busRoutes);
+ canvas.drawRect(rectLeft, mCurScreenCoords.y + ((yOfsetPerMarker * makersPlaced) - (45 * scale)), rectRight, mCurScreenCoords.y
+ + (yOfsetPerMarker * makersPlaced) - ((45 * scale) - markerYSize), paint);
- if (route.code.equals("U1")) {
- paint.setColor(U1);
- } else if (route.code.equals("U1N")) {
- paint.setColor(U1N);
- } else if (route.code.equals("U2")) {
- paint.setColor(U2);
- } else if (route.code.equals("U6")) {
- paint.setColor(U6);
- } else if (route.code.equals("U9")) {
- paint.setColor(U9);
- } else {
- Log.e(TAG, "Unknown route code");
+ makersPlaced++;
}
-
- canvas.drawRect(rectLeft, mCurScreenCoords.y + ((yOfsetPerMarker * makersPlaced) - (45 * scale)), rectRight, mCurScreenCoords.y
- + (yOfsetPerMarker * makersPlaced) - ((45 * scale) - markerYSize), paint);
-
- makersPlaced++;
}
}
@@ -284,13 +291,17 @@ public class BusStopOverlay extends Overlay implements RouteColorConstants {
pj.toPixels(busStop.point, mItemPoint);
if (marker.getBounds().contains(mTouchScreenPoint.x - mItemPoint.x, mTouchScreenPoint.y - mItemPoint.y)) {
- for (Iterator<BusRoute> busRouteIter = busStop.routes.iterator(); busRouteIter.hasNext();) {
- BusRoute route = busRouteIter.next();
- if (routes.get(route)) {
- break;
+ boolean drawing = false;
+ for (int route = 0; route < 5; route++) {
+ if ((busStop.routes & (1 << route)) != 0) {
+ if (routes[route]) {
+ drawing = true;
+ break;
+ }
}
- continue;
}
+ if (!drawing)
+ continue;
return busStop;
}
diff --git a/src/net/cbaines/suma/DataManager.java b/src/net/cbaines/suma/DataManager.java
index 461189f..b82d31f 100644
--- a/src/net/cbaines/suma/DataManager.java
+++ b/src/net/cbaines/suma/DataManager.java
@@ -29,7 +29,6 @@ import java.util.Date;
import java.util.GregorianCalendar;
import java.util.HashMap;
import java.util.Iterator;
-import java.util.List;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.parsers.SAXParser;
@@ -206,10 +205,12 @@ public class DataManager {
Dao<BusStop, String> busStopDao = helper.getBusStopDao();
Dao<BusRoute, Integer> busRouteDao = helper.getBusRouteDao();
Dao<RouteStops, Integer> routeStopsDao = helper.getRouteStopsDao();
+ Dao<Direction, Integer> directionDao = helper.getDirectionDao();
TableUtils.clearTable(helper.getConnectionSource(), BusStop.class);
TableUtils.clearTable(helper.getConnectionSource(), BusRoute.class);
TableUtils.clearTable(helper.getConnectionSource(), RouteStops.class);
+ TableUtils.clearTable(helper.getConnectionSource(), Direction.class);
Log.i(TAG, "Loading busstops from csv");
@@ -272,6 +273,14 @@ public class DataManager {
e.printStackTrace();
}
+ directionDao.create(new Direction("A", busRouteDao.queryForId(326)));
+ directionDao.create(new Direction("C", busRouteDao.queryForId(326)));
+ directionDao.create(new Direction("E", busRouteDao.queryForId(326)));
+ directionDao.create(new Direction("B", busRouteDao.queryForId(329)));
+ directionDao.create(new Direction("C", busRouteDao.queryForId(329)));
+ directionDao.create(new Direction("C", busRouteDao.queryForId(327)));
+ directionDao.create(new Direction("H", busRouteDao.queryForId(327)));
+
Log.i(TAG, "Finished loading routes, now loading routestops");
inputStream = context.getAssets().open("routestops.csv");
@@ -306,7 +315,17 @@ public class DataManager {
routeStopsDao.create(new RouteStops(stop, route, sequence));
- stop.routes.add(route);
+ if (route.id == 326) { // U1
+ stop.routes = (byte) (stop.routes | 1);
+ } else if (route.id == 468) { // U1N
+ stop.routes = (byte) (stop.routes | (1 << 1));
+ } else if (route.id == 329) { // U2
+ stop.routes = (byte) (stop.routes | (1 << 2));
+ } else if (route.id == 327) { // U6
+ stop.routes = (byte) (stop.routes | (1 << 3));
+ } else if (route.id == 354) { // U9
+ stop.routes = (byte) (stop.routes | (1 << 4));
+ }
Log.v(TAG, "Stop routes " + stop.routes);
busStopDao.update(stop);
@@ -414,8 +433,6 @@ public class DataManager {
busDao = helper.getBusDao();
if (busStopDao == null)
busStopDao = helper.getBusStopDao();
- if (stopDao == null)
- stopDao = helper.getStopDao();
try {
String time = stopObj.getString("time");
@@ -459,7 +476,7 @@ public class DataManager {
}
for (Direction possibleDir : route.directions) {
- if (name.charAt(3) == possibleDir.direction.charAt(0)) {
+ if (name.charAt(2) == possibleDir.direction.charAt(0)) {
dir = possibleDir;
break;
}
@@ -545,8 +562,6 @@ public class DataManager {
helper = OpenHelperManager.getHelper(context, DatabaseHelper.class);
if (busRoutes == null)
busRoutes = helper.getBusRouteDao();
- if (stopDao == null)
- stopDao = helper.getStopDao();
if (busStopDao == null)
busStopDao = helper.getBusStopDao();
diff --git a/src/net/cbaines/suma/DatabaseHelper.java b/src/net/cbaines/suma/DatabaseHelper.java
index 00f441f..d5790a3 100644
--- a/src/net/cbaines/suma/DatabaseHelper.java
+++ b/src/net/cbaines/suma/DatabaseHelper.java
@@ -51,7 +51,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
private Dao<RouteStops, Integer> routeStopsDao = null;
private Dao<Site, String> siteDao = null;
private Dao<Bus, Integer> busDao = null;
- private Dao<Stop, Integer> stopDao = null;
+ private Dao<Direction, Integer> directionDao = null;
private Context context;
@@ -71,7 +71,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
TableUtils.createTable(connectionSource, RouteStops.class);
TableUtils.createTable(connectionSource, Site.class);
TableUtils.createTable(connectionSource, Bus.class);
- TableUtils.createTable(connectionSource, Stop.class);
+ TableUtils.createTable(connectionSource, Direction.class);
} catch (SQLException e) {
Log.e(DatabaseHelper.class.getName(), "Can't create database", e);
throw new RuntimeException(e);
@@ -82,18 +82,10 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
public void onUpgrade(SQLiteDatabase database, ConnectionSource connectionSource, int oldVersion, int newVersion) {
try {
Log.i(DatabaseHelper.class.getName(), "onUpgrade");
- TableUtils.dropTable(connectionSource, Building.class, true);
- TableUtils.dropTable(connectionSource, BusStop.class, true);
- TableUtils.dropTable(connectionSource, BusRoute.class, true);
- TableUtils.dropTable(connectionSource, RouteStops.class, true);
- TableUtils.dropTable(connectionSource, Site.class, true);
- TableUtils.dropTable(connectionSource, Bus.class, true);
- TableUtils.dropTable(connectionSource, Stop.class, true);
- // after we drop the old databases, we create the new ones
- onCreate(database, connectionSource);
- } catch (SQLException e) {
- Log.e(DatabaseHelper.class.getName(), "Can't drop databases", e);
- throw new RuntimeException(e);
+ copyDataBase();
+
+ } catch (IOException e) {
+ e.printStackTrace();
}
}
@@ -151,21 +143,21 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
/**
* Returns the Database Access Object (DAO) for our SimpleData class. It will create it or just give the cached value.
*/
- public Dao<Bus, Integer> getBusDao() throws SQLException {
- if (busDao == null) {
- busDao = getDao(Bus.class);
+ public Dao<Direction, Integer> getDirectionDao() throws SQLException {
+ if (directionDao == null) {
+ directionDao = getDao(Direction.class);
}
- return busDao;
+ return directionDao;
}
/**
* Returns the Database Access Object (DAO) for our SimpleData class. It will create it or just give the cached value.
*/
- public Dao<Stop, Integer> getStopDao() throws SQLException {
- if (stopDao == null) {
- stopDao = getDao(Stop.class);
+ public Dao<Bus, Integer> getBusDao() throws SQLException {
+ if (busDao == null) {
+ busDao = getDao(Bus.class);
}
- return stopDao;
+ return busDao;
}
/**
@@ -275,6 +267,6 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
routeStopsDao = null;
siteDao = null;
busDao = null;
- stopDao = null;
+ directionDao = null;
}
} \ No newline at end of file
diff --git a/src/net/cbaines/suma/Direction.java b/src/net/cbaines/suma/Direction.java
index 698e352..1ea0fcd 100644
--- a/src/net/cbaines/suma/Direction.java
+++ b/src/net/cbaines/suma/Direction.java
@@ -1,5 +1,31 @@
package net.cbaines.suma;
+import com.j256.ormlite.field.DatabaseField;
+import com.j256.ormlite.table.DatabaseTable;
+
+@DatabaseTable(tableName = "directions")
public class Direction {
+
+ public final static String ROUTE_ID_FIELD_NAME = "route_id";
+
+ @DatabaseField(generatedId = true)
+ int id;
+
+ @DatabaseField(canBeNull = false)
String direction;
+
+ @DatabaseField(foreign = true, columnName = ROUTE_ID_FIELD_NAME)
+ BusRoute route;
+
+ Direction() {
+ }
+
+ Direction(String dir, BusRoute route) {
+ this.direction = dir;
+ this.route = route;
+ }
+
+ public String toString() {
+ return direction;
+ }
}
diff --git a/src/net/cbaines/suma/RouteStops.java b/src/net/cbaines/suma/RouteStops.java
index 8375785..1206153 100644
--- a/src/net/cbaines/suma/RouteStops.java
+++ b/src/net/cbaines/suma/RouteStops.java
@@ -47,7 +47,6 @@ public class RouteStops {
BusRoute route;
RouteStops() {
- // for ormlite
}
public RouteStops(BusStop stop, BusRoute route, int sequence) {
diff --git a/src/net/cbaines/suma/SouthamptonUniversityMapActivity.java b/src/net/cbaines/suma/SouthamptonUniversityMapActivity.java
index c172cdc..5e8caa8 100644
--- a/src/net/cbaines/suma/SouthamptonUniversityMapActivity.java
+++ b/src/net/cbaines/suma/SouthamptonUniversityMapActivity.java
@@ -75,7 +75,7 @@ import com.j256.ormlite.dao.Dao;
public class SouthamptonUniversityMapActivity extends OrmLiteBaseActivity<DatabaseHelper> implements MapViewConstants, Runnable, RouteColorConstants,
OnChildClickListener, OnItemClickListener, OnItemLongClickListener, OnSharedPreferenceChangeListener {
- private boolean useBundledDatabase = true;
+ private boolean useBundledDatabase = false;
private MapView mapView;
private MapController mapController;
@@ -694,17 +694,13 @@ public class SouthamptonUniversityMapActivity extends OrmLiteBaseActivity<Databa
Collections.sort(mapView.getOverlays(), comparator);
}
}
- try {
- Dao<BusRoute, Integer> busRouteDao = getHelper().getBusRouteDao();
- busStopOverlay.setRoutes(busRouteDao.queryForId(326), activityPrefs.getBoolean("Bus Stops:U1", BUS_STOP_OVERLAY_ENABLED_BY_DEFAULT));
- busStopOverlay.setRoutes(busRouteDao.queryForId(468), activityPrefs.getBoolean("Bus Stops:U1N", BUS_STOP_OVERLAY_ENABLED_BY_DEFAULT));
- busStopOverlay.setRoutes(busRouteDao.queryForId(329), activityPrefs.getBoolean("Bus Stops:U2", BUS_STOP_OVERLAY_ENABLED_BY_DEFAULT));
- busStopOverlay.setRoutes(busRouteDao.queryForId(327), activityPrefs.getBoolean("Bus Stops:U6", BUS_STOP_OVERLAY_ENABLED_BY_DEFAULT));
- busStopOverlay.setRoutes(busRouteDao.queryForId(354), activityPrefs.getBoolean("Bus Stops:U9", BUS_STOP_OVERLAY_ENABLED_BY_DEFAULT));
- } catch (SQLException e) {
- e.printStackTrace();
- }
+ busStopOverlay.setRoutes(0, activityPrefs.getBoolean("Bus Stops:U1", BUS_STOP_OVERLAY_ENABLED_BY_DEFAULT));
+ busStopOverlay.setRoutes(1, activityPrefs.getBoolean("Bus Stops:U1N", BUS_STOP_OVERLAY_ENABLED_BY_DEFAULT));
+ busStopOverlay.setRoutes(2, activityPrefs.getBoolean("Bus Stops:U2", BUS_STOP_OVERLAY_ENABLED_BY_DEFAULT));
+ busStopOverlay.setRoutes(3, activityPrefs.getBoolean("Bus Stops:U6", BUS_STOP_OVERLAY_ENABLED_BY_DEFAULT));
+ busStopOverlay.setRoutes(4, activityPrefs.getBoolean("Bus Stops:U9", BUS_STOP_OVERLAY_ENABLED_BY_DEFAULT));
+
mapView.postInvalidate();
Log.i(TAG, "Finished showing bus stop overlays at " + (System.currentTimeMillis() - startTime));