diff options
author | Bananeweizen <Bananeweizen@gmx.de> | 2012-02-17 11:15:48 +0100 |
---|---|---|
committer | Bananeweizen <Bananeweizen@gmx.de> | 2012-02-17 11:15:48 +0100 |
commit | 5252edc70a02378624144a8e42ae4e71318f9ed3 (patch) | |
tree | e2e2abf0c209759053e0fec7d9298810ec48e29c /main/src/cgeo/geocaching/StaticMapsActivity.java | |
parent | 87aca9bffc6bbcf5113ebdae3c81ad719d564654 (diff) | |
download | cgeo-5252edc70a02378624144a8e42ae4e71318f9ed3.zip cgeo-5252edc70a02378624144a8e42ae4e71318f9ed3.tar.gz cgeo-5252edc70a02378624144a8e42ae4e71318f9ed3.tar.bz2 |
new: menu to refresh static maps in static map activity
Diffstat (limited to 'main/src/cgeo/geocaching/StaticMapsActivity.java')
-rw-r--r-- | main/src/cgeo/geocaching/StaticMapsActivity.java | 57 |
1 files changed, 40 insertions, 17 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 |