Example usage for android.view KeyEvent FLAG_LONG_PRESS

List of usage examples for android.view KeyEvent FLAG_LONG_PRESS

Introduction

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

Prototype

int FLAG_LONG_PRESS

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

Click Source Link

Document

This flag is set for the first key repeat that occurs after the long press timeout.

Usage

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  va 2s .c om*/
    }

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