@Override public boolean onDrag(View view, DragEvent event) { if (mLauncher == null || mDragController == null) { postCleanup(); return false; } if (event.getAction() == DragEvent.ACTION_DRAG_STARTED) { if (onDragStart(event)) { return true; } else { postCleanup(); return false; } } return mDragController.onDragEvent(mDragStartTime, event); }
/** * Same as {@link #recordMotionEvent}. It creates a temporary {@link MotionEvent} object * using {@param event} for tracking velocity. */ void recordDragEvent(long dragStartTime, DragEvent event) { final int motionAction; switch (event.getAction()) { case DragEvent.ACTION_DRAG_STARTED: motionAction = MotionEvent.ACTION_DOWN; break; case DragEvent.ACTION_DRAG_LOCATION: motionAction = MotionEvent.ACTION_MOVE; break; case DragEvent.ACTION_DRAG_ENDED: motionAction = MotionEvent.ACTION_UP; break; default: return; } MotionEvent emulatedEvent = MotionEvent.obtain(dragStartTime, SystemClock.uptimeMillis(), motionAction, event.getX(), event.getY(), 0); recordMotionEvent(emulatedEvent); emulatedEvent.recycle(); }
@Override public boolean dispatchDragEvent(DragEvent e) { ContentViewCore contentViewCore = mTabVisible.getContentViewCore(); if (contentViewCore == null) return false; if (mLayoutManager != null) mLayoutManager.getViewportPixel(mCacheViewport); contentViewCore.setCurrentTouchEventOffsets(-mCacheViewport.left, -mCacheViewport.top); boolean ret = super.dispatchDragEvent(e); int action = e.getAction(); if (action == DragEvent.ACTION_DRAG_EXITED || action == DragEvent.ACTION_DRAG_ENDED || action == DragEvent.ACTION_DROP) { contentViewCore.setCurrentTouchEventOffsets(0.f, 0.f); } return ret; }
/** * Continue dragging the currently moving block. Called during ACTION_DRAG_LOCATION. * * @param event The next drag event to handle, as received by the {@link WorkspaceView}. */ private void continueDragging(DragEvent event) { updateBlockPosition(event); // highlight as we go BlockView highlightedBlockView = mHighlightedBlockViewRef.get(); if (highlightedBlockView != null) { highlightedBlockView.setHighlightedConnection(null); } Pair<Connection, Connection> connectionCandidate = findBestConnection(mPendingDrag.getRootDraggedBlock()); if (connectionCandidate != null) { highlightedBlockView = mViewHelper.getView(connectionCandidate.second.getBlock()); mHighlightedBlockViewRef = new WeakReference<>(highlightedBlockView); highlightedBlockView.setHighlightedConnection(connectionCandidate.second); } mPendingDrag.getDragGroup().requestLayout(); }
/** * Move the currently dragged block in response to a new {@link MotionEvent}. * <p/> * All of the child blocks move with the root block based on its position during layout. * * @param event The {@link MotionEvent} to react to. */ private void updateBlockPosition(DragEvent event) { // The event is relative to the WorkspaceView. Grab the pixel offset within. ViewPoint curDragLocationPixels = mTempViewPoint; curDragLocationPixels.set((int) event.getX(), (int) event.getY()); WorkspacePoint curDragPositionWorkspace = mTempWorkspacePoint; mViewHelper.virtualViewToWorkspaceCoordinates( curDragLocationPixels, curDragPositionWorkspace); WorkspacePoint touchDownWorkspace = mPendingDrag.getTouchDownWorkspaceCoordinates(); // Subtract original drag location from current location to get delta float workspaceDeltaX = curDragPositionWorkspace.x - touchDownWorkspace.x; float workspaceDeltaY = curDragPositionWorkspace.y - touchDownWorkspace.y; WorkspacePoint blockOrigPosition = mPendingDrag.getOriginalBlockPosition(); mPendingDrag.getRootDraggedBlock().setPosition(blockOrigPosition.x + workspaceDeltaX, blockOrigPosition.y + workspaceDeltaY); mPendingDrag.getDragGroup().requestLayout(); }
@Override public void setOnDragListener(final View.OnDragListener dragListener) { View.OnDragListener wrapper = new OnDragListener() { @Override public boolean onDrag(View view, DragEvent dragEvent) { int action = dragEvent.getAction(); // Whether the dragged object can be handled by the trash. boolean result = dragListener.onDrag(view, dragEvent); if (action == DragEvent.ACTION_DRAG_ENDED) { setState(STATE_DEFAULT); } else if (result) { switch (action) { case DragEvent.ACTION_DRAG_ENTERED: setState(STATE_ON_HOVER); break; case DragEvent.ACTION_DROP: case DragEvent.ACTION_DRAG_EXITED: setState(STATE_DEFAULT); break; } } return result; } }; super.setOnDragListener(wrapper); }
public QuickRow(final View.OnDragListener dragListener, MainActivity mainActivity) { mMainActivity = mainActivity; mQuickRow = mMainActivity.findViewById(R.id.layout_quickrow); mQuickRowScroller = mMainActivity.findViewById(R.id.layout_quickrow_scroll); mQuickRow.setOnDragListener(dragListener); mQuickRowScroller.setOnDragListener(new View.OnDragListener() { @Override public boolean onDrag(View view, DragEvent dragEvent) { return dragListener.onDrag(mQuickRow, dragEvent); } }); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); getWindow().setWindowAnimations(R.style.animation_baseDialog); setContentView(R.layout.video_edit_text_input); mEditText = (EditText) findViewById(android.R.id.edit); mConfirmButton = (ImageView) findViewById(R.id.text_edit_confirm_button); mBackImg = (ImageView) findViewById(R.id.back_img); mEditText.setText(mExistText); mEditText.setSelection(mExistText.length()); mEditText.setOnDragListener(new View.OnDragListener() { @Override public boolean onDrag(View v, DragEvent event) { return true; } }); }
@Override public boolean onDrag(View view, DragEvent dragEvent) { switch (dragEvent.getAction()) { case DragEvent.ACTION_DRAG_STARTED: AttachmentsProvider provider = AttachmentsProviderFactory.getAttachmentProvider(getContext()); return mCallback != null && provider.isSupported(); case DragEvent.ACTION_DRAG_ENTERED: setBackgroundColor(ContextCompat.getColor(getContext(), R.color.attachmentOverlay)); return isValidDragEvent(dragEvent.getClipData()); case DragEvent.ACTION_DRAG_ENDED: setBackgroundColor(ContextCompat.getColor(getContext(), android.R.color.transparent)); return true; case DragEvent.ACTION_DRAG_EXITED: case DragEvent.ACTION_DRAG_LOCATION: return true; case DragEvent.ACTION_DROP: if (isValidDragEvent(dragEvent.getClipData())) { final List<Attachment> attachments = extractAttachments(dragEvent.getClipData()); post(() -> mCallback.onAttachmentsDropped(attachments)); return true; } // Fallback } return false; }
/** * Handles drag event. */ @Override public boolean onDragEvent(DragEvent event) { switch (event.getAction()) { case DragEvent.ACTION_DRAG_STARTED: // Only handle plain text drag and drop. return event.getClipDescription().hasMimeType(ClipDescription.MIMETYPE_TEXT_PLAIN); case DragEvent.ACTION_DRAG_ENTERED: requestFocus(); return true; case DragEvent.ACTION_DROP: handlePasteClip(event.getClipData()); return true; } return false; }
@Override public boolean dispatchDragEvent(DragEvent ev) { final DragEvent event = ev; boolean r = super.dispatchDragEvent(ev); if (r && (ev.getAction() == DragEvent.ACTION_DRAG_STARTED || ev.getAction() == DragEvent.ACTION_DRAG_ENDED)) { // If we got a start or end and the return value is true, our // onDragEvent wasn't called by ViewGroup.dispatchDragEvent // So we do it here. this.post(new Runnable() { @Override public void run() { onDragEvent(event); } }); // fix crash on older versions of android try { super.dispatchDragEvent(ev); } catch (NullPointerException e) { e.printStackTrace(); } } return r; }
private boolean handleDragEvent(final View v, final DragEvent event) { switch(event.getAction()) { case DragEvent.ACTION_DRAG_STARTED: case DragEvent.ACTION_DRAG_ENTERED: case DragEvent.ACTION_DRAG_LOCATION: case DragEvent.ACTION_DRAG_EXITED: case DragEvent.ACTION_DRAG_ENDED: return true; case DragEvent.ACTION_DROP: final String phrase = event.getClipData().getItemAt(0).getText().toString(); moveViewToCorrectLocationFromDrag(v, phrase); return true; default: return false; } }
@Override public boolean onDragEvent(DragEvent event) { switch (event.getAction()) { case DragEvent.ACTION_DRAG_STARTED: return mEditor != null && mEditor.hasInsertionController(); case DragEvent.ACTION_DRAG_ENTERED: TextView.this.requestFocus(); return true; case DragEvent.ACTION_DRAG_LOCATION: final int offset = getOffsetForPosition(event.getX(), event.getY()); Selection.setSelection((Spannable)mText, offset); return true; case DragEvent.ACTION_DROP: if (mEditor != null) mEditor.onDrop(event); return true; case DragEvent.ACTION_DRAG_ENDED: case DragEvent.ACTION_DRAG_EXITED: default: return true; } }
/** * 获取拖拽触发的执行事件类型 * * @param draggedViewPager 最外层 {@link com.bigfat.draggedviewpager.view.MDA_DraggedViewPager} * @param currentPageIndex 当前页索引 * @param pageIndex 响应拖拽事件item所在页索引 * @param view 响应拖拽事件的item * @param event 拖拽事件 * @return 拖拽事件类型 */ public static DragEventType getDragEventType(MDA_DraggedViewPager draggedViewPager, int currentPageIndex, int pageIndex, View view, DragEvent event) { if (currentPageIndex > 0//有上一页 && (draggedViewPager.getPageDragSetting() == null || draggedViewPager.getPageDragSetting() .canBeSwiped(currentPageIndex - 1))//上一页可被交换 //触摸至上一页//或至触摸至当前页左边界,则切换到上一页 && (pageIndex < currentPageIndex || (pageIndex == currentPageIndex && event.getX() < view.getWidth() / 8))) { return DragEventType.SCROLL_PREVIOUS; } else if (currentPageIndex < (draggedViewPager.getContainer().getChildCount() - 1)//在有下一页的前提下 && (draggedViewPager.getPageDragSetting() == null || draggedViewPager.getPageDragSetting() .canBeSwiped(currentPageIndex + 1))//下一页可被交换 //触摸至下一页//或至触摸至当前页右边界,则切换到下一页 && (pageIndex > currentPageIndex || (pageIndex == currentPageIndex && event.getX() > view.getWidth() / 8 * 7))) { return DragEventType.SCROLL_NEXT; } return DragEventType.DEFAULT; }
private boolean dragLocation(View v, DragEvent event) { Projection p = mapView.getProjection(); LatLng latLng = (LatLng) p.fromPixels(event.getX(), event.getY()); this.activeVertex.getOwner().setLatLng(this.activeIndex, latLng); // Let implementing classes perform reset action. this.activeVertex.getOwner().reset(); Vertex vertex = vertices.get(selected); Vertex prev = vertex.getPrev(); Vertex next = vertex.getNext(); if (prev != null && !prev.equals(vertex)) { vertex.getMiddleLeft().setPoint(getMiddleLatLng(prev.getPoint(), latLng)); } if (next != null && !next.equals(vertex)) { vertex.getMiddleRight().setPoint(getMiddleLatLng(latLng, next.getPoint())); } // Invalidating the view causes a redraw. v.invalidate(); return true; }
public boolean onDrag(View v, DragEvent event) { final int action = event.getAction(); switch (action) { case DragEvent.ACTION_DRAG_STARTED: return dragStart(v, event); case DragEvent.ACTION_DRAG_ENTERED: return true; case DragEvent.ACTION_DRAG_LOCATION: return this.dragLocation(v, event); case DragEvent.ACTION_DRAG_EXITED: return true; case DragEvent.ACTION_DROP: return this.dragDrop(v, event); case DragEvent.ACTION_DRAG_ENDED: return true; default: Log.e("MarkerDragEventListener", "Unknown action type received by OnDragListener."); break; } return false; }
@Override public boolean onDrag (View view, DragEvent event) { try { switch (event.getAction ()) { case DragEvent.ACTION_DRAG_ENTERED: this.appManager.startedDraggingPinnedApp (); break; case DragEvent.ACTION_DROP: case DragEvent.ACTION_DRAG_EXITED: this.appManager.stoppedDraggingPinnedApp (); break; } } catch (Exception ex) { ExceptionHandler exh = new ExceptionHandler (this.appManager.getContext (), ex); exh.show (); } return true; }
private TableRow createNewTableRow() { TableRow row = new TableRow(getActivity()) { @Override public boolean dispatchDragEvent(DragEvent ev) { boolean r = super.dispatchDragEvent(ev); if (r && (ev.getAction() == DragEvent.ACTION_DRAG_STARTED || ev.getAction() == DragEvent.ACTION_DRAG_ENDED)) { // If we got a start or end and the return value is true, // our // onDragEvent wasn't called by ViewGroup.dispatchDragEvent // So we do it here. onDragEvent(ev); } return r; } }; row.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.WRAP_CONTENT, TableRow.LayoutParams.WRAP_CONTENT)); row.setPadding(2, 5, 5, 2); return row; }
@TargetApi(Build.VERSION_CODES.HONEYCOMB) private void setUpTabDeleteCross() { mTabDeleteCross.setOnDragListener(new View.OnDragListener() { @Override public boolean onDrag(View v, DragEvent event) { switch (event.getAction()) { case DragEvent.ACTION_DROP: int tabPosition = mFragmentCommunicator.getPositionOfTab(); mFragmentCommunicator.removeTabAt(tabPosition); case DragEvent.ACTION_DRAG_ENDED: mTabDeleteCross.startAnimation( AnimationUtils.loadAnimation(getActivity(), android.R.anim.fade_out)); mTabDeleteCross.setVisibility(View.INVISIBLE); mTabDeleteCross.getBackground().clearColorFilter(); } return true; } }); }
@Override public boolean onDragEvent(DragEvent event) { switch (event.getAction()) { case DragEvent.ACTION_DRAG_STARTED: //Log.i(TAG, "Drag Started."); return onDragStarted(event); case DragEvent.ACTION_DRAG_ENTERED: Log.i(TAG, "Drag entered ADDV"); return onDragEntered(event); case DragEvent.ACTION_DRAG_LOCATION: return onDragMoveOn(event); case DragEvent.ACTION_DRAG_EXITED: Log.i(TAG, "Drag exited ADDV"); return onDragExited(event); case DragEvent.ACTION_DROP: Log.i(TAG, "Drag droped ADDV"); return onDrop(event); case DragEvent.ACTION_DRAG_ENDED: //Log.i(TAG, "Drag ended ADDV."); return onDragEnded(event); } return super.onDragEvent(event); }
@Override public boolean onDragEvent(DragEvent event) { switch (event.getAction()) { case DragEvent.ACTION_DRAG_STARTED: //Log.i(TAG, "DropLV Drag Started."); return onDragStarted(event); case DragEvent.ACTION_DRAG_ENTERED: Log.i(TAG, "Drag entered DropLV."); return onDragEntered(event); case DragEvent.ACTION_DRAG_LOCATION: return onDragMoveOn(event); case DragEvent.ACTION_DRAG_EXITED: Log.i(TAG, "Drag exited DropLV."); return onDragExited(event); case DragEvent.ACTION_DROP: Log.i(TAG, "Drag droped DropLV."); return onDrop(event); case DragEvent.ACTION_DRAG_ENDED: //Log.i(TAG, "DropLV Drag ended."); return onDragEnded(event); } return super.onDragEvent(event); }
private boolean findAppropriateDropHandle(DragEvent event) { Log.i(TAG, "Loc of parent: x:" + mLocationOnScreen[0] + " y:" + mLocationOnScreen[1]); mDragLocationOnScreen[0] = (int) (mLocationOnScreen[0] + event.getX()); mDragLocationOnScreen[1] = (int) (mLocationOnScreen[1] + event.getY()); Log.i(TAG, "DLV Drag location relative, x: " + mDragLocationOnScreen[0] + " y: " + mDragLocationOnScreen[1]); if (mCurrentDropHandleView != null) { ((DropAcceptable) mCurrentDropHandleView).onDrop(event); mCurrentDropHandleView = null; return true; } else { return false; } }
@Override public boolean onDragEvent(DragEvent event) { switch (event.getAction()) { case DragEvent.ACTION_DRAG_STARTED: //Log.i(TAG, "DropGV Drag Started."); return onDragStarted(event); case DragEvent.ACTION_DRAG_ENTERED: Log.i(TAG, "Drag entered DropGV."); return onDragEntered(event); case DragEvent.ACTION_DRAG_LOCATION: return onDragMoveOn(event); case DragEvent.ACTION_DRAG_EXITED: Log.i(TAG, "Drag exited DropGV"); return onDragExited(event); case DragEvent.ACTION_DROP: Log.i(TAG, "Drag droped DropGV"); return onDrop(event); case DragEvent.ACTION_DRAG_ENDED: //Log.i(TAG, "Drag ended DropGV."); return onDragEnded(event); } return super.onDragEvent(event); }
private boolean findAppropriateDropHandle(DragEvent event) { Log.i(TAG, "Loc of parent: x:" + mLocationOnScreen[0] + " y:" + mLocationOnScreen[1]); mDragLocationOnScreen[0] = (int) (mLocationOnScreen[0] + event.getX()); mDragLocationOnScreen[1] = (int) (mLocationOnScreen[1] + event.getY()); Log.i(TAG, "DGV Drag location relative, x: " + mDragLocationOnScreen[0] + " y: " + mDragLocationOnScreen[1]); if (mCurrentDropHandleView != null) { ((DropAcceptable) mCurrentDropHandleView).onDrop(event); mCurrentDropHandleView = null; return true; } else { return false; } }
/** * Tests to see if the drop will be accepted by Launcher, and if so, includes additional data * in the returned structure related to the widgets that match the drop (or a null list if it is * a shortcut drop). If the drop is not accepted then a null structure is returned. */ private Pair<Integer, List<WidgetMimeTypeHandlerData>> validateDrag(DragEvent event) { final LauncherModel model = mLauncher.getModel(); final ClipDescription desc = event.getClipDescription(); final int mimeTypeCount = desc.getMimeTypeCount(); for (int i = 0; i < mimeTypeCount; ++i) { final String mimeType = desc.getMimeType(i); if (mimeType.equals(InstallShortcutReceiver.SHORTCUT_MIMETYPE)) { return new Pair<Integer, List<WidgetMimeTypeHandlerData>>(i, null); } else { final List<WidgetMimeTypeHandlerData> widgets = model.resolveWidgetsForMimeType(mContext, mimeType); if (widgets.size() > 0) { return new Pair<Integer, List<WidgetMimeTypeHandlerData>>(i, widgets); } } } return null; }
@Override public boolean onDrag(final View view, final DragEvent event) { //if (catView == null) return true; switch (event.getAction()) { case DragEvent.ACTION_DROP: final View dragView = (View)event.getLocalState(); final int width = dragView.getWidth(); final int height = dragView.getHeight(); final int xPos = (int)(event.getX() - (width / 2)); final int yPos = (int)(event.getY() - (height / 2)); final FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(width, height); layoutParams.setMargins(xPos, yPos, 0, 0); dragView.setLayoutParams(layoutParams); dragView.setVisibility(View.VISIBLE); catView = null; break; } return true; }
@Override public boolean onDragEvent (DragEvent event) { final int action = event.getAction(); switch (action) { case DragEvent.ACTION_DRAG_STARTED: mLastX = event.getX(); mLastY = event.getY(); return true; case DragEvent.ACTION_DRAG_ENTERED: return true; case DragEvent.ACTION_DRAG_LOCATION: mLastX = event.getX(); mLastY = event.getY(); mEventListener.onDriverDragMove(event.getX(), event.getY()); return true; case DragEvent.ACTION_DROP: mLastX = event.getX(); mLastY = event.getY(); mEventListener.onDriverDragMove(event.getX(), event.getY()); mEventListener.onDriverDragEnd(mLastX, mLastY); return true; case DragEvent.ACTION_DRAG_EXITED: mEventListener.onDriverDragExitWindow(); return true; case DragEvent.ACTION_DRAG_ENDED: mEventListener.onDriverDragCancel(); return true; default: return false; } }
/** * Create {@link DragAndDropPermissions} object bound to this activity and controlling the * access permissions for content URIs associated with the {@link DragEvent}. * @param event Drag event * @return The {@link DragAndDropPermissions} object used to control access to the content URIs. * Null if no content URIs are associated with the event or if permissions could not be granted. */ public DragAndDropPermissions requestDragAndDropPermissions(DragEvent event) { DragAndDropPermissions dragAndDropPermissions = DragAndDropPermissions.obtain(event); if (dragAndDropPermissions != null && dragAndDropPermissions.take(getActivityToken())) { return dragAndDropPermissions; } return null; }