Search in sources :

Example 46 with SliceMetadata

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

the class WifiSliceTest method getWifiSlice_shouldHaveTitleAndToggle.

@Test
public void getWifiSlice_shouldHaveTitleAndToggle() {
    final Slice wifiSlice = mWifiSlice.getSlice();
    final SliceMetadata metadata = SliceMetadata.from(mContext, wifiSlice);
    assertThat(metadata.getTitle()).isEqualTo(mContext.getString(R.string.wifi_settings));
    final List<SliceAction> toggles = metadata.getToggles();
    assertThat(toggles).hasSize(1);
    final SliceAction primaryAction = metadata.getPrimaryAction();
    final IconCompat expectedToggleIcon = IconCompat.createWithResource(mContext, R.drawable.ic_settings_wireless);
    assertThat(primaryAction.getIcon().toString()).isEqualTo(expectedToggleIcon.toString());
}
Also used : Slice(androidx.slice.Slice) IconCompat(androidx.core.graphics.drawable.IconCompat) SliceMetadata(androidx.slice.SliceMetadata) SliceAction(androidx.slice.core.SliceAction) Test(org.junit.Test)

Example 47 with SliceMetadata

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

the class SliceHalfCardRendererHelper method bindView.

void bindView(RecyclerView.ViewHolder holder, ContextualCard card, Slice slice) {
    final HalfCardViewHolder view = (HalfCardViewHolder) holder;
    final SliceMetadata sliceMetadata = SliceMetadata.from(mContext, slice);
    final SliceAction primaryAction = sliceMetadata.getPrimaryAction();
    view.icon.setImageDrawable(primaryAction.getIcon().loadDrawable(mContext));
    view.title.setText(primaryAction.getTitle());
    view.content.setOnClickListener(v -> {
        try {
            primaryAction.getAction().send();
        } catch (PendingIntent.CanceledException e) {
            Log.w(TAG, "Failed to start intent " + primaryAction.getTitle());
        }
        final String log = ContextualCardLogUtils.buildCardClickLog(card, 0, /* row */
        EventInfo.ACTION_TYPE_CONTENT, view.getAdapterPosition());
        final MetricsFeatureProvider metricsFeatureProvider = FeatureFactory.getFactory(mContext).getMetricsFeatureProvider();
        metricsFeatureProvider.action(mContext, SettingsEnums.ACTION_CONTEXTUAL_CARD_CLICK, log);
    });
}
Also used : MetricsFeatureProvider(com.android.settingslib.core.instrumentation.MetricsFeatureProvider) SliceMetadata(androidx.slice.SliceMetadata) SliceAction(androidx.slice.core.SliceAction) PendingIntent(android.app.PendingIntent)

Example 48 with SliceMetadata

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

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

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

SliceMetadata (androidx.slice.SliceMetadata)57 Slice (androidx.slice.Slice)44 Test (org.junit.Test)43 SliceAction (androidx.slice.core.SliceAction)29 PendingIntent (android.app.PendingIntent)12 SliceItem (androidx.slice.SliceItem)12 ParceledListSlice (android.content.pm.ParceledListSlice)11 IconCompat (androidx.core.graphics.drawable.IconCompat)11 Config (org.robolectric.annotation.Config)9 PrivateStorageInfo (com.android.settingslib.deviceinfo.PrivateStorageInfo)3 MetricsFeatureProvider (com.android.settingslib.core.instrumentation.MetricsFeatureProvider)2 Uri (android.net.Uri)1 Handler (android.os.Handler)1 VisibleForTesting (androidx.annotation.VisibleForTesting)1 ListContent (androidx.slice.widget.ListContent)1 RowContent (androidx.slice.widget.RowContent)1 SliceContent (androidx.slice.widget.SliceContent)1 MediaDevice (com.android.settingslib.media.MediaDevice)1