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

Commit 611aa05b authored by Prabir Pradhan's avatar Prabir Pradhan
Browse files

PointerIcon: Create bitmap using density-aware constructor

Instead of manually setting the density of a Bitmap that we create
(which looks like we're working around Bitmap's functionality), use
Bitmap's density-aware constructor that takes a DisplayMetrics object.
It essentially provides the same functionality as setting the density,
but since it's wrapped up in a supported constructor, it increases
readability and removes the need for us to explain what we're doing.

Bug: 305193969
Test: Presubmit
Change-Id: I2b4bdc60e2744a89c8154bd9359de6254a810426
parent 6f918e27
Loading
Loading
Loading
Loading
+5 −7
Original line number Diff line number Diff line
@@ -428,13 +428,11 @@ public final class PointerIcon implements Parcelable {

    private BitmapDrawable getBitmapDrawableFromVectorDrawable(Resources resources,
            VectorDrawable vectorDrawable) {
        Bitmap bitmap = Bitmap.createBitmap(vectorDrawable.getIntrinsicWidth(),
                vectorDrawable.getIntrinsicHeight(), Bitmap.Config.ARGB_8888);
        // BitmapDrawables and Bitmap have a default density of DisplayMetrics.DENSITY_DEVICE,
        // (which is deprecated in favor of DENSITY_DEVICE_STABLE/resources.densityDpi). In
        // rare cases when device density differs from the resource density, the bitmap will
        // scale as the BitmapDrawable is created. Avoid by explicitly setting density here.
        bitmap.setDensity(resources.getDisplayMetrics().densityDpi);
        // Ensure we pass the display metrics into the Bitmap constructor so that it is initialized
        // with the correct density.
        Bitmap bitmap = Bitmap.createBitmap(resources.getDisplayMetrics(),
                vectorDrawable.getIntrinsicWidth(),
                vectorDrawable.getIntrinsicHeight(), Bitmap.Config.ARGB_8888, true /* hasAlpha */);
        Canvas canvas = new Canvas(bitmap);
        vectorDrawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
        vectorDrawable.draw(canvas);