Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 7ef6889f authored by Jorge Gil's avatar Jorge Gil Committed by Automerger Merge Worker
Browse files

Merge "Do not mark mouse events as 'drag' on ACTION_DOWN" into tm-qpr-dev am:...

Merge "Do not mark mouse events as 'drag' on ACTION_DOWN" into tm-qpr-dev am: c3a4b7b7 am: 5e65583d am: 317d7df2

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/21733533



Change-Id: I58f79841a691050178bf45042ef574d4a138ec12
Signed-off-by: default avatarAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
parents 5f9baf62 317d7df2
Loading
Loading
Loading
Loading
+16 −15
Original line number Diff line number Diff line
@@ -193,6 +193,7 @@ public class CaptionWindowDecorViewModel implements WindowDecorViewModel {
        private final DragDetector mDragDetector;

        private int mDragPointerId = -1;
        private boolean mIsDragging;

        private CaptionTouchEventListener(
                RunningTaskInfo taskInfo,
@@ -223,19 +224,15 @@ public class CaptionWindowDecorViewModel implements WindowDecorViewModel {
            if (v.getId() != R.id.caption) {
                return false;
            }
            mDragDetector.onMotionEvent(e);

            if (e.getAction() != MotionEvent.ACTION_DOWN) {
                return false;
            }
            if (e.getAction() == MotionEvent.ACTION_DOWN) {
                final RunningTaskInfo taskInfo = mTaskOrganizer.getRunningTaskInfo(mTaskId);
            if (taskInfo.isFocused) {
                return false;
            }
                if (!taskInfo.isFocused) {
                    final WindowContainerTransaction wct = new WindowContainerTransaction();
                    wct.reorder(mTaskToken, true /* onTop */);
                    mSyncQueue.queue(wct);
            return true;
                }
            }
            return mDragDetector.onMotionEvent(e);
        }

        /**
@@ -253,20 +250,24 @@ public class CaptionWindowDecorViewModel implements WindowDecorViewModel {
                    mDragPointerId = e.getPointerId(0);
                    mDragPositioningCallback.onDragPositioningStart(
                            0 /* ctrlType */, e.getRawX(0), e.getRawY(0));
                    break;
                    mIsDragging = false;
                    return false;
                }
                case MotionEvent.ACTION_MOVE: {
                    int dragPointerIdx = e.findPointerIndex(mDragPointerId);
                    mDragPositioningCallback.onDragPositioningMove(
                            e.getRawX(dragPointerIdx), e.getRawY(dragPointerIdx));
                    break;
                    mIsDragging = true;
                    return true;
                }
                case MotionEvent.ACTION_UP:
                case MotionEvent.ACTION_CANCEL: {
                    int dragPointerIdx = e.findPointerIndex(mDragPointerId);
                    mDragPositioningCallback.onDragPositioningEnd(
                            e.getRawX(dragPointerIdx), e.getRawY(dragPointerIdx));
                    break;
                    final boolean wasDragging = mIsDragging;
                    mIsDragging = false;
                    return wasDragging;
                }
            }
            return true;
+9 −20
Original line number Diff line number Diff line
@@ -223,6 +223,7 @@ public class DesktopModeWindowDecorViewModel implements WindowDecorViewModel {
        private final DragPositioningCallback mDragPositioningCallback;
        private final DragDetector mDragDetector;

        private boolean mIsDragging;
        private int mDragPointerId = -1;

        private DesktopModeTouchEventListener(
@@ -273,23 +274,7 @@ public class DesktopModeWindowDecorViewModel implements WindowDecorViewModel {
            if (id != R.id.caption_handle && id != R.id.desktop_mode_caption) {
                return false;
            }
            switch (e.getAction()) {
                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();
            }
            return mDragDetector.onMotionEvent(e);
        }

        /**
@@ -313,13 +298,15 @@ public class DesktopModeWindowDecorViewModel implements WindowDecorViewModel {
                    mDragPointerId = e.getPointerId(0);
                    mDragPositioningCallback.onDragPositioningStart(
                            0 /* ctrlType */, e.getRawX(0), e.getRawY(0));
                    break;
                    mIsDragging = false;
                    return false;
                }
                case MotionEvent.ACTION_MOVE: {
                    final int dragPointerIdx = e.findPointerIndex(mDragPointerId);
                    mDragPositioningCallback.onDragPositioningMove(
                            e.getRawX(dragPointerIdx), e.getRawY(dragPointerIdx));
                    break;
                    mIsDragging = true;
                    return true;
                }
                case MotionEvent.ACTION_UP:
                case MotionEvent.ACTION_CANCEL: {
@@ -336,7 +323,9 @@ public class DesktopModeWindowDecorViewModel implements WindowDecorViewModel {
                                    c -> c.moveToFullscreen(taskInfo));
                        }
                    }
                    break;
                    final boolean wasDragging = mIsDragging;
                    mIsDragging = false;
                    return wasDragging;
                }
            }
            return true;
+11 −6
Original line number Diff line number Diff line
@@ -56,10 +56,15 @@ class DragDetector {
     * {@link #mEventHandler} handles the previous down event if the event shouldn't be passed
    */
    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()) {
            case ACTION_DOWN: {
                // Only touch screens generate noisy moves.
                mIsDragEvent = (ev.getSource() & SOURCE_TOUCHSCREEN) != SOURCE_TOUCHSCREEN;
                mDragPointerId = ev.getPointerId(0);
                float rawX = ev.getRawX(0);
                float rawY = ev.getRawY(0);
@@ -72,8 +77,12 @@ class DragDetector {
                    int dragPointerIndex = ev.findPointerIndex(mDragPointerId);
                    float dx = ev.getRawX(dragPointerIndex) - mInputDownPoint.x;
                    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;
                }
                // The event handler should only be notified about 'move' events if a drag has been
                // detected.
                if (mIsDragEvent) {
                    return mEventHandler.handleMotionEvent(ev);
                } else {
@@ -94,10 +103,6 @@ class DragDetector {
        mTouchSlop = touchSlop;
    }

    boolean isDragEvent() {
        return mIsDragEvent;
    }

    private void resetState() {
        mIsDragEvent = false;
        mInputDownPoint.set(0, 0);