/** * 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)); }
public class SpellChecker implements SpellCheckerSessionListener { public SpellChecker(Activity a) { final TextServicesManager tsm = (TextServicesManager) a.getSystemService( Context.TEXT_SERVICES_MANAGER_SERVICE); SpellCheckerSession scs = tsm.newSpellCheckerSession(null, null, this, true); TextInfo[] tia = {new TextInfo("trewgjj"), new TextInfo("great")}; scs.getSentenceSuggestions(tia, 3); } @Override public void onGetSuggestions(SuggestionsInfo[] results) { // TODO Auto-generated method stub } @Override public void onGetSentenceSuggestions(SentenceSuggestionsInfo[] results) { for (int i = 0; i < results.length; ++i) { // Returned suggestions are contained in SuggestionsInfo for (int j = 0; j < results[i].getSuggestionsCount(); ++j) { SuggestionsInfo si = results[i].getSuggestionsInfoAt(j); if ((si.getSuggestionsAttributes() & SuggestionsInfo.RESULT_ATTR_IN_THE_DICTIONARY) != 0) Log.d("", "EXACT MATCH FOUND"); } } } }