package net.tasksnow.util;
import android.graphics.Color;
/**
* @author D056943
* @since 16:38:57 - 19.12.2012
* @project cFoldersDemo
*/
public class ColorUtil {
// ===========================================================
// Constants
// ===========================================================
private static final int BRIGHTNESS_THRESHOLD = 130;
private static float colorDiff = 0.18f;
// ===========================================================
// Constructors
// ===========================================================
private ColorUtil() {
}
// ===========================================================
// Methods
// ===========================================================
/**
* Calculate whether a color is light or dark, based on a commonly known
* brightness formula.
*
* @see {@literal http://en.wikipedia.org/wiki/HSV_color_space%23Lightness}
*/
public static boolean isColorDark(int color) {
return (((30 * Color.red(color)) + (59 * Color.green(color)) + (11 * Color.blue(color))) / 100) <= BRIGHTNESS_THRESHOLD;
}
public static int darkerColor(int color) {
return changeColor(color, 1f - colorDiff);
}
public static int lighterColor(int color) {
return changeColor(color, 1f + colorDiff);
}
public static int changeColor(int color, float multiplier) {
int red = Color.red(color);
int blue = Color.blue(color);
int green = Color.green(color);
return Color.rgb((int) (red * multiplier), (int) (green * multiplier), (int) (blue * multiplier));
}
public static int setAlpha(int color, int alpha) {
int red = Color.red(color);
int blue = Color.blue(color);
int green = Color.green(color);
return Color.argb(alpha, red, green, blue);
}
}