summaryrefslogtreecommitdiffstats
path: root/src/com/android/launcher3/graphics/IconPalette.java
diff options
context:
space:
mode:
authorTony Wickham <twickham@google.com>2017-06-07 14:32:23 -0700
committerTony Wickham <twickham@google.com>2017-06-08 21:08:47 +0000
commit7092db02410562026da17a7b38f48025cc847de2 (patch)
treef1c0c5a50594ce890109bdb25dd0346dee9cbf6d /src/com/android/launcher3/graphics/IconPalette.java
parent85b64c7da0f1134fdbae954acbc2925c1433566a (diff)
downloadandroid_packages_apps_Trebuchet-7092db02410562026da17a7b38f48025cc847de2.tar.gz
android_packages_apps_Trebuchet-7092db02410562026da17a7b38f48025cc847de2.tar.bz2
android_packages_apps_Trebuchet-7092db02410562026da17a7b38f48025cc847de2.zip
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
Diffstat (limited to 'src/com/android/launcher3/graphics/IconPalette.java')
-rw-r--r--src/com/android/launcher3/graphics/IconPalette.java53
1 files changed, 44 insertions, 9 deletions
diff --git a/src/com/android/launcher3/graphics/IconPalette.java b/src/com/android/launcher3/graphics/IconPalette.java
index 60ca7b236..a17ceeb94 100644
--- 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;
import android.app.Notification;
import android.content.Context;
+import android.content.res.Resources;
import android.graphics.Color;
import android.graphics.ColorMatrix;
import android.graphics.ColorMatrixColorFilter;
+import android.support.annotation.NonNull;
+import android.support.annotation.Nullable;
import android.support.v4.graphics.ColorUtils;
import android.util.Log;
@@ -35,11 +38,12 @@ public class IconPalette {
private static final boolean DEBUG = false;
private static final String TAG = "IconPalette";
- public static final IconPalette FOLDER_ICON_PALETTE = new IconPalette(Color.parseColor("#BDC1C6"));
-
private static final float MIN_PRELOAD_COLOR_SATURATION = 0.2f;
private static final float MIN_PRELOAD_COLOR_LIGHTNESS = 0.6f;
+ private static IconPalette sBadgePalette;
+ private static IconPalette sFolderBadgePalette;
+
public final int dominantColor;
public final int backgroundColor;
public final ColorMatrixColorFilter backgroundColorMatrixFilter;
@@ -47,15 +51,19 @@ public class IconPalette {
public final int textColor;
public final int secondaryColor;
- private IconPalette(int color) {
+ private IconPalette(int color, boolean desaturateBackground) {
dominantColor = color;
- backgroundColor = dominantColor;
+ backgroundColor = desaturateBackground ? getMutedColor(dominantColor, 0.87f) : dominantColor;
ColorMatrix backgroundColorMatrix = new ColorMatrix();
Themes.setColorScaleOnMatrix(backgroundColor, backgroundColorMatrix);
backgroundColorMatrixFilter = new ColorMatrixColorFilter(backgroundColorMatrix);
- // Get slightly more saturated background color.
- Themes.setColorScaleOnMatrix(getMutedColor(dominantColor, 0.54f), backgroundColorMatrix);
- saturatedBackgroundColorMatrixFilter = new ColorMatrixColorFilter(backgroundColorMatrix);
+ if (!desaturateBackground) {
+ saturatedBackgroundColorMatrixFilter = backgroundColorMatrixFilter;
+ } else {
+ // Get slightly more saturated background color.
+ Themes.setColorScaleOnMatrix(getMutedColor(dominantColor, 0.54f), backgroundColorMatrix);
+ saturatedBackgroundColorMatrixFilter = new ColorMatrixColorFilter(backgroundColorMatrix);
+ }
textColor = getTextColorForBackground(backgroundColor);
secondaryColor = getLowContrastColor(backgroundColor);
}
@@ -78,8 +86,35 @@ public class IconPalette {
return result;
}
- public static IconPalette fromDominantColor(int dominantColor) {
- return new IconPalette(dominantColor);
+ public static IconPalette fromDominantColor(int dominantColor, boolean desaturateBackground) {
+ return new IconPalette(dominantColor, desaturateBackground);
+ }
+
+ /**
+ * Returns an IconPalette based on the badge_color in colors.xml.
+ * If that color is Color.TRANSPARENT, then returns null instead.
+ */
+ public static @Nullable IconPalette getBadgePalette(Resources resources) {
+ int badgeColor = resources.getColor(R.color.badge_color);
+ if (badgeColor == Color.TRANSPARENT) {
+ // Colors will be extracted per app icon, so a static palette won't work.
+ return null;
+ }
+ if (sBadgePalette == null) {
+ sBadgePalette = fromDominantColor(badgeColor, false);
+ }
+ return sBadgePalette;
+ }
+
+ /**
+ * Returns an IconPalette based on the folder_badge_color in colors.xml.
+ */
+ public static @NonNull IconPalette getFolderBadgePalette(Resources resources) {
+ if (sFolderBadgePalette == null) {
+ int badgeColor = resources.getColor(R.color.folder_badge_color);
+ sFolderBadgePalette = fromDominantColor(badgeColor, false);
+ }
+ return sFolderBadgePalette;
}
/**