Search in sources :

Example 21 with ValueAnimator

use of com.nineoldandroids.animation.ValueAnimator in project Carbon by ZieIony.

the class CheckableDrawable method setChecked.

public void setChecked(CheckedState state) {
    if (checkedState == state)
        return;
    if (checkedState == CheckedState.UNCHECKED) {
        if (state == CheckedState.CHECKED) {
            Animator fill = animateFill();
            fill.addListener(new AnimatorListenerAdapter() {

                @Override
                public void onAnimationEnd(Animator animation) {
                    animateCheck().start();
                }
            });
            fill.start();
        } else {
            animateFill().start();
        }
    }
    if (checkedState == CheckedState.CHECKED) {
        if (state == CheckedState.UNCHECKED) {
            ValueAnimator check = animateCheck();
            check.addListener(new AnimatorListenerAdapter() {

                @Override
                public void onAnimationEnd(Animator animation) {
                    animateFill().reverse();
                }
            });
            check.reverse();
        } else {
            animateCheck().reverse();
        }
    }
    if (checkedState == CheckedState.INDETERMINATE) {
        if (state == CheckedState.CHECKED) {
            animateCheck().start();
        } else {
            animateFill().reverse();
        }
    }
    checkedState = state;
    invalidateSelf();
}
Also used : ValueAnimator(com.nineoldandroids.animation.ValueAnimator) Animator(com.nineoldandroids.animation.Animator) AnimatorListenerAdapter(com.nineoldandroids.animation.AnimatorListenerAdapter) ValueAnimator(com.nineoldandroids.animation.ValueAnimator)

Example 22 with ValueAnimator

use of com.nineoldandroids.animation.ValueAnimator in project Carbon by ZieIony.

the class CoordinatorLayout method setVisibility.

public void setVisibility(final int visibility) {
    if (visibility == View.VISIBLE && (getVisibility() != View.VISIBLE || animator != null)) {
        if (animator != null)
            animator.cancel();
        if (inAnim != AnimUtils.Style.None) {
            animator = AnimUtils.animateIn(this, inAnim, new AnimatorListenerAdapter() {

                @Override
                public void onAnimationEnd(Animator a) {
                    animator = null;
                    clearAnimation();
                }
            });
        }
        super.setVisibility(visibility);
    } else if (visibility != View.VISIBLE && (getVisibility() == View.VISIBLE || animator != null)) {
        if (animator != null)
            animator.cancel();
        if (outAnim == AnimUtils.Style.None) {
            super.setVisibility(visibility);
            return;
        }
        animator = AnimUtils.animateOut(this, outAnim, new AnimatorListenerAdapter() {

            @Override
            public void onAnimationEnd(Animator a) {
                if (((ValueAnimator) a).getAnimatedFraction() == 1)
                    CoordinatorLayout.super.setVisibility(visibility);
                animator = null;
                clearAnimation();
            }
        });
    }
}
Also used : ValueAnimator(com.nineoldandroids.animation.ValueAnimator) Animator(com.nineoldandroids.animation.Animator) StateAnimator(carbon.animation.StateAnimator) AnimatorListenerAdapter(com.nineoldandroids.animation.AnimatorListenerAdapter) ValueAnimator(com.nineoldandroids.animation.ValueAnimator)

Example 23 with ValueAnimator

use of com.nineoldandroids.animation.ValueAnimator in project Carbon by ZieIony.

the class DefaultItemAnimator method animateMoveImpl.

private void animateMoveImpl(final RecyclerView.ViewHolder holder, int fromX, int fromY, int toX, int toY) {
    final View view = holder.itemView;
    final int deltaX = toX - fromX;
    final int deltaY = toY - fromY;
    // TODO: make EndActions end listeners instead, since end actions aren't called when
    // vpas are canceled (and can't end them. why?)
    // need listener functionality in VPACompat for this. Ick.
    final ValueAnimator animation = ValueAnimator.ofFloat(0, 1);
    mMoveAnimations.add(holder);
    animation.setDuration(getMoveDuration());
    final float startX = ViewHelper.getTranslationX(view);
    final float startY = ViewHelper.getTranslationY(view);
    animation.addUpdateListener(__ -> {
        ViewHelper.setTranslationX(view, MathUtils.lerp(startX, 0, (Float) animation.getAnimatedValue()));
        ViewHelper.setTranslationY(view, MathUtils.lerp(startY, 0, (Float) animation.getAnimatedValue()));
    });
    animation.addListener(new AnimatorListenerAdapter() {

        @Override
        public void onAnimationStart(Animator animation) {
            dispatchMoveStarting(holder);
        }

        @Override
        public void onAnimationCancel(Animator animation) {
            if (deltaX != 0) {
                ViewHelper.setTranslationX(view, 0);
            }
            if (deltaY != 0) {
                ViewHelper.setTranslationY(view, 0);
            }
        }

        @Override
        public void onAnimationEnd(Animator animation) {
            dispatchMoveFinished(holder);
            mMoveAnimations.remove(holder);
            dispatchFinishedWhenDone();
        }
    });
    animation.start();
}
Also used : ValueAnimator(com.nineoldandroids.animation.ValueAnimator) Animator(com.nineoldandroids.animation.Animator) SimpleItemAnimator(android.support.v7.widget.SimpleItemAnimator) AnimatorListenerAdapter(com.nineoldandroids.animation.AnimatorListenerAdapter) ValueAnimator(com.nineoldandroids.animation.ValueAnimator) RecyclerView(android.support.v7.widget.RecyclerView) View(android.view.View)

Example 24 with ValueAnimator

use of com.nineoldandroids.animation.ValueAnimator in project Carbon by ZieIony.

the class AppBarLayout method setVisibility.

public void setVisibility(final int visibility) {
    if (visibility == View.VISIBLE && (getVisibility() != View.VISIBLE || animator != null)) {
        if (animator != null)
            animator.cancel();
        if (inAnim != AnimUtils.Style.None) {
            animator = AnimUtils.animateIn(this, inAnim, new AnimatorListenerAdapter() {

                @Override
                public void onAnimationEnd(Animator a) {
                    animator = null;
                    clearAnimation();
                }
            });
        }
        super.setVisibility(visibility);
    } else if (visibility != View.VISIBLE && (getVisibility() == View.VISIBLE || animator != null)) {
        if (animator != null)
            animator.cancel();
        if (outAnim == AnimUtils.Style.None) {
            super.setVisibility(visibility);
            return;
        }
        animator = AnimUtils.animateOut(this, outAnim, new AnimatorListenerAdapter() {

            @Override
            public void onAnimationEnd(Animator a) {
                if (((ValueAnimator) a).getAnimatedFraction() == 1)
                    AppBarLayout.super.setVisibility(visibility);
                animator = null;
                clearAnimation();
            }
        });
    }
}
Also used : ValueAnimator(com.nineoldandroids.animation.ValueAnimator) Animator(com.nineoldandroids.animation.Animator) StateAnimator(carbon.animation.StateAnimator) AnimatorListenerAdapter(com.nineoldandroids.animation.AnimatorListenerAdapter) ValueAnimator(com.nineoldandroids.animation.ValueAnimator)

Example 25 with ValueAnimator

use of com.nineoldandroids.animation.ValueAnimator in project Carbon by ZieIony.

the class CollapsingToolbarLayout method setVisibility.

public void setVisibility(final int visibility) {
    if (visibility == View.VISIBLE && (getVisibility() != View.VISIBLE || animator != null)) {
        if (animator != null)
            animator.cancel();
        if (inAnim != AnimUtils.Style.None) {
            animator = AnimUtils.animateIn(this, inAnim, new AnimatorListenerAdapter() {

                @Override
                public void onAnimationEnd(Animator a) {
                    animator = null;
                    clearAnimation();
                }
            });
        }
        super.setVisibility(visibility);
    } else if (visibility != View.VISIBLE && (getVisibility() == View.VISIBLE || animator != null)) {
        if (animator != null)
            animator.cancel();
        if (outAnim == AnimUtils.Style.None) {
            super.setVisibility(visibility);
            return;
        }
        animator = AnimUtils.animateOut(this, outAnim, new AnimatorListenerAdapter() {

            @Override
            public void onAnimationEnd(Animator a) {
                if (((ValueAnimator) a).getAnimatedFraction() == 1)
                    CollapsingToolbarLayout.super.setVisibility(visibility);
                animator = null;
                clearAnimation();
            }
        });
    }
}
Also used : ValueAnimator(com.nineoldandroids.animation.ValueAnimator) Animator(com.nineoldandroids.animation.Animator) StateAnimator(carbon.animation.StateAnimator) AnimatorListenerAdapter(com.nineoldandroids.animation.AnimatorListenerAdapter) ValueAnimator(com.nineoldandroids.animation.ValueAnimator)

Aggregations

ValueAnimator (com.nineoldandroids.animation.ValueAnimator)105 Animator (com.nineoldandroids.animation.Animator)55 AnimatorListenerAdapter (com.nineoldandroids.animation.AnimatorListenerAdapter)46 StateAnimator (carbon.animation.StateAnimator)30 DecelerateInterpolator (android.view.animation.DecelerateInterpolator)19 View (android.view.View)17 AccelerateDecelerateInterpolator (android.view.animation.AccelerateDecelerateInterpolator)15 Interpolator (android.view.animation.Interpolator)11 Reveal (carbon.internal.Reveal)11 Paint (android.graphics.Paint)7 ObjectAnimator (com.nineoldandroids.animation.ObjectAnimator)6 AccelerateInterpolator (android.view.animation.AccelerateInterpolator)5 RecyclerView (android.support.v7.widget.RecyclerView)4 SimpleItemAnimator (android.support.v7.widget.SimpleItemAnimator)4 FrameLayout (android.widget.FrameLayout)4 ImageView (android.widget.ImageView)4 ArrayList (java.util.ArrayList)4 MotionEvent (android.view.MotionEvent)3 TouchInterceptionFrameLayout (com.github.ksoichiro.android.observablescrollview.TouchInterceptionFrameLayout)3 AnimatorUpdateListener (com.nineoldandroids.animation.ValueAnimator.AnimatorUpdateListener)3