Search in sources :

Example 6 with SliceItem

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

the class Enhanced4gLteSliceHelperTest method testEnhanced4gLteSettingsUnavailableSlice.

private void testEnhanced4gLteSettingsUnavailableSlice(Slice slice, PendingIntent expectedPrimaryAction) {
    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 Enhanced4gLte settings activity
    final PendingIntent primaryPendingIntent = metadata.getPrimaryAction().getAction();
    assertThat(primaryPendingIntent).isEqualTo(expectedPrimaryAction);
    // Check the title
    final List<SliceItem> sliceItems = slice.getItems();
    assertTitle(sliceItems, mContext.getString(R.string.enhanced_4g_lte_mode_title));
}
Also used : SliceMetadata(androidx.slice.SliceMetadata) SliceAction(androidx.slice.core.SliceAction) SliceItem(androidx.slice.SliceItem) PendingIntent(android.app.PendingIntent)

Example 7 with SliceItem

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

the class SliceTester method assertAnySliceItemContainsIcon.

/**
 * Assert any slice item contains icon.
 *
 * @param sliceItems All slice items of a Slice.
 * @param icon Icon for asserting.
 */
public static void assertAnySliceItemContainsIcon(List<SliceItem> sliceItems, IconCompat icon) {
    boolean hasIcon = false;
    for (SliceItem item : sliceItems) {
        List<SliceItem> iconItems = SliceQuery.findAll(item, FORMAT_IMAGE, (String) null, /* hints */
        null);
        if (iconItems == null) {
            continue;
        }
        for (SliceItem iconItem : iconItems) {
            if (icon.toString().equals(iconItem.getIcon().toString())) {
                hasIcon = true;
                break;
            }
        }
    }
    assertThat(hasIcon).isTrue();
}
Also used : SliceItem(androidx.slice.SliceItem)

Example 8 with SliceItem

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

the class SliceTester method testSettingsUnavailableSlice.

/**
 * Test the contents of an unavailable slice, including:
 * - No toggles
 * - Correct title
 * - Correct intent
 * - Correct keywords
 * - Color
 * - TTL
 */
public static void testSettingsUnavailableSlice(Context context, Slice slice, SliceData sliceData) {
    final SliceMetadata metadata = SliceMetadata.from(context, slice);
    final long sliceTTL = metadata.getExpiry();
    assertThat(sliceTTL).isEqualTo(ListBuilder.INFINITY);
    final SliceItem colorItem = SliceQuery.findSubtype(slice, FORMAT_INT, SUBTYPE_COLOR);
    final int color = colorItem.getInt();
    assertThat(color).isEqualTo(Utils.getColorAccentDefaultColor(context));
    final List<SliceAction> toggles = metadata.getToggles();
    assertThat(toggles).isEmpty();
    final PendingIntent primaryPendingIntent = metadata.getPrimaryAction().getAction();
    assertThat(primaryPendingIntent).isEqualTo(SliceBuilderUtils.getContentPendingIntent(context, sliceData));
    assertThat(metadata.getTitle()).isEqualTo(sliceData.getTitle());
    assertKeywords(metadata, sliceData);
}
Also used : SliceMetadata(androidx.slice.SliceMetadata) SliceAction(androidx.slice.core.SliceAction) SliceItem(androidx.slice.SliceItem) PendingIntent(android.app.PendingIntent)

Example 9 with SliceItem

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

the class SliceTester method testSettingsSliderSlice.

/**
 * Test the contents of an slider based slice, including:
 * - No intent
 * - Correct title
 * - Correct keywords
 * - TTL
 * - Color
 */
public static void testSettingsSliderSlice(Context context, Slice slice, SliceData sliceData) {
    final SliceMetadata metadata = SliceMetadata.from(context, slice);
    final SliceItem colorItem = SliceQuery.findSubtype(slice, FORMAT_INT, SUBTYPE_COLOR);
    final int color = colorItem.getInt();
    assertThat(color).isEqualTo(Utils.getColorAccentDefaultColor(context));
    final SliceAction primaryAction = metadata.getPrimaryAction();
    final IconCompat expectedIcon = IconCompat.createWithResource(context, sliceData.getIconResource());
    assertThat(expectedIcon.toString()).isEqualTo(primaryAction.getIcon().toString());
    final long sliceTTL = metadata.getExpiry();
    assertThat(sliceTTL).isEqualTo(ListBuilder.INFINITY);
    final int headerType = metadata.getHeaderType();
    assertThat(headerType).isEqualTo(EventInfo.ROW_TYPE_SLIDER);
    // Check primary intent
    final PendingIntent primaryPendingIntent = primaryAction.getAction();
    assertThat(primaryPendingIntent).isEqualTo(SliceBuilderUtils.getContentPendingIntent(context, sliceData));
    assertThat(metadata.getTitle()).isEqualTo(sliceData.getTitle());
    assertKeywords(metadata, sliceData);
}
Also used : IconCompat(androidx.core.graphics.drawable.IconCompat) SliceMetadata(androidx.slice.SliceMetadata) SliceAction(androidx.slice.core.SliceAction) SliceItem(androidx.slice.SliceItem) PendingIntent(android.app.PendingIntent)

Example 10 with SliceItem

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

the class WifiSliceTest method getWifiSlice_noAp_shouldReturnLoadingRow.

@Test
public void getWifiSlice_noAp_shouldReturnLoadingRow() {
    final Slice wifiSlice = mWifiSlice.getSlice();
    final int rows = SliceQuery.findAll(wifiSlice, FORMAT_SLICE, HINT_LIST_ITEM, null).size();
    final List<SliceItem> sliceItems = wifiSlice.getItems();
    // All AP rows + title row
    assertThat(rows).isEqualTo(DEFAULT_EXPANDED_ROW_COUNT + 1);
    // Has scanning text
    SliceTester.assertAnySliceItemContainsSubtitle(sliceItems, mContext.getString(R.string.wifi_empty_list_wifi_on));
}
Also used : Slice(androidx.slice.Slice) SliceItem(androidx.slice.SliceItem) AccessPoint(com.android.settingslib.wifi.AccessPoint) Test(org.junit.Test)

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