示例#1
0
  private void dataSetChanged() {
    final int currentPage = mCurrentPage;

    // if the adapter has stable ids, try to keep the page currently on
    // stable.
    if (mAdapter.hasStableIds() && mCurrentPage != INVALID_PAGE_POSITION) {
      mCurrentPage = getNewPositionOfCurrentPage();
    } else if (mCurrentPage == INVALID_PAGE_POSITION) {
      mCurrentPage = 0;
    }

    // remove all the current views
    removeAllViews();
    mActivePageQueue.clear();

    mPageCount = mAdapter.getCount();

    // put the current page within the new adapter range
    mCurrentPage =
        Math.min(mPageCount - 1, mCurrentPage == INVALID_PAGE_POSITION ? 0 : mCurrentPage);

    if (mCurrentPage != INVALID_PAGE_POSITION) {
      mRecycler.setViewTypeCount(mAdapter.getViewTypeCount());
      mCurrentPageId = mAdapter.getItemId(mCurrentPage);
      addView(viewForPage(mCurrentPage));
      if (mCurrentPage != currentPage) {
        flipTo(mCurrentPage);
      }
    } else {
      mPageCount = 0;
      mFlipDistance = 0;
    }

    updateEmptyStatus();
  }
示例#2
0
 public void flipBy(int delta) {
   flipTo(mCurrentPage + delta);
 }