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

The following examples show how to use android.widget.Scroller#getCurrY() . 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 iGap-Android with GNU Affero General Public License v3.0 6 votes vote down vote up
private boolean moveToFinalScrollerPosition(Scroller scroller) {
    scroller.forceFinished(true);
    int amountToScroll = scroller.getFinalY() - scroller.getCurrY();
    int futureScrollOffset = (mCurrentScrollOffset + amountToScroll) % mSelectorElementHeight;
    int overshootAdjustment = mInitialScrollOffset - futureScrollOffset;
    if (overshootAdjustment != 0) {
        if (Math.abs(overshootAdjustment) > mSelectorElementHeight / 2) {
            if (overshootAdjustment > 0) {
                overshootAdjustment -= mSelectorElementHeight;
            } else {
                overshootAdjustment += mSelectorElementHeight;
            }
        }
        amountToScroll += overshootAdjustment;
        scrollBy(0, amountToScroll);
        return true;
    }
    return false;
}
 
Example 2
Source File: NumberPicker.java    From iGap-Android with GNU Affero General Public License v3.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: 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 4
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 5
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 6
Source File: NumberPicker.java    From ticdesign with Apache License 2.0 6 votes vote down vote up
/**
 * Move to the final position of a scroller. Ensures to force finish the scroller
 * and if it is not at its final position a scroll of the selector wheel is
 * performed to fast forward to the final position.
 *
 * @param scroller The scroller to whose final position to get.
 * @return True of the a move was performed, i.e. the scroller was not in final position.
 */
private boolean moveToFinalScrollerPosition(Scroller scroller) {
    scroller.forceFinished(true);
    int amountToScroll = scroller.getFinalY() - scroller.getCurrY();
    int futureScrollOffset = (mCurrentScrollOffset + amountToScroll) % mSelectorElementHeight;
    int overshootAdjustment = mInitialScrollOffset - futureScrollOffset;
    if (overshootAdjustment != 0) {
        if (Math.abs(overshootAdjustment) > mSelectorElementHeight / 2) {
            if (overshootAdjustment > 0) {
                overshootAdjustment -= mSelectorElementHeight;
            } else {
                overshootAdjustment += mSelectorElementHeight;
            }
        }
        amountToScroll += overshootAdjustment;
        amountToScroll %= mSelectorElementHeight;
        scrollBy(0, amountToScroll);
        return true;
    }
    return false;
}
 
Example 7
Source File: NumberPicker.java    From ticdesign 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 8
Source File: NumberPicker.java    From NewXmPluginSDK with Apache License 2.0 6 votes vote down vote up
/**
 * Move to the final position of a scroller. Ensures to force finish the scroller
 * and if it is not at its final position a scroll of the selector wheel is
 * performed to fast forward to the final position.
 *
 * @param scroller The scroller to whose final position to get.
 * @return True of the a move was performed, i.e. the scroller was not in final position.
 */
private boolean moveToFinalScrollerPosition(Scroller scroller) {
    scroller.forceFinished(true);
    int amountToScroll = scroller.getFinalY() - scroller.getCurrY();
    int futureScrollOffset = (mCurrentScrollOffset + amountToScroll) % mSelectorElementHeight;
    int overshootAdjustment = mInitialScrollOffset - futureScrollOffset;
    if (overshootAdjustment != 0) {
        if (Math.abs(overshootAdjustment) > mSelectorElementHeight / 2) {
            if (overshootAdjustment > 0) {
                overshootAdjustment -= mSelectorElementHeight;
            } else {
                overshootAdjustment += mSelectorElementHeight;
            }
        }
        amountToScroll += overshootAdjustment;
        scrollBy(0, amountToScroll);
        return true;
    }
    return false;
}
 
Example 9
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 10
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 11
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 12
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 13
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 14
Source File: ExtendableListView.java    From PullToRefreshLibrary 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 15
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 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: 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 18
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 19
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 20
Source File: Touch.java    From PowerFileExplorer with GNU General Public License v3.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;
            }
            }

        }