Java Code Examples for android.preference.CheckBoxPreference#setChecked()
The following examples show how to use
android.preference.CheckBoxPreference#setChecked() .
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: TwoFactorPreferenceFragment.java From GreenBits with GNU General Public License v3.0 | 6 votes |
private CheckBoxPreference setupCheckbox(final Map<?, ?> twoFacConfig, final String method) { final CheckBoxPreference c = getPref(method); if (method.equals(NLOCKTIME_EMAILS)) c.setChecked(isNlocktimeConfig(true)); else c.setChecked(isEnabled(twoFacConfig, method)); c.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(final Preference p, final Object newValue) { if (method.equals(NLOCKTIME_EMAILS)) setNlocktimeConfig((Boolean) newValue); else prompt2FAChange(method, (Boolean) newValue); return false; } }); return c; }
Example 2
Source File: SettingsActivity.java From good-weather with GNU General Public License v3.0 | 6 votes |
@Override public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) { switch (key) { case Constants.KEY_PREF_WIDGET_THEME: Intent intent = new Intent(Constants.ACTION_APPWIDGET_THEME_CHANGED); getActivity().sendBroadcast(intent); break; case Constants.KEY_PREF_WIDGET_UPDATE_PERIOD: Intent intent1 = new Intent(Constants.ACTION_APPWIDGET_UPDATE_PERIOD_CHANGED); getActivity().sendBroadcast(intent1); setSummary(); break; case Constants.KEY_PREF_WIDGET_UPDATE_LOCATION: int fineLocationPermission = ContextCompat.checkSelfPermission(getActivity(), Manifest.permission.ACCESS_FINE_LOCATION); if (fineLocationPermission != PackageManager.PERMISSION_GRANTED) { Snackbar.make(getActivity().findViewById(android.R.id.content), R.string.permission_location_need, Snackbar.LENGTH_SHORT).show(); CheckBoxPreference updateLocation = (CheckBoxPreference) findPreference(key); updateLocation.setChecked(false); } break; } }
Example 3
Source File: PreferencesListener.java From SensorTag-CC2650 with Apache License 2.0 | 6 votes |
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) { // Check operating system version if (android.os.Build.VERSION.SDK_INT > android.os.Build.VERSION_CODES. JELLY_BEAN_MR2) { return; } Sensor sensor = getSensorFromPrefKey(key); boolean noCheckboxWithThatKey = sensor == null; if (noCheckboxWithThatKey) return; boolean turnedOn = sharedPreferences.getBoolean(key, true); if (turnedOn && enabledSensors().size() > MAX_NOTIFICATIONS) { // Undo CheckBoxPreference cb = (CheckBoxPreference) preferenceFragment.findPreference(key); cb.setChecked(false); // Alert user alertNotifyLimitaion(); } }
Example 4
Source File: SettingsFragment.java From SecondScreen with Apache License 2.0 | 5 votes |
public void onSafeModeDialogPositiveClick(CheckBoxPreference checkBoxPreference) { try { checkBoxPreference.setChecked(false); SharedPreferences prefNew = U.getPrefNew(getActivity()); SharedPreferences.Editor editor = prefNew.edit(); editor.putBoolean("safe_mode", false); editor.apply(); safeModePrefChanged(); } catch (NullPointerException e) { /* Gracefully fail */ } }
Example 5
Source File: FreeformModeFragment.java From Taskbar with Apache License 2.0 | 5 votes |
@Override public void onReceive(Context context, Intent intent) { CheckBoxPreference preference = (CheckBoxPreference) findPreference(PREF_FREEFORM_HACK); if(preference != null) { SharedPreferences pref = U.getSharedPreferences(getActivity()); preference.setChecked(pref.getBoolean(PREF_FREEFORM_HACK, false)); } }
Example 6
Source File: SettingsFragment.java From CamCov with GNU General Public License v3.0 | 5 votes |
@Override public void onResume() { Log.d(getClass().getSimpleName(), "onResume"); super.onResume(); getPreferenceScreen().getSharedPreferences() .registerOnSharedPreferenceChangeListener(listener); CheckBoxPreference preference_enabled = (CheckBoxPreference) this.findPreference(getString(R.string.key_pref_enabled)); preference_enabled.setChecked(OverlayService.isRunning()); }
Example 7
Source File: PreferenceFragment.java From HeadsUp with GNU General Public License v2.0 | 5 votes |
/** * {@inheritDoc} */ @Override public void setValue(@NonNull Preference preference, @NonNull ConfigBase.Option option, @NonNull Object value) { CheckBoxPreference cbp = (CheckBoxPreference) preference; cbp.setChecked((Boolean) value); }
Example 8
Source File: LocationFragment.java From android with Apache License 2.0 | 5 votes |
@Override public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) { if (requestCode == DEFAULT_PERMISSIONS_REQUEST_CODE) { CheckBoxPreference auto = (CheckBoxPreference) findPreference("location_automatic"); int permission = PermissionChecker.checkSelfPermission(getActivity(), Manifest.permission.ACCESS_FINE_LOCATION); auto.setChecked(permission == PermissionChecker.PERMISSION_GRANTED); } }
Example 9
Source File: SyncCustomizationFragment.java From delion with Apache License 2.0 | 5 votes |
/** * Update the data type switch state. * * If sync is on, load the prefs from native. Otherwise, all data types are disabled and * checked. Note that the Password data type will be shown as disabled and unchecked between * sync being turned on and the backend initialization completing. */ private void updateDataTypeState() { boolean isSyncEnabled = mSyncSwitchPreference.isChecked(); boolean syncEverything = mSyncEverything.isChecked(); boolean passwordSyncConfigurable = mProfileSyncService.isBackendInitialized() && mProfileSyncService.isCryptographerReady(); Set<Integer> syncTypes = mProfileSyncService.getPreferredDataTypes(); boolean syncAutofill = syncTypes.contains(ModelType.AUTOFILL); for (CheckBoxPreference pref : mAllTypes) { boolean canSyncType = true; if (pref == mSyncPasswords) canSyncType = passwordSyncConfigurable; if (pref == mPaymentsIntegration) { canSyncType = syncAutofill || syncEverything; } if (!isSyncEnabled) { pref.setChecked(true); } else if (syncEverything) { pref.setChecked(canSyncType); } pref.setEnabled(isSyncEnabled && !syncEverything && canSyncType); } if (isSyncEnabled && !syncEverything) { mSyncAutofill.setChecked(syncAutofill); mSyncBookmarks.setChecked(syncTypes.contains(ModelType.BOOKMARKS)); mSyncOmnibox.setChecked(syncTypes.contains(ModelType.TYPED_URLS)); mSyncPasswords.setChecked(passwordSyncConfigurable && syncTypes.contains(ModelType.PASSWORDS)); mSyncRecentTabs.setChecked(syncTypes.contains(ModelType.PROXY_TABS)); // TODO(zea): Switch this to PREFERENCE once that datatype is // supported on Android. mSyncSettings.setChecked(syncTypes.contains(ModelType.PRIORITY_PREFERENCES)); mPaymentsIntegration.setChecked( syncAutofill && PersonalDataManager.isPaymentsIntegrationEnabled()); } }
Example 10
Source File: PreferencesBrowser.java From habpanelviewer with GNU General Public License v3.0 | 5 votes |
private void setAllowWebRtcPref(boolean allowWebRtc) { final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getActivity()); if (prefs.getBoolean(Constants.PREF_ALLOW_WEBRTC, false) != allowWebRtc) { SharedPreferences.Editor editor1 = prefs.edit(); editor1.putBoolean(Constants.PREF_ALLOW_WEBRTC, allowWebRtc); editor1.apply(); CheckBoxPreference allowPreference = (CheckBoxPreference) findPreference(Constants.PREF_ALLOW_WEBRTC); allowPreference.setChecked(allowWebRtc); } }
Example 11
Source File: PreferencesBrowser.java From habpanelviewer with GNU General Public License v3.0 | 5 votes |
@Override public void onStart() { super.onStart(); if (needsPermissions()) { CheckBoxPreference allowPreference = (CheckBoxPreference) findPreference(Constants.PREF_ALLOW_WEBRTC); allowPreference.setChecked(false); } }
Example 12
Source File: SettingsActivity.java From Hews with MIT License | 5 votes |
private void disableOpenLinkOptionPreference() { CheckBoxPreference openLinkOptionPref = (CheckBoxPreference) findPreference( getString(R.string.pref_key_open_link_option)); openLinkOptionPref.setEnabled(false); openLinkOptionPref.setChecked(false); openLinkOptionPref.setSummary(R.string.summary_open_link_option_unavailable); }
Example 13
Source File: SetupActivity.java From trigger with GNU General Public License v2.0 | 5 votes |
private void setChecked(String key, boolean checked) { CheckBoxPreference cbp = (CheckBoxPreference) findAnyPreference(key, null); if (cbp != null) { cbp.setChecked(checked); } else { Log.e("SetupActivity", "Cannot find CheckBoxPreference in PreferenceGroup with key: " + key); } }
Example 14
Source File: GroupSettingsFragment.java From snapdroid with GNU General Public License v3.0 | 4 votes |
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // Load the preferences from an XML resource addPreferencesFromResource(R.xml.group_preferences); PreferenceScreen screen = this.getPreferenceScreen(); prefStreams = (ListPreference) findPreference("pref_stream"); Bundle bundle = getArguments(); try { group = new Group(new JSONObject(bundle.getString("group"))); serverStatus = new ServerStatus(new JSONObject(bundle.getString("serverStatus"))); } catch (JSONException e) { e.printStackTrace(); } final ArrayList<Stream> streams = serverStatus.getStreams(); final CharSequence[] streamNames = new CharSequence[streams.size()]; final CharSequence[] streamIds = new CharSequence[streams.size()]; for (int i = 0; i < streams.size(); ++i) { streamNames[i] = streams.get(i).getName(); streamIds[i] = streams.get(i).getId(); } prefStreams.setEntries(streamNames); prefStreams.setEntryValues(streamIds); for (int i = 0; i < streams.size(); ++i) { if (streamIds[i].equals(group.getStreamId())) { prefStreams.setTitle(streamNames[i]); prefStreams.setValueIndex(i); oldStream = prefStreams.getValue(); break; } } prefStreams.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(Preference preference, Object newValue) { for (int i = 0; i < streams.size(); ++i) { if (streamIds[i].equals(newValue)) { prefStreams.setTitle(streamNames[i]); // client.getConfig().setStream(streamIds[i].toString()); prefStreams.setValueIndex(i); break; } } return false; } }); prefCatClients = (PreferenceCategory) findPreference("pref_cat_clients"); ArrayList<CheckBoxPreference> allClients = new ArrayList<>(); for (Group g : serverStatus.getGroups()) { for (Client client : g.getClients()) { CheckBoxPreference checkBoxPref = new CheckBoxPreference(screen.getContext()); checkBoxPref.setKey(client.getId()); checkBoxPref.setTitle(client.getVisibleName()); checkBoxPref.setChecked(g.getId().equals(group.getId())); checkBoxPref.setPersistent(false); allClients.add(checkBoxPref); } } Collections.sort(allClients, new Comparator<CheckBoxPreference>() { @Override public int compare(CheckBoxPreference lhs, CheckBoxPreference rhs) { return lhs.getTitle().toString().compareToIgnoreCase(rhs.getTitle().toString()); } }); for (CheckBoxPreference pref : allClients) prefCatClients.addPreference(pref); oldClients = getClients().toString(); }
Example 15
Source File: PreferencesOther.java From habpanelviewer with GNU General Public License v3.0 | 4 votes |
private void removeAsAdmin() { mDPM.removeActiveAdmin(AdminReceiver.COMP); CheckBoxPreference adminPreference = (CheckBoxPreference) findPreference(Constants.PREF_DEVICE_ADMIN); adminPreference.setChecked(false); }
Example 16
Source File: PGPClipperSettingsActivity.java From PGPClipper with Apache License 2.0 | 4 votes |
@Override protected void onResume() { super.onResume(); final ListPreference themePref = (ListPreference) fragment.findPreference("themeSelection"); final SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()); final CheckBoxPreference fingerprintCheckboxPreference = (CheckBoxPreference) fragment.findPreference("enableFingerprintAuth"); final CheckBoxPreference pgpClipperEnabledCheckbox = (CheckBoxPreference) fragment.findPreference("pgpClipperEnabledCheckbox"); themePref.setEntryValues(R.array.themes_values); themePref.setEntries(R.array.themes); String currentVal = sharedPreferences.getString("themeSelection", "dark"); if (currentVal != null) { switch (currentVal) { case "dark": themePref.setSummary(getResources().getString(R.string.darkText)); break; case "light": themePref.setSummary(getResources().getString(R.string.lightText)); break; } } String providerApp = sharedPreferences.getString("pgpServiceProviderApp", null); if (providerApp == null || "".equals(providerApp)) { pgpClipperEnabledCheckbox.setEnabled(false); pgpClipperEnabledCheckbox.setChecked(false); stopService(new Intent(PGPClipperSettingsActivity.this, PGPClipperService.class)); } else { if (pgpClipperEnabledCheckbox.isChecked()) { startService(new Intent(PGPClipperSettingsActivity.this, PGPClipperService.class)); } pgpClipperEnabledCheckbox.setEnabled(true); } if (android.os.Build.VERSION.SDK_INT < Build.VERSION_CODES.M) // Fingerprint API not supported below M fingerprintCheckboxPreference.setEnabled(false); else { fingerprintCheckboxPreference.setEnabled(true); } }
Example 17
Source File: SuntimesSettingsActivity.java From SuntimesWidget with GNU General Public License v3.0 | 4 votes |
private static void loadPref_altitude(Context context, CheckBoxPreference altitudePref) { boolean useAltitude = WidgetSettings.loadLocationAltitudeEnabledPref(context, 0); altitudePref.setChecked(useAltitude); }
Example 18
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); } } }
Example 19
Source File: AppsWidgetSettings.java From Hangar with GNU General Public License v3.0 | 4 votes |
@Override public void onCreate(final Bundle savedInstanceState) { super.onCreate(savedInstanceState); addPreferencesFromResource(R.layout.apps_widget_settings); int defaultAppsNo = APPS_WIDGET_DEFAULT_APPSNO; int defaultAppsNoLs = APPS_WIDGET_DEFAULT_APPSNO_LS; SharedPreferences mPrefs = prefs.prefsGet(); apps_by_widget_size_preference = (SwitchPreference)findPreference(Settings.APPS_BY_WIDGET_SIZE_PREFERENCE); apps_by_widget_size_preference.setChecked(mPrefs.getBoolean(Settings.APPS_BY_WIDGET_SIZE_PREFERENCE, Settings.APPS_BY_WIDGET_SIZE_DEFAULT)); apps_by_widget_size_preference.setOnPreferenceChangeListener(changeListener); background_color_preference = (ColorPickerPreference) findPreference(Settings.BACKGROUND_COLOR_PREFERENCE); int intColor = mPrefs.getInt(Settings.BACKGROUND_COLOR_PREFERENCE, Settings.BACKGROUND_COLOR_DEFAULT); String hexColor = String.format("#%08x", (intColor)); background_color_preference.setSummary(hexColor); background_color_preference.setOnPreferenceChangeListener(changeListener); appnos_preference = (UpdatingListPreference)findPreference(Settings.STATS_WIDGET_APPSNO_PREFERENCE); appnos_preference.setValue(mPrefs.getString(extras == null ? Settings.STATS_WIDGET_APPSNO_PREFERENCE : Integer.toString(defaultAppsNo), Integer.toString(defaultAppsNo))); appnos_preference.setOnPreferenceChangeListener(changeListener); if (apps_by_widget_size_preference.isChecked()) { appnos_preference.setSummary(R.string.automatic_appsno); } appnos_ls_preference = (UpdatingListPreference)findPreference(Settings.STATS_WIDGET_APPSNO_LS_PREFERENCE); appnos_ls_preference.setValue(mPrefs.getString(extras == null ? Settings.STATS_WIDGET_APPSNO_LS_PREFERENCE : Integer.toString(defaultAppsNoLs), Integer.toString(defaultAppsNoLs))); appnos_ls_preference.setOnPreferenceChangeListener(changeListener); if (apps_by_widget_size_preference.isChecked()) { appnos_ls_preference.setSummary(R.string.automatic_appsno); } weighted_recents_preference = (CheckBoxPreference)findPreference(Settings.WEIGHTED_RECENTS_PREFERENCE); weighted_recents_preference.setChecked(mPrefs.getBoolean(Settings.WEIGHTED_RECENTS_PREFERENCE, Settings.WEIGHTED_RECENTS_DEFAULT)); weighted_recents_preference.setOnPreferenceChangeListener(changeListener); weight_priority_preference = (UpdatingListPreference)findPreference(Settings.WEIGHT_PRIORITY_PREFERENCE); weight_priority_preference.setValue(mPrefs.getString(Settings.WEIGHT_PRIORITY_PREFERENCE, Integer.toString(Settings.WEIGHT_PRIORITY_DEFAULT))); weight_priority_preference.setOnPreferenceChangeListener(changeListener); colorize_preference = (CheckBoxPreference)findPreference(Settings.COLORIZE_PREFERENCE); colorize_preference.setChecked(mPrefs.getBoolean(Settings.COLORIZE_PREFERENCE, Settings.COLORIZE_DEFAULT)); colorize_preference.setOnPreferenceChangeListener(changeListener); ignore_pinned_preference = (CheckBoxPreference)findPreference(Settings.IGNORE_PINNED_PREFERENCE); ignore_pinned_preference.setChecked(mPrefs.getBoolean(Settings.IGNORE_PINNED_PREFERENCE, Settings.IGNORE_PINNED_DEFAULT)); ignore_pinned_preference.setOnPreferenceChangeListener(changeListener); icon_color_preference = (ColorPickerPreference) findPreference(Settings.ICON_COLOR_PREFERENCE); int intColor2 = mPrefs.getInt(Settings.ICON_COLOR_PREFERENCE, Settings.ICON_COLOR_DEFAULT); String hexColor2 = String.format("#%08x", (intColor2)); icon_color_preference.setSummary(hexColor2); icon_color_preference.setOnPreferenceChangeListener(changeListener); rounded_corners_preference = (CheckBoxPreference)findPreference(Settings.ROUNDED_CORNERS_PREFERENCE); rounded_corners_preference.setChecked(mPrefs.getBoolean(Settings.ROUNDED_CORNERS_PREFERENCE, Settings.ROUNDED_CORNERS_DEFAULT)); rounded_corners_preference.setOnPreferenceChangeListener(changeListener); icon_size_preference = (UpdatingListPreference)findPreference(Settings.ICON_SIZE_PREFERENCE); icon_size_preference.setValue(mPrefs.getString(Settings.ICON_SIZE_PREFERENCE, Integer.toString(Settings.ICON_SIZE_DEFAULT))); icon_size_preference.setOnPreferenceChangeListener(changeListener); alignment_preference = (UpdatingListPreference)findPreference(Settings.ALIGNMENT_PREFERENCE); alignment_preference.setValue(mPrefs.getString(Settings.ALIGNMENT_PREFERENCE, Integer.toString(Settings.ALIGNMENT_DEFAULT))); alignment_preference.setOnPreferenceChangeListener(changeListener); }
Example 20
Source File: TGPreferencesFragment.java From tuxguitar with GNU Lesser General Public License v2.1 | 4 votes |
public void createSafPreferences() { CheckBoxPreference checkBoxPreference = (CheckBoxPreference) this.findPreference(TGStorageProperties.PROPERTY_SAF_PROVIDER); checkBoxPreference.setChecked(new TGStorageProperties(this.findContext()).isUseSafProvider()); }