Merge "Add a flag to cancelDragAndDrop to skip animation" into qt-dev

This commit is contained in:
TreeHugger Robot
2019-04-19 05:40:41 +00:00
committed by Android (Google) Code Review
6 changed files with 13 additions and 10 deletions

View File

@@ -187,8 +187,10 @@ interface IWindowSession {
/** /**
* Cancel the current drag operation. * Cancel the current drag operation.
* skipAnimation is 'true' when it should skip the drag cancel animation which brings the drag
* shadow image back to the drag start position.
*/ */
void cancelDragAndDrop(IBinder dragToken); void cancelDragAndDrop(IBinder dragToken, boolean skipAnimation);
/** /**
* Tell the OS that we've just dragged into a View that is willing to accept the drop * Tell the OS that we've just dragged into a View that is willing to accept the drop

View File

@@ -25456,7 +25456,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
} }
if (mAttachInfo.mDragToken != null) { if (mAttachInfo.mDragToken != null) {
try { try {
mAttachInfo.mSession.cancelDragAndDrop(mAttachInfo.mDragToken); mAttachInfo.mSession.cancelDragAndDrop(mAttachInfo.mDragToken, false);
} catch (Exception e) { } catch (Exception e) {
Log.e(VIEW_LOG_TAG, "Unable to cancel drag", e); Log.e(VIEW_LOG_TAG, "Unable to cancel drag", e);
} }

View File

@@ -236,7 +236,7 @@ class DragDropController {
} }
} }
void cancelDragAndDrop(IBinder dragToken) { void cancelDragAndDrop(IBinder dragToken, boolean skipAnimation) {
if (DEBUG_DRAG) { if (DEBUG_DRAG) {
Slog.d(TAG_WM, "cancelDragAndDrop"); Slog.d(TAG_WM, "cancelDragAndDrop");
} }
@@ -257,7 +257,7 @@ class DragDropController {
} }
mDragState.mDragResult = false; mDragState.mDragResult = false;
mDragState.cancelDragLocked(); mDragState.cancelDragLocked(skipAnimation);
} }
} finally { } finally {
mCallback.get().postCancelDragAndDrop(); mCallback.get().postCancelDragAndDrop();

View File

@@ -475,15 +475,16 @@ class DragState {
closeLocked(); closeLocked();
} }
void cancelDragLocked() { void cancelDragLocked(boolean skipAnimation) {
if (mAnimator != null) { if (mAnimator != null) {
return; return;
} }
if (!mDragInProgress) { if (!mDragInProgress || skipAnimation) {
// This can happen if an app invokes Session#cancelDragAndDrop before // mDragInProgress is false if an app invokes Session#cancelDragAndDrop before
// Session#performDrag. Reset the drag state without playing the cancel animation // Session#performDrag. Reset the drag state without playing the cancel animation
// because H.DRAG_START_TIMEOUT may be sent to WindowManagerService, which will cause // because H.DRAG_START_TIMEOUT may be sent to WindowManagerService, which will cause
// DragState#reset() while playing the cancel animation. // DragState#reset() while playing the cancel animation.
// skipAnimation is true when a caller requests to skip the drag cancel animation.
closeLocked(); closeLocked();
return; return;
} }

View File

@@ -283,10 +283,10 @@ class Session extends IWindowSession.Stub implements IBinder.DeathRecipient {
} }
@Override @Override
public void cancelDragAndDrop(IBinder dragToken) { public void cancelDragAndDrop(IBinder dragToken, boolean skipAnimation) {
final long ident = Binder.clearCallingIdentity(); final long ident = Binder.clearCallingIdentity();
try { try {
mDragDropController.cancelDragAndDrop(dragToken); mDragDropController.cancelDragAndDrop(dragToken, skipAnimation);
} finally { } finally {
Binder.restoreCallingIdentity(ident); Binder.restoreCallingIdentity(ident);
} }

View File

@@ -137,7 +137,7 @@ public class DragDropControllerTests extends WindowTestsBase {
return; return;
} }
if (mToken != null) { if (mToken != null) {
mTarget.cancelDragAndDrop(mToken); mTarget.cancelDragAndDrop(mToken, false);
} }
latch = new CountDownLatch(1); latch = new CountDownLatch(1);
mTarget.setOnClosedCallbackLocked(latch::countDown); mTarget.setOnClosedCallbackLocked(latch::countDown);