Java Code Examples for android.widget.OverScroller#getCurrX()

The following examples show how to use android.widget.OverScroller#getCurrX() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: WeekDatePicker.java    From WeekDatePicker with MIT License 6 votes vote down vote up
private void computeScrollX() {
    OverScroller scroller = flingScrollerX;
    if(scroller.isFinished()) {
        scroller = adjustScrollerX;
        if(scroller.isFinished()) {
            return;
        }
    }

    if(scroller.computeScrollOffset()) {

        int currentScrollerX = scroller.getCurrX();
        if(previousScrollerX == Integer.MIN_VALUE) {
            previousScrollerX = scroller.getStartX();
        }

        scrollBy(currentScrollerX - previousScrollerX, 0);
        previousScrollerX = currentScrollerX;

        if(scroller.isFinished()) {
            onScrollerFinishedX(scroller);
        }

        postInvalidate();
    }
}
 
Example 2
Source File: PagingOverScroller.java    From ProjectX with Apache License 2.0 5 votes vote down vote up
@Override
public void run() {
    if (mRecyclerView == null)
        return;
    final RecyclerView.LayoutManager layoutManager = mRecyclerView.getLayoutManager();
    if (layoutManager == null) {
        stop();
        return; // no layout, cannot scroll.
    }
    disableRunOnAnimationRequests();
    // keep a local reference so that if it is changed during onAnimation method, it won't
    // cause unexpected behaviors
    final OverScroller scroller = mScroller;

    if (scroller.computeScrollOffset()) {
        final int x = scroller.getCurrX();
        final int y = scroller.getCurrY();
        final int dx = x - mLastFlingX;
        final int dy = y - mLastFlingY;
        mLastFlingX = x;
        mLastFlingY = y;
        if (dx != 0 || dy != 0)
            mRecyclerView.scrollBy(dx, dy);
        if (scroller.isFinished()) {
            if (layoutManager instanceof PagingLayoutManager) {
                ((PagingLayoutManager) layoutManager).onFlingFinish();
            }
        } else {
            postOnAnimation();
        }
    }
    enableRunOnAnimationRequests();
}