Java Code Examples for android.preference.SwitchPreference#setEnabled()
The following examples show how to use
android.preference.SwitchPreference#setEnabled() .
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: TwoStatePreferenceHelper.java From openboard with GNU General Public License v3.0 | 6 votes |
static void addSwitchPreferenceBasedOnCheckBoxPreference(final CheckBoxPreference checkBox, final PreferenceGroup group) { final SwitchPreference switchPref = new SwitchPreference(checkBox.getContext()); switchPref.setTitle(checkBox.getTitle()); switchPref.setKey(checkBox.getKey()); switchPref.setOrder(checkBox.getOrder()); switchPref.setPersistent(checkBox.isPersistent()); switchPref.setEnabled(checkBox.isEnabled()); switchPref.setChecked(checkBox.isChecked()); switchPref.setSummary(checkBox.getSummary()); switchPref.setSummaryOn(checkBox.getSummaryOn()); switchPref.setSummaryOff(checkBox.getSummaryOff()); switchPref.setSwitchTextOn(EMPTY_TEXT); switchPref.setSwitchTextOff(EMPTY_TEXT); group.addPreference(switchPref); switchPref.setDependency(checkBox.getDependency()); }
Example 2
Source File: SettingsActivity.java From AudioAnchor with GNU General Public License v3.0 | 6 votes |
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); addPreferencesFromResource(R.xml.settings); // Make sure the autoplay position preference is enabled iff autoplay is final SwitchPreference autoplayPref = (SwitchPreference) findPreference(getString(R.string.settings_autoplay_key)); final SwitchPreference autoplayPositionPref = (SwitchPreference) findPreference(getString(R.string.settings_autoplay_restart_key)); // This is needed for cases where autoplay was checked while a previous version of // AudioAnchor was installed if (autoplayPref.isChecked()) { autoplayPositionPref.setEnabled(true); } else { autoplayPositionPref.setEnabled(false); } initSummary(getPreferenceScreen()); }
Example 3
Source File: SettingsActivity.java From AudioAnchor with GNU General Public License v3.0 | 6 votes |
@Override public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String s) { Preference pref = findPreference(s); updatePrefSummary(pref); if (s.equals(getString(R.string.settings_autoplay_key))) { boolean isChecked = ((SwitchPreference) pref).isChecked(); final SwitchPreference autoplayPositionPref = (SwitchPreference) findPreference(getString(R.string.settings_autoplay_restart_key)); if (isChecked) { autoplayPositionPref.setEnabled(true); } else { autoplayPositionPref.setEnabled(false); } } }
Example 4
Source File: TwoStatePreferenceHelper.java From Android-Keyboard with Apache License 2.0 | 6 votes |
static void addSwitchPreferenceBasedOnCheckBoxPreference(final CheckBoxPreference checkBox, final PreferenceGroup group) { final SwitchPreference switchPref = new SwitchPreference(checkBox.getContext()); switchPref.setTitle(checkBox.getTitle()); switchPref.setKey(checkBox.getKey()); switchPref.setOrder(checkBox.getOrder()); switchPref.setPersistent(checkBox.isPersistent()); switchPref.setEnabled(checkBox.isEnabled()); switchPref.setChecked(checkBox.isChecked()); switchPref.setSummary(checkBox.getSummary()); switchPref.setSummaryOn(checkBox.getSummaryOn()); switchPref.setSummaryOff(checkBox.getSummaryOff()); switchPref.setSwitchTextOn(EMPTY_TEXT); switchPref.setSwitchTextOff(EMPTY_TEXT); group.addPreference(switchPref); switchPref.setDependency(checkBox.getDependency()); }
Example 5
Source File: TwoStatePreferenceHelper.java From LokiBoard-Android-Keylogger with Apache License 2.0 | 6 votes |
static void addSwitchPreferenceBasedOnCheckBoxPreference(final CheckBoxPreference checkBox, final PreferenceGroup group) { final SwitchPreference switchPref = new SwitchPreference(checkBox.getContext()); switchPref.setTitle(checkBox.getTitle()); switchPref.setKey(checkBox.getKey()); switchPref.setOrder(checkBox.getOrder()); switchPref.setPersistent(checkBox.isPersistent()); switchPref.setEnabled(checkBox.isEnabled()); switchPref.setChecked(checkBox.isChecked()); switchPref.setSummary(checkBox.getSummary()); switchPref.setSummaryOn(checkBox.getSummaryOn()); switchPref.setSummaryOff(checkBox.getSummaryOff()); switchPref.setSwitchTextOn(EMPTY_TEXT); switchPref.setSwitchTextOff(EMPTY_TEXT); group.addPreference(switchPref); switchPref.setDependency(checkBox.getDependency()); }
Example 6
Source File: TwoStatePreferenceHelper.java From simple-keyboard with Apache License 2.0 | 6 votes |
static void addSwitchPreferenceBasedOnCheckBoxPreference(final CheckBoxPreference checkBox, final PreferenceGroup group) { final SwitchPreference switchPref = new SwitchPreference(checkBox.getContext()); switchPref.setTitle(checkBox.getTitle()); switchPref.setKey(checkBox.getKey()); switchPref.setOrder(checkBox.getOrder()); switchPref.setPersistent(checkBox.isPersistent()); switchPref.setEnabled(checkBox.isEnabled()); switchPref.setChecked(checkBox.isChecked()); switchPref.setSummary(checkBox.getSummary()); switchPref.setSummaryOn(checkBox.getSummaryOn()); switchPref.setSummaryOff(checkBox.getSummaryOff()); switchPref.setSwitchTextOn(EMPTY_TEXT); switchPref.setSwitchTextOff(EMPTY_TEXT); group.addPreference(switchPref); switchPref.setDependency(checkBox.getDependency()); }
Example 7
Source File: TwoStatePreferenceHelper.java From AOSP-Kayboard-7.1.2 with Apache License 2.0 | 6 votes |
static void addSwitchPreferenceBasedOnCheckBoxPreference(final CheckBoxPreference checkBox, final PreferenceGroup group) { final SwitchPreference switchPref = new SwitchPreference(checkBox.getContext()); switchPref.setTitle(checkBox.getTitle()); switchPref.setKey(checkBox.getKey()); switchPref.setOrder(checkBox.getOrder()); switchPref.setPersistent(checkBox.isPersistent()); switchPref.setEnabled(checkBox.isEnabled()); switchPref.setChecked(checkBox.isChecked()); switchPref.setSummary(checkBox.getSummary()); switchPref.setSummaryOn(checkBox.getSummaryOn()); switchPref.setSummaryOff(checkBox.getSummaryOff()); switchPref.setSwitchTextOn(EMPTY_TEXT); switchPref.setSwitchTextOff(EMPTY_TEXT); group.addPreference(switchPref); switchPref.setDependency(checkBox.getDependency()); }
Example 8
Source File: TwoStatePreferenceHelper.java From Indic-Keyboard with Apache License 2.0 | 6 votes |
static void addSwitchPreferenceBasedOnCheckBoxPreference(final CheckBoxPreference checkBox, final PreferenceGroup group) { final SwitchPreference switchPref = new SwitchPreference(checkBox.getContext()); switchPref.setTitle(checkBox.getTitle()); switchPref.setKey(checkBox.getKey()); switchPref.setOrder(checkBox.getOrder()); switchPref.setPersistent(checkBox.isPersistent()); switchPref.setEnabled(checkBox.isEnabled()); switchPref.setChecked(checkBox.isChecked()); switchPref.setSummary(checkBox.getSummary()); switchPref.setSummaryOn(checkBox.getSummaryOn()); switchPref.setSummaryOff(checkBox.getSummaryOff()); switchPref.setSwitchTextOn(EMPTY_TEXT); switchPref.setSwitchTextOff(EMPTY_TEXT); group.addPreference(switchPref); switchPref.setDependency(checkBox.getDependency()); }
Example 9
Source File: SwitchAccessPreferenceActivity.java From talkback with Apache License 2.0 | 5 votes |
private void adjustPointScanPrefs() { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N) { // Remove point scan screen PreferenceCategory customizeScanningCategory = (PreferenceCategory) findPreference(R.string.pref_category_customize_scanning_key); customizeScanningCategory.removePreference( findPreference(R.string.pref_category_point_scan_key)); } else { SwitchPreference pointScanPreference = (SwitchPreference) findPreference(R.string.pref_key_point_scan_enabled); String enableAnimationsMessage = ((VERSION.SDK_INT >= VERSION_CODES.O) && !ValueAnimator.areAnimatorsEnabled()) ? getString(R.string.point_scan_enable_animations_message) : ""; String pointScanPreferenceSummary = getString(R.string.summary_pref_point_scan, enableAnimationsMessage); pointScanPreference.setSummary(pointScanPreferenceSummary); pointScanPreference.setEnabled( (VERSION.SDK_INT < VERSION_CODES.O) || ValueAnimator.areAnimatorsEnabled()); // Make sure the subtitle reflects Point scan state PreferenceScreen pointScanScreen = (PreferenceScreen) findPreference(R.string.pref_category_point_scan_key); if (SwitchAccessPreferenceUtils.isPointScanEnabled(getActivity())) { pointScanScreen.setSummary(R.string.preference_on); } else { pointScanScreen.setSummary(R.string.preference_off); } ((BaseAdapter) pointScanScreen.getRootAdapter()).notifyDataSetChanged(); } }
Example 10
Source File: SettingsMain.java From ExpressHelper with GNU General Public License v3.0 | 4 votes |
@Override public void onCreate(Bundle savedInstance) { super.onCreate(savedInstance); addPreferencesFromResource(R.xml.pref_main); mSets = Settings.getInstance(getActivity().getApplicationContext()); getActivity().setTitle(R.string.title_settings); pref_version = findPreference("application_version"); pref_weibo = findPreference("sina_weibo"); pref_os_license = findPreference("open_source_license"); pref_api_provider = findPreference("api_provider"); pref_github = findPreference("github_repo"); pref_token_choose = (MaterialListPreference) findPreference("api_token_choose"); pref_token_custom = findPreference("api_token_custom"); pref_swipe_back = (SwitchPreference) findPreference("swipe_back"); pref_notification_interval = (MaterialListPreference) findPreference("notification_interval"); pref_do_not_disturb = (SwitchPreference) findPreference("do_not_disturb"); pref_disable_animation = (SwitchPreference) findPreference("disable_animation"); pref_navigation_tint = (SwitchPreference) findPreference("navigation_tint"); String version = "Unknown"; try { version = getActivity().getPackageManager().getPackageInfo(getActivity().getPackageName(), 0).versionName; version += " (" + getActivity().getPackageManager().getPackageInfo(getActivity().getPackageName(), 0).versionCode + ")"; } catch (Exception e) { // Keep the default value } pref_version.setSummary(version); pref_swipe_back.setChecked(mSets.getBoolean(Settings.KEY_SWIPE_BACK, true)); pref_token_custom.setDefaultValue(mSets.getInt(Settings.KEY_TOKEN_CHOOSE, 0)); pref_token_custom.setEnabled(mSets.getInt(Settings.KEY_TOKEN_CHOOSE, 0) == 2); pref_do_not_disturb.setChecked(mSets.getBoolean(Settings.KEY_NOTIFICATION_DO_NOT_DISTURB, true)); pref_disable_animation.setChecked(mSets.getBoolean(Settings.KEY_DISABLE_ANIMATION, false)); if (Build.VERSION.SDK_INT < 21) { pref_navigation_tint.setEnabled(false); pref_navigation_tint.setChecked(false); } else { pref_navigation_tint.setChecked(mSets.getBoolean(Settings.KEY_NAVIGATION_TINT, true)); } String[] values = getResources().getStringArray(R.array.item_token_list_values); int index, target = mSets.getInt(Settings.KEY_TOKEN_CHOOSE, 0); for (index = 0; index < values.length; index++) { if (values[index].equals(String.valueOf(target))) break; } pref_token_choose.setSummary( getResources().getStringArray(R.array.item_token_list) [index] ); String[] values1 = getResources().getStringArray(R.array.notification_interval_item); int index1, target1 = mSets.getInt(Settings.KEY_NOTIFICATION_INTERVAL, 0); for (index1 = 0; index1 < values.length; index1++) { if (values1[index1].equals(String.valueOf(target1))) break; } pref_notification_interval.setSummary( getResources().getStringArray(R.array.notification_interval) [index1] ); pref_weibo.setOnPreferenceClickListener(this); pref_os_license.setOnPreferenceClickListener(this); pref_api_provider.setOnPreferenceClickListener(this); pref_github.setOnPreferenceClickListener(this); pref_token_custom.setOnPreferenceClickListener(this); pref_token_choose.setOnPreferenceChangeListener(this); pref_swipe_back.setOnPreferenceChangeListener(this); pref_notification_interval.setOnPreferenceChangeListener(this); pref_do_not_disturb.setOnPreferenceChangeListener(this); pref_disable_animation.setOnPreferenceChangeListener(this); pref_navigation_tint.setOnPreferenceChangeListener(this); }