List of usage examples for android.view.inputmethod InputConnection commitText
boolean commitText(CharSequence text, int newCursorPosition);
From source file:research.sg.edu.edapp.kb.KbSoftKeyboard.java
public void onKey(int primaryCode, int[] keyCodes) { /*String tap_file_name; String currentmood = "-99";/*from w w w . j ava2s. c o m*/ boolean esm_event=false,esm_signal=false,esm_time=false; //SimpleDateFormat sdf = new SimpleDateFormat("yyyy:MM:dd__HH:mm:ss.SSS"); SimpleDateFormat sdf = new SimpleDateFormat(getResources().getString(R.string.time_format)); String currentDateandTime = sdf.format(new Date()); //boolean mood_rdy_to_record; //Store the timestamp in SharedPref //SharedPreferences prefs = getApplicationContext().getSharedPreferences(getResources().getString(R.string.sharedpref_file), Context.MODE_WORLD_READABLE); SharedPreferences prefs = getApplicationContext().getSharedPreferences(getApplicationContext().getResources().getString(R.string.sharedpref_file), Context.MODE_WORLD_READABLE); //currentDateandTime1=prefs.getString("TimeStamp", "No Data"); //System.out.println("[TimeStamp:"+currentDateandTime1+"]"); //SharedPreferences.Editor editor = prefs.edit(); SharedPreferences.Editor seditor =prefs.edit(); seditor.putString(getResources().getString(R.string.sharedpref_tstamp), currentDateandTime); seditor.putString(getResources().getString(R.string.sharedpref_last_app_name), getAppName()); seditor.putBoolean(getResources().getString(R.string.sharedpref_mood_rdy_to_record), true); //seditor.putString(getResources().getString(R.string.sharedpref_last_app_name), getAppName()); //editor.apply(); seditor.apply(); seditor.commit(); //System.out.println("Current Mood to Record:"+prefs.getBoolean(getResources().getString(R.string.sharedpref_mood_rdy_to_record),false)); //Retrieve current mood from sharedpref try { Context con = getApplicationContext().createPackageContext(getResources().getString(R.string.moodrecorder_pkg), Context.CONTEXT_IGNORE_SECURITY); SharedPreferences mood_pref = con.getSharedPreferences(getResources().getString(R.string.tap_mood_sharedpref_file), Context.MODE_MULTI_PROCESS); currentmood = mood_pref.getString(getResources().getString(R.string.sharedpref_current_mood), "-99"); esm_event = mood_pref.getBoolean(getResources().getString(R.string.sharedpref_esm_event),false); esm_signal = mood_pref.getBoolean(getResources().getString(R.string.sharedpref_esm_signal),false); esm_time = mood_pref.getBoolean(getResources().getString(R.string.sharedpref_esm_time),false); System.out.println("Current Mood:" + currentmood); } catch (Exception e) { e.printStackTrace(); }*/ SimpleDateFormat sdf = new SimpleDateFormat(getResources().getString(R.string.time_format)); String currentDateandTime = sdf.format(new Date()); ContentValues values = new ContentValues(); values.put(KbTouchEvent.TouchEntry.TE_APP_NAME, getAppName()); values.put(KbTouchEvent.TouchEntry.TE_TIMESTAMP, currentDateandTime); //values.put(TouchEvent.TouchEntry.TE_KEY, String.valueOf((char)primaryCode)); values.put(KbTouchEvent.TouchEntry.TE_KEY, primaryCode); Uri uri = getContentResolver().insert(KbContentProvider.CONTENT_URI, values); //End of retrieving current mood from sharedpref //currentDateandTime1=prefs.getString("TimeStamp", "No Data"); //System.out.println("[TimeStamp:"+currentDateandTime1+"]"); String keypress = String.valueOf((char) primaryCode); Log.d("Key Pressed", keypress); System.out.println("Ascii value:" + (int) keypress.charAt(0)); /*if(Character.va >=){ }*/ //System.out.println("Alternate way key pressed:"+Character.toChars(primaryCode)[0]); /*String string_t; //string_t = currentDateandTime+ " ----> " + "X = " + x_Coordinate + ", Y = "+y_Coordinate+ "\n"; //string_t = getAppName() + "," + currentDateandTime+ "," + keypress + "\n"; string_t = getAppName() + "," + currentDateandTime + "," + currentmood + "," + esm_event + "," + esm_signal + "," + esm_time + "\n"; //tap_file_name = imei_no + getResources().getString(R.string.tap_file_postfix); tap_file_name = imei_no + "_" + tap_ctr + getResources().getString(R.string.tap_file_postfix); File tap_file = new File(dataDir, tap_file_name); try{ //String SDCARD = Environment.getExternalStorageDirectory().getAbsolutePath(); //String FILENAME = "keylogger.txt"; //File outfile = new File(SDCARD+File.separator+FILENAME); FileOutputStream fos = new FileOutputStream(tap_file,true); fos.write(string_t.getBytes()); fos.close(); }catch(Exception e) { Log.d("EXCEPTION",e.getMessage()); } //Checks file size and move to ToBeUploaded folder int tap_file_size = Integer.parseInt(String.valueOf(tap_file.length() / 1024)); //mood_file_size = mood_file_size /4; int tap_file_size_threshold = Integer.parseInt(getResources().getString(R.string.tap_file_size_limit)); System.out.println("Tap File Size:" + tap_file_size + ", Tap File Threshold:" + tap_file_size_threshold ); if (tap_file_size > tap_file_size_threshold) { int ctr = Integer.parseInt(tap_ctr) + 1; tap_ctr=String.valueOf(ctr); tap_ctr=String.format("%06d", Integer.parseInt(tap_ctr)); //String.format("%05d", Integer.parseInt(mood_ctr)); move_file(tap_file_name); }*/ /********************************************************important edit edit 6****************************************/ InputConnection ic = getCurrentInputConnection(); // playClick(primaryCode) String suggested_string = ""; /***********************************************************check edit***********************************************/ if (isWordSeparator(primaryCode)) { // Handle separator if (mComposing.length() > 0) { commitTyped(getCurrentInputConnection()); swipe = ""; } sendKey(primaryCode); updateShiftKeyState(getCurrentInputEditorInfo()); } else if (primaryCode == Keyboard.KEYCODE_DELETE) { handleBackspace(); } else if (primaryCode == Keyboard.KEYCODE_SHIFT) { handleShift(); } else if (primaryCode == Keyboard.KEYCODE_CANCEL) { handleClose(); return; } else if (primaryCode == KbLatinKeyboardView.KEYCODE_OPTIONS) { // Show a menu or somethin' } else if (primaryCode == Keyboard.KEYCODE_MODE_CHANGE && mInputView != null) { Keyboard current = mInputView.getKeyboard(); if (current == mSymbolsKeyboard || current == mSymbolsShiftedKeyboard) { current = mQwertyKeyboard; } else { current = mSymbolsKeyboard; } mInputView.setKeyboard(current); if (current == mSymbolsKeyboard) { current.setShifted(false); } } else { /****************************************************************8default handling******************************************/ char code = (char) primaryCode; if (swipe2.length() != 0 && code != swipe2.charAt(swipe2.length() - 1)) { swipe2 += "+" + code; } if (frequent_char == 0 || frequent_char == code || frequent_char == test.charAt(0)) test += ".*" + code; else test += ".*" + frequent_char + ".*" + code; Log.d("Pattern", test); if (Character.isLetter(code) && mCapsLock) { code = Character.toUpperCase(code); } if (swipe2.length() < 3) { ic.commitText(String.valueOf(code), 1); swipe = ""; swipe2 = ""; } else { suggested_string = strings_matched(test); suggested_string += " "; if (suggested_string.length() <= 1) { ic.commitText(String.valueOf(code), 1); } else ic.commitText(suggested_string, suggested_string.length()); //handleCharacter(primaryCode, keyCodes); } } }
From source file:org.distantshoresmedia.keyboard.LatinIME.java
private void sendTab() { InputConnection ic = getCurrentInputConnection(); boolean tabHack = isConnectbot() && mConnectbotTabHack; // FIXME: tab and ^I don't work in connectbot, hackish workaround if (tabHack) { if (mModAlt) { // send ESC prefix ic.commitText(Character.toString((char) 27), 1); }//from w w w . j av a 2 s .c o m ic.sendKeyEvent(new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_DPAD_CENTER)); ic.sendKeyEvent(new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_DPAD_CENTER)); ic.sendKeyEvent(new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_I)); ic.sendKeyEvent(new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_I)); } else { sendModifiedKeyDownUp(KeyEvent.KEYCODE_TAB); } }
From source file:org.pocketworkstation.pckeyboard.LatinIME.java
private void sendSpecialKey(int code) { if (!isConnectbot()) { commitTyped(getCurrentInputConnection(), true); sendModifiedKeyDownUp(code);// ww w . ja v a 2s . c o m return; } // TODO(klausw): properly support xterm sequences for Ctrl/Alt modifiers? // See http://slackware.osuosl.org/slackware-12.0/source/l/ncurses/xterm.terminfo // and the output of "$ infocmp -1L". Support multiple sets, and optional // true numpad keys? if (ESC_SEQUENCES == null) { ESC_SEQUENCES = new HashMap<Integer, String>(); CTRL_SEQUENCES = new HashMap<Integer, Integer>(); // VT escape sequences without leading Escape ESC_SEQUENCES.put(-LatinKeyboardView.KEYCODE_HOME, "[1~"); ESC_SEQUENCES.put(-LatinKeyboardView.KEYCODE_END, "[4~"); ESC_SEQUENCES.put(-LatinKeyboardView.KEYCODE_PAGE_UP, "[5~"); ESC_SEQUENCES.put(-LatinKeyboardView.KEYCODE_PAGE_DOWN, "[6~"); ESC_SEQUENCES.put(-LatinKeyboardView.KEYCODE_FKEY_F1, "OP"); ESC_SEQUENCES.put(-LatinKeyboardView.KEYCODE_FKEY_F2, "OQ"); ESC_SEQUENCES.put(-LatinKeyboardView.KEYCODE_FKEY_F3, "OR"); ESC_SEQUENCES.put(-LatinKeyboardView.KEYCODE_FKEY_F4, "OS"); ESC_SEQUENCES.put(-LatinKeyboardView.KEYCODE_FKEY_F5, "[15~"); ESC_SEQUENCES.put(-LatinKeyboardView.KEYCODE_FKEY_F6, "[17~"); ESC_SEQUENCES.put(-LatinKeyboardView.KEYCODE_FKEY_F7, "[18~"); ESC_SEQUENCES.put(-LatinKeyboardView.KEYCODE_FKEY_F8, "[19~"); ESC_SEQUENCES.put(-LatinKeyboardView.KEYCODE_FKEY_F9, "[20~"); ESC_SEQUENCES.put(-LatinKeyboardView.KEYCODE_FKEY_F10, "[21~"); ESC_SEQUENCES.put(-LatinKeyboardView.KEYCODE_FKEY_F11, "[23~"); ESC_SEQUENCES.put(-LatinKeyboardView.KEYCODE_FKEY_F12, "[24~"); ESC_SEQUENCES.put(-LatinKeyboardView.KEYCODE_FORWARD_DEL, "[3~"); ESC_SEQUENCES.put(-LatinKeyboardView.KEYCODE_INSERT, "[2~"); // Special ConnectBot hack: Ctrl-1 to Ctrl-0 for F1-F10. CTRL_SEQUENCES.put(-LatinKeyboardView.KEYCODE_FKEY_F1, KeyEvent.KEYCODE_1); CTRL_SEQUENCES.put(-LatinKeyboardView.KEYCODE_FKEY_F2, KeyEvent.KEYCODE_2); CTRL_SEQUENCES.put(-LatinKeyboardView.KEYCODE_FKEY_F3, KeyEvent.KEYCODE_3); CTRL_SEQUENCES.put(-LatinKeyboardView.KEYCODE_FKEY_F4, KeyEvent.KEYCODE_4); CTRL_SEQUENCES.put(-LatinKeyboardView.KEYCODE_FKEY_F5, KeyEvent.KEYCODE_5); CTRL_SEQUENCES.put(-LatinKeyboardView.KEYCODE_FKEY_F6, KeyEvent.KEYCODE_6); CTRL_SEQUENCES.put(-LatinKeyboardView.KEYCODE_FKEY_F7, KeyEvent.KEYCODE_7); CTRL_SEQUENCES.put(-LatinKeyboardView.KEYCODE_FKEY_F8, KeyEvent.KEYCODE_8); CTRL_SEQUENCES.put(-LatinKeyboardView.KEYCODE_FKEY_F9, KeyEvent.KEYCODE_9); CTRL_SEQUENCES.put(-LatinKeyboardView.KEYCODE_FKEY_F10, KeyEvent.KEYCODE_0); // Natively supported by ConnectBot // ESC_SEQUENCES.put(-LatinKeyboardView.KEYCODE_DPAD_UP, "OA"); // ESC_SEQUENCES.put(-LatinKeyboardView.KEYCODE_DPAD_DOWN, "OB"); // ESC_SEQUENCES.put(-LatinKeyboardView.KEYCODE_DPAD_LEFT, "OD"); // ESC_SEQUENCES.put(-LatinKeyboardView.KEYCODE_DPAD_RIGHT, "OC"); // No VT equivalents? // ESC_SEQUENCES.put(-LatinKeyboardView.KEYCODE_DPAD_CENTER, ""); // ESC_SEQUENCES.put(-LatinKeyboardView.KEYCODE_SYSRQ, ""); // ESC_SEQUENCES.put(-LatinKeyboardView.KEYCODE_BREAK, ""); // ESC_SEQUENCES.put(-LatinKeyboardView.KEYCODE_NUM_LOCK, ""); // ESC_SEQUENCES.put(-LatinKeyboardView.KEYCODE_SCROLL_LOCK, ""); } InputConnection ic = getCurrentInputConnection(); Integer ctrlseq = null; if (mConnectbotTabHack) { ctrlseq = CTRL_SEQUENCES.get(code); } String seq = ESC_SEQUENCES.get(code); if (ctrlseq != null) { if (mModAlt) { // send ESC prefix for "Alt" ic.commitText(Character.toString((char) 27), 1); } ic.sendKeyEvent(new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_DPAD_CENTER)); ic.sendKeyEvent(new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_DPAD_CENTER)); ic.sendKeyEvent(new KeyEvent(KeyEvent.ACTION_DOWN, ctrlseq)); ic.sendKeyEvent(new KeyEvent(KeyEvent.ACTION_UP, ctrlseq)); } else if (seq != null) { if (mModAlt) { // send ESC prefix for "Alt" ic.commitText(Character.toString((char) 27), 1); } // send ESC prefix of escape sequence ic.commitText(Character.toString((char) 27), 1); ic.commitText(seq, 1); } else { // send key code, let connectbot handle it sendDownUpKeyEvents(code); } handleModifierKeysUp(false, false); }
From source file:org.distantshoresmedia.keyboard.LatinIME.java
private void swapPunctuationAndSpace() { final InputConnection ic = getCurrentInputConnection(); if (ic == null) return;/*w ww . ja v a 2s .c om*/ CharSequence lastTwo = ic.getTextBeforeCursor(2, 0); if (lastTwo != null && lastTwo.length() == 2 && lastTwo.charAt(0) == ASCII_SPACE && isSentenceSeparator(lastTwo.charAt(1))) { ic.beginBatchEdit(); ic.deleteSurroundingText(2, 0); ic.commitText(lastTwo.charAt(1) + " ", 1); ic.endBatchEdit(); updateShiftKeyState(getCurrentInputEditorInfo()); mJustAddedAutoSpace = true; } }
From source file:org.distantshoresmedia.keyboard.LatinIME.java
private void sendSpecialKey(int code) { if (!isConnectbot()) { commitTyped(getCurrentInputConnection(), true); sendModifiedKeyDownUp(code);/* w ww. j a v a 2 s. com*/ return; } // TODO(klausw): properly support xterm sequences for Ctrl/Alt modifiers? // See http://slackware.osuosl.org/slackware-12.0/source/l/ncurses/xterm.terminfo // and the output of "$ infocmp -1L". Support multiple sets, and optional // true numpad keys? if (ESC_SEQUENCES == null) { ESC_SEQUENCES = new HashMap<Integer, String>(); CTRL_SEQUENCES = new HashMap<Integer, Integer>(); // VT escape sequences without leading Escape ESC_SEQUENCES.put(-TKKeyboardView.KEYCODE_HOME, "[1~"); ESC_SEQUENCES.put(-TKKeyboardView.KEYCODE_END, "[4~"); ESC_SEQUENCES.put(-TKKeyboardView.KEYCODE_PAGE_UP, "[5~"); ESC_SEQUENCES.put(-TKKeyboardView.KEYCODE_PAGE_DOWN, "[6~"); ESC_SEQUENCES.put(-TKKeyboardView.KEYCODE_FKEY_F1, "OP"); ESC_SEQUENCES.put(-TKKeyboardView.KEYCODE_FKEY_F2, "OQ"); ESC_SEQUENCES.put(-TKKeyboardView.KEYCODE_FKEY_F3, "OR"); ESC_SEQUENCES.put(-TKKeyboardView.KEYCODE_FKEY_F4, "OS"); ESC_SEQUENCES.put(-TKKeyboardView.KEYCODE_FKEY_F5, "[15~"); ESC_SEQUENCES.put(-TKKeyboardView.KEYCODE_FKEY_F6, "[17~"); ESC_SEQUENCES.put(-TKKeyboardView.KEYCODE_FKEY_F7, "[18~"); ESC_SEQUENCES.put(-TKKeyboardView.KEYCODE_FKEY_F8, "[19~"); ESC_SEQUENCES.put(-TKKeyboardView.KEYCODE_FKEY_F9, "[20~"); ESC_SEQUENCES.put(-TKKeyboardView.KEYCODE_FKEY_F10, "[21~"); ESC_SEQUENCES.put(-TKKeyboardView.KEYCODE_FKEY_F11, "[23~"); ESC_SEQUENCES.put(-TKKeyboardView.KEYCODE_FKEY_F12, "[24~"); ESC_SEQUENCES.put(-TKKeyboardView.KEYCODE_FORWARD_DEL, "[3~"); ESC_SEQUENCES.put(-TKKeyboardView.KEYCODE_INSERT, "[2~"); // Special ConnectBot hack: Ctrl-1 to Ctrl-0 for F1-F10. CTRL_SEQUENCES.put(-TKKeyboardView.KEYCODE_FKEY_F1, KeyEvent.KEYCODE_1); CTRL_SEQUENCES.put(-TKKeyboardView.KEYCODE_FKEY_F2, KeyEvent.KEYCODE_2); CTRL_SEQUENCES.put(-TKKeyboardView.KEYCODE_FKEY_F3, KeyEvent.KEYCODE_3); CTRL_SEQUENCES.put(-TKKeyboardView.KEYCODE_FKEY_F4, KeyEvent.KEYCODE_4); CTRL_SEQUENCES.put(-TKKeyboardView.KEYCODE_FKEY_F5, KeyEvent.KEYCODE_5); CTRL_SEQUENCES.put(-TKKeyboardView.KEYCODE_FKEY_F6, KeyEvent.KEYCODE_6); CTRL_SEQUENCES.put(-TKKeyboardView.KEYCODE_FKEY_F7, KeyEvent.KEYCODE_7); CTRL_SEQUENCES.put(-TKKeyboardView.KEYCODE_FKEY_F8, KeyEvent.KEYCODE_8); CTRL_SEQUENCES.put(-TKKeyboardView.KEYCODE_FKEY_F9, KeyEvent.KEYCODE_9); CTRL_SEQUENCES.put(-TKKeyboardView.KEYCODE_FKEY_F10, KeyEvent.KEYCODE_0); // Natively supported by ConnectBot // ESC_SEQUENCES.put(-LatinKeyboardView.KEYCODE_DPAD_UP, "OA"); // ESC_SEQUENCES.put(-LatinKeyboardView.KEYCODE_DPAD_DOWN, "OB"); // ESC_SEQUENCES.put(-LatinKeyboardView.KEYCODE_DPAD_LEFT, "OD"); // ESC_SEQUENCES.put(-LatinKeyboardView.KEYCODE_DPAD_RIGHT, "OC"); // No VT equivalents? // ESC_SEQUENCES.put(-LatinKeyboardView.KEYCODE_DPAD_CENTER, ""); // ESC_SEQUENCES.put(-LatinKeyboardView.KEYCODE_SYSRQ, ""); // ESC_SEQUENCES.put(-LatinKeyboardView.KEYCODE_BREAK, ""); // ESC_SEQUENCES.put(-LatinKeyboardView.KEYCODE_NUM_LOCK, ""); // ESC_SEQUENCES.put(-LatinKeyboardView.KEYCODE_SCROLL_LOCK, ""); } InputConnection ic = getCurrentInputConnection(); Integer ctrlseq = null; if (mConnectbotTabHack) { ctrlseq = CTRL_SEQUENCES.get(code); } String seq = ESC_SEQUENCES.get(code); if (ctrlseq != null) { if (mModAlt) { // send ESC prefix for "Alt" ic.commitText(Character.toString((char) 27), 1); } ic.sendKeyEvent(new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_DPAD_CENTER)); ic.sendKeyEvent(new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_DPAD_CENTER)); ic.sendKeyEvent(new KeyEvent(KeyEvent.ACTION_DOWN, ctrlseq)); ic.sendKeyEvent(new KeyEvent(KeyEvent.ACTION_UP, ctrlseq)); } else if (seq != null) { if (mModAlt) { // send ESC prefix for "Alt" ic.commitText(Character.toString((char) 27), 1); } // send ESC prefix of escape sequence ic.commitText(Character.toString((char) 27), 1); ic.commitText(seq, 1); } else { // send key code, let connectbot handle it sendDownUpKeyEvents(code); } handleModifierKeysUp(false, false); }
From source file:org.distantshoresmedia.keyboard.LatinIME.java
private void reswapPeriodAndSpace() { final InputConnection ic = getCurrentInputConnection(); if (ic == null) return;/*from w ww .j ava2 s . com*/ CharSequence lastThree = ic.getTextBeforeCursor(3, 0); if (lastThree != null && lastThree.length() == 3 && lastThree.charAt(0) == ASCII_PERIOD && lastThree.charAt(1) == ASCII_SPACE && lastThree.charAt(2) == ASCII_PERIOD) { ic.beginBatchEdit(); ic.deleteSurroundingText(3, 0); ic.commitText(" ..", 1); ic.endBatchEdit(); updateShiftKeyState(getCurrentInputEditorInfo()); } }
From source file:org.distantshoresmedia.keyboard.LatinIME.java
private void doubleSpace() { // if (!mAutoPunctuate) return; if (mCorrectionMode == Suggest.CORRECTION_NONE) return;//from ww w.j av a 2 s . com final InputConnection ic = getCurrentInputConnection(); if (ic == null) return; CharSequence lastThree = ic.getTextBeforeCursor(3, 0); if (lastThree != null && lastThree.length() == 3 && Character.isLetterOrDigit(lastThree.charAt(0)) && lastThree.charAt(1) == ASCII_SPACE && lastThree.charAt(2) == ASCII_SPACE) { ic.beginBatchEdit(); ic.deleteSurroundingText(2, 0); ic.commitText(". ", 1); ic.endBatchEdit(); updateShiftKeyState(getCurrentInputEditorInfo()); mJustAddedAutoSpace = true; } }
From source file:org.distantshoresmedia.keyboard.LatinIME.java
public void onText(CharSequence text) { //mDeadAccentBuffer.clear(); // FIXME InputConnection ic = getCurrentInputConnection(); if (ic == null) return;//from w w w .j av a 2 s . c o m if (mPredicting && text.length() == 1) { // If adding a single letter, treat it as a regular keystroke so // that completion works as expected. int c = text.charAt(0); if (!isWordSeparator(c)) { int[] codes = { c }; handleCharacter(c, codes); return; } } abortCorrection(false); ic.beginBatchEdit(); if (mPredicting) { commitTyped(ic, true); } maybeRemovePreviousPeriod(text); ic.commitText(text, 1); ic.endBatchEdit(); updateShiftKeyState(getCurrentInputEditorInfo()); mKeyboardSwitcher.onKey(0); // dummy key code. mJustRevertedSeparator = null; mJustAddedAutoSpace = false; mEnteredText = text; }
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 //from w w w . j a v a2s . co 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.anysoftkeyboard.AnySoftKeyboard.java
private void handleSeparator(int primaryCode) { // Issue 146: Right to left languages require reversed parenthesis if (!getCurrentAlphabetKeyboard().isLeftToRightLanguage()) { if (primaryCode == (int) ')') primaryCode = (int) '('; else if (primaryCode == (int) '(') primaryCode = (int) ')'; }/*from w w w.j ava 2 s.co m*/ mExpectingSelectionUpdateBy = SystemClock.uptimeMillis() + MAX_TIME_TO_EXPECT_SELECTION_UPDATE; //will not show next-word suggestion in case of a new line or if the separator is a sentence separator. boolean isEndOfSentence = (primaryCode == KeyCodes.ENTER || mSentenceSeparators.get(primaryCode)); // Should dismiss the "Touch again to save" message when handling // separator if (mCandidateView != null && mCandidateView.dismissAddToDictionaryHint()) { postUpdateSuggestions(); } // Handle separator InputConnection ic = getCurrentInputConnection(); if (ic != null) { ic.beginBatchEdit(); } // this is a special case, when the user presses a separator WHILE // inside the predicted word. // in this case, I will want to just dump the separator. final boolean separatorInsideWord = (mWord.cursorPosition() < mWord.length()); if (TextEntryState.isPredicting() && !separatorInsideWord) { //ACTION does not invoke default picking. See https://github.com/AnySoftKeyboard/AnySoftKeyboard/issues/198 pickDefaultSuggestion(mAutoCorrectOn && primaryCode != KeyCodes.ENTER); // Picked the suggestion by a space/punctuation character: we will treat it // as "added an auto space". mJustAddedAutoSpace = true; } else if (separatorInsideWord) { // when putting a separator in the middle of a word, there is no // need to do correction, or keep knowledge abortCorrectionAndResetPredictionState(false); } if (mJustAddedAutoSpace && primaryCode == KeyCodes.ENTER) { removeTrailingSpace(); mJustAddedAutoSpace = false; } boolean handledOutputToInputConnection = false; if (ic != null) { if (primaryCode == KeyCodes.SPACE) { if (mAskPrefs.isDoubleSpaceChangesToPeriod()) { if ((SystemClock.uptimeMillis() - mLastSpaceTimeStamp) < ((long) mAskPrefs.getMultiTapTimeout())) { //current text in the input-box should be something like "word " //the user pressed on space again. So we want to change the text in the input-box //into "word "->"word. " ic.deleteSurroundingText(1, 0); ic.commitText(". ", 1); mJustAddedAutoSpace = true; isEndOfSentence = true; handledOutputToInputConnection = true; } } } else if (mJustAddedAutoSpace && mLastSpaceTimeStamp != NEVER_TIME_STAMP/*meaning last key was SPACE*/ && mAskPrefs.shouldSwapPunctuationAndSpace() && primaryCode != KeyCodes.ENTER && isSentenceSeparator(primaryCode)) { //current text in the input-box should be something like "word " //the user pressed a punctuation (say ","). So we want to change the text in the input-box //into "word "->"word, " ic.deleteSurroundingText(1, 0); ic.commitText(((char) primaryCode) + " ", 1); mJustAddedAutoSpace = true; handledOutputToInputConnection = true; } } if (!handledOutputToInputConnection) { sendKeyChar((char) primaryCode); } TextEntryState.typedCharacter((char) primaryCode, true); if (ic != null) { ic.endBatchEdit(); } if (isEndOfSentence) { mSuggest.resetNextWordSentence(); clearSuggestions(); } else if (!TextUtils.isEmpty(mCommittedWord)) { setSuggestions(mSuggest.getNextSuggestions(mCommittedWord, mWord.isAllUpperCase()), false, false, false); mWord.setFirstCharCapitalized(false); } }