List of usage examples for android.preference Preference isPersistent
public boolean isPersistent()
From source file:be.deadba.ampd.SettingsActivity.java
/** * A preference value change listener that updates the preference's summary * to reflect its new value./* ww w .j a v a 2 s . c o m*/ */ @Override public boolean onPreferenceChange(Preference preference, Object value) { String stringValue = value.toString(); String key = preference.getKey(); Log.d(TAG, "onPreferenceChange: key: " + key + " / value: " + stringValue); if (preference.isPersistent()) { Editor editor = MPDConf.getSharedPreferences(this).edit(); if (value instanceof Boolean) editor.putBoolean(key, (Boolean) value); else editor.putString(key, (String) value); editor.commit(); } if (key.equals("run")) { mRunPreference = (TwoStatePreference) preference; mRun = stringValue.equals("true"); onMPDStatePreferenceChange(false); return true; } if (key.equals("run_on_boot")) { mRunOnBootPreference = (TwoStatePreference) preference; mRunOnBoot = stringValue.equals("true"); if (mRunOnBoot) mRun = true; onMPDStatePreferenceChange(false); return true; } else if (key.equals("wakelock")) { onMPDStatePreferenceChange(true); return true; } else if (key.equals("mpd_music_directory")) { File file = new File(stringValue); mDirValid = file.exists() && file.isDirectory() && file.canRead() && file.canExecute(); onMPDStatePreferenceChange(true); } else if (key.equals("mpd_port")) { int port = 0; try { port = Integer.parseInt(stringValue); } catch (NumberFormatException e) { } mPortValid = port >= 1024 && port <= 65535; if (mPortValid) mPort = String.valueOf(port); onMPDStatePreferenceChange(true); } else if (key.equals("mpd_mixer")) { onMPDStatePreferenceChange(true); return true; } else if (key.equals("mpd_output")) { onMPDStatePreferenceChange(true); } 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); // Set the summary to reflect the new value. preference.setSummary(index >= 0 ? listPreference.getEntries()[index] : null); } else { // For all other preferences, set the summary to the value's // simple string representation. preference.setSummary(stringValue); } return true; }