Merge "Do not mark mouse events as 'drag' on ACTION_DOWN" into tm-qpr-dev am: c3a4b7b7d9
Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/21733533 Change-Id: I83bcca07303fc6a504ecb23167d86ee153e7cef8 Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
@@ -193,6 +193,7 @@ public class CaptionWindowDecorViewModel implements WindowDecorViewModel {
|
|||||||
private final DragDetector mDragDetector;
|
private final DragDetector mDragDetector;
|
||||||
|
|
||||||
private int mDragPointerId = -1;
|
private int mDragPointerId = -1;
|
||||||
|
private boolean mIsDragging;
|
||||||
|
|
||||||
private CaptionTouchEventListener(
|
private CaptionTouchEventListener(
|
||||||
RunningTaskInfo taskInfo,
|
RunningTaskInfo taskInfo,
|
||||||
@@ -223,19 +224,15 @@ public class CaptionWindowDecorViewModel implements WindowDecorViewModel {
|
|||||||
if (v.getId() != R.id.caption) {
|
if (v.getId() != R.id.caption) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
mDragDetector.onMotionEvent(e);
|
if (e.getAction() == MotionEvent.ACTION_DOWN) {
|
||||||
|
final RunningTaskInfo taskInfo = mTaskOrganizer.getRunningTaskInfo(mTaskId);
|
||||||
if (e.getAction() != MotionEvent.ACTION_DOWN) {
|
if (!taskInfo.isFocused) {
|
||||||
return false;
|
final WindowContainerTransaction wct = new WindowContainerTransaction();
|
||||||
|
wct.reorder(mTaskToken, true /* onTop */);
|
||||||
|
mSyncQueue.queue(wct);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
final RunningTaskInfo taskInfo = mTaskOrganizer.getRunningTaskInfo(mTaskId);
|
return mDragDetector.onMotionEvent(e);
|
||||||
if (taskInfo.isFocused) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
final WindowContainerTransaction wct = new WindowContainerTransaction();
|
|
||||||
wct.reorder(mTaskToken, true /* onTop */);
|
|
||||||
mSyncQueue.queue(wct);
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -253,20 +250,24 @@ public class CaptionWindowDecorViewModel implements WindowDecorViewModel {
|
|||||||
mDragPointerId = e.getPointerId(0);
|
mDragPointerId = e.getPointerId(0);
|
||||||
mDragPositioningCallback.onDragPositioningStart(
|
mDragPositioningCallback.onDragPositioningStart(
|
||||||
0 /* ctrlType */, e.getRawX(0), e.getRawY(0));
|
0 /* ctrlType */, e.getRawX(0), e.getRawY(0));
|
||||||
break;
|
mIsDragging = false;
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
case MotionEvent.ACTION_MOVE: {
|
case MotionEvent.ACTION_MOVE: {
|
||||||
int dragPointerIdx = e.findPointerIndex(mDragPointerId);
|
int dragPointerIdx = e.findPointerIndex(mDragPointerId);
|
||||||
mDragPositioningCallback.onDragPositioningMove(
|
mDragPositioningCallback.onDragPositioningMove(
|
||||||
e.getRawX(dragPointerIdx), e.getRawY(dragPointerIdx));
|
e.getRawX(dragPointerIdx), e.getRawY(dragPointerIdx));
|
||||||
break;
|
mIsDragging = true;
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
case MotionEvent.ACTION_UP:
|
case MotionEvent.ACTION_UP:
|
||||||
case MotionEvent.ACTION_CANCEL: {
|
case MotionEvent.ACTION_CANCEL: {
|
||||||
int dragPointerIdx = e.findPointerIndex(mDragPointerId);
|
int dragPointerIdx = e.findPointerIndex(mDragPointerId);
|
||||||
mDragPositioningCallback.onDragPositioningEnd(
|
mDragPositioningCallback.onDragPositioningEnd(
|
||||||
e.getRawX(dragPointerIdx), e.getRawY(dragPointerIdx));
|
e.getRawX(dragPointerIdx), e.getRawY(dragPointerIdx));
|
||||||
break;
|
final boolean wasDragging = mIsDragging;
|
||||||
|
mIsDragging = false;
|
||||||
|
return wasDragging;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
@@ -223,6 +223,7 @@ public class DesktopModeWindowDecorViewModel implements WindowDecorViewModel {
|
|||||||
private final DragPositioningCallback mDragPositioningCallback;
|
private final DragPositioningCallback mDragPositioningCallback;
|
||||||
private final DragDetector mDragDetector;
|
private final DragDetector mDragDetector;
|
||||||
|
|
||||||
|
private boolean mIsDragging;
|
||||||
private int mDragPointerId = -1;
|
private int mDragPointerId = -1;
|
||||||
|
|
||||||
private DesktopModeTouchEventListener(
|
private DesktopModeTouchEventListener(
|
||||||
@@ -273,23 +274,7 @@ public class DesktopModeWindowDecorViewModel implements WindowDecorViewModel {
|
|||||||
if (id != R.id.caption_handle && id != R.id.desktop_mode_caption) {
|
if (id != R.id.caption_handle && id != R.id.desktop_mode_caption) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
switch (e.getAction()) {
|
return mDragDetector.onMotionEvent(e);
|
||||||
case MotionEvent.ACTION_DOWN:
|
|
||||||
mDragDetector.onMotionEvent(e);
|
|
||||||
final RunningTaskInfo taskInfo = mTaskOrganizer.getRunningTaskInfo(mTaskId);
|
|
||||||
if (taskInfo.isFocused) {
|
|
||||||
return mDragDetector.isDragEvent();
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
case MotionEvent.ACTION_UP:
|
|
||||||
case MotionEvent.ACTION_CANCEL:
|
|
||||||
boolean res = mDragDetector.isDragEvent();
|
|
||||||
mDragDetector.onMotionEvent(e);
|
|
||||||
return res;
|
|
||||||
default:
|
|
||||||
mDragDetector.onMotionEvent(e);
|
|
||||||
return mDragDetector.isDragEvent();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -313,13 +298,15 @@ public class DesktopModeWindowDecorViewModel implements WindowDecorViewModel {
|
|||||||
mDragPointerId = e.getPointerId(0);
|
mDragPointerId = e.getPointerId(0);
|
||||||
mDragPositioningCallback.onDragPositioningStart(
|
mDragPositioningCallback.onDragPositioningStart(
|
||||||
0 /* ctrlType */, e.getRawX(0), e.getRawY(0));
|
0 /* ctrlType */, e.getRawX(0), e.getRawY(0));
|
||||||
break;
|
mIsDragging = false;
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
case MotionEvent.ACTION_MOVE: {
|
case MotionEvent.ACTION_MOVE: {
|
||||||
final int dragPointerIdx = e.findPointerIndex(mDragPointerId);
|
final int dragPointerIdx = e.findPointerIndex(mDragPointerId);
|
||||||
mDragPositioningCallback.onDragPositioningMove(
|
mDragPositioningCallback.onDragPositioningMove(
|
||||||
e.getRawX(dragPointerIdx), e.getRawY(dragPointerIdx));
|
e.getRawX(dragPointerIdx), e.getRawY(dragPointerIdx));
|
||||||
break;
|
mIsDragging = true;
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
case MotionEvent.ACTION_UP:
|
case MotionEvent.ACTION_UP:
|
||||||
case MotionEvent.ACTION_CANCEL: {
|
case MotionEvent.ACTION_CANCEL: {
|
||||||
@@ -336,7 +323,9 @@ public class DesktopModeWindowDecorViewModel implements WindowDecorViewModel {
|
|||||||
c -> c.moveToFullscreen(taskInfo));
|
c -> c.moveToFullscreen(taskInfo));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
final boolean wasDragging = mIsDragging;
|
||||||
|
mIsDragging = false;
|
||||||
|
return wasDragging;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
@@ -56,10 +56,15 @@ class DragDetector {
|
|||||||
* {@link #mEventHandler} handles the previous down event if the event shouldn't be passed
|
* {@link #mEventHandler} handles the previous down event if the event shouldn't be passed
|
||||||
*/
|
*/
|
||||||
boolean onMotionEvent(MotionEvent ev) {
|
boolean onMotionEvent(MotionEvent ev) {
|
||||||
|
final boolean isTouchScreen =
|
||||||
|
(ev.getSource() & SOURCE_TOUCHSCREEN) == SOURCE_TOUCHSCREEN;
|
||||||
|
if (!isTouchScreen) {
|
||||||
|
// Only touches generate noisy moves, so mouse/trackpad events don't need to filtered
|
||||||
|
// to take the slop threshold into consideration.
|
||||||
|
return mEventHandler.handleMotionEvent(ev);
|
||||||
|
}
|
||||||
switch (ev.getActionMasked()) {
|
switch (ev.getActionMasked()) {
|
||||||
case ACTION_DOWN: {
|
case ACTION_DOWN: {
|
||||||
// Only touch screens generate noisy moves.
|
|
||||||
mIsDragEvent = (ev.getSource() & SOURCE_TOUCHSCREEN) != SOURCE_TOUCHSCREEN;
|
|
||||||
mDragPointerId = ev.getPointerId(0);
|
mDragPointerId = ev.getPointerId(0);
|
||||||
float rawX = ev.getRawX(0);
|
float rawX = ev.getRawX(0);
|
||||||
float rawY = ev.getRawY(0);
|
float rawY = ev.getRawY(0);
|
||||||
@@ -72,8 +77,12 @@ class DragDetector {
|
|||||||
int dragPointerIndex = ev.findPointerIndex(mDragPointerId);
|
int dragPointerIndex = ev.findPointerIndex(mDragPointerId);
|
||||||
float dx = ev.getRawX(dragPointerIndex) - mInputDownPoint.x;
|
float dx = ev.getRawX(dragPointerIndex) - mInputDownPoint.x;
|
||||||
float dy = ev.getRawY(dragPointerIndex) - mInputDownPoint.y;
|
float dy = ev.getRawY(dragPointerIndex) - mInputDownPoint.y;
|
||||||
|
// Touches generate noisy moves, so only once the move is past the touch
|
||||||
|
// slop threshold should it be considered a drag.
|
||||||
mIsDragEvent = Math.hypot(dx, dy) > mTouchSlop;
|
mIsDragEvent = Math.hypot(dx, dy) > mTouchSlop;
|
||||||
}
|
}
|
||||||
|
// The event handler should only be notified about 'move' events if a drag has been
|
||||||
|
// detected.
|
||||||
if (mIsDragEvent) {
|
if (mIsDragEvent) {
|
||||||
return mEventHandler.handleMotionEvent(ev);
|
return mEventHandler.handleMotionEvent(ev);
|
||||||
} else {
|
} else {
|
||||||
@@ -94,10 +103,6 @@ class DragDetector {
|
|||||||
mTouchSlop = touchSlop;
|
mTouchSlop = touchSlop;
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean isDragEvent() {
|
|
||||||
return mIsDragEvent;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void resetState() {
|
private void resetState() {
|
||||||
mIsDragEvent = false;
|
mIsDragEvent = false;
|
||||||
mInputDownPoint.set(0, 0);
|
mInputDownPoint.set(0, 0);
|
||||||
|
|||||||
Reference in New Issue
Block a user