Search in sources :

Example 41 with AnimatorListenerAdapter

use of com.nineoldandroids.animation.AnimatorListenerAdapter in project PaymentKit-Droid by brendanw.

the class AnimUtils method getShakeAnimation.

/**
     * @param shouldResetTextColor if true make sure you end the previous animation before starting this one.
     */
public static ObjectAnimator getShakeAnimation(final TextView textView, final boolean shouldResetTextColor) {
    final int textColor = textView.getCurrentTextColor();
    textView.setTextColor(Color.RED);
    ObjectAnimator shakeAnim = ObjectAnimator.ofFloat(textView, "translationX", -16);
    shakeAnim.setDuration(SHAKE_DURATION);
    shakeAnim.setInterpolator(new CycleInterpolator(2.0f));
    shakeAnim.addListener(new AnimatorListenerAdapter() {

        @Override
        public void onAnimationEnd(Animator anim) {
            if (shouldResetTextColor) {
                textView.setTextColor(textColor);
            }
        }
    });
    return shakeAnim;
}
Also used : ObjectAnimator(com.nineoldandroids.animation.ObjectAnimator) Animator(com.nineoldandroids.animation.Animator) ObjectAnimator(com.nineoldandroids.animation.ObjectAnimator) AnimatorListenerAdapter(com.nineoldandroids.animation.AnimatorListenerAdapter) CycleInterpolator(android.view.animation.CycleInterpolator)

Example 42 with AnimatorListenerAdapter

use of com.nineoldandroids.animation.AnimatorListenerAdapter 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 43 with AnimatorListenerAdapter

use of com.nineoldandroids.animation.AnimatorListenerAdapter 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 44 with AnimatorListenerAdapter

use of com.nineoldandroids.animation.AnimatorListenerAdapter 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)

Example 45 with AnimatorListenerAdapter

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

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

Animator (com.nineoldandroids.animation.Animator)68 AnimatorListenerAdapter (com.nineoldandroids.animation.AnimatorListenerAdapter)68 ValueAnimator (com.nineoldandroids.animation.ValueAnimator)49 StateAnimator (carbon.animation.StateAnimator)29 ObjectAnimator (com.nineoldandroids.animation.ObjectAnimator)16 Interpolator (android.view.animation.Interpolator)11 Reveal (carbon.internal.Reveal)11 AnimatorSet (com.nineoldandroids.animation.AnimatorSet)11 View (android.view.View)10 DecelerateInterpolator (android.view.animation.DecelerateInterpolator)7 RecyclerView (android.support.v7.widget.RecyclerView)5 SimpleItemAnimator (android.support.v7.widget.SimpleItemAnimator)4 MotionEvent (android.view.MotionEvent)3 ViewGroup (android.view.ViewGroup)3 ViewPropertyAnimator (android.view.ViewPropertyAnimator)3 AbsListView (android.widget.AbsListView)2 ListView (android.widget.ListView)2 TextView (android.widget.TextView)2 IDetailView (com.yydcdut.note.views.note.IDetailView)2 FontTextView (com.yydcdut.note.widget.FontTextView)2