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

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

Merge "Updated UserIconDrawable#shouldUpdateColorFilter to return true if...

Merge "Updated UserIconDrawable#shouldUpdateColorFilter to return true if current ColorFilter was not an instance of PorterDuffColorFilter"
parents d2a25e66 6a8727eb
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -269,7 +269,7 @@ public class UserIconDrawable extends Drawable implements Drawable.Callback {
            PorterDuff.Mode currentMode = porterDuffColorFilter.getMode();
            return currentColor != color || currentMode != mode;
        } else {
            return false;
            return true;
        }
    }

+28 −1
Original line number Diff line number Diff line
@@ -18,8 +18,15 @@ package com.android.settingslib.drawable;

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

import android.annotation.ColorInt;
import android.content.res.ColorStateList;
import android.graphics.Bitmap;
import android.graphics.Bitmap.Config;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.PorterDuff;
import android.graphics.PorterDuff.Mode;
import android.support.test.InstrumentationRegistry;
import android.support.test.runner.AndroidJUnit4;

@@ -39,7 +46,27 @@ public class UserIconDrawableTest {
                InstrumentationRegistry.getTargetContext().getResources(),
                R.drawable.home);
        mDrawable = new UserIconDrawable(100 /* size */).setIcon(b).bake();

        assertThat(mDrawable.getConstantState()).isNotNull();
    }

    @Test
    public void setTintList_shouldBeApplied() {
        @ColorInt final int targetColor = Color.BLUE;
        final PorterDuff.Mode mode = Mode.SRC_OVER;

        final Bitmap b = Bitmap.createBitmap(1, 1, Config.ARGB_8888);
        UserIconDrawable drawable = new UserIconDrawable().setIcon(b);
        drawable.setBounds(0, 0, 100, 100);

        int[][] stateSet = new int[][] { {} };
        int[] colors = new int[] { targetColor };
        drawable.setTintList(new ColorStateList(stateSet, colors));
        drawable.setTintMode(mode);

        Bitmap bitmap = Bitmap.createBitmap(1, 1, Bitmap.Config.ARGB_8888);
        Canvas canvas = new Canvas(bitmap);
        drawable.draw(canvas);

        assertThat(bitmap.getPixel(0, 0)).isEqualTo(Color.BLUE);
    }
}