Code example for InputConnection

Methods: clearMetaKeyStates, commitText

0
     * @param caps 
     * @param ic 
     */ 
    private void handleAccentKey(KeyEvent event, CharSequence smallCaps, CharSequence caps, InputConnection ic)
    { 
		ic.clearMetaKeyStates(event.getMetaState());
		if(shiftInactive) {
			ic.commitText(smallCaps, 1);			
		} else if (shiftActive) {
			ic.commitText(caps, 1);
			 
			/* 
			 * Next two lines of code have to clear Shift for the purose of other processes which take part in input handling. 
			 * When Shift is on, we properly handle it but if do not explicitly send a KeyEvent to the InputConnection, Shift stays turned on 
			 * (There is probably some other process with its own MetaKeyListener). Then the next inserted letter (which we do not handle) handles the Shift 
			 * and becomes capital letter. This behaviour is undesirable of course. That is why we use this workaround. We send two events indicating  
			 * Shift key press. The first causes CAPS LOCK (SHIFT LOCKED) and the second an entire Shift clearing. 
			 *  
			 * If we respond to an event and CAPS LOCK (SHIFT LOCKED) is on (see if statement above), we do not change the Shift state, so  
			 * nothing has to be done.  
			 */ 
			keyDownUp(KeyEvent.KEYCODE_SHIFT_LEFT);
			keyDownUp(KeyEvent.KEYCODE_SHIFT_LEFT);
		} else if (shiftLocked) {
			ic.commitText(caps, 1);			
		} 
		 
		/* 
		 * See the long comment for Shift clearing above, this is the same for ALT. 
		 */