@Override public boolean onTouch(View v, MotionEvent event) { if (MotionEventCompat.getActionMasked(event) == MotionEvent.ACTION_DOWN) { if (item.isDraggable()) item.getTouchHelper().startDrag(holder); } return false; } });
@Override public boolean onTouch(View view, MotionEvent event) { if (MotionEventCompat.getActionMasked(event) == MotionEvent.ACTION_DOWN) { mDragStartListener.onStartDrag(holder); } return 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; }
@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; }