@Override public boolean onTouch(View v, MotionEvent event) { if (MotionEventCompat.getActionMasked(event) == MotionEvent.ACTION_DOWN) { if (item.isDraggable()) item.getTouchHelper().startDrag(holder); } return false; } });
private void onSecondaryPointerUp(MotionEvent ev) { final int pointerIndex = MotionEventCompat.getActionIndex(ev); final int pointerId = MotionEventCompat.getPointerId(ev, pointerIndex); if (pointerId == mActivePointerId) { // This was our active pointer going up. Choose a new // active pointer and adjust accordingly. final int newPointerIndex = pointerIndex == 0 ? 1 : 0; if (isHorizontal()) { mLastMotionX = MotionEventCompat.getX(ev, newPointerIndex); } else { mLastMotionY = MotionEventCompat.getY(ev, newPointerIndex); } mActivePointerId = MotionEventCompat.getPointerId(ev, newPointerIndex); if (mVelocityTracker != null) { mVelocityTracker.clear(); } } }
mActivePointerId = MotionEventCompat.getPointerId(ev, 0); break; if (!mIsBeingDragged) { final int pointerIndex = MotionEventCompat.findPointerIndex(ev, mActivePointerId); if (pointerIndex == -1) { final float x = MotionEventCompat.getX(ev, pointerIndex); final float xDiff = Math.abs(x - mLastMotionX); final float y = MotionEventCompat.getY(ev, pointerIndex); final float yDiff = Math.abs(y - mLastMotionY); final int activePointerIndex = MotionEventCompat.findPointerIndex( ev, mActivePointerId); final float x = MotionEventCompat.getX(ev, activePointerIndex); needsInvalidate |= performDrag(x, 0); / (ii.widthFactor + marginOffset); final int activePointerIndex = MotionEventCompat.findPointerIndex(ev, mActivePointerId); final float x = MotionEventCompat.getX(ev, activePointerIndex); final int totalDelta = (int) (x - mInitialMotionX); int nextPage = determineTargetPage(currentPage, pageOffset, initialVelocity, final int index = MotionEventCompat.getActionIndex(ev);
@Override public boolean onTouch(View view, MotionEvent event) { if (MotionEventCompat.getActionMasked(event) == MotionEvent.ACTION_DOWN) { mDragStartListener.onStartDrag(holder); } return false; } });
= MotionEventCompat.findPointerIndex(ev, activePointerId); final float x = MotionEventCompat.getX(ev, pointerIndex); final float dx = x - mLastMotionX; final float xDiff = Math.abs(dx); final float y = MotionEventCompat.getY(ev, pointerIndex); final float yDiff = Math.abs(y - mInitialMotionY); mActivePointerId = MotionEventCompat.getPointerId(ev, 0); mIsUnableToDrag = false; = MotionEventCompat.findPointerIndex(ev, activePointerId); final float y = MotionEventCompat.getY(ev, pointerIndex); final float dy = y - mLastMotionY; final float yDiff = Math.abs(dy); final float x = MotionEventCompat.getX(ev, pointerIndex); final float xDiff = Math.abs(x - mInitialMotionX); mActivePointerId = MotionEventCompat.getPointerId(ev, 0); mIsUnableToDrag = false;
private boolean handleMotionEvent(MotionEvent event) { if (mState != STATE_NONE && mState != STATE_STOPPING) { int action = MotionEventCompat.getActionMasked(event); int x = (int) event.getX(); int y = (int) event.getY(); if (mState == STATE_STARTING && (action == MotionEvent.ACTION_DOWN || action == MotionEvent.ACTION_MOVE)) { // Start the drag. startInternal(); mTouchStartX = mTouchCurrentX = x; mTouchStartY = mTouchCurrentY = y; return true; } if (mState != STATE_RECOVERING && action == MotionEvent.ACTION_MOVE) { // Update the drag, the touch event is moving. mTouchCurrentX = x; mTouchCurrentY = y; mRecyclerView.invalidate(); return true; } if (action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_CANCEL) { // Stop the drag, the touch event as ended. stop(); return true; } } return false; }
switch (action) { case MotionEvent.ACTION_DOWN: mActivePointerId = MotionEventCompat.getPointerId(ev, 0); mLastMotionX = ev.getX(); break; final int activePointerIndex = MotionEventCompat.findPointerIndex(ev, mActivePointerId); final float x = MotionEventCompat.getX(ev, activePointerIndex); final float deltaX = x - mLastMotionX; final int index = MotionEventCompat.getActionIndex(ev); mLastMotionX = MotionEventCompat.getX(ev, index); mActivePointerId = MotionEventCompat.getPointerId(ev, index); break; final int pointerIndex = MotionEventCompat.getActionIndex(ev); final int pointerId = MotionEventCompat.getPointerId(ev, pointerIndex); if (pointerId == mActivePointerId) { final int newPointerIndex = pointerIndex == 0 ? 1 : 0; mActivePointerId = MotionEventCompat.getPointerId(ev, newPointerIndex); mLastMotionX = MotionEventCompat.getX(ev, MotionEventCompat.findPointerIndex(ev, mActivePointerId)); break;
@Override public boolean onInterceptTouchEvent(RecyclerView rv, MotionEvent e) { if (!mEnabled) { return false; } // Bail out when onRequestDisallowInterceptTouchEvent is called and the motion event has started. if (mDisallowInterceptTouchEvent) { switch (MotionEventCompat.getActionMasked(e)) { case MotionEvent.ACTION_DOWN: mDisallowInterceptTouchEvent = false; break; // Continue handling since down event should always be handled. case MotionEvent.ACTION_UP: case MotionEvent.ACTION_CANCEL: mDisallowInterceptTouchEvent = false; default: return false; // Exit now as UP, CANCEL, MOVE and other events shouldn't be handled when disallowed. } } // Grab RV reference and current orientation. mRecyclerView = rv; if (rv.getLayoutManager() instanceof LinearLayoutManager) { mOrientation = ((LinearLayoutManager) rv.getLayoutManager()).getOrientation(); } else { throw new IllegalStateException("PinchZoomItemTouchListener only supports LinearLayoutManager"); } // Proxy the call to ScaleGestureDetector. Its onScaleBegin() method sets mIntercept when called. mScaleGestureDetector.onTouchEvent(e); return mIntercept; }