Computes if the color is considered "dark" - Android Graphics

Android examples for Graphics:Color Darken

Description

Computes if the color is considered "dark"

Demo Code


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

public class Main{
    /**/*w  ww  .  j av  a 2  s .c o m*/
     * Computes if the color is considered "dark"; used to determine if the foreground
     * image (the checkmark) should be white or black.
     * <p/>
     * Based on http://stackoverflow.com/a/24810681/2444312.
     *
     * @return true if the color is "dark"
     */
    public static boolean isColorDark(@ColorInt int color) {
        double brightness = Color.red(color) * 0.299 + Color.green(color)
                * 0.587 + Color.blue(color) * 0.114;
        return brightness < 160;
    }
}

Related Tutorials