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

Commit 4f639749 authored by Vladislav Kaznacheev's avatar Vladislav Kaznacheev
Browse files

Implement View.updateDragShadow

The new method allows changing the drag shadow image
while the drag is in process.

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

Bug: 25520420
Change-Id: I57e752626a4a6a86d42c597c09dbd7ec77f42f30
parent 4657518d
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -36773,6 +36773,7 @@ package android.view {
    method public void stopNestedScroll();
    method public void unscheduleDrawable(android.graphics.drawable.Drawable, java.lang.Runnable);
    method public void unscheduleDrawable(android.graphics.drawable.Drawable);
    method public final void updateDragShadow(android.view.View.DragShadowBuilder);
    method protected boolean verifyDrawable(android.graphics.drawable.Drawable);
    method public boolean willNotCacheDrawing();
    method public boolean willNotDraw();
+1 −0
Original line number Diff line number Diff line
@@ -39096,6 +39096,7 @@ package android.view {
    method public void stopNestedScroll();
    method public void unscheduleDrawable(android.graphics.drawable.Drawable, java.lang.Runnable);
    method public void unscheduleDrawable(android.graphics.drawable.Drawable);
    method public final void updateDragShadow(android.view.View.DragShadowBuilder);
    method protected boolean verifyDrawable(android.graphics.drawable.Drawable);
    method public boolean willNotCacheDrawing();
    method public boolean willNotDraw();
+36 −10
Original line number Diff line number Diff line
@@ -19978,19 +19978,22 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
            Log.d(VIEW_LOG_TAG, "drag shadow: width=" + shadowSize.x + " height=" + shadowSize.y
                    + " shadowX=" + shadowTouchPoint.x + " shadowY=" + shadowTouchPoint.y);
        }
        Surface surface = new Surface();
        if (mAttachInfo.mDragSurface != null) {
            mAttachInfo.mDragSurface.release();
        }
        mAttachInfo.mDragSurface = new Surface();
        try {
            mAttachInfo.mDragToken = mAttachInfo.mSession.prepareDrag(mAttachInfo.mWindow,
                    flags, shadowSize.x, shadowSize.y, surface);
                    flags, shadowSize.x, shadowSize.y, mAttachInfo.mDragSurface);
            if (ViewDebug.DEBUG_DRAG) Log.d(VIEW_LOG_TAG, "prepareDrag returned token="
                    + mAttachInfo.mDragToken + " surface=" + surface);
                    + mAttachInfo.mDragToken + " surface=" + mAttachInfo.mDragSurface);
            if (mAttachInfo.mDragToken != null) {
                Canvas canvas = surface.lockCanvas(null);
                Canvas canvas = mAttachInfo.mDragSurface.lockCanvas(null);
                try {
                    canvas.drawColor(0, PorterDuff.Mode.CLEAR);
                    shadowBuilder.onDrawShadow(canvas);
                } finally {
                    surface.unlockCanvasAndPost(canvas);
                    mAttachInfo.mDragSurface.unlockCanvasAndPost(canvas);
                }
                final ViewRootImpl root = getViewRootImpl();
@@ -20005,14 +20008,11 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
                        shadowSize.x, shadowSize.y,
                        shadowTouchPoint.x, shadowTouchPoint.y, data);
                if (ViewDebug.DEBUG_DRAG) Log.d(VIEW_LOG_TAG, "performDrag returned " + okay);
                // Off and running!  Release our local surface instance; the drag
                // shadow surface is now managed by the system process.
                surface.release();
            }
        } catch (Exception e) {
            Log.e(VIEW_LOG_TAG, "Unable to initiate drag", e);
            surface.destroy();
            mAttachInfo.mDragSurface.destroy();
            mAttachInfo.mDragSurface = null;
        }
        return okay;
@@ -20051,6 +20051,27 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
        }
    }
    public final void updateDragShadow(DragShadowBuilder shadowBuilder) {
        if (ViewDebug.DEBUG_DRAG) {
            Log.d(VIEW_LOG_TAG, "updateDragShadow");
        }
        if (mAttachInfo.mDragToken != null) {
            try {
                Canvas canvas = mAttachInfo.mDragSurface.lockCanvas(null);
                try {
                    canvas.drawColor(0, PorterDuff.Mode.CLEAR);
                    shadowBuilder.onDrawShadow(canvas);
                } finally {
                    mAttachInfo.mDragSurface.unlockCanvasAndPost(canvas);
                }
            } catch (Exception e) {
                Log.e(VIEW_LOG_TAG, "Unable to update drag shadow", e);
            }
        } else {
            Log.e(VIEW_LOG_TAG, "No active drag");
        }
    }
    /**
     * Starts a move from {startX, startY}, the amount of the movement will be the offset
     * between {startX, startY} and the new cursor positon.
@@ -22341,6 +22362,11 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
         */
        IBinder mDragToken;
        /**
         * The drag shadow surface for the current drag operation.
         */
        public Surface mDragSurface;
        /**
         * Creates a new set of attachment information with the specified
         * events handler and thread.
+4 −0
Original line number Diff line number Diff line
@@ -5376,6 +5376,10 @@ public final class ViewRootImpl implements ViewParent,
                if (what == DragEvent.ACTION_DRAG_ENDED) {
                    setLocalDragState(null);
                    mAttachInfo.mDragToken = null;
                    if (mAttachInfo.mDragSurface != null) {
                        mAttachInfo.mDragSurface.release();
                        mAttachInfo.mDragSurface = null;
                    }
                }
            }
        }