Search in sources :

Example 76 with SliceMetadata

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

the class NotificationChannelSliceTest method getSlice_isAllDisplayableChannelBlocked_shouldHaveNoSuggestedAppTitle.

@Test
@Config(shadows = ShadowRestrictedLockUtilsInternal.class)
public void getSlice_isAllDisplayableChannelBlocked_shouldHaveNoSuggestedAppTitle() {
    addMockPackageToPackageManager(true, /* isRecentlyInstalled */
    ApplicationInfo.FLAG_INSTALLED);
    mockNotificationBackend(CHANNEL_COUNT, NOTIFICATION_COUNT, false, /* banned */
    true);
    final Slice slice = mNotificationChannelSlice.getSlice();
    final SliceMetadata metadata = SliceMetadata.from(mContext, slice);
    assertThat(metadata.getTitle()).isEqualTo(mContext.getString(R.string.no_suggested_app));
}
Also used : Slice(androidx.slice.Slice) ParceledListSlice(android.content.pm.ParceledListSlice) SliceMetadata(androidx.slice.SliceMetadata) Test(org.junit.Test) Config(org.robolectric.annotation.Config)

Example 77 with SliceMetadata

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

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

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

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

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

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, (int type, Throwable source) -> {
            removeSliceLiveData(uri);
            mPanelSlicesLoaderCountdownLatch.markSliceLoaded(uri);
        });
        // Add slice first to make it in order.  Will remove it later if there's an error.
        mSliceLiveData.put(uri, 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, if slice
             *     uri is not in the allowlist, remove the Slice data from the list, otherwise
             *     keep the Slice data.
             * <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()) {
                removeSliceLiveData(uri);
                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)

Example 80 with SliceMetadata

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

the class BluetoothSliceBuilderTest method getBluetoothSlice_correctSliceContent.

@Test
public void getBluetoothSlice_correctSliceContent() {
    final Slice BluetoothSlice = BluetoothSliceBuilder.getSlice(mContext);
    final SliceMetadata metadata = SliceMetadata.from(mContext, BluetoothSlice);
    assertThat(metadata.getTitle()).isEqualTo(mContext.getString(R.string.bluetooth_settings_title));
    final List<SliceAction> toggles = metadata.getToggles();
    assertThat(toggles).hasSize(1);
    final SliceAction primaryAction = metadata.getPrimaryAction();
    final IconCompat expectedToggleIcon = IconCompat.createWithResource(mContext, com.android.internal.R.drawable.ic_settings_bluetooth);
    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)

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