Refactoring

This commit is contained in:
M66B 2022-05-04 11:30:00 +02:00
parent df7ddc32ce
commit 09b8e26974
4 changed files with 20 additions and 43 deletions

View File

@ -392,7 +392,7 @@ public class HtmlEx {
if (style[j] instanceof UnderlineSpan) {
out.append("<u>");
}
if (style[j] instanceof MarkSpan) {
if (style[j] instanceof StyleHelper.MarkSpan) {
out.append("<mark>");
}
if (style[j] instanceof StrikethroughSpan) {
@ -444,7 +444,7 @@ public class HtmlEx {
out.append(String.format("<span style=\"color:%s;\">",
eu.faircode.email.HtmlHelper.encodeWebColor(color)));
}
if (style[j] instanceof BackgroundColorSpan && !(style[j] instanceof MarkSpan)) {
if (style[j] instanceof BackgroundColorSpan && !(style[j] instanceof StyleHelper.MarkSpan)) {
int color = ((BackgroundColorSpan) style[j]).getBackgroundColor();
//out.append(String.format("<span style=\"background-color:#%06X;\">",
// 0xFFFFFF & color));
@ -456,7 +456,7 @@ public class HtmlEx {
withinStyle(out, text, i, next);
for (int j = style.length - 1; j >= 0; j--) {
if (style[j] instanceof BackgroundColorSpan && !(style[j] instanceof MarkSpan)) {
if (style[j] instanceof BackgroundColorSpan && !(style[j] instanceof StyleHelper.MarkSpan)) {
out.append("</span>");
}
if (style[j] instanceof ForegroundColorSpan) {
@ -474,7 +474,7 @@ public class HtmlEx {
if (style[j] instanceof StrikethroughSpan) {
out.append("</span>");
}
if (style[j] instanceof MarkSpan) {
if (style[j] instanceof StyleHelper.MarkSpan) {
out.append("</mark>");
}
if (style[j] instanceof UnderlineSpan) {

View File

@ -3409,7 +3409,7 @@ public class HtmlHelper {
break;
case "mark":
setSpan(ssb, new MarkSpan(), start, ssb.length());
setSpan(ssb, new StyleHelper.MarkSpan(), start, ssb.length());
break;
case "pre":
case "tt":

View File

@ -1,38 +0,0 @@
package eu.faircode.email;
/*
This file is part of FairEmail.
FairEmail is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
FairEmail is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with FairEmail. If not, see <http://www.gnu.org/licenses/>.
Copyright 2018-2022 by Marcel Bokhorst (M66B)
*/
import android.graphics.Color;
import android.text.TextPaint;
import android.text.style.BackgroundColorSpan;
import androidx.annotation.NonNull;
public class MarkSpan extends BackgroundColorSpan {
public MarkSpan() {
super(Color.YELLOW);
}
@Override
public void updateDrawState(@NonNull TextPaint textPaint) {
super.updateDrawState(textPaint);
textPaint.setColor(Color.BLACK);
}
}

View File

@ -23,6 +23,7 @@ import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.Color;
import android.graphics.Typeface;
import android.os.Build;
import android.text.Editable;
@ -31,6 +32,7 @@ import android.text.NoCopySpan;
import android.text.Spannable;
import android.text.SpannableStringBuilder;
import android.text.Spanned;
import android.text.TextPaint;
import android.text.TextUtils;
import android.text.style.AlignmentSpan;
import android.text.style.BackgroundColorSpan;
@ -82,6 +84,7 @@ public class StyleHelper {
StrikethroughSpan.class,
URLSpan.class,
TypefaceSpan.class, CustomTypefaceSpan.class,
MarkSpan.class,
InsertedSpan.class
));
@ -966,6 +969,18 @@ public class StyleHelper {
static class InsertedSpan implements NoCopySpan {
}
static class MarkSpan extends BackgroundColorSpan {
public MarkSpan() {
super(Color.YELLOW);
}
@Override
public void updateDrawState(@NonNull TextPaint textPaint) {
super.updateDrawState(textPaint);
textPaint.setColor(Color.BLACK);
}
}
static String getFamily(String family) {
// https://web.mit.edu/jmorzins/www/fonts.html
// https://en.wikipedia.org/wiki/Croscore_fonts