Example #1
0
  protected void dispatchDraw(Canvas canvas) {
    Log.d(LOG_TAG, "dispatchDraw");
    super.dispatchDraw(canvas);
    if (!hasInit) {
      hasInit = true;
      indexPage = 0;
      if (mPageAdapter == null) {
        throw new RuntimeException("please set the PageAdapter on init");
      }
      totalPageNum = mPageAdapter.getCount();
      mainLayout = new LinearLayout(mContext);
      mainLayout.setLayoutParams(new LayoutParams(contentWidth, contentHeight));
      mainLayout.setBackgroundColor(0xffffffff);
      mState = BookState.READY;

      invisibleLayout = new LinearLayout(mContext);
      invisibleLayout.setLayoutParams(new LayoutParams(contentWidth, contentHeight));

      this.addView(invisibleLayout);
      this.addView(mainLayout);

      mBookView = new BookView(mContext);
      mBookView.setLayoutParams(new LayoutParams(contentWidth, contentHeight));
      this.addView(mBookView);

      updatePageView();
      invalidate();
    } else if (mState == BookState.READY) {
      mBookView.update();
    }
  }
Example #2
0
  /** 此方法做过修改,改成一页显示 */
  public void updatePageView() {
    Log.d(LOG_TAG, "updatePageView");
    if (indexPage < 0 || indexPage > totalPageNum - 1) {
      return;
    }
    invisibleLayout.removeAllViews();
    mainLayout.removeAllViews();

    /* 当前页 */
    currentPage = mPageAdapter.getView(indexPage);
    if (currentPage == null) {
      currentPage = new WhiteView(mContext);
    }
    currentPage.setLayoutParams(new LayoutParams(contentWidth, contentHeight));
    mainLayout.addView(currentPage);

    /* 背景页 */
    middlePage = new WhiteView(mContext);
    middlePage.setLayoutParams(new LayoutParams(contentWidth, contentHeight));
    invisibleLayout.addView(middlePage);

    /* 前一页 */
    prevPage = null;
    if (indexPage > 0) {
      prevPage = mPageAdapter.getView(indexPage - 1);
    }
    if (prevPage == null) {
      prevPage = new WhiteView(mContext);
    }
    prevPage.setLayoutParams(new LayoutParams(contentWidth, contentHeight));
    invisibleLayout.addView(prevPage);

    /* 后一页 */
    nextPage = null;
    if (indexPage < totalPageNum - 1) {
      nextPage = mPageAdapter.getView(indexPage + 1);
    }
    if (nextPage == null) {
      nextPage = new WhiteView(mContext);
    }
    nextPage.setLayoutParams(new LayoutParams(contentWidth, contentHeight));
    invisibleLayout.addView(nextPage);

    Log.d(LOG_TAG, "updatePageView finish");
  }