示例#1
0
  @Override
  public void onDrawFrame() {
    // We are not animating.
    if (mAnimate == false) {
      return;
    }

    long currentTime = System.currentTimeMillis();
    // If animation is done.
    if (currentTime >= mAnimationStartTime + mAnimationDurationTime) {
      if (mAnimationTargetEvent == SET_CURL_TO_RIGHT) {
        // Switch curled page to right.
        CurlMesh right = mPageCurl;
        CurlMesh curl = mPageRight;
        right.setRect(mRenderer.getPageRect(CurlRenderer.PAGE_RIGHT));
        right.setFlipTexture(false);
        right.reset();
        mRenderer.removeCurlMesh(curl);
        mPageCurl = curl;
        mPageRight = right;
        // If we were curling left page update current index.
        if (mCurlState == CURL_LEFT) {
          --mCurrentIndex;
        }
      } else if (mAnimationTargetEvent == SET_CURL_TO_LEFT) {
        // Switch curled page to left.
        CurlMesh left = mPageCurl;
        CurlMesh curl = mPageLeft;
        left.setRect(mRenderer.getPageRect(CurlRenderer.PAGE_LEFT));
        left.setFlipTexture(true);
        left.reset();
        mRenderer.removeCurlMesh(curl);
        if (!mRenderLeftPage) {
          mRenderer.removeCurlMesh(left);
        }
        mPageCurl = curl;
        mPageLeft = left;
        // If we were curling right page update current index.
        if (mCurlState == CURL_RIGHT) {
          ++mCurrentIndex;
        }
      }
      mCurlState = CURL_NONE;
      mAnimate = false;
      requestRender();
    } else {
      mPointerPos.mPos.set(mAnimationSource);
      float t = 1f - ((float) (currentTime - mAnimationStartTime) / mAnimationDurationTime);
      t = 1f - (t * t * t * (3 - 2 * t));
      mPointerPos.mPos.x += (mAnimationTarget.x - mAnimationSource.x) * t;
      mPointerPos.mPos.y += (mAnimationTarget.y - mAnimationSource.y) * t;
      updateCurlPos(mPointerPos);
    }
  }
示例#2
0
  /** Updates bitmaps for page meshes. */
  private void updatePages() {
    Log.d("artbook", ">>>>>update page(s): " + Thread.currentThread());
    if (mPageProvider == null || mPageBitmapWidth <= 0 || mPageBitmapHeight <= 0) {
      return;
    }

    // Remove meshes from renderer.
    mRenderer.removeCurlMesh(mPageLeft);
    mRenderer.removeCurlMesh(mPageRight);
    mRenderer.removeCurlMesh(mPageCurl);

    int leftIdx = mCurrentIndex - 1;
    int rightIdx = mCurrentIndex;
    int curlIdx = -1;
    if (mCurlState == CURL_LEFT) {
      curlIdx = leftIdx;
      --leftIdx;
    } else if (mCurlState == CURL_RIGHT) {
      curlIdx = rightIdx;
      ++rightIdx;
    }

    if (rightIdx >= 0 && rightIdx < mPageProvider.getPageCount()) {
      updatePage(mPageRight.getTexturePage(), rightIdx);
      mPageRight.setFlipTexture(false);
      mPageRight.setRect(mRenderer.getPageRect(CurlRenderer.PAGE_RIGHT));
      mPageRight.reset();
      mRenderer.addCurlMesh(mPageRight);
    }
    if (leftIdx >= 0 && leftIdx < mPageProvider.getPageCount()) {
      updatePage(mPageLeft.getTexturePage(), leftIdx);
      mPageLeft.setFlipTexture(true);
      mPageLeft.setRect(mRenderer.getPageRect(CurlRenderer.PAGE_LEFT));
      mPageLeft.reset();
      if (mRenderLeftPage) {
        mRenderer.addCurlMesh(mPageLeft);
      }
    }
    if (curlIdx >= 0 && curlIdx < mPageProvider.getPageCount()) {
      updatePage(mPageCurl.getTexturePage(), curlIdx);

      if (mCurlState == CURL_RIGHT) {
        mPageCurl.setFlipTexture(true);
        mPageCurl.setRect(mRenderer.getPageRect(CurlRenderer.PAGE_RIGHT));
      } else {
        mPageCurl.setFlipTexture(false);
        mPageCurl.setRect(mRenderer.getPageRect(CurlRenderer.PAGE_LEFT));
      }

      mPageCurl.reset();
      mRenderer.addCurlMesh(mPageCurl);
    }
  }
示例#3
0
  /** Switches meshes and loads new bitmaps if available. Updated to support 2 pages in landscape */
  private void startCurl(int page) {
    switch (page) {

        // Once right side page is curled, first right page is assigned into
        // curled page. And if there are more bitmaps available new bitmap is
        // loaded into right side mesh.
      case CURL_RIGHT:
        {
          // Remove meshes from renderer.
          mRenderer.removeCurlMesh(mPageLeft);
          mRenderer.removeCurlMesh(mPageRight);
          mRenderer.removeCurlMesh(mPageCurl);

          // We are curling right page.
          CurlMesh curl = mPageRight;
          mPageRight = mPageCurl;
          mPageCurl = curl;

          if (mCurrentIndex > 0) {
            mPageLeft.setFlipTexture(true);
            mPageLeft.setRect(mRenderer.getPageRect(CurlRenderer.PAGE_LEFT));
            mPageLeft.reset();
            if (mRenderLeftPage) {
              mRenderer.addCurlMesh(mPageLeft);
            }
          }
          if (mCurrentIndex < mPageProvider.getPageCount() - 1) {
            updatePage(mPageRight.getTexturePage(), mCurrentIndex + 1);
            mPageRight.setRect(mRenderer.getPageRect(CurlRenderer.PAGE_RIGHT));
            mPageRight.setFlipTexture(false);
            mPageRight.reset();
            mRenderer.addCurlMesh(mPageRight);
          }

          // Add curled page to renderer.
          mPageCurl.setRect(mRenderer.getPageRect(CurlRenderer.PAGE_RIGHT));
          mPageCurl.setFlipTexture(false);
          mPageCurl.reset();
          mRenderer.addCurlMesh(mPageCurl);

          mCurlState = CURL_RIGHT;
          break;
        }

        // On left side curl, left page is assigned to curled page. And if
        // there are more bitmaps available before currentIndex, new bitmap
        // is loaded into left page.
      case CURL_LEFT:
        {
          // Remove meshes from renderer.
          mRenderer.removeCurlMesh(mPageLeft);
          mRenderer.removeCurlMesh(mPageRight);
          mRenderer.removeCurlMesh(mPageCurl);

          // We are curling left page.
          CurlMesh curl = mPageLeft;
          mPageLeft = mPageCurl;
          mPageCurl = curl;

          if (mCurrentIndex > 1) {
            updatePage(mPageLeft.getTexturePage(), mCurrentIndex - 2);
            mPageLeft.setFlipTexture(true);
            mPageLeft.setRect(mRenderer.getPageRect(CurlRenderer.PAGE_LEFT));
            mPageLeft.reset();
            if (mRenderLeftPage) {
              mRenderer.addCurlMesh(mPageLeft);
            }
          }

          // If there is something to show on right page add it to renderer.
          if (mCurrentIndex < mPageProvider.getPageCount()) {
            mPageRight.setFlipTexture(false);
            mPageRight.setRect(mRenderer.getPageRect(CurlRenderer.PAGE_RIGHT));
            mPageRight.reset();
            mRenderer.addCurlMesh(mPageRight);
          }

          // How dragging previous page happens depends on view mode.
          if (mViewMode == SHOW_ONE_PAGE
              || (mCurlState == CURL_LEFT && mViewMode == SHOW_TWO_PAGES)) {
            mPageCurl.setRect(mRenderer.getPageRect(CurlRenderer.PAGE_RIGHT));
            mPageCurl.setFlipTexture(false);
          } else {
            mPageCurl.setRect(mRenderer.getPageRect(CurlRenderer.PAGE_LEFT));
            mPageCurl.setFlipTexture(true);
          }
          mPageCurl.reset();
          mRenderer.addCurlMesh(mPageCurl);

          mCurlState = CURL_LEFT;
          break;
        }
    }
  }