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

Commit e40d785b authored by Mady Mellor's avatar Mady Mellor
Browse files

Drag n drop for stylus

This assumes the gesture used to initiate the drag and drop would be a
stylus touch + button press. This enables stylus users to drop an item
by releasing the button, if it was pressed at the beginning of the drag n
drop. Users could still lift the stylus from the screen to end the drop.

Bug: 19621008
Change-Id: I01051f541bedf006480d46e728498a20f153b322
parent 49cb2775
Loading
Loading
Loading
Loading
+30 −3
Original line number Diff line number Diff line
@@ -709,6 +709,11 @@ public class WindowManagerService extends IWindowManager.Stub
    private WindowContentFrameStats mTempWindowRenderStats;

    final class DragInputEventReceiver extends InputEventReceiver {
        // Set, if stylus button was down at the start of the drag.
        private boolean mStylusButtonDownAtStart;
        // Indicates the first event to check for button state.
        private boolean mIsStartEvent = true;

        public DragInputEventReceiver(InputChannel inputChannel, Looper looper) {
            super(inputChannel, looper);
        }
@@ -724,6 +729,18 @@ public class WindowManagerService extends IWindowManager.Stub
                    boolean endDrag = false;
                    final float newX = motionEvent.getRawX();
                    final float newY = motionEvent.getRawY();
                    final boolean isStylusButtonDown =
                            (motionEvent.getToolType(0) == MotionEvent.TOOL_TYPE_STYLUS)
                            && (motionEvent.getButtonState() & MotionEvent.BUTTON_SECONDARY) != 0;

                    if (mIsStartEvent) {
                        if (isStylusButtonDown) {
                            // First event and the button was down, check for the button being
                            // lifted in the future, if that happens we'll drop the item.
                            mStylusButtonDownAtStart = true;
                        }
                        mIsStartEvent = false;
                    }

                    switch (motionEvent.getAction()) {
                    case MotionEvent.ACTION_DOWN: {
@@ -733,10 +750,18 @@ public class WindowManagerService extends IWindowManager.Stub
                    } break;

                    case MotionEvent.ACTION_MOVE: {
                        if (mStylusButtonDownAtStart && !isStylusButtonDown) {
                            if (DEBUG_DRAG) Slog.d(TAG, "Button no longer pressed; dropping at "
                                    + newX + "," + newY);
                            synchronized (mWindowMap) {
                                endDrag = mDragState.notifyDropLw(newX, newY);
                            }
                        } else {
                            synchronized (mWindowMap) {
                                // move the surface and tell the involved window(s) where we are
                                mDragState.notifyMoveLw(newX, newY);
                            }
                        }
                    } break;

                    case MotionEvent.ACTION_UP: {
@@ -759,6 +784,8 @@ public class WindowManagerService extends IWindowManager.Stub
                        synchronized (mWindowMap) {
                            mDragState.endDragLw();
                        }
                        mStylusButtonDownAtStart = false;
                        mIsStartEvent = true;
                    }

                    handled = true;