Code example for Scroller

Methods: abortAnimation, computeScrollOffset, getCurrX, getFinalX, startScroll

0
        } else { 
        	duration = 4 * Math.round(1000.f * Math.abs((float) dx / velocity));
        } 
        duration = Math.min(duration, DURATION_MAX);
 
        mScroller.startScroll(startX, 0, dx, 0, duration);
        postAnimationInvalidate(); 
    } 
     
    protected void setOffsetPixels(int offsetPixels) {
        if (offsetPixels != mCurrentOffset) {
            onOffsetPixelsChanged(offsetPixels);
            mCurrentOffset = offsetPixels;
            mIsCoverVisible = offsetPixels != 0;
        } 
    } 
 
    @Override 
    protected boolean fitSystemWindows(Rect insets) {
        if (mDisplayMode == DISPLAY_ON_WINDOW) {
        	mCoverContainer.setPadding(0, insets.top, 0, 0);
        } 
        return super.fitSystemWindows(insets);
    } 
 
    private void updateTouchAreaWidth() { 
        if (mTouchMode == TOUCH_MODE_CONTENT) {
            mTouchWidth = getMeasuredWidth();
        }  
        else if(mTouchMode == TOUCH_MODE_EDGE){
        	mTouchWidth =mEdgeWidth;
        } 
        else { 
            mTouchWidth = 0;
        } 
    } 
  
    protected boolean isCloseEnough() { 
        return mCurrentOffset <= mCloseEnough;
    } 
     
    protected abstract Drawable getDropShadowColor(int color);
     
    protected abstract void drawDropShadow(Canvas canvas, int offsetPixels);
 
    protected abstract void onOffsetPixelsChanged(int offsetPixels);
     
    protected abstract boolean isAirTouch(MotionEvent ev);
 
    protected abstract boolean onDownAllowDrag(MotionEvent ev , float initialMotionX);
 
    protected abstract boolean onMoveAllowDrag(MotionEvent ev, float dx , float initialMotionX);
 
    protected abstract void onMoveEvent(float dx);
 
    protected abstract void onUpEvent(MotionEvent ev , VelocityTracker tracker);
 
    protected void stopAnimation() { 
        removeCallbacks(mDragRunnable);
        mScroller.abortAnimation();
    } 
     
    @SuppressLint("NewApi") 
	@Override 
    public void postOnAnimation(Runnable action) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
            super.postOnAnimation(action);
        } else { 
            postDelayed(action, ANIMATION_DELAY);
        } 
    } 
     
    private final Runnable mDragRunnable = new Runnable() {
        public void run() { 
            postAnimationInvalidate(); 
        } 
    }; 
     
    private void postAnimationInvalidate() { 
        if (mScroller.computeScrollOffset()) {
            final int oldX = mCurrentOffset;
            final int x = mScroller.getCurrX();
            if (x != oldX){
            	setOffsetPixels(x);
            } 
            if (x != mScroller.getFinalX()) {
                postOnAnimation(mDragRunnable);
                return; 
            } 
        } 
 
        // move contentscomplete scroll Animation 
        mScroller.abortAnimation();
        final int finalX = mScroller.getFinalX();
        setOffsetPixels(finalX);
        setCoverState(finalX == 0 ? STATE_CLOSED : STATE_OPEN);
         
    } 
}