mirror of https://github.com/M66B/FairEmail.git
LanguageTool improvements
This commit is contained in:
parent
472ea58740
commit
fe2ee9d68c
|
@ -71,6 +71,7 @@ import android.text.Html;
|
||||||
import android.text.Spannable;
|
import android.text.Spannable;
|
||||||
import android.text.SpannableStringBuilder;
|
import android.text.SpannableStringBuilder;
|
||||||
import android.text.Spanned;
|
import android.text.Spanned;
|
||||||
|
import android.text.TextPaint;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
import android.text.TextWatcher;
|
import android.text.TextWatcher;
|
||||||
import android.text.method.ArrowKeyMovementMethod;
|
import android.text.method.ArrowKeyMovementMethod;
|
||||||
|
@ -2392,17 +2393,25 @@ public class FragmentCompose extends FragmentBase {
|
||||||
private void onLanguageTool() {
|
private void onLanguageTool() {
|
||||||
etBody.clearComposingText();
|
etBody.clearComposingText();
|
||||||
|
|
||||||
|
Log.i("LT running enabled=" + etBody.isSuggestionsEnabled());
|
||||||
|
|
||||||
Bundle args = new Bundle();
|
Bundle args = new Bundle();
|
||||||
args.putCharSequence("text", etBody.getText());
|
args.putCharSequence("text", etBody.getText());
|
||||||
|
|
||||||
new SimpleTask<List<LanguageTool.Suggestion>>() {
|
new SimpleTask<List<LanguageTool.Suggestion>>() {
|
||||||
|
private Toast toast = null;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onPreExecute(Bundle args) {
|
protected void onPreExecute(Bundle args) {
|
||||||
|
toast = ToastEx.makeText(getContext(), R.string.title_suggestions_check, Toast.LENGTH_LONG);
|
||||||
|
toast.show();
|
||||||
setBusy(true);
|
setBusy(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onPostExecute(Bundle args) {
|
protected void onPostExecute(Bundle args) {
|
||||||
|
if (toast != null)
|
||||||
|
toast.cancel();
|
||||||
setBusy(false);
|
setBusy(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2414,18 +2423,29 @@ public class FragmentCompose extends FragmentBase {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onExecuted(Bundle args, List<LanguageTool.Suggestion> suggestions) {
|
protected void onExecuted(Bundle args, List<LanguageTool.Suggestion> suggestions) {
|
||||||
// https://developer.android.com/reference/android/text/style/SuggestionSpan
|
if (suggestions == null || suggestions.size() == 0) {
|
||||||
final Context context = getContext();
|
ToastEx.makeText(getContext(), R.string.title_suggestions_none, Toast.LENGTH_LONG).show();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
Editable edit = etBody.getText();
|
Editable edit = etBody.getText();
|
||||||
|
if (edit == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
// https://developer.android.com/reference/android/text/style/SuggestionSpan
|
||||||
|
for (SuggestionSpanEx span : edit.getSpans(0, edit.length(), SuggestionSpanEx.class)) {
|
||||||
|
Log.i("LT removing=" + span);
|
||||||
|
edit.removeSpan(span);
|
||||||
|
}
|
||||||
|
|
||||||
for (LanguageTool.Suggestion suggestion : suggestions) {
|
for (LanguageTool.Suggestion suggestion : suggestions) {
|
||||||
Log.i("LT suggestion=" + suggestion);
|
Log.i("LT adding=" + suggestion);
|
||||||
SuggestionSpan span = new SuggestionSpan(context,
|
SuggestionSpan span = new SuggestionSpanEx(getContext(),
|
||||||
suggestion.replacements.toArray(new String[0]),
|
suggestion.replacements.toArray(new String[0]),
|
||||||
SuggestionSpan.FLAG_MISSPELLED);
|
SuggestionSpan.FLAG_MISSPELLED);
|
||||||
int start = suggestion.offset;
|
int start = suggestion.offset;
|
||||||
int end = start + suggestion.length;
|
int end = start + suggestion.length;
|
||||||
edit.setSpan(span, start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE | Spanned.SPAN_COMPOSING);
|
edit.setSpan(span, start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2437,6 +2457,20 @@ public class FragmentCompose extends FragmentBase {
|
||||||
}.execute(this, args, "compose:lt");
|
}.execute(this, args, "compose:lt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static class SuggestionSpanEx extends SuggestionSpan {
|
||||||
|
private final int textColorHighlight;
|
||||||
|
|
||||||
|
public SuggestionSpanEx(Context context, String[] suggestions, int flags) {
|
||||||
|
super(context, suggestions, flags);
|
||||||
|
textColorHighlight = Helper.resolveColor(context, android.R.attr.textColorHighlight);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void updateDrawState(TextPaint tp) {
|
||||||
|
tp.bgColor = textColorHighlight;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private boolean onActionStyle(int action, View anchor) {
|
private boolean onActionStyle(int action, View anchor) {
|
||||||
Log.i("Style action=" + action);
|
Log.i("Style action=" + action);
|
||||||
return StyleHelper.apply(action, getViewLifecycleOwner(), anchor, etBody);
|
return StyleHelper.apply(action, getViewLifecycleOwner(), anchor, etBody);
|
||||||
|
|
|
@ -1387,6 +1387,8 @@
|
||||||
<string name="title_translate_html_hint">This will consume more characters</string>
|
<string name="title_translate_html_hint">This will consume more characters</string>
|
||||||
<string name="title_translate_usage">Usage: %1$s / %2$s (%3$d %%)</string>
|
<string name="title_translate_usage">Usage: %1$s / %2$s (%3$d %%)</string>
|
||||||
<string name="title_translate_tap">Tap the text to be translated</string>
|
<string name="title_translate_tap">Tap the text to be translated</string>
|
||||||
|
<string name="title_suggestions_check">Checking …</string>
|
||||||
|
<string name="title_suggestions_none">No suggestions</string>
|
||||||
<string name="title_edit_plain_text">Edit as plain text</string>
|
<string name="title_edit_plain_text">Edit as plain text</string>
|
||||||
<string name="title_edit_formatted_text">Edit as reformatted text</string>
|
<string name="title_edit_formatted_text">Edit as reformatted text</string>
|
||||||
<string name="title_select_certificate">Select public key</string>
|
<string name="title_select_certificate">Select public key</string>
|
||||||
|
|
Loading…
Reference in New Issue