List of usage examples for android.view DragEvent ACTION_DRAG_LOCATION
int ACTION_DRAG_LOCATION
To view the source code for android.view DragEvent ACTION_DRAG_LOCATION.
Click Source Link
From source file:com.svpino.longhorn.fragments.StockListFragment.java
@TargetApi(11) @Override//w w w.j a v a 2s . c o m public boolean onDrag(View tile2, DragEvent event) { View tile1 = (View) event.getLocalState(); StockTileViewHolder stockTileViewHolder1 = (StockTileViewHolder) tile1.getTag(); StockTileViewHolder stockTileViewHolder2 = (StockTileViewHolder) tile2.getTag(); switch (event.getAction()) { case DragEvent.ACTION_DRAG_STARTED: tile1.setVisibility(View.INVISIBLE); if (stockTileViewHolder1.getPosition() != stockTileViewHolder2.getPosition()) { return true; } return false; case DragEvent.ACTION_DRAG_ENTERED: this.focusedTileDuringDragAndDrop = tile2; StockTileProcessor.updateTileColorToDropReceptor(tile2); tile2.invalidate(); return true; case DragEvent.ACTION_DRAG_LOCATION: return true; case DragEvent.ACTION_DRAG_EXITED: this.focusedTileDuringDragAndDrop = null; StockTileProcessor.updateTileColor(this, tile2, this.selectedTiles); tile2.invalidate(); return true; case DragEvent.ACTION_DROP: this.focusedTileDuringDragAndDrop = null; swapTiles(tile1, tile2); return true; case DragEvent.ACTION_DRAG_ENDED: if (this.focusedTileDuringDragAndDrop != null) { swapTiles(tile1, this.focusedTileDuringDragAndDrop); this.focusedTileDuringDragAndDrop = null; return true; } StockTileProcessor.updateTileColor(this, tile1, this.selectedTiles); StockTileProcessor.updateTileColor(this, tile2, this.selectedTiles); tile1.setVisibility(View.VISIBLE); tile2.setVisibility(View.VISIBLE); tile1.invalidate(); tile2.invalidate(); return true; default: return true; } }
From source file:com.android.systemui.qs.QSDragPanel.java
@Override public boolean onDrag(View v, DragEvent event) { final DragTileRecord targetTile = (DragTileRecord) getRecord(v); boolean originatingTileEvent = mDraggingRecord != null && v == mDraggingRecord.tileView; final int dragRecordIndex = mRecords.indexOf(mDraggingRecord); boolean dragRecordAttached = dragRecordIndex != -1; switch (event.getAction()) { case DragEvent.ACTION_DRAG_STARTED: if (DEBUG_DRAG) { Log.v(TAG, "ACTION_DRAG_STARTED on view: " + v); }/*w w w. j ava 2 s. c om*/ if (originatingTileEvent) { if (DEBUG_DRAG) { Log.v(TAG, "ACTION_DRAG_STARTED on target view."); } mRestored = false; mQsPanelTop.setDropIcon(R.drawable.ic_qs_tile_delete_disable, R.color.qs_tile_trash_normal_tint); } break; case DragEvent.ACTION_DRAG_ENTERED: if (DEBUG_DRAG) { if (targetTile != null) { Log.v(TAG, "ACTION_DRAG_ENTERED on view with tile: " + targetTile); } else { Log.v(TAG, "ACTION_DRAG_ENTERED on view: " + v); } } mLocationHits = 0; mMovedByLocation = false; if (v == mQsPanelTop) { int icon, color; if (mDraggingRecord.tile instanceof EditTile) { // use a different warning, user can't erase this one icon = R.drawable.ic_qs_tile_delete_disable_avd; color = R.color.qs_tile_trash_delete_tint_warning; } else { icon = R.drawable.ic_qs_tile_delete_disable; color = R.color.qs_tile_trash_delete_tint; } mQsPanelTop.setDropIcon(icon, color); } if (!originatingTileEvent && v != getDropTarget() && targetTile != null) { if (DEBUG_DRAG) { Log.e(TAG, "entered tile " + targetTile); } if (mCurrentlyAnimating.isEmpty() && !mViewPager.isFakeDragging() && !dragRecordAttached) { mMovedByLocation = true; shiftTiles(targetTile, true); } else { if (DEBUG_DRAG) { Log.w(TAG, "ignoring action enter for animating tiles and fake drags"); } } } break; case DragEvent.ACTION_DRAG_ENDED: if (DEBUG_DRAG) { Log.v(TAG, "ACTION_DRAG_ENDED on view: " + v + "(tile: " + targetTile + "), result: " + event.getResult()); } if (originatingTileEvent && !event.getResult()) { // view pager probably ate the event restoreDraggingTilePosition(v, null); } break; case DragEvent.ACTION_DROP: if (DEBUG_DRAG) { Log.v(TAG, "ACTION_DROP, event loc: " + event.getX() + ", " + event.getY() + " + with tile: " + targetTile + " and view: " + v); } mLastTouchLocationX = event.getX(); mLastTouchLocationY = event.getY(); if (isDropTargetEvent(event, v)) { if (DEBUG_DRAG) { Log.d(TAG, "dropping on delete target!!"); } if (mDraggingRecord.tile instanceof EditTile) { final QSTileView editTileView = mDraggingRecord.tileView; mQsPanelTop.toast(R.string.quick_settings_cannot_delete_edit_tile); restoreDraggingTilePosition(v, new Runnable() { @Override public void run() { // move edit tile to the back final TileRecord editTile = getRecord(editTileView); if (mRecords.remove(editTile)) { // we depend on mHost.setTiles() placing it on the end persistRecords(); } } }); break; } else if (mDraggingRecord.tile instanceof CustomQSTile) { ((CustomQSTile) mDraggingRecord.tile).setUserRemoved(true); final String spec = mHost.getSpec(mDraggingRecord.tile); restoreDraggingTilePosition(v, new Runnable() { @Override public void run() { // it might get added back later by the app, but that's ok, // we just want to reset its position after it has been removed. mHost.remove(spec); } }); } else { mRestored = true; removeDraggingRecord(); } } else { restoreDraggingTilePosition(v, null); } break; case DragEvent.ACTION_DRAG_EXITED: if (DEBUG_DRAG) { if (targetTile != null) { Log.v(TAG, "ACTION_DRAG_EXITED on view with tile: " + targetTile); } else { Log.v(TAG, "ACTION_DRAG_EXITED on view: " + v); } } if (v == mQsPanelTop) { mQsPanelTop.setDropIcon(R.drawable.ic_qs_tile_delete_disable, R.color.qs_tile_trash_normal_tint); } if (originatingTileEvent && mCurrentlyAnimating.isEmpty() && !mViewPager.isFakeDragging() && dragRecordAttached && mLastLeftShift == -1) { if (DEBUG_DRAG) { Log.v(TAG, "target: " + targetTile + ", hit mLastRightShift: " + mLastRightShift + ", mLastLeftShift: " + mLastLeftShift + ", dragRecordIndex: " + dragRecordIndex); } // move tiles back shiftTiles(mDraggingRecord, false); break; } // fall through so exit events can trigger a left shift case DragEvent.ACTION_DRAG_LOCATION: mLastTouchLocationX = event.getX(); mLastTouchLocationY = event.getY(); // do nothing if we're animating tiles if (mCurrentlyAnimating.isEmpty() && !mViewPager.isFakeDragging()) { if (v == mViewPager) { // do we need to change pages? int x = (int) event.getX(); int width = mViewPager.getWidth(); int scrollPadding = (int) (width * QSViewPager.SCROLL_PERCENT); if (x < scrollPadding) { if (mViewPager.canScrollHorizontally(-1)) { mViewPager.animatePagerTransition(false); return true; } } else if (x > width - scrollPadding) { if (mViewPager.canScrollHorizontally(1)) { mViewPager.animatePagerTransition(true); return true; } } } if (DEBUG_DRAG) { Log.v(TAG, "location hit:// target: " + targetTile + ", hit mLastRightShift: " + mLastRightShift + ", mLastLeftShift: " + mLastLeftShift + ", dragRecordIndex: " + dragRecordIndex + ", originatingTileEvent: " + originatingTileEvent + ", mLocationHits: " + mLocationHits + ", mMovedByLocation: " + mMovedByLocation); } if (v != getDropTarget() && targetTile != null && !dragRecordAttached) { // dragging around on another tile if (mLocationHits++ == 30) { if (DEBUG_DRAG) { Log.w(TAG, "shifting right due to location hits."); } // add dragging tile to current page shiftTiles(targetTile, true); mMovedByLocation = true; } else { mLocationHits++; } } else if (mLastRightShift != -1 // right has shifted recently && mLastLeftShift == -1 // -1 means its attached && dragRecordIndex == mLastRightShift && !originatingTileEvent && !mMovedByLocation /* helps avoid continuous shifting */) { // check if the location is on another tile/view // that is not the last drag index, shift back left to revert back and // potentially get ready for shifting right if (DEBUG_DRAG) { Log.w(TAG, "conditions met to reverse!!!! shifting left. <<<<<<<"); } shiftTiles((DragTileRecord) mRecords.get(mLastRightShift), false); mMovedByLocation = true; } } else { if (DEBUG_DRAG) { Log.i(TAG, "ignoring location event because things are animating, size: " + mCurrentlyAnimating.size()); } } break; default: Log.w(TAG, "unhandled event"); return false; } return true; }
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; }//w w w . ja v a2 s .com 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; }