Code example for KeyEvent

Methods: handleKeyDowngetMetaStategetUnicodeChar

0
	 * This translates incoming hard key events in to edit operations on an 
	 * InputConnection. It is only needed when using the PROCESS_HARD_KEYS 
	 * option. 
	 */ 
	private boolean translateKeyDown(int keyCode, KeyEvent event) {
		mMetaState = MetaKeyKeyListener.handleKeyDown(mMetaState, keyCode,
				event);
		int c = event.getUnicodeChar(MetaKeyKeyListener
				.getMetaState(mMetaState));
		mMetaState = MetaKeyKeyListener.adjustMetaAfterKeypress(mMetaState);
		InputConnection ic = getCurrentInputConnection();
		if (c == 0 || ic == null) {
			return false; 
		} 
 
		if ((c & KeyCharacterMap.COMBINING_ACCENT) != 0) {
			c = c & KeyCharacterMap.COMBINING_ACCENT_MASK;
		} 
 
		if (mComposing.length() > 0) {
			char accent = mComposing.charAt(mComposing.length() - 1);
			int composed = KeyEvent.getDeadChar(accent, c);
 
			if (composed != 0) {
				c = composed;
				mComposing.setLength(mComposing.length() - 1);
			} 
		} 
 
		onKey(c, null);
 
		return true; 
	} 
 
	/** 
	 * 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. 
	 */ 
	@Override 
	public boolean onKeyDown(int keyCode, KeyEvent event) {
		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) {
				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 
Stop searching for code, let great code find you!  Add Codota to your java IDE