Search in sources :

Example 16 with AnimatorListenerAdapter

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

the class ImageView 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)
                    ImageView.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 17 with AnimatorListenerAdapter

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

the class ProgressBar 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)
                    ProgressBar.super.setVisibility(visibility);
                animator = null;
                clearAnimation();
            }
        });
    }
}
Also used : ValueAnimator(com.nineoldandroids.animation.ValueAnimator) Animator(com.nineoldandroids.animation.Animator) AnimatorListenerAdapter(com.nineoldandroids.animation.AnimatorListenerAdapter) ValueAnimator(com.nineoldandroids.animation.ValueAnimator)

Example 18 with AnimatorListenerAdapter

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

the class RelativeLayout 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 19 with AnimatorListenerAdapter

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

the class RelativeLayout 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)
                    RelativeLayout.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 20 with AnimatorListenerAdapter

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

the class RangeSeekBar method onTouchEvent.

@Override
public boolean onTouchEvent(MotionEvent event) {
    float v = (value - min) / (max - min);
    float v2 = (value2 - min) / (max - min);
    if (event.getAction() == MotionEvent.ACTION_DOWN) {
        int thumbX = (int) (v * (getWidth() - getPaddingLeft() - getPaddingRight() - thumbRadius * 2) + getPaddingLeft() + thumbRadius);
        int thumbX2 = (int) (v2 * (getWidth() - getPaddingLeft() - getPaddingRight() - thumbRadius2 * 2) + getPaddingLeft() + thumbRadius2);
        if (Math.abs(event.getX() - thumbX) < Math.abs(event.getX() - thumbX2)) {
            draggedThumb = 1;
            if (radiusAnimator != null)
                radiusAnimator.end();
            radiusAnimator = ValueAnimator.ofFloat(thumbRadius, THUMB_RADIUS_DRAGGED);
            radiusAnimator.setDuration(200);
            radiusAnimator.setInterpolator(interpolator);
            radiusAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {

                @Override
                public void onAnimationUpdate(ValueAnimator animation) {
                    thumbRadius = (float) animation.getAnimatedValue();
                    postInvalidate();
                }
            });
            radiusAnimator.addListener(new AnimatorListenerAdapter() {

                @Override
                public void onAnimationEnd(Animator animation) {
                    radiusAnimator = null;
                }
            });
            radiusAnimator.start();
        } else {
            draggedThumb = 2;
            if (radiusAnimator != null)
                radiusAnimator.end();
            radiusAnimator = ValueAnimator.ofFloat(thumbRadius2, THUMB_RADIUS_DRAGGED);
            radiusAnimator.setDuration(200);
            radiusAnimator.setInterpolator(interpolator);
            radiusAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {

                @Override
                public void onAnimationUpdate(ValueAnimator animation) {
                    thumbRadius2 = (float) animation.getAnimatedValue();
                    postInvalidate();
                }
            });
            radiusAnimator.addListener(new AnimatorListenerAdapter() {

                @Override
                public void onAnimationEnd(Animator animation) {
                    radiusAnimator = null;
                }
            });
            radiusAnimator.start();
        }
        ViewParent parent = getParent();
        if (parent != null)
            parent.requestDisallowInterceptTouchEvent(true);
        if (showLabel)
            popup.show(this);
    } else if (event.getAction() == MotionEvent.ACTION_CANCEL || event.getAction() == MotionEvent.ACTION_UP) {
        if (draggedThumb == 1) {
            if (style == Style.Discrete) {
                float val = (float) Math.floor((value - min + step / 2) / step) * step + min;
                if (valueAnimator != null)
                    valueAnimator.cancel();
                valueAnimator = ValueAnimator.ofFloat(value, val);
                valueAnimator.setDuration(200);
                valueAnimator.setInterpolator(interpolator);
                valueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {

                    @Override
                    public void onAnimationUpdate(ValueAnimator animation) {
                        value = (float) animation.getAnimatedValue();
                        int thumbX = (int) ((value - min) / (max - min) * (getWidth() - getPaddingLeft() - getPaddingRight()) + getPaddingLeft());
                        int thumbY = getHeight() / 2;
                        int radius = rippleDrawable.getRadius();
                        rippleDrawable.setBounds(thumbX - radius, thumbY - radius, thumbX + radius, thumbY + radius);
                        postInvalidate();
                    }
                });
                valueAnimator.start();
            }
            if (radiusAnimator != null)
                radiusAnimator.end();
            radiusAnimator = ValueAnimator.ofFloat(thumbRadius, THUMB_RADIUS);
            radiusAnimator.setDuration(200);
            radiusAnimator.setInterpolator(interpolator);
            radiusAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {

                @Override
                public void onAnimationUpdate(ValueAnimator animation) {
                    thumbRadius = (float) animation.getAnimatedValue();
                    postInvalidate();
                }
            });
            radiusAnimator.start();
        } else {
            if (style == Style.Discrete) {
                float val2 = (float) Math.floor((value2 - min + step / 2) / step) * step + min;
                if (valueAnimator != null)
                    valueAnimator.cancel();
                valueAnimator = ValueAnimator.ofFloat(value2, val2);
                valueAnimator.setDuration(200);
                valueAnimator.setInterpolator(interpolator);
                valueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {

                    @Override
                    public void onAnimationUpdate(ValueAnimator animation) {
                        value2 = (float) animation.getAnimatedValue();
                        int thumbX = (int) ((value2 - min) / (max - min) * (getWidth() - getPaddingLeft() - getPaddingRight()) + getPaddingLeft());
                        int thumbY = getHeight() / 2;
                        int radius = rippleDrawable.getRadius();
                        rippleDrawable.setBounds(thumbX - radius, thumbY - radius, thumbX + radius, thumbY + radius);
                        postInvalidate();
                    }
                });
                valueAnimator.start();
            }
            if (radiusAnimator != null)
                radiusAnimator.end();
            radiusAnimator = ValueAnimator.ofFloat(thumbRadius2, THUMB_RADIUS);
            radiusAnimator.setDuration(200);
            radiusAnimator.setInterpolator(interpolator);
            radiusAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {

                @Override
                public void onAnimationUpdate(ValueAnimator animation) {
                    thumbRadius2 = (float) animation.getAnimatedValue();
                    postInvalidate();
                }
            });
            radiusAnimator.start();
        }
        //draggedThumb = -1;
        ViewParent parent = getParent();
        if (parent != null)
            parent.requestDisallowInterceptTouchEvent(false);
        if (showLabel)
            popup.dismiss();
    }
    if (draggedThumb == 1) {
        v = (event.getX() - getPaddingLeft()) / (getWidth() - getPaddingLeft() - getPaddingRight());
        v = Math.max(0, Math.min(v, 1));
    } else if (draggedThumb == 2) {
        v2 = (event.getX() - getPaddingLeft()) / (getWidth() - getPaddingLeft() - getPaddingRight());
        v2 = Math.max(0, Math.min(v2, 1));
    }
    if (v > v2) {
        draggedThumb = 3 - draggedThumb;
        float t = v;
        v = v2;
        v2 = t;
        t = thumbRadius;
        thumbRadius = thumbRadius2;
        thumbRadius2 = t;
    }
    float newValue = v * (max - min) + min;
    float newValue2 = v2 * (max - min) + min;
    int thumbX = 0;
    if (draggedThumb == 1) {
        thumbX = (int) (v * (getWidth() - getPaddingLeft() - getPaddingRight()) + getPaddingLeft());
    } else if (draggedThumb == 2) {
        thumbX = (int) (v2 * (getWidth() - getPaddingLeft() - getPaddingRight()) + getPaddingLeft());
    }
    int thumbY = getHeight() / 2;
    int radius = rippleDrawable.getRadius();
    if (showLabel && draggedThumb > 0) {
        int[] location = new int[2];
        getLocationInWindow(location);
        popup.setText(String.format(labelFormat, draggedThumb == 1 ? newValue : newValue2));
        popup.update(thumbX + location[0] - popup.getBubbleWidth() / 2, thumbY - radius + location[1] - popup.getHeight());
    }
    if (rippleDrawable != null) {
        rippleDrawable.setHotspot(event.getX(), event.getY());
        rippleDrawable.setBounds(thumbX - radius, thumbY - radius, thumbX + radius, thumbY + radius);
    }
    postInvalidate();
    if ((newValue != value || newValue2 != value2) && onValueChangedListener != null) {
        if (style == Style.Discrete) {
            int sv = stepValue(newValue);
            int sv2 = stepValue(newValue2);
            if (stepValue(value) != sv || stepValue(value2) != sv2)
                onValueChangedListener.onValueChanged(this, sv, sv2);
        } else {
            onValueChangedListener.onValueChanged(this, newValue, newValue2);
        }
    }
    value = newValue;
    value2 = newValue2;
    super.onTouchEvent(event);
    return true;
}
Also used : ValueAnimator(com.nineoldandroids.animation.ValueAnimator) Animator(com.nineoldandroids.animation.Animator) StateAnimator(carbon.animation.StateAnimator) AnimatorListenerAdapter(com.nineoldandroids.animation.AnimatorListenerAdapter) ViewParent(android.view.ViewParent) ValueAnimator(com.nineoldandroids.animation.ValueAnimator) Paint(android.graphics.Paint)

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