Search in sources :

Example 71 with ValueAnimator

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

the class NotificationViewWrapper method startIntensityAnimation.

protected void startIntensityAnimation(ValueAnimator.AnimatorUpdateListener updateListener, boolean dark, long delay, Animator.AnimatorListener listener) {
    float startIntensity = dark ? 0f : 1f;
    float endIntensity = dark ? 1f : 0f;
    ValueAnimator animator = ValueAnimator.ofFloat(startIntensity, endIntensity);
    animator.addUpdateListener(updateListener);
    animator.setDuration(NotificationPanelView.DOZE_ANIMATION_DURATION);
    animator.setInterpolator(Interpolators.LINEAR_OUT_SLOW_IN);
    animator.setStartDelay(delay);
    if (listener != null) {
        animator.addListener(listener);
    }
    animator.start();
}
Also used : ValueAnimator(android.animation.ValueAnimator)

Example 72 with ValueAnimator

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

the class KeyguardAffordanceHelper method startUnlockHintAnimationPhase2.

/**
     * Phase 2: Move back.
     */
private void startUnlockHintAnimationPhase2(boolean right, final Runnable onFinishedListener) {
    ValueAnimator animator = getAnimatorToRadius(right, 0);
    animator.addListener(new AnimatorListenerAdapter() {

        @Override
        public void onAnimationEnd(Animator animation) {
            mSwipeAnimator = null;
            mTargetedView = null;
            onFinishedListener.run();
        }
    });
    animator.setInterpolator(Interpolators.FAST_OUT_LINEAR_IN);
    animator.setDuration(HINT_PHASE2_DURATION);
    animator.setStartDelay(HINT_CIRCLE_OPEN_DURATION);
    animator.start();
    mSwipeAnimator = animator;
}
Also used : Animator(android.animation.Animator) ValueAnimator(android.animation.ValueAnimator) AnimatorListenerAdapter(android.animation.AnimatorListenerAdapter) ValueAnimator(android.animation.ValueAnimator)

Example 73 with ValueAnimator

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

the class KeyguardAffordanceHelper method getAnimatorToRadius.

private ValueAnimator getAnimatorToRadius(final boolean right, int radius) {
    final KeyguardAffordanceView targetView = right ? mRightIcon : mLeftIcon;
    ValueAnimator animator = ValueAnimator.ofFloat(targetView.getCircleRadius(), radius);
    animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {

        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            float newRadius = (float) animation.getAnimatedValue();
            targetView.setCircleRadiusWithoutAnimation(newRadius);
            float translation = getTranslationFromRadius(newRadius);
            mTranslation = right ? -translation : translation;
            updateIconsFromTranslation(targetView);
        }
    });
    return animator;
}
Also used : KeyguardAffordanceView(com.android.systemui.statusbar.KeyguardAffordanceView) ValueAnimator(android.animation.ValueAnimator)

Example 74 with ValueAnimator

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

the class KeyguardAffordanceView method setCircleRadius.

private void setCircleRadius(float circleRadius, boolean slowAnimation, boolean noAnimation) {
    // Check if we need a new animation
    boolean radiusHidden = (mCircleAnimator != null && mCircleWillBeHidden) || (mCircleAnimator == null && mCircleRadius == 0.0f);
    boolean nowHidden = circleRadius == 0.0f;
    boolean radiusNeedsAnimation = (radiusHidden != nowHidden) && !noAnimation;
    if (!radiusNeedsAnimation) {
        if (mCircleAnimator == null) {
            mCircleRadius = circleRadius;
            updateIconColor();
            invalidate();
            if (nowHidden) {
                if (mPreviewView != null) {
                    mPreviewView.setVisibility(View.INVISIBLE);
                }
            }
        } else if (!mCircleWillBeHidden) {
            // We just update the end value
            float diff = circleRadius - mMinBackgroundRadius;
            PropertyValuesHolder[] values = mCircleAnimator.getValues();
            values[0].setFloatValues(mCircleStartValue + diff, circleRadius);
            mCircleAnimator.setCurrentPlayTime(mCircleAnimator.getCurrentPlayTime());
        }
    } else {
        cancelAnimator(mCircleAnimator);
        cancelAnimator(mPreviewClipper);
        ValueAnimator animator = getAnimatorToRadius(circleRadius);
        Interpolator interpolator = circleRadius == 0.0f ? Interpolators.FAST_OUT_LINEAR_IN : Interpolators.LINEAR_OUT_SLOW_IN;
        animator.setInterpolator(interpolator);
        long duration = 250;
        if (!slowAnimation) {
            float durationFactor = Math.abs(mCircleRadius - circleRadius) / (float) mMinBackgroundRadius;
            duration = (long) (CIRCLE_APPEAR_DURATION * durationFactor);
            duration = Math.min(duration, CIRCLE_DISAPPEAR_MAX_DURATION);
        }
        animator.setDuration(duration);
        animator.start();
        if (mPreviewView != null && mPreviewView.getVisibility() == View.VISIBLE) {
            mPreviewView.setVisibility(View.VISIBLE);
            mPreviewClipper = ViewAnimationUtils.createCircularReveal(mPreviewView, getLeft() + mCenterX, getTop() + mCenterY, mCircleRadius, circleRadius);
            mPreviewClipper.setInterpolator(interpolator);
            mPreviewClipper.setDuration(duration);
            mPreviewClipper.addListener(mClipEndListener);
            mPreviewClipper.addListener(new AnimatorListenerAdapter() {

                @Override
                public void onAnimationEnd(Animator animation) {
                    mPreviewView.setVisibility(View.INVISIBLE);
                }
            });
            mPreviewClipper.start();
        }
    }
}
Also used : Animator(android.animation.Animator) RenderNodeAnimator(android.view.RenderNodeAnimator) ValueAnimator(android.animation.ValueAnimator) AnimatorListenerAdapter(android.animation.AnimatorListenerAdapter) Interpolator(android.view.animation.Interpolator) ValueAnimator(android.animation.ValueAnimator)

Example 75 with ValueAnimator

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

the class ChangeText method createAnimator.

@Override
public Animator createAnimator(ViewGroup sceneRoot, TransitionValues startValues, TransitionValues endValues) {
    if (startValues == null || endValues == null || !(startValues.view instanceof TextView) || !(endValues.view instanceof TextView)) {
        return null;
    }
    final TextView view = (TextView) endValues.view;
    Map<String, Object> startVals = startValues.values;
    Map<String, Object> endVals = endValues.values;
    final CharSequence startText = startVals.get(PROPNAME_TEXT) != null ? (CharSequence) startVals.get(PROPNAME_TEXT) : "";
    final CharSequence endText = endVals.get(PROPNAME_TEXT) != null ? (CharSequence) endVals.get(PROPNAME_TEXT) : "";
    final int startSelectionStart, startSelectionEnd, endSelectionStart, endSelectionEnd;
    if (view instanceof EditText) {
        startSelectionStart = startVals.get(PROPNAME_TEXT_SELECTION_START) != null ? (Integer) startVals.get(PROPNAME_TEXT_SELECTION_START) : -1;
        startSelectionEnd = startVals.get(PROPNAME_TEXT_SELECTION_END) != null ? (Integer) startVals.get(PROPNAME_TEXT_SELECTION_END) : startSelectionStart;
        endSelectionStart = endVals.get(PROPNAME_TEXT_SELECTION_START) != null ? (Integer) endVals.get(PROPNAME_TEXT_SELECTION_START) : -1;
        endSelectionEnd = endVals.get(PROPNAME_TEXT_SELECTION_END) != null ? (Integer) endVals.get(PROPNAME_TEXT_SELECTION_END) : endSelectionStart;
    } else {
        startSelectionStart = startSelectionEnd = endSelectionStart = endSelectionEnd = -1;
    }
    if (!startText.equals(endText)) {
        final int startColor;
        final int endColor;
        if (mChangeBehavior != CHANGE_BEHAVIOR_IN) {
            view.setText(startText);
            if (view instanceof EditText) {
                setSelection(((EditText) view), startSelectionStart, startSelectionEnd);
            }
        }
        Animator anim;
        if (mChangeBehavior == CHANGE_BEHAVIOR_KEEP) {
            startColor = endColor = 0;
            anim = ValueAnimator.ofFloat(0, 1);
            anim.addListener(new AnimatorListenerAdapter() {

                @Override
                public void onAnimationEnd(Animator animation) {
                    if (startText.equals(view.getText())) {
                        // Only set if it hasn't been changed since anim started
                        view.setText(endText);
                        if (view instanceof EditText) {
                            setSelection(((EditText) view), endSelectionStart, endSelectionEnd);
                        }
                    }
                }
            });
        } else {
            startColor = (Integer) startVals.get(PROPNAME_TEXT_COLOR);
            endColor = (Integer) endVals.get(PROPNAME_TEXT_COLOR);
            // Fade out start text
            ValueAnimator outAnim = null, inAnim = null;
            if (mChangeBehavior == CHANGE_BEHAVIOR_OUT_IN || mChangeBehavior == CHANGE_BEHAVIOR_OUT) {
                outAnim = ValueAnimator.ofInt(255, 0);
                outAnim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {

                    @Override
                    public void onAnimationUpdate(ValueAnimator animation) {
                        int currAlpha = (Integer) animation.getAnimatedValue();
                        view.setTextColor(currAlpha << 24 | startColor & 0xff0000 | startColor & 0xff00 | startColor & 0xff);
                    }
                });
                outAnim.addListener(new AnimatorListenerAdapter() {

                    @Override
                    public void onAnimationEnd(Animator animation) {
                        if (startText.equals(view.getText())) {
                            // Only set if it hasn't been changed since anim started
                            view.setText(endText);
                            if (view instanceof EditText) {
                                setSelection(((EditText) view), endSelectionStart, endSelectionEnd);
                            }
                        }
                        // restore opaque alpha and correct end color
                        view.setTextColor(endColor);
                    }
                });
            }
            if (mChangeBehavior == CHANGE_BEHAVIOR_OUT_IN || mChangeBehavior == CHANGE_BEHAVIOR_IN) {
                inAnim = ValueAnimator.ofInt(0, 255);
                inAnim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {

                    @Override
                    public void onAnimationUpdate(ValueAnimator animation) {
                        int currAlpha = (Integer) animation.getAnimatedValue();
                        view.setTextColor(currAlpha << 24 | Color.red(endColor) << 16 | Color.green(endColor) << 8 | Color.red(endColor));
                    }
                });
                inAnim.addListener(new AnimatorListenerAdapter() {

                    @Override
                    public void onAnimationCancel(Animator animation) {
                        // restore opaque alpha and correct end color
                        view.setTextColor(endColor);
                    }
                });
            }
            if (outAnim != null && inAnim != null) {
                anim = new AnimatorSet();
                ((AnimatorSet) anim).playSequentially(outAnim, inAnim);
            } else if (outAnim != null) {
                anim = outAnim;
            } else {
                // Must be an in-only animation
                anim = inAnim;
            }
        }
        TransitionListener transitionListener = new TransitionListenerAdapter() {

            int mPausedColor = 0;

            @Override
            public void onTransitionPause(Transition transition) {
                if (mChangeBehavior != CHANGE_BEHAVIOR_IN) {
                    view.setText(endText);
                    if (view instanceof EditText) {
                        setSelection(((EditText) view), endSelectionStart, endSelectionEnd);
                    }
                }
                if (mChangeBehavior > CHANGE_BEHAVIOR_KEEP) {
                    mPausedColor = view.getCurrentTextColor();
                    view.setTextColor(endColor);
                }
            }

            @Override
            public void onTransitionResume(Transition transition) {
                if (mChangeBehavior != CHANGE_BEHAVIOR_IN) {
                    view.setText(startText);
                    if (view instanceof EditText) {
                        setSelection(((EditText) view), startSelectionStart, startSelectionEnd);
                    }
                }
                if (mChangeBehavior > CHANGE_BEHAVIOR_KEEP) {
                    view.setTextColor(mPausedColor);
                }
            }
        };
        addListener(transitionListener);
        if (DBG) {
            Log.d(LOG_TAG, "createAnimator returning " + anim);
        }
        return anim;
    }
    return null;
}
Also used : EditText(android.widget.EditText) AnimatorSet(android.animation.AnimatorSet) ValueAnimator(android.animation.ValueAnimator) Animator(android.animation.Animator) ValueAnimator(android.animation.ValueAnimator) AnimatorListenerAdapter(android.animation.AnimatorListenerAdapter) TextView(android.widget.TextView)

Aggregations

ValueAnimator (android.animation.ValueAnimator)1224 Animator (android.animation.Animator)625 AnimatorListenerAdapter (android.animation.AnimatorListenerAdapter)455 ObjectAnimator (android.animation.ObjectAnimator)187 ArrayList (java.util.ArrayList)128 Paint (android.graphics.Paint)124 AnimatorUpdateListener (android.animation.ValueAnimator.AnimatorUpdateListener)111 LinearInterpolator (android.view.animation.LinearInterpolator)102 DecelerateInterpolator (android.view.animation.DecelerateInterpolator)91 View (android.view.View)90 AnimatorSet (android.animation.AnimatorSet)87 AccelerateDecelerateInterpolator (android.view.animation.AccelerateDecelerateInterpolator)74 ArgbEvaluator (android.animation.ArgbEvaluator)57 ViewGroup (android.view.ViewGroup)44 TextView (android.widget.TextView)44 StackStateAnimator (com.android.systemui.statusbar.stack.StackStateAnimator)40 PropertyValuesHolder (android.animation.PropertyValuesHolder)36 ImageView (android.widget.ImageView)34 Interpolator (android.view.animation.Interpolator)31 SuppressLint (android.annotation.SuppressLint)25