aboutsummaryrefslogtreecommitdiff
path: root/src/net
diff options
context:
space:
mode:
authorChristopher Baines <cbaines8@gmail.com>2012-02-26 17:09:58 +0000
committerChristopher Baines <cbaines8@gmail.com>2012-02-26 17:09:58 +0000
commit731a2b26410f6fa6427acdf675376742793c6332 (patch)
treec50b0901a748c5055ed46be89a297ebba9af06d9 /src/net
parentb88f5cabd4cf4876c3e5ba32acb2a7e59dd03edc (diff)
downloadsouthamptonuniversitymap-731a2b26410f6fa6427acdf675376742793c6332.tar
southamptonuniversitymap-731a2b26410f6fa6427acdf675376742793c6332.tar.gz
Optimised the custom overlays.
Diffstat (limited to 'src/net')
-rw-r--r--src/net/cbaines/suma/BuildingActivity.java120
-rw-r--r--src/net/cbaines/suma/BuildingNumOverlay.java92
-rw-r--r--src/net/cbaines/suma/BusStopActivity.java35
-rw-r--r--src/net/cbaines/suma/BusStopOverlay.java109
-rw-r--r--src/net/cbaines/suma/DataManager.java62
-rw-r--r--src/net/cbaines/suma/MapActivity.java195
-rw-r--r--src/net/cbaines/suma/POI.java3
-rw-r--r--src/net/cbaines/suma/POIFavouriteComparator.java32
-rw-r--r--src/net/cbaines/suma/Preferences.java2
9 files changed, 235 insertions, 415 deletions
diff --git a/src/net/cbaines/suma/BuildingActivity.java b/src/net/cbaines/suma/BuildingActivity.java
index 930c2d1..45babbc 100644
--- a/src/net/cbaines/suma/BuildingActivity.java
+++ b/src/net/cbaines/suma/BuildingActivity.java
@@ -23,38 +23,30 @@ import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
-import java.util.Iterator;
+import java.sql.SQLException;
import android.content.Context;
+import android.content.SharedPreferences;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.util.Log;
+import android.view.Display;
import android.view.View;
+import android.view.WindowManager;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.ImageButton;
+import android.widget.ImageView.ScaleType;
import android.widget.TextView;
-import com.hp.hpl.jena.query.Query;
-import com.hp.hpl.jena.query.QueryExecution;
-import com.hp.hpl.jena.query.QueryExecutionFactory;
-import com.hp.hpl.jena.query.QueryFactory;
-import com.hp.hpl.jena.query.QuerySolution;
-import com.hp.hpl.jena.query.ResultSet;
-import com.hp.hpl.jena.rdf.model.Literal;
-import com.hp.hpl.jena.rdf.model.Model;
-import com.hp.hpl.jena.rdf.model.RDFNode;
-import com.hp.hpl.jena.rdf.model.Resource;
-import com.hp.hpl.jena.tdb.TDBFactory;
import com.j256.ormlite.android.apptools.OrmLiteBaseActivity;
+import com.j256.ormlite.dao.Dao;
-public class BuildingActivity extends OrmLiteBaseActivity<DatabaseHelper> implements OnCheckedChangeListener {
+public class BuildingActivity extends OrmLiteBaseActivity<DatabaseHelper> implements OnCheckedChangeListener, Preferences {
final static String TAG = "BusTimeActivity";
- private boolean dataChanged;
-
private Context instance;
private ImageButton imageButton;
@@ -62,6 +54,8 @@ public class BuildingActivity extends OrmLiteBaseActivity<DatabaseHelper> implem
private TextView buildingName;
private TextView buildingID;
+ private Building building;
+
private CheckBox favouritesCheckBox;
public void onCreate(Bundle savedInstanceState) {
@@ -71,8 +65,10 @@ public class BuildingActivity extends OrmLiteBaseActivity<DatabaseHelper> implem
String ID = getIntent().getExtras().getString("buildingID");
+ final SharedPreferences favouritesPrefs = instance.getSharedPreferences(FAVOURITES_PREFERENCES, 0);
+
favouritesCheckBox = (CheckBox) findViewById(R.id.buildingActivityFavouriteCheckBox);
- // favouritesCheckBox.setChecked(busStop.favourite);
+ favouritesCheckBox.setChecked(favouritesPrefs.getBoolean(ID, false));
favouritesCheckBox.setOnCheckedChangeListener(this);
buildingName = (TextView) findViewById(R.id.buildingActivityName);
@@ -80,17 +76,61 @@ public class BuildingActivity extends OrmLiteBaseActivity<DatabaseHelper> implem
Log.i(TAG, "Building id " + ID);
- buildingID.setText(ID);
+ try {
+ Dao<Building, String> buildingDao = getHelper().getBuildingDao();
+
+ building = buildingDao.queryForId(ID);
+
+ buildingName.setText(building.name);
+ } catch (SQLException e1) {
+ // TODO Auto-generated catch block
+ e1.printStackTrace();
+ }
+
+ buildingID.setText(ID);
try {
- URL url = new URL("http://data.southampton.ac.uk/images/buildings/600/" + ID + ".jpg");
- InputStream is = (InputStream) url.getContent();
+ /* First, get the Display from the WindowManager */
+ Display display = ((WindowManager) getSystemService(WINDOW_SERVICE)).getDefaultDisplay();
+
+ /* Now we can retrieve all display-related infos */
+ int orientation = display.getOrientation();
+ Log.i(TAG, "orientation " + orientation);
+ Log.i(TAG, "width " + display.getWidth() + " height " + display.getHeight());
+ int width;
+ // if (orientation == 0) {
+ width = display.getWidth();
+ // } else {
+ // width = display.getHeight();
+ // }
+
+ URL imageURL;
+ Log.i(TAG, "Screen width " + width);
+ if (width >= 1000) {
+ imageURL = new URL("http://data.southampton.ac.uk/images/buildings/1000/" + ID + ".jpg");
+ } else if (width >= 800) {
+ imageURL = new URL("http://data.southampton.ac.uk/images/buildings/1000/" + ID + ".jpg");
+ } else if (width >= 600) {
+ imageURL = new URL("http://data.southampton.ac.uk/images/buildings/600/" + ID + ".jpg");
+ } else if (width >= 400) {
+ imageURL = new URL("http://data.southampton.ac.uk/images/buildings/600/" + ID + ".jpg");
+ } else if (width >= 300) {
+ imageURL = new URL("http://data.southampton.ac.uk/images/buildings/300/" + ID + ".jpg");
+ } else if (width >= 200) {
+ imageURL = new URL("http://data.southampton.ac.uk/images/buildings/200/" + ID + ".jpg");
+ } else {
+ imageURL = new URL("http://data.southampton.ac.uk/images/buildings/100/" + ID + ".jpg");
+ }
+ Log.i(TAG, "URL " + imageURL);
+
+ InputStream is = (InputStream) imageURL.getContent();
Drawable image = Drawable.createFromStream(is, "src");
imageButton = new ImageButton(this);
imageButton = (ImageButton) findViewById(R.id.buildingActivityImage);
imageButton.setImageDrawable(image);
+ imageButton.setScaleType(ScaleType.CENTER_INSIDE);
imageButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
@@ -105,51 +145,18 @@ public class BuildingActivity extends OrmLiteBaseActivity<DatabaseHelper> implem
e.printStackTrace();
}
- String directory = "/data/data/net.cbaines.suma/databases";
- Model model = TDBFactory.createModel(directory);
-
- String queryString = ID;
- Query query = QueryFactory.create(queryString);
- QueryExecution qexec = QueryExecutionFactory.create(query, model);
- try {
- ResultSet results = qexec.execSelect();
- for (; results.hasNext();) {
- QuerySolution soln = results.nextSolution();
-
- Log.i(TAG, "solution " + soln.toString());
-
- for (Iterator<String> iter = soln.varNames(); iter.hasNext();) {
- Log.i(TAG, "solnVarName " + iter.next());
- }
-
- // RDFNode x = soln.get("varName"); // Get a result variable by
- // name.
- // Resource r = soln.getResource("VarR"); // Get a result
- // variable
- // - must be a resource
- // Literal l = soln.getLiteral("VarL"); // Get a result variable
- // -
- // must be a literal
- }
- } finally {
- qexec.close();
- }
-
}
public void onResume() {
super.onResume();
-
}
public void onPause() {
-
super.onPause();
}
public void finish() {
setResult(RESULT_OK, getIntent());
-
super.finish();
}
@@ -158,9 +165,14 @@ public class BuildingActivity extends OrmLiteBaseActivity<DatabaseHelper> implem
return null;
}
- public void onCheckedChanged(CompoundButton arg0, boolean arg1) {
- // TODO Auto-generated method stub
+ public void onCheckedChanged(CompoundButton button, boolean checked) {
+ SharedPreferences favouritesPreferences = getSharedPreferences(FAVOURITES_PREFERENCES, 0);
+ if (checked) {
+ favouritesPreferences.edit().putBoolean(building.id, true).commit();
+ } else {
+ favouritesPreferences.edit().remove(building.id).commit();
+ }
}
}
diff --git a/src/net/cbaines/suma/BuildingNumOverlay.java b/src/net/cbaines/suma/BuildingNumOverlay.java
index 74688a0..887f8b7 100644
--- a/src/net/cbaines/suma/BuildingNumOverlay.java
+++ b/src/net/cbaines/suma/BuildingNumOverlay.java
@@ -31,6 +31,8 @@ import org.osmdroid.views.overlay.Overlay;
import android.app.Activity;
import android.content.Intent;
+import android.content.SharedPreferences;
+import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
@@ -42,10 +44,7 @@ import android.util.Log;
import android.view.MotionEvent;
import android.widget.Toast;
-import com.j256.ormlite.android.apptools.OpenHelperManager;
-import com.j256.ormlite.dao.Dao;
-
-public class BuildingNumOverlay extends Overlay {
+public class BuildingNumOverlay extends Overlay implements Preferences, OnSharedPreferenceChangeListener {
private ArrayList<Building> buildings;
@@ -64,8 +63,6 @@ public class BuildingNumOverlay extends Overlay {
private final MapActivity context;
- private Dao<Building, String> buildingDao;
-
private float userScale = 1f;
public BuildingNumOverlay(MapActivity context, List<Building> buildings) throws SQLException {
@@ -76,8 +73,8 @@ public class BuildingNumOverlay extends Overlay {
marker = context.getResources().getDrawable(R.drawable.building);
favMarker = context.getResources().getDrawable(R.drawable.building_fav);
- DatabaseHelper helper = OpenHelperManager.getHelper(context, DatabaseHelper.class);
- buildingDao = helper.getBuildingDao();
+ final SharedPreferences favouritesPrefs = context.getSharedPreferences(FAVOURITES_PREFERENCES, 0);
+ favouritesPrefs.registerOnSharedPreferenceChangeListener(this);
paint = new Paint();
paint.setColor(Color.BLACK);
@@ -91,33 +88,24 @@ public class BuildingNumOverlay extends Overlay {
}
/**
- * Draw a marker on each of our items. populate() must have been called
- * first.<br/>
+ * Draw a marker on each of our items. populate() must have been called first.<br/>
* <br/>
- * The marker will be drawn twice for each Item in the Overlay--once in the
- * shadow phase, skewed and darkened, then again in the non-shadow phase.
- * The bottom-center of the marker will be aligned with the geographical
- * coordinates of the Item.<br/>
+ * The marker will be drawn twice for each Item in the Overlay--once in the shadow phase, skewed and darkened, then again in
+ * the non-shadow phase. The bottom-center of the marker will be aligned with the geographical coordinates of the Item.<br/>
* <br/>
- * The order of drawing may be changed by overriding the getIndexToDraw(int)
- * method. An item may provide an alternate marker via its
- * OverlayItem.getMarker(int) method. If that method returns null, the
- * default marker is used.<br/>
+ * The order of drawing may be changed by overriding the getIndexToDraw(int) method. An item may provide an alternate marker
+ * via its OverlayItem.getMarker(int) method. If that method returns null, the default marker is used.<br/>
* <br/>
- * The focused item is always drawn last, which puts it visually on top of
- * the other items.<br/>
+ * The focused item is always drawn last, which puts it visually on top of the other items.<br/>
*
* @param canvas
- * the Canvas upon which to draw. Note that this may already have
- * a transformation applied, so be sure to leave it the way you
- * found it
+ * the Canvas upon which to draw. Note that this may already have a transformation applied, so be sure to leave it
+ * the way you found it
* @param mapView
- * the MapView that requested the draw. Use
- * MapView.getProjection() to convert between on-screen pixels
- * and latitude/longitude pairs
+ * the MapView that requested the draw. Use MapView.getProjection() to convert between on-screen pixels and
+ * latitude/longitude pairs
* @param shadow
- * if true, draw the shadow layer. If false, draw the overlay
- * contents.
+ * if true, draw the shadow layer. If false, draw the overlay contents.
*/
@Override
public void draw(final Canvas canvas, final MapView mapView, final boolean shadow) {
@@ -138,9 +126,10 @@ public class BuildingNumOverlay extends Overlay {
marker.setBounds(mRect);
favMarker.setBounds(mRect);
+ final SharedPreferences favouritesPrefs = context.getSharedPreferences(FAVOURITES_PREFERENCES, 0);
+
/*
- * Draw in backward cycle, so the items with the least index are on the
- * front.
+ * Draw in backward cycle, so the items with the least index are on the front.
*/
for (Iterator<Building> buildingIter = buildings.iterator(); buildingIter.hasNext();) {
final Building building = buildingIter.next();
@@ -148,9 +137,12 @@ public class BuildingNumOverlay extends Overlay {
// Log.i(TAG, "Looking at drawing stop " + stop.id);
pj.toMapPixels(building.point, mCurScreenCoords);
+ if (!pj.getBoundingBox().increaseByScale(1.2f).contains(building.point)) {
+ continue;
+ }
// draw it
- if (building.favourite) {
+ if (favouritesPrefs.getBoolean(building.id, false)) {
Overlay.drawAt(canvas, favMarker, mCurScreenCoords.x, mCurScreenCoords.y, false);
} else {
Overlay.drawAt(canvas, marker, mCurScreenCoords.x, mCurScreenCoords.y, false);
@@ -208,8 +200,7 @@ public class BuildingNumOverlay extends Overlay {
Log.v(TAG, "building Pressed " + building.id);
if (context.activityToast == null) {
- context.activityToast = Toast.makeText(context, building.name + " (" + building.id + ")",
- Toast.LENGTH_SHORT);
+ context.activityToast = Toast.makeText(context, building.name + " (" + building.id + ")", Toast.LENGTH_SHORT);
} else {
context.activityToast.setDuration(Toast.LENGTH_SHORT);
context.activityToast.setText(building.name + " (" + building.id + ")");
@@ -252,12 +243,13 @@ public class BuildingNumOverlay extends Overlay {
} else {
Log.v(TAG, "building Pressed " + building.id);
- if (building.favourite) {
- building.favourite = false;
+ final SharedPreferences favouritesPrefs = context.getSharedPreferences(FAVOURITES_PREFERENCES, 0);
+
+ if (favouritesPrefs.getBoolean(building.id, false)) {
+ favouritesPrefs.edit().remove(building.id).commit();
if (context.activityToast == null) {
- context.activityToast = Toast.makeText(context, building.id + " removed from favourites",
- Toast.LENGTH_SHORT);
+ context.activityToast = Toast.makeText(context, building.id + " removed from favourites", Toast.LENGTH_SHORT);
} else {
context.activityToast.setDuration(Toast.LENGTH_SHORT);
context.activityToast.setText(building.id + " removed from favourites");
@@ -266,25 +258,16 @@ public class BuildingNumOverlay extends Overlay {
} else {
if (context.activityToast == null) {
- context.activityToast = Toast.makeText(context, building.id + " made a favourite",
- Toast.LENGTH_SHORT);
+ context.activityToast = Toast.makeText(context, building.id + " made a favourite", Toast.LENGTH_SHORT);
} else {
context.activityToast.setDuration(Toast.LENGTH_SHORT);
context.activityToast.setText(building.id + " made a favourite");
}
context.activityToast.show();
- building.favourite = true;
+ favouritesPrefs.edit().putBoolean(building.id, true).commit();
}
- try {
- buildingDao.update(building);
- } catch (SQLException e) {
- e.printStackTrace();
- }
-
- Collections.sort(buildings, new POIFavouriteComparator());
-
mapView.invalidate();
return true;
@@ -313,17 +296,10 @@ public class BuildingNumOverlay extends Overlay {
return null;
}
- public void refresh() {
- for (int i = 0; i < buildings.size(); i++) {
- refresh(buildings.get(i));
- }
- }
+ public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
+ Log.i(TAG, "Got a favourites change in the BuildingNumOverlay for key " + key);
- public void refresh(Building building) {
- if (building.favourite) {
- buildings.remove(building);
- buildings.add(building);
- }
+ Collections.sort(buildings, new POIFavouriteComparator(context.getSharedPreferences(FAVOURITES_PREFERENCES, 0)));
}
}
diff --git a/src/net/cbaines/suma/BusStopActivity.java b/src/net/cbaines/suma/BusStopActivity.java
index 0d4dea4..bc8e22e 100644
--- a/src/net/cbaines/suma/BusStopActivity.java
+++ b/src/net/cbaines/suma/BusStopActivity.java
@@ -59,13 +59,11 @@ 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,
- Preferences, OnItemClickListener {
+public class BusStopActivity extends OrmLiteBaseActivity<DatabaseHelper> implements OnCheckedChangeListener, Preferences,
+ OnItemClickListener {
final static String TAG = "BusTimeActivity";
- private boolean dataChanged;
-
private ListView busTimeList;
private TextView busName;
private TextView busID;
@@ -110,6 +108,8 @@ public class BusStopActivity extends OrmLiteBaseActivity<DatabaseHelper> impleme
final DatabaseHelper helper = getHelper();
+ SharedPreferences favouritesPreferences = getSharedPreferences(FAVOURITES_PREFERENCES, 0);
+
instance = this;
busStopID = getIntent().getExtras().getString("busStopID");
@@ -184,7 +184,7 @@ public class BusStopActivity extends OrmLiteBaseActivity<DatabaseHelper> impleme
busStop = busStopDao.queryForId(busStopID);
busFavourite = (CheckBox) findViewById(R.id.favouriteCheckBox);
- busFavourite.setChecked(busStop.favourite);
+ busFavourite.setChecked(favouritesPreferences.getBoolean(busStop.id, false));
busFavourite.setOnCheckedChangeListener(this);
} catch (SQLException e) {
@@ -257,23 +257,18 @@ public class BusStopActivity extends OrmLiteBaseActivity<DatabaseHelper> impleme
}
public void finish() {
- if (dataChanged) {
- getIntent().putExtra("busStopChanged", busStopID);
- }
-
setResult(RESULT_OK, getIntent());
-
super.finish();
}
public void onCheckedChanged(CompoundButton button, boolean checked) {
if (button.equals(busFavourite)) {
- busStop.favourite = checked;
- try {
- busStopDao.update(busStop);
- dataChanged = true;
- } catch (SQLException e) {
- e.printStackTrace();
+ SharedPreferences favouritesPreferences = getSharedPreferences(FAVOURITES_PREFERENCES, 0);
+
+ if (checked) {
+ favouritesPreferences.edit().putBoolean(busStop.id, true).commit();
+ } else {
+ favouritesPreferences.edit().remove(busStop.id).commit();
}
} else {
Log.i(TAG, "Route radio button made " + checked);
@@ -300,10 +295,10 @@ public class BusStopActivity extends OrmLiteBaseActivity<DatabaseHelper> impleme
try {
final SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(instance);
- newTimetable = DataManager.getTimetable(instance, busStopID, sharedPrefs.getBoolean(
- MapActivity.UNI_LINK_BUS_TIMES, MapActivity.UNI_LINK_BUS_TIMES_ENABLED_BY_DEFAULT), sharedPrefs
- .getBoolean(MapActivity.NON_UNI_LINK_BUS_TIMES,
- MapActivity.NON_UNI_LINK_BUS_TIMES_ENABLED_BY_DEFAULT));
+ newTimetable = DataManager
+ .getTimetable(instance, busStopID, sharedPrefs.getBoolean(MapActivity.UNI_LINK_BUS_TIMES,
+ MapActivity.UNI_LINK_BUS_TIMES_ENABLED_BY_DEFAULT), sharedPrefs.getBoolean(
+ MapActivity.NON_UNI_LINK_BUS_TIMES, MapActivity.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 060ad47..176bd4f 100644
--- a/src/net/cbaines/suma/BusStopOverlay.java
+++ b/src/net/cbaines/suma/BusStopOverlay.java
@@ -29,6 +29,7 @@ import org.osmdroid.views.overlay.Overlay;
import android.app.Activity;
import android.content.Intent;
+import android.content.SharedPreferences;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Paint.Style;
@@ -39,10 +40,7 @@ import android.util.Log;
import android.view.MotionEvent;
import android.widget.Toast;
-import com.j256.ormlite.android.apptools.OpenHelperManager;
-import com.j256.ormlite.dao.Dao;
-
-public class BusStopOverlay extends Overlay implements RouteColorConstants {
+public class BusStopOverlay extends Overlay implements RouteColorConstants, Preferences {
List<BusStop> busStops;
@@ -61,8 +59,6 @@ public class BusStopOverlay extends Overlay implements RouteColorConstants {
private final MapActivity context;
- private Dao<BusStop, String> busStopDao;
-
private float userScale = 1f;
private boolean[] routes = new boolean[5];
@@ -75,9 +71,6 @@ public class BusStopOverlay extends Overlay implements RouteColorConstants {
marker = context.getResources().getDrawable(R.drawable.busstop);
favMarker = context.getResources().getDrawable(R.drawable.busstop_fav);
- DatabaseHelper helper = OpenHelperManager.getHelper(context, DatabaseHelper.class);
- busStopDao = helper.getBusStopDao();
-
paint = new Paint();
paint.setStyle(Style.FILL);
paint.setStrokeWidth(6);
@@ -96,7 +89,7 @@ public class BusStopOverlay extends Overlay implements RouteColorConstants {
return;
}
- float scale = mScale * userScale;
+ final float scale = mScale * userScale;
final Projection pj = mapView.getProjection();
@@ -108,14 +101,20 @@ public class BusStopOverlay extends Overlay implements RouteColorConstants {
marker.setBounds(mRect);
favMarker.setBounds(mRect);
+ final SharedPreferences favouritesPreferences = context.getSharedPreferences(FAVOURITES_PREFERENCES, 0);
+
/*
- * Draw in backward cycle, so the items with the least index are on the
- * front.
+ * Draw in backward cycle, so the items with the least index are on the front.
*/
for (int stopNum = 0; stopNum < busStops.size(); stopNum++) {
BusStop stop = busStops.get(stopNum);
+ pj.toMapPixels(stop.point, mCurScreenCoords);
+ if (!pj.getBoundingBox().increaseByScale(1.2f).contains(stop.point)) {
+ continue;
+ }
+
byte routeNum = 0;
final byte stopRoutes = stop.routes;
@@ -137,9 +136,7 @@ public class BusStopOverlay extends Overlay implements RouteColorConstants {
}
- pj.toMapPixels(stop.point, mCurScreenCoords);
-
- if (stop.favourite) {
+ if (favouritesPreferences.getBoolean(stop.id, false)) {
Overlay.drawAt(canvas, favMarker, mCurScreenCoords.x, mCurScreenCoords.y, false);
} else {
Overlay.drawAt(canvas, marker, mCurScreenCoords.x, mCurScreenCoords.y, false);
@@ -148,12 +145,13 @@ public class BusStopOverlay extends Overlay implements RouteColorConstants {
if (stop.uniLink) {
int makersPlaced = 0;
+
+ final float rectLeft = mCurScreenCoords.x + (8.8f * scale);
+ final float rectRight = rectLeft + (int) (8 * scale);
+
int yOfsetPerMarker = (int) (10 * scale);
int markerYSize = (int) (8 * scale);
- float rectLeft = mCurScreenCoords.x + (8.8f * scale);
- float rectRight = rectLeft + markerYSize;
-
if (routeNum == 5) {
markerYSize = (int) (5 * scale);
yOfsetPerMarker = (int) (7 * scale);
@@ -165,12 +163,6 @@ public class BusStopOverlay extends Overlay implements RouteColorConstants {
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) {
@@ -185,9 +177,9 @@ public class BusStopOverlay extends Overlay implements RouteColorConstants {
Log.e(TAG, "Unknown route code");
}
- canvas.drawRect(rectLeft, mCurScreenCoords.y
- + ((yOfsetPerMarker * makersPlaced) - (45 * scale)), rectRight, mCurScreenCoords.y
- + (yOfsetPerMarker * makersPlaced) - ((45 * scale) - markerYSize), paint);
+ canvas.drawRect(rectLeft, mCurScreenCoords.y + ((yOfsetPerMarker * makersPlaced) - (45 * scale)),
+ rectRight, mCurScreenCoords.y + (yOfsetPerMarker * makersPlaced) - ((45 * scale) - markerYSize),
+ paint);
makersPlaced++;
}
@@ -208,8 +200,8 @@ public class BusStopOverlay extends Overlay implements RouteColorConstants {
Log.i(TAG, "busStop Pressed " + busStop.id);
if (context.activityToast == null) {
- context.activityToast = Toast.makeText(context, busStop.description + " (" + busStop.id + ")",
- Toast.LENGTH_SHORT);
+ context.activityToast = Toast
+ .makeText(context, busStop.description + " (" + busStop.id + ")", Toast.LENGTH_SHORT);
} else {
context.activityToast.setDuration(Toast.LENGTH_SHORT);
context.activityToast.setText(busStop.description + " (" + busStop.id + ")");
@@ -251,12 +243,13 @@ public class BusStopOverlay extends Overlay implements RouteColorConstants {
} else {
Log.i(TAG, "Pressed " + busStop.id);
- if (busStop.favourite) {
- busStop.favourite = false;
+ SharedPreferences favouritesPreferences = context.getSharedPreferences(FAVOURITES_PREFERENCES, 0);
+
+ if (favouritesPreferences.getBoolean(busStop.id, false)) {
+ favouritesPreferences.edit().putBoolean(busStop.id, false).commit();
if (context.activityToast == null) {
- context.activityToast = Toast.makeText(context, busStop.id + " removed from favourites",
- Toast.LENGTH_SHORT);
+ context.activityToast = Toast.makeText(context, busStop.id + " removed from favourites", Toast.LENGTH_SHORT);
} else {
context.activityToast.setDuration(Toast.LENGTH_SHORT);
context.activityToast.setText(busStop.id + " removed from favourites");
@@ -264,62 +257,22 @@ public class BusStopOverlay extends Overlay implements RouteColorConstants {
context.activityToast.show();
} else {
if (context.activityToast == null) {
- context.activityToast = Toast.makeText(context, busStop.id + " made a favourite",
- Toast.LENGTH_SHORT);
+ context.activityToast = Toast.makeText(context, busStop.id + " made a favourite", Toast.LENGTH_SHORT);
} else {
context.activityToast.setDuration(Toast.LENGTH_SHORT);
context.activityToast.setText(busStop.id + " made a favourite");
}
context.activityToast.show();
- busStop.favourite = true;
+ favouritesPreferences.edit().putBoolean(busStop.id, true).commit();
}
- try {
- busStopDao.update(busStop);
- } catch (SQLException e) {
- e.printStackTrace();
- }
-
- Collections.sort(busStops, new POIFavouriteComparator());
-
mapView.invalidate();
return true;
}
}
- public void refresh() {
- try {
- for (int i = 0; i < busStops.size(); i++) {
- BusStop busStop = busStops.get(i);
- busStopDao.refresh(busStop);
- if (busStop.favourite) {
- busStops.remove(i);
- busStops.add(busStop);
- } else {
- busStops.set(i, busStop);
- }
- }
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
-
- /**
- * Replaces any bus stops that equal the argument in the overlay with the
- * argument
- *
- * @param busStop
- */
- public void refresh(BusStop busStop) {
- for (int i = 0; i < busStops.size(); i++) {
- if (busStop.equals(busStops.get(i))) {
- busStops.set(i, busStop);
- }
- }
- }
-
private BusStop getSelectedItem(final MotionEvent event, final MapView mapView) {
final Projection pj = mapView.getProjection();
final int eventX = (int) event.getX();
@@ -354,4 +307,10 @@ public class BusStopOverlay extends Overlay implements RouteColorConstants {
return null;
}
+ public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
+ Log.i(TAG, "Got a favourites change in the BuildingNumOverlay for key " + key);
+
+ Collections.sort(busStops, new POIFavouriteComparator(context.getSharedPreferences(FAVOURITES_PREFERENCES, 0)));
+ }
+
}
diff --git a/src/net/cbaines/suma/DataManager.java b/src/net/cbaines/suma/DataManager.java
index b4a0e3d..fbede76 100644
--- a/src/net/cbaines/suma/DataManager.java
+++ b/src/net/cbaines/suma/DataManager.java
@@ -23,8 +23,6 @@ import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
-import java.io.PrintWriter;
-import java.io.StringWriter;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Calendar;
@@ -60,8 +58,6 @@ import org.xml.sax.XMLReader;
import android.content.Context;
import android.util.Log;
-import com.hp.hpl.jena.rdf.model.Model;
-import com.hp.hpl.jena.tdb.TDBFactory;
import com.j256.ormlite.android.apptools.OpenHelperManager;
import com.j256.ormlite.dao.Dao;
import com.j256.ormlite.stmt.PreparedQuery;
@@ -213,64 +209,6 @@ public class DataManager {
}
- public static void loadBuildingPhotos(Context context) {
- // Direct way: Make a TDB-backed Jena model in the named directory.
- String directory = "/data/data/net.cbaines.suma/databases";
- Model model = TDBFactory.createModel(directory);
-
- Log.i(TAG, "Created the model");
-
- // write it to standard out
- StringWriter sw = new StringWriter();
- model.write(new PrintWriter(sw));
- Log.v(TAG, sw.toString());
-
- Log.i(TAG, "Finished the first output");
-
- if (model.isEmpty()) {
-
- Log.i(TAG, "Model is empty");
-
- // use the FileManager to find the input file
- InputStream in;
- try {
-
- String[] datasets = { "photos.rdf", "places.rdf" };
-
- for (String dataset : datasets) {
-
- in = context.getAssets().open(dataset);
-
- if (in == null) {
- throw new IllegalArgumentException(dataset + " not found");
- }
-
- // read the RDF/XML file
- model.read(in, null);
-
- Log.i(TAG, "Finished the read of " + dataset);
-
- }
-
- // write it to standard out
- sw = new StringWriter();
- model.write(new PrintWriter(sw));
- Log.i(TAG, sw.toString());
-
- Log.i(TAG, "Finished the second output");
-
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
-
- }
-
- model.close();
-
- Log.i(TAG, "Closed the model");
- }
-
public static void loadBusData(Context context, boolean onlyUniLink) throws SQLException, IOException {
DatabaseHelper helper = OpenHelperManager.getHelper(context, DatabaseHelper.class);
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();
}
}
diff --git a/src/net/cbaines/suma/POI.java b/src/net/cbaines/suma/POI.java
index 244198d..e815731 100644
--- a/src/net/cbaines/suma/POI.java
+++ b/src/net/cbaines/suma/POI.java
@@ -48,9 +48,6 @@ public abstract class POI {
@DatabaseField(id = true)
public String id;
- @DatabaseField(canBeNull = false)
- public boolean favourite; // This field is not assessed by equals
-
public int distTo = -1; // Used by the comparator to store distances, then later by the gui to display them.
public String type;
diff --git a/src/net/cbaines/suma/POIFavouriteComparator.java b/src/net/cbaines/suma/POIFavouriteComparator.java
index 94148d4..341ff4c 100644
--- a/src/net/cbaines/suma/POIFavouriteComparator.java
+++ b/src/net/cbaines/suma/POIFavouriteComparator.java
@@ -21,20 +21,28 @@ package net.cbaines.suma;
import java.util.Comparator;
+import android.content.SharedPreferences;
+
public class POIFavouriteComparator implements Comparator<POI> {
- public int compare(POI poi1, POI poi2) {
- if (poi1.favourite) {
- if (poi2.favourite) {
- return 0;
- } else {
- return 1;
- }
- } else if (poi2.favourite) {
- return -1;
- } else {
- return 0;
+ SharedPreferences favourites;
+
+ POIFavouriteComparator(SharedPreferences favourites) {
+ this.favourites = favourites;
+ }
+
+ public int compare(POI poi1, POI poi2) {
+ if (favourites.getBoolean(poi1.id, false)) {
+ if (favourites.getBoolean(poi2.id, false)) {
+ return 0;
+ } else {
+ return 1;
+ }
+ } else if (favourites.getBoolean(poi2.id, false)) {
+ return -1;
+ } else {
+ return 0;
+ }
}
- }
}
diff --git a/src/net/cbaines/suma/Preferences.java b/src/net/cbaines/suma/Preferences.java
index a978dd9..84e1d27 100644
--- a/src/net/cbaines/suma/Preferences.java
+++ b/src/net/cbaines/suma/Preferences.java
@@ -10,4 +10,6 @@ public interface Preferences {
static final boolean NON_UNI_LINK_BUS_TIMES_ENABLED_BY_DEFAULT = false;
static final String NON_UNI_LINK_BUS_STOPS_OVERLAY = "nonUniLinkBusStops";
static final boolean NON_UNI_LINK_BUS_STOP_OVERLAY_ENABLED_BY_DEFAULT = false;
+
+ static final String FAVOURITES_PREFERENCES = "favourites";
}