Search in sources :

Example 71 with SwitchPreference

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);
    }
}
Also used : SwitchPreference(androidx.preference.SwitchPreference)

Example 72 with SwitchPreference

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());
    }
}
Also used : NotificationChannel(android.app.NotificationChannel) NotificationChannelGroup(android.app.NotificationChannelGroup) SwitchPreference(androidx.preference.SwitchPreference) PrimarySwitchPreference(com.android.settings.widget.PrimarySwitchPreference) ArrayList(java.util.ArrayList) PreferenceGroup(androidx.preference.PreferenceGroup) PrimarySwitchPreference(com.android.settings.widget.PrimarySwitchPreference) SmallTest(androidx.test.filters.SmallTest) Test(org.junit.Test) UiThreadTest(androidx.test.annotation.UiThreadTest) UiThreadTest(androidx.test.annotation.UiThreadTest)

Example 73 with SwitchPreference

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();
}
Also used : SwitchPreference(androidx.preference.SwitchPreference) Preference(androidx.preference.Preference) SwitchPreference(androidx.preference.SwitchPreference) ChangeConfig(android.compat.Compatibility.ChangeConfig) CompatibilityChangeConfig(com.android.internal.compat.CompatibilityChangeConfig) CompatibilityChangeConfig(com.android.internal.compat.CompatibilityChangeConfig) CompatibilityChangeInfo(com.android.internal.compat.CompatibilityChangeInfo) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 74 with SwitchPreference

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();
}
Also used : SwitchPreference(androidx.preference.SwitchPreference) Preference(androidx.preference.Preference) SwitchPreference(androidx.preference.SwitchPreference) ChangeConfig(android.compat.Compatibility.ChangeConfig) CompatibilityChangeConfig(com.android.internal.compat.CompatibilityChangeConfig) CompatibilityChangeConfig(com.android.internal.compat.CompatibilityChangeConfig) CompatibilityChangeInfo(com.android.internal.compat.CompatibilityChangeInfo) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 75 with SwitchPreference

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);
}
Also used : SwitchPreference(androidx.preference.SwitchPreference) Before(org.junit.Before)

Aggregations

SwitchPreference (androidx.preference.SwitchPreference)299 Test (org.junit.Test)125 Before (org.junit.Before)68 Intent (android.content.Intent)17 Preference (androidx.preference.Preference)17 ComponentName (android.content.ComponentName)10 A2dpProfile (com.android.settingslib.bluetooth.A2dpProfile)10 RestrictedSwitchPreference (com.android.settingslib.RestrictedSwitchPreference)8 PbapServerProfile (com.android.settingslib.bluetooth.PbapServerProfile)8 ListPreference (androidx.preference.ListPreference)7 PreferenceScreen (androidx.preference.PreferenceScreen)7 RemoteException (android.os.RemoteException)6 PreferenceCategory (androidx.preference.PreferenceCategory)6 HashSet (java.util.HashSet)6 Context (android.content.Context)5 Parcel (android.os.Parcel)5 VisibleForTesting (androidx.annotation.VisibleForTesting)5 BluetoothDevice (android.bluetooth.BluetoothDevice)4 ChangeConfig (android.compat.Compatibility.ChangeConfig)4 ServiceInfo (android.content.pm.ServiceInfo)4