Java Code Examples for androidx.preference.PreferenceManager#findPreference()
The following examples show how to use
androidx.preference.PreferenceManager#findPreference() .
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: EventPreferencesNFC.java From PhoneProfilesPlus with Apache License 2.0 | 6 votes |
void setAllSummary(PreferenceManager prefMng, SharedPreferences preferences, Context context) { setSummary(prefMng, PREF_EVENT_NFC_ENABLED, preferences, context); setSummary(prefMng, PREF_EVENT_NFC_NFC_TAGS, preferences, context); setSummary(prefMng, PREF_EVENT_NFC_PERMANENT_RUN, preferences, context); setSummary(prefMng, PREF_EVENT_NFC_DURATION, preferences, context); if (Event.isEventPreferenceAllowed(PREF_EVENT_NFC_ENABLED, context).allowed != PreferenceAllowed.PREFERENCE_ALLOWED) { Preference preference = prefMng.findPreference(PREF_EVENT_NFC_ENABLED); if (preference != null) preference.setEnabled(false); preference = prefMng.findPreference(PREF_EVENT_NFC_NFC_TAGS); if (preference != null) preference.setEnabled(false); preference = prefMng.findPreference(PREF_EVENT_NFC_DURATION); if (preference != null) preference.setEnabled(false); } }
Example 2
Source File: EventPreferencesNFC.java From PhoneProfilesPlus with Apache License 2.0 | 6 votes |
@Override void checkPreferences(PreferenceManager prefMng, Context context) { boolean enabled = Event.isEventPreferenceAllowed(PREF_EVENT_NFC_ENABLED, context).allowed == PreferenceAllowed.PREFERENCE_ALLOWED; Preference nfcTagsPreference = prefMng.findPreference(PREF_EVENT_NFC_NFC_TAGS); Preference permanentRunPreference = prefMng.findPreference(PREF_EVENT_NFC_PERMANENT_RUN); Preference durationPreference = prefMng.findPreference(PREF_EVENT_NFC_DURATION); if (nfcTagsPreference != null) nfcTagsPreference.setEnabled(enabled); if (permanentRunPreference != null) permanentRunPreference.setEnabled(enabled); SharedPreferences preferences = prefMng.getSharedPreferences(); if (preferences != null) { boolean permanentRun = preferences.getBoolean(PREF_EVENT_NFC_PERMANENT_RUN, false); enabled = enabled && (!permanentRun); if (durationPreference != null) durationPreference.setEnabled(enabled); } }
Example 3
Source File: SettingsActivity.java From Hauk with Apache License 2.0 | 5 votes |
private static void setTextEditParams(PreferenceManager manager, info.varden.hauk.system.preferences.Preference<?> preference, EditTextPreference.OnBindEditTextListener... listeners) { EditTextPreference pref = manager.findPreference(preference.getKey()); if (pref != null) { pref.setOnBindEditTextListener(new CascadeBindListener(listeners)); } else { Log.wtf("Could not find setting for preference %s setting OnBindEditTextListener", preference); //NON-NLS } }
Example 4
Source File: SettingsActivity.java From Hauk with Apache License 2.0 | 5 votes |
private static void setChangeListeners(PreferenceManager manager, info.varden.hauk.system.preferences.Preference<?> preference, Preference.OnPreferenceChangeListener... listeners) { Preference pref = manager.findPreference(preference.getKey()); if (pref != null) { pref.setOnPreferenceChangeListener(new CascadeChangeListener(listeners)); } else { Log.wtf("Could not find setting for preference %s when setting OnPreferenceChangeListener", preference); //NON-NLS } }
Example 5
Source File: SettingsFragment.java From android-notification-log with MIT License | 5 votes |
@Override public void onCreatePreferences(Bundle bundle, String s) { addPreferencesFromResource(R.xml.preferences); PreferenceManager pm = getPreferenceManager(); prefStatus = pm.findPreference(Const.PREF_STATUS); if(prefStatus != null) { prefStatus.setOnPreferenceClickListener(preference -> { startActivity(new Intent("android.settings.ACTION_NOTIFICATION_LISTENER_SETTINGS")); return true; }); } prefBrowse = pm.findPreference(Const.PREF_BROWSE); if(prefBrowse != null) { prefBrowse.setOnPreferenceClickListener(preference -> { startActivity(new Intent(getActivity(), BrowseActivity.class)); return true; }); } prefText = pm.findPreference(Const.PREF_TEXT); prefOngoing = pm.findPreference(Const.PREF_ONGOING); Preference prefAbout = pm.findPreference(Const.PREF_ABOUT); if(prefAbout != null) { prefAbout.setOnPreferenceClickListener(preference -> { Intent intent = new Intent(Intent.ACTION_VIEW); intent.setData(Uri.parse("https://github.com/interactionlab/android-notification-log")); startActivity(intent); return true; }); } Preference prefVersion = pm.findPreference(Const.PREF_VERSION); if(prefVersion != null) { prefVersion.setSummary(BuildConfig.VERSION_NAME + (Const.DEBUG ? " dev" : "")); } }
Example 6
Source File: Preferences.java From materialistic with Apache License 2.0 | 5 votes |
private static void sync(PreferenceManager preferenceManager, String key) { Preference pref = preferenceManager.findPreference(key); if (pref instanceof ListPreference) { ListPreference listPref = (ListPreference) pref; pref.setSummary(listPref.getEntry()); } }
Example 7
Source File: EventPreferencesAlarmClock.java From PhoneProfilesPlus with Apache License 2.0 | 5 votes |
void setAllSummary(PreferenceManager prefMng, SharedPreferences preferences, Context context) { setSummary(prefMng, PREF_EVENT_ALARM_CLOCK_ENABLED, preferences, context); setSummary(prefMng, PREF_EVENT_ALARM_CLOCK_PERMANENT_RUN, preferences, context); setSummary(prefMng, PREF_EVENT_ALARM_CLOCK_DURATION, preferences, context); setSummary(prefMng, PREF_EVENT_ALARM_CLOCK_APPLICATIONS, preferences, context); InfoDialogPreferenceX preference = prefMng.findPreference(PREF_EVENT_ALARM_CLOCK_SUPPORTED_APPS); if (preference != null) { String supportedApps = "<ul>" + "<li>Google Clock</li>" + "<li>Samsung Clock</li>" + "<li>Sony Clock</li>" + "<li>AMdroid</li>" + "<li>Alarm Clock XTreme free</li>" + "<li>Alarm Clock XTreme</li>" + "<li>Alarmy (Sleep if u can)</li>" + "<li>Early Bird Alarm Clock</li>" + "<li>Good Morning Alarm Clock</li>" + "<li>I Can't Wake Up! Alarm Clock</li>" + "<li>Sleep as Android</li>" + "<li>Timely</li>" + "<li>Alarm Klock</li>" + "</ul>" ; preference.setInfoText(supportedApps); preference.setIsHtml(true); } }
Example 8
Source File: EventPreferencesSMS.java From PhoneProfilesPlus with Apache License 2.0 | 5 votes |
@Override void checkPreferences(PreferenceManager prefMng, Context context) { final boolean accessibilityEnabled = PPPExtenderBroadcastReceiver.isEnabled(context.getApplicationContext(), PPApplication.VERSION_CODE_EXTENDER_3_0); SharedPreferences preferences = prefMng.getSharedPreferences(); boolean enabled = (preferences != null) && preferences.getBoolean(PREF_EVENT_SMS_ENABLED, false); Preference preference = prefMng.findPreference(PREF_EVENT_SMS_ACCESSIBILITY_SETTINGS); if (preference != null) GlobalGUIRoutines.setPreferenceTitleStyleX(preference, enabled, false, true, !accessibilityEnabled, false); setCategorySummary(prefMng, preferences, context); }
Example 9
Source File: EventPreferencesCall.java From PhoneProfilesPlus with Apache License 2.0 | 5 votes |
@Override void checkPreferences(PreferenceManager prefMng, Context context) { final boolean accessibilityEnabled = PPPExtenderBroadcastReceiver.isEnabled(context.getApplicationContext(), PPApplication.VERSION_CODE_EXTENDER_3_0); SharedPreferences preferences = prefMng.getSharedPreferences(); boolean enabled = (preferences != null) && preferences.getBoolean(PREF_EVENT_CALL_ENABLED, false); Preference preference = prefMng.findPreference(PREF_EVENT_CALL_ACCESSIBILITY_SETTINGS); if (preference != null) GlobalGUIRoutines.setPreferenceTitleStyleX(preference, enabled, false, true, !accessibilityEnabled, false); setCategorySummary(prefMng, preferences, context); }
Example 10
Source File: BasePreferenceFragment.java From XMiTools with GNU General Public License v3.0 | 4 votes |
@NonNull @Override public <T extends Preference> T findPreference(@NonNull CharSequence key) { PreferenceManager pm = getPreferenceManager(); return pm.findPreference(key); }
Example 11
Source File: SettingsActivity.java From Hauk with Apache License 2.0 | 4 votes |
@Override public void onCreatePreferences(Bundle savedInstanceState, String rootKey) { PreferenceManager manager = getPreferenceManager(); info.varden.hauk.system.preferences.PreferenceManager prefs = new info.varden.hauk.system.preferences.PreferenceManager(this.ctx); // Intercept all reads and writes so that values are properly validated and encrypted if // required by Preference. manager.setPreferenceDataStore(new PreferenceHandler(this.ctx)); // Load the preferences layout. setPreferencesFromResource(R.xml.root_preferences, rootKey); // Set InputType and other attributes for text edit boxes. setTextEditParams(manager, Constants.PREF_SERVER_ENCRYPTED, new InputTypeBindListener(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_URI), new HintBindListener(R.string.pref_cryptServer_hint)); setTextEditParams(manager, Constants.PREF_USERNAME_ENCRYPTED, new InputTypeBindListener(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PERSON_NAME), new HintBindListener(R.string.pref_cryptUsername_hint)); setTextEditParams(manager, Constants.PREF_PASSWORD_ENCRYPTED, new InputTypeBindListener(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD)); setTextEditParams(manager, Constants.PREF_E2E_PASSWORD, new InputTypeBindListener(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD)); setTextEditParams(manager, Constants.PREF_INTERVAL, new InputTypeBindListener(InputType.TYPE_CLASS_NUMBER)); setTextEditParams(manager, Constants.PREF_UPDATE_DISTANCE, new InputTypeBindListener(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_DECIMAL)); setTextEditParams(manager, Constants.PREF_CUSTOM_ID, new InputTypeBindListener(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_SHORT_MESSAGE), new HintBindListener(R.string.pref_requestLink_hint)); setTextEditParams(manager, Constants.PREF_PROXY_HOST, new InputTypeBindListener(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_URI)); setTextEditParams(manager, Constants.PREF_PROXY_PORT, new InputTypeBindListener(InputType.TYPE_CLASS_NUMBER)); setTextEditParams(manager, Constants.PREF_CONNECTION_TIMEOUT, new InputTypeBindListener(InputType.TYPE_CLASS_NUMBER)); // Set value bounds checks. setChangeListeners(manager, Constants.PREF_INTERVAL, new IntegerBoundChangeListener(1, Integer.MAX_VALUE)); setChangeListeners(manager, Constants.PREF_UPDATE_DISTANCE, new FloatBoundChangeListener(0.0F, Float.MAX_VALUE)); setChangeListeners(manager, Constants.PREF_PROXY_PORT, new IntegerBoundChangeListener(Constants.PORT_MIN, Constants.PORT_MAX)); setChangeListeners(manager, Constants.PREF_CONNECTION_TIMEOUT, new IntegerBoundChangeListener(1, Integer.MAX_VALUE)); // Set proxy settings disabled if proxy is set to default or none. setChangeListeners(manager, Constants.PREF_PROXY_TYPE, new ProxyPreferenceChangeListener(new Preference[]{ manager.findPreference(Constants.PREF_PROXY_HOST.getKey()), manager.findPreference(Constants.PREF_PROXY_PORT.getKey()) })); Preference proxyTypePref = manager.findPreference(Constants.PREF_PROXY_TYPE.getKey()); if (proxyTypePref != null) proxyTypePref.callChangeListener(String.valueOf(prefs.get(Constants.PREF_PROXY_TYPE).getIndex())); // Update night mode when its preference is changed. setChangeListeners(manager, Constants.PREF_NIGHT_MODE, new NightModeChangeListener()); manager.findPreference("dummy_version").setSummary(BuildConfig.VERSION_NAME); manager.findPreference("dummy_sourceCode").setOnPreferenceClickListener(new OpenLinkListener(this.ctx, R.string.label_source_link)); manager.findPreference("dummy_reportIssue").setOnPreferenceClickListener(new OpenLinkListener(this.ctx, R.string.link_issue_tracker)); }
Example 12
Source File: EventPreferencesOrientation.java From PhoneProfilesPlus with Apache License 2.0 | 4 votes |
@Override void checkPreferences(PreferenceManager prefMng, Context context) { SensorManager sensorManager = (SensorManager) context.getSystemService(Context.SENSOR_SERVICE); boolean hasAccelerometer = (sensorManager != null) && (sensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER) != null); boolean hasMagneticField = (sensorManager != null) && (sensorManager.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD) != null); boolean hasProximity = (sensorManager != null) && (sensorManager.getDefaultSensor(Sensor.TYPE_PROXIMITY) != null); boolean hasLight = (sensorManager != null) && (sensorManager.getDefaultSensor(Sensor.TYPE_LIGHT) != null); boolean enabledAll = (hasAccelerometer) && (hasMagneticField); Preference preference = prefMng.findPreference(PREF_EVENT_ORIENTATION_DISPLAY); if (preference != null) { if (!hasAccelerometer) preference.setSummary(context.getString(R.string.profile_preferences_device_not_allowed)+ ": "+context.getString(R.string.preference_not_allowed_reason_no_hardware)); preference.setEnabled(hasAccelerometer); } preference = prefMng.findPreference(PREF_EVENT_ORIENTATION_SIDES); if (preference != null) { if (!enabledAll) preference.setSummary(context.getString(R.string.profile_preferences_device_not_allowed)+ ": "+context.getString(R.string.preference_not_allowed_reason_no_hardware)); preference.setEnabled(enabledAll); } boolean enabled = hasProximity; preference = prefMng.findPreference(PREF_EVENT_ORIENTATION_DISTANCE); if (preference != null) { if (!enabled) preference.setSummary(context.getString(R.string.profile_preferences_device_not_allowed)+ ": "+context.getString(R.string.preference_not_allowed_reason_no_hardware)); preference.setEnabled(enabled); } SwitchPreferenceCompat switchPreference = prefMng.findPreference(PREF_EVENT_ORIENTATION_CHECK_LIGHT); if (switchPreference != null) { boolean checkLight = switchPreference.isChecked(); if (checkLight) { enabled = hasLight; preference = prefMng.findPreference(PREF_EVENT_ORIENTATION_LIGHT_MIN); if (preference != null) { if (!enabled) preference.setSummary(context.getString(R.string.profile_preferences_device_not_allowed) + ": " + context.getString(R.string.preference_not_allowed_reason_no_hardware)); preference.setEnabled(enabled); } preference = prefMng.findPreference(PREF_EVENT_ORIENTATION_LIGHT_MAX); if (preference != null) { if (!enabled) preference.setSummary(context.getString(R.string.profile_preferences_device_not_allowed) + ": " + context.getString(R.string.preference_not_allowed_reason_no_hardware)); preference.setEnabled(enabled); } } } enabled = PPPExtenderBroadcastReceiver.isEnabled(context.getApplicationContext(), PPApplication.VERSION_CODE_EXTENDER_3_0); ApplicationsMultiSelectDialogPreferenceX applicationsPreference = prefMng.findPreference(PREF_EVENT_ORIENTATION_IGNORED_APPLICATIONS); if (applicationsPreference != null) { applicationsPreference.setEnabled(enabled); applicationsPreference.setSummaryAMSDP(); } SharedPreferences preferences = prefMng.getSharedPreferences(); setSummary(prefMng, PREF_EVENT_ORIENTATION_APP_SETTINGS, preferences, context); setCategorySummary(prefMng, preferences, context); }
Example 13
Source File: Event.java From PhoneProfilesPlus with Apache License 2.0 | 4 votes |
public void setAllSummary(PreferenceManager prefMng, SharedPreferences preferences, Context context) { Preference preference = prefMng.findPreference(PREF_EVENT_FORCE_RUN); if (preference != null) preference.setTitle("[ยป] " + context.getString(R.string.event_preferences_ForceRun)); setSummary(prefMng, PREF_EVENT_ENABLED, preferences, context); setSummary(prefMng, PREF_EVENT_NAME, preferences, context); setSummary(prefMng, PREF_EVENT_PROFILE_START, preferences, context); setSummary(prefMng, PREF_EVENT_PROFILE_END, preferences, context); setSummary(prefMng, PREF_EVENT_NOTIFICATION_SOUND_START, preferences, context); setSummary(prefMng, PREF_EVENT_NOTIFICATION_VIBRATE_START, preferences, context); setSummary(prefMng, PREF_EVENT_NOTIFICATION_REPEAT_START, preferences, context); setSummary(prefMng, PREF_EVENT_NOTIFICATION_REPEAT_INTERVAL_START, preferences, context); setSummary(prefMng, PREF_EVENT_NOTIFICATION_SOUND_END, preferences, context); setSummary(prefMng, PREF_EVENT_NOTIFICATION_VIBRATE_END, preferences, context); setSummary(prefMng, PREF_EVENT_PRIORITY_APP_SETTINGS, preferences, context); setSummary(prefMng, PREF_EVENT_PRIORITY, preferences, context); setSummary(prefMng, PREF_EVENT_DELAY_START, preferences, context); setSummary(prefMng, PREF_EVENT_DELAY_END, preferences, context); setSummary(prefMng, PREF_EVENT_AT_END_DO, preferences, context); setSummary(prefMng, PREF_EVENT_START_WHEN_ACTIVATED_PROFILE, preferences, context); setSummary(prefMng, PREF_EVENT_FORCE_RUN, preferences, context); setSummary(prefMng, PREF_EVENT_MANUAL_PROFILE_ACTIVATION, preferences, context); setSummary(prefMng, PREF_EVENT_NO_PAUSE_BY_MANUAL_ACTIVATION, preferences, context); setCategorySummary(prefMng, "", preferences, context); _eventPreferencesTime.setAllSummary(prefMng, preferences, context); _eventPreferencesTime.setCategorySummary(prefMng, preferences, context); _eventPreferencesBattery.setAllSummary(prefMng, preferences, context); _eventPreferencesBattery.setCategorySummary(prefMng, preferences, context); _eventPreferencesCall.setAllSummary(prefMng, preferences, context); _eventPreferencesCall.setCategorySummary(prefMng, preferences, context); _eventPreferencesPeripherals.setAllSummary(prefMng, preferences, context); _eventPreferencesPeripherals.setCategorySummary(prefMng, preferences, context); _eventPreferencesCalendar.setAllSummary(prefMng, preferences, context); _eventPreferencesCalendar.setCategorySummary(prefMng, preferences, context); _eventPreferencesWifi.setAllSummary(prefMng, preferences, context); _eventPreferencesWifi.setCategorySummary(prefMng, preferences, context); _eventPreferencesScreen.setAllSummary(prefMng, preferences, context); _eventPreferencesScreen.setCategorySummary(prefMng, preferences, context); _eventPreferencesBluetooth.setAllSummary(prefMng, preferences, context); _eventPreferencesBluetooth.setCategorySummary(prefMng, preferences, context); _eventPreferencesSMS.setAllSummary(prefMng, preferences, context); _eventPreferencesSMS.setCategorySummary(prefMng, preferences, context); _eventPreferencesNotification.setAllSummary(prefMng, preferences, context); _eventPreferencesNotification.setCategorySummary(prefMng, preferences, context); _eventPreferencesApplication.setAllSummary(prefMng, preferences, context); _eventPreferencesApplication.setCategorySummary(prefMng, preferences, context); _eventPreferencesLocation.setAllSummary(prefMng, preferences, context); _eventPreferencesLocation.setCategorySummary(prefMng, preferences, context); _eventPreferencesOrientation.setAllSummary(prefMng, preferences, context); _eventPreferencesOrientation.setCategorySummary(prefMng, preferences, context); _eventPreferencesMobileCells.setAllSummary(prefMng, preferences, context); _eventPreferencesMobileCells.setCategorySummary(prefMng, preferences, context); _eventPreferencesNFC.setAllSummary(prefMng, preferences, context); _eventPreferencesNFC.setCategorySummary(prefMng, preferences, context); _eventPreferencesRadioSwitch.setAllSummary(prefMng, preferences, context); _eventPreferencesRadioSwitch.setCategorySummary(prefMng, preferences, context); _eventPreferencesAlarmClock.setAllSummary(prefMng, preferences, context); _eventPreferencesAlarmClock.setCategorySummary(prefMng, preferences, context); _eventPreferencesDeviceBoot.setAllSummary(prefMng, preferences, context); _eventPreferencesDeviceBoot.setCategorySummary(prefMng, preferences, context); }