Example usage for android.animation PropertyValuesHolder ofObject

List of usage examples for android.animation PropertyValuesHolder ofObject

Introduction

In this page you can find the example usage for android.animation PropertyValuesHolder ofObject.

Prototype

@SafeVarargs
public static <T, V> PropertyValuesHolder ofObject(Property<?, V> property, TypeConverter<T, V> converter,
        TypeEvaluator<T> evaluator, T... values) 

Source Link

Document

Constructs and returns a PropertyValuesHolder with a given property and set of Object values.

Usage

From source file:com.taobao.weex.dom.action.AnimationAction.java

private @Nullable ObjectAnimator createAnimator(final View target, final int viewPortWidth) {
    if (target == null) {
        return null;
    }// ww w  .  ja  v a  2s. c  o  m
    WXAnimationBean.Style style = mAnimationBean.styles;
    if (style != null) {
        ObjectAnimator animator;
        List<PropertyValuesHolder> holders = style.getHolders();
        if (!TextUtils.isEmpty(style.backgroundColor)) {
            BorderDrawable borderDrawable;
            if ((borderDrawable = WXViewUtils.getBorderDrawable(target)) != null) {
                holders.add(PropertyValuesHolder.ofObject(new BackgroundColorProperty(), new ArgbEvaluator(),
                        borderDrawable.getColor(), WXResourceUtils.getColor(style.backgroundColor)));
            } else if (target.getBackground() instanceof ColorDrawable) {
                holders.add(PropertyValuesHolder.ofObject(new BackgroundColorProperty(), new ArgbEvaluator(),
                        ((ColorDrawable) target.getBackground()).getColor(),
                        WXResourceUtils.getColor(style.backgroundColor)));
            }
        }
        if (style.getPivot() != null) {
            Pair<Float, Float> pair = style.getPivot();
            target.setPivotX(pair.first);
            target.setPivotY(pair.second);
        }
        animator = ObjectAnimator.ofPropertyValuesHolder(target,
                holders.toArray(new PropertyValuesHolder[holders.size()]));
        animator.setStartDelay(mAnimationBean.delay);
        if (target.getLayoutParams() != null
                && (!TextUtils.isEmpty(style.width) || !TextUtils.isEmpty(style.height))) {
            DimensionUpdateListener listener = new DimensionUpdateListener(target);
            ViewGroup.LayoutParams layoutParams = target.getLayoutParams();
            if (!TextUtils.isEmpty(style.width)) {
                listener.setWidth(layoutParams.width,
                        (int) WXViewUtils.getRealPxByWidth(WXUtils.getFloat(style.width), viewPortWidth));
            }
            if (!TextUtils.isEmpty(style.height)) {
                listener.setHeight(layoutParams.height,
                        (int) WXViewUtils.getRealPxByWidth(WXUtils.getFloat(style.height), viewPortWidth));
            }
            animator.addUpdateListener(listener);
        }
        return animator;
    } else {
        return null;
    }
}

From source file:com.taobao.weex.ui.action.GraphicActionAnimation.java

private @Nullable ObjectAnimator createAnimator(final View target, final int viewPortWidth) {
    if (target == null) {
        return null;
    }//  w  w w.  java 2s.co  m
    WXAnimationBean.Style style = mAnimationBean.styles;
    if (style != null) {
        ObjectAnimator animator;
        List<PropertyValuesHolder> holders = style.getHolders();
        if (!TextUtils.isEmpty(style.backgroundColor)) {
            BorderDrawable borderDrawable;
            if ((borderDrawable = WXViewUtils.getBorderDrawable(target)) != null) {
                holders.add(PropertyValuesHolder.ofObject(new BackgroundColorProperty(), new ArgbEvaluator(),
                        borderDrawable.getColor(), WXResourceUtils.getColor(style.backgroundColor)));
            } else if (target.getBackground() instanceof ColorDrawable) {
                holders.add(PropertyValuesHolder.ofObject(new BackgroundColorProperty(), new ArgbEvaluator(),
                        ((ColorDrawable) target.getBackground()).getColor(),
                        WXResourceUtils.getColor(style.backgroundColor)));
            }
        }

        if (target.getLayoutParams() != null
                && (!TextUtils.isEmpty(style.width) || !TextUtils.isEmpty(style.height))) {
            ViewGroup.LayoutParams layoutParams = target.getLayoutParams();
            if (!TextUtils.isEmpty(style.width)) {
                holders.add(PropertyValuesHolder.ofInt(new WidthProperty(), layoutParams.width,
                        (int) WXViewUtils.getRealPxByWidth(WXUtils.getFloat(style.width), viewPortWidth)));
            }
            if (!TextUtils.isEmpty(style.height)) {
                holders.add(PropertyValuesHolder.ofInt(new HeightProperty(), layoutParams.height,
                        (int) WXViewUtils.getRealPxByWidth(WXUtils.getFloat(style.height), viewPortWidth)));
            }
        }

        if (style.getPivot() != null) {
            Pair<Float, Float> pair = style.getPivot();
            target.setPivotX(pair.first);
            target.setPivotY(pair.second);
        }
        animator = ObjectAnimator.ofPropertyValuesHolder(target,
                holders.toArray(new PropertyValuesHolder[holders.size()]));
        animator.setStartDelay(mAnimationBean.delay);
        return animator;
    } else {
        return null;
    }
}

From source file:android.support.graphics.drawable.AnimatorInflaterCompat.java

private static PropertyValuesHolder getPVH(TypedArray styledAttributes, int valueType, int valueFromId,
        int valueToId, String propertyName) {

    TypedValue tvFrom = styledAttributes.peekValue(valueFromId);
    boolean hasFrom = (tvFrom != null);
    int fromType = hasFrom ? tvFrom.type : 0;
    TypedValue tvTo = styledAttributes.peekValue(valueToId);
    boolean hasTo = (tvTo != null);
    int toType = hasTo ? tvTo.type : 0;

    if (valueType == VALUE_TYPE_UNDEFINED) {
        // Check whether it's color type. If not, fall back to default type (i.e. float type)
        if ((hasFrom && isColorType(fromType)) || (hasTo && isColorType(toType))) {
            valueType = VALUE_TYPE_COLOR;
        } else {/*  ww w  . ja v a 2 s. c om*/
            valueType = VALUE_TYPE_FLOAT;
        }
    }

    boolean getFloats = (valueType == VALUE_TYPE_FLOAT);

    PropertyValuesHolder returnValue = null;

    if (valueType == VALUE_TYPE_PATH) {
        String fromString = styledAttributes.getString(valueFromId);
        String toString = styledAttributes.getString(valueToId);

        PathParser.PathDataNode[] nodesFrom = PathParser.createNodesFromPathData(fromString);
        PathParser.PathDataNode[] nodesTo = PathParser.createNodesFromPathData(toString);
        if (nodesFrom != null || nodesTo != null) {
            if (nodesFrom != null) {
                TypeEvaluator evaluator = new PathDataEvaluator();
                if (nodesTo != null) {
                    if (!PathParser.canMorph(nodesFrom, nodesTo)) {
                        throw new InflateException(" Can't morph from " + fromString + " to " + toString);
                    }
                    returnValue = PropertyValuesHolder.ofObject(propertyName, evaluator, nodesFrom, nodesTo);
                } else {
                    returnValue = PropertyValuesHolder.ofObject(propertyName, evaluator, (Object) nodesFrom);
                }
            } else if (nodesTo != null) {
                TypeEvaluator evaluator = new PathDataEvaluator();
                returnValue = PropertyValuesHolder.ofObject(propertyName, evaluator, (Object) nodesTo);
            }
        }
    } else {
        TypeEvaluator evaluator = null;
        // Integer and float value types are handled here.
        if (valueType == VALUE_TYPE_COLOR) {
            // special case for colors: ignore valueType and get ints
            evaluator = ArgbEvaluator.getInstance();
        }
        if (getFloats) {
            float valueFrom;
            float valueTo;
            if (hasFrom) {
                if (fromType == TypedValue.TYPE_DIMENSION) {
                    valueFrom = styledAttributes.getDimension(valueFromId, 0f);
                } else {
                    valueFrom = styledAttributes.getFloat(valueFromId, 0f);
                }
                if (hasTo) {
                    if (toType == TypedValue.TYPE_DIMENSION) {
                        valueTo = styledAttributes.getDimension(valueToId, 0f);
                    } else {
                        valueTo = styledAttributes.getFloat(valueToId, 0f);
                    }
                    returnValue = PropertyValuesHolder.ofFloat(propertyName, valueFrom, valueTo);
                } else {
                    returnValue = PropertyValuesHolder.ofFloat(propertyName, valueFrom);
                }
            } else {
                if (toType == TypedValue.TYPE_DIMENSION) {
                    valueTo = styledAttributes.getDimension(valueToId, 0f);
                } else {
                    valueTo = styledAttributes.getFloat(valueToId, 0f);
                }
                returnValue = PropertyValuesHolder.ofFloat(propertyName, valueTo);
            }
        } else {
            int valueFrom;
            int valueTo;
            if (hasFrom) {
                if (fromType == TypedValue.TYPE_DIMENSION) {
                    valueFrom = (int) styledAttributes.getDimension(valueFromId, 0f);
                } else if (isColorType(fromType)) {
                    valueFrom = styledAttributes.getColor(valueFromId, 0);
                } else {
                    valueFrom = styledAttributes.getInt(valueFromId, 0);
                }
                if (hasTo) {
                    if (toType == TypedValue.TYPE_DIMENSION) {
                        valueTo = (int) styledAttributes.getDimension(valueToId, 0f);
                    } else if (isColorType(toType)) {
                        valueTo = styledAttributes.getColor(valueToId, 0);
                    } else {
                        valueTo = styledAttributes.getInt(valueToId, 0);
                    }
                    returnValue = PropertyValuesHolder.ofInt(propertyName, valueFrom, valueTo);
                } else {
                    returnValue = PropertyValuesHolder.ofInt(propertyName, valueFrom);
                }
            } else {
                if (hasTo) {
                    if (toType == TypedValue.TYPE_DIMENSION) {
                        valueTo = (int) styledAttributes.getDimension(valueToId, 0f);
                    } else if (isColorType(toType)) {
                        valueTo = styledAttributes.getColor(valueToId, 0);
                    } else {
                        valueTo = styledAttributes.getInt(valueToId, 0);
                    }
                    returnValue = PropertyValuesHolder.ofInt(propertyName, valueTo);
                }
            }
        }
        if (returnValue != null && evaluator != null) {
            returnValue.setEvaluator(evaluator);
        }
    }

    return returnValue;
}

From source file:android.support.transition.ChangeTransform.java

private ObjectAnimator createTransformAnimator(TransitionValues startValues, TransitionValues endValues,
        final boolean handleParentChange) {
    Matrix startMatrix = (Matrix) startValues.values.get(PROPNAME_MATRIX);
    Matrix endMatrix = (Matrix) endValues.values.get(PROPNAME_MATRIX);

    if (startMatrix == null) {
        startMatrix = MatrixUtils.IDENTITY_MATRIX;
    }//  w w  w . j a v  a 2s. co m

    if (endMatrix == null) {
        endMatrix = MatrixUtils.IDENTITY_MATRIX;
    }

    if (startMatrix.equals(endMatrix)) {
        return null;
    }

    final Transforms transforms = (Transforms) endValues.values.get(PROPNAME_TRANSFORMS);

    // clear the transform properties so that we can use the animation matrix instead
    final View view = endValues.view;
    setIdentityTransforms(view);

    final float[] startMatrixValues = new float[9];
    startMatrix.getValues(startMatrixValues);
    final float[] endMatrixValues = new float[9];
    endMatrix.getValues(endMatrixValues);
    final PathAnimatorMatrix pathAnimatorMatrix = new PathAnimatorMatrix(view, startMatrixValues);

    PropertyValuesHolder valuesProperty = PropertyValuesHolder.ofObject(NON_TRANSLATIONS_PROPERTY,
            new FloatArrayEvaluator(new float[9]), startMatrixValues, endMatrixValues);
    Path path = getPathMotion().getPath(startMatrixValues[Matrix.MTRANS_X], startMatrixValues[Matrix.MTRANS_Y],
            endMatrixValues[Matrix.MTRANS_X], endMatrixValues[Matrix.MTRANS_Y]);
    PropertyValuesHolder translationProperty = PropertyValuesHolderUtils.ofPointF(TRANSLATIONS_PROPERTY, path);
    ObjectAnimator animator = ObjectAnimator.ofPropertyValuesHolder(pathAnimatorMatrix, valuesProperty,
            translationProperty);

    final Matrix finalEndMatrix = endMatrix;

    AnimatorListenerAdapter listener = new AnimatorListenerAdapter() {
        private boolean mIsCanceled;
        private Matrix mTempMatrix = new Matrix();

        @Override
        public void onAnimationCancel(Animator animation) {
            mIsCanceled = true;
        }

        @Override
        public void onAnimationEnd(Animator animation) {
            if (!mIsCanceled) {
                if (handleParentChange && mUseOverlay) {
                    setCurrentMatrix(finalEndMatrix);
                } else {
                    view.setTag(R.id.transition_transform, null);
                    view.setTag(R.id.parent_matrix, null);
                }
            }
            ViewUtils.setAnimationMatrix(view, null);
            transforms.restore(view);
        }

        @Override
        public void onAnimationPause(Animator animation) {
            Matrix currentMatrix = pathAnimatorMatrix.getMatrix();
            setCurrentMatrix(currentMatrix);
        }

        @Override
        public void onAnimationResume(Animator animation) {
            setIdentityTransforms(view);
        }

        private void setCurrentMatrix(Matrix currentMatrix) {
            mTempMatrix.set(currentMatrix);
            view.setTag(R.id.transition_transform, mTempMatrix);
            transforms.restore(view);
        }
    };

    animator.addListener(listener);
    AnimatorUtils.addPauseListener(animator, listener);
    return animator;
}

From source file:com.taobao.weex.ui.animation.WXAnimationModule.java

private static @Nullable ObjectAnimator createAnimator(@NonNull WXAnimationBean animation, final View target,
        final int viewPortWidth) {
    if (target == null) {
        return null;
    }/*from w  w w  .j  a v  a 2  s  .c  o m*/
    WXAnimationBean.Style style = animation.styles;
    if (style != null) {
        ObjectAnimator animator;
        List<PropertyValuesHolder> holders = style.getHolders();
        if (!TextUtils.isEmpty(style.backgroundColor)) {
            BorderDrawable borderDrawable;
            if ((borderDrawable = WXViewUtils.getBorderDrawable(target)) != null) {
                holders.add(PropertyValuesHolder.ofObject(WXAnimationBean.Style.BACKGROUND_COLOR,
                        new ArgbEvaluator(), borderDrawable.getColor(),
                        WXResourceUtils.getColor(style.backgroundColor)));
            } else if (target.getBackground() instanceof ColorDrawable) {
                holders.add(PropertyValuesHolder.ofObject(WXAnimationBean.Style.BACKGROUND_COLOR,
                        new ArgbEvaluator(), ((ColorDrawable) target.getBackground()).getColor(),
                        WXResourceUtils.getColor(style.backgroundColor)));
            }
        }
        if (style.getPivot() != null) {
            Pair<Float, Float> pair = style.getPivot();
            target.setPivotX(pair.first);
            target.setPivotY(pair.second);
        }
        animator = ObjectAnimator.ofPropertyValuesHolder(target,
                holders.toArray(new PropertyValuesHolder[holders.size()]));
        animator.setStartDelay(animation.delay);
        if (target.getLayoutParams() != null
                && (!TextUtils.isEmpty(style.width) || !TextUtils.isEmpty(style.height))) {
            DimensionUpdateListener listener = new DimensionUpdateListener(target);
            ViewGroup.LayoutParams layoutParams = target.getLayoutParams();
            if (!TextUtils.isEmpty(style.width)) {
                listener.setWidth(layoutParams.width,
                        (int) WXViewUtils.getRealPxByWidth(WXUtils.getFloat(style.width), viewPortWidth));
            }
            if (!TextUtils.isEmpty(style.height)) {
                listener.setHeight(layoutParams.height,
                        (int) WXViewUtils.getRealPxByWidth(WXUtils.getFloat(style.height), viewPortWidth));
            }
            animator.addUpdateListener(listener);
        }
        return animator;
    } else {
        return null;
    }
}

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

/**
 *  transform, opacity, backgroundcolor which not effect layout use android system animation in main thread.
 * *//*from   w  w w  . j av a2s  .  c om*/
private void doPendingTransformAnimation(int token) {
    if (transformAnimator != null) {
        transformAnimator.cancel();
        transformAnimator = null;
    }
    if (transformPendingUpdates.size() == 0) {
        return;
    }
    final View taregtView = getTargetView();
    if (taregtView == null) {
        return;
    }
    List<PropertyValuesHolder> holders = new ArrayList<>(8);
    String transform = WXUtils.getString(transformPendingUpdates.remove(Constants.Name.TRANSFORM), null);
    if (!TextUtils.isEmpty(transform)) {
        Map<Property<View, Float>, Float> properties = TransformParser.parseTransForm(transform,
                (int) domObject.getLayoutWidth(), (int) domObject.getLayoutHeight(),
                domObject.getViewPortWidth());
        PropertyValuesHolder[] transformHolders = TransformParser.toHolders(properties);
        for (PropertyValuesHolder holder : transformHolders) {
            holders.add(holder);
        }
        synchronized (targetStyles) {
            targetStyles.put(Constants.Name.TRANSFORM, transform);
        }
    }

    for (String property : properties) {
        if (!TRANSFORM_PROPERTIES.contains(property)) {
            continue;
        }
        if (!transformPendingUpdates.containsKey(property)) {
            continue;
        }
        Object value = transformPendingUpdates.remove(property);
        synchronized (targetStyles) {
            targetStyles.put(property, value);
        }
        switch (property) {
        case Constants.Name.OPACITY: {
            holders.add(PropertyValuesHolder.ofFloat(View.ALPHA, taregtView.getAlpha(),
                    WXUtils.getFloat(value, 1.0f)));
            taregtView.setLayerType(View.LAYER_TYPE_SOFTWARE, null); //hardware or none has bug on some platform
        }
            break;
        case Constants.Name.BACKGROUND_COLOR: {
            int fromColor = WXResourceUtils
                    .getColor(WXUtils.getString(domObject.getStyles().getBackgroundColor(), null), 0);
            int toColor = WXResourceUtils.getColor(WXUtils.getString(value, null), 0);
            if (WXViewUtils.getBorderDrawable(taregtView) != null) {
                fromColor = WXViewUtils.getBorderDrawable(taregtView).getColor();
            } else if (taregtView.getBackground() instanceof ColorDrawable) {
                fromColor = ((ColorDrawable) taregtView.getBackground()).getColor();
            }
            holders.add(PropertyValuesHolder.ofObject(new BackgroundColorProperty(), new ArgbEvaluator(),
                    fromColor, toColor));
        }
            break;
        default:
            break;
        }
    }

    if (token == lockToken.get()) {
        transformPendingUpdates.clear();
    }
    transformAnimator = ObjectAnimator.ofPropertyValuesHolder(taregtView,
            holders.toArray(new PropertyValuesHolder[holders.size()]));
    transformAnimator.setDuration((long) duration);
    if ((long) delay > 0) {
        transformAnimator.setStartDelay((long) delay);
    }
    if (interpolator != null) {
        transformAnimator.setInterpolator(interpolator);
    }
    transformAnimator.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);
            WXTransition.this.onTransitionAnimationEnd();
            if (WXEnvironment.isApkDebugable()) {
                WXLogUtils.d("WXTransition transform onTransitionAnimationEnd " + domObject.getRef());
            }
        }
    });
    transformAnimator.start();
}

From source file:com.android.deskclock.alarms.AlarmActivity.java

private ValueAnimator getButtonAnimator(ImageView button, int tintColor) {
    return ObjectAnimator.ofPropertyValuesHolder(button,
            PropertyValuesHolder.ofFloat(View.SCALE_X, BUTTON_SCALE_DEFAULT, 1.0f),
            PropertyValuesHolder.ofFloat(View.SCALE_Y, BUTTON_SCALE_DEFAULT, 1.0f),
            PropertyValuesHolder.ofInt(AnimatorUtils.BACKGROUND_ALPHA, 0, 255),
            PropertyValuesHolder.ofInt(AnimatorUtils.DRAWABLE_ALPHA, BUTTON_DRAWABLE_ALPHA_DEFAULT, 255),
            PropertyValuesHolder.ofObject(AnimatorUtils.DRAWABLE_TINT, AnimatorUtils.ARGB_EVALUATOR,
                    Color.WHITE, tintColor));
}