Search in sources :

Example 41 with ValueAnimator

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

the class GridLayout 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 42 with ValueAnimator

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

the class FlowLayout 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 ValueAnimator

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

the class ShareToolbarActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_share_toolbar);
    final LinearLayout shareToolbar = (LinearLayout) findViewById(R.id.shareToolbar);
    final View root = shareToolbar.getRootView();
    findViewById(R.id.shareIcon).setOnClickListener(view -> {
        view.setVisibility(View.GONE);
        final ValueAnimator animator = ValueAnimator.ofFloat(0, 1);
        animator.setInterpolator(new AccelerateInterpolator());
        animator.addUpdateListener(animation -> {
            float frac = animator.getAnimatedFraction();
            float cornerRadius = MathUtils.lerp(shareToolbar.getHeight() / 2.0f, 0, frac);
            shareToolbar.setCornerRadius((int) cornerRadius);
            float left = MathUtils.lerp(root.getWidth() - shareToolbar.getHeight() - getResources().getDimension(R.dimen.carbon_padding), 0, frac);
            float right = MathUtils.lerp(root.getWidth() - getResources().getDimension(R.dimen.carbon_padding), root.getWidth(), frac);
            shareToolbar.layout((int) left, shareToolbar.getTop(), (int) right, shareToolbar.getBottom());
            shareToolbar.setElevation(frac);
            shareToolbar.setBackgroundColor(AnimUtils.lerpColor(frac, 0xff9ACE00, 0xffffffff));
            if (shareToolbar.getParent() != null)
                ((View) shareToolbar.getParent()).postInvalidate();
        });
        animator.setStartDelay(200);
        animator.setDuration(500);
        view.setEnabled(false);
        animator.start();
        final List<View> viewsWithTag = shareToolbar.findViewsWithTag("animate");
        view.getHandler().postDelayed(() -> {
            for (int i = 0; i < viewsWithTag.size(); i++) {
                final int finalI = i;
                view.getHandler().postDelayed(() -> viewsWithTag.get(finalI).setVisibility(View.VISIBLE), i * 40);
            }
        }, 500);
    });
}
Also used : AccelerateInterpolator(android.view.animation.AccelerateInterpolator) ValueAnimator(com.nineoldandroids.animation.ValueAnimator) View(android.view.View) LinearLayout(carbon.widget.LinearLayout)

Example 44 with ValueAnimator

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

the class Toolbar 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 45 with ValueAnimator

use of com.nineoldandroids.animation.ValueAnimator in project ElasticDownload by Tibolte.

the class PathAnimatorInflater method loadAnimator.

/**
     * Creates a new animation whose parameters come from the specified context
     * and attributes set.
     *
     * @param res   The resources
     * @param attrs The set of attributes holding the animation parameters
     * @param anim  Null if this is a ValueAnimator, otherwise this is an
     *              ObjectAnimator
     */
private static ValueAnimator loadAnimator(Context c, Resources res, Resources.Theme theme, AttributeSet attrs, ValueAnimator anim, float pathErrorScale) throws Resources.NotFoundException {
    TypedArray arrayAnimator = null;
    TypedArray arrayObjectAnimator = null;
    if (theme != null) {
        arrayAnimator = theme.obtainStyledAttributes(attrs, R.styleable.Animator, 0, 0);
    } else {
        arrayAnimator = res.obtainAttributes(attrs, R.styleable.Animator);
    }
    // If anim is not null, then it is an object animator.
    if (anim != null) {
        if (theme != null) {
            arrayObjectAnimator = theme.obtainStyledAttributes(attrs, R.styleable.PropertyAnimator, 0, 0);
        } else {
            arrayObjectAnimator = res.obtainAttributes(attrs, R.styleable.PropertyAnimator);
        }
    }
    if (anim == null) {
        anim = new ValueAnimator();
    }
    parseAnimatorFromTypeArray(anim, arrayAnimator, arrayObjectAnimator);
    final int resId = arrayAnimator.getResourceId(R.styleable.Animator_android_interpolator, 0);
    if (resId > 0) {
        anim.setInterpolator(AnimationUtils.loadInterpolator(c, resId));
    }
    arrayAnimator.recycle();
    if (arrayObjectAnimator != null) {
        arrayObjectAnimator.recycle();
    }
    return anim;
}
Also used : TypedArray(android.content.res.TypedArray) 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