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

Commit 7092db02 authored by Tony Wickham's avatar Tony Wickham
Browse files

Add support for color extracted notification dots

Changing the badge_color in colors.xml to transparent
will cause them to be color extracted.

When an extracted color is used in the IconPalette, we
desaturate the background. Otherwise we respect the
exact color specified in colors.xml.

Change-Id: Ie82d0c5335fa5f24d4cc47766e4c1719c4916f8b
parent 85b64c7d
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -42,6 +42,7 @@
    <color name="notification_color_beneath">#E0E0E0</color> <!-- Gray 300 -->

    <color name="badge_color">#1DE9B6</color> <!-- Teal A400 -->
    <color name="folder_badge_color">#1DE9B6</color> <!-- Teal A400 -->

    <!-- System shortcuts -->
    <color name="system_shortcuts_icon_color">@android:color/tertiary_text_light</color>
+10 −3
Original line number Diff line number Diff line
@@ -96,7 +96,7 @@ public class BubbleTextView extends TextView implements ItemInfoUpdateReceiver {

    private BadgeInfo mBadgeInfo;
    private BadgeRenderer mBadgeRenderer;
    private IconPalette mIconPalette;
    private IconPalette mBadgePalette;
    private float mBadgeScale;
    private boolean mForceHideBadge;
    private Point mTempSpaceForBadgeOffset = new Point();
@@ -453,7 +453,7 @@ public class BubbleTextView extends TextView implements ItemInfoUpdateReceiver {
            final int scrollX = getScrollX();
            final int scrollY = getScrollY();
            canvas.translate(scrollX, scrollY);
            mBadgeRenderer.draw(canvas, mBadgeInfo, mTempIconBounds, mBadgeScale,
            mBadgeRenderer.draw(canvas, mBadgePalette, mBadgeInfo, mTempIconBounds, mBadgeScale,
                    mTempSpaceForBadgeOffset);
            canvas.translate(-scrollX, -scrollY);
        }
@@ -578,7 +578,10 @@ public class BubbleTextView extends TextView implements ItemInfoUpdateReceiver {
            float newBadgeScale = isBadged ? 1f : 0;
            mBadgeRenderer = mLauncher.getDeviceProfile().mBadgeRenderer;
            if (wasBadged || isBadged) {
                mIconPalette = ((FastBitmapDrawable) mIcon).getIconPalette();
                mBadgePalette = IconPalette.getBadgePalette(getResources());
                if (mBadgePalette == null) {
                    mBadgePalette = ((FastBitmapDrawable) mIcon).getIconPalette();
                }
                // Animate when a badge is first added or when it is removed.
                if (animate && (wasBadged ^ isBadged) && isShown()) {
                    ObjectAnimator.ofFloat(this, BADGE_SCALE_PROPERTY, newBadgeScale).start();
@@ -590,6 +593,10 @@ public class BubbleTextView extends TextView implements ItemInfoUpdateReceiver {
        }
    }

    public IconPalette getBadgePalette() {
        return mBadgePalette;
    }

    /**
     * Sets the icon for this view based on the layout direction.
     */
+1 −1
Original line number Diff line number Diff line
@@ -124,7 +124,7 @@ public class FastBitmapDrawable extends Drawable {
    public IconPalette getIconPalette() {
        if (mIconPalette == null) {
            mIconPalette = IconPalette.fromDominantColor(Utilities
                    .findDominantColorByHue(mBitmap, 20));
                    .findDominantColorByHue(mBitmap, 20), true /* desaturateBackground */);
        }
        return mIconPalette;
    }
+6 −8
Original line number Diff line number Diff line
@@ -63,7 +63,6 @@ public class BadgeRenderer {
    private final Paint mBackgroundPaint = new Paint(Paint.ANTI_ALIAS_FLAG
            | Paint.FILTER_BITMAP_FLAG);
    private final SparseArray<Bitmap> mBackgroundsWithShadow;
    private final IconPalette mIconPalette;

    public BadgeRenderer(Context context, int iconSizePx) {
        mContext = context;
@@ -83,25 +82,24 @@ public class BadgeRenderer {
        mTextHeight = tempTextHeight.height();

        mBackgroundsWithShadow = new SparseArray<>(3);

        mIconPalette = IconPalette.fromDominantColor(context.getColor(R.color.badge_color));
    }

    /**
     * Draw a circle in the top right corner of the given bounds, and draw
     * {@link BadgeInfo#getNotificationCount()} on top of the circle.
     * @param palette The colors (based on the icon) to use for the badge.
     * @param badgeInfo Contains data to draw on the badge. Could be null if we are animating out.
     * @param iconBounds The bounds of the icon being badged.
     * @param badgeScale The progress of the animation, from 0 to 1.
     * @param spaceForOffset How much space is available to offset the badge up and to the right.
     */
    public void draw(Canvas canvas, @Nullable BadgeInfo badgeInfo,
    public void draw(Canvas canvas, IconPalette palette, @Nullable BadgeInfo badgeInfo,
            Rect iconBounds, float badgeScale, Point spaceForOffset) {
        mTextPaint.setColor(mIconPalette.textColor);
        mTextPaint.setColor(palette.textColor);
        IconDrawer iconDrawer = badgeInfo != null && badgeInfo.isIconLarge()
                ? mLargeIconDrawer : mSmallIconDrawer;
        Shader icon = badgeInfo == null ? null : badgeInfo.getNotificationIconForBadge(
                mContext, mIconPalette.backgroundColor, mSize, iconDrawer.mPadding);
                mContext, palette.backgroundColor, mSize, iconDrawer.mPadding);
        String notificationCount = badgeInfo == null ? "0"
                : String.valueOf(badgeInfo.getNotificationCount());
        int numChars = notificationCount.length();
@@ -127,7 +125,7 @@ public class BadgeRenderer {
        canvas.translate(badgeCenterX + offsetX, badgeCenterY - offsetY);
        canvas.scale(badgeScale, badgeScale);
        // Prepare the background and shadow and possible stacking effect.
        mBackgroundPaint.setColorFilter(mIconPalette.backgroundColorMatrixFilter);
        mBackgroundPaint.setColorFilter(palette.backgroundColorMatrixFilter);
        int backgroundWithShadowSize = backgroundWithShadow.getHeight(); // Same as width.
        boolean shouldStack = !isDot && badgeInfo != null
                && badgeInfo.getNotificationKeys().size() > 1;
@@ -149,7 +147,7 @@ public class BadgeRenderer {
                    -backgroundWithShadowSize / 2, mBackgroundPaint);
            iconDrawer.drawIcon(icon, canvas);
        } else if (isDot) {
            mBackgroundPaint.setColorFilter(mIconPalette.saturatedBackgroundColorMatrixFilter);
            mBackgroundPaint.setColorFilter(palette.saturatedBackgroundColorMatrixFilter);
            canvas.drawBitmap(backgroundWithShadow, -backgroundWithShadowSize / 2,
                    -backgroundWithShadowSize / 2, mBackgroundPaint);
        }
+3 −1
Original line number Diff line number Diff line
@@ -75,6 +75,7 @@ import com.android.launcher3.badge.FolderBadgeInfo;
import com.android.launcher3.config.FeatureFlags;
import com.android.launcher3.dragndrop.DragLayer;
import com.android.launcher3.dragndrop.DragView;
import com.android.launcher3.graphics.IconPalette;
import com.android.launcher3.util.Thunk;

import java.util.ArrayList;
@@ -885,7 +886,8 @@ public class FolderIcon extends FrameLayout implements FolderListener {
            // If we are animating to the accepting state, animate the badge out.
            float badgeScale = Math.max(0, mBadgeScale - mBackground.getScaleProgress());
            mTempSpaceForBadgeOffset.set(getWidth() - mTempBounds.right, mTempBounds.top);
            mBadgeRenderer.draw(canvas, mBadgeInfo, mTempBounds,
            IconPalette badgePalette = IconPalette.getFolderBadgePalette(getResources());
            mBadgeRenderer.draw(canvas, badgePalette, mBadgeInfo, mTempBounds,
                    badgeScale, mTempSpaceForBadgeOffset);
        }
    }
Loading