示例#1
0
  private void pushPageInternal(
      final Page newPage,
      final Page oldPage,
      final Object arg,
      boolean animated,
      PageAnimator.AnimationDirection animationDirection) {
    if (animated) {
      mAnimating = true;
    }

    newPage.onShow(arg);

    if (oldPage != null) {
      if (animated) {
        // when a new page is being pushed, ensures the oldPage always be visible during the
        // animation
        // transition if animated is true
        oldPage.getView().bringToFront();
      }

      oldPage.onCover();
    }

    mCurPage = newPage;
    mPageStack.addLast(newPage);
    mContainerView.addView(newPage.getView());
    newPage.onAttached();

    mViewTransparentMask.bringToFront();

    if (mEnableDebug) {
      Log.d(
          TAG,
          String.format(
              ">>>> pushPage, pagestack=%d, %s, arg=%s", mPageStack.size(), newPage, arg));
    }

    if (animated
        && mPageAnimator != null
        && !newPage.onPushPageAnimation(oldPage, newPage, animationDirection)) {
      mPageAnimator.onPushPageAnimation(oldPage, newPage, animationDirection);
    }

    int animationDuration = newPage.getAnimationDuration();
    if (animationDuration == -1 && mPageAnimator != null) {
      animationDuration = mPageAnimator.getAnimationDuration();
    }
    if (animated && animationDuration != -1) {
      newPage.postDelayed(
          new Runnable() {
            @Override
            public void run() {
              doFinalWorkForPushPage(oldPage, newPage, arg);
            }
          },
          animationDuration);
    } else {
      doFinalWorkForPushPage(oldPage, newPage, arg);
    }
  }
示例#2
0
  private void popPageInternal(
      final Page removedPage,
      boolean animated,
      PageAnimator.AnimationDirection animationDirection) {
    if (mEnableDebug) {
      Log.d(TAG, String.format(">>>> popPage, pagestack=%d, %s", mPageStack.size(), removedPage));
    }

    removedPage.onHide();

    final Page prevPage;
    if (mPageStack.size() > 0) { // this check is always necessary
      prevPage = mPageStack.getLast();
      prevPage.onUncover(removedPage.getReturnData());

      if (animated
          && mPageAnimator != null
          && !removedPage.onPopPageAnimation(removedPage, prevPage, animationDirection)) {
        mPageAnimator.onPopPageAnimation(removedPage, prevPage, animationDirection);
      }

      prevPage.getView().setVisibility(View.VISIBLE);
    } else {
      prevPage = null;

      if (animated
          && mPageAnimator != null
          && !removedPage.onPopPageAnimation(removedPage, null, animationDirection)) {
        mPageAnimator.onPopPageAnimation(removedPage, null, animationDirection);
      }
    }

    mViewTransparentMask.bringToFront();
    mCurPage = prevPage;

    int animationDuration = removedPage.getAnimationDuration();
    if (animationDuration == -1 && mPageAnimator != null) {
      animationDuration = mPageAnimator.getAnimationDuration();
    }
    if (animated && animationDuration != -1) {
      removedPage.postDelayed(
          new Runnable() {
            @Override
            public void run() {
              doFinalWorkForPopPageInternal(removedPage, prevPage);
            }
          },
          animationDuration);

    } else {
      doFinalWorkForPopPageInternal(removedPage, prevPage);
    }
  }