Experiment: delete translated text

This commit is contained in:
M66B
2022-03-15 09:31:04 +01:00
parent 5d3c26c961
commit ddc5c434b1
2 changed files with 36 additions and 1 deletions

View File

@@ -27,6 +27,8 @@ import android.graphics.Typeface;
import android.os.Build;
import android.text.Editable;
import android.text.Layout;
import android.text.NoCopySpan;
import android.text.Spannable;
import android.text.SpannableStringBuilder;
import android.text.Spanned;
import android.text.TextUtils;
@@ -79,7 +81,8 @@ public class StyleHelper {
QuoteSpan.class, IndentSpan.class,
StrikethroughSpan.class,
URLSpan.class,
TypefaceSpan.class, CustomTypefaceSpan.class
TypefaceSpan.class, CustomTypefaceSpan.class,
TranslatedSpan.class
));
static boolean apply(int action, LifecycleOwner owner, View anchor, EditText etBody, Object... args) {
@@ -925,6 +928,15 @@ public class StyleHelper {
}
}
static void markAsTranslated(Editable text, int start, int end) {
for (TranslatedSpan span : text.getSpans(0, text.length(), TranslatedSpan.class))
text.removeSpan(span);
text.setSpan(new TranslatedSpan(), start, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
}
static class TranslatedSpan implements NoCopySpan {
}
static String getFamily(String family) {
// https://web.mit.edu/jmorzins/www/fonts.html
// https://en.wikipedia.org/wiki/Croscore_fonts