Search in sources :

Example 11 with IconCompat

use of androidx.core.graphics.drawable.IconCompat 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 12 with IconCompat

use of androidx.core.graphics.drawable.IconCompat in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class DataUsageSlice method getSlice.

@Override
public Slice getSlice() {
    final IconCompat icon = IconCompat.createWithResource(mContext, R.drawable.ic_settings_data_usage);
    final String title = mContext.getString(R.string.data_usage_summary_title);
    final SliceAction primaryAction = SliceAction.createDeeplink(getPrimaryAction(), icon, ListBuilder.ICON_IMAGE, title);
    DataUsageController dataUsageController = new DataUsageController(mContext);
    DataUsageController.DataUsageInfo info = null;
    SubscriptionManager subscriptionManager = (SubscriptionManager) mContext.getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
    int defaultSubId = subscriptionManager.getDefaultDataSubscriptionId();
    boolean showDailyDataUsage = Settings.System.getInt(mContext.getContentResolver(), Settings.System.DATA_USAGE_PERIOD, 1) == 0;
    if (defaultSubId == SubscriptionManager.INVALID_SUBSCRIPTION_ID) {
        info = dataUsageController.getDataUsageInfo();
    } else {
        info = showDailyDataUsage ? dataUsageController.getDailyDataUsageInfo(DataUsageUtils.getMobileTemplate(mContext, defaultSubId)) : dataUsageController.getDataUsageInfo(DataUsageUtils.getMobileTemplate(mContext, defaultSubId));
    }
    final ListBuilder listBuilder = new ListBuilder(mContext, CustomSliceRegistry.DATA_USAGE_SLICE_URI, ListBuilder.INFINITY).setAccentColor(Utils.getColorAccentDefaultColor(mContext)).setHeader(new ListBuilder.HeaderBuilder().setTitle(title));
    if (DataUsageUtils.hasSim(mContext)) {
        listBuilder.addRow(new ListBuilder.RowBuilder().setTitle(getDataUsageText(info)).setSubtitle(getCycleTime(info)).setPrimaryAction(primaryAction));
    } else {
        listBuilder.addRow(new ListBuilder.RowBuilder().setTitle(mContext.getText(R.string.no_sim_card)).setPrimaryAction(primaryAction));
    }
    return listBuilder.build();
}
Also used : IconCompat(androidx.core.graphics.drawable.IconCompat) DataUsageController(com.android.settingslib.net.DataUsageController) SliceAction(androidx.slice.builders.SliceAction) ListBuilder(androidx.slice.builders.ListBuilder) SpannableString(android.text.SpannableString) SubscriptionManager(android.telephony.SubscriptionManager)

Example 13 with IconCompat

use of androidx.core.graphics.drawable.IconCompat in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class MediaOutputIndicatorSlice method getSlice.

@Override
public Slice getSlice() {
    if (!isVisible()) {
        return null;
    }
    final IconCompat icon = IconCompat.createWithResource(mContext, com.android.internal.R.drawable.ic_settings_bluetooth);
    final CharSequence title = mContext.getText(R.string.media_output_title);
    final PendingIntent primaryActionIntent = PendingIntent.getActivity(mContext, 0, /* requestCode */
    getMediaOutputSliceIntent(), 0);
    final SliceAction primarySliceAction = SliceAction.createDeeplink(primaryActionIntent, icon, ListBuilder.ICON_IMAGE, title);
    @ColorInt final int color = Utils.getColorAccentDefaultColor(mContext);
    final ListBuilder listBuilder = new ListBuilder(mContext, MEDIA_OUTPUT_INDICATOR_SLICE_URI, ListBuilder.INFINITY).setAccentColor(color).addRow(new ListBuilder.RowBuilder().setTitle(title).setSubtitle(findActiveDeviceName()).setPrimaryAction(primarySliceAction));
    return listBuilder.build();
}
Also used : ColorInt(android.annotation.ColorInt) IconCompat(androidx.core.graphics.drawable.IconCompat) SliceAction(androidx.slice.builders.SliceAction) ListBuilder(androidx.slice.builders.ListBuilder) PendingIntent(android.app.PendingIntent)

Example 14 with IconCompat

use of androidx.core.graphics.drawable.IconCompat in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class LocationSlice method getSlice.

@Override
public Slice getSlice() {
    final IconCompat icon = IconCompat.createWithResource(mContext, com.android.internal.R.drawable.ic_signal_location);
    final CharSequence title = mContext.getText(R.string.location_settings_title);
    @ColorInt final int color = Utils.getColorAccentDefaultColor(mContext);
    final PendingIntent primaryAction = getPrimaryAction();
    final SliceAction primarySliceAction = SliceAction.createDeeplink(primaryAction, icon, ListBuilder.ICON_IMAGE, title);
    return new ListBuilder(mContext, CustomSliceRegistry.LOCATION_SLICE_URI, ListBuilder.INFINITY).setAccentColor(color).addRow(new RowBuilder().setTitle(title).setTitleItem(icon, ICON_IMAGE).setPrimaryAction(primarySliceAction)).build();
}
Also used : ColorInt(android.annotation.ColorInt) IconCompat(androidx.core.graphics.drawable.IconCompat) SliceAction(androidx.slice.builders.SliceAction) ListBuilder(androidx.slice.builders.ListBuilder) PendingIntent(android.app.PendingIntent) RowBuilder(androidx.slice.builders.ListBuilder.RowBuilder)

Example 15 with IconCompat

use of androidx.core.graphics.drawable.IconCompat in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class MediaOutputSlice method getMediaDeviceRow.

private ListBuilder.RowBuilder getMediaDeviceRow(MediaDevice device) {
    final String title = device.getName();
    final PendingIntent broadcastAction = getBroadcastIntent(mContext, device.getId(), device.hashCode());
    final IconCompat deviceIcon = getDeviceIconCompat(device);
    final ListBuilder.RowBuilder rowBuilder = new ListBuilder.RowBuilder().setTitleItem(deviceIcon, ListBuilder.ICON_IMAGE).setPrimaryAction(SliceAction.create(broadcastAction, deviceIcon, ListBuilder.ICON_IMAGE, title)).setTitle(title).setSubtitle(device.getSummary());
    return rowBuilder;
}
Also used : IconCompat(androidx.core.graphics.drawable.IconCompat) ListBuilder(androidx.slice.builders.ListBuilder) PendingIntent(android.app.PendingIntent)

Aggregations

IconCompat (androidx.core.graphics.drawable.IconCompat)102 ListBuilder (androidx.slice.builders.ListBuilder)55 PendingIntent (android.app.PendingIntent)42 SliceAction (androidx.slice.builders.SliceAction)39 Test (org.junit.Test)25 ColorInt (android.annotation.ColorInt)22 RowBuilder (androidx.slice.builders.ListBuilder.RowBuilder)21 SliceMetadata (androidx.slice.SliceMetadata)18 SliceAction (androidx.slice.core.SliceAction)18 Intent (android.content.Intent)14 Slice (androidx.slice.Slice)14 Drawable (android.graphics.drawable.Drawable)7 ShortcutInfoCompat (androidx.core.content.pm.ShortcutInfoCompat)6 SliceItem (androidx.slice.SliceItem)6 ColorDrawable (android.graphics.drawable.ColorDrawable)5 SpannableString (android.text.SpannableString)4 PrivateStorageInfo (com.android.settingslib.deviceinfo.PrivateStorageInfo)4 Resources (android.content.res.Resources)3 Bitmap (android.graphics.Bitmap)3 PorterDuffColorFilter (android.graphics.PorterDuffColorFilter)3