Java Code Examples for android.view.textservice.SuggestionsInfo#RESULT_ATTR_LOOKS_LIKE_TYPO
The following examples show how to use
android.view.textservice.SuggestionsInfo#RESULT_ATTR_LOOKS_LIKE_TYPO .
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: SpellCheckerSessionBridge.java From delion with Apache License 2.0 | 6 votes |
/** * Checks for typos and sends results back to native through a JNI call. * @param results Results returned by the Android spellchecker. */ @Override public void onGetSentenceSuggestions(SentenceSuggestionsInfo[] results) { ArrayList<Integer> offsets = new ArrayList<Integer>(); ArrayList<Integer> lengths = new ArrayList<Integer>(); for (SentenceSuggestionsInfo result : results) { for (int i = 0; i < result.getSuggestionsCount(); i++) { // If a word looks like a typo, record its offset and length. if ((result.getSuggestionsInfoAt(i).getSuggestionsAttributes() & SuggestionsInfo.RESULT_ATTR_LOOKS_LIKE_TYPO) == SuggestionsInfo.RESULT_ATTR_LOOKS_LIKE_TYPO) { offsets.add(result.getOffsetAt(i)); lengths.add(result.getLengthAt(i)); } } } nativeProcessSpellCheckResults(mNativeSpellCheckerSessionBridge, convertListToArray(offsets), convertListToArray(lengths)); }
Example 2
Source File: SpellCheckerSessionBridge.java From 365browser with Apache License 2.0 | 5 votes |
/** * Checks for typos and sends results back to native through a JNI call. * @param results Results returned by the Android spellchecker. */ @Override public void onGetSentenceSuggestions(SentenceSuggestionsInfo[] results) { mStopMs = SystemClock.elapsedRealtime(); if (mNativeSpellCheckerSessionBridge == 0) { return; } ArrayList<Integer> offsets = new ArrayList<Integer>(); ArrayList<Integer> lengths = new ArrayList<Integer>(); for (SentenceSuggestionsInfo result : results) { if (result == null) { // In some cases null can be returned by the selected spellchecking service, // see crbug.com/651458. In this case skip to next result to avoid a // NullPointerException later on. continue; } for (int i = 0; i < result.getSuggestionsCount(); i++) { // If a word looks like a typo, record its offset and length. if ((result.getSuggestionsInfoAt(i).getSuggestionsAttributes() & SuggestionsInfo.RESULT_ATTR_LOOKS_LIKE_TYPO) == SuggestionsInfo.RESULT_ATTR_LOOKS_LIKE_TYPO) { offsets.add(result.getOffsetAt(i)); lengths.add(result.getLengthAt(i)); } } } nativeProcessSpellCheckResults(mNativeSpellCheckerSessionBridge, convertListToArray(offsets), convertListToArray(lengths)); RecordHistogram.recordTimesHistogram("SpellCheck.Android.Latency", mStopMs - mStartMs, TimeUnit.MILLISECONDS); }
Example 3
Source File: SpellChecker.java From android_9.0.0_r45 with Apache License 2.0 | 4 votes |
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]; //TODO: we need to change that rule for results from a sentence-level spell // 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; }
Example 4
Source File: AndroidSpellCheckerService.java From openboard with GNU General Public License v3.0 | 2 votes |
/** * Returns an empty SuggestionsInfo with flags signaling the word is not in the dictionary. * @param reportAsTypo whether this should include the flag LOOKS_LIKE_TYPO, for red underline. * @return the empty SuggestionsInfo with the appropriate flags set. */ public static SuggestionsInfo getNotInDictEmptySuggestions(final boolean reportAsTypo) { return new SuggestionsInfo(reportAsTypo ? SuggestionsInfo.RESULT_ATTR_LOOKS_LIKE_TYPO : 0, EMPTY_STRING_ARRAY); }
Example 5
Source File: AndroidSpellCheckerService.java From Android-Keyboard with Apache License 2.0 | 2 votes |
/** * Returns an empty SuggestionsInfo with flags signaling the word is not in the dictionary. * @param reportAsTypo whether this should include the flag LOOKS_LIKE_TYPO, for red underline. * @return the empty SuggestionsInfo with the appropriate flags set. */ public static SuggestionsInfo getNotInDictEmptySuggestions(final boolean reportAsTypo) { return new SuggestionsInfo(reportAsTypo ? SuggestionsInfo.RESULT_ATTR_LOOKS_LIKE_TYPO : 0, EMPTY_STRING_ARRAY); }
Example 6
Source File: AndroidSpellCheckerService.java From AOSP-Kayboard-7.1.2 with Apache License 2.0 | 2 votes |
/** * Returns an empty SuggestionsInfo with flags signaling the word is not in the dictionary. * @param reportAsTypo whether this should include the flag LOOKS_LIKE_TYPO, for red underline. * @return the empty SuggestionsInfo with the appropriate flags set. */ public static SuggestionsInfo getNotInDictEmptySuggestions(final boolean reportAsTypo) { return new SuggestionsInfo(reportAsTypo ? SuggestionsInfo.RESULT_ATTR_LOOKS_LIKE_TYPO : 0, EMPTY_STRING_ARRAY); }
Example 7
Source File: AndroidSpellCheckerService.java From Indic-Keyboard with Apache License 2.0 | 2 votes |
/** * Returns an empty SuggestionsInfo with flags signaling the word is not in the dictionary. * @param reportAsTypo whether this should include the flag LOOKS_LIKE_TYPO, for red underline. * @return the empty SuggestionsInfo with the appropriate flags set. */ public static SuggestionsInfo getNotInDictEmptySuggestions(final boolean reportAsTypo) { return new SuggestionsInfo(reportAsTypo ? SuggestionsInfo.RESULT_ATTR_LOOKS_LIKE_TYPO : 0, EMPTY_STRING_ARRAY); }