Created
May 14, 2019 03:49
-
-
Save esabook/8b334b757da05b8e8dd6df6913ef589b to your computer and use it in GitHub Desktop.
Get color contrast
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* TODO: modify function for get color contrast based on `background color` and `foreground color` (not black or white only) | |
* based on sensitive eyes (Y of YIQ) {@linkplain "https://en.wikipedia.org/wiki/YIQ"} | |
*/ | |
public static int getContrastColor(int color) { | |
@SuppressLint("Range") | |
double y = (299 * Color.red(color) + 587 * Color.green(color) + 114 * Color.blue(color)) / 1000; | |
return y >= 178 || color == Color.TRANSPARENT ? Color.rgb(130, 130, 130) : Color.WHITE; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment