/** * 监听滑动手势 * * @param e * @return */ @Override public boolean onInterceptTouchEvent(MotionEvent e) { final int action = android.support.v4.view.MotionEventCompat.getActionMasked(e); final int actionIndex = android.support.v4.view.MotionEventCompat.getActionIndex(e); switch (action) { case MotionEvent.ACTION_DOWN: { mActivePointerId = android.support.v4.view.MotionEventCompat.getPointerId(e, 0); mLastTouchX = (int) (android.support.v4.view.MotionEventCompat.getX(e, actionIndex) + 0.5f); mLastTouchY = (int) (android.support.v4.view.MotionEventCompat.getY(e, actionIndex) + 0.5f); } break; case MotionEvent.ACTION_POINTER_DOWN: { mActivePointerId = android.support.v4.view.MotionEventCompat.getPointerId(e, actionIndex); mLastTouchX = (int) (android.support.v4.view.MotionEventCompat.getX(e, actionIndex) + 0.5f); mLastTouchY = (int) (android.support.v4.view.MotionEventCompat.getY(e, actionIndex) + 0.5f); } break; case android.support.v4.view.MotionEventCompat.ACTION_POINTER_UP: { onPointerUp(e); } break; } return super.onInterceptTouchEvent(e); }
private float getMotionEventY(MotionEvent ev, int activePointerId) { final int index = MotionEventCompat.findPointerIndex(ev, activePointerId); if (index < 0) { return -1; } return MotionEventCompat.getY(ev, index); }
private void saveLastMotion(MotionEvent ev) { final int pointerCount = MotionEventCompat.getPointerCount(ev); for (int i = 0; i < pointerCount; i++) { final int pointerId = MotionEventCompat.getPointerId(ev, i); final float x = MotionEventCompat.getX(ev, i); final float y = MotionEventCompat.getY(ev, i); mLastMotionX[pointerId] = x; mLastMotionY[pointerId] = y; } }
private void onSecondaryPointerUp(MotionEvent ev) { 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); } }
@Override public void onBindViewHolder(final ItemViewHolder holder, int position) { holder.textView.setText(mItems.get(position)); holder.handleView.setOnTouchListener((v, event) -> { if (MotionEventCompat.getActionMasked(event) == MotionEvent.ACTION_DOWN) mItemTouchHelper.startDrag(holder); return false; }); }
@Override public boolean onInterceptTouchEvent(MotionEvent ev) { final int action = MotionEventCompat.getActionMasked(ev); mActivePointerId = MotionEventCompat.getPointerId(ev, 0); final float initialMotionY = getMotionEventY(ev, mActivePointerId); if (initialMotionY == -1) {
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; mLastMotionX = MotionEventCompat.getX(ev, newPointerIndex); mActivePointerId = MotionEventCompat.getPointerId(ev, newPointerIndex); if (mVelocityTracker != null) { mVelocityTracker.clear(); } } }
@Override public boolean onTouchEvent(MotionEvent event) { final int action = MotionEventCompat.getActionMasked(event); mActivePointerId = MotionEventCompat.getPointerId(event, 0); return true; final int pointerIndex = MotionEventCompat.getActionIndex(event); final int pointerId = MotionEventCompat.getPointerId(event, pointerIndex); if (pointerId != INVALID_POINTER) { mActivePointerId = pointerId;
private float getMotionEventX(MotionEvent event, int activePointId) { final int index = MotionEventCompat.findPointerIndex(event, activePointId); if (index < 0) { return INVALID_COORDINATE; } return MotionEventCompat.getX(event, index); }
private void onSecondaryPointerUp(MotionEvent ev) { final int pointerIndex = MotionEventCompat.getActionIndex(ev); final int pointerId = ev.getPointerId(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; mLastMotionX = ev.getX(newPointerIndex); mActivePointerId = ev.getPointerId(newPointerIndex); if (mVelocityTracker != null) { mVelocityTracker.clear(); } } }
private int getMotionEventY(MotionEvent e, int pointerIndex) { return (int) (android.support.v4.view.MotionEventCompat.getY(e, pointerIndex) + 0.5f); }
private int getMotionEventX(MotionEvent e, int pointerIndex) { return (int) (android.support.v4.view.MotionEventCompat.getX(e, pointerIndex) + 0.5f); }
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(); } } }
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; mActivePointerId = MotionEventCompat.getPointerId(ev, newPointerIndex); } }
@Override public boolean dispatchTouchEvent(MotionEvent ev) { final int action = MotionEventCompat.getActionMasked(ev); switch (action) { case MotionEvent.ACTION_UP: case MotionEvent.ACTION_CANCEL: // support compile sdk version < 23 onStopNestedScroll(this); break; default: break; } return super.dispatchTouchEvent(ev); }
ensureTarget(); final int action = MotionEventCompat.getActionMasked(ev); if (mReturningToStart && action == MotionEvent.ACTION_DOWN) { mReturningToStart = false; case MotionEvent.ACTION_DOWN: setTargetOffsetTopAndBottom(mOriginalOffsetTop - mCircleView.getTop(), true); mActivePointerId = MotionEventCompat.getPointerId(ev, 0); mIsBeingDragged = false; final float initialDownY = getMotionEventY(ev, mActivePointerId);
final int index = MotionEventCompat.getActionIndex(ev); final float x = ev.getX(index); mLastMotionX = x;
private void saveLastMotion(MotionEvent ev) { final int pointerCount = MotionEventCompat.getPointerCount(ev); for (int i = 0; i < pointerCount; i++) { final int pointerId = MotionEventCompat.getPointerId(ev, i); final float x = MotionEventCompat.getX(ev, i); final float y = MotionEventCompat.getY(ev, i); // Sometimes we can try and save last motion for a pointer never recorded in initial motion. In this case we just discard it. if (mLastMotionX != null && mLastMotionY != null && mLastMotionX.length > pointerId && mLastMotionY.length > pointerId) { mLastMotionX[pointerId] = x; mLastMotionY[pointerId] = y; } } }
/** * on not active finger up * * @param ev */ 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; mActivePointerId = MotionEventCompat.getPointerId(ev, newPointerIndex); } }
@Override public boolean dispatchTouchEvent(MotionEvent ev) { final int action = MotionEventCompat.getActionMasked(ev); switch (action) { case MotionEvent.ACTION_CANCEL: case MotionEvent.ACTION_UP: // swipeToRefresh -> finger up -> finger down if the status is still swipeToRefresh // in onInterceptTouchEvent ACTION_DOWN event will stop the scroller // if the event pass to the child view while ACTION_MOVE(condition is false) // in onInterceptTouchEvent ACTION_MOVE the ACTION_UP or ACTION_CANCEL will not be // passed to onInterceptTouchEvent and onTouchEvent. Instead It will be passed to // child view's onTouchEvent. So we must deal this situation in dispatchTouchEvent onActivePointerUp(); break; } return super.dispatchTouchEvent(ev); }