Small improvement

pull/209/head
M66B 2 years ago
parent aa52334145
commit 9ba931a356

@ -170,24 +170,23 @@ public class LanguageTool {
Editable edit = etBody.getText(); Editable edit = etBody.getText();
if (edit == null) if (edit == null)
return; return;
if (suggestions == null)
return;
// https://developer.android.com/reference/android/text/style/SuggestionSpan // https://developer.android.com/reference/android/text/style/SuggestionSpan
for (SuggestionSpanEx span : edit.getSpans(0, edit.length(), SuggestionSpanEx.class)) { for (SuggestionSpanEx suggestion : edit.getSpans(0, edit.length(), SuggestionSpanEx.class)) {
Log.i("LT removing=" + span); Log.i("LT removing=" + suggestion);
edit.removeSpan(span); edit.removeSpan(suggestion);
} }
for (LanguageTool.Suggestion suggestion : suggestions) { if (suggestions != null)
Log.i("LT adding=" + suggestion); for (LanguageTool.Suggestion suggestion : suggestions) {
SuggestionSpan span = new SuggestionSpanEx(etBody.getContext(), Log.i("LT adding=" + suggestion);
suggestion.replacements.toArray(new String[0]), SuggestionSpan span = new SuggestionSpanEx(etBody.getContext(),
SuggestionSpan.FLAG_MISSPELLED); suggestion.replacements.toArray(new String[0]),
int start = suggestion.offset; SuggestionSpan.FLAG_MISSPELLED);
int end = start + suggestion.length; int start = suggestion.offset;
edit.setSpan(span, start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); int end = start + suggestion.length;
} edit.setSpan(span, start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
}
} }
static class Suggestion { static class Suggestion {

Loading…
Cancel
Save