Search in sources :

Example 26 with SliceMetadata

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

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);
}
Also used : SliceMetadata(androidx.slice.SliceMetadata) SliceAction(androidx.slice.core.SliceAction) SliceItem(androidx.slice.SliceItem) PendingIntent(android.app.PendingIntent)

Example 27 with SliceMetadata

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

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 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);
    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 28 with SliceMetadata

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

the class EligibleCardChecker method isSliceToggleable.

@VisibleForTesting
boolean isSliceToggleable(Slice slice) {
    final SliceMetadata metadata = SliceMetadata.from(mContext, slice);
    final List<SliceAction> toggles = metadata.getToggles();
    return !toggles.isEmpty();
}
Also used : SliceMetadata(androidx.slice.SliceMetadata) SliceAction(androidx.slice.core.SliceAction) VisibleForTesting(androidx.annotation.VisibleForTesting)

Example 29 with SliceMetadata

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

the class SliceDeferredSetupCardRendererHelper method bindView.

void bindView(RecyclerView.ViewHolder holder, ContextualCard card, Slice slice) {
    final DeferredSetupCardViewHolder view = (DeferredSetupCardViewHolder) 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.summary.setText(sliceMetadata.getSubtitle());
    view.button.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 30 with SliceMetadata

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

the class PanelFragment method loadAllSlices.

private void loadAllSlices() {
    mSliceLiveData.clear();
    final List<Uri> sliceUris = mPanel.getSlices();
    mPanelSlicesLoaderCountdownLatch = new PanelSlicesLoaderCountdownLatch(sliceUris.size());
    for (Uri uri : sliceUris) {
        final LiveData<Slice> sliceLiveData = SliceLiveData.fromUri(getActivity(), uri);
        // Add slice first to make it in order.  Will remove it later if there's an error.
        mSliceLiveData.add(sliceLiveData);
        sliceLiveData.observe(getViewLifecycleOwner(), slice -> {
            // If the Slice has already loaded, do nothing.
            if (mPanelSlicesLoaderCountdownLatch.isSliceLoaded(uri)) {
                return;
            }
            /**
             * Watching for the {@link Slice} to load.
             * <p>
             *     If the Slice comes back {@code null} or with the Error attribute, remove the
             *     Slice data from the list, and mark the Slice as loaded.
             * <p>
             *     If the Slice has come back fully loaded, then mark the Slice as loaded.  No
             *     other actions required since we already have the Slice data in the list.
             * <p>
             *     If the Slice does not match the above condition, we will still want to mark
             *     it as loaded after 250ms timeout to avoid delay showing up the panel for
             *     too long.  Since we are still having the Slice data in the list, the Slice
             *     will show up later once it is loaded.
             */
            final SliceMetadata metadata = SliceMetadata.from(getActivity(), slice);
            if (slice == null || metadata.isErrorSlice()) {
                mSliceLiveData.remove(sliceLiveData);
                mPanelSlicesLoaderCountdownLatch.markSliceLoaded(uri);
            } else if (metadata.getLoadingState() == SliceMetadata.LOADED_ALL) {
                mPanelSlicesLoaderCountdownLatch.markSliceLoaded(uri);
            } else {
                Handler handler = new Handler();
                handler.postDelayed(() -> {
                    mPanelSlicesLoaderCountdownLatch.markSliceLoaded(uri);
                    loadPanelWhenReady();
                }, DURATION_SLICE_BINDING_TIMEOUT_MS);
            }
            loadPanelWhenReady();
        });
    }
}
Also used : Slice(androidx.slice.Slice) SliceMetadata(androidx.slice.SliceMetadata) Handler(android.os.Handler) Uri(android.net.Uri)

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