use of androidx.preference.SwitchPreference in project android_packages_apps_Settings by omnirom.
the class ChannelListPreferenceController method addOrUpdateGroupToggle.
/**
* Add or find and update the toggle for disabling the entire notification channel group.
*/
private Preference addOrUpdateGroupToggle(@NonNull final PreferenceGroup parent, @NonNull final NotificationChannelGroup group) {
boolean shouldAdd = false;
final RestrictedSwitchPreference preference;
if (parent.getPreferenceCount() > 0 && parent.getPreference(0) instanceof RestrictedSwitchPreference) {
preference = (RestrictedSwitchPreference) parent.getPreference(0);
} else {
shouldAdd = true;
preference = new RestrictedSwitchPreference(mContext);
}
preference.setOrder(-1);
preference.setTitle(mContext.getString(R.string.notification_switch_label, group.getName()));
preference.setEnabled(mAdmin == null && isChannelGroupBlockable(group));
preference.setChecked(!group.isBlocked());
preference.setOnPreferenceClickListener(preference1 -> {
final boolean allowGroup = ((SwitchPreference) preference1).isChecked();
group.setBlocked(!allowGroup);
mBackend.updateChannelGroup(mAppRow.pkg, mAppRow.uid, group);
onGroupBlockStateChanged(group);
return true;
});
if (shouldAdd) {
parent.addPreference(preference);
}
return preference;
}
use of androidx.preference.SwitchPreference in project android_packages_apps_Settings by omnirom.
the class AutoSyncDataPreferenceControllerTest method autoSyncData_shouldNotBeSetOnCancel.
@Test
public void autoSyncData_shouldNotBeSetOnCancel() {
final Context context = RuntimeEnvironment.application;
final SwitchPreference preference = new SwitchPreference(context);
preference.setChecked(false);
mController = new AutoSyncDataPreferenceController(context, mFragment);
mConfirmSyncFragment.mPreference = preference;
mConfirmSyncFragment.mEnabling = true;
mConfirmSyncFragment.onClick(null, DialogInterface.BUTTON_NEGATIVE);
assertThat(preference.isChecked()).isFalse();
}
use of androidx.preference.SwitchPreference in project android_packages_apps_Settings by omnirom.
the class MmsMessagePreferenceControllerTest method setUp.
@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
mContext = spy(ApplicationProvider.getApplicationContext());
when(mContext.getSystemService(TelephonyManager.class)).thenReturn(mTelephonyManager);
when(mContext.getSystemService(Context.TELEPHONY_SERVICE)).thenReturn(mTelephonyManager);
when(mContext.getSystemService(SubscriptionManager.class)).thenReturn(mSubscriptionManager);
when(mTelephonyManager.createForSubscriptionId(SUB_ID)).thenReturn(mTelephonyManager);
mPreference = new SwitchPreference(mContext);
mController = new MmsMessagePreferenceController(mContext, "mms_message");
mController.init(SUB_ID);
mPreference.setKey(mController.getPreferenceKey());
}
use of androidx.preference.SwitchPreference in project android_packages_apps_Settings by omnirom.
the class BluetoothDetailsProfilesController method refreshProfilePreference.
/**
* Refreshes the state for an existing SwitchPreference for a profile.
*/
private void refreshProfilePreference(SwitchPreference profilePref, LocalBluetoothProfile profile) {
BluetoothDevice device = mCachedDevice.getDevice();
profilePref.setEnabled(!mCachedDevice.isBusy());
if (profile instanceof MapProfile) {
profilePref.setChecked(device.getMessageAccessPermission() == BluetoothDevice.ACCESS_ALLOWED);
} else if (profile instanceof PbapServerProfile) {
profilePref.setChecked(device.getPhonebookAccessPermission() == BluetoothDevice.ACCESS_ALLOWED);
} else if (profile instanceof PanProfile) {
profilePref.setChecked(profile.getConnectionStatus(device) == BluetoothProfile.STATE_CONNECTED);
} else {
profilePref.setChecked(profile.isEnabled(device));
}
if (profile instanceof A2dpProfile) {
A2dpProfile a2dp = (A2dpProfile) profile;
SwitchPreference highQualityPref = (SwitchPreference) mProfilesContainer.findPreference(HIGH_QUALITY_AUDIO_PREF_TAG);
if (highQualityPref != null) {
if (a2dp.isEnabled(device) && a2dp.supportsHighQualityAudio(device)) {
highQualityPref.setVisible(true);
highQualityPref.setTitle(a2dp.getHighQualityAudioOptionLabel(device));
highQualityPref.setChecked(a2dp.isHighQualityAudioEnabled(device));
highQualityPref.setEnabled(!mCachedDevice.isBusy());
} else {
highQualityPref.setVisible(false);
}
}
}
}
use of androidx.preference.SwitchPreference in project android_packages_apps_Settings by omnirom.
the class BluetoothDetailsProfilesController method onPreferenceClick.
/**
* When the pref for a bluetooth profile is clicked on, we want to toggle the enabled/disabled
* state for that profile.
*/
@Override
public boolean onPreferenceClick(Preference preference) {
LocalBluetoothProfile profile = mProfileManager.getProfileByName(preference.getKey());
if (profile == null) {
// It might be the PbapServerProfile, which is not stored by name.
PbapServerProfile psp = mManager.getProfileManager().getPbapProfile();
if (TextUtils.equals(preference.getKey(), psp.toString())) {
profile = psp;
} else {
return false;
}
}
SwitchPreference profilePref = (SwitchPreference) preference;
if (profilePref.isChecked()) {
enableProfile(profile);
} else {
disableProfile(profile);
}
refreshProfilePreference(profilePref, profile);
return true;
}
Aggregations