mirror of https://github.com/M66B/FairEmail.git
Added text marking
This commit is contained in:
parent
7d1ad17d35
commit
c0daddef8c
|
@ -6,6 +6,7 @@
|
|||
|
||||
### 1.1866 - 2022-04-02
|
||||
|
||||
* Added highlighting (marking) of text
|
||||
* Small improvements and minor bug fixes
|
||||
* Updated translations
|
||||
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
|
||||
### 1.1866 - 2022-04-02
|
||||
|
||||
* Added highlighting (marking) of text
|
||||
* Small improvements and minor bug fixes
|
||||
* Updated translations
|
||||
|
||||
|
|
|
@ -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":
|
||||
|
|
|
@ -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");
|
||||
|
||||
|
|
|
@ -0,0 +1,16 @@
|
|||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24"
|
||||
android:tint="?attr/colorControlNormal">
|
||||
<path
|
||||
android:fillColor="@android:color/white"
|
||||
android:pathData="M16.81,8.94l-3.75,-3.75L4,14.25V18h3.75L16.81,8.94zM6,16v-0.92l7.06,-7.06l0.92,0.92L6.92,16H6z"/>
|
||||
<path
|
||||
android:fillColor="@android:color/white"
|
||||
android:pathData="M19.71,6.04c0.39,-0.39 0.39,-1.02 0,-1.41l-2.34,-2.34C17.17,2.09 16.92,2 16.66,2c-0.25,0 -0.51,0.1 -0.7,0.29l-1.83,1.83l3.75,3.75L19.71,6.04z"/>
|
||||
<path
|
||||
android:fillColor="@android:color/white"
|
||||
android:pathData="M2,20h20v4h-20z"/>
|
||||
</vector>
|
|
@ -134,8 +134,17 @@
|
|||
</item>
|
||||
|
||||
<group
|
||||
android:id="@+id/group_style_strikethrough"
|
||||
android:id="@+id/group_style_mark"
|
||||
android:orderInCategory="9">
|
||||
<item
|
||||
android:id="@+id/menu_style_mark"
|
||||
android:icon="@drawable/twotone_border_color_24"
|
||||
android:title="@string/title_style_mark" />
|
||||
</group>
|
||||
|
||||
<group
|
||||
android:id="@+id/group_style_strikethrough"
|
||||
android:orderInCategory="10">
|
||||
<item
|
||||
android:id="@+id/menu_style_strikethrough"
|
||||
android:icon="@drawable/twotone_format_strikethrough_24"
|
||||
|
@ -144,7 +153,7 @@
|
|||
|
||||
<group
|
||||
android:id="@+id/group_style_code"
|
||||
android:orderInCategory="10">
|
||||
android:orderInCategory="11">
|
||||
<item
|
||||
android:id="@+id/menu_style_code"
|
||||
android:icon="@drawable/baseline_code_24"
|
||||
|
@ -153,7 +162,7 @@
|
|||
|
||||
<group
|
||||
android:id="@+id/group_style_clear"
|
||||
android:orderInCategory="11">
|
||||
android:orderInCategory="12">
|
||||
<item
|
||||
android:id="@+id/menu_style_clear"
|
||||
android:icon="@drawable/twotone_format_clear_24"
|
||||
|
|
|
@ -1333,6 +1333,7 @@
|
|||
<string name="title_style_font_default">Default</string>
|
||||
<string name="title_style_blockquote">Block quote</string>
|
||||
<string name="title_style_indentation">Indentation</string>
|
||||
<string name="title_style_mark">Highlight</string>
|
||||
<string name="title_style_strikethrough">Strikethrough</string>
|
||||
<string name="title_style_code" translatable="false">Code</string>
|
||||
<string name="title_style_clear">Clear formatting</string>
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
|
||||
### 1.1866 - 2022-04-02
|
||||
|
||||
* Added highlighting (marking) of text
|
||||
* Small improvements and minor bug fixes
|
||||
* Updated translations
|
||||
|
||||
|
|
Loading…
Reference in New Issue