API CHANGE: drags can now carry an originator-only object payload

When calling startDrag(), the app can now supply an Object to be passed
along in every DragEvent that the app winds up receiving itself.  This
object is *not* passed to any other applications; it's strictly app-
local.  The purpose is to allow state tracking/management to be done
directly through the drag mechanism rather than requiring out-of-band
code.

An example of the utility here might be TextEdit widgets.  A drag that
starts in one TextEdit but ends in a different one should be treated as
a copy/paste operation, where the originating TextEdit is not altered.
However, a drag that starts and ends in the *same* TextEdit is a 'move'
operation within that TextEdit; the text is removed from its original
position and inserted at the drop point.  To support this easily, the
drag/drop code in TextEdit can now pass a pointer to the originating
view as the local state object.  Then, the drop recipient could tell
whether the drag started within the same TextEdit without needing to
implement any other out-of-band state tracking.

This CL (and its accompanying CLs in a few other packages where the
startDrag() API is being used) adds the new local-state parameter to
the API, but does not actually change the behavior of any existing
clients.

Change-Id: Icba73b2ab4a650b7a94485a19633065b0ef9058c
This commit is contained in:
Christopher Tate
2010-11-30 17:14:08 -08:00
parent 4da12f07b5
commit 407b4e91fe
7 changed files with 68 additions and 13 deletions

View File

@ -619,7 +619,7 @@ public class WindowManagerService extends IWindowManager.Stub
if (mDragInProgress && newWin.isPotentialDragTarget()) {
DragEvent event = DragEvent.obtain(DragEvent.ACTION_DRAG_STARTED,
touchX - newWin.mFrame.left, touchY - newWin.mFrame.top,
desc, null, false);
null, desc, null, false);
try {
newWin.mClient.dispatchDragEvent(event);
// track each window that we've notified that the drag is starting
@ -659,7 +659,7 @@ public class WindowManagerService extends IWindowManager.Stub
Slog.d(TAG, "broadcasting DRAG_ENDED");
}
DragEvent evt = DragEvent.obtain(DragEvent.ACTION_DRAG_ENDED,
0, 0, null, null, mDragResult);
0, 0, null, null, null, mDragResult);
for (WindowState ws: mNotifiedWindows) {
try {
ws.mClient.dispatchDragEvent(evt);
@ -711,7 +711,7 @@ public class WindowManagerService extends IWindowManager.Stub
// force DRAG_EXITED_EVENT if appropriate
DragEvent evt = DragEvent.obtain(DragEvent.ACTION_DRAG_EXITED,
x - mTargetWindow.mFrame.left, y - mTargetWindow.mFrame.top,
null, null, false);
null, null, null, false);
mTargetWindow.mClient.dispatchDragEvent(evt);
if (myPid != mTargetWindow.mSession.mPid) {
evt.recycle();
@ -723,7 +723,7 @@ public class WindowManagerService extends IWindowManager.Stub
}
DragEvent evt = DragEvent.obtain(DragEvent.ACTION_DRAG_LOCATION,
x - touchedWin.mFrame.left, y - touchedWin.mFrame.top,
null, null, false);
null, null, null, false);
touchedWin.mClient.dispatchDragEvent(evt);
if (myPid != touchedWin.mSession.mPid) {
evt.recycle();
@ -754,7 +754,7 @@ public class WindowManagerService extends IWindowManager.Stub
final IBinder token = touchedWin.mClient.asBinder();
DragEvent evt = DragEvent.obtain(DragEvent.ACTION_DROP,
x - touchedWin.mFrame.left, y - touchedWin.mFrame.top,
null, mData, false);
null, null, mData, false);
try {
touchedWin.mClient.dispatchDragEvent(evt);