AVIARY API TERMS OF USE
Full Legal Agreement
The following terms and conditions and the terms and conditions at http://www.aviary.com/terms (collectively, the ?Terms??)
govern your use of any and ...
If you think the Android project Aviary-Android-SDK listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
Java Source Code
package com.aviary.android.feather.widget;
/*fromwww.java2s.com*/import android.annotation.TargetApi;
import android.view.View;
import android.view.animation.Interpolator;
import android.widget.OverScroller;
import android.widget.Scroller;
publicclass ScrollerRunnable implements Runnable {
publicstaticinterface ScrollableView {
boolean removeCallbacks( Runnable action );
boolean post( Runnable action );
void scrollIntoSlots();
void trackMotionScroll( int newX );
int getMinX();
int getMaxX();
}
protectedint mLastFlingX;
protectedboolean mShouldStopFling;
protected ScrollableView mParent;
protectedint mAnimationDuration;
protectedint mPreviousX;
protectedboolean mHasMore;
private OverScroller mScroller;
privateint mOverscrollDistance;
/**
* ScrollerRunnable acts like a {@link Scroller} adding some help methods
*
* @param parent
* the parent view
* @param animationDuration
* the default animation duration
* @param overscrollDistance
* the overscroller distance
* @param interpolator
* the default interpolator, can be null
*/public ScrollerRunnable ( ScrollableView parent, int animationDuration, int overscrollDistance, Interpolator interpolator ) {
if ( null == interpolator ) {
mScroller = new OverScroller( ( (View) parent ).getContext() );
} else {
mScroller = new OverScroller( ( (View) parent ).getContext(), interpolator );
}
mOverscrollDistance = overscrollDistance;
mParent = parent;
mAnimationDuration = animationDuration;
}
publicint getLastFlingX() {
return mLastFlingX;
}
protectedvoid startCommon() {
mParent.removeCallbacks( this );
}
publicvoid stop( boolean scrollIntoSlots ) {
mParent.removeCallbacks( this );
endFling( scrollIntoSlots );
}
publicvoid endFling( boolean scrollIntoSlots ) {
abortAnimation();
mLastFlingX = 0;
mHasMore = false;
if ( scrollIntoSlots ) {
mParent.scrollIntoSlots();
}
}
publicvoid startUsingDistance( int initialX, int distance ) {
if ( distance == 0 ) return;
startCommon();
mLastFlingX = initialX;
mScroller.startScroll( initialX, 0, distance, 0, mAnimationDuration );
mParent.post( this );
}
publicvoid startUsingVelocity( int initialX, int initialVelocity ) {
if ( initialVelocity == 0 ) return;
startCommon();
mLastFlingX = initialX;
mScroller.fling( initialX, 0, initialVelocity, 0, mParent.getMinX(), mParent.getMaxX(), 0, Integer.MAX_VALUE, mOverscrollDistance, 0 );
mParent.post( this );
}
publicint getPreviousX() {
return mPreviousX;
}
publicboolean hasMore() {
return mHasMore;
}
@TargetApi ( 14 )
publicfloat getCurrVelocity() {
return mScroller.getCurrVelocity();
}
publicboolean isFinished() {
return mScroller.isFinished();
}
publicboolean springBack( int startX, int startY, int minX, int maxX, int minY, int maxY ) {
return mScroller.springBack( startX, startY, minX, maxX, minY, maxY );
}
publicboolean computeScrollOffset() {
return mScroller.computeScrollOffset();
}
publicint getCurrX() {
return mScroller.getCurrX();
}
protectedvoid abortAnimation() {
mScroller.abortAnimation();
}
@Override
publicvoid run() {
mShouldStopFling = false;
mPreviousX = getCurrX();
mHasMore = computeScrollOffset();
int x = getCurrX();
mParent.trackMotionScroll( x );
if ( mHasMore && !mShouldStopFling ) {
mLastFlingX = x;
mParent.post( this );
} else {
endFling( true );
}
}
}