Search in sources :

Example 21 with DragEvent

use of android.view.DragEvent in project android_frameworks_base by crdroidandroid.

the class DragState method sendDragStartedLw.

/* helper - send a ACTION_DRAG_STARTED event, if the
     * designated window is potentially a drop recipient.  There are race situations
     * around DRAG_ENDED broadcast, so we make sure that once we've declared that
     * the drag has ended, we never send out another DRAG_STARTED for this drag action.
     *
     * This method clones the 'event' parameter if it's being delivered to the same
     * process, so it's safe for the caller to call recycle() on the event afterwards.
     */
private void sendDragStartedLw(WindowState newWin, float touchX, float touchY, ClipDescription desc) {
    if (mDragInProgress && isValidDropTarget(newWin)) {
        DragEvent event = obtainDragEvent(newWin, DragEvent.ACTION_DRAG_STARTED, touchX, touchY, null, desc, null, null, false);
        try {
            newWin.mClient.dispatchDragEvent(event);
            // track each window that we've notified that the drag is starting
            mNotifiedWindows.add(newWin);
        } catch (RemoteException e) {
            Slog.w(TAG_WM, "Unable to drag-start window " + newWin);
        } finally {
            // if the callee was local, the dispatch has already recycled the event
            if (Process.myPid() != newWin.mSession.mPid) {
                event.recycle();
            }
        }
    }
}
Also used : DragEvent(android.view.DragEvent) RemoteException(android.os.RemoteException)

Example 22 with DragEvent

use of android.view.DragEvent in project android_frameworks_base by crdroidandroid.

the class DragState method notifyDropLw.

// Find the drop target and tell it about the data.  Returns 'true' if we can immediately
// dispatch the global drag-ended message, 'false' if we need to wait for a
// result from the recipient.
boolean notifyDropLw(float x, float y) {
    if (mAnimation != null) {
        return false;
    }
    mCurrentX = x;
    mCurrentY = y;
    WindowState touchedWin = mDisplayContent.getTouchableWinAtPointLocked(x, y);
    if (!isWindowNotified(touchedWin)) {
        // "drop" outside a valid window -- no recipient to apply a
        // timeout to, and we can send the drag-ended message immediately.
        mDragResult = false;
        return true;
    }
    if (DEBUG_DRAG) {
        Slog.d(TAG_WM, "sending DROP to " + touchedWin);
    }
    final int targetUserId = UserHandle.getUserId(touchedWin.getOwningUid());
    DragAndDropPermissionsHandler dragAndDropPermissions = null;
    if ((mFlags & View.DRAG_FLAG_GLOBAL) != 0 && (mFlags & DRAG_FLAGS_URI_ACCESS) != 0) {
        dragAndDropPermissions = new DragAndDropPermissionsHandler(mData, mUid, touchedWin.getOwningPackage(), mFlags & DRAG_FLAGS_URI_PERMISSIONS, mSourceUserId, targetUserId);
    }
    if (mSourceUserId != targetUserId) {
        mData.fixUris(mSourceUserId);
    }
    final int myPid = Process.myPid();
    final IBinder token = touchedWin.mClient.asBinder();
    DragEvent evt = obtainDragEvent(touchedWin, DragEvent.ACTION_DROP, x, y, null, null, mData, dragAndDropPermissions, false);
    try {
        touchedWin.mClient.dispatchDragEvent(evt);
        // 5 second timeout for this window to respond to the drop
        mService.mH.removeMessages(H.DRAG_END_TIMEOUT, token);
        Message msg = mService.mH.obtainMessage(H.DRAG_END_TIMEOUT, token);
        mService.mH.sendMessageDelayed(msg, 5000);
    } catch (RemoteException e) {
        Slog.w(TAG_WM, "can't send drop notification to win " + touchedWin);
        return true;
    } finally {
        if (myPid != touchedWin.mSession.mPid) {
            evt.recycle();
        }
    }
    mToken = token;
    return false;
}
Also used : DragEvent(android.view.DragEvent) IBinder(android.os.IBinder) Message(android.os.Message) RemoteException(android.os.RemoteException) Point(android.graphics.Point)

Aggregations

DragEvent (android.view.DragEvent)22 RemoteException (android.os.RemoteException)20 Point (android.graphics.Point)14 IBinder (android.os.IBinder)7 Message (android.os.Message)5 ClipData (android.content.ClipData)2 Uri (android.net.Uri)2 DragAndDropPermissions (android.view.DragAndDropPermissions)2 View (android.view.View)2 ImageView (android.widget.ImageView)2 TextView (android.widget.TextView)2 MediaWrapper (org.videolan.medialibrary.media.MediaWrapper)2