Search in sources :

Example 31 with ValueAnimator

use of android.animation.ValueAnimator in project platform_frameworks_base by android.

the class ActivatableNotificationView method startAppearAnimation.

private void startAppearAnimation(boolean isAppearing, float translationDirection, long delay, long duration, final Runnable onFinishedRunnable) {
    cancelAppearAnimation();
    mAnimationTranslationY = translationDirection * getActualHeight();
    if (mAppearAnimationFraction == -1.0f) {
        // not initialized yet, we start anew
        if (isAppearing) {
            mAppearAnimationFraction = 0.0f;
            mAppearAnimationTranslation = mAnimationTranslationY;
        } else {
            mAppearAnimationFraction = 1.0f;
            mAppearAnimationTranslation = 0;
        }
    }
    float targetValue;
    if (isAppearing) {
        mCurrentAppearInterpolator = mSlowOutFastInInterpolator;
        mCurrentAlphaInterpolator = Interpolators.LINEAR_OUT_SLOW_IN;
        targetValue = 1.0f;
    } else {
        mCurrentAppearInterpolator = Interpolators.FAST_OUT_SLOW_IN;
        mCurrentAlphaInterpolator = mSlowOutLinearInInterpolator;
        targetValue = 0.0f;
    }
    mAppearAnimator = ValueAnimator.ofFloat(mAppearAnimationFraction, targetValue);
    mAppearAnimator.setInterpolator(Interpolators.LINEAR);
    mAppearAnimator.setDuration((long) (duration * Math.abs(mAppearAnimationFraction - targetValue)));
    mAppearAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {

        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            mAppearAnimationFraction = (float) animation.getAnimatedValue();
            updateAppearAnimationAlpha();
            updateAppearRect();
            invalidate();
        }
    });
    if (delay > 0) {
        // we need to apply the initial state already to avoid drawn frames in the wrong state
        updateAppearAnimationAlpha();
        updateAppearRect();
        mAppearAnimator.setStartDelay(delay);
    }
    mAppearAnimator.addListener(new AnimatorListenerAdapter() {

        private boolean mWasCancelled;

        @Override
        public void onAnimationEnd(Animator animation) {
            if (onFinishedRunnable != null) {
                onFinishedRunnable.run();
            }
            if (!mWasCancelled) {
                enableAppearDrawing(false);
                onAppearAnimationFinished(isAppearing);
            }
        }

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

        @Override
        public void onAnimationCancel(Animator animation) {
            mWasCancelled = true;
        }
    });
    mAppearAnimator.start();
}
Also used : ObjectAnimator(android.animation.ObjectAnimator) Animator(android.animation.Animator) StackStateAnimator(com.android.systemui.statusbar.stack.StackStateAnimator) TimeAnimator(android.animation.TimeAnimator) ValueAnimator(android.animation.ValueAnimator) AnimatorListenerAdapter(android.animation.AnimatorListenerAdapter) ValueAnimator(android.animation.ValueAnimator)

Example 32 with ValueAnimator

use of android.animation.ValueAnimator in project platform_frameworks_base by android.

the class ActivatableNotificationView method startActivateAnimation.

private void startActivateAnimation(final boolean reverse) {
    if (!isAttachedToWindow()) {
        return;
    }
    int widthHalf = mBackgroundNormal.getWidth() / 2;
    int heightHalf = mBackgroundNormal.getActualHeight() / 2;
    float radius = (float) Math.sqrt(widthHalf * widthHalf + heightHalf * heightHalf);
    Animator animator;
    if (reverse) {
        animator = ViewAnimationUtils.createCircularReveal(mBackgroundNormal, widthHalf, heightHalf, radius, 0);
    } else {
        animator = ViewAnimationUtils.createCircularReveal(mBackgroundNormal, widthHalf, heightHalf, 0, radius);
    }
    mBackgroundNormal.setVisibility(View.VISIBLE);
    Interpolator interpolator;
    Interpolator alphaInterpolator;
    if (!reverse) {
        interpolator = Interpolators.LINEAR_OUT_SLOW_IN;
        alphaInterpolator = Interpolators.LINEAR_OUT_SLOW_IN;
    } else {
        interpolator = ACTIVATE_INVERSE_INTERPOLATOR;
        alphaInterpolator = ACTIVATE_INVERSE_ALPHA_INTERPOLATOR;
    }
    animator.setInterpolator(interpolator);
    animator.setDuration(ACTIVATE_ANIMATION_LENGTH);
    if (reverse) {
        mBackgroundNormal.setAlpha(1f);
        animator.addListener(new AnimatorListenerAdapter() {

            @Override
            public void onAnimationEnd(Animator animation) {
                updateBackground();
            }
        });
        animator.start();
    } else {
        mBackgroundNormal.setAlpha(0.4f);
        animator.start();
    }
    mBackgroundNormal.animate().alpha(reverse ? 0f : 1f).setInterpolator(alphaInterpolator).setUpdateListener(new ValueAnimator.AnimatorUpdateListener() {

        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            float animatedFraction = animation.getAnimatedFraction();
            if (reverse) {
                animatedFraction = 1.0f - animatedFraction;
            }
            setNormalBackgroundVisibilityAmount(animatedFraction);
        }
    }).setDuration(ACTIVATE_ANIMATION_LENGTH);
}
Also used : ObjectAnimator(android.animation.ObjectAnimator) Animator(android.animation.Animator) StackStateAnimator(com.android.systemui.statusbar.stack.StackStateAnimator) TimeAnimator(android.animation.TimeAnimator) ValueAnimator(android.animation.ValueAnimator) AnimatorListenerAdapter(android.animation.AnimatorListenerAdapter) PathInterpolator(android.view.animation.PathInterpolator) Interpolator(android.view.animation.Interpolator) ValueAnimator(android.animation.ValueAnimator)

Example 33 with ValueAnimator

use of android.animation.ValueAnimator in project platform_frameworks_base by android.

the class KeyguardAffordanceView method setImageScale.

/**
     * Sets the scale of the containing image
     *
     * @param imageScale The new Scale.
     * @param animate Should an animation be performed
     * @param duration If animate, whats the duration? When -1 we take the default duration
     * @param interpolator If animate, whats the interpolator? When null we take the default
     *                     interpolator.
     */
public void setImageScale(float imageScale, boolean animate, long duration, Interpolator interpolator) {
    cancelAnimator(mScaleAnimator);
    if (!animate) {
        mImageScale = imageScale;
        invalidate();
    } else {
        ValueAnimator animator = ValueAnimator.ofFloat(mImageScale, imageScale);
        mScaleAnimator = animator;
        animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {

            @Override
            public void onAnimationUpdate(ValueAnimator animation) {
                mImageScale = (float) animation.getAnimatedValue();
                invalidate();
            }
        });
        animator.addListener(mScaleEndListener);
        if (interpolator == null) {
            interpolator = imageScale == 0.0f ? Interpolators.FAST_OUT_LINEAR_IN : Interpolators.LINEAR_OUT_SLOW_IN;
        }
        animator.setInterpolator(interpolator);
        if (duration == -1) {
            float durationFactor = Math.abs(mImageScale - imageScale) / (1.0f - MIN_ICON_SCALE_AMOUNT);
            durationFactor = Math.min(1.0f, durationFactor);
            duration = (long) (NORMAL_ANIMATION_DURATION * durationFactor);
        }
        animator.setDuration(duration);
        animator.start();
    }
}
Also used : ValueAnimator(android.animation.ValueAnimator)

Example 34 with ValueAnimator

use of android.animation.ValueAnimator in project platform_frameworks_base by android.

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 35 with ValueAnimator

use of android.animation.ValueAnimator in project platform_frameworks_base by android.

the class StackStateAnimator method animateOverScrollToAmount.

public void animateOverScrollToAmount(float targetAmount, final boolean onTop, final boolean isRubberbanded) {
    final float startOverScrollAmount = mHostLayout.getCurrentOverScrollAmount(onTop);
    if (targetAmount == startOverScrollAmount) {
        return;
    }
    cancelOverScrollAnimators(onTop);
    ValueAnimator overScrollAnimator = ValueAnimator.ofFloat(startOverScrollAmount, targetAmount);
    overScrollAnimator.setDuration(ANIMATION_DURATION_STANDARD);
    overScrollAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {

        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            float currentOverScroll = (float) animation.getAnimatedValue();
            mHostLayout.setOverScrollAmount(currentOverScroll, onTop, false, /* animate */
            false, /* cancelAnimators */
            isRubberbanded);
        }
    });
    overScrollAnimator.setInterpolator(Interpolators.FAST_OUT_SLOW_IN);
    overScrollAnimator.addListener(new AnimatorListenerAdapter() {

        @Override
        public void onAnimationEnd(Animator animation) {
            if (onTop) {
                mTopOverScrollAnimator = null;
            } else {
                mBottomOverScrollAnimator = null;
            }
        }
    });
    overScrollAnimator.start();
    if (onTop) {
        mTopOverScrollAnimator = overScrollAnimator;
    } else {
        mBottomOverScrollAnimator = overScrollAnimator;
    }
}
Also used : ObjectAnimator(android.animation.ObjectAnimator) Animator(android.animation.Animator) ValueAnimator(android.animation.ValueAnimator) AnimatorListenerAdapter(android.animation.AnimatorListenerAdapter) ValueAnimator(android.animation.ValueAnimator)

Aggregations

ValueAnimator (android.animation.ValueAnimator)745 Animator (android.animation.Animator)377 AnimatorListenerAdapter (android.animation.AnimatorListenerAdapter)307 ObjectAnimator (android.animation.ObjectAnimator)142 AnimatorUpdateListener (android.animation.ValueAnimator.AnimatorUpdateListener)88 ArrayList (java.util.ArrayList)77 Paint (android.graphics.Paint)68 AnimatorSet (android.animation.AnimatorSet)57 LinearInterpolator (android.view.animation.LinearInterpolator)56 DecelerateInterpolator (android.view.animation.DecelerateInterpolator)51 View (android.view.View)47 AccelerateDecelerateInterpolator (android.view.animation.AccelerateDecelerateInterpolator)40 StackStateAnimator (com.android.systemui.statusbar.stack.StackStateAnimator)40 PropertyValuesHolder (android.animation.PropertyValuesHolder)31 ArgbEvaluator (android.animation.ArgbEvaluator)30 ViewGroup (android.view.ViewGroup)30 Interpolator (android.view.animation.Interpolator)26 TextView (android.widget.TextView)25 RenderNodeAnimator (android.view.RenderNodeAnimator)20 Rect (android.graphics.Rect)19