Added text marking

This commit is contained in:
M66B
2022-04-04 09:13:38 +02:00
parent 7d1ad17d35
commit c0daddef8c
10 changed files with 107 additions and 7 deletions

View File

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

View File

@@ -2910,7 +2910,6 @@ public class HtmlHelper {
final int colorPrimary = Helper.resolveColor(context, R.attr.colorPrimary);
final int colorAccent = Helper.resolveColor(context, R.attr.colorAccent);
final int colorHighlight = Helper.resolveColor(context, R.attr.colorHighlight);
final int colorBlockquote = Helper.resolveColor(context, R.attr.colorBlockquote, colorPrimary);
final int colorSeparator = Helper.resolveColor(context, R.attr.colorSeparator);
int bulletGap = context.getResources().getDimensionPixelSize(R.dimen.bullet_gap_size);
@@ -3375,7 +3374,7 @@ public class HtmlHelper {
break;
case "mark":
setSpan(ssb, new BackgroundColorSpan(colorHighlight), start, ssb.length());
setSpan(ssb, new MarkSpan(), start, ssb.length());
break;
case "pre":
case "tt":

View File

@@ -0,0 +1,38 @@
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

@@ -228,6 +228,8 @@ public class StyleHelper {
return setBlockQuote(item);
} else if (groupId == R.id.group_style_indentation) {
return setIndentation(item);
} else if (groupId == R.id.group_style_mark) {
return setMark(item);
} else if (groupId == R.id.group_style_strikethrough) {
return setStrikeThrough(item);
} else if (groupId == R.id.group_style_code) {
@@ -609,6 +611,32 @@ public class StyleHelper {
return true;
}
private boolean setMark(MenuItem item) {
Log.breadcrumb("style", "action", "strike");
Context context = etBody.getContext();
boolean has = false;
MarkSpan[] spans = edit.getSpans(start, end, MarkSpan.class);
for (MarkSpan span : spans) {
int s = edit.getSpanStart(span);
int e = edit.getSpanEnd(span);
int f = edit.getSpanFlags(span);
edit.removeSpan(span);
if (splitSpan(edit, start, end, s, e, f, true,
new MarkSpan(), new MarkSpan()))
has = true;
}
if (!has)
edit.setSpan(new MarkSpan(), start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
etBody.setText(edit);
etBody.setSelection(end);
return true;
}
private boolean setStrikeThrough(MenuItem item) {
Log.breadcrumb("style", "action", "strike");