当前位置: 首页>>代码示例>>Java>>正文


Java Preference.OnPreferenceChangeListener方法代码示例

本文整理汇总了Java中android.preference.Preference.OnPreferenceChangeListener方法的典型用法代码示例。如果您正苦于以下问题:Java Preference.OnPreferenceChangeListener方法的具体用法?Java Preference.OnPreferenceChangeListener怎么用?Java Preference.OnPreferenceChangeListener使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在android.preference.Preference的用法示例。


在下文中一共展示了Preference.OnPreferenceChangeListener方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: onCreate

import android.preference.Preference; //导入方法依赖的package包/类
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    addPreferencesFromResource(R.xml.preference_settings);
    mSp = PreferenceManager.getDefaultSharedPreferences(getActivity());
    mSpEditor = mSp.edit();
    mSpEditor.apply();
    launchService = new Preference.OnPreferenceChangeListener() {
        @Override
        public boolean onPreferenceChange(Preference p, Object o) {
            BaseMethod.RestartAccessibilityService(getActivity());
            return true;
        }
    };
    GeneralSettings();
    ActivityBlockSettings();
    NotificationSettings();
    RootSettings();
    NSettings();
    CustomSettings();
}
 
开发者ID:XFY9326,项目名称:KeyBlocker,代码行数:22,代码来源:SettingsActivity.java

示例2: onCreate

import android.preference.Preference; //导入方法依赖的package包/类
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    addPreferencesFromResource(R.xml.anim_preferences);
    setHasOptionsMenu(true);

    Preference.OnPreferenceChangeListener checkInteger = new Preference.OnPreferenceChangeListener() {
        @Override
        public boolean onPreferenceChange(Preference preference, Object newValue) {
            try {
                int value = Integer.parseInt(newValue.toString());
                //if parsable without throwing errors
                return true;
            } catch (NumberFormatException e) {
                return false;
            }
        }
    };

    Preference burgerCount = getPreferenceScreen().findPreference("burger_count");
    burgerCount.setOnPreferenceChangeListener(checkInteger);

    String[] checkIntegerPrefs = new String[] {
            "burger_count",
            "burger_speed",
            "pizza_count",
            "pizza_speed"
    };
    //adds integer-validator for all integerValues
    for (String s: checkIntegerPrefs) {
        getPreferenceScreen().findPreference(s).setOnPreferenceChangeListener(checkInteger);
    }
}
 
开发者ID:samsumas,项目名称:LivingBurger,代码行数:34,代码来源:SettingsActivity.java

示例3: createThemeChangeListener

import android.preference.Preference; //导入方法依赖的package包/类
/**
 * Creates and returns a listener, which allows to adapt the app's theme, when the value of the
 * corresponding preference has been changed.
 *
 * @return The listener, which has been created, as an instance of the type {@link
 * Preference.OnPreferenceChangeListener}
 */
@NonNull
private Preference.OnPreferenceChangeListener createThemeChangeListener() {
    return new Preference.OnPreferenceChangeListener() {

        @Override
        public boolean onPreferenceChange(final Preference preference, final Object newValue) {
            getActivity().recreate();
            return true;
        }

    };
}
 
开发者ID:michael-rapp,项目名称:ChromeLikeTabSwitcher,代码行数:20,代码来源:PreferenceFragment.java

示例4: onCreate

import android.preference.Preference; //导入方法依赖的package包/类
@Override
    protected void onCreate(Bundle savedInstanceState) {
        SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(this);
        switch (settings.getString(getString(R.string.pref_key_theme), "")) {
            case "DARK" :
                setTheme(R.style.AppTheme_Dark);
                break;
            case "LIGHT": default:
                setTheme(R.style.AppTheme_Light);
                break;
        }
        super.onCreate(savedInstanceState);
        setupActionBar();

        prefsFragment = new PrefsFragment();

        getFragmentManager().beginTransaction().replace(android.R.id.content, prefsFragment).commit();
        getFragmentManager().executePendingTransactions();


        Preference.OnPreferenceChangeListener preferenceChangeListener = new Preference.OnPreferenceChangeListener() {
            @Override
            public boolean onPreferenceChange(Preference preference, Object value) {
                if (preference.getKey().equals(getString(R.string.pref_key_wheelstyle))) {
                    String[] aStrValuesWheelStyle = getResources().getStringArray(R.array.pref_values_wheelstyle);
                    String[] aStrValuesTextWheelStyle = getResources().getStringArray(R.array.pref_values_text_wheelstyle);
                    for (int i=0; i<aStrValuesWheelStyle.length; i++)
                        if (aStrValuesWheelStyle[i].equals(value.toString())) preference.setSummary(aStrValuesTextWheelStyle[i]);
                } else if (preference.getKey().equals(getString(R.string.pref_key_theme))) {
                    recreate();
//                    String[] aStrValuesTheme = getResources().getStringArray(R.array.pref_values_theme);
//                    String[] aStrValuesTextTheme = getResources().getStringArray(R.array.pref_values_text_theme);
//                    for (int i=0; i<aStrValuesTheme.length; i++)
//                        if (aStrValuesTheme[i].equals(value.toString())) preference.setSummary(aStrValuesTextTheme[i]);
                } else {
                    String stringValue = value.toString();
                    preference.setSummary(stringValue);
                }
                return true;
            }
        };

        Preference prefIpAddress = prefsFragment.findPreference(getString(R.string.pref_key_ipaddress));
        Preference prefPort = prefsFragment.findPreference(getString(R.string.pref_key_port));
        Preference prefTheme = prefsFragment.findPreference(getString(R.string.pref_key_theme));
        Preference prefWheelStyle = prefsFragment.findPreference(getString(R.string.pref_key_wheelstyle));

        prefIpAddress.setOnPreferenceChangeListener(preferenceChangeListener);
        prefPort.setOnPreferenceChangeListener(preferenceChangeListener);
        prefTheme.setOnPreferenceChangeListener(preferenceChangeListener);
        prefWheelStyle.setOnPreferenceChangeListener(preferenceChangeListener);

        prefIpAddress.setSummary(PreferenceManager.getDefaultSharedPreferences(prefIpAddress.getContext()).getString(prefIpAddress.getKey(), ""));
        prefPort.setSummary(PreferenceManager.getDefaultSharedPreferences(prefPort.getContext()).getString(prefPort.getKey(), ""));

        String prefWheelStyleKey = PreferenceManager.getDefaultSharedPreferences(prefWheelStyle.getContext()).getString(prefWheelStyle.getKey(), "");
        preferenceChangeListener.onPreferenceChange(prefWheelStyle, prefWheelStyleKey);

        String prefThemeKey = PreferenceManager.getDefaultSharedPreferences(prefTheme.getContext()).getString(prefTheme.getKey(), "");

        String[] aStrValuesTheme = getResources().getStringArray(R.array.pref_values_theme);
        String[] aStrValuesTextTheme = getResources().getStringArray(R.array.pref_values_text_theme);
        for (int i=0; i<aStrValuesTheme.length; i++)
        if (aStrValuesTheme[i].equals(prefThemeKey)) prefTheme.setSummary(aStrValuesTextTheme[i]);
    }
 
开发者ID:Lexycon,项目名称:android-ws2801,代码行数:66,代码来源:SettingsActivity.java

示例5: onCreate

import android.preference.Preference; //导入方法依赖的package包/类
@Override
public void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);

    // Load the preferences from an XML resource
    addPreferencesFromResource(R.xml.preferences);

    // We've already abstracted the preferences that we want to save in SettingsManager, so
    // we'll manually get and save the preference values instead of using the built in
    // auto-binding magic.

    cbLongRoomNames = (CheckBoxPreference)findPreference(settingsList.longRoomNames.name());
    cbRefreshWiFi = (CheckBoxPreference)findPreference(settingsList.refreshWiFi.name());
    cbRefreshCellular = (CheckBoxPreference)findPreference(settingsList.refreshCellular.name());

    // Set values
    cbLongRoomNames.setChecked(settings.getLongRoomNames());
    cbRefreshWiFi.setChecked(settings.getRefreshWiFi());
    cbRefreshCellular.setChecked(settings.getRefreshCellular());

    // Set listeners
    Preference.OnPreferenceChangeListener listener = new Preference.OnPreferenceChangeListener() {

        @Override
        public boolean onPreferenceChange(Preference preference, Object o) {

            CheckBoxPreference pref = (CheckBoxPreference) preference;

            String key = pref.getKey();
            boolean value = (boolean)o;

            Logger.getInstance()
                .debug("PreferenceFragment", "Changed: " + key)
                .debug("PreferenceFragment", "Value: " + value);

            if (key.equals(settingsList.longRoomNames.name()))
                settings.setLongRoomNames(value);
            else if (key.equals(settingsList.refreshWiFi.name()))
                settings.setRefreshWiFi(value);
            else if (key.equals(settingsList.refreshCellular.name()))
                settings.setRefreshCellular(value);

            return true;
        }
    };

    cbLongRoomNames.setOnPreferenceChangeListener(listener);
    cbRefreshWiFi.setOnPreferenceChangeListener(listener);
    cbRefreshCellular.setOnPreferenceChangeListener(listener);
}
 
开发者ID:adriankeenan,项目名称:uob-timetable-android,代码行数:52,代码来源:PreferencesFragment.java


注:本文中的android.preference.Preference.OnPreferenceChangeListener方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。