Java Code Examples for android.view.KeyEvent#getUnicodeChar()

The following examples show how to use android.view.KeyEvent#getUnicodeChar() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: StartConversationActivity.java    From Conversations with GNU General Public License v3.0 6 votes vote down vote up
@Override
public boolean onKeyUp(int keyCode, KeyEvent event) {
	if (keyCode == KeyEvent.KEYCODE_SEARCH && !event.isLongPress()) {
		openSearch();
		return true;
	}
	int c = event.getUnicodeChar();
	if (c > 32) {
		if (mSearchEditText != null && !mSearchEditText.isFocused()) {
			openSearch();
			mSearchEditText.append(Character.toString((char) c));
			return true;
		}
	}
	return super.onKeyUp(keyCode, event);
}
 
Example 2
Source File: AllAppsContainerView.java    From Trebuchet with GNU General Public License v3.0 6 votes vote down vote up
@Override
public boolean dispatchKeyEvent(KeyEvent event) {
    // Determine if the key event was actual text, if so, focus the search bar and then dispatch
    // the key normally so that it can process this key event
    if (mSearchBarController != null &&
            !mSearchBarController.isSearchFieldFocused() &&
            event.getAction() == KeyEvent.ACTION_DOWN) {
        final int unicodeChar = event.getUnicodeChar();
        final boolean isKeyNotWhitespace = unicodeChar > 0 &&
                !Character.isWhitespace(unicodeChar) && !Character.isSpaceChar(unicodeChar);
        if (isKeyNotWhitespace) {
            boolean gotKey = TextKeyListener.getInstance().onKeyDown(this, mSearchQueryBuilder,
                    event.getKeyCode(), event);
            if (gotKey && mSearchQueryBuilder.length() > 0) {
                mSearchBarController.focusSearchField();
            }
        }
    }

    return super.dispatchKeyEvent(event);
}
 
Example 3
Source File: KeysInterpreter.java    From CodeEditor with Apache License 2.0 6 votes vote down vote up
/**
 * Maps shortcut keys and Android keycodes to printable characters.
 * Note that whitespace is considered printable.
 * 
 * @param event The KeyEvent to interpret
 * @return The printable character the event represents, 
 * 	or Language.NULL_CHAR if the event does not represent a printable char
 */
public static char keyEventToPrintableChar(KeyEvent event){
	char c = Language.NULL_CHAR;

   	// convert tab, backspace, newline and space keycodes to standard ASCII values
   	if (isNewline(event)){
   		c = Language.NEWLINE;
       }
   	else if (isBackspace(event)){
   		c = Language.BACKSPACE;
       }
	// This should be before the check for isSpace() because the
   	// shortcut for TAB uses the SPACE key.
   	else if (isTab(event)){
   		c = Language.TAB;
       }
   	else if (isSpace(event)){
   		c = ' ';
       }
   	else if (event.isPrintingKey()){
   		c = (char) event.getUnicodeChar(event.getMetaState());
   	}
   	
	return c;
}
 
Example 4
Source File: AllAppsContainerView.java    From LaunchEnr with GNU General Public License v3.0 6 votes vote down vote up
@Override
public boolean dispatchKeyEvent(KeyEvent event) {
    // Determine if the key event was actual text, if so, focus the search bar and then dispatch
    // the key normally so that it can process this key event
    if (!mSearchBarController.isSearchFieldFocused() &&
            event.getAction() == KeyEvent.ACTION_DOWN) {
        final int unicodeChar = event.getUnicodeChar();
        final boolean isKeyNotWhitespace = unicodeChar > 0 &&
                !Character.isWhitespace(unicodeChar) && !Character.isSpaceChar(unicodeChar);
        if (isKeyNotWhitespace) {
            boolean gotKey = TextKeyListener.getInstance().onKeyDown(this, mSearchQueryBuilder,
                    event.getKeyCode(), event);
            if (gotKey && mSearchQueryBuilder.length() > 0) {
                mSearchBarController.focusSearchField();
            }
        }
    }

    return super.dispatchKeyEvent(event);
}
 
Example 5
Source File: Launcher.java    From LaunchEnr with GNU General Public License v3.0 6 votes vote down vote up
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    final int uniChar = event.getUnicodeChar();
    final boolean handled = super.onKeyDown(keyCode, event);
    final boolean isKeyNotWhitespace = uniChar > 0 && !Character.isWhitespace(uniChar);
    if (!handled && acceptFilter() && isKeyNotWhitespace) {
        boolean gotKey = TextKeyListener.getInstance().onKeyDown(mWorkspace, mDefaultKeySsb,
                keyCode, event);
        if (gotKey && mDefaultKeySsb != null && mDefaultKeySsb.length() > 0) {
            // something usable has been typed - start a search
            // the typed text will be retrieved and cleared by
            // showSearchDialog()
            // If there are multiple keystrokes before the search dialog takes focus,
            // onSearchRequested() will be called for every keystroke,
            // but it is idempotent, so it's fine.
            return onSearchRequested();
        }
    }

    // Eat the long press event so the keyboard doesn't come up.
    if (keyCode == KeyEvent.KEYCODE_MENU && event.isLongPress()) {
        return true;
    }

    return handled;
}
 
Example 6
Source File: KeysInterpreter.java    From lua-for-android with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Maps shortcut keys and Android keycodes to printable characters.
 * Note that whitespace is considered printable.
 *
 * @param event The KeyEvent to interpret
 * @return The printable character the event represents,
 * or Language.NULL_CHAR if the event does not represent a printable char
 */
public static char keyEventToPrintableChar(KeyEvent event) {
    char c = Language.NULL_CHAR;

    // convert tab, backspace, newline and space keycodes to standard ASCII values
    if (isNewline(event)) {
        c = Language.NEWLINE;
    } else if (isBackspace(event)) {
        c = Language.BACKSPACE;
    }
    // This should be before the check for isSpace() because the
    // shortcut for TAB uses the SPACE key.
    else if (isTab(event)) {
        c = Language.TAB;
    } else if (isSpace(event)) {
        c = ' ';
    } else if (event.isPrintingKey()) {
        c = (char) event.getUnicodeChar(event.getMetaState());
    }

    return c;
}
 
Example 7
Source File: CharInputConnection.java    From TextFiction with Apache License 2.0 5 votes vote down vote up
@Override
public boolean sendKeyEvent(KeyEvent event) {
	if (event.getAction() == KeyEvent.ACTION_UP) {
		char[] tmp = { (char)event.getUnicodeChar() };
		inputProcessor.executeCommand(tmp);
	}
	return true;
}
 
Example 8
Source File: c.java    From letv with Apache License 2.0 5 votes vote down vote up
public boolean onKeyDown(int i, KeyEvent keyEvent) {
    f.b("SecureWebView", "-->onKeyDown, is device support: " + a);
    if (!a) {
        return super.onKeyDown(i, keyEvent);
    }
    if (keyEvent.getAction() != 0) {
        return super.onKeyDown(i, keyEvent);
    }
    switch (keyEvent.getKeyCode()) {
        case 4:
            return super.onKeyDown(i, keyEvent);
        case 66:
            return super.onKeyDown(i, keyEvent);
        case 67:
            a.b = true;
            return super.onKeyDown(i, keyEvent);
        default:
            if (keyEvent.getUnicodeChar() == 0) {
                return super.onKeyDown(i, keyEvent);
            }
            if (SecureJsInterface.isPWDEdit) {
                int unicodeChar = keyEvent.getUnicodeChar();
                if ((unicodeChar >= 33 && unicodeChar <= 95) || (unicodeChar >= 97 && unicodeChar <= 125)) {
                    this.b = new KeyEvent(0, 17);
                    return super.onKeyDown(this.b.getKeyCode(), this.b);
                }
            }
            return super.onKeyDown(i, keyEvent);
    }
}
 
Example 9
Source File: c.java    From letv with Apache License 2.0 5 votes vote down vote up
public boolean dispatchKeyEvent(KeyEvent keyEvent) {
    f.b("SecureWebView", "-->dispatchKeyEvent, is device support: " + a);
    if (!a) {
        return super.dispatchKeyEvent(keyEvent);
    }
    if (keyEvent.getAction() != 0) {
        return super.dispatchKeyEvent(keyEvent);
    }
    switch (keyEvent.getKeyCode()) {
        case 4:
            return super.dispatchKeyEvent(keyEvent);
        case 66:
            return super.dispatchKeyEvent(keyEvent);
        case 67:
            a.b = true;
            return super.dispatchKeyEvent(keyEvent);
        default:
            if (keyEvent.getUnicodeChar() == 0) {
                return super.dispatchKeyEvent(keyEvent);
            }
            if (SecureJsInterface.isPWDEdit) {
                int unicodeChar = keyEvent.getUnicodeChar();
                if ((unicodeChar >= 33 && unicodeChar <= 95) || (unicodeChar >= 97 && unicodeChar <= 125)) {
                    this.b = new KeyEvent(0, 17);
                    return super.dispatchKeyEvent(this.b);
                }
            }
            return super.dispatchKeyEvent(keyEvent);
    }
}
 
Example 10
Source File: DpadPwActivity.java    From jellyfin-androidtv with GNU General Public License v2.0 5 votes vote down vote up
private void processKey(int keyCode, boolean doubleClick, KeyEvent event) {
    switch (keyCode) {
        case KeyEvent.KEYCODE_DPAD_UP:
            password += doubleClick ? 6 : 1;
            break;
        case KeyEvent.KEYCODE_DPAD_LEFT:
            password += doubleClick ? 7 : 2;
            break;
        case KeyEvent.KEYCODE_DPAD_RIGHT:
            password += doubleClick ? 8 : 3;
            break;
        case KeyEvent.KEYCODE_DPAD_DOWN:
            password += doubleClick ? 9 : 4;
            break;
        case KeyEvent.KEYCODE_DPAD_CENTER:
            password += doubleClick ? 5 : 0;
            break;
        case KeyEvent.KEYCODE_0:
        case KeyEvent.KEYCODE_1:
        case KeyEvent.KEYCODE_2:
        case KeyEvent.KEYCODE_3:
        case KeyEvent.KEYCODE_4:
        case KeyEvent.KEYCODE_5:
        case KeyEvent.KEYCODE_6:
        case KeyEvent.KEYCODE_7:
        case KeyEvent.KEYCODE_8:
        case KeyEvent.KEYCODE_9:
            password += (char)event.getUnicodeChar();
            break;
    }
    //TvApp.getApplication().getLogger().Debug(password);
    pwField.setText(password);
}
 
Example 11
Source File: TerminalKeyboard.java    From java-n-IDE-for-Android with Apache License 2.0 5 votes vote down vote up
/**
     * 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) {
//        Log.v("SpartacusRex","SOFT : translateKeyDown "+keyCode);

        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;
        }

        boolean dead = false;

        if ((c & KeyCharacterMap.COMBINING_ACCENT) != 0) {
            dead = true;
            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;
    }
 
Example 12
Source File: InputImpl.java    From Game with GNU General Public License v3.0 4 votes vote down vote up
@Override
public boolean onKey(View v, int keyCode, KeyEvent event) {
    if (osConfig.C_VOLUME_TO_ROTATE) {
        if (keyCode == KeyEvent.KEYCODE_VOLUME_UP) {
            mudclient.keyLeft = event.getAction() == KeyEvent.ACTION_DOWN;
            return true;
        }
        if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) {
            mudclient.keyRight = event.getAction() == KeyEvent.ACTION_DOWN;
            return true;
        }
    }
    // If we are not volume to rotate, then we are volume to zoom...
    else {
        if (Config.S_ZOOM_VIEW_TOGGLE) {
            if (keyCode == KeyEvent.KEYCODE_VOLUME_UP) {
                mudclient.keyUp = event.getAction() == KeyEvent.ACTION_DOWN;
                return true;
            }
            if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) {
                mudclient.keyDown = event.getAction() == KeyEvent.ACTION_DOWN;
                return true;
            }
        }
    }

    if (event.getAction() == KeyEvent.ACTION_DOWN) {
        int key = event.getUnicodeChar();
        if (keyCode == KeyEvent.KEYCODE_DEL) {
            key = 8;
        }

        boolean hitInputFilter = false;

        for (int var5 = 0; var5 < Fonts.inputFilterChars.length(); ++var5) {
            if (Fonts.inputFilterChars.charAt(var5) == key) {
                hitInputFilter = true;

                break;
            }
        }

        mudclient.handleKeyPress((byte) 126, key);
        if (hitInputFilter && mudclient.inputTextCurrent.length() < 20) {
            mudclient.inputTextCurrent = mudclient.inputTextCurrent + (char) key;
        }

        if (hitInputFilter && mudclient.chatMessageInput.length() < 80) {
            mudclient.chatMessageInput = mudclient.chatMessageInput + (char) key;
        }

        // Backspace
        if (key == '\b' && mudclient.inputTextCurrent.length() > 0) {
            mudclient.inputTextCurrent = mudclient.inputTextCurrent.substring(0,
                    mudclient.inputTextCurrent.length() - 1);
        }

        // Backspace
        if (key == '\b' && mudclient.chatMessageInput.length() > 0) {
            mudclient.chatMessageInput = mudclient.chatMessageInput.substring(0,
                    mudclient.chatMessageInput.length() - 1);
        }

        if (key == 10 || key == 13) {
            mudclient.inputTextFinal = mudclient.inputTextCurrent;
            mudclient.chatMessageInputCommit = mudclient.chatMessageInput;
        }
        return true;
    }
    return false;
}
 
Example 13
Source File: HardwareKeyboardEventDecoder.java    From AOSP-Kayboard-7.1.2 with Apache License 2.0 4 votes vote down vote up
@Override
public Event decodeHardwareKey(final KeyEvent keyEvent) {
    // KeyEvent#getUnicodeChar() does not exactly returns a unicode char, but rather a value
    // that includes both the unicode char in the lower 21 bits and flags in the upper bits,
    // hence the name "codePointAndFlags". {@see KeyEvent#getUnicodeChar()} for more info.
    final int codePointAndFlags = keyEvent.getUnicodeChar();
    // The keyCode is the abstraction used by the KeyEvent to represent different keys that
    // do not necessarily map to a unicode character. This represents a physical key, like
    // the key for 'A' or Space, but also Backspace or Ctrl or Caps Lock.
    final int keyCode = keyEvent.getKeyCode();
    final boolean isKeyRepeat = (0 != keyEvent.getRepeatCount());
    if (KeyEvent.KEYCODE_DEL == keyCode) {
        return Event.createHardwareKeypressEvent(Event.NOT_A_CODE_POINT, Constants.CODE_DELETE,
                null /* next */, isKeyRepeat);
    }
    if (keyEvent.isPrintingKey() || KeyEvent.KEYCODE_SPACE == keyCode
            || KeyEvent.KEYCODE_ENTER == keyCode) {
        if (0 != (codePointAndFlags & KeyCharacterMap.COMBINING_ACCENT)) {
            // A dead key.
            return Event.createDeadEvent(
                    codePointAndFlags & KeyCharacterMap.COMBINING_ACCENT_MASK, keyCode,
                    null /* next */);
        }
        if (KeyEvent.KEYCODE_ENTER == keyCode) {
            // The Enter key. If the Shift key is not being pressed, this should send a
            // CODE_ENTER to trigger the action if any, or a carriage return otherwise. If the
            // Shift key is being pressed, this should send a CODE_SHIFT_ENTER and let
            // Latin IME decide what to do with it.
            if (keyEvent.isShiftPressed()) {
                return Event.createHardwareKeypressEvent(Event.NOT_A_CODE_POINT,
                        Constants.CODE_SHIFT_ENTER, null /* next */, isKeyRepeat);
            }
            return Event.createHardwareKeypressEvent(Constants.CODE_ENTER, keyCode,
                    null /* next */, isKeyRepeat);
        }
        // If not Enter, then this is just a regular keypress event for a normal character
        // that can be committed right away, taking into account the current state.
        return Event.createHardwareKeypressEvent(codePointAndFlags, keyCode, null /* next */,
                isKeyRepeat);
    }
    return Event.createNotHandledEvent();
}
 
Example 14
Source File: KeyboardWidget.java    From FirefoxReality with Mozilla Public License 2.0 4 votes vote down vote up
@Override
public boolean dispatchKeyEvent(final KeyEvent event) {
    final int keyCode = event.getKeyCode();
    final InputConnection connection = mInputConnection;
    if (connection != null) {
        if (isAttachToWindowWidget()) {
            if (event.getKeyCode() == KeyEvent.KEYCODE_BACK) {
                return false;
            } else {
                connection.sendKeyEvent(event);
                hide(UIWidget.KEEP_WIDGET);
            }
            return true;
        }
        // Android Components do not support InputConnection.sendKeyEvent()
        if (event.getAction() == KeyEvent.ACTION_DOWN) {
            Log.e("reb", "key = " + KeyEvent.keyCodeToString(keyCode));

            switch (keyCode) {
                case KeyEvent.KEYCODE_DEL:
                    handleBackspace();
                    return true;
                case KeyEvent.KEYCODE_ENTER:
                case KeyEvent.KEYCODE_NUMPAD_ENTER:
                    handleDone();
                    return true;
                case KeyEvent.KEYCODE_DPAD_LEFT:
                    moveCursor(-1);
                    return true;
                case KeyEvent.KEYCODE_DPAD_RIGHT:
                    moveCursor(1);
                    return true;
                default:
                    break;
            }
            if (event.getUnicodeChar() != 0) {
                KeyCharacterMap map = event.getKeyCharacterMap();
                String value = String.valueOf((char) map.get(keyCode, event.getMetaState()));
                connection.commitText(value, 1);
                return true;
            }
        }
    }
    return false;
}
 
Example 15
Source File: PlaybackActivity.java    From android-vlc-remote with GNU General Public License v3.0 4 votes vote down vote up
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    int c = event.getUnicodeChar();
    if (keyCode == KeyEvent.KEYCODE_VOLUME_UP) {
        if (mVolumeLevel != VOLUME_LEVEL_UNKNOWN) {
            setVolume(mVolumeLevel + 20);
        } else {
            mMediaServer.status().command.volumeUp();
        }
        return true;
    } else if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN) {
        if (mVolumeLevel != VOLUME_LEVEL_UNKNOWN) {
            setVolume(mVolumeLevel - 20);
        } else {
            mMediaServer.status().command.volumeDown();
        }
        return true;
    } else if (keyCode == KeyEvent.KEYCODE_DPAD_LEFT) {
        if (event.isAltPressed()) {
            mMediaServer.status().command.seek(Uri.encode("-".concat(Preferences.get(this).getSeekTime())));
            return true;
        } else if (event.isShiftPressed()) {
            mMediaServer.status().command.seek(Uri.encode("-3"));
            return true;
        } else {
            mMediaServer.status().command.key("nav-left");
            return true;
        }
    } else if (keyCode == KeyEvent.KEYCODE_DPAD_RIGHT) {
        if (event.isAltPressed()) {
            mMediaServer.status().command.seek(Uri.encode("+".concat(Preferences.get(this).getSeekTime())));
            return true;
        } else if (event.isShiftPressed()) {
            mMediaServer.status().command.seek(Uri.encode("+3"));
            return true;
        } else {
            mMediaServer.status().command.key("nav-right");
            return true;
        }
    } else if (keyCode == KeyEvent.KEYCODE_DPAD_UP) {
        mMediaServer.status().command.key("nav-up");
        return true;
    } else if (keyCode == KeyEvent.KEYCODE_DPAD_DOWN) {
        mMediaServer.status().command.key("nav-down");
        return true;
    } else if (keyCode == KeyEvent.KEYCODE_DPAD_CENTER) {
        mMediaServer.status().command.key("nav-activate");
        return true;
    } else if (c == ' ') {
        mMediaServer.status().command.playback.pause();
        return true;
    } else if (c == 's') {
        mMediaServer.status().command.playback.stop();
        return true;
    } else if (c == 'p') {
        mMediaServer.status().command.playback.previous();
        return true;
    } else if (c == 'n') {
        mMediaServer.status().command.playback.next();
        return true;
    } else if (c == '+') {
        // TODO: Play faster
        return super.onKeyDown(keyCode, event);
    } else if (c == '-') {
        // TODO: Play slower
        return super.onKeyDown(keyCode, event);
    } else if (c == 'f') {
        mMediaServer.status().command.fullscreen();
        return true;
    } else if (c == 'm') {
        mute();
        return true;
    } else {
        return super.onKeyDown(keyCode, event);
    }
}
 
Example 16
Source File: HardwareKeyboardEventDecoder.java    From Indic-Keyboard with Apache License 2.0 4 votes vote down vote up
@Override
public Event decodeHardwareKey(final KeyEvent keyEvent) {
    // KeyEvent#getUnicodeChar() does not exactly returns a unicode char, but rather a value
    // that includes both the unicode char in the lower 21 bits and flags in the upper bits,
    // hence the name "codePointAndFlags". {@see KeyEvent#getUnicodeChar()} for more info.
    final int codePointAndFlags = keyEvent.getUnicodeChar();
    // The keyCode is the abstraction used by the KeyEvent to represent different keys that
    // do not necessarily map to a unicode character. This represents a physical key, like
    // the key for 'A' or Space, but also Backspace or Ctrl or Caps Lock.
    final int keyCode = keyEvent.getKeyCode();
    final boolean isKeyRepeat = (0 != keyEvent.getRepeatCount());
    if (KeyEvent.KEYCODE_DEL == keyCode) {
        return Event.createHardwareKeypressEvent(Event.NOT_A_CODE_POINT, Constants.CODE_DELETE,
                null /* next */, isKeyRepeat);
    }
    if (keyEvent.isPrintingKey() || KeyEvent.KEYCODE_SPACE == keyCode
            || KeyEvent.KEYCODE_ENTER == keyCode) {
        if (0 != (codePointAndFlags & KeyCharacterMap.COMBINING_ACCENT)) {
            // A dead key.
            return Event.createDeadEvent(
                    codePointAndFlags & KeyCharacterMap.COMBINING_ACCENT_MASK, keyCode,
                    null /* next */);
        }
        if (KeyEvent.KEYCODE_ENTER == keyCode) {
            // The Enter key. If the Shift key is not being pressed, this should send a
            // CODE_ENTER to trigger the action if any, or a carriage return otherwise. If the
            // Shift key is being pressed, this should send a CODE_SHIFT_ENTER and let
            // Latin IME decide what to do with it.
            if (keyEvent.isShiftPressed()) {
                return Event.createHardwareKeypressEvent(Event.NOT_A_CODE_POINT,
                        Constants.CODE_SHIFT_ENTER, null /* next */, isKeyRepeat);
            }
            return Event.createHardwareKeypressEvent(Constants.CODE_ENTER, keyCode,
                    null /* next */, isKeyRepeat);
        }
        // If not Enter, then this is just a regular keypress event for a normal character
        // that can be committed right away, taking into account the current state.
        return Event.createHardwareKeypressEvent(codePointAndFlags, keyCode, null /* next */,
                isKeyRepeat);
    }
    return Event.createNotHandledEvent();
}
 
Example 17
Source File: UnicodeIME.java    From io.appium.android.ime with Apache License 2.0 4 votes vote down vote up
private int getUnicodeChar(int keyCode, KeyEvent event) {
    metaState = MetaKeyKeyListener.handleKeyDown(metaState, keyCode, event);
    int c = event.getUnicodeChar(event.getMetaState());
    metaState = MetaKeyKeyListener.adjustMetaAfterKeypress(metaState);
    return c;
}
 
Example 18
Source File: UnicodeIME.java    From io.appium.settings with Apache License 2.0 4 votes vote down vote up
private int getUnicodeChar(int keyCode, KeyEvent event) {
    metaState = MetaKeyKeyListener.handleKeyDown(metaState, keyCode, event);
    int c = event.getUnicodeChar(event.getMetaState());
    metaState = MetaKeyKeyListener.adjustMetaAfterKeypress(metaState);
    return c;
}
 
Example 19
Source File: AdapterInputConnection.java    From android-chromium with BSD 2-Clause "Simplified" License 4 votes vote down vote up
/**
 * @see BaseInputConnection#sendKeyEvent(android.view.KeyEvent)
 */
@Override
public boolean sendKeyEvent(KeyEvent event) {
    if (DEBUG) {
        Log.w(TAG, "sendKeyEvent [" + event.getAction() + "] [" + event.getKeyCode() + "]");
    }
    // If this is a key-up, and backspace/del or if the key has a character representation,
    // need to update the underlying Editable (i.e. the local representation of the text
    // being edited).
    if (event.getAction() == KeyEvent.ACTION_UP) {
        if (event.getKeyCode() == KeyEvent.KEYCODE_DEL) {
            deleteSurroundingText(1, 0);
            return true;
        } else if (event.getKeyCode() == KeyEvent.KEYCODE_FORWARD_DEL) {
            deleteSurroundingText(0, 1);
            return true;
        } else {
            int unicodeChar = event.getUnicodeChar();
            if (unicodeChar != 0) {
                Editable editable = getEditable();
                int selectionStart = Selection.getSelectionStart(editable);
                int selectionEnd = Selection.getSelectionEnd(editable);
                if (selectionStart > selectionEnd) {
                    int temp = selectionStart;
                    selectionStart = selectionEnd;
                    selectionEnd = temp;
                }
                editable.replace(selectionStart, selectionEnd,
                        Character.toString((char)unicodeChar));
            }
        }
    } else if (event.getAction() == KeyEvent.ACTION_DOWN) {
        // TODO(aurimas): remove this workaround when crbug.com/278584 is fixed.
        if (event.getKeyCode() == KeyEvent.KEYCODE_ENTER) {
            beginBatchEdit();
            finishComposingText();
            mImeAdapter.translateAndSendNativeEvents(event);
            endBatchEdit();
            return true;
        } else if (event.getKeyCode() == KeyEvent.KEYCODE_DEL) {
            return true;
        } else if (event.getKeyCode() == KeyEvent.KEYCODE_FORWARD_DEL) {
            return true;
        }
    }
    mImeAdapter.translateAndSendNativeEvents(event);
    return true;
}
 
Example 20
Source File: FastEdit.java    From fastedit with Apache License 2.0 4 votes vote down vote up
void onKeyEvent(KeyEvent event) {
    int action = event.getAction();
    int keyCode = event.getKeyCode();
    switch (action) {
        case KeyEvent.ACTION_DOWN: {

            //输入模式
            int unicodeChar = event.getUnicodeChar();
            if (unicodeChar != 0) {

                input((char) unicodeChar);
                event.cancel();
            }
            if (!event.isCanceled() && !event.isCtrlPressed() && !event.isAltPressed()
                    && !event.isShiftPressed()) {
                switch (keyCode) {
                    case KeyEvent.KEYCODE_TAB:
                        //tab
                        input(tabText);
                        event.cancel();
                        break;
                    case KeyEvent.KEYCODE_SPACE:
                        //空格
                        input(' ');
                        event.cancel();
                        break;
                    case KeyEvent.KEYCODE_ENTER:
                        //enter
                        onKeyCodeEnter(event);
                        event.cancel();
                        break;
                    case KeyEvent.KEYCODE_DEL:
                        //del
                        onKeyCodeDel(event);
                        event.cancel();
                        break;
                    case KeyEvent.KEYCODE_FORWARD_DEL:
                        //del
                        onKeyCodeForwardDel(event);
                        event.cancel();
                        break;
                    case KeyEvent.KEYCODE_DPAD_LEFT:
                        //left
                        onKeyCodeDpadLeft(event);
                        event.cancel();
                        break;
                    case KeyEvent.KEYCODE_DPAD_RIGHT:
                        //right
                        onKeyCodeDpadRight(event);
                        event.cancel();
                        break;
                    case KeyEvent.KEYCODE_DPAD_UP:
                        //up
                        onKeyCodeDpadUp(event);
                        event.cancel();
                        break;
                    case KeyEvent.KEYCODE_DPAD_DOWN:
                        //down
                        onKeyCodeDpadDown(event);
                        event.cancel();
                        break;
                    case KeyEvent.KEYCODE_VOLUME_DOWN:

                    case KeyEvent.KEYCODE_PAGE_DOWN:
                        //page down
                        onKeyCodePageDown(event);
                        event.cancel();
                        break;
                    case KeyEvent.KEYCODE_VOLUME_UP:

                    case KeyEvent.KEYCODE_PAGE_UP:
                        //page up
                        onKeyCodePageUp(event);
                        event.cancel();
                        break;
                    case KeyEvent.KEYCODE_MOVE_HOME:
                        onKeyCodeMoveHome(event);
                        event.cancel();
                        break;
                    case KeyEvent.KEYCODE_MOVE_END:
                        onKeyCodeMoveEnd(event);
                        event.cancel();
                        break;
                }
            }
            if (!event.isCanceled()) {
                //快捷键模式
                if (onShortKey(event.isCtrlPressed(), event.isAltPressed(), event.isShiftPressed(), keyCode)) {
                    event.cancel();
                }
            }

            break;
        }

    }
}