From e82067b57595a2bce656e5ba3a9bcf19048f2f25 Mon Sep 17 00:00:00 2001 From: Mady Mellor Date: Thu, 30 Apr 2015 09:58:35 -0700 Subject: Add onStylusButtonPress listener to View The gesture is: stylus touching screen + button pressed, the event is recognized when the button is pressed, not when it's released. It can be pressed during DOWN or MOVE. If the stylus touch + press button is occurring longpress cannot occur and vice versa. Also adds the haptic feedback and accessibility bits specific to the new gesture. Bug: 19620479 Change-Id: Ibc4654978ef39e7b4251d17636453d90f3bf622d --- core/java/android/view/MotionEvent.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'core/java/android/view/MotionEvent.java') diff --git a/core/java/android/view/MotionEvent.java b/core/java/android/view/MotionEvent.java index 5e45c8fe10dd..5df596a1fce0 100644 --- a/core/java/android/view/MotionEvent.java +++ b/core/java/android/view/MotionEvent.java @@ -3180,6 +3180,18 @@ public final class MotionEvent extends InputEvent implements Parcelable { return (getButtonState() & button) == button; } + /** + * Checks if a stylus is being used and if the first stylus button is + * pressed. + * + * @return True if the tool is a stylus and if the first stylus button is + * pressed. + * @see #BUTTON_SECONDARY + */ + public final boolean isStylusButtonPressed() { + return (isButtonPressed(BUTTON_SECONDARY) && getToolType(0) == TOOL_TYPE_STYLUS); + } + public static final Parcelable.Creator CREATOR = new Parcelable.Creator() { public MotionEvent createFromParcel(Parcel in) { -- cgit v1.2.3