am 47c52a87: Merge "Some accessibility events not sent from touch explorer if apps misbehave." into jb-mr1-dev

* commit '47c52a873e78d78a73abe85bb5491701a7b39feb':
  Some accessibility events not sent from touch explorer if apps misbehave.
This commit is contained in:
Svetoslav Ganov
2012-09-28 12:38:06 -07:00
committed by Android Git Automerger
5 changed files with 58 additions and 0 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 190 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 172 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 741 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 205 B

View File

@@ -102,6 +102,10 @@ class TouchExplorer implements EventStreamTransformation {
// The timeout after which we are no longer trying to detect a gesture.
private static final int EXIT_GESTURE_DETECTION_TIMEOUT = 2000;
// The timeout to send interaction end events in case we did not
// receive the expected hover exit event due to a misbehaving app.
private static final int SEND_INTERACTION_END_EVENTS_TIMEOUT = 200;
// Temporary array for storing pointer IDs.
private final int[] mTempPointerIds = new int[MAX_POINTER_COUNT];
@@ -135,6 +139,9 @@ class TouchExplorer implements EventStreamTransformation {
// Command for delayed sending of a hover exit event.
private final SendHoverDelayed mSendHoverExitDelayed;
// Command for delayed sending of interaction ending events.
private final SendInteractionEndEventsDelayed mSendInteractionEndEventsDelayed;
// Command for delayed sending of a long press.
private final PerformLongPressDelayed mPerformLongPressDelayed;
@@ -233,6 +240,7 @@ class TouchExplorer implements EventStreamTransformation {
mGestureLibrary.load();
mSendHoverEnterDelayed = new SendHoverDelayed(MotionEvent.ACTION_HOVER_ENTER, true);
mSendHoverExitDelayed = new SendHoverDelayed(MotionEvent.ACTION_HOVER_EXIT, false);
mSendInteractionEndEventsDelayed = new SendInteractionEndEventsDelayed();
mDoubleTapDetector = new DoubleTapDetector();
final float density = context.getResources().getDisplayMetrics().density;
mScaledMinPointerDistanceToUseMiddleLocation =
@@ -278,6 +286,7 @@ class TouchExplorer implements EventStreamTransformation {
mSendHoverExitDelayed.remove();
mPerformLongPressDelayed.remove();
mExitGestureDetectionModeDelayed.remove();
mSendInteractionEndEventsDelayed.remove();
// Reset the pointer trackers.
mReceivedPointerTracker.clear();
mInjectedPointerTracker.clear();
@@ -334,6 +343,7 @@ class TouchExplorer implements EventStreamTransformation {
// last hover exit event.
if (mTouchExplorationGestureEnded
&& eventType == AccessibilityEvent.TYPE_VIEW_HOVER_EXIT) {
mSendInteractionEndEventsDelayed.remove();
mTouchExplorationGestureEnded = false;
sendAccessibilityEvent(AccessibilityEvent.TYPE_TOUCH_EXPLORATION_GESTURE_END);
}
@@ -342,6 +352,7 @@ class TouchExplorer implements EventStreamTransformation {
// last hover exit and the touch exploration gesture end events.
if (mTouchInteractionEnded
&& eventType == AccessibilityEvent.TYPE_VIEW_HOVER_EXIT) {
mSendInteractionEndEventsDelayed.remove();
mTouchInteractionEnded = false;
sendAccessibilityEvent(AccessibilityEvent.TYPE_TOUCH_INTERACTION_END);
}
@@ -416,6 +427,10 @@ class TouchExplorer implements EventStreamTransformation {
mSendHoverExitDelayed.remove();
}
if (mSendInteractionEndEventsDelayed.isPending()) {
mSendInteractionEndEventsDelayed.forceSendAndRemove();
}
mPerformLongPressDelayed.remove();
// If we have the first tap schedule a long press and break
@@ -873,6 +888,9 @@ class TouchExplorer implements EventStreamTransformation {
final int pointerIdBits = event.getPointerIdBits();
mTouchExplorationGestureEnded = true;
mTouchInteractionEnded = true;
if (!mSendInteractionEndEventsDelayed.isPending()) {
mSendInteractionEndEventsDelayed.post();
}
sendMotionEvent(event, MotionEvent.ACTION_HOVER_EXIT, pointerIdBits, policyFlags);
}
}
@@ -1484,10 +1502,16 @@ class TouchExplorer implements EventStreamTransformation {
} else {
mTouchExplorationGestureEnded = true;
mTouchInteractionEnded = true;
if (!mSendInteractionEndEventsDelayed.isPending()) {
mSendInteractionEndEventsDelayed.post();
}
}
} else {
if (!mGestureStarted) {
mTouchInteractionEnded = true;
if (!mSendInteractionEndEventsDelayed.isPending()) {
mSendInteractionEndEventsDelayed.post();
}
}
}
sendMotionEvent(mPrototype, mHoverAction, mPointerIdBits, mPolicyFlags);
@@ -1495,6 +1519,40 @@ class TouchExplorer implements EventStreamTransformation {
}
}
private class SendInteractionEndEventsDelayed implements Runnable {
public void remove() {
mHandler.removeCallbacks(this);
}
public void post() {
mHandler.postDelayed(this, SEND_INTERACTION_END_EVENTS_TIMEOUT);
}
public boolean isPending() {
return mHandler.hasCallbacks(this);
}
public void forceSendAndRemove() {
if (isPending()) {
run();
remove();
}
}
@Override
public void run() {
if (mTouchExplorationGestureEnded) {
mTouchExplorationGestureEnded = false;
sendAccessibilityEvent(AccessibilityEvent.TYPE_TOUCH_EXPLORATION_GESTURE_END);
}
if (mTouchInteractionEnded) {
mTouchInteractionEnded = false;
sendAccessibilityEvent(AccessibilityEvent.TYPE_TOUCH_INTERACTION_END);
}
}
}
@Override
public String toString() {
return LOG_TAG;