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

Commit c896e6d3 authored by Sunny Goyal's avatar Sunny Goyal Committed by android-build-merger
Browse files

Merge "Setting the alpha on the full bitmap for AdaptiveIcon instead of...

Merge "Setting the alpha on the full bitmap for AdaptiveIcon instead of individual layers" into pi-dev am: b577d00c
am: bde7a11a

Change-Id: I506145f13280d4895e6f2af9aaa26812e837a4d1
parents 44deec21 bde7a11a
Loading
Loading
Loading
Loading
+25 −5
Original line number Diff line number Diff line
package android.graphics.drawable;

import static org.junit.Assert.assertTrue;

import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.Bitmap.Config;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Outline;
import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.Path.Direction;
import android.graphics.Rect;
@@ -19,10 +15,12 @@ import android.support.test.filters.LargeTest;
import android.test.AndroidTestCase;
import android.util.Log;
import android.util.PathParser;

import org.junit.Test;

import java.io.File;
import java.io.FileOutputStream;
import java.util.Arrays;
import org.junit.Test;

@LargeTest
public class AdaptiveIconDrawableTest extends AndroidTestCase {
@@ -173,6 +171,28 @@ public class AdaptiveIconDrawableTest extends AndroidTestCase {
        assertTrue("outline path should be convex", outline.mPath.isConvex());
    }

    @Test
    public void testSetAlpha() throws Exception {
        mIconDrawable = new AdaptiveIconDrawable(mBackgroundDrawable, mForegroundDrawable);
        mIconDrawable.setBounds(0, 0, 100, 100);

        Bitmap bitmap = Bitmap.createBitmap(100, 100, Bitmap.Config.ARGB_8888);
        Canvas canvas = new Canvas(bitmap);

        mIconDrawable.draw(canvas);
        assertEquals(255, Color.alpha(bitmap.getPixel(50, 50)));

        mIconDrawable.setAlpha(200);
        bitmap.eraseColor(Color.TRANSPARENT);
        mIconDrawable.draw(canvas);
        assertEquals(200, Color.alpha(bitmap.getPixel(50, 50)));

        mIconDrawable.setAlpha(100);
        bitmap.eraseColor(Color.TRANSPARENT);
        mIconDrawable.draw(canvas);
        assertEquals(100, Color.alpha(bitmap.getPixel(50, 50)));
    }

    //
    // Utils
    //
+2 −7
Original line number Diff line number Diff line
@@ -44,6 +44,7 @@ import android.util.DisplayMetrics;
import android.util.PathParser;

import com.android.internal.R;

import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;

@@ -668,13 +669,7 @@ public class AdaptiveIconDrawable extends Drawable implements Drawable.Callback

    @Override
    public void setAlpha(int alpha) {
        final ChildDrawable[] array = mLayerState.mChildren;
        for (int i = 0; i < mLayerState.N_CHILDREN; i++) {
            final Drawable dr = array[i].mDrawable;
            if (dr != null) {
                dr.setAlpha(alpha);
            }
        }
        mPaint.setAlpha(alpha);
    }

    @Override