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

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

Merge "Remove getShapePath from GraphicsUtils to rely on IconShape instead" into main

parents e3f30bba 4985d469
Loading
Loading
Loading
Loading
+0 −32
Original line number Diff line number Diff line
@@ -16,22 +16,14 @@
package com.android.launcher3.icons;

import android.content.Context;
import android.content.res.Resources;
import android.content.res.TypedArray;
import android.graphics.Bitmap;
import android.graphics.Color;
import android.graphics.Matrix;
import android.graphics.Path;
import android.graphics.Rect;
import android.graphics.Region;
import android.graphics.RegionIterator;
import android.graphics.drawable.AdaptiveIconDrawable;
import android.graphics.drawable.ColorDrawable;
import android.util.Log;

import androidx.annotation.ColorInt;
import androidx.annotation.NonNull;
import androidx.core.graphics.PathParser;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
@@ -99,30 +91,6 @@ public class GraphicsUtils {
        sOnNewBitmapRunnable.run();
    }


    /**
     * Returns the default path to be used by an icon
     */
    public static Path getShapePath(@NonNull Context context, int size) {
        if (IconProvider.CONFIG_ICON_MASK_RES_ID != Resources.ID_NULL) {
            Path path = PathParser.createPathFromPathData(
                    context.getString(IconProvider.CONFIG_ICON_MASK_RES_ID));
            if (path != null) {
                if (size != MASK_SIZE) {
                    Matrix m = new Matrix();
                    float scale = ((float) size) / MASK_SIZE;
                    m.setScale(scale, scale);
                    path.transform(m);
                }
                return path;
            }
        }
        AdaptiveIconDrawable drawable = new AdaptiveIconDrawable(
                new ColorDrawable(Color.BLACK), new ColorDrawable(Color.BLACK));
        drawable.setBounds(0, 0, size, size);
        return new Path(drawable.getIconMask());
    }

    /**
     * Returns the color associated with the attribute
     */
+14 −2
Original line number Diff line number Diff line
@@ -25,6 +25,8 @@ import android.graphics.Path;
import android.graphics.PorterDuff;
import android.graphics.PorterDuffColorFilter;
import android.graphics.Rect;
import android.graphics.drawable.AdaptiveIconDrawable;
import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable;

import androidx.core.graphics.ColorUtils;
@@ -39,12 +41,22 @@ public class PlaceHolderIconDrawable extends FastBitmapDrawable {

    public PlaceHolderIconDrawable(BitmapInfo info, Context context) {
        super(info);

        mProgressPath = GraphicsUtils.getShapePath(context, 100);
        mProgressPath = getDefaultPath();
        mPaint.setColor(ColorUtils.compositeColors(
                GraphicsUtils.getAttrColor(context, R.attr.loadingIconColor), info.color));
    }

    /**
     * Gets the current default icon mask {@link Path}.
     * @return Shaped {@link Path} scaled to [0, 0, 100, 100] bounds
     */
    private Path getDefaultPath() {
        AdaptiveIconDrawable drawable = new AdaptiveIconDrawable(
                new ColorDrawable(Color.BLACK), new ColorDrawable(Color.BLACK));
        drawable.setBounds(0, 0, 100, 100);
        return new Path(drawable.getIconMask());
    }

    @Override
    protected void drawInternal(Canvas canvas, Rect bounds) {
        int saveCount = canvas.save();