private void handleActionUp(MotionEvent event) { if (whichCardOnTouch == -1 || !isTouchOnCard) return; long pressDuration = System.currentTimeMillis() - mPressStartTime; computeVelocity(); if (!isDisplaying && ((event.getY() - firstDownY < 0 && (Math.abs(event.getY() - firstDownY) > mMoveDistanceToTrigger)) || (yVelocity < 0 && Math.abs(yVelocity) > mMinVelocity && Math.abs(yVelocity) > Math.abs(xVelocity)))) { displayCard(whichCardOnTouch); } else if (!isDisplaying && pressDuration < MAX_CLICK_TIME && // means click distance(firstDownX, firstDownY, event.getX(), event.getY()) < MAX_CLICK_DISTANCE) { displayCard(whichCardOnTouch); } else if (!isDisplaying && isDragging && ((event.getY() - firstDownY > 0) || Math.abs(event.getY() - firstDownY) < mMoveDistanceToTrigger)) { hideCard(whichCardOnTouch); } else if (isDisplaying) { float currentY = ViewHelper.getY(getChildAt(mDisplayingCard)); if (currentY < mMarginTop || currentY < (mMarginTop + mMoveDistanceToTrigger)) { ObjectAnimator.ofFloat(getChildAt(mDisplayingCard), "y", currentY, mMarginTop) .setDuration(mDuration) .start(); } else if (currentY > (mMarginTop + mMoveDistanceToTrigger)) { hideCard(mDisplayingCard); } } isTouchOnCard = false; deltaY = 0; isDragging = false; }
private void handleActionMove(MotionEvent event) { if (whichCardOnTouch == -1 || !isTouchOnCard) return; if (supportScrollInView((int) (firstDownY - event.getY()))) return; computeVelocity(); if (Math.abs(yVelocity) < Math.abs(xVelocity)) return; if (!isDragging && Math.abs(event.getY() - firstDownY) > mTouchSlop && Math.abs(event.getX() - firstDownX) < mTouchSlop) { isDragging = true; downY = event.getY(); } if (isDragging) { deltaY = event.getY() - downY; downY = event.getY(); View touchingChildView = getChildAt(whichCardOnTouch); if (!mBoundary) { touchingChildView.offsetTopAndBottom((int) deltaY); } else { float touchingViewY = ViewHelper.getY(touchingChildView); if (touchingViewY + deltaY <= mMarginTop) { touchingChildView.offsetTopAndBottom((int) (mMarginTop - touchingViewY)); } else if (touchingViewY + deltaY >= mTouchingViewOriginY) { touchingChildView.offsetTopAndBottom((int) (mTouchingViewOriginY - touchingViewY)); } else { touchingChildView.offsetTopAndBottom((int) deltaY); } } } }