mirror of https://github.com/M66B/FairEmail.git
Parse web colors
This commit is contained in:
parent
e4f896fdf9
commit
e004228529
|
@ -1537,7 +1537,7 @@ public class HtmlHelper {
|
||||||
if (x11ColorMap.containsKey(code)) // workaround
|
if (x11ColorMap.containsKey(code)) // workaround
|
||||||
color = x11ColorMap.get(code);
|
color = x11ColorMap.get(code);
|
||||||
else
|
else
|
||||||
color = Long.decode(c).intValue();
|
color = parseWebColor(code);
|
||||||
}
|
}
|
||||||
} else if (c.startsWith("rgb") || c.startsWith("hsl")) {
|
} else if (c.startsWith("rgb") || c.startsWith("hsl")) {
|
||||||
int s = c.indexOf("(");
|
int s = c.indexOf("(");
|
||||||
|
@ -1567,12 +1567,7 @@ public class HtmlHelper {
|
||||||
} else if (x11ColorMap.containsKey(c))
|
} else if (x11ColorMap.containsKey(c))
|
||||||
color = x11ColorMap.get(c);
|
color = x11ColorMap.get(c);
|
||||||
else
|
else
|
||||||
try {
|
color = parseWebColor(c);
|
||||||
color = Color.parseColor(c);
|
|
||||||
} catch (IllegalArgumentException ex) {
|
|
||||||
// Workaround
|
|
||||||
color = Long.decode("#" + c).intValue();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (BuildConfig.DEBUG)
|
if (BuildConfig.DEBUG)
|
||||||
Log.i("Color " + c + "=" + (color == null ? null : Long.toHexString(color)));
|
Log.i("Color " + c + "=" + (color == null ? null : Long.toHexString(color)));
|
||||||
|
@ -1584,6 +1579,18 @@ public class HtmlHelper {
|
||||||
return color;
|
return color;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static int parseWebColor(String value) {
|
||||||
|
if (value.length() == 3 || value.length() == 6 || value.length() == 8) {
|
||||||
|
if (value.length() == 3)
|
||||||
|
value = "" +
|
||||||
|
value.charAt(0) + value.charAt(0) +
|
||||||
|
value.charAt(1) + value.charAt(1) +
|
||||||
|
value.charAt(2) + value.charAt(2);
|
||||||
|
return (int) Long.parseLong(value, 16);
|
||||||
|
} else
|
||||||
|
throw new IllegalArgumentException("Unknown color=" + value);
|
||||||
|
}
|
||||||
|
|
||||||
private static Integer adjustColor(boolean dark, int textColorPrimary, Integer color) {
|
private static Integer adjustColor(boolean dark, int textColorPrimary, Integer color) {
|
||||||
int r = Color.red(color);
|
int r = Color.red(color);
|
||||||
int g = Color.green(color);
|
int g = Color.green(color);
|
||||||
|
|
Loading…
Reference in New Issue