private int getSwipeDuration ( MotionEvent ev , int velocity ) { int sx = getScrollX ( ) ; int dx = ( int ) ( ev . getX ( ) - sx ) ; final int width = mSwipeCurrentHorizontal . getMenuWidth ( ) ; final int halfWidth = width / 2 ; final float distanceRatio = Math . min ( 1f , 1.0f * Math . abs ( dx ) / width ) ; final float distance = halfWidth + halfWidth * distanceInfluenceForSnapDuration ( distanceRatio ) ; int duration ; if ( velocity > 0 ) { duration = 4 * Math . round ( 1000 * Math . abs ( distance / velocity ) ) ; } else { final float pageDelta = ( float ) Math . abs ( dx ) / width ; duration = ( int ) ( ( pageDelta + 1 ) * 100 ) ; } duration = Math . min ( duration , mScrollerDuration ) ; return duration ; }
compute finish duration .