From 6e971428e780adc781c3d8146168590dabec7ada Mon Sep 17 00:00:00 2001 From: Christopher Baines Date: Fri, 24 Feb 2012 20:47:11 +0000 Subject: Added a BuildingActivity, with a photo, and am begining to use rdf data :) --- src/net/cbaines/suma/BusStopOverlay.java | 480 ++++++++++++++++--------------- 1 file changed, 243 insertions(+), 237 deletions(-) (limited to 'src/net/cbaines/suma/BusStopOverlay.java') diff --git a/src/net/cbaines/suma/BusStopOverlay.java b/src/net/cbaines/suma/BusStopOverlay.java index 06a1729..060ad47 100644 --- a/src/net/cbaines/suma/BusStopOverlay.java +++ b/src/net/cbaines/suma/BusStopOverlay.java @@ -44,308 +44,314 @@ import com.j256.ormlite.dao.Dao; public class BusStopOverlay extends Overlay implements RouteColorConstants { - List busStops; + List busStops; - private final Point mCurScreenCoords = new Point(); - private final Point mTouchScreenPoint = new Point(); - private final Point mItemPoint = new Point(); + private final Point mCurScreenCoords = new Point(); + private final Point mTouchScreenPoint = new Point(); + private final Point mItemPoint = new Point(); - private final Rect mRect = new Rect(); + private final Rect mRect = new Rect(); - private final Drawable marker; - private final Drawable favMarker; + private final Drawable marker; + private final Drawable favMarker; - private final Paint paint; + private final Paint paint; - private static final String TAG = "BusStopOverlay"; + private static final String TAG = "BusStopOverlay"; - private final MapActivity context; + private final MapActivity context; - private Dao busStopDao; + private Dao busStopDao; - private float userScale = 1f; + private float userScale = 1f; - private boolean[] routes = new boolean[5]; + private boolean[] routes = new boolean[5]; - public BusStopOverlay(MapActivity context, List busStops) throws SQLException { - super(context); + public BusStopOverlay(MapActivity context, List busStops) throws SQLException { + super(context); - this.context = context; + this.context = context; - marker = context.getResources().getDrawable(R.drawable.busstop); - favMarker = context.getResources().getDrawable(R.drawable.busstop_fav); + 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(); + DatabaseHelper helper = OpenHelperManager.getHelper(context, DatabaseHelper.class); + busStopDao = helper.getBusStopDao(); - paint = new Paint(); - paint.setStyle(Style.FILL); - paint.setStrokeWidth(6); + paint = new Paint(); + paint.setStyle(Style.FILL); + paint.setStrokeWidth(6); - this.busStops = busStops; - } - - void setRoutes(int route, boolean visible) { - routes[route] = visible; - } - - @Override - public void draw(final Canvas canvas, final MapView mapView, final boolean shadow) { - - if (shadow) { - return; + this.busStops = busStops; } - float scale = mScale * userScale; + void setRoutes(int route, boolean visible) { + routes[route] = visible; + } - final Projection pj = mapView.getProjection(); + @Override + public void draw(final Canvas canvas, final MapView mapView, final boolean shadow) { - final int markerWidth = (int) (marker.getIntrinsicWidth() * userScale); - final int markerHeight = (int) (marker.getIntrinsicHeight() * userScale); + if (shadow) { + return; + } - mRect.set(0, 0, 0 + markerWidth, 0 + markerHeight); - mRect.offset(-markerWidth / 2, -markerHeight); - marker.setBounds(mRect); - favMarker.setBounds(mRect); + float scale = mScale * userScale; - /* Draw in backward cycle, so the items with the least index are on the front. */ + final Projection pj = mapView.getProjection(); - for (int stopNum = 0; stopNum < busStops.size(); stopNum++) { - BusStop stop = busStops.get(stopNum); + final int markerWidth = (int) (marker.getIntrinsicWidth() * userScale); + final int markerHeight = (int) (marker.getIntrinsicHeight() * userScale); - byte routeNum = 0; - final byte stopRoutes = stop.routes; + mRect.set(0, 0, 0 + markerWidth, 0 + markerHeight); + mRect.offset(-markerWidth / 2, -markerHeight); + marker.setBounds(mRect); + favMarker.setBounds(mRect); - boolean drawing = false; + /* + * Draw in backward cycle, so the items with the least index are on the + * front. + */ - if (stop.uniLink) { + for (int stopNum = 0; stopNum < busStops.size(); stopNum++) { + BusStop stop = busStops.get(stopNum); - for (int i = 0; i < 5; i++) { - if ((stopRoutes & (1 << i)) != 0) { - routeNum++; - if (routes[i]) { - drawing = true; - } - } - } + byte routeNum = 0; + final byte stopRoutes = stop.routes; - if (!drawing) - continue; + boolean drawing = false; - } + if (stop.uniLink) { - pj.toMapPixels(stop.point, mCurScreenCoords); + for (int i = 0; i < 5; i++) { + if ((stopRoutes & (1 << i)) != 0) { + routeNum++; + if (routes[i]) { + drawing = true; + } + } + } - if (stop.favourite) { - Overlay.drawAt(canvas, favMarker, mCurScreenCoords.x, mCurScreenCoords.y, false); - } else { - Overlay.drawAt(canvas, marker, mCurScreenCoords.x, mCurScreenCoords.y, false); - } + if (!drawing) + continue; - if (stop.uniLink) { + } - int makersPlaced = 0; - int yOfsetPerMarker = (int) (10 * scale); - int markerYSize = (int) (8 * scale); + pj.toMapPixels(stop.point, mCurScreenCoords); - float rectLeft = mCurScreenCoords.x + (8.8f * scale); - float rectRight = rectLeft + markerYSize; + if (stop.favourite) { + Overlay.drawAt(canvas, favMarker, mCurScreenCoords.x, mCurScreenCoords.y, false); + } else { + Overlay.drawAt(canvas, marker, mCurScreenCoords.x, mCurScreenCoords.y, false); + } - if (routeNum == 5) { - markerYSize = (int) (5 * scale); - yOfsetPerMarker = (int) (7 * scale); - } else if (routeNum == 4) { - markerYSize = (int) (6.5f * scale); - yOfsetPerMarker = (int) (8 * scale); + if (stop.uniLink) { + + int makersPlaced = 0; + 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); + } else if (routeNum == 4) { + markerYSize = (int) (6.5f * scale); + yOfsetPerMarker = (int) (8 * scale); + } + + 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"); + } + + canvas.drawRect(rectLeft, mCurScreenCoords.y + + ((yOfsetPerMarker * makersPlaced) - (45 * scale)), rectRight, mCurScreenCoords.y + + (yOfsetPerMarker * makersPlaced) - ((45 * scale) - markerYSize), paint); + + makersPlaced++; + } + } + } } + } - for (int i = 0; i < 5; i++) { - if ((stopRoutes & (1 << i)) != 0) { + @Override + public boolean onSingleTapConfirmed(final MotionEvent event, final MapView mapView) { - // Log.i(TAG, "Route " + route + " is " + routes.get(route)); + BusStop busStop = getSelectedItem(event, mapView); - // Log.i(TAG, "Index is " + busRoutes.indexOf(route) + " busRoutes " + busRoutes); + if (busStop == null) { + // Log.v(TAG, "No busStop pressed"); + return false; + } else { + Log.i(TAG, "busStop Pressed " + busStop.id); - 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); + if (context.activityToast == null) { + context.activityToast = Toast.makeText(context, busStop.description + " (" + busStop.id + ")", + Toast.LENGTH_SHORT); } else { - Log.e(TAG, "Unknown route code"); + context.activityToast.setDuration(Toast.LENGTH_SHORT); + context.activityToast.setText(busStop.description + " (" + busStop.id + ")"); } + context.activityToast.show(); - canvas.drawRect(rectLeft, mCurScreenCoords.y - + ((yOfsetPerMarker * makersPlaced) - (45 * scale)), rectRight, mCurScreenCoords.y - + (yOfsetPerMarker * makersPlaced) - ((45 * scale) - markerYSize), paint); - - makersPlaced++; - } + return true; } - } } - } - - @Override - public boolean onSingleTapConfirmed(final MotionEvent event, final MapView mapView) { - BusStop busStop = getSelectedItem(event, mapView); + public boolean onDoubleTap(final MotionEvent event, final MapView mapView) { - if (busStop == null) { - // Log.v(TAG, "No busStop pressed"); - return false; - } else { - Log.i(TAG, "busStop Pressed " + busStop.id); + BusStop busStop = getSelectedItem(event, mapView); - if (context.activityToast == null) { - 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 + ")"); - } - context.activityToast.show(); - - return true; - } - } - - public boolean onDoubleTap(final MotionEvent event, final MapView mapView) { - - BusStop busStop = getSelectedItem(event, mapView); + if (busStop == null) { + // Log.v(TAG, "No busStop pressed"); + return false; + } else { + Log.i(TAG, "Pressed " + busStop.id); - if (busStop == null) { - // Log.v(TAG, "No busStop pressed"); - return false; - } else { - Log.i(TAG, "Pressed " + busStop.id); + Intent i = new Intent(context, BusStopActivity.class); + i.putExtra("busStopID", busStop.id); + i.putExtra("busStopName", busStop.description); + ((Activity) context).startActivityForResult(i, 0); - Intent i = new Intent(context, BusStopActivity.class); - i.putExtra("busStopID", busStop.id); - i.putExtra("busStopName", busStop.description); - ((Activity) context).startActivityForResult(i, 0); + return true; + } - return true; } - } - - @Override - public boolean onLongPress(final MotionEvent event, final MapView mapView) { - - BusStop busStop = getSelectedItem(event, mapView); + @Override + public boolean onLongPress(final MotionEvent event, final MapView mapView) { - if (busStop == null) { - // Log.v(TAG, "No busStop pressed"); - return false; - } else { - Log.i(TAG, "Pressed " + busStop.id); + BusStop busStop = getSelectedItem(event, mapView); - if (busStop.favourite) { - busStop.favourite = false; - - if (context.activityToast == null) { - 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"); - } - context.activityToast.show(); - } else { - if (context.activityToast == null) { - context.activityToast = Toast.makeText(context, busStop.id + " made a favourite", - Toast.LENGTH_SHORT); + if (busStop == null) { + // Log.v(TAG, "No busStop pressed"); + return false; } else { - context.activityToast.setDuration(Toast.LENGTH_SHORT); - context.activityToast.setText(busStop.id + " made a favourite"); - } - context.activityToast.show(); - - busStop.favourite = true; - } + Log.i(TAG, "Pressed " + busStop.id); + + if (busStop.favourite) { + busStop.favourite = false; + + if (context.activityToast == null) { + 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"); + } + context.activityToast.show(); + } else { + if (context.activityToast == null) { + 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; + } - try { - busStopDao.update(busStop); - } catch (SQLException e) { - e.printStackTrace(); - } + try { + busStopDao.update(busStop); + } catch (SQLException e) { + e.printStackTrace(); + } - Collections.sort(busStops, new POIFavouriteComparator()); + Collections.sort(busStops, new POIFavouriteComparator()); - mapView.invalidate(); + 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); + return true; } - } - } 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); - } + + 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(); + } } - } - - private BusStop getSelectedItem(final MotionEvent event, final MapView mapView) { - final Projection pj = mapView.getProjection(); - final int eventX = (int) event.getX(); - final int eventY = (int) event.getY(); - - /* These objects are created to avoid construct new ones every cycle. */ - pj.fromMapPixels(eventX, eventY, mTouchScreenPoint); - - for (int i = busStops.size() - 1; i > 0; i--) { - BusStop busStop = busStops.get(i); - - pj.toPixels(busStop.point, mItemPoint); - - if (marker.getBounds().contains(mTouchScreenPoint.x - mItemPoint.x, mTouchScreenPoint.y - mItemPoint.y)) { - if (busStop.uniLink) { - boolean drawing = false; - for (int route = 0; route < 5; route++) { - if ((busStop.routes & (1 << route)) != 0) { - if (routes[route]) { - drawing = true; - break; - } + + /** + * 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); } - } - if (!drawing) - continue; } + } - return busStop; - } + private BusStop getSelectedItem(final MotionEvent event, final MapView mapView) { + final Projection pj = mapView.getProjection(); + final int eventX = (int) event.getX(); + final int eventY = (int) event.getY(); + + /* These objects are created to avoid construct new ones every cycle. */ + pj.fromMapPixels(eventX, eventY, mTouchScreenPoint); + + for (int i = busStops.size() - 1; i > 0; i--) { + BusStop busStop = busStops.get(i); + + pj.toPixels(busStop.point, mItemPoint); + + if (marker.getBounds().contains(mTouchScreenPoint.x - mItemPoint.x, mTouchScreenPoint.y - mItemPoint.y)) { + if (busStop.uniLink) { + boolean drawing = false; + for (int route = 0; route < 5; route++) { + if ((busStop.routes & (1 << route)) != 0) { + if (routes[route]) { + drawing = true; + break; + } + } + } + if (!drawing) + continue; + } + + return busStop; + } + } + return null; } - return null; - } } -- cgit v1.2.3 From 731a2b26410f6fa6427acdf675376742793c6332 Mon Sep 17 00:00:00 2001 From: Christopher Baines Date: Sun, 26 Feb 2012 17:09:58 +0000 Subject: Optimised the custom overlays. --- src/net/cbaines/suma/BusStopOverlay.java | 109 ++++++++++--------------------- 1 file changed, 34 insertions(+), 75 deletions(-) (limited to 'src/net/cbaines/suma/BusStopOverlay.java') 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 busStops; @@ -61,8 +59,6 @@ public class BusStopOverlay extends Overlay implements RouteColorConstants { private final MapActivity context; - private Dao 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))); + } + } -- cgit v1.2.3 From b640f758e603305a3c32c283c9237dbe47f2cdee Mon Sep 17 00:00:00 2001 From: Christopher Baines Date: Sun, 26 Feb 2012 19:48:31 +0000 Subject: Fixed another bug to do with a unreactive bus stop, improved the U1 route overlay. --- src/net/cbaines/suma/BusStopOverlay.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'src/net/cbaines/suma/BusStopOverlay.java') diff --git a/src/net/cbaines/suma/BusStopOverlay.java b/src/net/cbaines/suma/BusStopOverlay.java index 176bd4f..7894be2 100644 --- a/src/net/cbaines/suma/BusStopOverlay.java +++ b/src/net/cbaines/suma/BusStopOverlay.java @@ -274,6 +274,8 @@ public class BusStopOverlay extends Overlay implements RouteColorConstants, Pref } private BusStop getSelectedItem(final MotionEvent event, final MapView mapView) { + Log.i(TAG, "Getting selected item"); + final Projection pj = mapView.getProjection(); final int eventX = (int) event.getX(); final int eventY = (int) event.getY(); @@ -281,7 +283,7 @@ public class BusStopOverlay extends Overlay implements RouteColorConstants, Pref /* These objects are created to avoid construct new ones every cycle. */ pj.fromMapPixels(eventX, eventY, mTouchScreenPoint); - for (int i = busStops.size() - 1; i > 0; i--) { + for (int i = busStops.size() - 1; i >= 0; i--) { BusStop busStop = busStops.get(i); pj.toPixels(busStop.point, mItemPoint); -- cgit v1.2.3 From 9b09f1286a8a003f0d24f745f648748cd3c2f2e2 Mon Sep 17 00:00:00 2001 From: Christopher Baines Date: Sun, 26 Feb 2012 23:21:13 +0000 Subject: More bug fixes, with the location overlay. --- src/net/cbaines/suma/BusStopOverlay.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'src/net/cbaines/suma/BusStopOverlay.java') diff --git a/src/net/cbaines/suma/BusStopOverlay.java b/src/net/cbaines/suma/BusStopOverlay.java index 7894be2..4705d1d 100644 --- a/src/net/cbaines/suma/BusStopOverlay.java +++ b/src/net/cbaines/suma/BusStopOverlay.java @@ -246,7 +246,7 @@ public class BusStopOverlay extends Overlay implements RouteColorConstants, Pref SharedPreferences favouritesPreferences = context.getSharedPreferences(FAVOURITES_PREFERENCES, 0); if (favouritesPreferences.getBoolean(busStop.id, false)) { - favouritesPreferences.edit().putBoolean(busStop.id, false).commit(); + favouritesPreferences.edit().remove(busStop.id).commit(); if (context.activityToast == null) { context.activityToast = Toast.makeText(context, busStop.id + " removed from favourites", Toast.LENGTH_SHORT); @@ -267,6 +267,8 @@ public class BusStopOverlay extends Overlay implements RouteColorConstants, Pref favouritesPreferences.edit().putBoolean(busStop.id, true).commit(); } + Collections.sort(busStops, new POIFavouriteComparator(context.getSharedPreferences(FAVOURITES_PREFERENCES, 0))); + mapView.invalidate(); return true; -- cgit v1.2.3