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

Commit f89dbff4 authored by d34d's avatar d34d Committed by Clark Scheff
Browse files

Themes: Pass ComposedIconInfo into createIconBitmap

The majority of the parameters being passed into createIconBitmap
were coming straight from the ComposedIconInfo so rather than pass
them in separately we just pass in the ComposedIconInfo object.
This will help prevent increasing the # of parameters as more
features are added to composed icons.

Change-Id: I6840db66a1369e0d75de4c662563b96dc58c34ab
parent d63f5d54
Loading
Loading
Loading
Loading
+24 −32
Original line number Diff line number Diff line
@@ -597,10 +597,7 @@ public class IconPackHelper {
            } else if (iconInfo.iconBacks != null && iconInfo.iconBacks.length > 0) {
                back = iconInfo.iconBacks[sRandom.nextInt(iconInfo.iconBacks.length)];
            }
            Bitmap bmp = createIconBitmap(icon, res, back, iconInfo.iconMask, iconInfo.iconUpon,
                    iconInfo.iconScale, iconInfo.iconRotation, iconInfo.iconTranslationX,
                    iconInfo.iconTranslationY, iconInfo.iconSize, iconInfo.colorFilter,
                    iconInfo.swatchType, defaultSwatchColor);
            Bitmap bmp = createIconBitmap(icon, res, back, defaultSwatchColor, iconInfo);
            return bmp != null ? new BitmapDrawable(res, bmp): null;
        }

@@ -631,10 +628,7 @@ public class IconPackHelper {
                if (DEBUG) {
                    Log.d(TAG, "Composing icon for " + pkgName);
                }
                Bitmap bmp = createIconBitmap(baseIcon, res, back, iconInfo.iconMask,
                        iconInfo.iconUpon, iconInfo.iconScale, iconInfo.iconRotation,
                        iconInfo.iconTranslationX, iconInfo.iconTranslationY, iconInfo.iconSize,
                        iconInfo.colorFilter, iconInfo.swatchType, defaultSwatchColor);
                Bitmap bmp = createIconBitmap(baseIcon, res, back, defaultSwatchColor, iconInfo);
                if (!cacheComposedIcon(bmp, getCachedIconName(pkgName, resId, outValue.density))) {
                    Log.w(TAG, "Unable to cache icon " + outValue.string);
                    // restore the original TypedValue
@@ -644,10 +638,8 @@ public class IconPackHelper {
        }

        private static Bitmap createIconBitmap(Drawable icon, Resources res, int iconBack,
                int iconMask, int iconUpon, float scale, float angle, float translationX,
                float translationY, int iconSize, float[] colorFilter,
                ComposedIconInfo.SwatchType swatchType, int defaultSwatchColor) {
            if (iconSize <= 0) return null;
                int defaultSwatchColor, ComposedIconInfo iconInfo) {
            if (iconInfo.iconSize <= 0) return null;

            final Canvas canvas = new Canvas();
            canvas.setDrawFilter(new PaintFlagsDrawFilter(Paint.ANTI_ALIAS_FLAG,
@@ -657,12 +649,12 @@ public class IconPackHelper {
            int backTintColor = 0;
            if (icon instanceof PaintDrawable) {
                PaintDrawable painter = (PaintDrawable) icon;
                painter.setIntrinsicWidth(iconSize);
                painter.setIntrinsicHeight(iconSize);
                painter.setIntrinsicWidth(iconInfo.iconSize);
                painter.setIntrinsicHeight(iconInfo.iconSize);

                // A PaintDrawable does not have an exact size
                width = iconSize;
                height = iconSize;
                width = iconInfo.iconSize;
                height = iconInfo.iconSize;
            } else if (icon instanceof BitmapDrawable) {
                // Ensure the bitmap has a density.
                BitmapDrawable bitmapDrawable = (BitmapDrawable) icon;
@@ -677,17 +669,17 @@ public class IconPackHelper {
                // respect the original size of the icon
                // otherwise enormous icons can easily create
                // OOM situations.
                if ((bitmap.getWidth() < (iconSize * 2))
                        && (bitmap.getHeight() < (iconSize * 2))) {
                if ((bitmap.getWidth() < (iconInfo.iconSize * 2))
                        && (bitmap.getHeight() < (iconInfo.iconSize * 2))) {
                    width = bitmap.getWidth();
                    height = bitmap.getHeight();
                } else {
                    width = iconSize;
                    height = iconSize;
                    width = iconInfo.iconSize;
                    height = iconInfo.iconSize;
                }
                if (swatchType != ComposedIconInfo.SwatchType.None) {
                if (iconInfo.swatchType != ComposedIconInfo.SwatchType.None) {
                    Palette palette = Palette.generate(bitmap, NUM_PALETTE_COLORS);
                    switch (swatchType) {
                    switch (iconInfo.swatchType) {
                        case Vibrant:
                            backTintColor = palette.getVibrantColor(defaultSwatchColor);
                            break;
@@ -712,7 +704,7 @@ public class IconPackHelper {
                    }
                }
            } else if (icon instanceof VectorDrawable) {
                width = height = iconSize;
                width = height = iconInfo.iconSize;
            }

            if (width <= 0 || height <= 0) return null;
@@ -728,24 +720,24 @@ public class IconPackHelper {
            canvas.save();
            final float halfWidth = width / 2f;
            final float halfHeight = height / 2f;
            canvas.rotate(angle, halfWidth, halfHeight);
            canvas.scale(scale, scale, halfWidth, halfHeight);
            canvas.translate(translationX, translationY);
            if (colorFilter != null) {
            canvas.rotate(iconInfo.iconRotation, halfWidth, halfHeight);
            canvas.scale(iconInfo.iconScale, iconInfo.iconScale, halfWidth, halfHeight);
            canvas.translate(iconInfo.iconTranslationX, iconInfo.iconTranslationY);
            if (iconInfo.colorFilter != null) {
                Paint p = null;
                if (icon instanceof BitmapDrawable) {
                    p = ((BitmapDrawable) icon).getPaint();
                } else if (icon instanceof PaintDrawable) {
                    p = ((PaintDrawable) icon).getPaint();
                }
                if (p != null) p.setColorFilter(new ColorMatrixColorFilter(colorFilter));
                if (p != null) p.setColorFilter(new ColorMatrixColorFilter(iconInfo.colorFilter));
            }
            icon.draw(canvas);
            canvas.restore();

            // Mask off the original if iconMask is not null
            if (iconMask != 0) {
                Drawable mask = res.getDrawable(iconMask);
            if (iconInfo.iconMask != 0) {
                Drawable mask = res.getDrawable(iconInfo.iconMask);
                if (mask != null) {
                    mask.setBounds(icon.getBounds());
                    ((BitmapDrawable) mask).getPaint().setXfermode(
@@ -769,8 +761,8 @@ public class IconPackHelper {
                }
            }
            // Finally draw the foreground if one was supplied
            if (iconUpon != 0) {
                Drawable upon = res.getDrawable(iconUpon);
            if (iconInfo.iconUpon != 0) {
                Drawable upon = res.getDrawable(iconInfo.iconUpon);
                if (upon != null) {
                    upon.setBounds(icon.getBounds());
                    upon.draw(canvas);