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

Commit a13c4769 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Fix small but crashy edge case in Icon.scaleDown"

parents 151c52c0 76dc52ac
Loading
Loading
Loading
Loading
+15 −0
Original line number Diff line number Diff line
@@ -16,6 +16,8 @@

package android.graphics.drawable;

import static com.google.common.truth.Truth.assertThat;

import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Region;
@@ -107,6 +109,19 @@ public class IconTest extends AndroidTestCase {
        }
    }

    @SmallTest
    public void testScaleDownIfNecessary() throws Exception {
        final Bitmap bm = Bitmap.createBitmap(4321, 78, Bitmap.Config.ARGB_8888);
        final Icon ic = Icon.createWithBitmap(bm);
        ic.scaleDownIfNecessary(40, 20);

        assertThat(bm.getWidth()).isEqualTo(4321);
        assertThat(bm.getHeight()).isEqualTo(78);

        assertThat(ic.getBitmap().getWidth()).isLessThan(41);
        assertThat(ic.getBitmap().getHeight()).isLessThan(21);
    }

    @SmallTest
    public void testWithAdaptiveBitmap() throws Exception {
        final Bitmap bm1 = Bitmap.createBitmap(150, 150, Bitmap.Config.ARGB_8888);
+4 −2
Original line number Diff line number Diff line
@@ -819,8 +819,10 @@ public final class Icon implements Parcelable {
        if (bitmapWidth > maxWidth || bitmapHeight > maxHeight) {
            float scale = Math.min((float) maxWidth / bitmapWidth,
                    (float) maxHeight / bitmapHeight);
            bitmap = Bitmap.createScaledBitmap(bitmap, (int) (scale * bitmapWidth),
                    (int) (scale * bitmapHeight), true /* filter */);
            bitmap = Bitmap.createScaledBitmap(bitmap,
                    Math.max(1, (int) (scale * bitmapWidth)),
                    Math.max(1, (int) (scale * bitmapHeight)),
                    true /* filter */);
        }
        return bitmap;
    }