summaryrefslogtreecommitdiffstats
path: root/src/com/android/launcher3/graphics
diff options
context:
space:
mode:
authorTony Wickham <twickham@google.com>2017-01-18 22:36:17 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2017-01-18 22:36:17 +0000
commit197f97bde4368e79b9475749560ab668a29fc552 (patch)
tree46f25194582af6706b9bcc509f0bcd8c97292e92 /src/com/android/launcher3/graphics
parent8e98cb876f1c913c256ce6d542a1f975f59f1e2e (diff)
parent9a8d11f930ced4c2706db150b7bbbb21330bd68d (diff)
downloadandroid_packages_apps_Trebuchet-197f97bde4368e79b9475749560ab668a29fc552.tar.gz
android_packages_apps_Trebuchet-197f97bde4368e79b9475749560ab668a29fc552.tar.bz2
android_packages_apps_Trebuchet-197f97bde4368e79b9475749560ab668a29fc552.zip
Merge "FastBitmapDrawable can draw an icon badge (notification count)" into ub-launcher3-master
Diffstat (limited to 'src/com/android/launcher3/graphics')
-rw-r--r--src/com/android/launcher3/graphics/IconPalette.java63
1 files changed, 63 insertions, 0 deletions
diff --git a/src/com/android/launcher3/graphics/IconPalette.java b/src/com/android/launcher3/graphics/IconPalette.java
new file mode 100644
index 000000000..dcc5fcb14
--- /dev/null
+++ b/src/com/android/launcher3/graphics/IconPalette.java
@@ -0,0 +1,63 @@
+/*
+ * Copyright (C) 2017 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.launcher3.graphics;
+
+import android.graphics.Color;
+import android.support.v4.graphics.ColorUtils;
+
+/**
+ * Contains colors based on the dominant color of an icon.
+ */
+public class IconPalette {
+
+ public int backgroundColor;
+ public int textColor;
+
+ public static IconPalette fromDominantColor(int dominantColor) {
+ IconPalette palette = new IconPalette();
+ palette.backgroundColor = getMutedColor(dominantColor);
+ palette.textColor = getTextColorForBackground(palette.backgroundColor);
+ return palette;
+ }
+
+ private static int getMutedColor(int color) {
+ int alpha = (int) (255 * 0.2f);
+ return ColorUtils.compositeColors(ColorUtils.setAlphaComponent(color, alpha), Color.WHITE);
+ }
+
+ private static int getTextColorForBackground(int backgroundColor) {
+ return getLighterOrDarkerVersionOfColor(backgroundColor, 3f);
+ }
+
+ private static int getLowContrastColor(int color) {
+ return getLighterOrDarkerVersionOfColor(color, 1.5f);
+ }
+
+ private static int getLighterOrDarkerVersionOfColor(int color, float contrastRatio) {
+ int whiteMinAlpha = ColorUtils.calculateMinimumAlpha(Color.WHITE, color, contrastRatio);
+ int blackMinAlpha = ColorUtils.calculateMinimumAlpha(Color.BLACK, color, contrastRatio);
+ int translucentWhiteOrBlack;
+ if (whiteMinAlpha >= 0) {
+ translucentWhiteOrBlack = ColorUtils.setAlphaComponent(Color.WHITE, whiteMinAlpha);
+ } else if (blackMinAlpha >= 0) {
+ translucentWhiteOrBlack = ColorUtils.setAlphaComponent(Color.BLACK, blackMinAlpha);
+ } else {
+ translucentWhiteOrBlack = Color.WHITE;
+ }
+ return ColorUtils.compositeColors(translucentWhiteOrBlack, color);
+ }
+}