Example usage for android.view KeyEvent FLAG_CANCELED_LONG_PRESS

List of usage examples for android.view KeyEvent FLAG_CANCELED_LONG_PRESS

Introduction

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

Prototype

int FLAG_CANCELED_LONG_PRESS

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

Click Source Link

Document

Set when a key event has #FLAG_CANCELED set because a long press action was executed while it was down.

Usage

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

/**
 * Calls from {@link Activity#onKeyUp(int, KeyEvent)} to delegate
 * @param keyCode    event key code/* w ww.j ava2s .co 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;
}