diff --git a/app/src/main/java/eu/faircode/email/FragmentOptions.java b/app/src/main/java/eu/faircode/email/FragmentOptions.java
index 5a1ab9af32..5212402c17 100644
--- a/app/src/main/java/eu/faircode/email/FragmentOptions.java
+++ b/app/src/main/java/eu/faircode/email/FragmentOptions.java
@@ -124,7 +124,7 @@ public class FragmentOptions extends FragmentBase {
"keywords_header", "labels_header", "flags", "flags_background", "preview", "preview_italic", "preview_lines",
"message_zoom", "overview_mode", "addresses", "button_extra", "attachments_alt", "thumbnails",
"contrast", "monospaced", "monospaced_pre",
- "text_color", "text_size", "text_font", "text_align", "text_separators",
+ "background_color", "text_color", "text_size", "text_font", "text_align", "text_separators",
"collapse_quotes", "image_placeholders", "inline_images",
"seekbar", "actionbar", "actionbar_color", "navbar_colorize",
"autoscroll", "swipenav", "swipe_close", "swipe_move", "autoexpand", "autoclose", "onclose",
diff --git a/app/src/main/java/eu/faircode/email/FragmentOptionsDisplay.java b/app/src/main/java/eu/faircode/email/FragmentOptionsDisplay.java
index 7884e68a6d..1931d17819 100644
--- a/app/src/main/java/eu/faircode/email/FragmentOptionsDisplay.java
+++ b/app/src/main/java/eu/faircode/email/FragmentOptionsDisplay.java
@@ -127,6 +127,7 @@ public class FragmentOptionsDisplay extends FragmentBase implements SharedPrefer
private SwitchCompat swContrast;
private SwitchCompat swMonospaced;
private SwitchCompat swMonospacedPre;
+ private SwitchCompat swBackgroundColor;
private SwitchCompat swTextColor;
private SwitchCompat swTextSize;
private SwitchCompat swTextFont;
@@ -158,7 +159,7 @@ public class FragmentOptionsDisplay extends FragmentBase implements SharedPrefer
"preview", "preview_italic", "preview_lines",
"addresses",
"message_zoom", "overview_mode", "contrast", "monospaced", "monospaced_pre",
- "text_color", "text_size", "text_font", "text_align", "text_separators",
+ "background_color", "text_color", "text_size", "text_font", "text_align", "text_separators",
"collapse_quotes", "image_placeholders", "inline_images", "button_extra", "attachments_alt", "thumbnails",
"parse_classes", "authentication"
};
@@ -238,6 +239,7 @@ public class FragmentOptionsDisplay extends FragmentBase implements SharedPrefer
swContrast = view.findViewById(R.id.swContrast);
swMonospaced = view.findViewById(R.id.swMonospaced);
swMonospacedPre = view.findViewById(R.id.swMonospacedPre);
+ swBackgroundColor = view.findViewById(R.id.swBackgroundColor);
swTextColor = view.findViewById(R.id.swTextColor);
swTextSize = view.findViewById(R.id.swTextSize);
swTextFont = view.findViewById(R.id.swTextFont);
@@ -799,6 +801,18 @@ public class FragmentOptionsDisplay extends FragmentBase implements SharedPrefer
}
});
+ String theme = prefs.getString("theme", "blue_orange_system");
+ boolean bw = "black_and_white".equals(theme);
+
+ swBackgroundColor.setEnabled(!bw);
+ swBackgroundColor.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
+ @Override
+ public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
+ prefs.edit().putBoolean("background_color", checked).apply();
+ }
+ });
+
+ swTextColor.setEnabled(!bw);
swTextColor.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
@@ -806,9 +820,6 @@ public class FragmentOptionsDisplay extends FragmentBase implements SharedPrefer
}
});
- String theme = prefs.getString("theme", "blue_orange_system");
- swTextColor.setEnabled(!"black_and_white".equals(theme));
-
swTextSize.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
@@ -1061,6 +1072,7 @@ public class FragmentOptionsDisplay extends FragmentBase implements SharedPrefer
swContrast.setChecked(prefs.getBoolean("contrast", false));
swMonospaced.setChecked(prefs.getBoolean("monospaced", false));
swMonospacedPre.setChecked(prefs.getBoolean("monospaced_pre", false));
+ swBackgroundColor.setChecked(prefs.getBoolean("background_color", false));
swTextColor.setChecked(prefs.getBoolean("text_color", true));
swTextSize.setChecked(prefs.getBoolean("text_size", true));
swTextFont.setChecked(prefs.getBoolean("text_font", true));
diff --git a/app/src/main/java/eu/faircode/email/HtmlHelper.java b/app/src/main/java/eu/faircode/email/HtmlHelper.java
index 0440aa661e..95dc74af83 100644
--- a/app/src/main/java/eu/faircode/email/HtmlHelper.java
+++ b/app/src/main/java/eu/faircode/email/HtmlHelper.java
@@ -36,7 +36,9 @@ import android.text.Spanned;
import android.text.TextDirectionHeuristics;
import android.text.TextUtils;
import android.text.style.AlignmentSpan;
+import android.text.style.BackgroundColorSpan;
import android.text.style.BulletSpan;
+import android.text.style.CharacterStyle;
import android.text.style.ClickableSpan;
import android.text.style.ForegroundColorSpan;
import android.text.style.ImageSpan;
@@ -357,7 +359,9 @@ public class HtmlHelper {
private static Document sanitize(Context context, Document parsed, boolean view, boolean show_images) {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
String theme = prefs.getString("theme", "blue_orange_system");
- boolean text_color = (!view || (prefs.getBoolean("text_color", true) && !"black_and_white".equals(theme)));
+ boolean bw = "black_and_white".equals(theme);
+ boolean background_color = (!view || (!bw && prefs.getBoolean("background_color", false)));
+ boolean text_color = (!view || (!bw && prefs.getBoolean("text_color", true)));
boolean text_size = (!view || prefs.getBoolean("text_size", true));
boolean text_font = (!view || prefs.getBoolean("text_font", true));
boolean text_align = prefs.getBoolean("text_align", true);
@@ -368,8 +372,6 @@ public class HtmlHelper {
boolean text_separators = prefs.getBoolean("text_separators", true);
boolean image_placeholders = prefs.getBoolean("image_placeholders", true);
- int textColorPrimary = Helper.resolveColor(context, android.R.attr.textColorPrimary);
-
// https://chromium.googlesource.com/chromium/blink/+/master/Source/core/css/html.css
// ...
@@ -575,31 +577,37 @@ public class HtmlHelper {
String value = kv.get(key);
switch (key) {
case "color":
+ case "background-color":
// https://developer.mozilla.org/en-US/docs/Web/CSS/color
- if (!text_color)
+ if ("color".equals(key) && !text_color)
+ continue;
+ if ("background-color".equals(key) && !background_color)
continue;
Integer color = parseColor(value);
- if (color != null && !view && Helper.isDarkTheme(context)) {
+ if (color != null && !view && dark) {
float lum = (float) ColorUtils.calculateLuminance(color);
if (lum < 0.1f)
color = null;
}
- if (color == null)
- element.removeAttr("color");
- else {
- if (view)
- color = adjustColor(dark, textColorPrimary, color);
+ if (color != null && view)
+ if ("color".equals(key))
+ color = adjustColor(dark, color);
+ else
+ color = adjustColor(!dark, color);
- // fromHtml does not support transparency
- String c = String.format("#%06x", color);
- sb.append("color:").append(c).append(";");
- if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N)
- element.attr("color", c);
+ if (color == null) {
+ element.removeAttr(key);
+ continue;
}
+ // fromHtml does not support transparency
+ String c = String.format("#%06x", color);
+ sb.append(key).append(':').append(c).append(";");
+ if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N)
+ element.attr(key, c);
break;
case "font-size":
@@ -1549,15 +1557,14 @@ public class HtmlHelper {
return color;
}
- private static Integer adjustColor(boolean dark, int textColorPrimary, Integer color) {
+ private static Integer adjustColor(boolean dark, Integer color) {
int r = Color.red(color);
int g = Color.green(color);
int b = Color.blue(color);
if (r == g && r == b && (dark ? 255 - r : r) < GRAY_THRESHOLD)
- color = textColorPrimary;
- else
- color = Helper.adjustLuminance(color, dark, MIN_LUMINANCE);
+ return null;
+ color = Helper.adjustLuminance(color, dark, MIN_LUMINANCE);
return (color & 0xFFFFFF);
}
@@ -2347,10 +2354,16 @@ public class HtmlHelper {
String value = param.substring(semi + 1);
switch (key) {
case "color":
+ case "background-color":
if (!TextUtils.isEmpty(value))
try {
int color = Integer.parseInt(value.substring(1), 16) | 0xFF000000;
- setSpan(ssb, new ForegroundColorSpan(color), start, ssb.length());
+ CharacterStyle span;
+ if ("color".equals(key))
+ span = new ForegroundColorSpan(color);
+ else
+ span = new BackgroundColorSpan(color);
+ setSpan(ssb, span, start, ssb.length());
} catch (NumberFormatException ex) {
Log.i(ex);
}
diff --git a/app/src/main/res/layout/fragment_options_display.xml b/app/src/main/res/layout/fragment_options_display.xml
index 553180bcf4..946a8bbc71 100644
--- a/app/src/main/res/layout/fragment_options_display.xml
+++ b/app/src/main/res/layout/fragment_options_display.xml
@@ -1129,6 +1129,18 @@
app:layout_constraintTop_toBottomOf="@id/swMonospaced"
app:switchPadding="12dp" />
+
+
Use high contrast for message text
Use monospaced font for message text by default
Use monospaced font for preformatted text
+ Use background colors
Use text colors
Use text sizes
Use fonts