/** * Call this when you want to know the new location. If it returns true, the animation is not yet * finished. */ public boolean computeScrollOffset(long time) { if (isFinished()) { return false; } switch (mMode) { case SCROLL_MODE: // Any scroller can be used for time, since they were started // together in scroll mode. We use X here. final long elapsedTime = time - mScrollerX.mStartTime; final int duration = mScrollerX.mDuration; if (elapsedTime < duration) { float q = (float) (elapsedTime) / duration; q = viscousFluid(q); mScrollerX.updateScroll(q); mScrollerY.updateScroll(q); } else { abortAnimation(); } break; case FLING_MODE: if (!mScrollerX.mFinished) { if (!mScrollerX.update(time)) { if (!mScrollerX.continueWhenFinished(time)) { mScrollerX.finish(); } } } if (!mScrollerY.mFinished) { if (!mScrollerY.update(time)) { if (!mScrollerY.continueWhenFinished(time)) { mScrollerY.finish(); } } } break; default: break; } return true; }
/** * Stops the animation. Contrary to {@link #forceFinished(boolean)}, aborting the animating causes * the scroller to move to the final x and y positions. * * @see #forceFinished(boolean) */ public void abortAnimation() { mScrollerX.finish(); mScrollerY.finish(); }