contrastingForeground static method
Get a contrasting foreground color (black or white) for a background. Uses WCAG relative luminance formula.
Implementation
static int contrastingForeground(int color) {
final double luminance = relativeLuminance(color);
// Use white text on dark backgrounds, black on light
return luminance > 0.179 ? 0xFF000000 : 0xFFffffff;
}