aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBananeweizen <bananeweizen@gmx.de>2011-10-03 13:47:07 +0200
committerBananeweizen <bananeweizen@gmx.de>2011-10-03 13:47:07 +0200
commitf52b1f0c1a58978efd5e8478f29484cb1f3b421e (patch)
tree39080018d83b12407a7df47153431464173e5e19
parente99ed4d71470da9efe59f4b363762d105dbfdc6d (diff)
downloadcgeo-f52b1f0c1a58978efd5e8478f29484cb1f3b421e.zip
cgeo-f52b1f0c1a58978efd5e8478f29484cb1f3b421e.tar.gz
cgeo-f52b1f0c1a58978efd5e8478f29484cb1f3b421e.tar.bz2
fix #120: make settings static (no singleton)
* Settings can no longer be instantiated, everything is static instead. * Most option values are no longer cached in fields. This has been done for clarity during the refactoring. I will add some performance tests afterwards and may re-introduce those fields for caching the option values. Sorry, if anyone gets merge issues afterwards. There was no easier way to implement this...
-rw-r--r--main/src/cgeo/geocaching/GCVote.java18
-rw-r--r--main/src/cgeo/geocaching/LogTemplateProvider.java2
-rw-r--r--main/src/cgeo/geocaching/Settings.java863
-rw-r--r--main/src/cgeo/geocaching/StaticMapsProvider.java14
-rw-r--r--main/src/cgeo/geocaching/Twitter.java16
-rw-r--r--main/src/cgeo/geocaching/activity/AbstractActivity.java12
-rw-r--r--main/src/cgeo/geocaching/activity/AbstractListActivity.java12
-rw-r--r--main/src/cgeo/geocaching/activity/ActivityMixin.java12
-rw-r--r--main/src/cgeo/geocaching/activity/IAbstractActivity.java6
-rw-r--r--main/src/cgeo/geocaching/apps/AbstractApp.java7
-rw-r--r--main/src/cgeo/geocaching/apps/AbstractLocusApp.java6
-rw-r--r--main/src/cgeo/geocaching/apps/cache/GeneralAppsFactory.java4
-rw-r--r--main/src/cgeo/geocaching/apps/cache/navi/GoogleMapsApp.java4
-rw-r--r--main/src/cgeo/geocaching/apps/cache/navi/GoogleNavigationApp.java8
-rw-r--r--main/src/cgeo/geocaching/apps/cache/navi/InternalMap.java5
-rw-r--r--main/src/cgeo/geocaching/apps/cache/navi/NavigationAppFactory.java4
-rw-r--r--main/src/cgeo/geocaching/apps/cachelist/CacheListAppFactory.java4
-rw-r--r--main/src/cgeo/geocaching/apps/cachelist/InternalCacheListMap.java3
-rw-r--r--main/src/cgeo/geocaching/backup/CentralBackupAgent.java4
-rw-r--r--main/src/cgeo/geocaching/cgBase.java474
-rw-r--r--main/src/cgeo/geocaching/cgCache.java16
-rw-r--r--main/src/cgeo/geocaching/cgCacheListAdapter.java32
-rw-r--r--main/src/cgeo/geocaching/cgCompass.java2
-rw-r--r--main/src/cgeo/geocaching/cgData.java196
-rw-r--r--main/src/cgeo/geocaching/cgDirection.java2
-rw-r--r--main/src/cgeo/geocaching/cgDirectionImg.java14
-rw-r--r--main/src/cgeo/geocaching/cgGPXListAdapter.java2
-rw-r--r--main/src/cgeo/geocaching/cgGeo.java28
-rw-r--r--main/src/cgeo/geocaching/cgHtmlImg.java28
-rw-r--r--main/src/cgeo/geocaching/cgMapfileListAdapter.java2
-rw-r--r--main/src/cgeo/geocaching/cgOAuth.java4
-rw-r--r--main/src/cgeo/geocaching/cgSearchHandler.java2
-rw-r--r--main/src/cgeo/geocaching/cgSearchThread.java2
-rw-r--r--main/src/cgeo/geocaching/cgSelectMapfile.java3
-rw-r--r--main/src/cgeo/geocaching/cgSettings.java644
-rw-r--r--main/src/cgeo/geocaching/cgeo.java67
-rw-r--r--main/src/cgeo/geocaching/cgeoabout.java3
-rw-r--r--main/src/cgeo/geocaching/cgeoaddresses.java7
-rw-r--r--main/src/cgeo/geocaching/cgeoadvsearch.java28
-rw-r--r--main/src/cgeo/geocaching/cgeoapplication.java16
-rw-r--r--main/src/cgeo/geocaching/cgeoauth.java25
-rw-r--r--main/src/cgeo/geocaching/cgeocaches.java123
-rw-r--r--main/src/cgeo/geocaching/cgeocoords.java10
-rw-r--r--main/src/cgeo/geocaching/cgeodetail.java41
-rw-r--r--main/src/cgeo/geocaching/cgeohelpers.java1
-rw-r--r--main/src/cgeo/geocaching/cgeoimages.java9
-rw-r--r--main/src/cgeo/geocaching/cgeoinit.java686
-rw-r--r--main/src/cgeo/geocaching/cgeonavigate.java52
-rw-r--r--main/src/cgeo/geocaching/cgeopoint.java29
-rw-r--r--main/src/cgeo/geocaching/cgeopopup.java15
-rw-r--r--main/src/cgeo/geocaching/cgeosmaps.java13
-rw-r--r--main/src/cgeo/geocaching/cgeotouch.java54
-rw-r--r--main/src/cgeo/geocaching/cgeotrackable.java7
-rw-r--r--main/src/cgeo/geocaching/cgeotrackables.java5
-rw-r--r--main/src/cgeo/geocaching/cgeovisit.java47
-rw-r--r--main/src/cgeo/geocaching/cgeowaypoint.java9
-rw-r--r--main/src/cgeo/geocaching/cgeowaypointadd.java15
-rw-r--r--main/src/cgeo/geocaching/compatibility/AndroidLevel8.java4
-rw-r--r--main/src/cgeo/geocaching/compatibility/Compatibility.java8
-rw-r--r--main/src/cgeo/geocaching/connector/GCConnector.java12
-rw-r--r--main/src/cgeo/geocaching/connector/opencaching/ApiOpenCachingConnector.java2
-rw-r--r--main/src/cgeo/geocaching/files/FileList.java9
-rw-r--r--main/src/cgeo/geocaching/files/GPXParser.java26
-rw-r--r--main/src/cgeo/geocaching/files/LocParser.java8
-rw-r--r--main/src/cgeo/geocaching/geopoint/DistanceParser.java5
-rw-r--r--main/src/cgeo/geocaching/maps/CGeoMap.java151
-rw-r--r--main/src/cgeo/geocaching/maps/CachesOverlay.java20
-rw-r--r--main/src/cgeo/geocaching/maps/OtherCachersOverlay.java8
-rw-r--r--main/src/cgeo/geocaching/maps/PositionOverlay.java14
-rw-r--r--main/src/cgeo/geocaching/maps/ScaleOverlay.java52
-rw-r--r--main/src/cgeo/geocaching/maps/google/GoogleCacheOverlay.java5
-rw-r--r--main/src/cgeo/geocaching/maps/google/GoogleMapView.java31
-rw-r--r--main/src/cgeo/geocaching/maps/google/GoogleOverlay.java9
-rw-r--r--main/src/cgeo/geocaching/maps/interfaces/MapViewImpl.java13
-rw-r--r--main/src/cgeo/geocaching/maps/mapsforge/MapsforgeCacheOverlay.java5
-rw-r--r--main/src/cgeo/geocaching/maps/mapsforge/MapsforgeMapView.java35
-rw-r--r--main/src/cgeo/geocaching/maps/mapsforge/MapsforgeOverlay.java7
-rw-r--r--main/src/cgeo/geocaching/sorting/AbstractCacheComparator.java4
-rw-r--r--main/src/cgeo/geocaching/utils/CryptUtils.java8
-rw-r--r--tests/src/cgeo/geocaching/test/DistanceParserTest.java19
-rw-r--r--tests/src/cgeo/geocaching/test/RegExRealPerformanceTest.java4
-rw-r--r--tests/src/cgeo/geocaching/test/SettingsTest.java27
-rw-r--r--tests/src/cgeo/geocaching/test/WhitespaceTest.java6
-rw-r--r--tests/src/cgeo/geocaching/test/cgSettingsTest.java30
-rw-r--r--tests/src/cgeo/geocaching/test/cgeoApplicationTest.java10
85 files changed, 1973 insertions, 2276 deletions
diff --git a/main/src/cgeo/geocaching/GCVote.java b/main/src/cgeo/geocaching/GCVote.java
index 7e271e5..5126859 100644
--- a/main/src/cgeo/geocaching/GCVote.java
+++ b/main/src/cgeo/geocaching/GCVote.java
@@ -55,8 +55,8 @@ public final class GCVote {
try {
final Parameters params = new Parameters();
- if (cgSettings.isLogin()) {
- final Map<String, String> login = cgSettings.getGCvoteLogin();
+ if (Settings.isLogin()) {
+ final Map<String, String> login = Settings.getGCvoteLogin();
if (login != null) {
params.put("userName", login.get("username"));
params.put("password", login.get("password"));
@@ -96,7 +96,7 @@ public final class GCVote {
}
}
} catch (Exception e) {
- Log.w(cgSettings.tag, "cgBase.getRating: Failed to parse guid");
+ Log.w(Settings.tag, "cgBase.getRating: Failed to parse guid");
}
try {
@@ -109,7 +109,7 @@ public final class GCVote {
}
}
} catch (Exception e) {
- Log.w(cgSettings.tag, "cgBase.getRating: Failed to parse loggedIn");
+ Log.w(Settings.tag, "cgBase.getRating: Failed to parse loggedIn");
}
try {
@@ -120,7 +120,7 @@ public final class GCVote {
}
}
} catch (Exception e) {
- Log.w(cgSettings.tag, "cgBase.getRating: Failed to parse rating");
+ Log.w(Settings.tag, "cgBase.getRating: Failed to parse rating");
}
try {
@@ -131,7 +131,7 @@ public final class GCVote {
}
}
} catch (Exception e) {
- Log.w(cgSettings.tag, "cgBase.getRating: Failed to parse vote count");
+ Log.w(Settings.tag, "cgBase.getRating: Failed to parse vote count");
}
if (loggedIn) {
@@ -143,7 +143,7 @@ public final class GCVote {
}
}
} catch (Exception e) {
- Log.w(cgSettings.tag, "cgBase.getRating: Failed to parse user's vote");
+ Log.w(Settings.tag, "cgBase.getRating: Failed to parse user's vote");
}
}
@@ -152,7 +152,7 @@ public final class GCVote {
}
}
} catch (Exception e) {
- Log.e(cgSettings.tag, "cgBase.getRating: " + e.toString());
+ Log.e(Settings.tag, "cgBase.getRating: " + e.toString());
}
return ratings;
@@ -170,7 +170,7 @@ public final class GCVote {
return false;
}
- final Map<String, String> login = cgSettings.getGCvoteLogin();
+ final Map<String, String> login = Settings.getGCvoteLogin();
if (login == null) {
return false;
}
diff --git a/main/src/cgeo/geocaching/LogTemplateProvider.java b/main/src/cgeo/geocaching/LogTemplateProvider.java
index e9c1f1d..1a775fc 100644
--- a/main/src/cgeo/geocaching/LogTemplateProvider.java
+++ b/main/src/cgeo/geocaching/LogTemplateProvider.java
@@ -143,7 +143,7 @@ public class LogTemplateProvider {
}
}
} catch (Exception e) {
- Log.w(cgSettings.tag, "cgBase.parseFindCount: " + e.toString());
+ Log.w(Settings.tag, "cgBase.parseFindCount: " + e.toString());
}
return findCount;
diff --git a/main/src/cgeo/geocaching/Settings.java b/main/src/cgeo/geocaching/Settings.java
new file mode 100644
index 0000000..a71de99
--- /dev/null
+++ b/main/src/cgeo/geocaching/Settings.java
@@ -0,0 +1,863 @@
+package cgeo.geocaching;
+
+import cgeo.geocaching.geopoint.Geopoint;
+import cgeo.geocaching.maps.google.GoogleMapFactory;
+import cgeo.geocaching.maps.interfaces.MapFactory;
+import cgeo.geocaching.maps.mapsforge.MapsforgeMapFactory;
+
+import org.apache.commons.lang3.StringUtils;
+import org.apache.commons.lang3.tuple.ImmutablePair;
+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.content.res.Resources;
+import android.os.Environment;
+
+import java.util.HashMap;
+import java.util.Locale;
+import java.util.Map;
+
+/**
+ * General c:geo preferences/settings set by the user
+ */
+public final class Settings {
+
+ private static final String KEY_HELP_SHOWN = "helper";
+ private static final String KEY_ANYLONGITUDE = "anylongitude";
+ private static final String KEY_ANYLATITUDE = "anylatitude";
+ private static final String KEY_PUBLICLOC = "publicloc";
+ private static final String KEY_USE_OFFLINEMAPS = "offlinemaps";
+ 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 static final String KEY_COORD_INPUT_FORMAT = "coordinputformat";
+ private static final String KEY_LOG_OFFLINE = "log_offline";
+ private static final String KEY_LOAD_DIRECTION_IMG = "loaddirectionimg";
+ private static final String KEY_GC_CUSTOM_DATE = "gccustomdate";
+ private static final String KEY_SHOW_WAYPOINTS_THRESHOLD = "gcshowwaypointsthreshold";
+
+ private final static int unitsMetric = 1;
+ private final static int unitsImperial = 2;
+
+ // twitter api keys
+ private final static String keyConsumerPublic = "RFafPiNi3xRhcS1TPE3wTw";
+ private final static String keyConsumerSecret = "7iDJprNPI9hzRwWhpzycSr9SPZMFrdVdsxD2OauI9k";
+
+ private interface PrefRunnable {
+ void edit(final Editor edit);
+ }
+
+ public enum mapSourceEnum {
+ googleMap,
+ googleSat,
+ mapsforgeMapnik,
+ mapsforgeOsmarender,
+ mapsforgeCycle,
+ mapsforgeOffline;
+
+ static mapSourceEnum fromInt(int id) {
+ final mapSourceEnum[] values = mapSourceEnum.values();
+ if (id >= 0 && id < values.length) {
+ return values[id];
+ } else {
+ return googleMap;
+ }
+ }
+
+ public boolean isGoogleMapSource() {
+ if (googleMap == this || googleSat == this) {
+ return true;
+ }
+
+ return false;
+ }
+ }
+
+ public enum coordInputFormatEnum {
+ Plain,
+ Deg,
+ Min,
+ Sec;
+
+ static coordInputFormatEnum fromInt(int id) {
+ final coordInputFormatEnum[] values = coordInputFormatEnum.values();
+ if (id >= 0 && id < values.length) {
+ return values[id];
+ } else {
+ return Min;
+ }
+ }
+ }
+
+ // constants
+ public final static String cache = ".cgeo";
+
+ // usable values
+ public static final String tag = "cgeo";
+
+ /** Name of the preferences file */
+ public static final String preferences = "cgeo.pref";
+
+ private static final SharedPreferences sharedPrefs = cgeoapplication.getInstance().getSharedPreferences(Settings.preferences, Context.MODE_PRIVATE);
+ private static String username = null;
+ private static String password = null;
+
+ // maps
+ private static MapFactory mapFactory = null;
+
+ private Settings() {
+ // this class is not to be instantiated;
+ }
+
+ private static void setLanguage(boolean useEnglish) {
+ Locale locale = Locale.getDefault();
+ if (useEnglish) {
+ locale = new Locale("en");
+ }
+ final Configuration config = new Configuration();
+ config.locale = locale;
+ final Resources resources = cgeoapplication.getInstance().getResources();
+ resources.updateConfiguration(config, resources.getDisplayMetrics());
+ }
+
+ public static String getStorage() {
+ return getStorageSpecific()[0];
+ }
+
+ public static String getStorageSec() {
+ return getStorageSpecific()[1];
+ }
+
+ public static String[] getStorageSpecific() {
+ final String external = Environment.getExternalStorageDirectory() + "/" + cache + "/";
+ final String data = Environment.getDataDirectory() + "/data/cgeo.geocaching/" + cache + "/";
+
+ if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
+ return new String[] { external, data };
+ } else {
+ return new String[] { data, external };
+ }
+ }
+
+ public static boolean isLogin() {
+ final String preUsername = sharedPrefs.getString(KEY_USERNAME, null);
+ final String prePassword = sharedPrefs.getString(KEY_PASSWORD, null);
+
+ return !StringUtils.isBlank(preUsername) && !StringUtils.isBlank(prePassword);
+ }
+
+ /**
+ * Get login and password information.
+ *
+ * @return a pair (login, password) or null if no valid information is stored
+ */
+ public static ImmutablePair<String, String> getLogin() {
+ if (username == null || password == null) {
+ final String preUsername = sharedPrefs.getString(KEY_USERNAME, null);
+ final String prePassword = sharedPrefs.getString(KEY_PASSWORD, null);
+
+ if (!isInitialized() && (preUsername == null || prePassword == null)) {
+ final Context context = cgeoapplication.getInstance().getApplicationContext();
+ final Intent initIntent = new Intent(context, cgeoinit.class);
+ context.startActivity(initIntent);
+
+ setInitialized();
+ return null;
+ } else if (isInitialized() && (preUsername == null || prePassword == null)) {
+ return null;
+ }
+
+ username = preUsername;
+ password = prePassword;
+ }
+ return new ImmutablePair<String, String>(username, password);
+ }
+
+ public static String getUsername() {
+ if (null == username) {
+ return sharedPrefs.getString(KEY_USERNAME, null);
+ } else {
+ return username;
+ }
+ }
+
+ public static boolean setLogin(final String username, final String password) {
+ Settings.username = username;
+ Settings.password = password;
+ return editSharedSettings(new PrefRunnable() {
+
+ @Override
+ public void edit(Editor edit) {
+ if (StringUtils.isBlank(username) || StringUtils.isBlank(password)) {
+ // 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 static boolean isGCvoteLogin() {
+ final String preUsername = sharedPrefs.getString(KEY_USERNAME, null);
+ final String prePassword = sharedPrefs.getString(KEY_GCVOTE_PASSWORD, null);
+
+ return !StringUtils.isBlank(preUsername) && !StringUtils.isBlank(prePassword);
+ }
+
+ public static boolean setGCvoteLogin(final String password) {
+ return editSharedSettings(new PrefRunnable() {
+
+ @Override
+ public void edit(Editor edit) {
+ if (StringUtils.isBlank(password)) {
+ // erase password
+ edit.remove(KEY_GCVOTE_PASSWORD);
+ } else {
+ // save password
+ edit.putString(KEY_GCVOTE_PASSWORD, password);
+ }
+ }
+ });
+ }
+
+ public static Map<String, String> getGCvoteLogin() {
+ final String preUsername = sharedPrefs.getString(KEY_USERNAME, null);
+ final String prePassword = sharedPrefs.getString(KEY_GCVOTE_PASSWORD, null);
+
+ if (StringUtils.isBlank(preUsername) || StringUtils.isBlank(prePassword)) {
+ return null;
+ }
+ final Map<String, String> login = new HashMap<String, String>();
+
+ login.put(KEY_USERNAME, preUsername);
+ login.put(KEY_PASSWORD, prePassword);
+
+ return login;
+ }
+
+ public static boolean setSignature(final String signature) {
+ return editSharedSettings(new PrefRunnable() {
+
+ @Override
+ public void edit(Editor edit) {
+ if (StringUtils.isBlank(signature)) {
+ // erase signature
+ edit.remove(KEY_SIGNATURE);
+ } else {
+ // save signature
+ edit.putString(KEY_SIGNATURE, signature);
+ }
+ }
+ });
+ }
+
+ public static String getSignature() {
+ return sharedPrefs.getString(KEY_SIGNATURE, null);
+ }
+
+ public static String setCacheType(final String cacheTypeIn) {
+ editSharedSettings(new PrefRunnable() {
+ @Override
+ public void edit(Editor edit) {
+ edit.putString(KEY_CACHE_TYPE, cacheTypeIn);
+ }
+ });
+ return cacheTypeIn;
+ }
+
+ public static void setLiveMap(final boolean live) {
+ editSharedSettings(new PrefRunnable() {
+
+ @Override
+ public void edit(Editor edit) {
+ edit.putInt(KEY_MAP_LIVE, live ? 1 : 0);
+ }
+ });
+ }
+
+ public static int getLastList() {
+ final int listId = sharedPrefs.getInt(KEY_LAST_USED_LIST, -1);
+
+ return listId;
+ }
+
+ public static void saveLastList(final int listId) {
+ editSharedSettings(new PrefRunnable() {
+
+ @Override
+ public void edit(Editor edit) {
+ edit.putInt(KEY_LAST_USED_LIST, listId);
+ }
+ });
+ }
+
+ public static void setWebNameCode(final String name, final String code) {
+ editSharedSettings(new PrefRunnable() {
+
+ @Override
+ public void edit(Editor edit) {
+
+ edit.putString(KEY_WEBDEVICE_NAME, name);
+ edit.putString(KEY_WEB_DEVICE_CODE, code);
+ }
+ });
+ }
+
+ public static MapFactory getMapFactory() {
+ if (mapFactory == null) {
+ if (getMapSource().isGoogleMapSource()) {
+ mapFactory = new GoogleMapFactory();
+ }
+ else {
+ mapFactory = new MapsforgeMapFactory();
+ }
+ }
+ return mapFactory;
+ }
+
+ public static String getMapFile() {
+ return sharedPrefs.getString(KEY_MAPFILE, null);
+ }
+
+ public static boolean setMapFile(final String mapFile) {
+ final boolean commitResult = editSharedSettings(new PrefRunnable() {
+
+ @Override
+ public void edit(Editor edit) {
+ edit.putString(KEY_MAPFILE, mapFile);
+ }
+ });
+
+ return commitResult;
+ }
+
+ public static boolean isValidMapFile() {
+ return checkMapfile(getMapFile());
+ }
+
+ private static boolean checkMapfile(String mapFileIn) {
+ if (null == mapFileIn) {
+ return false;
+ }
+ return MapDatabase.isValidMapFile(mapFileIn);
+ }
+
+ public static coordInputFormatEnum getCoordInputFormat() {
+ return coordInputFormatEnum.fromInt(sharedPrefs.getInt(KEY_COORD_INPUT_FORMAT, 0));
+ }
+
+ public static void setCoordInputFormat(final coordInputFormatEnum format) {
+ editSharedSettings(new PrefRunnable() {
+
+ @Override
+ public void edit(Editor edit) {
+ edit.putInt(KEY_COORD_INPUT_FORMAT, format.ordinal());
+ }
+ });
+ }
+
+ static void setLogOffline(final boolean offline) {
+ editSharedSettings(new PrefRunnable() {
+
+ @Override
+ public void edit(Editor edit) {
+ edit.putBoolean(KEY_LOG_OFFLINE, offline);
+ }
+ });
+ }
+
+ public static boolean getLogOffline() {
+ return sharedPrefs.getBoolean(KEY_LOG_OFFLINE, false);
+ }
+
+ static void setLoadDirImg(final boolean value) {
+ editSharedSettings(new PrefRunnable() {
+
+ @Override
+ public void edit(Editor edit) {
+ edit.putBoolean(KEY_LOAD_DIRECTION_IMG, value);
+ }
+ });
+ }
+
+ public static boolean getLoadDirImg() {
+ return sharedPrefs.getBoolean(KEY_LOAD_DIRECTION_IMG, true);
+ }
+
+ static void setGcCustomDate(final String format) {
+ editSharedSettings(new PrefRunnable() {
+
+ @Override
+ public void edit(Editor edit) {
+ edit.putString(KEY_GC_CUSTOM_DATE, format);
+ }
+ });
+ }
+
+ public static String getGcCustomDate() {
+ return sharedPrefs.getString(KEY_GC_CUSTOM_DATE, null);
+ }
+
+ public static boolean isBrowser() {
+ return 0 != sharedPrefs.getInt(KEY_AS_BROWSER, 1);
+ }
+
+ public static boolean isExcludeMyCaches() {
+ return 0 != sharedPrefs.getInt(KEY_EXCLUDE_OWN, 0);
+ }
+
+ /**
+ * edit some settings without knowing how to get the settings editor or how to commit
+ *
+ * @param runnable
+ * @return
+ */
+ private static boolean editSharedSettings(final PrefRunnable runnable) {
+ final SharedPreferences.Editor prefsEdit = sharedPrefs.edit();
+ runnable.edit(prefsEdit);
+ return prefsEdit.commit();
+ }
+
+ public static void setExcludeMine(final boolean exclude) {
+ editSharedSettings(new PrefRunnable() {
+
+ @Override
+ public void edit(Editor edit) {
+ edit.putInt(KEY_EXCLUDE_OWN, exclude ? 1 : 0);
+ }
+ });
+ }
+
+ public static void setAsBrowser(final boolean asBrowser) {
+ editSharedSettings(new PrefRunnable() {
+
+ @Override
+ public void edit(Editor edit) {
+ edit.putInt(KEY_AS_BROWSER, asBrowser ? 1 : 0);
+ }
+ });
+ }
+
+ public static void setUseEnglish(final boolean english) {
+ editSharedSettings(new PrefRunnable() {
+ @Override
+ public void edit(Editor edit) {
+ edit.putBoolean(KEY_USE_ENGLISH, english);
+ setLanguage(english);
+ }
+ });
+ }
+
+ public static boolean isUseEnglish() {
+ return sharedPrefs.getBoolean(KEY_USE_ENGLISH, false);
+ }
+
+ public static boolean isShowAddress() {
+ return 0 != sharedPrefs.getInt(KEY_SHOW_ADDRESS, 1);
+ }
+
+ public static void setShowAddress(final boolean showAddress) {
+ editSharedSettings(new PrefRunnable() {
+
+ @Override
+ public void edit(Editor edit) {
+ edit.putInt(KEY_SHOW_ADDRESS, showAddress ? 1 : 0);
+ }
+ });
+ }
+
+ public static boolean isShowCaptcha() {
+ return sharedPrefs.getBoolean(KEY_SHOW_CAPTCHA, false);
+ }
+
+ public static void setShowCaptcha(final boolean showCaptcha) {
+ editSharedSettings(new PrefRunnable() {
+
+ @Override
+ public void edit(Editor edit) {
+ edit.putBoolean(KEY_SHOW_CAPTCHA, showCaptcha);
+ }
+ });
+ }
+
+ public static boolean isExcludeDisabledCaches() {
+ return 0 != sharedPrefs.getInt(KEY_EXCLUDE_DISABLED, 0);
+ }
+
+ public static void setExcludeDisabledCaches(final boolean exclude) {
+ editSharedSettings(new PrefRunnable() {
+
+ @Override
+ public void edit(Editor edit) {
+ edit.putInt(KEY_EXCLUDE_DISABLED, exclude ? 1 : 0);
+ }
+ });
+ }
+
+ public static boolean isStoreOfflineMaps() {
+ return 0 != sharedPrefs.getInt(KEY_USE_OFFLINEMAPS, 1);
+ }
+
+ public static void setStoreOfflineMaps(final boolean offlineMaps) {
+ editSharedSettings(new PrefRunnable() {
+
+ @Override
+ public void edit(Editor edit) {
+ edit.putInt(KEY_USE_OFFLINEMAPS, offlineMaps ? 1 : 0);
+ }
+ });
+ }
+
+ public static boolean isStoreLogImages() {
+ return sharedPrefs.getBoolean(KEY_STORE_LOG_IMAGES, false);
+ }
+
+ public static void setStoreLogImages(final boolean storeLogImages) {
+ editSharedSettings(new PrefRunnable() {
+
+ @Override
+ public void edit(Editor edit) {
+ edit.putBoolean(KEY_STORE_LOG_IMAGES, storeLogImages);
+ }
+ });
+ }
+
+ public static boolean isUseGoogleNavigation() {
+ return 0 != sharedPrefs.getInt(KEY_USE_GOOGLE_NAVIGATION, 1);
+ }
+
+ public static void setUseGoogleNavigation(final boolean useGoogleNavigation) {
+ editSharedSettings(new PrefRunnable() {
+
+ @Override
+ public void edit(Editor edit) {
+ edit.putInt(KEY_USE_GOOGLE_NAVIGATION, useGoogleNavigation ? 1 : 0);
+ }
+ });
+ }
+
+ public static boolean isAutoLoadDescription() {
+ return 0 != sharedPrefs.getInt(KEY_LOAD_DESCRIPTION, 0);
+ }
+
+ public static void setAutoLoadDesc(final boolean autoLoad) {
+ editSharedSettings(new PrefRunnable() {
+
+ @Override
+ public void edit(Editor edit) {
+ edit.putInt(KEY_LOAD_DESCRIPTION, autoLoad ? 1 : 0);
+ }
+ });
+ }
+
+ public static boolean isLiveList() {
+ return 0 != sharedPrefs.getInt(KEY_LIVE_LIST, 1);
+ }
+
+ public static void setLiveList(final boolean liveList) {
+ editSharedSettings(new PrefRunnable() {
+
+ @Override
+ public void edit(Editor edit) {
+ edit.putInt(KEY_LIVE_LIST, liveList ? 1 : 0);
+ }
+ });
+ }
+
+ public static boolean isPublicLoc() {
+ return 0 != sharedPrefs.getInt(KEY_PUBLICLOC, 0);
+ }
+
+ public static void setPublicLoc(final boolean publicLocation) {
+ editSharedSettings(new PrefRunnable() {
+
+ @Override
+ public void edit(Editor edit) {
+ edit.putInt(KEY_PUBLICLOC, publicLocation ? 1 : 0);
+ }
+ });
+ }
+
+ public static boolean isTrackableAutoVisit() {
+ return sharedPrefs.getBoolean(KEY_AUTO_VISIT_TRACKABLES, false);
+ }
+
+ public static void setTrackableAutoVisit(final boolean autoVisit) {
+ editSharedSettings(new PrefRunnable() {
+
+ @Override
+ public void edit(Editor edit) {
+ edit.putBoolean(KEY_AUTO_VISIT_TRACKABLES, autoVisit);
+ }
+ });
+ }
+
+ public static boolean isAutoInsertSignature() {
+ return sharedPrefs.getBoolean(KEY_AUTO_INSERT_SIGNATURE, false);
+ }
+
+ public static void setAutoInsertSignature(final boolean autoInsert) {
+ editSharedSettings(new PrefRunnable() {
+
+ @Override
+ public void edit(Editor edit) {
+ edit.putBoolean(KEY_AUTO_INSERT_SIGNATURE, autoInsert);
+ }
+ });
+ }
+
+ public static boolean isUseMetricUnits() {
+ return sharedPrefs.getInt(KEY_METRIC_UNITS, unitsMetric) == unitsMetric;
+ }
+
+ public static void setUseMetricUnits(final boolean metric) {
+ editSharedSettings(new PrefRunnable() {
+
+ @Override
+ public void edit(Editor edit) {
+ edit.putInt(KEY_METRIC_UNITS, metric ? unitsMetric : unitsImperial);
+ }
+ });
+ }
+
+ public static boolean isLiveMap() {
+ return sharedPrefs.getInt(KEY_MAP_LIVE, 1) != 0;
+ }
+
+ public static boolean isMapTrail() {
+ return sharedPrefs.getInt(KEY_MAP_TRAIL, 1) != 0;
+ }
+
+ public static void setMapTrail(final boolean showTrail) {
+ editSharedSettings(new PrefRunnable() {
+
+ @Override
+ public void edit(Editor edit) {
+ edit.putInt(KEY_MAP_TRAIL, showTrail ? 1 : 0);
+ }
+ });
+ }
+
+ public static int getMapZoom() {
+ return sharedPrefs.getInt(KEY_LAST_MAP_ZOOM, 14);
+ }
+
+ public static void setMapZoom(final int mapZoomLevel) {
+ editSharedSettings(new PrefRunnable() {
+
+ @Override
+ public void edit(Editor edit) {
+ edit.putInt(KEY_LAST_MAP_ZOOM, mapZoomLevel);
+ }
+ });
+ }
+
+ public static mapSourceEnum getMapSource() {
+ return mapSourceEnum.fromInt(sharedPrefs.getInt(KEY_MAP_SOURCE, 0));
+ }
+
+ public static void setMapSource(final mapSourceEnum newMapSource) {
+ if (getMapSource().isGoogleMapSource() != newMapSource.isGoogleMapSource()) {
+ mapFactory = null;
+ }
+ editSharedSettings(new PrefRunnable() {
+
+ @Override
+ public void edit(Editor edit) {
+ edit.putInt(KEY_MAP_SOURCE, newMapSource.ordinal());
+ }
+ });
+ }
+
+ public static void setAnyCoordinates(final Geopoint coords) {
+ editSharedSettings(new PrefRunnable() {
+
+ @Override
+ public void edit(Editor edit) {
+ if (null != coords) {
+ edit.putFloat(KEY_ANYLATITUDE, (float) coords.getLatitude());
+ edit.putFloat(KEY_ANYLONGITUDE, (float) coords.getLongitude());
+ } else {
+ edit.remove(KEY_ANYLATITUDE);
+ edit.remove(KEY_ANYLONGITUDE);
+ }
+ }
+ });
+
+ }
+
+ public static boolean isUseCompass() {
+ return 0 != sharedPrefs.getInt(KEY_USE_COMPASS, 1);
+ }
+
+ public static void setUseCompass(final boolean useCompass) {
+ editSharedSettings(new PrefRunnable() {
+
+ @Override
+ public void edit(Editor edit) {
+ edit.putInt(KEY_USE_COMPASS, useCompass ? 1 : 0);
+ }
+ });
+ }
+
+ private static boolean isInitialized() {
+ return 0 != sharedPrefs.getInt(KEY_INITIALIZED, 0);
+ }
+
+ private static void setInitialized() {
+ editSharedSettings(new PrefRunnable() {
+
+ @Override
+ public void edit(Editor edit) {
+ edit.putInt(KEY_INITIALIZED, 1);
+ }
+ });
+ }
+
+ public static boolean isHelpShown() {
+ return sharedPrefs.getInt(KEY_HELP_SHOWN, 0) != 0;
+ }
+
+ public static void setHelpShown() {
+ editSharedSettings(new PrefRunnable() {
+
+ @Override
+ public void edit(Editor edit) {
+ edit.putInt(KEY_HELP_SHOWN, 1);
+ }
+ });
+ }
+
+ public static boolean isLightSkin() {
+ return sharedPrefs.getInt(KEY_SKIN, 0) != 0;
+ }
+
+ public static void setLightSkin(final boolean lightSkin) {
+ editSharedSettings(new PrefRunnable() {
+
+ @Override
+ public void edit(Editor edit) {
+ edit.putInt(KEY_SKIN, lightSkin ? 1 : 0);
+ }
+ });
+ }
+
+ public static String getKeyConsumerPublic() {
+ return keyConsumerPublic;
+ }
+
+ public static String getKeyConsumerSecret() {
+ return keyConsumerSecret;
+ }
+
+ public static int getAltCorrection() {
+ return sharedPrefs.getInt(KEY_ALTITUDE_CORRECTION, 0);
+ }
+
+ public static boolean setAltCorrection(final int altitude) {
+ return editSharedSettings(new PrefRunnable() {
+
+ @Override
+ public void edit(Editor edit) {
+ edit.putInt(KEY_ALTITUDE_CORRECTION, altitude);
+ }
+ });
+ }
+
+ public static String getWebDeviceCode() {
+ return sharedPrefs.getString(KEY_WEB_DEVICE_CODE, null);
+ }
+
+ public static String getWebDeviceName() {
+ return sharedPrefs.getString(KEY_WEBDEVICE_NAME, null);
+ }
+
+ public static String getCacheType() {
+ return sharedPrefs.getString(KEY_CACHE_TYPE, null);
+ }
+
+ public static int getWayPointsThreshold() {
+ return sharedPrefs.getInt(KEY_SHOW_WAYPOINTS_THRESHOLD, 0);
+ }
+
+ public static void setShowWaypointsThreshold(final int threshold) {
+ editSharedSettings(new PrefRunnable() {
+
+ @Override
+ public void edit(Editor edit) {
+ edit.putInt(KEY_SHOW_WAYPOINTS_THRESHOLD, threshold);
+ }
+ });
+ }
+
+ public static boolean isUseTwitter() {
+ return 0 != sharedPrefs.getInt(KEY_USE_TWITTER, 0);
+ }
+
+ public static void setUseTwitter(final boolean useTwitter) {
+ editSharedSettings(new PrefRunnable() {
+
+ @Override
+ public void edit(Editor edit) {
+ edit.putInt(KEY_USE_TWITTER, useTwitter ? 1 : 0);
+ }
+ });
+ }
+
+ public static boolean isTwitterLoginValid() {
+ return !StringUtils.isBlank(getTokenPublic()) && !StringUtils.isBlank(getTokenSecret());
+ }
+
+ public static String getTokenPublic() {
+ return sharedPrefs.getString(KEY_TWITTER_TOKEN_PUBLIC, null);
+ }
+
+ public static String getTokenSecret() {
+ return sharedPrefs.getString(KEY_TWITTER_TOKEN_SECRET, null);
+
+ }
+
+ public static int getVersion() {
+ return sharedPrefs.getInt(KEY_VERSION, 0);
+ }
+
+}
diff --git a/main/src/cgeo/geocaching/StaticMapsProvider.java b/main/src/cgeo/geocaching/StaticMapsProvider.java
index a33e8b2..0c21912 100644
--- a/main/src/cgeo/geocaching/StaticMapsProvider.java
+++ b/main/src/cgeo/geocaching/StaticMapsProvider.java
@@ -40,7 +40,7 @@ public class StaticMapsProvider {
}
private static void createStorageDirectory(final cgCache cache) {
- File dir = new File(cgSettings.getStorage());
+ File dir = new File(Settings.getStorage());
if (dir.exists() == false) {
dir.mkdirs();
}
@@ -51,7 +51,7 @@ public class StaticMapsProvider {
}
private static String getStaticMapsDirectory(final cgCache cache) {
- return cgSettings.getStorage() + cache.geocode;
+ return Settings.getStorage() + cache.geocode;
}
private static void downloadMap(cgCache cache, int zoom, String mapType, int level, String latlonMap, int edge, String waypoints) {
@@ -70,7 +70,7 @@ public class StaticMapsProvider {
for (int i = 0; i < 3; i++) {
if (i > 0)
- Log.w(cgSettings.tag, "cgMapImg.getDrawable: Failed to download data, retrying. Attempt #" + (i + 1));
+ Log.w(Settings.tag, "cgMapImg.getDrawable: Failed to download data, retrying. Attempt #" + (i + 1));
try {
client = new DefaultHttpClient();
@@ -99,7 +99,7 @@ public class StaticMapsProvider {
fos.flush();
ok = true;
} catch (IOException e) {
- Log.e(cgSettings.tag, "cgMapImg.getDrawable (saving to cache): " + e.toString());
+ Log.e(Settings.tag, "cgMapImg.getDrawable (saving to cache): " + e.toString());
} finally {
is.close();
fos.close();
@@ -114,13 +114,13 @@ public class StaticMapsProvider {
break;
}
} catch (Exception e) {
- Log.e(cgSettings.tag, "cgMapImg.getDrawable (downloading from web): " + e.toString());
+ Log.e(Settings.tag, "cgMapImg.getDrawable (downloading from web): " + e.toString());
}
}
}
- public static void downloadMaps(cgCache cache, cgSettings settings, Activity activity) {
- if (settings.storeOfflineMaps != 1 || cache.coords == null || StringUtils.isBlank(cache.geocode)) {
+ public static void downloadMaps(cgCache cache, Activity activity) {
+ if (!Settings.isStoreOfflineMaps() || cache.coords == null || StringUtils.isBlank(cache.geocode)) {
return;
}
diff --git a/main/src/cgeo/geocaching/Twitter.java b/main/src/cgeo/geocaching/Twitter.java
index 37e594b..b6300f2 100644
--- a/main/src/cgeo/geocaching/Twitter.java
+++ b/main/src/cgeo/geocaching/Twitter.java
@@ -2,8 +2,6 @@ package cgeo.geocaching;
import cgeo.geocaching.geopoint.Geopoint;
-import org.apache.commons.lang3.StringUtils;
-
import android.util.Log;
import java.io.BufferedReader;
@@ -22,11 +20,11 @@ import java.util.zip.InflaterInputStream;
public final class Twitter {
public static final int MAX_TWEET_SIZE = 140;
- public static void postTweet(cgeoapplication app, cgSettings settings, String status, final Geopoint coords) {
+ public static void postTweet(cgeoapplication app, String status, final Geopoint coords) {
if (app == null) {
return;
}
- if (settings == null || StringUtils.isBlank(settings.tokenPublic) || StringUtils.isBlank(settings.tokenSecret)) {
+ if (!Settings.isTwitterLoginValid()) {
return;
}
@@ -40,7 +38,7 @@ public final class Twitter {
parameters.put("display_coordinates", "true");
}
- final String paramsDone = cgOAuth.signOAuth("api.twitter.com", "/1/statuses/update.json", "POST", false, parameters, settings.tokenPublic, settings.tokenSecret);
+ final String paramsDone = cgOAuth.signOAuth("api.twitter.com", "/1/statuses/update.json", "POST", false, parameters, Settings.getTokenPublic(), Settings.getTokenSecret());
HttpURLConnection connection = null;
try {
@@ -63,7 +61,7 @@ public final class Twitter {
wr.flush();
wr.close();
- Log.i(cgSettings.tag, "Twitter.com: " + connection.getResponseCode() + " " + connection.getResponseMessage());
+ Log.i(Settings.tag, "Twitter.com: " + connection.getResponseCode() + " " + connection.getResponseMessage());
InputStream ins;
final String encoding = connection.getContentEncoding();
@@ -86,7 +84,7 @@ public final class Twitter {
inr.close();
connection.disconnect();
} catch (IOException e) {
- Log.e(cgSettings.tag, "cgBase.postTweet.IO: " + connection.getResponseCode() + ": " + connection.getResponseMessage() + " ~ " + e.toString());
+ Log.e(Settings.tag, "cgBase.postTweet.IO: " + connection.getResponseCode() + ": " + connection.getResponseMessage() + " ~ " + e.toString());
final InputStream ins = connection.getErrorStream();
final StringBuffer buffer = new StringBuffer();
@@ -99,12 +97,12 @@ public final class Twitter {
ins.close();
inr.close();
} catch (Exception e) {
- Log.e(cgSettings.tag, "cgBase.postTweet.inner: " + e.toString());
+ Log.e(Settings.tag, "cgBase.postTweet.inner: " + e.toString());
}
connection.disconnect();
} catch (Exception e) {
- Log.e(cgSettings.tag, "cgBase.postTweet: " + e.toString());
+ Log.e(Settings.tag, "cgBase.postTweet: " + e.toString());
}
}
diff --git a/main/src/cgeo/geocaching/activity/AbstractActivity.java b/main/src/cgeo/geocaching/activity/AbstractActivity.java
index be3a8f9..5359b5e 100644
--- a/main/src/cgeo/geocaching/activity/AbstractActivity.java
+++ b/main/src/cgeo/geocaching/activity/AbstractActivity.java
@@ -2,7 +2,7 @@ package cgeo.geocaching.activity;
import cgeo.geocaching.cgBase;
import cgeo.geocaching.cgCache;
-import cgeo.geocaching.cgSettings;
+import cgeo.geocaching.Settings;
import cgeo.geocaching.cgeoapplication;
import android.app.Activity;
@@ -19,7 +19,6 @@ public abstract class AbstractActivity extends Activity implements IAbstractActi
protected cgeoapplication app = null;
protected Resources res = null;
- protected cgSettings settings = null;
protected cgBase base = null;
protected SharedPreferences prefs = null;
@@ -70,13 +69,8 @@ public abstract class AbstractActivity extends Activity implements IAbstractActi
// init
res = this.getResources();
app = (cgeoapplication) this.getApplication();
- prefs = getSharedPreferences(cgSettings.preferences, Context.MODE_PRIVATE);
- settings = new cgSettings(this, prefs);
- base = new cgBase(app, settings);
- }
-
- final public cgSettings getSettings() {
- return settings;
+ prefs = getSharedPreferences(Settings.preferences, Context.MODE_PRIVATE);
+ base = new cgBase(app);
}
public void addVisitMenu(Menu menu, cgCache cache) {
diff --git a/main/src/cgeo/geocaching/activity/AbstractListActivity.java b/main/src/cgeo/geocaching/activity/AbstractListActivity.java
index 25c188b..2e50f88 100644
--- a/main/src/cgeo/geocaching/activity/AbstractListActivity.java
+++ b/main/src/cgeo/geocaching/activity/AbstractListActivity.java
@@ -2,7 +2,7 @@ package cgeo.geocaching.activity;
import cgeo.geocaching.cgBase;
import cgeo.geocaching.cgCache;
-import cgeo.geocaching.cgSettings;
+import cgeo.geocaching.Settings;
import cgeo.geocaching.cgeoapplication;
import android.app.ListActivity;
@@ -20,7 +20,6 @@ public abstract class AbstractListActivity extends ListActivity implements
protected cgeoapplication app = null;
protected Resources res = null;
- protected cgSettings settings = null;
protected cgBase base = null;
protected SharedPreferences prefs = null;
@@ -67,19 +66,14 @@ public abstract class AbstractListActivity extends ListActivity implements
// init
res = this.getResources();
app = (cgeoapplication) this.getApplication();
- prefs = getSharedPreferences(cgSettings.preferences, Context.MODE_PRIVATE);
- settings = new cgSettings(this, prefs);
- base = new cgBase(app, settings);
+ prefs = getSharedPreferences(Settings.preferences, Context.MODE_PRIVATE);
+ base = new cgBase(app);
}
final public void setTitle(final String title) {
ActivityMixin.setTitle(this, title);
}
- final public cgSettings getSettings() {
- return settings;
- }
-
public void addVisitMenu(Menu menu, cgCache cache) {
ActivityMixin.addVisitMenu(this, menu, cache);
}
diff --git a/main/src/cgeo/geocaching/activity/ActivityMixin.java b/main/src/cgeo/geocaching/activity/ActivityMixin.java
index 558b51d..f720890 100644
--- a/main/src/cgeo/geocaching/activity/ActivityMixin.java
+++ b/main/src/cgeo/geocaching/activity/ActivityMixin.java
@@ -3,7 +3,7 @@ package cgeo.geocaching.activity;
import cgeo.geocaching.R;
import cgeo.geocaching.cgBase;
import cgeo.geocaching.cgCache;
-import cgeo.geocaching.cgSettings;
+import cgeo.geocaching.Settings;
import cgeo.geocaching.cgeo;
import org.apache.commons.lang3.StringUtils;
@@ -77,8 +77,7 @@ public final class ActivityMixin {
}
public final static void setTheme(final Activity activity) {
- cgSettings settings = new cgSettings(activity, activity.getSharedPreferences(cgSettings.preferences, Context.MODE_PRIVATE));
- if (settings.skin == 1) {
+ if (Settings.isLightSkin()) {
activity.setTheme(R.style.light);
} else {
activity.setTheme(R.style.dark);
@@ -129,12 +128,11 @@ public final class ActivityMixin {
if (!cache.supportsLogging()) {
return;
}
- cgSettings settings = activity.getSettings();
Resources res = ((Activity) activity).getResources();
- if (cgSettings.isLogin()) {
- if (settings.getLogOffline()) {
+ if (Settings.isLogin()) {
+ if (Settings.getLogOffline()) {
SubMenu logMenu = menu.addSubMenu(1, IAbstractActivity.MENU_LOG_VISIT_OFFLINE, 0, res.getString(R.string.cache_menu_visit_offline)).setIcon(MENU_ICON_LOG_VISIT);
- List<Integer> logTypes = cache.getPossibleLogTypes(settings);
+ List<Integer> logTypes = cache.getPossibleLogTypes();
for (Integer logType : logTypes) {
String label = cgBase.logTypes2.get(logType);
logMenu.add(1, IAbstractActivity.MENU_LOG_VISIT_OFFLINE + logType, 0, label);
diff --git a/main/src/cgeo/geocaching/activity/IAbstractActivity.java b/main/src/cgeo/geocaching/activity/IAbstractActivity.java
index dac97f3..85a112a 100644
--- a/main/src/cgeo/geocaching/activity/IAbstractActivity.java
+++ b/main/src/cgeo/geocaching/activity/IAbstractActivity.java
@@ -1,7 +1,6 @@
package cgeo.geocaching.activity;
import cgeo.geocaching.cgCache;
-import cgeo.geocaching.cgSettings;
import android.view.Menu;
import android.view.View;
@@ -26,11 +25,6 @@ public interface IAbstractActivity {
public void setTitle(final String title);
- /**
- * TODO: remove after settings are a singleton
- */
- public cgSettings getSettings();
-
void addVisitMenu(Menu menu, cgCache cache);
}
diff --git a/main/src/cgeo/geocaching/apps/AbstractApp.java b/main/src/cgeo/geocaching/apps/AbstractApp.java
index f917563..1a166c6 100644
--- a/main/src/cgeo/geocaching/apps/AbstractApp.java
+++ b/main/src/cgeo/geocaching/apps/AbstractApp.java
@@ -1,9 +1,7 @@
package cgeo.geocaching.apps;
-import cgeo.geocaching.cgSettings;
import cgeo.geocaching.utils.CollectionUtils;
-import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
@@ -74,9 +72,4 @@ public abstract class AbstractApp implements App {
public int getId() {
return getName().hashCode();
}
-
- protected static cgSettings getSettings(Activity activity) {
- return new cgSettings(activity,
- activity.getSharedPreferences(cgSettings.preferences, Context.MODE_PRIVATE));
- }
}
diff --git a/main/src/cgeo/geocaching/apps/AbstractLocusApp.java b/main/src/cgeo/geocaching/apps/AbstractLocusApp.java
index 26874c4..6213899 100644
--- a/main/src/cgeo/geocaching/apps/AbstractLocusApp.java
+++ b/main/src/cgeo/geocaching/apps/AbstractLocusApp.java
@@ -2,7 +2,7 @@ package cgeo.geocaching.apps;
import cgeo.geocaching.R;
import cgeo.geocaching.cgCache;
-import cgeo.geocaching.cgSettings;
+import cgeo.geocaching.Settings;
import cgeo.geocaching.cgWaypoint;
import cgeo.geocaching.enumerations.CacheSize;
import cgeo.geocaching.enumerations.CacheType;
@@ -105,7 +105,7 @@ public abstract class AbstractLocusApp extends AbstractApp {
}
// create one simple point with location
- Location loc = new Location(cgSettings.tag);
+ Location loc = new Location(Settings.tag);
loc.setLatitude(cache.coords.getLatitude());
loc.setLongitude(cache.coords.getLongitude());
@@ -183,7 +183,7 @@ public abstract class AbstractLocusApp extends AbstractApp {
}
// create one simple point with location
- Location loc = new Location(cgSettings.tag);
+ Location loc = new Location(Settings.tag);
loc.setLatitude(waypoint.coords.getLatitude());
loc.setLongitude(waypoint.coords.getLongitude());
diff --git a/main/src/cgeo/geocaching/apps/cache/GeneralAppsFactory.java b/main/src/cgeo/geocaching/apps/cache/GeneralAppsFactory.java
index eb581ca..ad72dc9 100644
--- a/main/src/cgeo/geocaching/apps/cache/GeneralAppsFactory.java
+++ b/main/src/cgeo/geocaching/apps/cache/GeneralAppsFactory.java
@@ -1,7 +1,7 @@
package cgeo.geocaching.apps.cache;
import cgeo.geocaching.cgCache;
-import cgeo.geocaching.cgSettings;
+import cgeo.geocaching.Settings;
import cgeo.geocaching.apps.AbstractAppFactory;
import org.apache.commons.lang3.ArrayUtils;
@@ -39,7 +39,7 @@ public final class GeneralAppsFactory extends AbstractAppFactory {
try {
return app.invoke(activity, cache);
} catch (Exception e) {
- Log.e(cgSettings.tag, "GeneralAppsFactory.onMenuItemSelected: " + e.toString());
+ Log.e(Settings.tag, "GeneralAppsFactory.onMenuItemSelected: " + e.toString());
}
}
return false;
diff --git a/main/src/cgeo/geocaching/apps/cache/navi/GoogleMapsApp.java b/main/src/cgeo/geocaching/apps/cache/navi/GoogleMapsApp.java
index b60a635..961773f 100644
--- a/main/src/cgeo/geocaching/apps/cache/navi/GoogleMapsApp.java
+++ b/main/src/cgeo/geocaching/apps/cache/navi/GoogleMapsApp.java
@@ -3,7 +3,7 @@ package cgeo.geocaching.apps.cache.navi;
import cgeo.geocaching.R;
import cgeo.geocaching.cgCache;
import cgeo.geocaching.cgGeo;
-import cgeo.geocaching.cgSettings;
+import cgeo.geocaching.Settings;
import cgeo.geocaching.cgWaypoint;
import cgeo.geocaching.activity.ActivityMixin;
import cgeo.geocaching.geopoint.Geopoint;
@@ -49,7 +49,7 @@ class GoogleMapsApp extends AbstractNavigationApp implements NavigationApp {
// nothing
}
- Log.i(cgSettings.tag, "cgBase.runExternalMap: No maps application available.");
+ Log.i(Settings.tag, "cgBase.runExternalMap: No maps application available.");
if (res != null) {
ActivityMixin.showToast(activity, res.getString(R.string.err_application_no));
diff --git a/main/src/cgeo/geocaching/apps/cache/navi/GoogleNavigationApp.java b/main/src/cgeo/geocaching/apps/cache/navi/GoogleNavigationApp.java
index 2cd2b22..44a4cbd 100644
--- a/main/src/cgeo/geocaching/apps/cache/navi/GoogleNavigationApp.java
+++ b/main/src/cgeo/geocaching/apps/cache/navi/GoogleNavigationApp.java
@@ -3,7 +3,7 @@ package cgeo.geocaching.apps.cache.navi;
import cgeo.geocaching.R;
import cgeo.geocaching.cgCache;
import cgeo.geocaching.cgGeo;
-import cgeo.geocaching.cgSettings;
+import cgeo.geocaching.Settings;
import cgeo.geocaching.cgWaypoint;
import cgeo.geocaching.activity.ActivityMixin;
import cgeo.geocaching.geopoint.Geopoint;
@@ -61,10 +61,8 @@ class GoogleNavigationApp extends AbstractNavigationApp implements
private static boolean navigateToCoordinates(cgGeo geo, Activity activity, final Geopoint coords) {
final Geopoint coordsNow = geo == null ? null : geo.coordsNow;
- cgSettings settings = getSettings(activity);
-
// Google Navigation
- if (settings.useGNavigation == 1) {
+ if (Settings.isUseGoogleNavigation()) {
try {
activity.startActivity(new Intent(Intent.ACTION_VIEW, Uri
.parse("google.navigation:ll=" + coords.getLatitude() + ","
@@ -94,7 +92,7 @@ class GoogleNavigationApp extends AbstractNavigationApp implements
// nothing
}
- Log.i(cgSettings.tag,
+ Log.i(Settings.tag,
"cgBase.runNavigation: No navigation application available.");
return false;
}
diff --git a/main/src/cgeo/geocaching/apps/cache/navi/InternalMap.java b/main/src/cgeo/geocaching/apps/cache/navi/InternalMap.java
index e5069c5..57e67a5 100644
--- a/main/src/cgeo/geocaching/apps/cache/navi/InternalMap.java
+++ b/main/src/cgeo/geocaching/apps/cache/navi/InternalMap.java
@@ -3,7 +3,7 @@ package cgeo.geocaching.apps.cache.navi;
import cgeo.geocaching.R;
import cgeo.geocaching.cgCache;
import cgeo.geocaching.cgGeo;
-import cgeo.geocaching.cgSettings;
+import cgeo.geocaching.Settings;
import cgeo.geocaching.cgWaypoint;
import cgeo.geocaching.enumerations.WaypointType;
import cgeo.geocaching.geopoint.Geopoint;
@@ -25,8 +25,7 @@ class InternalMap extends AbstractInternalMap implements
public boolean invoke(cgGeo geo, Activity activity, Resources res,
cgCache cache,
final UUID searchId, cgWaypoint waypoint, final Geopoint coords) {
- cgSettings settings = getSettings(activity);
- Intent mapIntent = new Intent(activity, settings.getMapFactory().getMapClass());
+ Intent mapIntent = new Intent(activity, Settings.getMapFactory().getMapClass());
if (cache != null) {
mapIntent.putExtra("detail", false);
mapIntent.putExtra("geocode", cache.geocode);
diff --git a/main/src/cgeo/geocaching/apps/cache/navi/NavigationAppFactory.java b/main/src/cgeo/geocaching/apps/cache/navi/NavigationAppFactory.java
index 1a46200..15ee464 100644
--- a/main/src/cgeo/geocaching/apps/cache/navi/NavigationAppFactory.java
+++ b/main/src/cgeo/geocaching/apps/cache/navi/NavigationAppFactory.java
@@ -2,7 +2,7 @@ package cgeo.geocaching.apps.cache.navi;
import cgeo.geocaching.cgCache;
import cgeo.geocaching.cgGeo;
-import cgeo.geocaching.cgSettings;
+import cgeo.geocaching.Settings;
import cgeo.geocaching.cgWaypoint;
import cgeo.geocaching.apps.AbstractAppFactory;
import cgeo.geocaching.geopoint.Geopoint;
@@ -56,7 +56,7 @@ public final class NavigationAppFactory extends AbstractAppFactory {
return app.invoke(geo, activity, res, cache,
searchId, waypoint, destination);
} catch (Exception e) {
- Log.e(cgSettings.tag, "NavigationAppFactory.onMenuItemSelected: " + e.toString());
+ Log.e(Settings.tag, "NavigationAppFactory.onMenuItemSelected: " + e.toString());
}
}
return false;
diff --git a/main/src/cgeo/geocaching/apps/cachelist/CacheListAppFactory.java b/main/src/cgeo/geocaching/apps/cachelist/CacheListAppFactory.java
index 5359719..5b3dc9a 100644
--- a/main/src/cgeo/geocaching/apps/cachelist/CacheListAppFactory.java
+++ b/main/src/cgeo/geocaching/apps/cachelist/CacheListAppFactory.java
@@ -3,7 +3,7 @@ package cgeo.geocaching.apps.cachelist;
import cgeo.geocaching.R;
import cgeo.geocaching.cgCache;
import cgeo.geocaching.cgGeo;
-import cgeo.geocaching.cgSettings;
+import cgeo.geocaching.Settings;
import cgeo.geocaching.apps.AbstractAppFactory;
import org.apache.commons.lang3.ArrayUtils;
@@ -70,7 +70,7 @@ public final class CacheListAppFactory extends AbstractAppFactory {
try {
return app.invoke(geo, caches, activity, res, searchId);
} catch (Exception e) {
- Log.e(cgSettings.tag, "CacheListAppFactory.onMenuItemSelected: " + e.toString());
+ Log.e(Settings.tag, "CacheListAppFactory.onMenuItemSelected: " + e.toString());
}
}
return false;
diff --git a/main/src/cgeo/geocaching/apps/cachelist/InternalCacheListMap.java b/main/src/cgeo/geocaching/apps/cachelist/InternalCacheListMap.java
index 7eec0f8..75997e0 100644
--- a/main/src/cgeo/geocaching/apps/cachelist/InternalCacheListMap.java
+++ b/main/src/cgeo/geocaching/apps/cachelist/InternalCacheListMap.java
@@ -3,6 +3,7 @@ package cgeo.geocaching.apps.cachelist;
import cgeo.geocaching.R;
import cgeo.geocaching.cgCache;
import cgeo.geocaching.cgGeo;
+import cgeo.geocaching.Settings;
import cgeo.geocaching.apps.AbstractApp;
import android.app.Activity;
@@ -26,7 +27,7 @@ class InternalCacheListMap extends AbstractApp implements CacheListApp {
@Override
public boolean invoke(cgGeo geo, List<cgCache> caches, Activity activity, Resources res, final UUID searchId) {
- Intent mapIntent = new Intent(activity, getSettings(activity).getMapFactory()
+ Intent mapIntent = new Intent(activity, Settings.getMapFactory()
.getMapClass());
mapIntent.putExtra("detail", false); // this is the main difference to the activity for a single point
mapIntent.putExtra("searchid", searchId.toString());
diff --git a/main/src/cgeo/geocaching/backup/CentralBackupAgent.java b/main/src/cgeo/geocaching/backup/CentralBackupAgent.java
index 742eb0c..28b9e4b 100644
--- a/main/src/cgeo/geocaching/backup/CentralBackupAgent.java
+++ b/main/src/cgeo/geocaching/backup/CentralBackupAgent.java
@@ -1,6 +1,6 @@
package cgeo.geocaching.backup;
-import cgeo.geocaching.cgSettings;
+import cgeo.geocaching.Settings;
import android.app.backup.BackupAgentHelper;
import android.app.backup.SharedPreferencesBackupHelper;
@@ -11,7 +11,7 @@ public class CentralBackupAgent extends BackupAgentHelper {
@Override
public void onCreate() {
- SharedPreferencesBackupHelper helper = new SharedPreferencesBackupHelper(this, cgSettings.preferences);
+ SharedPreferencesBackupHelper helper = new SharedPreferencesBackupHelper(this, Settings.preferences);
addHelper(PREFS_BACKUP_KEY, helper);
}
diff --git a/main/src/cgeo/geocaching/cgBase.java b/main/src/cgeo/geocaching/cgBase.java
index cc51992..a9c4e7d 100644
--- a/main/src/cgeo/geocaching/cgBase.java
+++ b/main/src/cgeo/geocaching/cgBase.java
@@ -94,7 +94,7 @@ import javax.net.ssl.X509TrustManager;
/**
* @author bananeweizen
- *
+ *
*/
public class cgBase {
@@ -189,7 +189,6 @@ public class cgBase {
public static final double rad2deg = 180 / Math.PI;
public static final float erad = 6371.0f;
private cgeoapplication app = null;
- private cgSettings settings = null;
public String version = null;
/**
@@ -225,7 +224,7 @@ public class cgBase {
private static final int NB_DOWNLOAD_RETRIES = 4;
- public cgBase(cgeoapplication appIn, cgSettings settingsIn) {
+ public cgBase(cgeoapplication appIn) {
context = appIn.getBaseContext();
res = appIn.getBaseContext().getResources();
@@ -361,18 +360,17 @@ public class cgBase {
// init
app = appIn;
- settings = settingsIn;
try {
final PackageManager manager = app.getPackageManager();
final PackageInfo info = manager.getPackageInfo(app.getPackageName(), 0);
version = info.versionName;
} catch (PackageManager.NameNotFoundException e) {
- Log.e(cgSettings.tag, "unable to get version information", e);
+ Log.e(Settings.tag, "unable to get version information", e);
version = null;
}
- if (cgSettings.asBrowser()) {
+ if (Settings.isBrowser()) {
final long rndBrowser = Math.round(Math.random() * 6);
switch ((int) rndBrowser) {
case 0:
@@ -500,7 +498,7 @@ public class cgBase {
String[] viewstates = null;
- final ImmutablePair<String, String> loginStart = settings.getLogin();
+ final ImmutablePair<String, String> loginStart = Settings.getLogin();
if (loginStart == null) {
return -3; // no login information stored
@@ -510,7 +508,7 @@ public class cgBase {
loginData = getResponseData(loginResponse);
if (StringUtils.isNotBlank(loginData)) {
if (checkLogin(loginData)) {
- Log.i(cgSettings.tag, "Already logged in Geocaching.com as " + loginStart.left);
+ Log.i(Settings.tag, "Already logged in Geocaching.com as " + loginStart.left);
switchToEnglish(viewstates);
@@ -520,18 +518,18 @@ public class cgBase {
viewstates = getViewstates(loginData);
if (isEmpty(viewstates)) {
- Log.e(cgSettings.tag, "cgeoBase.login: Failed to find viewstates");
+ Log.e(Settings.tag, "cgeoBase.login: Failed to find viewstates");
return -1; // no viewstates
}
} else {
- Log.e(cgSettings.tag, "cgeoBase.login: Failed to retrieve login page (1st)");
+ Log.e(Settings.tag, "cgeoBase.login: Failed to retrieve login page (1st)");
return -2; // no loginpage
}
- final ImmutablePair<String, String> login = settings.getLogin();
+ final ImmutablePair<String, String> login = Settings.getLogin();
if (login == null || StringUtils.isEmpty(login.left) || StringUtils.isEmpty(login.right)) {
- Log.e(cgSettings.tag, "cgeoBase.login: No login information stored");
+ Log.e(Settings.tag, "cgeoBase.login: No login information stored");
return -3;
}
@@ -552,24 +550,24 @@ public class cgBase {
if (StringUtils.isNotBlank(loginData)) {
if (checkLogin(loginData)) {
- Log.i(cgSettings.tag, "Successfully logged in Geocaching.com as " + login.left);
+ Log.i(Settings.tag, "Successfully logged in Geocaching.com as " + login.left);
switchToEnglish(getViewstates(loginData));
return 1; // logged in
} else {
if (loginData.contains("Your username/password combination does not match.")) {
- Log.i(cgSettings.tag, "Failed to log in Geocaching.com as " + login.left + " because of wrong username/password");
+ Log.i(Settings.tag, "Failed to log in Geocaching.com as " + login.left + " because of wrong username/password");
return -6; // wrong login
} else {
- Log.i(cgSettings.tag, "Failed to log in Geocaching.com as " + login.left + " for some unknown reason");
+ Log.i(Settings.tag, "Failed to log in Geocaching.com as " + login.left + " for some unknown reason");
return -4; // can't login
}
}
} else {
- Log.e(cgSettings.tag, "cgeoBase.login: Failed to retrieve login page (2nd)");
+ Log.e(Settings.tag, "cgeoBase.login: Failed to retrieve login page (2nd)");
return -5; // no login page
}
@@ -586,7 +584,7 @@ public class cgBase {
public static boolean checkLogin(String page) {
if (StringUtils.isBlank(page)) {
- Log.e(cgSettings.tag, "cgeoBase.checkLogin: No page given");
+ Log.e(Settings.tag, "cgeoBase.checkLogin: No page given");
return false;
}
@@ -617,7 +615,7 @@ public class cgBase {
public cgCacheWrap parseSearch(cgSearchThread thread, String url, String page, boolean showCaptcha) {
if (StringUtils.isBlank(page)) {
- Log.e(cgSettings.tag, "cgeoBase.parseSearch: No page given");
+ Log.e(Settings.tag, "cgeoBase.parseSearch: No page given");
return null;
}
@@ -668,7 +666,7 @@ public class cgBase {
}
} catch (Exception e) {
// failed to parse recaptcha challenge
- Log.w(cgSettings.tag, "cgeoBase.parseSearch: Failed to parse recaptcha challenge");
+ Log.w(Settings.tag, "cgeoBase.parseSearch: Failed to parse recaptcha challenge");
}
if (thread != null && StringUtils.isNotBlank(recaptchaChallenge)) {
@@ -684,7 +682,7 @@ public class cgBase {
int startPos = page.indexOf("<div id=\"ctl00_ContentBody_ResultsPanel\"");
if (startPos == -1) {
- Log.e(cgSettings.tag, "cgeoBase.parseSearch: ID \"ctl00_ContentBody_dlResults\" not found on page");
+ Log.e(Settings.tag, "cgeoBase.parseSearch: ID \"ctl00_ContentBody_dlResults\" not found on page");
return null;
}
@@ -693,7 +691,7 @@ public class cgBase {
startPos = page.indexOf(">");
int endPos = page.indexOf("ctl00_ContentBody_UnitTxt");
if (startPos == -1 || endPos == -1) {
- Log.e(cgSettings.tag, "cgeoBase.parseSearch: ID \"ctl00_ContentBody_UnitTxt\" not found on page");
+ Log.e(Settings.tag, "cgeoBase.parseSearch: ID \"ctl00_ContentBody_UnitTxt\" not found on page");
return null;
}
@@ -744,10 +742,10 @@ public class cgBase {
}
} catch (Exception e) {
// failed to parse GUID and/or Disabled
- Log.w(cgSettings.tag, "cgeoBase.parseSearch: Failed to parse GUID and/or Disabled data");
+ Log.w(Settings.tag, "cgeoBase.parseSearch: Failed to parse GUID and/or Disabled data");
}
- if (settings.excludeDisabled == 1 && (cache.disabled || cache.archived)) {
+ if (Settings.isExcludeDisabledCaches() && (cache.disabled || cache.archived)) {
// skip disabled and archived caches
cache = null;
continue;
@@ -765,7 +763,7 @@ public class cgBase {
}
} catch (Exception e) {
// failed to parse code
- Log.w(cgSettings.tag, "cgeoBase.parseSearch: Failed to parse cache code");
+ Log.w(Settings.tag, "cgeoBase.parseSearch: Failed to parse cache code");
}
// cache type
@@ -778,11 +776,11 @@ public class cgBase {
}
} catch (Exception e) {
// failed to parse type
- Log.w(cgSettings.tag, "cgeoBase.parseSearch: Failed to parse cache type");
+ Log.w(Settings.tag, "cgeoBase.parseSearch: Failed to parse cache type");
}
// cache direction - image
- if (settings.getLoadDirImg())
+ if (Settings.getLoadDirImg())
{
try {
final Matcher matcherDirection = patternDirection.matcher(row);
@@ -793,7 +791,7 @@ public class cgBase {
}
} catch (Exception e) {
// failed to parse direction image
- Log.w(cgSettings.tag, "cgeoBase.parseSearch: Failed to parse cache direction image");
+ Log.w(Settings.tag, "cgeoBase.parseSearch: Failed to parse cache direction image");
}
}
@@ -808,7 +806,7 @@ public class cgBase {
}
} catch (Exception e) {
// failed to parse inventory
- Log.w(cgSettings.tag, "cgeoBase.parseSearch: Failed to parse cache inventory (1)");
+ Log.w(Settings.tag, "cgeoBase.parseSearch: Failed to parse cache inventory (1)");
}
if (StringUtils.isNotBlank(inventoryPre)) {
@@ -828,7 +826,7 @@ public class cgBase {
}
} catch (Exception e) {
// failed to parse cache inventory info
- Log.w(cgSettings.tag, "cgeoBase.parseSearch: Failed to parse cache inventory info");
+ Log.w(Settings.tag, "cgeoBase.parseSearch: Failed to parse cache inventory info");
}
}
@@ -852,7 +850,7 @@ public class cgBase {
}
} catch (Exception e) {
// failed to parse cache id
- Log.w(cgSettings.tag, "cgeoBase.parseSearch: Failed to parse cache id");
+ Log.w(Settings.tag, "cgeoBase.parseSearch: Failed to parse cache id");
}
// favourite count
@@ -865,7 +863,7 @@ public class cgBase {
}
} catch (Exception e) {
// failed to parse favourite count
- Log.w(cgSettings.tag, "cgeoBase.parseSearch: Failed to parse favourite count");
+ Log.w(Settings.tag, "cgeoBase.parseSearch: Failed to parse favourite count");
}
if (cache.nameSp == null) {
@@ -890,7 +888,7 @@ public class cgBase {
}
} catch (Exception e) {
// failed to parse cache count
- Log.w(cgSettings.tag, "cgeoBase.parseSearch: Failed to parse cache count");
+ Log.w(Settings.tag, "cgeoBase.parseSearch: Failed to parse cache count");
}
if (thread != null && recaptchaChallenge != null) {
@@ -902,7 +900,7 @@ public class cgBase {
}
if (cids.size() > 0 && (recaptchaChallenge == null || StringUtils.isNotBlank(recaptchaText))) {
- Log.i(cgSettings.tag, "Trying to get .loc for " + cids.size() + " caches");
+ Log.i(Settings.tag, "Trying to get .loc for " + cids.size() + " caches");
try {
// get coordinates for parsed caches
@@ -932,7 +930,7 @@ public class cgBase {
if (StringUtils.isNotBlank(coordinates)) {
if (coordinates.contains("You have not agreed to the license agreement. The license agreement is required before you can start downloading GPX or LOC files from Geocaching.com")) {
- Log.i(cgSettings.tag, "User has not agreed to the license agreement. Can\'t download .loc file.");
+ Log.i(Settings.tag, "User has not agreed to the license agreement. Can\'t download .loc file.");
caches.error = errorRetrieve.get(-7);
@@ -942,12 +940,12 @@ public class cgBase {
LocParser.parseLoc(caches, coordinates);
} catch (Exception e) {
- Log.e(cgSettings.tag, "cgBase.parseSearch.CIDs: " + e.toString());
+ Log.e(Settings.tag, "cgBase.parseSearch.CIDs: " + e.toString());
}
}
// get direction images
- if (settings.getLoadDirImg())
+ if (Settings.getLoadDirImg())
{
for (cgCache oneCache : caches.cacheList) {
if (oneCache.coords == null && oneCache.directionImg != null) {
@@ -958,7 +956,7 @@ public class cgBase {
// get ratings
if (guids.size() > 0) {
- Log.i(cgSettings.tag, "Trying to get ratings for " + cids.size() + " caches");
+ Log.i(Settings.tag, "Trying to get ratings for " + cids.size() + " caches");
try {
final Map<String, cgRating> ratings = GCVote.getRating(guids, null);
@@ -976,7 +974,7 @@ public class cgBase {
}
}
} catch (Exception e) {
- Log.e(cgSettings.tag, "cgBase.parseSearch.GCvote: " + e.toString());
+ Log.e(Settings.tag, "cgBase.parseSearch.GCvote: " + e.toString());
}
}
@@ -985,7 +983,7 @@ public class cgBase {
public static cgCacheWrap parseMapJSON(final String uri, final String data) {
if (StringUtils.isEmpty(data)) {
- Log.e(cgSettings.tag, "cgeoBase.parseMapJSON: No page given");
+ Log.e(Settings.tag, "cgeoBase.parseMapJSON: No page given");
return null;
}
@@ -997,7 +995,7 @@ public class cgBase {
final String json = yoDawg.getString("d");
if (StringUtils.isBlank(json)) {
- Log.e(cgSettings.tag, "cgeoBase.parseMapJSON: No JSON inside JSON");
+ Log.e(Settings.tag, "cgeoBase.parseMapJSON: No JSON inside JSON");
return null;
}
@@ -1055,12 +1053,12 @@ public class cgBase {
}
}
} else {
- Log.w(cgSettings.tag, "There are no caches in viewport");
+ Log.w(Settings.tag, "There are no caches in viewport");
}
caches.totalCnt = caches.cacheList.size();
}
} catch (Exception e) {
- Log.e(cgSettings.tag, "cgBase.parseMapJSON", e);
+ Log.e(Settings.tag, "cgBase.parseMapJSON", e);
}
return caches;
@@ -1068,7 +1066,7 @@ public class cgBase {
public cgCacheWrap parseCache(String page, int reason) {
if (StringUtils.isBlank(page)) {
- Log.e(cgSettings.tag, "cgeoBase.parseCache: No page given");
+ Log.e(Settings.tag, "cgeoBase.parseCache: No page given");
return null;
}
@@ -1114,7 +1112,7 @@ public class cgBase {
// URLDecoder.decode() neccessary here ?
cache.ownerReal = URLDecoder.decode(BaseUtils.getMatch(page, Constants.PATTERN_OWNERREAL, 1, cache.ownerReal));
- final String username = settings.getUsername();
+ final String username = Settings.getUsername();
if (cache.ownerReal != null && username != null && cache.ownerReal.equalsIgnoreCase(username)) {
cache.own = true;
}
@@ -1124,7 +1122,7 @@ public class cgBase {
pos = tableInside.indexOf("id=\"cacheDetails\"");
if (pos == -1) {
- Log.e(cgSettings.tag, "cgeoBase.parseCache: ID \"cacheDetails\" not found on page");
+ Log.e(Settings.tag, "cgeoBase.parseCache: ID \"cacheDetails\" not found on page");
return null;
}
@@ -1132,7 +1130,7 @@ public class cgBase {
pos = tableInside.indexOf("<div class=\"CacheInformationTable\"");
if (pos == -1) {
- Log.e(cgSettings.tag, "cgeoBase.parseCache: ID \"CacheInformationTable\" not found on page");
+ Log.e(Settings.tag, "cgeoBase.parseCache: ID \"CacheInformationTable\" not found on page");
return null;
}
@@ -1159,7 +1157,7 @@ public class cgBase {
}
} catch (Exception e) {
// failed to parse owner
- Log.w(cgSettings.tag, "cgeoBase.parseCache: Failed to parse cache owner");
+ Log.w(Settings.tag, "cgeoBase.parseCache: Failed to parse cache owner");
}
// hidden
@@ -1170,7 +1168,7 @@ public class cgBase {
}
} catch (ParseException e) {
// failed to parse cache hidden date
- Log.w(cgSettings.tag, "cgeoBase.parseCache: Failed to parse cache hidden date");
+ Log.w(Settings.tag, "cgeoBase.parseCache: Failed to parse cache hidden date");
}
if (cache.hidden == null) {
@@ -1182,7 +1180,7 @@ public class cgBase {
}
} catch (ParseException e) {
// failed to parse cache event date
- Log.w(cgSettings.tag, "cgeoBase.parseCache: Failed to parse cache event date");
+ Log.w(Settings.tag, "cgeoBase.parseCache: Failed to parse cache event date");
}
}
@@ -1194,7 +1192,7 @@ public class cgBase {
}
} catch (Exception e) {
// failed to parse favourite count
- Log.w(cgSettings.tag, "cgeoBase.parseCache: Failed to parse favourite count");
+ Log.w(Settings.tag, "cgeoBase.parseCache: Failed to parse favourite count");
}
// cache size
@@ -1212,7 +1210,7 @@ public class cgBase {
}
} catch (Exception e) {
// failed to parse type
- Log.w(cgSettings.tag, "cgeoBase.parseCache: Failed to parse cache type");
+ Log.w(Settings.tag, "cgeoBase.parseCache: Failed to parse cache type");
}
// on watchlist
@@ -1221,7 +1219,7 @@ public class cgBase {
cache.onWatchlist = matcher.find();
} catch (Exception e) {
// failed to parse watchlist state
- Log.w(cgSettings.tag, "cgeoBase.parseCache: Failed to parse watchlist state");
+ Log.w(Settings.tag, "cgeoBase.parseCache: Failed to parse watchlist state");
}
// latitude and logitude
@@ -1246,34 +1244,10 @@ public class cgBase {
}
} catch (Exception e) {
// failed to parse hint
- Log.w(cgSettings.tag, "cgeoBase.parseCache: Failed to parse cache hint");
+ Log.w(Settings.tag, "cgeoBase.parseCache: Failed to parse cache hint");
}
checkFields(cache);
- /*
- * // short info debug
- * Log.d(cgSettings.tag, "gc-code: " + cache.geocode);
- * Log.d(cgSettings.tag, "id: " + cache.cacheid);
- * Log.d(cgSettings.tag, "guid: " + cache.guid);
- * Log.d(cgSettings.tag, "name: " + cache.name);
- * Log.d(cgSettings.tag, "terrain: " + cache.terrain);
- * Log.d(cgSettings.tag, "difficulty: " + cache.difficulty);
- * Log.d(cgSettings.tag, "owner: " + cache.owner);
- * Log.d(cgSettings.tag, "owner (real): " + cache.ownerReal);
- * Log.d(cgSettings.tag, "hidden: " + dateOutShort.format(cache.hidden));
- * Log.d(cgSettings.tag, "favorite: " + cache.favouriteCnt);
- * Log.d(cgSettings.tag, "size: " + cache.size);
- * if (cache.found) {
- * Log.d(cgSettings.tag, "found!");
- * } else {
- * Log.d(cgSettings.tag, "not found");
- * }
- * Log.d(cgSettings.tag, "type: " + cache.type);
- * Log.d(cgSettings.tag, "latitude: " + String.format("%.6f", cache.latitude));
- * Log.d(cgSettings.tag, "longitude: " + String.format("%.6f", cache.longitude));
- * Log.d(cgSettings.tag, "location: " + cache.location);
- * Log.d(cgSettings.tag, "hint: " + cache.hint);
- */
// cache personal note
cache.personalNote = BaseUtils.getMatch(page, Constants.PATTERN_PERSONALNOTE, 1, cache.personalNote);
@@ -1314,7 +1288,7 @@ public class cgBase {
}
} catch (Exception e) {
// failed to parse cache attributes
- Log.w(cgSettings.tag, "cgeoBase.parseCache: Failed to parse cache attributes");
+ Log.w(Settings.tag, "cgeoBase.parseCache: Failed to parse cache attributes");
}
// cache spoilers
@@ -1342,7 +1316,7 @@ public class cgBase {
}
} catch (Exception e) {
// failed to parse cache spoilers
- Log.w(cgSettings.tag, "cgeoBase.parseCache: Failed to parse cache spoilers");
+ Log.w(Settings.tag, "cgeoBase.parseCache: Failed to parse cache spoilers");
}
// cache inventory
@@ -1376,7 +1350,7 @@ public class cgBase {
}
} catch (Exception e) {
// failed to parse cache inventory
- Log.w(cgSettings.tag, "cgeoBase.parseCache: Failed to parse cache inventory (2)");
+ Log.w(Settings.tag, "cgeoBase.parseCache: Failed to parse cache inventory (2)");
}
// cache logs counts
@@ -1404,7 +1378,7 @@ public class cgBase {
} catch (Exception e)
{
// failed to parse logs
- Log.w(cgSettings.tag, "cgeoBase.parseCache: Failed to parse cache log count");
+ Log.w(Settings.tag, "cgeoBase.parseCache: Failed to parse cache log count");
}
// cache logs
@@ -1453,7 +1427,7 @@ public class cgBase {
}
} catch (Exception e) {
// failed to parse type
- Log.w(cgSettings.tag, "cgeoBase.parseCache: Failed to parse waypoint type");
+ Log.w(Settings.tag, "cgeoBase.parseCache: Failed to parse waypoint type");
}
// waypoint prefix
@@ -1464,7 +1438,7 @@ public class cgBase {
}
} catch (Exception e) {
// failed to parse prefix
- Log.w(cgSettings.tag, "cgeoBase.parseCache: Failed to parse waypoint prefix");
+ Log.w(Settings.tag, "cgeoBase.parseCache: Failed to parse waypoint prefix");
}
// waypoint lookup
@@ -1475,7 +1449,7 @@ public class cgBase {
}
} catch (Exception e) {
// failed to parse lookup
- Log.w(cgSettings.tag, "cgeoBase.parseCache: Failed to parse waypoint lookup");
+ Log.w(Settings.tag, "cgeoBase.parseCache: Failed to parse waypoint lookup");
}
// waypoint name
@@ -1494,7 +1468,7 @@ public class cgBase {
}
} catch (Exception e) {
// failed to parse name
- Log.w(cgSettings.tag, "cgeoBase.parseCache: Failed to parse waypoint name");
+ Log.w(Settings.tag, "cgeoBase.parseCache: Failed to parse waypoint name");
}
// waypoint latitude and logitude
@@ -1509,7 +1483,7 @@ public class cgBase {
}
} catch (Exception e) {
// failed to parse latitude and/or longitude
- Log.w(cgSettings.tag, "cgeoBase.parseCache: Failed to parse waypoint coordinates");
+ Log.w(Settings.tag, "cgeoBase.parseCache: Failed to parse waypoint coordinates");
}
j++;
@@ -1525,7 +1499,7 @@ public class cgBase {
}
} catch (Exception e) {
// failed to parse note
- Log.w(cgSettings.tag, "cgeoBase.parseCache: Failed to parse waypoint note");
+ Log.w(Settings.tag, "cgeoBase.parseCache: Failed to parse waypoint note");
}
if (cache.waypoints == null) {
@@ -1566,7 +1540,7 @@ public class cgBase {
private void loadLogsFromDetails(final String page, final cgCache cache) {
final Matcher userTokenMatcher = patternUserToken.matcher(page);
if (!userTokenMatcher.find()) {
- Log.e(cgSettings.tag, "cgBase.loadLogsFromDetails: unable to extract userToken");
+ Log.e(Settings.tag, "cgBase.loadLogsFromDetails: unable to extract userToken");
return;
}
@@ -1578,19 +1552,19 @@ public class cgBase {
params.put("decrypt", "true");
final HttpResponse response = request("http://www.geocaching.com/seek/geocache.logbook", params, false, false, false);
if (response == null) {
- Log.e(cgSettings.tag, "cgBase.loadLogsFromDetails: cannot log logs, response is null");
+ Log.e(Settings.tag, "cgBase.loadLogsFromDetails: cannot log logs, response is null");
return;
}
final int statusCode = response.getStatusLine().getStatusCode();
if (statusCode != 200) {
- Log.e(cgSettings.tag, "cgBase.loadLogsFromDetails: error " + statusCode + " when requesting log information");
+ Log.e(Settings.tag, "cgBase.loadLogsFromDetails: error " + statusCode + " when requesting log information");
return;
}
try {
final JSONObject resp = new JSONObject(cgBase.getResponseData(response));
if (!resp.getString("status").equals("success")) {
- Log.e(cgSettings.tag, "cgBase.loadLogsFromDetails: status is " + resp.getString("status"));
+ Log.e(Settings.tag, "cgBase.loadLogsFromDetails: status is " + resp.getString("status"));
return;
}
@@ -1612,7 +1586,7 @@ public class cgBase {
try {
logDone.date = parseGcCustomDate(entry.getString("Visited")).getTime();
} catch (ParseException e) {
- Log.e(cgSettings.tag, "cgBase.loadLogsFromDetails: failed to parse log date.");
+ Log.e(Settings.tag, "cgBase.loadLogsFromDetails: failed to parse log date.");
}
logDone.author = entry.getString("UserName");
@@ -1638,49 +1612,49 @@ public class cgBase {
}
} catch (JSONException e) {
// failed to parse logs
- Log.w(cgSettings.tag, "cgBase.loadLogsFromDetails: Failed to parse cache logs", e);
+ Log.w(Settings.tag, "cgBase.loadLogsFromDetails: Failed to parse cache logs", e);
}
}
private static void checkFields(cgCache cache) {
if (StringUtils.isBlank(cache.geocode)) {
- Log.w(cgSettings.tag, "cgBase.loadLogsFromDetails: geo code not parsed correctly");
+ Log.w(Settings.tag, "cgBase.loadLogsFromDetails: geo code not parsed correctly");
}
if (StringUtils.isBlank(cache.name)) {
- Log.w(cgSettings.tag, "name not parsed correctly");
+ Log.w(Settings.tag, "name not parsed correctly");
}
if (StringUtils.isBlank(cache.guid)) {
- Log.w(cgSettings.tag, "guid not parsed correctly");
+ Log.w(Settings.tag, "guid not parsed correctly");
}
if (cache.terrain == null || cache.terrain == 0.0) {
- Log.w(cgSettings.tag, "terrain not parsed correctly");
+ Log.w(Settings.tag, "terrain not parsed correctly");
}
if (cache.difficulty == null || cache.difficulty == 0.0) {
- Log.w(cgSettings.tag, "difficulty not parsed correctly");
+ Log.w(Settings.tag, "difficulty not parsed correctly");
}
if (StringUtils.isBlank(cache.owner)) {
- Log.w(cgSettings.tag, "owner not parsed correctly");
+ Log.w(Settings.tag, "owner not parsed correctly");
}
if (StringUtils.isBlank(cache.ownerReal)) {
- Log.w(cgSettings.tag, "owner real not parsed correctly");
+ Log.w(Settings.tag, "owner real not parsed correctly");
}
if (cache.hidden == null) {
- Log.w(cgSettings.tag, "hidden not parsed correctly");
+ Log.w(Settings.tag, "hidden not parsed correctly");
}
if (cache.favouriteCnt == null) {
- Log.w(cgSettings.tag, "favoriteCount not parsed correctly");
+ Log.w(Settings.tag, "favoriteCount not parsed correctly");
}
if (cache.size == null) {
- Log.w(cgSettings.tag, "size not parsed correctly");
+ Log.w(Settings.tag, "size not parsed correctly");
}
if (StringUtils.isBlank(cache.type)) {
- Log.w(cgSettings.tag, "type not parsed correctly");
+ Log.w(Settings.tag, "type not parsed correctly");
}
if (cache.coords == null) {
- Log.w(cgSettings.tag, "coordinates not parsed correctly");
+ Log.w(Settings.tag, "coordinates not parsed correctly");
}
if (StringUtils.isBlank(cache.location)) {
- Log.w(cgSettings.tag, "location not parsed correctly");
+ Log.w(Settings.tag, "location not parsed correctly");
}
}
@@ -1694,13 +1668,11 @@ public class cgBase {
final String trimmed = input.trim();
- if (null != settings
- //&& null != settings.getGcCustomDate()
- && gcCustomDateFormats.containsKey(settings.getGcCustomDate()))
+ if (gcCustomDateFormats.containsKey(Settings.getGcCustomDate()))
{
try
{
- return gcCustomDateFormats.get(settings.getGcCustomDate()).parse(trimmed);
+ return gcCustomDateFormats.get(Settings.getGcCustomDate()).parse(trimmed);
} catch (ParseException e) {
}
}
@@ -1722,7 +1694,7 @@ public class cgBase {
final String result = getResponseData(request("http://www.geocaching.com/account/ManagePreferences.aspx", null, false, false, false));
if (null == result) {
- Log.w(cgSettings.tag, "cgeoBase.detectGcCustomDate: result is null");
+ Log.w(Settings.tag, "cgeoBase.detectGcCustomDate: result is null");
return;
}
@@ -1731,13 +1703,13 @@ public class cgBase {
if (matcher.find())
{
- settings.setGcCustomDate(matcher.group(1));
+ Settings.setGcCustomDate(matcher.group(1));
}
}
public cgTrackable parseTrackable(String page) {
if (StringUtils.isBlank(page)) {
- Log.e(cgSettings.tag, "cgeoBase.parseTrackable: No page given");
+ Log.e(Settings.tag, "cgeoBase.parseTrackable: No page given");
return null;
}
@@ -1751,7 +1723,7 @@ public class cgBase {
}
} catch (Exception e) {
// failed to parse trackable geocode
- Log.w(cgSettings.tag, "cgeoBase.parseTrackable: Failed to parse trackable geocode");
+ Log.w(Settings.tag, "cgeoBase.parseTrackable: Failed to parse trackable geocode");
}
// trackable id
@@ -1762,7 +1734,7 @@ public class cgBase {
}
} catch (Exception e) {
// failed to parse trackable id
- Log.w(cgSettings.tag, "cgeoBase.parseTrackable: Failed to parse trackable id");
+ Log.w(Settings.tag, "cgeoBase.parseTrackable: Failed to parse trackable id");
}
// trackable icon
@@ -1773,7 +1745,7 @@ public class cgBase {
}
} catch (Exception e) {
// failed to parse trackable icon
- Log.w(cgSettings.tag, "cgeoBase.parseTrackable: Failed to parse trackable icon");
+ Log.w(Settings.tag, "cgeoBase.parseTrackable: Failed to parse trackable icon");
}
// trackable name
@@ -1784,7 +1756,7 @@ public class cgBase {
}
} catch (Exception e) {
// failed to parse trackable name
- Log.w(cgSettings.tag, "cgeoBase.parseTrackable: Failed to parse trackable name");
+ Log.w(Settings.tag, "cgeoBase.parseTrackable: Failed to parse trackable name");
}
// trackable type
@@ -1796,7 +1768,7 @@ public class cgBase {
}
} catch (Exception e) {
// failed to parse trackable type
- Log.w(cgSettings.tag, "cgeoBase.parseTrackable: Failed to parse trackable type");
+ Log.w(Settings.tag, "cgeoBase.parseTrackable: Failed to parse trackable type");
}
}
@@ -1809,7 +1781,7 @@ public class cgBase {
}
} catch (Exception e) {
// failed to parse trackable owner name
- Log.w(cgSettings.tag, "cgeoBase.parseTrackable: Failed to parse trackable owner name");
+ Log.w(Settings.tag, "cgeoBase.parseTrackable: Failed to parse trackable owner name");
}
// trackable origin
@@ -1820,7 +1792,7 @@ public class cgBase {
}
} catch (Exception e) {
// failed to parse trackable origin
- Log.w(cgSettings.tag, "cgeoBase.parseTrackable: Failed to parse trackable origin");
+ Log.w(Settings.tag, "cgeoBase.parseTrackable: Failed to parse trackable origin");
}
// trackable spotted
@@ -1850,7 +1822,7 @@ public class cgBase {
}
} catch (Exception e) {
// failed to parse trackable last known place
- Log.w(cgSettings.tag, "cgeoBase.parseTrackable: Failed to parse trackable last known place");
+ Log.w(Settings.tag, "cgeoBase.parseTrackable: Failed to parse trackable last known place");
}
// released
@@ -1875,7 +1847,7 @@ public class cgBase {
}
} catch (Exception e) {
// failed to parse trackable released date
- Log.w(cgSettings.tag, "cgeoBase.parseTrackable: Failed to parse trackable released date");
+ Log.w(Settings.tag, "cgeoBase.parseTrackable: Failed to parse trackable released date");
}
// trackable distance
@@ -1883,7 +1855,7 @@ public class cgBase {
final Matcher matcherDistance = PATTERN_TRACKABLE_Distance.matcher(page);
if (matcherDistance.find() && matcherDistance.groupCount() > 0) {
try {
- trackable.distance = DistanceParser.parseDistance(matcherDistance.group(1), settings.units);
+ trackable.distance = DistanceParser.parseDistance(matcherDistance.group(1), Settings.isUseMetricUnits());
} catch (NumberFormatException e) {
trackable.distance = null;
throw e;
@@ -1891,7 +1863,7 @@ public class cgBase {
}
} catch (Exception e) {
// failed to parse trackable distance
- Log.w(cgSettings.tag, "cgeoBase.parseTrackable: Failed to parse trackable distance");
+ Log.w(Settings.tag, "cgeoBase.parseTrackable: Failed to parse trackable distance");
}
// trackable goal
@@ -1902,7 +1874,7 @@ public class cgBase {
}
} catch (Exception e) {
// failed to parse trackable goal
- Log.w(cgSettings.tag, "cgeoBase.parseTrackable: Failed to parse trackable goal");
+ Log.w(Settings.tag, "cgeoBase.parseTrackable: Failed to parse trackable goal");
}
// trackable details & image
@@ -1921,7 +1893,7 @@ public class cgBase {
}
} catch (Exception e) {
// failed to parse trackable details & image
- Log.w(cgSettings.tag, "cgeoBase.parseTrackable: Failed to parse trackable details & image");
+ Log.w(Settings.tag, "cgeoBase.parseTrackable: Failed to parse trackable details & image");
}
// trackable logs
@@ -1969,7 +1941,7 @@ public class cgBase {
}
} catch (Exception e) {
// failed to parse logs
- Log.w(cgSettings.tag, "cgeoBase.parseCache: Failed to parse cache logs");
+ Log.w(Settings.tag, "cgeoBase.parseCache: Failed to parse cache logs");
}
app.saveTrackable(trackable);
@@ -2023,7 +1995,7 @@ public class cgBase {
startPos = page.indexOf("<table id=\"tblTravelBugs\"");
if (startPos == -1) {
- Log.e(cgSettings.tag, "cgeoBase.parseTrackableLog: ID \"tblTravelBugs\" not found on page");
+ Log.e(Settings.tag, "cgeoBase.parseTrackableLog: ID \"tblTravelBugs\" not found on page");
return null;
}
@@ -2031,7 +2003,7 @@ public class cgBase {
endPos = page.indexOf("</table>");
if (endPos == -1) {
- Log.e(cgSettings.tag, "cgeoBase.parseTrackableLog: end of ID \"tblTravelBugs\" not found on page");
+ Log.e(Settings.tag, "cgeoBase.parseTrackableLog: end of ID \"tblTravelBugs\" not found on page");
return null;
}
@@ -2039,7 +2011,7 @@ public class cgBase {
startPos = page.indexOf("<tbody>");
if (startPos == -1) {
- Log.e(cgSettings.tag, "cgeoBase.parseTrackableLog: tbody not found on page");
+ Log.e(Settings.tag, "cgeoBase.parseTrackableLog: tbody not found on page");
return null;
}
@@ -2047,7 +2019,7 @@ public class cgBase {
endPos = page.indexOf("</tbody>");
if (endPos == -1) {
- Log.e(cgSettings.tag, "cgeoBase.parseTrackableLog: end of tbody not found on page");
+ Log.e(Settings.tag, "cgeoBase.parseTrackableLog: end of tbody not found on page");
return null;
}
@@ -2084,7 +2056,7 @@ public class cgBase {
continue;
}
- Log.i(cgSettings.tag, "Trackable in inventory (#" + trackable.ctl + "/" + trackable.id + "): " + trackable.trackCode + " - " + trackable.name);
+ Log.i(Settings.tag, "Trackable in inventory (#" + trackable.ctl + "/" + trackable.id + "): " + trackable.trackCode + " - " + trackable.name);
trackables.add(trackable);
}
@@ -2098,7 +2070,21 @@ public class cgBase {
return "?";
}
- if (settings.units == cgSettings.unitsImperial) {
+ if (Settings.isUseMetricUnits()) {
+ if (distance > 100) {
+ return String.format(Locale.getDefault(), "%.0f", Double.valueOf(Math.round(distance))) + " km";
+ } else if (distance > 10) {
+ return String.format(Locale.getDefault(), "%.1f", Double.valueOf(Math.round(distance * 10.0) / 10.0)) + " km";
+ } else if (distance > 1) {
+ return String.format(Locale.getDefault(), "%.2f", Double.valueOf(Math.round(distance * 100.0) / 100.0)) + " km";
+ } else if (distance > 0.1) {
+ return String.format(Locale.getDefault(), "%.0f", Double.valueOf(Math.round(distance * 1000.0))) + " m";
+ } else if (distance > 0.01) {
+ return String.format(Locale.getDefault(), "%.1f", Double.valueOf(Math.round(distance * 1000.0 * 10.0) / 10.0)) + " m";
+ } else {
+ return String.format(Locale.getDefault(), "%.2f", Double.valueOf(Math.round(distance * 1000.0 * 100.0) / 100.0)) + " m";
+ }
+ } else {
final Float miles = distance / miles2km;
if (distance > 100) {
return String.format(Locale.getDefault(), "%.0f", Double.valueOf(Math.round(miles))) + " mi";
@@ -2113,20 +2099,6 @@ public class cgBase {
} else {
return String.format(Locale.getDefault(), "%.2f", Double.valueOf(Math.round(miles * 5280 * 100.0) / 100.0)) + " ft";
}
- } else {
- if (distance > 100) {
- return String.format(Locale.getDefault(), "%.0f", Double.valueOf(Math.round(distance))) + " km";
- } else if (distance > 10) {
- return String.format(Locale.getDefault(), "%.1f", Double.valueOf(Math.round(distance * 10.0) / 10.0)) + " km";
- } else if (distance > 1) {
- return String.format(Locale.getDefault(), "%.2f", Double.valueOf(Math.round(distance * 100.0) / 100.0)) + " km";
- } else if (distance > 0.1) {
- return String.format(Locale.getDefault(), "%.0f", Double.valueOf(Math.round(distance * 1000.0))) + " m";
- } else if (distance > 0.01) {
- return String.format(Locale.getDefault(), "%.1f", Double.valueOf(Math.round(distance * 1000.0 * 10.0) / 10.0)) + " m";
- } else {
- return String.format(Locale.getDefault(), "%.2f", Double.valueOf(Math.round(distance * 1000.0 * 100.0) / 100.0)) + " m";
- }
}
}
@@ -2186,12 +2158,12 @@ public class cgBase {
final String url = app.getUrl(searchId);
if (StringUtils.isBlank(url)) {
- Log.e(cgSettings.tag, "cgeoBase.searchByNextPage: No url found");
+ Log.e(Settings.tag, "cgeoBase.searchByNextPage: No url found");
return searchId;
}
if (isEmpty(viewstates)) {
- Log.e(cgSettings.tag, "cgeoBase.searchByNextPage: No viewstate given");
+ Log.e(Settings.tag, "cgeoBase.searchByNextPage: No viewstate given");
return searchId;
}
@@ -2209,22 +2181,22 @@ public class cgBase {
if (loginState == 1) {
page = getResponseData(postRequest(uri, params));
} else if (loginState == -3) {
- Log.i(cgSettings.tag, "Working as guest.");
+ Log.i(Settings.tag, "Working as guest.");
} else {
app.setError(searchId, errorRetrieve.get(loginState));
- Log.e(cgSettings.tag, "cgeoBase.searchByNextPage: Can not log in geocaching");
+ Log.e(Settings.tag, "cgeoBase.searchByNextPage: Can not log in geocaching");
return searchId;
}
}
if (StringUtils.isBlank(page)) {
- Log.e(cgSettings.tag, "cgeoBase.searchByNextPage: No data from server");
+ Log.e(Settings.tag, "cgeoBase.searchByNextPage: No data from server");
return searchId;
}
final cgCacheWrap caches = parseSearch(thread, url, page, showCaptcha);
if (caches == null || caches.cacheList == null || caches.cacheList.isEmpty()) {
- Log.e(cgSettings.tag, "cgeoBase.searchByNextPage: No cache parsed");
+ Log.e(Settings.tag, "cgeoBase.searchByNextPage: No cache parsed");
return searchId;
}
@@ -2247,7 +2219,7 @@ public class cgBase {
final cgSearch search = new cgSearch();
if (StringUtils.isBlank(geocode) && StringUtils.isBlank(guid)) {
- Log.e(cgSettings.tag, "cgeoBase.searchByGeocode: No geocode nor guid given");
+ Log.e(Settings.tag, "cgeoBase.searchByGeocode: No geocode nor guid given");
return null;
}
@@ -2271,7 +2243,7 @@ public class cgBase {
public UUID searchByOffline(final Geopoint coords, final String cacheType, final int list) {
if (app == null) {
- Log.e(cgSettings.tag, "cgeoBase.searchByOffline: No application found");
+ Log.e(Settings.tag, "cgeoBase.searchByOffline: No application found");
return null;
}
final cgSearch search = app.getBatchOfStoredCaches(true, coords, cacheType, list);
@@ -2281,7 +2253,7 @@ public class cgBase {
public UUID searchByHistory(final String cacheType) {
if (app == null) {
- Log.e(cgSettings.tag, "cgeoBase.searchByHistory: No application found");
+ Log.e(Settings.tag, "cgeoBase.searchByHistory: No application found");
return null;
}
@@ -2304,21 +2276,21 @@ public class cgBase {
String page = requestLogged(uri, params, false, false, true);
if (StringUtils.isBlank(page)) {
- Log.e(cgSettings.tag, "cgeoBase.searchByCoords: No data from server");
+ Log.e(Settings.tag, "cgeoBase.searchByCoords: No data from server");
return null;
}
final cgCacheWrap caches = parseSearch(thread, fullUri, page, showCaptcha);
if (caches == null || caches.cacheList == null || caches.cacheList.isEmpty()) {
- Log.e(cgSettings.tag, "cgeoBase.searchByCoords: No cache parsed");
+ Log.e(Settings.tag, "cgeoBase.searchByCoords: No cache parsed");
}
if (app == null) {
- Log.e(cgSettings.tag, "cgeoBase.searchByCoords: No application found");
+ Log.e(Settings.tag, "cgeoBase.searchByCoords: No application found");
return null;
}
- List<cgCache> cacheList = processSearchResults(search, caches, settings.excludeDisabled, 0, null);
+ List<cgCache> cacheList = processSearchResults(search, caches, Settings.isExcludeDisabledCaches(), false, null);
app.addSearch(search, cacheList, true, reason);
@@ -2329,7 +2301,7 @@ public class cgBase {
final cgSearch search = new cgSearch();
if (StringUtils.isBlank(keyword)) {
- Log.e(cgSettings.tag, "cgeoBase.searchByKeyword: No keyword given");
+ Log.e(Settings.tag, "cgeoBase.searchByKeyword: No keyword given");
return null;
}
@@ -2342,21 +2314,21 @@ public class cgBase {
String page = requestLogged(uri, params, false, false, true);
if (StringUtils.isBlank(page)) {
- Log.e(cgSettings.tag, "cgeoBase.searchByKeyword: No data from server");
+ Log.e(Settings.tag, "cgeoBase.searchByKeyword: No data from server");
return null;
}
final cgCacheWrap caches = parseSearch(thread, fullUri, page, showCaptcha);
if (caches == null || caches.cacheList == null || caches.cacheList.isEmpty()) {
- Log.e(cgSettings.tag, "cgeoBase.searchByKeyword: No cache parsed");
+ Log.e(Settings.tag, "cgeoBase.searchByKeyword: No cache parsed");
}
if (app == null) {
- Log.e(cgSettings.tag, "cgeoBase.searchByCoords: No application found");
+ Log.e(Settings.tag, "cgeoBase.searchByCoords: No application found");
return null;
}
- List<cgCache> cacheList = processSearchResults(search, caches, settings.excludeDisabled, 0, null);
+ List<cgCache> cacheList = processSearchResults(search, caches, Settings.isExcludeDisabledCaches(), false, null);
app.addSearch(search, cacheList, true, reason);
@@ -2366,7 +2338,7 @@ public class cgBase {
public UUID searchByUsername(final cgSearchThread thread, final String userName, final String cacheType, final int reason, final boolean showCaptcha) {
final cgSearch search = new cgSearch();
if (StringUtils.isBlank(userName)) {
- Log.e(cgSettings.tag, "cgeoBase.searchByUsername: No user name given");
+ Log.e(Settings.tag, "cgeoBase.searchByUsername: No user name given");
return null;
}
@@ -2375,9 +2347,9 @@ public class cgBase {
params.put("ul", userName);
boolean my = false;
- if (userName.equalsIgnoreCase(settings.getLogin().left)) {
+ if (userName.equalsIgnoreCase(Settings.getLogin().left)) {
my = true;
- Log.i(cgSettings.tag, "cgBase.searchByUsername: Overriding users choice, downloading all caches.");
+ Log.i(Settings.tag, "cgBase.searchByUsername: Overriding users choice, downloading all caches.");
}
final String uri = "http://www.geocaching.com/seek/nearest.aspx";
@@ -2385,21 +2357,21 @@ public class cgBase {
String page = requestLogged(uri, params, false, my, true);
if (StringUtils.isBlank(page)) {
- Log.e(cgSettings.tag, "cgeoBase.searchByUsername: No data from server");
+ Log.e(Settings.tag, "cgeoBase.searchByUsername: No data from server");
return null;
}
final cgCacheWrap caches = parseSearch(thread, fullUri, page, showCaptcha);
if (caches == null || caches.cacheList == null || caches.cacheList.isEmpty()) {
- Log.e(cgSettings.tag, "cgeoBase.searchByUsername: No cache parsed");
+ Log.e(Settings.tag, "cgeoBase.searchByUsername: No cache parsed");
}
if (app == null) {
- Log.e(cgSettings.tag, "cgeoBase.searchByUsername: No application found");
+ Log.e(Settings.tag, "cgeoBase.searchByUsername: No application found");
return null;
}
- List<cgCache> cacheList = processSearchResults(search, caches, settings.excludeDisabled, 0, null);
+ List<cgCache> cacheList = processSearchResults(search, caches, Settings.isExcludeDisabledCaches(), false, null);
app.addSearch(search, cacheList, true, reason);
@@ -2409,7 +2381,7 @@ public class cgBase {
public UUID searchByOwner(final cgSearchThread thread, final String userName, final String cacheType, final int reason, final boolean showCaptcha) {
final cgSearch search = new cgSearch();
if (StringUtils.isBlank(userName)) {
- Log.e(cgSettings.tag, "cgeoBase.searchByOwner: No user name given");
+ Log.e(Settings.tag, "cgeoBase.searchByOwner: No user name given");
return null;
}
@@ -2422,21 +2394,21 @@ public class cgBase {
String page = requestLogged(uri, params, false, false, true);
if (StringUtils.isBlank(page)) {
- Log.e(cgSettings.tag, "cgeoBase.searchByOwner: No data from server");
+ Log.e(Settings.tag, "cgeoBase.searchByOwner: No data from server");
return null;
}
final cgCacheWrap caches = parseSearch(thread, fullUri, page, showCaptcha);
if (caches == null || caches.cacheList == null) {
- Log.e(cgSettings.tag, "cgeoBase.searchByOwner: No cache parsed");
+ Log.e(Settings.tag, "cgeoBase.searchByOwner: No cache parsed");
}
if (app == null) {
- Log.e(cgSettings.tag, "cgeoBase.searchByCoords: No application found");
+ Log.e(Settings.tag, "cgeoBase.searchByCoords: No application found");
return null;
}
- List<cgCache> cacheList = processSearchResults(search, caches, settings.excludeDisabled, reason, null);
+ List<cgCache> cacheList = processSearchResults(search, caches, Settings.isExcludeDisabledCaches(), Settings.isExcludeMyCaches(), null);
app.addSearch(search, cacheList, true, 0);
@@ -2454,21 +2426,21 @@ public class cgBase {
page = requestJSONgc(uri, params);
if (StringUtils.isBlank(page)) {
- Log.e(cgSettings.tag, "cgeoBase.searchByViewport: No data from server");
+ Log.e(Settings.tag, "cgeoBase.searchByViewport: No data from server");
return null;
}
final cgCacheWrap caches = parseMapJSON(Uri.parse(uri).buildUpon().encodedQuery(params).build().toString(), page);
if (caches == null || caches.cacheList == null || caches.cacheList.isEmpty()) {
- Log.e(cgSettings.tag, "cgeoBase.searchByViewport: No cache parsed");
+ Log.e(Settings.tag, "cgeoBase.searchByViewport: No cache parsed");
}
if (app == null) {
- Log.e(cgSettings.tag, "cgeoBase.searchByViewport: No application found");
+ Log.e(Settings.tag, "cgeoBase.searchByViewport: No application found");
return null;
}
- List<cgCache> cacheList = processSearchResults(search, caches, settings.excludeDisabled, cgSettings.getExcludeMine() ? 1 : 0, settings.cacheType);
+ List<cgCache> cacheList = processSearchResults(search, caches, Settings.isExcludeDisabledCaches(), Settings.isExcludeMyCaches(), Settings.getCacheType());
app.addSearch(search, cacheList, true, reason);
@@ -2481,7 +2453,7 @@ public class cgBase {
try {
request.setEntity(new StringEntity(params, HTTP.UTF_8));
} catch (UnsupportedEncodingException e) {
- Log.e(cgSettings.tag, "cgeoBase.searchByViewport", e);
+ Log.e(Settings.tag, "cgeoBase.searchByViewport", e);
}
request.addHeader("Content-Type", "application/json; charset=UTF-8");
@@ -2513,7 +2485,7 @@ public class cgBase {
final String data = getResponseData(postRequest("http://api.go4cache.com/get.php", params));
if (StringUtils.isBlank(data)) {
- Log.e(cgSettings.tag, "cgeoBase.getGeocachersInViewport: No data from server");
+ Log.e(Settings.tag, "cgeoBase.getGeocachersInViewport: No data from server");
return null;
}
@@ -2546,23 +2518,13 @@ public class cgBase {
}
}
} catch (Exception e) {
- Log.e(cgSettings.tag, "cgBase.getGeocachersInViewport: " + e.toString());
+ Log.e(Settings.tag, "cgBase.getGeocachersInViewport: " + e.toString());
}
return users;
}
- /**
- * FIXME: excludeDisabled, excludeMine should be boolean after settings rework
- *
- * @param search
- * @param caches
- * @param excludeDisabled
- * @param excludeMine
- * @param cacheType
- * @return
- */
- public static List<cgCache> processSearchResults(final cgSearch search, final cgCacheWrap caches, final int excludeDisabled, final int excludeMine, final String cacheType) {
+ public static List<cgCache> processSearchResults(final cgSearch search, final cgCacheWrap caches, final boolean excludeDisabled, final boolean excludeMine, final String cacheType) {
List<cgCache> cacheList = new ArrayList<cgCache>();
if (caches != null) {
if (StringUtils.isNotBlank(caches.error)) {
@@ -2576,9 +2538,9 @@ public class cgBase {
if (CollectionUtils.isNotEmpty(caches.cacheList)) {
for (cgCache cache : caches.cacheList) {
- if ((excludeDisabled == 0 || (excludeDisabled == 1 && cache.disabled == false))
- && (excludeMine == 0 || (excludeMine == 1 && cache.own == false))
- && (excludeMine == 0 || (excludeMine == 1 && cache.found == false))
+ if ((!excludeDisabled || (excludeDisabled && cache.disabled == false))
+ && (!excludeMine || (excludeMine && cache.own == false))
+ && (!excludeMine || (excludeMine && cache.found == false))
&& (cacheType == null || (cacheType.equals(cache.type)))) {
search.addGeocode(cache.geocode);
cacheList.add(cache);
@@ -2593,7 +2555,7 @@ public class cgBase {
cgTrackable trackable = new cgTrackable();
if (StringUtils.isBlank(geocode) && StringUtils.isBlank(guid) && StringUtils.isBlank(id)) {
- Log.w(cgSettings.tag, "cgeoBase.searchTrackable: No geocode nor guid nor id given");
+ Log.w(Settings.tag, "cgeoBase.searchTrackable: No geocode nor guid nor id given");
return null;
}
@@ -2609,13 +2571,13 @@ public class cgBase {
String page = requestLogged("http://www.geocaching.com/track/details.aspx", params, false, false, false);
if (StringUtils.isBlank(page)) {
- Log.e(cgSettings.tag, "cgeoBase.searchTrackable: No data from server");
+ Log.e(Settings.tag, "cgeoBase.searchTrackable: No data from server");
return trackable;
}
trackable = parseTrackable(page);
if (trackable == null) {
- Log.e(cgSettings.tag, "cgeoBase.searchTrackable: No trackable parsed");
+ Log.e(Settings.tag, "cgeoBase.searchTrackable: No trackable parsed");
return trackable;
}
@@ -2626,17 +2588,17 @@ public class cgBase {
final int logType, final int year, final int month, final int day,
final String log, final List<cgTrackableLog> trackables) {
if (isEmpty(viewstates)) {
- Log.e(cgSettings.tag, "cgeoBase.postLog: No viewstate given");
+ Log.e(Settings.tag, "cgeoBase.postLog: No viewstate given");
return 1000;
}
if (logTypes2.containsKey(logType) == false) {
- Log.e(cgSettings.tag, "cgeoBase.postLog: Unknown logtype");
+ Log.e(Settings.tag, "cgeoBase.postLog: Unknown logtype");
return 1000;
}
if (StringUtils.isBlank(log)) {
- Log.e(cgSettings.tag, "cgeoBase.postLog: No log text given");
+ Log.e(Settings.tag, "cgeoBase.postLog: No log text given");
return 1001;
}
@@ -2659,9 +2621,9 @@ public class cgBase {
final String logInfo = logUpdated.toString().replace("\n", "\r\n"); // windows' eol
if (trackables != null) {
- Log.i(cgSettings.tag, "Trying to post log for cache #" + cacheid + " - action: " + logType + "; date: " + year + "." + month + "." + day + ", log: " + logInfo + "; trackables: " + trackables.size());
+ Log.i(Settings.tag, "Trying to post log for cache #" + cacheid + " - action: " + logType + "; date: " + year + "." + month + "." + day + ", log: " + logInfo + "; trackables: " + trackables.size());
} else {
- Log.i(cgSettings.tag, "Trying to post log for cache #" + cacheid + " - action: " + logType + "; date: " + year + "." + month + "." + day + ", log: " + logInfo + "; trackables: 0");
+ Log.i(Settings.tag, "Trying to post log for cache #" + cacheid + " - action: " + logType + "; date: " + year + "." + month + "." + day + ", log: " + logInfo + "; trackables: 0");
}
final Parameters params = new Parameters();
@@ -2701,13 +2663,13 @@ public class cgBase {
if (loginState == 1) {
page = getResponseData(postRequest(uri, params));
} else {
- Log.e(cgSettings.tag, "cgeoBase.postLog: Can not log in geocaching (error: " + loginState + ")");
+ Log.e(Settings.tag, "cgeoBase.postLog: Can not log in geocaching (error: " + loginState + ")");
return loginState;
}
}
if (StringUtils.isBlank(page)) {
- Log.e(cgSettings.tag, "cgeoBase.postLog: No data from server");
+ Log.e(Settings.tag, "cgeoBase.postLog: No data from server");
return 1002;
}
@@ -2720,7 +2682,7 @@ public class cgBase {
final String[] viewstatesConfirm = getViewstates(page);
if (isEmpty(viewstatesConfirm)) {
- Log.e(cgSettings.tag, "cgeoBase.postLog: No viewstate for confirm log");
+ Log.e(Settings.tag, "cgeoBase.postLog: No viewstate for confirm log");
return 1000;
}
@@ -2759,14 +2721,14 @@ public class cgBase {
page = getResponseData(postRequest(uri, params));
}
} catch (Exception e) {
- Log.e(cgSettings.tag, "cgeoBase.postLog.confim: " + e.toString());
+ Log.e(Settings.tag, "cgeoBase.postLog.confim: " + e.toString());
}
try {
final Pattern patternOk = Pattern.compile("<h2[^>]*>[^<]*<span id=\"ctl00_ContentBody_lbHeading\"[^>]*>[^<]*</span>[^<]*</h2>", Pattern.CASE_INSENSITIVE | Pattern.MULTILINE);
final Matcher matcherOk = patternOk.matcher(page);
if (matcherOk.find()) {
- Log.i(cgSettings.tag, "Log successfully posted to cache #" + cacheid);
+ Log.i(Settings.tag, "Log successfully posted to cache #" + cacheid);
if (app != null && geocode != null) {
app.saveVisitDate(geocode);
@@ -2775,31 +2737,31 @@ public class cgBase {
return 1;
}
} catch (Exception e) {
- Log.e(cgSettings.tag, "cgeoBase.postLog.check: " + e.toString());
+ Log.e(Settings.tag, "cgeoBase.postLog.check: " + e.toString());
}
- Log.e(cgSettings.tag, "cgeoBase.postLog: Failed to post log because of unknown error");
+ Log.e(Settings.tag, "cgeoBase.postLog: Failed to post log because of unknown error");
return 1000;
}
public int postLogTrackable(final String tbid, final String trackingCode, final String[] viewstates,
final int logType, final int year, final int month, final int day, final String log) {
if (isEmpty(viewstates)) {
- Log.e(cgSettings.tag, "cgeoBase.postLogTrackable: No viewstate given");
+ Log.e(Settings.tag, "cgeoBase.postLogTrackable: No viewstate given");
return 1000;
}
if (logTypes2.containsKey(logType) == false) {
- Log.e(cgSettings.tag, "cgeoBase.postLogTrackable: Unknown logtype");
+ Log.e(Settings.tag, "cgeoBase.postLogTrackable: Unknown logtype");
return 1000;
}
if (StringUtils.isBlank(log)) {
- Log.e(cgSettings.tag, "cgeoBase.postLogTrackable: No log text given");
+ Log.e(Settings.tag, "cgeoBase.postLogTrackable: No log text given");
return 1001;
}
- Log.i(cgSettings.tag, "Trying to post log for trackable #" + trackingCode + " - action: " + logType + "; date: " + year + "." + month + "." + day + ", log: " + log);
+ Log.i(Settings.tag, "Trying to post log for trackable #" + trackingCode + " - action: " + logType + "; date: " + year + "." + month + "." + day + ", log: " + log);
final String logInfo = log.replace("\n", "\r\n"); // windows' eol
@@ -2831,13 +2793,13 @@ public class cgBase {
if (loginState == 1) {
page = getResponseData(postRequest(uri, params));
} else {
- Log.e(cgSettings.tag, "cgeoBase.postLogTrackable: Can not log in geocaching (error: " + loginState + ")");
+ Log.e(Settings.tag, "cgeoBase.postLogTrackable: Can not log in geocaching (error: " + loginState + ")");
return loginState;
}
}
if (StringUtils.isBlank(page)) {
- Log.e(cgSettings.tag, "cgeoBase.postLogTrackable: No data from server");
+ Log.e(Settings.tag, "cgeoBase.postLogTrackable: No data from server");
return 1002;
}
@@ -2845,14 +2807,14 @@ public class cgBase {
final Pattern patternOk = Pattern.compile("<div id=[\"|']ctl00_ContentBody_LogBookPanel1_ViewLogPanel[\"|']>", Pattern.CASE_INSENSITIVE);
final Matcher matcherOk = patternOk.matcher(page);
if (matcherOk.find()) {
- Log.i(cgSettings.tag, "Log successfully posted to trackable #" + trackingCode);
+ Log.i(Settings.tag, "Log successfully posted to trackable #" + trackingCode);
return 1;
}
} catch (Exception e) {
- Log.e(cgSettings.tag, "cgeoBase.postLogTrackable.check: " + e.toString());
+ Log.e(Settings.tag, "cgeoBase.postLogTrackable.check: " + e.toString());
}
- Log.e(cgSettings.tag, "cgeoBase.postLogTrackable: Failed to post log because of unknown error");
+ Log.e(Settings.tag, "cgeoBase.postLogTrackable: Failed to post log because of unknown error");
return 1000;
}
@@ -2868,16 +2830,16 @@ public class cgBase {
String page = postRequestLogged(uri);
if (StringUtils.isBlank(page)) {
- Log.e(cgSettings.tag, "cgBase.addToWatchlist: No data from server");
+ Log.e(Settings.tag, "cgBase.addToWatchlist: No data from server");
return -1; // error
}
boolean guidOnPage = cache.isGuidContainedInPage(page);
if (guidOnPage) {
- Log.i(cgSettings.tag, "cgBase.addToWatchlist: cache is on watchlist");
+ Log.i(Settings.tag, "cgBase.addToWatchlist: cache is on watchlist");
cache.onWatchlist = true;
} else {
- Log.e(cgSettings.tag, "cgBase.addToWatchlist: cache is not on watchlist");
+ Log.e(Settings.tag, "cgBase.addToWatchlist: cache is not on watchlist");
}
return guidOnPage ? 1 : -1; // on watchlist (=added) / else: error
}
@@ -2894,7 +2856,7 @@ public class cgBase {
String page = postRequestLogged(uri);
if (StringUtils.isBlank(page)) {
- Log.e(cgSettings.tag, "cgBase.removeFromWatchlist: No data from server");
+ Log.e(Settings.tag, "cgBase.removeFromWatchlist: No data from server");
return -1; // error
}
@@ -2908,10 +2870,10 @@ public class cgBase {
page = getResponseData(postRequest(uri, params));
boolean guidOnPage = cache.isGuidContainedInPage(page);
if (!guidOnPage) {
- Log.i(cgSettings.tag, "cgBase.removeFromWatchlist: cache removed from watchlist");
+ Log.i(Settings.tag, "cgBase.removeFromWatchlist: cache removed from watchlist");
cache.onWatchlist = false;
} else {
- Log.e(cgSettings.tag, "cgBase.removeFromWatchlist: cache not removed from watchlist");
+ Log.e(Settings.tag, "cgBase.removeFromWatchlist: cache not removed from watchlist");
}
return guidOnPage ? -1 : 0; // on watchlist (=error) / not on watchlist
}
@@ -2944,11 +2906,11 @@ public class cgBase {
sc.init(null, trustAllCerts, new java.security.SecureRandom());
HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
} catch (Exception e) {
- Log.e(cgSettings.tag, "cgBase.trustAllHosts: " + e.toString());
+ Log.e(Settings.tag, "cgBase.trustAllHosts: " + e.toString());
}
}
- public static void postTweetCache(cgeoapplication app, cgSettings settings, String geocode) {
+ public static void postTweetCache(cgeoapplication app, String geocode) {
final cgCache cache = app.getCacheByGeocode(geocode);
String status;
final String url = cache.getUrl();
@@ -2966,10 +2928,10 @@ public class cgBase {
status = Twitter.appendHashTag(status, "geocaching");
}
- Twitter.postTweet(app, settings, status, null);
+ Twitter.postTweet(app, status, null);
}
- public static void postTweetTrackable(cgeoapplication app, cgSettings settings, String geocode) {
+ public static void postTweetTrackable(cgeoapplication app, String geocode) {
final cgTrackable trackable = app.getTrackableByGeocode(geocode);
String name = trackable.name;
if (name.length() > 82) {
@@ -2978,7 +2940,7 @@ public class cgBase {
String status = "I touched " + name + " (" + trackable.getUrl() + ")!";
status = Twitter.appendHashTag(status, "cgeo");
status = Twitter.appendHashTag(status, "geocaching");
- Twitter.postTweet(app, settings, status, null);
+ Twitter.postTweet(app, status, null);
}
public static String getLocalIpAddress() {
@@ -3006,12 +2968,12 @@ public class cgBase {
}
public static String prepareParameters(final Parameters params, final boolean my, final boolean addF) {
- if (!my && cgSettings.getExcludeMine() && addF) {
+ if (!my && Settings.isExcludeMyCaches() && addF) {
if (params == null) {
return "f=1";
}
params.put("f", "1");
- Log.i(cgSettings.tag, "Skipping caches found or hidden by user.");
+ Log.i(Settings.tag, "Skipping caches found or hidden by user.");
}
return prepareParameters(params);
@@ -3042,7 +3004,7 @@ public class cgBase {
try {
return replaceWhitespace(EntityUtils.toString(response.getEntity(), HTTP.UTF_8));
} catch (Exception e) {
- Log.e(cgSettings.tag, "getResponseData", e);
+ Log.e(Settings.tag, "getResponseData", e);
return null;
}
}
@@ -3053,7 +3015,7 @@ public class cgBase {
if (login() == 1) {
return getResponseData(postRequest(uri, null));
} else {
- Log.i(cgSettings.tag, "Working as guest.");
+ Log.i(Settings.tag, "Working as guest.");
}
}
return data;
@@ -3069,7 +3031,7 @@ public class cgBase {
response = request(uri, params, xContentType, my, addF);
data = getResponseData(response);
} else {
- Log.i(cgSettings.tag, "Working as guest.");
+ Log.i(Settings.tag, "Working as guest.");
}
}
@@ -3124,7 +3086,7 @@ public class cgBase {
return request(request);
} catch (Exception e) {
// Can be UnsupportedEncodingException, ClientProtocolException or IOException
- Log.e(cgSettings.tag, "postRequest", e);
+ Log.e(Settings.tag, "postRequest", e);
return null;
}
}
@@ -3142,7 +3104,7 @@ public class cgBase {
}
private static HttpResponse request(final HttpRequestBase request) {
- if (cgSettings.asBrowser()) {
+ if (Settings.isBrowser()) {
request.setHeader("Accept-Charset", "utf-8, iso-8859-1, utf-16, *;q=0.7");
request.setHeader("Accept-Language", "en-US");
request.getParams().setParameter(CoreProtocolPNames.USER_AGENT, idBrowser);
@@ -3156,22 +3118,22 @@ public class cgBase {
static public HttpResponse doRequest(final HttpRequestBase request) {
final String reqLogStr = request.getMethod() + " " + hidePassword(request.getURI().toString());
- Log.d(cgSettings.tag, reqLogStr);
+ Log.d(Settings.tag, reqLogStr);
final HttpClient client = getHttpClient();
for (int i = 0; i <= NB_DOWNLOAD_RETRIES; i++) {
final long before = System.currentTimeMillis();
try {
final HttpResponse response = client.execute(request);
- Log.d(cgSettings.tag, response.getStatusLine().getStatusCode() + formatTimeSpan(before) + reqLogStr);
+ Log.d(Settings.tag, response.getStatusLine().getStatusCode() + formatTimeSpan(before) + reqLogStr);
return response;
} catch (IOException e) {
final String timeSpan = formatTimeSpan(before);
final String tries = (i + 1) + "/" + (NB_DOWNLOAD_RETRIES + 1);
if (i == NB_DOWNLOAD_RETRIES) {
- Log.e(cgSettings.tag, "Failure " + tries + timeSpan + reqLogStr, e);
+ Log.e(Settings.tag, "Failure " + tries + timeSpan + reqLogStr, e);
} else {
- Log.e(cgSettings.tag, "Failure " + tries + " (" + e.toString() + ")" + timeSpan + "- retrying " + reqLogStr);
+ Log.e(Settings.tag, "Failure " + tries + " (" + e.toString() + ")" + timeSpan + "- retrying " + reqLogStr);
}
}
}
@@ -3219,7 +3181,7 @@ public class cgBase {
try {
return new JSONObject(getResponseData(response));
} catch (JSONException e) {
- Log.e(cgSettings.tag, "cgeoBase.requestJSON", e);
+ Log.e(Settings.tag, "cgeoBase.requestJSON", e);
}
}
@@ -3279,7 +3241,7 @@ public class cgBase {
}
// store images from logs
- if (settings.storelogimages && cache.logs != null) {
+ if (Settings.isStoreLogImages() && cache.logs != null) {
for (cgLog log : cache.logs) {
if (CollectionUtils.isNotEmpty(log.logImages)) {
for (cgImage oneLogImg : log.logImages) {
@@ -3290,7 +3252,7 @@ public class cgBase {
}
// store map previews
- StaticMapsProvider.downloadMaps(cache, settings, activity);
+ StaticMapsProvider.downloadMaps(cache, activity);
app.markStored(cache.geocode, listId);
app.removeCacheFromCache(cache.geocode);
@@ -3299,7 +3261,7 @@ public class cgBase {
handler.sendMessage(new Message());
}
} catch (Exception e) {
- Log.e(cgSettings.tag, "cgBase.storeCache: " + e.toString());
+ Log.e(Settings.tag, "cgBase.storeCache: " + e.toString());
}
}
@@ -3310,7 +3272,7 @@ public class cgBase {
handler.sendMessage(new Message());
} catch (Exception e) {
- Log.e(cgSettings.tag, "cgBase.dropCache: " + e.toString());
+ Log.e(Settings.tag, "cgBase.dropCache: " + e.toString());
}
}
@@ -3342,7 +3304,7 @@ public class cgBase {
return true;
} catch (Exception e) {
- Log.e(cgSettings.tag, "cgBase.isInViewPort: " + e.toString());
+ Log.e(Settings.tag, "cgBase.isInViewPort: " + e.toString());
return false;
}
}
@@ -3607,11 +3569,11 @@ public class cgBase {
}
}
- public static boolean runNavigation(Activity activity, Resources res, cgSettings settings, final Geopoint coords) {
+ public static boolean runNavigation(Activity activity, Resources res, Settings settings, final Geopoint coords) {
return runNavigation(activity, res, settings, coords, null);
}
- public static boolean runNavigation(Activity activity, Resources res, cgSettings settings, final Geopoint coords, final Geopoint coordsNow) {
+ public static boolean runNavigation(Activity activity, Resources res, Settings settings, final Geopoint coords, final Geopoint coordsNow) {
if (activity == null) {
return false;
}
@@ -3620,7 +3582,7 @@ public class cgBase {
}
// Google Navigation
- if (settings.useGNavigation == 1) {
+ if (Settings.isUseGoogleNavigation()) {
try {
activity.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("google.navigation:ll=" + coords.getLatitude() + "," + coords.getLongitude())));
@@ -3646,7 +3608,7 @@ public class cgBase {
// nothing
}
- Log.i(cgSettings.tag, "cgBase.runNavigation: No navigation application available.");
+ Log.i(Settings.tag, "cgBase.runNavigation: No navigation application available.");
if (res != null) {
ActivityMixin.showToast(activity, res.getString(R.string.err_navigation_no));
@@ -3703,7 +3665,7 @@ public class cgBase {
return result.getDouble("elevation");
}
} catch (Exception e) {
- Log.w(cgSettings.tag, "cgBase.getElevation: " + e.toString());
+ Log.w(Settings.tag, "cgBase.getElevation: " + e.toString());
}
return null;
@@ -3780,7 +3742,7 @@ public class cgBase {
* @return
*/
public String getUserName() {
- return settings.getUsername();
+ return Settings.getUsername();
}
/**
diff --git a/main/src/cgeo/geocaching/cgCache.java b/main/src/cgeo/geocaching/cgCache.java
index c56d0f7..1ff1f96 100644
--- a/main/src/cgeo/geocaching/cgCache.java
+++ b/main/src/cgeo/geocaching/cgCache.java
@@ -252,10 +252,10 @@ public class cgCache implements ICache {
Pattern patternOk = Pattern.compile(guid, Pattern.CASE_INSENSITIVE);
Matcher matcherOk = patternOk.matcher(page);
if (matcherOk.find()) {
- Log.i(cgSettings.tag, "cgCache.isGuidContainedInPage: guid '" + guid + "' found");
+ Log.i(Settings.tag, "cgCache.isGuidContainedInPage: guid '" + guid + "' found");
return true;
} else {
- Log.i(cgSettings.tag, "cgCache.isGuidContainedInPage: guid '" + guid + "' not found");
+ Log.i(Settings.tag, "cgCache.isGuidContainedInPage: guid '" + guid + "' not found");
return false;
}
}
@@ -279,11 +279,11 @@ public class cgCache implements ICache {
return true;
}
- public boolean logOffline(final IAbstractActivity fromActivity, final int logType, final cgSettings settings, final cgBase base) {
+ public boolean logOffline(final IAbstractActivity fromActivity, final int logType, final cgBase base) {
String log = "";
- if (StringUtils.isNotBlank(settings.getSignature())
- && settings.signatureAutoinsert) {
- log = LogTemplateProvider.applyTemplates(settings.getSignature(), base, true);
+ if (StringUtils.isNotBlank(Settings.getSignature())
+ && Settings.isAutoInsertSignature()) {
+ log = LogTemplateProvider.applyTemplates(Settings.getSignature(), base, true);
}
logOffline(fromActivity, log, Calendar.getInstance(), logType);
return true;
@@ -305,8 +305,8 @@ public class cgCache implements ICache {
}
}
- public List<Integer> getPossibleLogTypes(cgSettings settings) {
- boolean isOwner = owner != null && owner.equalsIgnoreCase(settings.getUsername());
+ public List<Integer> getPossibleLogTypes() {
+ boolean isOwner = owner != null && owner.equalsIgnoreCase(Settings.getUsername());
List<Integer> types = new ArrayList<Integer>();
if ("event".equals(type) || "mega".equals(type) || "cito".equals(type) || "lostfound".equals(type)) {
types.add(cgBase.LOG_WILL_ATTEND);
diff --git a/main/src/cgeo/geocaching/cgCacheListAdapter.java b/main/src/cgeo/geocaching/cgCacheListAdapter.java
index a307f93..90d676a 100644
--- a/main/src/cgeo/geocaching/cgCacheListAdapter.java
+++ b/main/src/cgeo/geocaching/cgCacheListAdapter.java
@@ -47,7 +47,6 @@ public class cgCacheListAdapter extends ArrayAdapter<cgCache> {
private Resources res = null;
private List<cgCache> list = null;
- private cgSettings settings = null;
private cgCacheView holder = null;
private LayoutInflater inflater = null;
private Activity activity = null;
@@ -72,12 +71,11 @@ public class cgCacheListAdapter extends ArrayAdapter<cgCache> {
private cgFilter currentFilter = null;
private List<cgCache> originalList = null;
- public cgCacheListAdapter(Activity activityIn, cgSettings settingsIn, List<cgCache> listIn, cgBase baseIn) {
+ public cgCacheListAdapter(Activity activityIn, List<cgCache> listIn, cgBase baseIn) {
super(activityIn, 0, listIn);
res = activityIn.getResources();
activity = activityIn;
- settings = settingsIn;
list = listIn;
base = baseIn;
@@ -91,14 +89,14 @@ public class cgCacheListAdapter extends ArrayAdapter<cgCache> {
}
}
- if (settings.skin == 0) {
- ratingBcgs[0] = R.drawable.favourite_background_red_dark;
- ratingBcgs[1] = R.drawable.favourite_background_orange_dark;
- ratingBcgs[2] = R.drawable.favourite_background_green_dark;
- } else {
+ if (Settings.isLightSkin()) {
ratingBcgs[0] = R.drawable.favourite_background_red_light;
ratingBcgs[1] = R.drawable.favourite_background_orange_light;
ratingBcgs[2] = R.drawable.favourite_background_green_light;
+ } else {
+ ratingBcgs[0] = R.drawable.favourite_background_red_dark;
+ ratingBcgs[1] = R.drawable.favourite_background_orange_dark;
+ ratingBcgs[2] = R.drawable.favourite_background_green_dark;
}
}
@@ -266,7 +264,7 @@ public class cgCacheListAdapter extends ArrayAdapter<cgCache> {
}
notifyDataSetChanged();
} catch (Exception e) {
- Log.w(cgSettings.tag, "cgCacheListAdapter.setActualCoordinates: failed to sort caches in list");
+ Log.w(Settings.tag, "cgCacheListAdapter.setActualCoordinates: failed to sort caches in list");
}
}
@@ -287,7 +285,7 @@ public class cgCacheListAdapter extends ArrayAdapter<cgCache> {
}
notifyDataSetChanged();
} catch (Exception e) {
- Log.w(cgSettings.tag, "cgCacheListAdapter.setActualCoordinates: failed to sort caches in list");
+ Log.w(Settings.tag, "cgCacheListAdapter.setActualCoordinates: failed to sort caches in list");
}
lastSort = System.currentTimeMillis();
@@ -360,7 +358,7 @@ public class cgCacheListAdapter extends ArrayAdapter<cgCache> {
}
if (position > getCount()) {
- Log.w(cgSettings.tag, "cgCacheListAdapter.getView: Attempt to access missing item #" + position);
+ Log.w(Settings.tag, "cgCacheListAdapter.getView: Attempt to access missing item #" + position);
return null;
}
@@ -394,7 +392,7 @@ public class cgCacheListAdapter extends ArrayAdapter<cgCache> {
}
if (cache.own) {
- if (settings.skin == 1) {
+ if (Settings.isLightSkin()) {
holder.oneInfo.setBackgroundResource(R.color.owncache_background_light);
holder.oneCheckbox.setBackgroundResource(R.color.owncache_background_light);
} else {
@@ -402,7 +400,7 @@ public class cgCacheListAdapter extends ArrayAdapter<cgCache> {
holder.oneCheckbox.setBackgroundResource(R.color.owncache_background_dark);
}
} else {
- if (settings.skin == 1) {
+ if (Settings.isLightSkin()) {
holder.oneInfo.setBackgroundResource(R.color.background_light);
holder.oneCheckbox.setBackgroundResource(R.color.background_light);
} else {
@@ -524,7 +522,7 @@ public class cgCacheListAdapter extends ArrayAdapter<cgCache> {
Bitmap dirImgPre = null;
Bitmap dirImg = null;
try {
- dirImgPre = BitmapFactory.decodeFile(cgSettings.getStorage() + cache.geocode + "/direction.png");
+ dirImgPre = BitmapFactory.decodeFile(Settings.getStorage() + cache.geocode + "/direction.png");
dirImg = dirImgPre.copy(Bitmap.Config.ARGB_8888, true);
dirImgPre.recycle();
@@ -534,7 +532,7 @@ public class cgCacheListAdapter extends ArrayAdapter<cgCache> {
}
if (dirImg != null) {
- if (settings.skin == 0) {
+ if (!Settings.isLightSkin()) {
int length = dirImg.getWidth() * dirImg.getHeight();
int[] pixels = new int[length];
dirImg.getPixels(pixels, 0, dirImg.getWidth(), 0, 0, dirImg.getWidth(), dirImg.getHeight());
@@ -562,7 +560,7 @@ public class cgCacheListAdapter extends ArrayAdapter<cgCache> {
int favoriteBack;
// set default background, neither vote nor rating may be available
- if (settings.skin == 1) {
+ if (Settings.isLightSkin()) {
favoriteBack = R.drawable.favourite_background_light;
} else {
favoriteBack = R.drawable.favourite_background_dark;
@@ -783,7 +781,7 @@ public class cgCacheListAdapter extends ArrayAdapter<cgCache> {
return true;
}
} catch (Exception e) {
- Log.w(cgSettings.tag, "cgCacheListAdapter.detectGesture.onFling: " + e.toString());
+ Log.w(Settings.tag, "cgCacheListAdapter.detectGesture.onFling: " + e.toString());
}
return false;
diff --git a/main/src/cgeo/geocaching/cgCompass.java b/main/src/cgeo/geocaching/cgCompass.java
index e6b9447..81fd655 100644
--- a/main/src/cgeo/geocaching/cgCompass.java
+++ b/main/src/cgeo/geocaching/cgCompass.java
@@ -43,7 +43,7 @@ public class cgCompass extends View {
try {
invalidate();
} catch (Exception e) {
- Log.e(cgSettings.tag, "cgCompass.changeHandler: " + e.toString());
+ Log.e(Settings.tag, "cgCompass.changeHandler: " + e.toString());
}
}
};
diff --git a/main/src/cgeo/geocaching/cgData.java b/main/src/cgeo/geocaching/cgData.java
index c1b0082..4768b8b 100644
--- a/main/src/cgeo/geocaching/cgData.java
+++ b/main/src/cgeo/geocaching/cgData.java
@@ -232,16 +232,16 @@ public class cgData {
databaseRW = dbHelper.getWritableDatabase();
if (databaseRW != null && databaseRW.isOpen()) {
- Log.i(cgSettings.tag, "Connection to RW database established.");
+ Log.i(Settings.tag, "Connection to RW database established.");
} else {
- Log.e(cgSettings.tag, "Failed to open connection to RW database.");
+ Log.e(Settings.tag, "Failed to open connection to RW database.");
}
if (databaseRW != null && databaseRW.inTransaction()) {
databaseRW.endTransaction();
}
} catch (Exception e) {
- Log.e(cgSettings.tag, "cgData.openDb.RW: " + e.toString());
+ Log.e(Settings.tag, "cgData.openDb.RW: " + e.toString());
}
}
@@ -257,16 +257,16 @@ public class cgData {
}
if (databaseRO != null && databaseRO.isOpen()) {
- Log.i(cgSettings.tag, "Connection to RO database established.");
+ Log.i(Settings.tag, "Connection to RO database established.");
} else {
- Log.e(cgSettings.tag, "Failed to open connection to RO database.");
+ Log.e(Settings.tag, "Failed to open connection to RO database.");
}
if (databaseRO != null && databaseRO.inTransaction()) {
databaseRO.endTransaction();
}
} catch (Exception e) {
- Log.e(cgSettings.tag, "cgData.openDb.RO: " + e.toString());
+ Log.e(Settings.tag, "cgData.openDb.RO: " + e.toString());
}
}
@@ -285,7 +285,7 @@ public class cgData {
databaseRO = null;
SQLiteDatabase.releaseMemory();
- Log.d(cgSettings.tag, "Closing RO database");
+ Log.d(Settings.tag, "Closing RO database");
}
if (databaseRW != null) {
@@ -299,7 +299,7 @@ public class cgData {
databaseRW = null;
SQLiteDatabase.releaseMemory();
- Log.d(cgSettings.tag, "Closing RW database");
+ Log.d(Settings.tag, "Closing RW database");
}
if (dbHelper != null) {
@@ -310,7 +310,7 @@ public class cgData {
public String backupDatabase() {
if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED) == false) {
- Log.w(cgSettings.tag, "Database wasn't backed up: no external memory");
+ Log.w(Settings.tag, "Database wasn't backed up: no external memory");
return null;
}
@@ -318,7 +318,7 @@ public class cgData {
closeDb();
boolean backupDone = false;
- final String directoryImg = cgSettings.cache;
+ final String directoryImg = Settings.cache;
final String directoryTarget = Environment.getExternalStorageDirectory() + "/" + directoryImg + "/";
final String fileTarget = directoryTarget + "cgeo.sqlite";
final String fileSource = path;
@@ -334,7 +334,7 @@ public class cgData {
input = new FileInputStream(fileSource);
output = new FileOutputStream(fileTarget);
} catch (FileNotFoundException e) {
- Log.e(cgSettings.tag, "Database wasn't backed up, could not open file: " + e.toString());
+ Log.e(Settings.tag, "Database wasn't backed up, could not open file: " + e.toString());
}
byte[] buffer = new byte[1024];
@@ -347,7 +347,7 @@ public class cgData {
output.flush();
backupDone = true;
} catch (IOException e) {
- Log.e(cgSettings.tag, "Database wasn't backed up, could not read/write file: " + e.toString());
+ Log.e(Settings.tag, "Database wasn't backed up, could not read/write file: " + e.toString());
}
}
@@ -359,11 +359,11 @@ public class cgData {
input.close();
}
} catch (IOException e) {
- Log.e(cgSettings.tag, "Database wasn't backed up, could not close file: " + e.toString());
+ Log.e(Settings.tag, "Database wasn't backed up, could not close file: " + e.toString());
}
if (backupDone) {
- Log.i(cgSettings.tag, "Database was copied to " + fileTarget);
+ Log.i(Settings.tag, "Database was copied to " + fileTarget);
}
init();
@@ -372,7 +372,7 @@ public class cgData {
}
public static File isRestoreFile() {
- final String directoryImg = cgSettings.cache;
+ final String directoryImg = Settings.cache;
final String fileSource = Environment.getExternalStorageDirectory() + "/" + directoryImg + "/cgeo.sqlite";
File fileSourceFile = new File(fileSource);
@@ -385,7 +385,7 @@ public class cgData {
public boolean restoreDatabase() {
if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED) == false) {
- Log.w(cgSettings.tag, "Database wasn't restored: no external memory");
+ Log.w(Settings.tag, "Database wasn't restored: no external memory");
return false;
}
@@ -394,13 +394,13 @@ public class cgData {
boolean restoreDone = false;
- final String directoryImg = cgSettings.cache;
+ final String directoryImg = Settings.cache;
final String fileSource = Environment.getExternalStorageDirectory() + "/" + directoryImg + "/cgeo.sqlite";
final String fileTarget = path;
File fileSourceFile = new File(fileSource);
if (fileSourceFile.exists() == false) {
- Log.w(cgSettings.tag, "Database backup was not found");
+ Log.w(Settings.tag, "Database backup was not found");
init();
@@ -413,7 +413,7 @@ public class cgData {
input = new FileInputStream(fileSource);
output = new FileOutputStream(fileTarget);
} catch (FileNotFoundException e) {
- Log.e(cgSettings.tag, "Database wasn't restored, could not open file: " + e.toString());
+ Log.e(Settings.tag, "Database wasn't restored, could not open file: " + e.toString());
}
byte[] buffer = new byte[1024];
@@ -426,7 +426,7 @@ public class cgData {
output.flush();
restoreDone = true;
} catch (IOException e) {
- Log.e(cgSettings.tag, "Database wasn't restored, could not read/write file: " + e.toString());
+ Log.e(Settings.tag, "Database wasn't restored, could not read/write file: " + e.toString());
}
}
@@ -438,11 +438,11 @@ public class cgData {
input.close();
}
} catch (IOException e) {
- Log.e(cgSettings.tag, "Database wasn't restored, could not close file: " + e.toString());
+ Log.e(Settings.tag, "Database wasn't restored, could not close file: " + e.toString());
}
if (restoreDone) {
- Log.i(cgSettings.tag, "Database was restored");
+ Log.i(Settings.tag, "Database was restored");
}
init();
@@ -492,7 +492,7 @@ public class cgData {
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
- Log.i(cgSettings.tag, "Upgrade database from ver. " + oldVersion + " to ver. " + newVersion + ": start");
+ Log.i(Settings.tag, "Upgrade database from ver. " + oldVersion + " to ver. " + newVersion + ": start");
try {
if (db.isReadOnly()) {
@@ -505,7 +505,7 @@ public class cgData {
dropDatabase(db);
onCreate(db);
- Log.i(cgSettings.tag, "Database structure created.");
+ Log.i(Settings.tag, "Database structure created.");
}
if (oldVersion > 0) {
@@ -525,9 +525,9 @@ public class cgData {
db.execSQL("create index if not exists in_a on " + dbTableLogs + " (geocode)");
db.execSQL("create index if not exists in_a on " + dbTableTrackables + " (geocode)");
- Log.i(cgSettings.tag, "Indexes added.");
+ Log.i(Settings.tag, "Indexes added.");
} catch (Exception e) {
- Log.e(cgSettings.tag, "Failed to upgrade to ver. 34: " + e.toString());
+ Log.e(Settings.tag, "Failed to upgrade to ver. 34: " + e.toString());
}
}
@@ -536,9 +536,9 @@ public class cgData {
db.execSQL("alter table " + dbTableCaches + " add column direction text");
db.execSQL("alter table " + dbTableCaches + " add column distance double");
- Log.i(cgSettings.tag, "Columns direction and distance added to " + dbTableCaches + ".");
+ Log.i(Settings.tag, "Columns direction and distance added to " + dbTableCaches + ".");
} catch (Exception e) {
- Log.e(cgSettings.tag, "Failed to upgrade to ver. 37: " + e.toString());
+ Log.e(Settings.tag, "Failed to upgrade to ver. 37: " + e.toString());
}
}
@@ -547,9 +547,9 @@ public class cgData {
db.execSQL("drop table " + dbTableLogs);
db.execSQL(dbCreateLogs);
- Log.i(cgSettings.tag, "Changed type column in " + dbTableLogs + " to integer.");
+ Log.i(Settings.tag, "Changed type column in " + dbTableLogs + " to integer.");
} catch (Exception e) {
- Log.e(cgSettings.tag, "Failed to upgrade to ver. 38: " + e.toString());
+ Log.e(Settings.tag, "Failed to upgrade to ver. 38: " + e.toString());
}
}
@@ -557,9 +557,9 @@ public class cgData {
try {
db.execSQL(dbCreateLists);
- Log.i(cgSettings.tag, "Created lists table.");
+ Log.i(Settings.tag, "Created lists table.");
} catch (Exception e) {
- Log.e(cgSettings.tag, "Failed to upgrade to ver. 39: " + e.toString());
+ Log.e(Settings.tag, "Failed to upgrade to ver. 39: " + e.toString());
}
}
@@ -568,9 +568,9 @@ public class cgData {
db.execSQL("drop table " + dbTableTrackables);
db.execSQL(dbCreateTrackables);
- Log.i(cgSettings.tag, "Changed type of geocode column in trackables table.");
+ Log.i(Settings.tag, "Changed type of geocode column in trackables table.");
} catch (Exception e) {
- Log.e(cgSettings.tag, "Failed to upgrade to ver. 40: " + e.toString());
+ Log.e(Settings.tag, "Failed to upgrade to ver. 40: " + e.toString());
}
}
@@ -580,9 +580,9 @@ public class cgData {
db.execSQL("alter table " + dbTableCaches + " add column votes integer");
db.execSQL("alter table " + dbTableCaches + " add column vote integer");
- Log.i(cgSettings.tag, "Added columns for GCvote.");
+ Log.i(Settings.tag, "Added columns for GCvote.");
} catch (Exception e) {
- Log.e(cgSettings.tag, "Failed to upgrade to ver. 41: " + e.toString());
+ Log.e(Settings.tag, "Failed to upgrade to ver. 41: " + e.toString());
}
}
@@ -590,9 +590,9 @@ public class cgData {
try {
db.execSQL(dbCreateLogsOffline);
- Log.i(cgSettings.tag, "Added table for offline logs");
+ Log.i(Settings.tag, "Added table for offline logs");
} catch (Exception e) {
- Log.e(cgSettings.tag, "Failed to upgrade to ver. 42: " + e.toString());
+ Log.e(Settings.tag, "Failed to upgrade to ver. 42: " + e.toString());
}
}
@@ -688,9 +688,9 @@ public class cgData {
db.execSQL("drop table " + dbTableCachesTemp);
db.setTransactionSuccessful();
- Log.i(cgSettings.tag, "Changed direction column");
+ Log.i(Settings.tag, "Changed direction column");
} catch (Exception e) {
- Log.e(cgSettings.tag, "Failed to upgrade to ver. 43: " + e.toString());
+ Log.e(Settings.tag, "Failed to upgrade to ver. 43: " + e.toString());
} finally {
db.endTransaction();
}
@@ -700,9 +700,9 @@ public class cgData {
try {
db.execSQL("alter table " + dbTableCaches + " add column favourite_cnt integer");
- Log.i(cgSettings.tag, "Column favourite_cnt added to " + dbTableCaches + ".");
+ Log.i(Settings.tag, "Column favourite_cnt added to " + dbTableCaches + ".");
} catch (Exception e) {
- Log.e(cgSettings.tag, "Failed to upgrade to ver. 44: " + e.toString());
+ Log.e(Settings.tag, "Failed to upgrade to ver. 44: " + e.toString());
}
}
@@ -710,9 +710,9 @@ public class cgData {
try {
db.execSQL("alter table " + dbTableCaches + " add column owner_real text");
- Log.i(cgSettings.tag, "Column owner_real added to " + dbTableCaches + ".");
+ Log.i(Settings.tag, "Column owner_real added to " + dbTableCaches + ".");
} catch (Exception e) {
- Log.e(cgSettings.tag, "Failed to upgrade to ver. 45: " + e.toString());
+ Log.e(Settings.tag, "Failed to upgrade to ver. 45: " + e.toString());
}
}
@@ -721,18 +721,18 @@ public class cgData {
db.execSQL("alter table " + dbTableCaches + " add column visiteddate long");
db.execSQL("create index if not exists in_f on " + dbTableCaches + " (visiteddate, detailedupdate)");
- Log.i(cgSettings.tag, "Added column for date of visit.");
+ Log.i(Settings.tag, "Added column for date of visit.");
} catch (Exception e) {
- Log.e(cgSettings.tag, "Failed to upgrade to ver. 46: " + e.toString());
+ Log.e(Settings.tag, "Failed to upgrade to ver. 46: " + e.toString());
}
}
if (oldVersion < 47) { // upgrade to 47
try {
db.execSQL("alter table " + dbTableCaches + " add column own integer not null default 0");
- Log.i(cgSettings.tag, "Added column own.");
+ Log.i(Settings.tag, "Added column own.");
} catch (Exception e) {
- Log.e(cgSettings.tag, "Failed to upgrade to ver. 47: " + e.toString());
+ Log.e(Settings.tag, "Failed to upgrade to ver. 47: " + e.toString());
}
}
@@ -740,9 +740,9 @@ public class cgData {
try {
db.execSQL("alter table " + dbTableCaches + " add column elevation double");
- Log.i(cgSettings.tag, "Column elevation added to " + dbTableCaches + ".");
+ Log.i(Settings.tag, "Column elevation added to " + dbTableCaches + ".");
} catch (Exception e) {
- Log.e(cgSettings.tag, "Failed to upgrade to ver. 48: " + e.toString());
+ Log.e(Settings.tag, "Failed to upgrade to ver. 48: " + e.toString());
}
}
@@ -750,9 +750,9 @@ public class cgData {
try {
db.execSQL(dbCreateLogCount);
- Log.i(cgSettings.tag, "Created table " + dbTableLogCount + ".");
+ Log.i(Settings.tag, "Created table " + dbTableLogCount + ".");
} catch (Exception e) {
- Log.e(cgSettings.tag, "Failed to upgrade to ver. 49: " + e.toString());
+ Log.e(Settings.tag, "Failed to upgrade to ver. 49: " + e.toString());
}
}
@@ -760,9 +760,9 @@ public class cgData {
try {
db.execSQL("alter table " + dbTableCaches + " add column myvote float");
- Log.i(cgSettings.tag, "Added float column for votes to " + dbTableCaches + ".");
+ Log.i(Settings.tag, "Added float column for votes to " + dbTableCaches + ".");
} catch (Exception e) {
- Log.e(cgSettings.tag, "Failed to upgrade to ver. 50: " + e.toString());
+ Log.e(Settings.tag, "Failed to upgrade to ver. 50: " + e.toString());
}
}
@@ -770,9 +770,9 @@ public class cgData {
try {
db.execSQL("alter table " + dbTableCaches + " add column reliable_latlon integer");
- Log.i(cgSettings.tag, "Column reliable_latlon added to " + dbTableCaches + ".");
+ Log.i(Settings.tag, "Column reliable_latlon added to " + dbTableCaches + ".");
} catch (Exception e) {
- Log.e(cgSettings.tag, "Failed to upgrade to ver. 51: " + e.toString());
+ Log.e(Settings.tag, "Failed to upgrade to ver. 51: " + e.toString());
}
}
@@ -780,9 +780,9 @@ public class cgData {
try {
db.execSQL(dbCreateSearchDestinationHistory);
- Log.i(cgSettings.tag, "Added table " + dbTableSearchDestionationHistory + ".");
+ Log.i(Settings.tag, "Added table " + dbTableSearchDestionationHistory + ".");
} catch (Exception e) {
- Log.e(cgSettings.tag, "Failed to upgrade to ver. 52", e);
+ Log.e(Settings.tag, "Failed to upgrade to ver. 52", e);
}
}
@@ -790,9 +790,9 @@ public class cgData {
try {
db.execSQL("alter table " + dbTableCaches + " add column onWatchlist integer");
- Log.i(cgSettings.tag, "Column onWatchlist added to " + dbTableCaches + ".");
+ Log.i(Settings.tag, "Column onWatchlist added to " + dbTableCaches + ".");
} catch (Exception e) {
- Log.e(cgSettings.tag, "Failed to upgrade to ver. 53", e);
+ Log.e(Settings.tag, "Failed to upgrade to ver. 53", e);
}
}
@@ -800,7 +800,7 @@ public class cgData {
try {
db.execSQL(dbCreateLogImages);
} catch (Exception e) {
- Log.e(cgSettings.tag, "Failed to upgrade to ver. 54: " + e.toString());
+ Log.e(Settings.tag, "Failed to upgrade to ver. 54: " + e.toString());
}
}
@@ -809,7 +809,7 @@ public class cgData {
try {
db.execSQL("alter table " + dbTableCaches + " add column personal_note text");
} catch (Exception e) {
- Log.e(cgSettings.tag, "Failed to upgrade to ver. 55: " + e.toString());
+ Log.e(Settings.tag, "Failed to upgrade to ver. 55: " + e.toString());
}
}
@@ -822,7 +822,7 @@ public class cgData {
"lower(attribute) where attribute like \"%_yes\" " +
"or attribute like \"%_no\"");
} catch (Exception e) {
- Log.e(cgSettings.tag, "Failed to upgrade to ver. 56: " + e.toString());
+ Log.e(Settings.tag, "Failed to upgrade to ver. 56: " + e.toString());
}
}
@@ -837,7 +837,7 @@ public class cgData {
db.execSQL("drop index in_f");
createIndices(db);
} catch (Exception e) {
- Log.e(cgSettings.tag, "Failed to upgrade to ver. 57: " + e.toString());
+ Log.e(Settings.tag, "Failed to upgrade to ver. 57: " + e.toString());
}
}
@@ -925,9 +925,9 @@ public class cgData {
db.setTransactionSuccessful();
- Log.i(cgSettings.tag, "Removed latitude_string and longitude_string columns");
+ Log.i(Settings.tag, "Removed latitude_string and longitude_string columns");
} catch (Exception e) {
- Log.e(cgSettings.tag, "Failed to upgrade to ver. 58", e);
+ Log.e(Settings.tag, "Failed to upgrade to ver. 58", e);
} finally {
db.endTransaction();
}
@@ -940,7 +940,7 @@ public class cgData {
db.endTransaction();
}
- Log.i(cgSettings.tag, "Upgrade database from ver. " + oldVersion + " to ver. " + newVersion + ": completed");
+ Log.i(Settings.tag, "Upgrade database from ver. " + oldVersion + " to ver. " + newVersion + ": completed");
}
}
@@ -988,7 +988,7 @@ public class cgData {
}
}
} catch (Exception e) {
- Log.e(cgSettings.tag, "cgData.allDetailedThere: " + e.toString());
+ Log.e(Settings.tag, "cgData.allDetailedThere: " + e.toString());
}
if (cursor != null) {
@@ -1049,7 +1049,7 @@ public class cgData {
}
}
} catch (Exception e) {
- Log.e(cgSettings.tag, "cgData.isThere: " + e.toString());
+ Log.e(Settings.tag, "cgData.isThere: " + e.toString());
}
if (cursor != null) {
@@ -1125,7 +1125,7 @@ public class cgData {
cursor.close();
}
} catch (Exception e) {
- Log.e(cgSettings.tag, "cgData.isOffline: " + e.toString());
+ Log.e(Settings.tag, "cgData.isOffline: " + e.toString());
}
if (reason >= 1) {
@@ -1167,7 +1167,7 @@ public class cgData {
}
}
} catch (Exception e) {
- Log.e(cgSettings.tag, "cgData.getGeocodeForGuid: " + e.toString());
+ Log.e(Settings.tag, "cgData.getGeocodeForGuid: " + e.toString());
}
if (cursor != null) {
@@ -1209,7 +1209,7 @@ public class cgData {
}
}
} catch (Exception e) {
- Log.e(cgSettings.tag, "cgData.getCacheidForGeocode: " + e.toString());
+ Log.e(Settings.tag, "cgData.getCacheidForGeocode: " + e.toString());
}
if (cursor != null) {
@@ -1408,7 +1408,7 @@ public class cgData {
databaseRW.setTransactionSuccessful();
} catch (Exception e) {
success = false;
- Log.e(cgSettings.tag, "Updating searchedDestinations db failed", e);
+ Log.e(Settings.tag, "Updating searchedDestinations db failed", e);
} finally {
databaseRW.endTransaction();
}
@@ -1497,7 +1497,7 @@ public class cgData {
} catch (MalformedCoordinateException e) {
// TODO: check whether the exception should be returned to the caller instead,
// as it might want to remove an invalid geopoint from the database.
- Log.e(cgSettings.tag, "cannot parse geopoint from database: " + e.getMessage());
+ Log.e(Settings.tag, "cannot parse geopoint from database: " + e.getMessage());
return null;
}
}
@@ -1797,7 +1797,7 @@ public class cgData {
}
}
} catch (Exception e) {
- Log.e(cgSettings.tag, "cgData.getBounds: " + e.toString());
+ Log.e(Settings.tag, "cgData.getBounds: " + e.toString());
}
if (cursor != null) {
@@ -2045,7 +2045,7 @@ public class cgData {
}
}
} catch (Exception e) {
- Log.e(cgSettings.tag, "cgData.loadCaches: " + e.toString());
+ Log.e(Settings.tag, "cgData.loadCaches: " + e.toString());
}
if (cursor != null) {
@@ -2337,7 +2337,7 @@ public class cgData {
databaseRW.setTransactionSuccessful();
} catch (Exception e) {
success = false;
- Log.e(cgSettings.tag, "Unable to clear searched destinations", e);
+ Log.e(Settings.tag, "Unable to clear searched destinations", e);
} finally {
databaseRW.endTransaction();
}
@@ -2563,7 +2563,7 @@ public class cgData {
count = (int) compiledStmnt.simpleQueryForLong();
compiledStmnt.close();
} catch (Exception e) {
- Log.e(cgSettings.tag, "cgData.loadAllStoredCachesCount: " + e.toString());
+ Log.e(Settings.tag, "cgData.loadAllStoredCachesCount: " + e.toString());
}
return count;
@@ -2579,7 +2579,7 @@ public class cgData {
count = (int) sqlCount.simpleQueryForLong();
sqlCount.close();
} catch (Exception e) {
- Log.e(cgSettings.tag, "cgData.getAllHistoricCachesCount: " + e.toString());
+ Log.e(Settings.tag, "cgData.getAllHistoricCachesCount: " + e.toString());
}
return count;
@@ -2634,7 +2634,7 @@ public class cgData {
}
} catch (Exception e) {
- Log.e(cgSettings.tag, "cgData.loadBatchOfStoredGeocodes: " + e.toString());
+ Log.e(Settings.tag, "cgData.loadBatchOfStoredGeocodes: " + e.toString());
}
return geocodes;
@@ -2684,7 +2684,7 @@ public class cgData {
cursor.close();
}
} catch (Exception e) {
- Log.e(cgSettings.tag, "cgData.loadBatchOfHistoricGeocodes: " + e.toString());
+ Log.e(Settings.tag, "cgData.loadBatchOfHistoricGeocodes: " + e.toString());
}
return geocodes;
@@ -2774,7 +2774,7 @@ public class cgData {
cursor.close();
}
} catch (Exception e) {
- Log.e(cgSettings.tag, "cgData.getOfflineInViewport: " + e.toString());
+ Log.e(Settings.tag, "cgData.getOfflineInViewport: " + e.toString());
}
return geocodes;
@@ -2826,7 +2826,7 @@ public class cgData {
cursor.close();
}
} catch (Exception e) {
- Log.e(cgSettings.tag, "cgData.getOfflineAll: " + e.toString());
+ Log.e(Settings.tag, "cgData.getOfflineAll: " + e.toString());
}
return geocodes;
@@ -2860,7 +2860,7 @@ public class cgData {
return true;
}
} catch (Exception e) {
- Log.e(cgSettings.tag, "cgData.markDropped: " + e.toString());
+ Log.e(Settings.tag, "cgData.markDropped: " + e.toString());
}
return false;
@@ -2882,7 +2882,7 @@ public class cgData {
return true;
}
} catch (Exception e) {
- Log.e(cgSettings.tag, "cgData.markFound: " + e.toString());
+ Log.e(Settings.tag, "cgData.markFound: " + e.toString());
}
return false;
@@ -2895,7 +2895,7 @@ public class cgData {
public void clean(boolean more) {
init();
- Log.d(cgSettings.tag, "Database clean: started");
+ Log.d(Settings.tag, "Database clean: started");
Cursor cursor = null;
List<String> geocodes = new ArrayList<String>();
@@ -2938,7 +2938,7 @@ public class cgData {
final int size = geocodes.size();
if (size > 0) {
- Log.d(cgSettings.tag, "Database clean: removing " + size + " geocaches");
+ Log.d(Settings.tag, "Database clean: removing " + size + " geocaches");
String geocodeList = StringUtils.join(geocodes.toArray(), ", ");
databaseRW.execSQL("delete from " + dbTableCaches + " where geocode in (" + geocodeList + ")");
@@ -2955,17 +2955,17 @@ public class cgData {
databaseRW.execSQL("delete from " + dbTableCaches + " where geocode = \"\"");
- if (Log.isLoggable(cgSettings.tag, Log.DEBUG)) {
+ if (Log.isLoggable(Settings.tag, Log.DEBUG)) {
final SQLiteStatement countSql = databaseRO.compileStatement("select count(_id) from " + dbTableCaches + " where reason = 0");
final int count = (int) countSql.simpleQueryForLong();
countSql.close();
- Log.d(cgSettings.tag, "Database clean: " + count + " cached geocaches remaining");
+ Log.d(Settings.tag, "Database clean: " + count + " cached geocaches remaining");
}
} catch (Exception e) {
- Log.w(cgSettings.tag, "cgData.clean: " + e.toString());
+ Log.w(Settings.tag, "cgData.clean: " + e.toString());
}
- Log.d(cgSettings.tag, "Database clean: finished");
+ Log.d(Settings.tag, "Database clean: finished");
}
public void dropStored(int listId) {
@@ -3014,7 +3014,7 @@ public class cgData {
geocodes.clear();
}
} catch (Exception e) {
- Log.e(cgSettings.tag, "cgData.dropStored: " + e.toString());
+ Log.e(Settings.tag, "cgData.dropStored: " + e.toString());
}
}
@@ -3050,7 +3050,7 @@ public class cgData {
}
}
} catch (Exception e) {
- Log.e(cgSettings.tag, "cgData.saveLogOffline: " + e.toString());
+ Log.e(Settings.tag, "cgData.saveLogOffline: " + e.toString());
}
return status;
@@ -3115,7 +3115,7 @@ public class cgData {
countSql.close();
} catch (Exception e) {
- Log.e(cgSettings.tag, "cgData.hasLogOffline: " + e.toString());
+ Log.e(Settings.tag, "cgData.hasLogOffline: " + e.toString());
}
return count > 0;
@@ -3132,7 +3132,7 @@ public class cgData {
try {
databaseRW.update(dbTableCaches, values, "geocode = ?", new String[] { geocode });
} catch (Exception e) {
- Log.e(cgSettings.tag, "cgData.saveVisitDate: " + e.toString());
+ Log.e(Settings.tag, "cgData.saveVisitDate: " + e.toString());
}
}
@@ -3147,7 +3147,7 @@ public class cgData {
try {
databaseRW.update(dbTableCaches, values, "geocode = ?", new String[] { geocode });
} catch (Exception e) {
- Log.e(cgSettings.tag, "cgData.clearVisitDate: " + e.toString());
+ Log.e(Settings.tag, "cgData.clearVisitDate: " + e.toString());
}
}
@@ -3201,7 +3201,7 @@ public class cgData {
cursor.close();
}
} catch (Exception e) {
- Log.e(cgSettings.tag, "cgData.readLists: " + e.toString());
+ Log.e(Settings.tag, "cgData.readLists: " + e.toString());
}
return result;
}
@@ -3316,7 +3316,7 @@ public class cgData {
databaseRW.delete(dbTableSearchDestionationHistory, "_id = " + destination.getId(), null);
databaseRW.setTransactionSuccessful();
} catch (Exception e) {
- Log.e(cgSettings.tag, "Unable to remove searched destination", e);
+ Log.e(Settings.tag, "Unable to remove searched destination", e);
success = false;
} finally {
databaseRW.endTransaction();
diff --git a/main/src/cgeo/geocaching/cgDirection.java b/main/src/cgeo/geocaching/cgDirection.java
index e786edf..7b1ad60 100644
--- a/main/src/cgeo/geocaching/cgDirection.java
+++ b/main/src/cgeo/geocaching/cgDirection.java
@@ -60,7 +60,7 @@ public class cgDirection {
* See for example https://code.google.com/p/android/issues/detail?id=14792
*/
- //Log.i(cgSettings.tag, "Compass' accuracy is low (" + accuracy + ")");
+ //Log.i(Settings.tag, "Compass' accuracy is low (" + accuracy + ")");
}
@Override
diff --git a/main/src/cgeo/geocaching/cgDirectionImg.java b/main/src/cgeo/geocaching/cgDirectionImg.java
index d8c7d06..c0a37b0 100644
--- a/main/src/cgeo/geocaching/cgDirectionImg.java
+++ b/main/src/cgeo/geocaching/cgDirectionImg.java
@@ -26,14 +26,14 @@ public class cgDirectionImg {
}
if (StringUtils.isNotBlank(geocode)) {
- dirName = cgSettings.getStorage() + geocode + "/";
- fileName = cgSettings.getStorage() + geocode + "/direction.png";
+ dirName = Settings.getStorage() + geocode + "/";
+ fileName = Settings.getStorage() + geocode + "/direction.png";
} else {
return;
}
File dir = null;
- dir = new File(cgSettings.getStorage());
+ dir = new File(Settings.getStorage());
if (dir.exists() == false) {
dir.mkdirs();
}
@@ -52,7 +52,7 @@ public class cgDirectionImg {
for (int i = 0; i < 3; i++) {
if (i > 0)
- Log.w(cgSettings.tag, "cgDirectionImg.getDrawable: Failed to download data, retrying. Attempt #" + (i + 1));
+ Log.w(Settings.tag, "cgDirectionImg.getDrawable: Failed to download data, retrying. Attempt #" + (i + 1));
try {
client = new DefaultHttpClient();
@@ -61,7 +61,7 @@ public class cgDirectionImg {
entity = httpResponse.getEntity();
final BufferedHttpEntity bufferedEntity = new BufferedHttpEntity(entity);
- Log.i(cgSettings.tag, "[" + entity.getContentLength() + "B] Downloading direction image " + code);
+ Log.i(Settings.tag, "[" + entity.getContentLength() + "B] Downloading direction image " + code);
InputStream is = (InputStream) bufferedEntity.getContent();
FileOutputStream fos = new FileOutputStream(fileName);
@@ -75,7 +75,7 @@ public class cgDirectionImg {
ok = true;
fos.flush();
} catch (IOException e) {
- Log.e(cgSettings.tag, "cgDirectionImg.getDrawable (saving to cache): " + e.toString());
+ Log.e(Settings.tag, "cgDirectionImg.getDrawable (saving to cache): " + e.toString());
} finally {
is.close();
fos.close();
@@ -85,7 +85,7 @@ public class cgDirectionImg {
break;
}
} catch (Exception e) {
- Log.e(cgSettings.tag, "cgDirectionImg.getDrawable (downloading from web): " + e.toString());
+ Log.e(Settings.tag, "cgDirectionImg.getDrawable (downloading from web): " + e.toString());
}
}
}
diff --git a/main/src/cgeo/geocaching/cgGPXListAdapter.java b/main/src/cgeo/geocaching/cgGPXListAdapter.java
index 5db046c..92d701f 100644
--- a/main/src/cgeo/geocaching/cgGPXListAdapter.java
+++ b/main/src/cgeo/geocaching/cgGPXListAdapter.java
@@ -28,7 +28,7 @@ public class cgGPXListAdapter extends ArrayAdapter<File> {
inflater = ((Activity) getContext()).getLayoutInflater();
if (position > getCount()) {
- Log.w(cgSettings.tag, "cgGPXListAdapter.getView: Attempt to access missing item #" + position);
+ Log.w(Settings.tag, "cgGPXListAdapter.getView: Attempt to access missing item #" + position);
return null;
}
diff --git a/main/src/cgeo/geocaching/cgGeo.java b/main/src/cgeo/geocaching/cgGeo.java
index c5cc7a0..79c04fa 100644
--- a/main/src/cgeo/geocaching/cgGeo.java
+++ b/main/src/cgeo/geocaching/cgGeo.java
@@ -25,7 +25,6 @@ public class cgGeo {
private LocationManager geoManager = null;
private cgUpdateLoc geoUpdate = null;
private cgBase base = null;
- private cgSettings settings = null;
private SharedPreferences prefs = null;
private cgeoGeoListener geoNetListener = null;
private cgeoGeoListener geoGpsListener = null;
@@ -49,24 +48,23 @@ public class cgGeo {
public Integer satellitesFixed = null;
public double distanceNow = 0d;
- public cgGeo(Context contextIn, cgeoapplication appIn, cgUpdateLoc geoUpdateIn, cgBase baseIn, cgSettings settingsIn, int timeIn, int distanceIn) {
+ public cgGeo(Context contextIn, cgeoapplication appIn, cgUpdateLoc geoUpdateIn, cgBase baseIn, int timeIn, int distanceIn) {
context = contextIn;
app = appIn;
geoUpdate = geoUpdateIn;
base = baseIn;
- settings = settingsIn;
time = timeIn;
distance = distanceIn;
if (prefs == null) {
- prefs = context.getSharedPreferences(cgSettings.preferences, 0);
+ prefs = context.getSharedPreferences(Settings.preferences, 0);
}
distanceNow = prefs.getFloat("dst", 0f);
if (Double.isNaN(distanceNow)) {
distanceNow = 0d;
}
if (distanceNow == 0f) {
- final SharedPreferences.Editor prefsEdit = context.getSharedPreferences(cgSettings.preferences, 0).edit();
+ final SharedPreferences.Editor prefsEdit = context.getSharedPreferences(Settings.preferences, 0).edit();
if (prefsEdit != null) {
prefsEdit.putLong("dst-since", System.currentTimeMillis());
prefsEdit.commit();
@@ -106,13 +104,13 @@ public class cgGeo {
try {
geoManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, time, distance, geoNetListener);
} catch (Exception e) {
- Log.e(cgSettings.tag, "There is no NETWORK location provider");
+ Log.e(Settings.tag, "There is no NETWORK location provider");
}
try {
geoManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, time, distance, geoGpsListener);
} catch (Exception e) {
- Log.e(cgSettings.tag, "There is no GPS location provider");
+ Log.e(Settings.tag, "There is no GPS location provider");
}
}
@@ -127,7 +125,7 @@ public class cgGeo {
geoManager.removeGpsStatusListener(geoGpsStatusListener);
}
- final SharedPreferences.Editor prefsEdit = context.getSharedPreferences(cgSettings.preferences, 0).edit();
+ final SharedPreferences.Editor prefsEdit = context.getSharedPreferences(Settings.preferences, 0).edit();
if (prefsEdit != null && Double.isNaN(distanceNow) == false) {
prefsEdit.putFloat("dst", (float) distanceNow);
prefsEdit.commit();
@@ -229,9 +227,9 @@ public class cgGeo {
/*
* satellite signal strength
* if (sat.usedInFix()) {
- * Log.d(cgSettings.tag, "Sat #" + satellites + ": " + sat.getSnr() + " FIX");
+ * Log.d(Settings.tag, "Sat #" + satellites + ": " + sat.getSnr() + " FIX");
* } else {
- * Log.d(cgSettings.tag, "Sat #" + satellites + ": " + sat.getSnr());
+ * Log.d(Settings.tag, "Sat #" + satellites + ": " + sat.getSnr());
* }
*/
}
@@ -320,7 +318,7 @@ public class cgGeo {
app.setLastLoc(coordsNow);
if (location.hasAltitude() && gps != -1) {
- altitudeNow = location.getAltitude() + settings.altCorrection;
+ altitudeNow = location.getAltitude() + Settings.getAltCorrection();
} else {
altitudeNow = null;
}
@@ -376,7 +374,7 @@ public class cgGeo {
return;
}
- if (settings.publicLoc == 1 && (lastGo4cacheCoords == null || coordsNow.distanceTo(lastGo4cacheCoords) > 0.75)) {
+ if (Settings.isPublicLoc() && (lastGo4cacheCoords == null || coordsNow.distanceTo(lastGo4cacheCoords) > 0.75)) {
g4cRunning = true;
String action = null;
@@ -386,7 +384,7 @@ public class cgGeo {
action = "";
}
- final String username = settings.getUsername();
+ final String username = Settings.getUsername();
if (username != null) {
final Parameters params = new Parameters();
final String latStr = String.format((Locale) null, "%.6f", coordsNow.getLatitude());
@@ -420,7 +418,7 @@ public class cgGeo {
lastGps.setProvider("last");
assign(lastGps);
- Log.i(cgSettings.tag, "Using last location from GPS");
+ Log.i(Settings.tag, "Using last location from GPS");
return;
}
@@ -430,7 +428,7 @@ public class cgGeo {
lastGsm.setProvider("last");
assign(lastGsm);
- Log.i(cgSettings.tag, "Using last location from NETWORK");
+ Log.i(Settings.tag, "Using last location from NETWORK");
return;
}
}
diff --git a/main/src/cgeo/geocaching/cgHtmlImg.java b/main/src/cgeo/geocaching/cgHtmlImg.java
index a21dda0..6448576 100644
--- a/main/src/cgeo/geocaching/cgHtmlImg.java
+++ b/main/src/cgeo/geocaching/cgHtmlImg.java
@@ -84,17 +84,17 @@ public class cgHtmlImg implements Html.ImageGetter {
}
if (StringUtils.isNotBlank(geocode)) {
- dirName = cgSettings.getStorage() + geocode + "/";
- fileName = cgSettings.getStorage() + geocode + "/" + CryptUtils.md5(url) + urlExt;
- fileNameSec = cgSettings.getStorageSec() + geocode + "/" + CryptUtils.md5(url) + urlExt;
+ dirName = Settings.getStorage() + geocode + "/";
+ fileName = Settings.getStorage() + geocode + "/" + CryptUtils.md5(url) + urlExt;
+ fileNameSec = Settings.getStorageSec() + geocode + "/" + CryptUtils.md5(url) + urlExt;
} else {
- dirName = cgSettings.getStorage() + "_others/";
- fileName = cgSettings.getStorage() + "_others/" + CryptUtils.md5(url) + urlExt;
- fileNameSec = cgSettings.getStorageSec() + "_others/" + CryptUtils.md5(url) + urlExt;
+ dirName = Settings.getStorage() + "_others/";
+ fileName = Settings.getStorage() + "_others/" + CryptUtils.md5(url) + urlExt;
+ fileNameSec = Settings.getStorageSec() + "_others/" + CryptUtils.md5(url) + urlExt;
}
File dir = null;
- dir = new File(cgSettings.getStorage());
+ dir = new File(Settings.getStorage());
if (dir.exists() == false) {
dir.mkdirs();
}
@@ -155,7 +155,7 @@ public class cgHtmlImg implements Html.ImageGetter {
}
}
} catch (Exception e) {
- Log.w(cgSettings.tag, "cgHtmlImg.getDrawable (reading cache): " + e.toString());
+ Log.w(Settings.tag, "cgHtmlImg.getDrawable (reading cache): " + e.toString());
}
}
@@ -173,13 +173,13 @@ public class cgHtmlImg implements Html.ImageGetter {
url = "http://" + connector.getHost() + url;
}
} catch (Exception e) {
- Log.e(cgSettings.tag, "cgHtmlImg.getDrawable (parse URL): " + e.toString());
+ Log.e(Settings.tag, "cgHtmlImg.getDrawable (parse URL): " + e.toString());
}
if (uri != null) {
for (int i = 0; i < 2; i++) {
if (i > 0) {
- Log.w(cgSettings.tag, "cgHtmlImg.getDrawable: Failed to download data, retrying. Attempt #" + (i + 1));
+ Log.w(Settings.tag, "cgHtmlImg.getDrawable: Failed to download data, retrying. Attempt #" + (i + 1));
}
try {
@@ -216,7 +216,7 @@ public class cgHtmlImg implements Html.ImageGetter {
break;
}
} catch (Exception e) {
- Log.e(cgSettings.tag, "cgHtmlImg.getDrawable (downloading from web)", e);
+ Log.e(Settings.tag, "cgHtmlImg.getDrawable (downloading from web)", e);
}
}
}
@@ -243,7 +243,7 @@ public class cgHtmlImg implements Html.ImageGetter {
}
}
} catch (IOException e) {
- Log.e(cgSettings.tag, "cgHtmlImg.getDrawable (saving to cache)", e);
+ Log.e(Settings.tag, "cgHtmlImg.getDrawable (saving to cache)", e);
}
}
}
@@ -254,7 +254,7 @@ public class cgHtmlImg implements Html.ImageGetter {
// get image and return
if (imagePre == null) {
- Log.d(cgSettings.tag, "cgHtmlImg.getDrawable: Failed to obtain image");
+ Log.d(Settings.tag, "cgHtmlImg.getDrawable: Failed to obtain image");
if (placement == false) {
imagePre = BitmapFactory.decodeResource(activity.getResources(), R.drawable.image_no_placement);
@@ -283,7 +283,7 @@ public class cgHtmlImg implements Html.ImageGetter {
try {
imagePre = Bitmap.createScaledBitmap(imagePre, width, height, true);
} catch (Exception e) {
- Log.d(cgSettings.tag, "cgHtmlImg.getDrawable: Failed to scale image");
+ Log.d(Settings.tag, "cgHtmlImg.getDrawable: Failed to scale image");
return null;
}
} else {
diff --git a/main/src/cgeo/geocaching/cgMapfileListAdapter.java b/main/src/cgeo/geocaching/cgMapfileListAdapter.java
index 89cb1f5..e52e517 100644
--- a/main/src/cgeo/geocaching/cgMapfileListAdapter.java
+++ b/main/src/cgeo/geocaching/cgMapfileListAdapter.java
@@ -30,7 +30,7 @@ public class cgMapfileListAdapter extends ArrayAdapter<File> {
inflater = ((Activity) getContext()).getLayoutInflater();
if (position > getCount()) {
- Log.w(cgSettings.tag, "cgGPXListAdapter.getView: Attempt to access missing item #" + position);
+ Log.w(Settings.tag, "cgGPXListAdapter.getView: Attempt to access missing item #" + position);
return null;
}
diff --git a/main/src/cgeo/geocaching/cgOAuth.java b/main/src/cgeo/geocaching/cgOAuth.java
index 6e84408..4f0036e 100644
--- a/main/src/cgeo/geocaching/cgOAuth.java
+++ b/main/src/cgeo/geocaching/cgOAuth.java
@@ -17,7 +17,7 @@ public class cgOAuth {
currentTime = currentTime / 1000; // seconds
currentTime = (long) Math.floor(currentTime);
- params.put("oauth_consumer_key", cgSettings.keyConsumerPublic);
+ params.put("oauth_consumer_key", Settings.getKeyConsumerPublic());
params.put("oauth_nonce", CryptUtils.md5(Long.toString(System.currentTimeMillis())));
params.put("oauth_signature_method", "HMAC-SHA1");
params.put("oauth_timestamp", Long.toString(currentTime));
@@ -31,7 +31,7 @@ public class cgOAuth {
paramsEncoded.add(nameValue.getName() + "=" + cgBase.urlencode_rfc3986(nameValue.getValue()));
}
- final String keysPacked = cgSettings.keyConsumerSecret + "&" + StringUtils.defaultString(tokenSecret); // both even if empty some of them!
+ final String keysPacked = Settings.getKeyConsumerSecret() + "&" + StringUtils.defaultString(tokenSecret); // both even if empty some of them!
final String requestPacked = method + "&" + cgBase.urlencode_rfc3986((https ? "https" : "http") + "://" + host + path) + "&" + cgBase.urlencode_rfc3986(StringUtils.join(paramsEncoded.toArray(), '&'));
paramsEncoded.add("oauth_signature=" + cgBase.urlencode_rfc3986(cgBase.base64Encode(CryptUtils.hashHmac(requestPacked, keysPacked))));
diff --git a/main/src/cgeo/geocaching/cgSearchHandler.java b/main/src/cgeo/geocaching/cgSearchHandler.java
index 4fc6200..8e8dffd 100644
--- a/main/src/cgeo/geocaching/cgSearchHandler.java
+++ b/main/src/cgeo/geocaching/cgSearchHandler.java
@@ -98,7 +98,7 @@ public class cgSearchHandler extends Handler {
imgHandler.sendEmptyMessage(0);
} catch (IOException e) {
- Log.e(cgSettings.tag, "Failed to download reCAPTCHA image");
+ Log.e(Settings.tag, "Failed to download reCAPTCHA image");
}
}
}
diff --git a/main/src/cgeo/geocaching/cgSearchThread.java b/main/src/cgeo/geocaching/cgSearchThread.java
index 732275c..0d802f3 100644
--- a/main/src/cgeo/geocaching/cgSearchThread.java
+++ b/main/src/cgeo/geocaching/cgSearchThread.java
@@ -22,7 +22,7 @@ public class cgSearchThread extends Thread {
try {
wait();
} catch (InterruptedException e) {
- Log.w(cgSettings.tag, "searchThread is not waiting for user...");
+ Log.w(Settings.tag, "searchThread is not waiting for user...");
}
}
diff --git a/main/src/cgeo/geocaching/cgSelectMapfile.java b/main/src/cgeo/geocaching/cgSelectMapfile.java
index 921987c..6210c61 100644
--- a/main/src/cgeo/geocaching/cgSelectMapfile.java
+++ b/main/src/cgeo/geocaching/cgSelectMapfile.java
@@ -20,8 +20,7 @@ public class cgSelectMapfile extends FileList<cgMapfileListAdapter> {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
-
- mapFile = getSettings().getMapFile();
+ mapFile = Settings.getMapFile();
}
public void close() {
diff --git a/main/src/cgeo/geocaching/cgSettings.java b/main/src/cgeo/geocaching/cgSettings.java
deleted file mode 100644
index 32af792..0000000
--- a/main/src/cgeo/geocaching/cgSettings.java
+++ /dev/null
@@ -1,644 +0,0 @@
-package cgeo.geocaching;
-
-import cgeo.geocaching.maps.google.GoogleMapFactory;
-import cgeo.geocaching.maps.interfaces.MapFactory;
-import cgeo.geocaching.maps.mapsforge.MapsforgeMapFactory;
-
-import org.apache.commons.lang3.StringUtils;
-import org.apache.commons.lang3.tuple.ImmutablePair;
-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 java.util.HashMap;
-import java.util.Locale;
-import java.util.Map;
-
-/**
- * General c:geo preferences/settings set by the user
- */
-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 static final String KEY_COORD_INPUT_FORMAT = "coordinputformat";
- private static final String KEY_LOG_OFFLINE = "log_offline";
- private static final String KEY_LOAD_DIRECTION_IMG = "loaddirectionimg";
- private static final String KEY_GC_CUSTOM_DATE = "gccustomdate";
- private static final String KEY_SHOW_WAYPOINTS_THRESHOLD = "gcshowwaypointsthreshold";
-
- private interface PrefRunnable {
- void edit(final Editor edit);
- }
-
- public enum mapSourceEnum {
- googleMap,
- googleSat,
- mapsforgeMapnik,
- mapsforgeOsmarender,
- mapsforgeCycle,
- mapsforgeOffline;
-
- static mapSourceEnum fromInt(int id) {
- mapSourceEnum[] values = mapSourceEnum.values();
- if (id >= 0 && id < values.length) {
- return values[id];
- } else {
- return googleMap;
- }
- }
-
- public boolean isGoogleMapSource() {
- if (googleMap == this || googleSat == this) {
- return true;
- }
-
- return false;
- }
- }
-
- public enum coordInputFormatEnum {
- Plain,
- Deg,
- Min,
- Sec;
-
- static coordInputFormatEnum fromInt(int id) {
- coordInputFormatEnum[] values = coordInputFormatEnum.values();
- if (id >= 0 && id < values.length) {
- return values[id];
- } else {
- return Min;
- }
- }
- }
-
- // constants
- public final static int unitsMetric = 1;
- public final static int unitsImperial = 2;
- public final static String cache = ".cgeo";
-
- // twitter api keys
- public final static String keyConsumerPublic = "RFafPiNi3xRhcS1TPE3wTw";
- public final static String keyConsumerSecret = "7iDJprNPI9hzRwWhpzycSr9SPZMFrdVdsxD2OauI9k";
-
- // version
- public int version = 0;
-
- // skin
- public int skin = 0;
-
- // settings
- public int helper = 0;
- public int initialized = 0;
- public int autoLoadDesc = 0;
- public int units = unitsMetric;
- public int livelist = 1;
- public int mapzoom = 14;
- public int maplive = 1;
- public int maptrail = 1;
- public boolean useEnglish = false;
- public boolean showCaptcha = false;
- // public int excludeMine = 0;
- public int excludeDisabled = 0;
- public int storeOfflineMaps = 0;
- public boolean storelogimages = false;
- // public int asBrowser = 1;
- public int useCompass = 1;
- public int useGNavigation = 1;
- public int showAddress = 1;
- public int publicLoc = 0;
- public int twitter = 0;
- public int altCorrection = 0;
- public String cacheType = null;
- public String tokenPublic = null;
- public String tokenSecret = null;
- public String webDeviceName = null;
- public String webDeviceCode = null;
- public boolean trackableAutovisit = false;
- public boolean signatureAutoinsert = false;
-
- // usable values
- public static final String tag = "cgeo";
-
- /** Name of the preferences file */
- public static final String preferences = "cgeo.pref";
-
- // private variables
- private Context context = null;
- private SharedPreferences prefs = null;
- /**
- * FIXME: this static instance of the preferences is only needed as long as the cgSettings class has
- * not yet been reworked to a singleton. It makes it possible to gradually rework all preference access methods
- * to be static.
- */
- private static SharedPreferences sharedPrefs = null;
- private String username = null;
- private String password = null;
- private coordInputFormatEnum coordInput = coordInputFormatEnum.Plain;
-
- // maps
- public MapFactory mapFactory = null;
- public mapSourceEnum mapSourceUsed = mapSourceEnum.googleMap;
- public mapSourceEnum mapSource = mapSourceEnum.googleMap;
- private String mapFile = null;
- private boolean mapFileValid = false;
- public int showWaypointsthreshold = 0;
-
- public cgSettings(Context contextIn, SharedPreferences prefsIn) {
- context = contextIn;
- prefs = prefsIn;
- sharedPrefs = prefsIn;
-
- load();
- }
-
- public void load() {
- version = prefs.getInt(KEY_VERSION, 0);
-
- initialized = prefs.getInt(KEY_INITIALIZED, 0);
- helper = prefs.getInt("helper", 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);
- excludeDisabled = prefs.getInt(KEY_EXCLUDE_DISABLED, 0);
- storeOfflineMaps = prefs.getInt("offlinemaps", 1);
- storelogimages = prefs.getBoolean(KEY_STORE_LOG_IMAGES, false);
- 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(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(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);
- coordInput = coordInputFormatEnum.fromInt(prefs.getInt(KEY_COORD_INPUT_FORMAT, 0));
- showWaypointsthreshold = prefs.getInt(KEY_SHOW_WAYPOINTS_THRESHOLD, 0);
-
- setLanguage(useEnglish);
- }
-
- public void setSkin(final int skin) {
- this.skin = skin;
- }
-
- public void setLanguage(boolean useEnglish) {
- Locale locale = Locale.getDefault();
- if (useEnglish) {
- locale = new Locale("en");
- }
- Configuration config = new Configuration();
- config.locale = locale;
- context.getResources().updateConfiguration(config,
- context.getResources().getDisplayMetrics());
- }
-
- public void reloadTwitterTokens() {
- tokenPublic = prefs.getString(KEY_TWITTER_TOKEN_PUBLIC, null);
- tokenSecret = prefs.getString(KEY_TWITTER_TOKEN_SECRET, null);
- }
-
- public void reloadCacheType() {
- cacheType = prefs.getString(KEY_CACHE_TYPE, null);
- }
-
- public static String getStorage() {
- return getStorageSpecific()[0];
- }
-
- public static String getStorageSec() {
- return getStorageSpecific()[1];
- }
-
- public static String[] getStorageSpecific() {
- String external = Environment.getExternalStorageDirectory() + "/" + cache + "/";
- String data = Environment.getDataDirectory() + "/data/cgeo.geocaching/" + cache + "/";
-
- if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
- return new String[] { external, data };
- } else {
- return new String[] { data, external };
- }
- }
-
- public static boolean isLogin() {
- final String preUsername = sharedPrefs.getString(KEY_USERNAME, null);
- final String prePassword = sharedPrefs.getString(KEY_PASSWORD, null);
-
- return (!StringUtils.isBlank(preUsername) && !StringUtils.isBlank(prePassword));
- }
-
- /**
- * Get login and password information.
- *
- * @return a pair (login, password) or null if no valid information is stored
- */
- public ImmutablePair<String, String> getLogin() {
- if (username == null || 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(KEY_INITIALIZED, 1);
- prefsEdit.commit();
-
- initialized = 1;
-
- return null;
- } else if (initialized == 1 && (preUsername == null || prePassword == null)) {
- return null;
- }
-
- username = preUsername;
- password = prePassword;
- }
- return new ImmutablePair<String, String>(username, password);
- }
-
- public String getUsername() {
- if (username == null) {
- return prefs.getString(KEY_USERNAME, null);
- } else {
- return username;
- }
- }
-
- public boolean setLogin(final String username, final String password) {
- this.username = username;
- this.password = password;
- return editSettings(new PrefRunnable() {
-
- @Override
- public void edit(Editor edit) {
- if (StringUtils.isBlank(username) || StringUtils.isBlank(password)) {
- // 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(KEY_USERNAME, null);
- final String prePassword = prefs.getString(KEY_GCVOTE_PASSWORD, null);
-
- if (StringUtils.isBlank(preUsername) || StringUtils.isBlank(prePassword)) {
- return false;
- } else {
- return true;
- }
- }
-
- public boolean setGCvoteLogin(final String password) {
- return editSettings(new PrefRunnable() {
-
- @Override
- public void edit(Editor edit) {
- if (StringUtils.isBlank(password)) {
- // erase password
- edit.remove(KEY_GCVOTE_PASSWORD);
- } else {
- // save password
- edit.putString(KEY_GCVOTE_PASSWORD, password);
- }
- }
- });
- }
-
- public static Map<String, String> getGCvoteLogin() {
- final String preUsername = sharedPrefs.getString(KEY_USERNAME, null);
- final String prePassword = sharedPrefs.getString(KEY_GCVOTE_PASSWORD, null);
-
- if (StringUtils.isBlank(preUsername) || StringUtils.isBlank(prePassword)) {
- return null;
- }
- final Map<String, String> login = new HashMap<String, String>();
-
- login.put(KEY_USERNAME, preUsername);
- login.put(KEY_PASSWORD, prePassword);
-
- return login;
- }
-
- public boolean setSignature(final String signature) {
- return editSettings(new PrefRunnable() {
-
- @Override
- public void edit(Editor edit) {
- if (StringUtils.isBlank(signature)) {
- // erase signature
- edit.remove(KEY_SIGNATURE);
- } else {
- // save signature
- edit.putString(KEY_SIGNATURE, signature);
- }
- }
- });
- }
-
- public String getSignature() {
- return prefs.getString(KEY_SIGNATURE, null);
- }
-
- public boolean setAltCorrection(final int altitude) {
- altCorrection = altitude;
- return editSettings(new PrefRunnable() {
-
- @Override
- public void edit(Editor edit) {
- edit.putInt(KEY_ALTITUDE_CORRECTION, altitude);
- }
- });
- }
-
- public String setCacheType(final String cacheTypeIn) {
- editSettings(new PrefRunnable() {
- @Override
- public void edit(Editor edit) {
- edit.putString(KEY_CACHE_TYPE, cacheTypeIn);
- }
- });
-
- cacheType = cacheTypeIn;
-
- return cacheType;
- }
-
- public void liveMapEnable() {
- if (editSettings(new PrefRunnable() {
-
- @Override
- public void edit(Editor edit) {
- edit.putInt(KEY_MAP_LIVE, 1);
- }
- })) {
- maplive = 1;
- }
- }
-
- public void liveMapDisable() {
- if (editSettings(new PrefRunnable() {
-
- @Override
- public void edit(Editor edit) {
- edit.putInt(KEY_MAP_LIVE, 0);
- }
- })) {
- maplive = 0;
- }
- }
-
- public int getLastList() {
- int listId = prefs.getInt(KEY_LAST_USED_LIST, -1);
-
- return listId;
- }
-
- public void saveLastList(final int listId) {
- editSettings(new PrefRunnable() {
-
- @Override
- public void edit(Editor edit) {
- edit.putInt(KEY_LAST_USED_LIST, listId);
- }
- });
- }
-
- public void setWebNameCode(final String name, final String code) {
- if (editSettings(new PrefRunnable() {
-
- @Override
- public void edit(Editor edit) {
-
- edit.putString(KEY_WEBDEVICE_NAME, name);
- edit.putString(KEY_WEB_DEVICE_CODE, code);
- }
- })) {
- webDeviceCode = code;
- webDeviceName = name;
- }
- }
-
- public MapFactory getMapFactory() {
- if (mapSource.isGoogleMapSource()) {
- if (!mapSourceUsed.isGoogleMapSource() || mapFactory == null) {
- mapFactory = new GoogleMapFactory();
- mapSourceUsed = mapSource;
- }
- } else if (!mapSource.isGoogleMapSource()) {
- if (mapSourceUsed.isGoogleMapSource() || mapFactory == null) {
- mapFactory = new MapsforgeMapFactory();
- mapSourceUsed = mapSource;
- }
- }
-
- return mapFactory;
- }
-
- public String getMapFile() {
- return mapFile;
- }
-
- public boolean setMapFile(final String mapFileIn) {
- boolean commitResult = editSettings(new PrefRunnable() {
-
- @Override
- public void edit(Editor edit) {
- edit.putString(KEY_MAPFILE, mapFileIn);
- }
- });
-
- mapFile = mapFileIn;
- mapFileValid = checkMapfile(mapFile);
-
- return commitResult;
- }
-
- public boolean hasValidMapFile() {
- return mapFileValid;
- }
-
- private static boolean checkMapfile(String mapFileIn) {
- if (null == mapFileIn) {
- return false;
- }
- return MapDatabase.isValidMapFile(mapFileIn);
- }
-
- public coordInputFormatEnum getCoordInputFormat() {
- return coordInput;
- }
-
- public boolean setCoordInputFormat(coordInputFormatEnum format) {
- coordInput = format;
- boolean commitResult = editSettings(new PrefRunnable() {
-
- @Override
- public void edit(Editor edit) {
- edit.putInt(KEY_COORD_INPUT_FORMAT, coordInput.ordinal());
- }
- });
- return commitResult;
- }
-
- /**
- * 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();
- }
-
- void setLogOffline(final boolean offline) {
- editSettings(new PrefRunnable() {
-
- @Override
- public void edit(Editor edit) {
- edit.putBoolean(KEY_LOG_OFFLINE, offline);
- }
- });
- }
-
- public boolean getLogOffline() {
- return prefs.getBoolean(KEY_LOG_OFFLINE, false);
- }
-
- void setLoadDirImg(final boolean value) {
- editSettings(new PrefRunnable() {
-
- @Override
- public void edit(Editor edit) {
- edit.putBoolean(KEY_LOAD_DIRECTION_IMG, value);
- }
- });
- }
-
- public boolean getLoadDirImg() {
- return prefs.getBoolean(KEY_LOAD_DIRECTION_IMG, true);
- }
-
- void setGcCustomDate(final String format) {
- editSettings(new PrefRunnable() {
-
- @Override
- public void edit(Editor edit) {
- edit.putString(KEY_GC_CUSTOM_DATE, format);
- }
- });
- }
-
- public String getGcCustomDate() {
- return prefs.getString(KEY_GC_CUSTOM_DATE, null);
- }
-
- public void setShowWaypointsThreshold(int parseInt) {
- showWaypointsthreshold = parseInt;
- editSettings(new PrefRunnable() {
-
- @Override
- public void edit(Editor edit) {
- edit.putInt(KEY_SHOW_WAYPOINTS_THRESHOLD, showWaypointsthreshold);
- }
- });
- }
-
- public static boolean asBrowser() {
- return sharedPrefs.getInt(KEY_AS_BROWSER, 1) == 1;
- }
-
- public static boolean getExcludeMine() {
- return sharedPrefs.getInt(KEY_EXCLUDE_OWN, 0) == 1;
- }
-
- private static boolean editSharedSettings(final PrefRunnable runnable) {
- final SharedPreferences.Editor prefsEdit = sharedPrefs.edit();
- runnable.edit(prefsEdit);
- return prefsEdit.commit();
- }
-
- public static void setExcludeMine(final boolean exclude) {
- editSharedSettings(new PrefRunnable() {
-
- @Override
- public void edit(Editor edit) {
- edit.putInt(KEY_EXCLUDE_OWN, exclude ? 1 : 0);
- }
- });
- }
-
- public static void setAsBrowser(final boolean asBrowser) {
- editSharedSettings(new PrefRunnable() {
-
- @Override
- public void edit(Editor edit) {
- edit.putInt(KEY_AS_BROWSER, asBrowser ? 1 : 0);
- }
- });
- }
-}
diff --git a/main/src/cgeo/geocaching/cgeo.java b/main/src/cgeo/geocaching/cgeo.java
index 66f7340..74456c8 100644
--- a/main/src/cgeo/geocaching/cgeo.java
+++ b/main/src/cgeo/geocaching/cgeo.java
@@ -80,7 +80,7 @@ public class cgeo extends AbstractActivity {
countBubble.setVisibility(View.VISIBLE);
}
} catch (Exception e) {
- Log.w(cgSettings.tag, "cgeo.countBubbleHander: " + e.toString());
+ Log.w(Settings.tag, "cgeo.countBubbleHander: " + e.toString());
}
}
};
@@ -135,7 +135,7 @@ public class cgeo extends AbstractActivity {
showToast(res.getString(R.string.err_login_failed_toast));
}
} catch (Exception e) {
- Log.w(cgSettings.tag, "cgeo.fisrtLoginHander: " + e.toString());
+ Log.w(Settings.tag, "cgeo.fisrtLoginHander: " + e.toString());
}
}
};
@@ -163,16 +163,16 @@ public class cgeo extends AbstractActivity {
version = info.versionCode;
- Log.i(cgSettings.tag, "Starting " + info.packageName + " " + info.versionCode + " a.k.a " + info.versionName + "...");
+ Log.i(Settings.tag, "Starting " + info.packageName + " " + info.versionCode + " a.k.a " + info.versionName + "...");
info = null;
manager = null;
} catch (Exception e) {
- Log.i(cgSettings.tag, "No info.");
+ Log.i(Settings.tag, "No info.");
}
try {
- if (settings.helper == 0) {
+ if (!Settings.isHelpShown()) {
RelativeLayout helper = (RelativeLayout) findViewById(R.id.helper);
if (helper != null) {
helper.setVisibility(View.VISIBLE);
@@ -184,10 +184,7 @@ public class cgeo extends AbstractActivity {
view.setVisibility(View.GONE);
}
});
-
- final SharedPreferences.Editor edit = getSharedPreferences(cgSettings.preferences, 0).edit();
- edit.putInt("helper", 1);
- edit.commit();
+ Settings.setHelpShown();
}
}
} catch (Exception e) {
@@ -208,7 +205,6 @@ public class cgeo extends AbstractActivity {
public void onResume() {
super.onResume();
- settings.load();
init();
}
@@ -365,8 +361,8 @@ public class cgeo extends AbstractActivity {
menu.setGroupCheckable(1, true, true);
boolean foundItem = false;
int itemCount = menu.size();
- if (settings.cacheType != null) {
- String typeTitle = cgBase.cacheTypesInv.get(settings.cacheType);
+ if (Settings.getCacheType() != null) {
+ String typeTitle = cgBase.cacheTypesInv.get(Settings.getCacheType());
if (typeTitle != null) {
for (int i = 0; i < itemCount; i++) {
if (menu.getItem(i).getTitle().equals(typeTitle)) {
@@ -387,13 +383,13 @@ public class cgeo extends AbstractActivity {
final int id = item.getItemId();
if (id == 0) {
- settings.setCacheType(null);
+ Settings.setCacheType(null);
setFilterTitle();
return true;
} else if (id > MENU_OPEN_LIST) {
int listId = id - MENU_OPEN_LIST;
- settings.saveLastList(listId);
+ Settings.saveLastList(listId);
cgeocaches.startActivityOffline(context);
return true;
} else if (id > 0) {
@@ -406,9 +402,9 @@ public class cgeo extends AbstractActivity {
}
}
if (choice == null) {
- settings.setCacheType(null);
+ Settings.setCacheType(null);
} else {
- settings.setCacheType(choice);
+ Settings.setCacheType(choice);
}
setFilterTitle();
@@ -422,8 +418,8 @@ public class cgeo extends AbstractActivity {
if (filterTitle == null) {
filterTitle = (TextView) findViewById(R.id.filter_button_title);
}
- if (settings.cacheType != null) {
- filterTitle.setText(cgBase.cacheTypesInv.get(settings.cacheType));
+ if (Settings.getCacheType() != null) {
+ filterTitle.setText(cgBase.cacheTypesInv.get(Settings.getCacheType()));
} else {
filterTitle.setText(res.getString(R.string.all));
}
@@ -444,8 +440,7 @@ public class cgeo extends AbstractActivity {
initialized = true;
- settings.getLogin();
- settings.reloadCacheType();
+ Settings.getLogin();
if (app.firstRun) {
(new firstLogin()).start();
@@ -454,12 +449,12 @@ public class cgeo extends AbstractActivity {
(new countBubbleUpdate()).start();
(new cleanDatabase()).start();
- if (settings.cacheType != null && cgBase.cacheTypesInv.containsKey(settings.cacheType) == false) {
- settings.setCacheType(null);
+ if (Settings.getCacheType() != null && cgBase.cacheTypesInv.containsKey(Settings.getCacheType()) == false) {
+ Settings.setCacheType(null);
}
if (geo == null) {
- geo = app.startGeo(context, geoUpdate, base, settings, 0, 0);
+ geo = app.startGeo(context, geoUpdate, base, 0, 0);
}
navType = (TextView) findViewById(R.id.nav_type);
@@ -558,16 +553,16 @@ public class cgeo extends AbstractActivity {
}
if (geo.accuracyNow != null) {
- if (settings.units == cgSettings.unitsImperial) {
- navAccuracy.setText("±" + String.format(Locale.getDefault(), "%.0f", (geo.accuracyNow * 3.2808399)) + " ft");
- } else {
+ if (Settings.isUseMetricUnits()) {
navAccuracy.setText("±" + String.format(Locale.getDefault(), "%.0f", geo.accuracyNow) + " m");
+ } else {
+ navAccuracy.setText("±" + String.format(Locale.getDefault(), "%.0f", (geo.accuracyNow * 3.2808399)) + " ft");
}
} else {
navAccuracy.setText(null);
}
- if (settings.showAddress == 1) {
+ if (Settings.isShowAddress()) {
if (addCoords == null) {
navLocation.setText(res.getString(R.string.loc_no_addr));
}
@@ -577,10 +572,10 @@ public class cgeo extends AbstractActivity {
} else {
if (geo.altitudeNow != null) {
String humanAlt;
- if (settings.units == cgSettings.unitsImperial) {
- humanAlt = String.format("%.0f", (geo.altitudeNow * 3.2808399)) + " ft";
- } else {
+ if (Settings.isUseMetricUnits()) {
humanAlt = String.format("%.0f", geo.altitudeNow) + " m";
+ } else {
+ humanAlt = String.format("%.0f", (geo.altitudeNow * 3.2808399)) + " ft";
}
navLocation.setText(cgBase.formatCoords(geo.coordsNow, true) + " | " + humanAlt);
} else {
@@ -599,7 +594,7 @@ public class cgeo extends AbstractActivity {
navLocation.setText(res.getString(R.string.loc_trying));
}
} catch (Exception e) {
- Log.w(cgSettings.tag, "Failed to update location.");
+ Log.w(Settings.tag, "Failed to update location.");
}
}
}
@@ -610,7 +605,7 @@ public class cgeo extends AbstractActivity {
*/
public void cgeoFindOnMap(View v) {
findViewById(R.id.map).setPressed(true);
- context.startActivity(new Intent(context, settings.getMapFactory().getMapClass()));
+ context.startActivity(new Intent(context, Settings.getMapFactory().getMapClass()));
}
/**
@@ -627,7 +622,7 @@ public class cgeo extends AbstractActivity {
cachesIntent.putExtra("type", "nearest");
cachesIntent.putExtra("latitude", geo.coordsNow.getLatitude());
cachesIntent.putExtra("longitude", geo.coordsNow.getLongitude());
- cachesIntent.putExtra("cachetype", settings.cacheType);
+ cachesIntent.putExtra("cachetype", Settings.getCacheType());
context.startActivity(cachesIntent);
}
@@ -709,8 +704,8 @@ public class cgeo extends AbstractActivity {
}
boolean more = false;
- if (version != settings.version) {
- Log.i(cgSettings.tag, "Initializing hard cleanup - version changed from " + settings.version + " to " + version + ".");
+ if (version != Settings.getVersion()) {
+ Log.i(Settings.tag, "Initializing hard cleanup - version changed from " + Settings.getVersion() + " to " + version + ".");
more = true;
}
@@ -770,7 +765,7 @@ public class cgeo extends AbstractActivity {
addresses = geocoder.getFromLocation(geo.coordsNow.getLatitude(), geo.coordsNow.getLongitude(), 1);
} catch (Exception e) {
- Log.i(cgSettings.tag, "Failed to obtain address");
+ Log.i(Settings.tag, "Failed to obtain address");
}
obtainAddressHandler.sendEmptyMessage(0);
diff --git a/main/src/cgeo/geocaching/cgeoabout.java b/main/src/cgeo/geocaching/cgeoabout.java
index a335566..dff592b 100644
--- a/main/src/cgeo/geocaching/cgeoabout.java
+++ b/main/src/cgeo/geocaching/cgeoabout.java
@@ -29,7 +29,6 @@ public class cgeoabout extends AbstractActivity {
public void onResume() {
super.onResume();
- settings.load();
}
@Override
@@ -48,7 +47,7 @@ public class cgeoabout extends AbstractActivity {
((TextView) findViewById(R.id.contributors)).setMovementMethod(LinkMovementMethod.getInstance());
} catch (Exception e) {
- Log.e(cgSettings.tag, "cgeoabout.init: Failed to obtain package version.");
+ Log.e(Settings.tag, "cgeoabout.init: Failed to obtain package version.");
}
}
diff --git a/main/src/cgeo/geocaching/cgeoaddresses.java b/main/src/cgeo/geocaching/cgeoaddresses.java
index 1012997..8941fe2 100644
--- a/main/src/cgeo/geocaching/cgeoaddresses.java
+++ b/main/src/cgeo/geocaching/cgeoaddresses.java
@@ -59,7 +59,7 @@ public class cgeoaddresses extends AbstractActivity {
try {
return geocoder.getFromLocationName(keyword, 20);
} catch (Exception e) {
- Log.e(cgSettings.tag, "cgeoaddresses.doInBackground", e);
+ Log.e(Settings.tag, "cgeoaddresses.doInBackground", e);
return null;
}
}
@@ -108,7 +108,7 @@ public class cgeoaddresses extends AbstractActivity {
}
}
} catch (Exception e) {
- Log.e(cgSettings.tag, "cgeoaddresses.onPostExecute", e);
+ Log.e(Settings.tag, "cgeoaddresses.onPostExecute", e);
}
}
@@ -119,7 +119,6 @@ public class cgeoaddresses extends AbstractActivity {
public void onResume() {
super.onResume();
- settings.load();
}
private class buttonListener implements View.OnClickListener {
@@ -140,7 +139,7 @@ public class cgeoaddresses extends AbstractActivity {
addressIntent.putExtra("latitude", (Double) latitude);
addressIntent.putExtra("longitude", (Double) longitude);
addressIntent.putExtra("address", (String) address);
- addressIntent.putExtra("cachetype", settings.cacheType);
+ addressIntent.putExtra("cachetype", Settings.getCacheType());
startActivity(addressIntent);
finish();
diff --git a/main/src/cgeo/geocaching/cgeoadvsearch.java b/main/src/cgeo/geocaching/cgeoadvsearch.java
index 9e70a3a..8caf67d 100644
--- a/main/src/cgeo/geocaching/cgeoadvsearch.java
+++ b/main/src/cgeo/geocaching/cgeoadvsearch.java
@@ -77,7 +77,6 @@ public class cgeoadvsearch extends AbstractActivity {
public void onResume() {
super.onResume();
- settings.load();
init();
}
@@ -133,28 +132,27 @@ public class cgeoadvsearch extends AbstractActivity {
final Intent cachesIntent = new Intent(this, cgeocaches.class);
cachesIntent.putExtra("type", "keyword");
cachesIntent.putExtra("keyword", query);
- cachesIntent.putExtra("cachetype", settings.cacheType);
+ cachesIntent.putExtra("cachetype", Settings.getCacheType());
startActivity(cachesIntent);
found = true;
}
} catch (Exception e) {
- Log.w(cgSettings.tag, "cgeoadvsearch.instantSearch: " + e.toString());
+ Log.w(Settings.tag, "cgeoadvsearch.instantSearch: " + e.toString());
}
return found;
}
private void init() {
- settings.getLogin();
- settings.reloadCacheType();
+ Settings.getLogin();
- if (settings.cacheType != null && cgBase.cacheTypesInv.containsKey(settings.cacheType) == false) {
- settings.setCacheType(null);
+ if (Settings.getCacheType() != null && cgBase.cacheTypesInv.containsKey(Settings.getCacheType()) == false) {
+ Settings.setCacheType(null);
}
if (geo == null) {
- geo = app.startGeo(this, geoUpdate, base, settings, 0, 0);
+ geo = app.startGeo(this, geoUpdate, base, 0, 0);
}
((Button) findViewById(R.id.buttonLatitude)).setOnClickListener(new findByCoordsAction());
@@ -228,7 +226,7 @@ public class cgeoadvsearch extends AbstractActivity {
lonEdit.setHint(cgBase.formatLongitude(geo.coordsNow.getLongitude(), false));
}
} catch (Exception e) {
- Log.w(cgSettings.tag, "Failed to update location.");
+ Log.w(Settings.tag, "Failed to update location.");
}
}
}
@@ -237,7 +235,7 @@ public class cgeoadvsearch extends AbstractActivity {
@Override
public void onClick(View arg0) {
- cgeocoords coordsDialog = new cgeocoords(cgeoadvsearch.this, settings, null, geo);
+ cgeocoords coordsDialog = new cgeocoords(cgeoadvsearch.this, null, geo);
coordsDialog.setCancelable(true);
coordsDialog.setOnCoordinateUpdate(new cgeocoords.CoordinateUpdate() {
@Override
@@ -274,7 +272,7 @@ public class cgeoadvsearch extends AbstractActivity {
cachesIntent.putExtra("latitude", GeopointParser.parseLatitude(latText));
cachesIntent.putExtra("longitude", GeopointParser.parseLongitude(lonText));
cachesIntent.putExtra("type", "coordinate");
- cachesIntent.putExtra("cachetype", settings.cacheType);
+ cachesIntent.putExtra("cachetype", Settings.getCacheType());
startActivity(cachesIntent);
} catch (GeopointParser.ParseException e) {
showToast(res.getString(e.resource));
@@ -314,7 +312,7 @@ public class cgeoadvsearch extends AbstractActivity {
final Intent cachesIntent = new Intent(this, cgeocaches.class);
cachesIntent.putExtra("type", "keyword");
cachesIntent.putExtra("keyword", keyText);
- cachesIntent.putExtra("cachetype", settings.cacheType);
+ cachesIntent.putExtra("cachetype", Settings.getCacheType());
startActivity(cachesIntent);
}
@@ -382,7 +380,7 @@ public class cgeoadvsearch extends AbstractActivity {
final Intent cachesIntent = new Intent(this, cgeocaches.class);
cachesIntent.putExtra("type", "username");
cachesIntent.putExtra("username", usernameText);
- cachesIntent.putExtra("cachetype", settings.cacheType);
+ cachesIntent.putExtra("cachetype", Settings.getCacheType());
startActivity(cachesIntent);
}
@@ -414,7 +412,7 @@ public class cgeoadvsearch extends AbstractActivity {
final Intent cachesIntent = new Intent(this, cgeocaches.class);
cachesIntent.putExtra("type", "owner");
cachesIntent.putExtra("username", usernameText);
- cachesIntent.putExtra("cachetype", settings.cacheType);
+ cachesIntent.putExtra("cachetype", Settings.getCacheType());
startActivity(cachesIntent);
}
@@ -491,7 +489,7 @@ public class cgeoadvsearch extends AbstractActivity {
@Override
public boolean onOptionsItemSelected(MenuItem item) {
if (item.getItemId() == MENU_SEARCH_OWN_CACHES) {
- findByOwnerFn(settings.getUsername());
+ findByOwnerFn(Settings.getUsername());
return true;
}
return super.onOptionsItemSelected(item);
diff --git a/main/src/cgeo/geocaching/cgeoapplication.java b/main/src/cgeo/geocaching/cgeoapplication.java
index dab6b9a..6caa40d 100644
--- a/main/src/cgeo/geocaching/cgeoapplication.java
+++ b/main/src/cgeo/geocaching/cgeoapplication.java
@@ -46,14 +46,14 @@ public class cgeoapplication extends Application {
@Override
public void onLowMemory() {
- Log.i(cgSettings.tag, "Cleaning applications cache.");
+ Log.i(Settings.tag, "Cleaning applications cache.");
cachesCache.clear();
}
@Override
public void onTerminate() {
- Log.d(cgSettings.tag, "Terminating c:geo...");
+ Log.d(Settings.tag, "Terminating c:geo...");
if (geo != null) {
geo.closeGeo();
@@ -104,12 +104,12 @@ public class cgeoapplication extends Application {
return storage.status();
}
- public cgGeo startGeo(Context context, cgUpdateLoc geoUpdate, cgBase base, cgSettings settings, int time, int distance) {
+ public cgGeo startGeo(Context context, cgUpdateLoc geoUpdate, cgBase base, int time, int distance) {
if (geo == null) {
- geo = new cgGeo(context, this, geoUpdate, base, settings, time, distance);
+ geo = new cgGeo(context, this, geoUpdate, base, time, distance);
geo.initGeo();
- Log.i(cgSettings.tag, "Location service started");
+ Log.i(Settings.tag, "Location service started");
}
geo.replaceUpdate(geoUpdate);
@@ -143,7 +143,7 @@ public class cgeoapplication extends Application {
geo.closeGeo();
geo = null;
- Log.i(cgSettings.tag, "Location service stopped");
+ Log.i(Settings.tag, "Location service stopped");
}
}
}
@@ -153,7 +153,7 @@ public class cgeoapplication extends Application {
dir = new cgDirection(context, dirUpdate);
dir.initDir();
- Log.i(cgSettings.tag, "Direction service started");
+ Log.i(Settings.tag, "Direction service started");
}
dir.replaceUpdate(dirUpdate);
@@ -187,7 +187,7 @@ public class cgeoapplication extends Application {
dir.closeDir();
dir = null;
- Log.i(cgSettings.tag, "Direction service stopped");
+ Log.i(Settings.tag, "Direction service stopped");
}
}
}
diff --git a/main/src/cgeo/geocaching/cgeoauth.java b/main/src/cgeo/geocaching/cgeoauth.java
index 2a12ce7..a9f9eea 100644
--- a/main/src/cgeo/geocaching/cgeoauth.java
+++ b/main/src/cgeo/geocaching/cgeoauth.java
@@ -108,7 +108,6 @@ public class cgeoauth extends AbstractActivity {
public void onResume() {
super.onResume();
- settings.load();
}
private void init() {
@@ -155,7 +154,7 @@ public class cgeoauth extends AbstractActivity {
do {
// base.trustAllHosts();
- Log.d(cgSettings.tag, "https://" + host + pathRequest + "?" + params);
+ Log.d(Settings.tag, "https://" + host + pathRequest + "?" + params);
final URL u = new URL("https://" + host + pathRequest + "?" + params);
final URLConnection uc = u.openConnection();
connection = (HttpsURLConnection) uc;
@@ -179,7 +178,7 @@ public class cgeoauth extends AbstractActivity {
code = connection.getResponseCode();
retries++;
- Log.i(cgSettings.tag, host + ": " + connection.getResponseCode() + " " + connection.getResponseMessage());
+ Log.i(Settings.tag, host + ": " + connection.getResponseCode() + " " + connection.getResponseMessage());
br.close();
in.close();
@@ -199,7 +198,7 @@ public class cgeoauth extends AbstractActivity {
}
if (StringUtils.isNotBlank(OAtoken) && StringUtils.isNotBlank(OAtokenSecret)) {
- final SharedPreferences.Editor prefsEdit = getSharedPreferences(cgSettings.preferences, 0).edit();
+ final SharedPreferences.Editor prefsEdit = getSharedPreferences(Settings.preferences, 0).edit();
prefsEdit.putString("temp-token-public", OAtoken);
prefsEdit.putString("temp-token-secret", OAtokenSecret);
prefsEdit.commit();
@@ -214,21 +213,21 @@ public class cgeoauth extends AbstractActivity {
status = 1;
} catch (Exception e) {
- Log.e(cgSettings.tag, "cgeoauth.requestToken(2): " + e.toString());
+ Log.e(Settings.tag, "cgeoauth.requestToken(2): " + e.toString());
}
}
}
} catch (IOException eio) {
- Log.e(cgSettings.tag, "cgeoauth.requestToken(IO): " + eio.toString() + " ~ " + connection.getResponseCode() + ": " + connection.getResponseMessage());
+ Log.e(Settings.tag, "cgeoauth.requestToken(IO): " + eio.toString() + " ~ " + connection.getResponseCode() + ": " + connection.getResponseMessage());
} catch (Exception e) {
- Log.e(cgSettings.tag, "cgeoauth.requestToken(1): " + e.toString());
+ Log.e(Settings.tag, "cgeoauth.requestToken(1): " + e.toString());
} finally {
if (connection != null) {
connection.disconnect();
}
}
} catch (Exception e2) {
- Log.e(cgSettings.tag, "cgeoauth.requestToken(3): " + e2.toString());
+ Log.e(Settings.tag, "cgeoauth.requestToken(3): " + e2.toString());
}
requestTokenHandler.sendEmptyMessage(status);
@@ -284,7 +283,7 @@ public class cgeoauth extends AbstractActivity {
code = connection.getResponseCode();
retries++;
- Log.i(cgSettings.tag, host + ": " + connection.getResponseCode() + " " + connection.getResponseMessage());
+ Log.i(Settings.tag, host + ": " + connection.getResponseCode() + " " + connection.getResponseMessage());
br.close();
ins.close();
@@ -310,13 +309,13 @@ public class cgeoauth extends AbstractActivity {
OAtoken = "";
OAtokenSecret = "";
- final SharedPreferences.Editor prefs = getSharedPreferences(cgSettings.preferences, 0).edit();
+ final SharedPreferences.Editor prefs = getSharedPreferences(Settings.preferences, 0).edit();
prefs.putString("tokenpublic", null);
prefs.putString("tokensecret", null);
prefs.putInt("twitter", 0);
prefs.commit();
} else {
- final SharedPreferences.Editor prefs = getSharedPreferences(cgSettings.preferences, 0).edit();
+ final SharedPreferences.Editor prefs = getSharedPreferences(Settings.preferences, 0).edit();
prefs.remove("temp-token-public");
prefs.remove("temp-token-secret");
prefs.putString("tokenpublic", OAtoken);
@@ -327,7 +326,7 @@ public class cgeoauth extends AbstractActivity {
status = 1;
}
} catch (Exception e) {
- Log.e(cgSettings.tag, "cgeoauth.changeToken: " + e.toString());
+ Log.e(Settings.tag, "cgeoauth.changeToken: " + e.toString());
}
changeTokensHandler.sendEmptyMessage(status);
@@ -346,7 +345,7 @@ public class cgeoauth extends AbstractActivity {
startButton.setOnTouchListener(null);
startButton.setOnClickListener(null);
- final SharedPreferences.Editor prefs = getSharedPreferences(cgSettings.preferences, 0).edit();
+ final SharedPreferences.Editor prefs = getSharedPreferences(Settings.preferences, 0).edit();
prefs.putString("temp-token-public", null);
prefs.putString("temp-token-secret", null);
prefs.commit();
diff --git a/main/src/cgeo/geocaching/cgeocaches.java b/main/src/cgeo/geocaching/cgeocaches.java
index 9b166f8..34f9bea 100644
--- a/main/src/cgeo/geocaching/cgeocaches.java
+++ b/main/src/cgeo/geocaching/cgeocaches.java
@@ -249,7 +249,7 @@ public class cgeocaches extends AbstractListActivity {
}
} catch (Exception e) {
showToast(res.getString(R.string.err_detail_cache_find_any));
- Log.e(cgSettings.tag, "cgeocaches.loadCachesHandler: " + e.toString());
+ Log.e(Settings.tag, "cgeocaches.loadCachesHandler: " + e.toString());
hideLoading();
showProgress(false);
@@ -262,7 +262,7 @@ public class cgeocaches extends AbstractListActivity {
hideLoading();
showProgress(false);
} catch (Exception e2) {
- Log.e(cgSettings.tag, "cgeocaches.loadCachesHandler.2: " + e2.toString());
+ Log.e(Settings.tag, "cgeocaches.loadCachesHandler.2: " + e2.toString());
}
if (adapter != null) {
@@ -327,7 +327,7 @@ public class cgeocaches extends AbstractListActivity {
}
} catch (Exception e) {
showToast(res.getString(R.string.err_detail_cache_find_next));
- Log.e(cgSettings.tag, "cgeocaches.loadNextPageHandler: " + e.toString());
+ Log.e(Settings.tag, "cgeocaches.loadNextPageHandler: " + e.toString());
}
listFooter.setOnClickListener(new moreCachesListener());
@@ -389,9 +389,9 @@ public class cgeocaches extends AbstractListActivity {
}
if (geo == null) {
- geo = app.startGeo(cgeocaches.this, geoUpdate, base, settings, 0, 0);
+ geo = app.startGeo(cgeocaches.this, geoUpdate, base, 0, 0);
}
- if (settings.livelist == 1 && settings.useCompass == 1 && dir == null) {
+ if (Settings.isLiveList() && Settings.isUseCompass() && dir == null) {
dir = app.startDir(cgeocaches.this, dirUpdate);
}
}
@@ -580,7 +580,7 @@ public class cgeocaches extends AbstractListActivity {
cgSearchThread thread;
if (type.equals("offline")) {
- listId = settings.getLastList();
+ listId = Settings.getLastList();
if (listId <= 0) {
listId = 1;
title = res.getString(R.string.caches_stored);
@@ -674,7 +674,7 @@ public class cgeocaches extends AbstractListActivity {
} else {
title = "caches";
setTitle(title);
- Log.e(cgSettings.tag, "cgeocaches.onCreate: No action or unknown action specified");
+ Log.e(Settings.tag, "cgeocaches.onCreate: No action or unknown action specified");
}
prepareFilterBar();
@@ -691,7 +691,6 @@ public class cgeocaches extends AbstractListActivity {
public void onResume() {
super.onResume();
- settings.load();
init();
if (adapter != null && geo != null && geo.coordsNow != null) {
@@ -755,7 +754,7 @@ public class cgeocaches extends AbstractListActivity {
public boolean onCreateOptionsMenu(Menu menu) {
SubMenu subMenuFilter = menu.addSubMenu(0, SUBMENU_FILTER, 0, res.getString(R.string.caches_filter)).setIcon(R.drawable.ic_menu_filter);
subMenuFilter.setHeaderTitle(res.getString(R.string.caches_filter_title));
- if (settings.cacheType == null) {
+ if (Settings.getCacheType() == null) {
subMenuFilter.add(0, SUBMENU_FILTER_TYPE, 0, res.getString(R.string.caches_filter_type));
}
subMenuFilter.add(0, SUBMENU_FILTER_SIZE, 0, res.getString(R.string.caches_filter_size));
@@ -798,7 +797,7 @@ public class cgeocaches extends AbstractListActivity {
subMenu.add(0, MENU_REFRESH_STORED, 0, res.getString(R.string.cache_offline_refresh)); // download details for all caches
subMenu.add(0, MENU_MOVE_TO_LIST, 0, res.getString(R.string.cache_menu_move_list));
subMenu.add(0, MENU_EXPORT_NOTES, 0, res.getString(R.string.cache_export_fieldnote)); // export field notes
- if (settings.webDeviceCode == null)
+ if (Settings.getWebDeviceCode() == null)
{
menu.add(0, MENU_IMPORT_GPX, 0, res.getString(R.string.gpx_import_title)).setIcon(android.R.drawable.ic_menu_upload); // import gpx file
} else {
@@ -939,7 +938,7 @@ public class cgeocaches extends AbstractListActivity {
}
}
} catch (Exception e) {
- Log.e(cgSettings.tag, "cgeocaches.onPrepareOptionsMenu: " + e.toString());
+ Log.e(Settings.tag, "cgeocaches.onPrepareOptionsMenu: " + e.toString());
}
return true;
@@ -1080,7 +1079,7 @@ public class cgeocaches extends AbstractListActivity {
try {
adapterInfo = (AdapterContextMenuInfo) info;
} catch (Exception e) {
- Log.w(cgSettings.tag, "cgeocaches.onCreateContextMenu: " + e.toString());
+ Log.w(Settings.tag, "cgeocaches.onCreateContextMenu: " + e.toString());
}
if ((adapterInfo == null || adapterInfo.position < 0 || contextMenuShowFilter) && selectedFilter != null) {
@@ -1175,7 +1174,7 @@ public class cgeocaches extends AbstractListActivity {
try {
adapterInfo = (AdapterContextMenuInfo) info;
} catch (Exception e) {
- Log.w(cgSettings.tag, "cgeocaches.onContextItemSelected: " + e.toString());
+ Log.w(Settings.tag, "cgeocaches.onContextItemSelected: " + e.toString());
}
// the context menu may be invoked for the cache or for the filter list
@@ -1299,7 +1298,7 @@ public class cgeocaches extends AbstractListActivity {
}
int logType = id - MENU_LOG_VISIT_OFFLINE;
- cache.logOffline(this, logType, settings, base);
+ cache.logOffline(this, logType, base);
}
return true;
}
@@ -1349,7 +1348,7 @@ public class cgeocaches extends AbstractListActivity {
list.setLongClickable(true);
list.addFooterView(listFooter);
- adapter = new cgCacheListAdapter(this, settings, cacheList, base);
+ adapter = new cgCacheListAdapter(this, cacheList, base);
setListAdapter(adapter);
} else {
adapter.notifyDataSetChanged();
@@ -1403,9 +1402,9 @@ public class cgeocaches extends AbstractListActivity {
private void init() {
// sensor & geolocation manager
if (geo == null) {
- geo = app.startGeo(this, geoUpdate, base, settings, 0, 0);
+ geo = app.startGeo(this, geoUpdate, base, 0, 0);
}
- if (settings.livelist == 1 && settings.useCompass == 1 && dir == null) {
+ if (Settings.isLiveList() && Settings.isUseCompass() && dir == null) {
dir = app.startDir(this, dirUpdate);
}
@@ -1471,13 +1470,13 @@ public class cgeocaches extends AbstractListActivity {
}
if (geo == null) {
- geo = app.startGeo(cgeocaches.this, geoUpdate, base, settings, 0, 0);
+ geo = app.startGeo(cgeocaches.this, geoUpdate, base, 0, 0);
}
- if (settings.livelist == 1 && settings.useCompass == 1 && dir == null) {
+ if (Settings.isLiveList() && Settings.isUseCompass() && dir == null) {
dir = app.startDir(cgeocaches.this, dirUpdate);
}
} catch (Exception e) {
- Log.e(cgSettings.tag, "cgeocaches.onOptionsItemSelected.onCancel: " + e.toString());
+ Log.e(Settings.tag, "cgeocaches.onOptionsItemSelected.onCancel: " + e.toString());
}
}
});
@@ -1552,7 +1551,7 @@ public class cgeocaches extends AbstractListActivity {
}
} catch (Exception e)
{
- Log.e(cgSettings.tag, "cgeocaches.removeFromHistory.onCancel: " + e.toString());
+ Log.e(Settings.tag, "cgeocaches.removeFromHistory.onCancel: " + e.toString());
}
}
});
@@ -1596,7 +1595,7 @@ public class cgeocaches extends AbstractListActivity {
}
} catch (Exception e)
{
- Log.e(cgSettings.tag, "cgeocaches.exportFieldNotes.onCancel: " + e.toString());
+ Log.e(Settings.tag, "cgeocaches.exportFieldNotes.onCancel: " + e.toString());
}
}
});
@@ -1627,13 +1626,13 @@ public class cgeocaches extends AbstractListActivity {
}
if (geo == null) {
- geo = app.startGeo(cgeocaches.this, geoUpdate, base, settings, 0, 0);
+ geo = app.startGeo(cgeocaches.this, geoUpdate, base, 0, 0);
}
- if (settings.livelist == 1 && settings.useCompass == 1 && dir == null) {
+ if (Settings.isLiveList() && Settings.isUseCompass() && dir == null) {
dir = app.startDir(cgeocaches.this, dirUpdate);
}
} catch (Exception e) {
- Log.e(cgSettings.tag, "cgeocaches.importWeb.onCancel: " + e.toString());
+ Log.e(Settings.tag, "cgeocaches.importWeb.onCancel: " + e.toString());
}
}
});
@@ -1693,7 +1692,7 @@ public class cgeocaches extends AbstractListActivity {
threadR.kill();
}
} catch (Exception e) {
- Log.e(cgSettings.tag, "cgeocaches.onOptionsItemSelected.onCancel: " + e.toString());
+ Log.e(Settings.tag, "cgeocaches.onOptionsItemSelected.onCancel: " + e.toString());
}
}
});
@@ -1721,8 +1720,8 @@ public class cgeocaches extends AbstractListActivity {
adapter.setActualCoordinates(geo.coordsNow);
}
- if (settings.useCompass == 0 || (geo.speedNow != null && geo.speedNow > 5)) { // use GPS when speed is higher than 18 km/h
- if (settings.useCompass == 0) {
+ if (!Settings.isUseCompass() || (geo.speedNow != null && geo.speedNow > 5)) { // use GPS when speed is higher than 18 km/h
+ if (!Settings.isUseCompass()) {
if (geo.bearingNow != null) {
adapter.setActualHeading(geo.bearingNow);
} else {
@@ -1734,7 +1733,7 @@ public class cgeocaches extends AbstractListActivity {
}
}
} catch (Exception e) {
- Log.w(cgSettings.tag, "Failed to update location.");
+ Log.w(Settings.tag, "Failed to update location.");
}
}
}
@@ -1743,7 +1742,7 @@ public class cgeocaches extends AbstractListActivity {
@Override
public void updateDir(cgDirection dir) {
- if (settings.livelist == 0) {
+ if (!Settings.isLiveList()) {
return;
}
if (dir == null || dir.directionNow == null) {
@@ -1772,7 +1771,7 @@ public class cgeocaches extends AbstractListActivity {
@Override
public void run() {
if (coords != null) {
- searchId = base.searchByOffline(coords, settings.cacheType, listId);
+ searchId = base.searchByOffline(coords, Settings.getCacheType(), listId);
} else {
searchId = base.searchByOffline(null, null, 1);
}
@@ -1790,7 +1789,7 @@ public class cgeocaches extends AbstractListActivity {
@Override
public void run() {
- searchId = base.searchByHistory(coords != null ? settings.cacheType : null);
+ searchId = base.searchByHistory(coords != null ? Settings.getCacheType() : null);
handler.sendMessage(new Message());
}
}
@@ -1805,7 +1804,7 @@ public class cgeocaches extends AbstractListActivity {
@Override
public void run() {
- searchId = base.searchByNextPage(this, searchId, 0, settings.showCaptcha);
+ searchId = base.searchByNextPage(this, searchId, 0, Settings.isShowCaptcha());
handler.sendMessage(new Message());
}
@@ -1834,7 +1833,7 @@ public class cgeocaches extends AbstractListActivity {
@Override
public void run() {
- searchId = base.searchByCoords(this, coords, cachetype, 0, settings.showCaptcha);
+ searchId = base.searchByCoords(this, coords, cachetype, 0, Settings.isShowCaptcha());
handler.sendMessage(new Message());
}
@@ -1863,7 +1862,7 @@ public class cgeocaches extends AbstractListActivity {
@Override
public void run() {
- searchId = base.searchByKeyword(this, keyword, cachetype, 0, settings.showCaptcha);
+ searchId = base.searchByKeyword(this, keyword, cachetype, 0, Settings.isShowCaptcha());
handler.sendMessage(new Message());
}
}
@@ -1891,7 +1890,7 @@ public class cgeocaches extends AbstractListActivity {
@Override
public void run() {
- searchId = base.searchByUsername(this, username, cachetype, 0, settings.showCaptcha);
+ searchId = base.searchByUsername(this, username, cachetype, 0, Settings.isShowCaptcha());
handler.sendMessage(new Message());
}
}
@@ -1923,7 +1922,7 @@ public class cgeocaches extends AbstractListActivity {
params.put("username", username);
params.put("cachetype", cachetype);
- searchId = base.searchByOwner(this, username, cachetype, 0, settings.showCaptcha);
+ searchId = base.searchByOwner(this, username, cachetype, 0, Settings.isShowCaptcha());
handler.sendMessage(new Message());
}
@@ -1972,7 +1971,7 @@ public class cgeocaches extends AbstractListActivity {
try {
if (needToStop) {
- Log.i(cgSettings.tag, "Stopped storing process.");
+ Log.i(Settings.tag, "Stopped storing process.");
break;
}
@@ -1983,15 +1982,15 @@ public class cgeocaches extends AbstractListActivity {
delay = 500;
}
- Log.i(cgSettings.tag, "Waiting for next cache " + delay + " ms");
+ Log.i(Settings.tag, "Waiting for next cache " + delay + " ms");
sleep(delay);
} catch (Exception e) {
- Log.e(cgSettings.tag, "cgeocaches.geocachesLoadDetails.sleep: " + e.toString());
+ Log.e(Settings.tag, "cgeocaches.geocachesLoadDetails.sleep: " + e.toString());
}
}
if (needToStop) {
- Log.i(cgSettings.tag, "Stopped storing process.");
+ Log.i(Settings.tag, "Stopped storing process.");
break;
}
@@ -2002,7 +2001,7 @@ public class cgeocaches extends AbstractListActivity {
yield();
} catch (Exception e) {
- Log.e(cgSettings.tag, "cgeocaches.geocachesLoadDetails: " + e.toString());
+ Log.e(Settings.tag, "cgeocaches.geocachesLoadDetails: " + e.toString());
}
last = System.currentTimeMillis();
@@ -2051,7 +2050,7 @@ public class cgeocaches extends AbstractListActivity {
}
//download new code
- String deviceCode = settings.webDeviceCode;
+ String deviceCode = Settings.getWebDeviceCode();
if (deviceCode == null) {
deviceCode = "";
}
@@ -2080,7 +2079,7 @@ public class cgeocaches extends AbstractListActivity {
yield();
} else if ("RG".equals(cgBase.getResponseData(responseFromWeb))) {
//Server returned RG (registration) and this device no longer registered.
- settings.setWebNameCode(null, null);
+ Settings.setWebNameCode(null, null);
needToStop = true;
handler.sendEmptyMessage(-3);
return;
@@ -2107,7 +2106,7 @@ public class cgeocaches extends AbstractListActivity {
times = 0;
}
} catch (InterruptedException e) {
- Log.e(cgSettings.tag, "cgeocaches.geocachesLoadFromWeb.sleep: " + e.toString());
+ Log.e(Settings.tag, "cgeocaches.geocachesLoadFromWeb.sleep: " + e.toString());
}
}
handler.sendEmptyMessage(-1);
@@ -2151,13 +2150,13 @@ public class cgeocaches extends AbstractListActivity {
try {
if (needToStop) {
- Log.i(cgSettings.tag, "Stopped dropping process.");
+ Log.i(Settings.tag, "Stopped dropping process.");
break;
}
app.markDropped(cache.geocode);
} catch (Exception e) {
- Log.e(cgSettings.tag, "cgeocaches.geocachesDropDetails: " + e.toString());
+ Log.e(Settings.tag, "cgeocaches.geocachesDropDetails: " + e.toString());
}
}
cacheListTemp.clear();
@@ -2198,7 +2197,7 @@ public class cgeocaches extends AbstractListActivity {
try {
if (needToStop) {
- Log.i(cgSettings.tag, "Stopped removing process.");
+ Log.i(Settings.tag, "Stopped removing process.");
break;
}
@@ -2208,7 +2207,7 @@ public class cgeocaches extends AbstractListActivity {
yield();
} catch (Exception e) {
- Log.e(cgSettings.tag, "cgeocaches.geocachesRemoveFromHistory: " + e.toString());
+ Log.e(Settings.tag, "cgeocaches.geocachesRemoveFromHistory: " + e.toString());
}
}
@@ -2269,7 +2268,7 @@ public class cgeocaches extends AbstractListActivity {
try {
if (needToStop)
{
- Log.i(cgSettings.tag, "Stopped exporting process.");
+ Log.i(Settings.tag, "Stopped exporting process.");
break;
}
@@ -2296,7 +2295,7 @@ public class cgeocaches extends AbstractListActivity {
yield();
} catch (Exception e) {
- Log.e(cgSettings.tag, "cgeocaches.geocachesExportFieldNotes: " + e.toString());
+ Log.e(Settings.tag, "cgeocaches.geocachesExportFieldNotes: " + e.toString());
}
}
@@ -2318,7 +2317,7 @@ public class cgeocaches extends AbstractListActivity {
Message.obtain(handler, -2, exportFile).sendToTarget();
} catch (IOException e) {
- Log.e(cgSettings.tag, "cgeocaches.geocachesExportFieldNotes: " + e.toString());
+ Log.e(Settings.tag, "cgeocaches.geocachesExportFieldNotes: " + e.toString());
handler.sendEmptyMessage(-3);
} finally
{
@@ -2327,7 +2326,7 @@ public class cgeocaches extends AbstractListActivity {
try {
fw.close();
} catch (IOException e) {
- Log.e(cgSettings.tag, "cgeocaches.geocachesExportFieldNotes: " + e.toString());
+ Log.e(Settings.tag, "cgeocaches.geocachesExportFieldNotes: " + e.toString());
}
}
}
@@ -2412,7 +2411,7 @@ public class cgeocaches extends AbstractListActivity {
listId = list.id;
title = list.title;
- settings.saveLastList(listId);
+ Settings.saveLastList(listId);
showProgress(true);
setLoadingCaches();
@@ -2537,7 +2536,7 @@ public class cgeocaches extends AbstractListActivity {
return;
}
- Intent mapIntent = new Intent(this, settings.getMapFactory().getMapClass());
+ Intent mapIntent = new Intent(this, Settings.getMapFactory().getMapClass());
mapIntent.putExtra("detail", false);
mapIntent.putExtra("searchid", searchId.toString());
@@ -2571,7 +2570,7 @@ public class cgeocaches extends AbstractListActivity {
cachesIntent.putExtra("type", "coordinate");
cachesIntent.putExtra("latitude", coords.getLatitude());
cachesIntent.putExtra("longitude", coords.getLongitude());
- cachesIntent.putExtra("cachetype", context.getSettings().cacheType);
+ cachesIntent.putExtra("cachetype", Settings.getCacheType());
context.startActivity(cachesIntent);
}
@@ -2581,7 +2580,7 @@ public class cgeocaches extends AbstractListActivity {
cachesIntent.putExtra("type", "owner");
cachesIntent.putExtra("username", userName);
- cachesIntent.putExtra("cachetype", context.getSettings().cacheType);
+ cachesIntent.putExtra("cachetype", Settings.getCacheType());
context.startActivity(cachesIntent);
}
@@ -2591,7 +2590,7 @@ public class cgeocaches extends AbstractListActivity {
cachesIntent.putExtra("type", "username");
cachesIntent.putExtra("username", userName);
- cachesIntent.putExtra("cachetype", context.getSettings().cacheType);
+ cachesIntent.putExtra("cachetype", Settings.getCacheType());
context.startActivity(cachesIntent);
}
@@ -2601,15 +2600,15 @@ public class cgeocaches extends AbstractListActivity {
View filterBar = findViewById(R.id.filter_bar);
String cacheType = "", filter = "";
- if (settings.cacheType != null || adapter.isFilter()) {
- if (settings.cacheType != null) {
- cacheType = cgBase.cacheTypesInv.get(settings.cacheType);
+ if (Settings.getCacheType() != null || adapter.isFilter()) {
+ if (Settings.getCacheType() != null) {
+ cacheType = cgBase.cacheTypesInv.get(Settings.getCacheType());
}
if (adapter.isFilter()) {
filter = adapter.getFilterName();
}
- if (settings.cacheType != null && adapter.isFilter()) {
+ if (Settings.getCacheType() != null && adapter.isFilter()) {
filter = ", " + filter;
}
diff --git a/main/src/cgeo/geocaching/cgeocoords.java b/main/src/cgeo/geocaching/cgeocoords.java
index 972eba9..852fe5b 100644
--- a/main/src/cgeo/geocaching/cgeocoords.java
+++ b/main/src/cgeo/geocaching/cgeocoords.java
@@ -1,6 +1,6 @@
package cgeo.geocaching;
-import cgeo.geocaching.cgSettings.coordInputFormatEnum;
+import cgeo.geocaching.Settings.coordInputFormatEnum;
import cgeo.geocaching.activity.AbstractActivity;
import cgeo.geocaching.geopoint.Geopoint;
import cgeo.geocaching.geopoint.Geopoint.MalformedCoordinateException;
@@ -27,7 +27,6 @@ import android.widget.TextView;
public class cgeocoords extends Dialog {
private AbstractActivity context = null;
- private cgSettings settings = null;
private cgGeo geo = null;
private Geopoint gp = null;
@@ -44,10 +43,9 @@ public class cgeocoords extends Dialog {
coordInputFormatEnum currentFormat = null;
- public cgeocoords(final AbstractActivity contextIn, cgSettings settingsIn, final Geopoint gpIn, final cgGeo geoIn) {
+ public cgeocoords(final AbstractActivity contextIn, final Geopoint gpIn, final cgGeo geoIn) {
super(contextIn);
context = contextIn;
- settings = settingsIn;
geo = geoIn;
if (gpIn != null) {
@@ -77,7 +75,7 @@ public class cgeocoords extends Dialog {
android.R.layout.simple_spinner_item);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner.setAdapter(adapter);
- spinner.setSelection(settings.getCoordInputFormat().ordinal());
+ spinner.setSelection(Settings.getCoordInputFormat().ordinal());
spinner.setOnItemSelectedListener(new CoordinateFormatListener());
bLat = (Button) findViewById(R.id.ButtonLat);
@@ -441,7 +439,7 @@ public class cgeocoords extends Dialog {
}
currentFormat = coordInputFormatEnum.fromInt(pos);
- settings.setCoordInputFormat(currentFormat);
+ Settings.setCoordInputFormat(currentFormat);
updateGUI();
}
diff --git a/main/src/cgeo/geocaching/cgeodetail.java b/main/src/cgeo/geocaching/cgeodetail.java
index a3a2020..720db71 100644
--- a/main/src/cgeo/geocaching/cgeodetail.java
+++ b/main/src/cgeo/geocaching/cgeodetail.java
@@ -129,7 +129,7 @@ public class cgeodetail extends AbstractActivity {
} catch (Exception e) {
showToast(res.getString(R.string.err_store_failed));
- Log.e(cgSettings.tag, "cgeodetail.storeCacheHandler: " + e.toString());
+ Log.e(Settings.tag, "cgeodetail.storeCacheHandler: " + e.toString());
}
setView();
@@ -146,7 +146,7 @@ public class cgeodetail extends AbstractActivity {
} catch (Exception e) {
showToast(res.getString(R.string.err_refresh_failed));
- Log.e(cgSettings.tag, "cgeodetail.refreshCacheHandler: " + e.toString());
+ Log.e(Settings.tag, "cgeodetail.refreshCacheHandler: " + e.toString());
}
setView();
@@ -161,7 +161,7 @@ public class cgeodetail extends AbstractActivity {
} catch (Exception e) {
showToast(res.getString(R.string.err_drop_failed));
- Log.e(cgSettings.tag, "cgeodetail.dropCacheHandler: " + e.toString());
+ Log.e(Settings.tag, "cgeodetail.dropCacheHandler: " + e.toString());
}
setView();
@@ -187,7 +187,7 @@ public class cgeodetail extends AbstractActivity {
setView();
- if (settings.autoLoadDesc == 1) {
+ if (Settings.isAutoLoadDescription()) {
try {
loadLongDesc();
} catch (Exception e) {
@@ -339,9 +339,9 @@ public class cgeodetail extends AbstractActivity {
String uriQuery = uri.getQuery();
if (uriQuery != null) {
- Log.i(cgSettings.tag, "Opening URI: " + uriHost + uriPath + "?" + uriQuery);
+ Log.i(Settings.tag, "Opening URI: " + uriHost + uriPath + "?" + uriQuery);
} else {
- Log.i(cgSettings.tag, "Opening URI: " + uriHost + uriPath);
+ Log.i(Settings.tag, "Opening URI: " + uriHost + uriPath);
}
if (uriHost.contains("geocaching.com")) {
@@ -408,10 +408,9 @@ public class cgeodetail extends AbstractActivity {
public void onResume() {
super.onResume();
- settings.load();
if (geo == null) {
- geo = app.startGeo(this, geoUpdate, base, settings, 0, 0);
+ geo = app.startGeo(this, geoUpdate, base, 0, 0);
}
if (!disableResumeSetView) {
setView();
@@ -574,7 +573,7 @@ public class cgeodetail extends AbstractActivity {
}
int logType = menuItem - MENU_LOG_VISIT_OFFLINE;
- cache.logOffline(this, logType, settings, base);
+ cache.logOffline(this, logType, base);
return true;
}
@@ -586,7 +585,7 @@ public class cgeodetail extends AbstractActivity {
inflater = getLayoutInflater();
}
if (geo == null) {
- geo = app.startGeo(this, geoUpdate, base, settings, 0, 0);
+ geo = app.startGeo(this, geoUpdate, base, 0, 0);
}
if (searchId != null) {
@@ -1075,7 +1074,7 @@ public class cgeodetail extends AbstractActivity {
cacheDistance.bringToFront();
}
} catch (Exception e) {
- Log.e(cgSettings.tag, "cgeodetail.setView: " + e.toString());
+ Log.e(Settings.tag, "cgeodetail.setView: " + e.toString());
}
if (waitDialog != null && waitDialog.isShowing())
@@ -1363,7 +1362,7 @@ public class cgeodetail extends AbstractActivity {
Message message = handler.obtainMessage(0, image);
handler.sendMessage(message);
} catch (Exception e) {
- Log.w(cgSettings.tag, "cgeodetail.loadMapPreview.run: " + e.toString());
+ Log.w(Settings.tag, "cgeodetail.loadMapPreview.run: " + e.toString());
}
}
}
@@ -1411,7 +1410,7 @@ public class cgeodetail extends AbstractActivity {
coords.coords = cache.coords;
coordinates.add(coords);
} catch (Exception e) {
- Log.e(cgSettings.tag, "cgeodetail.getCoordinates (cache): " + e.toString());
+ Log.e(Settings.tag, "cgeodetail.getCoordinates (cache): " + e.toString());
}
try {
@@ -1428,7 +1427,7 @@ public class cgeodetail extends AbstractActivity {
coordinates.add(coords);
}
} catch (Exception e) {
- Log.e(cgSettings.tag, "cgeodetail.getCoordinates (waypoint): " + e.toString());
+ Log.e(Settings.tag, "cgeodetail.getCoordinates (waypoint): " + e.toString());
}
return coordinates;
@@ -1549,7 +1548,7 @@ public class cgeodetail extends AbstractActivity {
} catch (Exception e) {
showToast(res.getString(R.string.event_fail));
- Log.e(cgSettings.tag, "cgeodetail.addToCalendarFn: " + e.toString());
+ Log.e(Settings.tag, "cgeodetail.addToCalendarFn: " + e.toString());
}
}
@@ -1635,12 +1634,12 @@ public class cgeodetail extends AbstractActivity {
} else if (diff < 0) {
dist.append(" ↘");
}
- if (settings.units == cgSettings.unitsImperial) {
- dist.append(String.format(Locale.getDefault(), "%.0f", (Math.abs(diff) * 3.2808399)));
- dist.append(" ft");
- } else {
+ if (Settings.isUseMetricUnits()) {
dist.append(String.format(Locale.getDefault(), "%.0f", (Math.abs(diff))));
dist.append(" m");
+ } else {
+ dist.append(String.format(Locale.getDefault(), "%.0f", (Math.abs(diff) * 3.2808399)));
+ dist.append(" ft");
}
}
}
@@ -1648,7 +1647,7 @@ public class cgeodetail extends AbstractActivity {
cacheDistance.setText(dist.toString());
cacheDistance.bringToFront();
} catch (Exception e) {
- Log.w(cgSettings.tag, "Failed to update location.");
+ Log.w(Settings.tag, "Failed to update location.");
}
}
}
@@ -1668,7 +1667,7 @@ public class cgeodetail extends AbstractActivity {
startActivity(trackablesIntent);
}
} catch (Exception e) {
- Log.e(cgSettings.tag, "cgeodetail.selectTrackable: " + e.toString());
+ Log.e(Settings.tag, "cgeodetail.selectTrackable: " + e.toString());
}
}
}
diff --git a/main/src/cgeo/geocaching/cgeohelpers.java b/main/src/cgeo/geocaching/cgeohelpers.java
index 0fd4e6e..560ab84 100644
--- a/main/src/cgeo/geocaching/cgeohelpers.java
+++ b/main/src/cgeo/geocaching/cgeohelpers.java
@@ -25,7 +25,6 @@ public class cgeohelpers extends AbstractActivity {
public void onResume() {
super.onResume();
- settings.load();
}
private void installFromMarket(String marketId) {
diff --git a/main/src/cgeo/geocaching/cgeoimages.java b/main/src/cgeo/geocaching/cgeoimages.java
index c177bf2..fe505c9 100644
--- a/main/src/cgeo/geocaching/cgeoimages.java
+++ b/main/src/cgeo/geocaching/cgeoimages.java
@@ -105,14 +105,14 @@ public class cgeoimages extends AbstractActivity {
image_view.setOnClickListener(new View.OnClickListener() {
public void onClick(View arg0) {
- final String directoryTarget = Environment.getExternalStorageDirectory() + "/" + cgSettings.cache + "/" + "temp.jpg";
+ final String directoryTarget = Environment.getExternalStorageDirectory() + "/" + Settings.cache + "/" + "temp.jpg";
final File file = new File(directoryTarget);
try {
final FileOutputStream fos = new FileOutputStream(file);
image.getBitmap().compress(CompressFormat.JPEG, 100, fos);
fos.close();
} catch (Exception e) {
- Log.e(cgSettings.tag, "cgeoimages.handleMessage.onClick: " + e.toString());
+ Log.e(Settings.tag, "cgeoimages.handleMessage.onClick: " + e.toString());
return;
}
@@ -186,8 +186,8 @@ public class cgeoimages extends AbstractActivity {
}
final int message = img_type == SPOILER_IMAGES ? R.string.cache_spoiler_images_loading : R.string.cache_log_images_loading;
- final boolean offline = app.isOffline(geocode, null) && (img_type == SPOILER_IMAGES || settings.storelogimages);
- final boolean save = img_type == SPOILER_IMAGES ? true : settings.storelogimages;
+ final boolean offline = app.isOffline(geocode, null) && (img_type == SPOILER_IMAGES || Settings.isStoreLogImages());
+ final boolean save = img_type == SPOILER_IMAGES ? true : Settings.isStoreLogImages();
loadImages(images, message, save, offline);
}
@@ -206,7 +206,6 @@ public class cgeoimages extends AbstractActivity {
public void onResume() {
super.onResume();
- settings.load();
}
}
diff --git a/main/src/cgeo/geocaching/cgeoinit.java b/main/src/cgeo/geocaching/cgeoinit.java
index 9d930be..0689f47 100644
--- a/main/src/cgeo/geocaching/cgeoinit.java
+++ b/main/src/cgeo/geocaching/cgeoinit.java
@@ -1,7 +1,7 @@
package cgeo.geocaching;
import cgeo.geocaching.LogTemplateProvider.LogTemplate;
-import cgeo.geocaching.cgSettings.mapSourceEnum;
+import cgeo.geocaching.Settings.mapSourceEnum;
import cgeo.geocaching.activity.AbstractActivity;
import cgeo.geocaching.compatibility.Compatibility;
@@ -10,7 +10,6 @@ import org.apache.http.HttpResponse;
import android.app.ProgressDialog;
import android.content.Intent;
-import android.content.SharedPreferences;
import android.content.res.Configuration;
import android.net.Uri;
import android.os.Bundle;
@@ -63,7 +62,7 @@ public class cgeoinit extends AbstractActivity {
} catch (Exception e) {
showToast(res.getString(R.string.err_login_failed));
- Log.e(cgSettings.tag, "cgeoinit.logInHandler: " + e.toString());
+ Log.e(Settings.tag, "cgeoinit.logInHandler: " + e.toString());
}
if (loginDialog != null && loginDialog.isShowing()) {
@@ -91,7 +90,7 @@ public class cgeoinit extends AbstractActivity {
} catch (Exception e) {
showToast(res.getString(R.string.init_sendToCgeo_register_fail));
- Log.e(cgSettings.tag, "cgeoinit.webHandler: " + e.toString());
+ Log.e(Settings.tag, "cgeoinit.webHandler: " + e.toString());
}
if (webDialog != null && webDialog.isShowing()) {
@@ -124,7 +123,6 @@ public class cgeoinit extends AbstractActivity {
public void onResume() {
super.onResume();
- settings.load();
}
@Override
@@ -250,13 +248,15 @@ public class cgeoinit extends AbstractActivity {
}
});
- CheckBox publicButton = (CheckBox) findViewById(R.id.publicloc);
- if (prefs.getInt("publicloc", 0) == 0) {
- publicButton.setChecked(false);
- } else {
- publicButton.setChecked(true);
- }
- publicButton.setOnClickListener(new cgeoChangePublic());
+ final CheckBox publicButton = (CheckBox) findViewById(R.id.publicloc);
+ publicButton.setChecked(Settings.isPublicLoc());
+ publicButton.setOnClickListener(new View.OnClickListener() {
+
+ @Override
+ public void onClick(View v) {
+ Settings.setPublicLoc(publicButton.isChecked());
+ }
+ });
// Twitter settings
Button authorizeTwitter = (Button) findViewById(R.id.authorize_twitter);
@@ -268,18 +268,26 @@ public class cgeoinit extends AbstractActivity {
}
});
- CheckBox twitterButton = (CheckBox) findViewById(R.id.twitter_option);
- if (prefs.getInt("twitter", 0) == 0 || StringUtils.isBlank(settings.tokenPublic) || StringUtils.isBlank(settings.tokenSecret)) {
- twitterButton.setChecked(false);
- } else {
- twitterButton.setChecked(true);
- }
- twitterButton.setOnClickListener(new cgeoChangeTwitter());
+ final CheckBox twitterButton = (CheckBox) findViewById(R.id.twitter_option);
+ twitterButton.setChecked(Settings.isUseTwitter() && Settings.isTwitterLoginValid());
+ twitterButton.setOnClickListener(new View.OnClickListener() {
+
+ @Override
+ public void onClick(View v) {
+ Settings.setUseTwitter(twitterButton.isChecked());
+ if (Settings.isUseTwitter() && !Settings.isTwitterLoginValid()) {
+ Intent authIntent = new Intent(cgeoinit.this, cgeoauth.class);
+ startActivity(authIntent);
+ }
+
+ twitterButton.setChecked(Settings.isUseTwitter());
+ }
+ });
// Signature settings
EditText sigEdit = (EditText) findViewById(R.id.signature);
if (sigEdit.getText().length() == 0) {
- sigEdit.setText(settings.getSignature());
+ sigEdit.setText(Settings.getSignature());
}
Button sigBtn = (Button) findViewById(R.id.signature_help);
sigBtn.setOnClickListener(new View.OnClickListener() {
@@ -296,157 +304,179 @@ public class cgeoinit extends AbstractActivity {
enableTemplatesMenu = false;
}
});
- CheckBox autoinsertButton = (CheckBox) findViewById(R.id.sigautoinsert);
- autoinsertButton.setChecked(prefs.getBoolean("sigautoinsert", false));
- autoinsertButton.setOnClickListener(new cgeoChangeSignatureAutoinsert());
+ final CheckBox autoinsertButton = (CheckBox) findViewById(R.id.sigautoinsert);
+ autoinsertButton.setChecked(Settings.isAutoInsertSignature());
+ autoinsertButton.setOnClickListener(new View.OnClickListener() {
+
+ @Override
+ public void onClick(View v) {
+ Settings.setAutoInsertSignature(autoinsertButton.isChecked());
+ }
+ });
// Other settings
- CheckBox skinButton = (CheckBox) findViewById(R.id.skin);
- if (prefs.getInt("skin", 0) == 0) {
- skinButton.setChecked(false);
- } else {
- skinButton.setChecked(true);
- }
- skinButton.setOnClickListener(new cgeoChangeSkin());
+ final CheckBox skinButton = (CheckBox) findViewById(R.id.skin);
+ skinButton.setChecked(Settings.isLightSkin());
+ skinButton.setOnClickListener(new View.OnClickListener() {
- CheckBox addressButton = (CheckBox) findViewById(R.id.address);
- if (prefs.getInt("showaddress", 1) == 0) {
- addressButton.setChecked(false);
- } else {
- addressButton.setChecked(true);
- }
- addressButton.setOnClickListener(new cgeoChangeAddress());
+ @Override
+ public void onClick(View v) {
+ Settings.setLightSkin(skinButton.isChecked());
+ }
+ });
- CheckBox captchaButton = (CheckBox) findViewById(R.id.captcha);
- if (prefs.getBoolean("showcaptcha", false) == false) {
- captchaButton.setChecked(false);
- } else {
- captchaButton.setChecked(true);
- }
- captchaButton.setOnClickListener(new cgeoChangeCaptcha());
+ final CheckBox addressButton = (CheckBox) findViewById(R.id.address);
+ addressButton.setChecked(Settings.isShowAddress());
+ addressButton.setOnClickListener(new View.OnClickListener() {
+
+ @Override
+ public void onClick(View v) {
+ Settings.setShowAddress(addressButton.isChecked());
+ }
+ });
+
+ final CheckBox captchaButton = (CheckBox) findViewById(R.id.captcha);
+ captchaButton.setChecked(Settings.isShowCaptcha());
+ captchaButton.setOnClickListener(new View.OnClickListener() {
+
+ @Override
+ public void onClick(View v) {
+ Settings.setShowCaptcha(captchaButton.isChecked());
+ }
+ });
final CheckBox dirImgButton = (CheckBox) findViewById(R.id.loaddirectionimg);
- dirImgButton.setChecked(settings.getLoadDirImg());
+ dirImgButton.setChecked(Settings.getLoadDirImg());
dirImgButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
- settings.setLoadDirImg(!settings.getLoadDirImg());
- dirImgButton.setChecked(settings.getLoadDirImg());
+ Settings.setLoadDirImg(!Settings.getLoadDirImg());
+ dirImgButton.setChecked(Settings.getLoadDirImg());
}
});
- CheckBox useEnglishButton = (CheckBox) findViewById(R.id.useenglish);
- if (prefs.getBoolean("useenglish", false) == false) {
- useEnglishButton.setChecked(false);
- } else {
- useEnglishButton.setChecked(true);
- }
- useEnglishButton.setOnClickListener(new cgeoChangeUseEnglish());
+ final CheckBox useEnglishButton = (CheckBox) findViewById(R.id.useenglish);
+ useEnglishButton.setChecked(Settings.isUseEnglish());
+ useEnglishButton.setOnClickListener(new View.OnClickListener() {
+
+ @Override
+ public void onClick(View v) {
+ Settings.setUseEnglish(useEnglishButton.isChecked());
+ }
+ });
final CheckBox excludeButton = (CheckBox) findViewById(R.id.exclude);
- if (prefs.getInt("excludemine", 0) == 0) {
- excludeButton.setChecked(false);
- } else {
- excludeButton.setChecked(true);
- }
+ excludeButton.setChecked(Settings.isExcludeMyCaches());
excludeButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
- cgSettings.setExcludeMine(excludeButton.isChecked());
+ Settings.setExcludeMine(excludeButton.isChecked());
}
});
- CheckBox disabledButton = (CheckBox) findViewById(R.id.disabled);
- if (prefs.getInt("excludedisabled", 0) == 0) {
- disabledButton.setChecked(false);
- } else {
- disabledButton.setChecked(true);
- }
- disabledButton.setOnClickListener(new cgeoChangeDisabled());
+ final CheckBox disabledButton = (CheckBox) findViewById(R.id.disabled);
+ disabledButton.setChecked(Settings.isExcludeDisabledCaches());
+ disabledButton.setOnClickListener(new View.OnClickListener() {
+
+ @Override
+ public void onClick(View v) {
+ Settings.setExcludeDisabledCaches(disabledButton.isChecked());
+ }
+ });
TextView showWaypointsThreshold = (TextView) findViewById(R.id.showwaypointsthreshold);
showWaypointsThreshold.setText("" + prefs.getInt("gcshowwaypointsthreshold", 0));
- CheckBox autovisitButton = (CheckBox) findViewById(R.id.trackautovisit);
- if (prefs.getBoolean("trackautovisit", false)) {
- autovisitButton.setChecked(true);
- } else {
- autovisitButton.setChecked(false);
- }
- autovisitButton.setOnClickListener(new cgeoChangeAutovisit());
+ final CheckBox autovisitButton = (CheckBox) findViewById(R.id.trackautovisit);
+ autovisitButton.setChecked(Settings.isTrackableAutoVisit());
+ autovisitButton.setOnClickListener(new View.OnClickListener() {
- CheckBox offlineButton = (CheckBox) findViewById(R.id.offline);
- if (prefs.getInt("offlinemaps", 1) == 0) {
- offlineButton.setChecked(false);
- } else {
- offlineButton.setChecked(true);
- }
- offlineButton.setOnClickListener(new cgeoChangeOffline());
+ @Override
+ public void onClick(View v) {
+ Settings.setTrackableAutoVisit(autovisitButton.isChecked());
+ }
+ });
- CheckBox saveLogImgButton = (CheckBox) findViewById(R.id.save_log_img);
- if (prefs.getBoolean("logimages", false) == false) {
- saveLogImgButton.setChecked(false);
- } else {
- saveLogImgButton.setChecked(true);
- }
- saveLogImgButton.setOnClickListener(new cgeoChangeSaveLogImg());
+ final CheckBox offlineButton = (CheckBox) findViewById(R.id.offline);
+ offlineButton.setChecked(Settings.isStoreOfflineMaps());
+ offlineButton.setOnClickListener(new View.OnClickListener() {
- CheckBox autoloadButton = (CheckBox) findViewById(R.id.autoload);
- if (prefs.getInt("autoloaddesc", 0) == 0) {
- autoloadButton.setChecked(false);
- } else {
- autoloadButton.setChecked(true);
- }
- autoloadButton.setOnClickListener(new cgeoChangeAutoload());
+ @Override
+ public void onClick(View v) {
+ Settings.setStoreOfflineMaps(offlineButton.isChecked());
+ }
+ });
- CheckBox livelistButton = (CheckBox) findViewById(R.id.livelist);
- if (prefs.getInt("livelist", 1) == 0) {
- livelistButton.setChecked(false);
- } else {
- livelistButton.setChecked(true);
- }
- livelistButton.setOnClickListener(new cgeoChangeLivelist());
+ final CheckBox saveLogImgButton = (CheckBox) findViewById(R.id.save_log_img);
+ saveLogImgButton.setChecked(Settings.isStoreLogImages());
+ saveLogImgButton.setOnClickListener(new View.OnClickListener() {
- CheckBox unitsButton = (CheckBox) findViewById(R.id.units);
- if (prefs.getInt("units", cgSettings.unitsMetric) == cgSettings.unitsMetric) {
- unitsButton.setChecked(false);
- } else {
- unitsButton.setChecked(true);
- }
- unitsButton.setOnClickListener(new cgeoChangeUnits());
+ @Override
+ public void onClick(View v) {
+ Settings.setStoreLogImages(saveLogImgButton.isChecked());
+ }
+ });
- CheckBox gnavButton = (CheckBox) findViewById(R.id.gnav);
- if (prefs.getInt("usegnav", 1) == 1) {
- gnavButton.setChecked(true);
- } else {
- gnavButton.setChecked(false);
- }
- gnavButton.setOnClickListener(new cgeoChangeGNav());
+ final CheckBox autoloadButton = (CheckBox) findViewById(R.id.autoload);
+ autoloadButton.setChecked(Settings.isAutoLoadDescription());
+ autoloadButton.setOnClickListener(new View.OnClickListener() {
+
+ @Override
+ public void onClick(View v) {
+ Settings.setAutoLoadDesc(autoloadButton.isChecked());
+ }
+ });
+
+ final CheckBox livelistButton = (CheckBox) findViewById(R.id.livelist);
+ livelistButton.setChecked(Settings.isLiveList());
+ livelistButton.setOnClickListener(new View.OnClickListener() {
+
+ @Override
+ public void onClick(View v) {
+ Settings.setLiveList(livelistButton.isChecked());
+ }
+ });
+
+ final CheckBox unitsButton = (CheckBox) findViewById(R.id.units);
+ unitsButton.setChecked(!Settings.isUseMetricUnits());
+ unitsButton.setOnClickListener(new View.OnClickListener() {
+
+ @Override
+ public void onClick(View v) {
+ Settings.setUseMetricUnits(!unitsButton.isChecked());
+ }
+ });
+
+ final CheckBox gnavButton = (CheckBox) findViewById(R.id.gnav);
+ gnavButton.setChecked(Settings.isUseGoogleNavigation());
+ gnavButton.setOnClickListener(new View.OnClickListener() {
+
+ @Override
+ public void onClick(View v) {
+ Settings.setUseGoogleNavigation(gnavButton.isChecked());
+ }
+ });
final CheckBox logOffline = (CheckBox) findViewById(R.id.log_offline);
- logOffline.setChecked(settings.getLogOffline());
+ logOffline.setChecked(Settings.getLogOffline());
logOffline.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
- settings.setLogOffline(!settings.getLogOffline());
- logOffline.setChecked(settings.getLogOffline());
+ Settings.setLogOffline(!Settings.getLogOffline());
+ logOffline.setChecked(Settings.getLogOffline());
}
});
final CheckBox browserButton = (CheckBox) findViewById(R.id.browser);
- if (prefs.getInt("asbrowser", 1) == 0) {
- browserButton.setChecked(false);
- } else {
- browserButton.setChecked(true);
- }
+ browserButton.setChecked(Settings.isBrowser());
browserButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
- cgSettings.setAsBrowser(browserButton.isChecked());
+ Settings.setAsBrowser(browserButton.isChecked());
}
});
@@ -455,7 +485,7 @@ public class cgeoinit extends AbstractActivity {
altitudeEdit.setText("" + prefs.getInt("altcorrection", 0));
//Send2cgeo settings
- String webDeviceName = prefs.getString("webDeviceName", null);
+ String webDeviceName = Settings.getWebDeviceName();
if (StringUtils.isNotBlank(webDeviceName)) {
((EditText) findViewById(R.id.webDeviceName)).setText(webDeviceName);
@@ -594,13 +624,13 @@ public class cgeoinit extends AbstractActivity {
}
}
- final boolean status1 = settings.setLogin(usernameNew, passwordNew);
- final boolean status2 = settings.setGCvoteLogin(passvoteNew);
- final boolean status3 = settings.setSignature(signatureNew);
- final boolean status4 = settings.setAltCorrection(altitudeNewInt);
- final boolean status5 = settings.setMapFile(mfmapFileNew);
+ final boolean status1 = Settings.setLogin(usernameNew, passwordNew);
+ final boolean status2 = Settings.setGCvoteLogin(passvoteNew);
+ final boolean status3 = Settings.setSignature(signatureNew);
+ final boolean status4 = Settings.setAltCorrection(altitudeNewInt);
+ final boolean status5 = Settings.setMapFile(mfmapFileNew);
TextView field = (TextView) findViewById(R.id.showwaypointsthreshold);
- settings.setShowWaypointsThreshold(safeParse(field, 5));
+ Settings.setShowWaypointsThreshold(safeParse(field, 5));
return status1 && status2 && status3 && status4 && status5;
}
@@ -623,397 +653,17 @@ public class cgeoinit extends AbstractActivity {
}
}
- private class cgeoChangeTwitter implements View.OnClickListener {
-
- public void onClick(View arg0) {
- CheckBox twitterButton = (CheckBox) findViewById(R.id.twitter_option);
-
- if (twitterButton.isChecked()) {
- settings.reloadTwitterTokens();
-
- SharedPreferences.Editor edit = prefs.edit();
- if (prefs.getInt("twitter", 0) == 0) {
- edit.putInt("twitter", 1);
- settings.twitter = 1;
- } else {
- edit.putInt("twitter", 0);
- settings.twitter = 0;
- }
- edit.commit();
-
- if (settings.twitter == 1 && (StringUtils.isBlank(settings.tokenPublic) || StringUtils.isBlank(settings.tokenSecret))) {
- Intent authIntent = new Intent(cgeoinit.this, cgeoauth.class);
- startActivity(authIntent);
- }
-
- if (prefs.getInt("twitter", 0) == 0) {
- twitterButton.setChecked(false);
- } else {
- twitterButton.setChecked(true);
- }
- } else {
- SharedPreferences.Editor edit = prefs.edit();
- edit.putInt("twitter", 0);
- settings.twitter = 0;
- edit.commit();
-
- twitterButton.setChecked(false);
- }
-
- return;
- }
- }
-
- private class cgeoChangeSkin implements View.OnClickListener {
-
- public void onClick(View arg0) {
- SharedPreferences.Editor edit = prefs.edit();
- if (prefs.getInt("skin", 0) == 0) {
- edit.putInt("skin", 1);
- settings.setSkin(1);
- } else {
- edit.putInt("skin", 0);
- settings.setSkin(0);
- }
- edit.commit();
-
- CheckBox skinButton = (CheckBox) findViewById(R.id.skin);
- if (prefs.getInt("skin", 0) == 0) {
- skinButton.setChecked(false);
- } else {
- skinButton.setChecked(true);
- }
-
- return;
- }
- }
-
- private class cgeoChangeAddress implements View.OnClickListener {
-
- public void onClick(View arg0) {
- SharedPreferences.Editor edit = prefs.edit();
- if (prefs.getInt("showaddress", 1) == 0) {
- edit.putInt("showaddress", 1);
- } else {
- edit.putInt("showaddress", 0);
- }
- edit.commit();
-
- CheckBox transparentButton = (CheckBox) findViewById(R.id.address);
- if (prefs.getInt("showaddress", 1) == 0) {
- transparentButton.setChecked(false);
- } else {
- transparentButton.setChecked(true);
- }
-
- return;
- }
- }
-
- private class cgeoChangePublic implements View.OnClickListener {
-
- public void onClick(View arg0) {
- SharedPreferences.Editor edit = prefs.edit();
- if (prefs.getInt("publicloc", 0) == 0) {
- edit.putInt("publicloc", 1);
- settings.publicLoc = 1;
- } else {
- edit.putInt("publicloc", 0);
- settings.publicLoc = 0;
- }
- edit.commit();
-
- CheckBox publicloc = (CheckBox) findViewById(R.id.publicloc);
- if (prefs.getInt("publicloc", 0) == 0) {
- publicloc.setChecked(false);
- } else {
- publicloc.setChecked(true);
- }
-
- return;
- }
- }
-
- private class cgeoChangeCaptcha implements View.OnClickListener {
-
- public void onClick(View arg0) {
- SharedPreferences.Editor edit = prefs.edit();
- if (prefs.getBoolean("showcaptcha", false) == false) {
- edit.putBoolean("showcaptcha", true);
- settings.showCaptcha = true;
- } else {
- edit.putBoolean("showcaptcha", false);
- settings.showCaptcha = false;
- }
- edit.commit();
-
- CheckBox captchaButton = (CheckBox) findViewById(R.id.captcha);
- if (prefs.getBoolean("showcaptcha", false) == false) {
- captchaButton.setChecked(false);
- } else {
- captchaButton.setChecked(true);
- }
-
- return;
- }
- }
-
- private class cgeoChangeUseEnglish implements View.OnClickListener {
-
- public void onClick(View arg0) {
- SharedPreferences.Editor edit = prefs.edit();
- if (prefs.getBoolean("useenglish", false) == false) {
- edit.putBoolean("useenglish", true);
- settings.useEnglish = true;
- settings.setLanguage(true);
- } else {
- edit.putBoolean("useenglish", false);
- settings.useEnglish = false;
- settings.setLanguage(false);
- }
- edit.commit();
-
- CheckBox useEnglishButton = (CheckBox) findViewById(R.id.useenglish);
- if (prefs.getBoolean("useenglish", false) == false) {
- useEnglishButton.setChecked(false);
- } else {
- useEnglishButton.setChecked(true);
- }
-
- return;
- }
- }
-
- private class cgeoChangeAutovisit implements View.OnClickListener {
-
- public void onClick(View arg0) {
- SharedPreferences.Editor edit = prefs.edit();
- if (prefs.getBoolean("trackautovisit", false)) {
- edit.putBoolean("trackautovisit", false);
- settings.trackableAutovisit = false;
- } else {
- edit.putBoolean("trackautovisit", true);
- settings.trackableAutovisit = true;
- }
- edit.commit();
-
- CheckBox autovisitButton = (CheckBox) findViewById(R.id.trackautovisit);
- if (prefs.getBoolean("trackautovisit", false) == false) {
- autovisitButton.setChecked(false);
- } else {
- autovisitButton.setChecked(true);
- }
-
- return;
- }
- }
-
- private class cgeoChangeSignatureAutoinsert implements View.OnClickListener {
-
- public void onClick(View arg0) {
- SharedPreferences.Editor edit = prefs.edit();
- if (prefs.getBoolean("sigautoinsert", false)) {
- edit.putBoolean("sigautoinsert", false);
- settings.signatureAutoinsert = false;
- } else {
- edit.putBoolean("sigautoinsert", true);
- settings.signatureAutoinsert = true;
- }
- edit.commit();
-
- CheckBox autoinsertButton = (CheckBox) findViewById(R.id.sigautoinsert);
- if (prefs.getBoolean("sigautoinsert", false) == false) {
- autoinsertButton.setChecked(false);
- } else {
- autoinsertButton.setChecked(true);
- }
-
- return;
- }
- }
-
- private class cgeoChangeDisabled implements View.OnClickListener {
-
- public void onClick(View arg0) {
- SharedPreferences.Editor edit = prefs.edit();
- if (prefs.getInt("excludedisabled", 0) == 0) {
- edit.putInt("excludedisabled", 1);
- settings.excludeDisabled = 1;
- } else {
- edit.putInt("excludedisabled", 0);
- settings.excludeDisabled = 0;
- }
- edit.commit();
-
- CheckBox disabledButton = (CheckBox) findViewById(R.id.disabled);
- if (prefs.getInt("excludedisabled", 0) == 0) {
- disabledButton.setChecked(false);
- } else {
- disabledButton.setChecked(true);
- }
-
- return;
- }
- }
-
- private class cgeoChangeOffline implements View.OnClickListener {
-
- public void onClick(View arg0) {
- SharedPreferences.Editor edit = prefs.edit();
- if (prefs.getInt("offlinemaps", 1) == 0) {
- edit.putInt("offlinemaps", 1);
- settings.excludeDisabled = 1;
- } else {
- edit.putInt("offlinemaps", 0);
- settings.excludeDisabled = 0;
- }
- edit.commit();
-
- CheckBox offlineButton = (CheckBox) findViewById(R.id.offline);
- if (prefs.getInt("offlinemaps", 0) == 0) {
- offlineButton.setChecked(false);
- } else {
- offlineButton.setChecked(true);
- }
-
- return;
- }
- }
-
- private class cgeoChangeSaveLogImg implements View.OnClickListener {
-
- public void onClick(View arg0) {
- SharedPreferences.Editor edit = prefs.edit();
- if (prefs.getBoolean("logimages", true) == false) {
- edit.putBoolean("logimages", true);
- settings.storelogimages = true;
- } else {
- edit.putBoolean("logimages", false);
- settings.storelogimages = false;
- }
- edit.commit();
-
- CheckBox saveLogImgButton = (CheckBox) findViewById(R.id.save_log_img);
- if (prefs.getBoolean("logimages", true) == false) {
- saveLogImgButton.setChecked(false);
- } else {
- saveLogImgButton.setChecked(true);
- }
-
- return;
- }
- }
-
- private class cgeoChangeLivelist implements View.OnClickListener {
-
- public void onClick(View arg0) {
- SharedPreferences.Editor edit = prefs.edit();
- if (prefs.getInt("livelist", 1) == 0) {
- edit.putInt("livelist", 1);
- settings.livelist = 1;
- } else {
- edit.putInt("livelist", 0);
- settings.livelist = 0;
- }
- edit.commit();
-
- CheckBox livelistButton = (CheckBox) findViewById(R.id.livelist);
- if (prefs.getInt("livelist", 1) == 0) {
- livelistButton.setChecked(false);
- } else {
- livelistButton.setChecked(true);
- }
-
- return;
- }
- }
-
- private class cgeoChangeAutoload implements View.OnClickListener {
-
- public void onClick(View arg0) {
- SharedPreferences.Editor edit = prefs.edit();
- if (prefs.getInt("autoloaddesc", 0) == 0) {
- edit.putInt("autoloaddesc", 1);
- settings.autoLoadDesc = 1;
- } else {
- edit.putInt("autoloaddesc", 0);
- settings.autoLoadDesc = 0;
- }
- edit.commit();
-
- CheckBox autoloadButton = (CheckBox) findViewById(R.id.autoload);
- if (prefs.getInt("autoloaddesc", 0) == 0) {
- autoloadButton.setChecked(false);
- } else {
- autoloadButton.setChecked(true);
- }
-
- return;
- }
- }
-
- private class cgeoChangeUnits implements View.OnClickListener {
-
- public void onClick(View arg0) {
- SharedPreferences.Editor edit = prefs.edit();
- if (prefs.getInt("units", cgSettings.unitsMetric) == cgSettings.unitsMetric) {
- edit.putInt("units", cgSettings.unitsImperial);
- settings.units = cgSettings.unitsImperial;
- } else {
- edit.putInt("units", cgSettings.unitsMetric);
- settings.units = cgSettings.unitsMetric;
- }
- edit.commit();
-
- CheckBox unitsButton = (CheckBox) findViewById(R.id.units);
- if (prefs.getInt("units", cgSettings.unitsMetric) == cgSettings.unitsMetric) {
- unitsButton.setChecked(false);
- } else {
- unitsButton.setChecked(true);
- }
-
- return;
- }
- }
-
- private class cgeoChangeGNav implements View.OnClickListener {
-
- public void onClick(View arg0) {
- SharedPreferences.Editor edit = prefs.edit();
- if (prefs.getInt("usegnav", 1) == 1) {
- edit.putInt("usegnav", 0);
- settings.useGNavigation = 0;
- } else {
- edit.putInt("usegnav", 1);
- settings.useGNavigation = 1;
- }
- edit.commit();
-
- CheckBox gnavButton = (CheckBox) findViewById(R.id.gnav);
- if (prefs.getInt("usegnav", 1) == 1) {
- gnavButton.setChecked(true);
- } else {
- gnavButton.setChecked(false);
- }
-
- return;
- }
- }
-
private class cgeoChangeMapSource implements OnItemSelectedListener {
@Override
public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2,
long arg3) {
- settings.mapSource = mapSourceEnum.fromInt(arg2);
- SharedPreferences.Editor edit = prefs.edit();
- edit.putInt("mapsource", arg2);
- edit.commit();
+ Settings.setMapSource(mapSourceEnum.fromInt(arg2));
}
@Override
public void onNothingSelected(AdapterView<?> arg0) {
- arg0.setSelection(settings.mapSource.ordinal());
+ arg0.setSelection(Settings.getMapSource().ordinal());
}
}
@@ -1031,7 +681,7 @@ public class cgeoinit extends AbstractActivity {
loginDialog = ProgressDialog.show(cgeoinit.this, res.getString(R.string.init_login_popup), res.getString(R.string.init_login_popup_working), true);
loginDialog.setCancelable(false);
- settings.setLogin(username, password);
+ Settings.setLogin(username, password);
cgBase.clearCookies();
(new Thread() {
@@ -1083,10 +733,10 @@ public class cgeoinit extends AbstractActivity {
try {
pin = Integer.parseInt(strings[1].trim());
} catch (Exception e) {
- Log.e(cgSettings.tag, "webDialog: " + e.toString());
+ Log.e(Settings.tag, "webDialog: " + e.toString());
}
String code = strings[0];
- settings.setWebNameCode(nam, code);
+ Settings.setWebNameCode(nam, code);
}
webAuthHandler.sendEmptyMessage(pin);
@@ -1102,7 +752,7 @@ public class cgeoinit extends AbstractActivity {
if (requestCode == SELECT_MAPFILE_REQUEST) {
if (resultCode == RESULT_OK) {
if (data.hasExtra("mapfile")) {
- settings.setMapFile(data.getStringExtra("mapfile"));
+ Settings.setMapFile(data.getStringExtra("mapfile"));
}
}
initMapfileEdittext(true);
diff --git a/main/src/cgeo/geocaching/cgeonavigate.java b/main/src/cgeo/geocaching/cgeonavigate.java
index 5325a58..420b697 100644
--- a/main/src/cgeo/geocaching/cgeonavigate.java
+++ b/main/src/cgeo/geocaching/cgeonavigate.java
@@ -7,7 +7,6 @@ import org.apache.commons.lang3.StringUtils;
import android.content.Context;
import android.content.Intent;
-import android.content.SharedPreferences;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
@@ -53,7 +52,7 @@ public class cgeonavigate extends AbstractActivity {
compassView.updateNorth(northHeading, cacheHeading);
}
} catch (Exception e) {
- Log.e(cgSettings.tag, "cgeonavigate.updaterHandler: " + e.toString());
+ Log.e(Settings.tag, "cgeonavigate.updaterHandler: " + e.toString());
}
}
};
@@ -74,9 +73,9 @@ public class cgeonavigate extends AbstractActivity {
// sensor & geolocation manager
if (geo == null) {
- geo = app.startGeo(this, geoUpdate, base, settings, 0, 0);
+ geo = app.startGeo(this, geoUpdate, base, 0, 0);
}
- if (settings.useCompass == 1 && dir == null) {
+ if (Settings.isUseCompass() && dir == null) {
dir = app.startDir(this, dirUpdate);
}
@@ -131,7 +130,6 @@ public class cgeonavigate extends AbstractActivity {
public void onResume() {
super.onResume();
- settings.load();
if (StringUtils.isNotBlank(title)) {
app.setAction(title);
@@ -141,9 +139,9 @@ public class cgeonavigate extends AbstractActivity {
// sensor & geolocation manager
if (geo == null) {
- geo = app.startGeo(this, geoUpdate, base, settings, 0, 0);
+ geo = app.startGeo(this, geoUpdate, base, 0, 0);
}
- if (settings.useCompass == 1 && dir == null) {
+ if (Settings.isUseCompass() && dir == null) {
dir = app.startDir(this, dirUpdate);
}
@@ -200,7 +198,7 @@ public class cgeonavigate extends AbstractActivity {
@Override
public boolean onCreateOptionsMenu(Menu menu) {
- if (settings.useCompass == 1) {
+ if (Settings.isUseCompass()) {
menu.add(0, 1, 0, res.getString(R.string.use_gps)).setIcon(android.R.drawable.ic_menu_compass);
} else {
menu.add(0, 1, 0, res.getString(R.string.use_compass)).setIcon(android.R.drawable.ic_menu_compass);
@@ -230,7 +228,7 @@ public class cgeonavigate extends AbstractActivity {
MenuItem item;
item = menu.findItem(1);
- if (settings.useCompass == 1) {
+ if (Settings.isUseCompass()) {
item.setTitle(res.getString(R.string.use_gps));
} else {
item.setTitle(res.getString(R.string.use_compass));
@@ -244,33 +242,23 @@ public class cgeonavigate extends AbstractActivity {
int id = item.getItemId();
if (id == 0) {
- Intent mapIntent = new Intent(this, settings.getMapFactory().getMapClass());
+ Intent mapIntent = new Intent(this, Settings.getMapFactory().getMapClass());
mapIntent.putExtra("detail", false);
mapIntent.putExtra("latitude", dstCoords.getLatitude());
mapIntent.putExtra("longitude", dstCoords.getLongitude());
startActivity(mapIntent);
} else if (id == 1) {
- if (settings.useCompass == 1) {
- settings.useCompass = 0;
-
+ boolean oldSetting = Settings.isUseCompass();
+ Settings.setUseCompass(!oldSetting);
+ if (oldSetting) {
if (dir != null) {
dir = app.removeDir();
}
-
- SharedPreferences.Editor prefsEdit = getSharedPreferences(cgSettings.preferences, 0).edit();
- prefsEdit.putInt("usecompass", settings.useCompass);
- prefsEdit.commit();
} else {
- settings.useCompass = 1;
-
if (dir == null) {
dir = app.startDir(this, dirUpdate);
}
-
- SharedPreferences.Editor prefsEdit = getSharedPreferences(cgSettings.preferences, 0).edit();
- prefsEdit.putInt("usecompass", settings.useCompass);
- prefsEdit.commit();
}
} else if (id == 2) {
Intent pointIntent = new Intent(this, cgeopoint.class);
@@ -287,7 +275,7 @@ public class cgeonavigate extends AbstractActivity {
setDestCoords();
updateDistanceInfo();
- Log.d(cgSettings.tag, "destination set: " + title + " (" +
+ Log.d(Settings.tag, "destination set: " + title + " (" +
String.format(Locale.getDefault(), "%.8f", dstCoords.getLatitude()) + " | " +
String.format(Locale.getDefault(), "%.8f", dstCoords.getLongitude()) + ")");
return true;
@@ -382,10 +370,10 @@ public class cgeonavigate extends AbstractActivity {
}
if (geo.accuracyNow != null) {
- if (settings.units == cgSettings.unitsImperial) {
- navAccuracy.setText("±" + String.format(Locale.getDefault(), "%.0f", (geo.accuracyNow * 3.2808399)) + " ft");
- } else {
+ if (Settings.isUseMetricUnits()) {
navAccuracy.setText("±" + String.format(Locale.getDefault(), "%.0f", geo.accuracyNow) + " m");
+ } else {
+ navAccuracy.setText("±" + String.format(Locale.getDefault(), "%.0f", (geo.accuracyNow * 3.2808399)) + " ft");
}
} else {
navAccuracy.setText(null);
@@ -393,10 +381,10 @@ public class cgeonavigate extends AbstractActivity {
if (geo.altitudeNow != null) {
String humanAlt;
- if (settings.units == cgSettings.unitsImperial) {
- humanAlt = String.format("%.0f", (geo.altitudeNow * 3.2808399)) + " ft";
- } else {
+ if (Settings.isUseMetricUnits()) {
humanAlt = String.format("%.0f", geo.altitudeNow) + " m";
+ } else {
+ humanAlt = String.format("%.0f", (geo.altitudeNow * 3.2808399)) + " ft";
}
navLocation.setText(cgBase.formatCoords(geo.coordsNow, true) + " | " + humanAlt);
} else {
@@ -410,7 +398,7 @@ public class cgeonavigate extends AbstractActivity {
navLocation.setText(res.getString(R.string.loc_trying));
}
- if (settings.useCompass == 0 || (geo.speedNow != null && geo.speedNow > 5)) { // use GPS when speed is higher than 18 km/h
+ if (!Settings.isUseCompass() || (geo.speedNow != null && geo.speedNow > 5)) { // use GPS when speed is higher than 18 km/h
if (geo.bearingNow != null) {
northHeading = geo.bearingNow;
} else {
@@ -418,7 +406,7 @@ public class cgeonavigate extends AbstractActivity {
}
}
} catch (Exception e) {
- Log.w(cgSettings.tag, "Failed to update location.");
+ Log.w(Settings.tag, "Failed to update location.");
}
}
}
diff --git a/main/src/cgeo/geocaching/cgeopoint.java b/main/src/cgeo/geocaching/cgeopoint.java
index 140619c..0a60b43 100644
--- a/main/src/cgeo/geocaching/cgeopoint.java
+++ b/main/src/cgeo/geocaching/cgeopoint.java
@@ -11,7 +11,6 @@ import org.apache.commons.lang3.StringUtils;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
-import android.content.SharedPreferences;
import android.content.res.Configuration;
import android.os.Bundle;
import android.util.Log;
@@ -198,7 +197,6 @@ public class cgeopoint extends AbstractActivity {
public void onResume() {
super.onResume();
- settings.load();
init();
}
@@ -231,7 +229,7 @@ public class cgeopoint extends AbstractActivity {
private void init() {
if (geo == null) {
- geo = app.startGeo(this, geoUpdate, base, settings, 0, 0);
+ geo = app.startGeo(this, geoUpdate, base, 0, 0);
}
latButton = (Button) findViewById(R.id.buttonLatitude);
@@ -258,7 +256,7 @@ public class cgeopoint extends AbstractActivity {
if (latButton.getText().length() > 0 && lonButton.getText().length() > 0) {
gp = new Geopoint(latButton.getText().toString() + " " + lonButton.getText().toString());
}
- cgeocoords coordsDialog = new cgeocoords(cgeopoint.this, settings, gp, geo);
+ cgeocoords coordsDialog = new cgeocoords(cgeopoint.this, gp, geo);
coordsDialog.setCancelable(true);
coordsDialog.setOnCoordinateUpdate(new cgeocoords.CoordinateUpdate() {
@Override
@@ -429,7 +427,7 @@ public class cgeopoint extends AbstractActivity {
cachesIntent.putExtra("type", "coordinate");
cachesIntent.putExtra("latitude", coords.getLatitude());
cachesIntent.putExtra("longitude", coords.getLongitude());
- cachesIntent.putExtra("cachetype", settings.cacheType);
+ cachesIntent.putExtra("cachetype", Settings.getCacheType());
startActivity(cachesIntent);
@@ -448,7 +446,7 @@ public class cgeopoint extends AbstractActivity {
latButton.setHint(cgBase.formatLatitude(geo.coordsNow.getLatitude(), false));
lonButton.setHint(cgBase.formatLongitude(geo.coordsNow.getLongitude(), false));
} catch (Exception e) {
- Log.w(cgSettings.tag, "Failed to update location.");
+ Log.w(Settings.tag, "Failed to update location.");
}
}
}
@@ -514,7 +512,7 @@ public class cgeopoint extends AbstractActivity {
double distance;
try {
- distance = DistanceParser.parseDistance(distanceText, settings.units);
+ distance = DistanceParser.parseDistance(distanceText, Settings.isUseMetricUnits());
} catch (NumberFormatException e) {
showToast(res.getString(R.string.err_parse_dist));
return null;
@@ -540,20 +538,9 @@ public class cgeopoint extends AbstractActivity {
}
private void saveCoords(final Geopoint coords) {
- if (changed && coords != null) {
- SharedPreferences.Editor edit = prefs.edit();
-
- edit.putFloat("anylatitude", (float) coords.getLatitude());
- edit.putFloat("anylongitude", (float) coords.getLongitude());
-
- edit.commit();
- } else {
- SharedPreferences.Editor edit = prefs.edit();
-
- edit.remove("anylatitude");
- edit.remove("anylongitude");
-
- edit.commit();
+ if (!changed) {
+ return;
}
+ Settings.setAnyCoordinates(coords);
}
}
diff --git a/main/src/cgeo/geocaching/cgeopopup.java b/main/src/cgeo/geocaching/cgeopopup.java
index a74e681..502280b 100644
--- a/main/src/cgeo/geocaching/cgeopopup.java
+++ b/main/src/cgeo/geocaching/cgeopopup.java
@@ -67,7 +67,7 @@ public class cgeopopup extends AbstractActivity {
} catch (Exception e) {
showToast(res.getString(R.string.err_store));
- Log.e(cgSettings.tag, "cgeopopup.storeCacheHandler: " + e.toString());
+ Log.e(Settings.tag, "cgeopopup.storeCacheHandler: " + e.toString());
}
if (storeDialog != null) {
@@ -90,7 +90,7 @@ public class cgeopopup extends AbstractActivity {
} catch (Exception e) {
showToast(res.getString(R.string.err_drop));
- Log.e(cgSettings.tag, "cgeopopup.dropCacheHandler: " + e.toString());
+ Log.e(Settings.tag, "cgeopopup.dropCacheHandler: " + e.toString());
}
if (dropDialog != null) {
@@ -156,7 +156,7 @@ public class cgeopopup extends AbstractActivity {
menu.findItem(5).setVisible(false);
}
- boolean visitPossible = fromDetail == false && cgSettings.isLogin();
+ boolean visitPossible = fromDetail == false && Settings.isLogin();
menu.findItem(MENU_LOG_VISIT).setEnabled(visitPossible);
} catch (Exception e) {
// nothing
@@ -189,13 +189,13 @@ public class cgeopopup extends AbstractActivity {
}
int logType = menuItem - MENU_LOG_VISIT_OFFLINE;
- cache.logOffline(this, logType, settings, base);
+ cache.logOffline(this, logType, base);
return true;
}
private void init() {
if (geo == null) {
- geo = app.startGeo(this, geoUpdate, base, settings, 0, 0);
+ geo = app.startGeo(this, geoUpdate, base, 0, 0);
}
app.setAction(geocode);
@@ -455,7 +455,7 @@ public class cgeopopup extends AbstractActivity {
((LinearLayout) findViewById(R.id.offline_box)).setVisibility(View.GONE);
}
} catch (Exception e) {
- Log.e(cgSettings.tag, "cgeopopup.init: " + e.toString());
+ Log.e(Settings.tag, "cgeopopup.init: " + e.toString());
}
if (geo != null) {
@@ -474,7 +474,6 @@ public class cgeopopup extends AbstractActivity {
public void onResume() {
super.onResume();
- settings.load();
init();
}
@@ -519,7 +518,7 @@ public class cgeopopup extends AbstractActivity {
cacheDistance.bringToFront();
}
} catch (Exception e) {
- Log.w(cgSettings.tag, "Failed to update location.");
+ Log.w(Settings.tag, "Failed to update location.");
}
}
}
diff --git a/main/src/cgeo/geocaching/cgeosmaps.java b/main/src/cgeo/geocaching/cgeosmaps.java
index 96c9e0d..fd3d6e8 100644
--- a/main/src/cgeo/geocaching/cgeosmaps.java
+++ b/main/src/cgeo/geocaching/cgeosmaps.java
@@ -65,7 +65,7 @@ public class cgeosmaps extends AbstractActivity {
if (waitDialog != null) {
waitDialog.dismiss();
}
- Log.e(cgSettings.tag, "cgeosmaps.loadMapsHandler: " + e.toString());
+ Log.e(Settings.tag, "cgeosmaps.loadMapsHandler: " + e.toString());
}
}
};
@@ -102,7 +102,6 @@ public class cgeosmaps extends AbstractActivity {
public void onResume() {
super.onResume();
- settings.load();
}
private class loadMaps extends Thread {
@@ -116,31 +115,31 @@ public class cgeosmaps extends AbstractActivity {
for (int level = 1; level <= 5; level++) {
try {
- Bitmap image = BitmapFactory.decodeFile(cgSettings.getStorage() + geocode + "/map_" + level);
+ Bitmap image = BitmapFactory.decodeFile(Settings.getStorage() + geocode + "/map_" + level);
if (image != null) {
maps.add(image);
}
} catch (Exception e) {
- Log.e(cgSettings.tag, "cgeosmaps.loadMaps.run.1: " + e.toString());
+ Log.e(Settings.tag, "cgeosmaps.loadMaps.run.1: " + e.toString());
}
}
if (maps.isEmpty()) {
for (int level = 1; level <= 5; level++) {
try {
- Bitmap image = BitmapFactory.decodeFile(cgSettings.getStorageSec() + geocode + "/map_" + level);
+ Bitmap image = BitmapFactory.decodeFile(Settings.getStorageSec() + geocode + "/map_" + level);
if (image != null) {
maps.add(image);
}
} catch (Exception e) {
- Log.e(cgSettings.tag, "cgeosmaps.loadMaps.run.2: " + e.toString());
+ Log.e(Settings.tag, "cgeosmaps.loadMaps.run.2: " + e.toString());
}
}
}
loadMapsHandler.sendMessage(new Message());
} catch (Exception e) {
- Log.e(cgSettings.tag, "cgeosmaps.loadMaps.run: " + e.toString());
+ Log.e(Settings.tag, "cgeosmaps.loadMaps.run: " + e.toString());
}
}
}
diff --git a/main/src/cgeo/geocaching/cgeotouch.java b/main/src/cgeo/geocaching/cgeotouch.java
index f423d87..d46108e 100644
--- a/main/src/cgeo/geocaching/cgeotouch.java
+++ b/main/src/cgeo/geocaching/cgeotouch.java
@@ -149,7 +149,6 @@ public class cgeotouch extends cgLogForm {
public void onResume() {
super.onResume();
- settings.load();
}
@Override
@@ -174,7 +173,7 @@ public class cgeotouch extends cgLogForm {
@Override
public boolean onPrepareOptionsMenu(Menu menu) {
- if (settings.getSignature() == null) {
+ if (Settings.getSignature() == null) {
menu.findItem(0x1).setVisible(false);
menu.findItem(0x7).setVisible(false);
} else {
@@ -212,14 +211,14 @@ public class cgeotouch extends cgLogForm {
if ((id & 0x2) == 0x2) {
addText += timeString;
}
- if ((id & 0x1) == 0x1 && settings.getSignature() != null) {
+ if ((id & 0x1) == 0x1 && Settings.getSignature() != null) {
if (addText.length() > 0) {
addText += "\n";
}
- addText += settings.getSignature()
+ addText += Settings.getSignature()
.replaceAll("\\[DATE\\]", dateString)
.replaceAll("\\[TIME\\]", timeString)
- .replaceAll("\\[USER\\]", settings.getUsername())
+ .replaceAll("\\[USER\\]", Settings.getUsername())
.replaceAll("\\[NUMBER\\]", "");
}
if (textContent.length() > 0 && addText.length() > 0) {
@@ -239,8 +238,9 @@ public class cgeotouch extends cgLogForm {
final int viewId = view.getId();
if (viewId == R.id.type) {
- for (final int typeOne : types)
+ for (final int typeOne : types) {
menu.add(viewId, typeOne, 0, cgBase.logTypes2.get(typeOne));
+ }
}
}
@@ -259,8 +259,9 @@ public class cgeotouch extends cgLogForm {
}
public void init() {
- if (geocode != null)
+ if (geocode != null) {
app.setAction("logging trackable");
+ }
types.clear();
types.add(cgBase.LOG_RETRIEVED_IT);
@@ -268,8 +269,9 @@ public class cgeotouch extends cgLogForm {
types.add(cgBase.LOG_NOTE);
types.add(cgBase.LOG_DISCOVERED_IT);
- if (typeSelected < 0 && cgBase.logTypes2.get(typeSelected) == null)
+ if (typeSelected < 0 && cgBase.logTypes2.get(typeSelected) == null) {
typeSelected = types.get(2);
+ }
setType(typeSelected);
Button typeButton = (Button) findViewById(R.id.type);
@@ -285,10 +287,12 @@ public class cgeotouch extends cgLogForm {
dateButton.setText(base.formatShortDate(date.getTime().getTime()));
dateButton.setOnClickListener(new cgeotouchDateListener());
- if (tweetBox == null)
+ if (tweetBox == null) {
tweetBox = (LinearLayout) findViewById(R.id.tweet_box);
- if (tweetCheck == null)
+ }
+ if (tweetCheck == null) {
tweetCheck = (CheckBox) findViewById(R.id.tweet);
+ }
tweetCheck.setChecked(true);
Button buttonPost = (Button) findViewById(R.id.post);
@@ -316,18 +320,22 @@ public class cgeotouch extends cgLogForm {
public void setType(int type) {
final Button typeButton = (Button) findViewById(R.id.type);
- if (cgBase.logTypes2.get(type) != null)
+ if (cgBase.logTypes2.get(type) != null) {
typeSelected = type;
- if (cgBase.logTypes2.get(typeSelected) == null)
+ }
+ if (cgBase.logTypes2.get(typeSelected) == null) {
typeSelected = 0;
+ }
typeButton.setText(cgBase.logTypes2.get(typeSelected));
- if (tweetBox == null)
+ if (tweetBox == null) {
tweetBox = (LinearLayout) findViewById(R.id.tweet_box);
- if (settings.twitter == 1)
+ }
+ if (Settings.isUseTwitter()) {
tweetBox.setVisibility(View.VISIBLE);
- else
+ } else {
tweetBox.setVisibility(View.GONE);
+ }
}
private class cgeotouchDateListener implements View.OnClickListener {
@@ -401,7 +409,7 @@ public class cgeotouch extends cgLogForm {
showToast(res.getString(R.string.info_log_type_changed));
}
} catch (Exception e) {
- Log.e(cgSettings.tag, "cgeotouch.loadData.run: " + e.toString());
+ Log.e(Settings.tag, "cgeotouch.loadData.run: " + e.toString());
}
loadDataHandler.sendEmptyMessage(0);
@@ -433,22 +441,24 @@ public class cgeotouch extends cgLogForm {
int status = -1;
try {
- if (tweetBox == null)
+ if (tweetBox == null) {
tweetBox = (LinearLayout) findViewById(R.id.tweet_box);
- if (tweetCheck == null)
+ }
+ if (tweetCheck == null) {
tweetCheck = (CheckBox) findViewById(R.id.tweet);
+ }
status = base.postLogTrackable(guid, tracking, viewstates, typeSelected, date.get(Calendar.YEAR), (date.get(Calendar.MONTH) + 1), date.get(Calendar.DATE), log);
- if (status == 1 && settings.twitter == 1 &&
- StringUtils.isNotBlank(settings.tokenPublic) && StringUtils.isNotBlank(settings.tokenSecret) &&
+ if (status == 1 && Settings.isUseTwitter() &&
+ Settings.isTwitterLoginValid() &&
tweetCheck.isChecked() && tweetBox.getVisibility() == View.VISIBLE) {
- cgBase.postTweetTrackable(app, settings, geocode);
+ cgBase.postTweetTrackable(app, geocode);
}
return status;
} catch (Exception e) {
- Log.e(cgSettings.tag, "cgeotouch.postLogFn: " + e.toString());
+ Log.e(Settings.tag, "cgeotouch.postLogFn: " + e.toString());
}
return 1000;
diff --git a/main/src/cgeo/geocaching/cgeotrackable.java b/main/src/cgeo/geocaching/cgeotrackable.java
index 8d847a0..0f8da92 100644
--- a/main/src/cgeo/geocaching/cgeotrackable.java
+++ b/main/src/cgeo/geocaching/cgeotrackable.java
@@ -280,7 +280,7 @@ public class cgeotrackable extends AbstractActivity {
Message message = handler.obtainMessage(0, image);
handler.sendMessage(message);
} catch (Exception e) {
- Log.e(cgSettings.tag, "cgeospoilers.onCreate.onClick.run: " + e.toString());
+ Log.e(Settings.tag, "cgeospoilers.onCreate.onClick.run: " + e.toString());
}
}
}.start();
@@ -288,7 +288,7 @@ public class cgeotrackable extends AbstractActivity {
imgView.addView(trackableImage);
}
} catch (Exception e) {
- Log.e(cgSettings.tag, "cgeotrackable.loadTrackableHandler: " + e.toString() + Arrays.toString(e.getStackTrace()));
+ Log.e(Settings.tag, "cgeotrackable.loadTrackableHandler: " + e.toString() + Arrays.toString(e.getStackTrace()));
}
displayLogs();
@@ -387,7 +387,6 @@ public class cgeotrackable extends AbstractActivity {
public void onResume() {
super.onResume();
- settings.load();
}
@Override
@@ -580,7 +579,7 @@ public class cgeotrackable extends AbstractActivity {
Message message = handler.obtainMessage(0, image);
handler.sendMessage(message);
} catch (Exception e) {
- Log.e(cgSettings.tag, "cgeotrackable.tbIconThread.run: " + e.toString());
+ Log.e(Settings.tag, "cgeotrackable.tbIconThread.run: " + e.toString());
}
}
}
diff --git a/main/src/cgeo/geocaching/cgeotrackables.java b/main/src/cgeo/geocaching/cgeotrackables.java
index ef6752f..c27ce11 100644
--- a/main/src/cgeo/geocaching/cgeotrackables.java
+++ b/main/src/cgeo/geocaching/cgeotrackables.java
@@ -74,7 +74,7 @@ public class cgeotrackables extends AbstractActivity {
if (waitDialog != null) {
waitDialog.dismiss();
}
- Log.e(cgSettings.tag, "cgeotrackables.loadInventoryHandler: " + e.toString());
+ Log.e(Settings.tag, "cgeotrackables.loadInventoryHandler: " + e.toString());
}
}
};
@@ -115,7 +115,6 @@ public class cgeotrackables extends AbstractActivity {
public void onResume() {
super.onResume();
- settings.load();
}
private class loadInventory extends Thread {
@@ -127,7 +126,7 @@ public class cgeotrackables extends AbstractActivity {
loadInventoryHandler.sendMessage(new Message());
} catch (Exception e) {
- Log.e(cgSettings.tag, "cgeotrackables.loadInventory.run: " + e.toString());
+ Log.e(Settings.tag, "cgeotrackables.loadInventory.run: " + e.toString());
}
}
}
diff --git a/main/src/cgeo/geocaching/cgeovisit.java b/main/src/cgeo/geocaching/cgeovisit.java
index f9575ba..6a5ca09 100644
--- a/main/src/cgeo/geocaching/cgeovisit.java
+++ b/main/src/cgeo/geocaching/cgeovisit.java
@@ -120,7 +120,7 @@ public class cgeovisit extends cgLogForm {
((TextView) inventoryItem.findViewById(R.id.trackcode)).setText(tb.trackCode);
((TextView) inventoryItem.findViewById(R.id.name)).setText(tb.name);
- ((TextView) inventoryItem.findViewById(R.id.action)).setText(cgBase.logTypesTrackable.get(settings.trackableAutovisit ? 1 : 0));
+ ((TextView) inventoryItem.findViewById(R.id.action)).setText(cgBase.logTypesTrackable.get(Settings.isTrackableAutoVisit() ? 1 : 0));
inventoryItem.setId(tb.id);
final String tbCode = tb.trackCode;
@@ -143,7 +143,7 @@ public class cgeovisit extends cgLogForm {
inventoryView.addView(inventoryItem);
- if (settings.trackableAutovisit)
+ if (Settings.isTrackableAutoVisit())
{
tb.action = 1;
tbChanged = true;
@@ -264,7 +264,6 @@ public class cgeovisit extends cgLogForm {
public void onResume() {
super.onResume();
- settings.load();
}
@Override
@@ -307,10 +306,10 @@ public class cgeovisit extends cgLogForm {
@Override
public boolean onPrepareOptionsMenu(Menu menu) {
- boolean signatureAvailable = settings.getSignature() != null;
+ boolean signatureAvailable = Settings.getSignature() != null;
menu.findItem(MENU_SIGNATURE).setVisible(signatureAvailable);
- boolean voteAvailable = settings.isGCvoteLogin() && typeSelected == cgBase.LOG_FOUND_IT && StringUtils.isNotBlank(cache.guid);
+ boolean voteAvailable = Settings.isGCvoteLogin() && typeSelected == cgBase.LOG_FOUND_IT && StringUtils.isNotBlank(cache.guid);
menu.findItem(SUBMENU_VOTE).setVisible(voteAvailable);
return true;
@@ -326,7 +325,7 @@ public class cgeovisit extends cgLogForm {
if (StringUtils.isNotBlank(content)) {
insertIntoLog("\n", false);
}
- insertIntoLog(LogTemplateProvider.applyTemplates(settings.getSignature(), base, false), false);
+ insertIntoLog(LogTemplateProvider.applyTemplates(Settings.getSignature(), base, false), false);
return true;
} else if (id >= 10 && id <= 19) {
rating = (id - 9) / 2.0;
@@ -367,7 +366,7 @@ public class cgeovisit extends cgLogForm {
if (viewId == R.id.type) {
for (final int typeOne : types) {
menu.add(viewId, typeOne, 0, cgBase.logTypes2.get(typeOne));
- Log.w(cgSettings.tag, "Adding " + typeOne + " " + cgBase.logTypes2.get(typeOne));
+ Log.w(Settings.tag, "Adding " + typeOne + " " + cgBase.logTypes2.get(typeOne));
}
} else if (viewId == R.id.changebutton) {
final int textId = ((TextView) findViewById(viewId)).getId();
@@ -423,7 +422,7 @@ public class cgeovisit extends cgLogForm {
return true;
}
} catch (Exception e) {
- Log.e(cgSettings.tag, "cgeovisit.onContextItemSelected: " + e.toString());
+ Log.e(Settings.tag, "cgeovisit.onContextItemSelected: " + e.toString());
}
} else {
try {
@@ -446,14 +445,14 @@ public class cgeovisit extends cgLogForm {
tb.action = id;
tbText.setText(logTbAction);
- Log.i(cgSettings.tag, "Trackable " + tb.trackCode + " (" + tb.name + ") has new action: #" + id);
+ Log.i(Settings.tag, "Trackable " + tb.trackCode + " (" + tb.name + ") has new action: #" + id);
}
}
return true;
}
} catch (Exception e) {
- Log.e(cgSettings.tag, "cgeovisit.onContextItemSelected: " + e.toString());
+ Log.e(Settings.tag, "cgeovisit.onContextItemSelected: " + e.toString());
}
}
@@ -465,23 +464,23 @@ public class cgeovisit extends cgLogForm {
app.setAction(geocode);
}
- types = cache.getPossibleLogTypes(settings);
+ types = cache.getPossibleLogTypes();
final cgLog log = app.loadLogOffline(geocode);
if (log != null) {
typeSelected = log.type;
date.setTime(new Date(log.date));
text = log.log;
- if (typeSelected == cgBase.LOG_FOUND_IT && settings.isGCvoteLogin()) {
+ if (typeSelected == cgBase.LOG_FOUND_IT && Settings.isGCvoteLogin()) {
if (post == null) {
post = (Button) findViewById(R.id.post);
}
post.setText(res.getString(R.string.log_post_no_rate));
}
- } else if (StringUtils.isNotBlank(settings.getSignature())
- && settings.signatureAutoinsert
+ } else if (StringUtils.isNotBlank(Settings.getSignature())
+ && Settings.isAutoInsertSignature()
&& StringUtils.isBlank(((EditText) findViewById(R.id.log)).getText())) {
- text = "\n" + LogTemplateProvider.applyTemplates(settings.getSignature(), base, false);
+ text = "\n" + LogTemplateProvider.applyTemplates(Settings.getSignature(), base, false);
insertIntoLog(text, false);
}
@@ -582,7 +581,7 @@ public class cgeovisit extends cgLogForm {
// TODO: change action
}
- if (type == cgBase.LOG_FOUND_IT && settings.twitter == 1) {
+ if (type == cgBase.LOG_FOUND_IT && Settings.isUseTwitter()) {
tweetBox.setVisibility(View.VISIBLE);
} else {
tweetBox.setVisibility(View.GONE);
@@ -592,7 +591,7 @@ public class cgeovisit extends cgLogForm {
post = (Button) findViewById(R.id.post);
}
- if (type == cgBase.LOG_FOUND_IT && settings.isGCvoteLogin()) {
+ if (type == cgBase.LOG_FOUND_IT && Settings.isGCvoteLogin()) {
if (rating == 0) {
post.setText(res.getString(R.string.log_post_no_rate));
} else {
@@ -699,7 +698,7 @@ public class cgeovisit extends cgLogForm {
}
typesPre.clear();
} catch (Exception e) {
- Log.e(cgSettings.tag, "cgeovisit.loadData.run: " + e.toString());
+ Log.e(Settings.tag, "cgeovisit.loadData.run: " + e.toString());
}
loadDataHandler.sendEmptyMessage(0);
@@ -743,7 +742,7 @@ public class cgeovisit extends cgLogForm {
if (status == 1) {
cgLog logNow = new cgLog();
- logNow.author = settings.getUsername();
+ logNow.author = Settings.getUsername();
logNow.date = date.getTimeInMillis();
logNow.type = typeSelected;
logNow.log = log;
@@ -771,19 +770,19 @@ public class cgeovisit extends cgLogForm {
app.clearLogOffline(geocode);
}
- if (status == 1 && typeSelected == cgBase.LOG_FOUND_IT && settings.twitter == 1
- && StringUtils.isNotBlank(settings.tokenPublic) && StringUtils.isNotBlank(settings.tokenSecret)
+ if (status == 1 && typeSelected == cgBase.LOG_FOUND_IT && Settings.isUseTwitter()
+ && Settings.isTwitterLoginValid()
&& tweetCheck.isChecked() && tweetBox.getVisibility() == View.VISIBLE) {
- cgBase.postTweetCache(app, settings, geocode);
+ cgBase.postTweetCache(app, geocode);
}
- if (status == 1 && typeSelected == cgBase.LOG_FOUND_IT && settings.isGCvoteLogin()) {
+ if (status == 1 && typeSelected == cgBase.LOG_FOUND_IT && Settings.isGCvoteLogin()) {
GCVote.setRating(cache, rating);
}
return status;
} catch (Exception e) {
- Log.e(cgSettings.tag, "cgeovisit.postLogFn: " + e.toString());
+ Log.e(Settings.tag, "cgeovisit.postLogFn: " + e.toString());
}
return 1000;
diff --git a/main/src/cgeo/geocaching/cgeowaypoint.java b/main/src/cgeo/geocaching/cgeowaypoint.java
index 5f3c7e8..e6ef877 100644
--- a/main/src/cgeo/geocaching/cgeowaypoint.java
+++ b/main/src/cgeo/geocaching/cgeowaypoint.java
@@ -107,7 +107,7 @@ public class cgeowaypoint extends AbstractActivity {
waitDialog.dismiss();
waitDialog = null;
}
- Log.e(cgSettings.tag, "cgeowaypoint.loadWaypointHandler: " + e.toString());
+ Log.e(Settings.tag, "cgeowaypoint.loadWaypointHandler: " + e.toString());
}
}
@@ -153,7 +153,7 @@ public class cgeowaypoint extends AbstractActivity {
}
if (geo == null) {
- geo = app.startGeo(this, geoUpdate, base, settings, 0, 0);
+ geo = app.startGeo(this, geoUpdate, base, 0, 0);
}
waitDialog = ProgressDialog.show(this, null, res.getString(R.string.waypoint_loading), true);
@@ -166,10 +166,9 @@ public class cgeowaypoint extends AbstractActivity {
public void onResume() {
super.onResume();
- settings.load();
if (geo == null) {
- geo = app.startGeo(this, geoUpdate, base, settings, 0, 0);
+ geo = app.startGeo(this, geoUpdate, base, 0, 0);
}
if (waitDialog == null) {
@@ -272,7 +271,7 @@ public class cgeowaypoint extends AbstractActivity {
loadWaypointHandler.sendMessage(new Message());
} catch (Exception e) {
- Log.e(cgSettings.tag, "cgeowaypoint.loadWaypoint.run: " + e.toString());
+ Log.e(Settings.tag, "cgeowaypoint.loadWaypoint.run: " + e.toString());
}
}
}
diff --git a/main/src/cgeo/geocaching/cgeowaypointadd.java b/main/src/cgeo/geocaching/cgeowaypointadd.java
index e53ae0a..b33e3ff 100644
--- a/main/src/cgeo/geocaching/cgeowaypointadd.java
+++ b/main/src/cgeo/geocaching/cgeowaypointadd.java
@@ -76,7 +76,7 @@ public class cgeowaypointadd extends AbstractActivity {
waitDialog.dismiss();
waitDialog = null;
}
- Log.e(cgSettings.tag, "cgeowaypointadd.loadWaypointHandler: " + e.toString());
+ Log.e(Settings.tag, "cgeowaypointadd.loadWaypointHandler: " + e.toString());
}
}
};
@@ -90,7 +90,7 @@ public class cgeowaypointadd extends AbstractActivity {
setTitle("waypoint");
if (geo == null) {
- geo = app.startGeo(this, geoUpdate, base, settings, 0, 0);
+ geo = app.startGeo(this, geoUpdate, base, 0, 0);
}
// get parameters
@@ -143,10 +143,9 @@ public class cgeowaypointadd extends AbstractActivity {
public void onResume() {
super.onResume();
- settings.load();
if (geo == null) {
- geo = app.startGeo(this, geoUpdate, base, settings, 0, 0);
+ geo = app.startGeo(this, geoUpdate, base, 0, 0);
}
if (id > 0) {
@@ -200,7 +199,7 @@ public class cgeowaypointadd extends AbstractActivity {
bLat.setHint(cgBase.formatLatitude(geo.coordsNow.getLatitude(), false));
bLon.setHint(cgBase.formatLongitude(geo.coordsNow.getLongitude(), false));
} catch (Exception e) {
- Log.w(cgSettings.tag, "Failed to update location.");
+ Log.w(Settings.tag, "Failed to update location.");
}
}
}
@@ -214,7 +213,7 @@ public class cgeowaypointadd extends AbstractActivity {
loadWaypointHandler.sendMessage(new Message());
} catch (Exception e) {
- Log.e(cgSettings.tag, "cgeowaypoint.loadWaypoint.run: " + e.toString());
+ Log.e(Settings.tag, "cgeowaypoint.loadWaypoint.run: " + e.toString());
}
}
}
@@ -225,7 +224,7 @@ public class cgeowaypointadd extends AbstractActivity {
Geopoint gp = null;
if (waypoint != null && waypoint.coords != null)
gp = waypoint.coords;
- cgeocoords coordsDialog = new cgeocoords(cgeowaypointadd.this, settings, gp, geo);
+ cgeocoords coordsDialog = new cgeocoords(cgeowaypointadd.this, gp, geo);
coordsDialog.setCancelable(true);
coordsDialog.setOnCoordinateUpdate(new cgeocoords.CoordinateUpdate() {
@Override
@@ -292,7 +291,7 @@ public class cgeowaypointadd extends AbstractActivity {
double distance;
try {
- distance = DistanceParser.parseDistance(distanceText, settings.units);
+ distance = DistanceParser.parseDistance(distanceText, Settings.isUseMetricUnits());
} catch (NumberFormatException e) {
showToast(res.getString(R.string.err_parse_dist));
return;
diff --git a/main/src/cgeo/geocaching/compatibility/AndroidLevel8.java b/main/src/cgeo/geocaching/compatibility/AndroidLevel8.java
index 4b7fd62..259cb5c 100644
--- a/main/src/cgeo/geocaching/compatibility/AndroidLevel8.java
+++ b/main/src/cgeo/geocaching/compatibility/AndroidLevel8.java
@@ -1,6 +1,6 @@
package cgeo.geocaching.compatibility;
-import cgeo.geocaching.cgSettings;
+import cgeo.geocaching.Settings;
import android.app.Activity;
import android.app.backup.BackupManager;
@@ -15,7 +15,7 @@ public class AndroidLevel8 {
}
static public void dataChanged(final String name) {
- Log.i(cgSettings.tag, "Requesting settings backup with settings manager");
+ Log.i(Settings.tag, "Requesting settings backup with settings manager");
BackupManager.dataChanged(name);
}
}
diff --git a/main/src/cgeo/geocaching/compatibility/Compatibility.java b/main/src/cgeo/geocaching/compatibility/Compatibility.java
index 72aa4c8..ef2f883 100644
--- a/main/src/cgeo/geocaching/compatibility/Compatibility.java
+++ b/main/src/cgeo/geocaching/compatibility/Compatibility.java
@@ -1,6 +1,6 @@
package cgeo.geocaching.compatibility;
-import cgeo.geocaching.cgSettings;
+import cgeo.geocaching.Settings;
import android.app.Activity;
import android.content.res.Configuration;
@@ -28,7 +28,7 @@ public final class Compatibility {
getRotationMethod = cl.getDeclaredMethod("getRotation", Activity.class);
} catch (final Exception e) {
// Exception can be ClassNotFoundException, SecurityException or NoSuchMethodException
- Log.e(cgSettings.tag, "Cannot load AndroidLevel8 class", e);
+ Log.e(Settings.tag, "Cannot load AndroidLevel8 class", e);
}
}
}
@@ -47,7 +47,7 @@ public final class Compatibility {
}
} catch (final Exception e) {
// This should never happen: IllegalArgumentException, IllegalAccessException or InvocationTargetException
- Log.e(cgSettings.tag, "Cannot call getRotation()", e);
+ Log.e(Settings.tag, "Cannot call getRotation()", e);
}
} else {
final Display display = activity.getWindowManager()
@@ -74,7 +74,7 @@ public final class Compatibility {
dataChangedMethod.invoke(null, name);
} catch (final Exception e) {
// This should never happen: IllegalArgumentException, IllegalAccessException or InvocationTargetException
- Log.e(cgSettings.tag, "Cannot call dataChanged()", e);
+ Log.e(Settings.tag, "Cannot call dataChanged()", e);
}
}
}
diff --git a/main/src/cgeo/geocaching/connector/GCConnector.java b/main/src/cgeo/geocaching/connector/GCConnector.java
index c7eec10..a7917b1 100644
--- a/main/src/cgeo/geocaching/connector/GCConnector.java
+++ b/main/src/cgeo/geocaching/connector/GCConnector.java
@@ -5,7 +5,7 @@ import cgeo.geocaching.cgBase;
import cgeo.geocaching.cgCache;
import cgeo.geocaching.cgCacheWrap;
import cgeo.geocaching.cgSearch;
-import cgeo.geocaching.cgSettings;
+import cgeo.geocaching.Settings;
import cgeo.geocaching.cgeoapplication;
import org.apache.commons.lang3.StringUtils;
@@ -79,7 +79,7 @@ public class GCConnector extends AbstractConnector implements IConnector {
if (StringUtils.isEmpty(page)) {
if (app.isThere(geocode, guid, true, false)) {
if (StringUtils.isBlank(geocode) && StringUtils.isNotBlank(guid)) {
- Log.i(cgSettings.tag, "Loading old cache from cache.");
+ Log.i(Settings.tag, "Loading old cache from cache.");
geocode = app.getGeocode(guid);
}
@@ -96,7 +96,7 @@ public class GCConnector extends AbstractConnector implements IConnector {
return search.getCurrentId();
}
- Log.e(cgSettings.tag, "cgeoBase.searchByGeocode: No data from server");
+ Log.e(Settings.tag, "cgeoBase.searchByGeocode: No data from server");
return null;
}
@@ -111,16 +111,16 @@ public class GCConnector extends AbstractConnector implements IConnector {
app.addSearch(search, null, true, reason);
- Log.e(cgSettings.tag, "cgeoBase.searchByGeocode: No cache parsed");
+ Log.e(Settings.tag, "cgeoBase.searchByGeocode: No cache parsed");
return null;
}
if (app == null) {
- Log.e(cgSettings.tag, "cgeoBase.searchByGeocode: No application found");
+ Log.e(Settings.tag, "cgeoBase.searchByGeocode: No application found");
return null;
}
- List<cgCache> cacheList = cgBase.processSearchResults(search, caches, 0, 0, null);
+ List<cgCache> cacheList = cgBase.processSearchResults(search, caches, false, false, null);
app.addSearch(search, cacheList, true, reason);
return search.getCurrentId();
diff --git a/main/src/cgeo/geocaching/connector/opencaching/ApiOpenCachingConnector.java b/main/src/cgeo/geocaching/connector/opencaching/ApiOpenCachingConnector.java
index aa86a81..0773532 100644
--- a/main/src/cgeo/geocaching/connector/opencaching/ApiOpenCachingConnector.java
+++ b/main/src/cgeo/geocaching/connector/opencaching/ApiOpenCachingConnector.java
@@ -45,7 +45,7 @@ public class ApiOpenCachingConnector extends OpenCachingConnector implements ICo
final cgCacheWrap caches = new cgCacheWrap();
caches.cacheList.add(cache);
- final List<cgCache> cacheList = cgBase.processSearchResults(search, caches, 0, 0, null);
+ final List<cgCache> cacheList = cgBase.processSearchResults(search, caches, false, false, null);
app.addSearch(search, cacheList, true, reason);
return search.getCurrentId();
diff --git a/main/src/cgeo/geocaching/files/FileList.java b/main/src/cgeo/geocaching/files/FileList.java
index 5998436..1d7fbfa 100644
--- a/main/src/cgeo/geocaching/files/FileList.java
+++ b/main/src/cgeo/geocaching/files/FileList.java
@@ -1,7 +1,7 @@
package cgeo.geocaching.files;
import cgeo.geocaching.R;
-import cgeo.geocaching.cgSettings;
+import cgeo.geocaching.Settings;
import cgeo.geocaching.activity.AbstractListActivity;
import org.apache.commons.lang3.ArrayUtils;
@@ -63,7 +63,7 @@ public abstract class FileList<T extends ArrayAdapter<File>> extends AbstractLis
if (waitDialog != null) {
waitDialog.dismiss();
}
- Log.e(cgSettings.tag, "cgFileList.loadFilesHandler: " + e.toString());
+ Log.e(Settings.tag, "cgFileList.loadFilesHandler: " + e.toString());
}
}
};
@@ -114,7 +114,6 @@ public abstract class FileList<T extends ArrayAdapter<File>> extends AbstractLis
public void onResume() {
super.onResume();
- getSettings().load();
}
protected abstract T getAdapter(List<File> files);
@@ -166,10 +165,10 @@ public abstract class FileList<T extends ArrayAdapter<File>> extends AbstractLis
listDir(list, Environment.getExternalStorageDirectory());
}
} else {
- Log.w(cgSettings.tag, "No external media mounted.");
+ Log.w(Settings.tag, "No external media mounted.");
}
} catch (Exception e) {
- Log.e(cgSettings.tag, "cgFileList.loadFiles.run: " + e.toString());
+ Log.e(Settings.tag, "cgFileList.loadFiles.run: " + e.toString());
}
final Message msg = new Message();
diff --git a/main/src/cgeo/geocaching/files/GPXParser.java b/main/src/cgeo/geocaching/files/GPXParser.java
index 3f05cd7..3856593 100644
--- a/main/src/cgeo/geocaching/files/GPXParser.java
+++ b/main/src/cgeo/geocaching/files/GPXParser.java
@@ -5,7 +5,7 @@ import cgeo.geocaching.cgBase;
import cgeo.geocaching.cgCache;
import cgeo.geocaching.cgLog;
import cgeo.geocaching.cgSearch;
-import cgeo.geocaching.cgSettings;
+import cgeo.geocaching.Settings;
import cgeo.geocaching.cgTrackable;
import cgeo.geocaching.cgWaypoint;
import cgeo.geocaching.cgeoapplication;
@@ -250,7 +250,7 @@ public abstract class GPXParser extends FileParser {
new Double(attrs.getValue("lon")));
}
} catch (Exception e) {
- Log.w(cgSettings.tag, "Failed to parse waypoint's latitude and/or longitude.");
+ Log.w(Settings.tag, "Failed to parse waypoint's latitude and/or longitude.");
}
}
});
@@ -328,7 +328,7 @@ public abstract class GPXParser extends FileParser {
try {
cache.hidden = parseDate(body);
} catch (Exception e) {
- Log.w(cgSettings.tag, "Failed to parse cache date: " + e.toString());
+ Log.w(Settings.tag, "Failed to parse cache date: " + e.toString());
}
}
});
@@ -449,7 +449,7 @@ public abstract class GPXParser extends FileParser {
cache.disabled = !attrs.getValue("available").equalsIgnoreCase("true");
}
} catch (Exception e) {
- Log.w(cgSettings.tag, "Failed to parse cache attributes.");
+ Log.w(Settings.tag, "Failed to parse cache attributes.");
}
}
});
@@ -532,7 +532,7 @@ public abstract class GPXParser extends FileParser {
try {
cache.difficulty = new Float(body);
} catch (Exception e) {
- Log.w(cgSettings.tag, "Failed to parse difficulty: " + e.toString());
+ Log.w(Settings.tag, "Failed to parse difficulty: " + e.toString());
}
}
});
@@ -545,7 +545,7 @@ public abstract class GPXParser extends FileParser {
try {
cache.terrain = new Float(body);
} catch (Exception e) {
- Log.w(cgSettings.tag, "Failed to parse terrain: " + e.toString());
+ Log.w(Settings.tag, "Failed to parse terrain: " + e.toString());
}
}
});
@@ -689,7 +689,7 @@ public abstract class GPXParser extends FileParser {
try {
log.date = parseDate(body).getTime();
} catch (Exception e) {
- Log.w(cgSettings.tag, "Failed to parse log date: " + e.toString());
+ Log.w(Settings.tag, "Failed to parse log date: " + e.toString());
}
}
});
@@ -731,9 +731,9 @@ public abstract class GPXParser extends FileParser {
Xml.parse(stream, Xml.Encoding.UTF_8, root.getContentHandler());
return true;
} catch (IOException e) {
- Log.e(cgSettings.tag, "Cannot parse .gpx file as GPX " + version + ": could not read file!");
+ Log.e(Settings.tag, "Cannot parse .gpx file as GPX " + version + ": could not read file!");
} catch (SAXException e) {
- Log.e(cgSettings.tag, "Cannot parse .gpx file as GPX " + version + ": could not parse XML - " + e.toString());
+ Log.e(Settings.tag, "Cannot parse .gpx file as GPX " + version + ": could not parse XML - " + e.toString());
}
return false;
}
@@ -749,14 +749,14 @@ public abstract class GPXParser extends FileParser {
fis = new FileInputStream(file);
parsed = parse(fis, handlerIn);
} catch (FileNotFoundException e) {
- Log.e(cgSettings.tag, "Cannot parse .gpx file " + file.getAbsolutePath() + " as GPX " + version + ": file not found!");
+ Log.e(Settings.tag, "Cannot parse .gpx file " + file.getAbsolutePath() + " as GPX " + version + ": file not found!");
} finally {
try {
if (fis != null) {
fis.close();
}
} catch (IOException e) {
- Log.e(cgSettings.tag, "Error after parsing .gpx file " + file.getAbsolutePath() + " as GPX " + version + ": could not close file!");
+ Log.e(Settings.tag, "Error after parsing .gpx file " + file.getAbsolutePath() + " as GPX " + version + ": could not close file!");
}
}
return parsed;
@@ -885,12 +885,12 @@ public abstract class GPXParser extends FileParser {
app.removeCacheFromCache(cache.geocode);
app.addCacheToSearch(search, cache);
}
- Log.i(cgSettings.tag, "Caches found in .gpx file: " + parser.getParsedCaches().size());
+ Log.i(Settings.tag, "Caches found in .gpx file: " + parser.getParsedCaches().size());
return search.getCurrentId();
}
} catch (Exception e) {
- Log.e(cgSettings.tag, "cgBase.parseGPX: " + e.toString());
+ Log.e(Settings.tag, "cgBase.parseGPX: " + e.toString());
}
return null;
diff --git a/main/src/cgeo/geocaching/files/LocParser.java b/main/src/cgeo/geocaching/files/LocParser.java
index 12cb1e7..b39658b 100644
--- a/main/src/cgeo/geocaching/files/LocParser.java
+++ b/main/src/cgeo/geocaching/files/LocParser.java
@@ -4,7 +4,7 @@ import cgeo.geocaching.cgCache;
import cgeo.geocaching.cgCacheWrap;
import cgeo.geocaching.cgCoord;
import cgeo.geocaching.cgSearch;
-import cgeo.geocaching.cgSettings;
+import cgeo.geocaching.Settings;
import cgeo.geocaching.cgeoapplication;
import cgeo.geocaching.enumerations.CacheSize;
import cgeo.geocaching.geopoint.GeopointParser;
@@ -133,7 +133,7 @@ public final class LocParser extends FileParser {
}
}
- Log.i(cgSettings.tag,
+ Log.i(Settings.tag,
"Coordinates found in .loc file: " + coords.size());
return coords;
}
@@ -163,9 +163,9 @@ public final class LocParser extends FileParser {
}
caches.totalCnt = caches.cacheList.size();
showCountMessage(handler, search.getCount());
- Log.i(cgSettings.tag, "Caches found in .gpx file: " + caches.totalCnt);
+ Log.i(Settings.tag, "Caches found in .gpx file: " + caches.totalCnt);
} catch (Exception e) {
- Log.e(cgSettings.tag, "cgBase.parseGPX: " + e.toString());
+ Log.e(Settings.tag, "cgBase.parseGPX: " + e.toString());
}
return search.getCurrentId();
diff --git a/main/src/cgeo/geocaching/geopoint/DistanceParser.java b/main/src/cgeo/geocaching/geopoint/DistanceParser.java
index 01264c4..f003bab 100644
--- a/main/src/cgeo/geocaching/geopoint/DistanceParser.java
+++ b/main/src/cgeo/geocaching/geopoint/DistanceParser.java
@@ -1,7 +1,6 @@
package cgeo.geocaching.geopoint;
import cgeo.geocaching.cgBase;
-import cgeo.geocaching.cgSettings;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@@ -21,7 +20,7 @@ public final class DistanceParser {
* @throws NumberFormatException
* if the given number is invalid
*/
- public static float parseDistance(String distanceText, final int defaultUnit) {
+ public static float parseDistance(String distanceText, final boolean metricUnit) {
final Matcher matcher = pattern.matcher(distanceText);
if (!matcher.find()) {
@@ -31,7 +30,7 @@ public final class DistanceParser {
final float value = Float.parseFloat(matcher.group(1).replace(',', '.'));
final String unit = matcher.group(2).toLowerCase();
- if (unit.equals("m") || (unit.length() == 0 && defaultUnit == cgSettings.unitsMetric)) {
+ if (unit.equals("m") || (unit.length() == 0 && metricUnit)) {
return value / 1000;
}
if (unit.equals("km")) {
diff --git a/main/src/cgeo/geocaching/maps/CGeoMap.java b/main/src/cgeo/geocaching/maps/CGeoMap.java
index 4772f89..e14bdec 100644
--- a/main/src/cgeo/geocaching/maps/CGeoMap.java
+++ b/main/src/cgeo/geocaching/maps/CGeoMap.java
@@ -6,8 +6,8 @@ import cgeo.geocaching.cgCache;
import cgeo.geocaching.cgCoord;
import cgeo.geocaching.cgDirection;
import cgeo.geocaching.cgGeo;
-import cgeo.geocaching.cgSettings;
-import cgeo.geocaching.cgSettings.mapSourceEnum;
+import cgeo.geocaching.Settings;
+import cgeo.geocaching.Settings.mapSourceEnum;
import cgeo.geocaching.cgUpdateDir;
import cgeo.geocaching.cgUpdateLoc;
import cgeo.geocaching.cgUser;
@@ -28,10 +28,8 @@ import org.apache.commons.lang3.StringUtils;
import android.app.Activity;
import android.app.ProgressDialog;
-import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
-import android.content.SharedPreferences;
import android.content.res.Resources;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
@@ -79,10 +77,8 @@ public class CGeoMap extends AbstractMap implements OnDragListener, ViewFactory
private Activity activity = null;
private MapViewImpl mapView = null;
private MapControllerImpl mapController = null;
- private cgSettings settings = null;
private cgBase base = null;
private cgeoapplication app = null;
- private SharedPreferences.Editor prefsEdit = null;
private cgGeo geo = null;
private cgDirection dir = null;
private cgUpdateLoc geoUpdate = new UpdateLoc();
@@ -224,9 +220,9 @@ public class CGeoMap extends AbstractMap implements OnDragListener, ViewFactory
}
if (geo == null) {
- geo = app.startGeo(activity, geoUpdate, base, settings, 0, 0);
+ geo = app.startGeo(activity, geoUpdate, base, 0, 0);
}
- if (settings.useCompass == 1 && dir == null) {
+ if (Settings.isUseCompass() && dir == null) {
dir = app.startDir(activity, dirUpdate);
}
}
@@ -257,10 +253,8 @@ public class CGeoMap extends AbstractMap implements OnDragListener, ViewFactory
activity = this.getActivity();
app = (cgeoapplication) activity.getApplication();
app.setAction(null);
- settings = new cgSettings(activity, activity.getSharedPreferences(cgSettings.preferences, Context.MODE_PRIVATE));
- base = new cgBase(app, settings);
- prefsEdit = activity.getSharedPreferences(cgSettings.preferences, Context.MODE_PRIVATE).edit();
- MapFactory mapFactory = settings.getMapFactory();
+ base = new cgBase(app);
+ MapFactory mapFactory = Settings.getMapFactory();
// reset status
noMapTokenShowed = false;
@@ -270,19 +264,19 @@ public class CGeoMap extends AbstractMap implements OnDragListener, ViewFactory
// set layout
ActivityMixin.setTheme(activity);
- activity.setContentView(settings.getMapFactory().getMapLayoutId());
+ activity.setContentView(Settings.getMapFactory().getMapLayoutId());
ActivityMixin.setTitle(activity, res.getString(R.string.map_map));
if (geo == null) {
- geo = app.startGeo(activity, geoUpdate, base, settings, 0, 0);
+ geo = app.startGeo(activity, geoUpdate, base, 0, 0);
}
- if (settings.useCompass == 1 && dir == null) {
+ if (Settings.isUseCompass() && dir == null) {
dir = app.startDir(activity, dirUpdate);
}
// initialize map
mapView = (MapViewImpl) activity.findViewById(mapFactory.getMapViewId());
- mapView.setMapSource(settings);
+ mapView.setMapSource();
if (!mapView.needsScaleOverlay()) {
mapView.setBuiltinScale(true);
}
@@ -295,25 +289,25 @@ public class CGeoMap extends AbstractMap implements OnDragListener, ViewFactory
mapView.clearOverlays();
if (overlayPosition == null) {
- overlayPosition = mapView.createAddPositionOverlay(activity, settings);
+ overlayPosition = mapView.createAddPositionOverlay(activity);
}
- if (settings.publicLoc > 0 && overlayOtherCachers == null) {
+ if (Settings.isPublicLoc() && overlayOtherCachers == null) {
overlayOtherCachers = mapView.createAddUsersOverlay(activity, getResources().getDrawable(R.drawable.user_location));
}
if (overlayCaches == null) {
- overlayCaches = mapView.createAddMapOverlay(settings, mapView.getContext(), getResources().getDrawable(R.drawable.marker), fromDetailIntent);
+ overlayCaches = mapView.createAddMapOverlay(mapView.getContext(), getResources().getDrawable(R.drawable.marker), fromDetailIntent);
}
if (overlayScale == null && mapView.needsScaleOverlay()) {
- overlayScale = mapView.createAddScaleOverlay(activity, settings);
+ overlayScale = mapView.createAddScaleOverlay(activity);
}
mapView.invalidate();
mapController = mapView.getMapController();
- mapController.setZoom(settings.mapzoom);
+ mapController.setZoom(Settings.getMapZoom());
// start location and directory services
if (geo != null) {
@@ -375,8 +369,8 @@ public class CGeoMap extends AbstractMap implements OnDragListener, ViewFactory
startTimer();
// show the filter warning bar if the filter is set
- if (settings.cacheType != null) {
- String cacheType = cgBase.cacheTypesInv.get(settings.cacheType);
+ if (Settings.getCacheType() != null) {
+ String cacheType = cgBase.cacheTypesInv.get(Settings.getCacheType());
((TextView) activity.findViewById(R.id.filter_text)).setText(cacheType);
activity.findViewById(R.id.filter_bar).setVisibility(View.VISIBLE);
}
@@ -386,13 +380,11 @@ public class CGeoMap extends AbstractMap implements OnDragListener, ViewFactory
public void onResume() {
super.onResume();
- settings.load();
-
app.setAction(null);
if (geo == null) {
- geo = app.startGeo(activity, geoUpdate, base, settings, 0, 0);
+ geo = app.startGeo(activity, geoUpdate, base, 0, 0);
}
- if (settings.useCompass == 1 && dir == null) {
+ if (Settings.isUseCompass() && dir == null) {
dir = app.startDir(activity, dirUpdate);
}
@@ -506,7 +498,7 @@ public class CGeoMap extends AbstractMap implements OnDragListener, ViewFactory
private void addMapViewMenuItems(final Menu menu) {
String[] mapViews = res.getStringArray(R.array.map_sources);
- mapSourceEnum mapSource = settings.mapSource;
+ mapSourceEnum mapSource = Settings.getMapSource();
menu.add(1, SUBMENU_VIEW_GOOGLE_MAP, 0, mapViews[0]).setCheckable(true).setChecked(mapSource == mapSourceEnum.googleMap);
menu.add(1, SUBMENU_VIEW_GOOGLE_SAT, 0, mapViews[1]).setCheckable(true).setChecked(mapSource == mapSourceEnum.googleSat);
@@ -524,7 +516,7 @@ public class CGeoMap extends AbstractMap implements OnDragListener, ViewFactory
MenuItem item;
try {
item = menu.findItem(MENU_TRAIL_MODE); // show trail
- if (settings.maptrail == 1) {
+ if (Settings.isMapTrail()) {
item.setTitle(res.getString(R.string.map_trail_hide));
} else {
item.setTitle(res.getString(R.string.map_trail_show));
@@ -535,7 +527,7 @@ public class CGeoMap extends AbstractMap implements OnDragListener, ViewFactory
item.setEnabled(false);
item.setTitle(res.getString(R.string.map_live_enable));
} else {
- if (settings.maplive == 1) {
+ if (Settings.isLiveMap()) {
item.setTitle(res.getString(R.string.map_live_disable));
} else {
item.setTitle(res.getString(R.string.map_live_enable));
@@ -557,13 +549,13 @@ public class CGeoMap extends AbstractMap implements OnDragListener, ViewFactory
}
item = menu.findItem(SUBMENU_VIEW_MF_OFFLINE);
- if (settings.hasValidMapFile()) {
+ if (Settings.isValidMapFile()) {
item.setEnabled(true);
} else {
item.setEnabled(false);
}
} catch (Exception e) {
- Log.e(cgSettings.tag, "cgeomap.onPrepareOptionsMenu: " + e.toString());
+ Log.e(Settings.tag, "cgeomap.onPrepareOptionsMenu: " + e.toString());
}
return true;
@@ -574,23 +566,9 @@ public class CGeoMap extends AbstractMap implements OnDragListener, ViewFactory
final int id = item.getItemId();
if (id == MENU_TRAIL_MODE) {
- if (settings.maptrail == 1) {
- prefsEdit.putInt("maptrail", 0);
- prefsEdit.commit();
-
- settings.maptrail = 0;
- } else {
- prefsEdit.putInt("maptrail", 1);
- prefsEdit.commit();
-
- settings.maptrail = 1;
- }
+ Settings.setMapTrail(!Settings.isMapTrail());
} else if (id == MENU_MAP_LIVE) {
- if (settings.maplive == 1) {
- settings.liveMapDisable();
- } else {
- settings.liveMapEnable();
- }
+ Settings.setLiveMap(!Settings.isLiveMap());
liveChanged = true;
searchId = null;
searchIdIntent = null;
@@ -616,7 +594,7 @@ public class CGeoMap extends AbstractMap implements OnDragListener, ViewFactory
}
}
} catch (Exception e) {
- Log.e(cgSettings.tag, "cgeomap.onOptionsItemSelected.#4: " + e.toString());
+ Log.e(Settings.tag, "cgeomap.onOptionsItemSelected.#4: " + e.toString());
}
detailTotal = geocodes.size();
@@ -640,13 +618,13 @@ public class CGeoMap extends AbstractMap implements OnDragListener, ViewFactory
}
if (geo == null) {
- geo = app.startGeo(activity, geoUpdate, base, settings, 0, 0);
+ geo = app.startGeo(activity, geoUpdate, base, 0, 0);
}
- if (settings.useCompass == 1 && dir == null) {
+ if (Settings.isUseCompass() && dir == null) {
dir = app.startDir(activity, dirUpdate);
}
} catch (Exception e) {
- Log.e(cgSettings.tag, "cgeocaches.onPrepareOptionsMenu.onCancel: " + e.toString());
+ Log.e(Settings.tag, "cgeocaches.onPrepareOptionsMenu.onCancel: " + e.toString());
}
}
});
@@ -688,7 +666,7 @@ public class CGeoMap extends AbstractMap implements OnDragListener, ViewFactory
activity.finish();
// prepare information to restart a similar view
- Intent mapIntent = new Intent(activity, settings.getMapFactory().getMapClass());
+ Intent mapIntent = new Intent(activity, Settings.getMapFactory().getMapClass());
mapIntent.putExtra("detail", fromDetailIntent);
mapIntent.putExtra("searchid", searchIdIntent);
@@ -738,16 +716,14 @@ public class CGeoMap extends AbstractMap implements OnDragListener, ViewFactory
}
private boolean switchMapSource(mapSourceEnum mapSource) {
+ boolean oldIsGoogle = Settings.getMapSource().isGoogleMapSource();
- settings.mapSource = mapSource;
-
- prefsEdit.putInt("mapsource", settings.mapSource.ordinal());
- prefsEdit.commit();
+ Settings.setMapSource(mapSource);
- boolean mapRestartRequired = settings.mapSource.isGoogleMapSource() != settings.mapSourceUsed.isGoogleMapSource();
+ boolean mapRestartRequired = mapSource.isGoogleMapSource() != oldIsGoogle;
if (!mapRestartRequired) {
- mapView.setMapSource(settings);
+ mapView.setMapSource();
}
return mapRestartRequired;
@@ -758,12 +734,7 @@ public class CGeoMap extends AbstractMap implements OnDragListener, ViewFactory
return;
}
- if (prefsEdit == null) {
- prefsEdit = activity.getSharedPreferences(cgSettings.preferences, Context.MODE_PRIVATE).edit();
- }
-
- prefsEdit.putInt("mapzoom", mapView.getMapZoomLevel());
- prefsEdit.commit();
+ Settings.setMapZoom(mapView.getMapZoomLevel());
}
// set center of map to my location
@@ -791,7 +762,7 @@ public class CGeoMap extends AbstractMap implements OnDragListener, ViewFactory
boolean repaintRequired = false;
if (overlayPosition == null && mapView != null) {
- overlayPosition = mapView.createAddPositionOverlay(activity, settings);
+ overlayPosition = mapView.createAddPositionOverlay(activity);
}
if (overlayPosition != null && geo.location != null) {
@@ -806,7 +777,7 @@ public class CGeoMap extends AbstractMap implements OnDragListener, ViewFactory
}
}
- if (settings.useCompass == 0 || (geo.speedNow != null && geo.speedNow > 5)) { // use GPS when speed is higher than 18 km/h
+ if (!Settings.isUseCompass() || (geo.speedNow != null && geo.speedNow > 5)) { // use GPS when speed is higher than 18 km/h
if (geo.bearingNow != null) {
overlayPosition.setHeading(geo.bearingNow);
} else {
@@ -820,7 +791,7 @@ public class CGeoMap extends AbstractMap implements OnDragListener, ViewFactory
}
} catch (Exception e) {
- Log.w(cgSettings.tag, "Failed to update location.");
+ Log.w(Settings.tag, "Failed to update location.");
}
}
}
@@ -859,7 +830,7 @@ public class CGeoMap extends AbstractMap implements OnDragListener, ViewFactory
loadTimer.start();
}
- if (settings.publicLoc > 0) {
+ if (Settings.isPublicLoc()) {
if (usersTimer != null) {
usersTimer.stopIt();
usersTimer = null;
@@ -930,7 +901,7 @@ public class CGeoMap extends AbstractMap implements OnDragListener, ViewFactory
if (liveChanged) {
moved = true;
force = true;
- } else if (live && settings.maplive == 1 && downloaded == false) {
+ } else if (live && Settings.isLiveMap() && downloaded == false) {
moved = true;
} else if (centerLatitude == null || centerLongitude == null) {
moved = true;
@@ -993,7 +964,7 @@ public class CGeoMap extends AbstractMap implements OnDragListener, ViewFactory
yield();
} catch (Exception e) {
- Log.w(cgSettings.tag, "cgeomap.LoadTimer.run: " + e.toString());
+ Log.w(Settings.tag, "cgeomap.LoadTimer.run: " + e.toString());
}
}
}
@@ -1082,7 +1053,7 @@ public class CGeoMap extends AbstractMap implements OnDragListener, ViewFactory
yield();
} catch (Exception e) {
- Log.w(cgSettings.tag, "cgeomap.LoadUsersTimer.run: " + e.toString());
+ Log.w(Settings.tag, "cgeomap.LoadUsersTimer.run: " + e.toString());
}
}
}
@@ -1123,10 +1094,10 @@ public class CGeoMap extends AbstractMap implements OnDragListener, ViewFactory
if (fromDetailIntent || StringUtils.isNotEmpty(searchIdIntent)) {
searchId = UUID.fromString(searchIdIntent);
} else {
- if (!live || settings.maplive == 0) {
- searchId = app.getStoredInViewport(centerLat, centerLon, spanLat, spanLon, settings.cacheType);
+ if (!live || !Settings.isLiveMap()) {
+ searchId = app.getStoredInViewport(centerLat, centerLon, spanLat, spanLon, Settings.getCacheType());
} else {
- searchId = app.getCachedInViewport(centerLat, centerLon, spanLat, spanLon, settings.cacheType);
+ searchId = app.getCachedInViewport(centerLat, centerLon, spanLat, spanLon, Settings.getCacheType());
}
}
@@ -1144,9 +1115,9 @@ public class CGeoMap extends AbstractMap implements OnDragListener, ViewFactory
caches = app.getCaches(searchId);
//if in live map and stored caches are found / disables are also shown.
- if (live && settings.maplive >= 1) {
- final boolean excludeMine = cgSettings.getExcludeMine();
- final boolean excludeDisabled = settings.excludeDisabled > 0;
+ if (live && Settings.isLiveMap()) {
+ final boolean excludeMine = Settings.isExcludeMyCaches();
+ final boolean excludeDisabled = Settings.isExcludeDisabledCaches();
for (int i = caches.size() - 1; i >= 0; i--) {
cgCache cache = caches.get(i);
@@ -1183,7 +1154,7 @@ public class CGeoMap extends AbstractMap implements OnDragListener, ViewFactory
// stage 2 - pull and render from geocaching.com
//this should just fetch and insert into the db _and_ be cancel-able if the viewport changes
- if (live && settings.maplive >= 1) {
+ if (live && Settings.isLiveMap()) {
if (downloadThread != null && downloadThread.isWorking()) {
downloadThread.stopIt();
}
@@ -1327,7 +1298,7 @@ public class CGeoMap extends AbstractMap implements OnDragListener, ViewFactory
if (cacheOne.waypoints != null
// Only show waypoints for single view or setting
// when less than showWaypointsthreshold Caches shown
- && (cachesProtected.size() == 1 || (cachesProtected.size() < settings.showWaypointsthreshold))
+ && (cachesProtected.size() == 1 || (cachesProtected.size() < Settings.getWayPointsThreshold()))
&& !cacheOne.waypoints.isEmpty()) {
for (cgWaypoint oneWaypoint : cacheOne.waypoints) {
if (oneWaypoint.coords == null) {
@@ -1386,7 +1357,7 @@ public class CGeoMap extends AbstractMap implements OnDragListener, ViewFactory
private CachesOverlayItemImpl getItem(cgCoord cgCoord, boolean cache, String type, boolean own, boolean found, boolean disabled) {
coordinates.add(cgCoord);
- CachesOverlayItemImpl item = settings.getMapFactory().getCachesOverlayItem(cgCoord, null);
+ CachesOverlayItemImpl item = Settings.getMapFactory().getCachesOverlayItem(cgCoord, null);
int icon = cgBase.getMarkerIcon(cache, type, own, found, disabled);
Drawable pin = null;
@@ -1443,7 +1414,7 @@ public class CGeoMap extends AbstractMap implements OnDragListener, ViewFactory
lonMin = llCache;
}
- users = base.getGeocachersInViewport(settings.getUsername(), latMin, latMax, lonMin, lonMax);
+ users = base.getGeocachersInViewport(Settings.getUsername(), latMin, latMax, lonMin, lonMax);
if (stop) {
return;
@@ -1498,7 +1469,7 @@ public class CGeoMap extends AbstractMap implements OnDragListener, ViewFactory
continue;
}
- item = settings.getMapFactory().getOtherCachersOverlayItemBase(activity, userOne);
+ item = Settings.getMapFactory().getOtherCachersOverlayItemBase(activity, userOne);
items.add(item);
counter++;
@@ -1533,7 +1504,7 @@ public class CGeoMap extends AbstractMap implements OnDragListener, ViewFactory
coord.name = "some place";
coordinates.add(coord);
- CachesOverlayItemImpl item = settings.getMapFactory().getCachesOverlayItem(coord, null);
+ CachesOverlayItemImpl item = Settings.getMapFactory().getCachesOverlayItem(coord, null);
final int icon = cgBase.getMarkerIcon(false, waypointTypeIntent, false, false, false);
Drawable pin = null;
@@ -1660,7 +1631,7 @@ public class CGeoMap extends AbstractMap implements OnDragListener, ViewFactory
}
if (stop) {
- Log.i(cgSettings.tag, "Stopped storing process.");
+ Log.i(Settings.tag, "Stopped storing process.");
break;
}
@@ -1668,7 +1639,7 @@ public class CGeoMap extends AbstractMap implements OnDragListener, ViewFactory
base.storeCache(app, activity, null, geocode, 1, handler);
}
} catch (Exception e) {
- Log.e(cgSettings.tag, "cgeocaches.LoadDetails.run: " + e.toString());
+ Log.e(Settings.tag, "cgeocaches.LoadDetails.run: " + e.toString());
} finally {
// one more cache over
detailProgress++;
@@ -1708,7 +1679,7 @@ public class CGeoMap extends AbstractMap implements OnDragListener, ViewFactory
if (!centered && mapState != null) {
try {
- mapController.setCenter(settings.getMapFactory().getGeoPointBase(new Geopoint(mapState[0] / 1.0e6, mapState[1] / 1.0e6)));
+ mapController.setCenter(Settings.getMapFactory().getGeoPointBase(new Geopoint(mapState[0] / 1.0e6, mapState[1] / 1.0e6)));
mapController.setZoom(mapState[2]);
} catch (Exception e) {
// nothing at all
@@ -1767,7 +1738,7 @@ public class CGeoMap extends AbstractMap implements OnDragListener, ViewFactory
}
if (cnt > 0) {
- mapController.setCenter(settings.getMapFactory().getGeoPointBase(new Geopoint(centerLat, centerLon)));
+ mapController.setCenter(Settings.getMapFactory().getGeoPointBase(new Geopoint(centerLat, centerLon)));
if (Math.abs(maxLat - minLat) != 0 && Math.abs(maxLon - minLon) != 0) {
mapController.zoomToSpan(Math.abs(maxLat - minLat), Math.abs(maxLon - minLon));
}
@@ -1817,8 +1788,8 @@ public class CGeoMap extends AbstractMap implements OnDragListener, ViewFactory
}
// make geopoint
- private GeoPointImpl makeGeoPoint(final Geopoint coords) {
- return settings.getMapFactory().getGeoPointBase(coords);
+ private static GeoPointImpl makeGeoPoint(final Geopoint coords) {
+ return Settings.getMapFactory().getGeoPointBase(coords);
}
// close activity and open homescreen
diff --git a/main/src/cgeo/geocaching/maps/CachesOverlay.java b/main/src/cgeo/geocaching/maps/CachesOverlay.java
index cae4448..eaac8b8 100644
--- a/main/src/cgeo/geocaching/maps/CachesOverlay.java
+++ b/main/src/cgeo/geocaching/maps/CachesOverlay.java
@@ -2,19 +2,19 @@ package cgeo.geocaching.maps;
import cgeo.geocaching.cgBase;
import cgeo.geocaching.cgCoord;
-import cgeo.geocaching.cgSettings;
+import cgeo.geocaching.Settings;
import cgeo.geocaching.cgeodetail;
import cgeo.geocaching.cgeonavigate;
import cgeo.geocaching.cgeopopup;
import cgeo.geocaching.cgeowaypoint;
import cgeo.geocaching.geopoint.Geopoint;
import cgeo.geocaching.maps.interfaces.CachesOverlayItemImpl;
+import cgeo.geocaching.maps.interfaces.GeneralOverlay;
import cgeo.geocaching.maps.interfaces.GeoPointImpl;
import cgeo.geocaching.maps.interfaces.ItemizedOverlayImpl;
import cgeo.geocaching.maps.interfaces.MapFactory;
import cgeo.geocaching.maps.interfaces.MapProjectionImpl;
import cgeo.geocaching.maps.interfaces.MapViewImpl;
-import cgeo.geocaching.maps.interfaces.GeneralOverlay;
import org.apache.commons.lang3.StringUtils;
@@ -48,19 +48,17 @@ public class CachesOverlay extends AbstractItemizedOverlay implements GeneralOve
private Paint blockedCircle = null;
private PaintFlagsDrawFilter setfil = null;
private PaintFlagsDrawFilter remfil = null;
- private cgSettings settings;
private MapFactory mapFactory = null;
- public CachesOverlay(cgSettings settingsIn, ItemizedOverlayImpl ovlImpl, Context contextIn, Boolean fromDetailIn) {
+ public CachesOverlay(ItemizedOverlayImpl ovlImpl, Context contextIn, Boolean fromDetailIn) {
super(ovlImpl);
populate();
- settings = settingsIn;
context = contextIn;
fromDetail = fromDetailIn;
- mapFactory = settings.getMapFactory();
+ mapFactory = Settings.getMapFactory();
}
public void updateItems(CachesOverlayItemImpl item) {
@@ -231,7 +229,7 @@ public class CachesOverlay extends AbstractItemizedOverlay implements GeneralOve
waitDialog.dismiss();
} catch (Exception e) {
- Log.e(cgSettings.tag, "cgMapOverlay.onTap: " + e.toString());
+ Log.e(Settings.tag, "cgMapOverlay.onTap: " + e.toString());
}
return false;
@@ -242,7 +240,7 @@ public class CachesOverlay extends AbstractItemizedOverlay implements GeneralOve
try {
return items.get(index);
} catch (Exception e) {
- Log.e(cgSettings.tag, "cgMapOverlay.createItem: " + e.toString());
+ Log.e(Settings.tag, "cgMapOverlay.createItem: " + e.toString());
}
return null;
@@ -253,7 +251,7 @@ public class CachesOverlay extends AbstractItemizedOverlay implements GeneralOve
try {
return items.size();
} catch (Exception e) {
- Log.e(cgSettings.tag, "cgMapOverlay.size: " + e.toString());
+ Log.e(Settings.tag, "cgMapOverlay.size: " + e.toString());
}
return 0;
@@ -265,7 +263,7 @@ public class CachesOverlay extends AbstractItemizedOverlay implements GeneralOve
final cgCoord coordinate = item.getCoord();
if (coordinate == null) {
- Log.e(cgSettings.tag, "cgMapOverlay:infoDialog: No coordinates given");
+ Log.e(Settings.tag, "cgMapOverlay:infoDialog: No coordinates given");
return;
}
@@ -353,7 +351,7 @@ public class CachesOverlay extends AbstractItemizedOverlay implements GeneralOve
AlertDialog alert = dialog.create();
alert.show();
} catch (Exception e) {
- Log.e(cgSettings.tag, "cgMapOverlay.infoDialog: " + e.toString());
+ Log.e(Settings.tag, "cgMapOverlay.infoDialog: " + e.toString());
}
}
}
diff --git a/main/src/cgeo/geocaching/maps/OtherCachersOverlay.java b/main/src/cgeo/geocaching/maps/OtherCachersOverlay.java
index 4eff80b..31a4192 100644
--- a/main/src/cgeo/geocaching/maps/OtherCachersOverlay.java
+++ b/main/src/cgeo/geocaching/maps/OtherCachersOverlay.java
@@ -1,7 +1,7 @@
package cgeo.geocaching.maps;
import cgeo.geocaching.R;
-import cgeo.geocaching.cgSettings;
+import cgeo.geocaching.Settings;
import cgeo.geocaching.cgUser;
import cgeo.geocaching.cgeodetail;
import cgeo.geocaching.maps.interfaces.ItemizedOverlayImpl;
@@ -128,7 +128,7 @@ public class OtherCachersOverlay extends AbstractItemizedOverlay implements Gene
return true;
} catch (Exception e) {
- Log.e(cgSettings.tag, "cgUsersOverlay.onTap: " + e.toString());
+ Log.e(Settings.tag, "cgUsersOverlay.onTap: " + e.toString());
}
return false;
@@ -150,7 +150,7 @@ public class OtherCachersOverlay extends AbstractItemizedOverlay implements Gene
try {
return items.get(index);
} catch (Exception e) {
- Log.e(cgSettings.tag, "cgUsersOverlay.createItem: " + e.toString());
+ Log.e(Settings.tag, "cgUsersOverlay.createItem: " + e.toString());
}
return null;
@@ -161,7 +161,7 @@ public class OtherCachersOverlay extends AbstractItemizedOverlay implements Gene
try {
return items.size();
} catch (Exception e) {
- Log.e(cgSettings.tag, "cgUsersOverlay.size: " + e.toString());
+ Log.e(Settings.tag, "cgUsersOverlay.size: " + e.toString());
}
return 0;
diff --git a/main/src/cgeo/geocaching/maps/PositionOverlay.java b/main/src/cgeo/geocaching/maps/PositionOverlay.java
index 8099400..bf08f3c 100644
--- a/main/src/cgeo/geocaching/maps/PositionOverlay.java
+++ b/main/src/cgeo/geocaching/maps/PositionOverlay.java
@@ -1,13 +1,13 @@
package cgeo.geocaching.maps;
import cgeo.geocaching.R;
-import cgeo.geocaching.cgSettings;
+import cgeo.geocaching.Settings;
import cgeo.geocaching.geopoint.Geopoint;
+import cgeo.geocaching.maps.interfaces.GeneralOverlay;
import cgeo.geocaching.maps.interfaces.GeoPointImpl;
import cgeo.geocaching.maps.interfaces.MapFactory;
import cgeo.geocaching.maps.interfaces.MapProjectionImpl;
import cgeo.geocaching.maps.interfaces.MapViewImpl;
-import cgeo.geocaching.maps.interfaces.GeneralOverlay;
import cgeo.geocaching.maps.interfaces.OverlayImpl;
import android.app.Activity;
@@ -25,7 +25,6 @@ import java.util.ArrayList;
import java.util.List;
public class PositionOverlay implements GeneralOverlay {
- private cgSettings settings = null;
private Location coordinates = null;
private GeoPointImpl location = null;
private Float heading = 0f;
@@ -47,16 +46,15 @@ public class PositionOverlay implements GeneralOverlay {
private MapFactory mapFactory = null;
private OverlayImpl ovlImpl = null;
- public PositionOverlay(cgSettings settingsIn, Activity activity, OverlayImpl ovlImpl) {
- settings = settingsIn;
+ public PositionOverlay(Activity activity, OverlayImpl ovlImpl) {
this.activity = activity;
- this.mapFactory = settings.getMapFactory();
+ this.mapFactory = Settings.getMapFactory();
this.ovlImpl = ovlImpl;
}
public void setCoordinates(Location coordinatesIn) {
coordinates = coordinatesIn;
- location = settings.getMapFactory().getGeoPointBase(new Geopoint(coordinates));
+ location = Settings.getMapFactory().getGeoPointBase(new Geopoint(coordinates));
}
public void setHeading(Float bearingNow) {
@@ -145,7 +143,7 @@ public class PositionOverlay implements GeneralOverlay {
}
}
- if (settings.maptrail == 1) {
+ if (Settings.isMapTrail()) {
int size = history.size();
if (size > 1) {
int alpha = 0;
diff --git a/main/src/cgeo/geocaching/maps/ScaleOverlay.java b/main/src/cgeo/geocaching/maps/ScaleOverlay.java
index d958597..249ef7a 100644
--- a/main/src/cgeo/geocaching/maps/ScaleOverlay.java
+++ b/main/src/cgeo/geocaching/maps/ScaleOverlay.java
@@ -1,13 +1,13 @@
package cgeo.geocaching.maps;
import cgeo.geocaching.cgBase;
-import cgeo.geocaching.cgSettings;
-import cgeo.geocaching.cgSettings.mapSourceEnum;
+import cgeo.geocaching.Settings;
+import cgeo.geocaching.Settings.mapSourceEnum;
import cgeo.geocaching.geopoint.Geopoint;
+import cgeo.geocaching.maps.interfaces.GeneralOverlay;
import cgeo.geocaching.maps.interfaces.GeoPointImpl;
import cgeo.geocaching.maps.interfaces.MapProjectionImpl;
import cgeo.geocaching.maps.interfaces.MapViewImpl;
-import cgeo.geocaching.maps.interfaces.GeneralOverlay;
import cgeo.geocaching.maps.interfaces.OverlayImpl;
import android.app.Activity;
@@ -19,7 +19,6 @@ import android.graphics.Typeface;
import android.util.DisplayMetrics;
public class ScaleOverlay implements GeneralOverlay {
- private cgSettings settings = null;
private Paint scale = null;
private Paint scaleShadow = null;
private BlurMaskFilter blur = null;
@@ -31,8 +30,7 @@ public class ScaleOverlay implements GeneralOverlay {
private String units = null;
private OverlayImpl ovlImpl = null;
- public ScaleOverlay(Activity activity, cgSettings settingsIn, OverlayImpl overlayImpl) {
- settings = settingsIn;
+ public ScaleOverlay(Activity activity, OverlayImpl overlayImpl) {
this.ovlImpl = overlayImpl;
DisplayMetrics metrics = new DisplayMetrics();
@@ -63,7 +61,26 @@ public class ScaleOverlay implements GeneralOverlay {
distance = leftCoords.distanceTo(rightCoords) / 2;
distanceRound = 0d;
- if (settings.units == cgSettings.unitsImperial) {
+ if (Settings.isUseMetricUnits()) {
+ if (distance > 100) { // 100+ km > 1xx km
+ distanceRound = Math.floor(distance / 100) * 100;
+ units = "km";
+ } else if (distance > 10) { // 10 - 100 km > 1x km
+ distanceRound = Math.floor(distance / 10) * 10;
+ units = "km";
+ } else if (distance > 1) { // 1 - 10 km > 1.x km
+ distanceRound = Math.floor(distance);
+ units = "km";
+ } else if (distance > 0.1) { // 100 m - 1 km > 1xx m
+ distance *= 1000;
+ distanceRound = Math.floor(distance / 100) * 100;
+ units = "m";
+ } else { // 1 - 100 m > 1x m
+ distance *= 1000;
+ distanceRound = Math.round(distance / 10) * 10;
+ units = "m";
+ }
+ } else {
distance /= cgBase.miles2km;
if (distance > 100) { // 100+ mi > 1xx mi
@@ -84,25 +101,6 @@ public class ScaleOverlay implements GeneralOverlay {
distanceRound = Math.round(distance / 10) * 10;
units = "ft";
}
- } else {
- if (distance > 100) { // 100+ km > 1xx km
- distanceRound = Math.floor(distance / 100) * 100;
- units = "km";
- } else if (distance > 10) { // 10 - 100 km > 1x km
- distanceRound = Math.floor(distance / 10) * 10;
- units = "km";
- } else if (distance > 1) { // 1 - 10 km > 1.x km
- distanceRound = Math.floor(distance);
- units = "km";
- } else if (distance > 0.1) { // 100 m - 1 km > 1xx m
- distance *= 1000;
- distanceRound = Math.floor(distance / 100) * 100;
- units = "m";
- } else { // 1 - 100 m > 1x m
- distance *= 1000;
- distanceRound = Math.round(distance / 10) * 10;
- units = "m";
- }
}
pixels = Math.round((pixels / distance) * distanceRound);
@@ -128,7 +126,7 @@ public class ScaleOverlay implements GeneralOverlay {
scale.setTypeface(Typeface.DEFAULT_BOLD);
}
- if (mapSourceEnum.googleSat == settings.mapSource) {
+ if (mapSourceEnum.googleSat == Settings.getMapSource()) {
scaleShadow.setColor(0xFF000000);
scale.setColor(0xFFFFFFFF);
} else {
diff --git a/main/src/cgeo/geocaching/maps/google/GoogleCacheOverlay.java b/main/src/cgeo/geocaching/maps/google/GoogleCacheOverlay.java
index f501b8c..f64e2ed 100644
--- a/main/src/cgeo/geocaching/maps/google/GoogleCacheOverlay.java
+++ b/main/src/cgeo/geocaching/maps/google/GoogleCacheOverlay.java
@@ -1,6 +1,5 @@
package cgeo.geocaching.maps.google;
-import cgeo.geocaching.cgSettings;
import cgeo.geocaching.maps.CachesOverlay;
import cgeo.geocaching.maps.interfaces.ItemizedOverlayImpl;
import cgeo.geocaching.maps.interfaces.MapProjectionImpl;
@@ -28,9 +27,9 @@ public class GoogleCacheOverlay extends ItemizedOverlay<GoogleCacheOverlayItem>
private CachesOverlay base;
private Lock lock = new ReentrantLock();
- public GoogleCacheOverlay(cgSettings settingsIn, Context contextIn, Drawable markerIn, Boolean fromDetailIn) {
+ public GoogleCacheOverlay(Context contextIn, Drawable markerIn, Boolean fromDetailIn) {
super(boundCenterBottom(markerIn));
- base = new CachesOverlay(settingsIn, this, contextIn, fromDetailIn);
+ base = new CachesOverlay(this, contextIn, fromDetailIn);
}
@Override
diff --git a/main/src/cgeo/geocaching/maps/google/GoogleMapView.java b/main/src/cgeo/geocaching/maps/google/GoogleMapView.java
index 0f7496b..11d145e 100644
--- a/main/src/cgeo/geocaching/maps/google/GoogleMapView.java
+++ b/main/src/cgeo/geocaching/maps/google/GoogleMapView.java
@@ -1,16 +1,16 @@
package cgeo.geocaching.maps.google;
-import cgeo.geocaching.cgSettings;
-import cgeo.geocaching.maps.PositionOverlay;
+import cgeo.geocaching.Settings;
import cgeo.geocaching.maps.CachesOverlay;
-import cgeo.geocaching.maps.ScaleOverlay;
import cgeo.geocaching.maps.OtherCachersOverlay;
+import cgeo.geocaching.maps.PositionOverlay;
+import cgeo.geocaching.maps.ScaleOverlay;
+import cgeo.geocaching.maps.interfaces.GeneralOverlay;
import cgeo.geocaching.maps.interfaces.GeoPointImpl;
import cgeo.geocaching.maps.interfaces.MapControllerImpl;
import cgeo.geocaching.maps.interfaces.MapProjectionImpl;
import cgeo.geocaching.maps.interfaces.MapViewImpl;
import cgeo.geocaching.maps.interfaces.OnDragListener;
-import cgeo.geocaching.maps.interfaces.GeneralOverlay;
import cgeo.geocaching.maps.interfaces.OverlayImpl;
import cgeo.geocaching.maps.interfaces.OverlayImpl.overlayType;
@@ -56,7 +56,7 @@ public class GoogleMapView extends MapView implements MapViewImpl {
super.draw(canvas);
} catch (Exception e) {
- Log.e(cgSettings.tag, "cgMapView.draw: " + e.toString());
+ Log.e(Settings.tag, "cgMapView.draw: " + e.toString());
}
}
@@ -65,7 +65,7 @@ public class GoogleMapView extends MapView implements MapViewImpl {
try {
super.displayZoomControls(takeFocus);
} catch (Exception e) {
- Log.e(cgSettings.tag, "cgMapView.displayZoomControls: " + e.toString());
+ Log.e(Settings.tag, "cgMapView.displayZoomControls: " + e.toString());
}
}
@@ -96,10 +96,9 @@ public class GoogleMapView extends MapView implements MapViewImpl {
}
@Override
- public CachesOverlay createAddMapOverlay(cgSettings settings,
- Context context, Drawable drawable, boolean fromDetailIntent) {
+ public CachesOverlay createAddMapOverlay(Context context, Drawable drawable, boolean fromDetailIntent) {
- GoogleCacheOverlay ovl = new GoogleCacheOverlay(settings, context, drawable, fromDetailIntent);
+ GoogleCacheOverlay ovl = new GoogleCacheOverlay(context, drawable, fromDetailIntent);
getOverlays().add(ovl);
return ovl.getBase();
}
@@ -112,19 +111,17 @@ public class GoogleMapView extends MapView implements MapViewImpl {
}
@Override
- public PositionOverlay createAddPositionOverlay(Activity activity,
- cgSettings settingsIn) {
+ public PositionOverlay createAddPositionOverlay(Activity activity) {
- GoogleOverlay ovl = new GoogleOverlay(activity, settingsIn, overlayType.PositionOverlay);
+ GoogleOverlay ovl = new GoogleOverlay(activity, overlayType.PositionOverlay);
getOverlays().add(ovl);
return (PositionOverlay) ovl.getBase();
}
@Override
- public ScaleOverlay createAddScaleOverlay(Activity activity,
- cgSettings settingsIn) {
+ public ScaleOverlay createAddScaleOverlay(Activity activity) {
- GoogleOverlay ovl = new GoogleOverlay(activity, settingsIn, overlayType.ScaleOverlay);
+ GoogleOverlay ovl = new GoogleOverlay(activity, overlayType.ScaleOverlay);
getOverlays().add(ovl);
return (ScaleOverlay) ovl.getBase();
}
@@ -135,9 +132,9 @@ public class GoogleMapView extends MapView implements MapViewImpl {
}
@Override
- public void setMapSource(cgSettings settings) {
+ public void setMapSource() {
- switch (settings.mapSource) {
+ switch (Settings.getMapSource()) {
case googleSat:
setSatellite(true);
break;
diff --git a/main/src/cgeo/geocaching/maps/google/GoogleOverlay.java b/main/src/cgeo/geocaching/maps/google/GoogleOverlay.java
index 03caafb..ef5887b 100644
--- a/main/src/cgeo/geocaching/maps/google/GoogleOverlay.java
+++ b/main/src/cgeo/geocaching/maps/google/GoogleOverlay.java
@@ -1,10 +1,9 @@
package cgeo.geocaching.maps.google;
-import cgeo.geocaching.cgSettings;
import cgeo.geocaching.maps.PositionOverlay;
import cgeo.geocaching.maps.ScaleOverlay;
-import cgeo.geocaching.maps.interfaces.MapViewImpl;
import cgeo.geocaching.maps.interfaces.GeneralOverlay;
+import cgeo.geocaching.maps.interfaces.MapViewImpl;
import cgeo.geocaching.maps.interfaces.OverlayImpl;
import com.google.android.maps.MapView;
@@ -21,13 +20,13 @@ public class GoogleOverlay extends Overlay implements OverlayImpl {
private GeneralOverlay overlayBase = null;
private Lock lock = new ReentrantLock();
- public GoogleOverlay(Activity activityIn, cgSettings settingsIn, overlayType ovlType) {
+ public GoogleOverlay(Activity activityIn, overlayType ovlType) {
switch (ovlType) {
case PositionOverlay:
- overlayBase = new PositionOverlay(settingsIn, activityIn, this);
+ overlayBase = new PositionOverlay(activityIn, this);
break;
case ScaleOverlay:
- overlayBase = new ScaleOverlay(activityIn, settingsIn, this);
+ overlayBase = new ScaleOverlay(activityIn, this);
}
}
diff --git a/main/src/cgeo/geocaching/maps/interfaces/MapViewImpl.java b/main/src/cgeo/geocaching/maps/interfaces/MapViewImpl.java
index e13e2e9..c618a6b 100644
--- a/main/src/cgeo/geocaching/maps/interfaces/MapViewImpl.java
+++ b/main/src/cgeo/geocaching/maps/interfaces/MapViewImpl.java
@@ -1,10 +1,9 @@
package cgeo.geocaching.maps.interfaces;
-import cgeo.geocaching.cgSettings;
-import cgeo.geocaching.maps.PositionOverlay;
import cgeo.geocaching.maps.CachesOverlay;
-import cgeo.geocaching.maps.ScaleOverlay;
import cgeo.geocaching.maps.OtherCachersOverlay;
+import cgeo.geocaching.maps.PositionOverlay;
+import cgeo.geocaching.maps.ScaleOverlay;
import android.app.Activity;
import android.content.Context;
@@ -51,20 +50,20 @@ public interface MapViewImpl {
Context getContext();
- CachesOverlay createAddMapOverlay(cgSettings settings, Context context,
+ CachesOverlay createAddMapOverlay(Context context,
Drawable drawable, boolean fromDetailIntent);
OtherCachersOverlay createAddUsersOverlay(Context context, Drawable markerIn);
- ScaleOverlay createAddScaleOverlay(Activity activity, cgSettings settingsIn);
+ ScaleOverlay createAddScaleOverlay(Activity activity);
- PositionOverlay createAddPositionOverlay(Activity activity, cgSettings settingsIn);
+ PositionOverlay createAddPositionOverlay(Activity activity);
boolean needsScaleOverlay();
void setBuiltinScale(boolean b);
- void setMapSource(cgSettings settings);
+ void setMapSource();
void repaintRequired(GeneralOverlay overlay);
diff --git a/main/src/cgeo/geocaching/maps/mapsforge/MapsforgeCacheOverlay.java b/main/src/cgeo/geocaching/maps/mapsforge/MapsforgeCacheOverlay.java
index c7f1552..a3872b7 100644
--- a/main/src/cgeo/geocaching/maps/mapsforge/MapsforgeCacheOverlay.java
+++ b/main/src/cgeo/geocaching/maps/mapsforge/MapsforgeCacheOverlay.java
@@ -1,6 +1,5 @@
package cgeo.geocaching.maps.mapsforge;
-import cgeo.geocaching.cgSettings;
import cgeo.geocaching.maps.CachesOverlay;
import cgeo.geocaching.maps.interfaces.ItemizedOverlayImpl;
import cgeo.geocaching.maps.interfaces.MapProjectionImpl;
@@ -22,9 +21,9 @@ public class MapsforgeCacheOverlay extends ItemizedOverlay<MapsforgeCacheOverlay
private CachesOverlay base;
private Lock lock = new ReentrantLock();
- public MapsforgeCacheOverlay(cgSettings settingsIn, Context contextIn, Drawable markerIn, Boolean fromDetailIn) {
+ public MapsforgeCacheOverlay(Context contextIn, Drawable markerIn, Boolean fromDetailIn) {
super(boundCenterBottom(markerIn));
- base = new CachesOverlay(settingsIn, this, contextIn, fromDetailIn);
+ base = new CachesOverlay(this, contextIn, fromDetailIn);
}
@Override
diff --git a/main/src/cgeo/geocaching/maps/mapsforge/MapsforgeMapView.java b/main/src/cgeo/geocaching/maps/mapsforge/MapsforgeMapView.java
index fa2dd45..a61213a 100644
--- a/main/src/cgeo/geocaching/maps/mapsforge/MapsforgeMapView.java
+++ b/main/src/cgeo/geocaching/maps/mapsforge/MapsforgeMapView.java
@@ -1,16 +1,16 @@
package cgeo.geocaching.maps.mapsforge;
-import cgeo.geocaching.cgSettings;
-import cgeo.geocaching.maps.PositionOverlay;
+import cgeo.geocaching.Settings;
import cgeo.geocaching.maps.CachesOverlay;
-import cgeo.geocaching.maps.ScaleOverlay;
import cgeo.geocaching.maps.OtherCachersOverlay;
+import cgeo.geocaching.maps.PositionOverlay;
+import cgeo.geocaching.maps.ScaleOverlay;
+import cgeo.geocaching.maps.interfaces.GeneralOverlay;
import cgeo.geocaching.maps.interfaces.GeoPointImpl;
import cgeo.geocaching.maps.interfaces.MapControllerImpl;
import cgeo.geocaching.maps.interfaces.MapProjectionImpl;
import cgeo.geocaching.maps.interfaces.MapViewImpl;
import cgeo.geocaching.maps.interfaces.OnDragListener;
-import cgeo.geocaching.maps.interfaces.GeneralOverlay;
import cgeo.geocaching.maps.interfaces.OverlayImpl;
import cgeo.geocaching.maps.interfaces.OverlayImpl.overlayType;
@@ -49,7 +49,7 @@ public class MapsforgeMapView extends MapView implements MapViewImpl {
super.draw(canvas);
} catch (Exception e) {
- Log.e(cgSettings.tag, "cgMapView.draw: " + e.toString());
+ Log.e(Settings.tag, "cgMapView.draw: " + e.toString());
}
}
@@ -85,10 +85,9 @@ public class MapsforgeMapView extends MapView implements MapViewImpl {
}
@Override
- public CachesOverlay createAddMapOverlay(cgSettings settings,
- Context context, Drawable drawable, boolean fromDetailIntent) {
+ public CachesOverlay createAddMapOverlay(Context context, Drawable drawable, boolean fromDetailIntent) {
- MapsforgeCacheOverlay ovl = new MapsforgeCacheOverlay(settings, context, drawable, fromDetailIntent);
+ MapsforgeCacheOverlay ovl = new MapsforgeCacheOverlay(context, drawable, fromDetailIntent);
getOverlays().add(ovl);
return ovl.getBase();
}
@@ -101,17 +100,15 @@ public class MapsforgeMapView extends MapView implements MapViewImpl {
}
@Override
- public PositionOverlay createAddPositionOverlay(Activity activity,
- cgSettings settingsIn) {
- MapsforgeOverlay ovl = new MapsforgeOverlay(activity, settingsIn, overlayType.PositionOverlay);
+ public PositionOverlay createAddPositionOverlay(Activity activity) {
+ MapsforgeOverlay ovl = new MapsforgeOverlay(activity, overlayType.PositionOverlay);
getOverlays().add(ovl);
return (PositionOverlay) ovl.getBase();
}
@Override
- public ScaleOverlay createAddScaleOverlay(Activity activity,
- cgSettings settingsIn) {
- MapsforgeOverlay ovl = new MapsforgeOverlay(activity, settingsIn, overlayType.ScaleOverlay);
+ public ScaleOverlay createAddScaleOverlay(Activity activity) {
+ MapsforgeOverlay ovl = new MapsforgeOverlay(activity, overlayType.ScaleOverlay);
getOverlays().add(ovl);
return (ScaleOverlay) ovl.getBase();
}
@@ -176,9 +173,9 @@ public class MapsforgeMapView extends MapView implements MapViewImpl {
}
@Override
- public void setMapSource(cgSettings settings) {
+ public void setMapSource() {
- switch (settings.mapSource) {
+ switch (Settings.getMapSource()) {
case mapsforgeOsmarender:
setMapViewMode(MapViewMode.OSMARENDER_TILE_DOWNLOAD);
break;
@@ -186,9 +183,9 @@ public class MapsforgeMapView extends MapView implements MapViewImpl {
setMapViewMode(MapViewMode.OPENCYCLEMAP_TILE_DOWNLOAD);
break;
case mapsforgeOffline:
- if (MapDatabase.isValidMapFile(settings.getMapFile())) {
+ if (MapDatabase.isValidMapFile(Settings.getMapFile())) {
setMapViewMode(MapViewMode.CANVAS_RENDERER);
- super.setMapFile(settings.getMapFile());
+ super.setMapFile(Settings.getMapFile());
} else {
setMapViewMode(MapViewMode.MAPNIK_TILE_DOWNLOAD);
}
@@ -209,7 +206,7 @@ public class MapsforgeMapView extends MapView implements MapViewImpl {
}
} catch (Exception e) {
- Log.e(cgSettings.tag, "mfMapView.repaintRequired: " + e.toString());
+ Log.e(Settings.tag, "mfMapView.repaintRequired: " + e.toString());
}
}
diff --git a/main/src/cgeo/geocaching/maps/mapsforge/MapsforgeOverlay.java b/main/src/cgeo/geocaching/maps/mapsforge/MapsforgeOverlay.java
index 60bc55a..dc8add2 100644
--- a/main/src/cgeo/geocaching/maps/mapsforge/MapsforgeOverlay.java
+++ b/main/src/cgeo/geocaching/maps/mapsforge/MapsforgeOverlay.java
@@ -1,6 +1,5 @@
package cgeo.geocaching.maps.mapsforge;
-import cgeo.geocaching.cgSettings;
import cgeo.geocaching.maps.PositionOverlay;
import cgeo.geocaching.maps.ScaleOverlay;
import cgeo.geocaching.maps.interfaces.GeneralOverlay;
@@ -21,14 +20,14 @@ public class MapsforgeOverlay extends Overlay implements OverlayImpl {
private GeneralOverlay overlayBase = null;
private Lock lock = new ReentrantLock();
- public MapsforgeOverlay(Activity activityIn, cgSettings settingsIn, OverlayImpl.overlayType ovlType) {
+ public MapsforgeOverlay(Activity activityIn, OverlayImpl.overlayType ovlType) {
switch (ovlType) {
case PositionOverlay:
- overlayBase = new PositionOverlay(settingsIn, activityIn, this);
+ overlayBase = new PositionOverlay(activityIn, this);
break;
case ScaleOverlay:
- overlayBase = new ScaleOverlay(activityIn, settingsIn, this);
+ overlayBase = new ScaleOverlay(activityIn, this);
}
}
diff --git a/main/src/cgeo/geocaching/sorting/AbstractCacheComparator.java b/main/src/cgeo/geocaching/sorting/AbstractCacheComparator.java
index 03db8df..bc93d3b 100644
--- a/main/src/cgeo/geocaching/sorting/AbstractCacheComparator.java
+++ b/main/src/cgeo/geocaching/sorting/AbstractCacheComparator.java
@@ -1,7 +1,7 @@
package cgeo.geocaching.sorting;
import cgeo.geocaching.cgCache;
-import cgeo.geocaching.cgSettings;
+import cgeo.geocaching.Settings;
import android.util.Log;
@@ -20,7 +20,7 @@ public abstract class AbstractCacheComparator implements CacheComparator {
}
return compareCaches(cache1, cache2);
} catch (Exception e) {
- Log.e(cgSettings.tag, "AbstractCacheComparator.compare: " + e.toString());
+ Log.e(Settings.tag, "AbstractCacheComparator.compare: " + e.toString());
}
return 0;
}
diff --git a/main/src/cgeo/geocaching/utils/CryptUtils.java b/main/src/cgeo/geocaching/utils/CryptUtils.java
index a2927aa..a0d7d1a 100644
--- a/main/src/cgeo/geocaching/utils/CryptUtils.java
+++ b/main/src/cgeo/geocaching/utils/CryptUtils.java
@@ -1,6 +1,6 @@
package cgeo.geocaching.utils;
-import cgeo.geocaching.cgSettings;
+import cgeo.geocaching.Settings;
import android.text.Spannable;
import android.text.SpannableStringBuilder;
@@ -49,7 +49,7 @@ public final class CryptUtils {
digest.update(text.getBytes(), 0, text.length());
hashed = new BigInteger(1, digest.digest()).toString(16);
} catch (Exception e) {
- Log.e(cgSettings.tag, "cgBase.md5: " + e.toString());
+ Log.e(Settings.tag, "cgBase.md5: " + e.toString());
}
return hashed;
@@ -63,7 +63,7 @@ public final class CryptUtils {
digest.update(text.getBytes(), 0, text.length());
hashed = new BigInteger(1, digest.digest()).toString(16);
} catch (Exception e) {
- Log.e(cgSettings.tag, "cgBase.sha1: " + e.toString());
+ Log.e(Settings.tag, "cgBase.sha1: " + e.toString());
}
return hashed;
@@ -78,7 +78,7 @@ public final class CryptUtils {
mac.init(secretKeySpec);
macBytes = mac.doFinal(text.getBytes());
} catch (Exception e) {
- Log.e(cgSettings.tag, "cgBase.hashHmac: " + e.toString());
+ Log.e(Settings.tag, "cgBase.hashHmac: " + e.toString());
}
return macBytes;
diff --git a/tests/src/cgeo/geocaching/test/DistanceParserTest.java b/tests/src/cgeo/geocaching/test/DistanceParserTest.java
index 709064f..34bef7b 100644
--- a/tests/src/cgeo/geocaching/test/DistanceParserTest.java
+++ b/tests/src/cgeo/geocaching/test/DistanceParserTest.java
@@ -1,6 +1,5 @@
package cgeo.geocaching.test;
-import cgeo.geocaching.cgSettings;
import cgeo.geocaching.geopoint.DistanceParser;
import android.test.AndroidTestCase;
@@ -13,24 +12,24 @@ public class DistanceParserTest extends AndroidTestCase {
static private final double MM = 1e-6; // 1mm, in kilometers
public void testFormats() {
- Assert.assertEquals(1.2, DistanceParser.parseDistance("1200 m", cgSettings.unitsMetric), MM);
- Assert.assertEquals(1.2, DistanceParser.parseDistance("1.2 km", cgSettings.unitsMetric), MM);
- Assert.assertEquals(0.36576, DistanceParser.parseDistance("1200 ft", cgSettings.unitsMetric), MM);
- Assert.assertEquals(1.09728, DistanceParser.parseDistance("1200 yd", cgSettings.unitsMetric), MM);
- Assert.assertEquals(1.9312128, DistanceParser.parseDistance("1.2 mi", cgSettings.unitsMetric), MM);
+ Assert.assertEquals(1.2, DistanceParser.parseDistance("1200 m", true), MM);
+ Assert.assertEquals(1.2, DistanceParser.parseDistance("1.2 km", true), MM);
+ Assert.assertEquals(0.36576, DistanceParser.parseDistance("1200 ft", true), MM);
+ Assert.assertEquals(1.09728, DistanceParser.parseDistance("1200 yd", true), MM);
+ Assert.assertEquals(1.9312128, DistanceParser.parseDistance("1.2 mi", true), MM);
}
public void testImplicit() {
- Assert.assertEquals(1.2, DistanceParser.parseDistance("1200", cgSettings.unitsMetric), MM);
- Assert.assertEquals(0.36576, DistanceParser.parseDistance("1200", cgSettings.unitsImperial), MM);
+ Assert.assertEquals(1.2, DistanceParser.parseDistance("1200", true), MM);
+ Assert.assertEquals(0.36576, DistanceParser.parseDistance("1200", false), MM);
}
public void testComma() {
- Assert.assertEquals(1.2, DistanceParser.parseDistance("1,2km", cgSettings.unitsMetric), MM);
+ Assert.assertEquals(1.2, DistanceParser.parseDistance("1,2km", true), MM);
}
public void testCase() {
- Assert.assertEquals(0.36576, DistanceParser.parseDistance("1200 FT", cgSettings.unitsMetric), MM);
+ Assert.assertEquals(0.36576, DistanceParser.parseDistance("1200 FT", true), MM);
}
} \ No newline at end of file
diff --git a/tests/src/cgeo/geocaching/test/RegExRealPerformanceTest.java b/tests/src/cgeo/geocaching/test/RegExRealPerformanceTest.java
index eda2f6d..971a12f 100644
--- a/tests/src/cgeo/geocaching/test/RegExRealPerformanceTest.java
+++ b/tests/src/cgeo/geocaching/test/RegExRealPerformanceTest.java
@@ -1,6 +1,6 @@
package cgeo.geocaching.test;
-import cgeo.geocaching.cgSettings;
+import cgeo.geocaching.Settings;
import android.test.AndroidTestCase;
import android.util.Log;
@@ -20,7 +20,7 @@ public class RegExRealPerformanceTest extends AndroidTestCase {
List<String> output = RegExPerformanceTest.doTheTests(10);
for (String s : output) {
- Log.w(cgSettings.tag, s);
+ Log.w(Settings.tag, s);
}
}
diff --git a/tests/src/cgeo/geocaching/test/SettingsTest.java b/tests/src/cgeo/geocaching/test/SettingsTest.java
new file mode 100644
index 0000000..bb3bee8
--- /dev/null
+++ b/tests/src/cgeo/geocaching/test/SettingsTest.java
@@ -0,0 +1,27 @@
+package cgeo.geocaching.test;
+
+import cgeo.geocaching.Settings;
+import cgeo.geocaching.cgeo;
+
+import android.test.ActivityInstrumentationTestCase2;
+
+public class SettingsTest extends ActivityInstrumentationTestCase2<cgeo> {
+
+ public SettingsTest() {
+ super("cgeo.geocaching", cgeo.class);
+ }
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ }
+
+ /**
+ * access settings.
+ * this should work fine without an exception (once there was an exception because of the empty map file string)
+ */
+ public void testSettingsException() {
+ // asserts A OR NOT A, because we don't know what the settings are on any device or emulator
+ assertTrue(Settings.isValidMapFile() || !Settings.isValidMapFile());
+ }
+}
diff --git a/tests/src/cgeo/geocaching/test/WhitespaceTest.java b/tests/src/cgeo/geocaching/test/WhitespaceTest.java
index 55c6bcf..f1ba0ea 100644
--- a/tests/src/cgeo/geocaching/test/WhitespaceTest.java
+++ b/tests/src/cgeo/geocaching/test/WhitespaceTest.java
@@ -1,6 +1,6 @@
package cgeo.geocaching.test;
-import cgeo.geocaching.cgSettings;
+import cgeo.geocaching.Settings;
import org.apache.commons.lang3.StringUtils;
@@ -66,7 +66,7 @@ public class WhitespaceTest extends AndroidTestCase {
result = replaceWhitespaceManually(data);
final long end = System.currentTimeMillis();
assertEquals(84028, result.length());
- Log.w(cgSettings.tag, (end - start) + " ms manually");
+ Log.w(Settings.tag, (end - start) + " ms manually");
}
public void testStringUtils() {
@@ -75,6 +75,6 @@ public class WhitespaceTest extends AndroidTestCase {
result = replaceWhitespaceStringUtils(data);
final long end = System.currentTimeMillis();
assertEquals(84026, result.length());
- Log.w(cgSettings.tag, (end - start) + " ms StringUtils");
+ Log.w(Settings.tag, (end - start) + " ms StringUtils");
}
}
diff --git a/tests/src/cgeo/geocaching/test/cgSettingsTest.java b/tests/src/cgeo/geocaching/test/cgSettingsTest.java
deleted file mode 100644
index 721330d..0000000
--- a/tests/src/cgeo/geocaching/test/cgSettingsTest.java
+++ /dev/null
@@ -1,30 +0,0 @@
-package cgeo.geocaching.test;
-
-import android.test.ActivityInstrumentationTestCase2;
-import cgeo.geocaching.cgSettings;
-import cgeo.geocaching.cgeo;
-
-public class cgSettingsTest extends ActivityInstrumentationTestCase2<cgeo> {
-
- private cgeo activity;
-
- public cgSettingsTest() {
- super("cgeo.geocaching", cgeo.class);
- }
-
- @Override
- protected void setUp() throws Exception {
- super.setUp();
- activity = getActivity();
- }
-
- /**
- * loads new empty settings, this should work fine without an exception (once there was an exception because of the empty map file string)
- */
- public void testSettingsException() {
- final cgSettings settings = new cgSettings(activity, activity.getSharedPreferences("not existing preferences", 0));
-
- // assert that we really created new settings
- assertNull(settings.getMapFile());
- }
-}
diff --git a/tests/src/cgeo/geocaching/test/cgeoApplicationTest.java b/tests/src/cgeo/geocaching/test/cgeoApplicationTest.java
index f69889a..89eda4d 100644
--- a/tests/src/cgeo/geocaching/test/cgeoApplicationTest.java
+++ b/tests/src/cgeo/geocaching/test/cgeoApplicationTest.java
@@ -3,14 +3,11 @@ package cgeo.geocaching.test;
import cgeo.geocaching.cgBase;
import cgeo.geocaching.cgCache;
import cgeo.geocaching.cgCacheWrap;
-import cgeo.geocaching.cgSettings;
import cgeo.geocaching.cgeoapplication;
import cgeo.geocaching.test.mock.GC1ZXX2;
import cgeo.geocaching.test.mock.GC2CJPF;
import cgeo.geocaching.test.mock.MockedCache;
-import android.content.Context;
-import android.content.SharedPreferences;
import android.test.ApplicationTestCase;
import android.test.suitebuilder.annotation.MediumTest;
import android.test.suitebuilder.annotation.SmallTest;
@@ -29,7 +26,6 @@ import junit.framework.Assert;
public class cgeoApplicationTest extends ApplicationTestCase<cgeoapplication> {
- private cgSettings settings = null;
private cgBase base = null;
public cgeoApplicationTest() {
@@ -42,13 +38,9 @@ public class cgeoApplicationTest extends ApplicationTestCase<cgeoapplication> {
// init environment
createApplication();
- final Context context = this.getContext();
- final SharedPreferences prefs = context.getSharedPreferences(
- cgSettings.preferences, Context.MODE_PRIVATE);
// create required c:geo objects
- settings = new cgSettings(context, prefs);
- base = new cgBase(this.getApplication(), settings);
+ base = new cgBase(this.getApplication());
}
/**