mirror of
https://github.com/M66B/FairEmail.git
synced 2026-03-29 21:34:44 +02:00
Added text marking
This commit is contained in:
@@ -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>");
|
||||
}
|
||||
|
||||
@@ -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":
|
||||
|
||||
38
app/src/main/java/eu/faircode/email/MarkSpan.java
Normal file
38
app/src/main/java/eu/faircode/email/MarkSpan.java
Normal 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);
|
||||
}
|
||||
}
|
||||
@@ -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");
|
||||
|
||||
|
||||
Reference in New Issue
Block a user