aboutsummaryrefslogtreecommitdiffstats
path: root/main/src/cgeo/geocaching/settings
diff options
context:
space:
mode:
Diffstat (limited to 'main/src/cgeo/geocaching/settings')
-rw-r--r--main/src/cgeo/geocaching/settings/AuthorizeOcDePreference.java45
-rw-r--r--main/src/cgeo/geocaching/settings/AuthorizeOcPreference.java80
-rw-r--r--main/src/cgeo/geocaching/settings/AuthorizeTwitterPreference.java3
-rw-r--r--main/src/cgeo/geocaching/settings/RegisterSend2CgeoPreference.java2
-rw-r--r--main/src/cgeo/geocaching/settings/Settings.java92
-rw-r--r--main/src/cgeo/geocaching/settings/SettingsActivity.java92
6 files changed, 202 insertions, 112 deletions
diff --git a/main/src/cgeo/geocaching/settings/AuthorizeOcDePreference.java b/main/src/cgeo/geocaching/settings/AuthorizeOcDePreference.java
deleted file mode 100644
index 28807eb..0000000
--- a/main/src/cgeo/geocaching/settings/AuthorizeOcDePreference.java
+++ /dev/null
@@ -1,45 +0,0 @@
-package cgeo.geocaching.settings;
-
-import cgeo.geocaching.connector.oc.OCAuthorizationActivity;
-
-import android.content.Context;
-import android.content.Intent;
-import android.preference.Preference;
-import android.util.AttributeSet;
-import android.view.View;
-import android.view.ViewGroup;
-
-public class AuthorizeOcDePreference extends Preference {
-
- public AuthorizeOcDePreference(Context context) {
- super(context);
- }
-
- public AuthorizeOcDePreference(Context context, AttributeSet attrs) {
- super(context, attrs);
- }
-
- public AuthorizeOcDePreference(Context context, AttributeSet attrs, int defStyle) {
- super(context, attrs, defStyle);
- }
-
- @Override
- protected View onCreateView(ViewGroup parent) {
- final SettingsActivity activity = (SettingsActivity) getContext();
-
- setOnPreferenceClickListener(new OnPreferenceClickListener() {
- @Override
- public boolean onPreferenceClick(Preference preference) {
- Intent authIntent = new Intent(preference.getContext(),
- OCAuthorizationActivity.class);
- activity.startActivityForResult(authIntent,
- SettingsActivity.OAUTH_OCDE_REQUEST);
-
- return false; // no shared preference has to be changed
- }
- });
-
- activity.setOCDEAuthTitle();
- return super.onCreateView(parent);
- }
-}
diff --git a/main/src/cgeo/geocaching/settings/AuthorizeOcPreference.java b/main/src/cgeo/geocaching/settings/AuthorizeOcPreference.java
new file mode 100644
index 0000000..f5d6a57
--- /dev/null
+++ b/main/src/cgeo/geocaching/settings/AuthorizeOcPreference.java
@@ -0,0 +1,80 @@
+package cgeo.geocaching.settings;
+
+import cgeo.geocaching.R;
+import cgeo.geocaching.cgeoapplication;
+import cgeo.geocaching.connector.oc.OCDEAuthorizationActivity;
+import cgeo.geocaching.connector.oc.OCPLAuthorizationActivity;
+
+import android.content.Context;
+import android.content.Intent;
+import android.preference.Preference;
+import android.util.AttributeSet;
+import android.view.View;
+import android.view.ViewGroup;
+
+public class AuthorizeOcPreference extends Preference {
+
+ private static final int NO_KEY = -1;
+
+ private enum OCAuthorizations {
+ NONE(NO_KEY, null),
+ OCDE(R.string.pref_fakekey_ocde_authorization, OCDEAuthorizationActivity.class),
+ OCPL(R.string.pref_fakekey_ocpl_authorization, OCPLAuthorizationActivity.class);
+
+ public int prefKeyId;
+ public Class<?> authActivity;
+
+ OCAuthorizations(int prefKeyId, Class<?> clazz) {
+ this.prefKeyId = prefKeyId;
+ this.authActivity = clazz;
+ }
+ }
+
+ private final OCAuthorizations ocAuth;
+
+ private OCAuthorizations getAuthorization() {
+ final String prefKey = getKey();
+ for (OCAuthorizations auth : OCAuthorizations.values()) {
+ if (auth.prefKeyId != NO_KEY && prefKey.equals(cgeoapplication.getInstance().getString(auth.prefKeyId))) {
+ return auth;
+ }
+ }
+ return OCAuthorizations.NONE;
+ }
+
+ public AuthorizeOcPreference(Context context) {
+ super(context);
+ this.ocAuth = getAuthorization();
+ }
+
+ public AuthorizeOcPreference(Context context, AttributeSet attrs) {
+ super(context, attrs);
+ this.ocAuth = getAuthorization();
+ }
+
+ public AuthorizeOcPreference(Context context, AttributeSet attrs, int defStyle) {
+ super(context, attrs, defStyle);
+ this.ocAuth = getAuthorization();
+ }
+
+ @Override
+ protected View onCreateView(ViewGroup parent) {
+ final SettingsActivity activity = (SettingsActivity) getContext();
+
+ setOnPreferenceClickListener(new OnPreferenceClickListener() {
+ @Override
+ public boolean onPreferenceClick(Preference preference) {
+ if (ocAuth.authActivity != null) {
+ Intent authIntent = new Intent(preference.getContext(),
+ ocAuth.authActivity);
+ activity.startActivityForResult(authIntent,
+ ocAuth.prefKeyId);
+ }
+ return false; // no shared preference has to be changed
+ }
+ });
+
+ activity.setOcAuthTitle(ocAuth.prefKeyId);
+ return super.onCreateView(parent);
+ }
+}
diff --git a/main/src/cgeo/geocaching/settings/AuthorizeTwitterPreference.java b/main/src/cgeo/geocaching/settings/AuthorizeTwitterPreference.java
index ed3e159..1fdd0de 100644
--- a/main/src/cgeo/geocaching/settings/AuthorizeTwitterPreference.java
+++ b/main/src/cgeo/geocaching/settings/AuthorizeTwitterPreference.java
@@ -1,5 +1,6 @@
package cgeo.geocaching.settings;
+import cgeo.geocaching.R;
import cgeo.geocaching.twitter.TwitterAuthorizationActivity;
import android.content.Context;
@@ -33,7 +34,7 @@ public class AuthorizeTwitterPreference extends Preference {
Intent authIntent = new Intent(preference.getContext(),
TwitterAuthorizationActivity.class);
activity.startActivityForResult(authIntent,
- SettingsActivity.OAUTH_TWITTER_REQUEST);
+ R.string.pref_fakekey_twitter_authorization);
return false; // no shared preference has to be changed
}
diff --git a/main/src/cgeo/geocaching/settings/RegisterSend2CgeoPreference.java b/main/src/cgeo/geocaching/settings/RegisterSend2CgeoPreference.java
index a019c4a..fbf08fa 100644
--- a/main/src/cgeo/geocaching/settings/RegisterSend2CgeoPreference.java
+++ b/main/src/cgeo/geocaching/settings/RegisterSend2CgeoPreference.java
@@ -99,7 +99,7 @@ public class RegisterSend2CgeoPreference extends Preference {
if (response != null && response.getStatusLine().getStatusCode() == 200) {
//response was OK
- String[] strings = Network.getResponseData(response).split(",");
+ String[] strings = StringUtils.split(Network.getResponseData(response), ',');
try {
pin = Integer.parseInt(strings[1].trim());
} catch (Exception e) {
diff --git a/main/src/cgeo/geocaching/settings/Settings.java b/main/src/cgeo/geocaching/settings/Settings.java
index 49c1764..34f5dc1 100644
--- a/main/src/cgeo/geocaching/settings/Settings.java
+++ b/main/src/cgeo/geocaching/settings/Settings.java
@@ -43,7 +43,7 @@ import java.util.Locale;
*/
public final class Settings {
- public static final int SHOW_WP_THRESHOLD_DEFAULT = 5;
+ 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();
@@ -53,14 +53,14 @@ public final class Settings {
private final static String keyConsumerPublic = CryptUtils.rot13("ESnsCvAv3kEupF1GCR3jGj");
private final static String keyConsumerSecret = CryptUtils.rot13("7vQWceACV9umEjJucmlpFe9FCMZSeqIqfkQ2BnhV9x");
- public enum coordInputFormatEnum {
+ public enum CoordInputFormatEnum {
Plain,
Deg,
Min,
Sec;
- public static coordInputFormatEnum fromInt(int id) {
- final coordInputFormatEnum[] values = coordInputFormatEnum.values();
+ public static CoordInputFormatEnum fromInt(int id) {
+ final CoordInputFormatEnum[] values = CoordInputFormatEnum.values();
if (id < 0 || id >= values.length) {
return Min;
}
@@ -135,10 +135,10 @@ public final class Settings {
e.putString(getKey(R.string.pref_memberstatus), old.getString(getKey(R.string.pref_memberstatus), ""));
e.putInt(getKey(R.string.pref_coordinputformat), old.getInt(getKey(R.string.pref_coordinputformat), 0));
e.putBoolean(getKey(R.string.pref_log_offline), old.getBoolean(getKey(R.string.pref_log_offline), false));
- e.putBoolean(getKey(R.string.pref_choose_list), old.getBoolean(getKey(R.string.pref_choose_list), false));
+ e.putBoolean(getKey(R.string.pref_choose_list), old.getBoolean(getKey(R.string.pref_choose_list), true));
e.putBoolean(getKey(R.string.pref_loaddirectionimg), old.getBoolean(getKey(R.string.pref_loaddirectionimg), true));
e.putString(getKey(R.string.pref_gccustomdate), old.getString(getKey(R.string.pref_gccustomdate), null));
- e.putInt(getKey(R.string.pref_gcshowwaypointsthreshold), old.getInt(getKey(R.string.pref_gcshowwaypointsthreshold), 0));
+ e.putInt(getKey(R.string.pref_showwaypointsthreshold), old.getInt(getKey(R.string.pref_showwaypointsthreshold), SHOW_WP_THRESHOLD_DEFAULT));
e.putString(getKey(R.string.pref_cookiestore), old.getString(getKey(R.string.pref_cookiestore), null));
e.putBoolean(getKey(R.string.pref_opendetailslastpage), old.getBoolean(getKey(R.string.pref_opendetailslastpage), false));
e.putInt(getKey(R.string.pref_lastdetailspage), old.getInt(getKey(R.string.pref_lastdetailspage), 1));
@@ -166,7 +166,7 @@ public final class Settings {
} else if (wpThreshold > SHOW_WP_THRESHOLD_MAX) {
wpThreshold = SHOW_WP_THRESHOLD_MAX;
}
- e.putInt(getKey(R.string.pref_gcshowwaypointsthreshold), wpThreshold);
+ 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);
@@ -313,47 +313,30 @@ public final class Settings {
return putString(R.string.pref_memberstatus, memberStatus);
}
- public static boolean isOCConnectorActive() {
- return getBoolean(R.string.pref_connectorOCActive, false);
+ public static ImmutablePair<String, String> getTokenPair(final int tokenPublicPrefKey, final int tokenSecretPrefKey) {
+ return new ImmutablePair<String, String>(getString(tokenPublicPrefKey, null), getString(tokenSecretPrefKey, null));
}
- public static boolean setOCConnectorActive(final boolean isActive) {
- return putBoolean(R.string.pref_connectorOCActive, isActive);
- }
-
- public static String getOCDETokenPublic() {
- return getString(R.string.pref_ocde_tokenpublic, "");
- }
-
- public static String getOCDETokenSecret() {
- return getString(R.string.pref_ocde_tokensecret, "");
- }
-
- public static boolean hasOCDEAuthorization() {
- return StringUtils.isNotBlank(getOCDETokenPublic())
- && StringUtils.isNotBlank(getOCDETokenSecret());
- }
-
- public static void setOCDETokens(final String tokenPublic,
- final String tokenSecret, boolean enableOcDe) {
- putString(R.string.pref_ocde_tokenpublic, tokenPublic);
- putString(R.string.pref_ocde_tokensecret, tokenSecret);
- if (tokenPublic != null) {
- remove(R.string.pref_temp_ocde_token_public);
- remove(R.string.pref_temp_ocde_token_secret);
+ public static void setTokens(final int tokenPublicPrefKey, final String tokenPublic, final int tokenSecretPrefKey, final String tokenSecret) {
+ if (tokenPublic == null) {
+ remove(tokenPublicPrefKey);
+ } else {
+ putString(tokenPublicPrefKey, tokenPublic);
+ }
+ if (tokenSecret == null) {
+ remove(tokenSecretPrefKey);
+ } else {
+ putString(tokenSecretPrefKey, tokenSecret);
}
- setOCConnectorActive(enableOcDe);
}
- public static void setOCDETempTokens(final String tokenPublic, final String tokenSecret) {
- putString(R.string.pref_temp_ocde_token_public, tokenPublic);
- putString(R.string.pref_temp_ocde_token_secret, tokenSecret);
+ public static boolean isOCConnectorActive(int isActivePrefKeyId) {
+ return getBoolean(isActivePrefKeyId, false);
}
- public static ImmutablePair<String, String> getTempOCDEToken() {
- String tokenPublic = getString(R.string.pref_temp_ocde_token_public, null);
- String tokenSecret = getString(R.string.pref_temp_ocde_token_secret, null);
- return new ImmutablePair<String, String>(tokenPublic, tokenSecret);
+ public static boolean hasOCAuthorization(int tokenPublicPrefKeyId, int tokenSecretPrefKeyId) {
+ return StringUtils.isNotBlank(getString(tokenPublicPrefKeyId, ""))
+ && StringUtils.isNotBlank(getString(tokenSecretPrefKeyId, ""));
}
public static boolean isGCvoteLogin() {
@@ -458,11 +441,15 @@ public final class Settings {
return MapsforgeMapProvider.isValidMapFile(mapFileIn);
}
- public static coordInputFormatEnum getCoordInputFormat() {
- return coordInputFormatEnum.fromInt(getInt(R.string.pref_coordinputformat, 0));
+ public static boolean isScaleMapsforgeText() {
+ return getBoolean(R.string.pref_mapsforge_scale_text, true);
}
- public static void setCoordInputFormat(final coordInputFormatEnum format) {
+ public static CoordInputFormatEnum getCoordInputFormat() {
+ return CoordInputFormatEnum.fromInt(getInt(R.string.pref_coordinputformat, 0));
+ }
+
+ public static void setCoordInputFormat(final CoordInputFormatEnum format) {
putInt(R.string.pref_coordinputformat, format.ordinal());
}
@@ -488,7 +475,7 @@ public final class Settings {
/**
* @return User selected date format on GC.com
- * @see Login#gcCustomDateFormats
+ * @see Login#GC_CUSTOM_DATE_FORMATS
*/
public static String getGcCustomDate() {
return getString(R.string.pref_gccustomdate, null);
@@ -560,7 +547,14 @@ public final class Settings {
}
public static boolean isUseImperialUnits() {
- return getBoolean(R.string.pref_units, false);
+ return getBoolean(R.string.pref_units, getImperialUnitsDefault());
+ }
+
+ static boolean getImperialUnitsDefault() {
+ final String countryCode = Locale.getDefault().getCountry();
+ return "US".equals(countryCode) // USA
+ || "LR".equals(countryCode) // Liberia
+ || "MM".equals(countryCode); // Burma
}
public static boolean isLiveMap() {
@@ -667,7 +661,7 @@ public final class Settings {
public static void setAnyCoordinates(final Geopoint coords) {
if (null != coords) {
putFloat(R.string.pref_anylatitude, (float) coords.getLatitude());
- putFloat(R.string.pref_anylatitude, (float) coords.getLongitude());
+ putFloat(R.string.pref_anylongitude, (float) coords.getLongitude());
} else {
remove(R.string.pref_anylatitude);
remove(R.string.pref_anylongitude);
@@ -723,11 +717,11 @@ public final class Settings {
* The Threshold for the showing of child waypoints
*/
public static int getWayPointsThreshold() {
- return getInt(R.string.pref_gcshowwaypointsthreshold, SHOW_WP_THRESHOLD_DEFAULT);
+ return getInt(R.string.pref_showwaypointsthreshold, SHOW_WP_THRESHOLD_DEFAULT);
}
public static void setShowWaypointsThreshold(final int threshold) {
- putInt(R.string.pref_gcshowwaypointsthreshold, threshold);
+ putInt(R.string.pref_showwaypointsthreshold, threshold);
}
public static boolean isUseTwitter() {
diff --git a/main/src/cgeo/geocaching/settings/SettingsActivity.java b/main/src/cgeo/geocaching/settings/SettingsActivity.java
index 5d34573..90b6145 100644
--- a/main/src/cgeo/geocaching/settings/SettingsActivity.java
+++ b/main/src/cgeo/geocaching/settings/SettingsActivity.java
@@ -8,6 +8,7 @@ import cgeo.geocaching.activity.ActivityMixin;
import cgeo.geocaching.apps.cache.navi.NavigationAppFactory;
import cgeo.geocaching.apps.cache.navi.NavigationAppFactory.NavigationAppsEnum;
import cgeo.geocaching.compatibility.Compatibility;
+import cgeo.geocaching.connector.gc.GCConnector;
import cgeo.geocaching.connector.gc.Login;
import cgeo.geocaching.files.SimpleDirChooser;
import cgeo.geocaching.maps.MapProviderFactory;
@@ -23,6 +24,7 @@ import org.openintents.intents.FileManagerIntents;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
+import android.os.Build;
import android.os.Bundle;
import android.os.Environment;
import android.preference.ListPreference;
@@ -44,6 +46,7 @@ import android.widget.ListAdapter;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
+import java.util.Locale;
/**
* A {@link PreferenceActivity} that presents a set of application settings. On
@@ -61,10 +64,6 @@ public class SettingsActivity extends PreferenceActivity {
private static final String INTENT_GOTO = "GOTO";
private static final int INTENT_GOTO_SERVICES = 1;
- private static final int DIR_CHOOSER_MAPS_DIRECTORY_REQUEST = 4;
- static final int OAUTH_OCDE_REQUEST = 5;
- static final int OAUTH_TWITTER_REQUEST = 6;
-
private EditText signatureText;
/**
@@ -91,7 +90,8 @@ public class SettingsActivity extends PreferenceActivity {
@Override
protected void onCreate(final Bundle savedInstanceState) {
- setTheme(Settings.isLightSkin() ? R.style.settings_light : R.style.settings);
+ // Set light skin in preferences only for devices > 2.x, it doesn't work under 2.x
+ setTheme(Settings.isLightSkin() && Build.VERSION.SDK_INT > 10 ? R.style.settings_light : R.style.settings);
super.onCreate(savedInstanceState);
SettingsActivity.addPreferencesFromResource(this, R.xml.preferences);
@@ -134,6 +134,7 @@ public class SettingsActivity extends PreferenceActivity {
R.string.pref_fakekey_preference_backup_info, }) {
bindSummaryToStringValue(k);
}
+ getPreference(R.string.pref_units).setDefaultValue(Settings.getImperialUnitsDefault());
}
private void initNavigationMenuPreferences() {
@@ -149,7 +150,24 @@ public class SettingsActivity extends PreferenceActivity {
private void initServicePreferences() {
getPreference(R.string.pref_connectorOCActive).setOnPreferenceChangeListener(VALUE_CHANGE_LISTENER);
+ getPreference(R.string.pref_connectorOCPLActive).setOnPreferenceChangeListener(VALUE_CHANGE_LISTENER);
getPreference(R.string.pref_connectorGCActive).setOnPreferenceChangeListener(VALUE_CHANGE_LISTENER);
+ setWebsite(R.string.pref_fakekey_gc_website, GCConnector.getInstance().getHost());
+ setWebsite(R.string.pref_fakekey_ocde_website, "opencaching.de");
+ setWebsite(R.string.pref_fakekey_ocpl_website, "opencaching.pl");
+ setWebsite(R.string.pref_fakekey_gcvote_website, "gcvote.com");
+ setWebsite(R.string.pref_fakekey_sendtocgeo_website, "send2.cgeo.org");
+ }
+
+ private void setWebsite(final int preferenceKey, final String host) {
+ Preference preference = getPreference(preferenceKey);
+ preference.setOnPreferenceClickListener(new OnPreferenceClickListener() {
+ @Override
+ public boolean onPreferenceClick(final Preference preference) {
+ startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://" + host)));
+ return true;
+ }
+ });
}
private static String getKey(final int prefKeyId) {
@@ -256,7 +274,7 @@ public class SettingsActivity extends PreferenceActivity {
public boolean onPreferenceClick(final Preference preference) {
Intent i = new Intent(SettingsActivity.this,
SelectMapfileActivity.class);
- startActivityForResult(i, DIR_CHOOSER_MAPS_DIRECTORY_REQUEST);
+ startActivityForResult(i, R.string.pref_mapDirectory);
return false;
}
});
@@ -380,13 +398,34 @@ public class SettingsActivity extends PreferenceActivity {
Settings.putString(R.string.pref_webDeviceName, Settings.getWebDeviceName());
}
+ public void setOcAuthTitle(int prefKeyId) {
+ //TODO: Generalize!
+ switch (prefKeyId) {
+ case R.string.pref_fakekey_ocde_authorization:
+ setOCDEAuthTitle();
+ break;
+ case R.string.pref_fakekey_ocpl_authorization:
+ setOCPLAuthTitle();
+ break;
+ default:
+ Log.e(String.format(Locale.ENGLISH, "Invalid key %d in SettingsActivity.setTitle()", prefKeyId));
+ }
+ }
+
void setOCDEAuthTitle() {
getPreference(R.string.pref_fakekey_ocde_authorization)
- .setTitle(getString(Settings.hasOCDEAuthorization()
+ .setTitle(getString(Settings.hasOCAuthorization(R.string.pref_ocde_tokenpublic, R.string.pref_ocde_tokensecret)
? R.string.init_reregister_oc_de
: R.string.init_register_oc_de));
}
+ void setOCPLAuthTitle() {
+ getPreference(R.string.pref_fakekey_ocpl_authorization)
+ .setTitle(getString(Settings.hasOCAuthorization(R.string.pref_ocpl_tokenpublic, R.string.pref_ocpl_tokensecret)
+ ? R.string.init_reregister_oc_pl
+ : R.string.init_register_oc_pl));
+ }
+
void setTwitterAuthTitle() {
getPreference(R.string.pref_fakekey_twitter_authorization)
.setTitle(getString(Settings.hasTwitterAuthorization()
@@ -415,7 +454,7 @@ public class SettingsActivity extends PreferenceActivity {
}
switch (requestCode) {
- case DIR_CHOOSER_MAPS_DIRECTORY_REQUEST:
+ case R.string.pref_mapDirectory:
if (data.hasExtra(Intents.EXTRA_MAP_FILE)) {
final String mapFile = data.getStringExtra(Intents.EXTRA_MAP_FILE);
Settings.setMapFile(mapFile);
@@ -427,11 +466,15 @@ public class SettingsActivity extends PreferenceActivity {
getPreference(R.string.pref_mapDirectory).setSummary(
Settings.getMapFileDirectory());
break;
- case OAUTH_OCDE_REQUEST:
+ case R.string.pref_fakekey_ocde_authorization:
setOCDEAuthTitle();
redrawScreen(R.string.pref_fakekey_services_screen);
break;
- case OAUTH_TWITTER_REQUEST:
+ case R.string.pref_fakekey_ocpl_authorization:
+ setOCPLAuthTitle();
+ redrawScreen(R.string.pref_fakekey_services_screen);
+ break;
+ case R.string.pref_fakekey_twitter_authorization:
setTwitterAuthTitle();
redrawScreen(R.string.pref_fakekey_services_screen);
break;
@@ -457,12 +500,29 @@ public class SettingsActivity extends PreferenceActivity {
}
} else if (isPreference(preference, R.string.pref_mapsource)) {
// reset the cached map source
- int mapSourceId = Integer.valueOf(stringValue);
- final MapSource mapSource = MapProviderFactory.getMapSource(mapSourceId);
+ MapSource mapSource;
+ try {
+ final int mapSourceId = Integer.valueOf(stringValue);
+ mapSource = MapProviderFactory.getMapSource(mapSourceId);
+ } catch (final NumberFormatException e) {
+ Log.e("SettingsActivity.onPreferenceChange: bad source id `" + stringValue + "'");
+ mapSource = null;
+ }
+ // If there is no corresponding map source (because some map sources were
+ // removed from the device since) then use the first one available.
+ if (mapSource == null) {
+ mapSource = MapProviderFactory.getAnyMapSource();
+ if (mapSource == null) {
+ // There are no map source. There is little we can do here, except log an error and
+ // return to avoid triggering a null pointer exception.
+ Log.e("SettingsActivity.onPreferenceChange: no map source available");
+ return true;
+ }
+ }
Settings.setMapSource(mapSource);
preference.setSummary(mapSource.getName());
- } else if (isPreference(preference, R.string.pref_connectorOCActive) || isPreference(preference, R.string.pref_connectorGCActive)) {
- // reset log-in status if connector activation was changed
+ } else if (isPreference(preference, R.string.pref_connectorOCActive) || isPreference(preference, R.string.pref_connectorOCPLActive) || isPreference(preference, R.string.pref_connectorGCActive)) {
+ // // reset log-in status if connector activation was changed
cgeoapplication.getInstance().checkLogin = true;
} else if (preference instanceof ListPreference) {
// For list preferences, look up the correct display value in
@@ -475,7 +535,7 @@ public class SettingsActivity extends PreferenceActivity {
index >= 0
? listPreference.getEntries()[index]
: null);
- } else if (getKey(R.string.pref_fakekey_preference_backup_info).equals(preference.getKey())) {
+ } else if (isPreference(preference, R.string.pref_fakekey_preference_backup_info)) {
final String text;
if (DatabaseBackupUtils.hasBackup()) {
text = preference.getContext().getString(R.string.init_backup_last) + " "
@@ -489,7 +549,7 @@ public class SettingsActivity extends PreferenceActivity {
// simple string representation.
preference.setSummary(stringValue);
}
- if (isPreference(preference, R.string.pref_username) || isPreference(preference, R.string.pref_password)) {
+ if ((isPreference(preference, R.string.pref_username) && !stringValue.equals(Settings.getUsername())) || (isPreference(preference, R.string.pref_password) && !stringValue.equals(Settings.getGcLogin().getRight()))) {
// reset log-in if gc user or password is changed
if (Login.isActualLoginStatus()) {
Login.logout();