blob: 7da582b21fb4fc452190be3ca4585da8da894765 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
package it.niedermann.nextcloud.deck;
import android.graphics.Color;
import androidx.annotation.ColorInt;
/**
* Helper implementation to deal with color related functionality.
*/
public final class ColorUtil {
private ColorUtil() {}
public static @ColorInt int getForegroundColorForBackgroundColor(int color) {
if (android.R.color.transparent == color)
return Color.BLACK;
int[] rgb = {Color.red(color), Color.green(color), Color.blue(color)};
int brightness = (int) Math.sqrt(rgb[0] * rgb[0] * .241 + rgb[1]
* rgb[1] * .691 + rgb[2] * rgb[2] * .068);
// light color -> use dark color
if (brightness >= 200) {
return Color.BLACK;
}
return Color.WHITE;
}
}
|