Java Code Examples for android.view.textservice.TextInfo#getCookie()

The following examples show how to use android.view.textservice.TextInfo#getCookie() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SentenceLevelAdapter.java    From openboard with GNU General Public License v3.0 6 votes vote down vote up
public SentenceTextInfoParams getSplitWords(TextInfo originalTextInfo) {
    final WordIterator wordIterator = mWordIterator;
    final CharSequence originalText =
            TextInfoCompatUtils.getCharSequenceOrString(originalTextInfo);
    final int cookie = originalTextInfo.getCookie();
    final int start = -1;
    final int end = originalText.length();
    final ArrayList<SentenceWordItem> wordItems = new ArrayList<>();
    int wordStart = wordIterator.getBeginningOfNextWord(originalText, start);
    int wordEnd = wordIterator.getEndOfWord(originalText, wordStart);
    while (wordStart <= end && wordEnd != -1 && wordStart != -1) {
        if (wordEnd >= start && wordEnd > wordStart) {
            final TextInfo ti = TextInfoCompatUtils.newInstance(originalText, wordStart,
                    wordEnd, cookie, originalText.subSequence(wordStart, wordEnd).hashCode());
            wordItems.add(new SentenceWordItem(ti, wordStart, wordEnd));
        }
        wordStart = wordIterator.getBeginningOfNextWord(originalText, wordEnd);
        if (wordStart == -1) {
            break;
        }
        wordEnd = wordIterator.getEndOfWord(originalText, wordStart);
    }
    return new SentenceTextInfoParams(originalTextInfo, wordItems);
}
 
Example 2
Source File: SentenceLevelAdapter.java    From Android-Keyboard with Apache License 2.0 6 votes vote down vote up
public SentenceTextInfoParams getSplitWords(TextInfo originalTextInfo) {
    final WordIterator wordIterator = mWordIterator;
    final CharSequence originalText =
            TextInfoCompatUtils.getCharSequenceOrString(originalTextInfo);
    final int cookie = originalTextInfo.getCookie();
    final int start = -1;
    final int end = originalText.length();
    final ArrayList<SentenceWordItem> wordItems = new ArrayList<>();
    int wordStart = wordIterator.getBeginningOfNextWord(originalText, start);
    int wordEnd = wordIterator.getEndOfWord(originalText, wordStart);
    while (wordStart <= end && wordEnd != -1 && wordStart != -1) {
        if (wordEnd >= start && wordEnd > wordStart) {
            final TextInfo ti = TextInfoCompatUtils.newInstance(originalText, wordStart,
                    wordEnd, cookie, originalText.subSequence(wordStart, wordEnd).hashCode());
            wordItems.add(new SentenceWordItem(ti, wordStart, wordEnd));
        }
        wordStart = wordIterator.getBeginningOfNextWord(originalText, wordEnd);
        if (wordStart == -1) {
            break;
        }
        wordEnd = wordIterator.getEndOfWord(originalText, wordStart);
    }
    return new SentenceTextInfoParams(originalTextInfo, wordItems);
}
 
Example 3
Source File: SentenceLevelAdapter.java    From AOSP-Kayboard-7.1.2 with Apache License 2.0 6 votes vote down vote up
public SentenceTextInfoParams getSplitWords(TextInfo originalTextInfo) {
    final WordIterator wordIterator = mWordIterator;
    final CharSequence originalText =
            TextInfoCompatUtils.getCharSequenceOrString(originalTextInfo);
    final int cookie = originalTextInfo.getCookie();
    final int start = -1;
    final int end = originalText.length();
    final ArrayList<SentenceWordItem> wordItems = new ArrayList<>();
    int wordStart = wordIterator.getBeginningOfNextWord(originalText, start);
    int wordEnd = wordIterator.getEndOfWord(originalText, wordStart);
    while (wordStart <= end && wordEnd != -1 && wordStart != -1) {
        if (wordEnd >= start && wordEnd > wordStart) {
            final TextInfo ti = TextInfoCompatUtils.newInstance(originalText, wordStart,
                    wordEnd, cookie, originalText.subSequence(wordStart, wordEnd).hashCode());
            wordItems.add(new SentenceWordItem(ti, wordStart, wordEnd));
        }
        wordStart = wordIterator.getBeginningOfNextWord(originalText, wordEnd);
        if (wordStart == -1) {
            break;
        }
        wordEnd = wordIterator.getEndOfWord(originalText, wordStart);
    }
    return new SentenceTextInfoParams(originalTextInfo, wordItems);
}
 
Example 4
Source File: SentenceLevelAdapter.java    From Indic-Keyboard with Apache License 2.0 6 votes vote down vote up
public SentenceTextInfoParams getSplitWords(TextInfo originalTextInfo) {
    final WordIterator wordIterator = mWordIterator;
    final CharSequence originalText =
            TextInfoCompatUtils.getCharSequenceOrString(originalTextInfo);
    final int cookie = originalTextInfo.getCookie();
    final int start = -1;
    final int end = originalText.length();
    final ArrayList<SentenceWordItem> wordItems = new ArrayList<>();
    int wordStart = wordIterator.getBeginningOfNextWord(originalText, start);
    int wordEnd = wordIterator.getEndOfWord(originalText, wordStart);
    while (wordStart <= end && wordEnd != -1 && wordStart != -1) {
        if (wordEnd >= start && wordEnd > wordStart) {
            final TextInfo ti = TextInfoCompatUtils.newInstance(originalText, wordStart,
                    wordEnd, cookie, originalText.subSequence(wordStart, wordEnd).hashCode());
            wordItems.add(new SentenceWordItem(ti, wordStart, wordEnd));
        }
        wordStart = wordIterator.getBeginningOfNextWord(originalText, wordEnd);
        if (wordStart == -1) {
            break;
        }
        wordEnd = wordIterator.getEndOfWord(originalText, wordStart);
    }
    return new SentenceTextInfoParams(originalTextInfo, wordItems);
}
 
Example 5
Source File: SpellCheckerService.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
private SentenceTextInfoParams getSplitWords(TextInfo originalTextInfo) {
    final WordIterator wordIterator = mWordIterator;
    final CharSequence originalText = originalTextInfo.getText();
    final int cookie = originalTextInfo.getCookie();
    final int start = 0;
    final int end = originalText.length();
    final ArrayList<SentenceWordItem> wordItems = new ArrayList<SentenceWordItem>();
    wordIterator.setCharSequence(originalText, 0, originalText.length());
    int wordEnd = wordIterator.following(start);
    int wordStart = wordIterator.getBeginning(wordEnd);
    if (DBG) {
        Log.d(TAG, "iterator: break: ---- 1st word start = " + wordStart + ", end = "
                + wordEnd + "\n" + originalText);
    }
    while (wordStart <= end && wordEnd != BreakIterator.DONE
            && wordStart != BreakIterator.DONE) {
        if (wordEnd >= start && wordEnd > wordStart) {
            final CharSequence query = originalText.subSequence(wordStart, wordEnd);
            final TextInfo ti = new TextInfo(query, 0, query.length(), cookie,
                    query.hashCode());
            wordItems.add(new SentenceWordItem(ti, wordStart, wordEnd));
            if (DBG) {
                Log.d(TAG, "Adapter: word (" + (wordItems.size() - 1) + ") " + query);
            }
        }
        wordEnd = wordIterator.following(wordEnd);
        if (wordEnd == BreakIterator.DONE) {
            break;
        }
        wordStart = wordIterator.getBeginning(wordEnd);
    }
    return new SentenceTextInfoParams(originalTextInfo, wordItems);
}