Search in sources :

Example 96 with SliceMetadata

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

the class SliceBuilderUtilsTest method buildDisabledDependentSlice_noIconPassed_returnsSliceWithIcon.

@Test
public void buildDisabledDependentSlice_noIconPassed_returnsSliceWithIcon() {
    final int expectedIconResource = IconCompat.createWithResource(mContext, R.drawable.ic_settings_accent).toIcon().getResId();
    final SliceData data = getMockData(FakeUnavailablePreferenceController.class, SUMMARY, SliceData.SliceType.SWITCH, SCREEN_TITLE, 0, /* icon */
    null);
    Settings.Global.putInt(mContext.getContentResolver(), FakeUnavailablePreferenceController.AVAILABILITY_KEY, BasePreferenceController.DISABLED_DEPENDENT_SETTING);
    final Slice slice = SliceBuilderUtils.buildSlice(mContext, data);
    final SliceMetadata metadata = SliceMetadata.from(mContext, slice);
    final SliceAction primaryAction = metadata.getPrimaryAction();
    final int actualIconResource = primaryAction.getIcon().toIcon().getResId();
    assertThat(actualIconResource).isEqualTo(expectedIconResource);
}
Also used : Slice(androidx.slice.Slice) SliceMetadata(androidx.slice.SliceMetadata) SliceAction(androidx.slice.core.SliceAction) Test(org.junit.Test)

Example 97 with SliceMetadata

use of androidx.slice.SliceMetadata 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)

Example 98 with SliceMetadata

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

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 99 with SliceMetadata

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

the class FaceSetupSliceTest method getSlice_faceEnrolled_noReEnroll_shouldReturnNull.

@Test
public void getSlice_faceEnrolled_noReEnroll_shouldReturnNull() {
    final FaceManager faceManager = mock(FaceManager.class);
    when(mPackageManager.hasSystemFeature(PackageManager.FEATURE_FACE)).thenReturn(true);
    when(faceManager.hasEnrolledTemplates(UserHandle.myUserId())).thenReturn(true);
    when(mContext.getSystemService(Context.FACE_SERVICE)).thenReturn(faceManager);
    Settings.Secure.putInt(mContext.getContentResolver(), Settings.Secure.FACE_UNLOCK_RE_ENROLL, 0);
    final FaceSetupSlice setupSlice = new FaceSetupSlice(mContext);
    final SliceMetadata metadata = SliceMetadata.from(mContext, setupSlice.getSlice());
    assertThat(metadata.isErrorSlice()).isTrue();
}
Also used : SliceMetadata(androidx.slice.SliceMetadata) FaceManager(android.hardware.face.FaceManager) Test(org.junit.Test)

Example 100 with SliceMetadata

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

the class FaceSetupSliceTest method getSlice_noFaceManager_shouldReturnNull.

@Test
public void getSlice_noFaceManager_shouldReturnNull() {
    when(mPackageManager.hasSystemFeature(PackageManager.FEATURE_FACE)).thenReturn(false);
    final FaceSetupSlice setupSlice = new FaceSetupSlice(mContext);
    final SliceMetadata metadata = SliceMetadata.from(mContext, setupSlice.getSlice());
    assertThat(metadata.isErrorSlice()).isTrue();
}
Also used : SliceMetadata(androidx.slice.SliceMetadata) Test(org.junit.Test)

Aggregations

SliceMetadata (androidx.slice.SliceMetadata)100 Slice (androidx.slice.Slice)72 Test (org.junit.Test)72 SliceAction (androidx.slice.core.SliceAction)53 PendingIntent (android.app.PendingIntent)24 SliceItem (androidx.slice.SliceItem)23 IconCompat (androidx.core.graphics.drawable.IconCompat)18 ParceledListSlice (android.content.pm.ParceledListSlice)11 Config (org.robolectric.annotation.Config)11 PrivateStorageInfo (com.android.settingslib.deviceinfo.PrivateStorageInfo)5 MetricsFeatureProvider (com.android.settingslib.core.instrumentation.MetricsFeatureProvider)3 Uri (android.net.Uri)2 Handler (android.os.Handler)2 VisibleForTesting (androidx.annotation.VisibleForTesting)2 ListContent (androidx.slice.widget.ListContent)2 RowContent (androidx.slice.widget.RowContent)2 SliceContent (androidx.slice.widget.SliceContent)2 ShadowPrivateStorageInfo (com.android.settings.testutils.shadow.ShadowPrivateStorageInfo)2 Intent (android.content.Intent)1 FaceManager (android.hardware.face.FaceManager)1