Search in sources :

Example 71 with ValueAnimator

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

the class AnimUtils method progressWidthOut.

public static ValueAnimator progressWidthOut(final ProgressBar circularProgress, Animator.AnimatorListener listener) {
    final float arcWidth = circularProgress.getBarPadding() + circularProgress.getBarWidth();
    float start = circularProgress.getBarWidth();
    ValueAnimator animator = ValueAnimator.ofFloat(start, 0);
    animator.setDuration((long) (100 * start));
    animator.setInterpolator(new DecelerateInterpolator());
    if (listener != null)
        animator.addListener(listener);
    animator.addUpdateListener(valueAnimator -> {
        float value = (Float) valueAnimator.getAnimatedValue();
        circularProgress.setBarWidth(value);
        circularProgress.setBarPadding(arcWidth - value);
    });
    animator.start();
    return animator;
}
Also used : AccelerateDecelerateInterpolator(android.view.animation.AccelerateDecelerateInterpolator) DecelerateInterpolator(android.view.animation.DecelerateInterpolator) ValueAnimator(com.nineoldandroids.animation.ValueAnimator)

Example 72 with ValueAnimator

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

the class AnimUtils method flyOut.

public static ValueAnimator flyOut(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());
        ViewHelper.setTranslationY(view, Math.min(view.getHeight() / 2, view.getResources().getDimension(R.dimen.carbon_1dip) * 50.0f) * (1 - (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 73 with ValueAnimator

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

the class Snackbar method show.

public void show(final ViewGroup container) {
    synchronized (Snackbar.class) {
        this.container = container;
        if (!next.contains(this))
            next.add(this);
        if (next.indexOf(this) == 0) {
            Rect windowFrame = new Rect();
            container.getWindowVisibleDisplayFrame(windowFrame);
            Rect drawingRect = new Rect();
            container.getDrawingRect(drawingRect);
            setPadding(0, 0, 0, drawingRect.bottom - windowFrame.bottom);
            container.addView(this);
            ViewHelper.setAlpha(content, 0);
            AnimUtils.flyIn(content, null);
            for (final View pushedView : pushedViews) {
                ValueAnimator animator = ValueAnimator.ofFloat(0, -1);
                animator.setDuration(200);
                animator.setInterpolator(new DecelerateInterpolator());
                animator.addUpdateListener(valueAnimator -> {
                    MarginLayoutParams lp = (MarginLayoutParams) content.getLayoutParams();
                    ViewHelper.setTranslationY(pushedView, (content.getHeight() + lp.bottomMargin) * (Float) valueAnimator.getAnimatedValue());
                    if (pushedView.getParent() != null)
                        ((View) pushedView.getParent()).postInvalidate();
                });
                animator.start();
            }
            if (duration != INFINITE)
                handler.postDelayed(hideRunnable, duration);
        }
    }
}
Also used : DecelerateInterpolator(android.view.animation.DecelerateInterpolator) Rect(android.graphics.Rect) ValueAnimator(com.nineoldandroids.animation.ValueAnimator) View(android.view.View)

Example 74 with ValueAnimator

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

the class Snackbar method onScroll.

@Override
public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {
    if (swipeToDismiss && animator == null && getParent() != null) {
        swipe = e2.getX() - e1.getX();
        ViewHelper.setTranslationX(content, swipe);
        ViewHelper.setAlpha(content, Math.max(0, 1 - 2 * Math.abs(swipe) / content.getMeasuredWidth()));
        if (Math.abs(swipe) > content.getMeasuredWidth() / 4) {
            handler.removeCallbacks(hideRunnable);
            animator = ObjectAnimator.ofFloat(swipe, content.getMeasuredWidth() / 2.0f * Math.signum(swipe));
            animator.setDuration(200);
            animator.addUpdateListener(valueAnimator -> {
                float s = (Float) valueAnimator.getAnimatedValue();
                ViewHelper.setTranslationX(content, s);
                float alpha = Math.max(0, 1 - 2 * Math.abs((Float) valueAnimator.getAnimatedValue()) / content.getMeasuredWidth());
                ViewHelper.setAlpha(content, alpha);
            });
            animator.start();
            animator.addListener(new AnimatorListenerAdapter() {

                @Override
                public void onAnimationEnd(Animator animation) {
                    hideInternal();
                    animator = null;
                }
            });
            for (final View pushedView : pushedViews) {
                ValueAnimator animator = ValueAnimator.ofFloat(-1, 0);
                animator.setDuration(200);
                animator.setInterpolator(new DecelerateInterpolator());
                animator.addUpdateListener(valueAnimator -> {
                    MarginLayoutParams lp = (MarginLayoutParams) content.getLayoutParams();
                    ViewHelper.setTranslationY(pushedView, (content.getHeight() + lp.bottomMargin) * (Float) valueAnimator.getAnimatedValue());
                    if (pushedView.getParent() != null)
                        ((View) pushedView.getParent()).postInvalidate();
                });
                animator.start();
            }
        }
        return true;
    }
    return false;
}
Also used : DecelerateInterpolator(android.view.animation.DecelerateInterpolator) ValueAnimator(com.nineoldandroids.animation.ValueAnimator) Animator(com.nineoldandroids.animation.Animator) ObjectAnimator(com.nineoldandroids.animation.ObjectAnimator) AnimatorListenerAdapter(com.nineoldandroids.animation.AnimatorListenerAdapter) ValueAnimator(com.nineoldandroids.animation.ValueAnimator) View(android.view.View)

Example 75 with ValueAnimator

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

the class TextView 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)
                    TextView.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