Android-x86
Fork
Donation

  • R/O
  • HTTP
  • SSH
  • HTTPS

packages-apps-Launcher3: Commit

packages/apps/Launcher3


Commit MetaInfo

Revisión7092db02410562026da17a7b38f48025cc847de2 (tree)
Tiempo2017-06-09 06:08:47
AutorTony Wickham <twickham@goog...>
CommiterTony Wickham

Log Message

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

Cambiar Resumen

Diferencia incremental

--- a/res/values/colors.xml
+++ b/res/values/colors.xml
@@ -42,6 +42,7 @@
4242 <color name="notification_color_beneath">#E0E0E0</color> <!-- Gray 300 -->
4343
4444 <color name="badge_color">#1DE9B6</color> <!-- Teal A400 -->
45+ <color name="folder_badge_color">#1DE9B6</color> <!-- Teal A400 -->
4546
4647 <!-- System shortcuts -->
4748 <color name="system_shortcuts_icon_color">@android:color/tertiary_text_light</color>
--- a/src/com/android/launcher3/BubbleTextView.java
+++ b/src/com/android/launcher3/BubbleTextView.java
@@ -96,7 +96,7 @@ public class BubbleTextView extends TextView implements ItemInfoUpdateReceiver {
9696
9797 private BadgeInfo mBadgeInfo;
9898 private BadgeRenderer mBadgeRenderer;
99- private IconPalette mIconPalette;
99+ private IconPalette mBadgePalette;
100100 private float mBadgeScale;
101101 private boolean mForceHideBadge;
102102 private Point mTempSpaceForBadgeOffset = new Point();
@@ -453,7 +453,7 @@ public class BubbleTextView extends TextView implements ItemInfoUpdateReceiver {
453453 final int scrollX = getScrollX();
454454 final int scrollY = getScrollY();
455455 canvas.translate(scrollX, scrollY);
456- mBadgeRenderer.draw(canvas, mBadgeInfo, mTempIconBounds, mBadgeScale,
456+ mBadgeRenderer.draw(canvas, mBadgePalette, mBadgeInfo, mTempIconBounds, mBadgeScale,
457457 mTempSpaceForBadgeOffset);
458458 canvas.translate(-scrollX, -scrollY);
459459 }
@@ -578,7 +578,10 @@ public class BubbleTextView extends TextView implements ItemInfoUpdateReceiver {
578578 float newBadgeScale = isBadged ? 1f : 0;
579579 mBadgeRenderer = mLauncher.getDeviceProfile().mBadgeRenderer;
580580 if (wasBadged || isBadged) {
581- mIconPalette = ((FastBitmapDrawable) mIcon).getIconPalette();
581+ mBadgePalette = IconPalette.getBadgePalette(getResources());
582+ if (mBadgePalette == null) {
583+ mBadgePalette = ((FastBitmapDrawable) mIcon).getIconPalette();
584+ }
582585 // Animate when a badge is first added or when it is removed.
583586 if (animate && (wasBadged ^ isBadged) && isShown()) {
584587 ObjectAnimator.ofFloat(this, BADGE_SCALE_PROPERTY, newBadgeScale).start();
@@ -590,6 +593,10 @@ public class BubbleTextView extends TextView implements ItemInfoUpdateReceiver {
590593 }
591594 }
592595
596+ public IconPalette getBadgePalette() {
597+ return mBadgePalette;
598+ }
599+
593600 /**
594601 * Sets the icon for this view based on the layout direction.
595602 */
--- a/src/com/android/launcher3/FastBitmapDrawable.java
+++ b/src/com/android/launcher3/FastBitmapDrawable.java
@@ -124,7 +124,7 @@ public class FastBitmapDrawable extends Drawable {
124124 public IconPalette getIconPalette() {
125125 if (mIconPalette == null) {
126126 mIconPalette = IconPalette.fromDominantColor(Utilities
127- .findDominantColorByHue(mBitmap, 20));
127+ .findDominantColorByHue(mBitmap, 20), true /* desaturateBackground */);
128128 }
129129 return mIconPalette;
130130 }
--- a/src/com/android/launcher3/badge/BadgeRenderer.java
+++ b/src/com/android/launcher3/badge/BadgeRenderer.java
@@ -63,7 +63,6 @@ public class BadgeRenderer {
6363 private final Paint mBackgroundPaint = new Paint(Paint.ANTI_ALIAS_FLAG
6464 | Paint.FILTER_BITMAP_FLAG);
6565 private final SparseArray<Bitmap> mBackgroundsWithShadow;
66- private final IconPalette mIconPalette;
6766
6867 public BadgeRenderer(Context context, int iconSizePx) {
6968 mContext = context;
@@ -83,25 +82,24 @@ public class BadgeRenderer {
8382 mTextHeight = tempTextHeight.height();
8483
8584 mBackgroundsWithShadow = new SparseArray<>(3);
86-
87- mIconPalette = IconPalette.fromDominantColor(context.getColor(R.color.badge_color));
8885 }
8986
9087 /**
9188 * Draw a circle in the top right corner of the given bounds, and draw
9289 * {@link BadgeInfo#getNotificationCount()} on top of the circle.
90+ * @param palette The colors (based on the icon) to use for the badge.
9391 * @param badgeInfo Contains data to draw on the badge. Could be null if we are animating out.
9492 * @param iconBounds The bounds of the icon being badged.
9593 * @param badgeScale The progress of the animation, from 0 to 1.
9694 * @param spaceForOffset How much space is available to offset the badge up and to the right.
9795 */
98- public void draw(Canvas canvas, @Nullable BadgeInfo badgeInfo,
96+ public void draw(Canvas canvas, IconPalette palette, @Nullable BadgeInfo badgeInfo,
9997 Rect iconBounds, float badgeScale, Point spaceForOffset) {
100- mTextPaint.setColor(mIconPalette.textColor);
98+ mTextPaint.setColor(palette.textColor);
10199 IconDrawer iconDrawer = badgeInfo != null && badgeInfo.isIconLarge()
102100 ? mLargeIconDrawer : mSmallIconDrawer;
103101 Shader icon = badgeInfo == null ? null : badgeInfo.getNotificationIconForBadge(
104- mContext, mIconPalette.backgroundColor, mSize, iconDrawer.mPadding);
102+ mContext, palette.backgroundColor, mSize, iconDrawer.mPadding);
105103 String notificationCount = badgeInfo == null ? "0"
106104 : String.valueOf(badgeInfo.getNotificationCount());
107105 int numChars = notificationCount.length();
@@ -127,7 +125,7 @@ public class BadgeRenderer {
127125 canvas.translate(badgeCenterX + offsetX, badgeCenterY - offsetY);
128126 canvas.scale(badgeScale, badgeScale);
129127 // Prepare the background and shadow and possible stacking effect.
130- mBackgroundPaint.setColorFilter(mIconPalette.backgroundColorMatrixFilter);
128+ mBackgroundPaint.setColorFilter(palette.backgroundColorMatrixFilter);
131129 int backgroundWithShadowSize = backgroundWithShadow.getHeight(); // Same as width.
132130 boolean shouldStack = !isDot && badgeInfo != null
133131 && badgeInfo.getNotificationKeys().size() > 1;
@@ -149,7 +147,7 @@ public class BadgeRenderer {
149147 -backgroundWithShadowSize / 2, mBackgroundPaint);
150148 iconDrawer.drawIcon(icon, canvas);
151149 } else if (isDot) {
152- mBackgroundPaint.setColorFilter(mIconPalette.saturatedBackgroundColorMatrixFilter);
150+ mBackgroundPaint.setColorFilter(palette.saturatedBackgroundColorMatrixFilter);
153151 canvas.drawBitmap(backgroundWithShadow, -backgroundWithShadowSize / 2,
154152 -backgroundWithShadowSize / 2, mBackgroundPaint);
155153 }
--- a/src/com/android/launcher3/folder/FolderIcon.java
+++ b/src/com/android/launcher3/folder/FolderIcon.java
@@ -75,6 +75,7 @@ import com.android.launcher3.badge.FolderBadgeInfo;
7575 import com.android.launcher3.config.FeatureFlags;
7676 import com.android.launcher3.dragndrop.DragLayer;
7777 import com.android.launcher3.dragndrop.DragView;
78+import com.android.launcher3.graphics.IconPalette;
7879 import com.android.launcher3.util.Thunk;
7980
8081 import java.util.ArrayList;
@@ -885,7 +886,8 @@ public class FolderIcon extends FrameLayout implements FolderListener {
885886 // If we are animating to the accepting state, animate the badge out.
886887 float badgeScale = Math.max(0, mBadgeScale - mBackground.getScaleProgress());
887888 mTempSpaceForBadgeOffset.set(getWidth() - mTempBounds.right, mTempBounds.top);
888- mBadgeRenderer.draw(canvas, mBadgeInfo, mTempBounds,
889+ IconPalette badgePalette = IconPalette.getFolderBadgePalette(getResources());
890+ mBadgeRenderer.draw(canvas, badgePalette, mBadgeInfo, mTempBounds,
889891 badgeScale, mTempSpaceForBadgeOffset);
890892 }
891893 }
--- a/src/com/android/launcher3/graphics/IconPalette.java
+++ b/src/com/android/launcher3/graphics/IconPalette.java
@@ -18,9 +18,12 @@ package com.android.launcher3.graphics;
1818
1919 import android.app.Notification;
2020 import android.content.Context;
21+import android.content.res.Resources;
2122 import android.graphics.Color;
2223 import android.graphics.ColorMatrix;
2324 import android.graphics.ColorMatrixColorFilter;
25+import android.support.annotation.NonNull;
26+import android.support.annotation.Nullable;
2427 import android.support.v4.graphics.ColorUtils;
2528 import android.util.Log;
2629
@@ -35,11 +38,12 @@ public class IconPalette {
3538 private static final boolean DEBUG = false;
3639 private static final String TAG = "IconPalette";
3740
38- public static final IconPalette FOLDER_ICON_PALETTE = new IconPalette(Color.parseColor("#BDC1C6"));
39-
4041 private static final float MIN_PRELOAD_COLOR_SATURATION = 0.2f;
4142 private static final float MIN_PRELOAD_COLOR_LIGHTNESS = 0.6f;
4243
44+ private static IconPalette sBadgePalette;
45+ private static IconPalette sFolderBadgePalette;
46+
4347 public final int dominantColor;
4448 public final int backgroundColor;
4549 public final ColorMatrixColorFilter backgroundColorMatrixFilter;
@@ -47,15 +51,19 @@ public class IconPalette {
4751 public final int textColor;
4852 public final int secondaryColor;
4953
50- private IconPalette(int color) {
54+ private IconPalette(int color, boolean desaturateBackground) {
5155 dominantColor = color;
52- backgroundColor = dominantColor;
56+ backgroundColor = desaturateBackground ? getMutedColor(dominantColor, 0.87f) : dominantColor;
5357 ColorMatrix backgroundColorMatrix = new ColorMatrix();
5458 Themes.setColorScaleOnMatrix(backgroundColor, backgroundColorMatrix);
5559 backgroundColorMatrixFilter = new ColorMatrixColorFilter(backgroundColorMatrix);
56- // Get slightly more saturated background color.
57- Themes.setColorScaleOnMatrix(getMutedColor(dominantColor, 0.54f), backgroundColorMatrix);
58- saturatedBackgroundColorMatrixFilter = new ColorMatrixColorFilter(backgroundColorMatrix);
60+ if (!desaturateBackground) {
61+ saturatedBackgroundColorMatrixFilter = backgroundColorMatrixFilter;
62+ } else {
63+ // Get slightly more saturated background color.
64+ Themes.setColorScaleOnMatrix(getMutedColor(dominantColor, 0.54f), backgroundColorMatrix);
65+ saturatedBackgroundColorMatrixFilter = new ColorMatrixColorFilter(backgroundColorMatrix);
66+ }
5967 textColor = getTextColorForBackground(backgroundColor);
6068 secondaryColor = getLowContrastColor(backgroundColor);
6169 }
@@ -78,8 +86,35 @@ public class IconPalette {
7886 return result;
7987 }
8088
81- public static IconPalette fromDominantColor(int dominantColor) {
82- return new IconPalette(dominantColor);
89+ public static IconPalette fromDominantColor(int dominantColor, boolean desaturateBackground) {
90+ return new IconPalette(dominantColor, desaturateBackground);
91+ }
92+
93+ /**
94+ * Returns an IconPalette based on the badge_color in colors.xml.
95+ * If that color is Color.TRANSPARENT, then returns null instead.
96+ */
97+ public static @Nullable IconPalette getBadgePalette(Resources resources) {
98+ int badgeColor = resources.getColor(R.color.badge_color);
99+ if (badgeColor == Color.TRANSPARENT) {
100+ // Colors will be extracted per app icon, so a static palette won't work.
101+ return null;
102+ }
103+ if (sBadgePalette == null) {
104+ sBadgePalette = fromDominantColor(badgeColor, false);
105+ }
106+ return sBadgePalette;
107+ }
108+
109+ /**
110+ * Returns an IconPalette based on the folder_badge_color in colors.xml.
111+ */
112+ public static @NonNull IconPalette getFolderBadgePalette(Resources resources) {
113+ if (sFolderBadgePalette == null) {
114+ int badgeColor = resources.getColor(R.color.folder_badge_color);
115+ sFolderBadgePalette = fromDominantColor(badgeColor, false);
116+ }
117+ return sFolderBadgePalette;
83118 }
84119
85120 /**
--- a/src/com/android/launcher3/popup/PopupContainerWithArrow.java
+++ b/src/com/android/launcher3/popup/PopupContainerWithArrow.java
@@ -47,7 +47,6 @@ import com.android.launcher3.AbstractFloatingView;
4747 import com.android.launcher3.BubbleTextView;
4848 import com.android.launcher3.DragSource;
4949 import com.android.launcher3.DropTarget;
50-import com.android.launcher3.FastBitmapDrawable;
5150 import com.android.launcher3.ItemInfo;
5251 import com.android.launcher3.Launcher;
5352 import com.android.launcher3.LauncherAnimUtils;
@@ -579,9 +578,7 @@ public class PopupContainerWithArrow extends AbstractFloatingView implements Dra
579578 ItemInfo itemInfo = (ItemInfo) mOriginalIcon.getTag();
580579 BadgeInfo badgeInfo = mLauncher.getPopupDataProvider().getBadgeInfoForItem(itemInfo);
581580 if (mNotificationItemView != null && badgeInfo != null) {
582- IconPalette palette = mOriginalIcon.getIcon() instanceof FastBitmapDrawable
583- ? ((FastBitmapDrawable) mOriginalIcon.getIcon()).getIconPalette()
584- : null;
581+ IconPalette palette = mOriginalIcon.getBadgePalette();
585582 mNotificationItemView.updateHeader(badgeInfo.getNotificationCount(), palette);
586583 }
587584 }
Show on old repository browser