public boolean computeScrollOffset ( ) { if ( mFinished ) { return false ; } int timePassed = ( int ) ( AnimationUtils . currentAnimationTimeMillis ( ) - mStartTime ) ; if ( timePassed < mDuration ) { switch ( mMode ) { case SCROLL_MODE : float x = timePassed * mDurationReciprocal ; if ( mInterpolator == null ) x = viscousFluid ( x ) ; else x = mInterpolator . getInterpolation ( x ) ; mCurrX = mStartX + Math . round ( x * mDeltaX ) ; mCurrY = mStartY + Math . round ( x * mDeltaY ) ; break ; case FLING_MODE : final float t = ( float ) timePassed / mDuration ; final int index = ( int ) ( NB_SAMPLES * t ) ; final float tInf = ( float ) index / NB_SAMPLES ; final float tSup = ( float ) ( index + 1 ) / NB_SAMPLES ; final float dInf = SPLINE [ index ] ; final float dSup = SPLINE [ index + 1 ] ; final float distanceCoef = dInf + ( t - tInf ) / ( tSup - tInf ) * ( dSup - dInf ) ; mCurrX = mStartX + Math . round ( distanceCoef * ( mFinalX - mStartX ) ) ; // Pin to mMinX <= mCurrX <= mMaxX mCurrX = Math . min ( mCurrX , mMaxX ) ; mCurrX = Math . max ( mCurrX , mMinX ) ; mCurrY = mStartY + Math . round ( distanceCoef * ( mFinalY - mStartY ) ) ; // Pin to mMinY <= mCurrY <= mMaxY mCurrY = Math . min ( mCurrY , mMaxY ) ; mCurrY = Math . max ( mCurrY , mMinY ) ; if ( mCurrX == mFinalX && mCurrY == mFinalY ) { mFinished = true ; } break ; } } else { mCurrX = mFinalX ; mCurrY = mFinalY ; mFinished = true ; } return true ; }
Call this when you want to know the new location . If it returns true the animation is not yet finished . loc will be altered to provide the new location .