Example usage for android.view KeyEvent getRepeatCount

List of usage examples for android.view KeyEvent getRepeatCount

Introduction

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

Prototype

public final int getRepeatCount() 

Source Link

Document

Retrieve the repeat count of the event.

Usage

From source file:org.pocketworkstation.pckeyboard.LatinIME.java

@Override
public boolean onKeyUp(int keyCode, KeyEvent event) {
    switch (keyCode) {
    case KeyEvent.KEYCODE_DPAD_DOWN:
    case KeyEvent.KEYCODE_DPAD_UP:
    case KeyEvent.KEYCODE_DPAD_LEFT:
    case KeyEvent.KEYCODE_DPAD_RIGHT:
        LatinKeyboardView inputView = mKeyboardSwitcher.getInputView();
        // Enable shift key and DPAD to do selections
        if (inputView != null && inputView.isShown() && inputView.getShiftState() == Keyboard.SHIFT_ON) {
            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);/*from w  w  w. j  a  v  a  2s  .c o  m*/
            return true;
        }
        break;
    case KeyEvent.KEYCODE_VOLUME_UP:
        if (!mVolUpAction.equals("none") && isKeyboardVisible()) {
            return doSwipeAction(mVolUpAction);
        }
        break;
    case KeyEvent.KEYCODE_VOLUME_DOWN:
        if (!mVolDownAction.equals("none") && isKeyboardVisible()) {
            return doSwipeAction(mVolDownAction);
        }
        break;
    }
    return super.onKeyUp(keyCode, event);
}

From source file:com.appunite.list.GridView.java

private boolean commonKey(int keyCode, int count, KeyEvent event) {
    if (mAdapter == null) {
        return false;
    }//  w  w  w  .j a va 2s. c o m

    if (mDataChanged) {
        layoutChildren();
    }

    boolean handled = false;
    int action = event.getAction();

    if (action != KeyEvent.ACTION_UP) {
        switch (keyCode) {
        case KeyEvent.KEYCODE_DPAD_LEFT:
            if (KeyEventCompat.hasNoModifiers(event)) {
                handled = resurrectSelectionIfNeeded() || arrowScroll(FOCUS_LEFT);
            }
            break;

        case KeyEvent.KEYCODE_DPAD_RIGHT:
            if (KeyEventCompat.hasNoModifiers(event)) {
                handled = resurrectSelectionIfNeeded() || arrowScroll(FOCUS_RIGHT);
            }
            break;

        case KeyEvent.KEYCODE_DPAD_UP:
            if (KeyEventCompat.hasNoModifiers(event)) {
                handled = resurrectSelectionIfNeeded() || arrowScroll(FOCUS_UP);
            } else if (KeyEventCompat.hasModifiers(event, KeyEvent.META_ALT_ON)) {
                handled = resurrectSelectionIfNeeded() || fullScroll(FOCUS_UP);
            }
            break;

        case KeyEvent.KEYCODE_DPAD_DOWN:
            if (KeyEventCompat.hasNoModifiers(event)) {
                handled = resurrectSelectionIfNeeded() || arrowScroll(FOCUS_DOWN);
            } else if (KeyEventCompat.hasModifiers(event, KeyEvent.META_ALT_ON)) {
                handled = resurrectSelectionIfNeeded() || fullScroll(FOCUS_DOWN);
            }
            break;

        case KeyEvent.KEYCODE_DPAD_CENTER:
        case KeyEvent.KEYCODE_ENTER:
            if (KeyEventCompat.hasNoModifiers(event)) {
                handled = resurrectSelectionIfNeeded();
                if (!handled && event.getRepeatCount() == 0 && getChildCount() > 0) {
                    keyPressed();
                    handled = true;
                }
            }
            break;

        case KeyEvent.KEYCODE_SPACE:
            if (mPopup == null || !mPopup.isShowing()) {
                if (KeyEventCompat.hasNoModifiers(event)) {
                    handled = resurrectSelectionIfNeeded() || pageScroll(FOCUS_DOWN);
                } else if (KeyEventCompat.hasModifiers(event, KeyEvent.META_SHIFT_ON)) {
                    handled = resurrectSelectionIfNeeded() || pageScroll(FOCUS_UP);
                }
            }
            break;

        case KeyEvent.KEYCODE_PAGE_UP:
            if (KeyEventCompat.hasNoModifiers(event)) {
                handled = resurrectSelectionIfNeeded() || pageScroll(FOCUS_UP);
            } else if (KeyEventCompat.hasModifiers(event, KeyEvent.META_ALT_ON)) {
                handled = resurrectSelectionIfNeeded() || fullScroll(FOCUS_UP);
            }
            break;

        case KeyEvent.KEYCODE_PAGE_DOWN:
            if (KeyEventCompat.hasNoModifiers(event)) {
                handled = resurrectSelectionIfNeeded() || pageScroll(FOCUS_DOWN);
            } else if (KeyEventCompat.hasModifiers(event, KeyEvent.META_ALT_ON)) {
                handled = resurrectSelectionIfNeeded() || fullScroll(FOCUS_DOWN);
            }
            break;

        case KeyEvent.KEYCODE_MOVE_HOME:
            if (KeyEventCompat.hasNoModifiers(event)) {
                handled = resurrectSelectionIfNeeded() || fullScroll(FOCUS_UP);
            }
            break;

        case KeyEvent.KEYCODE_MOVE_END:
            if (KeyEventCompat.hasNoModifiers(event)) {
                handled = resurrectSelectionIfNeeded() || fullScroll(FOCUS_DOWN);
            }
            break;

        case KeyEvent.KEYCODE_TAB:
            // XXX Sometimes it is useful to be able to TAB through the items in
            //     a GridView sequentially.  Unfortunately this can create an
            //     asymmetry in TAB navigation order unless the list selection
            //     always reverts to the top or bottom when receiving TAB focus from
            //     another widget.  Leaving this behavior disabled for now but
            //     perhaps it should be configurable (and more comprehensive).
            if (false) {
                if (KeyEventCompat.hasNoModifiers(event)) {
                    handled = resurrectSelectionIfNeeded() || sequenceScroll(FOCUS_FORWARD);
                } else if (KeyEventCompat.hasModifiers(event, KeyEvent.META_SHIFT_ON)) {
                    handled = resurrectSelectionIfNeeded() || sequenceScroll(FOCUS_BACKWARD);
                }
            }
            break;
        }
    }

    if (handled) {
        return true;
    }

    if (sendToTextFilter(keyCode, count, event)) {
        return true;
    }

    switch (action) {
    case KeyEvent.ACTION_DOWN:
        return super.onKeyDown(keyCode, event);
    case KeyEvent.ACTION_UP:
        return super.onKeyUp(keyCode, event);
    case KeyEvent.ACTION_MULTIPLE:
        return super.onKeyMultiple(keyCode, count, event);
    default:
        return false;
    }
}

From source file:com.android.tv.MainActivity.java

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (SystemProperties.LOG_KEYEVENT.getValue()) {
        Log.d(TAG, "onKeyDown(" + keyCode + ", " + event + ")");
    }//from  w w w  .ja v  a2 s  . c  o  m
    switch (mOverlayManager.onKeyDown(keyCode, event)) {
    case KEY_EVENT_HANDLER_RESULT_DISPATCH_TO_OVERLAY:
        return super.onKeyDown(keyCode, event);
    case KEY_EVENT_HANDLER_RESULT_HANDLED:
        return true;
    case KEY_EVENT_HANDLER_RESULT_NOT_HANDLED:
        return false;
    case KEY_EVENT_HANDLER_RESULT_PASSTHROUGH:
    default:
        // pass through
    }
    if (mSearchFragment.isVisible()) {
        return super.onKeyDown(keyCode, event);
    }
    if (!mChannelTuner.areAllChannelsLoaded()) {
        return false;
    }
    if (!mChannelTuner.isCurrentChannelPassthrough()) {
        switch (keyCode) {
        case KeyEvent.KEYCODE_CHANNEL_UP:
        case KeyEvent.KEYCODE_DPAD_UP:
            if (event.getRepeatCount() == 0 && mChannelTuner.getBrowsableChannelCount() > 0) {
                moveToAdjacentChannel(true, false);
                mHandler.sendMessageDelayed(
                        mHandler.obtainMessage(MSG_CHANNEL_UP_PRESSED, System.currentTimeMillis()),
                        CHANNEL_CHANGE_INITIAL_DELAY_MILLIS);
                mTracker.sendChannelUp();
            }
            return true;
        case KeyEvent.KEYCODE_CHANNEL_DOWN:
        case KeyEvent.KEYCODE_DPAD_DOWN:
            if (event.getRepeatCount() == 0 && mChannelTuner.getBrowsableChannelCount() > 0) {
                moveToAdjacentChannel(false, false);
                mHandler.sendMessageDelayed(
                        mHandler.obtainMessage(MSG_CHANNEL_DOWN_PRESSED, System.currentTimeMillis()),
                        CHANNEL_CHANGE_INITIAL_DELAY_MILLIS);
                mTracker.sendChannelDown();
            }
            return true;
        }
    }
    return super.onKeyDown(keyCode, event);
}

From source file:org.distantshoresmedia.keyboard.LatinIME.java

@Override
public boolean onKeyUp(int keyCode, KeyEvent event) {
    switch (keyCode) {
    case KeyEvent.KEYCODE_DPAD_DOWN:
    case KeyEvent.KEYCODE_DPAD_UP:
    case KeyEvent.KEYCODE_DPAD_LEFT:
    case KeyEvent.KEYCODE_DPAD_RIGHT:
        // If tutorial is visible, don't allow dpad to work
        if (mTutorial != null) {
            return true;
        }//from ww w  .j  av  a  2  s.  co  m
        TKKeyboardView inputView = mKeyboardSwitcher.getInputView();
        // Enable shift key and DPAD to do selections
        if (inputView != null && inputView.isShown() && inputView.getShiftState() == Keyboard.SHIFT_ON) {
            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_VOLUME_UP:
        if (!mVolUpAction.equals("none") && isKeyboardVisible()) {
            return doSwipeAction(mVolUpAction);
        }
        break;
    case KeyEvent.KEYCODE_VOLUME_DOWN:
        if (!mVolDownAction.equals("none") && isKeyboardVisible()) {
            return doSwipeAction(mVolDownAction);
        }
        break;
    }
    return super.onKeyUp(keyCode, event);
}

From source file:com.fishstix.dosboxfree.DBGLSurfaceView.java

private boolean handleKey(int keyCode, final KeyEvent event) {
    if (mDebug)//ww  w. j a v a 2  s  .  co  m
        Log.d("DosBoxTurbo", "handleKey keyCode=" + keyCode);
    int tKeyCode = 0;

    // check for xperia play back case
    if (keyCode == KeyEvent.KEYCODE_BACK && event.isAltPressed()) {
        int backval = customMap.get(DosBoxPreferences.XPERIA_BACK_BUTTON);
        if (backval > 0) {
            // Special Sony XPeria Play case
            if (mEnableDpad) {
                // FIRE2
                if ((mInputMode == INPUT_MODE_MOUSE) || (mInputMode == INPUT_MODE_REAL_MOUSE)) {
                    DosBoxControl.nativeMouse(0, 0, 0, 0, (event.getAction() == KeyEvent.ACTION_DOWN) ? 0 : 1,
                            BTN_B);
                } else if ((mInputMode == INPUT_MODE_JOYSTICK) || (mInputMode == INPUT_MODE_REAL_JOYSTICK)) {
                    DosBoxControl.nativeJoystick(0, 0, (event.getAction() == KeyEvent.ACTION_DOWN) ? 0 : 1,
                            BTN_B);
                }
            } else {
                // sony xperia play O (circle) button
                DosBoxControl.sendNativeKey(backval, (event.getAction() == KeyEvent.ACTION_DOWN), mModifierCtrl,
                        mModifierAlt, mModifierShift);
                return true; // consume event
            }
        }
        return true; // consume event
    }

    // Handle all other keyevents
    int value = customMap.get(keyCode);

    if (value > 0) {
        // found a valid mapping
        tKeyCode = getMappedKeyCode(value, event);
        if (tKeyCode > MAP_NONE) {
            DosBoxControl.sendNativeKey(tKeyCode, (event.getAction() == KeyEvent.ACTION_DOWN), mModifierCtrl,
                    mModifierAlt, mModifierShift);
            return true; // consume KeyEvent
        } else if (tKeyCode == MAP_EVENT_CONSUMED) {
            return true;
        }
    }

    if (keyCode == KeyEvent.KEYCODE_BACK) {
        // fishstix, allow remap of Android back button
        // catch no mapping
        if (event.getAction() == KeyEvent.ACTION_UP) {
            DBMenuSystem.doConfirmQuit(mParent);
        }
        return true;
    }

    switch (keyCode) {
    case KeyEvent.KEYCODE_UNKNOWN:
        break;

    default:
        boolean down = (event.getAction() == KeyEvent.ACTION_DOWN);
        if (mDebug)
            Log.d("DosBoxTurbo", "handleKey (default) keyCode=" + keyCode + " down=" + down);

        if (!down || (event.getRepeatCount() == 0)) {
            int unicode = event.getUnicodeChar();

            // filter system generated keys, but not hardware keypresses
            if ((event.isAltPressed() || event.isShiftPressed()) && (unicode == 0)
                    && ((event.getFlags() & KeyEvent.FLAG_FROM_SYSTEM) == 0))
                break;

            //fixed alt key problem for physical keyboard with only left alt
            if ((!mUseLeftAltOn) && (keyCode == KeyEvent.KEYCODE_ALT_LEFT)) {
                break;
            }

            if ((!mUseLeftAltOn) && (keyCode == KeyEvent.KEYCODE_SHIFT_RIGHT)) {
                break;
            }

            if ((keyCode > 255) || (unicode > 255)) {
                //unknown keys
                break;
            }

            keyCode = keyCode | (unicode << 8);

            long diff = event.getEventTime() - event.getDownTime();

            if (!down && (diff < 50)) {
                //simulate as long press
                if (mDebug)
                    Log.d("DosBoxTurbo", "LongPress consumed keyCode=" + keyCode + " down=" + down);
                mKeyHandler.removeMessages(keyCode);
                mKeyHandler.sendEmptyMessageDelayed(keyCode, BUTTON_REPEAT_DELAY - diff);
            } else if (down && mKeyHandler.hasMessages(keyCode)) {
                if (mDebug)
                    Log.d("DosBoxTurbo", "KeyUp consumed keyCode=" + keyCode + " down=" + down);
                //there is an key up in queue, should be repeated event
            } else {
                boolean result = DosBoxControl.sendNativeKey(keyCode, down, mModifierCtrl, mModifierAlt,
                        mModifierShift);
                if (!down) {
                    mModifierCtrl = false;
                    mModifierAlt = false;
                    mModifierShift = false;
                }
                return result;
            }
        }
    }

    return false;
}

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();/* ww w .  j a  v a 2  s .  c  o 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 av  a 2s . c o 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;

        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:org.bangbang.support.v4.widget.HListView.java

private boolean commonKey(int keyCode, int count, KeyEvent event) {
        if (mAdapter == null) {
            return false;
        }/*from   ww w.  j  ava2  s. c o  m*/

        if (mDataChanged) {
            layoutChildren();
        }

        boolean handled = false;
        int action = event.getAction();

        if (action != KeyEvent.ACTION_UP) {
            if (mSelectedPosition < 0) {
                switch (keyCode) {
                case KeyEvent.KEYCODE_DPAD_UP:
                case KeyEvent.KEYCODE_DPAD_DOWN:
                case KeyEvent.KEYCODE_DPAD_CENTER:
                case KeyEvent.KEYCODE_ENTER:
                case KeyEvent.KEYCODE_SPACE:
                    if (resurrectSelection()) {
                        return true;
                    }
                }
            }
            switch (keyCode) {
            case KeyEvent.KEYCODE_DPAD_LEFT:
                if (!event.isAltPressed()) {
                    while (count > 0) {
                        handled = arrowScroll(FOCUS_LEFT);
                        count--;
                    }
                } else {
                    handled = fullScroll(FOCUS_LEFT);
                }
                break;

            case KeyEvent.KEYCODE_DPAD_RIGHT:
                if (!event.isAltPressed()) {
                    while (count > 0) {
                        handled = arrowScroll(FOCUS_RIGHT);
                        count--;
                    }
                } else {
                    handled = fullScroll(FOCUS_RIGHT);
                }
                break;

            case KeyEvent.KEYCODE_DPAD_UP:
                handled = handleHorizontalFocusWithinListItem(View.FOCUS_UP);
                break;
            case KeyEvent.KEYCODE_DPAD_DOWN:
                handled = handleHorizontalFocusWithinListItem(View.FOCUS_DOWN);
                break;

            case KeyEvent.KEYCODE_DPAD_CENTER:
            case KeyEvent.KEYCODE_ENTER:
                if (mItemCount > 0 && event.getRepeatCount() == 0) {
                    keyPressed();
                }
                handled = true;
                break;

            case KeyEvent.KEYCODE_SPACE:
                if (mPopup == null || !mPopup.isShowing()) {
                    if (!event.isShiftPressed()) {
                        pageScroll(FOCUS_DOWN);
                    } else {
                        pageScroll(FOCUS_UP);
                    }
                    handled = true;
                }
                break;
            }
        }

        if (!handled) {
            handled = sendToTextFilter(keyCode, count, event);
        }

        if (handled) {
            return true;
        } else {
            switch (action) {
            case KeyEvent.ACTION_DOWN:
                return super.onKeyDown(keyCode, event);

            case KeyEvent.ACTION_UP:
                return super.onKeyUp(keyCode, event);

            case KeyEvent.ACTION_MULTIPLE:
                return super.onKeyMultiple(keyCode, count, event);

            default: // shouldn't happen
                return false;
            }
        }
    }

From source file:com.cognizant.trumobi.PersonaLauncher.java

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    // PersonaLog.e(LOG_TAG, "keyCode" + keyCode);
    //System.out.println("==========OnKeyDown ===========" + keyCode);
    //System.out.println("===========KeyEvent" + event.getAction());
    boolean handled = super.onKeyDown(keyCode, event);

    if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) {
        return true;
    }/*from   w ww  . j a v  a  2s .c  om*/

    if (112 == keyCode) /* 112 represents F2 key; */
    {
        /* Invoke Application PersonaDrawer screen in case F2 is selected */
        fireHomeBinding(BIND_APPS, 0);
    } else if (!handled && acceptFilter() && keyCode != KeyEvent.KEYCODE_ENTER) {
        /*
         * 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(); }
         */

        return true;
    }

    if (keyCode == KeyEvent.KEYCODE_MENU && event.isLongPress()) {
        return true;
    }

    if (keyCode == KeyEvent.KEYCODE_BACK) {
        onBackPressed();
    }

    return handled;
}