Fix drag-to-open forwarding behavior
BUG: 13695088 Change-Id: I4c6e824267b145e6dcedb1aa46c8378fd5b6ff83
This commit is contained in:
@@ -9016,10 +9016,13 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
|
||||
* @return True if the event was handled, false otherwise.
|
||||
*/
|
||||
public boolean onTouchEvent(MotionEvent event) {
|
||||
final float x = event.getX();
|
||||
final float y = event.getY();
|
||||
final int viewFlags = mViewFlags;
|
||||
|
||||
if ((viewFlags & ENABLED_MASK) == DISABLED) {
|
||||
if (event.getAction() == MotionEvent.ACTION_UP && (mPrivateFlags & PFLAG_PRESSED) != 0) {
|
||||
clearHotspot(R.attr.state_pressed);
|
||||
setPressed(false);
|
||||
}
|
||||
// A disabled view that is clickable still consumes the touch
|
||||
@@ -9052,6 +9055,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
|
||||
// showed it as pressed. Make it show the pressed
|
||||
// state now (before scheduling the click) to ensure
|
||||
// the user sees it.
|
||||
setHotspot(R.attr.state_pressed, x, y);
|
||||
setPressed(true);
|
||||
}
|
||||
|
||||
@@ -9084,6 +9088,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
|
||||
// If the post failed, unpress right now
|
||||
mUnsetPressedState.run();
|
||||
}
|
||||
|
||||
removeTapCallback();
|
||||
}
|
||||
break;
|
||||
@@ -9105,23 +9110,26 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
|
||||
if (mPendingCheckForTap == null) {
|
||||
mPendingCheckForTap = new CheckForTap();
|
||||
}
|
||||
mPendingCheckForTap.x = event.getX();
|
||||
mPendingCheckForTap.y = event.getY();
|
||||
postDelayed(mPendingCheckForTap, ViewConfiguration.getTapTimeout());
|
||||
} else {
|
||||
// Not inside a scrolling container, so show the feedback right away
|
||||
setHotspot(R.attr.state_pressed, x, y);
|
||||
setPressed(true);
|
||||
checkForLongClick(0);
|
||||
}
|
||||
break;
|
||||
|
||||
case MotionEvent.ACTION_CANCEL:
|
||||
clearHotspot(R.attr.state_pressed);
|
||||
setPressed(false);
|
||||
removeTapCallback();
|
||||
removeLongPressCallback();
|
||||
break;
|
||||
|
||||
case MotionEvent.ACTION_MOVE:
|
||||
final int x = (int) event.getX();
|
||||
final int y = (int) event.getY();
|
||||
setHotspot(R.attr.state_pressed, x, y);
|
||||
|
||||
// Be lenient about moving outside of buttons
|
||||
if (!pointInView(x, y, mTouchSlop)) {
|
||||
@@ -9137,46 +9145,24 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
|
||||
break;
|
||||
}
|
||||
|
||||
if (mBackground != null && mBackground.supportsHotspots()) {
|
||||
manageTouchHotspot(event);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private void manageTouchHotspot(MotionEvent event) {
|
||||
switch (event.getAction()) {
|
||||
case MotionEvent.ACTION_DOWN:
|
||||
case MotionEvent.ACTION_POINTER_DOWN: {
|
||||
final int index = event.getActionIndex();
|
||||
setPointerHotspot(event, index);
|
||||
} break;
|
||||
case MotionEvent.ACTION_MOVE: {
|
||||
final int count = event.getPointerCount();
|
||||
for (int index = 0; index < count; index++) {
|
||||
setPointerHotspot(event, index);
|
||||
}
|
||||
} break;
|
||||
case MotionEvent.ACTION_POINTER_UP: {
|
||||
final int actionIndex = event.getActionIndex();
|
||||
final int pointerId = event.getPointerId(actionIndex);
|
||||
mBackground.removeHotspot(pointerId);
|
||||
} break;
|
||||
case MotionEvent.ACTION_UP:
|
||||
case MotionEvent.ACTION_CANCEL:
|
||||
mBackground.clearHotspots();
|
||||
break;
|
||||
private void setHotspot(int id, float x, float y) {
|
||||
final Drawable bg = mBackground;
|
||||
if (bg != null && bg.supportsHotspots()) {
|
||||
bg.setHotspot(id, x, y);
|
||||
}
|
||||
}
|
||||
|
||||
private void setPointerHotspot(MotionEvent event, int index) {
|
||||
final int id = event.getPointerId(index);
|
||||
final float x = event.getX(index);
|
||||
final float y = event.getY(index);
|
||||
mBackground.setHotspot(id, x, y);
|
||||
private void clearHotspot(int id) {
|
||||
final Drawable bg = mBackground;
|
||||
if (bg != null && bg.supportsHotspots()) {
|
||||
bg.removeHotspot(id);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -19093,10 +19079,10 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
|
||||
}
|
||||
}
|
||||
|
||||
class CheckForLongPress implements Runnable {
|
||||
|
||||
private final class CheckForLongPress implements Runnable {
|
||||
private int mOriginalWindowAttachCount;
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
if (isPressed() && (mParent != null)
|
||||
&& mOriginalWindowAttachCount == mWindowAttachCount) {
|
||||
@@ -19112,14 +19098,20 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
|
||||
}
|
||||
|
||||
private final class CheckForTap implements Runnable {
|
||||
public float x;
|
||||
public float y;
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
mPrivateFlags &= ~PFLAG_PREPRESSED;
|
||||
setHotspot(R.attr.state_pressed, x, y);
|
||||
setPressed(true);
|
||||
checkForLongClick(ViewConfiguration.getTapTimeout());
|
||||
}
|
||||
}
|
||||
|
||||
private final class PerformClick implements Runnable {
|
||||
@Override
|
||||
public void run() {
|
||||
performClick();
|
||||
}
|
||||
@@ -19398,7 +19390,9 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
|
||||
}
|
||||
|
||||
private final class UnsetPressedState implements Runnable {
|
||||
@Override
|
||||
public void run() {
|
||||
clearHotspot(R.attr.state_pressed);
|
||||
setPressed(false);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,6 +24,7 @@ import android.database.DataSetObserver;
|
||||
import android.graphics.Rect;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.Handler;
|
||||
import android.os.SystemClock;
|
||||
import android.text.TextUtils;
|
||||
import android.util.AttributeSet;
|
||||
import android.util.IntProperty;
|
||||
@@ -1225,6 +1226,15 @@ public class ListPopupWindow {
|
||||
forwarding = onTouchForwarded(event) || !onForwardingStopped();
|
||||
} else {
|
||||
forwarding = onTouchObserved(event) && onForwardingStarted();
|
||||
|
||||
if (forwarding) {
|
||||
// Make sure we cancel any ongoing source event stream.
|
||||
final long now = SystemClock.uptimeMillis();
|
||||
final MotionEvent e = MotionEvent.obtain(now, now, MotionEvent.ACTION_CANCEL,
|
||||
0.0f, 0.0f, 0);
|
||||
mSrc.onTouchEvent(e);
|
||||
e.recycle();
|
||||
}
|
||||
}
|
||||
|
||||
mForwarding = forwarding;
|
||||
|
||||
Reference in New Issue
Block a user