Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 6a320a15 authored by Gary Mai's avatar Gary Mai
Browse files

Get bitmap from vector drawable in shortcuts

Phone icons aren't bitmap drawables anymore so convert the vector
into a bitmap for display.

Test: Manually verified:
  * Adding direct dial and message shortcuts don't crash the app
  * Appearance of the widgets is the same as before.

Bug: 34394590
Change-Id: I5cc056fe53ae6c5f2a0830f2f5d4d034cc7b4937
parent 57a122c1
Loading
Loading
Loading
Loading
+5 −2
Original line number Diff line number Diff line
@@ -46,6 +46,7 @@ import com.android.contacts.ContactPhotoManager;
import com.android.contacts.ContactPhotoManager.DefaultImageRequest;
import com.android.contacts.ContactsUtils;
import com.android.contacts.R;
import com.android.contacts.util.BitmapUtil;
import com.android.contacts.util.ImplicitIntentsUtil;

/**
@@ -356,8 +357,10 @@ public class ShortcutIntentBuilder {
        final Resources r = mContext.getResources();
        final float density = r.getDisplayMetrics().density;

        Bitmap phoneIcon = ((BitmapDrawable) r.getDrawableForDensity(actionResId, mIconDensity))
                .getBitmap();
        final Drawable phoneDrawable = r.getDrawableForDensity(actionResId, mIconDensity);
        // These icons have the same height and width so either is fine for the size.
        final Bitmap phoneIcon =
                BitmapUtil.drawableToBitmap(phoneDrawable, phoneDrawable.getIntrinsicHeight());

        Bitmap icon = generateQuickContactIcon(photo);
        Canvas canvas = new Canvas(icon);
+17 −0
Original line number Diff line number Diff line
@@ -161,4 +161,21 @@ public class BitmapUtil {
        canvas.drawBitmap(input, src, dst, paint);
        return result;
    }

    /**
     * Converts a drawable to a bitmap.
     */
    public static Bitmap drawableToBitmap(Drawable drawable, int avatarSizePx) {
        if (drawable instanceof BitmapDrawable) {
            return ((BitmapDrawable) drawable).getBitmap();
        }

        final Bitmap bitmap =
                Bitmap.createBitmap(avatarSizePx, avatarSizePx, Bitmap.Config.ARGB_8888);

        final Canvas canvas = new Canvas(bitmap);
        drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
        drawable.draw(canvas);
        return bitmap;
    }
}