Search in sources :

Example 71 with Spannable

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

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 72 with Spannable

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

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 73 with Spannable

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

the class TextView method onResolvePointerIcon.

@Override
public PointerIcon onResolvePointerIcon(MotionEvent event, int pointerIndex) {
    if (mText instanceof Spannable && mLinksClickable) {
        final float x = event.getX(pointerIndex);
        final float y = event.getY(pointerIndex);
        final int offset = getOffsetForPosition(x, y);
        final ClickableSpan[] clickables = ((Spannable) mText).getSpans(offset, offset, ClickableSpan.class);
        if (clickables.length > 0) {
            return PointerIcon.getSystemIcon(mContext, PointerIcon.TYPE_HAND);
        }
    }
    if (isTextSelectable() || isTextEditable()) {
        return PointerIcon.getSystemIcon(mContext, PointerIcon.TYPE_TEXT);
    }
    return super.onResolvePointerIcon(event, pointerIndex);
}
Also used : ClickableSpan(android.text.style.ClickableSpan) Spannable(android.text.Spannable) TextPaint(android.text.TextPaint) Paint(android.graphics.Paint)

Example 74 with Spannable

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

the class TextView method onKeyMultiple.

@Override
public boolean onKeyMultiple(int keyCode, int repeatCount, KeyEvent event) {
    KeyEvent down = KeyEvent.changeAction(event, KeyEvent.ACTION_DOWN);
    final int which = doKeyDown(keyCode, down, event);
    if (which == KEY_EVENT_NOT_HANDLED) {
        // Go through default dispatching.
        return super.onKeyMultiple(keyCode, repeatCount, event);
    }
    if (which == KEY_EVENT_HANDLED) {
        // Consumed the whole thing.
        return true;
    }
    repeatCount--;
    // We are going to dispatch the remaining events to either the input
    // or movement method.  To do this, we will just send a repeated stream
    // of down and up events until we have done the complete repeatCount.
    // It would be nice if those interfaces had an onKeyMultiple() method,
    // but adding that is a more complicated change.
    KeyEvent up = KeyEvent.changeAction(event, KeyEvent.ACTION_UP);
    if (which == KEY_DOWN_HANDLED_BY_KEY_LISTENER) {
        // mEditor and mEditor.mInput are not null from doKeyDown
        mEditor.mKeyListener.onKeyUp(this, (Editable) mText, keyCode, up);
        while (--repeatCount > 0) {
            mEditor.mKeyListener.onKeyDown(this, (Editable) mText, keyCode, down);
            mEditor.mKeyListener.onKeyUp(this, (Editable) mText, keyCode, up);
        }
        hideErrorIfUnchanged();
    } else if (which == KEY_DOWN_HANDLED_BY_MOVEMENT_METHOD) {
        // mMovement is not null from doKeyDown
        mMovement.onKeyUp(this, (Spannable) mText, keyCode, up);
        while (--repeatCount > 0) {
            mMovement.onKeyDown(this, (Spannable) mText, keyCode, down);
            mMovement.onKeyUp(this, (Spannable) mText, keyCode, up);
        }
    }
    return true;
}
Also used : KeyEvent(android.view.KeyEvent) TextPaint(android.text.TextPaint) Paint(android.graphics.Paint) Spannable(android.text.Spannable)

Example 75 with Spannable

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

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)

Aggregations

Spannable (android.text.Spannable)333 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)21 TextView (android.widget.TextView)17 ClickableSpan (android.text.style.ClickableSpan)14 StyleSpan (android.text.style.StyleSpan)14 Intent (android.content.Intent)13 KeyEvent (android.view.KeyEvent)13 URLSpan (android.text.style.URLSpan)12 Layout (android.text.Layout)11 Parcelable (android.os.Parcelable)8 SpannedString (android.text.SpannedString)8