Example usage for android.view KeyEvent KEYCODE_ALT_RIGHT

List of usage examples for android.view KeyEvent KEYCODE_ALT_RIGHT

Introduction

In this page you can find the example usage for android.view KeyEvent KEYCODE_ALT_RIGHT.

Prototype

int KEYCODE_ALT_RIGHT

To view the source code for android.view KeyEvent KEYCODE_ALT_RIGHT.

Click Source Link

Document

Key code constant: Right Alt modifier key.

Usage

From source file:com.yek.keyboard.anysoftkeyboard.AnySoftKeyboard.java

@Override
public boolean onKeyDown(final int keyEventKeyCode, @NonNull KeyEvent event) {
    InputConnection ic = getCurrentInputConnection();
    if (handleSelectionExpending(keyEventKeyCode, ic, mGlobalSelectionStartPosition, mGlobalCursorPosition))
        return true;
    final boolean shouldTranslateSpecialKeys = isInputViewShown();

    //greater than zero means it is a physical keyboard.
    //we also want to hide the view if it's a glyph (for example, not physical volume-up key)
    if (event.getDeviceId() > 0 && event.isPrintingKey())
        onPhysicalKeyboardKeyPressed();//from w w w .ja  va2  s .co  m

    mHardKeyboardAction.initializeAction(event, mMetaState);

    switch (keyEventKeyCode) {
    /****
     * SPECIAL translated HW keys If you add new keys here, do not forget
     * to add to the
     */
    case KeyEvent.KEYCODE_CAMERA:
        if (shouldTranslateSpecialKeys && mAskPrefs.useCameraKeyForBackspaceBackword()) {
            handleBackWord(getCurrentInputConnection());
            return true;
        }
        // DO NOT DELAY CAMERA KEY with unneeded checks in default mark
        return super.onKeyDown(keyEventKeyCode, event);
    case KeyEvent.KEYCODE_FOCUS:
        if (shouldTranslateSpecialKeys && mAskPrefs.useCameraKeyForBackspaceBackword()) {
            handleDeleteLastCharacter(false);
            return true;
        }
        // DO NOT DELAY FOCUS KEY with unneeded checks in default mark
        return super.onKeyDown(keyEventKeyCode, event);
    case KeyEvent.KEYCODE_VOLUME_UP:
        if (shouldTranslateSpecialKeys && mAskPrefs.useVolumeKeyForLeftRight()) {
            sendDownUpKeyEvents(KeyEvent.KEYCODE_DPAD_LEFT);
            return true;
        }
        // DO NOT DELAY VOLUME UP KEY with unneeded checks in default
        // mark
        return super.onKeyDown(keyEventKeyCode, event);
    case KeyEvent.KEYCODE_VOLUME_DOWN:
        if (shouldTranslateSpecialKeys && mAskPrefs.useVolumeKeyForLeftRight()) {
            sendDownUpKeyEvents(KeyEvent.KEYCODE_DPAD_RIGHT);
            return true;
        }
        // DO NOT DELAY VOLUME DOWN KEY with unneeded checks in default
        // mark
        return super.onKeyDown(keyEventKeyCode, event);
    /****
     * END of SPECIAL translated HW keys code section
     */
    case KeyEvent.KEYCODE_BACK:
        if (event.getRepeatCount() == 0 && getInputView() != null) {
            if (getInputView().handleBack()) {
                // consuming the meta keys
                if (ic != null) {
                    // translated, so we also take care of the metakeys
                    ic.clearMetaKeyStates(Integer.MAX_VALUE);
                }
                mMetaState = 0;
                return true;
            }
        }
        break;
    case 0x000000cc:// API 14: KeyEvent.KEYCODE_LANGUAGE_SWITCH
        switchToNextPhysicalKeyboard(ic);
        return true;
    case KeyEvent.KEYCODE_SHIFT_LEFT:
    case KeyEvent.KEYCODE_SHIFT_RIGHT:
        if (event.isAltPressed() && Workarounds.isAltSpaceLangSwitchNotPossible()) {
            switchToNextPhysicalKeyboard(ic);
            return true;
        }
        // NOTE: letting it fall-through to the other meta-keys
    case KeyEvent.KEYCODE_ALT_LEFT:
    case KeyEvent.KEYCODE_ALT_RIGHT:
    case KeyEvent.KEYCODE_SYM:
        Logger.d(TAG + "-meta-key", getMetaKeysStates("onKeyDown before handle"));
        mMetaState = MyMetaKeyKeyListener.handleKeyDown(mMetaState, keyEventKeyCode, event);
        Logger.d(TAG + "-meta-key", getMetaKeysStates("onKeyDown after handle"));
        break;
    case KeyEvent.KEYCODE_SPACE:
        if ((event.isAltPressed() && !Workarounds.isAltSpaceLangSwitchNotPossible())
                || event.isShiftPressed()) {
            switchToNextPhysicalKeyboard(ic);
            return true;
        }
        // NOTE:
        // letting it fall through to the "default"
    default:

        // Fix issue 185, check if we should process key repeat
        if (!mAskPrefs.getUseRepeatingKeys() && event.getRepeatCount() > 0)
            return true;

        AnyKeyboard.HardKeyboardTranslator keyTranslator = (AnyKeyboard.HardKeyboardTranslator) getCurrentAlphabetKeyboard();
        if (getKeyboardSwitcher().isCurrentKeyboardPhysical() && keyTranslator != null) {
            // sometimes, the physical keyboard will delete input, and then add some.
            // we'll try to make it nice.
            if (ic != null)
                ic.beginBatchEdit();
            try {
                // issue 393, backword on the hw keyboard!
                if (mAskPrefs.useBackword() && keyEventKeyCode == KeyEvent.KEYCODE_DEL
                        && event.isShiftPressed()) {
                    handleBackWord(ic);
                    return true;
                } else {
                    // http://article.gmane.org/gmane.comp.handhelds.openmoko.android-freerunner/629
                    keyTranslator.translatePhysicalCharacter(mHardKeyboardAction, this);

                    if (mHardKeyboardAction.getKeyCodeWasChanged()) {
                        final int translatedChar = mHardKeyboardAction.getKeyCode();
                        // typing my own.
                        onKey(translatedChar, null, -1, new int[] { translatedChar }, true/*faking from UI*/);
                        // my handling we are at a regular key press, so we'll update
                        // our meta-state member
                        mMetaState = MyMetaKeyKeyListener.adjustMetaAfterKeypress(mMetaState);
                        Logger.d(TAG + "-meta-key", getMetaKeysStates("onKeyDown after adjust - translated"));
                        return true;
                    }
                }
            } finally {
                if (ic != null)
                    ic.endBatchEdit();
            }
        }
        if (event.isPrintingKey()) {
            // we are at a regular key press, so we'll update our
            // meta-state
            // member
            mMetaState = MyMetaKeyKeyListener.adjustMetaAfterKeypress(mMetaState);
            Logger.d(TAG + "-meta-key", getMetaKeysStates("onKeyDown after adjust"));
        }
    }
    return super.onKeyDown(keyEventKeyCode, event);
}

From source file:com.anysoftkeyboard.AnySoftKeyboard.java

@Override
public boolean onKeyDown(final int keyEventKeyCode, @NonNull KeyEvent event) {
    InputConnection ic = getCurrentInputConnection();
    if (handleSelectionExpending(keyEventKeyCode, ic, mGlobalSelectionStartPosition, mGlobalCursorPosition))
        return true;
    final boolean shouldTranslateSpecialKeys = isInputViewShown();

    //greater than zero means it is a physical keyboard.
    //we also want to hide the view if it's a glyph (for example, not physical volume-up key)
    if (event.getDeviceId() > 0 && event.isPrintingKey())
        onPhysicalKeyboardKeyPressed();//w  ww .  j a  va 2 s  . com

    mHardKeyboardAction.initializeAction(event, mMetaState);

    switch (keyEventKeyCode) {
    /****
     * SPECIAL translated HW keys If you add new keys here, do not forget
     * to add to the
     */
    case KeyEvent.KEYCODE_CAMERA:
        if (shouldTranslateSpecialKeys && mAskPrefs.useCameraKeyForBackspaceBackword()) {
            handleBackWord(getCurrentInputConnection());
            return true;
        }
        // DO NOT DELAY CAMERA KEY with unneeded checks in default mark
        return super.onKeyDown(keyEventKeyCode, event);
    case KeyEvent.KEYCODE_FOCUS:
        if (shouldTranslateSpecialKeys && mAskPrefs.useCameraKeyForBackspaceBackword()) {
            handleDeleteLastCharacter(false);
            return true;
        }
        // DO NOT DELAY FOCUS KEY with unneeded checks in default mark
        return super.onKeyDown(keyEventKeyCode, event);
    case KeyEvent.KEYCODE_VOLUME_UP:
        if (shouldTranslateSpecialKeys && mAskPrefs.useVolumeKeyForLeftRight()) {
            sendDownUpKeyEvents(KeyEvent.KEYCODE_DPAD_LEFT);
            return true;
        }
        // DO NOT DELAY VOLUME UP KEY with unneeded checks in default
        // mark
        return super.onKeyDown(keyEventKeyCode, event);
    case KeyEvent.KEYCODE_VOLUME_DOWN:
        if (shouldTranslateSpecialKeys && mAskPrefs.useVolumeKeyForLeftRight()) {
            sendDownUpKeyEvents(KeyEvent.KEYCODE_DPAD_RIGHT);
            return true;
        }
        // DO NOT DELAY VOLUME DOWN KEY with unneeded checks in default
        // mark
        return super.onKeyDown(keyEventKeyCode, event);
    /****
     * END of SPECIAL translated HW keys code section
     */
    case KeyEvent.KEYCODE_BACK:
        if (event.getRepeatCount() == 0 && getInputView() != null) {
            if (getInputView().handleBack()) {
                // consuming the meta keys
                if (ic != null) {
                    // translated, so we also take care of the metakeys
                    ic.clearMetaKeyStates(Integer.MAX_VALUE);
                }
                mMetaState = 0;
                return true;
            }
        }
        break;
    case 0x000000cc:// API 14: KeyEvent.KEYCODE_LANGUAGE_SWITCH
        switchToNextPhysicalKeyboard(ic);
        return true;
    case KeyEvent.KEYCODE_SHIFT_LEFT:
    case KeyEvent.KEYCODE_SHIFT_RIGHT:
        if (event.isAltPressed() && Workarounds.isAltSpaceLangSwitchNotPossible()) {
            switchToNextPhysicalKeyboard(ic);
            return true;
        }
        // NOTE: letting it fall-through to the other meta-keys
    case KeyEvent.KEYCODE_ALT_LEFT:
    case KeyEvent.KEYCODE_ALT_RIGHT:
    case KeyEvent.KEYCODE_SYM:
        Logger.d(TAG + "-meta-key", getMetaKeysStates("onKeyDown before handle"));
        mMetaState = MyMetaKeyKeyListener.handleKeyDown(mMetaState, keyEventKeyCode, event);
        Logger.d(TAG + "-meta-key", getMetaKeysStates("onKeyDown after handle"));
        break;
    case KeyEvent.KEYCODE_SPACE:
        if ((event.isAltPressed() && !Workarounds.isAltSpaceLangSwitchNotPossible())
                || event.isShiftPressed()) {
            switchToNextPhysicalKeyboard(ic);
            return true;
        }
        // NOTE:
        // letting it fall through to the "default"
    default:

        // Fix issue 185, check if we should process key repeat
        if (!mAskPrefs.getUseRepeatingKeys() && event.getRepeatCount() > 0)
            return true;

        HardKeyboardTranslator keyTranslator = (HardKeyboardTranslator) getCurrentAlphabetKeyboard();
        if (getKeyboardSwitcher().isCurrentKeyboardPhysical() && keyTranslator != null) {
            // sometimes, the physical keyboard will delete input, and then add some.
            // we'll try to make it nice.
            if (ic != null)
                ic.beginBatchEdit();
            try {
                // issue 393, backword on the hw keyboard!
                if (mAskPrefs.useBackword() && keyEventKeyCode == KeyEvent.KEYCODE_DEL
                        && event.isShiftPressed()) {
                    handleBackWord(ic);
                    return true;
                } else {
                    // http://article.gmane.org/gmane.comp.handhelds.openmoko.android-freerunner/629
                    keyTranslator.translatePhysicalCharacter(mHardKeyboardAction, this);

                    if (mHardKeyboardAction.getKeyCodeWasChanged()) {
                        final int translatedChar = mHardKeyboardAction.getKeyCode();
                        // typing my own.
                        onKey(translatedChar, null, -1, new int[] { translatedChar }, true/*faking from UI*/);
                        // my handling we are at a regular key press, so we'll update
                        // our meta-state member
                        mMetaState = MyMetaKeyKeyListener.adjustMetaAfterKeypress(mMetaState);
                        Logger.d(TAG + "-meta-key", getMetaKeysStates("onKeyDown after adjust - translated"));
                        return true;
                    }
                }
            } finally {
                if (ic != null)
                    ic.endBatchEdit();
            }
        }
        if (event.isPrintingKey()) {
            // we are at a regular key press, so we'll update our
            // meta-state
            // member
            mMetaState = MyMetaKeyKeyListener.adjustMetaAfterKeypress(mMetaState);
            Logger.d(TAG + "-meta-key", getMetaKeysStates("onKeyDown after adjust"));
        }
    }
    return super.onKeyDown(keyEventKeyCode, event);
}

From source file:com.anysoftkeyboard.AnySoftKeyboard.java

@Override
public boolean onKeyUp(int keyCode, @NonNull KeyEvent event) {
    Logger.d(TAG, "onKeyUp keycode=%d", keyCode);
    switch (keyCode) {
    // Issue 248/*from  www .j av  a  2 s .  c om*/
    case KeyEvent.KEYCODE_VOLUME_DOWN:
    case KeyEvent.KEYCODE_VOLUME_UP:
        if (!isInputViewShown()) {
            return super.onKeyUp(keyCode, event);
        }
        if (mAskPrefs.useVolumeKeyForLeftRight()) {
            // no need of vol up/down sound
            return true;
        }
    case KeyEvent.KEYCODE_DPAD_DOWN:
    case KeyEvent.KEYCODE_DPAD_UP:
    case KeyEvent.KEYCODE_DPAD_LEFT:
    case KeyEvent.KEYCODE_DPAD_RIGHT:
        if (getInputView() != null && getInputView().isShown() && getInputView().isShifted()) {
            event = new KeyEvent(event.getDownTime(), event.getEventTime(), event.getAction(),
                    event.getKeyCode(), event.getRepeatCount(), event.getDeviceId(), event.getScanCode(),
                    KeyEvent.META_SHIFT_LEFT_ON | KeyEvent.META_SHIFT_ON);
            InputConnection ic = getCurrentInputConnection();
            if (ic != null)
                ic.sendKeyEvent(event);

            return true;
        }
        break;
    case KeyEvent.KEYCODE_ALT_LEFT:
    case KeyEvent.KEYCODE_ALT_RIGHT:
    case KeyEvent.KEYCODE_SHIFT_LEFT:
    case KeyEvent.KEYCODE_SHIFT_RIGHT:
    case KeyEvent.KEYCODE_SYM:
        mMetaState = MyMetaKeyKeyListener.handleKeyUp(mMetaState, keyCode, event);
        Logger.d(TAG + "-meta-key", getMetaKeysStates("onKeyUp"));
        setInputConnectionMetaStateAsCurrentMetaKeyKeyListenerState();
        break;
    }
    return super.onKeyUp(keyCode, event);
}