Java Code Examples for android.view.MotionEvent#getRawX()
The following examples show how to use
android.view.MotionEvent#getRawX() .
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: EmotionPickerEditText.java From FlowGeek with GNU General Public License v2.0 | 6 votes |
@SuppressLint("ClickableViewAccessibility") @Override public boolean onTouchEvent(MotionEvent event) { switch (event.getAction()) { case MotionEvent.ACTION_UP: if (mRightListener != null) { Drawable drawableRight = getCompoundDrawables()[DRAWABLE_RIGHT]; event.getY(); if (drawableRight != null && event.getRawX() >= (getRight() - drawableRight.getBounds().width())) { mRightListener.onDrawableRightClick(); return true ; } } break; } return super.onTouchEvent(event); }
Example 2
Source File: OverlayTextView.java From Chimee with MIT License | 6 votes |
@SuppressLint("ClickableViewAccessibility") @Override public boolean onTouchEvent(MotionEvent event) { int action = event.getActionMasked(); switch (action) { case MotionEvent.ACTION_DOWN: dX = getX() - event.getRawX(); dY = getY() - event.getRawY(); if (!hasFocus) { hasFocus = true; showControls(); invalidate(); } return true; case MotionEvent.ACTION_MOVE: moveView(event); return true; case MotionEvent.ACTION_UP: return true; } return super.onTouchEvent(event); }
Example 3
Source File: ZSwipeItem.java From ZListVIew with Apache License 2.0 | 6 votes |
/** * 判断View是否要去处理触摸事件 * * @param v * @param event * @return */ private boolean childNeedHandleTouchEvent(View v, MotionEvent event) { if (v == null) return false; int[] loc = new int[2]; v.getLocationOnScreen(loc); int left = loc[0]; int top = loc[1]; if (event.getRawX() > left && event.getRawX() < left + v.getWidth() && event.getRawY() > top && event.getRawY() < top + v.getHeight()) { return v.onTouchEvent(event); } return false; }
Example 4
Source File: EditTextWithDel.java From stynico with MIT License | 6 votes |
@Override public boolean onTouchEvent(MotionEvent event) { if (imgAble != null && event.getAction() == MotionEvent.ACTION_UP) { //获取点击坐标 int eventX = (int) event.getRawX(); int eventY = (int) event.getRawY(); //Log.e(TAG, "eventX = " + eventX + "; eventY = " + eventY); Rect rect = new Rect(); //获取当前View在屏幕坐标中的可视区域,放到rect getGlobalVisibleRect(rect); //图标的左右位置 rect.left = rect.right - imgAble.getIntrinsicWidth() - dip2px(22); //判断点击位置是否在 图标上面 if (rect.contains(eventX, eventY)) setText(""); } return super.onTouchEvent(event); }
Example 5
Source File: LinphoneTextureViewOverlay.java From linphone-android with GNU General Public License v3.0 | 6 votes |
@Override public boolean onTouchEvent(MotionEvent event) { mX = event.getRawX(); mY = event.getRawY(); switch (event.getAction()) { case MotionEvent.ACTION_DOWN: mTouchX = event.getX(); mTouchY = event.getY(); break; case MotionEvent.ACTION_MOVE: if (mDragEnabled) { updateViewPostion(); } break; case MotionEvent.ACTION_CANCEL: case MotionEvent.ACTION_UP: mTouchX = mTouchY = 0; mDragEnabled = false; break; default: break; } return super.onTouchEvent(event); }
Example 6
Source File: FloatMoveView.java From QSVideoPlayer with Apache License 2.0 | 6 votes |
@Override public boolean onTouchEvent(MotionEvent event) { if (!isBeingDragged) return super.onTouchEvent(event); switch (event.getAction()) { case MotionEvent.ACTION_DOWN: break; case MotionEvent.ACTION_MOVE: final float y = event.getRawY(); final float x = event.getRawX(); moveListener.move((int) (x - mInitialMotionX), (int) (y - mInitialMotionY)); //mInitialMotionY = y; //mInitialMotionX = x; //Log.e("move", // x + "-" + y); break; case MotionEvent.ACTION_UP: case MotionEvent.ACTION_CANCEL: moveListener.end(); } return true; }
Example 7
Source File: DefaultScrollHandle.java From AndroidPdfViewer with Apache License 2.0 | 5 votes |
@Override public boolean onTouchEvent(MotionEvent event) { if (!isPDFViewReady()) { return super.onTouchEvent(event); } switch (event.getAction()) { case MotionEvent.ACTION_DOWN: case MotionEvent.ACTION_POINTER_DOWN: pdfView.stopFling(); handler.removeCallbacks(hidePageScrollerRunnable); if (pdfView.isSwipeVertical()) { currentPos = event.getRawY() - getY(); } else { currentPos = event.getRawX() - getX(); } case MotionEvent.ACTION_MOVE: if (pdfView.isSwipeVertical()) { setPosition(event.getRawY() - currentPos + relativeHandlerMiddle); pdfView.setPositionOffset(relativeHandlerMiddle / (float) getHeight(), false); } else { setPosition(event.getRawX() - currentPos + relativeHandlerMiddle); pdfView.setPositionOffset(relativeHandlerMiddle / (float) getWidth(), false); } return true; case MotionEvent.ACTION_CANCEL: case MotionEvent.ACTION_UP: case MotionEvent.ACTION_POINTER_UP: hideDelayed(); pdfView.performPageSnap(); return true; } return super.onTouchEvent(event); }
Example 8
Source File: DragSortController.java From android-kernel-tweaker with GNU General Public License v3.0 | 5 votes |
public int viewIdHitPosition(MotionEvent ev, int id) { final int x = (int) ev.getX(); final int y = (int) ev.getY(); int touchPos = mDslv.pointToPosition(x, y); // includes headers/footers final int numHeaders = mDslv.getHeaderViewsCount(); final int numFooters = mDslv.getFooterViewsCount(); final int count = mDslv.getCount(); // Log.d("mobeta", "touch down on position " + itemnum); // We're only interested if the touch was on an // item that's not a header or footer. if (touchPos != AdapterView.INVALID_POSITION && touchPos >= numHeaders && touchPos < (count - numFooters)) { final View item = mDslv.getChildAt(touchPos - mDslv.getFirstVisiblePosition()); final int rawX = (int) ev.getRawX(); final int rawY = (int) ev.getRawY(); View dragBox = id == 0 ? item : (View) item.findViewById(id); if (dragBox != null) { dragBox.getLocationOnScreen(mTempLoc); if (rawX > mTempLoc[0] && rawY > mTempLoc[1] && rawX < mTempLoc[0] + dragBox.getWidth() && rawY < mTempLoc[1] + dragBox.getHeight()) { mItemX = item.getLeft(); mItemY = item.getTop(); return touchPos; } } } return MISS; }
Example 9
Source File: DragSortListView.java From biermacht with Apache License 2.0 | 5 votes |
private void saveTouchCoords(MotionEvent ev) { int action = ev.getAction() & MotionEvent.ACTION_MASK; if (action != MotionEvent.ACTION_DOWN) { mLastX = mX; mLastY = mY; } mX = (int) ev.getX(); mY = (int) ev.getY(); if (action == MotionEvent.ACTION_DOWN) { mLastX = mX; mLastY = mY; } mOffsetX = (int) ev.getRawX() - mX; mOffsetY = (int) ev.getRawY() - mY; }
Example 10
Source File: CallFragment.java From owt-client-android with Apache License 2.0 | 5 votes |
@Override public boolean onTouch(View v, MotionEvent event) { if (v.getId() == R.id.small_renderer) { switch (event.getAction()) { case MotionEvent.ACTION_DOWN: dX = v.getX() - event.getRawX(); dY = v.getY() - event.getRawY(); break; case MotionEvent.ACTION_MOVE: v.animate() .x(event.getRawX() + dX) .y(event.getRawY() + dY) .setDuration(0) .start(); break; case MotionEvent.ACTION_UP: v.animate() .x(event.getRawX() + dX >= event.getRawY() + dY ? event.getRawX() + dX : 0) .y(event.getRawX() + dX >= event.getRawY() + dY ? 0 : event.getRawY() + dY) .setDuration(10) .start(); break; } } return true; }
Example 11
Source File: ChannelView.java From ChannelView with Apache License 2.0 | 5 votes |
@Override public boolean onTouch(View v, MotionEvent event) { // //如果点击的是我的频道组中的频道 if (event.getAction() == MotionEvent.ACTION_DOWN) { maxDistanceToDownPosition = 0; downX = dragX = event.getRawX(); downY = dragY = event.getRawY(); if (isEditState) { setTime(v); } } if (isEditState) { if (event.getAction() == MotionEvent.ACTION_MOVE && isAccessDrag) { //手移动时拖动频道 //请求ScrollView不要拦截MOVE事件,交给TextView处理 requestDisallowInterceptTouchEvent(true); if (maxDistanceToDownPosition < maxAccessDrag) { double sqrt = Math.sqrt(Math.pow(event.getRawX() - downX, 2) + Math.pow(event.getRawY() - downY, 2)); if (sqrt > maxDistanceToDownPosition) { maxDistanceToDownPosition = sqrt; } } channelDrag(v, event); } if (event.getAction() == MotionEvent.ACTION_UP || event.getAction() == MotionEvent.ACTION_CANCEL) { if (thread != null && thread.isAlive() && !thread.isInterrupted()) { thread.interrupt(); } if (isAccessDrag) { ChannelAttr vTag = getChannelAttr(v); v.animate().x(vTag.coordinate.x).y(vTag.coordinate.y).setDuration(DURATION_TIME); styleAdapter.setEditStyle(getViewHolder(v)); isAccessDrag = false; return !(maxDistanceToDownPosition < maxAccessDrag); } } } return false; }
Example 12
Source File: SessionActivity.java From LQRWeChat with MIT License | 5 votes |
private boolean isCancelled(View view, MotionEvent event) { int[] location = new int[2]; view.getLocationOnScreen(location); if (event.getRawX() < location[0] || event.getRawX() > location[0] + view.getWidth() || event.getRawY() < location[1] - 40) { return true; } return false; }
Example 13
Source File: ReorderDecoration.java From RecyclerExt with Apache License 2.0 | 5 votes |
/** * This will determine two things. * 1. If we need to handle the touch event * 2. If reordering needs to start due to dragHandle being clicked */ @Override public boolean onInterceptTouchEvent(RecyclerView recyclerView, MotionEvent event) { if (dragState == DragState.DRAGGING) { return true; } if (dragHandleId == INVALID_RESOURCE_ID) { return false; } View itemView = recyclerView.findChildViewUnder(event.getX(), event.getY()); if (itemView == null) { return false; } View handleView = itemView.findViewById(dragHandleId); if (handleView == null || handleView.getVisibility() != View.VISIBLE) { return false; } int[] handlePosition = new int[2]; handleView.getLocationOnScreen(handlePosition); //Determine if the MotionEvent is inside the handle if ((event.getRawX() >= handlePosition[0] && event.getRawX() <= handlePosition[0] + handleView.getWidth()) && (event.getRawY() >= handlePosition[1] && event.getRawY() <= handlePosition[1] + handleView.getHeight())) { startReorder(itemView, event); return true; } return false; }
Example 14
Source File: ContentView.java From NewFastFrame with Apache License 2.0 | 5 votes |
@Override public boolean onInterceptTouchEvent(MotionEvent ev) { // if (ev.getRawX() >= range && getLeft() >= range) { // LogUtil.e("中断"); // } else { // LogUtil.e("不中断"); // } return ev.getRawX() >= range && getLeft() >= range; }
Example 15
Source File: DragScaleCircleView.java From DragScaleCircleView with Apache License 2.0 | 5 votes |
@Override public boolean onTouchEvent(MotionEvent event) { // If this view is not enabled, touch event must return false. if (!isEnabled()) { return false; } int action = event.getAction(); if (action == MotionEvent.ACTION_DOWN) { setHandleMode(HANDLE_DOWN); mLastY = (int) event.getRawY(); mLastX = (int) event.getRawX(); mDragDirection = getDragDirection((int) event.getX(), (int) event.getY()); invalidate(); } else if (action == MotionEvent.ACTION_MOVE) { setHandleMode(HANDLE_MOVE); drag(event, action); invalidate(); } else if (action == MotionEvent.ACTION_UP) { setHandleMode(HANDLE_UP); drag(event, action); invalidate(); } else if (action == MotionEvent.ACTION_CANCEL) { getParent().requestDisallowInterceptTouchEvent(false); } return true; }
Example 16
Source File: TouchUtils.java From AndroidUtilCode with Apache License 2.0 | 5 votes |
public boolean onUtilsMove(View view, MotionEvent event) { int x = (int) event.getRawX(); int y = (int) event.getRawY(); if (downX == -1) { // not receive down should reset resetTouch(x, y); view.setPressed(true); } if (state != STATE_MOVE) { if (Math.abs(x - lastX) < touchSlop && Math.abs(y - lastY) < touchSlop) { return true; } state = STATE_MOVE; if (Math.abs(x - lastX) >= Math.abs(y - lastY)) { if (x - lastX < 0) { direction = LEFT; } else { direction = RIGHT; } } else { if (y - lastY < 0) { direction = UP; } else { direction = DOWN; } } } boolean consumeMove = onMove(view, direction, x, y, x - lastX, y - lastY, x - downX, y - downY, event); lastX = x; lastY = y; return consumeMove; }
Example 17
Source File: ActivityTaskView.java From ActivityTaskView with Apache License 2.0 | 5 votes |
@Override public boolean onTouchEvent(MotionEvent event) { switch (event.getAction()) { case MotionEvent.ACTION_DOWN: downTime = System.currentTimeMillis(); mInnerX = event.getX(); mInnerY = event.getY(); postDelayed(this, 300); break; case MotionEvent.ACTION_MOVE: float x = event.getRawX(); float y = event.getRawY(); WindowManager.LayoutParams params = (WindowManager.LayoutParams) getLayoutParams(); params.x = (int) (x - mInnerX); params.y = (int) (y - mInnerY - mStatusHeight); updateLayout(params); if(Math.abs(event.getX() - mInnerX) > 20 || Math.abs(event.getY() - mInnerY) > 20) { removeCallbacks(this); } break; case MotionEvent.ACTION_UP: removeCallbacks(this); if(System.currentTimeMillis() - downTime < 100 && Math.abs(event.getX() - mInnerX) < 20 && Math.abs(event.getY() - mInnerY) < 20) { doClick(); } moveToBorder(); break; } return true; }
Example 18
Source File: EntityView.java From TelePlus-Android with GNU General Public License v2.0 | 4 votes |
@Override public boolean onTouchEvent(MotionEvent event) { int action = event.getActionMasked(); boolean handled = false; switch (action) { case MotionEvent.ACTION_POINTER_DOWN: case MotionEvent.ACTION_DOWN: { int handle = pointInsideHandle(event.getX(), event.getY()); if (handle != 0) { currentHandle = handle; previousLocationX = event.getRawX(); previousLocationY = event.getRawY(); hasReleased = false; handled = true; } } break; case MotionEvent.ACTION_MOVE: { if (currentHandle == SELECTION_WHOLE_HANDLE) { float x = event.getRawX(); float y = event.getRawY(); handled = onTouchMove(x, y); } else if (currentHandle != 0) { hasTransformed = true; Point translation = new Point(event.getRawX() - previousLocationX, event.getRawY() - previousLocationY); float radAngle = (float) Math.toRadians(getRotation()); float delta = (float) (translation.x * Math.cos(radAngle) + translation.y * Math.sin(radAngle)); if (currentHandle == SELECTION_LEFT_HANDLE) { delta *= -1; } float scaleDelta = 1 + (delta * 2) / getWidth(); scale(scaleDelta); float centerX = getLeft() + getWidth() / 2; float centerY = getTop() + getHeight() / 2; float parentX = event.getRawX() - ((View) getParent()).getLeft(); float parentY = event.getRawY() - ((View) getParent()).getTop() - AndroidUtilities.statusBarHeight; float angle = 0; if (currentHandle == SELECTION_LEFT_HANDLE) { angle = (float) Math.atan2(centerY - parentY, centerX - parentX); } else if (currentHandle == SELECTION_RIGHT_HANDLE) { angle = (float) Math.atan2(parentY - centerY, parentX - centerX); } rotate((float) Math.toDegrees(angle)); previousLocationX = event.getRawX(); previousLocationY = event.getRawY(); handled = true; } } break; case MotionEvent.ACTION_POINTER_UP: case MotionEvent.ACTION_UP: case MotionEvent.ACTION_CANCEL: { onTouchUp(); currentHandle = 0; handled = true; } break; } if (currentHandle == SELECTION_WHOLE_HANDLE) { gestureDetector.onTouchEvent(event); } return handled; }
Example 19
Source File: HandleView.java From android-chromium with BSD 2-Clause "Simplified" License | 4 votes |
@Override public boolean onTouchEvent(MotionEvent ev) { switch (ev.getActionMasked()) { case MotionEvent.ACTION_DOWN: { mDownPositionX = ev.getRawX(); mDownPositionY = ev.getRawY(); mTouchToWindowOffsetX = mDownPositionX - mPositionX; mTouchToWindowOffsetY = mDownPositionY - mPositionY; mIsDragging = true; mController.beforeStartUpdatingPosition(this); mTouchTimer = SystemClock.uptimeMillis(); break; } case MotionEvent.ACTION_MOVE: { updatePosition(ev.getRawX(), ev.getRawY()); break; } case MotionEvent.ACTION_UP: if (mIsInsertionHandle) { long delay = SystemClock.uptimeMillis() - mTouchTimer; if (delay < ViewConfiguration.getTapTimeout()) { if (mPastePopupWindow != null && mPastePopupWindow.isShowing()) { // Tapping on the handle dismisses the displayed paste view, mPastePopupWindow.hide(); } else { showPastePopupWindow(); } } } mIsDragging = false; break; case MotionEvent.ACTION_CANCEL: mIsDragging = false; break; default: return false; } return true; }
Example 20
Source File: ScrollableLayout.java From Scrollable with Apache License 2.0 | 4 votes |
@Override public boolean dispatchTouchEvent(@SuppressWarnings("NullableProblems") MotionEvent event) { if (mSelfUpdateScroll) { mIsTouchOngoing = false; mIsDraggingDraggable = false; mIsScrolling = false; mIsFlinging = false; mOverScrollStarted = false; removeCallbacks(mIdleRunnable); removeCallbacks(mScrollRunnable); return super.dispatchTouchEvent(event); } final int action = event.getActionMasked(); if (action == MotionEvent.ACTION_DOWN) { mIsTouchOngoing = true; mScroller.abortAnimation(); if (mDraggableView != null && mDraggableView.getGlobalVisibleRect(mDraggableRect)) { final int x = (int) (event.getRawX() + .5F); final int y = (int) (event.getRawY() + .5F); mIsDraggingDraggable = mDraggableRect.contains(x, y); } else { mIsDraggingDraggable = false; } } else if (action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_CANCEL){ mIsTouchOngoing = false; if (mCloseUpAlgorithm != null) { removeCallbacks(mIdleRunnable); postDelayed(mIdleRunnable, mConsiderIdleMillis); } // great, now we are able to cancel ghost touch when up event Y == mMaxScrollY if (mEventRedirected) { if (action == MotionEvent.ACTION_UP) { final float diff = Math.abs(event.getRawY() - mEventRedirectStartedY); if (Float.compare(diff, mScaledTouchSlop) < 0) { event.setAction(MotionEvent.ACTION_CANCEL); } } mEventRedirected = false; } cancelOverScroll(); } final boolean isPrevScrolling = mIsScrolling; final boolean isPrevFlinging = mIsFlinging; mIsFlinging = mFlingDetector .onTouchEvent(event); mIsScrolling = mScrollDetector.onTouchEvent(event); removeCallbacks(mScrollRunnable); post(mScrollRunnable); final boolean isIntercepted = mIsScrolling || mIsFlinging; final boolean isPrevIntercepted = isPrevScrolling || isPrevFlinging; final boolean shouldRedirectDownTouch = action == MotionEvent.ACTION_MOVE && (!isIntercepted && isPrevIntercepted) && getScrollY() == mMaxScrollY; if (isIntercepted || isPrevIntercepted) { mMotionEventHook.hook(event, MotionEvent.ACTION_CANCEL); if (!isPrevIntercepted) { return true; } } if (shouldRedirectDownTouch) { mMotionEventHook.hook(event, MotionEvent.ACTION_DOWN); mEventRedirectStartedY = event.getRawY(); mEventRedirected = true; } super.dispatchTouchEvent(event); return true; }