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

Commit d0f5aa0d authored by Schneider Victor-tulias's avatar Schneider Victor-tulias Committed by Android (Google) Code Review
Browse files

Merge "Update PreloadIconDrawable colors when an app is not startable." into sc-dev

parents 18fcb432 2e292b63
Loading
Loading
Loading
Loading
+73 −15
Original line number Diff line number Diff line
@@ -24,6 +24,7 @@ import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.animation.ObjectAnimator;
import android.content.Context;
import android.content.res.Configuration;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Matrix;
@@ -34,10 +35,12 @@ import android.graphics.Rect;
import android.util.Pair;
import android.util.Property;
import android.util.SparseArray;
import android.view.ContextThemeWrapper;

import com.android.launcher3.FastBitmapDrawable;
import com.android.launcher3.anim.Interpolators;
import com.android.launcher3.model.data.ItemInfoWithIcon;
import com.android.launcher3.util.Themes;

import java.lang.ref.WeakReference;

@@ -77,6 +80,9 @@ public class PreloadIconDrawable extends FastBitmapDrawable {
    private static final SparseArray<WeakReference<Pair<Path, Bitmap>>> sShadowCache =
            new SparseArray<>();

    private static final int PRELOAD_ACCENT_COLOR_INDEX = 0;
    private static final int PRELOAD_BACKGROUND_COLOR_INDEX = 1;

    private final Matrix mTmpMatrix = new Matrix();
    private final PathMeasure mPathMeasure = new PathMeasure();

@@ -91,6 +97,9 @@ public class PreloadIconDrawable extends FastBitmapDrawable {

    private Bitmap mShadowBitmap;
    private final int mIndicatorColor;
    private final int mSystemAccentColor;
    private final int mSystemBackgroundColor;
    private final boolean mIsDarkMode;

    private int mTrackAlpha;
    private float mTrackLength;
@@ -104,11 +113,23 @@ public class PreloadIconDrawable extends FastBitmapDrawable {

    private ObjectAnimator mCurrentAnim;

    private boolean mIsStartable;

    public PreloadIconDrawable(ItemInfoWithIcon info, Context context) {
        this(info, IconPalette.getPreloadProgressColor(context, info.bitmap.color));
        this(
                info,
                IconPalette.getPreloadProgressColor(context, info.bitmap.color),
                getPreloadColors(context),
            (context.getResources().getConfiguration().uiMode
                    & Configuration.UI_MODE_NIGHT_MASK
                    & Configuration.UI_MODE_NIGHT_YES) != 0) /* isDarkMode */;
    }

    public PreloadIconDrawable(ItemInfoWithIcon info, int indicatorColor) {
    public PreloadIconDrawable(
            ItemInfoWithIcon info,
            int indicatorColor,
            int[] preloadColors,
            boolean isDarkMode) {
        super(info.bitmap);
        mItem = info;
        mShapePath = getShapePath();
@@ -120,9 +141,12 @@ public class PreloadIconDrawable extends FastBitmapDrawable {
        mProgressPaint.setStrokeCap(Paint.Cap.ROUND);
        mIndicatorColor = indicatorColor;

        setInternalProgress(0);
        mSystemAccentColor = preloadColors[PRELOAD_ACCENT_COLOR_INDEX];
        mSystemBackgroundColor = preloadColors[PRELOAD_BACKGROUND_COLOR_INDEX];
        mIsDarkMode = isDarkMode;

        setIsDisabled(!info.isAppStartable());
        setInternalProgress(info.getProgressLevel());
        setIsStartable(info.isAppStartable());
    }

    @Override
@@ -148,7 +172,7 @@ public class PreloadIconDrawable extends FastBitmapDrawable {
    }

    private Bitmap getShadowBitmap(int width, int height, float shadowRadius) {
        int key = (width << 16) | height;
        int key = ((width << 16) | height) * (mIsDarkMode ? -1 : 1);
        WeakReference<Pair<Path, Bitmap>> shadowRef = sShadowCache.get(key);
        Pair<Path, Bitmap> cache = shadowRef != null ? shadowRef.get() : null;
        Bitmap shadow = cache != null && cache.first.equals(mShapePath) ? cache.second : null;
@@ -157,8 +181,9 @@ public class PreloadIconDrawable extends FastBitmapDrawable {
        }
        shadow = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
        Canvas c = new Canvas(shadow);
        mProgressPaint.setShadowLayer(shadowRadius, 0, 0, COLOR_SHADOW);
        mProgressPaint.setColor(COLOR_TRACK);
        mProgressPaint.setShadowLayer(shadowRadius, 0, 0, mIsStartable
                ? COLOR_SHADOW : mSystemAccentColor);
        mProgressPaint.setColor(mIsStartable ? COLOR_TRACK : mSystemBackgroundColor);
        mProgressPaint.setAlpha(MAX_PAINT_ALPHA);
        c.drawPath(mScaledTrackPath, mProgressPaint);
        mProgressPaint.clearShadowLayer();
@@ -176,7 +201,7 @@ public class PreloadIconDrawable extends FastBitmapDrawable {
        }

        // Draw track.
        mProgressPaint.setColor(mIndicatorColor);
        mProgressPaint.setColor(mIsStartable ? mIndicatorColor : mSystemAccentColor);
        mProgressPaint.setAlpha(mTrackAlpha);
        if (mShadowBitmap != null) {
            canvas.drawBitmap(mShadowBitmap, bounds.left, bounds.top, mProgressPaint);
@@ -215,6 +240,14 @@ public class PreloadIconDrawable extends FastBitmapDrawable {
        return !mRanFinishAnimation;
    }

    /** Sets whether this icon should display the startable app UI. */
    public void setIsStartable(boolean isStartable) {
        if (mIsStartable != isStartable) {
            mIsStartable = isStartable;
            setIsDisabled(!isStartable);
        }
    }

    private void updateInternalState(float finalProgress, boolean shouldAnimate, boolean isFinish) {
        if (mCurrentAnim != null) {
            mCurrentAnim.cancel();
@@ -295,6 +328,18 @@ public class PreloadIconDrawable extends FastBitmapDrawable {
        invalidateSelf();
    }

    private static int[] getPreloadColors(Context context) {
        Context dayNightThemeContext = new ContextThemeWrapper(
                context, android.R.style.Theme_DeviceDefault_DayNight);
        int[] preloadColors = new int[2];

        preloadColors[PRELOAD_ACCENT_COLOR_INDEX] = Themes.getColorAccent(dayNightThemeContext);
        preloadColors[PRELOAD_BACKGROUND_COLOR_INDEX] = Themes.getColorBackgroundFloating(
                dayNightThemeContext);

        return preloadColors;
    }

    /**
     * Returns a FastBitmapDrawable with the icon.
     */
@@ -305,13 +350,21 @@ public class PreloadIconDrawable extends FastBitmapDrawable {
    @Override
    public ConstantState getConstantState() {
        return new PreloadIconConstantState(
                mBitmap, mIconColor, !mItem.isAppStartable(), mItem, mIndicatorColor);
                mBitmap,
                mIconColor,
                !mItem.isAppStartable(),
                mItem,
                mIndicatorColor,
                new int[] {mSystemAccentColor, mSystemBackgroundColor},
                mIsDarkMode);
    }

    protected static class PreloadIconConstantState extends FastBitmapConstantState {

        protected final ItemInfoWithIcon mInfo;
        protected final int mIndicatorColor;
        protected final int[] mPreloadColors;
        protected final boolean mIsDarkMode;
        protected final int mLevel;

        public PreloadIconConstantState(
@@ -319,19 +372,24 @@ public class PreloadIconDrawable extends FastBitmapDrawable {
                int iconColor,
                boolean isDisabled,
                ItemInfoWithIcon info,
                int indicatorcolor) {
                int indicatorColor,
                int[] preloadColors,
                boolean isDarkMode) {
            super(bitmap, iconColor, isDisabled);
            mInfo = info;
            mIndicatorColor = indicatorcolor;
            mIndicatorColor = indicatorColor;
            mPreloadColors = preloadColors;
            mIsDarkMode = isDarkMode;
            mLevel = info.getProgressLevel();
        }

        @Override
        public PreloadIconDrawable newDrawable() {
            PreloadIconDrawable drawable = new PreloadIconDrawable(mInfo, mIndicatorColor);
            drawable.setLevel(mLevel);
            drawable.setIsDisabled(mIsDisabled);
            return drawable;
            return new PreloadIconDrawable(
                    mInfo,
                    mIndicatorColor,
                    mPreloadColors,
                    mIsDarkMode);
        }

        @Override
+5 −0
Original line number Diff line number Diff line
@@ -81,6 +81,11 @@ public class Themes {
        return getAttrColor(context, android.R.attr.colorAccent);
    }

    /** Returns the floating background color attribute. */
    public static int getColorBackgroundFloating(Context context) {
        return getAttrColor(context, android.R.attr.colorBackgroundFloating);
    }

    public static int getAttrColor(Context context, int attr) {
        TypedArray ta = context.obtainStyledAttributes(new int[]{attr});
        int colorAccent = ta.getColor(0, 0);