Java Code Examples for androidx.preference.Preference#setVisible()
The following examples show how to use
androidx.preference.Preference#setVisible() .
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: RecipientPreferenceActivity.java From mollyim-android with GNU General Public License v3.0 | 4 votes |
@Override public void onCreate(Bundle icicle) { Log.i(TAG, "onCreate (fragment)"); super.onCreate(icicle); initializeRecipients(); this.canHaveSafetyNumber = recipient.get().isRegistered() && !recipient.get().isLocalNumber(); Preference customNotificationsPref = this.findPreference(PREFERENCE_CUSTOM_NOTIFICATIONS); if (NotificationChannels.supported()) { ((SwitchPreferenceCompat) customNotificationsPref).setChecked(recipient.get().getNotificationChannel() != null); customNotificationsPref.setOnPreferenceChangeListener(new CustomNotificationsChangedListener()); this.findPreference(PREFERENCE_MESSAGE_TONE).setDependency(PREFERENCE_CUSTOM_NOTIFICATIONS); this.findPreference(PREFERENCE_MESSAGE_VIBRATE).setDependency(PREFERENCE_CUSTOM_NOTIFICATIONS); if (recipient.get().getNotificationChannel() != null) { final Context context = requireContext(); new AsyncTask<Void, Void, Void>() { @Override protected Void doInBackground(Void... voids) { RecipientDatabase db = DatabaseFactory.getRecipientDatabase(getContext()); db.setMessageRingtone(recipient.getId(), NotificationChannels.getMessageRingtone(context, recipient.get())); db.setMessageVibrate(recipient.getId(), NotificationChannels.getMessageVibrate(context, recipient.get()) ? VibrateState.ENABLED : VibrateState.DISABLED); NotificationChannels.ensureCustomChannelConsistency(context); return null; } }.executeOnExecutor(AsyncTask.SERIAL_EXECUTOR); } } else { customNotificationsPref.setVisible(false); } this.findPreference(PREFERENCE_MESSAGE_TONE) .setOnPreferenceChangeListener(new RingtoneChangeListener(false)); this.findPreference(PREFERENCE_MESSAGE_TONE) .setOnPreferenceClickListener(new RingtoneClickedListener(false)); this.findPreference(PREFERENCE_CALL_TONE) .setOnPreferenceChangeListener(new RingtoneChangeListener(true)); this.findPreference(PREFERENCE_CALL_TONE) .setOnPreferenceClickListener(new RingtoneClickedListener(true)); this.findPreference(PREFERENCE_MESSAGE_VIBRATE) .setOnPreferenceChangeListener(new VibrateChangeListener(false)); this.findPreference(PREFERENCE_CALL_VIBRATE) .setOnPreferenceChangeListener(new VibrateChangeListener(true)); this.findPreference(PREFERENCE_MUTED) .setOnPreferenceClickListener(new MuteClickedListener()); this.findPreference(PREFERENCE_BLOCK) .setOnPreferenceClickListener(new BlockClickedListener()); this.findPreference(PREFERENCE_COLOR) .setOnPreferenceChangeListener(new ColorChangeListener()); ((ContactPreference)this.findPreference(PREFERENCE_ABOUT)) .setListener(new AboutNumberClickedListener()); }
Example 2
Source File: RecipientPreferenceActivity.java From mollyim-android with GNU General Public License v3.0 | 4 votes |
private void setSummaries(Recipient recipient) { CheckBoxPreference mutePreference = (CheckBoxPreference) this.findPreference(PREFERENCE_MUTED); Preference customPreference = this.findPreference(PREFERENCE_CUSTOM_NOTIFICATIONS); Preference ringtoneMessagePreference = this.findPreference(PREFERENCE_MESSAGE_TONE); Preference ringtoneCallPreference = this.findPreference(PREFERENCE_CALL_TONE); ListPreference vibrateMessagePreference = (ListPreference) this.findPreference(PREFERENCE_MESSAGE_VIBRATE); ListPreference vibrateCallPreference = (ListPreference) this.findPreference(PREFERENCE_CALL_VIBRATE); ColorPickerPreference colorPreference = (ColorPickerPreference) this.findPreference(PREFERENCE_COLOR); Preference blockPreference = this.findPreference(PREFERENCE_BLOCK); Preference identityPreference = this.findPreference(PREFERENCE_IDENTITY); PreferenceCategory callCategory = (PreferenceCategory)this.findPreference("call_settings"); PreferenceCategory aboutCategory = (PreferenceCategory)this.findPreference("about"); PreferenceCategory aboutDivider = (PreferenceCategory)this.findPreference("about_divider"); ContactPreference aboutPreference = (ContactPreference)this.findPreference(PREFERENCE_ABOUT); PreferenceCategory privacyCategory = (PreferenceCategory) this.findPreference("privacy_settings"); PreferenceCategory divider = (PreferenceCategory) this.findPreference("divider"); mutePreference.setChecked(recipient.isMuted()); ringtoneMessagePreference.setSummary(ringtoneMessagePreference.isEnabled() ? getRingtoneSummary(getContext(), recipient.getMessageRingtone()) : ""); ringtoneCallPreference.setSummary(getRingtoneSummary(getContext(), recipient.getCallRingtone())); Pair<String, Integer> vibrateMessageSummary = getVibrateSummary(getContext(), recipient.getMessageVibrate()); Pair<String, Integer> vibrateCallSummary = getVibrateSummary(getContext(), recipient.getCallVibrate()); vibrateMessagePreference.setSummary(vibrateMessagePreference.isEnabled() ? vibrateMessageSummary.first : ""); vibrateMessagePreference.setValueIndex(vibrateMessageSummary.second); vibrateCallPreference.setSummary(vibrateCallSummary.first); vibrateCallPreference.setValueIndex(vibrateCallSummary.second); blockPreference.setVisible(RecipientUtil.isBlockable(recipient)); if (recipient.isBlocked()) blockPreference.setTitle(R.string.RecipientPreferenceActivity_unblock); else blockPreference.setTitle(R.string.RecipientPreferenceActivity_block); if (recipient.isLocalNumber()) { mutePreference.setVisible(false); customPreference.setVisible(false); ringtoneMessagePreference.setVisible(false); vibrateMessagePreference.setVisible(false); if (identityPreference != null) identityPreference.setVisible(false); if (aboutCategory != null) aboutCategory.setVisible(false); if (aboutDivider != null) aboutDivider.setVisible(false); if (privacyCategory != null) privacyCategory.setVisible(false); if (divider != null) divider.setVisible(false); if (callCategory != null) callCategory.setVisible(false); } if (recipient.isGroup()) { if (colorPreference != null) colorPreference.setVisible(false); if (identityPreference != null) identityPreference.setVisible(false); if (callCategory != null) callCategory.setVisible(false); if (aboutCategory != null) aboutCategory.setVisible(false); if (aboutDivider != null) aboutDivider.setVisible(false); if (divider != null) divider.setVisible(false); } else { colorPreference.setColors(MaterialColors.CONVERSATION_PALETTE.asConversationColorArray(requireActivity())); colorPreference.setColor(recipient.getColor().toActionBarColor(requireActivity())); if (FeatureFlags.profileDisplay()) { aboutPreference.setTitle(recipient.getDisplayName(requireContext())); aboutPreference.setSummary(recipient.resolve().getE164().or("")); } else { aboutPreference.setTitle(formatRecipient(recipient)); aboutPreference.setSummary(recipient.getCustomLabel()); } aboutPreference.setState(recipient.getRegistered() == RecipientDatabase.RegisteredState.REGISTERED, recipient.isBlocked()); IdentityUtil.getRemoteIdentityKey(getActivity(), recipient).addListener(new ListenableFuture.Listener<Optional<IdentityRecord>>() { @Override public void onSuccess(Optional<IdentityRecord> result) { if (result.isPresent()) { if (identityPreference != null) identityPreference.setOnPreferenceClickListener(new IdentityClickedListener(result.get())); if (identityPreference != null) identityPreference.setEnabled(true); } else if (canHaveSafetyNumber) { if (identityPreference != null) identityPreference.setSummary(R.string.RecipientPreferenceActivity_available_once_a_message_has_been_sent_or_received); if (identityPreference != null) identityPreference.setEnabled(false); } else { if (identityPreference != null) getPreferenceScreen().removePreference(identityPreference); } } @Override public void onFailure(ExecutionException e) { if (identityPreference != null) getPreferenceScreen().removePreference(identityPreference); } }); } if (recipient.isMmsGroup() && privacyCategory != null) { privacyCategory.setVisible(false); } }
Example 3
Source File: SettingsFragment.java From vinyl-cast with MIT License | 4 votes |
@Override public void onCreatePreferences(Bundle savedInstanceState, String rootKey) { Timber.d("onCreatePreferences"); setPreferencesFromResource(R.xml.preferences, rootKey); AudioDevicePreference recordingDevicePref = findPreference(R.string.prefs_key_recording_device_id); AudioDevicePreference playbackDevicePref = findPreference(R.string.prefs_key_local_playback_device_id); CheckBoxPreference lowLatencyPref = findPreference(R.string.prefs_key_low_latency); ListPreference audioEncodingPref = findPreference(R.string.prefs_key_audio_encoding); Preference feedbackPref = findPreference(R.string.prefs_key_feedback); Preference androidApiLevelPref = findPreference(R.string.prefs_key_android_api_level); Preference appVersionPref = findPreference(R.string.prefs_key_app_version); if (recordingDevicePref != null) { recordingDevicePref.setDirectionType(AudioManager.GET_DEVICES_INPUTS); recordingDevicePref.setOnPreferenceClickListener(disabledPreferenceClickListener); recordingDevicePref.setOnPreferenceChangeListener(audioDeviceOnChangeListener); } if (playbackDevicePref != null) { playbackDevicePref.setDirectionType(AudioManager.GET_DEVICES_OUTPUTS); playbackDevicePref.setOnPreferenceClickListener(disabledPreferenceClickListener); playbackDevicePref.setOnPreferenceChangeListener(audioDeviceOnChangeListener); } if (lowLatencyPref != null) { lowLatencyPref.setOnPreferenceClickListener(disabledPreferenceClickListener); } if (audioEncodingPref != null) { audioEncodingPref.setEntries(R.array.prefs_audio_encoding_entries); audioEncodingPref.setEntryValues(R.array.prefs_audio_encoding_entry_values); audioEncodingPref.setOnPreferenceClickListener(disabledPreferenceClickListener); } if (feedbackPref != null && BuildConfig.FLAVOR.equals("playstore")) { feedbackPref.setVisible(true); feedbackPref.setOnPreferenceClickListener(preference -> { try { // Use reflection to get Instabug since only available in playstore product flavor Class instabugClazz = Class.forName("com.instabug.library.Instabug"); if (binder != null) { //Instabug.setUserAttribute("Audio API", getAudioApiVersionString()); Method setUserAttributeMethod = instabugClazz.getMethod("setUserAttribute", String.class, String.class); setUserAttributeMethod.invoke(null, "Audio API", getAudioApiVersionString()); } //Instabug.show(); Method showMethod = instabugClazz.getMethod("show"); showMethod.invoke(null); } catch (ReflectiveOperationException e) { e.printStackTrace(); } return true; }); } if (androidApiLevelPref != null) { androidApiLevelPref.setSummaryProvider(preference -> Integer.toString(Build.VERSION.SDK_INT) ); } if (appVersionPref != null) { appVersionPref.setSummaryProvider(preference -> String.format(Locale.getDefault(), "%s (%d)", BuildConfig.VERSION_NAME, BuildConfig.VERSION_CODE) ); } // set initial state of dynamic preferences updateDynamicPreferences(); }