Added support for font display

pull/183/head
M66B 5 years ago
parent 22612c08ce
commit 2ecbe4d3ab

@ -85,7 +85,7 @@ public class FragmentOptions extends FragmentBase {
"subject_top", "font_size_sender", "font_size_subject", "subject_italic", "highlight_subject", "subject_ellipsize",
"keywords_header", "labels_header", "flags", "flags_background", "preview", "preview_italic", "preview_lines",
"addresses", "attachments_alt",
"contrast", "monospaced", "text_color", "text_size",
"contrast", "monospaced", "text_color", "text_size", "text_font", "text_align",
"inline_images", "collapse_quotes", "seekbar", "actionbar", "actionbar_color", "navbar_colorize",
"autoscroll", "swipenav", "autoexpand", "autoclose", "onclose",
"language_detection",

@ -108,6 +108,7 @@ public class FragmentOptionsDisplay extends FragmentBase implements SharedPrefer
private SwitchCompat swMonospaced;
private SwitchCompat swTextColor;
private SwitchCompat swTextSize;
private SwitchCompat swTextFont;
private SwitchCompat swTextAlign;
private SwitchCompat swCollapseQuotes;
private SwitchCompat swImagesInline;
@ -126,7 +127,7 @@ public class FragmentOptionsDisplay extends FragmentBase implements SharedPrefer
"keywords_header", "labels_header", "flags", "flags_background",
"preview", "preview_italic", "preview_lines",
"addresses",
"contrast", "monospaced", "text_color", "text_size", "text_align",
"contrast", "monospaced", "text_color", "text_size", "text_font", "text_align",
"inline_images", "collapse_quotes", "attachments_alt",
"parse_classes", "authentication"
};
@ -192,6 +193,7 @@ public class FragmentOptionsDisplay extends FragmentBase implements SharedPrefer
swMonospaced = view.findViewById(R.id.swMonospaced);
swTextColor = view.findViewById(R.id.swTextColor);
swTextSize = view.findViewById(R.id.swTextSize);
swTextFont = view.findViewById(R.id.swTextFont);
swTextAlign = view.findViewById(R.id.swTextAlign);
swCollapseQuotes = view.findViewById(R.id.swCollapseQuotes);
swImagesInline = view.findViewById(R.id.swImagesInline);
@ -615,6 +617,13 @@ public class FragmentOptionsDisplay extends FragmentBase implements SharedPrefer
}
});
swTextFont.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
prefs.edit().putBoolean("text_font", checked).apply();
}
});
swTextAlign.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
@ -798,6 +807,7 @@ public class FragmentOptionsDisplay extends FragmentBase implements SharedPrefer
swMonospaced.setChecked(prefs.getBoolean("monospaced", false));
swTextColor.setChecked(prefs.getBoolean("text_color", true));
swTextSize.setChecked(prefs.getBoolean("text_size", true));
swTextFont.setChecked(prefs.getBoolean("text_font", true));
swTextAlign.setChecked(prefs.getBoolean("text_align", true));
swCollapseQuotes.setChecked(prefs.getBoolean("collapse_quotes", false));
swImagesInline.setChecked(prefs.getBoolean("inline_images", false));

@ -319,6 +319,7 @@ public class HtmlHelper {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
boolean text_color = prefs.getBoolean("text_color", true);
boolean text_size = prefs.getBoolean("text_size", true);
boolean text_font = prefs.getBoolean("text_font", true);
boolean text_align = prefs.getBoolean("text_align", true);
boolean display_hidden = prefs.getBoolean("display_hidden", false);
boolean disable_tracking = prefs.getBoolean("disable_tracking", true);
@ -448,7 +449,6 @@ public class HtmlHelper {
.addTags("hr", "abbr", "big", "font", "dfn", "del", "s", "tt")
.addAttributes(":all", "class")
.addAttributes(":all", "style")
.addAttributes("font", "size")
.addAttributes("div", "x-plain")
.removeTags("col", "colgroup", "thead", "tbody")
.removeAttributes("table", "width")
@ -460,6 +460,10 @@ public class HtmlHelper {
.addProtocols("a", "href", "full", "xmpp", "geo", "tel");
if (text_color)
whitelist.addAttributes("font", "color");
if (text_size)
whitelist.addAttributes("font", "size");
if (text_font)
whitelist.addAttributes("font", "face");
if (text_align)
whitelist.addTags("center").addAttributes(":all", "align");
if (!view)
@ -475,6 +479,7 @@ public class HtmlHelper {
String style = font.attr("style");
String color = font.attr("color");
String size = font.attr("size");
String face = font.attr("face");
style = style.trim();
if (!TextUtils.isEmpty(style) && !style.endsWith(";"))
@ -482,6 +487,7 @@ public class HtmlHelper {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N)
font.removeAttr("color");
font.removeAttr("size");
font.removeAttr("face");
StringBuilder sb = new StringBuilder(style);
@ -503,6 +509,9 @@ public class HtmlHelper {
}
}
if (!TextUtils.isEmpty(face))
sb.append("font-family:").append(face).append(";");
font.attr("style", sb.toString());
font.tagName("span");
@ -600,6 +609,14 @@ public class HtmlHelper {
}
break;
case "font-family":
if (!text_font)
continue;
// https://developer.mozilla.org/en-US/docs/Web/CSS/font-family
sb.append(key).append(":").append(value).append(";");
break;
case "text-decoration":
// https://developer.mozilla.org/en-US/docs/Web/CSS/text-decoration
if (value.contains("line-through"))
@ -1975,6 +1992,9 @@ public class HtmlHelper {
Log.i(ex);
}
break;
case "font-family":
ssb.setSpan(new TypefaceSpan(value), start, ssb.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
break;
case "text-decoration":
if ("line-through".equals(value))
ssb.setSpan(new StrikethroughSpan(), start, ssb.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);

@ -833,6 +833,18 @@
app:layout_constraintTop_toBottomOf="@id/swTextColor"
app:switchPadding="12dp" />
<androidx.appcompat.widget.SwitchCompat
android:id="@+id/swTextFont"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:enabled="true"
android:text="@string/title_advanced_text_font"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/swTextSize"
app:switchPadding="12dp" />
<androidx.appcompat.widget.SwitchCompat
android:id="@+id/swTextAlign"
android:layout_width="0dp"
@ -842,7 +854,7 @@
android:text="@string/title_advanced_text_align"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/swTextSize"
app:layout_constraintTop_toBottomOf="@id/swTextFont"
app:switchPadding="12dp" />
<androidx.appcompat.widget.SwitchCompat

@ -356,10 +356,11 @@
<string name="title_advanced_addresses">Expand address details by default</string>
<string name="title_advanced_attachments_alt">Show attachments after the message text</string>
<string name="title_advanced_contrast">Use high contrast for message text</string>
<string name="title_advanced_monospaced">Use monospaced font for message text</string>
<string name="title_advanced_text_color">Show text colors</string>
<string name="title_advanced_text_size">Show small and large texts</string>
<string name="title_advanced_text_align">Show left/center/right aligned texts</string>
<string name="title_advanced_monospaced">Use monospaced font for message text by default</string>
<string name="title_advanced_text_color">Use text colors</string>
<string name="title_advanced_text_size">Use text sizes</string>
<string name="title_advanced_text_font">Use fonts</string>
<string name="title_advanced_text_align">Use text alignment</string>
<string name="title_advanced_collapse_quotes">Collapse quoted text</string>
<string name="title_advanced_images_inline">Automatically show inline images</string>
<string name="title_advanced_seekbar">Show relative conversation position with a dot</string>

Loading…
Cancel
Save