use of androidx.slice.SliceItem in project android_packages_apps_Settings by omnirom.
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);
}
use of androidx.slice.SliceItem in project android_packages_apps_Settings by omnirom.
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);
}
use of androidx.slice.SliceItem in project android_packages_apps_Settings by omnirom.
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();
}
use of androidx.slice.SliceItem in project android_packages_apps_Settings by omnirom.
the class BluetoothDevicesSliceTest method getSlice_bluetoothTurningOn_shouldHaveBluetoothDevicesTitleAndPairNewDevice.
@Test
public void getSlice_bluetoothTurningOn_shouldHaveBluetoothDevicesTitleAndPairNewDevice() {
mShadowBluetoothAdapter.setEnabled(false);
mShadowBluetoothAdapter.setState(BluetoothAdapter.STATE_OFF);
final Intent intent = new Intent().putExtra(EXTRA_ENABLE_BLUETOOTH, true);
mBluetoothDevicesSlice.onNotifyChange(intent);
final Slice slice = mBluetoothDevicesSlice.getSlice();
final SliceMetadata metadata = SliceMetadata.from(mContext, slice);
assertThat(metadata.getTitle()).isEqualTo(mContext.getString(R.string.bluetooth_devices));
final List<SliceItem> sliceItems = slice.getItems();
SliceTester.assertAnySliceItemContainsTitle(sliceItems, mContext.getString(R.string.bluetooth_pairing_pref_title));
}
use of androidx.slice.SliceItem in project android_packages_apps_Settings by omnirom.
the class WifiSliceTest method getWifiSlice_oneDisconnectedAp_shouldReturnLoadingRow.
@Test
public void getWifiSlice_oneDisconnectedAp_shouldReturnLoadingRow() {
setWorkerResults(createWifiSliceItem(AP1_NAME, WifiEntry.CONNECTED_STATE_DISCONNECTED));
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));
}
Aggregations