Search in sources :

Example 36 with SpellCheckSpan

use of android.text.style.SpellCheckSpan in project android_frameworks_base by DirtyUnicorns.

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 37 with SpellCheckSpan

use of android.text.style.SpellCheckSpan in project android_frameworks_base by DirtyUnicorns.

the class SpellChecker method addSpellCheckSpan.

private void addSpellCheckSpan(Editable editable, int start, int end) {
    final int index = nextSpellCheckSpanIndex();
    SpellCheckSpan spellCheckSpan = mSpellCheckSpans[index];
    editable.setSpan(spellCheckSpan, start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    spellCheckSpan.setSpellCheckInProgress(false);
    mIds[index] = mSpanSequenceCounter++;
}
Also used : SpellCheckSpan(android.text.style.SpellCheckSpan)

Example 38 with SpellCheckSpan

use of android.text.style.SpellCheckSpan in project android_frameworks_base by crdroidandroid.

the class SpellChecker method onGetSuggestionsInternal.

private SpellCheckSpan onGetSuggestionsInternal(SuggestionsInfo suggestionsInfo, int offset, int length) {
    if (suggestionsInfo == null || suggestionsInfo.getCookie() != mCookie) {
        return null;
    }
    final Editable editable = (Editable) mTextView.getText();
    final int sequenceNumber = suggestionsInfo.getSequence();
    for (int k = 0; k < mLength; ++k) {
        if (sequenceNumber == mIds[k]) {
            final int attributes = suggestionsInfo.getSuggestionsAttributes();
            final boolean isInDictionary = ((attributes & SuggestionsInfo.RESULT_ATTR_IN_THE_DICTIONARY) > 0);
            final boolean looksLikeTypo = ((attributes & SuggestionsInfo.RESULT_ATTR_LOOKS_LIKE_TYPO) > 0);
            final SpellCheckSpan spellCheckSpan = mSpellCheckSpans[k];
            // checker that will probably be in dictionary.
            if (!isInDictionary && looksLikeTypo) {
                createMisspelledSuggestionSpan(editable, suggestionsInfo, spellCheckSpan, offset, length);
            } else {
                // Valid word -- isInDictionary || !looksLikeTypo
                if (mIsSentenceSpellCheckSupported) {
                    // Allow the spell checker to remove existing misspelled span by
                    // overwriting the span over the same place
                    final int spellCheckSpanStart = editable.getSpanStart(spellCheckSpan);
                    final int spellCheckSpanEnd = editable.getSpanEnd(spellCheckSpan);
                    final int start;
                    final int end;
                    if (offset != USE_SPAN_RANGE && length != USE_SPAN_RANGE) {
                        start = spellCheckSpanStart + offset;
                        end = start + length;
                    } else {
                        start = spellCheckSpanStart;
                        end = spellCheckSpanEnd;
                    }
                    if (spellCheckSpanStart >= 0 && spellCheckSpanEnd > spellCheckSpanStart && end > start) {
                        final Long key = Long.valueOf(TextUtils.packRangeInLong(start, end));
                        final SuggestionSpan tempSuggestionSpan = mSuggestionSpanCache.get(key);
                        if (tempSuggestionSpan != null) {
                            if (DBG) {
                                Log.i(TAG, "Remove existing misspelled span. " + editable.subSequence(start, end));
                            }
                            editable.removeSpan(tempSuggestionSpan);
                            mSuggestionSpanCache.remove(key);
                        }
                    }
                }
            }
            return spellCheckSpan;
        }
    }
    return null;
}
Also used : SpellCheckSpan(android.text.style.SpellCheckSpan) Editable(android.text.Editable) SuggestionSpan(android.text.style.SuggestionSpan)

Example 39 with SpellCheckSpan

use of android.text.style.SpellCheckSpan in project android_frameworks_base by crdroidandroid.

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 40 with SpellCheckSpan

use of android.text.style.SpellCheckSpan in project android_frameworks_base by crdroidandroid.

the class SpellChecker method addSpellCheckSpan.

private void addSpellCheckSpan(Editable editable, int start, int end) {
    final int index = nextSpellCheckSpanIndex();
    SpellCheckSpan spellCheckSpan = mSpellCheckSpans[index];
    editable.setSpan(spellCheckSpan, start, end, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    spellCheckSpan.setSpellCheckInProgress(false);
    mIds[index] = mSpanSequenceCounter++;
}
Also used : SpellCheckSpan(android.text.style.SpellCheckSpan)

Aggregations

SpellCheckSpan (android.text.style.SpellCheckSpan)41 Editable (android.text.Editable)26 Paint (android.graphics.Paint)7 ParcelableSpan (android.text.ParcelableSpan)7 TextPaint (android.text.TextPaint)7 ParagraphStyle (android.text.style.ParagraphStyle)7 SuggestionSpan (android.text.style.SuggestionSpan)7 UpdateAppearance (android.text.style.UpdateAppearance)7 SuggestionsInfo (android.view.textservice.SuggestionsInfo)7 TextInfo (android.view.textservice.TextInfo)7 CharacterStyle (android.text.style.CharacterStyle)6 SentenceSuggestionsInfo (android.view.textservice.SentenceSuggestionsInfo)6 SpannableStringBuilder (android.text.SpannableStringBuilder)1