diff options
author | Bananeweizen <bananeweizen@gmx.de> | 2011-10-15 08:47:03 +0200 |
---|---|---|
committer | Bananeweizen <bananeweizen@gmx.de> | 2011-10-15 08:47:03 +0200 |
commit | 16c0bb033e858338108653ee95eeff9f80e1f678 (patch) | |
tree | adff6a5f76a9d69088ed9dd86a8cbab86602f894 /main | |
parent | 578e748cc4e829d1f2af34dd371987b54d9b5771 (diff) | |
download | cgeo-16c0bb033e858338108653ee95eeff9f80e1f678.zip cgeo-16c0bb033e858338108653ee95eeff9f80e1f678.tar.gz cgeo-16c0bb033e858338108653ee95eeff9f80e1f678.tar.bz2 |
new: map title describes what is shown, fixes #483
* shows geo code in case of caches
* shows list title in case of lists (works also for search)
* moved all map invocations into map class
* refactored extras keys into String constants
Diffstat (limited to 'main')
-rw-r--r-- | main/src/cgeo/geocaching/apps/cache/navi/InternalMap.java | 28 | ||||
-rw-r--r-- | main/src/cgeo/geocaching/apps/cachelist/InternalCacheListMap.java | 10 | ||||
-rw-r--r-- | main/src/cgeo/geocaching/cgeo.java | 3 | ||||
-rw-r--r-- | main/src/cgeo/geocaching/cgeocaches.java | 7 | ||||
-rw-r--r-- | main/src/cgeo/geocaching/cgeonavigate.java | 8 | ||||
-rw-r--r-- | main/src/cgeo/geocaching/maps/CGeoMap.java | 96 |
6 files changed, 87 insertions, 65 deletions
diff --git a/main/src/cgeo/geocaching/apps/cache/navi/InternalMap.java b/main/src/cgeo/geocaching/apps/cache/navi/InternalMap.java index bccf739..0594558 100644 --- a/main/src/cgeo/geocaching/apps/cache/navi/InternalMap.java +++ b/main/src/cgeo/geocaching/apps/cache/navi/InternalMap.java @@ -1,15 +1,14 @@ package cgeo.geocaching.apps.cache.navi; import cgeo.geocaching.R; -import cgeo.geocaching.Settings; import cgeo.geocaching.cgCache; import cgeo.geocaching.cgGeo; import cgeo.geocaching.cgWaypoint; import cgeo.geocaching.enumerations.WaypointType; import cgeo.geocaching.geopoint.Geopoint; +import cgeo.geocaching.maps.CGeoMap; import android.app.Activity; -import android.content.Intent; import android.content.res.Resources; import java.util.UUID; @@ -25,26 +24,19 @@ class InternalMap extends AbstractInternalMap implements public boolean invoke(cgGeo geo, Activity activity, Resources res, cgCache cache, final UUID searchId, cgWaypoint waypoint, final Geopoint coords) { - Intent mapIntent = new Intent(activity, Settings.getMapFactory().getMapClass()); - if (cache != null) { - mapIntent.putExtra("detail", false); - mapIntent.putExtra("geocode", cache.geocode); - } if (searchId != null) { - mapIntent.putExtra("detail", true); - mapIntent.putExtra("searchid", searchId.toString()); + CGeoMap.startActivitySearch(activity, searchId, cache != null ? cache.geocode : null, true); + } + else if (cache != null) { + CGeoMap.startActivityGeoCode(activity, cache.geocode); + } + else if (waypoint != null) { + CGeoMap.startActivityCoords(activity, waypoint.coords, waypoint.type); } - if (waypoint != null) { - mapIntent.putExtra("latitude", waypoint.coords.getLatitude()); - mapIntent.putExtra("longitude", waypoint.coords.getLongitude()); - mapIntent.putExtra("wpttype", waypoint.type != null ? waypoint.type.id : null); - } else if (coords != null) { - mapIntent.putExtra("latitude", coords.getLatitude()); - mapIntent.putExtra("longitude", coords.getLongitude()); - mapIntent.putExtra("wpttype", WaypointType.WAYPOINT.id); + else if (coords != null) { + CGeoMap.startActivityCoords(activity, coords, WaypointType.WAYPOINT); } - activity.startActivity(mapIntent); return true; } diff --git a/main/src/cgeo/geocaching/apps/cachelist/InternalCacheListMap.java b/main/src/cgeo/geocaching/apps/cachelist/InternalCacheListMap.java index 75997e0..6de5c13 100644 --- a/main/src/cgeo/geocaching/apps/cachelist/InternalCacheListMap.java +++ b/main/src/cgeo/geocaching/apps/cachelist/InternalCacheListMap.java @@ -3,12 +3,11 @@ package cgeo.geocaching.apps.cachelist; import cgeo.geocaching.R; import cgeo.geocaching.cgCache; import cgeo.geocaching.cgGeo; -import cgeo.geocaching.Settings; import cgeo.geocaching.apps.AbstractApp; +import cgeo.geocaching.maps.CGeoMap; import android.app.Activity; import android.content.Context; -import android.content.Intent; import android.content.res.Resources; import java.util.List; @@ -27,12 +26,7 @@ class InternalCacheListMap extends AbstractApp implements CacheListApp { @Override public boolean invoke(cgGeo geo, List<cgCache> caches, Activity activity, Resources res, final UUID searchId) { - Intent mapIntent = new Intent(activity, Settings.getMapFactory() - .getMapClass()); - mapIntent.putExtra("detail", false); // this is the main difference to the activity for a single point - mapIntent.putExtra("searchid", searchId.toString()); - - activity.startActivity(mapIntent); + CGeoMap.startActivitySearch(activity, searchId, null, false); return true; } } diff --git a/main/src/cgeo/geocaching/cgeo.java b/main/src/cgeo/geocaching/cgeo.java index b18a0d6..df81866 100644 --- a/main/src/cgeo/geocaching/cgeo.java +++ b/main/src/cgeo/geocaching/cgeo.java @@ -4,6 +4,7 @@ import cgeo.geocaching.activity.AbstractActivity; import cgeo.geocaching.activity.ActivityMixin; import cgeo.geocaching.enumerations.StatusCode; import cgeo.geocaching.geopoint.Geopoint; +import cgeo.geocaching.maps.CGeoMap; import org.apache.commons.collections.CollectionUtils; import org.apache.commons.lang3.StringUtils; @@ -604,7 +605,7 @@ public class cgeo extends AbstractActivity { */ public void cgeoFindOnMap(View v) { findViewById(R.id.map).setPressed(true); - context.startActivity(new Intent(context, Settings.getMapFactory().getMapClass())); + CGeoMap.startActivityLiveMap(context); } /** diff --git a/main/src/cgeo/geocaching/cgeocaches.java b/main/src/cgeo/geocaching/cgeocaches.java index 5109a79..d15375f 100644 --- a/main/src/cgeo/geocaching/cgeocaches.java +++ b/main/src/cgeo/geocaching/cgeocaches.java @@ -13,6 +13,7 @@ import cgeo.geocaching.filter.cgFilterBySize; import cgeo.geocaching.filter.cgFilterByTrackables; import cgeo.geocaching.filter.cgFilterByType; import cgeo.geocaching.geopoint.Geopoint; +import cgeo.geocaching.maps.CGeoMap; import cgeo.geocaching.sorting.CacheComparator; import cgeo.geocaching.sorting.DateComparator; import cgeo.geocaching.sorting.DifficultyComparator; @@ -2595,11 +2596,7 @@ public class cgeocaches extends AbstractListActivity { return; } - Intent mapIntent = new Intent(this, Settings.getMapFactory().getMapClass()); - mapIntent.putExtra("detail", false); - mapIntent.putExtra("searchid", searchId.toString()); - - startActivity(mapIntent); + CGeoMap.startActivitySearch(this, searchId, title + " [" + app.getCount(searchId) + "]", false); } public void goManual(View view) { diff --git a/main/src/cgeo/geocaching/cgeonavigate.java b/main/src/cgeo/geocaching/cgeonavigate.java index 838bcc3..370b859 100644 --- a/main/src/cgeo/geocaching/cgeonavigate.java +++ b/main/src/cgeo/geocaching/cgeonavigate.java @@ -2,6 +2,7 @@ package cgeo.geocaching; import cgeo.geocaching.activity.AbstractActivity; import cgeo.geocaching.geopoint.Geopoint; +import cgeo.geocaching.maps.CGeoMap; import org.apache.commons.lang3.StringUtils; @@ -242,12 +243,7 @@ public class cgeonavigate extends AbstractActivity { int id = item.getItemId(); if (id == 0) { - Intent mapIntent = new Intent(this, Settings.getMapFactory().getMapClass()); - mapIntent.putExtra("detail", false); - mapIntent.putExtra("latitude", dstCoords.getLatitude()); - mapIntent.putExtra("longitude", dstCoords.getLongitude()); - - startActivity(mapIntent); + CGeoMap.startActivityCoords(this, dstCoords, null); } else if (id == 1) { boolean oldSetting = Settings.isUseCompass(); Settings.setUseCompass(!oldSetting); diff --git a/main/src/cgeo/geocaching/maps/CGeoMap.java b/main/src/cgeo/geocaching/maps/CGeoMap.java index baaa78b..af638e0 100644 --- a/main/src/cgeo/geocaching/maps/CGeoMap.java +++ b/main/src/cgeo/geocaching/maps/CGeoMap.java @@ -32,6 +32,7 @@ import org.apache.commons.lang3.StringUtils; import android.app.Activity; import android.app.ProgressDialog; +import android.content.Context; import android.content.DialogInterface; import android.content.Intent; import android.content.res.Resources; @@ -64,6 +65,13 @@ import java.util.UUID; */ public class CGeoMap extends AbstractMap implements OnDragListener, ViewFactory { + private static final String EXTRAS_GEOCODE = "geocode"; + private static final String EXTRAS_LONGITUDE = "longitude"; + private static final String EXTRAS_LATITUDE = "latitude"; + private static final String EXTRAS_WPTTYPE = "wpttype"; + private static final String EXTRAS_MAPSTATE = "mapstate"; + private static final String EXTRAS_SEARCHID = "searchid"; + private static final String EXTRAS_DETAIL = "detail"; private static final int MENU_SELECT_MAPVIEW = 1; private static final int MENU_MAP_LIVE = 2; private static final int MENU_STORE_CACHES = 3; @@ -77,6 +85,7 @@ public class CGeoMap extends AbstractMap implements OnDragListener, ViewFactory private static final int SUBMENU_VIEW_MF_OSMARENDER = 14; private static final int SUBMENU_VIEW_MF_CYCLEMAP = 15; private static final int SUBMENU_VIEW_MF_OFFLINE = 16; + private static final String EXTRAS_MAP_TITLE = "mapTitle"; private Resources res = null; private Activity activity = null; @@ -167,10 +176,10 @@ public class CGeoMap extends AbstractMap implements OnDragListener, ViewFactory if (live) { title.append(res.getString(R.string.map_live)); } else { - title.append(res.getString(R.string.map_map)); + title.append(mapTitle); } - if (caches != null && cachesCnt > 0) { + if (caches != null && cachesCnt > 0 && !mapTitle.contains("[")) { title.append(" ["); title.append(caches.size()); title.append(']'); @@ -244,6 +253,10 @@ public class CGeoMap extends AbstractMap implements OnDragListener, ViewFactory } } }; + /** + * calling activities can set the map title via extras + */ + private String mapTitle; public CGeoMap(MapActivityImpl activity) { super(activity); @@ -325,14 +338,15 @@ public class CGeoMap extends AbstractMap implements OnDragListener, ViewFactory // get parameters Bundle extras = activity.getIntent().getExtras(); if (extras != null) { - fromDetailIntent = extras.getBoolean("detail"); - searchIdIntent = extras.getString("searchid"); - geocodeIntent = extras.getString("geocode"); - final double latitudeIntent = extras.getDouble("latitude"); - final double longitudeIntent = extras.getDouble("longitude"); + fromDetailIntent = extras.getBoolean(EXTRAS_DETAIL); + searchIdIntent = extras.getString(EXTRAS_SEARCHID); + geocodeIntent = extras.getString(EXTRAS_GEOCODE); + final double latitudeIntent = extras.getDouble(EXTRAS_LATITUDE); + final double longitudeIntent = extras.getDouble(EXTRAS_LONGITUDE); coordsIntent = new Geopoint(latitudeIntent, longitudeIntent); - waypointTypeIntent = WaypointType.FIND_BY_ID.get(extras.getString("wpttype")); - mapStateIntent = extras.getIntArray("mapstate"); + waypointTypeIntent = WaypointType.FIND_BY_ID.get(extras.getString(EXTRAS_WPTTYPE)); + mapStateIntent = extras.getIntArray(EXTRAS_MAPSTATE); + mapTitle = extras.getString(EXTRAS_MAP_TITLE); if ("".equals(searchIdIntent)) { searchIdIntent = null; @@ -342,20 +356,15 @@ public class CGeoMap extends AbstractMap implements OnDragListener, ViewFactory } } - // live or death - //FIXME What? - if (searchIdIntent == null && geocodeIntent == null && coordsIntent == null) { - live = true; - } else { - live = false; + if (StringUtils.isBlank(mapTitle)) { + mapTitle = res.getString(R.string.map_map); } + // live map, if no arguments are given + live = (searchIdIntent == null && geocodeIntent == null && coordsIntent == null); + if (null == mapStateIntent) { - if (live) { - followMyLocation = true; - } else { - followMyLocation = false; - } + followMyLocation = live; } else { followMyLocation = 1 == mapStateIntent[3] ? true : false; } @@ -677,21 +686,21 @@ public class CGeoMap extends AbstractMap implements OnDragListener, ViewFactory // prepare information to restart a similar view Intent mapIntent = new Intent(activity, Settings.getMapFactory().getMapClass()); - mapIntent.putExtra("detail", fromDetailIntent); - mapIntent.putExtra("searchid", searchIdIntent); - mapIntent.putExtra("geocode", geocodeIntent); + mapIntent.putExtra(EXTRAS_DETAIL, fromDetailIntent); + mapIntent.putExtra(EXTRAS_SEARCHID, searchIdIntent); + mapIntent.putExtra(EXTRAS_GEOCODE, geocodeIntent); if (coordsIntent != null) { - mapIntent.putExtra("latitude", coordsIntent.getLatitude()); - mapIntent.putExtra("longitude", coordsIntent.getLongitude()); + mapIntent.putExtra(EXTRAS_LATITUDE, coordsIntent.getLatitude()); + mapIntent.putExtra(EXTRAS_LONGITUDE, coordsIntent.getLongitude()); } - mapIntent.putExtra("wpttype", waypointTypeIntent != null ? waypointTypeIntent.id : null); + mapIntent.putExtra(EXTRAS_WPTTYPE, waypointTypeIntent != null ? waypointTypeIntent.id : null); int[] mapState = new int[4]; GeoPointImpl mapCenter = mapView.getMapViewCenter(); mapState[0] = mapCenter.getLatitudeE6(); mapState[1] = mapCenter.getLongitudeE6(); mapState[2] = mapView.getMapZoomLevel(); mapState[3] = followMyLocation ? 1 : 0; - mapIntent.putExtra("mapstate", mapState); + mapIntent.putExtra(EXTRAS_MAPSTATE, mapState); // start the new map activity.startActivity(mapIntent); @@ -1840,4 +1849,37 @@ public class CGeoMap extends AbstractMap implements OnDragListener, ViewFactory imageView.setLayoutParams(new ImageSwitcher.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT)); return imageView; } + + public static void startActivitySearch(final Activity fromActivity, final UUID searchId, final String title, boolean detail) { + Intent mapIntent = new Intent(fromActivity, Settings.getMapFactory().getMapClass()); + mapIntent.putExtra(EXTRAS_DETAIL, detail); + mapIntent.putExtra(EXTRAS_SEARCHID, searchId.toString()); + if (StringUtils.isNotBlank(title)) { + mapIntent.putExtra(CGeoMap.EXTRAS_MAP_TITLE, title); + } + fromActivity.startActivity(mapIntent); + } + + public static void startActivityLiveMap(final Context context) { + context.startActivity(new Intent(context, Settings.getMapFactory().getMapClass())); + } + + public static void startActivityCoords(final Context context, final Geopoint coords, final WaypointType type) { + Intent mapIntent = new Intent(context, Settings.getMapFactory().getMapClass()); + mapIntent.putExtra(EXTRAS_DETAIL, false); + mapIntent.putExtra(EXTRAS_LATITUDE, coords.getLatitude()); + mapIntent.putExtra(EXTRAS_LONGITUDE, coords.getLongitude()); + if (type != null) { + mapIntent.putExtra(EXTRAS_WPTTYPE, type != null ? type.id : null); + } + context.startActivity(mapIntent); + } + + public static void startActivityGeoCode(final Context context, final String geocode) { + Intent mapIntent = new Intent(context, Settings.getMapFactory().getMapClass()); + mapIntent.putExtra(EXTRAS_DETAIL, false); + mapIntent.putExtra(EXTRAS_GEOCODE, geocode); + mapIntent.putExtra(EXTRAS_MAP_TITLE, geocode); + context.startActivity(mapIntent); + } } |