Search in sources :

Example 46 with PropertyValuesHolder

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

the class SlideInAnimationHandler method animateMenuOpening.

@Override
public void animateMenuOpening(Point center) {
    super.animateMenuOpening(center);
    setAnimating(true);
    Animator lastAnimation = null;
    for (int i = 0; i < menu.getSubActionItems().size(); i++) {
        menu.getSubActionItems().get(i).view.setAlpha(0);
        FrameLayout.LayoutParams params = (FrameLayout.LayoutParams) menu.getSubActionItems().get(i).view.getLayoutParams();
        params.setMargins(menu.getSubActionItems().get(i).x, menu.getSubActionItems().get(i).y + DIST_Y, 0, 0);
        menu.getSubActionItems().get(i).view.setLayoutParams(params);
        //            PropertyValuesHolder pvhX = PropertyValuesHolder.ofFloat(View.TRANSLATION_X, menu.getSubActionItems().get(i).x/* - center.x + menu.getSubActionItems().get(i).width / 2*/);
        PropertyValuesHolder pvhY = PropertyValuesHolder.ofFloat(View.TRANSLATION_Y, -DIST_Y);
        //            PropertyValuesHolder pvhsX = PropertyValuesHolder.ofFloat(View.SCALE_X, 1);
        //            PropertyValuesHolder pvhsY = PropertyValuesHolder.ofFloat(View.SCALE_Y, 1);
        PropertyValuesHolder pvhA = PropertyValuesHolder.ofFloat(View.ALPHA, 1);
        final ObjectAnimator animation = ObjectAnimator.ofPropertyValuesHolder(menu.getSubActionItems().get(i).view, pvhY, pvhA);
        animation.setDuration(DURATION);
        animation.setInterpolator(new DecelerateInterpolator());
        animation.addListener(new SubActionItemAnimationListener(menu.getSubActionItems().get(i), ActionType.OPENING));
        if (i == 0) {
            lastAnimation = animation;
        }
        animation.setStartDelay(Math.abs(menu.getSubActionItems().size() / 2 - i) * LAG_BETWEEN_ITEMS);
        animation.start();
    }
    if (lastAnimation != null) {
        lastAnimation.addListener(new LastAnimationListener());
    }
}
Also used : DecelerateInterpolator(android.view.animation.DecelerateInterpolator) ObjectAnimator(android.animation.ObjectAnimator) Animator(android.animation.Animator) ObjectAnimator(android.animation.ObjectAnimator) FrameLayout(android.widget.FrameLayout) PropertyValuesHolder(android.animation.PropertyValuesHolder) Point(android.graphics.Point)

Example 47 with PropertyValuesHolder

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

the class SlideInAnimationHandler method animateMenuClosing.

@Override
public void animateMenuClosing(Point center) {
    super.animateMenuOpening(center);
    setAnimating(true);
    Animator lastAnimation = null;
    for (int i = 0; i < menu.getSubActionItems().size(); i++) {
        //            PropertyValuesHolder pvhX = PropertyValuesHolder.ofFloat(View.TRANSLATION_X, - (menu.getSubActionItems().get(i).x - center.x + menu.getSubActionItems().get(i).width / 2));
        PropertyValuesHolder pvhY = PropertyValuesHolder.ofFloat(View.TRANSLATION_Y, DIST_Y);
        //            PropertyValuesHolder pvhsX = PropertyValuesHolder.ofFloat(View.SCALE_X, 0);
        //            PropertyValuesHolder pvhsY = PropertyValuesHolder.ofFloat(View.SCALE_Y, 0);
        PropertyValuesHolder pvhA = PropertyValuesHolder.ofFloat(View.ALPHA, 0);
        final ObjectAnimator animation = ObjectAnimator.ofPropertyValuesHolder(menu.getSubActionItems().get(i).view, pvhY, pvhA);
        animation.setDuration(DURATION);
        animation.setInterpolator(new AccelerateInterpolator());
        animation.addListener(new SubActionItemAnimationListener(menu.getSubActionItems().get(i), ActionType.CLOSING));
        if (i == 0) {
            lastAnimation = animation;
        }
        if (i <= menu.getSubActionItems().size() / 2) {
            animation.setStartDelay(i * LAG_BETWEEN_ITEMS);
        } else {
            animation.setStartDelay((menu.getSubActionItems().size() - i) * LAG_BETWEEN_ITEMS);
        }
        animation.start();
    }
    if (lastAnimation != null) {
        lastAnimation.addListener(new LastAnimationListener());
    }
}
Also used : ObjectAnimator(android.animation.ObjectAnimator) Animator(android.animation.Animator) AccelerateInterpolator(android.view.animation.AccelerateInterpolator) ObjectAnimator(android.animation.ObjectAnimator) PropertyValuesHolder(android.animation.PropertyValuesHolder) Point(android.graphics.Point)

Example 48 with PropertyValuesHolder

use of android.animation.PropertyValuesHolder in project android_frameworks_base by DirtyUnicorns.

the class AnimatedVectorDrawable method updateAnimatorProperty.

private static void updateAnimatorProperty(Animator animator, String targetName, VectorDrawable vectorDrawable, boolean ignoreInvalidAnim) {
    if (animator instanceof ObjectAnimator) {
        // Change the property of the Animator from using reflection based on the property
        // name to a Property object that wraps the setter and getter for modifying that
        // specific property for a given object. By replacing the reflection with a direct call,
        // we can largely reduce the time it takes for a animator to modify a VD property.
        PropertyValuesHolder[] holders = ((ObjectAnimator) animator).getValues();
        for (int i = 0; i < holders.length; i++) {
            PropertyValuesHolder pvh = holders[i];
            String propertyName = pvh.getPropertyName();
            Object targetNameObj = vectorDrawable.getTargetByName(targetName);
            Property property = null;
            if (targetNameObj instanceof VectorDrawable.VObject) {
                property = ((VectorDrawable.VObject) targetNameObj).getProperty(propertyName);
            } else if (targetNameObj instanceof VectorDrawable.VectorDrawableState) {
                property = ((VectorDrawable.VectorDrawableState) targetNameObj).getProperty(propertyName);
            }
            if (property != null) {
                if (containsSameValueType(pvh, property)) {
                    pvh.setProperty(property);
                } else if (!ignoreInvalidAnim) {
                    throw new RuntimeException("Wrong valueType for Property: " + propertyName + ".  Expected type: " + property.getType().toString() + ". Actual " + "type defined in resources: " + pvh.getValueType().toString());
                }
            }
        }
    } else if (animator instanceof AnimatorSet) {
        for (Animator anim : ((AnimatorSet) animator).getChildAnimations()) {
            updateAnimatorProperty(anim, targetName, vectorDrawable, ignoreInvalidAnim);
        }
    }
}
Also used : ObjectAnimator(android.animation.ObjectAnimator) AnimatorSet(android.animation.AnimatorSet) Animator(android.animation.Animator) ObjectAnimator(android.animation.ObjectAnimator) ValueAnimator(android.animation.ValueAnimator) PropertyValuesHolder(android.animation.PropertyValuesHolder) Property(android.util.Property)

Example 49 with PropertyValuesHolder

use of android.animation.PropertyValuesHolder in project android_frameworks_base by DirtyUnicorns.

the class NotificationStackScrollLayout method startBottomAnimation.

private void startBottomAnimation() {
    int previousStartValue = mStartAnimationRect.bottom;
    int previousEndValue = mEndAnimationRect.bottom;
    int newEndValue = mBackgroundBounds.bottom;
    ObjectAnimator previousAnimator = mBottomAnimator;
    if (previousAnimator != null && previousEndValue == newEndValue) {
        return;
    }
    if (!mAnimateNextBackgroundBottom) {
        // just a local update was performed
        if (previousAnimator != null) {
            // we need to increase all animation keyframes of the previous animator by the
            // relative change to the end value
            PropertyValuesHolder[] values = previousAnimator.getValues();
            values[0].setIntValues(previousStartValue, newEndValue);
            mStartAnimationRect.bottom = previousStartValue;
            mEndAnimationRect.bottom = newEndValue;
            previousAnimator.setCurrentPlayTime(previousAnimator.getCurrentPlayTime());
            return;
        } else {
            // no new animation needed, let's just apply the value
            setBackgroundBottom(newEndValue);
            return;
        }
    }
    if (previousAnimator != null) {
        previousAnimator.cancel();
    }
    ObjectAnimator animator = ObjectAnimator.ofInt(this, "backgroundBottom", mCurrentBounds.bottom, newEndValue);
    Interpolator interpolator = Interpolators.FAST_OUT_SLOW_IN;
    animator.setInterpolator(interpolator);
    animator.setDuration(StackStateAnimator.ANIMATION_DURATION_STANDARD);
    // remove the tag when the animation is finished
    animator.addListener(new AnimatorListenerAdapter() {

        @Override
        public void onAnimationEnd(Animator animation) {
            mStartAnimationRect.bottom = -1;
            mEndAnimationRect.bottom = -1;
            mBottomAnimator = null;
        }
    });
    animator.start();
    mStartAnimationRect.bottom = mCurrentBounds.bottom;
    mEndAnimationRect.bottom = newEndValue;
    mBottomAnimator = animator;
}
Also used : Animator(android.animation.Animator) ObjectAnimator(android.animation.ObjectAnimator) TimeAnimator(android.animation.TimeAnimator) ValueAnimator(android.animation.ValueAnimator) ObjectAnimator(android.animation.ObjectAnimator) AnimatorListenerAdapter(android.animation.AnimatorListenerAdapter) PropertyValuesHolder(android.animation.PropertyValuesHolder) Interpolator(android.view.animation.Interpolator) Paint(android.graphics.Paint)

Example 50 with PropertyValuesHolder

use of android.animation.PropertyValuesHolder in project android_frameworks_base by DirtyUnicorns.

the class StackView method transformViewForTransition.

/**
     * Animate the views between different relative indexes within the {@link AdapterViewAnimator}
     */
void transformViewForTransition(int fromIndex, int toIndex, final View view, boolean animate) {
    if (!animate) {
        ((StackFrame) view).cancelSliderAnimator();
        view.setRotationX(0f);
        LayoutParams lp = (LayoutParams) view.getLayoutParams();
        lp.setVerticalOffset(0);
        lp.setHorizontalOffset(0);
    }
    if (fromIndex == -1 && toIndex == getNumActiveViews() - 1) {
        transformViewAtIndex(toIndex, view, false);
        view.setVisibility(VISIBLE);
        view.setAlpha(1.0f);
    } else if (fromIndex == 0 && toIndex == 1) {
        // Slide item in
        ((StackFrame) view).cancelSliderAnimator();
        view.setVisibility(VISIBLE);
        int duration = Math.round(mStackSlider.getDurationForNeutralPosition(mYVelocity));
        StackSlider animationSlider = new StackSlider(mStackSlider);
        animationSlider.setView(view);
        if (animate) {
            PropertyValuesHolder slideInY = PropertyValuesHolder.ofFloat("YProgress", 0.0f);
            PropertyValuesHolder slideInX = PropertyValuesHolder.ofFloat("XProgress", 0.0f);
            ObjectAnimator slideIn = ObjectAnimator.ofPropertyValuesHolder(animationSlider, slideInX, slideInY);
            slideIn.setDuration(duration);
            slideIn.setInterpolator(new LinearInterpolator());
            ((StackFrame) view).setSliderAnimator(slideIn);
            slideIn.start();
        } else {
            animationSlider.setYProgress(0f);
            animationSlider.setXProgress(0f);
        }
    } else if (fromIndex == 1 && toIndex == 0) {
        // Slide item out
        ((StackFrame) view).cancelSliderAnimator();
        int duration = Math.round(mStackSlider.getDurationForOffscreenPosition(mYVelocity));
        StackSlider animationSlider = new StackSlider(mStackSlider);
        animationSlider.setView(view);
        if (animate) {
            PropertyValuesHolder slideOutY = PropertyValuesHolder.ofFloat("YProgress", 1.0f);
            PropertyValuesHolder slideOutX = PropertyValuesHolder.ofFloat("XProgress", 0.0f);
            ObjectAnimator slideOut = ObjectAnimator.ofPropertyValuesHolder(animationSlider, slideOutX, slideOutY);
            slideOut.setDuration(duration);
            slideOut.setInterpolator(new LinearInterpolator());
            ((StackFrame) view).setSliderAnimator(slideOut);
            slideOut.start();
        } else {
            animationSlider.setYProgress(1.0f);
            animationSlider.setXProgress(0f);
        }
    } else if (toIndex == 0) {
        // Make sure this view that is "waiting in the wings" is invisible
        view.setAlpha(0.0f);
        view.setVisibility(INVISIBLE);
    } else if ((fromIndex == 0 || fromIndex == 1) && toIndex > 1) {
        view.setVisibility(VISIBLE);
        view.setAlpha(1.0f);
        view.setRotationX(0f);
        LayoutParams lp = (LayoutParams) view.getLayoutParams();
        lp.setVerticalOffset(0);
        lp.setHorizontalOffset(0);
    } else if (fromIndex == -1) {
        view.setAlpha(1.0f);
        view.setVisibility(VISIBLE);
    } else if (toIndex == -1) {
        if (animate) {
            postDelayed(new Runnable() {

                public void run() {
                    view.setAlpha(0);
                }
            }, STACK_RELAYOUT_DURATION);
        } else {
            view.setAlpha(0f);
        }
    }
    // Implement the faked perspective
    if (toIndex != -1) {
        transformViewAtIndex(toIndex, view, animate);
    }
}
Also used : LinearInterpolator(android.view.animation.LinearInterpolator) ObjectAnimator(android.animation.ObjectAnimator) PropertyValuesHolder(android.animation.PropertyValuesHolder) Paint(android.graphics.Paint)

Aggregations

PropertyValuesHolder (android.animation.PropertyValuesHolder)210 ObjectAnimator (android.animation.ObjectAnimator)144 Animator (android.animation.Animator)96 AnimatorListenerAdapter (android.animation.AnimatorListenerAdapter)70 ValueAnimator (android.animation.ValueAnimator)64 Paint (android.graphics.Paint)33 AnimatorSet (android.animation.AnimatorSet)25 NonNull (android.support.annotation.NonNull)18 LinearInterpolator (android.view.animation.LinearInterpolator)18 Interpolator (android.view.animation.Interpolator)16 ArrayList (java.util.ArrayList)16 ViewGroup (android.view.ViewGroup)14 View (android.view.View)12 IntEvaluator (android.animation.IntEvaluator)11 Point (android.graphics.Point)11 Keyframe (android.animation.Keyframe)10 TimeAnimator (android.animation.TimeAnimator)10 Path (android.graphics.Path)10 AccelerateDecelerateInterpolator (android.view.animation.AccelerateDecelerateInterpolator)8 Rect (android.graphics.Rect)7