Search in sources :

Example 66 with SuggestionSpan

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;
}
Also used : SuggestionSpan(android.text.style.SuggestionSpan) Spanned(android.text.Spanned)

Example 67 with SuggestionSpan

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;
}
Also used : SpannableString(android.text.SpannableString) SuggestionSpan(android.text.style.SuggestionSpan) Spanned(android.text.Spanned) Spannable(android.text.Spannable) TextPaint(android.text.TextPaint) Paint(android.graphics.Paint)

Example 68 with SuggestionSpan

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);
            }
        }
    }
}
Also used : SuggestionSpan(android.text.style.SuggestionSpan) Spannable(android.text.Spannable) TextPaint(android.text.TextPaint) Paint(android.graphics.Paint)

Example 69 with SuggestionSpan

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();
}
Also used : SuggestionSpan(android.text.style.SuggestionSpan) SmallTest(android.test.suitebuilder.annotation.SmallTest)

Example 70 with SuggestionSpan

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")));
}
Also used : SuggestionSpan(android.text.style.SuggestionSpan) SmallTest(android.test.suitebuilder.annotation.SmallTest)

Aggregations

SuggestionSpan (android.text.style.SuggestionSpan)114 Paint (android.graphics.Paint)43 SmallTest (android.test.suitebuilder.annotation.SmallTest)35 Spannable (android.text.Spannable)29 Spanned (android.text.Spanned)24 Editable (android.text.Editable)21 TextPaint (android.text.TextPaint)21 SpannableString (android.text.SpannableString)14 View (android.view.View)10 SpannableStringBuilder (android.text.SpannableStringBuilder)7 SpellCheckSpan (android.text.style.SpellCheckSpan)7 Nullable (android.annotation.Nullable)5 TypedArray (android.content.res.TypedArray)5 Espresso.onView (android.support.test.espresso.Espresso.onView)5 NoMatchingViewException (android.support.test.espresso.NoMatchingViewException)5 ViewAssertion (android.support.test.espresso.ViewAssertion)5 RootMatchers.withDecorView (android.support.test.espresso.matcher.RootMatchers.withDecorView)5 BackgroundColorSpan (android.text.style.BackgroundColorSpan)5 ForegroundColorSpan (android.text.style.ForegroundColorSpan)5 ImageSpan (android.text.style.ImageSpan)5