Search in sources :

Example 31 with SliceItem

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

the class WifiSliceTest method getWifiSlice_oneActiveApAndOneUnreachableAp_shouldReturnLoadingRow.

@Test
public void getWifiSlice_oneActiveApAndOneUnreachableAp_shouldReturnLoadingRow() {
    setWorkerResults(createAccessPoint(AP1_NAME, true, true), createAccessPoint(AP2_NAME, false, false));
    final Slice wifiSlice = mWifiSlice.getSlice();
    final List<SliceItem> sliceItems = wifiSlice.getItems();
    SliceTester.assertAnySliceItemContainsTitle(sliceItems, AP1_NAME);
    SliceTester.assertAnySliceItemContainsTitle(sliceItems, AP2_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 32 with SliceItem

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

the class WifiSliceTest method getWifiSlice_noReachableAp_shouldReturnLoadingRow.

@Test
public void getWifiSlice_noReachableAp_shouldReturnLoadingRow() {
    setWorkerResults(createAccessPoint(AP1_NAME, false, false), createAccessPoint(AP2_NAME, false, false));
    final Slice wifiSlice = mWifiSlice.getSlice();
    final List<SliceItem> sliceItems = wifiSlice.getItems();
    SliceTester.assertAnySliceItemContainsTitle(sliceItems, AP1_NAME);
    SliceTester.assertAnySliceItemContainsTitle(sliceItems, AP2_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 33 with SliceItem

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

the class SliceTester method testSettingsToggleSlice.

/**
 * Test the contents of an toggle based slice, including:
 * - Contains one toggle
 * - Correct toggle intent
 * - Correct content intent
 * - Correct title
 * - Correct keywords
 * - TTL
 * - Color
 */
public static void testSettingsToggleSlice(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 List<SliceAction> toggles = metadata.getToggles();
    assertThat(toggles).hasSize(1);
    final long sliceTTL = metadata.getExpiry();
    assertThat(sliceTTL).isEqualTo(ListBuilder.INFINITY);
    final SliceAction mainToggleAction = toggles.get(0);
    assertThat(mainToggleAction.getIcon()).isNull();
    // Check intent in Toggle Action
    final PendingIntent togglePendingIntent = mainToggleAction.getAction();
    assertThat(togglePendingIntent).isEqualTo(SliceBuilderUtils.getActionIntent(context, SettingsSliceProvider.ACTION_TOGGLE_CHANGED, sliceData));
    // Check primary intent
    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 34 with SliceItem

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

the class SliceTester method testSettingsCopyableSlice.

/**
 * Test the copyable slice, including:
 * - No intent
 * - Correct title
 * - Correct intent
 * - Correct keywords
 * - TTL
 * - Color
 */
public static void testSettingsCopyableSlice(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);
    // 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 35 with SliceItem

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

the class SliceTester method testSettingsIntentSlice.

/**
 * Test the contents of an intent based slice, including:
 * - No toggles
 * - Correct intent
 * - Correct title
 * - Correct keywords
 * - TTL
 * - Color
 */
public static void testSettingsIntentSlice(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)

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