Search in sources :

Example 76 with PropertyValuesHolder

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

the class StackStateAnimator method startHeightAnimation.

private void startHeightAnimation(final ExpandableView child, StackViewState viewState, long duration, long delay) {
    Integer previousStartValue = getChildTag(child, TAG_START_HEIGHT);
    Integer previousEndValue = getChildTag(child, TAG_END_HEIGHT);
    int newEndValue = viewState.height;
    if (previousEndValue != null && previousEndValue == newEndValue) {
        return;
    }
    ValueAnimator previousAnimator = getChildTag(child, TAG_ANIMATOR_HEIGHT);
    if (!mAnimationFilter.animateHeight) {
        // 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();
            int relativeDiff = newEndValue - previousEndValue;
            int newStartValue = previousStartValue + relativeDiff;
            values[0].setIntValues(newStartValue, newEndValue);
            child.setTag(TAG_START_HEIGHT, newStartValue);
            child.setTag(TAG_END_HEIGHT, newEndValue);
            previousAnimator.setCurrentPlayTime(previousAnimator.getCurrentPlayTime());
            return;
        } else {
            // no new animation needed, let's just apply the value
            child.setActualHeight(newEndValue, false);
            return;
        }
    }
    ValueAnimator animator = ValueAnimator.ofInt(child.getActualHeight(), newEndValue);
    animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {

        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            child.setActualHeight((int) animation.getAnimatedValue(), false);
        }
    });
    animator.setInterpolator(Interpolators.FAST_OUT_SLOW_IN);
    long newDuration = cancelAnimatorAndGetNewDuration(duration, previousAnimator);
    animator.setDuration(newDuration);
    if (delay > 0 && (previousAnimator == null || previousAnimator.getAnimatedFraction() == 0)) {
        animator.setStartDelay(delay);
    }
    animator.addListener(getGlobalAnimationFinishedListener());
    // remove the tag when the animation is finished
    animator.addListener(new AnimatorListenerAdapter() {

        boolean mWasCancelled;

        @Override
        public void onAnimationEnd(Animator animation) {
            child.setTag(TAG_ANIMATOR_HEIGHT, null);
            child.setTag(TAG_START_HEIGHT, null);
            child.setTag(TAG_END_HEIGHT, null);
            child.setActualHeightAnimating(false);
            if (!mWasCancelled && child instanceof ExpandableNotificationRow) {
                ((ExpandableNotificationRow) child).setGroupExpansionChanging(false);
            }
        }

        @Override
        public void onAnimationStart(Animator animation) {
            mWasCancelled = false;
        }

        @Override
        public void onAnimationCancel(Animator animation) {
            mWasCancelled = true;
        }
    });
    startAnimator(animator);
    child.setTag(TAG_ANIMATOR_HEIGHT, animator);
    child.setTag(TAG_START_HEIGHT, child.getActualHeight());
    child.setTag(TAG_END_HEIGHT, newEndValue);
    child.setActualHeightAnimating(true);
}
Also used : ObjectAnimator(android.animation.ObjectAnimator) Animator(android.animation.Animator) ValueAnimator(android.animation.ValueAnimator) AnimatorListenerAdapter(android.animation.AnimatorListenerAdapter) PropertyValuesHolder(android.animation.PropertyValuesHolder) ValueAnimator(android.animation.ValueAnimator) ExpandableNotificationRow(com.android.systemui.statusbar.ExpandableNotificationRow)

Example 77 with PropertyValuesHolder

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

the class ScrimController method updateScrim.

private void updateScrim(boolean animate, View scrim, float alpha, float currentAlpha) {
    if (mKeyguardFadingOutInProgress) {
        return;
    }
    ValueAnimator previousAnimator = StackStateAnimator.getChildTag(scrim, TAG_KEY_ANIM);
    float animEndValue = -1;
    if (previousAnimator != null) {
        if (animate || alpha == currentAlpha) {
            previousAnimator.cancel();
        } else {
            animEndValue = StackStateAnimator.getChildTag(scrim, TAG_END_ALPHA);
        }
    }
    if (alpha != currentAlpha && alpha != animEndValue) {
        if (animate) {
            startScrimAnimation(scrim, alpha);
            scrim.setTag(TAG_START_ALPHA, currentAlpha);
            scrim.setTag(TAG_END_ALPHA, alpha);
        } else {
            if (previousAnimator != null) {
                float previousStartValue = StackStateAnimator.getChildTag(scrim, TAG_START_ALPHA);
                float previousEndValue = StackStateAnimator.getChildTag(scrim, TAG_END_ALPHA);
                // we need to increase all animation keyframes of the previous animator by the
                // relative change to the end value
                PropertyValuesHolder[] values = previousAnimator.getValues();
                float relativeDiff = alpha - previousEndValue;
                float newStartValue = previousStartValue + relativeDiff;
                newStartValue = Math.max(0, Math.min(1.0f, newStartValue));
                values[0].setFloatValues(newStartValue, alpha);
                scrim.setTag(TAG_START_ALPHA, newStartValue);
                scrim.setTag(TAG_END_ALPHA, alpha);
                previousAnimator.setCurrentPlayTime(previousAnimator.getCurrentPlayTime());
            } else {
                // update the alpha directly
                setCurrentScrimAlpha(scrim, alpha);
                updateScrimColor(scrim);
            }
        }
    }
}
Also used : PropertyValuesHolder(android.animation.PropertyValuesHolder) ValueAnimator(android.animation.ValueAnimator)

Example 78 with PropertyValuesHolder

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

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 79 with PropertyValuesHolder

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

the class StackStateAnimator method startAlphaAnimation.

private void startAlphaAnimation(final View child, final ViewState viewState, long duration, long delay) {
    Float previousStartValue = getChildTag(child, TAG_START_ALPHA);
    Float previousEndValue = getChildTag(child, TAG_END_ALPHA);
    final float newEndValue = viewState.alpha;
    if (previousEndValue != null && previousEndValue == newEndValue) {
        return;
    }
    ObjectAnimator previousAnimator = getChildTag(child, TAG_ANIMATOR_ALPHA);
    if (!mAnimationFilter.animateAlpha) {
        // 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();
            float relativeDiff = newEndValue - previousEndValue;
            float newStartValue = previousStartValue + relativeDiff;
            values[0].setFloatValues(newStartValue, newEndValue);
            child.setTag(TAG_START_ALPHA, newStartValue);
            child.setTag(TAG_END_ALPHA, newEndValue);
            previousAnimator.setCurrentPlayTime(previousAnimator.getCurrentPlayTime());
            return;
        } else {
            // no new animation needed, let's just apply the value
            child.setAlpha(newEndValue);
            if (newEndValue == 0) {
                child.setVisibility(View.INVISIBLE);
            }
        }
    }
    ObjectAnimator animator = ObjectAnimator.ofFloat(child, View.ALPHA, child.getAlpha(), newEndValue);
    animator.setInterpolator(Interpolators.FAST_OUT_SLOW_IN);
    // Handle layer type
    child.setLayerType(View.LAYER_TYPE_HARDWARE, null);
    animator.addListener(new AnimatorListenerAdapter() {

        public boolean mWasCancelled;

        @Override
        public void onAnimationEnd(Animator animation) {
            child.setLayerType(View.LAYER_TYPE_NONE, null);
            if (newEndValue == 0 && !mWasCancelled) {
                child.setVisibility(View.INVISIBLE);
            }
            // remove the tag when the animation is finished
            child.setTag(TAG_ANIMATOR_ALPHA, null);
            child.setTag(TAG_START_ALPHA, null);
            child.setTag(TAG_END_ALPHA, null);
        }

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

        @Override
        public void onAnimationStart(Animator animation) {
            mWasCancelled = false;
        }
    });
    long newDuration = cancelAnimatorAndGetNewDuration(duration, previousAnimator);
    animator.setDuration(newDuration);
    if (delay > 0 && (previousAnimator == null || previousAnimator.getAnimatedFraction() == 0)) {
        animator.setStartDelay(delay);
    }
    animator.addListener(getGlobalAnimationFinishedListener());
    startAnimator(animator);
    child.setTag(TAG_ANIMATOR_ALPHA, animator);
    child.setTag(TAG_START_ALPHA, child.getAlpha());
    child.setTag(TAG_END_ALPHA, newEndValue);
}
Also used : ObjectAnimator(android.animation.ObjectAnimator) Animator(android.animation.Animator) ValueAnimator(android.animation.ValueAnimator) ObjectAnimator(android.animation.ObjectAnimator) AnimatorListenerAdapter(android.animation.AnimatorListenerAdapter) PropertyValuesHolder(android.animation.PropertyValuesHolder)

Example 80 with PropertyValuesHolder

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

the class StackStateAnimator method startHeightAnimation.

private void startHeightAnimation(final ExpandableView child, StackViewState viewState, long duration, long delay) {
    Integer previousStartValue = getChildTag(child, TAG_START_HEIGHT);
    Integer previousEndValue = getChildTag(child, TAG_END_HEIGHT);
    int newEndValue = viewState.height;
    if (previousEndValue != null && previousEndValue == newEndValue) {
        return;
    }
    ValueAnimator previousAnimator = getChildTag(child, TAG_ANIMATOR_HEIGHT);
    if (!mAnimationFilter.animateHeight) {
        // 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();
            int relativeDiff = newEndValue - previousEndValue;
            int newStartValue = previousStartValue + relativeDiff;
            values[0].setIntValues(newStartValue, newEndValue);
            child.setTag(TAG_START_HEIGHT, newStartValue);
            child.setTag(TAG_END_HEIGHT, newEndValue);
            previousAnimator.setCurrentPlayTime(previousAnimator.getCurrentPlayTime());
            return;
        } else {
            // no new animation needed, let's just apply the value
            child.setActualHeight(newEndValue, false);
            return;
        }
    }
    ValueAnimator animator = ValueAnimator.ofInt(child.getActualHeight(), newEndValue);
    animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {

        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            child.setActualHeight((int) animation.getAnimatedValue(), false);
        }
    });
    animator.setInterpolator(Interpolators.FAST_OUT_SLOW_IN);
    long newDuration = cancelAnimatorAndGetNewDuration(duration, previousAnimator);
    animator.setDuration(newDuration);
    if (delay > 0 && (previousAnimator == null || previousAnimator.getAnimatedFraction() == 0)) {
        animator.setStartDelay(delay);
    }
    animator.addListener(getGlobalAnimationFinishedListener());
    // remove the tag when the animation is finished
    animator.addListener(new AnimatorListenerAdapter() {

        boolean mWasCancelled;

        @Override
        public void onAnimationEnd(Animator animation) {
            child.setTag(TAG_ANIMATOR_HEIGHT, null);
            child.setTag(TAG_START_HEIGHT, null);
            child.setTag(TAG_END_HEIGHT, null);
            child.setActualHeightAnimating(false);
            if (!mWasCancelled && child instanceof ExpandableNotificationRow) {
                ((ExpandableNotificationRow) child).setGroupExpansionChanging(false);
            }
        }

        @Override
        public void onAnimationStart(Animator animation) {
            mWasCancelled = false;
        }

        @Override
        public void onAnimationCancel(Animator animation) {
            mWasCancelled = true;
        }
    });
    startAnimator(animator);
    child.setTag(TAG_ANIMATOR_HEIGHT, animator);
    child.setTag(TAG_START_HEIGHT, child.getActualHeight());
    child.setTag(TAG_END_HEIGHT, newEndValue);
    child.setActualHeightAnimating(true);
}
Also used : ObjectAnimator(android.animation.ObjectAnimator) Animator(android.animation.Animator) ValueAnimator(android.animation.ValueAnimator) AnimatorListenerAdapter(android.animation.AnimatorListenerAdapter) PropertyValuesHolder(android.animation.PropertyValuesHolder) ValueAnimator(android.animation.ValueAnimator) ExpandableNotificationRow(com.android.systemui.statusbar.ExpandableNotificationRow)

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