boolean pageRight() { if (mAdapter != null && mCurItem < (getAdapterCount() - 1)) { setCurrentItem(mCurItem + 1, true); return true; } return false; }
void setCurrentItemInternalHorizontal(int item, boolean smoothScroll, boolean always, int velocity) { if (mAdapter == null || getAdapterCount() <= 0) { setScrollingCacheEnabled(false); return; } else if (item >= getAdapterCount()) { item = getAdapterCount() - 1;
void setCurrentItemInternalVertical(int item, boolean smoothScroll, boolean always, int velocity) { if (mAdapter == null || getAdapterCount() <= 0) { setScrollingCacheEnabled(false); return; } else if (item >= getAdapterCount()) { item = getAdapterCount() - 1;
/** * Set the currently selected page. * * @param item Item index to select * @param smoothScroll True to smoothly scroll to the new item, false to transition immediately */ public void setCurrentItem(int item, boolean smoothScroll) { mPopulatePending = false; if (item >= mAdapter.getCount()) { throw new IllegalArgumentException("adapter's count is:" + mAdapter.getCount() + ",but you set the position" + "is:" + item + ",it bigger than the max count"); } else if (item < 0) { throw new IllegalArgumentException("you set the position" + "is:" + item + ",it less than 0"); } int newPos = 0; if (mCurrentStartPos == 0) { //init status newPos = isCirculatory ? getAdapterCount() / 2 + item : item; } else { //already scrolled status newPos = isCirculatory ? mCurrentStartPos + item : item; } if (isVertical) { setCurrentItemInternalVertical(newPos, smoothScroll, false); } else { setCurrentItemInternalHorizontal(newPos, smoothScroll, false); } }
/** * Set the currently selected page. If the ViewPager has already been through its first * layout with its current adapter there will be a smooth animated transition between * the current item and the specified item. * * @param item Item index to select */ public void setCurrentItem(int item) { mPopulatePending = false; if (item >= mAdapter.getCount()) { throw new IllegalArgumentException("adapter's count is" + mAdapter.getCount() + ",but you set the position" + "is:" + item + ",it bigger than the max count"); } else if (item < 0) { throw new IllegalArgumentException("you set the position" + "is:" + item + ",it less than 0"); } int newPos = 0; if (mCurrentStartPos == 0) { //init status newPos = isCirculatory ? getAdapterCount() / 2 + item : item; } else { //already scrolled status newPos = isCirculatory ? mCurrentStartPos + item : item; } if (isVertical) { setCurrentItemInternalVertical(newPos, !mFirstLayout, false); } else { setCurrentItemInternalHorizontal(newPos, !mFirstLayout, false); } }
private void calculatePageOffsetsHorizontal(ItemInfo curItem, int curIndex, ItemInfo oldCurInfo) { final int N = getAdapterCount(); final int width = getClientWidth(); final float marginOffset = width > 0 ? (float) mPageMargin / width : 0;
private void calculatePageOffsetsVertical(ItemInfo curItem, int curIndex, ItemInfo oldCurInfo) { final int N = getAdapterCount(); final int height = getClientHeight(); final float marginOffset = height > 0 ? (float) mPageMargin / height : 0;
if (lastItem.position != getAdapterCount() - 1) { bottomAbsolute = false; bottomBound = lastItem.offset * height;
if (lastItem.position != getAdapterCount() - 1) { rightAbsolute = false; rightBound = lastItem.offset * width;
void dataSetChanged() { final int adapterCount = getAdapterCount(); mExpectedAdapterCount = adapterCount; boolean needPopulate = mItems.size() < mOffscreenPageLimit * 2 + 1
removeNonDecorViews(); mCurItem = isCirculatory ? getAdapterCount() / 2 : 0; Log.d(TAG, "setAdapter() mCurItem1=>" + mCurItem); scrollTo(0, 0); final boolean wasFirstLayout = mFirstLayout; mFirstLayout = true; mExpectedAdapterCount = getAdapterCount(); mCurItem = isCirculatory ? getAdapterCount() / 2 : 0; Log.d(TAG, "setAdapter() mCurItem2=>" + mCurItem); if (mRestoredCurItem >= 0) {
final int N = getAdapterCount(); final int endPos = Math.min(N - 1, mCurItem + pageLimit); if (N != mExpectedAdapterCount) {
final int startPos = Math.max(0, mCurItem - pageLimit); final int N = getAdapterCount(); final int endPos = Math.min(N - 1, mCurItem + pageLimit); if (N != mExpectedAdapterCount) {
if (overScrollMode == View.OVER_SCROLL_ALWAYS || (overScrollMode == View.OVER_SCROLL_IF_CONTENT_SCROLLS && mAdapter != null && getAdapterCount() > 1)) { if (!isVertical && !mLeftEdge.isFinished()) { final int restoreCount = canvas.save();
if (mAdapter == null || getAdapterCount() == 0) {