Java Code Examples for android.view.DragEvent#getAction()
The following examples show how to use
android.view.DragEvent#getAction() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CompositorViewHolder.java From 365browser with Apache License 2.0 | 6 votes |
@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; }
Example 2
Source File: DragListenerGridView.java From PlusDemo with Apache License 2.0 | 6 votes |
@Override public boolean onDrag(View v, DragEvent event) { switch (event.getAction()) { case DragEvent.ACTION_DRAG_STARTED: if (event.getLocalState() == v) { v.setVisibility(INVISIBLE); } break; case DragEvent.ACTION_DRAG_ENTERED: System.out.println("draggg"); if (event.getLocalState() != v) { sort(v); } break; case DragEvent.ACTION_DRAG_EXITED: break; case DragEvent.ACTION_DRAG_ENDED: v.setVisibility(VISIBLE); break; } return true; }
Example 3
Source File: CompositorViewHolder.java From AndroidChromium with Apache License 2.0 | 6 votes |
@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; }
Example 4
Source File: PasswordGrid.java From Yahala-Messenger with MIT License | 6 votes |
@Override public boolean onDragEvent(DragEvent event) { if (event.getAction() == DragEvent.ACTION_DRAG_LOCATION) { Point p = new Point((int) event.getX(), (int) event.getY()); if (!roaming) { roaming = true; points.add(p); } else { try { points.set(points.size() - 1, p); } catch (Exception e) { Reset(); FileLog.e("Yahala", e); } } invalidate(); } return true; }
Example 5
Source File: PinItemDragListener.java From LaunchEnr with GNU General Public License v3.0 | 6 votes |
@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); }
Example 6
Source File: PasswordButton.java From Yahala-Messenger with MIT License | 6 votes |
@Override public boolean onDragEvent(DragEvent event) { PasswordStateObject state = (PasswordStateObject) event.getLocalState(); if (event.getAction() == DragEvent.ACTION_DRAG_LOCATION) { if (!state.toString().contains((String) getTag())) { state.append((String) getTag()); ((PasswordListener) getParent()).onPasswordButtonTouched(this); setBackgroundResource(R.drawable.loginbuttonpressed); } } if (event.getAction() == DragEvent.ACTION_DRAG_ENDED) if (state != null) { state.passwordComplete(); } return true; }
Example 7
Source File: LauncherDragListener.java From DistroHopper with GNU General Public License v3.0 | 6 votes |
@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 (ex); exh.show (this.appManager.getContext ()); } return true; }
Example 8
Source File: TextChipsEditView.java From talk-android with MIT License | 6 votes |
/** * 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; }
Example 9
Source File: DragDropTouchDragListener.java From RecyclerViewExtensions with MIT License | 6 votes |
@Override public boolean onDrag(View view, DragEvent event) { switch (event.getAction()) { case DragEvent.ACTION_DRAG_STARTED: intercept = false; startTime = SystemClock.uptimeMillis(); dispatchTouchEvent(view, MotionEvent.ACTION_DOWN, event.getX(), event.getY()); // Return true to receive further events. return true; case DragEvent.ACTION_DRAG_LOCATION: dispatchTouchEvent(view, MotionEvent.ACTION_MOVE, event.getX(), event.getY()); return false; case DragEvent.ACTION_DRAG_ENDED: dispatchTouchEvent(view, MotionEvent.ACTION_UP, event.getX(), event.getY()); return false; default: return false; } }
Example 10
Source File: AppLauncherDragListener.java From DistroHopper with GNU General Public License v3.0 | 5 votes |
@Override public boolean onDrag (View view, DragEvent event) { try { AppLauncher appLauncher = (AppLauncher) view; App app = appLauncher.getApp (); switch (event.getAction ()) { case DragEvent.ACTION_DRAG_ENTERED: appLauncher.animate ().setStartDelay (0).setDuration (120).alpha (0.2F); break; case DragEvent.ACTION_DROP: // Falls through // int oldIndex = Integer.parseInt (event.getClipData ().getDescription ().getLabel ().toString ()); int newIndex = this.appManager.indexOfPinned (app); this.appManager.movePinnedApp (oldIndex, newIndex); this.appManager.refreshPinnedView (); this.appManager.savePinnedApps (); case DragEvent.ACTION_DRAG_ENDED: // Falls through // this.appManager.stoppedDraggingPinnedApp (); case DragEvent.ACTION_DRAG_EXITED: if (Build.VERSION.SDK_INT >= 14) appLauncher.animate ().setStartDelay (0).setDuration (120).alpha (0.9F); else appLauncher.setAlpha (0.9F); break; } } catch (Exception ex) { ExceptionHandler exh = new ExceptionHandler (ex); exh.show (this.appManager.getContext ()); } return true; }
Example 11
Source File: DragActivity.java From codeexamples-android with Eclipse Public License 1.0 | 5 votes |
@Override public boolean onDrag(View v, DragEvent event) { switch (event.getAction()) { case DragEvent.ACTION_DRAG_STARTED: // Do nothing break; case DragEvent.ACTION_DRAG_ENTERED: v.setBackground(enterShape); break; case DragEvent.ACTION_DRAG_EXITED: v.setBackground(normalShape); break; case DragEvent.ACTION_DROP: // view dropped, reassign the view to the new ViewGroup View view = (View) event.getLocalState(); ViewGroup owner = (ViewGroup) view.getParent(); owner.removeView(view); LinearLayout container = (LinearLayout) v; container.addView(view); view.setVisibility(View.VISIBLE); break; case DragEvent.ACTION_DRAG_ENDED: v.setBackground(normalShape); default: break; } return true; }
Example 12
Source File: ImageDragListener.java From android-DragAndDropAcrossApps with Apache License 2.0 | 5 votes |
@Override public boolean onDrag(View view, DragEvent event) { switch (event.getAction()) { case DragEvent.ACTION_DRAG_STARTED: setTargetColor(view, COLOR_ACTIVE); return true; case DragEvent.ACTION_DRAG_ENTERED: setTargetColor(view, COLOR_HOVER); return true; case DragEvent.ACTION_DRAG_LOCATION: processLocation(event.getX(), event.getY()); return true; case DragEvent.ACTION_DRAG_EXITED: setTargetColor(view, COLOR_ACTIVE); return true; case DragEvent.ACTION_DROP: return processDrop(view, event); case DragEvent.ACTION_DRAG_ENDED: setTargetColor(view, COLOR_INACTIVE); return true; default: break; } return false; }
Example 13
Source File: ImageDragListener.java From android-DragAndDropAcrossApps with Apache License 2.0 | 5 votes |
@Override public boolean onDrag(View view, DragEvent event) { // Change the color of the target for all events. // For the drop action, set the view to the dropped image. switch (event.getAction()) { case DragEvent.ACTION_DRAG_STARTED: setTargetColor(view, COLOR_ACTIVE); return true; case DragEvent.ACTION_DRAG_ENTERED: setTargetColor(view, COLOR_HOVER); return true; case DragEvent.ACTION_DRAG_LOCATION: processLocation(event.getX(), event.getY()); return true; case DragEvent.ACTION_DRAG_EXITED: setTargetColor(view, COLOR_ACTIVE); return true; case DragEvent.ACTION_DROP: return processDrop(view, event); case DragEvent.ACTION_DRAG_ENDED: setTargetColor(view, COLOR_INACTIVE); return true; default: break; } return false; }
Example 14
Source File: DragActivity.java From codeexamples-android with Eclipse Public License 1.0 | 5 votes |
@Override public boolean onDrag(View v, DragEvent event) { int action = event.getAction(); switch (event.getAction()) { case DragEvent.ACTION_DRAG_STARTED: // Do nothing break; case DragEvent.ACTION_DRAG_ENTERED: v.setBackgroundDrawable(enterShape); break; case DragEvent.ACTION_DRAG_EXITED: v.setBackgroundDrawable(normalShape); break; case DragEvent.ACTION_DROP: // Dropped, reassign View to ViewGroup View view = (View) event.getLocalState(); ViewGroup owner = (ViewGroup) view.getParent(); // TODO 1 removeView from owner // TODO 2 add to v which is a LinearLayout // TODO 3 set view to View.Visible break; case DragEvent.ACTION_DRAG_ENDED: v.setBackgroundDrawable(normalShape); default: break; } return true; }
Example 15
Source File: DragToCollectLayout.java From PlusDemo with Apache License 2.0 | 5 votes |
@Override public boolean onDrag(View v, DragEvent event) { switch (event.getAction()) { case DragEvent.ACTION_DROP: if (v instanceof LinearLayout) { LinearLayout layout = (LinearLayout) v; TextView textView = new TextView(getContext()); textView.setTextSize(16); textView.setText(event.getClipData().getItemAt(0).getText()); layout.addView(textView); } break; } return true; }
Example 16
Source File: ImageDragListener.java From user-interface-samples with Apache License 2.0 | 5 votes |
@Override public boolean onDrag(View view, DragEvent event) { switch (event.getAction()) { case DragEvent.ACTION_DRAG_STARTED: setTargetColor(view, COLOR_ACTIVE); return true; case DragEvent.ACTION_DRAG_ENTERED: setTargetColor(view, COLOR_HOVER); return true; case DragEvent.ACTION_DRAG_LOCATION: processLocation(event.getX(), event.getY()); return true; case DragEvent.ACTION_DRAG_EXITED: setTargetColor(view, COLOR_ACTIVE); return true; case DragEvent.ACTION_DROP: return processDrop(view, event); case DragEvent.ACTION_DRAG_ENDED: setTargetColor(view, COLOR_INACTIVE); return true; default: break; } return false; }
Example 17
Source File: FeedbackCollectionOnDragListener.java From ssj with GNU General Public License v3.0 | 4 votes |
@Override public boolean onDrag(final View v, DragEvent event) { if (event.getLocalState() instanceof FeedbackComponentView) { final FeedbackComponentView feedbackComponentView = ((FeedbackComponentView) event.getLocalState()); switch (event.getAction()) { case ACTION_DRAG_STARTED: feedbackCollectionActivity.showDragIcons(feedbackComponentView.getWidth(), feedbackComponentView.getHeight()); break; case ACTION_DROP: if (v instanceof FeedbackLevelLayout) { ((FeedbackLevelLayout) v).addGridComponent(feedbackComponentView); } else if (v.equals(feedbackCollectionActivity.getRecycleBin())) { feedbackComponentView.post(new Runnable() { @Override public void run() { ((ViewGroup) feedbackComponentView.getParent()).removeView(feedbackComponentView); feedbackCollectionActivity.requestReorder(); } }); PipelineBuilder.getInstance().remove( feedbackComponentView.getFeedbackLevelBehaviourEntry().getKey() ); } break; case ACTION_DRAG_ENDED: // Set currently draged to false no matter where the drag ended, to force normal painting. feedbackComponentView.setCurrentlyDraged(false); feedbackCollectionActivity.hideDragIcons(); break; } return true; } return false; }
Example 18
Source File: PipeOnDragListener.java From ssj with GNU General Public License v3.0 | 4 votes |
/** * @param v View * @param event DragEvent * @return boolean */ @Override public boolean onDrag(final View v, final DragEvent event) { if (v instanceof PipeView) { final PipeView pipeView = (PipeView) v; switch (event.getAction()) { case DragEvent.ACTION_DRAG_STARTED: { //init values xCoord = 0; yCoord = 0; dropped = false; createRecycleBin(pipeView); break; } case DragEvent.ACTION_DRAG_ENTERED: break; case DragEvent.ACTION_DRAG_EXITED: break; case DragEvent.ACTION_DROP: //update drop location xCoord = event.getX(); yCoord = event.getY(); dropped = true; ComponentView view = (ComponentView) event.getLocalState(); pipeView.getGrid().setGridValue(view.getGridX(), view.getGridY(), false); break; case DragEvent.ACTION_DRAG_ENDED: cleanup(pipeView, event); break; case DragEvent.ACTION_DRAG_LOCATION: { // //@todo add scroll behaviour to drag and drop // HorizontalScrollView horizontalScrollView = (HorizontalScrollView) pipeView.getParent(); // if (horizontalScrollView != null) // { // ScrollView scrollView = (ScrollView) horizontalScrollView.getParent(); // if (scrollView != null) // { // //way one // int y = Math.round(event.getY()); // int translatedY = y - scrollView.getScrollY(); // int threshold = 50; // // make a scrolling up due the y has passed the threshold // if (translatedY < threshold) { // // make a scroll up by 30 px // scrollView.smoothScrollBy(0, -30); // } // // make a autoscrolling down due y has passed the 500 px border // if (translatedY + threshold > 500) { // // make a scroll down by 30 px // scrollView.smoothScrollBy(0, 30); // } // //way two // int topOfDropZone = pipeView.getTop(); // int bottomOfDropZone = pipeView.getBottom(); // int scrollY = scrollView.getScrollY(); // int scrollViewHeight = scrollView.getMeasuredHeight(); // Log.d("location: Scroll Y: " + scrollY + " Scroll Y+Height: " + (scrollY + scrollViewHeight)); // Log.d(" top: " + topOfDropZone + " bottom: " + bottomOfDropZone); // if (bottomOfDropZone > (scrollY + scrollViewHeight - 100)) // { // scrollView.smoothScrollBy(0, 30); // } // if (topOfDropZone < (scrollY + 100)) // { // scrollView.smoothScrollBy(0, -30); // } // } // } break; } default: break; } return true; } return false; }
Example 19
Source File: ViewDragListenerView.java From Android_UE with Apache License 2.0 | 4 votes |
@Override public boolean onDrag(View view, DragEvent dragEvent) { switch (dragEvent.getAction()) { case DragEvent.ACTION_DRAG_STARTED: if (dragEvent.getLocalState() == view) { view.setVisibility(View.INVISIBLE); } // 开始拖拽 Log.e(TAG, "开始拖拽"); break; case DragEvent.ACTION_DRAG_LOCATION: // 主要是感觉是在拖动中就会回调 // Log.e(TAG, "主要是感觉是在拖动中就会回调"); break; case DragEvent.ACTION_DROP: // 向用户已释放拖动阴影的视图发出信号,拖动点位于视图的边界框内,而不在可接受数据的后代视图中。 Log.e(TAG, "向用户已释放拖动阴影的视图发出信号,拖动点位于视图的边界框内,而不在可接受数据的后代视图中。"); break; case DragEvent.ACTION_DRAG_ENDED: // 拖拽已结束 Log.e(TAG, "拖拽已结束"); if (dragEvent.getLocalState() == view) { view.setVisibility(View.VISIBLE); } break; case DragEvent.ACTION_DRAG_ENTERED: // 拖拽的View已经到了其他View的范围,判断点为手指触摸的位置 if (dragEvent.getLocalState() != view) { // 每个View都会收到的,所以要排除掉自己 sortView(view); Log.e(TAG, "拖拽的View已经到了其他View的范围"); } break; case DragEvent.ACTION_DRAG_EXITED: // 移出了当前View的范围,判断点为手指触摸的位置 Log.e(TAG, "移出了当前View的范围"); break; } return true; }
Example 20
Source File: ContentViewCore.java From 365browser with Apache License 2.0 | 4 votes |
/** * @see View#onDragEvent(DragEvent) */ @TargetApi(Build.VERSION_CODES.N) public boolean onDragEvent(DragEvent event) { if (mNativeContentViewCore == 0 || Build.VERSION.SDK_INT <= Build.VERSION_CODES.M) { return false; } ClipDescription clipDescription = event.getClipDescription(); // text/* will match text/uri-list, text/html, text/plain. String[] mimeTypes = clipDescription == null ? new String[0] : clipDescription.filterMimeTypes("text/*"); if (event.getAction() == DragEvent.ACTION_DRAG_STARTED) { // TODO(hush): support dragging more than just text. return mimeTypes != null && mimeTypes.length > 0 && nativeIsTouchDragDropEnabled(mNativeContentViewCore); } StringBuilder content = new StringBuilder(""); if (event.getAction() == DragEvent.ACTION_DROP) { // TODO(hush): obtain dragdrop permissions, when dragging files into Chrome/WebView is // supported. Not necessary to do so for now, because only text dragging is supported. ClipData clipData = event.getClipData(); final int itemCount = clipData.getItemCount(); for (int i = 0; i < itemCount; i++) { ClipData.Item item = clipData.getItemAt(i); content.append(item.coerceToStyledText(mContainerView.getContext())); } } int[] locationOnScreen = new int[2]; mContainerView.getLocationOnScreen(locationOnScreen); float xPix = event.getX() + mCurrentTouchOffsetX; float yPix = event.getY() + mCurrentTouchOffsetY; int xCss = (int) mRenderCoordinates.fromPixToDip(xPix); int yCss = (int) mRenderCoordinates.fromPixToDip(yPix); int screenXCss = (int) mRenderCoordinates.fromPixToDip(xPix + locationOnScreen[0]); int screenYCss = (int) mRenderCoordinates.fromPixToDip(yPix + locationOnScreen[1]); nativeOnDragEvent(mNativeContentViewCore, event.getAction(), xCss, yCss, screenXCss, screenYCss, mimeTypes, content.toString()); return true; }