Search in sources :

Example 1 with SliceItem

use of androidx.slice.SliceItem in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class WifiCallingSliceHelperTest method testWifiCallingSettingsUnavailableSlice.

private void testWifiCallingSettingsUnavailableSlice(Slice slice, SliceData sliceData, PendingIntent expectedPrimaryAction, String title) {
    final SliceMetadata metadata = SliceMetadata.from(mContext, slice);
    // Check there is no toggle action
    final List<SliceAction> toggles = metadata.getToggles();
    assertThat(toggles).isEmpty();
    // Check whether the primary action is to open wifi calling settings activity
    final PendingIntent primaryPendingIntent = metadata.getPrimaryAction().getAction();
    assertThat(primaryPendingIntent).isEqualTo(expectedPrimaryAction);
    // Check the title
    final List<SliceItem> sliceItems = slice.getItems();
    assertTitle(sliceItems, title);
}
Also used : SliceMetadata(androidx.slice.SliceMetadata) SliceAction(androidx.slice.core.SliceAction) SliceItem(androidx.slice.SliceItem) PendingIntent(android.app.PendingIntent)

Example 2 with SliceItem

use of androidx.slice.SliceItem in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class NotificationChannelSliceTest method getSlice_hasSuggestedApp_shouldSortByNotificationSentCount.

@Test
@Config(shadows = ShadowRestrictedLockUtilsInternal.class)
public void getSlice_hasSuggestedApp_shouldSortByNotificationSentCount() {
    addMockPackageToPackageManager(true, /* isRecentlyInstalled */
    ApplicationInfo.FLAG_INSTALLED);
    mockNotificationBackend(CHANNEL_COUNT, NOTIFICATION_COUNT, false, /* banned */
    false);
    final Slice slice = mNotificationChannelSlice.getSlice();
    // Get all RowBuilders from Slice.
    final List<SliceItem> rowItems = SliceQuery.findAll(slice, FORMAT_SLICE, HINT_LIST_ITEM, null);
    // Ensure the total size of rows is equal to the notification channel count with header.
    assertThat(rowItems).isNotNull();
    assertThat(rowItems.size()).isEqualTo(CHANNEL_COUNT + 1);
    // Remove the header of slice.
    rowItems.remove(0);
    // Test the rows of slice are sorted with notification sent count by descending.
    for (int i = 0; i < rowItems.size(); i++) {
        // Assert the summary text is the same as expectation.
        assertThat(getSummaryFromSliceItem(rowItems.get(i))).isEqualTo(mContext.getResources().getQuantityString(R.plurals.notifications_sent_weekly, CHANNEL_COUNT - i, CHANNEL_COUNT - i));
    }
}
Also used : Slice(androidx.slice.Slice) ParceledListSlice(android.content.pm.ParceledListSlice) SliceItem(androidx.slice.SliceItem) Test(org.junit.Test) Config(org.robolectric.annotation.Config)

Example 3 with SliceItem

use of androidx.slice.SliceItem in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class DeviceInfoSliceTest method getSlice_hasSubscriptionInfo_shouldBeCorrectSliceContent.

@Test
public void getSlice_hasSubscriptionInfo_shouldBeCorrectSliceContent() {
    final String phoneNumber = "1111111111";
    doReturn(mSubscriptionInfo).when(mDeviceInfoSlice).getFirstSubscriptionInfo();
    doReturn(phoneNumber).when(mDeviceInfoSlice).getPhoneNumber();
    final Slice slice = mDeviceInfoSlice.getSlice();
    final SliceMetadata metadata = SliceMetadata.from(mContext, slice);
    assertThat(metadata.getTitle()).isEqualTo(mContext.getString(R.string.device_info_label));
    final SliceAction primaryAction = metadata.getPrimaryAction();
    final IconCompat expectedIcon = IconCompat.createWithResource(mContext, R.drawable.ic_info_outline_24dp);
    assertThat(primaryAction.getIcon().toString()).isEqualTo(expectedIcon.toString());
    final List<SliceItem> sliceItems = slice.getItems();
    SliceTester.assertAnySliceItemContainsTitle(sliceItems, phoneNumber);
}
Also used : Slice(androidx.slice.Slice) IconCompat(androidx.core.graphics.drawable.IconCompat) SliceMetadata(androidx.slice.SliceMetadata) SliceAction(androidx.slice.core.SliceAction) SliceItem(androidx.slice.SliceItem) Test(org.junit.Test)

Example 4 with SliceItem

use of androidx.slice.SliceItem in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class DeviceInfoSliceTest method getSlice_hasNoSubscriptionInfo_shouldShowUnknown.

@Test
public void getSlice_hasNoSubscriptionInfo_shouldShowUnknown() {
    final Slice slice = mDeviceInfoSlice.getSlice();
    final SliceMetadata metadata = SliceMetadata.from(mContext, slice);
    assertThat(metadata.getTitle()).isEqualTo(mContext.getString(R.string.device_info_label));
    final List<SliceItem> sliceItems = slice.getItems();
    SliceTester.assertAnySliceItemContainsTitle(sliceItems, mContext.getString(R.string.device_info_default));
}
Also used : Slice(androidx.slice.Slice) SliceMetadata(androidx.slice.SliceMetadata) SliceItem(androidx.slice.SliceItem) Test(org.junit.Test)

Example 5 with SliceItem

use of androidx.slice.SliceItem in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class Enhanced4gLteSliceHelperTest method assertTitle.

private void assertTitle(List<SliceItem> sliceItems, String title) {
    boolean hasTitle = false;
    for (SliceItem item : sliceItems) {
        List<SliceItem> titleItems = SliceQuery.findAll(item, FORMAT_TEXT, HINT_TITLE, null);
        if (titleItems == null) {
            continue;
        }
        hasTitle = true;
        for (SliceItem subTitleItem : titleItems) {
            assertThat(subTitleItem.getText()).isEqualTo(title);
        }
    }
    assertThat(hasTitle).isTrue();
}
Also used : SliceItem(androidx.slice.SliceItem)

Aggregations

SliceItem (androidx.slice.SliceItem)46 SliceMetadata (androidx.slice.SliceMetadata)23 Slice (androidx.slice.Slice)22 Test (org.junit.Test)21 PendingIntent (android.app.PendingIntent)19 SliceAction (androidx.slice.core.SliceAction)19 IconCompat (androidx.core.graphics.drawable.IconCompat)6 ParceledListSlice (android.content.pm.ParceledListSlice)2 Intent (android.content.Intent)1 UiThreadTest (androidx.test.annotation.UiThreadTest)1 WifiSliceItem (com.android.settings.wifi.slice.WifiSliceItem)1 AccessPoint (com.android.settingslib.wifi.AccessPoint)1 Config (org.robolectric.annotation.Config)1