Search in sources :

Example 81 with ListPreference

use of android.preference.ListPreference in project k-9 by k9mail.

the class K9PreferenceActivity method setupListPreference.

/**
     * Set up the {@link ListPreference} instance identified by {@code key}.
     *
     * @param key
     *         The key of the {@link ListPreference} object.
     * @param value
     *         Initial value for the {@link ListPreference} object.
     *
     * @return The {@link ListPreference} instance identified by {@code key}.
     */
protected ListPreference setupListPreference(final String key, final String value) {
    final ListPreference prefView = (ListPreference) findPreference(key);
    prefView.setValue(value);
    prefView.setSummary(prefView.getEntry());
    prefView.setOnPreferenceChangeListener(new PreferenceChangeListener(prefView));
    return prefView;
}
Also used : ListPreference(android.preference.ListPreference)

Example 82 with ListPreference

use of android.preference.ListPreference in project material-dialogs by afollestad.

the class MaterialListPreference method showDialog.

@Override
protected void showDialog(Bundle state) {
    if (getEntries() == null || getEntryValues() == null) {
        throw new IllegalStateException("ListPreference requires an entries array and an entryValues array.");
    }
    int preselect = findIndexOfValue(getValue());
    MaterialDialog.Builder builder = new MaterialDialog.Builder(context).title(getDialogTitle()).icon(getDialogIcon()).dismissListener(this).onAny(new MaterialDialog.SingleButtonCallback() {

        @Override
        public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
            switch(which) {
                default:
                    MaterialListPreference.this.onClick(dialog, DialogInterface.BUTTON_POSITIVE);
                    break;
                case NEUTRAL:
                    MaterialListPreference.this.onClick(dialog, DialogInterface.BUTTON_NEUTRAL);
                    break;
                case NEGATIVE:
                    MaterialListPreference.this.onClick(dialog, DialogInterface.BUTTON_NEGATIVE);
                    break;
            }
        }
    }).negativeText(getNegativeButtonText()).items(getEntries()).autoDismiss(// immediately close the dialog after selection
    true).itemsCallbackSingleChoice(preselect, new MaterialDialog.ListCallbackSingleChoice() {

        @Override
        public boolean onSelection(MaterialDialog dialog, View itemView, int which, CharSequence text) {
            onClick(null, DialogInterface.BUTTON_POSITIVE);
            if (which >= 0 && getEntryValues() != null) {
                try {
                    Field clickedIndex = ListPreference.class.getDeclaredField("mClickedDialogEntryIndex");
                    clickedIndex.setAccessible(true);
                    clickedIndex.set(MaterialListPreference.this, which);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
            return true;
        }
    });
    final View contentView = onCreateDialogView();
    if (contentView != null) {
        onBindDialogView(contentView);
        builder.customView(contentView, false);
    } else {
        builder.content(getDialogMessage());
    }
    PrefUtil.registerOnActivityDestroyListener(this, this);
    dialog = builder.build();
    if (state != null) {
        dialog.onRestoreInstanceState(state);
    }
    onClick(dialog, DialogInterface.BUTTON_NEGATIVE);
    dialog.show();
}
Also used : MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) ListPreference(android.preference.ListPreference) RecyclerView(android.support.v7.widget.RecyclerView) View(android.view.View) Field(java.lang.reflect.Field) DialogAction(com.afollestad.materialdialogs.DialogAction)

Example 83 with ListPreference

use of android.preference.ListPreference in project SeriesGuide by UweTrottmann.

the class ListWidgetPreferenceFragment method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    // use the settings file specific to widgets
    getPreferenceManager().setSharedPreferencesName(WidgetSettings.SETTINGS_FILE);
    getPreferenceManager().setSharedPreferencesMode(0);
    // create a widget specific settings screen
    PreferenceScreen preferenceScreen = getPreferenceManager().createPreferenceScreen(getActivity());
    int appWidgetId = getArguments().getInt("appWidgetId");
    // widget type setting
    final ListPreference typePref = new ListPreference(getActivity());
    typePref.setKey(WidgetSettings.KEY_PREFIX_WIDGET_LISTTYPE + appWidgetId);
    typePref.setTitle(R.string.pref_widget_type);
    typePref.setEntries(R.array.widgetType);
    typePref.setEntryValues(R.array.widgetTypeData);
    typePref.setDefaultValue(getString(R.string.widget_default_type));
    typePref.setPositiveButtonText(null);
    typePref.setNegativeButtonText(null);
    preferenceScreen.addPreference(typePref);
    // widget show type sort order setting
    final ListPreference sortPref = new ListPreference(getActivity());
    sortPref.setKey(WidgetSettings.KEY_PREFIX_WIDGET_SHOWS_SORT_ORDER + appWidgetId);
    sortPref.setTitle(R.string.action_shows_sort);
    sortPref.setEntries(R.array.widgetShowSortOrder);
    sortPref.setEntryValues(R.array.widgetShowSortOrderData);
    sortPref.setDefaultValue(getString(R.string.widget_default_show_sort_order));
    sortPref.setPositiveButtonText(null);
    sortPref.setNegativeButtonText(null);
    preferenceScreen.addPreference(sortPref);
    // only favorite shows setting
    final CheckBoxPreference onlyFavoritesPref = new CheckBoxPreference(getActivity());
    onlyFavoritesPref.setKey(WidgetSettings.KEY_PREFIX_WIDGET_ONLY_FAVORITES + appWidgetId);
    onlyFavoritesPref.setTitle(R.string.only_favorites);
    onlyFavoritesPref.setDefaultValue(false);
    preferenceScreen.addPreference(onlyFavoritesPref);
    // hide watched setting
    final CheckBoxPreference hideWatchedPreference = new CheckBoxPreference(getActivity());
    hideWatchedPreference.setKey(WidgetSettings.KEY_PREFIX_WIDGET_HIDE_WATCHED + appWidgetId);
    hideWatchedPreference.setTitle(R.string.hide_watched);
    hideWatchedPreference.setDefaultValue(true);
    preferenceScreen.addPreference(hideWatchedPreference);
    // widget theme setting
    ListPreference themePref = new ListPreference(getActivity());
    themePref.setKey(WidgetSettings.KEY_PREFIX_WIDGET_THEME + appWidgetId);
    themePref.setTitle(R.string.pref_theme);
    themePref.setEntries(R.array.widgetTheme);
    themePref.setEntryValues(R.array.widgetThemeData);
    themePref.setDefaultValue("0");
    themePref.setPositiveButtonText(null);
    themePref.setNegativeButtonText(null);
    preferenceScreen.addPreference(themePref);
    // background setting
    ListPreference backgroundPref = new ListPreference(getActivity());
    backgroundPref.setKey(WidgetSettings.KEY_PREFIX_WIDGET_BACKGROUND_OPACITY + appWidgetId);
    backgroundPref.setTitle(R.string.pref_widget_opacity);
    backgroundPref.setEntries(R.array.widgetOpacity);
    backgroundPref.setEntryValues(R.array.widgetOpacityData);
    backgroundPref.setDefaultValue(WidgetSettings.DEFAULT_WIDGET_BACKGROUND_OPACITY);
    backgroundPref.setPositiveButtonText(null);
    backgroundPref.setNegativeButtonText(null);
    preferenceScreen.addPreference(backgroundPref);
    setPreferenceScreen(preferenceScreen);
    bindPreferenceSummaryToValue(getPreferenceManager().getSharedPreferences(), typePref);
    bindPreferenceSummaryToValue(getPreferenceManager().getSharedPreferences(), sortPref);
    bindPreferenceSummaryToValue(getPreferenceManager().getSharedPreferences(), backgroundPref);
    bindPreferenceSummaryToValue(getPreferenceManager().getSharedPreferences(), themePref);
    // disable type and background pref for non-supporters
    if (!Utils.hasAccessToX(getActivity())) {
        typePref.setEnabled(false);
        typePref.setSummary(R.string.onlyx);
        themePref.setEnabled(false);
        themePref.setSummary(R.string.onlyx);
        backgroundPref.setEnabled(false);
        backgroundPref.setSummary(R.string.onlyx);
    }
    // disable episode related setting if selecting show widget type
    preferenceChangeListener = new SharedPreferences.OnSharedPreferenceChangeListener() {

        @Override
        public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
            if (!isAdded()) {
                // no longer attached to activity
                return;
            }
            if (typePref.getKey().equals(key)) {
                String newTypeValue = typePref.getValue();
                boolean displayingShows = getString(R.string.widget_type_shows).equals(newTypeValue);
                sortPref.setEnabled(displayingShows);
                hideWatchedPreference.setEnabled(!displayingShows);
            }
        }
    };
    // trigger the listener to handle the current state
    preferenceChangeListener.onSharedPreferenceChanged(getPreferenceManager().getSharedPreferences(), typePref.getKey());
    getPreferenceManager().getSharedPreferences().registerOnSharedPreferenceChangeListener(preferenceChangeListener);
}
Also used : PreferenceScreen(android.preference.PreferenceScreen) CheckBoxPreference(android.preference.CheckBoxPreference) SharedPreferences(android.content.SharedPreferences) ListPreference(android.preference.ListPreference)

Example 84 with ListPreference

use of android.preference.ListPreference in project SeriesGuide by UweTrottmann.

the class AmazonConfigurationFragment method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    // use the Amazon extension settings file
    getPreferenceManager().setSharedPreferencesName(AmazonSettings.SETTINGS_FILE);
    getPreferenceManager().setSharedPreferencesMode(0);
    // create a preference screen
    PreferenceScreen preferenceScreen = getPreferenceManager().createPreferenceScreen(getActivity());
    ListPreference countryPreference = new ListPreference(getActivity());
    countryPreference.setKey(AmazonSettings.KEY_COUNTRY);
    countryPreference.setTitle(R.string.pref_amazon_domain);
    countryPreference.setEntries(R.array.amazonDomainsData);
    countryPreference.setEntryValues(R.array.amazonDomainsData);
    countryPreference.setDefaultValue(AmazonSettings.DEFAULT_DOMAIN);
    countryPreference.setPositiveButtonText(null);
    countryPreference.setNegativeButtonText(null);
    preferenceScreen.addPreference(countryPreference);
    setPreferenceScreen(preferenceScreen);
    bindPreferenceSummaryToValue(getPreferenceManager().getSharedPreferences(), countryPreference);
}
Also used : PreferenceScreen(android.preference.PreferenceScreen) ListPreference(android.preference.ListPreference)

Example 85 with ListPreference

use of android.preference.ListPreference in project qksms by moezbhatti.

the class SettingsFragment method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Bundle args = getArguments();
    setHasOptionsMenu(true);
    mContext = (QKActivity) getActivity();
    mPrefs = mContext.getPrefs();
    mRes = mContext.getResources();
    mContext.setTitle(R.string.title_settings);
    mResource = args.getInt("category", R.xml.settings);
    addPreferencesFromResource(mResource);
    // Set `this` to be the preferences click/change listener for all the preferences.
    PreferenceScreen screen = getPreferenceScreen();
    for (int i = 0; i < screen.getPreferenceCount(); i++) {
        Preference pref = screen.getPreference(i);
        pref.setOnPreferenceClickListener(this);
        pref.setOnPreferenceChangeListener(this);
        // well.
        if (pref instanceof PreferenceCategory) {
            Stack<PreferenceCategory> stack = new Stack<>();
            stack.push((PreferenceCategory) pref);
            do {
                PreferenceCategory category = stack.pop();
                for (int j = 0; j < category.getPreferenceCount(); j++) {
                    Preference subPref = category.getPreference(j);
                    subPref.setOnPreferenceClickListener(this);
                    subPref.setOnPreferenceChangeListener(this);
                    if (subPref instanceof PreferenceCategory) {
                        stack.push((PreferenceCategory) subPref);
                    }
                }
            } while (!stack.isEmpty());
        }
    }
    Preference icon = findPreference(ICON);
    if (icon != null) {
        icon.setOnPreferenceClickListener(this);
    }
    mThemeLed = findPreference(NOTIFICATION_LED_COLOR);
    if (mThemeLed != null) {
        mLedColors = new int[] { mRes.getColor(R.color.blue_light), mRes.getColor(R.color.purple_light), mRes.getColor(R.color.green_light), mRes.getColor(R.color.yellow_light), mRes.getColor(R.color.red_light), mRes.getColor(R.color.white_pure) };
        mLedColorPickerDialog = new ColorPickerDialog();
        mLedColorPickerDialog.initialize(R.string.pref_theme_led, mLedColors, Integer.parseInt(mPrefs.getString(NOTIFICATION_LED_COLOR, "-48060")), 3, 2);
        mLedColorPickerDialog.setOnColorSelectedListener(new ColorPickerSwatch.OnColorSelectedListener() {

            @Override
            public void onColorSelected(int color) {
                mPrefs.edit().putString(mThemeLed.getKey(), "" + color).apply();
                onPreferenceChange(findPreference(mThemeLed.getKey()), color);
            }
        });
    }
    ListPreference font_family = (ListPreference) findPreference(FONT_FAMILY);
    if (font_family != null) {
        mFontFamilies = mRes.getStringArray(R.array.font_families);
        font_family.setSummary(mFontFamilies[Integer.parseInt(font_family.getValue())]);
    }
    ListPreference font_size = (ListPreference) findPreference(FONT_SIZE);
    if (font_size != null) {
        mFontSizes = mRes.getStringArray(R.array.font_sizes);
        font_size.setSummary(mFontSizes[Integer.parseInt(font_size.getValue())]);
    }
    ListPreference font_weight = (ListPreference) findPreference(FONT_WEIGHT);
    if (font_weight != null) {
        mFontWeights = mRes.getStringArray(R.array.font_weights);
        int i = Integer.parseInt(font_weight.getValue());
        font_weight.setSummary(mFontWeights[i == 2 ? 0 : 1]);
    }
    EditTextPreference deleteUnread = (EditTextPreference) findPreference(DELETE_UNREAD_MESSAGES);
    if (deleteUnread != null) {
        deleteUnread.setSummary(mContext.getString(R.string.pref_delete_old_messages_unread_summary, QKPreferences.getString(QKPreference.AUTO_DELETE_UNREAD)));
    }
    EditTextPreference deleteRead = (EditTextPreference) findPreference(DELETE_READ_MESSAGES);
    if (deleteRead != null) {
        deleteRead.setSummary(mContext.getString(R.string.pref_delete_old_messages_read_summary, QKPreferences.getString(QKPreference.AUTO_DELETE_READ)));
    }
    Preference day_start = findPreference(DAY_START);
    if (day_start != null) {
        day_start.setSummary(DateFormatter.getSummaryTimestamp(mContext, mPrefs.getString(DAY_START, "6:00")));
    }
    Preference night_start = findPreference(NIGHT_START);
    if (night_start != null) {
        night_start.setSummary(DateFormatter.getSummaryTimestamp(mContext, mPrefs.getString(NIGHT_START, "21:00")));
    }
    mMmscUrl = (EditTextPreference) findPreference(MMSC_URL);
    if (mMmscUrl != null) {
        mMmscUrl.setSummary(mMmscUrl.getText());
    }
    mMmsProxy = (EditTextPreference) findPreference(MMS_PROXY);
    if (mMmsProxy != null) {
        mMmsProxy.setSummary(mMmsProxy.getText());
    }
    mMmsPort = (EditTextPreference) findPreference(MMS_PORT);
    if (mMmsPort != null) {
        mMmsPort.setSummary(mMmsPort.getText());
    }
    mMaxMmsAttachmentSize = (ListPreference) findPreference(MAX_MMS_ATTACHMENT_SIZE);
    if (mMaxMmsAttachmentSize != null) {
        mMaxMmsAttachmentSizes = mRes.getStringArray(R.array.max_mms_attachment_sizes);
        String value = mMaxMmsAttachmentSize.getValue();
        String summary = mMaxMmsAttachmentSizes[mMaxMmsAttachmentSize.findIndexOfValue(value)];
        mMaxMmsAttachmentSize.setSummary(summary);
    }
    Preference version = findPreference(VERSION);
    if (version != null) {
        String v = "unknown";
        try {
            PackageInfo info = mContext.getPackageManager().getPackageInfo(mContext.getPackageName(), 0);
            v = info.versionName;
        } catch (PackageManager.NameNotFoundException e) {
            e.printStackTrace();
        }
        version.setSummary(v);
    }
    // Status and nav bar tinting are only supported on kit kat or above.
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
        removePreference(CATEGORY_APPEARANCE_SYSTEM_BARS);
    }
}
Also used : PreferenceScreen(android.preference.PreferenceScreen) Bundle(android.os.Bundle) PackageInfo(android.content.pm.PackageInfo) ListPreference(android.preference.ListPreference) EditTextPreference(android.preference.EditTextPreference) Stack(java.util.Stack) ColorPickerDialog(com.moez.QKSMS.ui.view.colorpicker.ColorPickerDialog) PackageManager(android.content.pm.PackageManager) EditTextPreference(android.preference.EditTextPreference) ListPreference(android.preference.ListPreference) QKPreference(com.moez.QKSMS.enums.QKPreference) CheckBoxPreference(android.preference.CheckBoxPreference) Preference(android.preference.Preference) PreferenceCategory(android.preference.PreferenceCategory) ColorPickerSwatch(com.moez.QKSMS.ui.view.colorpicker.ColorPickerSwatch)

Aggregations

ListPreference (android.preference.ListPreference)167 Preference (android.preference.Preference)80 CheckBoxPreference (android.preference.CheckBoxPreference)50 EditTextPreference (android.preference.EditTextPreference)35 PreferenceScreen (android.preference.PreferenceScreen)21 SharedPreferences (android.content.SharedPreferences)20 ArrayList (java.util.ArrayList)19 Intent (android.content.Intent)16 PreferenceCategory (android.preference.PreferenceCategory)16 SuppressLint (android.annotation.SuppressLint)13 OnPreferenceChangeListener (android.preference.Preference.OnPreferenceChangeListener)9 MultiSelectListPreference (android.preference.MultiSelectListPreference)8 OnPreferenceClickListener (android.preference.Preference.OnPreferenceClickListener)8 File (java.io.File)8 Bundle (android.os.Bundle)7 SwitchPreference (android.preference.SwitchPreference)7 View (android.view.View)7 Context (android.content.Context)6 DialogInterface (android.content.DialogInterface)6 RingtonePreference (android.preference.RingtonePreference)6