blob: a445208b6cf6870777cd83f8da1a2f54c7dfe0c9 (
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
|
package it.niedermann.owncloud.notes.shared.util;
import androidx.annotation.ColorInt;
import androidx.annotation.Nullable;
import androidx.core.util.Pair;
import java.util.HashMap;
import java.util.Map;
import it.niedermann.android.util.ColorUtil;
public final class NotesColorUtil {
private static final Map<ColorPair, Boolean> CONTRAST_RATIO_SUFFICIENT_CACHE = new HashMap<>();
private NotesColorUtil() {
}
public static boolean contrastRatioIsSufficient(@ColorInt int colorOne, @ColorInt int colorTwo) {
ColorPair key = new ColorPair(colorOne, colorTwo);
Boolean ret = CONTRAST_RATIO_SUFFICIENT_CACHE.get(key);
if (ret == null) {
ret = ColorUtil.INSTANCE.getContrastRatio(colorOne, colorTwo) > 3d;
CONTRAST_RATIO_SUFFICIENT_CACHE.put(key, ret);
return ret;
}
return ret;
}
private static class ColorPair extends Pair<Integer, Integer> {
private ColorPair(@Nullable Integer first, @Nullable Integer second) {
super(first, second);
}
@SuppressWarnings({"EqualsWhichDoesntCheckParameterClass", "NumberEquality"})
@Override
public boolean equals(Object o) {
final ColorPair colorPair = (ColorPair) o;
if (first != colorPair.first) return false;
return second == colorPair.second;
}
@Override
public int hashCode() {
int result = first;
result = 31 * result + second;
return result;
}
}
}
|