From ac9a84e8bb5dc43a5d72840eaa325c5e99ac610a Mon Sep 17 00:00:00 2001 From: Christopher Baines Date: Thu, 8 Mar 2012 22:03:48 +0000 Subject: Beginings of a welcome dialog, and overlay improvements. --- src/net/cbaines/suma/BuildingNumOverlay.java | 58 +++++++++++++--------------- src/net/cbaines/suma/BusStopOverlay.java | 33 +++++++++------- src/net/cbaines/suma/MapActivity.java | 7 ++++ src/net/cbaines/suma/WelcomeDialog.java | 48 +++++++++++++++++++++++ 4 files changed, 101 insertions(+), 45 deletions(-) create mode 100644 src/net/cbaines/suma/WelcomeDialog.java (limited to 'src/net') diff --git a/src/net/cbaines/suma/BuildingNumOverlay.java b/src/net/cbaines/suma/BuildingNumOverlay.java index f11a166..b541aa1 100644 --- a/src/net/cbaines/suma/BuildingNumOverlay.java +++ b/src/net/cbaines/suma/BuildingNumOverlay.java @@ -94,33 +94,24 @@ public class BuildingNumOverlay extends Overlay implements Preferences, OnShared } /** - * Draw a marker on each of our items. populate() must have been called - * first.
+ * Draw a marker on each of our items. populate() must have been called first.
*
- * 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.
+ * 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.
*
- * 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.
+ * 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.
*
- * The focused item is always drawn last, which puts it visually on top of - * the other items.
+ * The focused item is always drawn last, which puts it visually on top of the other items.
* * @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) { @@ -144,8 +135,7 @@ public class BuildingNumOverlay extends Overlay implements Preferences, OnShared 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 buildingIter = buildings.iterator(); buildingIter.hasNext();) { final Building building = buildingIter.next(); @@ -219,8 +209,7 @@ public class BuildingNumOverlay extends Overlay implements Preferences, OnShared if (showIdentifiers) { str += " (" + building.id + ")"; } - context.makeToast(str, context.getResources().getString(R.string.map_activity_toast_help_message), - Toast.LENGTH_SHORT); + context.makeToast(str, context.getResources().getString(R.string.map_activity_toast_help_message), Toast.LENGTH_SHORT); return true; } @@ -230,7 +219,7 @@ public class BuildingNumOverlay extends Overlay implements Preferences, OnShared public boolean onDoubleTap(final MotionEvent event, final MapView mapView) { if (!this.isEnabled()) return false; - + Building building = getSelectedItem(event, mapView); if (building == null) { @@ -265,19 +254,27 @@ public class BuildingNumOverlay extends Overlay implements Preferences, OnShared Log.v(TAG, "building Pressed " + building.id); final SharedPreferences favouritesPrefs = context.getSharedPreferences(FAVOURITES_PREFERENCES, 0); + final SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(context); if (favouritesPrefs.getBoolean(building.id, false)) { favouritesPrefs.edit().remove(building.id).commit(); - context.makeToast(building.id + " removed from favourites", Toast.LENGTH_SHORT); + // if (sharedPrefs.getBoolean(SHOW_IDENTIFIERS, SHOW_IDENTIFIERS_ENABLED_BY_DEFAULT)) { + context.makeToast(building.name + " removed from favourites", "(" + building.id + ")", Toast.LENGTH_SHORT); + // } else { + // context.makeToast(building.name + " removed from favourites", Toast.LENGTH_SHORT); + // } } else { - context.makeToast(building.id + " made a favourite", Toast.LENGTH_SHORT); + // if (sharedPrefs.getBoolean(SHOW_IDENTIFIERS, SHOW_IDENTIFIERS_ENABLED_BY_DEFAULT)) { + context.makeToast(building.name + " added to favourites", "(" + building.id + ")", Toast.LENGTH_SHORT); + // } else { + // context.makeToast(building.name + " added to favourites", Toast.LENGTH_SHORT); + // } favouritesPrefs.edit().putBoolean(building.id, true).commit(); } - Collections.sort(buildings, - new POIFavouriteComparator(context.getSharedPreferences(FAVOURITES_PREFERENCES, 0))); + Collections.sort(buildings, new POIFavouriteComparator(context.getSharedPreferences(FAVOURITES_PREFERENCES, 0))); mapView.invalidate(); @@ -310,8 +307,7 @@ public class BuildingNumOverlay extends Overlay implements Preferences, OnShared public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) { Log.i(TAG, "Got a favourites change in the BuildingNumOverlay for key " + key); - Collections - .sort(buildings, new POIFavouriteComparator(context.getSharedPreferences(FAVOURITES_PREFERENCES, 0))); + Collections.sort(buildings, new POIFavouriteComparator(context.getSharedPreferences(FAVOURITES_PREFERENCES, 0))); } } diff --git a/src/net/cbaines/suma/BusStopOverlay.java b/src/net/cbaines/suma/BusStopOverlay.java index 778b306..b8377cf 100644 --- a/src/net/cbaines/suma/BusStopOverlay.java +++ b/src/net/cbaines/suma/BusStopOverlay.java @@ -110,8 +110,7 @@ public class BusStopOverlay extends Overlay implements RouteColorConstants, Pref 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++) { @@ -184,9 +183,9 @@ public class BusStopOverlay extends Overlay implements RouteColorConstants, Pref 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++; } @@ -210,8 +209,7 @@ public class BusStopOverlay extends Overlay implements RouteColorConstants, Pref if (showIdentifiers) { str += " (" + busStop.id + ")"; } - context.makeToast(str, context.getResources().getString(R.string.map_activity_toast_help_message), - Toast.LENGTH_SHORT); + context.makeToast(str, context.getResources().getString(R.string.map_activity_toast_help_message), Toast.LENGTH_SHORT); return true; } @@ -250,21 +248,28 @@ public class BusStopOverlay extends Overlay implements RouteColorConstants, Pref } else { Log.i(TAG, "Pressed " + busStop.id); - SharedPreferences favouritesPreferences = context.getSharedPreferences(FAVOURITES_PREFERENCES, 0); + final SharedPreferences favouritesPreferences = context.getSharedPreferences(FAVOURITES_PREFERENCES, 0); + final SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(context); if (favouritesPreferences.getBoolean(busStop.id, false)) { favouritesPreferences.edit().remove(busStop.id).commit(); - context.makeToast(busStop.id + " removed from favourites", Toast.LENGTH_SHORT); - + if (sharedPrefs.getBoolean(SHOW_IDENTIFIERS, SHOW_IDENTIFIERS_ENABLED_BY_DEFAULT)) { + context.makeToast(busStop.description + " removed from favourites", "(" + busStop.id + ")", + Toast.LENGTH_SHORT); + } else { + context.makeToast(busStop.description + " removed from favourites", Toast.LENGTH_SHORT); + } } else { - context.makeToast(busStop.id + " made a favourite", Toast.LENGTH_SHORT); - + if (sharedPrefs.getBoolean(SHOW_IDENTIFIERS, SHOW_IDENTIFIERS_ENABLED_BY_DEFAULT)) { + context.makeToast(busStop.description + " added to favourites", "(" + busStop.id + ")", Toast.LENGTH_SHORT); + } else { + context.makeToast(busStop.description + " added to favourites", Toast.LENGTH_SHORT); + } favouritesPreferences.edit().putBoolean(busStop.id, true).commit(); } - Collections.sort(busStops, - new POIFavouriteComparator(context.getSharedPreferences(FAVOURITES_PREFERENCES, 0))); + Collections.sort(busStops, new POIFavouriteComparator(context.getSharedPreferences(FAVOURITES_PREFERENCES, 0))); mapView.invalidate(); diff --git a/src/net/cbaines/suma/MapActivity.java b/src/net/cbaines/suma/MapActivity.java index 6eab356..413ec48 100644 --- a/src/net/cbaines/suma/MapActivity.java +++ b/src/net/cbaines/suma/MapActivity.java @@ -86,6 +86,8 @@ public class MapActivity extends ToastHelperActivity implements MapViewConstants static final int VIEW_DIALOG_ID = 0; static final int FAVOURITE_DIALOG_ID = 1; + static final int WELCOME_DIALOG_ID = 2; + private POIDialog favDialog; private HashMap overlays = new HashMap(); @@ -271,6 +273,8 @@ public class MapActivity extends ToastHelperActivity implements MapViewConstants mapController.setCenter(userLocation); + showDialog(WELCOME_DIALOG_ID); + Log.i(TAG, "Finished onCreate " + (System.currentTimeMillis() - startTime)); } @@ -1079,6 +1083,9 @@ public class MapActivity extends ToastHelperActivity implements MapViewConstants favDialog.setOnItemLongClickListener(this); favDialog.setTitle(R.string.favourites_dialog_title); return favDialog; + case WELCOME_DIALOG_ID: + WelcomeDialog welcomeDialog = new WelcomeDialog(instance); + return welcomeDialog; } return null; } diff --git a/src/net/cbaines/suma/WelcomeDialog.java b/src/net/cbaines/suma/WelcomeDialog.java new file mode 100644 index 0000000..d0d6fd0 --- /dev/null +++ b/src/net/cbaines/suma/WelcomeDialog.java @@ -0,0 +1,48 @@ +/* + * Southampton University Map App + * Copyright (C) 2011 Christopher Baines + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +package net.cbaines.suma; + +import android.app.Dialog; +import android.content.Context; +import android.view.View; +import android.widget.Button; + +public class WelcomeDialog extends Dialog implements android.view.View.OnClickListener { + + // private static final String TAG = "WelcomeDialog"; + + private Button continueButton; + + public WelcomeDialog(Context context) { + super(context); + + this.setTitle(R.string.welcome_dialog_title); + + setContentView(R.layout.welcome_dialog); + + continueButton = (Button) findViewById(R.id.welcomeDialogButton); + continueButton.setOnClickListener(this); + } + + public void onClick(View arg0) { + this.dismiss(); + } + +} -- cgit v1.2.3