Example #1
0
  protected int measureZDepthPadding(ZDepth zDepth) {
    float maxAboveBlurRadius = zDepth.getBlurTopShadowPx(getContext());
    float maxAboveOffset = zDepth.getOffsetYTopShadowPx(getContext());
    float maxBelowBlurRadius = zDepth.getBlurBottomShadowPx(getContext());
    float maxBelowOffset = zDepth.getOffsetYBottomShadowPx(getContext());

    float maxAboveSize = maxAboveBlurRadius + maxAboveOffset;
    float maxBelowSize = maxBelowBlurRadius + maxBelowOffset;

    return (int) Math.max(maxAboveSize, maxBelowSize);
  }
Example #2
0
  protected void changeZDepth(ZDepth zDepth) {

    int newAlphaTopShadow = zDepth.getAlphaTopShadow();
    int newAlphaBottomShadow = zDepth.getAlphaBottomShadow();
    float newOffsetYTopShadow = zDepth.getOffsetYTopShadowPx(getContext());
    float newOffsetYBottomShadow = zDepth.getOffsetYBottomShadowPx(getContext());
    float newBlurTopShadow = zDepth.getBlurTopShadowPx(getContext());
    float newBlurBottomShadow = zDepth.getBlurBottomShadowPx(getContext());

    if (!mZDepthDoAnimation) {
      mZDepthParam.mAlphaTopShadow = newAlphaTopShadow;
      mZDepthParam.mAlphaBottomShadow = newAlphaBottomShadow;
      mZDepthParam.mOffsetYTopShadowPx = newOffsetYTopShadow;
      mZDepthParam.mOffsetYBottomShadowPx = newOffsetYBottomShadow;
      mZDepthParam.mBlurTopShadowPx = newBlurTopShadow;
      mZDepthParam.mBlurBottomShadowPx = newBlurBottomShadow;

      mShadow.setParameter(
          mZDepthParam,
          mZDepthPaddingLeft,
          mZDepthPaddingTop,
          getWidth() - mZDepthPaddingRight,
          getHeight() - mZDepthPaddingBottom);
      invalidate();
      return;
    }

    int nowAlphaTopShadow = mZDepthParam.mAlphaTopShadow;
    int nowAlphaBottomShadow = mZDepthParam.mAlphaBottomShadow;
    float nowOffsetYTopShadow = mZDepthParam.mOffsetYTopShadowPx;
    float nowOffsetYBottomShadow = mZDepthParam.mOffsetYBottomShadowPx;
    float nowBlurTopShadow = mZDepthParam.mBlurTopShadowPx;
    float nowBlurBottomShadow = mZDepthParam.mBlurBottomShadowPx;

    PropertyValuesHolder alphaTopShadowHolder =
        PropertyValuesHolder.ofInt(
            ANIM_PROPERTY_ALPHA_TOP_SHADOW, nowAlphaTopShadow, newAlphaTopShadow);
    PropertyValuesHolder alphaBottomShadowHolder =
        PropertyValuesHolder.ofInt(
            ANIM_PROPERTY_ALPHA_BOTTOM_SHADOW, nowAlphaBottomShadow, newAlphaBottomShadow);
    PropertyValuesHolder offsetTopShadowHolder =
        PropertyValuesHolder.ofFloat(
            ANIM_PROPERTY_OFFSET_TOP_SHADOW, nowOffsetYTopShadow, newOffsetYTopShadow);
    PropertyValuesHolder offsetBottomShadowHolder =
        PropertyValuesHolder.ofFloat(
            ANIM_PROPERTY_OFFSET_BOTTOM_SHADOW, nowOffsetYBottomShadow, newOffsetYBottomShadow);
    PropertyValuesHolder blurTopShadowHolder =
        PropertyValuesHolder.ofFloat(
            ANIM_PROPERTY_BLUR_TOP_SHADOW, nowBlurTopShadow, newBlurTopShadow);
    PropertyValuesHolder blurBottomShadowHolder =
        PropertyValuesHolder.ofFloat(
            ANIM_PROPERTY_BLUR_BOTTOM_SHADOW, nowBlurBottomShadow, newBlurBottomShadow);

    ValueAnimator anim =
        ValueAnimator.ofPropertyValuesHolder(
            alphaTopShadowHolder,
            alphaBottomShadowHolder,
            offsetTopShadowHolder,
            offsetBottomShadowHolder,
            blurTopShadowHolder,
            blurBottomShadowHolder);
    anim.setDuration(mZDepthAnimDuration);
    anim.setInterpolator(new LinearInterpolator());
    anim.addUpdateListener(
        new ValueAnimator.AnimatorUpdateListener() {
          @Override
          public void onAnimationUpdate(ValueAnimator animation) {
            int alphaTopShadow =
                (Integer) animation.getAnimatedValue(ANIM_PROPERTY_ALPHA_TOP_SHADOW);
            int alphaBottomShadow =
                (Integer) animation.getAnimatedValue(ANIM_PROPERTY_ALPHA_BOTTOM_SHADOW);
            float offsetTopShadow =
                (Float) animation.getAnimatedValue(ANIM_PROPERTY_OFFSET_TOP_SHADOW);
            float offsetBottomShadow =
                (Float) animation.getAnimatedValue(ANIM_PROPERTY_OFFSET_BOTTOM_SHADOW);
            float blurTopShadow = (Float) animation.getAnimatedValue(ANIM_PROPERTY_BLUR_TOP_SHADOW);
            float blurBottomShadow =
                (Float) animation.getAnimatedValue(ANIM_PROPERTY_BLUR_BOTTOM_SHADOW);

            mZDepthParam.mAlphaTopShadow = alphaTopShadow;
            mZDepthParam.mAlphaBottomShadow = alphaBottomShadow;
            mZDepthParam.mOffsetYTopShadowPx = offsetTopShadow;
            mZDepthParam.mOffsetYBottomShadowPx = offsetBottomShadow;
            mZDepthParam.mBlurTopShadowPx = blurTopShadow;
            mZDepthParam.mBlurBottomShadowPx = blurBottomShadow;

            mShadow.setParameter(
                mZDepthParam,
                mZDepthPaddingLeft,
                mZDepthPaddingTop,
                getWidth() - mZDepthPaddingRight,
                getHeight() - mZDepthPaddingBottom);

            invalidate();
          }
        });
    anim.start();
  }