OSDN Git Service

Implement View.updateDragShadow
authorVladislav Kaznacheev <kaznacheev@google.com>
Wed, 18 Nov 2015 21:21:35 +0000 (13:21 -0800)
committerVladislav Kaznacheev <kaznacheev@google.com>
Sat, 21 Nov 2015 01:07:23 +0000 (17:07 -0800)
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

api/current.txt
api/system-current.txt
core/java/android/view/View.java
core/java/android/view/ViewRootImpl.java

index 2f5686e..e7bdb40 100644 (file)
@@ -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();
index cbe8db7..dc82eba 100644 (file)
@@ -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();
index 66381f9..034cd77 100644 (file)
@@ -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.
@@ -22342,6 +22363,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.
          *
index 2c0cd7a..b503e12 100644 (file)
@@ -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;
+                    }
                 }
             }
         }