Java Code Examples for android.view.VelocityTracker#getYVelocity()

The following examples show how to use android.view.VelocityTracker#getYVelocity() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Utils.java    From JNChartDemo with Apache License 2.0 6 votes vote down vote up
public static void velocityTrackerPointerUpCleanUpIfNecessary(MotionEvent ev,
                                                              VelocityTracker tracker) {

    // Check the dot product of current velocities.
    // If the pointer that left was opposing another velocity vector, clear.
    tracker.computeCurrentVelocity(1000, mMaximumFlingVelocity);
    final int upIndex = ev.getActionIndex();
    final int id1 = ev.getPointerId(upIndex);
    final float x1 = tracker.getXVelocity(id1);
    final float y1 = tracker.getYVelocity(id1);
    for (int i = 0, count = ev.getPointerCount(); i < count; i++) {
        if (i == upIndex)
            continue;

        final int id2 = ev.getPointerId(i);
        final float x = x1 * tracker.getXVelocity(id2);
        final float y = y1 * tracker.getYVelocity(id2);

        final float dot = x + y;
        if (dot < 0) {
            tracker.clear();
            break;
        }
    }
}
 
Example 2
Source File: Utils.java    From iMoney with Apache License 2.0 6 votes vote down vote up
public static void velocityTrackerPointerUpCleanUpIfNecessary(MotionEvent ev,
        VelocityTracker tracker) {

    // Check the dot product of current velocities.
    // If the pointer that left was opposing another velocity vector, clear.
    tracker.computeCurrentVelocity(1000, mMaximumFlingVelocity);
    final int upIndex = ev.getActionIndex();
    final int id1 = ev.getPointerId(upIndex);
    final float x1 = tracker.getXVelocity(id1);
    final float y1 = tracker.getYVelocity(id1);
    for (int i = 0, count = ev.getPointerCount(); i < count; i++) {
        if (i == upIndex)
            continue;

        final int id2 = ev.getPointerId(i);
        final float x = x1 * tracker.getXVelocity(id2);
        final float y = y1 * tracker.getYVelocity(id2);

        final float dot = x + y;
        if (dot < 0) {
            tracker.clear();
            break;
        }
    }
}
 
Example 3
Source File: Utils.java    From Ticket-Analysis with MIT License 6 votes vote down vote up
public static void velocityTrackerPointerUpCleanUpIfNecessary(MotionEvent ev,
                                                              VelocityTracker tracker) {

    // Check the dot product of current velocities.
    // If the pointer that left was opposing another velocity vector, clear.
    tracker.computeCurrentVelocity(1000, mMaximumFlingVelocity);
    final int upIndex = ev.getActionIndex();
    final int id1 = ev.getPointerId(upIndex);
    final float x1 = tracker.getXVelocity(id1);
    final float y1 = tracker.getYVelocity(id1);
    for (int i = 0, count = ev.getPointerCount(); i < count; i++) {
        if (i == upIndex)
            continue;

        final int id2 = ev.getPointerId(i);
        final float x = x1 * tracker.getXVelocity(id2);
        final float y = y1 * tracker.getYVelocity(id2);

        final float dot = x + y;
        if (dot < 0) {
            tracker.clear();
            break;
        }
    }
}
 
Example 4
Source File: JellyViewPager.java    From Conquer with Apache License 2.0 5 votes vote down vote up
@Override
public boolean onInterceptTouchEvent(MotionEvent event) {
	if (vTracker == null) {
		vTracker = VelocityTracker.obtain();
	}
	vTracker.addMovement(event);
	float currentY = event.getY();
	switch (event.getAction()) {
		case MotionEvent.ACTION_DOWN:
			downY = event.getY();
			downX = event.getX();
			resetSpring();
			break;
		case MotionEvent.ACTION_MOVE:
			float distance = Math.abs(currentY - downY);
			if (distance > mTouchSlop) {
				// 拦截,不向下传递
				return true;
			}
			break;
		case MotionEvent.ACTION_CANCEL:
		case MotionEvent.ACTION_UP:
			final VelocityTracker tracker = vTracker;
			tracker.computeCurrentVelocity(UNIT);
			float velocityY = tracker.getYVelocity();
			if (vTracker != null) {
				vTracker.recycle();
				vTracker = null;
			}
			if (velocityY > FLING_VELOCITY) {
				// 拦截,不向下传递
				return true;
			}
			break;
	}
	return false;
}
 
Example 5
Source File: DraggableDrawer.java    From WayHoo with Apache License 2.0 5 votes vote down vote up
protected float getYVelocity(VelocityTracker velocityTracker) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.FROYO) {
        return velocityTracker.getYVelocity(mActivePointerId);
    }

    return velocityTracker.getYVelocity();
}
 
Example 6
Source File: DraggableSwipeBack.java    From SwipeBack with Apache License 2.0 5 votes vote down vote up
protected float getYVelocity(VelocityTracker velocityTracker) {
	if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.FROYO) {
		return velocityTracker.getYVelocity(mActivePointerId);
	}

	return velocityTracker.getYVelocity();
}
 
Example 7
Source File: NumberPickerView.java    From SmartChart with Apache License 2.0 4 votes vote down vote up
@Override
public boolean onTouchEvent(MotionEvent event) {
    if(mItemHeight == 0) return true;

    if (mVelocityTracker == null) {
        mVelocityTracker = VelocityTracker.obtain();
    }
    mVelocityTracker.addMovement(event);
    currY = event.getY();

    switch(event.getAction()){
        case MotionEvent.ACTION_DOWN:
            mFlagMayPress = true;
            mHandlerInNewThread.removeMessages(HANDLER_WHAT_REFRESH);
            stopScrolling();
            downY = currY;
            downYGlobal = mCurrDrawGlobalY;
            onScrollStateChange(OnScrollListener.SCROLL_STATE_IDLE);
            getParent().requestDisallowInterceptTouchEvent(true);
            break;
        case MotionEvent.ACTION_MOVE:
            float spanY = downY - currY;

            if(mFlagMayPress && (-mScaledTouchSlop < spanY && spanY < mScaledTouchSlop)){

            }else{
                mFlagMayPress = false;
                mCurrDrawGlobalY = limitY((int)(downYGlobal + spanY));
                calculateFirstItemParameterByGlobalY();
                invalidate();
            }
            onScrollStateChange(OnScrollListener.SCROLL_STATE_TOUCH_SCROLL);
            break;
        case MotionEvent.ACTION_UP:
            if(mFlagMayPress){
                click(event);
            }else {
                final VelocityTracker velocityTracker = mVelocityTracker;
                velocityTracker.computeCurrentVelocity(1000);
                int velocityY = (int) (velocityTracker.getYVelocity() * mFriction);
                if (Math.abs(velocityY) > mMiniVelocityFling) {
                    mScroller.fling(0, mCurrDrawGlobalY, 0, -velocityY,
                            Integer.MIN_VALUE, Integer.MAX_VALUE, limitY(Integer.MIN_VALUE), limitY(Integer.MAX_VALUE));
                    invalidate();
                    onScrollStateChange(OnScrollListener.SCROLL_STATE_FLING);
                }
                mHandlerInNewThread.sendMessageDelayed(getMsg(HANDLER_WHAT_REFRESH), 0);
                releaseVelocityTracker();
            }
            break;
        case MotionEvent.ACTION_CANCEL:
            downYGlobal = mCurrDrawGlobalY;
            stopScrolling();
            mHandlerInNewThread.sendMessageDelayed(getMsg(HANDLER_WHAT_REFRESH), 0);
            break;
    }
    return true ;
}
 
Example 8
Source File: VelocityTrackerCompatHoneycomb.java    From V.FlyoutTest with MIT License 4 votes vote down vote up
public static float getYVelocity(VelocityTracker tracker, int pointerId) {
    return tracker.getYVelocity(pointerId);
}
 
Example 9
Source File: SlidingDrawer.java    From flickr-uploader with GNU General Public License v2.0 4 votes vote down vote up
@Override
public boolean onTouchEvent(MotionEvent event) {
	if (mLocked) {
		return true;
	}

	if (mTracking) {
		mVelocityTracker.addMovement(event);
		final int action = event.getAction();
		switch (action) {
		case MotionEvent.ACTION_MOVE:
			moveHandle((int) (event.getY()));
			break;
		case MotionEvent.ACTION_UP:
		case MotionEvent.ACTION_CANCEL: {
			final VelocityTracker velocityTracker = mVelocityTracker;
			velocityTracker.computeCurrentVelocity(mVelocityUnits);

			float yVelocity = velocityTracker.getYVelocity();
			float xVelocity = velocityTracker.getXVelocity();
			boolean negative;

			negative = yVelocity < 0;
			if (xVelocity < 0) {
				xVelocity = -xVelocity;
			}
			if (xVelocity > mMaximumMinorVelocity) {
				xVelocity = mMaximumMinorVelocity;
			}

			float velocity = (float) Math.hypot(xVelocity, yVelocity);
			if (negative) {
				velocity = -velocity;
			}

			final int top = mHandle.getTop();

			if (Math.abs(velocity) < mMaximumTapVelocity) {
				if ((mExpanded && top < mTapThreshold + mTopOffset) || (!mExpanded && top > mBottomOffset + getBottom() - getTop() - mHandleHeight - mTapThreshold)) {

					if (mAllowSingleTap) {
						playSoundEffect(SoundEffectConstants.CLICK);

						if (mExpanded) {
							animateClose(top);
						} else {
							animateOpen(top);
						}
					} else {
						performFling(top, velocity, false);
					}

				} else {
					performFling(top, velocity, false);
				}
			} else {
				performFling(top, velocity, false);
			}
		}
			break;
		}
	}

	return mTracking || mAnimating || super.onTouchEvent(event);
}
 
Example 10
Source File: MultipleOrientationSlidingDrawer.java    From NYU-BusTracker-Android with Apache License 2.0 4 votes vote down vote up
@Override
public boolean onTouchEvent(MotionEvent event) {
    if (mLocked) {
        return true;
    }

    if (mTracking) {
        mVelocityTracker.addMovement(event);
        final int action = event.getAction();
        switch (action) {
            case MotionEvent.ACTION_MOVE:
                moveHandle((int) (mVertical ? event.getY() : event.getX()) - mTouchDelta);
                break;
            case MotionEvent.ACTION_UP:
            case MotionEvent.ACTION_CANCEL: {
                final VelocityTracker velocityTracker = mVelocityTracker;
                velocityTracker.computeCurrentVelocity(mVelocityUnits);

                float yVelocity = velocityTracker.getYVelocity();
                float xVelocity = velocityTracker.getXVelocity();
                boolean negative;

                final boolean vertical = mVertical;
                if (vertical) {
                    negative = yVelocity < 0;
                    if (xVelocity < 0) {
                        xVelocity = -xVelocity;
                    }
                    if (xVelocity > mMaximumMinorVelocity) {
                        xVelocity = mMaximumMinorVelocity;
                    }
                } else {
                    negative = xVelocity < 0;
                    if (yVelocity < 0) {
                        yVelocity = -yVelocity;
                    }
                    if (yVelocity > mMaximumMinorVelocity) {
                        yVelocity = mMaximumMinorVelocity;
                    }
                }

                float velocity = (float) Math.hypot(xVelocity, yVelocity);
                if (negative) {
                    velocity = -velocity;
                }

                final int top = mHandle.getTop();
                final int left = mHandle.getLeft();

                if (Math.abs(velocity) < mMaximumTapVelocity) {

                    if (inThreshold(top, left)) {
                        if (mAllowSingleTap) {
                            playSoundEffect(SoundEffectConstants.CLICK);

                            if (mExpanded) {
                                //animateClose(vertical ? top : left);
                                animateClose(getSide());
                            } else {
                                animateOpen(getSide());
                                //animateOpen(vertical ? top : left);
                            }
                        } else {
                            performFling(vertical ? top : left, velocity, false);
                        }

                    } else {
                        performFling(vertical ? top : left, velocity, false);
                    }
                } else {
                    performFling(vertical ? top : left, velocity, false);
                }
            }
            break;
        }
    }

    return mTracking || mAnimating || super.onTouchEvent(event);
}
 
Example 11
Source File: SwipeHelper.java    From HeadsUp with GNU General Public License v2.0 4 votes vote down vote up
private float getVelocity(VelocityTracker vt) {
    return mSwipeDirection == X ? vt.getXVelocity() :
            vt.getYVelocity();
}
 
Example 12
Source File: VelocityTrackerCompat.java    From adt-leanback-support with Apache License 2.0 4 votes vote down vote up
@Override
public float getYVelocity(VelocityTracker tracker, int pointerId) {
    return tracker.getYVelocity();
}
 
Example 13
Source File: VelocityTrackerCompat.java    From guideshow with MIT License 4 votes vote down vote up
@Override
public float getYVelocity(VelocityTracker tracker, int pointerId) {
    return tracker.getYVelocity();
}
 
Example 14
Source File: VelocityTrackerCompatHoneycomb.java    From guideshow with MIT License 4 votes vote down vote up
public static float getYVelocity(VelocityTracker tracker, int pointerId) {
    return tracker.getYVelocity(pointerId);
}
 
Example 15
Source File: VelocityTrackerCompat.java    From CodenameOne with GNU General Public License v2.0 4 votes vote down vote up
@Override
public float getYVelocity(VelocityTracker tracker, int pointerId) {
    return tracker.getYVelocity();
}
 
Example 16
Source File: KlyphSlidingDrawer.java    From Klyph with MIT License 4 votes vote down vote up
@Override
public boolean  onTouchEvent(MotionEvent event) {
    if (mLocked) {
        return true;
    }

    if (mTracking) {
        mVelocityTracker.addMovement(event);
        final int action = event.getAction();
        switch (action) {
            case MotionEvent.ACTION_MOVE:
                moveHandle((int) (mVertical ? event.getY() : event.getX()) - mTouchDelta);
                break;
            case MotionEvent.ACTION_UP:
            case MotionEvent.ACTION_CANCEL: {
                final VelocityTracker velocityTracker = mVelocityTracker;
                velocityTracker.computeCurrentVelocity(mVelocityUnits);

                float yVelocity = velocityTracker.getYVelocity();
                float xVelocity = velocityTracker.getXVelocity();
                boolean  negative;

                final boolean  vertical = mVertical;
                if (vertical) {
                    negative = yVelocity < 0;
                    if (xVelocity < 0) {
                        xVelocity = -xVelocity;
                    }
                    if (xVelocity > mMaximumMinorVelocity) {
                        xVelocity = mMaximumMinorVelocity;
                    }
                } else {
                    negative = xVelocity < 0;
                    if (yVelocity < 0) {
                        yVelocity = -yVelocity;
                    }
                    if (yVelocity > mMaximumMinorVelocity) {
                        yVelocity = mMaximumMinorVelocity;
                    }
                }

                float velocity = (float) Math.hypot(xVelocity, yVelocity);
                if (negative) {
                    velocity = -velocity;
                }

                final int top = mHandle.getTop();
                final int left = mHandle.getLeft();

                if (Math.abs(velocity) < mMaximumTapVelocity) {
                    if (vertical ? (mExpanded && top < mTapThreshold + mTopOffset) ||
                            (!mExpanded && top > mBottomOffset + getBottom() - getTop() -
                                    mHandleHeight - mTapThreshold) :
                            (mExpanded && left < mTapThreshold + mTopOffset) ||
                            (!mExpanded && left > mBottomOffset + getRight() - getLeft() -
                                    mHandleWidth - mTapThreshold)) {

                        if (mAllowSingleTap) {
                            playSoundEffect(SoundEffectConstants.CLICK);

                            if (mExpanded) {
                                animateClose(vertical ? top : left);
                            } else {
                                animateOpen(vertical ? top : left);
                            }
                        } else {
                            performFling(vertical ? top : left, velocity, false);
                        }

                    } else {
                        performFling(vertical ? top : left, velocity, false);
                    }
                } else {
                    performFling(vertical ? top : left, velocity, false);
                }
            }
            break;
        }
    }

    return mTracking || mAnimating || super.onTouchEvent(event);
}
 
Example 17
Source File: WheelView.java    From WheelViewDemo with Apache License 2.0 4 votes vote down vote up
@Override
public boolean onTouchEvent(MotionEvent event) {
    if (isEmpty())
        return super.onTouchEvent(event);

    initVelocityTrackerIfNotExists();
    switch (event.getAction()) {
        case MotionEvent.ACTION_DOWN:
            //add event into velocity tracker.
            mVelocityTracker.clear();

            //stop fling and reset fling direction
            flingDirection = 0;
            mOverScroller.forceFinished(true);

            if (animator != null && animator.isRunning()) {
                isAnimatorCanceledForwardly = true;
                animator.cancel();
            }
            lastX = event.getX();
            lastY = event.getY();

            //Make it as a click event when touch down,
            //and record touch down time stamp.
            touchDownTimeStamp = System.currentTimeMillis();
            break;
        case MotionEvent.ACTION_MOVE:
            //add event into velocity tracker and compute velocity.
            mVelocityTracker.addMovement(event);

            float currentX = event.getX();
            float currentY = event.getY();
            int distance = (int) (currentY - lastY);

            int direction = 0;
            if (distance == 0)
                break;

            //if moved, cancel click event
            touchDownTimeStamp = 0;
            direction = distance / Math.abs(distance);

            //initialize touch area
            rectF.set(0, 0, getWidth(), getHeight());
            if (rectF.contains(currentX, currentY)) {
                //inside touch area, execute move event.
                lastX = currentX;
                lastY = currentY;
                updateByTotalMoveY(totalMoveY + distance, direction);
            }
            break;
        case MotionEvent.ACTION_UP:
        case MotionEvent.ACTION_CANCEL:
            if (System.currentTimeMillis() - touchDownTimeStamp <= CLICK_EVENT_INTERNAL_TIME) {
                //it's a click event, do it
                executeClickEvent(event.getX(), event.getY());
                break;
            }

            //calculate current velocity
            final VelocityTracker velocityTracker = mVelocityTracker;
            velocityTracker.computeCurrentVelocity(velocityUnits, mMaximumVelocity);
            float currentVelocity = velocityTracker.getYVelocity();
            recycleVelocityTracker();

            final int tempFlingDirection = currentVelocity == 0 ? 0 : (currentVelocity < 0 ? -1 : 1);
            if (Math.abs(currentVelocity) >= mMinimumVelocity) {
                //it's a fling event.
                flingDirection = tempFlingDirection;
                mOverScroller.fling(
                        0, totalMoveY,
                        0, (int) currentVelocity,
                        0, 0,
                        -(getItemCount() + showCount / 2) * itemHeight, (showCount / 2) * itemHeight,
                        0, 0
                );
                invalidate();
            } else {
                calculateSelectedIndex(totalMoveY, tempFlingDirection);
                selectedIndex = calculateResult[0];
                offsetY = calculateResult[1];
                //execute rebound animation
                executeAnimation(
                        totalMoveY,
                        0 - selectedIndex * itemHeight
                );
            }
            break;

    }
    return true;
}
 
Example 18
Source File: ZrcAbsListView.java    From AndroidStudyDemo with GNU General Public License v2.0 4 votes vote down vote up
private void onTouchUp(MotionEvent ev) {
    switch (mTouchMode) {
    case TOUCH_MODE_DOWN:
    case TOUCH_MODE_TAP:
    case TOUCH_MODE_DONE_WAITING:
        final int motionPosition = mMotionPosition;
        final View child =
                getChildCount() == 0 ? null : getChildAt(motionPosition - mFirstPosition);
        if (child != null) {
            if (mTouchMode != TOUCH_MODE_DOWN) {
                child.setPressed(false);
            }
            final float x = ev.getX();
            final boolean inList = x > mListPadding.left && x < getWidth() - mListPadding.right;
            if (inList && !child.hasFocusable()) {
                if (mPerformClick == null) {
                    mPerformClick = new PerformClick();
                }
                final PerformClick performClick = mPerformClick;
                performClick.mClickMotionPosition = motionPosition;
                performClick.rememberWindowAttachCount();
                if (mTouchMode == TOUCH_MODE_DOWN || mTouchMode == TOUCH_MODE_TAP) {
                    mLayoutMode = LAYOUT_NORMAL;
                    if (!mDataChanged && mAdapter.isEnabled(motionPosition)) {
                        mTouchMode = TOUCH_MODE_TAP;
                        child.setPressed(true);
                        positionSelector(mMotionPosition, child);
                        setPressed(true);
                        if (mSelector != null) {
                            Drawable d = mSelector.getCurrent();
                            if (d != null && d instanceof TransitionDrawable) {
                                ((TransitionDrawable) d).resetTransition();
                            }
                        }
                        if (mTouchModeReset != null) {
                            removeCallbacks(mTouchModeReset);
                        }
                        mTouchModeReset = new Runnable() {
                            @Override
                            public void run() {
                                mTouchModeReset = null;
                                mTouchMode = TOUCH_MODE_REST;
                                child.setPressed(false);
                                setPressed(false);
                                invalidate();
                                if (!mDataChanged && mIsAttached) {
                                    performClick.run();
                                }
                            }
                        };
                        postDelayed(mTouchModeReset,
                                ViewConfiguration.getPressedStateDuration());
                    } else {
                        mTouchMode = TOUCH_MODE_REST;
                        updateSelectorState();
                    }
                    return;
                } else if (!mDataChanged && mAdapter.isEnabled(motionPosition)) {
                    performClick.run();
                }
            }
        }
        mTouchMode = TOUCH_MODE_REST;
        updateSelectorState();
        break;
    case TOUCH_MODE_SCROLL:
        if (mFlingRunnable == null) {
            mFlingRunnable = new FlingRunnable();
        }
        if (!mFlingRunnable.scrollToAdjustViewsUpOrDown()) {
            final VelocityTracker velocityTracker = mVelocityTracker;
            velocityTracker.computeCurrentVelocity(1000, mMaximumVelocity);
            final int initialVelocity =
                    (int) (velocityTracker.getYVelocity(mActivePointerId) * mVelocityScale);
            if (Math.abs(initialVelocity) > mMinimumVelocity) {
                if (mFlingRunnable == null) {
                    mFlingRunnable = new FlingRunnable();
                }
                reportScrollStateChange(ZrcListView.OnScrollListener.SCROLL_STATE_FLING);
                mFlingRunnable.start(-initialVelocity);
            } else {
                mTouchMode = TOUCH_MODE_REST;
                reportScrollStateChange(ZrcListView.OnScrollListener.SCROLL_STATE_IDLE);
                if (mFlingRunnable != null) {
                    mFlingRunnable.endFling();
                }
            }
        }
        break;
    }
    setPressed(false);
    invalidate();
    recycleVelocityTracker();
    mActivePointerId = INVALID_POINTER;
}
 
Example 19
Source File: JellyViewPager.java    From Conquer with Apache License 2.0 4 votes vote down vote up
@Override
public boolean onTouchEvent(MotionEvent event) {
	if (vTracker == null) {
		vTracker = VelocityTracker.obtain();
	}
	vTracker.addMovement(event);
	float currentY = event.getY();
	switch (event.getAction()) {
		case MotionEvent.ACTION_DOWN:
			downY = event.getY();
			downX = event.getX();
			if (!currentViewRect.contains((int) downX, (int) downY)) {
				return false;
			}
			break;
		case MotionEvent.ACTION_MOVE:
			distanceY = currentY - downY;
			if (Math.abs(distanceY) > mTouchSlop) {
				if (pageChangeListener != null) {
					pageChangeListener.onPageScrolled(currentItem, (int) Math.abs(distanceY) / getHeight(), (int) distanceY);
					pageChangeListener.onPageScrollStateChanged(SCROLL_STATE_DRAGGING);
				}
				tranSpring.setEndValue(distanceY);
				float degree = MAX_DEGREE * distanceY / mHeight;
				if (downX < mWidth / 2) {
					degree = -degree;
				}
				rotateSpring.setEndValue(degree);
			}
			break;
		case MotionEvent.ACTION_CANCEL:
		case MotionEvent.ACTION_UP:
			if (Math.abs(distanceY) > mTouchSlop) {
				if (pageChangeListener != null) {
					pageChangeListener.onPageScrollStateChanged(SCROLL_STATE_SETTLING);
				}
				final VelocityTracker tracker = vTracker;
				tracker.computeCurrentVelocity(UNIT);
				float velocityY = tracker.getYVelocity();
				animOutIfNeeded(currentY - downY, velocityY);
				if (vTracker != null) {
					vTracker.recycle();
					vTracker = null;
				}
			}
			break;
	}
	return true;
}
 
Example 20
Source File: SlidingDrawer.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
@Override
public boolean onTouchEvent(MotionEvent event) {
    if (mLocked) {
        return true;
    }

    if (mTracking) {
        mVelocityTracker.addMovement(event);
        final int action = event.getAction();
        switch (action) {
            case MotionEvent.ACTION_MOVE:
                moveHandle((int) (mVertical ? event.getY() : event.getX()) - mTouchDelta);
                break;
            case MotionEvent.ACTION_UP:
            case MotionEvent.ACTION_CANCEL: {
                final VelocityTracker velocityTracker = mVelocityTracker;
                velocityTracker.computeCurrentVelocity(mVelocityUnits);

                float yVelocity = velocityTracker.getYVelocity();
                float xVelocity = velocityTracker.getXVelocity();
                boolean negative;

                final boolean vertical = mVertical;
                if (vertical) {
                    negative = yVelocity < 0;
                    if (xVelocity < 0) {
                        xVelocity = -xVelocity;
                    }
                    if (xVelocity > mMaximumMinorVelocity) {
                        xVelocity = mMaximumMinorVelocity;
                    }
                } else {
                    negative = xVelocity < 0;
                    if (yVelocity < 0) {
                        yVelocity = -yVelocity;
                    }
                    if (yVelocity > mMaximumMinorVelocity) {
                        yVelocity = mMaximumMinorVelocity;
                    }
                }

                float velocity = (float) Math.hypot(xVelocity, yVelocity);
                if (negative) {
                    velocity = -velocity;
                }

                final int top = mHandle.getTop();
                final int left = mHandle.getLeft();

                if (Math.abs(velocity) < mMaximumTapVelocity) {
                    if (vertical ? (mExpanded && top < mTapThreshold + mTopOffset) ||
                            (!mExpanded && top > mBottomOffset + mBottom - mTop -
                                    mHandleHeight - mTapThreshold) :
                            (mExpanded && left < mTapThreshold + mTopOffset) ||
                            (!mExpanded && left > mBottomOffset + mRight - mLeft -
                                    mHandleWidth - mTapThreshold)) {

                        if (mAllowSingleTap) {
                            playSoundEffect(SoundEffectConstants.CLICK);

                            if (mExpanded) {
                                animateClose(vertical ? top : left, true);
                            } else {
                                animateOpen(vertical ? top : left, true);
                            }
                        } else {
                            performFling(vertical ? top : left, velocity, false, true);
                        }

                    } else {
                        performFling(vertical ? top : left, velocity, false, true);
                    }
                } else {
                    performFling(vertical ? top : left, velocity, false, true);
                }
            }
            break;
        }
    }

    return mTracking || mAnimating || super.onTouchEvent(event);
}