Example usage for android.view MotionEvent isButtonPressed

List of usage examples for android.view MotionEvent isButtonPressed

Introduction

In this page you can find the example usage for android.view MotionEvent isButtonPressed.

Prototype

public final boolean isButtonPressed(int button) 

Source Link

Document

Checks if a mouse or stylus button (or combination of buttons) is pressed.

Usage

From source file:Main.java

/**
 * Identifies if the provided {@link MotionEvent} is a stylus with the primary stylus button
 * pressed./* w ww . j a v a2 s.c  o  m*/
 *
 * @param event The event to check.
 * @return Whether a stylus button press occurred.
 */
public static boolean isStylusButtonPressed(MotionEvent event) {
    return event.getToolType(0) == MotionEvent.TOOL_TYPE_STYLUS
            && event.isButtonPressed(MotionEvent.BUTTON_SECONDARY);
}

From source file:com.android.systemui.statusbar.phone.NotificationPanelView.java

private boolean isOpenQsEvent(MotionEvent event) {
    final int pointerCount = event.getPointerCount();
    final int action = event.getActionMasked();

    final boolean twoFingerDrag = action == MotionEvent.ACTION_POINTER_DOWN && pointerCount == 2;

    final boolean stylusButtonClickDrag = action == MotionEvent.ACTION_DOWN
            && (event.isButtonPressed(MotionEvent.BUTTON_STYLUS_PRIMARY)
                    || event.isButtonPressed(MotionEvent.BUTTON_STYLUS_SECONDARY));

    final boolean mouseButtonClickDrag = action == MotionEvent.ACTION_DOWN
            && (event.isButtonPressed(MotionEvent.BUTTON_SECONDARY)
                    || event.isButtonPressed(MotionEvent.BUTTON_TERTIARY));
    boolean isOverride = true;

    return twoFingerDrag || isOverride || stylusButtonClickDrag || mouseButtonClickDrag;
}