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

Commit e02f9e39 authored by Jernej Virag's avatar Jernej Virag Committed by Android (Google) Code Review
Browse files

Merge "Prevent LocalImageResolver from upscaling images" into tm-dev

parents 5428fee9 dd397eac
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -198,6 +198,11 @@ public class LocalImageResolver {
                }

                final Size size = info.getSize();
                if (size.getWidth() <= maxWidth && size.getHeight() <= maxHeight) {
                    // We don't want to upscale images needlessly.
                    return;
                }

                if (size.getWidth() > size.getHeight()) {
                    if (size.getWidth() > maxWidth) {
                        final int targetHeight = size.getHeight() * maxWidth / size.getWidth();
+11 −0
Original line number Diff line number Diff line
@@ -194,6 +194,17 @@ public class LocalImageResolverTest {
        assertThat(bd.getBitmap().getHeight()).isGreaterThan(51);
    }

    @Test
    public void resolveImage_smallBitmapIcon_passedSmallerSize_dontResize() {
        Icon icon = Icon.createWithResource(mContext.getResources(), R.drawable.test32x24);
        Drawable d = LocalImageResolver.resolveImage(icon, mContext, 600, 450);

        assertThat(d).isInstanceOf(BitmapDrawable.class);
        BitmapDrawable bd = (BitmapDrawable) d;
        assertThat(bd.getBitmap().getWidth()).isEqualTo(32);
        assertThat(bd.getBitmap().getHeight()).isEqualTo(24);
    }

    @Test
    public void resolveImage_largeBitmapIcon_passedSize_resizeToDefinedSize() {
        Icon icon = Icon.createWithBitmap(