Esempio n. 1
0
  private void hideCard(int which) {
    if (isAnimating) return;
    List<Animator> animators = new ArrayList<>(mChildCount);
    final View displayingCard = getChildAt(which);
    int t = (int) (getMeasuredHeight() - (mChildCount - which) * mTitleBarHeightNoDisplay);
    ValueAnimator displayAnimator =
        ValueAnimator.ofFloat(ViewHelper.getY(displayingCard), t).setDuration(mDuration);
    displayAnimator.setTarget(displayingCard);
    final int finalT = t;
    displayAnimator.addUpdateListener(
        new ValueAnimator.AnimatorUpdateListener() {
          @Override
          public void onAnimationUpdate(ValueAnimator valueAnimator) {
            float value = (float) valueAnimator.getAnimatedValue();
            ViewHelper.setY(displayingCard, value);
            if (mDarkFrameLayout != null && isFade && value < finalT) {
              mDarkFrameLayout.fade((int) ((1 - value / finalT) * DarkFrameLayout.MAX_ALPHA));
            }
          }
        });
    animators.add(displayAnimator);
    for (int i = 0; i < mChildCount; i++) {
      if (i == 0 && isExistBackground) continue;
      if (i != which) {
        t = (int) (getMeasuredHeight() - (mChildCount - i) * mTitleBarHeightNoDisplay);
        animators.add(
            ObjectAnimator.ofFloat(getChildAt(i), "y", ViewHelper.getY(getChildAt(i)), t));
      }
    }
    AnimatorSet set = new AnimatorSet();
    set.addListener(
        new Animator.AnimatorListener() {
          @Override
          public void onAnimationStart(Animator animator) {
            isAnimating = true;
          }

          @Override
          public void onAnimationEnd(Animator animator) {
            isAnimating = false;
            isDisplaying = false;
          }

          @Override
          public void onAnimationCancel(Animator animator) {
            isAnimating = false;
            isDisplaying = false;
          }

          @Override
          public void onAnimationRepeat(Animator animator) {}
        });
    set.setInterpolator(mCloseAnimatorInterpolator);
    set.playTogether(animators);
    set.start();
    mDisplayingCard = -1;
    if (mOnDisplayOrHideListener != null)
      mOnDisplayOrHideListener.onHide(isExistBackground ? (which - 1) : which);
  }
Esempio n. 2
0
  private void displayCard(int which) {
    if (isDisplaying || isAnimating) return;
    if (isFade && mDarkFrameLayout != null) mDarkFrameLayout.fade(true);
    List<Animator> animators = new ArrayList<>(mChildCount);
    final float distance = ViewHelper.getY(getChildAt(which)) - mMarginTop;
    ValueAnimator displayAnimator =
        ValueAnimator.ofFloat(ViewHelper.getY(getChildAt(which)), mMarginTop)
            .setDuration(mDuration);
    displayAnimator.setTarget(getChildAt(which));
    final View displayingView = getChildAt(which);
    displayAnimator.addUpdateListener(
        new ValueAnimator.AnimatorUpdateListener() {
          @Override
          public void onAnimationUpdate(ValueAnimator valueAnimator) {
            float value = (float) valueAnimator.getAnimatedValue();
            ViewHelper.setY(displayingView, value);
            if (mDarkFrameLayout != null && isFade) {
              mDarkFrameLayout.fade(
                  (int) ((1 - (value - mMarginTop) / distance) * DarkFrameLayout.MAX_ALPHA));
            }
          }
        });
    animators.add(displayAnimator);
    int n = isExistBackground ? (mChildCount - 1) : mChildCount;
    for (int i = 0, j = 1; i < mChildCount; i++) {
      if (i == 0 && isExistBackground) continue;
      if (i != which) {
        animators.add(
            ObjectAnimator.ofFloat(
                    getChildAt(i),
                    "y",
                    ViewHelper.getY(getChildAt(i)),
                    getMeasuredHeight() - mTitleBarHeightDisplay * (n - j))
                .setDuration(mDuration));
        j++;
      }
    }
    AnimatorSet set = new AnimatorSet();
    set.addListener(
        new Animator.AnimatorListener() {
          @Override
          public void onAnimationStart(Animator animator) {
            isAnimating = true;
          }

          @Override
          public void onAnimationEnd(Animator animator) {
            isAnimating = false;
          }

          @Override
          public void onAnimationCancel(Animator animator) {
            isAnimating = false;
          }

          @Override
          public void onAnimationRepeat(Animator animator) {}
        });
    set.setInterpolator(mOpenAnimatorInterpolator);
    set.playTogether(animators);
    set.start();
    isDisplaying = true;
    mDisplayingCard = which;
    if (mOnDisplayOrHideListener != null)
      mOnDisplayOrHideListener.onDisplay(isExistBackground ? (which - 1) : which);
  }