Code example for KeyboardView

Methods: getKeyboard, isShifted, setKeyboard

1
		} else if (primaryCode == Keyboard.KEYCODE_CANCEL) {
			handleClose(); 
			return; 
 
		} else if (primaryCode == Keyboard.KEYCODE_MODE_CHANGE && keyboardView != null) {
			Keyboard current = keyboardView.getKeyboard();
			keyboardView.setKeyboard(current);
		} else { 
			handleCharacter(primaryCode, keyCodes);
		} 
	} 
 
	@Override 
	public void onText(CharSequence text) {
		InputConnection ic = getCurrentInputConnection();
		if (ic == null)
			return; 
		ic.beginBatchEdit();
		if (mComposing.length() > 0) {
			commitTyped(ic);
		} 
		ic.commitText(text, 0);
		ic.endBatchEdit();
		updateShiftKeyState(getCurrentInputEditorInfo());
	} 
 
	private void handleBackspace() { 
		final int length = mComposing.length();
		if (length > 1) {
			mComposing.delete(length - 1, length);
			getCurrentInputConnection().setComposingText(mComposing, 1);
		} else if (length > 0) {
			mComposing.setLength(0);
			getCurrentInputConnection().commitText("", 0);
		} else { 
			keyDownUp(KeyEvent.KEYCODE_DEL);
		} 
		updateShiftKeyState(getCurrentInputEditorInfo());
	} 
 
	private void handleShift() { 
		if (keyboardView == null) {
			return; 
		} 
 
		Keyboard currentKeyboard = keyboardView.getKeyboard();
		if (qwertyKeyboard == currentKeyboard) {
			keyboardView.setShifted(!keyboardView.isShifted());
		} 
	} 
 
	private void handleCharacter(int primaryCode, int[] keyCodes) {
		if (isInputViewShown()) {
			if (keyboardView.isShifted()) {
				primaryCode = Character.toUpperCase(primaryCode);
			} 
		} 
		getCurrentInputConnection().commitText(String.valueOf((char) primaryCode), 1);