Java Code Examples for android.preference.Preference#setEnabled()
The following examples show how to use
android.preference.Preference#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: EventPreferencesRadioSwitch.java From PhoneProfilesPlus with Apache License 2.0 | 6 votes |
@Override void checkPreferences(PreferenceManager prefMng, Context context) { boolean enabled = Event.isEventPreferenceAllowed(PREF_EVENT_RADIO_SWITCH_ENABLED, context).allowed == PreferenceAllowed.PREFERENCE_ALLOWED; Preference preference = prefMng.findPreference(PREF_EVENT_RADIO_SWITCH_WIFI); if (preference != null) preference.setEnabled(enabled); preference = prefMng.findPreference(PREF_EVENT_RADIO_SWITCH_BLUETOOTH); if (preference != null) preference.setEnabled(enabled); preference = prefMng.findPreference(PREF_EVENT_RADIO_SWITCH_MOBILE_DATA); if (preference != null) preference.setEnabled(enabled); preference = prefMng.findPreference(PREF_EVENT_RADIO_SWITCH_GPS); if (preference != null) preference.setEnabled(enabled); preference = prefMng.findPreference(PREF_EVENT_RADIO_SWITCH_NFC); if (preference != null) preference.setEnabled(enabled); preference = prefMng.findPreference(PREF_EVENT_RADIO_SWITCH_AIRPLANE_MODE); if (preference != null) preference.setEnabled(enabled); }
Example 2
Source File: EventPreferencesWifi.java From PhoneProfilesPlus with Apache License 2.0 | 6 votes |
void setAllSummary(PreferenceManager prefMng, SharedPreferences preferences, Context context) { setSummary(prefMng, PREF_EVENT_WIFI_ENABLED, preferences, context); setSummary(prefMng, PREF_EVENT_WIFI_SSID, preferences, context); setSummary(prefMng, PREF_EVENT_WIFI_CONNECTION_TYPE, preferences, context); setSummary(prefMng, PREF_EVENT_WIFI_APP_SETTINGS, preferences, context); setSummary(prefMng, PREF_EVENT_WIFI_LOCATION_SYSTEM_SETTINGS, preferences, context); setSummary(prefMng, PREF_EVENT_WIFI_KEEP_ON_SYSTEM_SETTINGS, preferences, context); if (Event.isEventPreferenceAllowed(EventPreferencesWifi.PREF_EVENT_WIFI_ENABLED, context).allowed != PreferenceAllowed.PREFERENCE_ALLOWED) { Preference preference = prefMng.findPreference(PREF_EVENT_WIFI_ENABLED); if (preference != null) preference.setEnabled(false); preference = prefMng.findPreference(PREF_EVENT_WIFI_SSID); if (preference != null) preference.setEnabled(false); preference = prefMng.findPreference(PREF_EVENT_WIFI_CONNECTION_TYPE); if (preference != null) preference.setEnabled(false); } }
Example 3
Source File: SensorSettingsActivity.java From mytracks with Apache License 2.0 | 6 votes |
/** * Updates an ant sensor. * * @param preferenceKey the preference key * @param valueKey the value key * @param enabled true if enabled */ @SuppressWarnings("deprecation") private void updateAntSensor(int preferenceKey, final int valueKey, boolean enabled) { Preference preference = findPreference(getString(preferenceKey)); if (preference != null) { preference.setEnabled(enabled); int deviceId = PreferencesUtils.getInt(this, valueKey, AntSensorManager.WILDCARD); if (deviceId == AntSensorManager.WILDCARD) { preference.setSummary(R.string.settings_sensor_ant_not_connected); } else { preference.setSummary(getString(R.string.settings_sensor_ant_paired, deviceId)); } preference.setOnPreferenceClickListener(new OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference pref) { PreferencesUtils.setInt(SensorSettingsActivity.this, valueKey, AntSensorManager.WILDCARD); pref.setSummary(R.string.settings_sensor_ant_not_connected); return true; } }); } }
Example 4
Source File: BrailleBackPreferencesActivity.java From brailleback with Apache License 2.0 | 6 votes |
@Override public void onConnectionStateChanged(int state) { mConnectionState = state; CharSequence summary; boolean enableBindings = false; switch (state) { case Display.STATE_CONNECTED: summary = getText(R.string.connstate_connected); enableBindings = true; break; case Display.STATE_NOT_CONNECTED: summary = getText(R.string.connstate_not_connected); break; default: summary = getText(R.string.connstate_error); break; } Preference bindingsPref = findPreferenceByResId(R.string.pref_key_bindings_key); bindingsPref.setEnabled(enableBindings); if (mConnectionProgress == null) { mStatusPreference.setSummary(summary); announceConnectionState(summary); } }
Example 5
Source File: SettingsActivity.java From Yahala-Messenger with MIT License | 5 votes |
private void setVideoBitrateEnable(SharedPreferences sharedPreferences) { Preference bitratePreferenceValue = settingsFragment.findPreference(keyprefStartVideoBitrateValue); String bitrateTypeDefault = getString(R.string.pref_startvideobitrate_default); String bitrateType = sharedPreferences.getString( keyprefStartVideoBitrateType, bitrateTypeDefault); if (bitrateType.equals(bitrateTypeDefault)) { bitratePreferenceValue.setEnabled(false); } else { bitratePreferenceValue.setEnabled(true); } }
Example 6
Source File: PasscodePreferencesActivity.java From UltimateAndroid with Apache License 2.0 | 5 votes |
@SuppressWarnings("deprecation") @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); overridePendingTransition(R.anim.slide_up, R.anim.do_nothing); setTitle("passcode_manage"); if (android.os.Build.VERSION.SDK_INT >= 11) { // getActionBar().setDisplayHomeAsUpEnabled(true); } addPreferencesFromResource(R.xml.passlock_preferences); turnPasscodeOnOff = (Preference) findPreference("turn_passcode_on_off"); changePasscode = (Preference) findPreference("change_passcode"); if ( AppLockManager.getInstance().getCurrentAppLock().isPasswordLocked() ) { turnPasscodeOnOff.setTitle("passcode_turn_off"); } else { turnPasscodeOnOff.setTitle("passcode_turn_on"); changePasscode.setEnabled(false); } turnPasscodeOnOff.setOnPreferenceClickListener(passcodeOnOffTouchListener); changePasscode.setOnPreferenceClickListener(changePasscodeTouchListener); }
Example 7
Source File: ConfigurationActivity.java From Noyze with Apache License 2.0 | 5 votes |
protected void updateFeatureList(String name) { LOGI("InterfaceSettings", "updateFeatureList()"); if (TextUtils.isEmpty(name)) { SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getActivity()); name = prefs.getString(mVolumePanel, name); } List<String> features = VolumePanelInfo.getSupportedFeatures(name); String[] allFeatures = VolumePanelInfo.getAllFeatures(); for (String feature : allFeatures) { Preference pref = findPreference(feature); pref.setEnabled(features.contains(feature)); } }
Example 8
Source File: AutofillAndPaymentsPreferences.java From 365browser with Apache License 2.0 | 5 votes |
private void refreshPaymentAppsPref() { Preference pref = findPreference(PREF_ANDROID_PAYMENT_APPS); if (pref != null) { if (AndroidPaymentAppFactory.hasAndroidPaymentApps()) { pref.setSummary(null); pref.setEnabled(true); } else { pref.setSummary(getActivity().getString(R.string.payment_no_apps_summary)); pref.setEnabled(false); } } }
Example 9
Source File: ShadowsocksSettings.java From Maying with Apache License 2.0 | 5 votes |
public void setEnabled(boolean enabled) { this.enabled = enabled; List<String> list = new ArrayList<>(); // list.add(Constants.Key.isNAT); list.addAll(Arrays.asList(PROXY_PREFS)); list.addAll(Arrays.asList(FEATURE_PREFS)); for (String name : list) { Preference pref = findPreference(name); if (pref != null) { pref.setEnabled(enabled && (!Constants.Key.proxyApps.equals(name) || Utils.isLollipopOrAbove() || false)); } } }
Example 10
Source File: PreferencesSettingsFragment.java From Android-Keyboard with Apache License 2.0 | 5 votes |
@Override public void onResume() { super.onResume(); final Preference voiceInputKeyOption = findPreference(Settings.PREF_VOICE_INPUT_KEY); if (voiceInputKeyOption != null) { RichInputMethodManager.getInstance().refreshSubtypeCaches(); voiceInputKeyOption.setEnabled(VOICE_IME_ENABLED); voiceInputKeyOption.setSummary(VOICE_IME_ENABLED ? null : getText(R.string.voice_input_disabled_summary)); } }
Example 11
Source File: ActivitySettings.java From FineGeotag with GNU General Public License v3.0 | 5 votes |
@Override protected void onResume() { super.onResume(); getPreferenceScreen().getSharedPreferences().registerOnSharedPreferenceChangeListener(this); SharedPreferences prefs = getPreferenceScreen().getSharedPreferences(); // Get preferences Preference pref_check = findPreference(PREF_CHECK); Preference pref_version = findPreference(PREF_VERSION); // Set summaries onSharedPreferenceChanged(prefs, PREF_ENABLED); onSharedPreferenceChanged(prefs, PREF_TOAST); onSharedPreferenceChanged(prefs, PREF_ALTITUDE); onSharedPreferenceChanged(prefs, PREF_ACCURACY); onSharedPreferenceChanged(prefs, PREF_TIMEOUT); onSharedPreferenceChanged(prefs, PREF_KNOWN); // Location settings Intent locationSettingsIntent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS); if (getPackageManager().queryIntentActivities(locationSettingsIntent, 0).size() > 0) pref_check.setIntent(locationSettingsIntent); else pref_check.setEnabled(false); // Version Intent playStoreIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=" + getPackageName())); if (getPackageManager().queryIntentActivities(playStoreIntent, 0).size() > 0) pref_version.setIntent(playStoreIntent); try { PackageInfo pInfo = getPackageManager().getPackageInfo(getPackageName(), 0); pref_version.setSummary( pInfo.versionName + "/" + pInfo.versionCode + "\n" + getString(R.string.msg_geocoder) + " " + getString(Geocoder.isPresent() ? R.string.msg_yes : R.string.msg_no)); } catch (PackageManager.NameNotFoundException ignored) { } }
Example 12
Source File: PreferencesSettingsFragment.java From openboard with GNU General Public License v3.0 | 5 votes |
@Override public void onResume() { super.onResume(); final Preference voiceInputKeyOption = findPreference(Settings.PREF_VOICE_INPUT_KEY); if (voiceInputKeyOption != null) { RichInputMethodManager.getInstance().refreshSubtypeCaches(); voiceInputKeyOption.setEnabled(VOICE_IME_ENABLED); voiceInputKeyOption.setSummary(VOICE_IME_ENABLED ? null : getText(R.string.voice_input_disabled_summary)); } }
Example 13
Source File: SubScreenFragment.java From openboard with GNU General Public License v3.0 | 5 votes |
static void setPreferenceEnabled(final String prefKey, final boolean enabled, final PreferenceScreen screen) { final Preference preference = screen.findPreference(prefKey); if (preference != null) { preference.setEnabled(enabled); } }
Example 14
Source File: AvailableDevicesFragment.java From wearmouse with Apache License 2.0 | 5 votes |
protected void initScanDevices(Preference pref) { if (bluetoothAdapter.isDiscovering()) { pref.setEnabled(false); } pref.setOnPreferenceClickListener( (p) -> { clearAvailableDevices(); startDiscovery(); return true; }); }
Example 15
Source File: DictionarySettingsFragment.java From Android-Keyboard with Apache License 2.0 | 4 votes |
private static Preference createErrorMessage(final Activity activity, final int messageResource) { final Preference message = new Preference(activity); message.setTitle(messageResource); message.setEnabled(false); return message; }
Example 16
Source File: AccountManagementFragment.java From 365browser with Apache License 2.0 | 4 votes |
private void configureSignOutSwitch() { Preference signOutSwitch = findPreference(PREF_SIGN_OUT); if (mProfile.isChild()) { getPreferenceScreen().removePreference(signOutSwitch); } else { signOutSwitch.setEnabled(getSignOutAllowedPreferenceValue()); signOutSwitch.setOnPreferenceClickListener(new OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference preference) { if (!isVisible() || !isResumed()) return false; if (mSignedInAccountName != null && getSignOutAllowedPreferenceValue()) { AccountManagementScreenHelper.logEvent( ProfileAccountManagementMetrics.TOGGLE_SIGNOUT, mGaiaServiceType); String managementDomain = SigninManager.get(getActivity()).getManagementDomain(); if (managementDomain != null) { // Show the 'You are signing out of a managed account' dialog. ConfirmManagedSyncDataDialog.showSignOutFromManagedAccountDialog( AccountManagementFragment.this, getFragmentManager(), getResources(), managementDomain); } else { // Show the 'You are signing out' dialog. SignOutDialogFragment signOutFragment = new SignOutDialogFragment(); Bundle args = new Bundle(); args.putInt(SHOW_GAIA_SERVICE_TYPE_EXTRA, mGaiaServiceType); signOutFragment.setArguments(args); signOutFragment.setTargetFragment(AccountManagementFragment.this, 0); signOutFragment.show(getFragmentManager(), SIGN_OUT_DIALOG_TAG); } return true; } return false; } }); } }
Example 17
Source File: BatteryFu.java From BatteryFu with GNU General Public License v2.0 | 4 votes |
/** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Log.i("BatteryFu", "Loading on API level " + android.os.Build.VERSION.SDK); // Show the preferences screen try { Settings settings = Settings.getSettings(getApplicationContext()); if (settings.getNightmodeStart(null) == null) { // set night-mode defaults (TimePicker defaults not working) settings.setNightmodeStart(Settings.DEFAULT_NIGHT_MODE_START); settings.setNightmodeEnd(Settings.DEFAULT_NIGHT_MODE_END); } addPreferencesFromResource(R.xml.settings); // test apn mobileErrorMsg = MobileDataSwitcher.getSwitcher(this, settings).isToggleWorking(getApplicationContext()); if (mobileErrorMsg >= 1) { showDialog(DIALOG_APN_PROBLEM); } // Data while charging only supported in API level 4 and above if (Integer.parseInt(Build.VERSION.SDK) < 4) { Preference chargerOnData = findPreference("charger_on_data"); if (chargerOnData != null) { chargerOnData.setDependency(null); chargerOnData.setEnabled(false); chargerOnData.setSummary(R.string.requires_android_1_6); } } // on gingerbread or above, no hacks needed if (!(MobileDataSwitcher.getSwitcher(this, settings) instanceof APNSwitcher)) { Preference dnsFix = findPreference("dns_fix"); if (dnsFix != null) { dnsFix.setDependency(null); dnsFix.setEnabled(false); dnsFix.setSummary(R.string.not_needed_on_this_device); } } } catch (Exception e) { Log.e("BatteryFu", "Error creating activity", e); Toast.makeText(getApplicationContext(), e.getMessage(), Toast.LENGTH_LONG).show(); } }
Example 18
Source File: NotificationFragment.java From iBeebo with GNU General Public License v3.0 | 4 votes |
private void switchPre(boolean value) { for (Preference p : preferenceList) { p.setEnabled(value); } }
Example 19
Source File: PlaySettingsWrapper.java From Pedometer with Apache License 2.0 | 4 votes |
public static void setupAccountSetting(final Preference account, final Bundle savedInstanceState, final Activity_Main main) { account.setSummary("This feature is not available on the F-Droid version of the app"); account.setEnabled(false); }
Example 20
Source File: ManageSpaceActivity.java From MiPushFramework with GNU General Public License v3.0 | 4 votes |
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); addPreferencesFromResource(R.xml.fragmented_preferences); Context context = getActivity(); //Too bad in ui thread //TODO: Three messages seem to be too much, and need separate strings for toast. getPreferenceScreen().findPreference("clear_history").setOnPreferenceClickListener(preference -> { Toast.makeText(context, getString(R.string.settings_clear_history) + getString(R.string.start), Toast.LENGTH_SHORT).show(); EventDb.deleteHistory(context, null); Toast.makeText(context, getString(R.string.settings_clear_history) + getString(R.string.end), Toast.LENGTH_SHORT).show(); return true; }); getPreferenceScreen().findPreference("clear_log").setOnPreferenceClickListener(preference -> { Toast.makeText(context, getString(R.string.settings_clear_log) + getString(R.string.start), Toast.LENGTH_SHORT).show(); LogUtils.clearLog(context); Toast.makeText(context, getString(R.string.settings_clear_log) + getString(R.string.end), Toast.LENGTH_SHORT).show(); return true; }); getPreferenceScreen().findPreference("mock_notification").setOnPreferenceClickListener(preference -> { String packageName = Constants.MANAGER_APP_NAME; Date date = new Date(); String title = context.getString(R.string.debug_test_title); String description = context.getString(R.string.debug_test_content) + date.toString(); NotificationController.test(context, packageName, title, description); return true; }); PackageManager pm = context.getPackageManager(); ComponentName componentName = new ComponentName(Constants.SERVICE_APP_NAME, EmptyActivity.OnePlus.class.getName()); boolean disabled = pm.getComponentEnabledSetting(componentName) == COMPONENT_ENABLED_STATE_DISABLED; TwoStatePreference preferencePushIcon = (TwoStatePreference) getPreferenceScreen().findPreference("activity_push_icon"); preferencePushIcon.setChecked(!disabled); preferencePushIcon.setOnPreferenceClickListener(preference -> { TwoStatePreference switchPreference = (TwoStatePreference) preference; boolean enableLauncher = switchPreference.isChecked(); pm.setComponentEnabledSetting(componentName, enableLauncher ? PackageManager.COMPONENT_ENABLED_STATE_ENABLED : COMPONENT_ENABLED_STATE_DISABLED, PackageManager.DONT_KILL_APP); return true; }); Preference iceboxSupported = getPreferenceScreen().findPreference("IceboxSupported"); if (!Utils.isAppInstalled(IceBox.PACKAGE_NAME)) { iceboxSupported.setEnabled(false); iceboxSupported.setTitle(R.string.settings_icebox_not_installed); } else { iceboxSupported.setOnPreferenceChangeListener((preference, newValue) -> { Boolean value = (Boolean) newValue; if (value) { if (ContextCompat.checkSelfPermission(getActivity(), IceBox.SDK_PERMISSION) != PackageManager.PERMISSION_GRANTED) { ActivityCompat.requestPermissions(getActivity(), new String[]{IceBox.SDK_PERMISSION}, 0x233); } else { Toast.makeText(context, getString(R.string.icebox_permission_granted), Toast.LENGTH_SHORT).show(); } } return true; }); } }