List of usage examples for android.view KeyEvent getUnicodeChar
public int getUnicodeChar()
From source file:com.vikingbrain.dmt.view.RemoteControlActivity.java
@Override public boolean dispatchKeyEvent(KeyEvent event) { int keyaction = event.getAction(); int keyCode = event.getKeyCode(); //Manage key up keys if (keyaction == KeyEvent.ACTION_UP) { if (keyCode == KeyEvent.KEYCODE_BACK) { //Back button, exit the activity onBackPressed();// ww w . j ava 2 s . co m return true; } else if (keyCode == KeyEvent.KEYCODE_DEL) { //this is for backspace addCharacterToSendQueue(Keyboard2RemoteKey.BACKSPACE.getKeyboardSymbol()); return true; } else { //Any other keyboard key up DmtLogger.d("key pressed", String.valueOf(event.getKeyCode())); char unicodeChar = (char) event.getUnicodeChar(); String keyboardSymbol = String.valueOf(unicodeChar); addCharacterToSendQueue(keyboardSymbol); return true; } } return super.dispatchKeyEvent(event); }
From source file:com.duy.pascal.ui.view.console.ConsoleView.java
@Override public boolean onKeyDown(int keyCode, KeyEvent event) { if (event.isSystem()) { return super.onKeyDown(keyCode, event); }//from w w w . ja v a 2s. c o m mKeyBuffer.push((char) event.getUnicodeChar()); //scan code if (keyCode == KeyEvent.KEYCODE_DEL) { putString(THE_DELETE_COMMAND); return true; } String c = event.getCharacters(); if (c == null) { c = Character.valueOf((char) event.getUnicodeChar()).toString(); } putString(c); return true; }
From source file:research.sg.edu.edapp.kb.KbSoftKeyboard.java
/** * Use this to monitor key events being delivered to the application. * We get first crack at them, and can either resume them or let them * continue to the app.//from ww w .j a va 2s . co m */ @Override public boolean onKeyDown(int keyCode, KeyEvent event) { String s = "" + event.getUnicodeChar(); Log.d("CAME HERE", "CAME HERE"); switch (keyCode) { case KeyEvent.KEYCODE_BACK: // The InputMethodService already takes care of the back // key for us, to dismiss the input method if it is shown. // However, our keyboard could be showing a pop-up window // that back should dismiss, so we first allow it to do that. if (event.getRepeatCount() == 0 && mInputView != null) { if (mInputView.handleBack()) { return true; } } break; case KeyEvent.KEYCODE_DEL: // Special handling of the delete key: if we currently are // composing text for the user, we want to modify that instead // of let the application to the delete itself. if (mComposing.length() > 0) { onKey(Keyboard.KEYCODE_DELETE, null); return true; } break; case KeyEvent.KEYCODE_ENTER: // Let the underlying text editor always handle these. return false; default: // For all other keys, if we want to do transformations on // text being entered with a hard keyboard, we need to process // it and do the appropriate action. if (PROCESS_HARD_KEYS) { //*********added changes here if (event.getAction() == KeyEvent.ACTION_DOWN) { swipe += (char) event.getUnicodeChar(); Log.d("msg", swipe); System.out.println(swipe); // keyDownUp(keyCode); // return true; } //*********done if (keyCode == KeyEvent.KEYCODE_SPACE && (event.getMetaState() & KeyEvent.META_ALT_ON) != 0) { // A silly example: in our input method, Alt+Space // is a shortcut for 'android' in lower case. InputConnection ic = getCurrentInputConnection(); if (ic != null) { // First, tell the editor that it is no longer in the // shift state, since we are consuming this. ic.clearMetaKeyStates(KeyEvent.META_ALT_ON); keyDownUp(KeyEvent.KEYCODE_A); keyDownUp(KeyEvent.KEYCODE_N); keyDownUp(KeyEvent.KEYCODE_D); keyDownUp(KeyEvent.KEYCODE_R); keyDownUp(KeyEvent.KEYCODE_O); keyDownUp(KeyEvent.KEYCODE_I); keyDownUp(KeyEvent.KEYCODE_D); // And we consume this event. return true; } } if (mPredictionOn && translateKeyDown(keyCode, event)) { return true; } } } return super.onKeyDown(keyCode, event); }
From source file:com.android.contacts.activities.PeopleActivity.java
@Override public boolean onKeyDown(int keyCode, KeyEvent event) { // TODO move to the fragment // Bring up the search UI if the user starts typing final int unicodeChar = event.getUnicodeChar(); if ((unicodeChar != 0) // If COMBINING_ACCENT is set, it's not a unicode character. && ((unicodeChar & KeyCharacterMap.COMBINING_ACCENT) == 0) && !Character.isWhitespace(unicodeChar)) { if (mActionBarAdapter.isSelectionMode()) { // Ignore keyboard input when in selection mode. return true; }/*from w w w. j av a 2 s. c om*/ String query = new String(new int[] { unicodeChar }, 0, 1); if (!mActionBarAdapter.isSearchMode()) { mActionBarAdapter.setSearchMode(true); mActionBarAdapter.setQueryString(query); return true; } } return super.onKeyDown(keyCode, event); }
From source file:com.hughes.android.dictionary.DictionaryActivity.java
@Override public boolean onKeyDown(final int keyCode, final KeyEvent event) { if (event.getUnicodeChar() != 0) { if (!searchView.hasFocus()) { setSearchText("" + (char) event.getUnicodeChar(), true); searchView.requestFocus();// www . j ava 2s. c om } return true; } if (keyCode == KeyEvent.KEYCODE_BACK) { // Log.d(LOG, "Clearing dictionary prefs."); // Pretend that we just autolaunched so that we won't do it again. // DictionaryManagerActivity.lastAutoLaunchMillis = // System.currentTimeMillis(); } if (keyCode == KeyEvent.KEYCODE_ENTER) { Log.d(LOG, "Trying to hide soft keyboard."); final InputMethodManager inputManager = (InputMethodManager) getSystemService( Context.INPUT_METHOD_SERVICE); View focus = getCurrentFocus(); if (focus != null) { inputManager.hideSoftInputFromWindow(focus.getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS); } return true; } return super.onKeyDown(keyCode, event); }
From source file:com.todoroo.astrid.activity.TaskListFragment.java
protected void setUpUiComponents() { // set listener for quick-changing task priority getListView().setOnKeyListener(new OnKeyListener() { @Override/*w w w .j ava2 s . c om*/ public boolean onKey(View view, int keyCode, KeyEvent event) { if (event.getAction() != KeyEvent.ACTION_UP || view == null) return false; boolean filterOn = getListView().isTextFilterEnabled(); View selected = getListView().getSelectedView(); // hot-key to set task priority - 1-4 or ALT + Q-R if (!filterOn && event.getUnicodeChar() >= '1' && event.getUnicodeChar() <= '4' && selected != null) { int importance = event.getNumber() - '1'; Task task = ((ViewHolder) selected.getTag()).task; task.setValue(Task.IMPORTANCE, importance); taskService.save(task); taskAdapter.setFieldContentsAndVisibility(selected); } // filter else if (!filterOn && event.getUnicodeChar() != 0) { getListView().setTextFilterEnabled(true); getListView().setFilterText(Character.toString((char) event.getUnicodeChar())); } // turn off filter if nothing is selected else if (filterOn && TextUtils.isEmpty(getListView().getTextFilter())) { getListView().setTextFilterEnabled(false); } return false; } }); SharedPreferences publicPrefs = AstridPreferences.getPublicPrefs(getActivity()); sortFlags = publicPrefs.getInt(SortHelper.PREF_SORT_FLAGS, 0); sortSort = publicPrefs.getInt(SortHelper.PREF_SORT_SORT, 0); sortFlags = SortHelper.setManualSort(sortFlags, isDraggable()); getView().findViewById(R.id.progressBar).setVisibility(View.GONE); }
From source file:com.chrynan.guitarchords.view.GuitarChordView.java
@Override public InputConnection onCreateInputConnection(EditorInfo outAttrs) { if (editable) { final InputConnectionAccomodatingLatinIMETypeNullIssues baseInputConnection = new InputConnectionAccomodatingLatinIMETypeNullIssues( this, false); outAttrs.actionLabel = null;// w ww . j ava2s .com outAttrs.inputType = InputType.TYPE_NULL; outAttrs.imeOptions = EditorInfo.IME_ACTION_DONE; setOnKeyListener(new OnKeyListener() { @Override public boolean onKey(View v, int keyCode, KeyEvent event) { if (editable) { if (event .getUnicodeChar() == (int) EditableAccomodatingLatinIMETypeNullIssues.ONE_UNPROCESSED_CHARACTER .charAt(0)) { //We are ignoring this character, and we want everyone else to ignore it, too, so // we return true indicating that we have handled it (by ignoring it). return true; } if (keyCode == KeyEvent.KEYCODE_ENTER && event.getAction() == KeyEvent.ACTION_UP) { //Trap the Done key and close the keyboard if it is pressed (if that's what you want to do) InputMethodManager imm = (InputMethodManager) getContext() .getSystemService(Context.INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(GuitarChordView.this.getWindowToken(), 0); if (touchEventMarker != null) { Integer finger; try { finger = Integer.valueOf(baseInputConnection.getEditable().toString()); } catch (Exception e) { e.printStackTrace(); finger = touchEventMarker.getFinger(); } touchEventMarker = new ChordMarker(touchEventMarker.getStartString(), touchEventMarker.getEndString(), touchEventMarker.getFret(), finger); alertOnChordSelected(null, new ChordMarker(touchEventMarker), chord.contains(touchEventMarker)); } return true; } } return false; } }); return baseInputConnection; } return null; }
From source file:org.akop.ararat.view.CrosswordView.java
@Override public boolean onKey(View v, int keyCode, KeyEvent event) { boolean handled = false; if (event.getAction() == KeyEvent.ACTION_UP) { if (keyCode == KeyEvent.KEYCODE_SPACE) { switchWordDirection();// w w w . j a v a 2 s. c o m handled = true; } else if (keyCode == KeyEvent.KEYCODE_DEL) { handleBackspace(); handled = true; } else { int uniChar = event.getUnicodeChar(); if (uniChar != 0) { handleInput((char) event.getUnicodeChar()); handled = true; } } } return handled; }
From source file:net.evendanan.android.thumbremote.ui.RemoteUiActivity.java
/** * Handler an android keypress and send it to boxee if appropriate. *//*from w w w . ja va 2s . c om*/ @Override public boolean onKeyDown(final int keyCode, final KeyEvent event) { switch (keyCode) { case KeyEvent.KEYCODE_BACK: if (RemoteApplication.getConfig().getHandleBack()) { Log.d(TAG, "Will handle back"); if (mBoundService != null) mBoundService.remoteBack(); return true; } else { Log.d(TAG, "Will NOT handle back"); return super.onKeyDown(keyCode, event); } case KeyEvent.KEYCODE_DPAD_CENTER: if (mBoundService != null) mBoundService.remoteSelect(); return true; case KeyEvent.KEYCODE_DPAD_DOWN: if (mBoundService != null) mBoundService.remoteDown(); return true; case KeyEvent.KEYCODE_DPAD_UP: if (mBoundService != null) mBoundService.remoteUp(); return true; case KeyEvent.KEYCODE_DPAD_LEFT: if (mBoundService != null) mBoundService.remoteLeft(); return true; case KeyEvent.KEYCODE_DPAD_RIGHT: if (mBoundService != null) mBoundService.remoteRight(); return true; case KeyEvent.KEYCODE_VOLUME_UP: case KeyEvent.KEYCODE_VOLUME_DOWN: final int volumeFactor = (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) ? -1 : 1; final int volumeOffset = (volumeFactor * RemoteApplication.getConfig().getVolumeStep()); if (mBoundService != null) mBoundService.remoteVolumeOffset(volumeOffset); return true; case KeyEvent.KEYCODE_DEL: if (mBoundService != null) mBoundService.remoteKeypress((char) 8); return true; default: final char unicodeChar = (char) event.getUnicodeChar(); // Log.d(TAG, "Unicode is " + ((char)unicodeChar)); if (Character.isLetterOrDigit(unicodeChar) || msPunctuation.contains(unicodeChar)) { // Log.d(TAG, "handling " + ((char)unicodeChar)); if (mBoundService != null) mBoundService.remoteKeypress(unicodeChar); return true; } else { return super.onKeyDown(keyCode, event); } } }