@@ -98,6 +98,9 @@ public class TouchExplorer {
9898 // the two dragging pointers as opposed to use the location of the primary one.
9999 private static final int MIN_POINTER_DISTANCE_TO_USE_MIDDLE_LOCATION_DIP = 200 ;
100100
101+ // The timeout after which we are no longer trying to detect a gesture.
102+ private static final int EXIT_GESTURE_DETECTION_TIMEOUT = 2000 ;
103+
101104 // Temporary array for storing pointer IDs.
102105 private final int [] mTempPointerIds = new int [MAX_POINTER_COUNT ];
103106
@@ -138,6 +141,9 @@ public class TouchExplorer {
138141 // Command for delayed sending of a long press.
139142 private final PerformLongPressDelayed mPerformLongPressDelayed ;
140143
144+ // Command for exiting gesture detection mode after a timeout.
145+ private final ExitGestureDetectionModeDelayed mExitGestureDetectionModeDelayed ;
146+
141147 // Helper to detect and react to double tap in touch explore mode.
142148 private final DoubleTapDetector mDoubleTapDetector ;
143149
@@ -212,6 +218,7 @@ public TouchExplorer(InputFilter inputFilter, Context context,
212218 mDoubleTapSlop = ViewConfiguration .get (context ).getScaledDoubleTapSlop ();
213219 mHandler = new Handler (context .getMainLooper ());
214220 mPerformLongPressDelayed = new PerformLongPressDelayed ();
221+ mExitGestureDetectionModeDelayed = new ExitGestureDetectionModeDelayed ();
215222 mGestureLibrary = GestureLibraries .fromRawResource (context , R .raw .accessibility_gestures );
216223 mGestureLibrary .setOrientationStyle (4 );
217224 mGestureLibrary .load ();
@@ -257,6 +264,7 @@ public void clear(MotionEvent event, int policyFlags) {
257264 mSendHoverEnterDelayed .remove ();
258265 mSendHoverExitDelayed .remove ();
259266 mPerformLongPressDelayed .remove ();
267+ mExitGestureDetectionModeDelayed .remove ();
260268 // Reset the pointer trackers.
261269 mReceivedPointerTracker .clear ();
262270 mInjectedPointerTracker .clear ();
@@ -420,6 +428,7 @@ private void handleMotionEventStateTouchExploring(MotionEvent event, int policyF
420428 mSendHoverEnterDelayed .remove ();
421429 mSendHoverExitDelayed .remove ();
422430 mPerformLongPressDelayed .remove ();
431+ mExitGestureDetectionModeDelayed .post ();
423432 } else {
424433 // We have just decided that the user is touch,
425434 // exploring so start sending events.
@@ -727,6 +736,7 @@ private void handleMotionEventGestureDetecting(MotionEvent event, int policyFlag
727736 }
728737
729738 mStrokeBuffer .clear ();
739+ mExitGestureDetectionModeDelayed .remove ();
730740 mCurrentState = STATE_TOUCH_EXPLORING ;
731741 } break ;
732742 case MotionEvent .ACTION_CANCEL : {
@@ -1262,6 +1272,25 @@ private int getNotInjectedActivePointerCount(ReceivedPointerTracker receivedTrac
12621272 return Integer .bitCount (pointerState );
12631273 }
12641274
1275+ /**
1276+ * Class for delayed exiting from gesture detecting mode.
1277+ */
1278+ private final class ExitGestureDetectionModeDelayed implements Runnable {
1279+
1280+ public void post () {
1281+ mHandler .postDelayed (this , EXIT_GESTURE_DETECTION_TIMEOUT );
1282+ }
1283+
1284+ public void remove () {
1285+ mHandler .removeCallbacks (this );
1286+ }
1287+
1288+ @ Override
1289+ public void run () {
1290+ clear ();
1291+ }
1292+ }
1293+
12651294 /**
12661295 * Class for delayed sending of long press.
12671296 */
0 commit comments