Example usage for android.view KeyEvent getFlags

List of usage examples for android.view KeyEvent getFlags

Introduction

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

Prototype

public final int getFlags() 

Source Link

Document

Returns the flags for this key event.

Usage

From source file:Main.java

public static boolean isLongPress(KeyEvent event) {
    return (event.getFlags() & FLAG_LONG_PRESS) != 0;
}

From source file:io.github.hidroh.materialistic.KeyDelegate.java

/**
 * Calls from {@link Activity#onKeyUp(int, KeyEvent)} to delegate
 * @param keyCode    event key code//from w w w . j  a  v a  2s  . c  o  m
 * @param event      key event
 * @return  true if is intercepted as navigation, false otherwise
 */
public boolean onKeyUp(int keyCode, KeyEvent event) {
    if (!mEnabled) {
        return false;
    }
    boolean notLongPress = (event.getFlags() & KeyEvent.FLAG_CANCELED_LONG_PRESS) == 0;
    if (keyCode == KeyEvent.KEYCODE_VOLUME_UP && notLongPress) {
        shortPress(DIRECTION_UP);
        return true;
    } else if (keyCode == KeyEvent.KEYCODE_VOLUME_DOWN && notLongPress) {
        shortPress(DIRECTION_DOWN);
        return true;
    }
    return false;
}

From source file:android.support.v7ox.app.AppCompatDelegateImplV7.java

boolean onKeyDown(int keyCode, KeyEvent event) {
    switch (keyCode) {
    case KeyEvent.KEYCODE_MENU:
        onKeyDownPanel(Window.FEATURE_OPTIONS_PANEL, event);
        // We need to return true here and not let it bubble up to the Window.
        // For empty menus, PhoneWindow's KEYCODE_BACK handling will steals all events,
        // not allowing the Activity to call onBackPressed().
        return true;
    case KeyEvent.KEYCODE_BACK:
        // Certain devices allow opening the options menu via a long press of the back
        // button. We keep a record of whether the last event is from a long press.
        mLongPressBackDown = (event.getFlags() & KeyEvent.FLAG_LONG_PRESS) != 0;
        break;/*from w  ww  . j  a v  a  2  s  .  c  o m*/
    }

    // On API v7-10 we need to manually call onKeyShortcut() as this is not called
    // from the Activity
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
        // We do not return true here otherwise dispatchKeyEvent will not reach the Activity
        // (which results in the back button not working)
        onKeyShortcut(keyCode, event);
    }
    return false;
}

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

private boolean handleKey(int keyCode, final KeyEvent event) {
    if (mDebug)/*from ww  w .jav a  2s  .  c  om*/
        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.tct.mail.ui.AbstractActivityController.java

@Override
public final boolean onKeyDown(int keyCode, KeyEvent event) {
    //[FRETURE]-ADD-BEGIN by TSNJ.wei huang 11/24/2014 FR848855
    if (keyCode == event.KEYCODE_BACK) {
        if (mCabActionMenu != null) {
            if (mCabActionMenu.isActivated()) {
                if (mCabActionMenu.isActionModeNull()) {
                    return false;
                } else {
                    mCabActionMenu.onSetEmpty();
                }/*from  w w  w.  j ava 2s . c  o m*/
                return true;
            } else {
                return false;
            }
        }
    }
    //[FEATURE]-ADD-END by TSNJ.wei huang

    // TS: gangjin.weng 2015-4-5 EMAIL BUGFIX-968391 ADD_S
    if (keyCode == KeyEvent.KEYCODE_DEL && mCabActionMenu == null && event != null && event.getScanCode() == 0
            && event.getMetaState() == 0
            && event.getFlags() == (KeyEvent.FLAG_SOFT_KEYBOARD | KeyEvent.FLAG_KEEP_TOUCH_MODE)) {
        return true;
    }
    // TS: gangjin.weng 2015-4-5 EMAIL BUGFIX-968391 ADD_E
    return false;
}