diff options
author | Marco Jacob <mjacob@union06.de> | 2012-01-11 22:57:50 +0100 |
---|---|---|
committer | Marco Jacob <mjacob@union06.de> | 2012-01-11 22:57:50 +0100 |
commit | 42e6aeded98723c3c5b121a2f82fc00eda817b77 (patch) | |
tree | c1375f4100e38fca56dcbdfd0c629dfe595c213c /main/src | |
parent | 943ae4421d1363fb465367250b9eb96b8944da08 (diff) | |
download | cgeo-42e6aeded98723c3c5b121a2f82fc00eda817b77.zip cgeo-42e6aeded98723c3c5b121a2f82fc00eda817b77.tar.gz cgeo-42e6aeded98723c3c5b121a2f82fc00eda817b77.tar.bz2 |
added setting and implementation for waypoint static map
Diffstat (limited to 'main/src')
-rw-r--r-- | main/src/cgeo/geocaching/Settings.java | 15 | ||||
-rw-r--r-- | main/src/cgeo/geocaching/StaticMapsActivity.java | 32 | ||||
-rw-r--r-- | main/src/cgeo/geocaching/StaticMapsProvider.java | 43 | ||||
-rw-r--r-- | main/src/cgeo/geocaching/apps/cache/navi/StaticMapApp.java | 22 | ||||
-rw-r--r-- | main/src/cgeo/geocaching/cgeowaypoint.java | 11 |
5 files changed, 95 insertions, 28 deletions
diff --git a/main/src/cgeo/geocaching/Settings.java b/main/src/cgeo/geocaching/Settings.java index 4611560..eb5fe60 100644 --- a/main/src/cgeo/geocaching/Settings.java +++ b/main/src/cgeo/geocaching/Settings.java @@ -29,6 +29,7 @@ public final class Settings { private static final String KEY_ANYLATITUDE = "anylatitude"; private static final String KEY_PUBLICLOC = "publicloc"; private static final String KEY_USE_OFFLINEMAPS = "offlinemaps"; + private static final String KEY_USE_OFFLINEWPMAPS = "offlinewpmaps"; private static final String KEY_WEB_DEVICE_CODE = "webDeviceCode"; private static final String KEY_WEBDEVICE_NAME = "webDeviceName"; private static final String KEY_MAP_LIVE = "maplive"; @@ -545,6 +546,20 @@ public final class Settings { }); } + public static boolean isStoreOfflineWpMaps() { + return 0 != sharedPrefs.getInt(KEY_USE_OFFLINEWPMAPS, 1); + } + + public static void setStoreOfflineWpMaps(final boolean offlineMaps) { + editSharedSettings(new PrefRunnable() { + + @Override + public void edit(Editor edit) { + edit.putInt(KEY_USE_OFFLINEWPMAPS, offlineMaps ? 1 : 0); + } + }); + } + public static boolean isStoreLogImages() { return sharedPrefs.getBoolean(KEY_STORE_LOG_IMAGES, false); } diff --git a/main/src/cgeo/geocaching/StaticMapsActivity.java b/main/src/cgeo/geocaching/StaticMapsActivity.java index b33d17d..713323c 100644 --- a/main/src/cgeo/geocaching/StaticMapsActivity.java +++ b/main/src/cgeo/geocaching/StaticMapsActivity.java @@ -21,6 +21,7 @@ import java.util.List; public class StaticMapsActivity extends AbstractActivity { private final List<Bitmap> maps = new ArrayList<Bitmap>(); + private Integer waypoint_id = null; private String geocode = null; private LayoutInflater inflater = null; private ProgressDialog waitDialog = null; @@ -85,6 +86,7 @@ public class StaticMapsActivity extends AbstractActivity { // try to get data from extras if (extras != null) { geocode = extras.getString("geocode"); + waypoint_id = extras.getInt("waypoint"); } if (geocode == null) { @@ -114,11 +116,22 @@ public class StaticMapsActivity extends AbstractActivity { factory = new BitmapFactory(); } + // TODO Hier testen, warum die Cache-Map nicht geladen werden kann + Log.d(Settings.tag, "StaticMapsActivity.run: waypoint_id = " + waypoint_id); + Log.d(Settings.tag, "StaticMapsActivity.run: geocode = " + geocode); + for (int level = 1; level <= 5; level++) { try { - final Bitmap image = BitmapFactory.decodeFile(StaticMapsProvider.getMapFile(geocode, level, false).getPath()); - if (image != null) { - maps.add(image); + if (waypoint_id != null) { + final Bitmap image = BitmapFactory.decodeFile(StaticMapsProvider.getMapFile(geocode, "wp" + waypoint_id + "_", level, false).getPath()); + if (image != null) { + maps.add(image); + } + } else { + final Bitmap image = BitmapFactory.decodeFile(StaticMapsProvider.getMapFile(geocode, "", level, false).getPath()); + if (image != null) { + maps.add(image); + } } } catch (Exception e) { Log.e(Settings.tag, "StaticMapsActivity.LoadMapsThread.run.1: " + e.toString()); @@ -128,9 +141,16 @@ public class StaticMapsActivity extends AbstractActivity { if (maps.isEmpty()) { for (int level = 1; level <= 5; level++) { try { - final Bitmap image = BitmapFactory.decodeFile(StaticMapsProvider.getMapFile(geocode, level, false).getPath()); - if (image != null) { - maps.add(image); + if (waypoint_id != null) { + final Bitmap image = BitmapFactory.decodeFile(StaticMapsProvider.getMapFile(geocode, "wp" + waypoint_id + "_", level, false).getPath()); + if (image != null) { + maps.add(image); + } + } else { + final Bitmap image = BitmapFactory.decodeFile(StaticMapsProvider.getMapFile(geocode, "", level, false).getPath()); + if (image != null) { + maps.add(image); + } } } catch (Exception e) { Log.e(Settings.tag, "StaticMapsActivity.LoadMapsThread.run.2: " + e.toString()); diff --git a/main/src/cgeo/geocaching/StaticMapsProvider.java b/main/src/cgeo/geocaching/StaticMapsProvider.java index 3176c9f..0ae60df 100644 --- a/main/src/cgeo/geocaching/StaticMapsProvider.java +++ b/main/src/cgeo/geocaching/StaticMapsProvider.java @@ -3,6 +3,7 @@ package cgeo.geocaching; import cgeo.geocaching.files.LocalStorage; import cgeo.geocaching.geopoint.GeopointFormatter.Format; +import org.apache.commons.collections.CollectionUtils; import org.apache.commons.lang3.StringUtils; import org.apache.http.HttpResponse; @@ -20,25 +21,25 @@ public class StaticMapsProvider { */ private static final int MIN_MAP_IMAGE_BYTES = 6000; - public static File getMapFile(final String geocode, final int level, final boolean createDirs) { - return LocalStorage.getStorageFile(geocode, "map_" + level, false, createDirs); + public static File getMapFile(final String geocode, String prefix, final int level, final boolean createDirs) { + return LocalStorage.getStorageFile(geocode, "map_" + prefix + level, false, createDirs); } - private static void downloadMapsInThread(final cgCache cache, String latlonMap, int edge, String waypoints) { - downloadMap(cache, 20, "satellite", 1, latlonMap, edge, waypoints); - downloadMap(cache, 18, "satellite", 2, latlonMap, edge, waypoints); - downloadMap(cache, 16, "roadmap", 3, latlonMap, edge, waypoints); - downloadMap(cache, 14, "roadmap", 4, latlonMap, edge, waypoints); - downloadMap(cache, 11, "roadmap", 5, latlonMap, edge, waypoints); + private static void downloadMapsInThread(final cgCache cache, String prefix, String latlonMap, int edge, String waypoints) { + downloadMap(cache, 20, "satellite", prefix, 1, latlonMap, edge, waypoints); + downloadMap(cache, 18, "satellite", prefix, 2, latlonMap, edge, waypoints); + downloadMap(cache, 16, "roadmap", prefix, 3, latlonMap, edge, waypoints); + downloadMap(cache, 14, "roadmap", prefix, 4, latlonMap, edge, waypoints); + downloadMap(cache, 11, "roadmap", prefix, 5, latlonMap, edge, waypoints); } - private static void downloadMap(cgCache cache, int zoom, String mapType, int level, String latlonMap, int edge, String waypoints) { + private static void downloadMap(cgCache cache, int zoom, String mapType, String prefix, int level, String latlonMap, int edge, String waypoints) { final String mapUrl = "http://maps.google.com/maps/api/staticmap?center=" + latlonMap; final String markerUrl = getMarkerUrl(cache); final String url = mapUrl + "&zoom=" + zoom + "&size=" + edge + "x" + edge + "&maptype=" + mapType + "&markers=icon%3A" + markerUrl + "%7C" + latlonMap + waypoints + "&sensor=false"; - final File file = getMapFile(cache.getGeocode(), level, true); + final File file = getMapFile(cache.getGeocode(), prefix, level, true); final HttpResponse httpResponse = cgBase.request(url, null, false); if (httpResponse != null) { @@ -85,15 +86,29 @@ public class StaticMapsProvider { } // download map images in separate background thread for higher performance - downloadMaps(cache, latlonMap, edge, waypoints.toString()); + downloadMaps(cache, "", latlonMap, edge, waypoints.toString()); + + // download static map for current waypoints + if (!Settings.isStoreOfflineWpMaps()) { + return; + } + if (CollectionUtils.isNotEmpty(cache.getWaypoints())) { + for (cgWaypoint waypoint : cache.getWaypoints()) { + if (waypoint.getCoords() == null) { + continue; + } + String wpLatlonMap = waypoint.getCoords().format(Format.LAT_LON_DECDEGREE_COMMA); + downloadMaps(cache, "wp" + waypoint.getId() + "_", wpLatlonMap, edge, ""); + } + } } - private static void downloadMaps(final cgCache cache, final String latlonMap, final int edge, + private static void downloadMaps(final cgCache cache, final String prefix, final String latlonMap, final int edge, final String waypoints) { - final Thread staticMapsThread = new Thread("getting static map") { + Thread staticMapsThread = new Thread("getting static map") { @Override public void run() { - downloadMapsInThread(cache, latlonMap, edge, waypoints); + downloadMapsInThread(cache, prefix, latlonMap, edge, waypoints); } }; staticMapsThread.setPriority(Thread.MIN_PRIORITY); diff --git a/main/src/cgeo/geocaching/apps/cache/navi/StaticMapApp.java b/main/src/cgeo/geocaching/apps/cache/navi/StaticMapApp.java index 6a29895..0bf2f56 100644 --- a/main/src/cgeo/geocaching/apps/cache/navi/StaticMapApp.java +++ b/main/src/cgeo/geocaching/apps/cache/navi/StaticMapApp.java @@ -2,10 +2,10 @@ package cgeo.geocaching.apps.cache.navi; import cgeo.geocaching.R; import cgeo.geocaching.SearchResult; +import cgeo.geocaching.StaticMapsActivity; import cgeo.geocaching.cgCache; import cgeo.geocaching.cgGeo; import cgeo.geocaching.cgWaypoint; -import cgeo.geocaching.StaticMapsActivity; import cgeo.geocaching.activity.ActivityMixin; import cgeo.geocaching.geopoint.Geopoint; @@ -28,18 +28,24 @@ class StaticMapApp extends AbstractNavigationApp { public boolean invoke(cgGeo geo, Activity activity, cgCache cache, final SearchResult search, cgWaypoint waypoint, final Geopoint coords) { - if (cache == null || cache.getListId() == 0) { + String geocode = null; + if (cache != null && cache.getListId() != 0) { + geocode = cache.getGeocode().toUpperCase(); + } + if (waypoint != null) { + geocode = waypoint.getGeocode().toUpperCase(); + } + if (geocode == null) { ActivityMixin.showToast(activity, getString(R.string.err_detail_no_map_static)); return true; - } - - if (cache.getGeocode() != null) { + } else { final Intent intent = new Intent(activity, StaticMapsActivity.class); - intent.putExtra("geocode", cache.getGeocode().toUpperCase()); + intent.putExtra("geocode", geocode); + if (waypoint != null) { + intent.putExtra("waypoint", waypoint.getId()); + } activity.startActivity(intent); return true; } - return false; } - } diff --git a/main/src/cgeo/geocaching/cgeowaypoint.java b/main/src/cgeo/geocaching/cgeowaypoint.java index 3d35189..214da35 100644 --- a/main/src/cgeo/geocaching/cgeowaypoint.java +++ b/main/src/cgeo/geocaching/cgeowaypoint.java @@ -315,6 +315,17 @@ public class cgeowaypoint extends AbstractActivity { public void onClick(View arg0) { if (app.deleteWaypoint(id)) { + if (Settings.isStoreOfflineWpMaps()) { + for (int level = 1; level <= 5; level++) { + try { + if (id > 0) { + StaticMapsProvider.getMapFile(geocode, "wp" + id + "_", level, false).delete(); + } + } catch (Exception e) { + Log.e(Settings.tag, "cgeowaypoint.deleteWaypointListener.onClick: " + e.toString()); + } + } + } cgeoapplication.removeCacheFromCache(geocode); finish(); |