Search in sources :

Example 1 with DragEvent

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

the class DragState method notifyDropLw.

// Tell the drop target 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) {
    WindowState touchedWin = getTouchedWinAtPointLw(x, y);
    if (touchedWin == null) {
        // "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 (WindowManagerService.DEBUG_DRAG) {
        Slog.d(WindowManagerService.TAG, "sending DROP to " + touchedWin);
    }
    final int myPid = Process.myPid();
    final IBinder token = touchedWin.mClient.asBinder();
    DragEvent evt = obtainDragEvent(touchedWin, DragEvent.ACTION_DROP, x, y, null, null, mData, 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(WindowManagerService.TAG, "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)

Example 2 with DragEvent

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

the class DragState method broadcastDragEndedLw.

void broadcastDragEndedLw() {
    if (WindowManagerService.DEBUG_DRAG) {
        Slog.d(WindowManagerService.TAG, "broadcasting DRAG_ENDED");
    }
    DragEvent evt = DragEvent.obtain(DragEvent.ACTION_DRAG_ENDED, 0, 0, null, null, null, mDragResult);
    for (WindowState ws : mNotifiedWindows) {
        try {
            ws.mClient.dispatchDragEvent(evt);
        } catch (RemoteException e) {
            Slog.w(WindowManagerService.TAG, "Unable to drag-end window " + ws);
        }
    }
    mNotifiedWindows.clear();
    mDragInProgress = false;
    evt.recycle();
}
Also used : DragEvent(android.view.DragEvent) RemoteException(android.os.RemoteException)

Example 3 with DragEvent

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

the class DragState method sendDragStartedLw.

/* helper - send a caller-provided event, presumed to be DRAG_STARTED, 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) {
    // to the originating window but 'newWin' is not that window.
    if ((mFlags & View.DRAG_FLAG_GLOBAL) == 0) {
        final IBinder winBinder = newWin.mClient.asBinder();
        if (winBinder != mLocalWin) {
            if (WindowManagerService.DEBUG_DRAG) {
                Slog.d(WindowManagerService.TAG, "Not dispatching local DRAG_STARTED to " + newWin);
            }
            return;
        }
    }
    if (mDragInProgress && newWin.isPotentialDragTarget()) {
        DragEvent event = obtainDragEvent(newWin, DragEvent.ACTION_DRAG_STARTED, touchX, touchY, null, desc, 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(WindowManagerService.TAG, "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) IBinder(android.os.IBinder) RemoteException(android.os.RemoteException)

Example 4 with DragEvent

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

the class DragState method broadcastDragEndedLw.

private void broadcastDragEndedLw() {
    final int myPid = Process.myPid();
    if (DEBUG_DRAG) {
        Slog.d(TAG_WM, "broadcasting DRAG_ENDED");
    }
    for (WindowState ws : mNotifiedWindows) {
        float x = 0;
        float y = 0;
        if (!mDragResult && (ws.mSession.mPid == mPid)) {
            // Report unconsumed drop location back to the app that started the drag.
            x = mCurrentX;
            y = mCurrentY;
        }
        DragEvent evt = DragEvent.obtain(DragEvent.ACTION_DRAG_ENDED, x, y, null, null, null, null, mDragResult);
        try {
            ws.mClient.dispatchDragEvent(evt);
        } catch (RemoteException e) {
            Slog.w(TAG_WM, "Unable to drag-end window " + ws);
        }
        // the dispatch has already recycled the event
        if (myPid != ws.mSession.mPid) {
            evt.recycle();
        }
    }
    mNotifiedWindows.clear();
    mDragInProgress = false;
}
Also used : DragEvent(android.view.DragEvent) RemoteException(android.os.RemoteException) Point(android.graphics.Point)

Example 5 with DragEvent

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

the class DragState method notifyLocationLw.

void notifyLocationLw(float x, float y) {
    // Tell the affected window
    WindowState touchedWin = mDisplayContent.getTouchableWinAtPointLocked(x, y);
    if (touchedWin != null && !isWindowNotified(touchedWin)) {
        // The drag point is over a window which was not notified about a drag start.
        // Pretend it's over empty space.
        touchedWin = null;
    }
    try {
        final int myPid = Process.myPid();
        // have we dragged over a new window?
        if ((touchedWin != mTargetWindow) && (mTargetWindow != null)) {
            if (DEBUG_DRAG) {
                Slog.d(TAG_WM, "sending DRAG_EXITED to " + mTargetWindow);
            }
            // force DRAG_EXITED_EVENT if appropriate
            DragEvent evt = obtainDragEvent(mTargetWindow, DragEvent.ACTION_DRAG_EXITED, 0, 0, null, null, null, null, false);
            mTargetWindow.mClient.dispatchDragEvent(evt);
            if (myPid != mTargetWindow.mSession.mPid) {
                evt.recycle();
            }
        }
        if (touchedWin != null) {
            if (false && DEBUG_DRAG) {
                Slog.d(TAG_WM, "sending DRAG_LOCATION to " + touchedWin);
            }
            DragEvent evt = obtainDragEvent(touchedWin, DragEvent.ACTION_DRAG_LOCATION, x, y, null, null, null, null, false);
            touchedWin.mClient.dispatchDragEvent(evt);
            if (myPid != touchedWin.mSession.mPid) {
                evt.recycle();
            }
        }
    } catch (RemoteException e) {
        Slog.w(TAG_WM, "can't send drag notification to windows");
    }
    mTargetWindow = touchedWin;
}
Also used : DragEvent(android.view.DragEvent) 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