Search in sources :

Example 46 with IconCompat

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

the class SliceBuilderUtils method buildCopyableSlice.

private static Slice buildCopyableSlice(Context context, SliceData sliceData, BasePreferenceController controller) {
    final SliceAction copyableAction = getCopyableAction(context, sliceData);
    final PendingIntent contentIntent = getContentPendingIntent(context, sliceData);
    final IconCompat icon = getSafeIcon(context, sliceData);
    final SliceAction primaryAction = SliceAction.createDeeplink(contentIntent, icon, ListBuilder.ICON_IMAGE, sliceData.getTitle());
    final CharSequence subtitleText = getSubtitleText(context, controller, sliceData);
    @ColorInt final int color = Utils.getColorAccentDefaultColor(context);
    final Set<String> keywords = buildSliceKeywords(sliceData);
    return new ListBuilder(context, sliceData.getUri(), ListBuilder.INFINITY).setAccentColor(color).addRow(new RowBuilder().setTitle(sliceData.getTitle()).setSubtitle(subtitleText).setPrimaryAction(primaryAction).addEndItem(copyableAction)).setKeywords(keywords).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 47 with IconCompat

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

the class SliceBuilderUtils method buildIntentSlice.

private static Slice buildIntentSlice(Context context, SliceData sliceData, BasePreferenceController controller) {
    final PendingIntent contentIntent = getContentPendingIntent(context, sliceData);
    final IconCompat icon = getSafeIcon(context, sliceData);
    final CharSequence subtitleText = getSubtitleText(context, controller, sliceData);
    @ColorInt final int color = Utils.getColorAccentDefaultColor(context);
    final Set<String> keywords = buildSliceKeywords(sliceData);
    return new ListBuilder(context, sliceData.getUri(), ListBuilder.INFINITY).setAccentColor(color).addRow(new RowBuilder().setTitle(sliceData.getTitle()).setSubtitle(subtitleText).setPrimaryAction(SliceAction.createDeeplink(contentIntent, icon, ListBuilder.ICON_IMAGE, sliceData.getTitle()))).setKeywords(keywords).build();
}
Also used : ColorInt(android.annotation.ColorInt) IconCompat(androidx.core.graphics.drawable.IconCompat) ListBuilder(androidx.slice.builders.ListBuilder) PendingIntent(android.app.PendingIntent) RowBuilder(androidx.slice.builders.ListBuilder.RowBuilder)

Example 48 with IconCompat

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

the class BluetoothSliceBuilder method getSlice.

/**
 * Return a Bluetooth Slice bound to {@link CustomSliceRegistry#BLUETOOTH_URI}.
 * <p>
 * Note that you should register a listener for {@link #INTENT_FILTER} to get changes for
 * Bluetooth.
 */
public static Slice getSlice(Context context) {
    final boolean isBluetoothEnabled = isBluetoothEnabled();
    final CharSequence title = context.getText(R.string.switch_on_text);
    final IconCompat icon = IconCompat.createWithResource(context, com.android.internal.R.drawable.ic_settings_bluetooth);
    @ColorInt final int color = com.android.settings.Utils.getColorAccent(context).getDefaultColor();
    final PendingIntent toggleAction = getBroadcastIntent(context);
    final PendingIntent primaryAction = getPrimaryAction(context);
    final SliceAction primarySliceAction = SliceAction.createDeeplink(primaryAction, icon, ListBuilder.ICON_IMAGE, title);
    final SliceAction toggleSliceAction = SliceAction.createToggle(toggleAction, null, /* actionTitle */
    isBluetoothEnabled);
    return new ListBuilder(context, CustomSliceRegistry.BLUETOOTH_URI, ListBuilder.INFINITY).setAccentColor(color).addRow(new RowBuilder().setTitle(title).addEndItem(toggleSliceAction).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 49 with IconCompat

use of androidx.core.graphics.drawable.IconCompat in project AntennaPod by AntennaPod.

the class SelectSubscriptionActivity method addShortcut.

private void addShortcut(Feed feed, Bitmap bitmap) {
    Intent intent = new Intent(this, MainActivity.class);
    intent.setAction(Intent.ACTION_MAIN);
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
    intent.putExtra(EXTRA_FEED_ID, feed.getId());
    String id = "subscription-" + feed.getId();
    IconCompat icon;
    if (bitmap != null) {
        icon = IconCompat.createWithAdaptiveBitmap(bitmap);
    } else {
        icon = IconCompat.createWithResource(this, R.drawable.ic_folder_shortcut);
    }
    ShortcutInfoCompat shortcut = new ShortcutInfoCompat.Builder(this, id).setShortLabel(feed.getTitle()).setLongLabel(feed.getFeedTitle()).setIntent(intent).setIcon(icon).build();
    setResult(RESULT_OK, ShortcutManagerCompat.createShortcutResultIntent(this, shortcut));
    finish();
}
Also used : IconCompat(androidx.core.graphics.drawable.IconCompat) Intent(android.content.Intent) ShortcutInfoCompat(androidx.core.content.pm.ShortcutInfoCompat)

Example 50 with IconCompat

use of androidx.core.graphics.drawable.IconCompat in project J2ME-Loader by nikita36078.

the class AppsListFragment method requestAddShortcut.

private void requestAddShortcut(AppItem appItem) {
    FragmentActivity activity = requireActivity();
    Bitmap bitmap = AppUtils.getIconBitmap(appItem);
    IconCompat icon;
    if (bitmap == null) {
        icon = IconCompat.createWithResource(activity, R.mipmap.ic_launcher);
    } else {
        int width = bitmap.getWidth();
        int height = bitmap.getHeight();
        ActivityManager am = (ActivityManager) activity.getSystemService(Context.ACTIVITY_SERVICE);
        int iconSize = am.getLauncherLargeIconSize();
        Rect src;
        if (width > height) {
            int left = (width - height) / 2;
            src = new Rect(left, 0, left + height, height);
        } else if (width < height) {
            int top = (height - width) / 2;
            src = new Rect(0, top, width, top + width);
        } else {
            src = null;
        }
        Bitmap scaled = Bitmap.createBitmap(iconSize, iconSize, Bitmap.Config.ARGB_8888);
        Canvas canvas = new Canvas(scaled);
        canvas.drawBitmap(bitmap, src, new RectF(0, 0, iconSize, iconSize), null);
        icon = IconCompat.createWithBitmap(scaled);
    }
    String title = appItem.getTitle();
    Intent launchIntent = new Intent(Intent.ACTION_DEFAULT, Uri.parse(appItem.getPathExt()), activity, ConfigActivity.class);
    launchIntent.putExtra(KEY_MIDLET_NAME, title);
    ShortcutInfoCompat shortcut = new ShortcutInfoCompat.Builder(activity, title).setIntent(launchIntent).setShortLabel(title).setIcon(icon).build();
    ShortcutManagerCompat.requestPinShortcut(activity, shortcut, null);
}
Also used : RectF(android.graphics.RectF) FragmentActivity(androidx.fragment.app.FragmentActivity) Bitmap(android.graphics.Bitmap) Rect(android.graphics.Rect) IconCompat(androidx.core.graphics.drawable.IconCompat) Canvas(android.graphics.Canvas) Intent(android.content.Intent) ActivityManager(android.app.ActivityManager) ShortcutInfoCompat(androidx.core.content.pm.ShortcutInfoCompat)

Aggregations

IconCompat (androidx.core.graphics.drawable.IconCompat)103 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)15 Slice (androidx.slice.Slice)14 Drawable (android.graphics.drawable.Drawable)7 ShortcutInfoCompat (androidx.core.content.pm.ShortcutInfoCompat)7 SliceItem (androidx.slice.SliceItem)6 ColorDrawable (android.graphics.drawable.ColorDrawable)5 Bitmap (android.graphics.Bitmap)4 SpannableString (android.text.SpannableString)4 PrivateStorageInfo (com.android.settingslib.deviceinfo.PrivateStorageInfo)4 Resources (android.content.res.Resources)3 PorterDuffColorFilter (android.graphics.PorterDuffColorFilter)3