List of usage examples for android.view.textservice TextInfo TextInfo
public TextInfo(Parcel source)
From source file:com.strathclyde.highlightingkeyboard.SoftKeyboardService.java
/** * Helper function to commit any text being composed in the editor * @param inputConnection our current connection with the editor * @param isWordSeparator /* w w w . j a va2 s . c o m*/ */ private void commitTyped(InputConnection inputConnection, boolean isWordSeparator) { if (mComposing.length() > 0) { //do some spell-checking mComposingTemp = mComposing.toString(); extr = ic.getExtractedText(new ExtractedTextRequest(), 0); WordDetails w = findWord(extr.selectionStart, extr.text); if (w.wordStart >= 0 && w.wordEnd >= 0 && w.wordStart < w.wordEnd) { w.word = extr.text.toString().substring(w.wordStart, extr.selectionStart); System.out.println("Cursor Position = " + extr.selectionStart + " Word=" + w.word); if (w != null && mComposingTemp != null) { if (w.word.length() != mComposingTemp.length()) { mComposingTemp = w.word; if (captureData) ic.setComposingRegion(w.wordStart, extr.selectionStart); } } } if (captureData) // don't want to be spell-checking on urls, emails, passwords { if (mScs != null) //get some suggestions { //Log.i("CommitTyped", "About to spellcheck "+mComposingTemp); mScs.getSuggestions(new TextInfo(mComposingTemp), 5); } else //handle spelling for Samsung devices { //Log.e("CommitTyped", "mScs NULL"); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); String lang = prefs.getString("available_dicts", "el"); XmlResourceParser p; if (lang.equals("en")) p = getResources().getXml(R.xml.qwerty); else p = getResources().getXml(R.xml.greekqwerty); SpellForSamsung sp = new SpellForSamsung(getAssets(), p, getFilesDir() + File.separator + "data", lang, 5); SuggestionsInfo si[] = new SuggestionsInfo[1]; si[0] = sp.spell(mComposingTemp); onGetSuggestions(si); } } else { //Log.i("CommitTyped", "Will not spellcheck in an inappropriate field, mComposing = "+mComposingTemp); inputConnection.commitText(mComposingTemp, mComposingTemp.length()); } } mComposing.setLength(0); updateCandidates(); }
From source file:com.strathclyde.highlightingkeyboard.SoftKeyboardService.java
/** * Update the list of available candidates using the spell-checker (for when a user moves the cursor within a word) * @param word the word to pass into the spell checker *//* w w w. j ava 2 s . c o m*/ public void updateCandidatesWithSpellChecker(String word) { if (mScs != null) { origWord = word; mScs.getSuggestions(new TextInfo(word), 5); updateSuggestionList = true; } else //handle this for Samsung devices { origWord = word; //Log.e("UpdateCandidatesWithSpell", "mScs NULL"); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); String lang = prefs.getString("available_dicts", "el"); XmlResourceParser p; if (lang.equals("en")) p = getResources().getXml(R.xml.qwerty); else p = getResources().getXml(R.xml.greekqwerty); SpellForSamsung sp = new SpellForSamsung(getAssets(), p, getFilesDir() + File.separator + "data", lang, 5); SuggestionsInfo si[] = new SuggestionsInfo[1]; si[0] = sp.spell(word); updateSuggestionList = true; onGetSuggestions(si); //Log.e("updateCandsWithSpell", "mScs NULL"); } }