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);
}
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);
}
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();
}
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);
});
}
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();
});
}
}
Aggregations