Search in sources :

Example 66 with ValueAnimator

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

the class AppBarLayout method startReveal.

@Override
public Animator startReveal(int x, int y, float startRadius, float finishRadius) {
    if (Build.VERSION.SDK_INT > Build.VERSION_CODES.KITKAT_WATCH) {
        android.animation.Animator circularReveal = ViewAnimationUtils.createCircularReveal(this, x, y, startRadius, finishRadius);
        circularReveal.start();
        return new Animator() {

            @Override
            @RequiresApi(api = Build.VERSION_CODES.HONEYCOMB)
            public long getStartDelay() {
                return circularReveal.getStartDelay();
            }

            @Override
            @RequiresApi(api = Build.VERSION_CODES.HONEYCOMB)
            public void setStartDelay(long startDelay) {
                circularReveal.setStartDelay(startDelay);
            }

            @Override
            @RequiresApi(api = Build.VERSION_CODES.HONEYCOMB)
            public Animator setDuration(long duration) {
                circularReveal.setDuration(duration);
                return this;
            }

            @Override
            @RequiresApi(api = Build.VERSION_CODES.HONEYCOMB)
            public long getDuration() {
                return circularReveal.getDuration();
            }

            @Override
            @RequiresApi(api = Build.VERSION_CODES.HONEYCOMB)
            public void setInterpolator(Interpolator value) {
                circularReveal.setInterpolator(value);
            }

            @Override
            @RequiresApi(api = Build.VERSION_CODES.HONEYCOMB)
            public boolean isRunning() {
                return circularReveal.isRunning();
            }
        };
    } else {
        reveal = new Reveal(x, y, startRadius);
        ValueAnimator animator = ValueAnimator.ofFloat(startRadius, finishRadius);
        animator.setDuration(Carbon.getDefaultRevealDuration());
        animator.addUpdateListener(animation -> {
            reveal.radius = (float) animation.getAnimatedValue();
            reveal.mask.reset();
            reveal.mask.addCircle(reveal.x, reveal.y, Math.max(reveal.radius, 1), Path.Direction.CW);
            postInvalidate();
        });
        animator.addListener(new AnimatorListenerAdapter() {

            @Override
            public void onAnimationCancel(Animator animation) {
                reveal = null;
            }

            @Override
            public void onAnimationEnd(Animator animation) {
                reveal = null;
            }
        });
        animator.start();
        return animator;
    }
}
Also used : ValueAnimator(com.nineoldandroids.animation.ValueAnimator) Animator(com.nineoldandroids.animation.Animator) StateAnimator(carbon.animation.StateAnimator) AnimatorListenerAdapter(com.nineoldandroids.animation.AnimatorListenerAdapter) Interpolator(android.view.animation.Interpolator) ValueAnimator(com.nineoldandroids.animation.ValueAnimator) Reveal(carbon.internal.Reveal)

Example 67 with ValueAnimator

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

the class AnimUtils method fadeOut.

public static ValueAnimator fadeOut(final View view, Animator.AnimatorListener listener) {
    float start = ViewHelper.getAlpha(view);
    ValueAnimator animator = ValueAnimator.ofFloat(start, 0);
    animator.setDuration((long) (200 * start));
    animator.setInterpolator(new DecelerateInterpolator());
    if (listener != null)
        animator.addListener(listener);
    animator.addUpdateListener(valueAnimator -> {
        ViewHelper.setAlpha(view, (Float) valueAnimator.getAnimatedValue());
        if (view.getParent() != null)
            ((View) view.getParent()).postInvalidate();
    });
    animator.start();
    return animator;
}
Also used : AccelerateDecelerateInterpolator(android.view.animation.AccelerateDecelerateInterpolator) DecelerateInterpolator(android.view.animation.DecelerateInterpolator) ValueAnimator(com.nineoldandroids.animation.ValueAnimator)

Example 68 with ValueAnimator

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

the class AnimUtils method brightnessSaturationFadeOut.

public static ValueAnimator brightnessSaturationFadeOut(final ImageView imageView, Animator.AnimatorListener listener) {
    final ValueAnimator animator = ValueAnimator.ofFloat(1, 0);
    final AccelerateDecelerateInterpolator interpolator = new AccelerateDecelerateInterpolator();
    animator.setInterpolator(interpolator);
    animator.setDuration(800);
    if (listener != null)
        animator.addListener(listener);
    animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {

        ColorMatrix saturationMatrix = new ColorMatrix();

        ColorMatrix brightnessMatrix = new ColorMatrix();

        @Override
        public void onAnimationUpdate(ValueAnimator valueAnimator) {
            float fraction = animator.getAnimatedFraction();
            saturationMatrix.setSaturation((Float) animator.getAnimatedValue());
            float scale = 2 - interpolator.getInterpolation(Math.min((1 - fraction) * 4 / 3, 1));
            brightnessMatrix.setScale(scale, scale, scale, interpolator.getInterpolation(Math.min((1 - fraction) * 2, 1)));
            saturationMatrix.preConcat(brightnessMatrix);
            imageView.setColorFilter(new ColorMatrixColorFilter(saturationMatrix));
            if (imageView.getParent() != null)
                ((View) imageView.getParent()).postInvalidate();
        }
    });
    animator.start();
    return animator;
}
Also used : ColorMatrixColorFilter(android.graphics.ColorMatrixColorFilter) AccelerateDecelerateInterpolator(android.view.animation.AccelerateDecelerateInterpolator) ColorMatrix(android.graphics.ColorMatrix) ValueAnimator(com.nineoldandroids.animation.ValueAnimator) ImageView(android.widget.ImageView) View(android.view.View) ShadowView(carbon.shadow.ShadowView)

Example 69 with ValueAnimator

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

the class AnimUtils method popIn.

public static ValueAnimator popIn(final View view, Animator.AnimatorListener listener) {
    if (view.getVisibility() != View.VISIBLE)
        ViewHelper.setAlpha(view, 0);
    float start = ViewHelper.getAlpha(view);
    ValueAnimator animator = ValueAnimator.ofFloat(start, 1);
    animator.setDuration((long) (200 * (1 - start)));
    animator.setInterpolator(new DecelerateInterpolator());
    if (listener != null)
        animator.addListener(listener);
    animator.addUpdateListener(valueAnimator -> {
        ViewHelper.setAlpha(view, (Float) valueAnimator.getAnimatedValue());
        ViewHelper.setScaleX(view, (Float) valueAnimator.getAnimatedValue());
        ViewHelper.setScaleY(view, (Float) valueAnimator.getAnimatedValue());
        if (view.getParent() != null)
            ((View) view.getParent()).postInvalidate();
    });
    animator.start();
    return animator;
}
Also used : AccelerateDecelerateInterpolator(android.view.animation.AccelerateDecelerateInterpolator) DecelerateInterpolator(android.view.animation.DecelerateInterpolator) ValueAnimator(com.nineoldandroids.animation.ValueAnimator)

Example 70 with ValueAnimator

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

the class AnimUtils method fadeIn.

public static ValueAnimator fadeIn(final View view, Animator.AnimatorListener listener) {
    if (view.getVisibility() != View.VISIBLE)
        ViewHelper.setAlpha(view, 0);
    float start = ViewHelper.getAlpha(view);
    ValueAnimator animator = ValueAnimator.ofFloat(start, 1);
    animator.setDuration((long) (200 * (1 - start)));
    animator.setInterpolator(new DecelerateInterpolator());
    if (listener != null)
        animator.addListener(listener);
    animator.addUpdateListener(valueAnimator -> {
        ViewHelper.setAlpha(view, (Float) valueAnimator.getAnimatedValue());
        if (view.getParent() != null)
            ((View) view.getParent()).postInvalidate();
    });
    animator.start();
    return animator;
}
Also used : AccelerateDecelerateInterpolator(android.view.animation.AccelerateDecelerateInterpolator) DecelerateInterpolator(android.view.animation.DecelerateInterpolator) 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