Example usage for android.animation ValueAnimator ofPropertyValuesHolder

List of usage examples for android.animation ValueAnimator ofPropertyValuesHolder

Introduction

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

Prototype

public static ValueAnimator ofPropertyValuesHolder(PropertyValuesHolder... values) 

Source Link

Document

Constructs and returns a ValueAnimator that animates between the values specified in the PropertyValuesHolder objects.

Usage

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/*from  www.j  av  a 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();
}