Search in sources :

Example 41 with SliceItem

use of androidx.slice.SliceItem in project android_packages_apps_Settings by omnirom.

the class WifiSliceTest method getWifiSlice_oneConnectedAp_shouldReturnLoadingRow.

@Test
public void getWifiSlice_oneConnectedAp_shouldReturnLoadingRow() {
    setWorkerResults(createWifiSliceItem(AP1_NAME, WifiEntry.CONNECTED_STATE_CONNECTED));
    final Slice wifiSlice = mWifiSlice.getSlice();
    final List<SliceItem> sliceItems = wifiSlice.getItems();
    SliceTester.assertAnySliceItemContainsTitle(sliceItems, AP1_NAME);
    // 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) Test(org.junit.Test)

Example 42 with SliceItem

use of androidx.slice.SliceItem in project android_packages_apps_Settings by omnirom.

the class WifiSliceTest method getWifiSlice_apReachExpandedCount_shouldNotReturnLoadingRow.

@Test
public void getWifiSlice_apReachExpandedCount_shouldNotReturnLoadingRow() {
    setWorkerResults(createWifiSliceItem(AP1_NAME, WifiEntry.CONNECTED_STATE_DISCONNECTED), createWifiSliceItem(AP2_NAME, WifiEntry.CONNECTED_STATE_DISCONNECTED), createWifiSliceItem(AP3_NAME, WifiEntry.CONNECTED_STATE_DISCONNECTED));
    final Slice wifiSlice = mWifiSlice.getSlice();
    final List<SliceItem> sliceItems = wifiSlice.getItems();
    SliceTester.assertAnySliceItemContainsTitle(sliceItems, AP1_NAME);
    SliceTester.assertAnySliceItemContainsTitle(sliceItems, AP2_NAME);
    SliceTester.assertAnySliceItemContainsTitle(sliceItems, AP3_NAME);
    // No scanning text
    SliceTester.assertNoSliceItemContainsSubtitle(sliceItems, mContext.getString(R.string.wifi_empty_list_wifi_on));
}
Also used : Slice(androidx.slice.Slice) SliceItem(androidx.slice.SliceItem) Test(org.junit.Test)

Example 43 with SliceItem

use of androidx.slice.SliceItem in project android_packages_apps_Settings by omnirom.

the class Enhanced4gLteSliceHelperTest method assertTitle.

private void assertTitle(List<SliceItem> sliceItems, String title) {
    boolean hasTitle = false;
    for (SliceItem item : sliceItems) {
        final 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)

Example 44 with SliceItem

use of androidx.slice.SliceItem in project android_packages_apps_Settings by omnirom.

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, ResourcesUtils.getResourcesString(mContext, "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 45 with SliceItem

use of androidx.slice.SliceItem in project android_packages_apps_Settings by omnirom.

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 SliceAction primaryAction = metadata.getPrimaryAction();
    final IconCompat icon = primaryAction.getIcon();
    if (icon == null) {
        final SliceItem colorItem = SliceQuery.findSubtype(slice, FORMAT_INT, SUBTYPE_COLOR);
        final int color = colorItem.getInt();
        assertThat(color).isEqualTo(Utils.getColorAccentDefaultColor(context));
    } else {
        final IconCompat expectedIcon = IconCompat.createWithResource(context, sliceData.getIconResource());
        assertThat(expectedIcon.toString()).isEqualTo(icon.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)

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