diff options
| author | keith.paterson <keith.paterson@saxsys.de> | 2012-04-11 19:54:06 +0200 |
|---|---|---|
| committer | keith.paterson <keith.paterson@saxsys.de> | 2012-04-11 19:54:06 +0200 |
| commit | 60d4f531a0d47dcf9231329e218974d267103fbc (patch) | |
| tree | 8e6ebbb4dc9941097d05c913165cf7d3439b4558 /main/src | |
| parent | 18dbf91f699477234d6dbaeb03473866a8a2529b (diff) | |
| parent | dfbdd962599a6034bba9945d92dbf0ba90580580 (diff) | |
| download | cgeo-60d4f531a0d47dcf9231329e218974d267103fbc.zip cgeo-60d4f531a0d47dcf9231329e218974d267103fbc.tar.gz cgeo-60d4f531a0d47dcf9231329e218974d267103fbc.tar.bz2 | |
Merge remote-tracking branch 'upstream/master' into master-new
Diffstat (limited to 'main/src')
| -rw-r--r-- | main/src/cgeo/geocaching/IBasicCache.java | 2 | ||||
| -rw-r--r-- | main/src/cgeo/geocaching/ICache.java | 10 | ||||
| -rw-r--r-- | main/src/cgeo/geocaching/ICoordinates.java | 9 | ||||
| -rw-r--r-- | main/src/cgeo/geocaching/IWaypoint.java | 5 | ||||
| -rw-r--r-- | main/src/cgeo/geocaching/Settings.java | 173 | ||||
| -rw-r--r-- | main/src/cgeo/geocaching/backup/CentralBackupAgent.java | 4 | ||||
| -rw-r--r-- | main/src/cgeo/geocaching/cgCache.java | 13 | ||||
| -rw-r--r-- | main/src/cgeo/geocaching/cgData.java | 53 | ||||
| -rw-r--r-- | main/src/cgeo/geocaching/cgDestination.java | 54 | ||||
| -rw-r--r-- | main/src/cgeo/geocaching/cgWaypoint.java | 8 | ||||
| -rw-r--r-- | main/src/cgeo/geocaching/cgeoapplication.java | 19 | ||||
| -rw-r--r-- | main/src/cgeo/geocaching/cgeopoint.java | 12 | ||||
| -rw-r--r-- | main/src/cgeo/geocaching/geopoint/Geopoint.java | 40 |
13 files changed, 199 insertions, 203 deletions
diff --git a/main/src/cgeo/geocaching/IBasicCache.java b/main/src/cgeo/geocaching/IBasicCache.java index 5e67b2d..195572b 100644 --- a/main/src/cgeo/geocaching/IBasicCache.java +++ b/main/src/cgeo/geocaching/IBasicCache.java @@ -11,7 +11,7 @@ import cgeo.geocaching.enumerations.CacheType; * @author blafoo * */ -public interface IBasicCache extends ILogable { +public interface IBasicCache extends ILogable, ICoordinates { public abstract String getGuid(); diff --git a/main/src/cgeo/geocaching/ICache.java b/main/src/cgeo/geocaching/ICache.java index b6a809f..dccdb85 100644 --- a/main/src/cgeo/geocaching/ICache.java +++ b/main/src/cgeo/geocaching/ICache.java @@ -28,16 +28,6 @@ public interface ICache extends IBasicCache { public String getOwnerReal(); /** - * @return Latitude, e.g. N 52° 12.345 - */ - public String getLatitude(); - - /** - * @return Longitude, e.g. E 9° 34.567 - */ - public String getLongitude(); - - /** * @return true if the user is the owner of the cache, false else */ public boolean isOwn(); diff --git a/main/src/cgeo/geocaching/ICoordinates.java b/main/src/cgeo/geocaching/ICoordinates.java new file mode 100644 index 0000000..b70e4ac --- /dev/null +++ b/main/src/cgeo/geocaching/ICoordinates.java @@ -0,0 +1,9 @@ +package cgeo.geocaching; + +import cgeo.geocaching.geopoint.Geopoint; + +public interface ICoordinates { + + public abstract Geopoint getCoords(); + +} diff --git a/main/src/cgeo/geocaching/IWaypoint.java b/main/src/cgeo/geocaching/IWaypoint.java index 3e26052..ad12d48 100644 --- a/main/src/cgeo/geocaching/IWaypoint.java +++ b/main/src/cgeo/geocaching/IWaypoint.java @@ -4,18 +4,15 @@ package cgeo.geocaching; import cgeo.geocaching.enumerations.WaypointType; -import cgeo.geocaching.geopoint.Geopoint; /** * @author blafoo * */ -public interface IWaypoint extends ILogable { +public interface IWaypoint extends ILogable, ICoordinates { public abstract int getId(); - public abstract Geopoint getCoords(); - public abstract WaypointType getWaypointType(); public abstract String getCoordType(); diff --git a/main/src/cgeo/geocaching/Settings.java b/main/src/cgeo/geocaching/Settings.java index 92e96aa..9080b3f 100644 --- a/main/src/cgeo/geocaching/Settings.java +++ b/main/src/cgeo/geocaching/Settings.java @@ -9,13 +9,13 @@ import cgeo.geocaching.utils.CryptUtils; 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.SharedPreferences; import android.content.SharedPreferences.Editor; import android.content.res.Configuration; import android.content.res.Resources; +import android.preference.PreferenceManager; import java.util.Locale; @@ -82,9 +82,9 @@ public final class Settings { private static final String KEY_DEBUG = "debug"; private static final String KEY_HIDE_LIVE_MAP_HINT = "hidelivemaphint"; private static final String KEY_LIVE_MAP_HINT_SHOW_COUNT = "livemaphintshowcount"; + private static final String KEY_SETTINGS_VERSION = "settingsversion"; private final static int unitsMetric = 1; - private final static int unitsImperial = 2; // twitter api keys private final static String keyConsumerPublic = CryptUtils.rot13("ESnsCvAv3kEupF1GCR3jGj"); @@ -113,13 +113,14 @@ public final class Settings { // 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; + private static final SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(cgeoapplication.getInstance().getBaseContext()); + static { + migrateSettings(); + } + // Debug settings are accessed often enough to be cached private static Boolean cachedDebug = sharedPrefs.getBoolean(KEY_DEBUG, false); @@ -130,6 +131,82 @@ public final class Settings { // this class is not to be instantiated; } + private static void migrateSettings() { + // migrate from non standard file location and integer based boolean types + if (sharedPrefs.getInt(KEY_SETTINGS_VERSION, 0) < 1) { + final String oldPreferencesName = "cgeo.pref"; + final SharedPreferences old = cgeoapplication.getInstance().getSharedPreferences(oldPreferencesName, Context.MODE_PRIVATE); + final Editor e = sharedPrefs.edit(); + + e.putString(KEY_TEMP_TOKEN_SECRET, old.getString(KEY_TEMP_TOKEN_SECRET, null)); + e.putString(KEY_TEMP_TOKEN_PUBLIC, old.getString(KEY_TEMP_TOKEN_PUBLIC, null)); + e.putBoolean(KEY_HELP_SHOWN, old.getInt(KEY_HELP_SHOWN, 0) != 0); + e.putFloat(KEY_ANYLONGITUDE, old.getFloat(KEY_ANYLONGITUDE, 0)); + e.putFloat(KEY_ANYLATITUDE, old.getFloat(KEY_ANYLATITUDE, 0)); + e.putBoolean(KEY_PUBLICLOC, 0 != old.getInt(KEY_PUBLICLOC, 0)); + e.putBoolean(KEY_USE_OFFLINEMAPS, 0 != old.getInt(KEY_USE_OFFLINEMAPS, 1)); + e.putBoolean(KEY_USE_OFFLINEWPMAPS, 0 != old.getInt(KEY_USE_OFFLINEWPMAPS, 0)); + e.putString(KEY_WEB_DEVICE_CODE, old.getString(KEY_WEB_DEVICE_CODE, null)); + e.putString(KEY_WEBDEVICE_NAME, old.getString(KEY_WEBDEVICE_NAME, null)); + e.putBoolean(KEY_MAP_LIVE, old.getInt(KEY_MAP_LIVE, 1) != 0); + e.putInt(KEY_MAP_SOURCE, old.getInt(KEY_MAP_SOURCE, 0)); + e.putBoolean(KEY_USE_TWITTER, 0 != old.getInt(KEY_USE_TWITTER, 0)); + e.putBoolean(KEY_SHOW_ADDRESS, 0 != old.getInt(KEY_SHOW_ADDRESS, 1)); + e.putBoolean(KEY_SHOW_CAPTCHA, old.getBoolean(KEY_SHOW_CAPTCHA, false)); + e.putBoolean(KEY_MAP_TRAIL, old.getInt(KEY_MAP_TRAIL, 1) != 0); + e.putInt(KEY_LAST_MAP_ZOOM, old.getInt(KEY_LAST_MAP_ZOOM, 14)); + e.putBoolean(KEY_LIVE_LIST, 0 != old.getInt(KEY_LIVE_LIST, 1)); + e.putBoolean(KEY_METRIC_UNITS, old.getInt(KEY_METRIC_UNITS, unitsMetric) == unitsMetric); + e.putBoolean(KEY_SKIN, old.getInt(KEY_SKIN, 0) != 0); + e.putInt(KEY_LAST_USED_LIST, old.getInt(KEY_LAST_USED_LIST, StoredList.STANDARD_LIST_ID)); + e.putString(KEY_CACHE_TYPE, old.getString(KEY_CACHE_TYPE, CacheType.ALL.id)); + e.putString(KEY_TWITTER_TOKEN_SECRET, old.getString(KEY_TWITTER_TOKEN_SECRET, null)); + e.putString(KEY_TWITTER_TOKEN_PUBLIC, old.getString(KEY_TWITTER_TOKEN_PUBLIC, null)); + e.putInt(KEY_VERSION, old.getInt(KEY_VERSION, 0)); + e.putBoolean(KEY_LOAD_DESCRIPTION, 0 != old.getInt(KEY_LOAD_DESCRIPTION, 0)); + e.putBoolean(KEY_RATING_WANTED, old.getBoolean(KEY_RATING_WANTED, true)); + e.putBoolean(KEY_ELEVATION_WANTED, old.getBoolean(KEY_ELEVATION_WANTED, true)); + e.putBoolean(KEY_FRIENDLOGS_WANTED, old.getBoolean(KEY_FRIENDLOGS_WANTED, true)); + e.putBoolean(KEY_USE_ENGLISH, old.getBoolean(KEY_USE_ENGLISH, false)); + e.putBoolean(KEY_USE_COMPASS, 0 != old.getInt(KEY_USE_COMPASS, 1)); + e.putBoolean(KEY_AUTO_VISIT_TRACKABLES, old.getBoolean(KEY_AUTO_VISIT_TRACKABLES, false)); + e.putBoolean(KEY_AUTO_INSERT_SIGNATURE, old.getBoolean(KEY_AUTO_INSERT_SIGNATURE, false)); + e.putInt(KEY_ALTITUDE_CORRECTION, old.getInt(KEY_ALTITUDE_CORRECTION, 0)); + e.putBoolean(KEY_USE_GOOGLE_NAVIGATION, 0 != old.getInt(KEY_USE_GOOGLE_NAVIGATION, 1)); + e.putBoolean(KEY_STORE_LOG_IMAGES, old.getBoolean(KEY_STORE_LOG_IMAGES, false)); + e.putBoolean(KEY_EXCLUDE_DISABLED, 0 != old.getInt(KEY_EXCLUDE_DISABLED, 0)); + e.putBoolean(KEY_EXCLUDE_OWN, 0 != old.getInt(KEY_EXCLUDE_OWN, 0)); + e.putString(KEY_MAPFILE, old.getString(KEY_MAPFILE, null)); + e.putString(KEY_SIGNATURE, old.getString(KEY_SIGNATURE, null)); + e.putString(KEY_GCVOTE_PASSWORD, old.getString(KEY_GCVOTE_PASSWORD, null)); + e.putString(KEY_PASSWORD, old.getString(KEY_PASSWORD, null)); + e.putString(KEY_USERNAME, old.getString(KEY_USERNAME, null)); + e.putString(KEY_MEMBER_STATUS, old.getString(KEY_MEMBER_STATUS, "")); + e.putInt(KEY_COORD_INPUT_FORMAT, old.getInt(KEY_COORD_INPUT_FORMAT, 0)); + e.putBoolean(KEY_LOG_OFFLINE, old.getBoolean(KEY_LOG_OFFLINE, false)); + e.putBoolean(KEY_LOAD_DIRECTION_IMG, old.getBoolean(KEY_LOAD_DIRECTION_IMG, true)); + e.putString(KEY_GC_CUSTOM_DATE, old.getString(KEY_GC_CUSTOM_DATE, null)); + e.putInt(KEY_SHOW_WAYPOINTS_THRESHOLD, old.getInt(KEY_SHOW_WAYPOINTS_THRESHOLD, 0)); + e.putString(KEY_COOKIE_STORE, old.getString(KEY_COOKIE_STORE, null)); + e.putBoolean(KEY_OPEN_LAST_DETAILS_PAGE, old.getBoolean(KEY_OPEN_LAST_DETAILS_PAGE, false)); + e.putInt(KEY_LAST_DETAILS_PAGE, old.getInt(KEY_LAST_DETAILS_PAGE, 1)); + e.putInt(KEY_DEFAULT_NAVIGATION_TOOL, old.getInt(KEY_DEFAULT_NAVIGATION_TOOL, 0)); + e.putInt(KEY_DEFAULT_NAVIGATION_TOOL_2, old.getInt(KEY_DEFAULT_NAVIGATION_TOOL_2, 0)); + e.putInt(KEY_LIVE_MAP_STRATEGY, old.getInt(KEY_LIVE_MAP_STRATEGY, Strategy.AUTO.id)); + e.putBoolean(KEY_DEBUG, old.getBoolean(KEY_DEBUG, false)); + e.putBoolean(KEY_HIDE_LIVE_MAP_HINT, old.getInt(KEY_HIDE_LIVE_MAP_HINT, 0) != 0); + e.putInt(KEY_LIVE_MAP_HINT_SHOW_COUNT, old.getInt(KEY_LIVE_MAP_HINT_SHOW_COUNT, 0)); + + e.putInt(KEY_SETTINGS_VERSION, 1) ; // mark migrated + e.commit(); + cachedDebug = sharedPrefs.getBoolean(KEY_DEBUG, false); + } + final SharedPreferences old = cgeoapplication.getInstance().getSharedPreferences("cgeo.pref", Context.MODE_PRIVATE); + System.out.println("old prefs " + old.getString(KEY_USERNAME, "not set")); + System.out.println("shared prefs " + sharedPrefs.getString(KEY_USERNAME, "no set")); + + } + public static void setLanguage(boolean useEnglish) { final Configuration config = new Configuration(); config.locale = useEnglish ? new Locale("en") : Locale.getDefault(); @@ -315,7 +392,7 @@ public final class Settings { @Override public void edit(Editor edit) { - edit.putInt(KEY_MAP_LIVE, live ? 1 : 0); + edit.putBoolean(KEY_MAP_LIVE, live); } }); } @@ -371,17 +448,6 @@ public final class Settings { return commitResult; } - public static boolean isValidMapFile() { - return checkMapfile(getMapFile()); - } - - private static boolean checkMapfile(final 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)); } @@ -443,7 +509,7 @@ public final class Settings { } public static boolean isExcludeMyCaches() { - return 0 != sharedPrefs.getInt(KEY_EXCLUDE_OWN, 0); + return sharedPrefs.getBoolean(KEY_EXCLUDE_OWN, false); } /** @@ -463,7 +529,7 @@ public final class Settings { @Override public void edit(Editor edit) { - edit.putInt(KEY_EXCLUDE_OWN, exclude ? 1 : 0); + edit.putBoolean(KEY_EXCLUDE_OWN, exclude); } }); } @@ -483,7 +549,7 @@ public final class Settings { } public static boolean isShowAddress() { - return 0 != sharedPrefs.getInt(KEY_SHOW_ADDRESS, 1); + return sharedPrefs.getBoolean(KEY_SHOW_ADDRESS, true); } public static void setShowAddress(final boolean showAddress) { @@ -491,7 +557,7 @@ public final class Settings { @Override public void edit(Editor edit) { - edit.putInt(KEY_SHOW_ADDRESS, showAddress ? 1 : 0); + edit.putBoolean(KEY_SHOW_ADDRESS, showAddress); } }); } @@ -511,7 +577,7 @@ public final class Settings { } public static boolean isExcludeDisabledCaches() { - return 0 != sharedPrefs.getInt(KEY_EXCLUDE_DISABLED, 0); + return sharedPrefs.getBoolean(KEY_EXCLUDE_DISABLED, false); } public static void setExcludeDisabledCaches(final boolean exclude) { @@ -519,13 +585,13 @@ public final class Settings { @Override public void edit(Editor edit) { - edit.putInt(KEY_EXCLUDE_DISABLED, exclude ? 1 : 0); + edit.putBoolean(KEY_EXCLUDE_DISABLED, exclude); } }); } public static boolean isStoreOfflineMaps() { - return 0 != sharedPrefs.getInt(KEY_USE_OFFLINEMAPS, 1); + return sharedPrefs.getBoolean(KEY_USE_OFFLINEMAPS, true); } public static void setStoreOfflineMaps(final boolean offlineMaps) { @@ -533,13 +599,13 @@ public final class Settings { @Override public void edit(Editor edit) { - edit.putInt(KEY_USE_OFFLINEMAPS, offlineMaps ? 1 : 0); + edit.putBoolean(KEY_USE_OFFLINEMAPS, offlineMaps); } }); } public static boolean isStoreOfflineWpMaps() { - return 0 != sharedPrefs.getInt(KEY_USE_OFFLINEWPMAPS, 0); + return sharedPrefs.getBoolean(KEY_USE_OFFLINEWPMAPS, false); } public static void setStoreOfflineWpMaps(final boolean offlineMaps) { @@ -547,7 +613,7 @@ public final class Settings { @Override public void edit(Editor edit) { - edit.putInt(KEY_USE_OFFLINEWPMAPS, offlineMaps ? 1 : 0); + edit.putBoolean(KEY_USE_OFFLINEWPMAPS, offlineMaps); } }); } @@ -567,7 +633,7 @@ public final class Settings { } public static boolean isUseGoogleNavigation() { - return 0 != sharedPrefs.getInt(KEY_USE_GOOGLE_NAVIGATION, 1); + return sharedPrefs.getBoolean(KEY_USE_GOOGLE_NAVIGATION, true); } public static void setUseGoogleNavigation(final boolean useGoogleNavigation) { @@ -575,13 +641,13 @@ public final class Settings { @Override public void edit(Editor edit) { - edit.putInt(KEY_USE_GOOGLE_NAVIGATION, useGoogleNavigation ? 1 : 0); + edit.putBoolean(KEY_USE_GOOGLE_NAVIGATION, useGoogleNavigation); } }); } public static boolean isAutoLoadDescription() { - return 0 != sharedPrefs.getInt(KEY_LOAD_DESCRIPTION, 0); + return sharedPrefs.getBoolean(KEY_LOAD_DESCRIPTION, false); } public static void setAutoLoadDesc(final boolean autoLoad) { @@ -589,7 +655,7 @@ public final class Settings { @Override public void edit(Editor edit) { - edit.putInt(KEY_LOAD_DESCRIPTION, autoLoad ? 1 : 0); + edit.putBoolean(KEY_LOAD_DESCRIPTION, autoLoad); } }); } @@ -641,7 +707,7 @@ public final class Settings { } public static boolean isLiveList() { - return 0 != sharedPrefs.getInt(KEY_LIVE_LIST, 1); + return sharedPrefs.getBoolean(KEY_LIVE_LIST, true); } public static void setLiveList(final boolean liveList) { @@ -649,13 +715,13 @@ public final class Settings { @Override public void edit(Editor edit) { - edit.putInt(KEY_LIVE_LIST, liveList ? 1 : 0); + edit.putBoolean(KEY_LIVE_LIST, liveList); } }); } public static boolean isPublicLoc() { - return 0 != sharedPrefs.getInt(KEY_PUBLICLOC, 0); + return sharedPrefs.getBoolean(KEY_PUBLICLOC, false); } public static void setPublicLoc(final boolean publicLocation) { @@ -663,7 +729,7 @@ public final class Settings { @Override public void edit(Editor edit) { - edit.putInt(KEY_PUBLICLOC, publicLocation ? 1 : 0); + edit.putBoolean(KEY_PUBLICLOC, publicLocation); } }); } @@ -697,7 +763,7 @@ public final class Settings { } public static boolean isUseMetricUnits() { - return sharedPrefs.getInt(KEY_METRIC_UNITS, unitsMetric) == unitsMetric; + return sharedPrefs.getBoolean(KEY_METRIC_UNITS, true); } public static void setUseMetricUnits(final boolean metric) { @@ -705,17 +771,17 @@ public final class Settings { @Override public void edit(Editor edit) { - edit.putInt(KEY_METRIC_UNITS, metric ? unitsMetric : unitsImperial); + edit.putBoolean(KEY_METRIC_UNITS, metric); } }); } public static boolean isLiveMap() { - return sharedPrefs.getInt(KEY_MAP_LIVE, 1) != 0; + return sharedPrefs.getBoolean(KEY_MAP_LIVE, true); } public static boolean isMapTrail() { - return sharedPrefs.getInt(KEY_MAP_TRAIL, 1) != 0; + return sharedPrefs.getBoolean(KEY_MAP_TRAIL, true); } public static void setMapTrail(final boolean showTrail) { @@ -723,7 +789,7 @@ public final class Settings { @Override public void edit(Editor edit) { - edit.putInt(KEY_MAP_TRAIL, showTrail ? 1 : 0); + edit.putBoolean(KEY_MAP_TRAIL, showTrail); } }); } @@ -786,7 +852,7 @@ public final class Settings { } public static boolean isUseCompass() { - return 0 != sharedPrefs.getInt(KEY_USE_COMPASS, 1); + return sharedPrefs.getBoolean(KEY_USE_COMPASS, true); } public static void setUseCompass(final boolean useCompass) { @@ -794,13 +860,13 @@ public final class Settings { @Override public void edit(Editor edit) { - edit.putInt(KEY_USE_COMPASS, useCompass ? 1 : 0); + edit.putBoolean(KEY_USE_COMPASS, useCompass); } }); } public static boolean isHelpShown() { - return sharedPrefs.getInt(KEY_HELP_SHOWN, 0) != 0; + return sharedPrefs.getBoolean(KEY_HELP_SHOWN, false); } public static void setHelpShown() { @@ -808,13 +874,13 @@ public final class Settings { @Override public void edit(Editor edit) { - edit.putInt(KEY_HELP_SHOWN, 1); + edit.putBoolean(KEY_HELP_SHOWN, true); } }); } public static boolean isLightSkin() { - return sharedPrefs.getInt(KEY_SKIN, 0) != 0; + return sharedPrefs.getBoolean(KEY_SKIN, false); } public static void setLightSkin(final boolean lightSkin) { @@ -822,7 +888,7 @@ public final class Settings { @Override public void edit(Editor edit) { - edit.putInt(KEY_SKIN, lightSkin ? 1 : 0); + edit.putBoolean(KEY_SKIN, lightSkin); } }); } @@ -879,7 +945,7 @@ public final class Settings { } public static boolean isUseTwitter() { - return 0 != sharedPrefs.getInt(KEY_USE_TWITTER, 0); + return sharedPrefs.getBoolean(KEY_USE_TWITTER, false); } public static void setUseTwitter(final boolean useTwitter) { @@ -887,7 +953,7 @@ public final class Settings { @Override public void edit(Editor edit) { - edit.putInt(KEY_USE_TWITTER, useTwitter ? 1 : 0); + edit.putBoolean(KEY_USE_TWITTER, useTwitter); } }); } @@ -1037,7 +1103,7 @@ public final class Settings { } public static boolean getHideLiveMapHint() { - return sharedPrefs.getInt(KEY_HIDE_LIVE_MAP_HINT, 0) == 0 ? false : true; + return sharedPrefs.getBoolean(KEY_HIDE_LIVE_MAP_HINT, false); } public static void setHideLiveHint(final boolean hide) { @@ -1045,7 +1111,7 @@ public final class Settings { @Override public void edit(Editor edit) { - edit.putInt(KEY_HIDE_LIVE_MAP_HINT, hide ? 1 : 0); + edit.putBoolean(KEY_HIDE_LIVE_MAP_HINT, hide); } }); } @@ -1063,4 +1129,9 @@ public final class Settings { } }); } + + public static String getPreferencesName() { + // there is currently no Android API to get the file name of the shared preferences + return cgeoapplication.getInstance().getPackageName() + "_preferences"; + } } diff --git a/main/src/cgeo/geocaching/backup/CentralBackupAgent.java b/main/src/cgeo/geocaching/backup/CentralBackupAgent.java index 28b9e4b..aef2b7b 100644 --- a/main/src/cgeo/geocaching/backup/CentralBackupAgent.java +++ b/main/src/cgeo/geocaching/backup/CentralBackupAgent.java @@ -7,11 +7,11 @@ import android.app.backup.SharedPreferencesBackupHelper; public class CentralBackupAgent extends BackupAgentHelper { - static final String PREFS_BACKUP_KEY = "prefs"; + private static final String PREFS_BACKUP_KEY = "prefs"; @Override public void onCreate() { - SharedPreferencesBackupHelper helper = new SharedPreferencesBackupHelper(this, Settings.preferences); + final SharedPreferencesBackupHelper helper = new SharedPreferencesBackupHelper(this, Settings.getPreferencesName()); addHelper(PREFS_BACKUP_KEY, helper); } diff --git a/main/src/cgeo/geocaching/cgCache.java b/main/src/cgeo/geocaching/cgCache.java index 15f430c..36fd064 100644 --- a/main/src/cgeo/geocaching/cgCache.java +++ b/main/src/cgeo/geocaching/cgCache.java @@ -13,7 +13,6 @@ import cgeo.geocaching.enumerations.LoadFlags.RemoveFlag; import cgeo.geocaching.enumerations.LogType; import cgeo.geocaching.enumerations.WaypointType; import cgeo.geocaching.geopoint.Geopoint; -import cgeo.geocaching.geopoint.GeopointFormatter; import cgeo.geocaching.geopoint.GeopointParser; import cgeo.geocaching.utils.CancellableHandler; import cgeo.geocaching.utils.Log; @@ -309,7 +308,7 @@ public class cgCache implements ICache, IWaypoint { premiumMembersOnly == other.premiumMembersOnly && difficulty == other.difficulty && terrain == other.terrain && - (coords != null ? coords.isEqualTo(other.coords) : null == other.coords) && + (coords != null ? coords.equals(other.coords) : null == other.coords) && reliableLatLon == other.reliableLatLon && disabled == other.disabled && archived == other.archived && @@ -523,16 +522,6 @@ public class cgCache implements ICache, IWaypoint { } @Override - public String getLatitude() { - return coords != null ? coords.format(GeopointFormatter.Format.LAT_DECMINUTE) : null; - } - - @Override - public String getLongitude() { - return coords != null ? coords.format(GeopointFormatter.Format.LON_DECMINUTE) : null; - } - - @Override public String getOwner() { return owner; } diff --git a/main/src/cgeo/geocaching/cgData.java b/main/src/cgeo/geocaching/cgData.java index 413caf6..3bc9d00 100644 --- a/main/src/cgeo/geocaching/cgData.java +++ b/main/src/cgeo/geocaching/cgData.java @@ -1413,37 +1413,25 @@ public class cgData { /** * Persists the given <code>destination</code> into the database. * - * @param destinations - * @return <code>true</code> if the given destination was successfully - * persisted <code>false</code> otherwise. + * @param destination + * a destination to save */ - public boolean saveSearchedDestination(cgDestination destination) { - boolean success = true; - - if (destination == null) { - success = false; - } else { - init(); - - databaseRW.beginTransaction(); + public void saveSearchedDestination(final cgDestination destination) { + init(); - try { - ContentValues values = new ContentValues(); - values.put("date", destination.getDate()); - putCoords(values, destination.getCoords()); + databaseRW.beginTransaction(); - long id = databaseRW.insert(dbTableSearchDestionationHistory, null, values); - destination.setId(id); - databaseRW.setTransactionSuccessful(); - } catch (Exception e) { - success = false; - Log.e(Settings.tag, "Updating searchedDestinations db failed", e); - } finally { - databaseRW.endTransaction(); - } + try { + ContentValues values = new ContentValues(); + values.put("date", destination.getDate()); + putCoords(values, destination.getCoords()); + databaseRW.insert(dbTableSearchDestionationHistory, null, values); + databaseRW.setTransactionSuccessful(); + } catch (Exception e) { + Log.e(Settings.tag, "Updating searchedDestinations db failed", e); + } finally { + databaseRW.endTransaction(); } - - return success; } public boolean saveWaypoints(String geocode, List<cgWaypoint> waypoints, boolean drop) { @@ -1875,7 +1863,7 @@ public class cgData { * @param loadFlags * @return Set of loaded caches. Never null. */ - public Set<cgCache> loadCaches(final Set<String> geocodes, final Long centerLat, final Long centerLon, final Long spanLat, final Long spanLon, final EnumSet<LoadFlag> loadFlags) { + private Set<cgCache> loadCaches(final Set<String> geocodes, final Long centerLat, final Long centerLon, final Long spanLat, final Long spanLon, final EnumSet<LoadFlag> loadFlags) { final Set<cgCache> caches = new HashSet<cgCache>(); if (CollectionUtils.isEmpty(geocodes)) { return caches; @@ -2273,7 +2261,7 @@ public class cgData { return waypoint; } - public List<cgImage> loadSpoilers(String geocode) { + private List<cgImage> loadSpoilers(String geocode) { if (StringUtils.isBlank(geocode)) { return null; } @@ -2340,10 +2328,7 @@ public class cgData { int indexLongitude = cursor.getColumnIndex("longitude"); do { - final cgDestination dest = new cgDestination(); - dest.setId(cursor.getLong(indexId)); - dest.setDate(cursor.getLong(indexDate)); - dest.setCoords(getCoords(cursor, indexLatitude, indexLongitude)); + final cgDestination dest = new cgDestination(cursor.getLong(indexId), cursor.getLong(indexDate), getCoords(cursor, indexLatitude, indexLongitude)); // If coordinates are non-existent or invalid, do not consider // this point. @@ -2474,7 +2459,7 @@ public class cgData { return logCounts; } - public List<cgTrackable> loadInventory(String geocode) { + private List<cgTrackable> loadInventory(String geocode) { if (StringUtils.isBlank(geocode)) { return null; } diff --git a/main/src/cgeo/geocaching/cgDestination.java b/main/src/cgeo/geocaching/cgDestination.java index cf9a8ef..1e5253c 100644 --- a/main/src/cgeo/geocaching/cgDestination.java +++ b/main/src/cgeo/geocaching/cgDestination.java @@ -2,73 +2,43 @@ package cgeo.geocaching; import cgeo.geocaching.geopoint.Geopoint; -public class cgDestination { +public class cgDestination implements ICoordinates { - private long id; - - private long date; - - private Geopoint coords; - - public cgDestination() { - } + final private long id; + final private long date; + final private Geopoint coords; public cgDestination(long id, long date, final Geopoint coords) { - super(); this.id = id; this.date = date; this.coords = coords; } - public long getDate() { - return date; + public cgDestination withDate(final long date) { + return new cgDestination(id, date, coords); } - public void setDate(long date) { - this.date = date; + public long getDate() { + return date; } + @Override public Geopoint getCoords() { return coords; } - public void setCoords(final Geopoint coords) { - this.coords = coords; - } - @Override public int hashCode() { - final int prime = 31; - int result = 1; - long temp; - temp = Double.doubleToLongBits(coords.getLatitude()); - result = prime * result + (int) (temp ^ (temp >>> 32)); - temp = Double.doubleToLongBits(coords.getLongitude()); - result = prime * result + (int) (temp ^ (temp >>> 32)); - return result; + return coords.hashCode(); } @Override - public boolean equals(Object obj) { - if (this == obj) { - return true; - } - if (obj == null) { - return false; - } - if (!(obj instanceof cgDestination)) { - return false; - } - cgDestination other = (cgDestination) obj; - return coords.isEqualTo(other.coords); + public boolean equals(final Object obj) { + return obj != null && obj instanceof cgDestination && ((cgDestination) obj).coords.equals(coords); } public long getId() { return id; } - public void setId(long id) { - this.id = id; - } - } diff --git a/main/src/cgeo/geocaching/cgWaypoint.java b/main/src/cgeo/geocaching/cgWaypoint.java index d70e5ae..8f9ec85 100644 --- a/main/src/cgeo/geocaching/cgWaypoint.java +++ b/main/src/cgeo/geocaching/cgWaypoint.java @@ -223,14 +223,6 @@ public class cgWaypoint implements IWaypoint, Comparable<cgWaypoint> { this.note = note; } - public int getCachedOrder() { - return cachedOrder; - } - - public void setCachedOrder(int cachedOrder) { - this.cachedOrder = cachedOrder; - } - @Override public String toString() { return name + " " + waypointType.getL10n(); diff --git a/main/src/cgeo/geocaching/cgeoapplication.java b/main/src/cgeo/geocaching/cgeoapplication.java index 5b3284c..92c0005 100644 --- a/main/src/cgeo/geocaching/cgeoapplication.java +++ b/main/src/cgeo/geocaching/cgeoapplication.java @@ -351,8 +351,8 @@ public class cgeoapplication extends Application { } /** {@link cgData#saveSearchedDestination(cgDestination)} */ - public boolean saveSearchedDestination(cgDestination destination) { - return storage.saveSearchedDestination(destination); + public void saveSearchedDestination(cgDestination destination) { + storage.saveSearchedDestination(destination); } /** {@link cgData#saveWaypoints(String, List, boolean)} */ @@ -385,21 +385,11 @@ public class cgeoapplication extends Application { storage.dropList(listId); } - /** {@link cgData#loadInventory(String)} */ - public List<cgTrackable> loadInventory(String geocode) { - return storage.loadInventory(geocode); - } - /** {@link cgData#loadLogCounts(String)} */ public Map<LogType, Integer> loadLogCounts(String geocode) { return storage.loadLogCounts(geocode); } - /** {@link cgData#loadSpoilers(String)} */ - public List<cgImage> loadSpoilers(String geocode) { - return storage.loadSpoilers(geocode); - } - /** {@link cgData#loadWaypoint(int)} */ public cgWaypoint loadWaypoint(int id) { return storage.loadWaypoint(id); @@ -521,11 +511,6 @@ public class cgeoapplication extends Application { return storage.loadCaches(geocodes, loadFlags); } - /** {@link cgData#loadCaches} */ - public Set<cgCache> loadCaches(Long centerLat, Long centerLon, Long spanLat, Long spanLon, final EnumSet<LoadFlag> loadFlags) { - return storage.loadCaches(null, centerLat, centerLon, spanLat, spanLon, loadFlags); - } - /** {@link cgData#saveCache} */ public boolean saveCache(cgCache cache, EnumSet<LoadFlags.SaveFlag> saveFlags) { return storage.saveCache(cache, saveFlags); diff --git a/main/src/cgeo/geocaching/cgeopoint.java b/main/src/cgeo/geocaching/cgeopoint.java index d3e5fba..6242952 100644 --- a/main/src/cgeo/geocaching/cgeopoint.java +++ b/main/src/cgeo/geocaching/cgeopoint.java @@ -410,16 +410,14 @@ public class cgeopoint extends AbstractActivity { private void addToHistory(final Geopoint coords) { // Add locations to history - cgDestination loc = new cgDestination(); - loc.setCoords(coords); + final cgDestination loc = new cgDestination(0, 0, coords); - if (!getHistoryOfSearchedLocations().contains(loc)) - { - loc.setDate(System.currentTimeMillis()); - getHistoryOfSearchedLocations().add(0, loc); + if (!getHistoryOfSearchedLocations().contains(loc)) { + final cgDestination updatedLoc = loc.withDate(System.currentTimeMillis()); + getHistoryOfSearchedLocations().add(0, updatedLoc); // Save location - app.saveSearchedDestination(loc); + app.saveSearchedDestination(updatedLoc); // Ensure to remove the footer historyListView.removeFooterView(getEmptyHistoryFooter()); diff --git a/main/src/cgeo/geocaching/geopoint/Geopoint.java b/main/src/cgeo/geocaching/geopoint/Geopoint.java index ef08401..93d9c87 100644 --- a/main/src/cgeo/geocaching/geopoint/Geopoint.java +++ b/main/src/cgeo/geocaching/geopoint/Geopoint.java @@ -1,5 +1,6 @@ package cgeo.geocaching.geopoint; +import cgeo.geocaching.ICoordinates; import cgeo.geocaching.Settings; import cgeo.geocaching.geopoint.GeopointFormatter.Format; import cgeo.geocaching.network.Network; @@ -18,8 +19,7 @@ import java.math.RoundingMode; /** * Abstraction of geographic point. */ -public final class Geopoint -{ +public final class Geopoint implements ICoordinates { public static final double deg2rad = Math.PI / 180; public static final double rad2deg = 180 / Math.PI; public static final float erad = 6371.0f; @@ -114,7 +114,7 @@ public final class Geopoint */ public int getLatitudeE6() { - return (int) (latitude * 1E6); + return (int) Math.round(latitude * 1E6); } /** @@ -134,7 +134,7 @@ public final class Geopoint */ public int getLongitudeE6() { - return (int) (longitude * 1E6); + return (int) Math.round(longitude * 1E6); } /** @@ -200,16 +200,21 @@ public final class Geopoint return new Geopoint(rlat * rad2deg, rlon * rad2deg); } - /** - * Checks if given Geopoint is identical with this Geopoint. - * - * @param gp - * Geopoint to check - * @return true if identical, false otherwise - */ - public boolean isEqualTo(Geopoint gp) - { - return null != gp && gp.latitude == latitude && gp.longitude == longitude; + @Override + public boolean equals(final Object obj) { + if (this == obj) { + return true; + } + if (obj == null || !(obj instanceof Geopoint)) { + return false; + } + final Geopoint gp = (Geopoint) obj; + return getLatitudeE6() == gp.getLatitudeE6() && getLongitudeE6() == gp.getLongitudeE6(); + } + + @Override + public int hashCode() { + return getLatitudeE6() ^ getLongitudeE6(); } /** @@ -242,7 +247,7 @@ public final class Geopoint /** * Returns formatted coordinates with default format. * Default format is decimalminutes, e.g. N 52° 36.123 E 010° 03.456 - * + * * @return formatted coordinates */ @Override @@ -512,4 +517,9 @@ public final class Geopoint return null; } + @Override + public Geopoint getCoords() { + return this; + } + } |
