package nickrout.lenslauncher.util;

import android.graphics.Color;
import android.support.annotation.ColorInt;
import android.support.v7.graphics.Palette;

import nickrout.lenslauncher.model.App;

/**
 * Created by nicholasrout on 2016/05/28.
 */
public class ColorUtil {

    public static @ColorInt int getPaletteColorFromApp(App app) {
        Palette palette = Palette.from(app.getIcon()).generate();
        if (palette.getSwatches().size() > 0) {
            int swatchIndex = 0;
            for (int i = 1; i < palette.getSwatches().size(); i++) {
                if (palette.getSwatches().get(i).getPopulation()
                        > palette.getSwatches().get(swatchIndex).getPopulation()) {
                    swatchIndex = i;
                }
            }
            return palette.getSwatches().get(swatchIndex).getRgb();
        } else {
            return Color.BLACK;
        }
    }

    public static float getHueColorFromApp(App app) {
        float[] hsvValues = new float[3];
        Color.colorToHSV(app.getPaletteColor(), hsvValues);
        return hsvValues[0];
    }
}

@@ -349,16 +349,51 @@
 Palette 
+palette;%0A        try %7B%0A            
 palette 
@@ -430,24 +430,146 @@
 generate();%0A
+        %7D catch (IllegalArgumentException e) %7B%0A            e.printStackTrace();%0A            return Color.BLACK;%0A        %7D%0A
         if (

Fix for occasional Palette crash