Code example for Scroller

Methods: getCurrX, getCurrY, getFinalX, getFinalY, startScroll

0
		int screenWidth  = getWidth();
		int screenHeight = getHeight();
		// We might be mid scroll; we want to calculate where we scroll to based on 
		// where this scroll would end, not where we are now (to allow for people 
		// bashing 'forwards' very fast. 
		int remainingX = mScroller.getFinalX() - mScroller.getCurrX();
		int remainingY = mScroller.getFinalY() - mScroller.getCurrY();
		// right/bottom is in terms of pixels within the scaled document; e.g. 1000 
		int top = -(v.getTop()  + mYScroll + remainingY);
		int right  = screenWidth -(v.getLeft() + mXScroll + remainingX);
		int bottom = screenHeight+top;
		// docWidth/Height are the width/height of the scaled document e.g. 2000x3000 
		int docWidth  = v.getMeasuredWidth();
		int docHeight = v.getMeasuredHeight();
 
		int xOffset, yOffset;
		if (bottom >= docHeight) {
			// We are flush with the bottom. Advance to next column. 
			if (right + screenWidth > docWidth) {
				// No room for another column - go to next page 
				View nv = mChildViews.get(mCurrent+1);
				if (nv == null) // No page to advance to
					return; 
				int nextTop  = -(nv.getTop() + mYScroll + remainingY);
				int nextLeft = -(nv.getLeft() + mXScroll + remainingX);
				int nextDocWidth = nv.getMeasuredWidth();
				int nextDocHeight = nv.getMeasuredHeight();
 
				// Allow for the next page maybe being shorter than the screen is high 
				yOffset = (nextDocHeight < screenHeight ? ((nextDocHeight - screenHeight)>>1) : 0);
 
				if (nextDocWidth < screenWidth) {
					// Next page is too narrow to fill the screen. Scroll to the top, centred. 
					xOffset = (nextDocWidth - screenWidth)>>1;
				} else { 
					// Reset X back to the left hand column 
					xOffset = right % screenWidth;
					// Adjust in case the previous page is less wide 
					if (xOffset + screenWidth > nextDocWidth)
						xOffset = nextDocWidth - screenWidth;
				} 
				xOffset -= nextLeft;
				yOffset -= nextTop;
			} else { 
				// Move to top of next column 
				xOffset = screenWidth;
				yOffset = screenHeight - bottom;
			} 
		} else { 
			// Advance by 90% of the screen height downwards (in case lines are partially cut off) 
			xOffset = 0;
			yOffset = smartAdvanceAmount(screenHeight, docHeight - bottom);
		} 
		mScrollerLastX = mScrollerLastY = 0;
		mScroller.startScroll(0, 0, remainingX - xOffset, remainingY - yOffset, 400);
		post(this);
	} 
 
	public void smartMoveBackwards() { 
		View v = mChildViews.get(mCurrent);