Search in sources :

Example 51 with ListPreference

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

Example 52 with ListPreference

use of android.preference.ListPreference in project AisenWeiBo by wangdan.

the class BasicItemSettingsFragment method onActivityCreated.

@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    addPreferencesFromResource(R.xml.ui_basic_settings_item);
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(GlobalContext.getInstance());
    int value = 0;
    // 主题
    pTheme = (Preference) findPreference("pTheme");
    pTheme.setOnPreferenceClickListener(this);
    pTheme.setSummary(getResources().getStringArray(R.array.mdColorNames)[AppSettings.getThemeColor()]);
    //        findPreference("pThemeCustom").setOnPreferenceClickListener(this);
    pFastScrollBar = (CheckBoxPreference) findPreference("pFastScrollBar");
    if (pFastScrollBar != null)
        pFastScrollBar.setOnPreferenceChangeListener(this);
    pPicSavePath = (Preference) findPreference("pPicSavePath");
    pPicSavePath.setOnPreferenceClickListener(this);
    //		pPicSavePath.setSummary(SystemUtility.getSdcardPath() + File.separator + AppSettings.getImageSavePath() + File.separator);
    pPicSavePath.setSummary("/sdcard" + File.separator + AppSettings.getImageSavePath() + File.separator);
    pClearRecentMention = (Preference) findPreference("pClearRecentMention");
    pClearRecentMention.setOnPreferenceClickListener(this);
    setMentionHint();
    pTextSize = (ListPreference) findPreference("pTextSize");
    pTextSize.setOnPreferenceChangeListener(this);
    value = Integer.parseInt(prefs.getString("pTextSize", "4"));
    setTextSize(value);
    pShowRemark = (CheckBoxPreference) findPreference("pShowRemark");
    pShowRemark.setOnPreferenceChangeListener(this);
    pShowDefGroup = (CheckBoxPreference) findPreference("pShowDefGroup");
    if (pShowDefGroup != null)
        pShowDefGroup.setOnPreferenceChangeListener(this);
    //        CheckBoxPreference pDoubleClickToRefresh = (CheckBoxPreference) findPreference("pDoubleClickToRefresh");
    //		pDoubleClickToRefresh.setOnPreferenceChangeListener(this);
    pAutoRefresh = (CheckBoxPreference) findPreference("pAutoRefresh");
    pAutoRefresh.setOnPreferenceChangeListener(this);
    pAutoRefresh.setChecked(SettingUtility.getPermanentSettingAsBool("pAutoRefresh", true));
    pSwipebackEdgeMode = (ListPreference) findPreference("pSwipebackEdgeMode");
    pSwipebackEdgeMode.setOnPreferenceChangeListener(this);
    value = Integer.parseInt(prefs.getString("pSwipebackEdgeMode", "0"));
    setListSetting(value, R.array.swipebackEdgeMode, pSwipebackEdgeMode);
    //        pFabType = (ListPreference) findPreference("pFabType");
    //        pFabType.setOnPreferenceChangeListener(this);
    //        value = Integer.parseInt(prefs.getString("pFabType", "0"));
    //        setListSetting(value, R.array.fabTypes, pFabType);
    pFabPosition = (ListPreference) findPreference("pFabPosition");
    if (pFabPosition != null) {
        pFabPosition.setOnPreferenceChangeListener(this);
        value = Integer.parseInt(prefs.getString("pFabPosition", "1"));
        setListSetting(value, R.array.fabPosition, pFabPosition);
    }
    // 缓存清理
    Preference pClearCache = (Preference) findPreference("pClearCache");
    CacheClearFragment clearFragment = (CacheClearFragment) getActivity().getFragmentManager().findFragmentByTag("CacheClearFragment");
    if (clearFragment == null) {
        clearFragment = new CacheClearFragment();
        getActivity().getFragmentManager().beginTransaction().add(clearFragment, "CacheClearFragment").commit();
    }
    clearFragment.setPreference(pClearCache, MyApplication.getImagePath());
}
Also used : SharedPreferences(android.content.SharedPreferences) CheckBoxPreference(android.preference.CheckBoxPreference) ListPreference(android.preference.ListPreference) Preference(android.preference.Preference) SuppressLint(android.annotation.SuppressLint)

Example 53 with ListPreference

use of android.preference.ListPreference in project pictureapp by EyeSeeTea.

the class SettingsActivity method setLanguageOptions.

/**
     * Sets the application languages and populate the language in the preference
     */
private static void setLanguageOptions(Preference preference) {
    ListPreference listPreference = (ListPreference) preference;
    HashMap<String, String> languages = getAppLanguages(R.string.system_defined);
    CharSequence[] newEntries = new CharSequence[languages.size() + 1];
    CharSequence[] newValues = new CharSequence[languages.size() + 1];
    int i = 0;
    newEntries[i] = PreferencesState.getInstance().getContext().getString(R.string.system_defined);
    newValues[i] = "";
    for (String language : languages.keySet()) {
        i++;
        String languageCode = languages.get(language);
        String firstLetter = language.substring(0, 1).toUpperCase();
        language = firstLetter + language.substring(1, language.length());
        newEntries[i] = language;
        newValues[i] = languageCode;
    }
    listPreference.setEntries(newEntries);
    listPreference.setEntryValues(newValues);
}
Also used : ListPreference(android.preference.ListPreference)

Example 54 with ListPreference

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);
}
Also used : Resources(android.content.res.Resources) ListPreference(android.preference.ListPreference) SuppressLint(android.annotation.SuppressLint)

Example 55 with ListPreference

use of android.preference.ListPreference in project AntennaPod by AntennaPod.

the class PreferenceController method buildEpisodeCleanupPreference.

private void buildEpisodeCleanupPreference() {
    final Resources res = ui.getActivity().getResources();
    ListPreference pref = (ListPreference) ui.findPreference(UserPreferences.PREF_EPISODE_CLEANUP);
    String[] values = res.getStringArray(R.array.episode_cleanup_values);
    String[] entries = new String[values.length];
    for (int x = 0; x < values.length; x++) {
        int v = Integer.parseInt(values[x]);
        if (v == UserPreferences.EPISODE_CLEANUP_QUEUE) {
            entries[x] = res.getString(R.string.episode_cleanup_queue_removal);
        } else if (v == UserPreferences.EPISODE_CLEANUP_NULL) {
            entries[x] = res.getString(R.string.episode_cleanup_never);
        } else if (v == 0) {
            entries[x] = res.getString(R.string.episode_cleanup_after_listening);
        } else {
            entries[x] = res.getQuantityString(R.plurals.episode_cleanup_days_after_listening, v, v);
        }
    }
    pref.setEntries(entries);
}
Also used : Resources(android.content.res.Resources) ListPreference(android.preference.ListPreference) SuppressLint(android.annotation.SuppressLint)

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