diff options
Diffstat (limited to 'main/src/cgeo/geocaching/settings')
11 files changed, 238 insertions, 179 deletions
diff --git a/main/src/cgeo/geocaching/settings/AbstractCheckCredentialsPreference.java b/main/src/cgeo/geocaching/settings/AbstractCheckCredentialsPreference.java index 917c9c4..2f83028 100644 --- a/main/src/cgeo/geocaching/settings/AbstractCheckCredentialsPreference.java +++ b/main/src/cgeo/geocaching/settings/AbstractCheckCredentialsPreference.java @@ -5,13 +5,15 @@ import cgeo.geocaching.activity.ActivityMixin; import cgeo.geocaching.enumerations.StatusCode; import cgeo.geocaching.network.Cookies; import cgeo.geocaching.ui.dialog.Dialogs; +import cgeo.geocaching.utils.RxUtils; import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.tuple.ImmutablePair; + +import rx.Observable; import rx.android.observables.AndroidObservable; import rx.functions.Action1; import rx.functions.Func0; -import rx.schedulers.Schedulers; import rx.util.async.Async; import android.app.ProgressDialog; @@ -38,55 +40,62 @@ public abstract class AbstractCheckCredentialsPreference extends AbstractClickab protected abstract ImmutablePair<String, String> getCredentials(); - protected abstract ImmutablePair<StatusCode, ? extends Drawable> login(); + /** + * Try to login. + * + * @return A pair containing the status code, and, if the status code is + * <tt>NO_ERROR</tt>, an observable (or <tt>null</tt>) wihch may emit + * the avatar for the user (every drawable will be shown in place of the previous one). + */ + protected abstract ImmutablePair<StatusCode, Observable<Drawable>> login(); private class LoginCheckClickListener implements OnPreferenceClickListener { - final private SettingsActivity activity; + final private SettingsActivity settingsActivity; LoginCheckClickListener(final SettingsActivity activity) { - this.activity = activity; + this.settingsActivity = activity; } @Override public boolean onPreferenceClick(Preference preference) { - final Resources res = activity.getResources(); + final Resources res = settingsActivity.getResources(); final ImmutablePair<String, String> credentials = getCredentials(); // check credentials for validity if (StringUtils.isBlank(credentials.getLeft()) || StringUtils.isBlank(credentials.getRight())) { - ActivityMixin.showToast(activity, R.string.err_missing_auth); + ActivityMixin.showToast(settingsActivity, R.string.err_missing_auth); return false; } - final ProgressDialog loginDialog = ProgressDialog.show(activity, + final ProgressDialog loginDialog = ProgressDialog.show(settingsActivity, res.getString(R.string.init_login_popup), res.getString(R.string.init_login_popup_working), true); loginDialog.setCancelable(false); Cookies.clearCookies(); - AndroidObservable.bindActivity(activity, Async.start(new Func0<ImmutablePair<StatusCode, ? extends Drawable>>() { + AndroidObservable.bindActivity(settingsActivity, Async.start(new Func0<ImmutablePair<StatusCode, Observable<Drawable>>>() { @Override - public ImmutablePair<StatusCode, ? extends Drawable> call() { + public ImmutablePair<StatusCode, Observable<Drawable>> call() { return login(); } - })).subscribe(new Action1<ImmutablePair<StatusCode, ? extends Drawable>>() { + })).subscribeOn(RxUtils.networkScheduler).subscribe(new Action1<ImmutablePair<StatusCode, Observable<Drawable>>>() { @Override - public void call(final ImmutablePair<StatusCode, ? extends Drawable> loginInfo) { + public void call(final ImmutablePair<StatusCode, Observable<Drawable>> loginInfo) { loginDialog.dismiss(); if (loginInfo.getLeft() == StatusCode.NO_ERROR) { - Dialogs.message(activity, R.string.init_login_popup, R.string.init_login_popup_ok, loginInfo.getRight()); + Dialogs.message(settingsActivity, R.string.init_login_popup, R.string.init_login_popup_ok, loginInfo.getRight()); } else { - Dialogs.message(activity, R.string.init_login_popup, + Dialogs.message(settingsActivity, R.string.init_login_popup, res.getString(R.string.init_login_popup_failed_reason) + " " + loginInfo.getLeft().getErrorString(res) + "." ); } - activity.initBasicMemberPreferences(); + settingsActivity.initBasicMemberPreferences(); } - }, Schedulers.io()); + }); return false; // no shared preference has to be changed } diff --git a/main/src/cgeo/geocaching/settings/CheckECCredentialsPreference.java b/main/src/cgeo/geocaching/settings/CheckECCredentialsPreference.java index c1cf740..f5d9ab5 100644 --- a/main/src/cgeo/geocaching/settings/CheckECCredentialsPreference.java +++ b/main/src/cgeo/geocaching/settings/CheckECCredentialsPreference.java @@ -6,6 +6,8 @@ import cgeo.geocaching.enumerations.StatusCode; import org.apache.commons.lang3.tuple.ImmutablePair; +import rx.Observable; + import android.content.Context; import android.graphics.drawable.Drawable; import android.util.AttributeSet; @@ -26,7 +28,7 @@ public class CheckECCredentialsPreference extends AbstractCheckCredentialsPrefer } @Override - protected ImmutablePair<StatusCode, Drawable> login() { - return new ImmutablePair<StatusCode, Drawable>(ECLogin.getInstance().login(), null); + protected ImmutablePair<StatusCode, Observable<Drawable>> login() { + return new ImmutablePair<>(ECLogin.getInstance().login(), null); } } diff --git a/main/src/cgeo/geocaching/settings/CheckGcCredentialsPreference.java b/main/src/cgeo/geocaching/settings/CheckGcCredentialsPreference.java index 2a05f47..0269f3b 100644 --- a/main/src/cgeo/geocaching/settings/CheckGcCredentialsPreference.java +++ b/main/src/cgeo/geocaching/settings/CheckGcCredentialsPreference.java @@ -5,6 +5,8 @@ import cgeo.geocaching.enumerations.StatusCode; import org.apache.commons.lang3.tuple.ImmutablePair; +import rx.Observable; + import android.content.Context; import android.graphics.drawable.Drawable; import android.util.AttributeSet; @@ -25,7 +27,7 @@ public class CheckGcCredentialsPreference extends AbstractCheckCredentialsPrefer } @Override - protected ImmutablePair<StatusCode, ? extends Drawable> login() { + protected ImmutablePair<StatusCode, Observable<Drawable>> login() { final StatusCode loginResult = GCLogin.getInstance().login(); switch (loginResult) { case NO_ERROR: diff --git a/main/src/cgeo/geocaching/settings/OAuthPreference.java b/main/src/cgeo/geocaching/settings/OAuthPreference.java index 54f8023..54bad6d 100644 --- a/main/src/cgeo/geocaching/settings/OAuthPreference.java +++ b/main/src/cgeo/geocaching/settings/OAuthPreference.java @@ -23,13 +23,14 @@ public class OAuthPreference extends AbstractClickablePreference { OCNL(R.string.pref_fakekey_ocnl_authorization, OCAuthorizationActivity.class, OCAuthParams.OC_NL_AUTH_PARAMS), OCUS(R.string.pref_fakekey_ocus_authorization, OCAuthorizationActivity.class, OCAuthParams.OC_US_AUTH_PARAMS), OCRO(R.string.pref_fakekey_ocro_authorization, OCAuthorizationActivity.class, OCAuthParams.OC_RO_AUTH_PARAMS), + OCUK(R.string.pref_fakekey_ocuk_authorization, OCAuthorizationActivity.class, OCAuthParams.OC_UK_AUTH_PARAMS), TWITTER(R.string.pref_fakekey_twitter_authorization, TwitterAuthorizationActivity.class, TwitterAuthorizationActivity.TWITTER_OAUTH_PARAMS); public final int prefKeyId; public final Class<?> authActivity; public final OAuthParameters authParams; - OAuthActivityMapping(int prefKeyId, Class<?> authActivity, OAuthParameters authParams) { + OAuthActivityMapping(final int prefKeyId, final Class<?> authActivity, final OAuthParameters authParams) { this.prefKeyId = prefKeyId; this.authActivity = authActivity; this.authParams = authParams; @@ -40,7 +41,7 @@ public class OAuthPreference extends AbstractClickablePreference { private OAuthActivityMapping getAuthorization() { final String prefKey = getKey(); - for (OAuthActivityMapping auth : OAuthActivityMapping.values()) { + for (final OAuthActivityMapping auth : OAuthActivityMapping.values()) { if (auth.prefKeyId != NO_KEY && prefKey.equals(CgeoApplication.getInstance().getString(auth.prefKeyId))) { return auth; } @@ -48,12 +49,12 @@ public class OAuthPreference extends AbstractClickablePreference { return OAuthActivityMapping.NONE; } - public OAuthPreference(Context context, AttributeSet attrs) { + public OAuthPreference(final Context context, final AttributeSet attrs) { super(context, attrs); this.oAuthMapping = getAuthorization(); } - public OAuthPreference(Context context, AttributeSet attrs, int defStyle) { + public OAuthPreference(final Context context, final AttributeSet attrs, final int defStyle) { super(context, attrs, defStyle); this.oAuthMapping = getAuthorization(); } @@ -63,9 +64,9 @@ public class OAuthPreference extends AbstractClickablePreference { activity.setAuthTitle(oAuthMapping.prefKeyId); return new OnPreferenceClickListener() { @Override - public boolean onPreferenceClick(Preference preference) { + public boolean onPreferenceClick(final Preference preference) { if (oAuthMapping.authActivity != null && oAuthMapping.authParams != null) { - Intent authIntent = new Intent(preference.getContext(), + final Intent authIntent = new Intent(preference.getContext(), oAuthMapping.authActivity); oAuthMapping.authParams.setOAuthExtras(authIntent); activity.startActivityForResult(authIntent, diff --git a/main/src/cgeo/geocaching/settings/OCPreferenceKeys.java b/main/src/cgeo/geocaching/settings/OCPreferenceKeys.java index e3c5aca..d8983e8 100644 --- a/main/src/cgeo/geocaching/settings/OCPreferenceKeys.java +++ b/main/src/cgeo/geocaching/settings/OCPreferenceKeys.java @@ -26,11 +26,14 @@ public enum OCPreferenceKeys { R.string.pref_ocnl_tokenpublic, R.string.pref_ocnl_tokensecret, OCAuthParams.OC_NL_AUTH_PARAMS), OC_RO("oc.ro", R.string.pref_connectorOCROActive, R.string.preference_screen_ocro, R.string.pref_fakekey_ocro_authorization, R.string.pref_fakekey_ocro_website, - R.string.pref_ocro_tokenpublic, R.string.pref_ocro_tokensecret, OCAuthParams.OC_RO_AUTH_PARAMS); + R.string.pref_ocro_tokenpublic, R.string.pref_ocro_tokensecret, OCAuthParams.OC_RO_AUTH_PARAMS), + OC_UK("oc.uk", R.string.pref_connectorOCUKActive, R.string.preference_screen_ocuk, + R.string.pref_fakekey_ocuk_authorization, R.string.pref_fakekey_ocuk_website, + R.string.pref_ocuk_tokenpublic, R.string.pref_ocuk_tokensecret, OCAuthParams.OC_UK_AUTH_PARAMS); - private OCPreferenceKeys(final String siteId, final int isActivePrefId, final int prefScreenId, final int authPrefId, - final int websitePrefId, final int publicTokenPrefId, final int privateTokenPrefId, final OCAuthParams authParams) { + OCPreferenceKeys(final String siteId, final int isActivePrefId, final int prefScreenId, final int authPrefId, + final int websitePrefId, final int publicTokenPrefId, final int privateTokenPrefId, final OCAuthParams authParams) { this.siteId = siteId; this.isActivePrefId = isActivePrefId; this.prefScreenId = prefScreenId; @@ -46,10 +49,10 @@ public enum OCPreferenceKeys { private static final SparseArray<OCPreferenceKeys> FIND_BY_AUTH_PREF_ID; static { - FIND_BY_ISACTIVE_ID = new SparseArray<OCPreferenceKeys>(values().length); - FIND_BY_AUTH_PREF_ID = new SparseArray<OCPreferenceKeys>(values().length); - Map<String, OCPreferenceKeys> byIsactiveKey = new HashMap<String, OCPreferenceKeys>(); - for (OCPreferenceKeys key : values()) { + FIND_BY_ISACTIVE_ID = new SparseArray<>(values().length); + FIND_BY_AUTH_PREF_ID = new SparseArray<>(values().length); + final Map<String, OCPreferenceKeys> byIsactiveKey = new HashMap<>(); + for (final OCPreferenceKeys key : values()) { FIND_BY_ISACTIVE_ID.put(key.isActivePrefId, key); FIND_BY_AUTH_PREF_ID.put(key.authPrefId, key); byIsactiveKey.put(CgeoApplication.getInstance().getString(key.isActivePrefId), key); diff --git a/main/src/cgeo/geocaching/settings/RegisterSend2CgeoPreference.java b/main/src/cgeo/geocaching/settings/RegisterSend2CgeoPreference.java index cc2de9f..84c343a 100644 --- a/main/src/cgeo/geocaching/settings/RegisterSend2CgeoPreference.java +++ b/main/src/cgeo/geocaching/settings/RegisterSend2CgeoPreference.java @@ -6,14 +6,16 @@ import cgeo.geocaching.network.Network; import cgeo.geocaching.network.Parameters; import cgeo.geocaching.ui.dialog.Dialogs; import cgeo.geocaching.utils.Log; +import cgeo.geocaching.utils.RxUtils; import ch.boye.httpclientandroidlib.HttpResponse; + import org.apache.commons.lang3.StringUtils; + import rx.Observable; import rx.android.observables.AndroidObservable; import rx.functions.Action1; import rx.functions.Func0; -import rx.schedulers.Schedulers; import android.app.ProgressDialog; import android.content.Context; @@ -75,7 +77,7 @@ public class RegisterSend2CgeoPreference extends AbstractClickablePreference { return Observable.empty(); } - }).firstOrDefault(0)).subscribe(new Action1<Integer>() { + }).firstOrDefault(0)).subscribeOn(RxUtils.networkScheduler).subscribe(new Action1<Integer>() { @Override public void call(final Integer pin) { progressDialog.dismiss(); @@ -87,7 +89,7 @@ public class RegisterSend2CgeoPreference extends AbstractClickablePreference { Dialogs.message(activity, R.string.init_sendToCgeo, R.string.init_sendToCgeo_register_fail); } } - }, Schedulers.io()); + }); return true; } diff --git a/main/src/cgeo/geocaching/settings/Settings.java b/main/src/cgeo/geocaching/settings/Settings.java index 7a4dfdd..01ebd6f 100644 --- a/main/src/cgeo/geocaching/settings/Settings.java +++ b/main/src/cgeo/geocaching/settings/Settings.java @@ -13,7 +13,7 @@ import cgeo.geocaching.enumerations.LogType; import cgeo.geocaching.geopoint.Geopoint; import cgeo.geocaching.list.StoredList; import cgeo.geocaching.maps.MapProviderFactory; -import cgeo.geocaching.maps.google.GoogleMapProvider; +import cgeo.geocaching.maps.google.v1.GoogleMapProvider; import cgeo.geocaching.maps.interfaces.GeoPointImpl; import cgeo.geocaching.maps.interfaces.MapProvider; import cgeo.geocaching.maps.interfaces.MapSource; @@ -39,6 +39,7 @@ import android.preference.PreferenceManager; import java.io.File; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; import java.util.Locale; @@ -47,6 +48,7 @@ import java.util.Locale; */ public class Settings { + private static final char HISTORY_SEPARATOR = ','; public static final int SHOW_WP_THRESHOLD_DEFAULT = 10; public static final int SHOW_WP_THRESHOLD_MAX = 50; private static final int MAP_SOURCE_DEFAULT = GoogleMapProvider.GOOGLE_MAP_ID.hashCode(); @@ -63,7 +65,7 @@ public class Settings { Min, Sec; - public static CoordInputFormatEnum fromInt(int id) { + public static CoordInputFormatEnum fromInt(final int id) { final CoordInputFormatEnum[] values = CoordInputFormatEnum.values(); if (id < 0 || id >= values.length) { return Min; @@ -76,7 +78,9 @@ public class Settings { .getDefaultSharedPreferences(CgeoApplication.getInstance().getBaseContext()); static { migrateSettings(); - Log.setDebug(sharedPrefs.getBoolean(getKey(R.string.pref_debug), false)); + final boolean isDebug = sharedPrefs.getBoolean(getKey(R.string.pref_debug), false); + Log.setDebug(isDebug); + CgeoApplication.dumpOnOutOfMemory(isDebug); } /** @@ -91,7 +95,7 @@ public class Settings { private static void migrateSettings() { // migrate from non standard file location and integer based boolean types - int oldVersion = getInt(R.string.pref_settingsversion, 0); + final int oldVersion = getInt(R.string.pref_settingsversion, 0); if (oldVersion < 1) { final String oldPreferencesName = "cgeo.pref"; final SharedPreferences old = CgeoApplication.getInstance().getSharedPreferences(oldPreferencesName, Context.MODE_PRIVATE); @@ -173,13 +177,13 @@ public class Settings { e.putInt(getKey(R.string.pref_showwaypointsthreshold), wpThreshold); // KEY_MAP_SOURCE must be string, because it is the key for a ListPreference now - int ms = sharedPrefs.getInt(getKey(R.string.pref_mapsource), MAP_SOURCE_DEFAULT); + final int ms = sharedPrefs.getInt(getKey(R.string.pref_mapsource), MAP_SOURCE_DEFAULT); e.remove(getKey(R.string.pref_mapsource)); e.putString(getKey(R.string.pref_mapsource), String.valueOf(ms)); // navigation tool ids must be string, because ListPreference uses strings as keys - int dnt1 = sharedPrefs.getInt(getKey(R.string.pref_defaultNavigationTool), NavigationAppsEnum.COMPASS.id); - int dnt2 = sharedPrefs.getInt(getKey(R.string.pref_defaultNavigationTool2), NavigationAppsEnum.INTERNAL_MAP.id); + final int dnt1 = sharedPrefs.getInt(getKey(R.string.pref_defaultNavigationTool), NavigationAppsEnum.COMPASS.id); + final int dnt2 = sharedPrefs.getInt(getKey(R.string.pref_defaultNavigationTool2), NavigationAppsEnum.INTERNAL_MAP.id); e.remove(getKey(R.string.pref_defaultNavigationTool)); e.remove(getKey(R.string.pref_defaultNavigationTool2)); e.putString(getKey(R.string.pref_defaultNavigationTool), String.valueOf(dnt1)); @@ -258,7 +262,7 @@ public class Settings { return sharedPrefs.contains(getKey(prefKeyId)); } - public static void setLanguage(boolean useEnglish) { + public static void setLanguage(final boolean useEnglish) { final Configuration config = new Configuration(); config.locale = useEnglish ? Locale.ENGLISH : Locale.getDefault(); final Resources resources = CgeoApplication.getInstance().getResources(); @@ -291,10 +295,10 @@ public class Settings { final String password = getString(connector.getPasswordPreferenceKey(), null); if (StringUtils.isBlank(username) || StringUtils.isBlank(password)) { - return new ImmutablePair<String, String>(StringUtils.EMPTY, StringUtils.EMPTY); + return new ImmutablePair<>(StringUtils.EMPTY, StringUtils.EMPTY); } - return new ImmutablePair<String, String>(username, password); + return new ImmutablePair<>(username, password); } public static String getUsername() { @@ -330,7 +334,7 @@ public class Settings { } public static ImmutablePair<String, String> getTokenPair(final int tokenPublicPrefKey, final int tokenSecretPrefKey) { - return new ImmutablePair<String, String>(getString(tokenPublicPrefKey, null), getString(tokenSecretPrefKey, null)); + return new ImmutablePair<>(getString(tokenPublicPrefKey, null), getString(tokenSecretPrefKey, null)); } public static void setTokens(final int tokenPublicPrefKey, @Nullable final String tokenPublic, final int tokenSecretPrefKey, @Nullable final String tokenSecret) { @@ -346,11 +350,11 @@ public class Settings { } } - public static boolean isOCConnectorActive(int isActivePrefKeyId) { + public static boolean isOCConnectorActive(final int isActivePrefKeyId) { return getBoolean(isActivePrefKeyId, false); } - public static boolean hasOCAuthorization(int tokenPublicPrefKeyId, int tokenSecretPrefKeyId) { + public static boolean hasOCAuthorization(final int tokenPublicPrefKeyId, final int tokenSecretPrefKeyId) { return StringUtils.isNotBlank(getString(tokenPublicPrefKeyId, "")) && StringUtils.isNotBlank(getString(tokenSecretPrefKeyId, "")); } @@ -370,11 +374,11 @@ public class Settings { return null; } - return new ImmutablePair<String, String>(username, password); + return new ImmutablePair<>(username, password); } public static String getSignature() { - return getString(R.string.pref_signature, null); + return getString(R.string.pref_signature, StringUtils.EMPTY); } public static boolean setCookieStore(final String cookies) { @@ -424,7 +428,7 @@ public class Settings { } public static boolean setMapFile(final String mapFile) { - boolean result = putString(R.string.pref_mapfile, mapFile); + final boolean result = putString(R.string.pref_mapfile, mapFile); if (mapFile != null) { setMapFileDirectory(new File(mapFile).getParent()); } @@ -444,7 +448,7 @@ public class Settings { } public static boolean setMapFileDirectory(final String mapFileDirectory) { - boolean result = putString(R.string.pref_mapDirectory, mapFileDirectory); + final boolean result = putString(R.string.pref_mapDirectory, mapFileDirectory); MapsforgeMapProvider.getInstance().updateOfflineMaps(); return result; } @@ -624,6 +628,7 @@ public class Settings { private final static int MAPNIK = 1; private final static int CYCLEMAP = 3; private final static int OFFLINE = 4; + private static final int HISTORY_SIZE = 10; /** * convert old preference ids for maps (based on constant values) into new hash based ids @@ -676,8 +681,8 @@ public class Settings { public static Geopoint getAnyCoordinates() { if (contains(R.string.pref_anylatitude) && contains(R.string.pref_anylongitude)) { - float lat = getFloat(R.string.pref_anylatitude, 0); - float lon = getFloat(R.string.pref_anylongitude, 0); + final float lat = getFloat(R.string.pref_anylatitude, 0); + final float lon = getFloat(R.string.pref_anylongitude, 0); return new Geopoint(lat, lon); } return null; @@ -709,6 +714,10 @@ public class Settings { return getString(R.string.pref_webDeviceCode, null); } + public static boolean isRegisteredForSend2cgeo() { + return getWebDeviceCode() != null; + } + public static String getWebDeviceName() { return getString(R.string.pref_webDeviceName, android.os.Build.MODEL); } @@ -760,7 +769,7 @@ public class Settings { } public static void setTwitterTokens(@Nullable final String tokenPublic, - @Nullable final String tokenSecret, boolean enableTwitter) { + @Nullable final String tokenSecret, final boolean enableTwitter) { putString(R.string.pref_twitter_token_public, tokenPublic); putString(R.string.pref_twitter_token_secret, tokenSecret); if (tokenPublic != null) { @@ -777,9 +786,9 @@ public class Settings { } public static ImmutablePair<String, String> getTempToken() { - String tokenPublic = getString(R.string.pref_temp_twitter_token_public, null); - String tokenSecret = getString(R.string.pref_temp_twitter_token_secret, null); - return new ImmutablePair<String, String>(tokenPublic, tokenSecret); + final String tokenPublic = getString(R.string.pref_temp_twitter_token_public, null); + final String tokenSecret = getString(R.string.pref_temp_twitter_token_secret, null); + return new ImmutablePair<>(tokenPublic, tokenSecret); } public static int getVersion() { @@ -889,8 +898,8 @@ public class Settings { } public static File[] getMapThemeFiles() { - File directory = new File(Settings.getCustomRenderThemeBaseFolder()); - List<File> result = new ArrayList<File>(); + final File directory = new File(Settings.getCustomRenderThemeBaseFolder()); + final List<File> result = new ArrayList<>(); FileUtils.listDir(result, directory, new ExtensionsBasedFileSelector(new String[] { "xml" }), null); return result.toArray(new File[result.size()]); @@ -898,13 +907,13 @@ public class Settings { private static class ExtensionsBasedFileSelector extends FileSelector { private final String[] extensions; - public ExtensionsBasedFileSelector(String[] extensions) { + public ExtensionsBasedFileSelector(final String[] extensions) { this.extensions = extensions; } @Override - public boolean isSelected(File file) { - String filename = file.getName(); - for (String ext : extensions) { + public boolean isSelected(final File file) { + final String filename = file.getName(); + for (final String ext : extensions) { if (StringUtils.endsWithIgnoreCase(filename, ext)) { return true; } @@ -970,7 +979,7 @@ public class Settings { putLong(R.string.pref_fieldNoteExportDate, date); } - public static boolean isUseNavigationApp(NavigationAppsEnum navApp) { + public static boolean isUseNavigationApp(final NavigationAppsEnum navApp) { return getBoolean(navApp.preferenceKey, true); } @@ -979,7 +988,7 @@ public class Settings { * * @param upload */ - public static void setFieldNoteExportUpload(boolean upload) { + public static void setFieldNoteExportUpload(final boolean upload) { putBoolean(R.string.pref_fieldNoteExportUpload, upload); } @@ -992,7 +1001,7 @@ public class Settings { * * @param onlyNew */ - public static void setFieldNoteExportOnlyNew(boolean onlyNew) { + public static void setFieldNoteExportOnlyNew(final boolean onlyNew) { putBoolean(R.string.pref_fieldNoteExportOnlyNew, onlyNew); } @@ -1004,4 +1013,25 @@ public class Settings { return getString(R.string.pref_ec_icons, "1"); } + /* Store last checksum of changelog for changelog display */ + public static long getLastChangelogChecksum() { + return getLong(R.string.pref_changelog_last_checksum, 0); + } + + public static void setLastChangelogChecksum(final long checksum) { + putLong(R.string.pref_changelog_last_checksum, checksum); + } + + public static List<String> getLastOpenedCaches() { + final List<String> history = Arrays.asList(StringUtils.split(getString(R.string.pref_caches_history, StringUtils.EMPTY), HISTORY_SEPARATOR)); + return history.subList(0, Math.min(HISTORY_SIZE, history.size())); + } + + public static void addCacheToHistory(@NonNull final String geocode) { + final ArrayList<String> history = new ArrayList<>(getLastOpenedCaches()); + // bring entry to front, if it already existed + history.remove(geocode); + history.add(0, geocode); + putString(R.string.pref_caches_history, StringUtils.join(history, HISTORY_SEPARATOR)); + } } diff --git a/main/src/cgeo/geocaching/settings/SettingsActivity.java b/main/src/cgeo/geocaching/settings/SettingsActivity.java index dc1a39d..bf73370 100644 --- a/main/src/cgeo/geocaching/settings/SettingsActivity.java +++ b/main/src/cgeo/geocaching/settings/SettingsActivity.java @@ -9,11 +9,11 @@ import cgeo.geocaching.activity.ActivityMixin; import cgeo.geocaching.apps.cache.navi.NavigationAppFactory; import cgeo.geocaching.apps.cache.navi.NavigationAppFactory.NavigationAppsEnum; import cgeo.geocaching.connector.gc.GCConnector; -import cgeo.geocaching.connector.gc.GCLogin; import cgeo.geocaching.files.SimpleDirChooser; import cgeo.geocaching.maps.MapProviderFactory; import cgeo.geocaching.maps.interfaces.MapSource; import cgeo.geocaching.utils.DatabaseBackupUtils; +import cgeo.geocaching.utils.DebugUtils; import cgeo.geocaching.utils.Log; import org.apache.commons.lang3.StringUtils; @@ -90,21 +90,21 @@ public class SettingsActivity extends PreferenceActivity { SettingsActivity.addPreferencesFromResource(this, R.xml.preferences); initPreferences(); - Intent intent = getIntent(); + final Intent intent = getIntent(); openInitialScreen(intent.getIntExtra(INTENT_OPEN_SCREEN, 0)); } - private void openInitialScreen(int initialScreen) { + private void openInitialScreen(final int initialScreen) { if (initialScreen == 0) { return; } - PreferenceScreen screen = (PreferenceScreen) getPreference(initialScreen); + final PreferenceScreen screen = (PreferenceScreen) getPreference(initialScreen); if (screen == null) { return; } try { setPreferenceScreen(screen); - } catch (RuntimeException e) { + } catch (final RuntimeException e) { Log.e("could not open preferences " + initialScreen, e); } } @@ -129,7 +129,7 @@ public class SettingsActivity extends PreferenceActivity { initNavigationMenuPreferences(); initMaintenanceButtons(); - for (int k : new int[] { R.string.pref_username, R.string.pref_password, + for (final int k : new int[] { R.string.pref_username, R.string.pref_password, R.string.pref_pass_vote, R.string.pref_signature, R.string.pref_mapsource, R.string.pref_renderthemepath, R.string.pref_gpxExportDir, R.string.pref_gpxImportDir, @@ -143,7 +143,7 @@ public class SettingsActivity extends PreferenceActivity { } private void initNavigationMenuPreferences() { - for (NavigationAppsEnum appEnum : NavigationAppsEnum.values()) { + for (final NavigationAppsEnum appEnum : NavigationAppsEnum.values()) { if (appEnum.app.isInstalled()) { getPreference(appEnum.preferenceKey).setEnabled(true); } @@ -154,26 +154,33 @@ public class SettingsActivity extends PreferenceActivity { } private void initServicePreferences() { - for (OCPreferenceKeys key : OCPreferenceKeys.values()) { + for (final OCPreferenceKeys key : OCPreferenceKeys.values()) { getPreference(key.isActivePrefId).setOnPreferenceChangeListener(VALUE_CHANGE_LISTENER); setWebsite(key.websitePrefId, key.authParams.host); - setServiceScreenSummary(getPreferenceManager(), key.isActivePrefId); + getPreference(key.prefScreenId).setSummary(getServiceSummary(Settings.isOCConnectorActive(key.isActivePrefId))); } getPreference(R.string.pref_connectorGCActive).setOnPreferenceChangeListener(VALUE_CHANGE_LISTENER); - getPreference(R.string.pref_connectorOXActive).setOnPreferenceChangeListener(VALUE_CHANGE_LISTENER); - getPreference(R.string.pref_connectorECActive).setOnPreferenceChangeListener(VALUE_CHANGE_LISTENER); setWebsite(R.string.pref_fakekey_gc_website, GCConnector.getInstance().getHost()); + getPreference(R.string.preference_screen_gc).setSummary(getServiceSummary(Settings.isGCConnectorActive())); + + getPreference(R.string.pref_connectorOXActive).setOnPreferenceChangeListener(VALUE_CHANGE_LISTENER); setWebsite(R.string.pref_fakekey_ox_website, "opencaching.com"); + getPreference(R.string.preference_screen_ox).setSummary(getServiceSummary(Settings.isOXConnectorActive())); + + getPreference(R.string.pref_connectorECActive).setOnPreferenceChangeListener(VALUE_CHANGE_LISTENER); setWebsite(R.string.pref_fakekey_ec_website, "extremcaching.com"); + getPreference(R.string.preference_screen_ec).setSummary(getServiceSummary(Settings.isECConnectorActive())); + + getPreference(R.string.pref_ratingwanted).setOnPreferenceChangeListener(VALUE_CHANGE_LISTENER); setWebsite(R.string.pref_fakekey_gcvote_website, "gcvote.com"); + getPreference(R.string.preference_screen_gcvote).setSummary(getServiceSummary(Settings.isRatingWanted())); + setWebsite(R.string.pref_fakekey_sendtocgeo_website, "send2.cgeo.org"); - setServiceScreenSummary(getPreferenceManager(), R.string.pref_connectorGCActive); - setServiceScreenSummary(getPreferenceManager(), R.string.pref_connectorOXActive); - setServiceScreenSummary(getPreferenceManager(), R.string.pref_connectorECActive); + getPreference(R.string.preference_screen_sendtocgeo).setSummary(getServiceSummary(Settings.isRegisteredForSend2cgeo())); } private void setWebsite(final int preferenceKey, final String host) { - Preference preference = getPreference(preferenceKey); + final Preference preference = getPreference(preferenceKey); preference.setOnPreferenceClickListener(new OnPreferenceClickListener() { @Override public boolean onPreferenceClick(final Preference preference) { @@ -183,36 +190,10 @@ public class SettingsActivity extends PreferenceActivity { }); } - private static String getServiceSummary(boolean status) { + private static String getServiceSummary(final boolean status) { return status ? CgeoApplication.getInstance().getString(R.string.settings_service_active) : StringUtils.EMPTY; } - private static void setServiceScreenSummary(PreferenceManager preferenceManager, final int preferenceKey) { - - String summary = StringUtils.EMPTY; - - switch (preferenceKey) { - case R.string.pref_connectorGCActive: - summary = getServiceSummary(Settings.isGCConnectorActive()); - preferenceManager.findPreference(getKey(R.string.preference_screen_gc)).setSummary(summary); - break; - case R.string.pref_connectorOXActive: - summary = getServiceSummary(Settings.isOXConnectorActive()); - preferenceManager.findPreference(getKey(R.string.preference_screen_ox)).setSummary(summary); - break; - case R.string.pref_connectorECActive: - summary = getServiceSummary(Settings.isECConnectorActive()); - preferenceManager.findPreference(getKey(R.string.preference_screen_ec)).setSummary(summary); - break; - default: - if (OCPreferenceKeys.isOCPreference(preferenceKey)) { - OCPreferenceKeys prefKey = OCPreferenceKeys.getById(preferenceKey); - summary = getServiceSummary(Settings.isOCConnectorActive(prefKey.isActivePrefId)); - preferenceManager.findPreference(getKey(prefKey.prefScreenId)).setSummary(summary); - } - } - } - private static String getKey(final int prefKeyId) { return CgeoApplication.getInstance().getString(prefKeyId); } @@ -225,11 +206,11 @@ public class SettingsActivity extends PreferenceActivity { * Fill the choice list for map sources. */ private void initMapSourcePreference() { - ListPreference pref = (ListPreference) getPreference(R.string.pref_mapsource); + final ListPreference pref = (ListPreference) getPreference(R.string.pref_mapsource); - List<MapSource> mapSources = MapProviderFactory.getMapSources(); - CharSequence[] entries = new CharSequence[mapSources.size()]; - CharSequence[] values = new CharSequence[mapSources.size()]; + final List<MapSource> mapSources = MapProviderFactory.getMapSources(); + final CharSequence[] entries = new CharSequence[mapSources.size()]; + final CharSequence[] values = new CharSequence[mapSources.size()]; for (int i = 0; i < mapSources.size(); ++i) { entries[i] = mapSources.get(i).getName(); values[i] = String.valueOf(mapSources.get(i).getNumericalId()); @@ -245,8 +226,8 @@ public class SettingsActivity extends PreferenceActivity { final List<NavigationAppsEnum> apps = NavigationAppFactory.getInstalledDefaultNavigationApps(); - CharSequence[] entries = new CharSequence[apps.size()]; - CharSequence[] values = new CharSequence[apps.size()]; + final CharSequence[] entries = new CharSequence[apps.size()]; + final CharSequence[] values = new CharSequence[apps.size()]; for (int i = 0; i < apps.size(); ++i) { entries[i] = apps.get(i).toString(); values[i] = String.valueOf(apps.get(i).id); @@ -277,7 +258,7 @@ public class SettingsActivity extends PreferenceActivity { new OnPreferenceClickListener() { @Override public boolean onPreferenceClick(final Preference preference) { - Intent i = new Intent(SettingsActivity.this, + final Intent i = new Intent(SettingsActivity.this, SelectMapfileActivity.class); startActivityForResult(i, R.string.pref_mapDirectory); return false; @@ -307,7 +288,7 @@ public class SettingsActivity extends PreferenceActivity { dirChooser.putExtra(FileManagerIntents.EXTRA_BUTTON_TEXT, getString(android.R.string.ok)); startActivityForResult(dirChooser, dct.requestCode); - } catch (android.content.ActivityNotFoundException ex) { + } catch (final android.content.ActivityNotFoundException ex) { // OI file manager not available final Intent dirChooser = new Intent(this, SimpleDirChooser.class); dirChooser.putExtra(Intents.EXTRA_START_DIR, startDirectory); @@ -319,7 +300,7 @@ public class SettingsActivity extends PreferenceActivity { private void setChosenDirectory(final DirChooserType dct, final Intent data) { final String directory = new File(data.getData().getPath()).getAbsolutePath(); if (StringUtils.isNotBlank(directory)) { - Preference p = getPreference(dct.keyId); + final Preference p = getPreference(dct.keyId); if (p == null) { return; } @@ -329,7 +310,7 @@ public class SettingsActivity extends PreferenceActivity { } public void initBackupButtons() { - Preference backup = getPreference(R.string.pref_fakekey_preference_backup); + final Preference backup = getPreference(R.string.pref_fakekey_preference_backup); backup.setOnPreferenceClickListener(new OnPreferenceClickListener() { @Override public boolean onPreferenceClick(final Preference preference) { @@ -343,7 +324,7 @@ public class SettingsActivity extends PreferenceActivity { } }); - Preference restore = getPreference(R.string.pref_fakekey_preference_restore); + final Preference restore = getPreference(R.string.pref_fakekey_preference_restore); restore.setOnPreferenceClickListener(new OnPreferenceClickListener() { @Override public boolean onPreferenceClick(final Preference preference) { @@ -354,14 +335,14 @@ public class SettingsActivity extends PreferenceActivity { } public void initMaintenanceButtons() { - Preference dirMaintenance = getPreference(R.string.pref_fakekey_preference_maintenance_directories); + final Preference dirMaintenance = getPreference(R.string.pref_fakekey_preference_maintenance_directories); dirMaintenance.setOnPreferenceClickListener(new OnPreferenceClickListener() { @Override public boolean onPreferenceClick(final Preference preference) { // disable the button, as the cleanup runs in background and should not be invoked a second time preference.setEnabled(false); - Resources res = getResources(); + final Resources res = getResources(); final SettingsActivity activity = SettingsActivity.this; final ProgressDialog dialog = ProgressDialog.show(activity, res.getString(R.string.init_maintenance), res.getString(R.string.init_maintenance_directories), true, false); new Thread() { @@ -380,10 +361,19 @@ public class SettingsActivity extends PreferenceActivity { return true; } }); + final Preference memoryDumpPref = getPreference(R.string.pref_memory_dump); + memoryDumpPref + .setOnPreferenceClickListener(new OnPreferenceClickListener() { + @Override public boolean onPreferenceClick( + final Preference preference) { + DebugUtils.createMemoryDump(SettingsActivity.this); + return true; + } + }); } private void initDbLocationPreference() { - Preference p = getPreference(R.string.pref_dbonsdcard); + final Preference p = getPreference(R.string.pref_dbonsdcard); p.setPersistent(false); p.setOnPreferenceClickListener(new OnPreferenceClickListener() { @Override @@ -396,11 +386,13 @@ public class SettingsActivity extends PreferenceActivity { } private void initDebugPreference() { - Preference p = getPreference(R.string.pref_debug); + final Preference p = getPreference(R.string.pref_debug); p.setOnPreferenceChangeListener(new OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(final Preference preference, final Object newValue) { - Log.setDebug((Boolean) newValue); + final boolean isDebug = (Boolean) newValue; + Log.setDebug(isDebug); + CgeoApplication.dumpOnOutOfMemory(isDebug); return true; } }); @@ -434,7 +426,7 @@ public class SettingsActivity extends PreferenceActivity { return; } final PreferenceScreen screen = (PreferenceScreen) preference; - ListAdapter adapter = screen.getRootAdapter(); + final ListAdapter adapter = screen.getRootAdapter(); if (adapter instanceof BaseAdapter) { ((BaseAdapter) adapter).notifyDataSetChanged(); } @@ -444,13 +436,14 @@ public class SettingsActivity extends PreferenceActivity { Settings.putString(R.string.pref_webDeviceName, Settings.getWebDeviceName()); } - public void setAuthTitle(int prefKeyId) { + public void setAuthTitle(final int prefKeyId) { switch (prefKeyId) { case R.string.pref_fakekey_ocde_authorization: case R.string.pref_fakekey_ocpl_authorization: case R.string.pref_fakekey_ocnl_authorization: case R.string.pref_fakekey_ocus_authorization: case R.string.pref_fakekey_ocro_authorization: + case R.string.pref_fakekey_ocuk_authorization: setOCAuthTitle(OCPreferenceKeys.getByAuthId(prefKeyId)); break; case R.string.pref_fakekey_twitter_authorization: @@ -490,7 +483,7 @@ public class SettingsActivity extends PreferenceActivity { return; } - for (DirChooserType dct : DirChooserType.values()) { + for (final DirChooserType dct : DirChooserType.values()) { if (requestCode == dct.requestCode) { setChosenDirectory(dct, data); return; @@ -501,7 +494,7 @@ public class SettingsActivity extends PreferenceActivity { case R.string.pref_mapDirectory: if (data.hasExtra(Intents.EXTRA_MAP_FILE)) { final String mapFile = data.getStringExtra(Intents.EXTRA_MAP_FILE); - File file = new File(mapFile); + final File file = new File(mapFile); if (!file.isDirectory()) { Settings.setMapFile(mapFile); if (!Settings.isValidMapFile(Settings.getMapFile())) { @@ -509,8 +502,8 @@ public class SettingsActivity extends PreferenceActivity { } else { // Ensure map source preference is updated accordingly. // TODO: There should be a better way to find and select the map source for a map file - Integer mapSourceId = mapFile.hashCode(); - ListPreference mapSource = (ListPreference) getPreference(R.string.pref_mapsource); + final Integer mapSourceId = mapFile.hashCode(); + final ListPreference mapSource = (ListPreference) getPreference(R.string.pref_mapsource); mapSource.setValue(mapSourceId.toString()); VALUE_CHANGE_LISTENER.onPreferenceChange(mapSource, mapSourceId); } @@ -526,7 +519,8 @@ public class SettingsActivity extends PreferenceActivity { case R.string.pref_fakekey_ocnl_authorization: case R.string.pref_fakekey_ocus_authorization: case R.string.pref_fakekey_ocro_authorization: - OCPreferenceKeys key = OCPreferenceKeys.getByAuthId(requestCode); + case R.string.pref_fakekey_ocuk_authorization: + final OCPreferenceKeys key = OCPreferenceKeys.getByAuthId(requestCode); if (key != null) { setOCAuthTitle(key); redrawScreen(key.prefScreenId); @@ -546,9 +540,13 @@ public class SettingsActivity extends PreferenceActivity { * to reflect its new value. */ private static final Preference.OnPreferenceChangeListener VALUE_CHANGE_LISTENER = new Preference.OnPreferenceChangeListener() { + + private PreferenceManager preferenceManager; + @Override public boolean onPreferenceChange(final Preference preference, final Object value) { - String stringValue = value.toString(); + preferenceManager = preference.getPreferenceManager(); + final String stringValue = value.toString(); if (isPreference(preference, R.string.pref_mapsource)) { // reset the cached map source @@ -578,14 +576,15 @@ public class SettingsActivity extends PreferenceActivity { || isPreference(preference, R.string.pref_connectorOCNLActive) || isPreference(preference, R.string.pref_connectorOCUSActive) || isPreference(preference, R.string.pref_connectorOCROActive) + || isPreference(preference, R.string.pref_connectorOCUKActive) || isPreference(preference, R.string.pref_connectorGCActive) || isPreference(preference, R.string.pref_connectorOXActive) || isPreference(preference, R.string.pref_connectorECActive)) { // update summary - boolean boolVal = ((Boolean) value).booleanValue(); - String summary = getServiceSummary(boolVal); + final boolean boolVal = (Boolean) value; + final String summary = getServiceSummary(boolVal); if (OCPreferenceKeys.isOCPreference(preference.getKey())) { - OCPreferenceKeys prefKey = OCPreferenceKeys.getByKey(preference.getKey()); + final OCPreferenceKeys prefKey = OCPreferenceKeys.getByKey(preference.getKey()); preference.getPreferenceManager().findPreference(getKey(prefKey.prefScreenId)).setSummary(summary); } else if (isPreference(preference, R.string.pref_connectorGCActive)) { preference.getPreferenceManager().findPreference(getKey(R.string.preference_screen_gc)).setSummary(summary); @@ -600,8 +599,8 @@ public class SettingsActivity extends PreferenceActivity { } else if (preference instanceof ListPreference) { // For list preferences, look up the correct display value in // the preference's 'entries' list. - ListPreference listPreference = (ListPreference) preference; - int index = listPreference.findIndexOfValue(stringValue); + final ListPreference listPreference = (ListPreference) preference; + final int index = listPreference.findIndexOfValue(stringValue); // Set the summary to reflect the new value. preference.setSummary( @@ -617,6 +616,9 @@ public class SettingsActivity extends PreferenceActivity { text = preference.getContext().getString(R.string.init_backup_last_no); } preference.setSummary(text); + } else if (isPreference(preference, R.string.pref_ratingwanted)) { + findPreference(R.string.preference_screen_gcvote).setSummary(getServiceSummary((Boolean) value)); + redrawScreen(findPreference(R.string.preference_screen_services)); } else { // For all other preferences, set the summary to the value's // simple string representation. @@ -625,13 +627,15 @@ public class SettingsActivity extends PreferenceActivity { // TODO: do not special case geocaching.com here if ((isPreference(preference, R.string.pref_username) && !stringValue.equals(Settings.getUsername())) || (isPreference(preference, R.string.pref_password) && !stringValue.equals(Settings.getGcCredentials().getRight()))) { // reset log-in if gc user or password is changed - if (GCLogin.getInstance().isActualLoginStatus()) { - GCLogin.getInstance().logout(); - } CgeoApplication.getInstance().forceRelog(); } return true; } + + private Preference findPreference(final int preferenceKeyResourceId) { + return preferenceManager.findPreference(getKey(preferenceKeyResourceId)); + } + }; /** @@ -662,12 +666,12 @@ public class SettingsActivity extends PreferenceActivity { */ private void bindSummaryToStringValue(final int key) { - Preference pref = getPreference(key); + final Preference pref = getPreference(key); if (pref == null) { return; } - String value = PreferenceManager + final String value = PreferenceManager .getDefaultSharedPreferences(pref.getContext()) .getString(pref.getKey(), ""); @@ -686,7 +690,7 @@ public class SettingsActivity extends PreferenceActivity { @SuppressWarnings("deprecation") @Override - public void setPreferenceScreen(PreferenceScreen preferenceScreen) { + public void setPreferenceScreen(final PreferenceScreen preferenceScreen) { // TODO replace with fragment based code super.setPreferenceScreen(preferenceScreen); } @@ -698,7 +702,7 @@ public class SettingsActivity extends PreferenceActivity { return super.getPreferenceManager(); } - private static boolean isPreference(final Preference preference, int preferenceKeyId) { + private static boolean isPreference(final Preference preference, final int preferenceKeyId) { return getKey(preferenceKeyId).equals(preference.getKey()); } } diff --git a/main/src/cgeo/geocaching/settings/TemplateTextPreference.java b/main/src/cgeo/geocaching/settings/TemplateTextPreference.java index 667b02b..a33f09d 100644 --- a/main/src/cgeo/geocaching/settings/TemplateTextPreference.java +++ b/main/src/cgeo/geocaching/settings/TemplateTextPreference.java @@ -1,5 +1,7 @@ package cgeo.geocaching.settings; +import butterknife.ButterKnife; + import cgeo.geocaching.R; import cgeo.geocaching.activity.ActivityMixin; import cgeo.geocaching.ui.dialog.Dialogs; @@ -30,12 +32,12 @@ public class TemplateTextPreference extends DialogPreference { private EditText editText; private String initialValue; - public TemplateTextPreference(Context context, AttributeSet attrs) { + public TemplateTextPreference(final Context context, final AttributeSet attrs) { super(context, attrs); init(); } - public TemplateTextPreference(Context context, AttributeSet attrs, int defStyle) { + public TemplateTextPreference(final Context context, final AttributeSet attrs, final int defStyle) { super(context, attrs, defStyle); init(); } @@ -45,28 +47,28 @@ public class TemplateTextPreference extends DialogPreference { } @Override - protected void onBindDialogView(View view) { + protected void onBindDialogView(final View view) { settingsActivity = (SettingsActivity) this.getContext(); - editText = (EditText) view.findViewById(R.id.signature_dialog_text); + editText = ButterKnife.findById(view, R.id.signature_dialog_text); editText.setText(getPersistedString(initialValue != null ? initialValue : StringUtils.EMPTY)); Dialogs.moveCursorToEnd(editText); - Button button = (Button) view.findViewById(R.id.signature_templates); + final Button button = ButterKnife.findById(view, R.id.signature_templates); button.setOnClickListener(new View.OnClickListener() { @Override - public void onClick(View button) { - AlertDialog.Builder alert = new AlertDialog.Builder(TemplateTextPreference.this.getContext()); + public void onClick(final View button) { + final AlertDialog.Builder alert = new AlertDialog.Builder(TemplateTextPreference.this.getContext()); alert.setTitle(R.string.init_signature_template_button); - final ArrayList<LogTemplate> templates = LogTemplateProvider.getTemplates(); - String[] items = new String[templates.size()]; + final ArrayList<LogTemplate> templates = LogTemplateProvider.getTemplatesWithoutSignature(); + final String[] items = new String[templates.size()]; for (int i = 0; i < templates.size(); i++) { items[i] = settingsActivity.getResources().getString(templates.get(i).getResourceId()); } alert.setItems(items, new DialogInterface.OnClickListener() { @Override - public void onClick(DialogInterface dialog, int position) { + public void onClick(final DialogInterface dialog, final int position) { dialog.dismiss(); final LogTemplate template = templates.get(position); insertSignatureTemplate(template); @@ -80,14 +82,14 @@ public class TemplateTextPreference extends DialogPreference { } private void insertSignatureTemplate(final LogTemplate template) { - String insertText = "[" + template.getTemplateString() + "]"; + final String insertText = "[" + template.getTemplateString() + "]"; ActivityMixin.insertAtPosition(editText, insertText, true); } @Override - protected void onDialogClosed(boolean positiveResult) { + protected void onDialogClosed(final boolean positiveResult) { if (positiveResult) { - String text = editText.getText().toString(); + final String text = editText.getText().toString(); persistString(text); callChangeListener(text); } @@ -95,7 +97,7 @@ public class TemplateTextPreference extends DialogPreference { } @Override - protected void onSetInitialValue(boolean restorePersistedValue, Object defaultValue) { + protected void onSetInitialValue(final boolean restorePersistedValue, final Object defaultValue) { if (restorePersistedValue) { // Restore existing state initialValue = this.getPersistedString(DEFAULT_VALUE); @@ -107,7 +109,7 @@ public class TemplateTextPreference extends DialogPreference { } @Override - protected Object onGetDefaultValue(TypedArray array, int index) { + protected Object onGetDefaultValue(final TypedArray array, final int index) { return array.getString(index); } } diff --git a/main/src/cgeo/geocaching/settings/TextPreference.java b/main/src/cgeo/geocaching/settings/TextPreference.java index eecf4cc..b3de59a 100644 --- a/main/src/cgeo/geocaching/settings/TextPreference.java +++ b/main/src/cgeo/geocaching/settings/TextPreference.java @@ -1,5 +1,7 @@ package cgeo.geocaching.settings; +import butterknife.ButterKnife; + import cgeo.geocaching.R; import android.content.Context; @@ -29,15 +31,15 @@ public class TextPreference extends AbstractAttributeBasedPrefence { private TextView summaryView; private CharSequence summaryText; - public TextPreference(Context context) { + public TextPreference(final Context context) { super(context); } - public TextPreference(Context context, AttributeSet attrs) { + public TextPreference(final Context context, final AttributeSet attrs) { super(context, attrs); } - public TextPreference(Context context, AttributeSet attrs, int defStyle) { + public TextPreference(final Context context, final AttributeSet attrs, final int defStyle) { super(context, attrs, defStyle); } @@ -47,27 +49,27 @@ public class TextPreference extends AbstractAttributeBasedPrefence { } @Override - protected void processAttributeValues(TypedArray values) { + protected void processAttributeValues(final TypedArray values) { this.text = values.getString(0); } @Override - protected View onCreateView(ViewGroup parent) { + protected View onCreateView(final ViewGroup parent) { this.setSelectable(false); - View v = super.onCreateView(parent); + final View v = super.onCreateView(parent); - TextView text = (TextView) v.findViewById(R.id.textPreferenceText); + final TextView text = ButterKnife.findById(v, R.id.textPreferenceText); text.setText(this.text); - summaryView = (TextView) v.findViewById(R.id.textPreferenceSummary); + summaryView = ButterKnife.findById(v, R.id.textPreferenceSummary); setSummary(null); // show saved summary text return v; } @Override - public void setSummary(CharSequence summaryText) { + public void setSummary(final CharSequence summaryText) { // the layout hasn't been inflated yet, save the summaryText for later use if (summaryView == null) { this.summaryText = summaryText; diff --git a/main/src/cgeo/geocaching/settings/WpThresholdPreference.java b/main/src/cgeo/geocaching/settings/WpThresholdPreference.java index 4c43acf..37edafa 100644 --- a/main/src/cgeo/geocaching/settings/WpThresholdPreference.java +++ b/main/src/cgeo/geocaching/settings/WpThresholdPreference.java @@ -1,5 +1,7 @@ package cgeo.geocaching.settings; +import butterknife.ButterKnife; + import cgeo.geocaching.R; import android.content.Context; @@ -15,17 +17,17 @@ public class WpThresholdPreference extends Preference { private TextView valueView; - public WpThresholdPreference(Context context) { + public WpThresholdPreference(final Context context) { super(context); init(); } - public WpThresholdPreference(Context context, AttributeSet attrs) { + public WpThresholdPreference(final Context context, final AttributeSet attrs) { super(context, attrs); init(); } - public WpThresholdPreference(Context context, AttributeSet attrs, int defStyle) { + public WpThresholdPreference(final Context context, final AttributeSet attrs, final int defStyle) { super(context, attrs, defStyle); init(); } @@ -35,33 +37,33 @@ public class WpThresholdPreference extends Preference { } @Override - protected View onCreateView(ViewGroup parent) { - View v = super.onCreateView(parent); + protected View onCreateView(final ViewGroup parent) { + final View v = super.onCreateView(parent); // get views - SeekBar seekBar = (SeekBar) v.findViewById(R.id.wp_threshold_seekbar); - valueView = (TextView) v.findViewById(R.id.wp_threshold_value_view); + final SeekBar seekBar = ButterKnife.findById(v, R.id.wp_threshold_seekbar); + valueView = ButterKnife.findById(v, R.id.wp_threshold_value_view); // init seekbar seekBar.setMax(Settings.SHOW_WP_THRESHOLD_MAX); // set initial value - int threshold = Settings.getWayPointsThreshold(); + final int threshold = Settings.getWayPointsThreshold(); valueView.setText(String.valueOf(threshold)); seekBar.setProgress(threshold); seekBar.setOnSeekBarChangeListener(new OnSeekBarChangeListener() { @Override - public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { + public void onProgressChanged(final SeekBar seekBar, final int progress, final boolean fromUser) { if (fromUser) { valueView.setText(String.valueOf(progress)); } } @Override - public void onStartTrackingTouch(SeekBar seekBar) { + public void onStartTrackingTouch(final SeekBar seekBar) { } @Override - public void onStopTrackingTouch(SeekBar seekBar) { + public void onStopTrackingTouch(final SeekBar seekBar) { Settings.setShowWaypointsThreshold(seekBar.getProgress()); } }); |