List of usage examples for android.view DragEvent getAction
public int getAction()
From source file:app.umitems.greenclock.widget.sgv.StaggeredGridView.java
@Override public boolean onDragEvent(DragEvent ev) { if (!isDragReorderingSupported()) { // If the consumer of this StaggeredGridView has not registered a ReorderListener, // don't bother handling drag events. return false; }//from ww w .j a v a 2 s. co m final int x = (int) ev.getX(); final int y = (int) ev.getY(); switch (ev.getAction()) { case DragEvent.ACTION_DRAG_LOCATION: if (mDragState == ReorderUtils.DRAG_STATE_DRAGGING) { handleDrag(x, y); mLastTouchY = y; } // Kick off the scroll handler on the first drag location event, // if it's not already running if (!mIsDragScrollerRunning && // And if the distance traveled while dragging exceeds the touch slop ((Math.abs(x - mTouchDownForDragStartX) >= 4 * mTouchSlop) || (Math.abs(y - mTouchDownForDragStartY) >= 4 * mTouchSlop))) { // Set true because that the scroller is running now mIsDragScrollerRunning = true; if (mScrollHandler == null) { mScrollHandler = getHandler(); } mScrollHandler.postDelayed(mDragScroller, SCROLL_HANDLER_DELAY); } return true; case DragEvent.ACTION_DROP: case DragEvent.ACTION_DRAG_ENDED: // We can either expect to receive: // 1. Both {@link DragEvent#ACTION_DROP} and then // {@link DragEvent#ACTION_DRAG_ENDED} if the drop is over this view. // 2. Only {@link DragEvent#ACTION_DRAG_ENDED} if the drop happened over a // different view. // For this reason, we should always handle the drop. In case #1, if this code path // gets executed again then nothing will happen because we will have already // updated {@link #mDragState} to not be {@link ReorderUtils#DRAG_STATE_DRAGGING}. if (mScrollHandler != null) { mScrollHandler.removeCallbacks(mDragScroller); // Scroller is no longer running mIsDragScrollerRunning = false; } return true; } return false; }