Java 类android.support.v7.preference.Preference.OnPreferenceChangeListener 实例源码

项目:SorceryIconPack    文件:SettingsFragment.java   
private void initDevOps() {
    SwitchPreference hideItselfPreference =
            (SwitchPreference) findPreference("preference_switch_hide_itself");
    hideItselfPreference.setChecked(mPrefs.hideItself().getValue());
    hideItselfPreference.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
        @Override
        public boolean onPreferenceChange(Preference preference, Object newValue) {
            PackageManager pm = getContext().getPackageManager();
            ComponentName componentName =
                    new ComponentName(getContext(), MainActivity.class);
            if ((Boolean) newValue) {
                mPrefs.hideItself().setValue(true);
                pm.setComponentEnabledSetting(componentName,
                        PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
                        PackageManager.DONT_KILL_APP);
            } else {
                mPrefs.hideItself().setValue(false);
                pm.setComponentEnabledSetting(componentName,
                        PackageManager.COMPONENT_ENABLED_STATE_ENABLED,
                        PackageManager.DONT_KILL_APP);
            }
            return true;
        }
    });
}
项目:TATupload    文件:OptionActivity.java   
@Override
public void onCreatePreferences(Bundle bundle, String s) {

    addPreferencesFromResource(R.xml.preferences);

    Preference account = findPreference(getString(R.string.account));
    account.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
        @Override
        public boolean onPreferenceClick(Preference arg0) {
            AuthManager.chooseAccount(getActivity());
            return true;
        }

    });

    Preference notify = findPreference(getString(R.string.show_notification_key));
    notify.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
        @Override
        public boolean onPreferenceChange(Preference preference, Object newValue) {
            Boolean processing = (Boolean) newValue;
            if (processing) {
                Notifications.displayNotification(getContext());
            } else {
                Notifications.hideNotification(getContext());
            }
            return true;
        }

    });
}