Search in sources :

Example 21 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 22 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 23 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 24 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)

Example 25 with Spannable

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

the class SuggestionsPopupWindowTest method setSuggestionSpan.

private void setSuggestionSpan(SuggestionSpan span, int start, int end) {
    final TextView textView = (TextView) getActivity().findViewById(R.id.textview);
    textView.post(() -> {
        final Spannable text = (Spannable) textView.getText();
        text.setSpan(span, start, end, Spanned.SPAN_INCLUSIVE_INCLUSIVE);
        Selection.setSelection(text, (start + end) / 2);
    });
    getInstrumentation().waitForIdleSync();
}
Also used : Spannable(android.text.Spannable)

Aggregations

Spannable (android.text.Spannable)478 SpannableString (android.text.SpannableString)138 Paint (android.graphics.Paint)133 TextPaint (android.text.TextPaint)118 TextView (android.widget.TextView)63 View (android.view.View)58 Editable (android.text.Editable)48 ForegroundColorSpan (android.text.style.ForegroundColorSpan)46 StyleSpan (android.text.style.StyleSpan)46 SpannableStringBuilder (android.text.SpannableStringBuilder)40 Spanned (android.text.Spanned)38 Intent (android.content.Intent)35 InputMethodManager (android.view.inputmethod.InputMethodManager)34 SuggestionSpan (android.text.style.SuggestionSpan)29 ClickableSpan (android.text.style.ClickableSpan)26 URLSpan (android.text.style.URLSpan)25 AlertDialog (android.app.AlertDialog)18 SuppressLint (android.annotation.SuppressLint)17 Date (java.util.Date)17 TextAppearanceSpan (android.text.style.TextAppearanceSpan)16