diff options
author | Christopher Baines <cbaines8@gmail.com> | 2012-02-29 19:37:44 +0000 |
---|---|---|
committer | Christopher Baines <cbaines8@gmail.com> | 2012-02-29 19:37:44 +0000 |
commit | ff96598874103eb2141f01b8b9ace300dfd3ab45 (patch) | |
tree | 6be99c7ab481a863ff521102178738eecfbd50ee /src/net | |
parent | 5f2b8712079aeb5b7cee476b06b36013edac4fb3 (diff) | |
download | southamptonuniversitymap-ff96598874103eb2141f01b8b9ace300dfd3ab45.tar southamptonuniversitymap-ff96598874103eb2141f01b8b9ace300dfd3ab45.tar.gz |
New Toast stuff, needs some work.
Diffstat (limited to 'src/net')
-rw-r--r-- | src/net/cbaines/suma/BuildingNumOverlay.java | 28 | ||||
-rw-r--r-- | src/net/cbaines/suma/BusStopOverlay.java | 47 | ||||
-rw-r--r-- | src/net/cbaines/suma/MapActivity.java | 13 | ||||
-rw-r--r-- | src/net/cbaines/suma/ToastHelperActivity.java | 26 |
4 files changed, 52 insertions, 62 deletions
diff --git a/src/net/cbaines/suma/BuildingNumOverlay.java b/src/net/cbaines/suma/BuildingNumOverlay.java index a4cf556..3e2a731 100644 --- a/src/net/cbaines/suma/BuildingNumOverlay.java +++ b/src/net/cbaines/suma/BuildingNumOverlay.java @@ -209,14 +209,7 @@ public class BuildingNumOverlay extends Overlay implements Preferences, OnShared } else { Log.v(TAG, "building Pressed " + building.id); - if (context.activityToast == null) { - 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 + ")"); - } - context.activityToast.show(); + context.makeToast(building.name + " (" + building.id + ")", Toast.LENGTH_SHORT); return true; } @@ -262,24 +255,9 @@ public class BuildingNumOverlay extends Overlay implements Preferences, OnShared 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); - } else { - context.activityToast.setDuration(Toast.LENGTH_SHORT); - context.activityToast.setText(building.id + " removed from favourites"); - } - context.activityToast.show(); - + context.makeToast(building.id + " removed from favourites", Toast.LENGTH_SHORT); } else { - if (context.activityToast == null) { - 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(); + context.makeToast(building.id + " made a favourite", Toast.LENGTH_SHORT); favouritesPrefs.edit().putBoolean(building.id, true).commit(); } diff --git a/src/net/cbaines/suma/BusStopOverlay.java b/src/net/cbaines/suma/BusStopOverlay.java index b8f1077..254e03a 100644 --- a/src/net/cbaines/suma/BusStopOverlay.java +++ b/src/net/cbaines/suma/BusStopOverlay.java @@ -36,6 +36,7 @@ import android.graphics.Point; import android.graphics.Rect; import android.graphics.drawable.Drawable; import android.net.Uri; +import android.preference.PreferenceManager; import android.util.Log; import android.view.MotionEvent; import android.widget.Toast; @@ -63,6 +64,8 @@ public class BusStopOverlay extends Overlay implements RouteColorConstants, Pref private boolean[] routes = new boolean[5]; + private boolean showIdentifiers; + public BusStopOverlay(MapActivity context, List<BusStop> busStops) throws SQLException { super(context); @@ -71,6 +74,9 @@ public class BusStopOverlay extends Overlay implements RouteColorConstants, Pref marker = context.getResources().getDrawable(R.drawable.busstop); favMarker = context.getResources().getDrawable(R.drawable.busstop_fav); + showIdentifiers = PreferenceManager.getDefaultSharedPreferences(context).getBoolean(SHOW_IDENTIFIERS, + SHOW_IDENTIFIERS_ENABLED_BY_DEFAULT); + paint = new Paint(); paint.setStyle(Style.FILL); paint.setStrokeWidth(6); @@ -104,7 +110,8 @@ 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++) { @@ -177,9 +184,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++; } @@ -199,14 +206,12 @@ public class BusStopOverlay extends Overlay implements RouteColorConstants, Pref } else { Log.i(TAG, "busStop Pressed " + busStop.id); - 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 + ")"); + String str = busStop.description; + if (showIdentifiers) { + str += " (" + busStop.id + ")"; } - context.activityToast.show(); + str += "\n" + context.getResources().getString(R.string.map_activity_toast_help_message); + context.makeToast(str, Toast.LENGTH_SHORT); return true; } @@ -250,26 +255,16 @@ public class BusStopOverlay extends Overlay implements RouteColorConstants, Pref if (favouritesPreferences.getBoolean(busStop.id, false)) { favouritesPreferences.edit().remove(busStop.id).commit(); - 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(); + context.makeToast(busStop.id + " removed from favourites", Toast.LENGTH_SHORT); + } 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(); + context.makeToast(busStop.id + " made a favourite", 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 8a7a39a..728591d 100644 --- a/src/net/cbaines/suma/MapActivity.java +++ b/src/net/cbaines/suma/MapActivity.java @@ -61,9 +61,7 @@ import android.view.View; import android.widget.AdapterView; import android.widget.AdapterView.OnItemClickListener; import android.widget.AdapterView.OnItemLongClickListener; -import android.widget.Toast; -import com.j256.ormlite.android.apptools.OrmLiteBaseActivity; import com.j256.ormlite.dao.Dao; /** @@ -71,9 +69,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 ToastHelperActivity implements MapViewConstants, Runnable, RouteColorConstants, + OnItemClickListener, OnItemLongClickListener, OnSharedPreferenceChangeListener, Preferences { /** * Enable to use the database in the assets folder, if its not enabled, the @@ -175,12 +172,6 @@ public class MapActivity extends OrmLiteBaseActivity<DatabaseHelper> implements static final String[][] PREFERENCES_CHILDREN = { UNI_LINK_ROUTES, UNI_LINK_ROUTES, BUILDING_TYPES, SITE_NAMES, OTHER_OVERLAY_NAMES }; - /** - * The toast for this activity, storing the toast centrally allows it to be - * changed quickly, instead of a queue building up - */ - Toast activityToast; - private MapActivity instance; private static final String TAG = "SUM"; diff --git a/src/net/cbaines/suma/ToastHelperActivity.java b/src/net/cbaines/suma/ToastHelperActivity.java new file mode 100644 index 0000000..6c5974c --- /dev/null +++ b/src/net/cbaines/suma/ToastHelperActivity.java @@ -0,0 +1,26 @@ +package net.cbaines.suma; + +import android.widget.TextView; +import android.widget.Toast; + +import com.j256.ormlite.android.apptools.OrmLiteBaseActivity; + +public class ToastHelperActivity extends OrmLiteBaseActivity<DatabaseHelper> { + + protected Toast toast; + protected TextView toastView; + + void makeToast(String message, int length) { + if (toastView == null) { + toastView = (TextView) getLayoutInflater().inflate(R.layout.toast_view, null); + } + toastView.setText(message); + if (toast == null) { + toast = new Toast(this); + } + toast.setDuration(length); + toast.setView(toastView); + toast.show(); + } + +} |