List of usage examples for android.inputmethodservice Keyboard KEYCODE_CANCEL
int KEYCODE_CANCEL
To view the source code for android.inputmethodservice Keyboard KEYCODE_CANCEL.
Click Source Link
From source file:com.mobisci_lab.virtualkeyboard.softkeyboard.LatinKeyboardView.java
@Override protected boolean onLongPress(Key key) { if (key.codes[0] == Keyboard.KEYCODE_CANCEL) { getOnKeyboardActionListener().onKey(KEYCODE_OPTIONS, null); return true; } else {/*w w w. ja va 2 s. c om*/ return super.onLongPress(key); } }
From source file:com.samplekeyboard.LatinKeyboardView.java
@Override protected boolean onLongPress(Key key) { if (key.codes[0] == Keyboard.KEYCODE_CANCEL) { getOnKeyboardActionListener().onKey(KEYCODE_OPTIONS, null); return true; } else {/*from ww w.j a va2 s . co m*/ Log.i(TAG, "key: " + key.codes[0]); return super.onLongPress(key); } }
From source file:research.sg.edu.edapp.kb.KbSoftKeyboard.java
public void onKey(int primaryCode, int[] keyCodes) { /*String tap_file_name; String currentmood = "-99";//w ww. j a v a2s. 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:com.strathclyde.highlightingkeyboard.SoftKeyboardService.java
/** * Manages actual input into the editor. Here we: * implement our injection algorithm as required * store data relating to the key press/*from w w w . ja va2 s . c o m*/ * initiate any spell checking as required */ public void onKey(int primaryCode, int[] keyCodes) { // touches all done, add the chars to the event and then the event to the session currentEvent.keyCode = primaryCode; if (errorInjection && primaryCode >= 32) { //give a n% chance of the key being modified Random r = new Random(); int res = r.nextInt(100); if (res <= errorInjectionThreshold) //%n chance of key being modified { //Log.i("OnKey", "Will modify"); try { //for each combination in the model, find the eucleidian distance and the replacement freq JSONObject targetObj = suspectReplacementDistribution .getJSONObject(Integer.toString(primaryCode)); Iterator<?> keys = targetObj.keys(); ArrayList<Character> list = new ArrayList(); while (keys.hasNext()) { String key = (String) keys.next(); int freq = targetObj.getInt(key); //if the frequency is 0, add the suspect as a replacement candidate double dist = keyModel.distance2(primaryCode, Integer.parseInt(key)); if (dist > 0) { if (dist > 2.0) //fix it so that only nearby keys have a chance of being elected dist = 100; //add to the list of candidates as many times as required if specific freq>0; int sfreq = (int) Math.round(freq / dist); //Log.i("Test", "Freq/Dist to "+key+": "+freq+"/"+dist+" final prob: "+sfreq); if (sfreq == 0) //add the suspect as a replacement candidate { list.add(Character.toChars(primaryCode)[0]); } else //add the other replacement candidates as required { for (int x = 0; x < targetObj.getInt(key); x++) { list.add(Character.toChars(Integer.parseInt(key))[0]); } } } } //Log.i("OnKey", "Replace list size: "+list.size()); Random x = new Random(); int sel = x.nextInt(list.size()); //if the replacement eventually happens if ((int) list.get(sel) != primaryCode) { if (errorInjectionSound) { final ToneGenerator tg = new ToneGenerator(AudioManager.STREAM_NOTIFICATION, 100); tg.startTone(ToneGenerator.TONE_CDMA_SOFT_ERROR_LITE); } //primaryCode = (int)list.get(sel); //Log.w("OnKey", "Replace "+Character.toChars(primaryCode)[0]+" with "+list.get(sel)); errorMap.put(mComposing.length(), (char) (int) list.get(sel)); //put in our current position and the replacement //nInjections++; } else Log.i("OnKey", "Replacement will not happen, same key selected"); } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } } else { //Log.i("OnKey", "Will not modify, r="+res); } } //switch adaptxt language if necessary if (coreEngine != null) { switch (mInputView.currentKeyboard) { case KeyboardViews.QWERTY_EL: coreEngine.activateLanguageKeymap(131092, null); coreEngine.setDictionaryPriority(131092, 0); break; case KeyboardViews.QWERTY_EN: coreEngine.activateLanguageKeymap(131081, null); coreEngine.setDictionaryPriority(131092, 1); break; } } //get the full inputted text extr = ic.getExtractedText(new ExtractedTextRequest(), 0); if (currentEvent != null && captureData == true) { //Log.i("OnKey", "OK to capture data!"); currentEvent.user = userid; if (primaryCode > 0) currentEvent.keyChar = (char) primaryCode; //handle the booleans if (currentSession.events.get(currentSession.events.size() - 1).keyChar == ' ') //space { currentEvent.followsSpace = true; } if (currentEvent.keyCode == Keyboard.KEYCODE_DELETE) { System.out.println("Backspace Pressed!"); //if a delete is pressed after another delete //and its cursor position is not -1 from the previous delete //we must commit the previous deletion as a suspect character. if (currentSession.events.get(currentSession.events.size() - 1).keyCode == Keyboard.KEYCODE_DELETE && extr.selectionStart != lastDeletedPos - 1) { currentSession.suspects.add(lastDeleted); //System.out.println("Suspect = "+lastDeleted); } //get all the text before the backspace press and the current cursor position if (extr.selectionStart > 0) { lastDeleted = extr.text.charAt(extr.selectionStart - 1); lastDeletedPos = extr.selectionStart; //System.out.println("Deleted = "+lastDeleted+"\nCursor Position = "+extr.selectionStart); } } //if the current key is NOT a backspace but the previous one was if (currentEvent.keyCode != Keyboard.KEYCODE_DELETE && currentSession.events .get(currentSession.events.size() - 1).keyCode == Keyboard.KEYCODE_DELETE) { currentSession.suspects.add(lastDeleted); //System.out.println("Suspect = "+lastDeleted); } } //do the handling if (isWordSeparator(primaryCode)) { // Handle separator //System.out.println("Detected a word separator \""+primaryCode+"\""); if (primaryCode != 32) { shouldInsertSpace = false; if (extr.text.length() > 0) { //Log.i("On Key ", "last letter after separator was ["+extr.text.charAt(extr.selectionStart-1)+"]"); //check if the previous char was a space, if so delete it. if (extr.text.charAt(extr.selectionStart - 1) == ' ' && !isSpecialSeparator(primaryCode)) //detecting if the current char is not part of a smiley face { onKey(-5, null); } } } //clear the touch history clearDots(); //ensure spell checker is using correct language SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); Editor ed = prefs.edit(); if (captureData) { if (mInputView.currentLang == 1) //english { ed.putString("available_dicts", "en"); ed.commit(); if (mScs != null) mScs.close(); String lang = prefs.getString("available_dicts", "jam"); Log.i("OnKey", "Spellcheck lang set to " + lang); Locale english = new Locale("en", "GB"); mScs = tsm.newSpellCheckerSession(null, english, this, false); if (mScs == null) Log.e("OnKey", "Failed to obtain spell-checker session"); } else { ed.putString("available_dicts", "el"); ed.commit(); if (mScs != null) mScs.close(); String lang = prefs.getString("available_dicts", "jam"); Log.i("OnKey", "Spellcheck lang set to " + lang); Locale greek = new Locale("el", "GR"); mScs = tsm.newSpellCheckerSession(null, greek, this, false); if (mScs == null) Log.e("OnKey", "Failed to obtain spell-checker session"); } } //handle space for Adaptxt if (Character.isSpaceChar(primaryCode)) { if (coreEngine != null) { //Log.i("Handle Character", "Space pressed"); coreEngine.resetCoreString(); //Log.i("Space Pressed", "Word is "+mComposing+" "); coreEngine.insertText(mComposing.toString() + " "); updateCandidates(); } } if (!firstWordSet && mComposing.length() > 1) { if (captureData) currentSession.firstWord = mComposing.toString(); else currentSession.firstWord = "$$$$"; firstWordSet = true; //System.out.println("First Word\""+mComposing.toString()+"\""); } //effect any injections as required if (mComposing.length() > 0) { //commitTyped(getCurrentInputConnection()); //check the errormap for any replacements if (errorMap.size() > 0) { //restrict the errormap to the 25% of word length cap int replacementstodelete = errorMap.size() - (int) Math.round(mComposing.length() * 0.25); //total replacements - those to keep if (replacementstodelete < 0) replacementstodelete = 0; //allow at least one if (errorMap.size() == replacementstodelete) replacementstodelete = errorMap.size() - 1; if (replacementstodelete > 0) { List<Integer> keys = new ArrayList<Integer>(errorMap.keySet()); for (int z = 0; z < replacementstodelete; z++) { Random random = new Random(); int listposition = random.nextInt(keys.size()); int randomKey = keys.get(listposition); //remove this from the error map and the list errorMap.remove(randomKey); keys.remove(listposition); } } //effect the injections String oldmComposing = mComposing.toString(); Iterator it = errorMap.entrySet().iterator(); while (it.hasNext()) { Map.Entry pair = (Map.Entry) it.next(); mComposing.replace((Integer) pair.getKey(), (Integer) pair.getKey() + 1, "" + (Character) pair.getValue()); //it.remove(); // avoids a ConcurrentModificationException } nInjections += errorMap.size(); currentSession.nInjections = nInjections; //Log.i("Injections", "Will replace "+oldmComposing+" with "+mComposing+", nInjections="+nInjections); errorMap.clear(); } wordSeparatorKeyCode = primaryCode; if (captureData) commitTyped(ic, isWordSeparator(primaryCode)); else { if (primaryCode != Keyboard.KEYCODE_DONE && primaryCode != 10) //done and go/enter handleCharacter(primaryCode, keyCodes); else sendKey(primaryCode); commitTyped(ic); } } else { sendKey(primaryCode); } updateShiftKeyState(getCurrentInputEditorInfo()); } else if (primaryCode == Keyboard.KEYCODE_DELETE) { if (errorMap.get(mComposing.length() - 1) != null) { //Log.i("Injection", "Delete from map pos="+(mComposing.length()-1)+", char="+errorMap.get(mComposing.length()-1)); errorMap.remove(mComposing.length() - 1); } handleBackspace(); } else if (primaryCode == Keyboard.KEYCODE_SHIFT) { handleShift(); } else if (primaryCode == Keyboard.KEYCODE_CANCEL) { //keyboard hiding button //override this for settings activity //handleClose(); Intent intent = new Intent(this, LoggingIMESettings.class); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); startActivity(intent); return; } else if (primaryCode == LatinKeyboardView.KEYCODE_OPTIONS) { // Show a menu or somethin' } else if (primaryCode == Keyboard.KEYCODE_MODE_CHANGE && mInputView != null) { //Keyboard current = mInputView.getKeyboard(); if (mInputView.currentKeyboard == KeyboardViews.SYMBOLS || mInputView.currentKeyboard == KeyboardViews.SYMBOLS_SHIFTED) { //mInputView.currentKeyboard = KeyboardViews.QWERTY_EN; mInputView.currentKeyboard = lastKeyboardView; } else { //about to change to symbols lastKeyboardView = mInputView.currentKeyboard; //keep track of where we came from mInputView.currentKeyboard = KeyboardViews.SYMBOLS; } mInputView.switchKeyboard(); if (mInputView.currentKeyboard == KeyboardViews.SYMBOLS) { mInputView.getKeyboard().setShifted(false); } } else { handleCharacter(primaryCode, keyCodes); } }