aboutsummaryrefslogtreecommitdiffstats
path: root/main/src/cgeo/geocaching/settings/SettingsActivity.java
diff options
context:
space:
mode:
Diffstat (limited to 'main/src/cgeo/geocaching/settings/SettingsActivity.java')
-rw-r--r--main/src/cgeo/geocaching/settings/SettingsActivity.java93
1 files changed, 62 insertions, 31 deletions
diff --git a/main/src/cgeo/geocaching/settings/SettingsActivity.java b/main/src/cgeo/geocaching/settings/SettingsActivity.java
index df6e680..6e3ba0e 100644
--- a/main/src/cgeo/geocaching/settings/SettingsActivity.java
+++ b/main/src/cgeo/geocaching/settings/SettingsActivity.java
@@ -1,7 +1,5 @@
package cgeo.geocaching.settings;
-import butterknife.ButterKnife;
-
import cgeo.geocaching.CgeoApplication;
import cgeo.geocaching.DataStore;
import cgeo.geocaching.Intents;
@@ -14,13 +12,19 @@ import cgeo.geocaching.connector.gc.GCConnector;
import cgeo.geocaching.files.SimpleDirChooser;
import cgeo.geocaching.maps.MapProviderFactory;
import cgeo.geocaching.maps.interfaces.MapSource;
+import cgeo.geocaching.network.AndroidBeam;
+import cgeo.geocaching.sensors.Sensors;
import cgeo.geocaching.utils.DatabaseBackupUtils;
import cgeo.geocaching.utils.DebugUtils;
import cgeo.geocaching.utils.Log;
+import cgeo.geocaching.utils.RxUtils;
import org.apache.commons.lang3.StringUtils;
import org.openintents.intents.FileManagerIntents;
+import rx.functions.Action0;
+import rx.schedulers.Schedulers;
+
import android.app.ProgressDialog;
import android.app.backup.BackupManager;
import android.content.ActivityNotFoundException;
@@ -90,12 +94,14 @@ public class SettingsActivity extends PreferenceActivity {
setTheme(Settings.isLightSkin() && Build.VERSION.SDK_INT > 10 ? R.style.settings_light : R.style.settings);
super.onCreate(savedInstanceState);
- initHardwareAccelerationPreferences();
+ initDeviceSpecificPreferences();
+ initUnitPreferences();
SettingsActivity.addPreferencesFromResource(this, R.xml.preferences);
initPreferences();
final Intent intent = getIntent();
openInitialScreen(intent.getIntExtra(INTENT_OPEN_SCREEN, 0));
+ AndroidBeam.disable(this);
}
private void openInitialScreen(final int initialScreen) {
@@ -126,6 +132,7 @@ public class SettingsActivity extends PreferenceActivity {
initDefaultNavigationPreferences();
initBackupButtons();
initDbLocationPreference();
+ initGeoDirPreferences();
initDebugPreference();
initBasicMemberPreferences();
initSend2CgeoPreferences();
@@ -143,7 +150,6 @@ public class SettingsActivity extends PreferenceActivity {
R.string.pref_ecusername, R.string.pref_ecpassword, R.string.pref_ec_icons }) {
bindSummaryToStringValue(k);
}
- getPreference(R.string.pref_units).setDefaultValue(Settings.getImperialUnitsDefault());
}
private void initNavigationMenuPreferences() {
@@ -278,7 +284,7 @@ public class SettingsActivity extends PreferenceActivity {
/**
* Fire up a directory chooser on click on the preference.
*
- * @see #onActivityResult() for processing of the selected directory
+ * The result can be processed using {@link android.app.Activity#onActivityResult}.
*
* @param dct
* type of directory to be selected
@@ -297,7 +303,7 @@ public class SettingsActivity extends PreferenceActivity {
dirChooser.putExtra(FileManagerIntents.EXTRA_BUTTON_TEXT,
getString(android.R.string.ok));
startActivityForResult(dirChooser, dct.requestCode);
- } catch (final android.content.ActivityNotFoundException ex) {
+ } catch (final ActivityNotFoundException ignored) {
// OI file manager not available
final Intent dirChooser = new Intent(this, SimpleDirChooser.class);
dirChooser.putExtra(Intents.EXTRA_START_DIR, startDirectory);
@@ -323,13 +329,14 @@ public class SettingsActivity extends PreferenceActivity {
backup.setOnPreferenceClickListener(new OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(final Preference preference) {
- return DatabaseBackupUtils.createBackup(SettingsActivity.this, new Runnable() {
+ DatabaseBackupUtils.createBackup(SettingsActivity.this, new Runnable() {
@Override
public void run() {
VALUE_CHANGE_LISTENER.onPreferenceChange(SettingsActivity.this.getPreference(R.string.pref_fakekey_preference_backup_info), "");
}
});
+ return true;
}
});
@@ -354,37 +361,41 @@ public class SettingsActivity extends PreferenceActivity {
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() {
+ RxUtils.andThenOnUi(Schedulers.io(), new Action0() {
@Override
- public void run() {
+ public void call() {
DataStore.removeObsoleteCacheDirectories();
- activity.runOnUiThread(new Runnable() {
- @Override
- public void run() {
- dialog.dismiss();
- }
- });
}
- }.start();
-
+ }, new Action0() {
+ @Override
+ public void call() {
+ dialog.dismiss();
+ }
+ });
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;
- }
- });
+ @Override
+ public boolean onPreferenceClick(
+ final Preference preference) {
+ DebugUtils.createMemoryDump(SettingsActivity.this);
+ return true;
+ }
+ });
}
- public static void initHardwareAccelerationPreferences() {
- // We have to ensure that the preference is initialized so that devices with hardware acceleration disabled
- // get the appropriate value.
+ public static void initDeviceSpecificPreferences() {
+ // We have to ensure that those preferences are initialized so that devices with specific default values
+ // will get the appropriate ones.
Settings.setUseHardwareAcceleration(Settings.useHardwareAcceleration());
+ Settings.setUseGooglePlayServices(Settings.useGooglePlayServices());
+ }
+
+ private static void initUnitPreferences() {
+ Settings.setUseImperialUnits(Settings.useImperialUnits());
}
private void initDbLocationPreference() {
@@ -413,6 +424,28 @@ public class SettingsActivity extends PreferenceActivity {
});
}
+ private void initGeoDirPreferences() {
+ final Sensors sensors = Sensors.getInstance();
+ final Preference playServices = getPreference(R.string.pref_googleplayservices);
+ playServices.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
+ @Override
+ public boolean onPreferenceChange(final Preference preference, final Object newValue) {
+ sensors.setupGeoDataObservables((Boolean) newValue, Settings.useLowPowerMode());
+ return true;
+ }
+ });
+ playServices.setEnabled(CgeoApplication.getInstance().isGooglePlayServicesAvailable());
+ getPreference(R.string.pref_lowpowermode).setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
+ @Override
+ public boolean onPreferenceChange(final Preference preference, final Object newValue) {
+ final Boolean useLowPower = (Boolean) newValue;
+ sensors.setupGeoDataObservables(Settings.useGooglePlayServices(), useLowPower);
+ sensors.setupDirectionObservable(useLowPower);
+ return true;
+ }
+ });
+ }
+
void initBasicMemberPreferences() {
getPreference(R.string.preference_screen_basicmembers)
.setEnabled(!Settings.isGCPremiumMember());
@@ -570,7 +603,7 @@ public class SettingsActivity extends PreferenceActivity {
final int mapSourceId = Integer.parseInt(stringValue);
mapSource = MapProviderFactory.getMapSource(mapSourceId);
} catch (final NumberFormatException e) {
- Log.e("SettingsActivity.onPreferenceChange: bad source id '" + stringValue + "'");
+ Log.e("SettingsActivity.onPreferenceChange: bad source id '" + stringValue + "'", e);
mapSource = null;
}
// If there is no corresponding map source (because some map sources were
@@ -676,8 +709,6 @@ public class SettingsActivity extends PreferenceActivity {
/**
* auto-care for the summary of the preference of string type with this key
- *
- * @param key
*/
private void bindSummaryToStringValue(final int key) {