That fuck shit the fascists are using
1package org.tm.archive.util;
2
3import android.graphics.Bitmap;
4import android.graphics.Canvas;
5import android.graphics.drawable.Drawable;
6
7import androidx.annotation.ColorInt;
8import androidx.annotation.NonNull;
9import androidx.core.graphics.drawable.DrawableCompat;
10
11public final class DrawableUtil {
12
13 private static final int SHORTCUT_INFO_BITMAP_SIZE = ViewUtil.dpToPx(108);
14 public static final int SHORTCUT_INFO_WRAPPED_SIZE = ViewUtil.dpToPx(72);
15 private static final int SHORTCUT_INFO_PADDING = (SHORTCUT_INFO_BITMAP_SIZE - SHORTCUT_INFO_WRAPPED_SIZE) / 2;
16
17 private DrawableUtil() {}
18
19 public static @NonNull Bitmap toBitmap(@NonNull Drawable drawable, int width, int height) {
20 Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
21 Canvas canvas = new Canvas(bitmap);
22
23 drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
24 drawable.draw(canvas);
25
26 return bitmap;
27 }
28
29 public static @NonNull Bitmap wrapBitmapForShortcutInfo(@NonNull Bitmap toWrap) {
30 Bitmap bitmap = Bitmap.createBitmap(SHORTCUT_INFO_BITMAP_SIZE, SHORTCUT_INFO_BITMAP_SIZE, Bitmap.Config.ARGB_8888);
31 Bitmap scaled = Bitmap.createScaledBitmap(toWrap, SHORTCUT_INFO_WRAPPED_SIZE, SHORTCUT_INFO_WRAPPED_SIZE, true);
32
33 Canvas canvas = new Canvas(bitmap);
34 canvas.drawBitmap(scaled, SHORTCUT_INFO_PADDING, SHORTCUT_INFO_PADDING, null);
35
36 return bitmap;
37 }
38
39 /**
40 * Returns a new {@link Drawable} that safely wraps and tints the provided drawable.
41 */
42 public static @NonNull Drawable tint(@NonNull Drawable drawable, @ColorInt int tint) {
43 Drawable tinted = DrawableCompat.wrap(drawable).mutate();
44 DrawableCompat.setTint(tinted, tint);
45 return tinted;
46 }
47}