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

Commit 93cf731b authored by Vladislav Kaznacheev's avatar Vladislav Kaznacheev
Browse files

Implement View.cancelDrag

View.cancelDrag cancels a drag operation initiated by
View.startDrag.

It has to be called on a View in the same window (under the
same ViewRootImpl) that the view which started the drag.

Bug: 24415683
Change-Id: Iae5ff3534b6c747ae174f170fdd01ff4d3b1c312
parent a8740105
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -36238,6 +36238,7 @@ package android.view {
    method public boolean canResolveTextDirection();
    method public boolean canScrollHorizontally(int);
    method public boolean canScrollVertically(int);
    method public final void cancelDrag();
    method public void cancelLongPress();
    method public final void cancelPendingInputEvents();
    method public boolean checkInputConnectionProxy(android.view.View);
+1 −0
Original line number Diff line number Diff line
@@ -38559,6 +38559,7 @@ package android.view {
    method public boolean canResolveTextDirection();
    method public boolean canScrollHorizontally(int);
    method public boolean canScrollVertically(int);
    method public final void cancelDrag();
    method public void cancelLongPress();
    method public final void cancelPendingInputEvents();
    method public boolean checkInputConnectionProxy(android.view.View);
+5 −0
Original line number Diff line number Diff line
@@ -185,6 +185,11 @@ interface IWindowSession {
     */
	void reportDropResult(IWindow window, boolean consumed);

    /**
     * Cancel a drag operation.
     */
    void cancelDrag(IBinder dragToken);

    /**
     * Tell the OS that we've just dragged into a View that is willing to accept the drop
     */
+26 −5
Original line number Diff line number Diff line
@@ -19905,11 +19905,11 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
        }
        Surface surface = new Surface();
        try {
            IBinder token = mAttachInfo.mSession.prepareDrag(mAttachInfo.mWindow,
            mAttachInfo.mDragToken = mAttachInfo.mSession.prepareDrag(mAttachInfo.mWindow,
                    flags, shadowSize.x, shadowSize.y, surface);
            if (ViewDebug.DEBUG_DRAG) Log.d(VIEW_LOG_TAG, "prepareDrag returned token=" + token
                    + " surface=" + surface);
            if (token != null) {
            if (ViewDebug.DEBUG_DRAG) Log.d(VIEW_LOG_TAG, "prepareDrag returned token="
                    + mAttachInfo.mDragToken + " surface=" + surface);
            if (mAttachInfo.mDragToken != null) {
                Canvas canvas = surface.lockCanvas(null);
                try {
                    canvas.drawColor(0, PorterDuff.Mode.CLEAR);
@@ -19926,7 +19926,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
                // repurpose 'shadowSize' for the last touch point
                root.getLastTouchPoint(shadowSize);
                okay = mAttachInfo.mSession.performDrag(mAttachInfo.mWindow, token,
                okay = mAttachInfo.mSession.performDrag(mAttachInfo.mWindow, mAttachInfo.mDragToken,
                        shadowSize.x, shadowSize.y,
                        shadowTouchPoint.x, shadowTouchPoint.y, data);
                if (ViewDebug.DEBUG_DRAG) Log.d(VIEW_LOG_TAG, "performDrag returned " + okay);
@@ -19943,6 +19943,22 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
        return okay;
    }
    public final void cancelDrag() {
        if (ViewDebug.DEBUG_DRAG) {
            Log.d(VIEW_LOG_TAG, "cancelDrag");
        }
        if (mAttachInfo.mDragToken != null) {
            try {
                mAttachInfo.mSession.cancelDrag(mAttachInfo.mDragToken);
            } catch (Exception e) {
                Log.e(VIEW_LOG_TAG, "Unable to cancel drag", e);
            }
            mAttachInfo.mDragToken = null;
        } else {
            Log.e(VIEW_LOG_TAG, "No active drag to cancel");
        }
    }
    /**
     * Starts a move from {startX, startY}, the amount of the movement will be the offset
     * between {startX, startY} and the new cursor positon.
@@ -22220,6 +22236,11 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
         */
        View mViewRequestingLayout;
        /**
         * Used to track the identity of the current drag operation.
         */
        IBinder mDragToken;
        /**
         * Creates a new set of attachment information with the specified
         * events handler and thread.
+2 −2
Original line number Diff line number Diff line
@@ -5307,10 +5307,10 @@ public final class ViewRootImpl implements ViewParent,
                    }
                }

                // When the drag operation ends, release any local state object
                // that may have been in use
                // When the drag operation ends, reset drag-related state
                if (what == DragEvent.ACTION_DRAG_ENDED) {
                    setLocalDragState(null);
                    mAttachInfo.mDragToken = null;
                }
            }
        }
Loading