Java Code Examples for android.view.DragEvent#getY()
The following examples show how to use
android.view.DragEvent#getY() .
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: 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 2
Source File: RemoteControlView.java From RemoteControlView with Apache License 2.0 | 5 votes |
/** * 计算控件位置 */ private void compute(int type, Rect rect, DragEvent event){ int size = mPhoneContentWidth / WIDTH_COUNT - dp2px(10); int x = (int) event.getX(); int y = (int) event.getY(); if (type == ONE_BY_ONE_PIC || type == ONE_BY_ONE_TEXT){ // 1 * 1 方格 rect.left = x - size / 2; rect.top = y - size / 2; rect.right = x + size / 2; rect.bottom = y + size / 2; }else if (type == THREE_BY_THREE_PIC){ // 3 * 3 方格 rect.left = x - size * 3 / 2; rect.top = y - size * 3 / 2; rect.right = x + size * 3 / 2; rect.bottom = y + size * 3 / 2; }else if (type == ONE_BY_TWO_PIC){ // 1 * 2 方格 rect.left = x - size / 2; rect.top = y - size; rect.right = x + size / 2; rect.bottom = y + size; } }
Example 3
Source File: DragDriver.java From LaunchEnr with GNU General Public License v3.0 | 5 votes |
@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; } }
Example 4
Source File: MainActivity.java From LaunchTime with GNU General Public License v3.0 | 5 votes |
private void scrollOnDrag(View view, DragEvent event, ScrollView scrollView) { float ty = view.getTop() + event.getY(); if (isAncestor(scrollView, view)) { int thresh = scrollView.getHeight() / 6; if (ty < scrollView.getScrollY() + thresh) { scrollView.smoothScrollBy(0, -10); } else if (ty > scrollView.getScrollY() + scrollView.getHeight() - thresh) { scrollView.smoothScrollBy(0, 10); } } }
Example 5
Source File: RemoteControlView.java From RemoteControlView with Apache License 2.0 | 4 votes |
/** * 调整控件位置 */ private void adjust(int type, Rect rect, DragEvent event){ // 最小单元格宽高 int size = mPhoneContentWidth / WIDTH_COUNT / 2; // 手机屏幕间距 int padding = dp2px(5); // 1 * 1方格宽高 int width = size * 2 - dp2px(10); int offsetX = (rect.left - padding) % size; if (offsetX < size / 2){ rect.left = rect.left + padding - offsetX; }else { rect.left = rect.left + padding - offsetX + size; } int offsetY = (rect.top - padding) % size; if (offsetY < size / 2){ rect.top = rect.top + padding - offsetY; }else { rect.top = rect.top + padding - offsetY + size; } if (type == ONE_BY_ONE_PIC || type == ONE_BY_ONE_TEXT){ rect.right = rect.left + width; rect.bottom = rect.top + width; }else if (type == ONE_BY_TWO_PIC){ rect.top = rect.top + padding; rect.right = rect.left + width; rect.bottom = rect.top + width * 2; }else if (type == THREE_BY_THREE_PIC){ rect.top = rect.top + padding * 2; rect.left = rect.left + padding * 2; rect.right = rect.left + width * 3; rect.bottom = rect.top + width * 3; } //超出部分修正(超出部分) if (rect.right > frameLayout.getWidth() || rect.bottom > frameLayout.getHeight()){ int currentX = (int) event.getX(); int currentY = (int) event.getY(); int centerX = frameLayout.getWidth() / 2; int centerY = frameLayout.getHeight() / 2; if (currentX <= centerX && currentY <= centerY){ //左上角区域 }else if (currentX >= centerX && currentY <= centerY){ //右上角区域 rect.left = rect.left - size; rect.right = rect.right - size; }else if (currentX <= centerX && currentY >= centerY){ //左下角区域 rect.top = rect.top - size; rect.bottom = rect.bottom - size; }else if (currentX >= centerX && currentY >= centerY){ //右下角区域 if (rect.right > frameLayout.getWidth()){ rect.left = rect.left - size; rect.right = rect.right - size; } if (rect.bottom > frameLayout.getHeight()){ rect.top = rect.top - size; rect.bottom = rect.bottom - size; } } } }
Example 6
Source File: PinItemDragListener.java From LaunchEnr with GNU General Public License v3.0 | 4 votes |
private boolean onDragStart(DragEvent event) { if (!mRequest.isValid()) { return false; } ClipDescription desc = event.getClipDescription(); if (desc == null || !desc.hasMimeType(getMimeType())) { return false; } final PendingAddItemInfo item; if (mRequest.getRequestType() == PinItemRequestCompat.REQUEST_TYPE_SHORTCUT) { item = new PendingAddShortcutInfo( new PinShortcutRequestActivityInfo(mRequest, mLauncher)); } else { // mRequest.getRequestType() == PinItemRequestCompat.REQUEST_TYPE_APPWIDGET LauncherAppWidgetProviderInfo providerInfo = LauncherAppWidgetProviderInfo.fromProviderInfo( mLauncher, mRequest.getAppWidgetProviderInfo(mLauncher)); final PinWidgetFlowHandler flowHandler = new PinWidgetFlowHandler(providerInfo, mRequest); item = new PendingAddWidgetInfo(providerInfo) { @Override public WidgetAddFlowHandler getHandler() { return flowHandler; } }; } View view = new View(mLauncher); view.setTag(item); Point downPos = new Point((int) event.getX(), (int) event.getY()); DragOptions options = new DragOptions(); options.systemDndStartPoint = downPos; options.preDragCondition = this; // We use drag event position as the screenPos for the preview image. Since mPreviewRect // already includes the view position relative to the drag event on the source window, // and the absolute position (position relative to the screen) of drag event is same // across windows, using drag position here give a good estimate for relative position // to source window. PendingItemDragHelper dragHelper = new PendingItemDragHelper(view); if (mRequest.getRequestType() == PinItemRequestCompat.REQUEST_TYPE_APPWIDGET) { dragHelper.setPreview(getPreview(mRequest)); } dragHelper.startDrag(new Rect(mPreviewRect), mPreviewBitmapWidth, mPreviewViewWidth, downPos, this, options); mDragStartTime = SystemClock.uptimeMillis(); return true; }
Example 7
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 8
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; }