use of androidx.preference.SwitchPreference in project android_packages_apps_Settings by omnirom.
the class ZenRuleRepeatCallersPreferenceController method updateState.
@Override
public void updateState(Preference preference) {
super.updateState(preference);
if (mRule == null || mRule.getZenPolicy() == null) {
return;
}
SwitchPreference pref = (SwitchPreference) preference;
boolean anyCallersCanBypassDnd = mRule.getZenPolicy().getPriorityCallSenders() == ZenPolicy.PEOPLE_TYPE_ANYONE;
// if any caller can bypass dnd then repeat callers preference is disabled
if (anyCallersCanBypassDnd) {
pref.setEnabled(false);
pref.setChecked(true);
} else {
pref.setEnabled(true);
pref.setChecked(mRule.getZenPolicy().getPriorityCategoryRepeatCallers() == ZenPolicy.STATE_ALLOW);
}
}
use of androidx.preference.SwitchPreference in project android_packages_apps_Settings by omnirom.
the class ChannelListPreferenceControllerTest method testUpdateFullList_groupBlockedChange.
@Test
@UiThreadTest
public void testUpdateFullList_groupBlockedChange() {
List<NotificationChannelGroup> inGroups = new ArrayList<>();
NotificationChannelGroup inGroup = new NotificationChannelGroup("group", "My Group");
inGroup.addChannel(new NotificationChannel("channelA", "Channel A", IMPORTANCE_DEFAULT));
inGroup.addChannel(new NotificationChannel("channelB", "Channel B", IMPORTANCE_NONE));
inGroups.add(inGroup);
// Test that the group is initially showing all preferences
mController.updateFullList(mGroupList, inGroups);
{
assertEquals(1, mGroupList.getPreferenceCount());
PreferenceGroup group = (PreferenceGroup) mGroupList.getPreference(0);
assertEquals("group", group.getKey());
assertEquals(3, group.getPreferenceCount());
SwitchPreference groupBlockPref = (SwitchPreference) group.getPreference(0);
assertNull(groupBlockPref.getKey());
assertEquals("All \"My Group\" notifications", groupBlockPref.getTitle());
assertTrue(groupBlockPref.isChecked());
PrimarySwitchPreference channelAPref = (PrimarySwitchPreference) group.getPreference(1);
assertEquals("channelA", channelAPref.getKey());
assertEquals("Channel A", channelAPref.getTitle());
assertEquals(Boolean.TRUE, channelAPref.getCheckedState());
PrimarySwitchPreference channelBPref = (PrimarySwitchPreference) group.getPreference(2);
assertEquals("channelB", channelBPref.getKey());
assertEquals("Channel B", channelBPref.getTitle());
assertEquals(Boolean.FALSE, channelBPref.getCheckedState());
}
// Test that when a group is blocked, the list removes its individual channel preferences
inGroup.setBlocked(true);
mController.updateFullList(mGroupList, inGroups);
{
assertEquals(1, mGroupList.getPreferenceCount());
PreferenceGroup group = (PreferenceGroup) mGroupList.getPreference(0);
assertEquals("group", group.getKey());
assertEquals(1, group.getPreferenceCount());
SwitchPreference groupBlockPref = (SwitchPreference) group.getPreference(0);
assertNull(groupBlockPref.getKey());
assertEquals("All \"My Group\" notifications", groupBlockPref.getTitle());
assertFalse(groupBlockPref.isChecked());
}
// Test that when a group is unblocked, the list adds its individual channel preferences
inGroup.setBlocked(false);
mController.updateFullList(mGroupList, inGroups);
{
assertEquals(1, mGroupList.getPreferenceCount());
PreferenceGroup group = (PreferenceGroup) mGroupList.getPreference(0);
assertEquals("group", group.getKey());
assertEquals(3, group.getPreferenceCount());
SwitchPreference groupBlockPref = (SwitchPreference) group.getPreference(0);
assertNull(groupBlockPref.getKey());
assertEquals("All \"My Group\" notifications", groupBlockPref.getTitle());
assertTrue(groupBlockPref.isChecked());
PrimarySwitchPreference channelAPref = (PrimarySwitchPreference) group.getPreference(1);
assertEquals("channelA", channelAPref.getKey());
assertEquals("Channel A", channelAPref.getTitle());
assertEquals(Boolean.TRUE, channelAPref.getCheckedState());
PrimarySwitchPreference channelBPref = (PrimarySwitchPreference) group.getPreference(2);
assertEquals("channelB", channelBPref.getKey());
assertEquals("Channel B", channelBPref.getTitle());
assertEquals(Boolean.FALSE, channelBPref.getCheckedState());
}
}
use of androidx.preference.SwitchPreference in project android_packages_apps_Settings by omnirom.
the class PlatformCompatDashboardTest method createPreferenceForChange_defaultEnabledChange_createCheckedEntry.
@Test
public void createPreferenceForChange_defaultEnabledChange_createCheckedEntry() {
CompatibilityChangeInfo enabledChange = mChanges[0];
CompatibilityChangeConfig config = new CompatibilityChangeConfig(new ChangeConfig(new HashSet<Long>(Arrays.asList(enabledChange.getId())), new HashSet<Long>()));
Preference enabledPreference = mDashboard.createPreferenceForChange(mContext, enabledChange, config);
SwitchPreference enabledSwitchPreference = (SwitchPreference) enabledPreference;
assertThat(enabledPreference.getSummary()).isEqualTo(mChanges[0].getName());
assertThat(enabledPreference instanceof SwitchPreference).isTrue();
assertThat(enabledSwitchPreference.isChecked()).isTrue();
assertThat(enabledSwitchPreference.isEnabled()).isTrue();
}
use of androidx.preference.SwitchPreference in project android_packages_apps_Settings by omnirom.
the class PlatformCompatDashboardTest method createPreferenceForChange_defaultDisabledChange_createUncheckedEntry.
@Test
public void createPreferenceForChange_defaultDisabledChange_createUncheckedEntry() {
CompatibilityChangeInfo disabledChange = mChanges[1];
CompatibilityChangeConfig config = new CompatibilityChangeConfig(new ChangeConfig(new HashSet<Long>(), new HashSet<Long>(Arrays.asList(disabledChange.getId()))));
Preference disabledPreference = mDashboard.createPreferenceForChange(mContext, disabledChange, config);
assertThat(disabledPreference.getSummary()).isEqualTo(mChanges[1].getName());
SwitchPreference disabledSwitchPreference = (SwitchPreference) disabledPreference;
assertThat(disabledSwitchPreference.isChecked()).isFalse();
assertThat(disabledSwitchPreference.isEnabled()).isTrue();
}
use of androidx.preference.SwitchPreference in project android_packages_apps_Settings by omnirom.
the class ShowFirstCrashDialogPreferenceControllerTest method setup.
@Before
public void setup() {
MockitoAnnotations.initMocks(this);
mContext = RuntimeEnvironment.application;
mPreference = new SwitchPreference(mContext);
mController = new ShowFirstCrashDialogPreferenceController(mContext);
when(mPreferenceScreen.findPreference(mController.getPreferenceKey())).thenReturn(mPreference);
mController.displayPreference(mPreferenceScreen);
}
Aggregations