use of android.preference.ListPreference in project platform_frameworks_base by android.
the class ListPreferenceTest method testListPreferenceSummaryFromEntries.
public void testListPreferenceSummaryFromEntries() {
String[] entries = { "one", "two", "three" };
String[] entryValues = { "1", "2", "3" };
ListPreference lp = new ListPreference(getContext());
lp.setEntries(entries);
lp.setEntryValues(entryValues);
lp.setValue(entryValues[1]);
assertTrue(lp.getSummary() == null);
lp.setSummary("%1$s");
assertEquals(entries[1], lp.getSummary());
lp.setValue(entryValues[2]);
assertEquals(entries[2], lp.getSummary());
lp.setSummary(null);
assertTrue(lp.getSummary() == null);
lp.setSummary("The color is %1$s");
assertEquals("The color is " + entries[2], lp.getSummary());
}
use of android.preference.ListPreference in project Timber by naman14.
the class SettingsFragment method onCreate.
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.preferences);
mPreferences = PreferencesUtility.getInstance(getActivity());
nowPlayingSelector = findPreference(NOW_PLAYING_SELECTOR);
lastFMlogin = findPreference(LASTFM_LOGIN);
updateLastFM();
// themePreference = (ListPreference) findPreference(KEY_THEME);
startPagePreference = (ListPreference) findPreference(KEY_START_PAGE);
nowPlayingSelector.setIntent(NavigationUtils.getNavigateToStyleSelectorIntent(getActivity(), Constants.SETTINGS_STYLE_SELECTOR_NOWPLAYING));
lastFMlogin.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference preference) {
if (lastFMlogedin) {
LastFmClient.getInstance(getActivity()).logout();
updateLastFM();
} else {
LastFmLoginDialog lastFmLoginDialog = new LastFmLoginDialog();
lastFmLoginDialog.setTargetFragment(SettingsFragment.this, 0);
lastFmLoginDialog.show(getFragmentManager(), LastFmLoginDialog.FRAGMENT_NAME);
}
return true;
}
});
PreferencesUtility.getInstance(getActivity()).setOnSharedPreferenceChangeListener(this);
setPreferenceClickListeners();
}
use of android.preference.ListPreference in project Etar-Calendar by Etar-Group.
the class GeneralPreferences method onCreate.
@Override
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
final Activity activity = getActivity();
// Make sure to always use the same preferences file regardless of the package name
// we're running under
final PreferenceManager preferenceManager = getPreferenceManager();
final SharedPreferences sharedPreferences = getSharedPreferences(activity);
preferenceManager.setSharedPreferencesName(SHARED_PREFS_NAME);
// Load the preferences from an XML resource
addPreferencesFromResource(R.xml.general_preferences);
final PreferenceScreen preferenceScreen = getPreferenceScreen();
mAlert = (CheckBoxPreference) preferenceScreen.findPreference(KEY_ALERTS);
mVibrate = (CheckBoxPreference) preferenceScreen.findPreference(KEY_ALERTS_VIBRATE);
Vibrator vibrator = (Vibrator) activity.getSystemService(Context.VIBRATOR_SERVICE);
if (vibrator == null || !vibrator.hasVibrator()) {
PreferenceCategory mAlertGroup = (PreferenceCategory) preferenceScreen.findPreference(KEY_ALERTS_CATEGORY);
mAlertGroup.removePreference(mVibrate);
}
mRingtone = (RingtonePreference) preferenceScreen.findPreference(KEY_ALERTS_RINGTONE);
String ringToneUri = Utils.getRingTonePreference(activity);
// Set the ringToneUri to the backup-able shared pref only so that
// the Ringtone dialog will open up with the correct value.
final Editor editor = preferenceScreen.getEditor();
editor.putString(GeneralPreferences.KEY_ALERTS_RINGTONE, ringToneUri).apply();
String ringtoneDisplayString = getRingtoneTitleFromUri(activity, ringToneUri);
mRingtone.setSummary(ringtoneDisplayString == null ? "" : ringtoneDisplayString);
mPopup = (CheckBoxPreference) preferenceScreen.findPreference(KEY_ALERTS_POPUP);
mUseHomeTZ = (CheckBoxPreference) preferenceScreen.findPreference(KEY_HOME_TZ_ENABLED);
mTheme = (ListPreference) preferenceScreen.findPreference(KEY_THEME_PREF);
mDefaultStart = (ListPreference) preferenceScreen.findPreference(KEY_DEFAULT_START);
mHideDeclined = (CheckBoxPreference) preferenceScreen.findPreference(KEY_HIDE_DECLINED);
mWeekStart = (ListPreference) preferenceScreen.findPreference(KEY_WEEK_START_DAY);
mDayWeek = (ListPreference) preferenceScreen.findPreference(KEY_DAYS_PER_WEEK);
mDefaultReminder = (ListPreference) preferenceScreen.findPreference(KEY_DEFAULT_REMINDER);
mHomeTZ = preferenceScreen.findPreference(KEY_HOME_TZ);
mSnoozeDelay = (ListPreference) preferenceScreen.findPreference(KEY_DEFAULT_SNOOZE_DELAY);
buildSnoozeDelayEntries();
mTheme.setSummary(mTheme.getEntry());
mWeekStart.setSummary(mWeekStart.getEntry());
mDayWeek.setSummary(mDayWeek.getEntry());
mDefaultReminder.setSummary(mDefaultReminder.getEntry());
mSnoozeDelay.setSummary(mSnoozeDelay.getEntry());
mDefaultStart.setSummary(mDefaultStart.getEntry());
// This triggers an asynchronous call to the provider to refresh the data in shared pref
mTimeZoneId = Utils.getTimeZone(activity, null);
SharedPreferences prefs = CalendarUtils.getSharedPreferences(activity, Utils.SHARED_PREFS_NAME);
// off, we will explicitly read it.
if (!prefs.getBoolean(KEY_HOME_TZ_ENABLED, false)) {
mTimeZoneId = prefs.getString(KEY_HOME_TZ, Time.getCurrentTimezone());
}
mHomeTZ.setOnPreferenceClickListener(new OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference preference) {
showTimezoneDialog();
return true;
}
});
if (mTzPickerUtils == null) {
mTzPickerUtils = new TimeZonePickerUtils(getActivity());
}
CharSequence timezoneName = mTzPickerUtils.getGmtDisplayName(getActivity(), mTimeZoneId, System.currentTimeMillis(), false);
mHomeTZ.setSummary(timezoneName != null ? timezoneName : mTimeZoneId);
TimeZonePickerDialog tzpd = (TimeZonePickerDialog) activity.getFragmentManager().findFragmentByTag(FRAG_TAG_TIME_ZONE_PICKER);
if (tzpd != null) {
tzpd.setOnTimeZoneSetListener(this);
}
migrateOldPreferences(sharedPreferences);
updateChildPreferences();
}
use of android.preference.ListPreference in project WordPress-Android by wordpress-mobile.
the class AppSettingsFragment method updateEditorSettings.
private void updateEditorSettings() {
if (!AppPrefs.isVisualEditorAvailable()) {
PreferenceScreen preferenceScreen = (PreferenceScreen) findPreference(getActivity().getString(R.string.pref_key_account_settings_root));
PreferenceCategory editor = (PreferenceCategory) findPreference(getActivity().getString(R.string.pref_key_editor));
if (preferenceScreen != null && editor != null) {
preferenceScreen.removePreference(editor);
}
} else {
final ListPreference editorTypePreference = (ListPreference) findPreference(getActivity().getString(R.string.pref_key_editor_type));
// If user has Aztec preference from previous installation and it's not available anymore, don't use it
if (!AppPrefs.isAztecEditorAvailable() && "2".equals(editorTypePreference.getValue())) {
if (AppPrefs.isVisualEditorEnabled()) {
editorTypePreference.setValue("1");
} else {
editorTypePreference.setValue("0");
}
}
// if Aztec unavailable, only show the old list old of editors
if (!AppPrefs.isAztecEditorAvailable()) {
editorTypePreference.setEntries(R.array.editor_entries_without_aztec);
editorTypePreference.setEntryValues(R.array.editor_values_without_aztec);
}
editorTypePreference.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(final Preference preference, final Object value) {
if (value != null) {
int index = Integer.parseInt(value.toString());
CharSequence[] entries = editorTypePreference.getEntries();
editorTypePreference.setSummary(entries[index]);
switch(index) {
case 1:
AppPrefs.setAztecEditorEnabled(false);
AppPrefs.setVisualEditorEnabled(true);
break;
case 2:
AppPrefs.setAztecEditorEnabled(true);
AppPrefs.setVisualEditorEnabled(false);
break;
default:
AppPrefs.setAztecEditorEnabled(false);
AppPrefs.setVisualEditorEnabled(false);
break;
}
return true;
} else {
return false;
}
}
});
String editorTypeKey = getString(R.string.pref_key_editor_type);
String editorTypeSetting = mSettings.getString(editorTypeKey, "");
if (!editorTypeSetting.equalsIgnoreCase("")) {
CharSequence[] entries = editorTypePreference.getEntries();
editorTypePreference.setSummary(entries[Integer.parseInt(editorTypeSetting)]);
}
}
}
use of android.preference.ListPreference in project AntennaPod by AntennaPod.
the class PreferenceController method buildSmartMarkAsPlayedPreference.
private void buildSmartMarkAsPlayedPreference() {
final Resources res = ui.getActivity().getResources();
ListPreference pref = (ListPreference) ui.findPreference(UserPreferences.PREF_SMART_MARK_AS_PLAYED_SECS);
String[] values = res.getStringArray(R.array.smart_mark_as_played_values);
String[] entries = new String[values.length];
for (int x = 0; x < values.length; x++) {
if (x == 0) {
entries[x] = res.getString(R.string.pref_smart_mark_as_played_disabled);
} else {
Integer v = Integer.parseInt(values[x]);
if (v < 60) {
entries[x] = res.getQuantityString(R.plurals.time_seconds_quantified, v, v);
} else {
v /= 60;
entries[x] = res.getQuantityString(R.plurals.time_minutes_quantified, v, v);
}
}
}
pref.setEntries(entries);
}
Aggregations