use of androidx.slice.core.SliceAction in project Resurrection_packages_apps_Settings by ResurrectionRemix.
the class SliceBuilderUtilsTest method buildToggleSlice_noIconPassed_returnsSliceWithIcon.
@Test
public void buildToggleSlice_noIconPassed_returnsSliceWithIcon() {
final int expectedIconResource = IconCompat.createWithResource(mContext, R.drawable.ic_settings_accent).toIcon().getResId();
final SliceData dummyData = getDummyData(TOGGLE_CONTROLLER, SliceData.SliceType.SWITCH, 0x0);
final Slice slice = SliceBuilderUtils.buildSlice(mContext, dummyData);
final SliceMetadata metadata = SliceMetadata.from(mContext, slice);
final SliceAction primaryAction = metadata.getPrimaryAction();
final int actualIconResource = primaryAction.getIcon().toIcon().getResId();
assertThat(actualIconResource).isEqualTo(expectedIconResource);
}
use of androidx.slice.core.SliceAction 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.core.SliceAction 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.core.SliceAction in project Resurrection_packages_apps_Settings by ResurrectionRemix.
the class ContextualCardFeatureProviderImpl method logNotificationPackage.
@Override
public void logNotificationPackage(Slice slice) {
if (slice == null || !slice.getUri().equals(CustomSliceRegistry.CONTEXTUAL_NOTIFICATION_CHANNEL_SLICE_URI)) {
return;
}
final SliceAction primaryAction = SliceMetadata.from(mContext, slice).getPrimaryAction();
final String currentPackage = primaryAction.getAction().getIntent().getBundleExtra(SettingsActivity.EXTRA_SHOW_FRAGMENT_ARGUMENTS).getString(AppInfoBase.ARG_PACKAGE_NAME);
final SharedPreferences prefs = mContext.getSharedPreferences(ContextualNotificationChannelSlice.PREFS, MODE_PRIVATE);
final Set<String> interactedPackages = prefs.getStringSet(ContextualNotificationChannelSlice.PREF_KEY_INTERACTED_PACKAGES, new ArraySet<>());
final Set<String> newInteractedPackages = new ArraySet<>(interactedPackages);
newInteractedPackages.add(currentPackage);
prefs.edit().putStringSet(ContextualNotificationChannelSlice.PREF_KEY_INTERACTED_PACKAGES, newInteractedPackages).apply();
}
use of androidx.slice.core.SliceAction 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();
}
Aggregations