Search in sources :

Example 1 with SentenceSuggestionsInfo

use of android.view.textservice.SentenceSuggestionsInfo in project android_frameworks_base by ParanoidAndroid.

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 2 with SentenceSuggestionsInfo

use of android.view.textservice.SentenceSuggestionsInfo 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 3 with SentenceSuggestionsInfo

use of android.view.textservice.SentenceSuggestionsInfo in project android_frameworks_base by AOSPA.

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 4 with SentenceSuggestionsInfo

use of android.view.textservice.SentenceSuggestionsInfo in project android_packages_inputmethods_LatinIME by CyanogenMod.

the class AndroidSpellCheckerSession method fixWronglyInvalidatedWordWithSingleQuote.

@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
private SentenceSuggestionsInfo fixWronglyInvalidatedWordWithSingleQuote(TextInfo ti, SentenceSuggestionsInfo ssi) {
    final CharSequence typedText = TextInfoCompatUtils.getCharSequenceOrString(ti);
    if (!typedText.toString().contains(AndroidSpellCheckerService.SINGLE_QUOTE)) {
        return null;
    }
    final int N = ssi.getSuggestionsCount();
    final ArrayList<Integer> additionalOffsets = new ArrayList<>();
    final ArrayList<Integer> additionalLengths = new ArrayList<>();
    final ArrayList<SuggestionsInfo> additionalSuggestionsInfos = new ArrayList<>();
    CharSequence currentWord = null;
    for (int i = 0; i < N; ++i) {
        final SuggestionsInfo si = ssi.getSuggestionsInfoAt(i);
        final int flags = si.getSuggestionsAttributes();
        if ((flags & SuggestionsInfo.RESULT_ATTR_IN_THE_DICTIONARY) == 0) {
            continue;
        }
        final int offset = ssi.getOffsetAt(i);
        final int length = ssi.getLengthAt(i);
        final CharSequence subText = typedText.subSequence(offset, offset + length);
        final NgramContext ngramContext = new NgramContext(new NgramContext.WordInfo(currentWord));
        currentWord = subText;
        if (!subText.toString().contains(AndroidSpellCheckerService.SINGLE_QUOTE)) {
            continue;
        }
        // Split preserving spans.
        final CharSequence[] splitTexts = SpannableStringUtils.split(subText, AndroidSpellCheckerService.SINGLE_QUOTE, true);
        if (splitTexts == null || splitTexts.length <= 1) {
            continue;
        }
        final int splitNum = splitTexts.length;
        for (int j = 0; j < splitNum; ++j) {
            final CharSequence splitText = splitTexts[j];
            if (TextUtils.isEmpty(splitText)) {
                continue;
            }
            if (mSuggestionsCache.getSuggestionsFromCache(splitText.toString()) == null) {
                continue;
            }
            final int newLength = splitText.length();
            // Neither RESULT_ATTR_IN_THE_DICTIONARY nor RESULT_ATTR_LOOKS_LIKE_TYPO
            final int newFlags = 0;
            final SuggestionsInfo newSi = new SuggestionsInfo(newFlags, EMPTY_STRING_ARRAY);
            newSi.setCookieAndSequence(si.getCookie(), si.getSequence());
            if (DBG) {
                Log.d(TAG, "Override and remove old span over: " + splitText + ", " + offset + "," + newLength);
            }
            additionalOffsets.add(offset);
            additionalLengths.add(newLength);
            additionalSuggestionsInfos.add(newSi);
        }
    }
    final int additionalSize = additionalOffsets.size();
    if (additionalSize <= 0) {
        return null;
    }
    final int suggestionsSize = N + additionalSize;
    final int[] newOffsets = new int[suggestionsSize];
    final int[] newLengths = new int[suggestionsSize];
    final SuggestionsInfo[] newSuggestionsInfos = new SuggestionsInfo[suggestionsSize];
    int i;
    for (i = 0; i < N; ++i) {
        newOffsets[i] = ssi.getOffsetAt(i);
        newLengths[i] = ssi.getLengthAt(i);
        newSuggestionsInfos[i] = ssi.getSuggestionsInfoAt(i);
    }
    for (; i < suggestionsSize; ++i) {
        newOffsets[i] = additionalOffsets.get(i - N);
        newLengths[i] = additionalLengths.get(i - N);
        newSuggestionsInfos[i] = additionalSuggestionsInfos.get(i - N);
    }
    return new SentenceSuggestionsInfo(newSuggestionsInfos, newOffsets, newLengths);
}
Also used : ArrayList(java.util.ArrayList) SentenceSuggestionsInfo(android.view.textservice.SentenceSuggestionsInfo) SentenceSuggestionsInfo(android.view.textservice.SentenceSuggestionsInfo) SuggestionsInfo(android.view.textservice.SuggestionsInfo) NgramContext(com.android.inputmethod.latin.NgramContext) TargetApi(android.annotation.TargetApi)

Example 5 with SentenceSuggestionsInfo

use of android.view.textservice.SentenceSuggestionsInfo in project android_packages_inputmethods_LatinIME by CyanogenMod.

the class SentenceLevelAdapter method reconstructSuggestions.

@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
public static SentenceSuggestionsInfo reconstructSuggestions(SentenceTextInfoParams originalTextInfoParams, SuggestionsInfo[] results) {
    if (results == null || results.length == 0) {
        return null;
    }
    if (originalTextInfoParams == null) {
        return null;
    }
    final int originalCookie = originalTextInfoParams.mOriginalTextInfo.getCookie();
    final int originalSequence = originalTextInfoParams.mOriginalTextInfo.getSequence();
    final int querySize = originalTextInfoParams.mSize;
    final int[] offsets = new int[querySize];
    final int[] lengths = new int[querySize];
    final SuggestionsInfo[] reconstructedSuggestions = new SuggestionsInfo[querySize];
    for (int i = 0; i < querySize; ++i) {
        final SentenceWordItem item = originalTextInfoParams.mItems.get(i);
        SuggestionsInfo result = null;
        for (int j = 0; j < results.length; ++j) {
            final SuggestionsInfo cur = results[j];
            if (cur != null && cur.getSequence() == item.mTextInfo.getSequence()) {
                result = cur;
                result.setCookieAndSequence(originalCookie, originalSequence);
                break;
            }
        }
        offsets[i] = item.mStart;
        lengths[i] = item.mLength;
        reconstructedSuggestions[i] = result != null ? result : EMPTY_SUGGESTIONS_INFO;
    }
    return new SentenceSuggestionsInfo(reconstructedSuggestions, offsets, lengths);
}
Also used : SentenceSuggestionsInfo(android.view.textservice.SentenceSuggestionsInfo) SentenceSuggestionsInfo(android.view.textservice.SentenceSuggestionsInfo) SuggestionsInfo(android.view.textservice.SuggestionsInfo) TargetApi(android.annotation.TargetApi)

Aggregations

SentenceSuggestionsInfo (android.view.textservice.SentenceSuggestionsInfo)8 SuggestionsInfo (android.view.textservice.SuggestionsInfo)8 Editable (android.text.Editable)6 SpellCheckSpan (android.text.style.SpellCheckSpan)6 TargetApi (android.annotation.TargetApi)2 NgramContext (com.android.inputmethod.latin.NgramContext)1 ArrayList (java.util.ArrayList)1