diff options
author | Bananeweizen <bananeweizen@gmx.de> | 2012-05-03 23:30:12 +0200 |
---|---|---|
committer | Bananeweizen <bananeweizen@gmx.de> | 2012-05-03 23:30:12 +0200 |
commit | 35ae3e1a76b69679f9cc9729d5d5f823a8a4e3e6 (patch) | |
tree | 4dd5c337e585ce9348cfec00a5d79599314a8769 /main | |
parent | 061bac468098d92a8a05d725aee77c5fb0c023cd (diff) | |
download | cgeo-35ae3e1a76b69679f9cc9729d5d5f823a8a4e3e6.zip cgeo-35ae3e1a76b69679f9cc9729d5d5f823a8a4e3e6.tar.gz cgeo-35ae3e1a76b69679f9cc9729d5d5f823a8a4e3e6.tar.bz2 |
refactoring: remove some activity contexts from non activity code
Diffstat (limited to 'main')
-rw-r--r-- | main/src/cgeo/geocaching/CacheDetailActivity.java | 12 | ||||
-rw-r--r-- | main/src/cgeo/geocaching/StaticMapsProvider.java | 9 | ||||
-rw-r--r-- | main/src/cgeo/geocaching/cgCache.java | 14 | ||||
-rw-r--r-- | main/src/cgeo/geocaching/cgeocaches.java | 6 | ||||
-rw-r--r-- | main/src/cgeo/geocaching/cgeoimages.java | 2 | ||||
-rw-r--r-- | main/src/cgeo/geocaching/cgeoinit.java | 2 | ||||
-rw-r--r-- | main/src/cgeo/geocaching/cgeopopup.java | 2 | ||||
-rw-r--r-- | main/src/cgeo/geocaching/cgeotrackable.java | 10 | ||||
-rw-r--r-- | main/src/cgeo/geocaching/connector/gc/Login.java | 5 | ||||
-rw-r--r-- | main/src/cgeo/geocaching/files/GPXImporter.java | 2 | ||||
-rw-r--r-- | main/src/cgeo/geocaching/maps/CGeoMap.java | 2 | ||||
-rw-r--r-- | main/src/cgeo/geocaching/network/HtmlImage.java | 14 |
12 files changed, 38 insertions, 42 deletions
diff --git a/main/src/cgeo/geocaching/CacheDetailActivity.java b/main/src/cgeo/geocaching/CacheDetailActivity.java index b1cb15e..885a6b5 100644 --- a/main/src/cgeo/geocaching/CacheDetailActivity.java +++ b/main/src/cgeo/geocaching/CacheDetailActivity.java @@ -1615,7 +1615,7 @@ public class CacheDetailActivity extends AbstractActivity { @Override public void run() { - cache.store(CacheDetailActivity.this, handler); + cache.store(handler); } } @@ -1628,7 +1628,7 @@ public class CacheDetailActivity extends AbstractActivity { @Override public void run() { - cache.refresh(CacheDetailActivity.this, cache.getListId(), handler); + cache.refresh(cache.getListId(), handler); handler.sendEmptyMessage(0); } @@ -1828,7 +1828,7 @@ public class CacheDetailActivity extends AbstractActivity { // TODO move this code to StaticMapProvider and use its constant values final String markerUrl = "http://cgeo.carnero.cc/_markers/my_location_mdpi.png"; - final HtmlImage mapGetter = new HtmlImage(CacheDetailActivity.this, cache.getGeocode(), false, 0, false); + 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); } catch (Exception e) { @@ -1927,7 +1927,7 @@ public class CacheDetailActivity extends AbstractActivity { if (StringUtils.isNotBlank(cache.getHint())) { TextView hintView = ((TextView) view.findViewById(R.id.hint)); if (BaseUtils.containsHtml(cache.getHint())) { - hintView.setText(Html.fromHtml(cache.getHint(), new HtmlImage(CacheDetailActivity.this, cache.getGeocode(), false, cache.getListId(), false), null), TextView.BufferType.SPANNABLE); + hintView.setText(Html.fromHtml(cache.getHint(), new HtmlImage(cache.getGeocode(), false, cache.getListId(), false), null), TextView.BufferType.SPANNABLE); hintView.setText(CryptUtils.rot13((Spannable) hintView.getText())); } else { @@ -2026,7 +2026,7 @@ public class CacheDetailActivity extends AbstractActivity { publishProgress(); if (imageCounter.getImageCount() > 0) { // Complete view: parse again with loading images - if necessary ! If there are any images causing problems the user can see at least the preview - description = Html.fromHtml(descriptionString, new HtmlImage(CacheDetailActivity.this, cache.getGeocode(), true, cache.getListId(), false), unknownTagsHandler); + description = Html.fromHtml(descriptionString, new HtmlImage(cache.getGeocode(), true, cache.getListId(), false), unknownTagsHandler); publishProgress(); } @@ -2199,7 +2199,7 @@ public class CacheDetailActivity extends AbstractActivity { // logtext, avoid parsing HTML if not necessary if (BaseUtils.containsHtml(log.log)) { - holder.text.setText(Html.fromHtml(log.log, new HtmlImage(CacheDetailActivity.this, cache.getGeocode(), false, cache.getListId(), false), null), TextView.BufferType.SPANNABLE); + holder.text.setText(Html.fromHtml(log.log, new HtmlImage(cache.getGeocode(), false, cache.getListId(), false), null), TextView.BufferType.SPANNABLE); } else { holder.text.setText(log.log); diff --git a/main/src/cgeo/geocaching/StaticMapsProvider.java b/main/src/cgeo/geocaching/StaticMapsProvider.java index 9fbf429..691516f 100644 --- a/main/src/cgeo/geocaching/StaticMapsProvider.java +++ b/main/src/cgeo/geocaching/StaticMapsProvider.java @@ -70,13 +70,8 @@ public class StaticMapsProvider { } } - public static void downloadMaps(cgCache cache, cgeoapplication app) { - final Display display = ((WindowManager) app.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay(); - downloadMaps(cache, display); - } - - public static void downloadMaps(cgCache cache, Activity activity) { - final Display display = ((WindowManager) activity.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay(); + public static void downloadMaps(cgCache cache) { + final Display display = ((WindowManager) cgeoapplication.getInstance().getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay(); downloadMaps(cache, display); } diff --git a/main/src/cgeo/geocaching/cgCache.java b/main/src/cgeo/geocaching/cgCache.java index 03c704b..bb6dffa 100644 --- a/main/src/cgeo/geocaching/cgCache.java +++ b/main/src/cgeo/geocaching/cgCache.java @@ -1347,9 +1347,9 @@ public class cgCache implements ICache, IWaypoint { return StringUtils.isNotBlank(geocode) && geocode.equals(((cgCache) obj).geocode); } - public void store(Activity activity, CancellableHandler handler) { + public void store(CancellableHandler handler) { final int listId = Math.max(getListId(), StoredList.STANDARD_LIST_ID); - storeCache(activity, this, null, listId, false, handler); + storeCache(this, null, listId, false, handler); } public void setZoomlevel(int zoomlevel) { @@ -1424,12 +1424,12 @@ public class cgCache implements ICache, IWaypoint { } } - public void refresh(Activity activity, int newListId, CancellableHandler handler) { + public void refresh(int newListId, CancellableHandler handler) { cgeoapplication.getInstance().removeCache(geocode, EnumSet.of(RemoveFlag.REMOVE_CACHE)); - storeCache(activity, null, geocode, newListId, true, handler); + storeCache(null, geocode, newListId, true, handler); } - public static void storeCache(Activity activity, cgCache origCache, String geocode, int listId, boolean forceRedownload, CancellableHandler handler) { + public static void storeCache(cgCache origCache, String geocode, int listId, boolean forceRedownload, CancellableHandler handler) { try { cgCache cache; // get cache details, they may not yet be complete @@ -1460,7 +1460,7 @@ public class cgCache implements ICache, IWaypoint { return; } - final HtmlImage imgGetter = new HtmlImage(activity, cache.getGeocode(), false, listId, true); + final HtmlImage imgGetter = new HtmlImage(cache.getGeocode(), false, listId, true); // store images from description if (StringUtils.isNotBlank(cache.getDescription())) { @@ -1498,7 +1498,7 @@ public class cgCache implements ICache, IWaypoint { } // store map previews - StaticMapsProvider.downloadMaps(cache, activity); + StaticMapsProvider.downloadMaps(cache); if (CancellableHandler.isCancelled(handler)) { return; diff --git a/main/src/cgeo/geocaching/cgeocaches.java b/main/src/cgeo/geocaching/cgeocaches.java index ec0e173..695af42 100644 --- a/main/src/cgeo/geocaching/cgeocaches.java +++ b/main/src/cgeo/geocaching/cgeocaches.java @@ -1119,7 +1119,7 @@ public class cgeocaches extends AbstractListActivity implements IObserver<Object break; case MENU_STORE_CACHE: //FIXME: this must use the same handler like in the CacheDetailActivity. Will be done by moving the handler into the store method. - cache.store(this, null); + cache.store(null); break; default: // we must remember the menu info for the sub menu, there is a bug @@ -1657,7 +1657,7 @@ public class cgeocaches extends AbstractListActivity implements IObserver<Object } detailProgress++; - cache.refresh(cgeocaches.this, listIdLD, null); + cache.refresh(listIdLD, null); handler.sendEmptyMessage(cacheList.indexOf(cache)); @@ -1718,7 +1718,7 @@ public class cgeocaches extends AbstractListActivity implements IObserver<Object handler.sendMessage(handler.obtainMessage(1, response)); yield(); - cgCache.storeCache(cgeocaches.this, null, response, listIdLFW, false, null); + cgCache.storeCache(null, response, listIdLFW, false, null); handler.sendMessage(handler.obtainMessage(2, response)); yield(); diff --git a/main/src/cgeo/geocaching/cgeoimages.java b/main/src/cgeo/geocaching/cgeoimages.java index 7145d59..6d4c77a 100644 --- a/main/src/cgeo/geocaching/cgeoimages.java +++ b/main/src/cgeo/geocaching/cgeoimages.java @@ -101,7 +101,7 @@ public class cgeoimages extends AbstractActivity { @Override protected BitmapDrawable doInBackground(Void... params) { - final HtmlImage imgGetter = new HtmlImage(cgeoimages.this, geocode, true, offline ? 1 : 0, false); + final HtmlImage imgGetter = new HtmlImage(geocode, true, offline ? 1 : 0, false); return imgGetter.getDrawable(img.getUrl()); } diff --git a/main/src/cgeo/geocaching/cgeoinit.java b/main/src/cgeo/geocaching/cgeoinit.java index aec2f8e..c3e193e 100644 --- a/main/src/cgeo/geocaching/cgeoinit.java +++ b/main/src/cgeo/geocaching/cgeoinit.java @@ -830,7 +830,7 @@ public class cgeoinit extends AbstractActivity { Object payload = loginResult; if (loginResult == StatusCode.NO_ERROR) { Login.detectGcCustomDate(); - payload = Login.downloadAvatarAndGetMemberStatus(cgeoinit.this); + payload = Login.downloadAvatarAndGetMemberStatus(); } logInHandler.obtainMessage(0, payload).sendToTarget(); } diff --git a/main/src/cgeo/geocaching/cgeopopup.java b/main/src/cgeo/geocaching/cgeopopup.java index 5284d4f..dd9be5b 100644 --- a/main/src/cgeo/geocaching/cgeopopup.java +++ b/main/src/cgeo/geocaching/cgeopopup.java @@ -545,7 +545,7 @@ public class cgeopopup extends AbstractActivity { @Override public void run() { - cache.store(cgeopopup.this, handler); + cache.store(handler); invalidateOptionsMenuCompatible(); } } diff --git a/main/src/cgeo/geocaching/cgeotrackable.java b/main/src/cgeo/geocaching/cgeotrackable.java index 005711c..039fb44 100644 --- a/main/src/cgeo/geocaching/cgeotrackable.java +++ b/main/src/cgeo/geocaching/cgeotrackable.java @@ -162,7 +162,7 @@ public class cgeotrackable extends AbstractActivity { ((LinearLayout) findViewById(R.id.goal_box)).setVisibility(View.VISIBLE); TextView descView = (TextView) findViewById(R.id.goal); descView.setVisibility(View.VISIBLE); - descView.setText(Html.fromHtml(trackable.getGoal(), new HtmlImage(cgeotrackable.this, geocode, true, 0, false), null), TextView.BufferType.SPANNABLE); + descView.setText(Html.fromHtml(trackable.getGoal(), new HtmlImage(geocode, true, 0, false), null), TextView.BufferType.SPANNABLE); descView.setMovementMethod(LinkMovementMethod.getInstance()); } @@ -171,7 +171,7 @@ public class cgeotrackable extends AbstractActivity { ((LinearLayout) findViewById(R.id.details_box)).setVisibility(View.VISIBLE); TextView descView = (TextView) findViewById(R.id.details); descView.setVisibility(View.VISIBLE); - descView.setText(Html.fromHtml(trackable.getDetails(), new HtmlImage(cgeotrackable.this, geocode, true, 0, false), null), TextView.BufferType.SPANNABLE); + descView.setText(Html.fromHtml(trackable.getDetails(), new HtmlImage(geocode, true, 0, false), null), TextView.BufferType.SPANNABLE); descView.setMovementMethod(LinkMovementMethod.getInstance()); } @@ -209,7 +209,7 @@ public class cgeotrackable extends AbstractActivity { public void run() { BitmapDrawable image; try { - HtmlImage imgGetter = new HtmlImage(cgeotrackable.this, geocode, true, 0, false); + HtmlImage imgGetter = new HtmlImage(geocode, true, 0, false); image = imgGetter.getDrawable(trackable.getImage()); Message message = handler.obtainMessage(0, image); @@ -459,7 +459,7 @@ public class cgeotrackable extends AbstractActivity { TextView logView = (TextView) rowView.findViewById(R.id.log); logView.setMovementMethod(LinkMovementMethod.getInstance()); - logView.setText(Html.fromHtml(log.log, new HtmlImage(this, null, false, StoredList.TEMPORARY_LIST_ID, false), null), TextView.BufferType.SPANNABLE); + logView.setText(Html.fromHtml(log.log, new HtmlImage(null, false, StoredList.TEMPORARY_LIST_ID, false), null), TextView.BufferType.SPANNABLE); // add LogImages LinearLayout logLayout = (LinearLayout) rowView.findViewById(R.id.log_layout); @@ -556,7 +556,7 @@ public class cgeotrackable extends AbstractActivity { BitmapDrawable image; try { - HtmlImage imgGetter = new HtmlImage(cgeotrackable.this, trackable.getGeocode(), false, 0, false); + HtmlImage imgGetter = new HtmlImage(trackable.getGeocode(), false, 0, false); image = imgGetter.getDrawable(url); Message message = handler.obtainMessage(0, image); diff --git a/main/src/cgeo/geocaching/connector/gc/Login.java b/main/src/cgeo/geocaching/connector/gc/Login.java index 28b2c6a..c39fcef 100644 --- a/main/src/cgeo/geocaching/connector/gc/Login.java +++ b/main/src/cgeo/geocaching/connector/gc/Login.java @@ -16,7 +16,6 @@ import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.tuple.ImmutablePair; import org.apache.http.HttpResponse; -import android.content.Context; import android.graphics.drawable.BitmapDrawable; import java.text.ParseException; @@ -231,7 +230,7 @@ public abstract class Login { } } - public static BitmapDrawable downloadAvatarAndGetMemberStatus(final Context context) { + public static BitmapDrawable downloadAvatarAndGetMemberStatus() { try { final String profile = BaseUtils.replaceWhitespace(Network.getResponseData(Network.getRequest("http://www.geocaching.com/my/"))); @@ -241,7 +240,7 @@ public abstract class Login { final String avatarURL = BaseUtils.getMatch(profile, GCConstants.PATTERN_AVATAR_IMAGE_PROFILE_PAGE, false, null); if (null != avatarURL) { - final HtmlImage imgGetter = new HtmlImage(context, "", false, 0, false); + final HtmlImage imgGetter = new HtmlImage("", false, 0, false); return imgGetter.getDrawable(avatarURL); } // No match? There may be no avatar set by user. diff --git a/main/src/cgeo/geocaching/files/GPXImporter.java b/main/src/cgeo/geocaching/files/GPXImporter.java index c669dcb..279f03f 100644 --- a/main/src/cgeo/geocaching/files/GPXImporter.java +++ b/main/src/cgeo/geocaching/files/GPXImporter.java @@ -195,7 +195,7 @@ public class GPXImporter { for (String geocode : importedCaches.getGeocodes()) {
cgCache cache = app.loadCache(geocode, LoadFlags.LOAD_WAYPOINTS);
Log.d("GPXImporter.ImportThread.importStaticMaps start downloadMaps for cache " + geocode);
- StaticMapsProvider.downloadMaps(cache, app);
+ StaticMapsProvider.downloadMaps(cache);
storedCacheMaps++;
if (progressHandler.isCancelled()) {
return false;
diff --git a/main/src/cgeo/geocaching/maps/CGeoMap.java b/main/src/cgeo/geocaching/maps/CGeoMap.java index 9531dd6..6b24ec9 100644 --- a/main/src/cgeo/geocaching/maps/CGeoMap.java +++ b/main/src/cgeo/geocaching/maps/CGeoMap.java @@ -1401,7 +1401,7 @@ public class CGeoMap extends AbstractMap implements OnMapDragListener, ViewFacto break; } - cgCache.storeCache(activity, null, geocode, StoredList.STANDARD_LIST_ID, false, handler); + cgCache.storeCache(null, geocode, StoredList.STANDARD_LIST_ID, false, handler); } } catch (Exception e) { Log.e("cgeocaches.LoadDetails.run: " + e.toString()); diff --git a/main/src/cgeo/geocaching/network/HtmlImage.java b/main/src/cgeo/geocaching/network/HtmlImage.java index 7e4143e..e0bcce7 100644 --- a/main/src/cgeo/geocaching/network/HtmlImage.java +++ b/main/src/cgeo/geocaching/network/HtmlImage.java @@ -2,6 +2,7 @@ package cgeo.geocaching.network; import cgeo.geocaching.R; import cgeo.geocaching.StoredList; +import cgeo.geocaching.cgeoapplication; import cgeo.geocaching.connector.ConnectorFactory; import cgeo.geocaching.files.LocalStorage; import cgeo.geocaching.utils.Log; @@ -10,6 +11,7 @@ import org.apache.commons.lang3.StringUtils; import org.apache.http.HttpResponse; import android.content.Context; +import android.content.res.Resources; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.graphics.Rect; @@ -37,7 +39,6 @@ public class HtmlImage implements Html.ImageGetter { "counter.digits.com", "andyhoppe" }; - final private Context context; final private String geocode; /** * on error: return large error image, if <code>true</code>, otherwise empty 1x1 image @@ -48,9 +49,9 @@ public class HtmlImage implements Html.ImageGetter { final private BitmapFactory.Options bfOptions; final private int maxWidth; final private int maxHeight; + final private Resources resources; - public HtmlImage(final Context contextIn, final String geocode, final boolean returnErrorImage, final int listId, final boolean onlySave) { - this.context = contextIn; + public HtmlImage(final String geocode, final boolean returnErrorImage, final int listId, final boolean onlySave) { this.geocode = geocode; this.returnErrorImage = returnErrorImage; this.listId = listId; @@ -59,9 +60,10 @@ public class HtmlImage implements Html.ImageGetter { bfOptions = new BitmapFactory.Options(); bfOptions.inTempStorage = new byte[16 * 1024]; - final Display display = ((WindowManager) context.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay(); + final Display display = ((WindowManager) cgeoapplication.getInstance().getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay(); this.maxWidth = display.getWidth() - 25; this.maxHeight = display.getHeight() - 25; + this.resources = cgeoapplication.getInstance().getResources(); } @Override @@ -109,7 +111,7 @@ public class HtmlImage implements Html.ImageGetter { Log.d("HtmlImage.getDrawable: Failed to obtain image"); if (returnErrorImage) { - imagePre = BitmapFactory.decodeResource(context.getResources(), R.drawable.image_not_loaded); + imagePre = BitmapFactory.decodeResource(resources, R.drawable.image_not_loaded); } else { imagePre = getTransparent1x1Image(); } @@ -144,7 +146,7 @@ public class HtmlImage implements Html.ImageGetter { } private Bitmap getTransparent1x1Image() { - return BitmapFactory.decodeResource(context.getResources(), R.drawable.image_no_placement); + return BitmapFactory.decodeResource(resources, R.drawable.image_no_placement); } private Bitmap loadImageFromStorage(final String url) { |