use of android.text.style.SuggestionSpan in project XobotOS by xamarin.
the class EditableInputConnection method commitText.
@Override
public boolean commitText(CharSequence text, int newCursorPosition) {
if (mTextView == null) {
return super.commitText(text, newCursorPosition);
}
if (text instanceof Spanned) {
Spanned spanned = ((Spanned) text);
SuggestionSpan[] spans = spanned.getSpans(0, text.length(), SuggestionSpan.class);
mIMM.registerSuggestionSpansForNotification(spans);
}
mTextView.resetErrorChangedFlag();
boolean success = super.commitText(text, newCursorPosition);
mTextView.hideErrorIfUnchanged();
return success;
}
use of android.text.style.SuggestionSpan in project XobotOS by xamarin.
the class TextView method removeSuggestionSpans.
/**
* Removes the suggestion spans.
*/
CharSequence removeSuggestionSpans(CharSequence text) {
if (text instanceof Spanned) {
Spannable spannable;
if (text instanceof Spannable) {
spannable = (Spannable) text;
} else {
spannable = new SpannableString(text);
text = spannable;
}
SuggestionSpan[] spans = spannable.getSpans(0, text.length(), SuggestionSpan.class);
for (int i = 0; i < spans.length; i++) {
spannable.removeSpan(spans[i]);
}
}
return text;
}
use of android.text.style.SuggestionSpan in project XobotOS by xamarin.
the class TextView method downgradeEasyCorrectionSpans.
/**
* Downgrades to simple suggestions all the easy correction spans that are not a spell check
* span.
*/
private void downgradeEasyCorrectionSpans() {
if (mText instanceof Spannable) {
Spannable spannable = (Spannable) mText;
SuggestionSpan[] suggestionSpans = spannable.getSpans(0, spannable.length(), SuggestionSpan.class);
for (int i = 0; i < suggestionSpans.length; i++) {
int flags = suggestionSpans[i].getFlags();
if ((flags & SuggestionSpan.FLAG_EASY_CORRECT) != 0 && (flags & SuggestionSpan.FLAG_MISSPELLED) == 0) {
flags &= ~SuggestionSpan.FLAG_EASY_CORRECT;
suggestionSpans[i].setFlags(flags);
}
}
}
}
use of android.text.style.SuggestionSpan in project android_frameworks_base by AOSPA.
the class SuggestionsPopupWindowTest method testSelectionActionMode.
@SmallTest
public void testSelectionActionMode() {
final String text = "abc def ghi";
onView(withId(R.id.textview)).perform(click());
onView(withId(R.id.textview)).perform(replaceText(text));
final SuggestionSpan suggestionSpan = new SuggestionSpan(getActivity(), new String[] { "DEF", "Def" }, SuggestionSpan.FLAG_AUTO_CORRECTION);
setSuggestionSpan(suggestionSpan, text.indexOf('d'), text.indexOf('f') + 1);
onView(withId(R.id.textview)).perform(longPressOnTextAtIndex(text.indexOf('e')));
sleepForFloatingToolbarPopup();
assertFloatingToolbarContainsItem(getActivity().getString(com.android.internal.R.string.replace));
sleepForFloatingToolbarPopup();
clickFloatingToolbarItem(getActivity().getString(com.android.internal.R.string.replace));
assertSuggestionsPopupIsDisplayed();
}
use of android.text.style.SuggestionSpan in project android_frameworks_base by AOSPA.
the class SuggestionsPopupWindowTest method testSuggestionItems.
@SmallTest
public void testSuggestionItems() {
final String text = "abc def ghi";
onView(withId(R.id.textview)).perform(click());
onView(withId(R.id.textview)).perform(replaceText(text));
final SuggestionSpan suggestionSpan = new SuggestionSpan(getActivity(), new String[] { "DEF", "Def" }, SuggestionSpan.FLAG_AUTO_CORRECTION);
setSuggestionSpan(suggestionSpan, text.indexOf('d'), text.indexOf('f') + 1);
showSuggestionsPopup();
assertSuggestionsPopupIsDisplayed();
assertSuggestionsPopupContainsItem("DEF");
assertSuggestionsPopupContainsItem("Def");
assertSuggestionsPopupContainsItem(getActivity().getString(com.android.internal.R.string.delete));
// Select an item.
clickSuggestionsPopupItem("DEF");
assertSuggestionsPopupIsNotDisplayed();
onView(withId(R.id.textview)).check(matches(withText("abc DEF ghi")));
showSuggestionsPopup();
assertSuggestionsPopupIsDisplayed();
assertSuggestionsPopupContainsItem("def");
assertSuggestionsPopupContainsItem("Def");
assertSuggestionsPopupContainsItem(getActivity().getString(com.android.internal.R.string.delete));
// Delete
clickSuggestionsPopupItem(getActivity().getString(com.android.internal.R.string.delete));
assertSuggestionsPopupIsNotDisplayed();
onView(withId(R.id.textview)).check(matches(withText("abc ghi")));
}
Aggregations