Search in sources :

Example 96 with Spannable

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

the class Editor method sendUpdateSelection.

private void sendUpdateSelection() {
    if (null != mInputMethodState && mInputMethodState.mBatchEditNesting <= 0) {
        final InputMethodManager imm = InputMethodManager.peekInstance();
        if (null != imm) {
            final int selectionStart = mTextView.getSelectionStart();
            final int selectionEnd = mTextView.getSelectionEnd();
            int candStart = -1;
            int candEnd = -1;
            if (mTextView.getText() instanceof Spannable) {
                final Spannable sp = (Spannable) mTextView.getText();
                candStart = EditableInputConnection.getComposingSpanStart(sp);
                candEnd = EditableInputConnection.getComposingSpanEnd(sp);
            }
            // InputMethodManager#updateSelection skips sending the message if
            // none of the parameters have changed since the last time we called it.
            imm.updateSelection(mTextView, selectionStart, selectionEnd, candStart, candEnd);
        }
    }
}
Also used : InputMethodManager(android.view.inputmethod.InputMethodManager) Paint(android.graphics.Paint) Spannable(android.text.Spannable)

Example 97 with Spannable

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

the class DialerFilter method removeFilterWatcher.

public void removeFilterWatcher(TextWatcher watcher) {
    Spannable text;
    if (mMode != DIGITS_ONLY) {
        text = mLetters.getText();
    } else {
        text = mDigits.getText();
    }
    text.removeSpan(watcher);
}
Also used : Spannable(android.text.Spannable)

Example 98 with Spannable

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

the class Editor method shouldOfferToShowSuggestions.

/**
     * @return <code>true</code> if it's reasonable to offer to show suggestions depending on
     * the current cursor position or selection range. This method is consistent with the
     * method to show suggestions {@link SuggestionsPopupWindow#updateSuggestions}.
     */
private boolean shouldOfferToShowSuggestions() {
    CharSequence text = mTextView.getText();
    if (!(text instanceof Spannable))
        return false;
    final Spannable spannable = (Spannable) text;
    final int selectionStart = mTextView.getSelectionStart();
    final int selectionEnd = mTextView.getSelectionEnd();
    final SuggestionSpan[] suggestionSpans = spannable.getSpans(selectionStart, selectionEnd, SuggestionSpan.class);
    if (suggestionSpans.length == 0) {
        return false;
    }
    if (selectionStart == selectionEnd) {
        // Spans overlap the cursor.
        for (int i = 0; i < suggestionSpans.length; i++) {
            if (suggestionSpans[i].getSuggestions().length > 0) {
                return true;
            }
        }
        return false;
    }
    int minSpanStart = mTextView.getText().length();
    int maxSpanEnd = 0;
    int unionOfSpansCoveringSelectionStartStart = mTextView.getText().length();
    int unionOfSpansCoveringSelectionStartEnd = 0;
    boolean hasValidSuggestions = false;
    for (int i = 0; i < suggestionSpans.length; i++) {
        final int spanStart = spannable.getSpanStart(suggestionSpans[i]);
        final int spanEnd = spannable.getSpanEnd(suggestionSpans[i]);
        minSpanStart = Math.min(minSpanStart, spanStart);
        maxSpanEnd = Math.max(maxSpanEnd, spanEnd);
        if (selectionStart < spanStart || selectionStart > spanEnd) {
            // The span doesn't cover the current selection start point.
            continue;
        }
        hasValidSuggestions = hasValidSuggestions || suggestionSpans[i].getSuggestions().length > 0;
        unionOfSpansCoveringSelectionStartStart = Math.min(unionOfSpansCoveringSelectionStartStart, spanStart);
        unionOfSpansCoveringSelectionStartEnd = Math.max(unionOfSpansCoveringSelectionStartEnd, spanEnd);
    }
    if (!hasValidSuggestions) {
        return false;
    }
    if (unionOfSpansCoveringSelectionStartStart >= unionOfSpansCoveringSelectionStartEnd) {
        // No spans cover the selection start point.
        return false;
    }
    if (minSpanStart < unionOfSpansCoveringSelectionStartStart || maxSpanEnd > unionOfSpansCoveringSelectionStartEnd) {
        // to show suggestions as it's confusing.
        return false;
    }
    return true;
}
Also used : SuggestionSpan(android.text.style.SuggestionSpan) Spannable(android.text.Spannable) Paint(android.graphics.Paint)

Example 99 with Spannable

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

the class DialerFilter method setDigitsWatcher.

public void setDigitsWatcher(TextWatcher watcher) {
    CharSequence text = mDigits.getText();
    Spannable span = (Spannable) text;
    span.setSpan(watcher, 0, text.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE);
}
Also used : Spannable(android.text.Spannable)

Example 100 with Spannable

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

the class DialerFilter method setLettersWatcher.

public void setLettersWatcher(TextWatcher watcher) {
    CharSequence text = mLetters.getText();
    Spannable span = (Spannable) text;
    span.setSpan(watcher, 0, text.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE);
}
Also used : Spannable(android.text.Spannable)

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