Example usage for android.animation ValueAnimator getAnimatedValue

List of usage examples for android.animation ValueAnimator getAnimatedValue

Introduction

In this page you can find the example usage for android.animation ValueAnimator getAnimatedValue.

Prototype

public Object getAnimatedValue(String propertyName) 

Source Link

Document

The most recent value calculated by this ValueAnimator for propertyName.

Usage

From source file:com.guodong.sun.guodong.widget.ZoomImageView.java

private void startTransform(final int state) {
    if (mTransfrom == null) {
        return;/* w ww.  j av a 2s .  c o  m*/
    }
    ValueAnimator valueAnimator = new ValueAnimator();
    valueAnimator.setDuration(300);
    valueAnimator.setInterpolator(new AccelerateDecelerateInterpolator());
    if (state == STATE_TRANSFORM_IN) {
        PropertyValuesHolder scaleHolder = PropertyValuesHolder.ofFloat("scale", mTransfrom.startScale,
                mTransfrom.endScale);
        PropertyValuesHolder leftHolder = PropertyValuesHolder.ofFloat("left", mTransfrom.startRect.left,
                mTransfrom.endRect.left);
        PropertyValuesHolder topHolder = PropertyValuesHolder.ofFloat("top", mTransfrom.startRect.top,
                mTransfrom.endRect.top);
        PropertyValuesHolder widthHolder = PropertyValuesHolder.ofFloat("width", mTransfrom.startRect.width,
                mTransfrom.endRect.width);
        PropertyValuesHolder heightHolder = PropertyValuesHolder.ofFloat("height", mTransfrom.startRect.height,
                mTransfrom.endRect.height);
        PropertyValuesHolder alphaHolder = PropertyValuesHolder.ofInt("alpha", 0, 255);
        valueAnimator.setValues(scaleHolder, leftHolder, topHolder, widthHolder, heightHolder, alphaHolder);
    } else {
        PropertyValuesHolder scaleHolder = PropertyValuesHolder.ofFloat("scale", mTransfrom.endScale,
                mTransfrom.startScale);
        PropertyValuesHolder leftHolder = PropertyValuesHolder.ofFloat("left", mTransfrom.endRect.left,
                mTransfrom.startRect.left);
        PropertyValuesHolder topHolder = PropertyValuesHolder.ofFloat("top", mTransfrom.endRect.top,
                mTransfrom.startRect.top);
        PropertyValuesHolder widthHolder = PropertyValuesHolder.ofFloat("width", mTransfrom.endRect.width,
                mTransfrom.startRect.width);
        PropertyValuesHolder heightHolder = PropertyValuesHolder.ofFloat("height", mTransfrom.endRect.height,
                mTransfrom.startRect.height);
        PropertyValuesHolder alphaHolder = PropertyValuesHolder.ofInt("alpha", 255, 0);
        valueAnimator.setValues(scaleHolder, leftHolder, topHolder, widthHolder, heightHolder, alphaHolder);
    }

    valueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public synchronized void onAnimationUpdate(ValueAnimator animation) {
            mTransfrom.scale = (Float) animation.getAnimatedValue("scale");
            mTransfrom.rect.left = (Float) animation.getAnimatedValue("left");
            mTransfrom.rect.top = (Float) animation.getAnimatedValue("top");
            mTransfrom.rect.width = (Float) animation.getAnimatedValue("width");
            mTransfrom.rect.height = (Float) animation.getAnimatedValue("height");
            mBgAlpha = (Integer) animation.getAnimatedValue("alpha");
            invalidate();
            ((Activity) getContext()).getWindow().getDecorView().invalidate();
        }
    });
    valueAnimator.addListener(new ValueAnimator.AnimatorListener() {
        @Override
        public void onAnimationStart(Animator animation) {

        }

        @Override
        public void onAnimationRepeat(Animator animation) {

        }

        @Override
        public void onAnimationEnd(Animator animation) {
            /*
             * ???center_cropout??center_crop?
             *  ???out???Normal???bug
             */
            // TODO ???
            if (state == STATE_TRANSFORM_IN) {
                mState = STATE_NORMAL;
            }
            if (mTransformListener != null) {
                mTransformListener.onTransformComplete(state);
            }
        }

        @Override
        public void onAnimationCancel(Animator animation) {

        }
    });
    valueAnimator.start();
}

From source file:com.taobao.weex.dom.transition.WXTransition.java

private void doLayoutPropertyValuesHolderAnimation(PropertyValuesHolder[] holders) {
    layoutValueAnimator = ValueAnimator.ofPropertyValuesHolder(holders);
    layoutValueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override/* w w  w .j  ava  2  s  . c  o m*/
        public void onAnimationUpdate(ValueAnimator animation) {
            PropertyValuesHolder holders[] = animation.getValues();
            for (PropertyValuesHolder holder : holders) {
                String property = holder.getPropertyName();
                switch (property) {
                case Constants.Name.WIDTH: {
                    domObject.setStyleWidth((Float) animation.getAnimatedValue(property));
                }
                    break;
                case Constants.Name.HEIGHT: {
                    domObject.setStyleHeight((Float) animation.getAnimatedValue(property));
                }
                    break;
                case Constants.Name.MARGIN_TOP: {
                    domObject.setMargin(Spacing.TOP, (Float) animation.getAnimatedValue(property));
                }
                    break;
                case Constants.Name.MARGIN_LEFT: {
                    domObject.setMargin(Spacing.LEFT, (Float) animation.getAnimatedValue(property));
                }
                    break;
                case Constants.Name.MARGIN_RIGHT: {
                    domObject.setMargin(Spacing.RIGHT, (Float) animation.getAnimatedValue(property));
                }
                    break;
                case Constants.Name.MARGIN_BOTTOM: {
                    domObject.setMargin(Spacing.BOTTOM, (Float) animation.getAnimatedValue(property));
                }
                    break;
                case Constants.Name.LEFT: {
                    domObject.setPositionLeft((Float) animation.getAnimatedValue(property));
                }
                    break;
                case Constants.Name.RIGHT: {
                    domObject.setPositionRight((Float) animation.getAnimatedValue(property));
                }
                    break;
                case Constants.Name.BOTTOM: {
                    domObject.setPositionBottom((Float) animation.getAnimatedValue(property));
                }
                    break;
                case Constants.Name.TOP: {
                    domObject.setPositionTop((Float) animation.getAnimatedValue(property));
                }
                    break;
                case Constants.Name.PADDING_TOP: {
                    domObject.setPadding(Spacing.TOP, (Float) animation.getAnimatedValue(property));
                }
                    break;
                case Constants.Name.PADDING_BOTTOM: {
                    domObject.setPadding(Spacing.BOTTOM, (Float) animation.getAnimatedValue(property));
                }
                    break;
                case Constants.Name.PADDING_LEFT: {
                    domObject.setPadding(Spacing.LEFT, (Float) animation.getAnimatedValue(property));
                }
                    break;
                case Constants.Name.PADDING_RIGHT: {
                    domObject.setPadding(Spacing.RIGHT, (Float) animation.getAnimatedValue(property));
                }
                    break;
                default:
                    break;
                }
            }

            DOMActionContext domActionContext = WXSDKManager.getInstance().getWXDomManager()
                    .getDomContext(domObject.getDomContext().getInstanceId());
            if (domActionContext == null) {
                return;
            }
            domActionContext.markDirty();
            WXSDKManager.getInstance().getWXDomManager()
                    .sendEmptyMessageDelayed(WXDomHandler.MsgType.WX_DOM_TRANSITION_BATCH, 0);
            if (WXEnvironment.isApkDebugable()) {
                WXLogUtils.d("WXTransition send layout batch msg");
            }
        }
    });
    layoutValueAnimator.addListener(new AnimatorListenerAdapter() {

        boolean hasCancel = false;

        @Override
        public void onAnimationCancel(Animator animation) {
            super.onAnimationCancel(animation);
            hasCancel = true;
        }

        @Override
        public void onAnimationEnd(Animator animation) {
            if (hasCancel) {
                return;
            }
            super.onAnimationEnd(animation);
            if (WXEnvironment.isApkDebugable()) {
                WXLogUtils.d("WXTransition layout onTransitionAnimationEnd " + domObject.getRef());
            }
            WXTransition.this.onTransitionAnimationEnd();
        }
    });
    if (interpolator != null) {
        layoutValueAnimator.setInterpolator(interpolator);
    }
    layoutValueAnimator.setStartDelay((long) (delay));
    layoutValueAnimator.setDuration((long) (duration));
    layoutValueAnimator.start();
}