Search in sources :

Example 46 with ListPreference

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);
        }
    }
}
Also used : ListPreference(android.preference.ListPreference)

Example 47 with ListPreference

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"));
}
Also used : JSONObject(org.json.JSONObject) JSONException(org.json.JSONException) ListPreference(android.preference.ListPreference)

Example 48 with ListPreference

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;
        }
    });
}
Also used : AlertDialog(android.app.AlertDialog) PreferenceScreen(android.preference.PreferenceScreen) DialogInterface(android.content.DialogInterface) ArrayList(java.util.ArrayList) Intent(android.content.Intent) ListPreference(android.preference.ListPreference) KeyStoreException(java.security.KeyStoreException) MemorizingTrustManager(de.duenndns.ssl.MemorizingTrustManager) PreferenceCategory(android.preference.PreferenceCategory) ListPreference(android.preference.ListPreference) Preference(android.preference.Preference)

Example 49 with ListPreference

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();
}
Also used : LastFmLoginDialog(com.naman14.timber.dialogs.LastFmLoginDialog) ListPreference(android.preference.ListPreference) Preference(android.preference.Preference) ATECheckBoxPreference(com.afollestad.appthemeengine.prefs.ATECheckBoxPreference) ATEColorPreference(com.afollestad.appthemeengine.prefs.ATEColorPreference) SwitchPreference(android.preference.SwitchPreference)

Example 50 with ListPreference

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();
}
Also used : PreferenceScreen(android.preference.PreferenceScreen) SharedPreferences(android.content.SharedPreferences) Activity(android.app.Activity) PreferenceManager(android.preference.PreferenceManager) OnPreferenceClickListener(android.preference.Preference.OnPreferenceClickListener) PreferenceCategory(android.preference.PreferenceCategory) CheckBoxPreference(android.preference.CheckBoxPreference) RingtonePreference(android.preference.RingtonePreference) ListPreference(android.preference.ListPreference) Preference(android.preference.Preference) TimeZonePickerUtils(com.android.timezonepicker.TimeZonePickerUtils) TimeZonePickerDialog(com.android.timezonepicker.TimeZonePickerDialog) Vibrator(android.os.Vibrator) Editor(android.content.SharedPreferences.Editor)

Aggregations

ListPreference (android.preference.ListPreference)60 Preference (android.preference.Preference)27 CheckBoxPreference (android.preference.CheckBoxPreference)20 EditTextPreference (android.preference.EditTextPreference)16 PreferenceScreen (android.preference.PreferenceScreen)12 PreferenceCategory (android.preference.PreferenceCategory)8 SharedPreferences (android.content.SharedPreferences)7 Intent (android.content.Intent)6 Resources (android.content.res.Resources)5 OnPreferenceClickListener (android.preference.Preference.OnPreferenceClickListener)5 DialogInterface (android.content.DialogInterface)4 OnPreferenceChangeListener (android.preference.Preference.OnPreferenceChangeListener)4 ArrayList (java.util.ArrayList)4 SuppressLint (android.annotation.SuppressLint)3 View (android.view.View)3 File (java.io.File)3 Activity (android.app.Activity)2 AlertDialog (android.app.AlertDialog)2 PackageManager (android.content.pm.PackageManager)2 Bundle (android.os.Bundle)2