1 /* 2 * Copyright (C) 2017 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.launcher3.graphics; 18 19 import android.content.Context; 20 import android.graphics.Color; 21 22 import com.android.launcher3.util.Themes; 23 24 /** 25 * Contains colors based on the dominant color of an icon. 26 */ 27 public class IconPalette { 28 private static final String TAG = "IconPalette"; 29 30 private static final float MIN_PRELOAD_COLOR_SATURATION = 0.2f; 31 private static final float MIN_PRELOAD_COLOR_LIGHTNESS = 0.6f; 32 33 /** 34 * Returns a color suitable for the progress bar color of preload icon. 35 */ getPreloadProgressColor(Context context, int dominantColor)36 public static int getPreloadProgressColor(Context context, int dominantColor) { 37 int result = dominantColor; 38 39 // Make sure that the dominant color has enough saturation to be visible properly. 40 float[] hsv = new float[3]; 41 Color.colorToHSV(result, hsv); 42 if (hsv[1] < MIN_PRELOAD_COLOR_SATURATION) { 43 result = Themes.getColorAccent(context); 44 } else { 45 hsv[2] = Math.max(MIN_PRELOAD_COLOR_LIGHTNESS, hsv[2]); 46 result = Color.HSVToColor(hsv); 47 } 48 return result; 49 } 50 } 51