|
|
@ -411,9 +411,13 @@ public class LanguageTool {
|
|
|
|
if (suggestions != null)
|
|
|
|
if (suggestions != null)
|
|
|
|
for (LanguageTool.Suggestion suggestion : suggestions) {
|
|
|
|
for (LanguageTool.Suggestion suggestion : suggestions) {
|
|
|
|
Log.i("LT adding=" + suggestion);
|
|
|
|
Log.i("LT adding=" + suggestion);
|
|
|
|
|
|
|
|
int flags = ("Spelling mistake".equals(suggestion.title)
|
|
|
|
|
|
|
|
|| Build.VERSION.SDK_INT < Build.VERSION_CODES.S
|
|
|
|
|
|
|
|
? SuggestionSpan.FLAG_MISSPELLED
|
|
|
|
|
|
|
|
: SuggestionSpan.FLAG_GRAMMAR_ERROR);
|
|
|
|
SuggestionSpan span = new SuggestionSpanEx(etBody.getContext(),
|
|
|
|
SuggestionSpan span = new SuggestionSpanEx(etBody.getContext(),
|
|
|
|
suggestion.replacements.toArray(new String[0]),
|
|
|
|
suggestion.replacements.toArray(new String[0]), flags);
|
|
|
|
SuggestionSpan.FLAG_MISSPELLED);
|
|
|
|
Log.i("MMM " + suggestion.title + ": " + flags);
|
|
|
|
int s = start + suggestion.offset;
|
|
|
|
int s = start + suggestion.offset;
|
|
|
|
int e = s + suggestion.length;
|
|
|
|
int e = s + suggestion.length;
|
|
|
|
if (s < 0 || s > edit.length() || e < 0 || e > edit.length()) {
|
|
|
|
if (s < 0 || s > edit.length() || e < 0 || e > edit.length()) {
|
|
|
@ -461,25 +465,25 @@ public class LanguageTool {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private static class SuggestionSpanEx extends SuggestionSpan {
|
|
|
|
private static class SuggestionSpanEx extends SuggestionSpan {
|
|
|
|
private final int highlightColor;
|
|
|
|
private final int underlineColor;
|
|
|
|
private final int dp3;
|
|
|
|
private final int underlineThickness;
|
|
|
|
|
|
|
|
|
|
|
|
public SuggestionSpanEx(Context context, String[] suggestions, int flags) {
|
|
|
|
public SuggestionSpanEx(Context context, String[] suggestions, int flags) {
|
|
|
|
super(context, suggestions, flags);
|
|
|
|
super(context, suggestions, flags);
|
|
|
|
highlightColor = Helper.resolveColor(context,
|
|
|
|
underlineColor = Helper.resolveColor(context,
|
|
|
|
Build.VERSION.SDK_INT < Build.VERSION_CODES.Q
|
|
|
|
Build.VERSION.SDK_INT < Build.VERSION_CODES.Q
|
|
|
|
? android.R.attr.textColorHighlight
|
|
|
|
? android.R.attr.textColorHighlight
|
|
|
|
: android.R.attr.colorError);
|
|
|
|
: android.R.attr.colorError);
|
|
|
|
dp3 = Helper.dp2pixels(context, 2);
|
|
|
|
underlineThickness = Helper.dp2pixels(context, (getFlags() & FLAG_MISSPELLED) != 0 ? 2 : 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public void updateDrawState(TextPaint tp) {
|
|
|
|
public void updateDrawState(TextPaint tp) {
|
|
|
|
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.Q)
|
|
|
|
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.Q)
|
|
|
|
tp.bgColor = highlightColor;
|
|
|
|
tp.bgColor = underlineColor;
|
|
|
|
else {
|
|
|
|
else {
|
|
|
|
tp.underlineColor = highlightColor;
|
|
|
|
tp.underlineColor = underlineColor;
|
|
|
|
tp.underlineThickness = dp3;
|
|
|
|
tp.underlineThickness = underlineThickness;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|