am cac7b2b1: Merge "Update stylus button press recognition in GestureDetector to use new APIs" into mnc-dev
* commit 'cac7b2b17505dd3d84966ff15abf5e5343783dee': Update stylus button press recognition in GestureDetector to use new APIs
This commit is contained in:
@@ -34644,6 +34644,7 @@ package android.view {
|
|||||||
ctor public GestureDetector(android.content.Context, android.view.GestureDetector.OnGestureListener, android.os.Handler);
|
ctor public GestureDetector(android.content.Context, android.view.GestureDetector.OnGestureListener, android.os.Handler);
|
||||||
ctor public GestureDetector(android.content.Context, android.view.GestureDetector.OnGestureListener, android.os.Handler, boolean);
|
ctor public GestureDetector(android.content.Context, android.view.GestureDetector.OnGestureListener, android.os.Handler, boolean);
|
||||||
method public boolean isLongpressEnabled();
|
method public boolean isLongpressEnabled();
|
||||||
|
method public boolean onGenericMotionEvent(android.view.MotionEvent);
|
||||||
method public boolean onTouchEvent(android.view.MotionEvent);
|
method public boolean onTouchEvent(android.view.MotionEvent);
|
||||||
method public void setIsLongpressEnabled(boolean);
|
method public void setIsLongpressEnabled(boolean);
|
||||||
method public void setOnDoubleTapListener(android.view.GestureDetector.OnDoubleTapListener);
|
method public void setOnDoubleTapListener(android.view.GestureDetector.OnDoubleTapListener);
|
||||||
|
|||||||
@@ -36902,6 +36902,7 @@ package android.view {
|
|||||||
ctor public GestureDetector(android.content.Context, android.view.GestureDetector.OnGestureListener, android.os.Handler);
|
ctor public GestureDetector(android.content.Context, android.view.GestureDetector.OnGestureListener, android.os.Handler);
|
||||||
ctor public GestureDetector(android.content.Context, android.view.GestureDetector.OnGestureListener, android.os.Handler, boolean);
|
ctor public GestureDetector(android.content.Context, android.view.GestureDetector.OnGestureListener, android.os.Handler, boolean);
|
||||||
method public boolean isLongpressEnabled();
|
method public boolean isLongpressEnabled();
|
||||||
|
method public boolean onGenericMotionEvent(android.view.MotionEvent);
|
||||||
method public boolean onTouchEvent(android.view.MotionEvent);
|
method public boolean onTouchEvent(android.view.MotionEvent);
|
||||||
method public void setIsLongpressEnabled(boolean);
|
method public void setIsLongpressEnabled(boolean);
|
||||||
method public void setOnDoubleTapListener(android.view.GestureDetector.OnDoubleTapListener);
|
method public void setOnDoubleTapListener(android.view.GestureDetector.OnDoubleTapListener);
|
||||||
|
|||||||
@@ -32,6 +32,9 @@ import android.os.Message;
|
|||||||
* <li>In the {@link View#onTouchEvent(MotionEvent)} method ensure you call
|
* <li>In the {@link View#onTouchEvent(MotionEvent)} method ensure you call
|
||||||
* {@link #onTouchEvent(MotionEvent)}. The methods defined in your callback
|
* {@link #onTouchEvent(MotionEvent)}. The methods defined in your callback
|
||||||
* will be executed when the events occur.
|
* will be executed when the events occur.
|
||||||
|
* <li>If listening for {@link OnStylusButtonPressListener#onStylusButtonPress(MotionEvent)}
|
||||||
|
* you must call {@link #onGenericMotionEvent(MotionEvent)}
|
||||||
|
* in {@link View#onGenericMotionEvent(MotionEvent)}.
|
||||||
* </ul>
|
* </ul>
|
||||||
*/
|
*/
|
||||||
public class GestureDetector {
|
public class GestureDetector {
|
||||||
@@ -149,12 +152,14 @@ public class GestureDetector {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The listener that is used to notify when a stylus button press occurs.
|
* The listener that is used to notify when a stylus button press occurs. When listening for a
|
||||||
|
* stylus button press ensure that you call {@link #onGenericMotionEvent(MotionEvent)} in
|
||||||
|
* {@link View#onGenericMotionEvent(MotionEvent)}.
|
||||||
*/
|
*/
|
||||||
public interface OnStylusButtonPressListener {
|
public interface OnStylusButtonPressListener {
|
||||||
/**
|
/**
|
||||||
* Notified when a stylus button press occurs. This is when the stylus
|
* Notified when a stylus button press occurs. This is when the stylus
|
||||||
* is touching the screen and the {@value MotionEvent#BUTTON_SECONDARY}
|
* is touching the screen and the {@value MotionEvent#BUTTON_STYLUS_PRIMARY}
|
||||||
* is pressed.
|
* is pressed.
|
||||||
*
|
*
|
||||||
* @param e The motion event that occurred during the stylus button
|
* @param e The motion event that occurred during the stylus button
|
||||||
@@ -241,6 +246,7 @@ public class GestureDetector {
|
|||||||
private boolean mInStylusButtonPress;
|
private boolean mInStylusButtonPress;
|
||||||
private boolean mAlwaysInTapRegion;
|
private boolean mAlwaysInTapRegion;
|
||||||
private boolean mAlwaysInBiggerTapRegion;
|
private boolean mAlwaysInBiggerTapRegion;
|
||||||
|
private boolean mIgnoreNextUpEvent;
|
||||||
|
|
||||||
private MotionEvent mCurrentDownEvent;
|
private MotionEvent mCurrentDownEvent;
|
||||||
private MotionEvent mPreviousUpEvent;
|
private MotionEvent mPreviousUpEvent;
|
||||||
@@ -552,18 +558,7 @@ public class GestureDetector {
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case MotionEvent.ACTION_DOWN:
|
case MotionEvent.ACTION_DOWN:
|
||||||
if (mStylusButtonListener != null
|
if (mDoubleTapListener != null) {
|
||||||
&& ev.getToolType(0) == MotionEvent.TOOL_TYPE_STYLUS
|
|
||||||
&& (ev.getButtonState() & MotionEvent.BUTTON_SECONDARY) != 0) {
|
|
||||||
if (mStylusButtonListener.onStylusButtonPress(ev)) {
|
|
||||||
mInStylusButtonPress = true;
|
|
||||||
handled = true;
|
|
||||||
mHandler.removeMessages(LONG_PRESS);
|
|
||||||
mHandler.removeMessages(TAP);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (mDoubleTapListener != null && !mInStylusButtonPress) {
|
|
||||||
boolean hadTapMessage = mHandler.hasMessages(TAP);
|
boolean hadTapMessage = mHandler.hasMessages(TAP);
|
||||||
if (hadTapMessage) mHandler.removeMessages(TAP);
|
if (hadTapMessage) mHandler.removeMessages(TAP);
|
||||||
if ((mCurrentDownEvent != null) && (mPreviousUpEvent != null) && hadTapMessage &&
|
if ((mCurrentDownEvent != null) && (mPreviousUpEvent != null) && hadTapMessage &&
|
||||||
@@ -592,7 +587,7 @@ public class GestureDetector {
|
|||||||
mInLongPress = false;
|
mInLongPress = false;
|
||||||
mDeferConfirmSingleTap = false;
|
mDeferConfirmSingleTap = false;
|
||||||
|
|
||||||
if (mIsLongpressEnabled && !mInStylusButtonPress) {
|
if (mIsLongpressEnabled) {
|
||||||
mHandler.removeMessages(LONG_PRESS);
|
mHandler.removeMessages(LONG_PRESS);
|
||||||
mHandler.sendEmptyMessageAtTime(LONG_PRESS, mCurrentDownEvent.getDownTime()
|
mHandler.sendEmptyMessageAtTime(LONG_PRESS, mCurrentDownEvent.getDownTime()
|
||||||
+ TAP_TIMEOUT + LONGPRESS_TIMEOUT);
|
+ TAP_TIMEOUT + LONGPRESS_TIMEOUT);
|
||||||
@@ -602,16 +597,6 @@ public class GestureDetector {
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case MotionEvent.ACTION_MOVE:
|
case MotionEvent.ACTION_MOVE:
|
||||||
if (mStylusButtonListener != null && !mInStylusButtonPress && !mInLongPress
|
|
||||||
&& ev.getToolType(0) == MotionEvent.TOOL_TYPE_STYLUS
|
|
||||||
&& (ev.getButtonState() & MotionEvent.BUTTON_SECONDARY) != 0) {
|
|
||||||
if (mStylusButtonListener.onStylusButtonPress(ev)) {
|
|
||||||
mInStylusButtonPress = true;
|
|
||||||
handled = true;
|
|
||||||
mHandler.removeMessages(LONG_PRESS);
|
|
||||||
mHandler.removeMessages(TAP);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (mInLongPress || mInStylusButtonPress) {
|
if (mInLongPress || mInStylusButtonPress) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -652,15 +637,12 @@ public class GestureDetector {
|
|||||||
} else if (mInLongPress) {
|
} else if (mInLongPress) {
|
||||||
mHandler.removeMessages(TAP);
|
mHandler.removeMessages(TAP);
|
||||||
mInLongPress = false;
|
mInLongPress = false;
|
||||||
} else if (mInStylusButtonPress) {
|
} else if (mAlwaysInTapRegion && !mIgnoreNextUpEvent) {
|
||||||
mHandler.removeMessages(TAP);
|
|
||||||
mInStylusButtonPress = false;
|
|
||||||
} else if (mAlwaysInTapRegion) {
|
|
||||||
handled = mListener.onSingleTapUp(ev);
|
handled = mListener.onSingleTapUp(ev);
|
||||||
if (mDeferConfirmSingleTap && mDoubleTapListener != null) {
|
if (mDeferConfirmSingleTap && mDoubleTapListener != null) {
|
||||||
mDoubleTapListener.onSingleTapConfirmed(ev);
|
mDoubleTapListener.onSingleTapConfirmed(ev);
|
||||||
}
|
}
|
||||||
} else {
|
} else if (!mIgnoreNextUpEvent) {
|
||||||
|
|
||||||
// A fling must travel the minimum tap distance
|
// A fling must travel the minimum tap distance
|
||||||
final VelocityTracker velocityTracker = mVelocityTracker;
|
final VelocityTracker velocityTracker = mVelocityTracker;
|
||||||
@@ -687,6 +669,7 @@ public class GestureDetector {
|
|||||||
}
|
}
|
||||||
mIsDoubleTapping = false;
|
mIsDoubleTapping = false;
|
||||||
mDeferConfirmSingleTap = false;
|
mDeferConfirmSingleTap = false;
|
||||||
|
mIgnoreNextUpEvent = false;
|
||||||
mHandler.removeMessages(SHOW_PRESS);
|
mHandler.removeMessages(SHOW_PRESS);
|
||||||
mHandler.removeMessages(LONG_PRESS);
|
mHandler.removeMessages(LONG_PRESS);
|
||||||
break;
|
break;
|
||||||
@@ -702,6 +685,43 @@ public class GestureDetector {
|
|||||||
return handled;
|
return handled;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Analyzes the given generic motion event and if applicable triggers the
|
||||||
|
* appropriate callbacks on the {@link OnGestureListener} supplied.
|
||||||
|
*
|
||||||
|
* @param ev The current motion event.
|
||||||
|
* @return true if the {@link OnGestureListener} consumed the event,
|
||||||
|
* else false.
|
||||||
|
*/
|
||||||
|
public boolean onGenericMotionEvent(MotionEvent ev) {
|
||||||
|
if (mInputEventConsistencyVerifier != null) {
|
||||||
|
mInputEventConsistencyVerifier.onGenericMotionEvent(ev, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (ev.getActionMasked()) {
|
||||||
|
case MotionEvent.ACTION_BUTTON_PRESS:
|
||||||
|
if (mStylusButtonListener != null && !mInStylusButtonPress && !mInLongPress
|
||||||
|
&& ev.getActionButton() == MotionEvent.BUTTON_STYLUS_PRIMARY) {
|
||||||
|
if (mStylusButtonListener.onStylusButtonPress(ev)) {
|
||||||
|
mInStylusButtonPress = true;
|
||||||
|
mHandler.removeMessages(LONG_PRESS);
|
||||||
|
mHandler.removeMessages(TAP);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case MotionEvent.ACTION_BUTTON_RELEASE:
|
||||||
|
if (mInStylusButtonPress
|
||||||
|
&& ev.getActionButton() == MotionEvent.BUTTON_STYLUS_PRIMARY) {
|
||||||
|
mInStylusButtonPress = false;
|
||||||
|
mIgnoreNextUpEvent = true;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
private void cancel() {
|
private void cancel() {
|
||||||
mHandler.removeMessages(SHOW_PRESS);
|
mHandler.removeMessages(SHOW_PRESS);
|
||||||
mHandler.removeMessages(LONG_PRESS);
|
mHandler.removeMessages(LONG_PRESS);
|
||||||
@@ -715,6 +735,7 @@ public class GestureDetector {
|
|||||||
mDeferConfirmSingleTap = false;
|
mDeferConfirmSingleTap = false;
|
||||||
mInLongPress = false;
|
mInLongPress = false;
|
||||||
mInStylusButtonPress = false;
|
mInStylusButtonPress = false;
|
||||||
|
mIgnoreNextUpEvent = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void cancelTaps() {
|
private void cancelTaps() {
|
||||||
@@ -727,6 +748,7 @@ public class GestureDetector {
|
|||||||
mDeferConfirmSingleTap = false;
|
mDeferConfirmSingleTap = false;
|
||||||
mInLongPress = false;
|
mInLongPress = false;
|
||||||
mInStylusButtonPress = false;
|
mInStylusButtonPress = false;
|
||||||
|
mIgnoreNextUpEvent = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isConsideredDoubleTap(MotionEvent firstDown, MotionEvent firstUp,
|
private boolean isConsideredDoubleTap(MotionEvent firstDown, MotionEvent firstUp,
|
||||||
|
|||||||
Reference in New Issue
Block a user