use of android.preference.ListPreference in project Anki-Android by Ramblurr.
the class Preferences method updateListPreference.
private void updateListPreference(String key) {
ListPreference listpref = (ListPreference) getPreferenceScreen().findPreference(key);
String entry;
try {
entry = listpref.getEntry().toString();
} catch (NullPointerException e) {
Log.e(AnkiDroidApp.TAG, "Error getting set preference value of " + key + ": " + e);
entry = "?";
}
if (mListsToUpdate.containsKey(key)) {
listpref.setSummary(replaceString(mListsToUpdate.get(key), entry));
} else {
String oldsum = (String) listpref.getSummary();
if (oldsum.contains("XXX")) {
mListsToUpdate.put(key, oldsum);
listpref.setSummary(replaceString(oldsum, entry));
} else {
listpref.setSummary(entry);
}
}
}
use of android.preference.ListPreference in project Anki-Android by Ramblurr.
the class DeckOptions method buildLists.
protected void buildLists() {
ListPreference deckConfPref = (ListPreference) findPreference("deckConf");
ArrayList<JSONObject> confs = mCol.getDecks().allConf();
Collections.sort(confs, new JSONNameComparator());
String[] confValues = new String[confs.size()];
String[] confLabels = new String[confs.size()];
try {
for (int i = 0; i < confs.size(); i++) {
JSONObject o = confs.get(i);
confValues[i] = o.getString("id");
confLabels[i] = o.getString("name");
}
} catch (JSONException e) {
throw new RuntimeException(e);
}
deckConfPref.setEntries(confLabels);
deckConfPref.setEntryValues(confValues);
deckConfPref.setValue(mPref.getString("deckConf", "0"));
ListPreference newOrderPref = (ListPreference) findPreference("newOrder");
newOrderPref.setEntries(R.array.new_order_labels);
newOrderPref.setEntryValues(R.array.new_order_values);
newOrderPref.setValue(mPref.getString("newOrder", "0"));
ListPreference leechActPref = (ListPreference) findPreference("lapLeechAct");
leechActPref.setEntries(R.array.leech_action_labels);
leechActPref.setEntryValues(R.array.leech_action_values);
leechActPref.setValue(mPref.getString("lapLeechAct", "0"));
}
use of android.preference.ListPreference in project Conversations by siacs.
the class SettingsActivity method onStart.
@Override
public void onStart() {
super.onStart();
PreferenceManager.getDefaultSharedPreferences(this).registerOnSharedPreferenceChangeListener(this);
ListPreference resources = (ListPreference) mSettingsFragment.findPreference("resource");
if (resources != null) {
ArrayList<CharSequence> entries = new ArrayList<>(Arrays.asList(resources.getEntries()));
if (!entries.contains(Build.MODEL)) {
entries.add(0, Build.MODEL);
resources.setEntries(entries.toArray(new CharSequence[entries.size()]));
resources.setEntryValues(entries.toArray(new CharSequence[entries.size()]));
}
}
if (Config.FORCE_ORBOT) {
PreferenceCategory connectionOptions = (PreferenceCategory) mSettingsFragment.findPreference("connection_options");
PreferenceScreen expert = (PreferenceScreen) mSettingsFragment.findPreference("expert");
if (connectionOptions != null) {
expert.removePreference(connectionOptions);
}
}
boolean removeLocation = new Intent("eu.siacs.conversations.location.request").resolveActivity(getPackageManager()) == null;
boolean removeVoice = new Intent(MediaStore.Audio.Media.RECORD_SOUND_ACTION).resolveActivity(getPackageManager()) == null;
ListPreference quickAction = (ListPreference) mSettingsFragment.findPreference("quick_action");
if (quickAction != null && (removeLocation || removeVoice)) {
ArrayList<CharSequence> entries = new ArrayList<>(Arrays.asList(quickAction.getEntries()));
ArrayList<CharSequence> entryValues = new ArrayList<>(Arrays.asList(quickAction.getEntryValues()));
int index = entryValues.indexOf("location");
if (index > 0 && removeLocation) {
entries.remove(index);
entryValues.remove(index);
}
index = entryValues.indexOf("voice");
if (index > 0 && removeVoice) {
entries.remove(index);
entryValues.remove(index);
}
quickAction.setEntries(entries.toArray(new CharSequence[entries.size()]));
quickAction.setEntryValues(entryValues.toArray(new CharSequence[entryValues.size()]));
}
final Preference removeCertsPreference = mSettingsFragment.findPreference("remove_trusted_certificates");
removeCertsPreference.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference preference) {
final MemorizingTrustManager mtm = xmppConnectionService.getMemorizingTrustManager();
final ArrayList<String> aliases = Collections.list(mtm.getCertificates());
if (aliases.size() == 0) {
displayToast(getString(R.string.toast_no_trusted_certs));
return true;
}
final ArrayList selectedItems = new ArrayList<>();
final AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(SettingsActivity.this);
dialogBuilder.setTitle(getResources().getString(R.string.dialog_manage_certs_title));
dialogBuilder.setMultiChoiceItems(aliases.toArray(new CharSequence[aliases.size()]), null, new DialogInterface.OnMultiChoiceClickListener() {
@Override
public void onClick(DialogInterface dialog, int indexSelected, boolean isChecked) {
if (isChecked) {
selectedItems.add(indexSelected);
} else if (selectedItems.contains(indexSelected)) {
selectedItems.remove(Integer.valueOf(indexSelected));
}
if (selectedItems.size() > 0)
((AlertDialog) dialog).getButton(DialogInterface.BUTTON_POSITIVE).setEnabled(true);
else {
((AlertDialog) dialog).getButton(DialogInterface.BUTTON_POSITIVE).setEnabled(false);
}
}
});
dialogBuilder.setPositiveButton(getResources().getString(R.string.dialog_manage_certs_positivebutton), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
int count = selectedItems.size();
if (count > 0) {
for (int i = 0; i < count; i++) {
try {
Integer item = Integer.valueOf(selectedItems.get(i).toString());
String alias = aliases.get(item);
mtm.deleteCertificate(alias);
} catch (KeyStoreException e) {
e.printStackTrace();
displayToast("Error: " + e.getLocalizedMessage());
}
}
if (xmppConnectionServiceBound) {
reconnectAccounts();
}
displayToast(getResources().getQuantityString(R.plurals.toast_delete_certificates, count, count));
}
}
});
dialogBuilder.setNegativeButton(getResources().getString(R.string.dialog_manage_certs_negativebutton), null);
AlertDialog removeCertsDialog = dialogBuilder.create();
removeCertsDialog.show();
removeCertsDialog.getButton(AlertDialog.BUTTON_POSITIVE).setEnabled(false);
return true;
}
});
final Preference exportLogsPreference = mSettingsFragment.findPreference("export_logs");
exportLogsPreference.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference preference) {
if (hasStoragePermission(REQUEST_WRITE_LOGS)) {
startExport();
}
return true;
}
});
if (Config.ONLY_INTERNAL_STORAGE) {
final Preference cleanCachePreference = mSettingsFragment.findPreference("clean_cache");
cleanCachePreference.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference preference) {
cleanCache();
return true;
}
});
final Preference cleanPrivateStoragePreference = mSettingsFragment.findPreference("clean_private_storage");
cleanPrivateStoragePreference.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference preference) {
cleanPrivateStorage();
return true;
}
});
}
final Preference deleteOmemoPreference = mSettingsFragment.findPreference("delete_omemo_identities");
deleteOmemoPreference.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
@Override
public boolean onPreferenceClick(Preference preference) {
deleteOmemoIdentities();
return true;
}
});
}
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();
}
Aggregations