wear/src/main/java/androidx/wear/widget/ScrollManager.java
boolean onTouchEvent(MotionEvent event) {
        float deltaX = event.getRawX() - mScreenRadiusPx;
        float deltaY = event.getRawY() - mScreenRadiusPx;
        float radiusSquared = deltaX * deltaX + deltaY * deltaY;
        final MotionEvent vtev = MotionEvent.obtain(event);
        mVelocityTracker.addMovement(vtev);
        vtev.recycle();

        switch (event.getActionMasked()) {
            case MotionEvent.ACTION_DOWN:
                if (radiusSquared / mScreenRadiusPxSquared > mMinRadiusFractionSquared) {
                    mDown = true;
                    return true; // Consume the event.
                }
                break;

            case MotionEvent.ACTION_MOVE:
                if (mScrolling) {
                    float angleRadians = (float) Math.atan2(deltaY, deltaX);
                    float deltaRadians = angleRadians - mLastAngleRadians;
                    deltaRadians = normalizeAngleRadians(deltaRadians);
                    int scrollPixels = Math.round(deltaRadians * mScrollPixelsPerRadian);
                    if (scrollPixels != 0) {
                        mRecyclerView.scrollBy(0 /* x */, scrollPixels /* y */);
                        // Recompute deltaRadians in terms of rounded scrollPixels.
                        deltaRadians = scrollPixels / mScrollPixelsPerRadian;
                        mLastAngleRadians += deltaRadians;
                        mLastAngleRadians = normalizeAngleRadians(mLastAngleRadians);
                    }
                    // Always consume the event so that we never break the circular scrolling
                    // gesture.
                    return true;
                }

                if (mDown) {
                    float deltaXFromCenter = event.getRawX() - mScreenRadiusPx;
                    float deltaYFromCenter = event.getRawY() - mScreenRadiusPx;
                    float distFromCenter = (float) Math.hypot(deltaXFromCenter, deltaYFromCenter);
                    if (distFromCenter != 0) {
                        deltaXFromCenter /= distFromCenter;
                        deltaYFromCenter /= distFromCenter;

                        mScrolling = true;
                        mRecyclerView.invalidate();
                        mLastAngleRadians = (float) Math.atan2(deltaYFromCenter, deltaXFromCenter);
                        return true; // Consume the event.
                    }
                } else {
                    // Double check we're not missing an event we should really be handling.
                    if (radiusSquared / mScreenRadiusPxSquared > mMinRadiusFractionSquared) {
                        mDown = true;
                        return true; // Consume the event.
                    }
                }
                break;

            case MotionEvent.ACTION_UP:
                mDown = false;
                mScrolling = false;
                mVelocityTracker.computeCurrentVelocity(ONE_SEC_IN_MS,
                        mRecyclerView.getMaxFlingVelocity());
                int velocityY = (int) mVelocityTracker.getYVelocity();
                if (event.getX() < FLING_EDGE_RATIO * mScreenRadiusPx) {
                    velocityY = -velocityY;
                }
                mVelocityTracker.clear();
                if (Math.abs(velocityY) > mRecyclerView.getMinFlingVelocity()) {
                    return mRecyclerView.fling(0, (int) (VELOCITY_MULTIPLIER * velocityY));
                }
                break;

            case MotionEvent.ACTION_CANCEL:
                if (mDown) {
                    mDown = false;
                    mScrolling = false;
                    mRecyclerView.invalidate();
                    return true; // Consume the event.
                }
                break;
        }

        return false;
    }
/**
     * Method dealing with touch events intercepted from the attached {@link RecyclerView}.
     *
     * @param event the intercepted touch event.
     * @return true if the even was handled, false otherwise.
     */
Method dealing with touch events intercepted from the attached  RecyclerView.
@param event the intercepted touch event.
@return true if the even was handled, false otherwise.
Method dealing with touch events intercepted from the attached RecyclerView . @param event the intercepted touch event . @return true if the even was handled false otherwise .
boolean onTouchEvent(MotionEvent event) {
        float deltaX = event.getRawX() - mScreenRadiusPx;
        float deltaY = event.getRawY() - mScreenRadiusPx;
        float radiusSquared = deltaX * deltaX + deltaY * deltaY;
        final MotionEvent vtev = MotionEvent.obtain(event);
        mVelocityTracker.addMovement(vtev);
        vtev.recycle();
        switch (event.getActionMasked()) {
            case MotionEvent.ACTION_DOWN:
                if (radiusSquared / mScreenRadiusPxSquared > mMinRadiusFractionSquared) {
                    mDown = true;
                    return true; 
                }
                break;
            case MotionEvent.ACTION_MOVE:
                if (mScrolling) {
                    float angleRadians = (float) Math.atan2(deltaY, deltaX);
                    float deltaRadians = angleRadians - mLastAngleRadians;
                    deltaRadians = normalizeAngleRadians(deltaRadians);
                    int scrollPixels = Math.round(deltaRadians * mScrollPixelsPerRadian);
                    if (scrollPixels != 0) {
                        mRecyclerView.scrollBy(0 /* x */, scrollPixels /* y */);
                        deltaRadians = scrollPixels / mScrollPixelsPerRadian;
                        mLastAngleRadians += deltaRadians;
                        mLastAngleRadians = normalizeAngleRadians(mLastAngleRadians);
                    }
                    return true;
                }
                if (mDown) {
                    float deltaXFromCenter = event.getRawX() - mScreenRadiusPx;
                    float deltaYFromCenter = event.getRawY() - mScreenRadiusPx;
                    float distFromCenter = (float) Math.hypot(deltaXFromCenter, deltaYFromCenter);
                    if (distFromCenter != 0) {
                        deltaXFromCenter /= distFromCenter;
                        deltaYFromCenter /= distFromCenter;
                        mScrolling = true;
                        mRecyclerView.invalidate();
                        mLastAngleRadians = (float) Math.atan2(deltaYFromCenter, deltaXFromCenter);
                        return true; 
                    }
                } else {
                    if (radiusSquared / mScreenRadiusPxSquared > mMinRadiusFractionSquared) {
                        mDown = true;
                        return true; 
                    }
                }
                break;
            case MotionEvent.ACTION_UP:
                mDown = false;
                mScrolling = false;
                mVelocityTracker.computeCurrentVelocity(ONE_SEC_IN_MS,
                        mRecyclerView.getMaxFlingVelocity());
                int velocityY = (int) mVelocityTracker.getYVelocity();
                if (event.getX() < FLING_EDGE_RATIO * mScreenRadiusPx) {
                    velocityY = -velocityY;
                }
                mVelocityTracker.clear();
                if (Math.abs(velocityY) > mRecyclerView.getMinFlingVelocity()) {
                    return mRecyclerView.fling(0, (int) (VELOCITY_MULTIPLIER * velocityY));
                }
                break;
            case MotionEvent.ACTION_CANCEL:
                if (mDown) {
                    mDown = false;
                    mScrolling = false;
                    mRecyclerView.invalidate();
                    return true; 
                }
                break;
        }
        return false;
    }
boolean onTouchEvent ( MotionEvent event ) { float deltaX = event . getRawX ( ) - mScreenRadiusPx ; float deltaY = event . getRawY ( ) - mScreenRadiusPx ; float radiusSquared = deltaX * deltaX + deltaY * deltaY ; final MotionEvent vtev = MotionEvent . obtain ( event ) ; mVelocityTracker . addMovement ( vtev ) ; vtev . recycle ( ) ; switch ( event . getActionMasked ( ) ) { case MotionEvent . ACTION_DOWN : if ( radiusSquared / mScreenRadiusPxSquared > mMinRadiusFractionSquared ) { mDown = true ; return true ; } break ; case MotionEvent . ACTION_MOVE : if ( mScrolling ) { float angleRadians = ( float ) Math . atan2 ( deltaY , deltaX ) ; float deltaRadians = angleRadians - mLastAngleRadians ; deltaRadians = normalizeAngleRadians ( deltaRadians ) ; int scrollPixels = Math . round ( deltaRadians * mScrollPixelsPerRadian ) ; if ( scrollPixels != 0 ) { mRecyclerView . scrollBy ( 0 /* x */ , scrollPixels /* y */ ) ; deltaRadians = scrollPixels / mScrollPixelsPerRadian ; mLastAngleRadians += deltaRadians ; mLastAngleRadians = normalizeAngleRadians ( mLastAngleRadians ) ; } return true ; } if ( mDown ) { float deltaXFromCenter = event . getRawX ( ) - mScreenRadiusPx ; float deltaYFromCenter = event . getRawY ( ) - mScreenRadiusPx ; float distFromCenter = ( float ) Math . hypot ( deltaXFromCenter , deltaYFromCenter ) ; if ( distFromCenter != 0 ) { deltaXFromCenter /= distFromCenter ; deltaYFromCenter /= distFromCenter ; mScrolling = true ; mRecyclerView . invalidate ( ) ; mLastAngleRadians = ( float ) Math . atan2 ( deltaYFromCenter , deltaXFromCenter ) ; return true ; } } else { if ( radiusSquared / mScreenRadiusPxSquared > mMinRadiusFractionSquared ) { mDown = true ; return true ; } } break ; case MotionEvent . ACTION_UP : mDown = false ; mScrolling = false ; mVelocityTracker . computeCurrentVelocity ( ONE_SEC_IN_MS , mRecyclerView . getMaxFlingVelocity ( ) ) ; int velocityY = ( int ) mVelocityTracker . getYVelocity ( ) ; if ( event . getX ( ) < FLING_EDGE_RATIO * mScreenRadiusPx ) { velocityY = - velocityY ; } mVelocityTracker . clear ( ) ; if ( Math . abs ( velocityY ) > mRecyclerView . getMinFlingVelocity ( ) ) { return mRecyclerView . fling ( 0 , ( int ) ( VELOCITY_MULTIPLIER * velocityY ) ) ; } break ; case MotionEvent . ACTION_CANCEL : if ( mDown ) { mDown = false ; mScrolling = false ; mRecyclerView . invalidate ( ) ; return true ; } break ; } return false ; }
Method dealing with touch events intercepted from the attached {@link RecyclerView}.
Method dealing with touch events intercepted from the attached { @link RecyclerView } .
// Consume the event. // Recompute deltaRadians in terms of rounded scrollPixels. // Always consume the event so that we never break the circular scrolling // gesture. // Consume the event. // Double check we're not missing an event we should really be handling. // Consume the event. // Consume the event.