Java Code Examples for android.widget.Scroller#computeScrollOffset()

The following examples show how to use android.widget.Scroller#computeScrollOffset() . 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: NumberPicker.java    From DatePicker with Apache License 2.0 6 votes vote down vote up
@Override
public void computeScroll() {

    Scroller scroller = mFlingScroller;
    if (scroller.isFinished()) {
        onScrollStateChange(OnScrollListener.SCROLL_STATE_IDLE);
        scroller = mAdjustScroller;
        if (scroller.isFinished()) {
            return;
        }
    }

    scroller.computeScrollOffset();

    mCurrY = scroller.getCurrY();
    mOffectY = mCurrY - mStartY;

    computeYPos(mOffectY);

    invalidate();
    mStartY = mCurrY;
}
 
Example 2
Source File: NumberPicker.java    From DateTimePicker with Apache License 2.0 6 votes vote down vote up
@Override
public void computeScroll() {
    Scroller scroller = mFlingScroller;
    if (scroller.isFinished()) {
        scroller = mAdjustScroller;
        if (scroller.isFinished()) {
            return;
        }
    }
    scroller.computeScrollOffset();
    int currentScrollerY = scroller.getCurrY();
    if (mPreviousScrollerY == 0) {
        mPreviousScrollerY = scroller.getStartY();
    }
    scrollBy(0, currentScrollerY - mPreviousScrollerY);
    mPreviousScrollerY = currentScrollerY;
    if (scroller.isFinished()) {
        onScrollerFinished(scroller);
    } else {
        invalidate();
    }
}
 
Example 3
Source File: AutoScrollTextView.java    From BigApp_Discuz_Android with Apache License 2.0 6 votes vote down vote up
/**
 * 此方法为最后机会来修改mScrollX,mScrollY. 这方法后将根据mScrollX,mScrollY来偏移Canvas已实现内容滚动
 */
@Override
public void computeScroll() {
	super.computeScroll();

	final Scroller scroller = mScroller;
	if (scroller.computeScrollOffset()) { // 正在滚动,让view滚动到当前位置
		int scrollY = scroller.getCurrY();
		final int maxY = (getLineCount() * getLineHeight()
				+ getPaddingTop() + getPaddingBottom())
				- getHeight();
		boolean toEdge = scrollY < 0 || scrollY > maxY;
		if (scrollY < 0)
			scrollY = 0;
		else if (scrollY > maxY)
			scrollY = maxY;

		/*
		 * 下面等同于: mScrollY = scrollY; awakenScrollBars(); //显示滚动条,必须在xml中配置。
		 * postInvalidate();
		 */
		scrollTo(0, scrollY);
		if (toEdge) // 移到两端,由于位置没有发生变化,导致滚动条不显示
			awakenScrollBars();
	}
}
 
Example 4
Source File: ScrollTextView.java    From BigApp_Discuz_Android with Apache License 2.0 6 votes vote down vote up
/**
 * 此方法为最后机会来修改mScrollX,mScrollY. 这方法后将根据mScrollX,mScrollY来偏移Canvas已实现内容滚动
 */
@Override
public void computeScroll() {
	super.computeScroll();

	final Scroller scroller = mScroller;
	if (scroller.computeScrollOffset()) { // 正在滚动,让view滚动到当前位置
		int scrollY = scroller.getCurrY();
		final int maxY = (getLineCount() * getLineHeight()
				+ getPaddingTop() + getPaddingBottom())
				- getHeight();
		boolean toEdge = scrollY < 0 || scrollY > maxY;
		if (scrollY < 0)
			scrollY = 0;
		else if (scrollY > maxY)
			scrollY = maxY;

		/*
		 * 下面等同于: mScrollY = scrollY; awakenScrollBars(); //显示滚动条,必须在xml中配置。
		 * postInvalidate();
		 */
		scrollTo(0, scrollY);
		if (toEdge) // 移到两端,由于位置没有发生变化,导致滚动条不显示
			awakenScrollBars();
	}
}
 
Example 5
Source File: NumberPicker.java    From NewXmPluginSDK with Apache License 2.0 6 votes vote down vote up
@Override
public void computeScroll() {
    Scroller scroller = mFlingScroller;
    if (scroller.isFinished()) {
        scroller = mAdjustScroller;
        if (scroller.isFinished()) {
            return;
        }
    }
    scroller.computeScrollOffset();
    int currentScrollerY = scroller.getCurrY();
    if (mPreviousScrollerY == 0) {
        mPreviousScrollerY = scroller.getStartY();
    }
    scrollBy(0, currentScrollerY - mPreviousScrollerY);
    mPreviousScrollerY = currentScrollerY;
    if (scroller.isFinished()) {
        onScrollerFinished(scroller);
    } else {
        invalidate();
    }
}
 
Example 6
Source File: VelocityViewPager.java    From CoverFlowPager with MIT License 6 votes vote down vote up
@Override
public void run() {

    final Scroller scroller = mScroller;
    boolean animationNotFinished = scroller.computeScrollOffset();
    final int x = scroller.getCurrX();
    int delta = x - mLastFlingX;

    trackMotion(delta);

    if (animationNotFinished) {
        mLastFlingX = x;
        post(this);
    } else {
        endFling();
    }

}
 
Example 7
Source File: MeterNumberPicker.java    From meter-number-picker with Apache License 2.0 5 votes vote down vote up
@Override
public void computeScroll() {
    Scroller scroller = flingScroller;
    if (scroller.isFinished()) {
        scroller = adjustScroller;
        if (scroller.isFinished()) {
            return;
        }
    }
    scroller.computeScrollOffset();
    int currentScrollerY = scroller.getCurrY();
    int diffScrollY = scrollerLastY - currentScrollerY;
    currentScrollOffset -= diffScrollY;
    scrollerLastY = currentScrollerY;

    if (adjustScroller.isFinished()) {
        if (flingScroller.isFinished()) {
            if (currentScrollOffset != 0) {
                int measuredHeight = getMeasuredHeight();
                int adjustedValueOffset = calculateAdjustedValueOffset(measuredHeight);
                value = getValue(adjustedValueOffset);
                adjust(measuredHeight, adjustedValueOffset);
            }
        } else {
            int newScrollOffset = currentScrollOffset % getMeasuredHeight();
            if (newScrollOffset != currentScrollOffset) {
                int numberOfValuesScrolled = (currentScrollOffset - newScrollOffset) / getMeasuredHeight();
                currentValueOffset += numberOfValuesScrolled;
                currentScrollOffset = newScrollOffset;
            }
        }
    }

    invalidate();
}
 
Example 8
Source File: MyScrollView.java    From prayer-times-android with Apache License 2.0 5 votes vote down vote up
private void initBounce() {

        // init the bouncy scroller, and make sure the layout is being drawn
        // after the top padding
        mScroller = new Scroller(getContext(), new OvershootInterpolator(OVERSHOOT_TENSION));
        overScrollerSpringbackTask = new Runnable() {
            @Override
            public void run() {
                // scroll till after the padding
                mScroller.computeScrollOffset();
                scrollTo(0, mScroller.getCurrY());

                if (!mScroller.isFinished()) {
                    post(this);
                }
            }
        };
        prevScrollY = getPaddingTop();

        try {
            mScrollXField = View.class.getDeclaredField("mScrollX");
            mScrollYField = View.class.getDeclaredField("mScrollY");

        } catch (Exception e) {
            hasFailedObtainingScrollFields = true;
        }
    }
 
Example 9
Source File: ScrollerCompat.java    From adt-leanback-support with Apache License 2.0 4 votes vote down vote up
@Override
public boolean computeScrollOffset(Object scroller) {
    final Scroller s = (Scroller) scroller;
    return s.computeScrollOffset();
}
 
Example 10
Source File: PLAAbsListView.java    From Lay-s with MIT License 4 votes vote down vote up
public void run() {
    switch (mTouchMode) {
        default:
            return;

        case TOUCH_MODE_FLING: {
            if (mItemCount == 0 || getChildCount() == 0) {
                endFling();
                return;
            }

            final Scroller scroller = mScroller;
            boolean more = scroller.computeScrollOffset();
            final int y = scroller.getCurrY();

            // Flip sign to convert finger direction to list items direction
            // (e.g. finger moving down means list is moving towards the top)
            int delta = mLastFlingY - y;

            // Pretend that each frame of a fling scroll is a touch scroll
            if (delta > 0) {
                // List is moving towards the top. Use first view as mMotionPosition
                mMotionPosition = mFirstPosition;
                //final View firstView = getChildAt(0);
                //mMotionViewOriginalTop = firstView.getTop();
                mMotionViewOriginalTop = getScrollChildTop();

                // Don't fling more than 1 screen
                // delta = Math.min(getHeight() - mPaddingBottom - mPaddingTop - 1, delta);
                delta = Math.min(getHeight() - getPaddingBottom() - getPaddingTop() - 1, delta);
            } else {
                // List is moving towards the bottom. Use last view as mMotionPosition
                int offsetToLast = getChildCount() - 1;
                mMotionPosition = mFirstPosition + offsetToLast;

                //final View lastView = getChildAt(offsetToLast);
                //mMotionViewOriginalTop = lastView.getTop();
                mMotionViewOriginalTop = getScrollChildBottom();

                // Don't fling more than 1 screen
                // delta = Math.max(-(getHeight() - mPaddingBottom - mPaddingTop - 1), delta);
                delta = Math.max(-(getHeight() - getPaddingBottom() - getPaddingTop() - 1), delta);
            }

            final boolean atEnd = trackMotionScroll(delta, delta);

            if (more && !atEnd) {
                invalidate();
                mLastFlingY = y;
                post(this);
            } else {
                endFling();
                if (PROFILE_FLINGING) {
                    if (mFlingProfilingStarted) {
                        Debug.stopMethodTracing();
                        mFlingProfilingStarted = false;
                    }
                }
            }
            break;
        }
    }
}
 
Example 11
Source File: Touch.java    From JotaTextEditor with Apache License 2.0 4 votes vote down vote up
public void run() {
            switch (mTouchMode) {
            default:
                return;

            case TOUCH_MODE_FLING: {
//                if (mItemCount == 0 || getChildCount() == 0) {
//                    endFling();
//                    return;
//                }

                final Scroller scroller = mScroller;
                boolean more = scroller.computeScrollOffset();

                int x = scroller.getCurrX();
                int y = scroller.getCurrY();


//                // Pretend that each frame of a fling scroll is a touch scroll
//                if (delta > 0) {
//                    // List is moving towards the top. Use first view as mMotionPosition
//                    mMotionPosition = mFirstPosition;
//                    final View firstView = getChildAt(0);
//                    mMotionViewOriginalTop = firstView.getTop();
//
//                    // Don't fling more than 1 screen
//                    delta = Math.min(getHeight() - mPaddingBottom - mPaddingTop - 1, delta);
//                } else {
//                    // List is moving towards the bottom. Use last view as mMotionPosition
//                    int offsetToLast = getChildCount() - 1;
//                    mMotionPosition = mFirstPosition + offsetToLast;
//
//                    final View lastView = getChildAt(offsetToLast);
//                    mMotionViewOriginalTop = lastView.getTop();
//
//                    // Don't fling more than 1 screen
//                    delta = Math.max(-(getHeight() - mPaddingBottom - mPaddingTop - 1), delta);
//                }

                Layout layout = mWidget.getLayout();

                int padding = mWidget.getTotalPaddingTop() +
                                mWidget.getTotalPaddingBottom();

                y = Math.min(y, layout.getHeight() - (mWidget.getHeight() -
                                                        padding));
                y = Math.max(y, 0);
//                final boolean atEnd = trackMotionScroll(delta, delta);

                Touch.scrollTo( mWidget , layout , x , y );
                int delta = mLastFlingY - y;

                if (more && delta != 0) {
                    mWidget.invalidate();
                    mLastFlingY = y;
                    mWidget.post(this);
                } else {
                    endFling();

//                    if (PROFILE_FLINGING) {
//                        if (mFlingProfilingStarted) {
//                            Debug.stopMethodTracing();
//                            mFlingProfilingStarted = false;
//                        }
//                    }
                }
                break;
            }
            }

        }
 
Example 12
Source File: ZrcAbsListView.java    From ZrcListView with MIT License 4 votes vote down vote up
@Override
public void run() {
	switch (mTouchMode) {
	default:
		endFling();
		return;
	case TOUCH_MODE_SCROLL:
		if (mScroller.isFinished()) {
			return;
		}
	case TOUCH_MODE_RESCROLL:
	case TOUCH_MODE_FLING: {
		if (mDataChanged) {
			layoutChildren();
		}
		final Scroller scroller = mScroller;
		boolean more = scroller.computeScrollOffset();
		final int y = scroller.getCurrY();
		final int mPaddingBottom = getPaddingBottom();
		final int mPaddingTop = getPaddingTop();
		int delta = mLastFlingY - y;
		if (delta > 0) {
			mMotionPosition = mFirstPosition;
			delta = Math.min(getHeight() - mPaddingBottom - mPaddingTop
					- 1, delta);
		} else {
			int offsetToLast = getChildCount() - 1;
			mMotionPosition = mFirstPosition + offsetToLast;
			delta = Math.max(-(getHeight() - mPaddingBottom
					- mPaddingTop - 1), delta);
		}
		final boolean atEdge = trackMotionScroll(delta, delta);
		final boolean atEnd = atEdge && (delta != 0);
		final int touchMode = mTouchMode;
		if (atEnd) {
			endFling();
			if (touchMode == TOUCH_MODE_FLING) {
				scrollToAdjustViewsUpOrDown();
			}
			break;
		}
		if (more && !atEnd) {
			mLastFlingY = y;
			ViewCompat.postOnAnimation(ZrcAbsListView.this, this);
		} else {
			endFling();
			if (touchMode == TOUCH_MODE_FLING) {
				scrollToAdjustViewsUpOrDown();
			}
		}
		break;
	}
	}
}
 
Example 13
Source File: PLA_AbsListView.java    From EverMemo with MIT License 4 votes vote down vote up
public void run() {
	switch (mTouchMode) {
	default:
		return;

	case TOUCH_MODE_FLING: {
		if (mItemCount == 0 || getChildCount() == 0) {
			endFling();
			return;
		}

		final Scroller scroller = mScroller;
		boolean more = scroller.computeScrollOffset();
		final int y = scroller.getCurrY();

		// Flip sign to convert finger direction to list items direction
		// (e.g. finger moving down means list is moving towards the top)
		int delta = mLastFlingY - y;

		// Pretend that each frame of a fling scroll is a touch scroll
		if (delta > 0) {
			// List is moving towards the top. Use first view as mMotionPosition
			mMotionPosition = mFirstPosition;
			//final View firstView = getChildAt(0);
			//mMotionViewOriginalTop = firstView.getTop();
			mMotionViewOriginalTop = getScrollChildTop();

			// Don't fling more than 1 screen
			//                    delta = Math.min(getHeight() - mPaddingBottom - mPaddingTop - 1, delta);
			delta = Math.min(getHeight() - getPaddingBottom() - getPaddingTop() - 1, delta);
		} else {
			// List is moving towards the bottom. Use last view as mMotionPosition
			int offsetToLast = getChildCount() - 1;
			mMotionPosition = mFirstPosition + offsetToLast;

			//final View lastView = getChildAt(offsetToLast);
			//mMotionViewOriginalTop = lastView.getTop();
			mMotionViewOriginalTop = getScrollChildBottom();

			// Don't fling more than 1 screen
			// delta = Math.max(-(getHeight() - mPaddingBottom - mPaddingTop - 1), delta);
			delta = Math.max(-(getHeight() - getPaddingBottom() - getPaddingTop() - 1), delta);
		}

		final boolean atEnd = trackMotionScroll(delta, delta);

		if (more && !atEnd) {
			invalidate();
			mLastFlingY = y;
			post(this);
		} else {
			endFling();
			if (PROFILE_FLINGING) {
				if (mFlingProfilingStarted) {
					Debug.stopMethodTracing();
					mFlingProfilingStarted = false;
				}
			}
		}
		break;
	}
	}
}
 
Example 14
Source File: PLAAbsListView.java    From SimplifyReader with Apache License 2.0 4 votes vote down vote up
public void run() {
    switch (mTouchMode) {
        default:
            return;

        case TOUCH_MODE_FLING: {
            if (mItemCount == 0 || getChildCount() == 0) {
                endFling();
                return;
            }

            final Scroller scroller = mScroller;
            boolean more = scroller.computeScrollOffset();
            final int y = scroller.getCurrY();

            // Flip sign to convert finger direction to list items direction
            // (e.g. finger moving down means list is moving towards the top)
            int delta = mLastFlingY - y;

            // Pretend that each frame of a fling scroll is a touch scroll
            if (delta > 0) {
                // List is moving towards the top. Use first view as mMotionPosition
                mMotionPosition = mFirstPosition;
                //final View firstView = getChildAt(0);
                //mMotionViewOriginalTop = firstView.getTop();
                mMotionViewOriginalTop = getScrollChildTop();

                // Don't fling more than 1 screen
                // delta = Math.min(getHeight() - mPaddingBottom - mPaddingTop - 1, delta);
                delta = Math.min(getHeight() - getPaddingBottom() - getPaddingTop() - 1, delta);
            } else {
                // List is moving towards the bottom. Use last view as mMotionPosition
                int offsetToLast = getChildCount() - 1;
                mMotionPosition = mFirstPosition + offsetToLast;

                //final View lastView = getChildAt(offsetToLast);
                //mMotionViewOriginalTop = lastView.getTop();
                mMotionViewOriginalTop = getScrollChildBottom();

                // Don't fling more than 1 screen
                // delta = Math.max(-(getHeight() - mPaddingBottom - mPaddingTop - 1), delta);
                delta = Math.max(-(getHeight() - getPaddingBottom() - getPaddingTop() - 1), delta);
            }

            final boolean atEnd = trackMotionScroll(delta, delta);

            if (more && !atEnd) {
                invalidate();
                mLastFlingY = y;
                post(this);
            } else {
                endFling();
                if (PROFILE_FLINGING) {
                    if (mFlingProfilingStarted) {
                        Debug.stopMethodTracing();
                        mFlingProfilingStarted = false;
                    }
                }
            }
            break;
        }
    }
}
 
Example 15
Source File: TwoWayAbsListView.java    From recent-images with MIT License 4 votes vote down vote up
@Override
public void run() {
	if (mTouchMode == TOUCH_MODE_FLING) {
		if (mItemCount == 0 || getChildCount() == 0) {
			endFling();
			return;
		}

		final Scroller scroller = mScroller;
		boolean more = scroller.computeScrollOffset();
		final int x = scroller.getCurrX();

		// Flip sign to convert finger direction to list items direction
		// (e.g. finger moving down means list is moving towards the top)
		int delta = mLastFlingX - x;

		// Pretend that each frame of a fling scroll is a touch scroll
		if (delta > 0) {
			// List is moving towards the top. Use first view as mMotionPosition
			mMotionPosition = mFirstPosition;
			final View firstView = getChildAt(0);
			mMotionViewOriginalLeft = firstView.getLeft();

			// Don't fling more than 1 screen
			delta = Math.min(getWidth() - getPaddingRight() - getPaddingLeft() - 1, delta);
		} else {
			// List is moving towards the bottom. Use last view as mMotionPosition
			int offsetToLast = getChildCount() - 1;
			mMotionPosition = mFirstPosition + offsetToLast;

			final View lastView = getChildAt(offsetToLast);
			mMotionViewOriginalLeft = lastView.getLeft();

			// Don't fling more than 1 screen
			delta = Math.max(-(getWidth() - getPaddingRight() - getPaddingLeft() - 1), delta);
		}

		final boolean atEnd = trackMotionScroll(delta, delta);

		if (more && !atEnd) {
			invalidate();
			mLastFlingX = x;
			post(this);
		} else {
			endFling();

			if (PROFILE_FLINGING && mFlingProfilingStarted) {
				Debug.stopMethodTracing();
				mFlingProfilingStarted = false;
			}
		}
	} else {
		return;
	}

}
 
Example 16
Source File: TwoWayAbsListView.java    From recent-images with MIT License 4 votes vote down vote up
@Override
public void run() {
	if (mTouchMode == TOUCH_MODE_FLING) {
		if (mItemCount == 0 || getChildCount() == 0) {
			endFling();
			return;
		}

		final Scroller scroller = mScroller;
		boolean more = scroller.computeScrollOffset();
		final int y = scroller.getCurrY();

		// Flip sign to convert finger direction to list items direction
		// (e.g. finger moving down means list is moving towards the top)
		int delta = mLastFlingY - y;

		// Pretend that each frame of a fling scroll is a touch scroll
		if (delta > 0) {
			// List is moving towards the top. Use first view as mMotionPosition
			mMotionPosition = mFirstPosition;
			final View firstView = getChildAt(0);
			mMotionViewOriginalTop = firstView.getTop();

			// Don't fling more than 1 screen
			delta = Math.min(getHeight() - getPaddingBottom() - getPaddingTop() - 1, delta);
		} else {
			// List is moving towards the bottom. Use last view as mMotionPosition
			int offsetToLast = getChildCount() - 1;
			mMotionPosition = mFirstPosition + offsetToLast;

			final View lastView = getChildAt(offsetToLast);
			mMotionViewOriginalTop = lastView.getTop();

			// Don't fling more than 1 screen
			delta = Math.max(-(getHeight() - getPaddingBottom() - getPaddingTop() - 1), delta);
		}

		final boolean atEnd = trackMotionScroll(delta, delta);

		if (more && !atEnd) {
			invalidate();
			mLastFlingY = y;
			post(this);
		} else {
			endFling();

			if (PROFILE_FLINGING && mFlingProfilingStarted) {
				Debug.stopMethodTracing();
				mFlingProfilingStarted = false;
			}
		}
	} else {
		return;
	}

}
 
Example 17
Source File: EcoGallery.java    From samples with Apache License 2.0 4 votes vote down vote up
public void run() {

            if (mItemCount == 0) {
                endFling(true);
                return;
            }

            mShouldStopFling = false;

            final Scroller scroller = mScroller;
            boolean more = scroller.computeScrollOffset();
            final int x = scroller.getCurrX();

            // Flip sign to convert finger direction to list items direction
            // (e.g. finger moving down means list is moving towards the top)
            int delta = mLastFlingX - x;

            // Pretend that each frame of a fling scroll is a touch scroll
            if (delta > 0) {
                // Moving towards the left. Use first view as mDownTouchPosition
                mDownTouchPosition = mFirstPosition;

                // Don't fling more than 1 screen
                delta = Math.min(getWidth() - getPaddingLeft() - getPaddingRight() - 1, delta);
            } else {
                // Moving towards the right. Use last view as mDownTouchPosition
                int offsetToLast = getChildCount() - 1;
                mDownTouchPosition = mFirstPosition + offsetToLast;

                // Don't fling more than 1 screen
                delta = Math.max(-(getWidth() - getPaddingRight() - getPaddingLeft() - 1), delta);
            }

            trackMotionScroll(delta);

            if (more && !mShouldStopFling) {
                mLastFlingX = x;
                post(this);
            } else {
                endFling(true);
            }
        }
 
Example 18
Source File: ExtendableListView.java    From UltimateAndroid with Apache License 2.0 4 votes vote down vote up
public void run() {
    switch (mTouchMode) {
        default:
            return;

        case TOUCH_MODE_FLINGING: {
            if (mItemCount == 0 || getChildCount() == 0) {
                endFling();
                return;
            }

            final Scroller scroller = mScroller;
            boolean more = scroller.computeScrollOffset();
            final int y = scroller.getCurrY();

            // Flip sign to convert finger direction to list items direction
            // (e.g. finger moving down means list is moving towards the top)
            int delta = mLastFlingY - y;

            // Pretend that each frame of a fling scroll is a touch scroll
            if (delta > 0) {
                // List is moving towards the top. Use first view as mMotionPosition
                mMotionPosition = mFirstPosition;
                // Don't fling more than 1 screen
                delta = Math.min(getHeight() - getPaddingBottom() - getPaddingTop() - 1, delta);
            }
            else {
                // List is moving towards the bottom. Use last view as mMotionPosition
                int offsetToLast = getChildCount() - 1;
                mMotionPosition = mFirstPosition + offsetToLast;

                // Don't fling more than 1 screen
                delta = Math.max(-(getHeight() - getPaddingBottom() - getPaddingTop() - 1), delta);
            }

            final boolean atEnd = moveTheChildren(delta, delta);

            if (more && !atEnd) {
                invalidate();
                mLastFlingY = y;
                postOnAnimate(this);
            }
            else {
                endFling();
            }
            break;
        }
    }
}
 
Example 19
Source File: ZrcAbsListView.java    From AndroidStudyDemo with GNU General Public License v2.0 4 votes vote down vote up
@Override
public void run() {
    switch (mTouchMode) {
    default:
        endFling();
        return;
    case TOUCH_MODE_SCROLL:
        if (mScroller.isFinished()) {
            return;
        }
    case TOUCH_MODE_RESCROLL:
    case TOUCH_MODE_FLING: {
        if (mDataChanged) {
            layoutChildren();
        }
        final Scroller scroller = mScroller;
        boolean more = scroller.computeScrollOffset();
        final int y = scroller.getCurrY();
        final int mPaddingBottom = getPaddingBottom();
        final int mPaddingTop = getPaddingTop();
        int delta = mLastFlingY - y;
        if (delta > 0) {
            mMotionPosition = mFirstPosition;
            delta = Math.min(getHeight() - mPaddingBottom - mPaddingTop - 1, delta);
        } else {
            int offsetToLast = getChildCount() - 1;
            mMotionPosition = mFirstPosition + offsetToLast;
            delta = Math.max(-(getHeight() - mPaddingBottom - mPaddingTop - 1), delta);
        }
        final boolean atEdge = trackMotionScroll(delta, delta);
        final boolean atEnd = atEdge && (delta != 0);
        final int touchMode = mTouchMode;
        if (atEnd) {
            endFling();
            if (touchMode == TOUCH_MODE_FLING) {
                scrollToAdjustViewsUpOrDown();
            }
            break;
        }
        if (more && !atEnd) {
            mLastFlingY = y;
            ViewCompat.postOnAnimation(ZrcAbsListView.this, this);
        } else {
            endFling();
            if (touchMode == TOUCH_MODE_FLING) {
                scrollToAdjustViewsUpOrDown();
            }
        }
        break;
    }
    }
}
 
Example 20
Source File: ExtendableListView.java    From UltimateAndroid with Apache License 2.0 4 votes vote down vote up
public void run() {
    switch (mTouchMode) {
        default:
            return;

        case TOUCH_MODE_FLINGING: {
            if (mItemCount == 0 || getChildCount() == 0) {
                endFling();
                return;
            }

            final Scroller scroller = mScroller;
            boolean more = scroller.computeScrollOffset();
            final int y = scroller.getCurrY();

            // Flip sign to convert finger direction to list items direction
            // (e.g. finger moving down means list is moving towards the top)
            int delta = mLastFlingY - y;

            // Pretend that each frame of a fling scroll is a touch scroll
            if (delta > 0) {
                // List is moving towards the top. Use first view as mMotionPosition
                mMotionPosition = mFirstPosition;
                // Don't fling more than 1 screen
                delta = Math.min(getHeight() - getPaddingBottom() - getPaddingTop() - 1, delta);
            }
            else {
                // List is moving towards the bottom. Use last view as mMotionPosition
                int offsetToLast = getChildCount() - 1;
                mMotionPosition = mFirstPosition + offsetToLast;

                // Don't fling more than 1 screen
                delta = Math.max(-(getHeight() - getPaddingBottom() - getPaddingTop() - 1), delta);
            }

            final boolean atEnd = moveTheChildren(delta, delta);

            if (more && !atEnd) {
                invalidate();
                mLastFlingY = y;
                postOnAnimate(this);
            }
            else {
                endFling();
            }
            break;
        }
    }
}