ScrollerCompatpublic class ScrollerCompat extends Object Provides access to new {@link android.widget.Scroller Scroller} APIs when available.
This class provides a platform version-independent mechanism for obeying the
current device's preferred scroll physics and fling behavior. It offers a subset of
the APIs from Scroller or OverScroller. |
Fields Summary |
---|
private static final String | TAG | Object | mScroller | ScrollerCompatImpl | mImpl | static final int | CHASE_FRAME_TIME |
Constructors Summary |
---|
ScrollerCompat(android.content.Context context, android.view.animation.Interpolator interpolator)
this(Build.VERSION.SDK_INT, context, interpolator);
| private ScrollerCompat(int apiVersion, android.content.Context context, android.view.animation.Interpolator interpolator)Private constructer where API version can be provided.
Useful for unit testing.
if (apiVersion >= 14) { // ICS
mImpl = new ScrollerCompatImplIcs();
} else if (apiVersion>= 9) { // Gingerbread
mImpl = new ScrollerCompatImplGingerbread();
} else {
mImpl = new ScrollerCompatImplBase();
}
mScroller = mImpl.createScroller(context, interpolator);
|
Methods Summary |
---|
public void | abortAnimation()Stops the animation. Aborting the animation causes the scroller to move to the final x and y
position.
mImpl.abortAnimation(mScroller);
| public boolean | computeScrollOffset()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.
return mImpl.computeScrollOffset(mScroller);
| public static android.support.v4.widget.ScrollerCompat | create(android.content.Context context)
return create(context, null);
| public static android.support.v4.widget.ScrollerCompat | create(android.content.Context context, android.view.animation.Interpolator interpolator)
return new ScrollerCompat(context, interpolator);
| public void | fling(int startX, int startY, int velocityX, int velocityY, int minX, int maxX, int minY, int maxY)Start scrolling based on a fling gesture. The distance travelled will
depend on the initial velocity of the fling.
mImpl.fling(mScroller, startX, startY, velocityX, velocityY, minX, maxX, minY, maxY);
| public void | fling(int startX, int startY, int velocityX, int velocityY, int minX, int maxX, int minY, int maxY, int overX, int overY)Start scrolling based on a fling gesture. The distance travelled will
depend on the initial velocity of the fling.
mImpl.fling(mScroller, startX, startY, velocityX, velocityY,
minX, maxX, minY, maxY, overX, overY);
| public float | getCurrVelocity()Returns the current velocity on platform versions that support it.
The device must support at least API level 14 (Ice Cream Sandwich).
On older platform versions this method will return 0. This method should
only be used as input for nonessential visual effects such as {@link EdgeEffectCompat}.
return mImpl.getCurrVelocity(mScroller);
| public int | getCurrX()Returns the current X offset in the scroll.
return mImpl.getCurrX(mScroller);
| public int | getCurrY()Returns the current Y offset in the scroll.
return mImpl.getCurrY(mScroller);
| public int | getFinalX()
return mImpl.getFinalX(mScroller);
| public int | getFinalY()
return mImpl.getFinalY(mScroller);
| public boolean | isFinished()Returns whether the scroller has finished scrolling.
return mImpl.isFinished(mScroller);
| public boolean | isOverScrolled()Returns whether the current Scroller is currently returning to a valid position.
Valid bounds were provided by the
{@link #fling(int, int, int, int, int, int, int, int, int, int)} method.
One should check this value before calling
{@link #startScroll(int, int, int, int)} as the interpolation currently in progress
to restore a valid position will then be stopped. The caller has to take into account
the fact that the started scroll will start from an overscrolled position.
return mImpl.isOverScrolled(mScroller);
| public void | notifyHorizontalEdgeReached(int startX, int finalX, int overX)Notify the scroller that we've reached a horizontal boundary.
Normally the information to handle this will already be known
when the animation is started, such as in a call to one of the
fling functions. However there are cases where this cannot be known
in advance. This function will transition the current motion and
animate from startX to finalX as appropriate.
mImpl.notifyHorizontalEdgeReached(mScroller, startX, finalX, overX);
| public void | notifyVerticalEdgeReached(int startY, int finalY, int overY)Notify the scroller that we've reached a vertical boundary.
Normally the information to handle this will already be known
when the animation is started, such as in a call to one of the
fling functions. However there are cases where this cannot be known
in advance. This function will animate a parabolic motion from
startY to finalY.
mImpl.notifyVerticalEdgeReached(mScroller, startY, finalY, overY);
| public void | startScroll(int startX, int startY, int dx, int dy)Start scrolling by providing a starting point and the distance to travel.
The scroll will use the default value of 250 milliseconds for the
duration.
mImpl.startScroll(mScroller, startX, startY, dx, dy);
| public void | startScroll(int startX, int startY, int dx, int dy, int duration)Start scrolling by providing a starting point and the distance to travel.
mImpl.startScroll(mScroller, startX, startY, dx, dy, duration);
|
|