From a8a5ed99a19144d03b02e56c900f28b86ba3d700 Mon Sep 17 00:00:00 2001 From: M66B Date: Wed, 25 Sep 2019 15:20:27 +0200 Subject: [PATCH] Text colors compatibility for Android < Nougat --- app/src/main/java/eu/faircode/email/HtmlHelper.java | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/eu/faircode/email/HtmlHelper.java b/app/src/main/java/eu/faircode/email/HtmlHelper.java index 02007cb1e9..7ac8910b0c 100644 --- a/app/src/main/java/eu/faircode/email/HtmlHelper.java +++ b/app/src/main/java/eu/faircode/email/HtmlHelper.java @@ -155,7 +155,9 @@ public class HtmlHelper { // Font for (Element font : document.select("font")) { String color = font.attr("color"); - font.removeAttr("color"); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) + font.removeAttr("color"); + font.removeAttr("face"); font.attr("style", "color:" + color + ";"); font.tagName("span"); } @@ -215,6 +217,9 @@ public class HtmlHelper { dark ? MIN_LUMINANCE - lum : lum - (1 - MIN_LUMINANCE)); c = String.format("#%06x", color & 0xFFFFFF); sb.append("color:").append(c).append(";"); + + if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N) + span.attr("color", c); } break; @@ -492,6 +497,11 @@ public class HtmlHelper { for (Element div : document.select("div")) div.tagName("span"); + if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N) + for (Element span : document.select("span")) + if (!TextUtils.isEmpty(span.attr("color"))) + span.tagName("font"); + Element body = document.body(); return (body == null ? "" : body.html()); }