Search in sources :

Example 56 with Editable

use of android.text.Editable in project platform_frameworks_base by android.

the class SpellChecker method onGetSuggestions.

@Override
public void onGetSuggestions(SuggestionsInfo[] results) {
    final Editable editable = (Editable) mTextView.getText();
    for (int i = 0; i < results.length; ++i) {
        final SpellCheckSpan spellCheckSpan = onGetSuggestionsInternal(results[i], USE_SPAN_RANGE, USE_SPAN_RANGE);
        if (spellCheckSpan != null) {
            // onSpellCheckSpanRemoved will recycle this span in the pool
            editable.removeSpan(spellCheckSpan);
        }
    }
    scheduleNewSpellCheck();
}
Also used : SpellCheckSpan(android.text.style.SpellCheckSpan) Editable(android.text.Editable)

Example 57 with Editable

use of android.text.Editable in project platform_frameworks_base by android.

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 (mIds[i] < 0 || 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
        final boolean isEditing;
        // Defer spell check when typing a word with an interior apostrophe.
        // TODO: a better solution to this would be to make the word
        // iterator locale-sensitive and include the apostrophe in
        // languages that use it (such as English).
        final boolean apostrophe = (selectionStart == end + 1 && editable.charAt(end) == '\'');
        if (mIsSentenceSpellCheckSupported) {
            // Allow the overlap of the cursor and the first boundary of the spell check span
            // no to skip the spell check of the following word because the
            // following word will never be spell-checked even if the user finishes composing
            isEditing = !apostrophe && (selectionEnd <= start || selectionStart > end);
        } else {
            isEditing = !apostrophe && (selectionEnd < start || selectionStart > end);
        }
        if (start >= 0 && end > start && isEditing) {
            spellCheckSpan.setSpellCheckInProgress(true);
            final TextInfo textInfo = new TextInfo(editable, start, end, mCookie, mIds[i]);
            textInfos[textInfosCount++] = textInfo;
            if (DBG) {
                Log.d(TAG, "create TextInfo: (" + i + "/" + mLength + ") text = " + textInfo.getSequence() + ", cookie = " + mCookie + ", seq = " + mIds[i] + ", sel start = " + selectionStart + ", sel end = " + selectionEnd + ", start = " + start + ", end = " + end);
            }
        }
    }
    if (textInfosCount > 0) {
        if (textInfosCount < textInfos.length) {
            TextInfo[] textInfosCopy = new TextInfo[textInfosCount];
            System.arraycopy(textInfos, 0, textInfosCopy, 0, textInfosCount);
            textInfos = textInfosCopy;
        }
        if (mIsSentenceSpellCheckSupported) {
            mSpellCheckerSession.getSentenceSuggestions(textInfos, SuggestionSpan.SUGGESTIONS_MAX_SIZE);
        } else {
            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 58 with Editable

use of android.text.Editable in project platform_frameworks_base by android.

the class SpellChecker method onGetSentenceSuggestions.

@Override
public void onGetSentenceSuggestions(SentenceSuggestionsInfo[] results) {
    final Editable editable = (Editable) mTextView.getText();
    for (int i = 0; i < results.length; ++i) {
        final SentenceSuggestionsInfo ssi = results[i];
        if (ssi == null) {
            continue;
        }
        SpellCheckSpan spellCheckSpan = null;
        for (int j = 0; j < ssi.getSuggestionsCount(); ++j) {
            final SuggestionsInfo suggestionsInfo = ssi.getSuggestionsInfoAt(j);
            if (suggestionsInfo == null) {
                continue;
            }
            final int offset = ssi.getOffsetAt(j);
            final int length = ssi.getLengthAt(j);
            final SpellCheckSpan scs = onGetSuggestionsInternal(suggestionsInfo, offset, length);
            if (spellCheckSpan == null && scs != null) {
                // the spellCheckSpan is shared by all the "SuggestionsInfo"s in the same
                // SentenceSuggestionsInfo. Removal is deferred after this loop.
                spellCheckSpan = scs;
            }
        }
        if (spellCheckSpan != null) {
            // onSpellCheckSpanRemoved will recycle this span in the pool
            editable.removeSpan(spellCheckSpan);
        }
    }
    scheduleNewSpellCheck();
}
Also used : SpellCheckSpan(android.text.style.SpellCheckSpan) Editable(android.text.Editable) SentenceSuggestionsInfo(android.view.textservice.SentenceSuggestionsInfo) SentenceSuggestionsInfo(android.view.textservice.SentenceSuggestionsInfo) SuggestionsInfo(android.view.textservice.SuggestionsInfo)

Example 59 with Editable

use of android.text.Editable in project Genius-Android by qiujuer.

the class EditText method initHintTitleText.

private void initHintTitleText() {
    if (isShowTitle()) {
        // Set up a default TextPaint object
        if (mTitlePaint == null) {
            mTitlePaint = new TextPaint(Paint.ANTI_ALIAS_FLAG);
            mTitlePaint.density = getResources().getDisplayMetrics().density;
            mTitlePaint.setTextAlign(Paint.Align.LEFT);
            mTitlePaint.setTypeface(getTypeface());
        }
        // Add Watcher
        if (mTextWatcher == null) {
            mTextWatcher = new TextWatcher() {

                @Override
                public void beforeTextChanged(CharSequence s, int start, int count, int after) {
                }

                @Override
                public void onTextChanged(CharSequence s, int start, int before, int count) {
                }

                @Override
                public void afterTextChanged(Editable s) {
                    checkShowTitle(s, false);
                }
            };
            addTextChangedListener(mTextWatcher);
        }
        // try show
        Editable editable = getEditableText();
        checkShowTitle(editable, false);
    } else {
        if (mTextWatcher != null) {
            removeTextChangedListener(mTextWatcher);
            mTextWatcher = null;
        }
        mTitlePaint = null;
        mCurTitleProperty = null;
        mAnimator = null;
    }
}
Also used : TextWatcher(android.text.TextWatcher) Editable(android.text.Editable) SuppressLint(android.annotation.SuppressLint) TextPaint(android.text.TextPaint) Paint(android.graphics.Paint) TextPaint(android.text.TextPaint)

Example 60 with Editable

use of android.text.Editable in project MaterialEditText by rengwuxian.

the class MaterialMultiAutoCompleteTextView method initFloatingLabel.

private void initFloatingLabel() {
    // observe the text changing
    addTextChangedListener(new TextWatcher() {

        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        }

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
        }

        @Override
        public void afterTextChanged(Editable s) {
            if (floatingLabelEnabled) {
                if (s.length() == 0) {
                    if (floatingLabelShown) {
                        floatingLabelShown = false;
                        getLabelAnimator().reverse();
                    }
                } else if (!floatingLabelShown) {
                    floatingLabelShown = true;
                    getLabelAnimator().start();
                }
            }
        }
    });
    // observe the focus state to animate the floating label's text color appropriately
    innerFocusChangeListener = new OnFocusChangeListener() {

        @Override
        public void onFocusChange(View v, boolean hasFocus) {
            if (floatingLabelEnabled && highlightFloatingLabel) {
                if (hasFocus) {
                    getLabelFocusAnimator().start();
                } else {
                    getLabelFocusAnimator().reverse();
                }
            }
            if (validateOnFocusLost && !hasFocus) {
                validate();
            }
            if (outerFocusChangeListener != null) {
                outerFocusChangeListener.onFocusChange(v, hasFocus);
            }
        }
    };
    super.setOnFocusChangeListener(innerFocusChangeListener);
}
Also used : TextWatcher(android.text.TextWatcher) Editable(android.text.Editable) View(android.view.View) AppCompatMultiAutoCompleteTextView(android.support.v7.widget.AppCompatMultiAutoCompleteTextView) TextPaint(android.text.TextPaint) Paint(android.graphics.Paint)

Aggregations

Editable (android.text.Editable)511 TextWatcher (android.text.TextWatcher)158 View (android.view.View)117 TextView (android.widget.TextView)77 Paint (android.graphics.Paint)73 Spannable (android.text.Spannable)45 TextPaint (android.text.TextPaint)44 EditText (android.widget.EditText)39 KeyEvent (android.view.KeyEvent)34 InputMethodManager (android.view.inputmethod.InputMethodManager)33 Intent (android.content.Intent)30 ImageView (android.widget.ImageView)30 SpellCheckSpan (android.text.style.SpellCheckSpan)26 SuppressLint (android.annotation.SuppressLint)24 AdapterView (android.widget.AdapterView)23 Spanned (android.text.Spanned)22 SuggestionSpan (android.text.style.SuggestionSpan)21 ListView (android.widget.ListView)19 SpannableStringBuilder (android.text.SpannableStringBuilder)18 DialogInterface (android.content.DialogInterface)16