Search in sources :

Example 36 with AnimatorListenerAdapter

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

the class StackStateAnimator method startInsetAnimation.

private void startInsetAnimation(final ExpandableView child, StackViewState viewState, long duration, long delay) {
    Integer previousStartValue = getChildTag(child, TAG_START_TOP_INSET);
    Integer previousEndValue = getChildTag(child, TAG_END_TOP_INSET);
    int newEndValue = viewState.clipTopAmount;
    if (previousEndValue != null && previousEndValue == newEndValue) {
        return;
    }
    ValueAnimator previousAnimator = getChildTag(child, TAG_ANIMATOR_TOP_INSET);
    if (!mAnimationFilter.animateTopInset) {
        // 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_TOP_INSET, newStartValue);
            child.setTag(TAG_END_TOP_INSET, newEndValue);
            previousAnimator.setCurrentPlayTime(previousAnimator.getCurrentPlayTime());
            return;
        } else {
            // no new animation needed, let's just apply the value
            child.setClipTopAmount(newEndValue);
            return;
        }
    }
    ValueAnimator animator = ValueAnimator.ofInt(child.getClipTopAmount(), newEndValue);
    animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {

        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            child.setClipTopAmount((int) animation.getAnimatedValue());
        }
    });
    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() {

        @Override
        public void onAnimationEnd(Animator animation) {
            child.setTag(TAG_ANIMATOR_TOP_INSET, null);
            child.setTag(TAG_START_TOP_INSET, null);
            child.setTag(TAG_END_TOP_INSET, null);
        }
    });
    startAnimator(animator);
    child.setTag(TAG_ANIMATOR_TOP_INSET, animator);
    child.setTag(TAG_START_TOP_INSET, child.getClipTopAmount());
    child.setTag(TAG_END_TOP_INSET, newEndValue);
}
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)

Example 37 with AnimatorListenerAdapter

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

the class NightDisplayService method onActivated.

@Override
public void onActivated(boolean activated) {
    if (mIsActivated == null || mIsActivated != activated) {
        Slog.i(TAG, activated ? "Turning on night display" : "Turning off night display");
        if (mAutoMode != null) {
            mAutoMode.onActivated(activated);
        }
        mIsActivated = activated;
        // Cancel the old animator if still running.
        if (mColorMatrixAnimator != null) {
            mColorMatrixAnimator.cancel();
        }
        // Don't do any color matrix change animations if we are ignoring them anyway.
        if (mIgnoreAllColorMatrixChanges.get()) {
            return;
        }
        final DisplayTransformManager dtm = getLocalService(DisplayTransformManager.class);
        final float[] from = dtm.getColorMatrix(LEVEL_COLOR_MATRIX_NIGHT_DISPLAY);
        final float[] to = mIsActivated ? MATRIX_NIGHT : null;
        mColorMatrixAnimator = ValueAnimator.ofObject(COLOR_MATRIX_EVALUATOR, from == null ? MATRIX_IDENTITY : from, to == null ? MATRIX_IDENTITY : to);
        mColorMatrixAnimator.setDuration(getContext().getResources().getInteger(android.R.integer.config_longAnimTime));
        mColorMatrixAnimator.setInterpolator(AnimationUtils.loadInterpolator(getContext(), android.R.interpolator.fast_out_slow_in));
        mColorMatrixAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {

            @Override
            public void onAnimationUpdate(ValueAnimator animator) {
                final float[] value = (float[]) animator.getAnimatedValue();
                dtm.setColorMatrix(LEVEL_COLOR_MATRIX_NIGHT_DISPLAY, value);
            }
        });
        mColorMatrixAnimator.addListener(new AnimatorListenerAdapter() {

            private boolean mIsCancelled;

            @Override
            public void onAnimationCancel(Animator animator) {
                mIsCancelled = true;
            }

            @Override
            public void onAnimationEnd(Animator animator) {
                if (!mIsCancelled) {
                    // Ensure final color matrix is set at the end of the animation. If the
                    // animation is cancelled then don't set the final color matrix so the new
                    // animator can pick up from where this one left off.
                    dtm.setColorMatrix(LEVEL_COLOR_MATRIX_NIGHT_DISPLAY, to);
                }
                mColorMatrixAnimator = null;
            }
        });
        mColorMatrixAnimator.start();
    }
}
Also used : Animator(android.animation.Animator) ValueAnimator(android.animation.ValueAnimator) AnimatorListenerAdapter(android.animation.AnimatorListenerAdapter) ValueAnimator(android.animation.ValueAnimator)

Example 38 with AnimatorListenerAdapter

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

the class ViewTransformationHelper method transformTo.

@Override
public void transformTo(final TransformableView notification, final Runnable endRunnable) {
    if (mViewTransformationAnimation != null) {
        mViewTransformationAnimation.cancel();
    }
    mViewTransformationAnimation = ValueAnimator.ofFloat(0.0f, 1.0f);
    mViewTransformationAnimation.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {

        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            transformTo(notification, animation.getAnimatedFraction());
        }
    });
    mViewTransformationAnimation.setInterpolator(Interpolators.LINEAR);
    mViewTransformationAnimation.setDuration(StackStateAnimator.ANIMATION_DURATION_STANDARD);
    mViewTransformationAnimation.addListener(new AnimatorListenerAdapter() {

        public boolean mCancelled;

        @Override
        public void onAnimationEnd(Animator animation) {
            if (!mCancelled) {
                if (endRunnable != null) {
                    endRunnable.run();
                }
                setVisible(false);
            } else {
                abortTransformations();
            }
        }

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

Example 39 with AnimatorListenerAdapter

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

the class KeyguardAffordanceHelper method startHintAnimationPhase1.

private void startHintAnimationPhase1(final boolean right, final Runnable onFinishedListener) {
    final KeyguardAffordanceView targetView = right ? mRightIcon : mLeftIcon;
    ValueAnimator animator = getAnimatorToRadius(right, mHintGrowAmount);
    animator.addListener(new AnimatorListenerAdapter() {

        private boolean mCancelled;

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

        @Override
        public void onAnimationEnd(Animator animation) {
            if (mCancelled) {
                mSwipeAnimator = null;
                mTargetedView = null;
                onFinishedListener.run();
            } else {
                startUnlockHintAnimationPhase2(right, onFinishedListener);
            }
        }
    });
    animator.setInterpolator(Interpolators.LINEAR_OUT_SLOW_IN);
    animator.setDuration(HINT_PHASE1_DURATION);
    animator.start();
    mSwipeAnimator = animator;
    mTargetedView = targetView;
}
Also used : Animator(android.animation.Animator) ValueAnimator(android.animation.ValueAnimator) AnimatorListenerAdapter(android.animation.AnimatorListenerAdapter) KeyguardAffordanceView(com.android.systemui.statusbar.KeyguardAffordanceView) ValueAnimator(android.animation.ValueAnimator)

Example 40 with AnimatorListenerAdapter

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

the class VolumeDialogMotion method startShowAnimation.

private void startShowAnimation() {
    if (D.BUG)
        Log.d(TAG, "startShowAnimation");
    mDialogView.animate().translationY(0).setDuration(scaledDuration(300)).setInterpolator(new LogDecelerateInterpolator()).setListener(null).setUpdateListener(new AnimatorUpdateListener() {

        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            if (mChevronPositionAnimator == null)
                return;
            // reposition chevron
            final float v = (Float) mChevronPositionAnimator.getAnimatedValue();
            final int posY = chevronPosY();
            mChevron.setTranslationY(posY + v + -mDialogView.getTranslationY());
        }
    }).start();
    mContentsPositionAnimator = ValueAnimator.ofFloat(-chevronDistance(), 0).setDuration(scaledDuration(400));
    mContentsPositionAnimator.addListener(new AnimatorListenerAdapter() {

        private boolean mCancelled;

        @Override
        public void onAnimationEnd(Animator animation) {
            if (mCancelled)
                return;
            if (D.BUG)
                Log.d(TAG, "show.onAnimationEnd");
            setShowing(false);
        }

        @Override
        public void onAnimationCancel(Animator animation) {
            if (D.BUG)
                Log.d(TAG, "show.onAnimationCancel");
            mCancelled = true;
        }
    });
    mContentsPositionAnimator.addUpdateListener(new AnimatorUpdateListener() {

        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            float v = (Float) animation.getAnimatedValue();
            mContents.setTranslationY(v + -mDialogView.getTranslationY());
        }
    });
    mContentsPositionAnimator.setInterpolator(new LogDecelerateInterpolator());
    mContentsPositionAnimator.start();
    mContents.setAlpha(0);
    mContents.animate().alpha(1).setDuration(scaledDuration(150)).setInterpolator(new PathInterpolator(0f, 0f, .2f, 1f)).start();
    mChevronPositionAnimator = ValueAnimator.ofFloat(-chevronDistance(), 0).setDuration(scaledDuration(250));
    mChevronPositionAnimator.setInterpolator(new PathInterpolator(.4f, 0f, .2f, 1f));
    mChevronPositionAnimator.start();
    mChevron.setAlpha(0);
    mChevron.animate().alpha(1).setStartDelay(scaledDuration(50)).setDuration(scaledDuration(150)).setInterpolator(new PathInterpolator(.4f, 0f, 1f, 1f)).start();
}
Also used : Animator(android.animation.Animator) ValueAnimator(android.animation.ValueAnimator) AnimatorListenerAdapter(android.animation.AnimatorListenerAdapter) AnimatorUpdateListener(android.animation.ValueAnimator.AnimatorUpdateListener) ValueAnimator(android.animation.ValueAnimator) PathInterpolator(android.view.animation.PathInterpolator)

Aggregations

Animator (android.animation.Animator)868 AnimatorListenerAdapter (android.animation.AnimatorListenerAdapter)868 ObjectAnimator (android.animation.ObjectAnimator)464 ValueAnimator (android.animation.ValueAnimator)459 AnimatorSet (android.animation.AnimatorSet)144 View (android.view.View)131 ViewGroup (android.view.ViewGroup)92 PropertyValuesHolder (android.animation.PropertyValuesHolder)70 StackStateAnimator (com.android.systemui.statusbar.stack.StackStateAnimator)70 AnimatorUpdateListener (android.animation.ValueAnimator.AnimatorUpdateListener)62 ImageView (android.widget.ImageView)45 TextView (android.widget.TextView)43 Interpolator (android.view.animation.Interpolator)42 Paint (android.graphics.Paint)41 AccelerateInterpolator (android.view.animation.AccelerateInterpolator)41 Rect (android.graphics.Rect)40 RenderNodeAnimator (android.view.RenderNodeAnimator)36 DecelerateInterpolator (android.view.animation.DecelerateInterpolator)36 TimeAnimator (android.animation.TimeAnimator)30 TargetApi (android.annotation.TargetApi)30