@OnClick(R.id.btnCheckSpell) public void checkSpellClicked(View view) { if (!etText.getText().toString().isEmpty()) { tvResult.setText(""); if (spellCheckerSession != null) { spellCheckerSession.getSentenceSuggestions( new TextInfo[]{new TextInfo(etText.getText().toString())}, 1); } else { Log.e("TAG_SPELL", "Couldn't obtain the spell checker service."); } } }
/** * Queries the input text against the SpellCheckerSession. * @param text Text to be queried. */ @CalledByNative private void requestTextCheck(String text) { // SpellCheckerSession thinks that any word ending with a period is a typo. // We trim the period off before sending the text for spellchecking in order to avoid // unnecessary red underlines when the user ends a sentence with a period. // Filed as an Android bug here: https://code.google.com/p/android/issues/detail?id=183294 if (text.endsWith(".")) { text = text.substring(0, text.length() - 1); } mSpellCheckerSession.getSentenceSuggestions(new TextInfo[] {new TextInfo(text)}, 0); }
/** * Update the list of available candidates from the current composing * text. This will need to be filled in by however you are determining * candidates. */ private void updateCandidates() { if (!mCompletionOn) { if (mComposing.length() > 0) { ArrayList<String> list = new ArrayList<String>(); list.add(mComposing.toString()); mScs.getSentenceSuggestions(new TextInfo[] {new TextInfo(mComposing.toString())}, 5); setSuggestions(list, true, true); } else { setSuggestions(null, false, false); } } }
/** * Update the list of available candidates from the current composing * text. This will need to be filled in by however you are determining * candidates. */ private void updateCandidates() { if (!mCompletionOn) { if (mComposing.length() > 0) { ArrayList<String> list = new ArrayList<String>(); //list.add(mComposing.toString()); Log.d("SoftKeyboard", "REQUESTING: " + mComposing.toString()); mScs.getSentenceSuggestions(new TextInfo[] {new TextInfo(mComposing.toString())}, 5); setSuggestions(list, true, true); } else { setSuggestions(null, false, false); } } }
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"); } } } }