Search in sources :

Example 1 with TypeEvaluator

use of android.animation.TypeEvaluator in project UltimateAndroid by cymcsg.

the class DynamicGridModification method animateBounds.

@TargetApi(Build.VERSION_CODES.HONEYCOMB)
private void animateBounds(final View mobileView) {
    TypeEvaluator<Rect> sBoundEvaluator = new TypeEvaluator<Rect>() {

        public Rect evaluate(float fraction, Rect startValue, Rect endValue) {
            return new Rect(interpolate(startValue.left, endValue.left, fraction), interpolate(startValue.top, endValue.top, fraction), interpolate(startValue.right, endValue.right, fraction), interpolate(startValue.bottom, endValue.bottom, fraction));
        }

        public int interpolate(int start, int end, float fraction) {
            return (int) (start + fraction * (end - start));
        }
    };
    ObjectAnimator hoverViewAnimator = ObjectAnimator.ofObject(mHoverCell, "bounds", sBoundEvaluator, mHoverCellCurrentBounds);
    hoverViewAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {

        @Override
        public void onAnimationUpdate(ValueAnimator valueAnimator) {
            invalidate();
        }
    });
    hoverViewAnimator.addListener(new AnimatorListenerAdapter() {

        @Override
        public void onAnimationStart(Animator animation) {
            mHoverAnimation = true;
            updateEnableState();
        }

        @Override
        public void onAnimationEnd(Animator animation) {
            mHoverAnimation = false;
            updateEnableState();
            reset(mobileView);
        }
    });
    hoverViewAnimator.start();
}
Also used : Rect(android.graphics.Rect) Animator(android.animation.Animator) ObjectAnimator(android.animation.ObjectAnimator) ValueAnimator(android.animation.ValueAnimator) TypeEvaluator(android.animation.TypeEvaluator) ObjectAnimator(android.animation.ObjectAnimator) AnimatorListenerAdapter(android.animation.AnimatorListenerAdapter) ValueAnimator(android.animation.ValueAnimator) TargetApi(android.annotation.TargetApi)

Example 2 with TypeEvaluator

use of android.animation.TypeEvaluator in project vector-compat by wnafee.

the class PathAnimatorInflater method parseAnimatorFromTypeArray.

/**
     * @param anim The animator, must not be null
     * @param arrayAnimator Incoming typed array for Animator's attributes.
     * @param arrayObjectAnimator Incoming typed array for Object Animator's
     *            attributes.
     */
private static void parseAnimatorFromTypeArray(ValueAnimator anim, TypedArray arrayAnimator, TypedArray arrayObjectAnimator) {
    long duration = arrayAnimator.getInt(R.styleable.Animator_android_duration, 300);
    long startDelay = arrayAnimator.getInt(R.styleable.Animator_android_startOffset, 0);
    int valueType = arrayAnimator.getInt(R.styleable.Animator_vc_valueType, 0);
    TypeEvaluator evaluator = null;
    // Must be a path animator by the time I reach here
    if (valueType == VALUE_TYPE_PATH) {
        evaluator = setupAnimatorForPath(anim, arrayAnimator);
    } else {
        throw new IllegalArgumentException("target is not a pathType target");
    }
    anim.setDuration(duration);
    anim.setStartDelay(startDelay);
    if (arrayAnimator.hasValue(R.styleable.Animator_android_repeatCount)) {
        anim.setRepeatCount(arrayAnimator.getInt(R.styleable.Animator_android_repeatCount, 0));
    }
    if (arrayAnimator.hasValue(R.styleable.Animator_android_repeatMode)) {
        anim.setRepeatMode(arrayAnimator.getInt(R.styleable.Animator_android_repeatMode, ValueAnimator.RESTART));
    }
    if (evaluator != null) {
        anim.setEvaluator(evaluator);
    }
    if (arrayObjectAnimator != null) {
        setupObjectAnimator(anim, arrayObjectAnimator);
    }
}
Also used : TypeEvaluator(android.animation.TypeEvaluator)

Example 3 with TypeEvaluator

use of android.animation.TypeEvaluator in project vector-compat by wnafee.

the class PathAnimatorInflater method setupAnimatorForPath.

/**
     * Setup the Animator to achieve path morphing.
     *
     * @param anim The target Animator which will be updated.
     * @param arrayAnimator TypedArray for the ValueAnimator.
     * @return the PathDataEvaluator.
     */
private static TypeEvaluator setupAnimatorForPath(ValueAnimator anim, TypedArray arrayAnimator) {
    TypeEvaluator evaluator = null;
    String fromString = arrayAnimator.getString(R.styleable.Animator_android_valueFrom);
    String toString = arrayAnimator.getString(R.styleable.Animator_android_valueTo);
    PathParser.PathDataNode[] nodesFrom = PathParser.createNodesFromPathData(fromString);
    PathParser.PathDataNode[] nodesTo = PathParser.createNodesFromPathData(toString);
    if (nodesFrom != null) {
        if (nodesTo != null) {
            anim.setObjectValues(nodesFrom, nodesTo);
            if (!PathParser.canMorph(nodesFrom, nodesTo)) {
                throw new InflateException(arrayAnimator.getPositionDescription() + " Can't morph from " + fromString + " to " + toString);
            }
        } else {
            anim.setObjectValues((Object) nodesFrom);
        }
        evaluator = new PathDataEvaluator(PathParser.deepCopyNodes(nodesFrom));
    } else if (nodesTo != null) {
        anim.setObjectValues((Object) nodesTo);
        evaluator = new PathDataEvaluator(PathParser.deepCopyNodes(nodesTo));
    }
    if (DBG_ANIMATOR_INFLATER && evaluator != null) {
        Log.v(TAG, "create a new PathDataEvaluator here");
    }
    return evaluator;
}
Also used : TypeEvaluator(android.animation.TypeEvaluator) InflateException(android.view.InflateException)

Aggregations

TypeEvaluator (android.animation.TypeEvaluator)3 Animator (android.animation.Animator)1 AnimatorListenerAdapter (android.animation.AnimatorListenerAdapter)1 ObjectAnimator (android.animation.ObjectAnimator)1 ValueAnimator (android.animation.ValueAnimator)1 TargetApi (android.annotation.TargetApi)1 Rect (android.graphics.Rect)1 InflateException (android.view.InflateException)1