diff options
Diffstat (limited to 'src/cgeo/geocaching')
| -rw-r--r-- | src/cgeo/geocaching/cgCacheListAdapter.java | 2 | ||||
| -rw-r--r-- | src/cgeo/geocaching/cgCompassMini.java | 9 | ||||
| -rw-r--r-- | src/cgeo/geocaching/cgGeo.java | 15 | ||||
| -rw-r--r-- | src/cgeo/geocaching/cgSettings.java | 421 | ||||
| -rw-r--r-- | src/cgeo/geocaching/cgeoapplication.java | 2 | ||||
| -rw-r--r-- | src/cgeo/geocaching/cgeodate.java | 12 | ||||
| -rw-r--r-- | src/cgeo/geocaching/cgeohelpers.java | 11 | ||||
| -rw-r--r-- | src/cgeo/geocaching/mapcommon/cgMapMyOverlay.java | 7 | ||||
| -rw-r--r-- | src/cgeo/geocaching/mapcommon/cgeomap.java | 4 |
9 files changed, 240 insertions, 243 deletions
diff --git a/src/cgeo/geocaching/cgCacheListAdapter.java b/src/cgeo/geocaching/cgCacheListAdapter.java index 722f650..6fa35e1 100644 --- a/src/cgeo/geocaching/cgCacheListAdapter.java +++ b/src/cgeo/geocaching/cgCacheListAdapter.java @@ -446,7 +446,7 @@ public class cgCacheListAdapter extends ArrayAdapter<cgCache> { if (compasses.contains(holder.direction) == false) { compasses.add(holder.direction); } - holder.direction.setContent(base, cache.latitude, cache.longitude); + holder.direction.setContent(cache.latitude, cache.longitude); if (cache.logOffline == true) { holder.offlineMark.setVisibility(View.VISIBLE); diff --git a/src/cgeo/geocaching/cgCompassMini.java b/src/cgeo/geocaching/cgCompassMini.java index 587188a..e90045a 100644 --- a/src/cgeo/geocaching/cgCompassMini.java +++ b/src/cgeo/geocaching/cgCompassMini.java @@ -12,9 +12,7 @@ import android.view.View; public class cgCompassMini extends View { private int arrowSkin = R.drawable.compass_arrow_mini_white; - private Boolean lock = false; private Context context = null; - private cgBase base = null; private Double cacheLat = null; private Double cacheLon = null; private Bitmap compassArrow = null; @@ -54,8 +52,7 @@ public class cgCompassMini extends View { } } - public void setContent(cgBase baseIn, Double cacheLatIn, Double cacheLonIn) { - base = baseIn; + public void setContent(Double cacheLatIn, Double cacheLonIn) { cacheLat = cacheLatIn; cacheLon = cacheLonIn; } @@ -98,8 +95,6 @@ public class cgCompassMini extends View { @Override protected void onDraw(Canvas canvas){ - lock = true; - super.onDraw(canvas); Double azimuthRelative = azimuth - heading; @@ -129,8 +124,6 @@ public class cgCompassMini extends View { canvas.rotate(azimuthRelative.floatValue(), canvasCenterX, canvasCenterY); canvas.setDrawFilter(remfil); - - lock = false; } @Override diff --git a/src/cgeo/geocaching/cgGeo.java b/src/cgeo/geocaching/cgGeo.java index 95c0b9d..0bdb5fb 100644 --- a/src/cgeo/geocaching/cgGeo.java +++ b/src/cgeo/geocaching/cgGeo.java @@ -1,5 +1,9 @@ package cgeo.geocaching; +import java.util.HashMap; +import java.util.Iterator; +import java.util.Locale; + import android.content.Context; import android.content.SharedPreferences; import android.location.GpsSatellite; @@ -9,9 +13,6 @@ import android.location.LocationListener; import android.location.LocationManager; import android.os.Bundle; import android.util.Log; -import java.util.HashMap; -import java.util.Iterator; -import java.util.Locale; public class cgGeo { @@ -19,7 +20,6 @@ public class cgGeo { private cgeoapplication app = null; private LocationManager geoManager = null; private cgUpdateLoc geoUpdate = null; - private cgWarning warning = null; private cgBase base = null; private cgSettings settings = null; private SharedPreferences prefs = null; @@ -48,13 +48,12 @@ public class cgGeo { public Integer satellitesFixed = null; public double distanceNow = 0d; - public cgGeo(Context contextIn, cgeoapplication appIn, cgUpdateLoc geoUpdateIn, cgBase baseIn, cgSettings settingsIn, cgWarning warningIn, int timeIn, int distanceIn) { + public cgGeo(Context contextIn, cgeoapplication appIn, cgUpdateLoc geoUpdateIn, cgBase baseIn, cgSettings settingsIn, int timeIn, int distanceIn) { context = contextIn; app = appIn; geoUpdate = geoUpdateIn; base = baseIn; settings = settingsIn; - warning = warningIn; time = timeIn; distance = distanceIn; @@ -423,7 +422,7 @@ public class cgGeo { assign(app.getLastLat(), app.getLastLon()); Location lastGps = geoManager.getLastKnownLocation(LocationManager.GPS_PROVIDER); - + if (lastGps != null) { lastGps.setProvider("last"); assign(lastGps); @@ -431,7 +430,7 @@ public class cgGeo { Log.i(cgSettings.tag, "Using last location from GPS"); return; } - + Location lastGsm = geoManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER); if (lastGsm != null) { diff --git a/src/cgeo/geocaching/cgSettings.java b/src/cgeo/geocaching/cgSettings.java index 827a417..f63db7e 100644 --- a/src/cgeo/geocaching/cgSettings.java +++ b/src/cgeo/geocaching/cgSettings.java @@ -9,6 +9,7 @@ import org.mapsforge.android.maps.MapDatabase; import android.content.Context; import android.content.Intent; import android.content.SharedPreferences; +import android.content.SharedPreferences.Editor; import android.content.res.Configuration; import android.os.Environment; import android.util.Log; @@ -18,6 +19,45 @@ import cgeo.geocaching.mapsforge.mfMapFactory; public class cgSettings { + 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"; + private static final String KEY_MAP_SOURCE = "mapsource"; + private static final String KEY_USE_TWITTER = "twitter"; + private static final String KEY_SHOW_ADDRESS = "showaddress"; + private static final String KEY_SHOW_CAPTCHA = "showcaptcha"; + private static final String KEY_MAP_TRAIL = "maptrail"; + private static final String KEY_LAST_MAP_ZOOM = "mapzoom"; + private static final String KEY_LIVE_LIST = "livelist"; + private static final String KEY_METRIC_UNITS = "units"; + private static final String KEY_SKIN = "skin"; + private static final String KEY_LAST_USED_LIST = "lastlist"; + private static final String KEY_CACHE_TYPE = "cachetype"; + private static final String KEY_INITIALIZED = "initialized"; + private static final String KEY_TWITTER_TOKEN_SECRET = "tokensecret"; + private static final String KEY_TWITTER_TOKEN_PUBLIC = "tokenpublic"; + private static final String KEY_VERSION = "version"; + private static final String KEY_LOAD_DESCRIPTION = "autoloaddesc"; + private static final String KEY_USE_ENGLISH = "useenglish"; + private static final String KEY_AS_BROWSER = "asbrowser"; + private static final String KEY_USE_COMPASS = "usecompass"; + private static final String KEY_AUTO_VISIT_TRACKABLES = "trackautovisit"; + private static final String KEY_AUTO_INSERT_SIGNATURE = "sigautoinsert"; + private static final String KEY_ALTITUDE_CORRECTION = "altcorrection"; + private static final String KEY_USE_GOOGLE_NAVIGATION = "usegnav"; + private static final String KEY_STORE_LOG_IMAGES = "logimages"; + private static final String KEY_EXCLUDE_DISABLED = "excludedisabled"; + private static final String KEY_EXCLUDE_OWN = "excludemine"; + private static final String KEY_MAPFILE = "mfmapfile"; + private static final String KEY_SIGNATURE = "signature"; + private static final String KEY_GCVOTE_PASSWORD = "pass-vote"; + private static final String KEY_PASSWORD = "password"; + private static final String KEY_USERNAME = "username"; + + private interface PrefRunnable { + void edit(final Editor edit); + } + public enum mapSourceEnum { googleMap, googleSat, @@ -48,7 +88,6 @@ public class cgSettings { public final static int unitsMetric = 1; public final static int unitsImperial = 2; public final static String cache = ".cgeo"; - public final static String analytics = "UA-1103507-15"; // twitter api keys public final static String keyConsumerPublic = "RFafPiNi3xRhcS1TPE3wTw"; @@ -59,17 +98,10 @@ public class cgSettings { // skin public int skin = 0; - public int buttonActive = R.drawable.action_button_dark; - public int buttonInactive = R.drawable.action_button_dark_off; - public int buttonPressed = R.drawable.action_button_dark_pressed; // settings - public boolean loaded = false; - public boolean hideMySearch = false; public int helper = 0; public int initialized = 0; - public String languages = null; - public int cachesFound = 0; public int autoLoadDesc = 0; public int units = unitsMetric; public int livelist = 1; @@ -89,7 +121,6 @@ public class cgSettings { public int publicLoc = 0; public int twitter = 0; public int altCorrection = 0; - public String signature = null; public String cacheType = null; public String tokenPublic = null; public String tokenSecret = null; @@ -109,7 +140,6 @@ public class cgSettings { private SharedPreferences prefs = null; private String username = null; private String password = null; - private String passVote = null; // maps public MapFactory mapFactory = null; @@ -126,70 +156,51 @@ public class cgSettings { } public void load() { - version = prefs.getInt("version", 0); + version = prefs.getInt(KEY_VERSION, 0); - initialized = prefs.getInt("initialized", 0); + initialized = prefs.getInt(KEY_INITIALIZED, 0); helper = prefs.getInt("helper", 0); - skin = prefs.getInt("skin", 0); - setSkinDefaults(); - - languages = prefs.getString("languages", null); - cachesFound = prefs.getInt("found", 0); - autoLoadDesc = prefs.getInt("autoloaddesc", 0); - units = prefs.getInt("units", 1); - livelist = prefs.getInt("livelist", 1); - maplive = prefs.getInt("maplive", 1); - mapzoom = prefs.getInt("mapzoom", 14); - maptrail = prefs.getInt("maptrail", 1); - useEnglish = prefs.getBoolean("useenglish", false); - showCaptcha = prefs.getBoolean("showcaptcha", false); - excludeMine = prefs.getInt("excludemine", 0); - excludeDisabled = prefs.getInt("excludedisabled", 0); + skin = prefs.getInt(KEY_SKIN, 0); + + autoLoadDesc = prefs.getInt(KEY_LOAD_DESCRIPTION, 0); + units = prefs.getInt(KEY_METRIC_UNITS, 1); + livelist = prefs.getInt(KEY_LIVE_LIST, 1); + maplive = prefs.getInt(KEY_MAP_LIVE, 1); + mapzoom = prefs.getInt(KEY_LAST_MAP_ZOOM, 14); + maptrail = prefs.getInt(KEY_MAP_TRAIL, 1); + useEnglish = prefs.getBoolean(KEY_USE_ENGLISH, false); + showCaptcha = prefs.getBoolean(KEY_SHOW_CAPTCHA, false); + excludeMine = prefs.getInt(KEY_EXCLUDE_OWN, 0); + excludeDisabled = prefs.getInt(KEY_EXCLUDE_DISABLED, 0); storeOfflineMaps = prefs.getInt("offlinemaps", 1); - storelogimages = prefs.getBoolean("logimages", false); - asBrowser = prefs.getInt("asbrowser", 1); - useCompass = prefs.getInt("usecompass", 1); - useGNavigation = prefs.getInt("usegnav", 1); - showAddress = prefs.getInt("showaddress", 1); + storelogimages = prefs.getBoolean(KEY_STORE_LOG_IMAGES, false); + asBrowser = prefs.getInt(KEY_AS_BROWSER, 1); + useCompass = prefs.getInt(KEY_USE_COMPASS, 1); + useGNavigation = prefs.getInt(KEY_USE_GOOGLE_NAVIGATION, 1); + showAddress = prefs.getInt(KEY_SHOW_ADDRESS, 1); publicLoc = prefs.getInt("publicloc", 0); - twitter = prefs.getInt("twitter", 0); - altCorrection = prefs.getInt("altcorrection", 0); - signature = prefs.getString("signature", null); - cacheType = prefs.getString("cachetype", null); - tokenPublic = prefs.getString("tokenpublic", null); - tokenSecret = prefs.getString("tokensecret", null); - mapFile = prefs.getString("mfmapfile", null); + twitter = prefs.getInt(KEY_USE_TWITTER, 0); + altCorrection = prefs.getInt(KEY_ALTITUDE_CORRECTION, 0); + cacheType = prefs.getString(KEY_CACHE_TYPE, null); + tokenPublic = prefs.getString(KEY_TWITTER_TOKEN_PUBLIC, null); + tokenSecret = prefs.getString(KEY_TWITTER_TOKEN_SECRET, null); + mapFile = prefs.getString(KEY_MAPFILE, null); mapFileValid = checkMapfile(mapFile); - mapSource = mapSourceEnum.fromInt(prefs.getInt("mapsource", 0)); - webDeviceName = prefs.getString("webDeviceName", null); - webDeviceCode = prefs.getString("webDeviceCode", null); - trackableAutovisit = prefs.getBoolean("trackautovisit", false); - signatureAutoinsert = prefs.getBoolean("sigautoinsert", false); + mapSource = mapSourceEnum.fromInt(prefs.getInt(KEY_MAP_SOURCE, 0)); + webDeviceName = prefs.getString(KEY_WEBDEVICE_NAME, null); + webDeviceCode = prefs.getString(KEY_WEB_DEVICE_CODE, null); + trackableAutovisit = prefs.getBoolean(KEY_AUTO_VISIT_TRACKABLES, false); + signatureAutoinsert = prefs.getBoolean(KEY_AUTO_INSERT_SIGNATURE, false); setLanguage(useEnglish); } - private void setSkinDefaults() { - if (skin == 1) { - buttonActive = R.drawable.action_button_light; - buttonInactive = R.drawable.action_button_light_off; - buttonPressed = R.drawable.action_button_light_pressed; - } else { - skin = 0; - buttonActive = R.drawable.action_button_dark; - buttonInactive = R.drawable.action_button_dark_off; - buttonPressed = R.drawable.action_button_dark_pressed; - } - } - public void setSkin(int skinIn) { if (skin == 1) { skin = 1; - setSkinDefaults(); } else { skin = 0; - setSkinDefaults(); } } @@ -205,12 +216,12 @@ public class cgSettings { } public void reloadTwitterTokens() { - tokenPublic = prefs.getString("tokenpublic", null); - tokenSecret = prefs.getString("tokensecret", null); + tokenPublic = prefs.getString(KEY_TWITTER_TOKEN_PUBLIC, null); + tokenSecret = prefs.getString(KEY_TWITTER_TOKEN_SECRET, null); } public void reloadCacheType() { - cacheType = prefs.getString("cachetype", null); + cacheType = prefs.getString(KEY_CACHE_TYPE, null); } public String getStorage() { @@ -222,22 +233,19 @@ public class cgSettings { } public String[] getStorageSpecific(Boolean hidden) { - String[] storage = new String[2]; + String external = Environment.getExternalStorageDirectory() + "/" + cache + "/"; + String data = Environment.getDataDirectory() + "/data/cgeo.geocaching/" + cache + "/"; if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) { - storage[0] = Environment.getExternalStorageDirectory() + "/" + cache + "/"; - storage[1] = Environment.getDataDirectory() + "/data/cgeo.geocaching/" + cache + "/"; + return new String[] {external, data}; } else { - storage[0] = Environment.getDataDirectory() + "/data/cgeo.geocaching/" + cache + "/"; - storage[1] = Environment.getExternalStorageDirectory() + "/" + cache + "/"; + return new String[] {data, external}; } - - return storage; } public boolean isLogin() { - final String preUsername = prefs.getString("username", null); - final String prePassword = prefs.getString("password", null); + final String preUsername = prefs.getString(KEY_USERNAME, null); + final String prePassword = prefs.getString(KEY_PASSWORD, null); if (preUsername == null || prePassword == null || preUsername.length() == 0 || prePassword.length() == 0) { return false; @@ -250,15 +258,15 @@ public class cgSettings { final HashMap<String, String> login = new HashMap<String, String>(); if (username == null || password == null) { - final String preUsername = prefs.getString("username", null); - final String prePassword = prefs.getString("password", null); + final String preUsername = prefs.getString(KEY_USERNAME, null); + final String prePassword = prefs.getString(KEY_PASSWORD, null); if (initialized == 0 && (preUsername == null || prePassword == null)) { Intent initIntent = new Intent(context, cgeoinit.class); context.startActivity(initIntent); final SharedPreferences.Editor prefsEdit = prefs.edit(); - prefsEdit.putInt("initialized", 1); + prefsEdit.putInt(KEY_INITIALIZED, 1); prefsEdit.commit(); initialized = 1; @@ -268,53 +276,50 @@ public class cgSettings { return null; } - login.put("username", preUsername); - login.put("password", prePassword); + login.put(KEY_USERNAME, preUsername); + login.put(KEY_PASSWORD, prePassword); username = preUsername; password = prePassword; } else { - login.put("username", username); - login.put("password", password); + login.put(KEY_USERNAME, username); + login.put(KEY_PASSWORD, password); } return login; } public String getUsername() { - String user = null; - if (username == null) { - user = prefs.getString("username", null); + return prefs.getString(KEY_USERNAME, null); } else { - user = username; + return username; } - - return user; } - public boolean setLogin(String username, String password) { - final SharedPreferences.Editor prefsEdit = prefs.edit(); - - if (username == null || username.length() == 0 || password == null || password.length() == 0) { - // erase username and password - prefsEdit.remove("username"); - prefsEdit.remove("password"); - } else { - // save username and password - prefsEdit.putString("username", username); - prefsEdit.putString("password", password); - } - + public boolean setLogin(final String username, final String password) { this.username = username; this.password = password; - - return prefsEdit.commit(); + return editSettings(new PrefRunnable() { + + @Override + public void edit(Editor edit) { + if (username == null || username.length() == 0 || password == null || password.length() == 0) { + // erase username and password + edit.remove(KEY_USERNAME); + edit.remove(KEY_PASSWORD); + } else { + // save username and password + edit.putString(KEY_USERNAME, username); + edit.putString(KEY_PASSWORD, password); + } + } + }); } public boolean isGCvoteLogin() { - final String preUsername = prefs.getString("username", null); - final String prePassword = prefs.getString("pass-vote", null); + final String preUsername = prefs.getString(KEY_USERNAME, null); + final String prePassword = prefs.getString(KEY_GCVOTE_PASSWORD, null); if (preUsername == null || prePassword == null || preUsername.length() == 0 || prePassword.length() == 0) { return false; @@ -323,125 +328,106 @@ public class cgSettings { } } - public boolean setGCvoteLogin(String password) { - final SharedPreferences.Editor prefsEdit = prefs.edit(); + public boolean setGCvoteLogin(final String password) { + return editSettings(new PrefRunnable() { - if (password == null || password.length() == 0) { - // erase password - prefsEdit.remove("pass-vote"); - } else { - // save password - prefsEdit.putString("pass-vote", password); - } - - passVote = password; - - return prefsEdit.commit(); + @Override + public void edit(Editor edit) { + if (password == null || password.length() == 0) { + // erase password + edit.remove(KEY_GCVOTE_PASSWORD); + } else { + // save password + edit.putString(KEY_GCVOTE_PASSWORD, password); + } + } + }); } public HashMap<String, String> getGCvoteLogin() { final HashMap<String, String> login = new HashMap<String, String>(); if (username == null || password == null) { - final String preUsername = prefs.getString("username", null); - final String prePassword = prefs.getString("pass-vote", null); + final String preUsername = prefs.getString(KEY_USERNAME, null); + final String prePassword = prefs.getString(KEY_GCVOTE_PASSWORD, null); if (preUsername == null || prePassword == null) { return null; } - login.put("username", preUsername); - login.put("password", prePassword); + login.put(KEY_USERNAME, preUsername); + login.put(KEY_PASSWORD, prePassword); username = preUsername; - passVote = prePassword; } else { - login.put("username", username); - login.put("password", password); + login.put(KEY_USERNAME, username); + login.put(KEY_PASSWORD, password); } return login; } - public boolean setSignature(String signature) { - final SharedPreferences.Editor prefsEdit = prefs.edit(); - - if (signature == null || signature.length() == 0) { - // erase signature - prefsEdit.remove("signature"); - } else { - // save signature - prefsEdit.putString("signature", signature); - } + public boolean setSignature(final String signature) { + return editSettings(new PrefRunnable() { - this.signature = signature; - - return prefsEdit.commit(); + @Override + public void edit(Editor edit) { + if (signature == null || signature.length() == 0) { + // erase signature + edit.remove(KEY_SIGNATURE); + } else { + // save signature + edit.putString(KEY_SIGNATURE, signature); + } + } + }); } public String getSignature() { - return prefs.getString("signature", null); + return prefs.getString(KEY_SIGNATURE, null); } - public boolean setLanguages(String languages) { - final SharedPreferences.Editor prefsEdit = prefs.edit(); - - if (languages == null || languages.length() == 0) { - // erase languages - prefsEdit.remove("languages"); - } else { - // save langauges - languages = languages.toLowerCase(); - languages = languages.replaceAll("([^a-z]+)", " "); - languages = languages.replaceAll("([ ]+)", " "); - - prefsEdit.putString("languages", languages); - } - - this.languages = languages; - - return prefsEdit.commit(); - } - - public boolean setAltCorrection(int altitude) { - final SharedPreferences.Editor prefsEdit = prefs.edit(); - - prefsEdit.putInt("altcorrection", altitude); - + public boolean setAltCorrection(final int altitude) { altCorrection = altitude; + return editSettings(new PrefRunnable() { - return prefsEdit.commit(); - } - - public String getLanguages() { - return prefs.getString("languages", null); + @Override + public void edit(Editor edit) { + edit.putInt(KEY_ALTITUDE_CORRECTION, altitude); + } + }); } public void deleteCookies() { - SharedPreferences.Editor prefsEdit = prefs.edit(); + editSettings(new PrefRunnable() { - // delete cookies - Map<String, ?> prefsValues = prefs.getAll(); + @Override + public void edit(Editor edit) { + // delete cookies + Map<String, ?> prefsValues = prefs.getAll(); - if (prefsValues != null && prefsValues.size() > 0) { - Log.i(cgSettings.tag, "Removing cookies"); + if (prefsValues != null && prefsValues.size() > 0) { + Log.i(cgSettings.tag, "Removing cookies"); - Object[] keys = prefsValues.keySet().toArray(); + Object[] keys = prefsValues.keySet().toArray(); - for (int i = 0; i < keys.length; i++) { - if (keys[i].toString().length() > 7 && keys[i].toString().substring(0, 7).equals("cookie_") == true) { - prefsEdit.remove(keys[i].toString()); + for (int i = 0; i < keys.length; i++) { + if (keys[i].toString().length() > 7 && keys[i].toString().substring(0, 7).equals("cookie_")) { + edit.remove(keys[i].toString()); + } + } } } - } - - prefsEdit.commit(); + }); } - public String setCacheType(String cacheTypeIn) { - final SharedPreferences.Editor edit = prefs.edit(); - edit.putString("cachetype", cacheTypeIn); - edit.commit(); + public String setCacheType(final String cacheTypeIn) { + editSettings(new PrefRunnable() { + @Override + public void edit(Editor edit) { + edit.putString(KEY_CACHE_TYPE, cacheTypeIn); + } + }); cacheType = cacheTypeIn; @@ -449,45 +435,58 @@ public class cgSettings { } public void liveMapEnable() { - final SharedPreferences.Editor edit = prefs.edit(); - edit.putInt("maplive", 1); + if (editSettings(new PrefRunnable() { - if (edit.commit() == true) { + @Override + public void edit(Editor edit) { + edit.putInt(KEY_MAP_LIVE, 1); + } + })) { maplive = 1; } } public void liveMapDisable() { - final SharedPreferences.Editor edit = prefs.edit(); - edit.putInt("maplive", 0); + if (editSettings(new PrefRunnable() { - if (edit.commit() == true) { + @Override + public void edit(Editor edit) { + edit.putInt(KEY_MAP_LIVE, 0); + } + })) { maplive = 0; } } public int getLastList() { - int listId = prefs.getInt("lastlist", -1); + int listId = prefs.getInt(KEY_LAST_USED_LIST, -1); return listId; } - public void saveLastList(int listId) { - final SharedPreferences.Editor edit = prefs.edit(); + public void saveLastList(final int listId) { + editSettings(new PrefRunnable() { - edit.putInt("lastlist", listId); - edit.commit(); + @Override + public void edit(Editor edit) { + edit.putInt(KEY_LAST_USED_LIST, listId); + } + }); } - public void setWebNameCode(String name, String code) { - final SharedPreferences.Editor edit = prefs.edit(); + public void setWebNameCode(final String name, final String code) { + if (editSettings(new PrefRunnable() { - this.webDeviceCode=code; - this.webDeviceName=name; + @Override + public void edit(Editor edit) { - edit.putString("webDeviceName", name); - edit.putString("webDeviceCode", code); - edit.commit(); + edit.putString(KEY_WEBDEVICE_NAME, name); + edit.putString(KEY_WEB_DEVICE_CODE, code); + } + })) { + webDeviceCode=code; + webDeviceName=name; + } } public MapFactory getMapFactory() { @@ -510,12 +509,14 @@ public class cgSettings { return mapFile; } - public boolean setMapFile(String mapFileIn) { - final SharedPreferences.Editor prefsEdit = prefs.edit(); - - prefsEdit.putString("mfmapfile", mapFileIn); + public boolean setMapFile(final String mapFileIn) { + boolean commitResult = editSettings(new PrefRunnable() { - boolean commitResult = prefsEdit.commit(); + @Override + public void edit(Editor edit) { + edit.putString(KEY_MAPFILE, mapFileIn); + } + }); mapFile = mapFileIn; mapFileValid = checkMapfile(mapFile); @@ -534,7 +535,15 @@ public class cgSettings { return MapDatabase.isValidMapFile(mapFileIn); } - public Context getContext() { - return context; + /** + * edit some settings without knowing how to get the settings editor or how to commit + * @param runnable + * @return commit result + */ + private boolean editSettings(final PrefRunnable runnable) { + final SharedPreferences.Editor prefsEdit = prefs.edit(); + runnable.edit(prefsEdit); + return prefsEdit.commit(); } + } diff --git a/src/cgeo/geocaching/cgeoapplication.java b/src/cgeo/geocaching/cgeoapplication.java index e11c1fc..651fdbe 100644 --- a/src/cgeo/geocaching/cgeoapplication.java +++ b/src/cgeo/geocaching/cgeoapplication.java @@ -98,7 +98,7 @@ public class cgeoapplication extends Application { public cgGeo startGeo(Context context, cgUpdateLoc geoUpdate, cgBase base, cgSettings settings, cgWarning warning, int time, int distance) { if (geo == null) { - geo = new cgGeo(context, this, geoUpdate, base, settings, warning, time, distance); + geo = new cgGeo(context, this, geoUpdate, base, settings, time, distance); geo.initGeo(); Log.i(cgSettings.tag, "Location service started"); diff --git a/src/cgeo/geocaching/cgeodate.java b/src/cgeo/geocaching/cgeodate.java index b1ec258..ce75e76 100644 --- a/src/cgeo/geocaching/cgeodate.java +++ b/src/cgeo/geocaching/cgeodate.java @@ -1,18 +1,16 @@ package cgeo.geocaching; +import java.util.Calendar; + import android.app.Activity; -import android.os.Bundle; import android.app.Dialog; +import android.os.Bundle; import android.view.ViewGroup.LayoutParams; import android.view.Window; import android.widget.DatePicker; -import java.util.Calendar; public class cgeodate extends Dialog { - private cgSettings settings = null; - private cgBase base = null; - private cgWarning warning = null; private cgLogForm parent = null; private Calendar date = Calendar.getInstance(); @@ -20,11 +18,7 @@ public class cgeodate extends Dialog { super(contextIn); // init - settings = new cgSettings(contextIn, contextIn.getSharedPreferences(cgSettings.preferences, 0)); - base = new cgBase((cgeoapplication) contextIn.getApplication(), settings, contextIn.getSharedPreferences(cgSettings.preferences, 0)); - warning = new cgWarning(contextIn); date = dateIn; - parent = parentIn; } diff --git a/src/cgeo/geocaching/cgeohelpers.java b/src/cgeo/geocaching/cgeohelpers.java index 3461cdc..33a596c 100644 --- a/src/cgeo/geocaching/cgeohelpers.java +++ b/src/cgeo/geocaching/cgeohelpers.java @@ -1,13 +1,14 @@ package cgeo.geocaching; -import android.os.Bundle; +import java.util.Locale; + import android.app.Activity; import android.content.Intent; -import android.view.View; import android.content.SharedPreferences; import android.content.res.Resources; import android.net.Uri; -import java.util.Locale; +import android.os.Bundle; +import android.view.View; public class cgeohelpers extends Activity { @@ -16,7 +17,6 @@ public class cgeohelpers extends Activity { private Activity activity = null; private cgSettings settings = null; private cgBase base = null; - private cgWarning warning = null; private SharedPreferences prefs = null; @Override @@ -30,7 +30,6 @@ public class cgeohelpers extends Activity { prefs = getSharedPreferences(cgSettings.preferences, 0); settings = new cgSettings(this, prefs); base = new cgBase(app, settings, prefs); - warning = new cgWarning(this); // set layout if (settings.skin == 1) { @@ -45,7 +44,7 @@ public class cgeohelpers extends Activity { @Override public void onResume() { super.onResume(); - + settings.load(); } diff --git a/src/cgeo/geocaching/mapcommon/cgMapMyOverlay.java b/src/cgeo/geocaching/mapcommon/cgMapMyOverlay.java index 664bdad..708ad3e 100644 --- a/src/cgeo/geocaching/mapcommon/cgMapMyOverlay.java +++ b/src/cgeo/geocaching/mapcommon/cgMapMyOverlay.java @@ -2,6 +2,7 @@ package cgeo.geocaching.mapcommon; import java.util.ArrayList; +import android.app.Activity; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.graphics.Canvas; @@ -38,9 +39,11 @@ public class cgMapMyOverlay implements OverlayBase { private ArrayList<Location> history = new ArrayList<Location>(); private Point historyPointN = new Point(); private Point historyPointP = new Point(); + private Activity activity; - public cgMapMyOverlay(cgSettings settingsIn) { + public cgMapMyOverlay(cgSettings settingsIn, Activity activity) { settings = settingsIn; + this.activity = activity; } public void setCoordinates(Location coordinatesIn) { @@ -180,7 +183,7 @@ public class cgMapMyOverlay implements OverlayBase { } if (arrow == null) { - arrow = BitmapFactory.decodeResource(settings.getContext().getResources(), R.drawable.my_location_chevron); + arrow = BitmapFactory.decodeResource(activity.getResources(), R.drawable.my_location_chevron); widthArrow = arrow.getWidth(); heightArrow = arrow.getHeight(); } diff --git a/src/cgeo/geocaching/mapcommon/cgeomap.java b/src/cgeo/geocaching/mapcommon/cgeomap.java index 7c38a53..ce7aada 100644 --- a/src/cgeo/geocaching/mapcommon/cgeomap.java +++ b/src/cgeo/geocaching/mapcommon/cgeomap.java @@ -278,7 +278,7 @@ public class cgeomap extends MapBase { mapView.clearOverlays(); if (overlayMyLoc == null) { - overlayMyLoc = new cgMapMyOverlay(settings); + overlayMyLoc = new cgMapMyOverlay(settings, activity); mapView.addOverlay(mapFactory.getOverlayBaseWrapper(overlayMyLoc)); } @@ -750,7 +750,7 @@ public class cgeomap extends MapBase { try { if (overlayMyLoc == null && mapView != null) { - overlayMyLoc = new cgMapMyOverlay(settings); + overlayMyLoc = new cgMapMyOverlay(settings, activity); mapView.addOverlay(settings.getMapFactory().getOverlayBaseWrapper(overlayMyLoc)); } |
