Search in sources :

Example 41 with SliceAction

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

Example 42 with SliceAction

use of androidx.slice.core.SliceAction 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 43 with SliceAction

use of androidx.slice.core.SliceAction 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 44 with SliceAction

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

Example 45 with SliceAction

use of androidx.slice.core.SliceAction in project android_packages_apps_Settings by omnirom.

the class WifiCallingSliceHelperTest method testWifiCallingSettingsToggleSlice.

private void testWifiCallingSettingsToggleSlice(Slice slice, SliceData sliceData) {
    final SliceMetadata metadata = SliceMetadata.from(mContext, slice);
    final List<SliceAction> toggles = metadata.getToggles();
    assertThat(toggles).hasSize(1);
    final SliceAction mainToggleAction = toggles.get(0);
    // Check intent in Toggle Action
    final PendingIntent togglePendingIntent = mainToggleAction.getAction();
    final PendingIntent expectedToggleIntent = getBroadcastIntent(WifiCallingSliceHelper.ACTION_WIFI_CALLING_CHANGED);
    assertThat(togglePendingIntent).isEqualTo(expectedToggleIntent);
    // Check primary intent
    final PendingIntent primaryPendingIntent = metadata.getPrimaryAction().getAction();
    final PendingIntent expectedPendingIntent = getActivityIntent(WifiCallingSliceHelper.ACTION_WIFI_CALLING_SETTINGS_ACTIVITY);
    assertThat(primaryPendingIntent).isEqualTo(expectedPendingIntent);
    // Check the title
    final List<SliceItem> sliceItems = slice.getItems();
    assertTitle(sliceItems, mContext.getString(R.string.wifi_calling_settings_title));
}
Also used : SliceMetadata(androidx.slice.SliceMetadata) SliceAction(androidx.slice.core.SliceAction) SliceItem(androidx.slice.SliceItem) PendingIntent(android.app.PendingIntent)

Aggregations

SliceAction (androidx.slice.core.SliceAction)54 SliceMetadata (androidx.slice.SliceMetadata)53 Slice (androidx.slice.Slice)27 Test (org.junit.Test)27 PendingIntent (android.app.PendingIntent)23 SliceItem (androidx.slice.SliceItem)19 IconCompat (androidx.core.graphics.drawable.IconCompat)18 MetricsFeatureProvider (com.android.settingslib.core.instrumentation.MetricsFeatureProvider)3 VisibleForTesting (androidx.annotation.VisibleForTesting)2 ListContent (androidx.slice.widget.ListContent)2 RowContent (androidx.slice.widget.RowContent)2 SliceContent (androidx.slice.widget.SliceContent)2 SharedPreferences (android.content.SharedPreferences)1 ArraySet (android.util.ArraySet)1 PrivateStorageInfo (com.android.settingslib.deviceinfo.PrivateStorageInfo)1 MediaDevice (com.android.settingslib.media.MediaDevice)1