Search in sources :

Example 16 with Editable

use of android.text.Editable in project XobotOS by xamarin.

the class SpellChecker method onGetSuggestions.

@Override
public void onGetSuggestions(SuggestionsInfo[] results) {
    Editable editable = (Editable) mTextView.getText();
    for (int i = 0; i < results.length; i++) {
        SuggestionsInfo suggestionsInfo = results[i];
        if (suggestionsInfo.getCookie() != mCookie)
            continue;
        final int sequenceNumber = suggestionsInfo.getSequence();
        for (int j = 0; j < mLength; j++) {
            if (sequenceNumber == mIds[j]) {
                final int attributes = suggestionsInfo.getSuggestionsAttributes();
                boolean isInDictionary = ((attributes & SuggestionsInfo.RESULT_ATTR_IN_THE_DICTIONARY) > 0);
                boolean looksLikeTypo = ((attributes & SuggestionsInfo.RESULT_ATTR_LOOKS_LIKE_TYPO) > 0);
                SpellCheckSpan spellCheckSpan = mSpellCheckSpans[j];
                if (!isInDictionary && looksLikeTypo) {
                    createMisspelledSuggestionSpan(editable, suggestionsInfo, spellCheckSpan);
                }
                editable.removeSpan(spellCheckSpan);
                break;
            }
        }
    }
    final int length = mSpellParsers.length;
    for (int i = 0; i < length; i++) {
        final SpellParser spellParser = mSpellParsers[i];
        if (!spellParser.isDone()) {
            spellParser.parse();
        }
    }
}
Also used : SpellCheckSpan(android.text.style.SpellCheckSpan) Editable(android.text.Editable) SuggestionsInfo(android.view.textservice.SuggestionsInfo)

Example 17 with Editable

use of android.text.Editable in project XobotOS by xamarin.

the class SpellChecker method spellCheck.

private void spellCheck() {
    if (mSpellCheckerSession == null)
        return;
    Editable editable = (Editable) mTextView.getText();
    final int selectionStart = Selection.getSelectionStart(editable);
    final int selectionEnd = Selection.getSelectionEnd(editable);
    TextInfo[] textInfos = new TextInfo[mLength];
    int textInfosCount = 0;
    for (int i = 0; i < mLength; i++) {
        final SpellCheckSpan spellCheckSpan = mSpellCheckSpans[i];
        if (spellCheckSpan.isSpellCheckInProgress())
            continue;
        final int start = editable.getSpanStart(spellCheckSpan);
        final int end = editable.getSpanEnd(spellCheckSpan);
        // Do not check this word if the user is currently editing it
        if (start >= 0 && end > start && (selectionEnd < start || selectionStart > end)) {
            final String word = editable.subSequence(start, end).toString();
            spellCheckSpan.setSpellCheckInProgress(true);
            textInfos[textInfosCount++] = new TextInfo(word, mCookie, mIds[i]);
        }
    }
    if (textInfosCount > 0) {
        if (textInfosCount < textInfos.length) {
            TextInfo[] textInfosCopy = new TextInfo[textInfosCount];
            System.arraycopy(textInfos, 0, textInfosCopy, 0, textInfosCount);
            textInfos = textInfosCopy;
        }
        mSpellCheckerSession.getSuggestions(textInfos, SuggestionSpan.SUGGESTIONS_MAX_SIZE, false);
    }
}
Also used : SpellCheckSpan(android.text.style.SpellCheckSpan) TextInfo(android.view.textservice.TextInfo) Editable(android.text.Editable)

Example 18 with Editable

use of android.text.Editable in project XobotOS by xamarin.

the class TextView method removeIntersectingSpans.

// Removes all spans that are inside or actually overlap the start..end range
private <T> void removeIntersectingSpans(int start, int end, Class<T> type) {
    if (!(mText instanceof Editable))
        return;
    Editable text = (Editable) mText;
    T[] spans = text.getSpans(start, end, type);
    final int length = spans.length;
    for (int i = 0; i < length; i++) {
        final int s = text.getSpanStart(spans[i]);
        final int e = text.getSpanEnd(spans[i]);
        // updateSpellCheckSpans. Result depends on what will be added (space or text)
        if (e == start || s == end)
            break;
        text.removeSpan(spans[i]);
    }
}
Also used : Editable(android.text.Editable) TextPaint(android.text.TextPaint) Paint(android.graphics.Paint)

Example 19 with Editable

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

the class TextView method setText.

private void setText(CharSequence text, BufferType type, boolean notifyBefore, int oldlen) {
    if (text == null) {
        text = "";
    }
    // If suggestions are not enabled, remove the suggestion spans from the text
    if (!isSuggestionsEnabled()) {
        text = removeSuggestionSpans(text);
    }
    if (!mUserSetTextScaleX)
        mTextPaint.setTextScaleX(1.0f);
    if (text instanceof Spanned && ((Spanned) text).getSpanStart(TextUtils.TruncateAt.MARQUEE) >= 0) {
        if (ViewConfiguration.get(mContext).isFadingMarqueeEnabled()) {
            setHorizontalFadingEdgeEnabled(true);
            mMarqueeFadeMode = MARQUEE_FADE_NORMAL;
        } else {
            setHorizontalFadingEdgeEnabled(false);
            mMarqueeFadeMode = MARQUEE_FADE_SWITCH_SHOW_ELLIPSIS;
        }
        setEllipsize(TextUtils.TruncateAt.MARQUEE);
    }
    int n = mFilters.length;
    for (int i = 0; i < n; i++) {
        CharSequence out = mFilters[i].filter(text, 0, text.length(), EMPTY_SPANNED, 0, 0);
        if (out != null) {
            text = out;
        }
    }
    if (notifyBefore) {
        if (mText != null) {
            oldlen = mText.length();
            sendBeforeTextChanged(mText, 0, oldlen, text.length());
        } else {
            sendBeforeTextChanged("", 0, 0, text.length());
        }
    }
    boolean needEditableForNotification = false;
    if (mListeners != null && mListeners.size() != 0) {
        needEditableForNotification = true;
    }
    if (type == BufferType.EDITABLE || getKeyListener() != null || needEditableForNotification) {
        createEditorIfNeeded();
        mEditor.forgetUndoRedo();
        Editable t = mEditableFactory.newEditable(text);
        text = t;
        setFilters(t, mFilters);
        InputMethodManager imm = InputMethodManager.peekInstance();
        if (imm != null)
            imm.restartInput(this);
    } else if (type == BufferType.SPANNABLE || mMovement != null) {
        text = mSpannableFactory.newSpannable(text);
    } else if (!(text instanceof CharWrapper)) {
        text = TextUtils.stringOrSpannedString(text);
    }
    if (mAutoLinkMask != 0) {
        Spannable s2;
        if (type == BufferType.EDITABLE || text instanceof Spannable) {
            s2 = (Spannable) text;
        } else {
            s2 = mSpannableFactory.newSpannable(text);
        }
        if (Linkify.addLinks(s2, mAutoLinkMask)) {
            text = s2;
            type = (type == BufferType.EDITABLE) ? BufferType.EDITABLE : BufferType.SPANNABLE;
            /*
                 * We must go ahead and set the text before changing the
                 * movement method, because setMovementMethod() may call
                 * setText() again to try to upgrade the buffer type.
                 */
            mText = text;
            // would prevent an arbitrary cursor displacement.
            if (mLinksClickable && !textCanBeSelected()) {
                setMovementMethod(LinkMovementMethod.getInstance());
            }
        }
    }
    mBufferType = type;
    mText = text;
    if (mTransformation == null) {
        mTransformed = text;
    } else {
        mTransformed = mTransformation.getTransformation(text, this);
    }
    final int textLength = text.length();
    if (text instanceof Spannable && !mAllowTransformationLengthChange) {
        Spannable sp = (Spannable) text;
        // Remove any ChangeWatchers that might have come from other TextViews.
        final ChangeWatcher[] watchers = sp.getSpans(0, sp.length(), ChangeWatcher.class);
        final int count = watchers.length;
        for (int i = 0; i < count; i++) {
            sp.removeSpan(watchers[i]);
        }
        if (mChangeWatcher == null)
            mChangeWatcher = new ChangeWatcher();
        sp.setSpan(mChangeWatcher, 0, textLength, Spanned.SPAN_INCLUSIVE_INCLUSIVE | (CHANGE_WATCHER_PRIORITY << Spanned.SPAN_PRIORITY_SHIFT));
        if (mEditor != null)
            mEditor.addSpanWatchers(sp);
        if (mTransformation != null) {
            sp.setSpan(mTransformation, 0, textLength, Spanned.SPAN_INCLUSIVE_INCLUSIVE);
        }
        if (mMovement != null) {
            mMovement.initialize(this, (Spannable) text);
            /*
                 * Initializing the movement method will have set the
                 * selection, so reset mSelectionMoved to keep that from
                 * interfering with the normal on-focus selection-setting.
                 */
            if (mEditor != null)
                mEditor.mSelectionMoved = false;
        }
    }
    if (mLayout != null) {
        checkForRelayout();
    }
    sendOnTextChanged(text, 0, oldlen, textLength);
    onTextChanged(text, 0, oldlen, textLength);
    notifyViewAccessibilityStateChangedIfNeeded(AccessibilityEvent.CONTENT_CHANGE_TYPE_TEXT);
    if (needEditableForNotification) {
        sendAfterTextChanged((Editable) text);
    }
    // SelectionModifierCursorController depends on textCanBeSelected, which depends on text
    if (mEditor != null)
        mEditor.prepareCursorControllers();
}
Also used : Editable(android.text.Editable) InputMethodManager(android.view.inputmethod.InputMethodManager) Spanned(android.text.Spanned) TextPaint(android.text.TextPaint) Paint(android.graphics.Paint) Spannable(android.text.Spannable)

Example 20 with Editable

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

the class TextView method onCreateInputConnection.

@Override
public InputConnection onCreateInputConnection(EditorInfo outAttrs) {
    if (onCheckIsTextEditor() && isEnabled()) {
        mEditor.createInputMethodStateIfNeeded();
        outAttrs.inputType = getInputType();
        if (mEditor.mInputContentType != null) {
            outAttrs.imeOptions = mEditor.mInputContentType.imeOptions;
            outAttrs.privateImeOptions = mEditor.mInputContentType.privateImeOptions;
            outAttrs.actionLabel = mEditor.mInputContentType.imeActionLabel;
            outAttrs.actionId = mEditor.mInputContentType.imeActionId;
            outAttrs.extras = mEditor.mInputContentType.extras;
            outAttrs.hintLocales = mEditor.mInputContentType.imeHintLocales;
        } else {
            outAttrs.imeOptions = EditorInfo.IME_NULL;
            outAttrs.hintLocales = null;
        }
        if (focusSearch(FOCUS_DOWN) != null) {
            outAttrs.imeOptions |= EditorInfo.IME_FLAG_NAVIGATE_NEXT;
        }
        if (focusSearch(FOCUS_UP) != null) {
            outAttrs.imeOptions |= EditorInfo.IME_FLAG_NAVIGATE_PREVIOUS;
        }
        if ((outAttrs.imeOptions & EditorInfo.IME_MASK_ACTION) == EditorInfo.IME_ACTION_UNSPECIFIED) {
            if ((outAttrs.imeOptions & EditorInfo.IME_FLAG_NAVIGATE_NEXT) != 0) {
                // An action has not been set, but the enter key will move to
                // the next focus, so set the action to that.
                outAttrs.imeOptions |= EditorInfo.IME_ACTION_NEXT;
            } else {
                // An action has not been set, and there is no focus to move
                // to, so let's just supply a "done" action.
                outAttrs.imeOptions |= EditorInfo.IME_ACTION_DONE;
            }
            if (!shouldAdvanceFocusOnEnter()) {
                outAttrs.imeOptions |= EditorInfo.IME_FLAG_NO_ENTER_ACTION;
            }
        }
        if (isMultilineInputType(outAttrs.inputType)) {
            // Multi-line text editors should always show an enter key.
            outAttrs.imeOptions |= EditorInfo.IME_FLAG_NO_ENTER_ACTION;
        }
        outAttrs.hintText = mHint;
        if (mText instanceof Editable) {
            InputConnection ic = new EditableInputConnection(this);
            outAttrs.initialSelStart = getSelectionStart();
            outAttrs.initialSelEnd = getSelectionEnd();
            outAttrs.initialCapsMode = ic.getCursorCapsMode(getInputType());
            return ic;
        }
    }
    return null;
}
Also used : BaseInputConnection(android.view.inputmethod.BaseInputConnection) EditableInputConnection(com.android.internal.widget.EditableInputConnection) InputConnection(android.view.inputmethod.InputConnection) EditableInputConnection(com.android.internal.widget.EditableInputConnection) Editable(android.text.Editable)

Aggregations

Editable (android.text.Editable)881 TextWatcher (android.text.TextWatcher)414 View (android.view.View)293 TextView (android.widget.TextView)217 EditText (android.widget.EditText)144 Paint (android.graphics.Paint)102 ImageView (android.widget.ImageView)94 Intent (android.content.Intent)81 AdapterView (android.widget.AdapterView)81 KeyEvent (android.view.KeyEvent)74 TextPaint (android.text.TextPaint)69 InputMethodManager (android.view.inputmethod.InputMethodManager)64 ListView (android.widget.ListView)64 DialogInterface (android.content.DialogInterface)57 SuppressLint (android.annotation.SuppressLint)56 Spannable (android.text.Spannable)51 AlertDialog (android.app.AlertDialog)46 RecyclerView (android.support.v7.widget.RecyclerView)45 ArrayList (java.util.ArrayList)43 Button (android.widget.Button)41