Java Code Examples for android.preference.CheckBoxPreference#setOnPreferenceClickListener()
The following examples show how to use
android.preference.CheckBoxPreference#setOnPreferenceClickListener() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PreferencesActivity.java From AndroidPirateBox with MIT License | 6 votes |
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); activity = this; preferences = PreferenceManager.getDefaultSharedPreferences(this); addPreferencesFromResource(R.xml.preferences); updateExternalServerPreference(); CheckBoxPreference extServerCheckBoxPref = (CheckBoxPreference) findPreference(Constants.PREF_USE_EXTERNAL_SERVER); extServerCheckBoxPref.setOnPreferenceClickListener( new OnPreferenceClickListener() { @Override public boolean onPreferenceClick( Preference preference) { updateExternalServerPreference(); return true; } }); }
Example 2
Source File: SettingFragment.java From ZhihuDaily with Apache License 2.0 | 5 votes |
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); addPreferencesFromResource(R.xml.setting); Preference clearCache = getPreferenceScreen().findPreference("clear_cache"); CheckBoxPreference noImgMode = (CheckBoxPreference) findPreference("NO_IMAGE_MODE"); if ((boolean) SharedPreferencesUtils.get(App.getContext(), "NO_IMAGE_MODE", false)) { noImgMode.setDefaultValue(true); } else { noImgMode.setDefaultValue(false); } clearCache.setOnPreferenceClickListener(this); noImgMode.setOnPreferenceClickListener(this); }
Example 3
Source File: FourchanModule.java From Overchan-Android with GNU General Public License v3.0 | 5 votes |
@Override public void addPreferencesOnScreen(PreferenceGroup preferenceGroup) { Context context = preferenceGroup.getContext(); addPasscodePreference(preferenceGroup); CheckBoxPreference newRecaptchaPref = new LazyPreferences.CheckBoxPreference(context); newRecaptchaPref.setTitle(R.string.fourchan_prefs_new_recaptcha); newRecaptchaPref.setSummary(R.string.fourchan_prefs_new_recaptcha_summary); newRecaptchaPref.setKey(getSharedKey(PREF_KEY_NEW_RECAPTCHA)); newRecaptchaPref.setDefaultValue(NEW_RECAPTCHA_DEFAULT); preferenceGroup.addPreference(newRecaptchaPref); final CheckBoxPreference fallbackRecaptchaPref = new LazyPreferences.CheckBoxPreference(context); fallbackRecaptchaPref.setTitle(R.string.fourchan_prefs_new_recaptcha_fallback); fallbackRecaptchaPref.setSummary(R.string.fourchan_prefs_new_recaptcha_fallback_summary); fallbackRecaptchaPref.setKey(getSharedKey(PREF_KEY_NEW_RECAPTCHA_FALLBACK)); fallbackRecaptchaPref.setDefaultValue(false); preferenceGroup.addPreference(fallbackRecaptchaPref); fallbackRecaptchaPref.setDependency(getSharedKey(PREF_KEY_NEW_RECAPTCHA)); addPasswordPreference(preferenceGroup); addHttpsPreference(preferenceGroup, true); addProxyPreferences(preferenceGroup); final CheckBoxPreference proxyPreference = (CheckBoxPreference) preferenceGroup.findPreference(getSharedKey(PREF_KEY_USE_PROXY)); fallbackRecaptchaPref.setEnabled(!proxyPreference.isChecked()); proxyPreference.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference preference) { fallbackRecaptchaPref.setEnabled(!proxyPreference.isChecked()); if (proxyPreference.isChecked() && !fallbackRecaptchaPref.isChecked()) fallbackRecaptchaPref.setChecked(true); return false; } }); }
Example 4
Source File: SettingFragment.java From FileManager with Apache License 2.0 | 4 votes |
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); addPreferencesFromResource(R.xml.setting); pDefaultDir = findPreference("pDefaultDir"); pDefaultScanDir = findPreference("pDefaultScanDir"); pAutoUpdate = (CheckBoxPreference) findPreference("pAutoUpdate"); pNotification = (CheckBoxPreference) findPreference("pNotification"); pThemeColor = findPreference("pThemeColor"); pLanguage = findPreference("pLanguage"); pDefaultDir.setOnPreferenceClickListener(this); pDefaultScanDir.setOnPreferenceClickListener(this); pNotification.setOnPreferenceClickListener(this); pAutoUpdate.setOnPreferenceClickListener(this); pDefaultDir.setOnPreferenceClickListener(this); pThemeColor.setOnPreferenceClickListener(this); pLanguage.setOnPreferenceClickListener(this); pDefaultDir.setSummary(Settings.getDefaultDir()); pDefaultScanDir.setSummary(SharedUtil.getString(App.sContext, AppConstant.DEFAULT_SCAN_PATH)); pLanguage.setSummary(LanguageUtil.getInstance().getLanguageName()); pThemeColor.setSummary(SettingPrefUtil.getThemeName(App.sContext)); mCompositeSubscription = new CompositeSubscription(); mCompositeSubscription.add(RxBus.getDefault() .IoToUiObservable(NewDirEvent.class) .subscribe(event -> { if (event.getType().equals("pDefaultDir")) { Settings.setDefaultDir(event.getPath()); pDefaultDir.setSummary(event.getPath()); } else { SharedUtil.putString(App.sContext , AppConstant.DEFAULT_SCAN_PATH , event.getPath()); pDefaultScanDir.setSummary(event.getPath()); } }, Throwable::printStackTrace)); }
Example 5
Source File: SettingsActivity.java From mosmetro-android with GNU General Public License v3.0 | 4 votes |
@Override public void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); setTitle(getString(R.string.pref_updater_branch)); PreferenceScreen screen = getPreferenceManager().createPreferenceScreen(getActivity()); setPreferenceScreen(screen); PreferenceCategory stable = new PreferenceCategory(getActivity()); stable.setTitle(R.string.pref_updater_branch_stable); screen.addPreference(stable); PreferenceCategory experimental = new PreferenceCategory(getActivity()); experimental.setTitle(R.string.pref_updater_branch_experimental); screen.addPreference(experimental); if (branches == null) return; final SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(getActivity()); for (final UpdateCheckTask.Branch branch : branches.values()) { CheckBoxPreference pref = new CheckBoxPreference(getActivity()) { @Override protected void onBindView(View view) { super.onBindView(view); // Increase number of lines on Android 4.x // Source: https://stackoverflow.com/a/2615650 TextView summary = (TextView) view.findViewById(android.R.id.summary); summary.setMaxLines(15); } }; pref.setTitle(branch.name); pref.setSummary(branch.description); pref.setChecked(Version.getBranch().equals(branch.name)); pref.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference preference) { boolean same = Version.getBranch().equals(branch.name); ((CheckBoxPreference)preference).setChecked(same); if (!same) { settings.edit().putInt("pref_updater_ignore", 0).apply(); branch.dialog().show(); } getActivity().onBackPressed(); return true; } }); if (branch.stable) { stable.addPreference(pref); } else { experimental.addPreference(pref); } } }