aboutsummaryrefslogtreecommitdiffstats
path: root/main/src/cgeo/geocaching/CacheDetailActivity.java
diff options
context:
space:
mode:
Diffstat (limited to 'main/src/cgeo/geocaching/CacheDetailActivity.java')
-rw-r--r--main/src/cgeo/geocaching/CacheDetailActivity.java51
1 files changed, 28 insertions, 23 deletions
diff --git a/main/src/cgeo/geocaching/CacheDetailActivity.java b/main/src/cgeo/geocaching/CacheDetailActivity.java
index 49f52ba..cbd771c 100644
--- a/main/src/cgeo/geocaching/CacheDetailActivity.java
+++ b/main/src/cgeo/geocaching/CacheDetailActivity.java
@@ -21,7 +21,15 @@ import cgeo.geocaching.network.Parameters;
import cgeo.geocaching.ui.CacheDetailsCreator;
import cgeo.geocaching.ui.DecryptTextClickListener;
import cgeo.geocaching.ui.Formatter;
-import cgeo.geocaching.utils.*;
+import cgeo.geocaching.utils.BaseUtils;
+import cgeo.geocaching.utils.CancellableHandler;
+import cgeo.geocaching.utils.ClipboardUtils;
+import cgeo.geocaching.utils.CryptUtils;
+import cgeo.geocaching.utils.GeoDirHandler;
+import cgeo.geocaching.utils.ImageHelper;
+import cgeo.geocaching.utils.Log;
+import cgeo.geocaching.utils.TranslationUtils;
+import cgeo.geocaching.utils.UnknownTagsHandler;
import com.viewpagerindicator.TitlePageIndicator;
import com.viewpagerindicator.TitleProvider;
@@ -38,6 +46,7 @@ import android.content.Intent;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.graphics.Bitmap;
+import android.graphics.BitmapFactory;
import android.graphics.Typeface;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
@@ -58,7 +67,6 @@ import android.text.format.DateUtils;
import android.text.method.LinkMovementMethod;
import android.text.style.StrikethroughSpan;
import android.text.style.StyleSpan;
-import android.util.DisplayMetrics;
import android.view.ContextMenu;
import android.view.Menu;
import android.view.MenuItem;
@@ -1680,10 +1688,7 @@ public class CacheDetailActivity extends AbstractActivity {
Button buttonRemove = (Button) view.findViewById(R.id.remove_from_watchlist);
TextView text = (TextView) view.findViewById(R.id.watchlist_text);
- //TODO: We already have cache.isOwn(). Those 2 should be combined.
- boolean userIsOwner = StringUtils.equals(cache.getOwnerReal(), Settings.getUsername());
-
- if (cache.isOnWatchlist() || userIsOwner) {
+ if (cache.isOnWatchlist() || cache.isOwn()) {
buttonAdd.setVisibility(View.GONE);
buttonRemove.setVisibility(View.VISIBLE);
text.setText(R.string.cache_watchlist_on);
@@ -1694,7 +1699,7 @@ public class CacheDetailActivity extends AbstractActivity {
}
// the owner of a cache has it always on his watchlist. Adding causes an error
- if (userIsOwner) {
+ if (cache.isOwn()) {
buttonAdd.setEnabled(false);
buttonAdd.setVisibility(View.GONE);
buttonRemove.setEnabled(false);
@@ -1707,12 +1712,10 @@ public class CacheDetailActivity extends AbstractActivity {
* shows/hides buttons, sets text in watchlist box
*/
private void updateFavPointBox() {
- boolean userIsOwner = StringUtils.equals(cache.getOwnerReal(), Settings.getUsername());
-
LinearLayout layout = (LinearLayout) view.findViewById(R.id.favpoint_box);
boolean supportsFavoritePoints = cache.supportsFavoritePoints();
layout.setVisibility(supportsFavoritePoints ? View.VISIBLE : View.GONE);
- if (!supportsFavoritePoints || userIsOwner || !Settings.isPremiumMember()) {
+ if (!supportsFavoritePoints || cache.isOwn() || !Settings.isPremiumMember()) {
return;
}
Button buttonAdd = (Button) view.findViewById(R.id.add_to_favpoint);
@@ -1798,26 +1801,28 @@ public class CacheDetailActivity extends AbstractActivity {
@Override
protected BitmapDrawable doInBackground(Void... parameters) {
try {
- final String latlonMap = cache.getCoords().format(GeopointFormatter.Format.LAT_LON_DECDEGREE_COMMA);
-
- DisplayMetrics metrics = new DisplayMetrics();
- getWindowManager().getDefaultDisplay().getMetrics(metrics);
-
- final int width = metrics.widthPixels;
- final int height = (int) (110 * metrics.density);
-
- // TODO move this code to StaticMapProvider and use its constant values
- final String markerUrl = "http://cgeo.carnero.cc/_markers/my_location_mdpi.png";
+ // persistent preview from storage
+ Bitmap image = decode(cache);
+
+ if (image == null) {
+ StaticMapsProvider.storeCachePreviewMap(cache);
+ image = decode(cache);
+ if (image == null) {
+ return null;
+ }
+ }
- final HtmlImage mapGetter = new HtmlImage(cache.getGeocode(), false, 0, false);
- final Parameters params = new Parameters("zoom", "15", "size", width + "x" + height, "maptype", "roadmap", "markers", "icon:" + markerUrl + "|shadow:false|" + latlonMap, "sensor", "false");
- return mapGetter.getDrawable("http://maps.google.com/maps/api/staticmap?" + params);
+ return ImageHelper.scaleBitmapToFitDisplay(image);
} catch (Exception e) {
Log.w("CacheDetailActivity.PreviewMapTask", e);
return null;
}
}
+ private Bitmap decode(final cgCache cache) {
+ return BitmapFactory.decodeFile(StaticMapsProvider.getMapFile(cache.getGeocode(), "preview", false).getPath());
+ }
+
@Override
protected void onPostExecute(BitmapDrawable image) {
if (image == null) {