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; } }); }
@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; } }); }