public int getPosition() { /// M: [FEATURE.ADD] fancy layout @{ if (mScrollMax != -1 && mScrollMin != -1 && mScroller.isOverScrolled()) { return Utils.clamp(mScroller.getCurrX(), mScrollMin, mScrollMax); } /// @} return mScroller.getCurrX(); }
public void setPosition(int position) { mScroller.startScroll( position, 0, // startX, startY 0, 0, 0); // dx, dy, duration // This forces the scroller to reach the final position. mScroller.abortAnimation(); }
public void fling(int velocity, int min, int max) { /// M: [FEATURE.ADD] fancy layout @{ mScrollMax = max; mScrollMin = min; mScroller.setMaxScrollLength(max); mScroller.setMinScrollLength(min); /// @} int currX = getPosition(); mScroller.fling( currX, 0, // startX, startY velocity, 0, // velocityX, velocityY min, max, // minX, maxX 0, 0, // minY, maxY mOverflingEnabled ? mOverflingDistance : 0, 0); }
// Returns the distance that over the scroll limit. public int startScroll(int distance, int min, int max) { /// M: [FEATURE.ADD] fancy layout @{ mScrollMax = max; mScrollMin = min; mScroller.setMaxScrollLength(max); mScroller.setMinScrollLength(min); /// @} int currPosition = mScroller.getCurrX(); int finalPosition = mScroller.isFinished() ? currPosition : mScroller.getFinalX(); int newPosition = Utils.clamp(finalPosition + distance, min, max); if (newPosition != currPosition) { mScroller.startScroll( currPosition, 0, // startX, startY newPosition - currPosition, 0, 0); // dx, dy, duration } return finalPosition + distance - newPosition; }
public float getCurrVelocity() { return mScroller.getCurrVelocity(); }
public void forceFinished() { mScroller.forceFinished(true); }
public boolean isFinished() { return mScroller.isFinished(); }
/** * Call this when you want to know the new location. The position will be updated and can be * obtained by getPosition(). Returns true if the animation is not yet finished. */ public boolean advanceAnimation(long currentTimeMillis) { return mScroller.computeScrollOffset(); }