public void fling(int startX,int startY,int velocityX,int velocityY,int minX,int maxX,int minY,int maxY){
  if (mFlywheel && !mFinished) {
    float oldVel=getCurrVelocity();
    float dx=(float)(mFinalX - mStartX);
    float dy=(float)(mFinalY - mStartY);
    float hyp=(float)Math.hypot(dx,dy);
    float ndx=dx / hyp;
    float ndy=dy / hyp;
    float oldVelocityX=ndx * oldVel;
    float oldVelocityY=ndy * oldVel;
    if (Math.signum(velocityX) == Math.signum(oldVelocityX) && Math.signum(velocityY) == Math.signum(oldVelocityY)) {
      velocityX+=oldVelocityX;
      velocityY+=oldVelocityY;
    }
  }
  mMode=FLING_MODE;
  mFinished=false;
  float velocity=(float)Math.hypot(velocityX,velocityY);
  mVelocity=velocity;
  mDuration=getSplineFlingDuration(velocity);
  mStartTime=AnimationUtils.currentAnimationTimeMillis();
  mStartX=startX;
  mStartY=startY;
  float coeffX=velocity == 0 ? 1.0f : velocityX / velocity;
  float coeffY=velocity == 0 ? 1.0f : velocityY / velocity;
  double totalDistance=getSplineFlingDistance(velocity);
  mDistance=(int)(totalDistance * Math.signum(velocity));
  mMinX=minX;
  mMaxX=maxX;
  mMinY=minY;
  mMaxY=maxY;
  mFinalX=startX + (int)Math.round(totalDistance * coeffX);
  mFinalX=Math.min(mFinalX,mMaxX);
  mFinalX=Math.max(mFinalX,mMinX);
  mFinalY=startY + (int)Math.round(totalDistance * coeffY);
  mFinalY=Math.min(mFinalY,mMaxY);
  mFinalY=Math.max(mFinalY,mMinY);
}

public void fling ( int startX , int startY , int velocityX , int velocityY , int minX , int maxX , int minY , int maxY ) { if ( mFlywheel && ! mFinished ) { float oldVel = getCurrVelocity ( ) ; float dx = ( float ) ( mFinalX - mStartX ) ; float dy = ( float ) ( mFinalY - mStartY ) ; float hyp = ( float ) Math . hypot ( dx , dy ) ; float ndx = dx / hyp ; float ndy = dy / hyp ; float oldVelocityX = ndx * oldVel ; float oldVelocityY = ndy * oldVel ; if ( Math . signum ( velocityX ) == Math . signum ( oldVelocityX ) && Math . signum ( velocityY ) == Math . signum ( oldVelocityY ) ) { velocityX += oldVelocityX ; velocityY += oldVelocityY ; } } mMode = FLING_MODE ; mFinished = false ; float velocity = ( float ) Math . hypot ( velocityX , velocityY ) ; mVelocity = velocity ; mDuration = getSplineFlingDuration ( velocity ) ; mStartTime = AnimationUtils . currentAnimationTimeMillis ( ) ; mStartX = startX ; mStartY = startY ; float coeffX = velocity == 0 ? 1.0f : velocityX / velocity ; float coeffY = velocity == 0 ? 1.0f : velocityY / velocity ; double totalDistance = getSplineFlingDistance ( velocity ) ; mDistance = ( int ) ( totalDistance * Math . signum ( velocity ) ) ; mMinX = minX ; mMaxX = maxX ; mMinY = minY ; mMaxY = maxY ; mFinalX = startX + ( int ) Math . round ( totalDistance * coeffX ) ; mFinalX = Math . min ( mFinalX , mMaxX ) ; mFinalX = Math . max ( mFinalX , mMinX ) ; mFinalY = startY + ( int ) Math . round ( totalDistance * coeffY ) ; mFinalY = Math . min ( mFinalY , mMaxY ) ; mFinalY = Math . max ( mFinalY , mMinY ) ; }
start scrolling based on a fling gesture . the distance travelled will depend on the initial velocity of the fling .
