From e40d785b7ab7aba533862181abcd95e06de13eb9 Mon Sep 17 00:00:00 2001 From: Mady Mellor Date: Thu, 16 Apr 2015 12:47:42 -0700 Subject: 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 --- .../android/server/wm/WindowManagerService.java | 33 ++++++++++++++++++++-- 1 file changed, 30 insertions(+), 3 deletions(-) (limited to 'services') diff --git a/services/core/java/com/android/server/wm/WindowManagerService.java b/services/core/java/com/android/server/wm/WindowManagerService.java index e790fb0..52de41c 100644 --- a/services/core/java/com/android/server/wm/WindowManagerService.java +++ b/services/core/java/com/android/server/wm/WindowManagerService.java @@ -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,9 +750,17 @@ public class WindowManagerService extends IWindowManager.Stub } break; case MotionEvent.ACTION_MOVE: { - synchronized (mWindowMap) { - // move the surface and tell the involved window(s) where we are - mDragState.notifyMoveLw(newX, newY); + 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; @@ -759,6 +784,8 @@ public class WindowManagerService extends IWindowManager.Stub synchronized (mWindowMap) { mDragState.endDragLw(); } + mStylusButtonDownAtStart = false; + mIsStartEvent = true; } handled = true; -- cgit v1.1