@Override public boolean onTouchEvent(MotionEvent ev) { final int action = MotionEventCompat.getActionMasked(ev); if (mReturningToStart && action == MotionEvent.ACTION_DOWN) { mReturningToStart = false; } if (!isEnabled() || mReturningToStart || (!isChildScrollToTop() && !isChildScrollToBottom())) { // 如果子View可以滑动,不拦截事件,交给子View处理 return false; } if (isChildScrollToBottom()) { // 上拉加载更多 return handlerPushTouchEvent(ev, action); } else { // 下拉刷新 return handlerPullTouchEvent(ev, action); } }
public boolean onGenericMotionEvent(MotionEvent event) { if (!(this.mLayout == null || this.mLayoutFrozen || (MotionEventCompat.getSource(event) & 2) == 0 || event.getAction() != 8)) { float vScroll; float hScroll; if (this.mLayout.canScrollVertically()) { vScroll = -MotionEventCompat.getAxisValue(event, 9); } else { vScroll = 0.0f; } if (this.mLayout.canScrollHorizontally()) { hScroll = MotionEventCompat.getAxisValue(event, 10); } else { hScroll = 0.0f; } if (!(vScroll == 0.0f && hScroll == 0.0f)) { float scrollFactor = getScrollFactor(); scrollByInternal((int) (hScroll * scrollFactor), (int) (vScroll * scrollFactor), event); } } return false; }
@Override public boolean dispatchTouchEvent(MotionEvent ev) { if (mAutoScrollable) { int action = MotionEventCompat.getActionMasked(ev); if (action == MotionEvent.ACTION_DOWN) { stopScroll(); } else if (ev.getAction() == MotionEvent.ACTION_UP) { resumeScroll(); } this.getParent().requestDisallowInterceptTouchEvent(true); } return super.dispatchTouchEvent(ev); }
@Override public boolean onTouchEvent(@NotNull MotionEvent event) { int action = MotionEventCompat.getActionMasked(event); switch(action) { case (MotionEvent.ACTION_DOWN): case (MotionEvent.ACTION_MOVE): case (MotionEvent.ACTION_UP): int band = Math.max(0, Math.min(mSourcePathPoints.length - 1, (int)(mSourcePathPoints.length * event.getX() / getWidth()))); float value = 30 * (getHeight() - event.getY()) / getHeight(); if (listener != null) listener.OnBandUpdated(band, value); return true; case (MotionEvent.ACTION_CANCEL): return true; case (MotionEvent.ACTION_OUTSIDE): return true; default : return super.onTouchEvent(event); } }
/** * this functions binds the view's touch listener to start the drag via the touch helper... * * @param holder the view holder * @param holder the item */ public static void bindDragHandle(final RecyclerView.ViewHolder holder, final IExtendedDraggable item) { // if necessary, init the drag handle, which will start the drag when touched if (item.getTouchHelper() != null && item.getDragView(holder) != null) { item.getDragView(holder).setOnTouchListener(new View.OnTouchListener() { @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 onTouchEvent(MotionEvent event) { if (event.getAction() == MotionEvent.ACTION_DOWN) { // Selection may be beginning. Sync the TextView with the buffer. refreshTextFromBuffer(); } // Mouse input is treated differently: if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH && MotionEventCompat.getSource(event) == InputDevice.SOURCE_MOUSE) { if (onMouseEvent(event, terminalView.bridge)) { return true; } terminalView.viewPager.setPagingEnabled(true); } else { if (terminalView.onTouchEvent(event)) { return true; } } return super.onTouchEvent(event); }
@Override public boolean onTouchEvent(MotionEvent event) { //Check pointer index to avoid -1 (error) if (MotionEventCompat.findPointerIndex(event, 0) == -1) { return super.onTouchEvent(event); } if (event.getPointerCount() >= 1) { requestDisallowInterceptTouchEvent(true); } else { requestDisallowInterceptTouchEvent(false); } return super.onTouchEvent(event); }
public boolean onTouchEvent(MotionEvent ev) { int action = MotionEventCompat.getActionMasked(ev); if (action == 0) { this.mEatingTouch = false; } if (!this.mEatingTouch) { boolean handled = super.onTouchEvent(ev); if (action == 0 && !handled) { this.mEatingTouch = true; } } if (action == 1 || action == 3) { this.mEatingTouch = false; } return true; }
@Override public boolean onInterceptTouchEvent(MotionEvent ev) { // L.e("call: onInterceptTouchEvent([ev])-> " + ev.getAction()); int action = MotionEventCompat.getActionMasked(ev); if (action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_CANCEL) { onTouchUp(); onTouchEnd(); if (Math.abs(mStartScrollY - getScrollY()) > ViewConfiguration.get(getContext()).getScaledTouchSlop()) { //ev.setAction(MotionEvent.ACTION_CANCEL); return true; } } return super.onInterceptTouchEvent(ev); }
private ViewHolder findSwipedView(MotionEvent motionEvent) { final RecyclerView.LayoutManager lm = mRecyclerView.getLayoutManager(); if (mActivePointerId == ACTIVE_POINTER_ID_NONE) { return null; } final int pointerIndex = MotionEventCompat.findPointerIndex(motionEvent, mActivePointerId); final float dx = MotionEventCompat.getX(motionEvent, pointerIndex) - mInitialTouchX; final float dy = MotionEventCompat.getY(motionEvent, pointerIndex) - mInitialTouchY; final float absDx = Math.abs(dx); final float absDy = Math.abs(dy); if (absDx < mSlop && absDy < mSlop) { return null; } if (absDx > absDy && lm.canScrollHorizontally()) { return null; } else if (absDy > absDx && lm.canScrollVertically()) { return null; } View child = findChildView(motionEvent); if (child == null) { return null; } return mRecyclerView.getChildViewHolder(child); }
public boolean onTouch(View v, MotionEvent event) { boolean z = true; if (!this.mEnabled) { return false; } switch (MotionEventCompat.getActionMasked(event)) { case 0: this.mNeedsCancel = true; this.mAlreadyDelayed = false; break; case 1: case 3: requestStop(); break; case 2: break; } this.mScroller.setTargetVelocity(computeTargetVelocity(0, event.getX(), (float) v.getWidth(), (float) this.mTarget.getWidth()), computeTargetVelocity(1, event.getY(), (float) v.getHeight(), (float) this.mTarget.getHeight())); if (!this.mAnimating && shouldAnimate()) { startAnimating(); } if (!(this.mExclusive && this.mAnimating)) { z = false; } return z; }
@Override public boolean onTouchEvent(CoordinatorLayout parent, V child, MotionEvent event) { if (!child.isShown()) { return false; } int action = MotionEventCompat.getActionMasked(event); if (mState == STATE_DRAGGING && action == MotionEvent.ACTION_DOWN) { return true; } mViewDragHelper.processTouchEvent(event); if (action == MotionEvent.ACTION_DOWN) { reset(); } // The ViewDragHelper tries to capture only the top-most View. We have to explicitly tell it // to capture the bottom sheet in case it is not captured and the touch slop is passed. if (action == MotionEvent.ACTION_MOVE && !mIgnoreEvents) { if (Math.abs(mInitialY - event.getY()) > mViewDragHelper.getTouchSlop()) { mViewDragHelper.captureChildView(child, event.getPointerId(event.getActionIndex())); } } return !mIgnoreEvents; }
private void determineDrag(MotionEvent ev) { final int activePointerId = mActivePointerId; final int pointerIndex = getPointerIndex(ev, activePointerId); if (activePointerId == INVALID_POINTER || pointerIndex == INVALID_POINTER) return; 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 dy = y - mLastMotionY; final float yDiff = Math.abs(dy); if (xDiff > (isMenuOpen()?mTouchSlop/2:mTouchSlop) && xDiff > yDiff && thisSlideAllowed(dx)) { startDrag(); mLastMotionX = x; mLastMotionY = y; setScrollingCacheEnabled(true); // TODO add back in touch slop check } else if (xDiff > mTouchSlop) { mIsUnableToDrag = true; } }
private boolean a(char c) { switch (c) { case '\t': case '\n': case '\f': case '\r': case ' ': case MotionEventCompat.AXIS_GENERIC_13 /*44*/: case ':': case '[': case ']': case '{': case '}': break; case '#': case MotionEventCompat.AXIS_GENERIC_16 /*47*/: case ';': case '=': case '\\': v(); break; default: return true; } return false; }
public boolean onInterceptTouchEvent(CoordinatorLayout parent, V child, MotionEvent event) { switch (MotionEventCompat.getActionMasked(event)) { case 1: case 3: if (this.mIgnoreEvents) { this.mIgnoreEvents = false; return false; } break; default: boolean z; if (parent.isPointInChildBounds(child, (int) event.getX(), (int) event.getY())) { z = false; } else { z = true; } this.mIgnoreEvents = z; break; } if (this.mIgnoreEvents) { return false; } ensureViewDragHelper(parent); return this.mViewDragHelper.shouldInterceptTouchEvent(event); }
@Override public boolean onInterceptTouchEvent(MotionEvent ev) { if (!isEnabled()) { return false; } switch (MotionEventCompat.getActionMasked(ev) & MotionEventCompat.ACTION_MASK) { case MotionEvent.ACTION_CANCEL: case MotionEvent.ACTION_UP: viewDragHelper.cancel(); return false; case MotionEvent.ACTION_DOWN: int index = MotionEventCompat.getActionIndex(ev); activePointerId = MotionEventCompat.getPointerId(ev, index); if (activePointerId == INVALID_VIEW_POINTER) { return false; } break; default: break; } boolean interceptTap = viewDragHelper.isViewUnder(dragView, (int) ev.getX(), (int) ev.getY()); return viewDragHelper.shouldInterceptTouchEvent(ev) || interceptTap; }
@Override public boolean onInterceptTouchEvent(MotionEvent ev) { hasInteractedWithSheet = true; if (isNestedScrolling) { return false; } final int action = MotionEventCompat.getActionMasked(ev); if (action == MotionEvent.ACTION_CANCEL || action == MotionEvent.ACTION_UP) { sheetDragHelper.cancel(); return false; } return isDraggableViewUnder((int) ev.getX(), (int) ev.getY()) && (sheetDragHelper.shouldInterceptTouchEvent(ev)); }
private float getActiveX(MotionEvent ev) { try { return MotionEventCompat.getX(ev, mActivePointerIndex); } catch (Exception e) { return ev.getX(); } }
private float getMotionEventY(MotionEvent ev, int activePointerId) { int index = MotionEventCompat.findPointerIndex(ev, activePointerId); if (index < 0) { return -1.0f; } return MotionEventCompat.getY(ev, index); }
public PhotoViewAttacher(ImageView imageView, boolean zoomable) { mImageView = new WeakReference<>(imageView); imageView.setDrawingCacheEnabled(true); imageView.setOnTouchListener(this); ViewTreeObserver observer = imageView.getViewTreeObserver(); if (null != observer) observer.addOnGlobalLayoutListener(this); // Make sure we using MATRIX Scale Type setImageViewScaleTypeMatrix(imageView); if (imageView.isInEditMode()) { return; } // Create Gesture Detectors... mScaleDragDetector = VersionedGestureDetector.newInstance(imageView.getContext(), this); mGestureDetector = new GestureDetector(imageView.getContext(), new GestureDetector.SimpleOnGestureListener() { // forward long click listener @Override public void onLongPress(MotionEvent e) { if (null != mLongClickListener) { mLongClickListener.onLongClick(getImageView()); } } @Override public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) { if (mSingleFlingListener != null) { if (getScale() > DEFAULT_MIN_SCALE) { return false; } if (MotionEventCompat.getPointerCount(e1) > SINGLE_TOUCH || MotionEventCompat.getPointerCount(e2) > SINGLE_TOUCH) { return false; } return mSingleFlingListener.onFling(e1, e2, velocityX, velocityY); } return false; } }); mGestureDetector.setOnDoubleTapListener(new DefaultOnDoubleTapListener(this)); mBaseRotation = 0.0f; // Finally, update the UI so that we're zoomable setZoomable(zoomable); }
@Override public boolean dispatchTouchEvent(MotionEvent ev) { int actionMasked = MotionEventCompat.getActionMasked(ev); if (actionMasked == MotionEvent.ACTION_DOWN) { isFling = false; fastDownX = ev.getX(); fastDownY = ev.getY(); fastDownTime = ev.getDownTime(); if (enableScroll && isEnabled()) { stopAutoScroll(); } } else if (actionMasked == MotionEvent.ACTION_UP || actionMasked == MotionEvent.ACTION_CANCEL) { if (actionMasked == MotionEvent.ACTION_UP && mOnFastTouchListener != null) { long eventTime = ev.getEventTime(); int dv = 10; if (eventTime - fastDownTime <= OnFastTouchListener.FAST_TIME) { float x = ev.getX(); float y = ev.getY(); if (Math.abs(x - fastDownX) <= dv && Math.abs(y - fastDownY) <= dv) { mOnFastTouchListener.onFastClick(); } } } if (enableScroll && isEnabled()) { startAutoScroll(); } } return super.dispatchTouchEvent(ev); }
private boolean onTouchObserved(MotionEvent srcEvent) { View src = this.mSrc; if (!src.isEnabled()) { return false; } switch (MotionEventCompat.getActionMasked(srcEvent)) { case 0: this.mActivePointerId = srcEvent.getPointerId(0); this.mWasLongPress = false; if (this.mDisallowIntercept == null) { this.mDisallowIntercept = new DisallowIntercept(); } src.postDelayed(this.mDisallowIntercept, (long) this.mTapTimeout); if (this.mTriggerLongPress == null) { this.mTriggerLongPress = new TriggerLongPress(); } src.postDelayed(this.mTriggerLongPress, (long) this.mLongPressTimeout); return false; case 1: case 3: clearCallbacks(); return false; case 2: int activePointerIndex = srcEvent.findPointerIndex(this.mActivePointerId); if (activePointerIndex < 0 || pointInView(src, srcEvent.getX(activePointerIndex), srcEvent.getY(activePointerIndex), this.mScaledTouchSlop)) { return false; } clearCallbacks(); src.getParent().requestDisallowInterceptTouchEvent(true); return true; default: return false; } }
private float getMotionEventY(MotionEvent ev, int activePointerId) { final int index = MotionEventCompat.findPointerIndex(ev, activePointerId); if (index < 0) { return -1; } return MotionEventCompat.getY(ev, index); }
public boolean onInterceptTouchEvent(MotionEvent ev) { MotionEvent cancelEvent = null; int action = MotionEventCompat.getActionMasked(ev); if (action == 0) { resetTouchBehaviors(); } boolean intercepted = performIntercept(ev, 0); if (cancelEvent != null) { cancelEvent.recycle(); } if (action == 1 || action == 3) { resetTouchBehaviors(); } return intercepted; }
@Override public boolean onInterceptTouchEvent(MotionEvent ev) { switch (MotionEventCompat.getActionMasked(ev)) { case MotionEvent.ACTION_DOWN: { mInitialMotionX = ev.getX(); mInitialMotionY = ev.getY(); break; } case MotionEvent.ACTION_MOVE: { final float x = ev.getX(); final float y = ev.getY(); // The user should always be able to "close" the pane, so we only check // for child scrollability if the pane is currently closed. if (mInitialMotionX > mEdgeSlop && !isOpen() && canScroll(this, false, Math.round(x - mInitialMotionX), Math.round(x), Math.round(y))) { // How do we set super.mIsUnableToDrag = true? // send the parent a cancel event MotionEvent cancelEvent = MotionEvent.obtain(ev); cancelEvent.setAction(MotionEvent.ACTION_CANCEL); return super.onInterceptTouchEvent(cancelEvent); } } } return super.onInterceptTouchEvent(ev); }
private void determineDrag(MotionEvent ev) { final int activePointerId = mActivePointerId; final int pointerIndex = getPointerIndex(ev, activePointerId); if (activePointerId == INVALID_POINTER || pointerIndex == INVALID_POINTER) { return; } 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 dy = y - mLastMotionY; final float yDiff = Math.abs(dy); if (xDiff > (isMenuOpen() ? mTouchSlop / 2 : mTouchSlop) && xDiff > yDiff && thisSlideAllowed(dx)) { startDrag(); mLastMotionX = x; mLastMotionY = y; setScrollingCacheEnabled(true); // TODO add back in touch slop check } else if (xDiff > mTouchSlop) { mIsUnableToDrag = true; } }
@Override public boolean onTouchEvent(MotionEvent event) { switch (event.getAction() & MotionEventCompat.ACTION_MASK) { case MotionEvent.ACTION_DOWN: mLastMotionX = mInitialMotionX = event.getX(); mLastMotionY = mInitialMotionY = event.getY(); break; case MotionEvent.ACTION_MOVE: float x = event.getX(); float xDiff = Math.abs(x - mInitialMotionX); float y = event.getY(); float yDiff = Math.abs(y - mInitialMotionY); if (yDiff > mTouchSlop && yDiff * 0.5f > xDiff) {//垂直方向 scrollBy(0, -(int) (y - mLastMotionY + 0.5f)); int distance = y >= mInitialMotionY ? mScrollDownHeight : mScrollUpHeight; if(mScrollListener != null) { float percent = yDiff / distance > 0.99 ? 1 : yDiff / distance; mScrollListener.onScrolling(percent); } } mLastMotionX = event.getX(); mLastMotionY = event.getY(); break; case MotionEvent.ACTION_UP: x = event.getX(); xDiff = Math.abs(x - mInitialMotionX); y = event.getY(); yDiff = Math.abs(y - mInitialMotionY); if (yDiff > mTouchSlop && yDiff * 0.5f > xDiff) {//垂直方向 FlingRunnable runnable = new FlingRunnable(yDiff, y - mInitialMotionY < 0); runnable.start(); } break; } return super.onTouchEvent(event); }
public boolean onInterceptTouchEvent(RecyclerView recyclerView, MotionEvent event) { ItemTouchHelper.this.mGestureDetector.onTouchEvent(event); int action = MotionEventCompat.getActionMasked(event); if (action == 0) { ItemTouchHelper.this.mActivePointerId = MotionEventCompat.getPointerId(event, 0); ItemTouchHelper.this.mInitialTouchX = event.getX(); ItemTouchHelper.this.mInitialTouchY = event.getY(); ItemTouchHelper.this.obtainVelocityTracker(); if (ItemTouchHelper.this.mSelected == null) { RecoverAnimation animation = ItemTouchHelper.this.findAnimation(event); if (animation != null) { ItemTouchHelper itemTouchHelper = ItemTouchHelper.this; itemTouchHelper.mInitialTouchX -= animation.mX; itemTouchHelper = ItemTouchHelper.this; itemTouchHelper.mInitialTouchY -= animation.mY; ItemTouchHelper.this.endRecoverAnimation(animation.mViewHolder, true); if (ItemTouchHelper.this.mPendingCleanup.remove(animation.mViewHolder.itemView)) { ItemTouchHelper.this.mCallback.clearView(ItemTouchHelper.this.mRecyclerView, animation.mViewHolder); } ItemTouchHelper.this.select(animation.mViewHolder, animation.mActionState); ItemTouchHelper.this.updateDxDy(event, ItemTouchHelper.this.mSelectedFlags, 0); } } } else if (action == 3 || action == 1) { ItemTouchHelper.this.mActivePointerId = -1; ItemTouchHelper.this.select(null, 0); } else if (ItemTouchHelper.this.mActivePointerId != -1) { int index = MotionEventCompat.findPointerIndex(event, ItemTouchHelper.this.mActivePointerId); if (index >= 0) { ItemTouchHelper.this.checkSelectForSwipe(action, event, index); } } if (ItemTouchHelper.this.mVelocityTracker != null) { ItemTouchHelper.this.mVelocityTracker.addMovement(event); } if (ItemTouchHelper.this.mSelected != null) { return true; } return false; }
/** * Override method to intercept only touch events over the drag view and to cancel the drag when * the action associated to the MotionEvent is equals to ACTION_CANCEL or ACTION_UP. * * @param ev captured. * @return true if the view is going to process the touch event or false if not. */ @Override public boolean onInterceptTouchEvent(MotionEvent ev) { if (!isEnabled()) { return false; } switch (MotionEventCompat.getActionMasked(ev) & MotionEventCompat.ACTION_MASK) { case MotionEvent.ACTION_CANCEL: case MotionEvent.ACTION_UP: viewDragHelper.cancel(); return false; case MotionEvent.ACTION_DOWN: int index = MotionEventCompat.getActionIndex(ev); activePointerId = MotionEventCompat.getPointerId(ev, index); if (activePointerId == INVALID_POINTER) { return false; } break; default: break; } boolean interceptTap = viewDragHelper.isViewUnder(dragView, (int) ev.getX(), (int) ev.getY()); return viewDragHelper.shouldInterceptTouchEvent(ev) || interceptTap; }
/** * Override method to dispatch touch event to the dragged view. * * @param ev captured. * @return true if the touch event is realized over the drag or second view. */ @Override public boolean onTouchEvent(MotionEvent ev) { int actionMasked = MotionEventCompat.getActionMasked(ev); if ((actionMasked & MotionEventCompat.ACTION_MASK) == MotionEvent.ACTION_DOWN) { activePointerId = MotionEventCompat.getPointerId(ev, actionMasked); } if (activePointerId == INVALID_POINTER) { return false; } viewDragHelper.processTouchEvent(ev); if (isClosed()) { return false; } boolean isDragViewHit = isViewHit(dragView, (int) ev.getX(), (int) ev.getY()); boolean isSecondViewHit = isViewHit(secondView, (int) ev.getX(), (int) ev.getY()); analyzeTouchToMaximizeIfNeeded(ev, isDragViewHit); if (isMaximized()) { dragView.dispatchTouchEvent(ev); } else { dragView.dispatchTouchEvent(cloneMotionEventWithAction(ev, MotionEvent.ACTION_CANCEL)); } return isDragViewHit || isSecondViewHit; }
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; } }
@Override public boolean onTouchEvent(MotionEvent ev) { final int action = MotionEventCompat.getActionMasked(ev); if (isBackToStart && action == MotionEvent.ACTION_DOWN) isBackToStart = false; switch (mType) { case BOTTOM: if (!isEnabled() || isBackToStart || canChildScrollDown() || isRefreshing) { return false; } break; case TOP: default: if (!isEnabled() || isBackToStart || canChildScrollUp() || isRefreshing) { return false; } break; } switch (action) { case MotionEvent.ACTION_DOWN: mActivePointerId = MotionEventCompat.getPointerId(ev, 0); isReady = false; break; case MotionEvent.ACTION_MOVE: if (TouchActionMove(ev)) return false; break; case MotionEventCompat.ACTION_POINTER_DOWN: final int index = MotionEventCompat.getActionIndex(ev); mActivePointerId = MotionEventCompat.getPointerId(ev, index); break; case MotionEventCompat.ACTION_POINTER_UP: onSecondaryPointerUp(ev); break; case MotionEvent.ACTION_UP: case MotionEvent.ACTION_CANCEL: { return TouchActionCancel(ev); } } return true; }
@Override public boolean onTouchEvent(MotionEvent ev) { final int action = ev.getActionMasked(); switch (action) { case MotionEvent.ACTION_DOWN: int index = MotionEventCompat.getActionIndex(ev); mActivePointerId = MotionEventCompat.getPointerId(ev, index); if (mActivePointerId == INVALID_POINTER) break; mLastMotionX = ev.getX(); mLastMotionY = ev.getY(); break; case MotionEvent.ACTION_MOVE: int indexMove = MotionEventCompat.getActionIndex(ev); mActivePointerId = MotionEventCompat.getPointerId(ev, indexMove); if (mActivePointerId == INVALID_POINTER) { } else { final float y = ev.getY(); float dy = y - mLastMotionY; if (checkIsTop() && dy >= 1.0f) { bScrollDown = true; bDraging = true; } else { bScrollDown = false; bDraging = false; } mLastMotionX = y; } break; case MotionEvent.ACTION_UP: mLastMotionY = 0; break; } return super.onTouchEvent(ev); }
@Override public void onLongPress(MotionEvent e) { View child = findChildView(e); if (child != null) { ViewHolder vh = mRecyclerView.getChildViewHolder(child); if (vh != null) { if (!mCallback.hasDragFlag(mRecyclerView, vh)) { return; } int pointerId = MotionEventCompat.getPointerId(e, 0); // Long press is deferred. // Check w/ active pointer id to avoid selecting after motion // event is canceled. if (pointerId == mActivePointerId) { final int index = MotionEventCompat .findPointerIndex(e, mActivePointerId); final float x = MotionEventCompat.getX(e, index); final float y = MotionEventCompat.getY(e, index); mInitialTouchX = x; mInitialTouchY = y; mDx = mDy = 0f; if (DEBUG) { Log.d(TAG, "onlong press: x:" + mInitialTouchX + ",y:" + mInitialTouchY); } if (mCallback.isLongPressDragEnabled()) { select(vh, ACTION_STATE_DRAG); } } } } }
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; mActivePointerId = ev.getPointerId(newPointerIndex); } }