Search in sources :

Example 91 with Spannable

use of android.text.Spannable in project android_frameworks_base by DirtyUnicorns.

the class InputMethodService method onExtractedSetSpan.

/**
     * @hide
     */
public void onExtractedSetSpan(Object span, int start, int end, int flags) {
    InputConnection conn = getCurrentInputConnection();
    if (conn != null) {
        if (!conn.setSelection(start, end))
            return;
        CharSequence text = conn.getSelectedText(InputConnection.GET_TEXT_WITH_STYLES);
        if (text instanceof Spannable) {
            ((Spannable) text).setSpan(span, 0, text.length(), flags);
            conn.setComposingRegion(start, end);
            conn.commitText(text, 1);
        }
    }
}
Also used : InputConnection(android.view.inputmethod.InputConnection) Spannable(android.text.Spannable)

Example 92 with Spannable

use of android.text.Spannable in project android_frameworks_base by DirtyUnicorns.

the class PasswordTransformationMethod method getTransformation.

public CharSequence getTransformation(CharSequence source, View view) {
    if (source instanceof Spannable) {
        Spannable sp = (Spannable) source;
        /*
             * Remove any references to other views that may still be
             * attached.  This will happen when you flip the screen
             * while a password field is showing; there will still
             * be references to the old EditText in the text.
             */
        ViewReference[] vr = sp.getSpans(0, sp.length(), ViewReference.class);
        for (int i = 0; i < vr.length; i++) {
            sp.removeSpan(vr[i]);
        }
        removeVisibleSpans(sp);
        sp.setSpan(new ViewReference(view), 0, 0, Spannable.SPAN_POINT_POINT);
    }
    return new PasswordCharSequence(source);
}
Also used : Spannable(android.text.Spannable)

Example 93 with Spannable

use of android.text.Spannable in project android_frameworks_base by DirtyUnicorns.

the class PasswordTransformationMethod method onTextChanged.

public void onTextChanged(CharSequence s, int start, int before, int count) {
    if (s instanceof Spannable) {
        Spannable sp = (Spannable) s;
        ViewReference[] vr = sp.getSpans(0, s.length(), ViewReference.class);
        if (vr.length == 0) {
            return;
        }
        /*
             * There should generally only be one ViewReference in the text,
             * but make sure to look through all of them if necessary in case
             * something strange is going on.  (We might still end up with
             * multiple ViewReferences if someone moves text from one password
             * field to another.)
             */
        View v = null;
        for (int i = 0; v == null && i < vr.length; i++) {
            v = vr[i].get();
        }
        if (v == null) {
            return;
        }
        int pref = TextKeyListener.getInstance().getPrefs(v.getContext());
        if ((pref & TextKeyListener.SHOW_PASSWORD) != 0) {
            if (count > 0) {
                removeVisibleSpans(sp);
                if (count == 1) {
                    sp.setSpan(new Visible(sp, this), start, start + count, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
                }
            }
        }
    }
}
Also used : View(android.view.View) Spannable(android.text.Spannable)

Example 94 with Spannable

use of android.text.Spannable in project android_frameworks_base by DirtyUnicorns.

the class PasswordTransformationMethod method onFocusChanged.

public void onFocusChanged(View view, CharSequence sourceText, boolean focused, int direction, Rect previouslyFocusedRect) {
    if (!focused) {
        if (sourceText instanceof Spannable) {
            Spannable sp = (Spannable) sourceText;
            removeVisibleSpans(sp);
        }
    }
}
Also used : Spannable(android.text.Spannable)

Example 95 with Spannable

use of android.text.Spannable in project android_frameworks_base by DirtyUnicorns.

the class Editor method downgradeEasyCorrectionSpans.

/**
     * Downgrades to simple suggestions all the easy correction spans that are not a spell check
     * span.
     */
private void downgradeEasyCorrectionSpans() {
    CharSequence text = mTextView.getText();
    if (text instanceof Spannable) {
        Spannable spannable = (Spannable) text;
        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) Paint(android.graphics.Paint)

Aggregations

Spannable (android.text.Spannable)328 Paint (android.graphics.Paint)122 TextPaint (android.text.TextPaint)97 SpannableString (android.text.SpannableString)72 Editable (android.text.Editable)42 InputMethodManager (android.view.inputmethod.InputMethodManager)34 Spanned (android.text.Spanned)32 SuggestionSpan (android.text.style.SuggestionSpan)29 View (android.view.View)28 SpannableStringBuilder (android.text.SpannableStringBuilder)24 ForegroundColorSpan (android.text.style.ForegroundColorSpan)20 TextView (android.widget.TextView)17 ClickableSpan (android.text.style.ClickableSpan)14 StyleSpan (android.text.style.StyleSpan)14 KeyEvent (android.view.KeyEvent)13 URLSpan (android.text.style.URLSpan)12 Intent (android.content.Intent)11 Layout (android.text.Layout)11 Parcelable (android.os.Parcelable)8 RemoteView (android.widget.RemoteViews.RemoteView)8