aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorSteve Kondik <steve@cyngn.com>2016-02-19 19:12:03 +0100
committerSteve Kondik <steve@cyngn.com>2016-02-19 19:12:03 +0100
commitccce2924981e38358e710359fee0a9a132eb6047 (patch)
tree80898d50ed7362db85700d0ebadafdc5149238dc /src
parent6ad5263eb345fcf9f69e9778896c0ff365b38a47 (diff)
downloadvendor_cmsdk-ccce2924981e38358e710359fee0a9a132eb6047.zip
vendor_cmsdk-ccce2924981e38358e710359fee0a9a132eb6047.tar.gz
vendor_cmsdk-ccce2924981e38358e710359fee0a9a132eb6047.tar.bz2
cmsdk: Add sanity checks in ColorUtils
* Protect against nulls when generating colors from icons. Change-Id: I0ba9540848f7be485e713301f2c6c804bd4522e1
Diffstat (limited to 'src')
-rw-r--r--src/java/cyanogenmod/util/ColorUtils.java14
1 files changed, 12 insertions, 2 deletions
diff --git a/src/java/cyanogenmod/util/ColorUtils.java b/src/java/cyanogenmod/util/ColorUtils.java
index 345a739..37b4e5d 100644
--- a/src/java/cyanogenmod/util/ColorUtils.java
+++ b/src/java/cyanogenmod/util/ColorUtils.java
@@ -237,6 +237,9 @@ public class ColorUtils {
* @return the dominant Swatch
*/
public static Palette.Swatch getDominantSwatch(Palette palette) {
+ if (palette == null || palette.getSwatches().size() == 0) {
+ return null;
+ }
// find most-represented swatch based on population
return Collections.max(palette.getSwatches(), new Comparator<Palette.Swatch>() {
@Override
@@ -273,10 +276,17 @@ public class ColorUtils {
if (bitmap != null) {
Palette p = Palette.from(bitmap).generate();
+ if (p == null) {
+ return alertColor;
+ }
// First try the dominant color
- int iconColor = getDominantSwatch(p).getRgb();
- alertColor = findPerceptuallyNearestSolidColor(iconColor);
+ final Palette.Swatch dominantSwatch = getDominantSwatch(p);
+ int iconColor = alertColor;
+ if (dominantSwatch != null) {
+ iconColor = dominantSwatch.getRgb();
+ alertColor = findPerceptuallyNearestSolidColor(iconColor);
+ }
// Try the most saturated color if we got white or black (boring)
if (alertColor == Color.BLACK || alertColor == Color.WHITE) {