aboutsummaryrefslogtreecommitdiffstats
path: root/main
diff options
context:
space:
mode:
authorBananeweizen <Bananeweizen@gmx.de>2012-02-17 11:15:48 +0100
committerBananeweizen <Bananeweizen@gmx.de>2012-02-17 11:15:48 +0100
commit5252edc70a02378624144a8e42ae4e71318f9ed3 (patch)
treee2e2abf0c209759053e0fec7d9298810ec48e29c /main
parent87aca9bffc6bbcf5113ebdae3c81ad719d564654 (diff)
downloadcgeo-5252edc70a02378624144a8e42ae4e71318f9ed3.zip
cgeo-5252edc70a02378624144a8e42ae4e71318f9ed3.tar.gz
cgeo-5252edc70a02378624144a8e42ae4e71318f9ed3.tar.bz2
new: menu to refresh static maps in static map activity
Diffstat (limited to 'main')
-rw-r--r--main/src/cgeo/geocaching/StaticMapsActivity.java57
-rw-r--r--main/src/cgeo/geocaching/StaticMapsProvider.java49
-rw-r--r--main/src/cgeo/geocaching/activity/AbstractActivity.java3
-rw-r--r--main/src/cgeo/geocaching/cgeowaypointadd.java2
-rw-r--r--main/src/cgeo/geocaching/compatibility/Compatibility.java15
5 files changed, 86 insertions, 40 deletions
diff --git a/main/src/cgeo/geocaching/StaticMapsActivity.java b/main/src/cgeo/geocaching/StaticMapsActivity.java
index 8f6bf23..3646c37 100644
--- a/main/src/cgeo/geocaching/StaticMapsActivity.java
+++ b/main/src/cgeo/geocaching/StaticMapsActivity.java
@@ -15,6 +15,8 @@ import android.os.Handler;
import android.os.Message;
import android.util.Log;
import android.view.LayoutInflater;
+import android.view.Menu;
+import android.view.MenuItem;
import android.widget.ImageView;
import android.widget.LinearLayout;
@@ -23,6 +25,7 @@ import java.util.List;
public class StaticMapsActivity extends AbstractActivity {
+ private static final int MENU_REFRESH = 1;
private final List<Bitmap> maps = new ArrayList<Bitmap>();
private Integer waypoint_id = null;
private String geocode = null;
@@ -85,25 +88,13 @@ public class StaticMapsActivity extends AbstractActivity {
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
switch (which) {
- case DialogInterface.BUTTON_POSITIVE:
- cgCache cache = app.loadCache(geocode, LoadFlags.LOAD_CACHE_OR_DB);
- if (waypoint_id == null) {
- StaticMapsProvider.storeCacheStaticMap(cache, StaticMapsActivity.this);
- } else {
- cgWaypoint waypoint = cache.getWaypointById(waypoint_id);
- if (waypoint != null) {
- StaticMapsProvider.storeWaypointStaticMap(cache, StaticMapsActivity.this, waypoint);
- } else {
- showToast(res.getString(R.string.err_detail_not_load_map_static));
- break;
- }
- }
- showToast(res.getString(R.string.info_storing_static_maps));
- break;
+ case DialogInterface.BUTTON_POSITIVE:
+ downloadStaticMaps();
+ break;
- case DialogInterface.BUTTON_NEGATIVE:
+ case DialogInterface.BUTTON_NEGATIVE:
showToast(res.getString(R.string.err_detail_not_load_map_static));
- break;
+ break;
}
finish();
}
@@ -199,4 +190,36 @@ public class StaticMapsActivity extends AbstractActivity {
}
}
}
+
+ @Override
+ public boolean onCreateOptionsMenu(Menu menu) {
+ menu.add(0, MENU_REFRESH, 0, res.getString(R.string.cache_offline_refresh));
+ return true;
+ }
+
+ @Override
+ public boolean onOptionsItemSelected(MenuItem item) {
+ if (item.getItemId() == MENU_REFRESH) {
+ downloadStaticMaps();
+ restartActivity();
+ return true;
+ }
+ return super.onOptionsItemSelected(item);
+ }
+
+ private void downloadStaticMaps() {
+ final cgCache cache = app.loadCache(geocode, LoadFlags.LOAD_CACHE_OR_DB);
+ if (waypoint_id == null) {
+ showToast(res.getString(R.string.info_storing_static_maps));
+ StaticMapsProvider.storeCacheStaticMap(cache, this, true);
+ } else {
+ final cgWaypoint waypoint = cache.getWaypointById(waypoint_id);
+ if (waypoint != null) {
+ showToast(res.getString(R.string.info_storing_static_maps));
+ StaticMapsProvider.storeWaypointStaticMap(cache, this, waypoint, true);
+ } else {
+ showToast(res.getString(R.string.err_detail_not_load_map_static));
+ }
+ }
+ }
} \ No newline at end of file
diff --git a/main/src/cgeo/geocaching/StaticMapsProvider.java b/main/src/cgeo/geocaching/StaticMapsProvider.java
index 6384d59..cd23489 100644
--- a/main/src/cgeo/geocaching/StaticMapsProvider.java
+++ b/main/src/cgeo/geocaching/StaticMapsProvider.java
@@ -26,7 +26,7 @@ public class StaticMapsProvider {
return LocalStorage.getStorageFile(geocode, "map_" + prefix + level, false, createDirs);
}
- private static void downloadMapsInThread(final cgCache cache, String markerUrl, String prefix, String latlonMap, int edge, String waypoints) {
+ private static void downloadDifferentZooms(final cgCache cache, String markerUrl, String prefix, String latlonMap, int edge, String waypoints) {
downloadMap(cache, 20, "satellite", markerUrl, prefix, 1, latlonMap, edge, waypoints);
downloadMap(cache, 18, "satellite", markerUrl, prefix, 2, latlonMap, edge, waypoints);
downloadMap(cache, 16, "roadmap", markerUrl, prefix, 3, latlonMap, edge, waypoints);
@@ -59,38 +59,38 @@ public class StaticMapsProvider {
int edge = guessMinDisplaySide(activity);
if (Settings.isStoreOfflineMaps() && cache.getCoords() != null) {
- storeCacheStaticMap(cache, edge);
+ storeCacheStaticMap(cache, edge, false);
}
// download static map for current waypoints
if (Settings.isStoreOfflineWpMaps() && CollectionUtils.isNotEmpty(cache.getWaypoints())) {
for (cgWaypoint waypoint : cache.getWaypoints()) {
- storeWaypointStaticMap(cache, edge, waypoint);
+ storeWaypointStaticMap(cache, edge, waypoint, false);
}
}
}
- public static void storeWaypointStaticMap(cgCache cache, Activity activity, cgWaypoint waypoint) {
+ public static void storeWaypointStaticMap(cgCache cache, Activity activity, cgWaypoint waypoint, boolean waitForResult) {
int edge = StaticMapsProvider.guessMinDisplaySide(activity);
- storeWaypointStaticMap(cache, edge, waypoint);
+ storeWaypointStaticMap(cache, edge, waypoint, waitForResult);
}
- private static void storeWaypointStaticMap(cgCache cache, int edge, cgWaypoint waypoint) {
+ private static void storeWaypointStaticMap(cgCache cache, int edge, cgWaypoint waypoint, final boolean waitForResult) {
if (waypoint.getCoords() == null) {
return;
}
String wpLatlonMap = waypoint.getCoords().format(Format.LAT_LON_DECDEGREE_COMMA);
String wpMarkerUrl = getWpMarkerUrl(waypoint);
// download map images in separate background thread for higher performance
- downloadMaps(cache, wpMarkerUrl, "wp" + waypoint.getId() + "_", wpLatlonMap, edge, "");
+ downloadMaps(cache, wpMarkerUrl, "wp" + waypoint.getId() + "_", wpLatlonMap, edge, "", waitForResult);
}
- public static void storeCacheStaticMap(cgCache cache, Activity activity) {
- int edge = StaticMapsProvider.guessMinDisplaySide(activity);
- storeCacheStaticMap(cache, edge);
+ public static void storeCacheStaticMap(cgCache cache, Activity activity, final boolean waitForResult) {
+ int edge = guessMinDisplaySide(activity);
+ storeCacheStaticMap(cache, edge, waitForResult);
}
- private static void storeCacheStaticMap(cgCache cache, int edge) {
+ private static void storeCacheStaticMap(cgCache cache, int edge, final boolean waitForResult) {
final String latlonMap = cache.getCoords().format(Format.LAT_LON_DECDEGREE_COMMA);
final StringBuilder waypoints = new StringBuilder();
if (cache.hasWaypoints()) {
@@ -107,7 +107,7 @@ public class StaticMapsProvider {
}
// download map images in separate background thread for higher performance
final String cacheMarkerUrl = getCacheMarkerUrl(cache);
- downloadMaps(cache, cacheMarkerUrl, "", latlonMap, edge, waypoints.toString());
+ downloadMaps(cache, cacheMarkerUrl, "", latlonMap, edge, waypoints.toString(), waitForResult);
}
private static int guessMinDisplaySide(Activity activity) {
@@ -124,15 +124,20 @@ public class StaticMapsProvider {
}
private static void downloadMaps(final cgCache cache, final String markerUrl, final String prefix, final String latlonMap, final int edge,
- final String waypoints) {
- Thread staticMapsThread = new Thread("getting static map") {
- @Override
- public void run() {
- downloadMapsInThread(cache, markerUrl, prefix, latlonMap, edge, waypoints);
- }
- };
- staticMapsThread.setPriority(Thread.MIN_PRIORITY);
- staticMapsThread.start();
+ final String waypoints, boolean waitForResult) {
+ if (waitForResult) {
+ downloadDifferentZooms(cache, markerUrl, prefix, latlonMap, edge, waypoints);
+ }
+ else {
+ Thread staticMapsThread = new Thread("getting static map") {
+ @Override
+ public void run() {
+ downloadDifferentZooms(cache, markerUrl, prefix, latlonMap, edge, waypoints);
+ }
+ };
+ staticMapsThread.setPriority(Thread.MIN_PRIORITY);
+ staticMapsThread.start();
+ }
}
private static String getCacheMarkerUrl(final cgCache cache) {
@@ -165,7 +170,7 @@ public class StaticMapsProvider {
/**
* Check if at least one map file exists for the given geocode.
- *
+ *
* @param geocode
* @return <code>true</code> if at least one mapfile exists; <code>false</code> otherwise
*/
diff --git a/main/src/cgeo/geocaching/activity/AbstractActivity.java b/main/src/cgeo/geocaching/activity/AbstractActivity.java
index e700c72..d4d578e 100644
--- a/main/src/cgeo/geocaching/activity/AbstractActivity.java
+++ b/main/src/cgeo/geocaching/activity/AbstractActivity.java
@@ -95,4 +95,7 @@ public abstract class AbstractActivity extends Activity implements IAbstractActi
Compatibility.disableSuggestions(edit);
}
+ protected void restartActivity() {
+ Compatibility.restartActivity(this);
+ }
}
diff --git a/main/src/cgeo/geocaching/cgeowaypointadd.java b/main/src/cgeo/geocaching/cgeowaypointadd.java
index ee9de72..f4ebbe6 100644
--- a/main/src/cgeo/geocaching/cgeowaypointadd.java
+++ b/main/src/cgeo/geocaching/cgeowaypointadd.java
@@ -384,7 +384,7 @@ public class cgeowaypointadd extends AbstractActivity {
if (app.saveOwnWaypoint(id, geocode, waypoint)) {
StaticMapsProvider.removeWpStaticMaps(id, geocode);
if (Settings.isStoreOfflineWpMaps()) {
- StaticMapsProvider.storeWaypointStaticMap(app.loadCache(geocode, LoadFlags.LOAD_CACHE_OR_DB), cgeowaypointadd.this, waypoint);
+ StaticMapsProvider.storeWaypointStaticMap(app.loadCache(geocode, LoadFlags.LOAD_CACHE_OR_DB), cgeowaypointadd.this, waypoint, false);
}
finish();
return;
diff --git a/main/src/cgeo/geocaching/compatibility/Compatibility.java b/main/src/cgeo/geocaching/compatibility/Compatibility.java
index 15d1924..61e2629 100644
--- a/main/src/cgeo/geocaching/compatibility/Compatibility.java
+++ b/main/src/cgeo/geocaching/compatibility/Compatibility.java
@@ -1,8 +1,10 @@
package cgeo.geocaching.compatibility;
import cgeo.geocaching.Settings;
+import cgeo.geocaching.activity.AbstractActivity;
import android.app.Activity;
+import android.content.Intent;
import android.content.res.Configuration;
import android.net.Uri;
import android.os.Build;
@@ -94,4 +96,17 @@ public final class Compatibility {
}
}
+ public static void restartActivity(AbstractActivity activity) {
+ final Intent intent = activity.getIntent();
+ if (isLevel5) {
+ activity.overridePendingTransition(0, 0);
+ intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
+ }
+ activity.finish();
+ if (isLevel5) {
+ activity.overridePendingTransition(0, 0);
+ }
+ activity.startActivity(intent);
+ }
+
}