Search in sources :

Example 11 with AnimatorListener

use of android.animation.Animator.AnimatorListener in project RecyclerViewAnimator by dkmeteor.

the class StandUpIn method startAnimation.

@Override
public void startAnimation(final ViewHolder holder, long duration, final BaseItemAnimator animator) {
    System.out.println("startAnimation");
    float x = (holder.itemView.getWidth() - holder.itemView.getPaddingLeft() - holder.itemView.getPaddingRight()) / 2 + holder.itemView.getPaddingLeft();
    float y = holder.itemView.getHeight() - holder.itemView.getPaddingBottom();
    AnimatorSet set = new AnimatorSet();
    set.playTogether(ObjectAnimator.ofFloat(holder.itemView, "pivotX", x, x, x, x, x), ObjectAnimator.ofFloat(holder.itemView, "pivotY", y, y, y, y, y), ObjectAnimator.ofFloat(holder.itemView, "rotationX", 90, 55, -30, 15, -15, 0));
    set.addListener(new AnimatorListener() {

        @Override
        public void onAnimationStart(Animator animation) {
        // TODO Auto-generated method stub
        }

        @Override
        public void onAnimationRepeat(Animator animation) {
        // TODO Auto-generated method stub
        }

        @Override
        public void onAnimationEnd(Animator animation) {
            animator.dispatchAddFinished(holder);
            animator.mAddAnimations.remove(holder);
            animator.dispatchFinishedWhenDone();
        }

        @Override
        public void onAnimationCancel(Animator animation) {
        // TODO Auto-generated method stub
        }
    });
    set.setStartDelay(mDelay * mDelayCount);
    set.setDuration(animator.getAddDuration());
    set.start();
    animator.mAddAnimations.add(holder);
}
Also used : AnimatorListener(android.animation.Animator.AnimatorListener) BaseItemAnimator(com.dk.animation.effect.BaseItemAnimator) ObjectAnimator(android.animation.ObjectAnimator) SegmentAnimator(com.dk.animation.effect.SegmentAnimator) Animator(android.animation.Animator) AnimatorSet(android.animation.AnimatorSet)

Example 12 with AnimatorListener

use of android.animation.Animator.AnimatorListener in project RecyclerViewAnimator by dkmeteor.

the class DropOut method startAnimation.

@Override
public void startAnimation(final ViewHolder holder, long duration, final BaseItemAnimator animator) {
    ViewCompat.animate(holder.itemView).cancel();
    AnimatorSet set = new AnimatorSet();
    int abs = Math.random() > 0.5 ? -1 : 1;
    ObjectAnimator objectAnimatorAnimatorR = ObjectAnimator.ofFloat(holder.itemView, "rotation", abs * 30, abs * 90);
    ObjectAnimator objectAnimatorAnimatorT = ObjectAnimator.ofFloat(holder.itemView, "translationY", 0, ViewUtils.getScreenHeight());
    set.addListener(new AnimatorListener() {

        @Override
        public void onAnimationStart(Animator animation) {
        }

        @Override
        public void onAnimationRepeat(Animator animation) {
        }

        @Override
        public void onAnimationEnd(Animator animation) {
            animator.dispatchAddFinished(holder);
            animator.mAddAnimations.remove(holder);
            animator.dispatchFinishedWhenDone();
        }

        @Override
        public void onAnimationCancel(Animator animation) {
        }
    });
    set.playTogether(objectAnimatorAnimatorR, objectAnimatorAnimatorT);
    set.setStartDelay(mDelay * mDelayCount);
    set.setDuration(animator.getAddDuration());
    set.start();
    animator.mAddAnimations.add(holder);
}
Also used : AnimatorListener(android.animation.Animator.AnimatorListener) BaseItemAnimator(com.dk.animation.effect.BaseItemAnimator) ObjectAnimator(android.animation.ObjectAnimator) SegmentAnimator(com.dk.animation.effect.SegmentAnimator) Animator(android.animation.Animator) ObjectAnimator(android.animation.ObjectAnimator) AnimatorSet(android.animation.AnimatorSet)

Example 13 with AnimatorListener

use of android.animation.Animator.AnimatorListener in project RecyclerViewAnimator by dkmeteor.

the class FlipHorizonIn method startAnimation.

@Override
public void startAnimation(final ViewHolder holder, long duration, final BaseItemAnimator animator) {
    ViewCompat.animate(holder.itemView).cancel();
    AnimatorSet set = new AnimatorSet();
    set.playTogether(ObjectAnimator.ofFloat(holder.itemView, "rotationY", 90, -15, 15, 0), ObjectAnimator.ofFloat(holder.itemView, "alpha", 0.25f, 0.5f, 0.75f, 1));
    set.addListener(new AnimatorListener() {

        @Override
        public void onAnimationStart(Animator animation) {
        // TODO Auto-generated method stub
        }

        @Override
        public void onAnimationRepeat(Animator animation) {
        // TODO Auto-generated method stub
        }

        @Override
        public void onAnimationEnd(Animator animation) {
            animator.dispatchAddFinished(holder);
            animator.mAddAnimations.remove(holder);
            animator.dispatchFinishedWhenDone();
        }

        @Override
        public void onAnimationCancel(Animator animation) {
        // TODO Auto-generated method stub
        }
    });
    set.setStartDelay(mDelay * mDelayCount);
    set.setDuration(animator.getAddDuration());
    set.start();
    animator.mAddAnimations.add(holder);
}
Also used : AnimatorListener(android.animation.Animator.AnimatorListener) BaseItemAnimator(com.dk.animation.effect.BaseItemAnimator) ObjectAnimator(android.animation.ObjectAnimator) SegmentAnimator(com.dk.animation.effect.SegmentAnimator) Animator(android.animation.Animator) AnimatorSet(android.animation.AnimatorSet)

Example 14 with AnimatorListener

use of android.animation.Animator.AnimatorListener in project KJFrameForAndroid by kymjs.

the class AnimationExecutor method animateView.

public void animateView(int duration, int fromY, int toY) {
    if (mCurtainViewController.getSlidingItem().getMaxDuration() > CurtainViewController.DEFAULT_INT) {
        duration = Math.min(duration, mCurtainViewController.getSlidingItem().getMaxDuration());
    }
    // 移动方式
    final MovingType movingType = toY == 0 ? MovingType.BOTTOM_TO_TOP : MovingType.TOP_TO_BOTTOM;
    String propertyName = "";
    if (mCurtainViewController.getSlidingItem().getSlidingType() == SlidingType.SIZE) {
        propertyName = "viewHeight";
    } else if (mCurtainViewController.getSlidingItem().getSlidingType() == SlidingType.MOVE) {
        propertyName = "viewTop";
    }
    ValueAnimator sizeAnim = ObjectAnimator.ofInt(mCurtainViewController, propertyName, fromY, toY);
    sizeAnim.setDuration(duration);
    sizeAnim.addListener(new AnimatorListener() {

        @Override
        public void onAnimationStart(Animator animation) {
        }

        @Override
        public void onAnimationRepeat(Animator animation) {
        }

        @Override
        public void onAnimationEnd(Animator animation) {
            if (movingType == AnimationExecutor.MovingType.BOTTOM_TO_TOP) {
                if (mCurtainViewController.getSlidingItem().getOnSwitchListener() != null) {
                    mCurtainViewController.getSlidingItem().getOnSwitchListener().onCollapsed();
                }
            } else if (movingType == AnimationExecutor.MovingType.TOP_TO_BOTTOM) {
                if (mCurtainViewController.getSlidingItem().getOnSwitchListener() != null) {
                    mCurtainViewController.getSlidingItem().getOnSwitchListener().onExpanded();
                }
            }
        }

        @Override
        public void onAnimationCancel(Animator animation) {
        }
    });
    sizeAnim.start();
}
Also used : AnimatorListener(android.animation.Animator.AnimatorListener) ObjectAnimator(android.animation.ObjectAnimator) Animator(android.animation.Animator) ValueAnimator(android.animation.ValueAnimator) ValueAnimator(android.animation.ValueAnimator)

Example 15 with AnimatorListener

use of android.animation.Animator.AnimatorListener in project android_frameworks_base by ParanoidAndroid.

the class Tweener method to.

public static Tweener to(Object object, long duration, Object... vars) {
    long delay = 0;
    AnimatorUpdateListener updateListener = null;
    AnimatorListener listener = null;
    TimeInterpolator interpolator = null;
    // Iterate through arguments and discover properties to animate
    ArrayList<PropertyValuesHolder> props = new ArrayList<PropertyValuesHolder>(vars.length / 2);
    for (int i = 0; i < vars.length; i += 2) {
        if (!(vars[i] instanceof String)) {
            throw new IllegalArgumentException("Key must be a string: " + vars[i]);
        }
        String key = (String) vars[i];
        Object value = vars[i + 1];
        if ("simultaneousTween".equals(key)) {
        // TODO
        } else if ("ease".equals(key)) {
            // TODO: multiple interpolators?
            interpolator = (TimeInterpolator) value;
        } else if ("onUpdate".equals(key) || "onUpdateListener".equals(key)) {
            updateListener = (AnimatorUpdateListener) value;
        } else if ("onComplete".equals(key) || "onCompleteListener".equals(key)) {
            listener = (AnimatorListener) value;
        } else if ("delay".equals(key)) {
            delay = ((Number) value).longValue();
        } else if ("syncWith".equals(key)) {
        // TODO
        } else if (value instanceof float[]) {
            props.add(PropertyValuesHolder.ofFloat(key, ((float[]) value)[0], ((float[]) value)[1]));
        } else if (value instanceof int[]) {
            props.add(PropertyValuesHolder.ofInt(key, ((int[]) value)[0], ((int[]) value)[1]));
        } else if (value instanceof Number) {
            float floatValue = ((Number) value).floatValue();
            props.add(PropertyValuesHolder.ofFloat(key, floatValue));
        } else {
            throw new IllegalArgumentException("Bad argument for key \"" + key + "\" with value " + value.getClass());
        }
    }
    // Re-use existing tween, if present
    Tweener tween = sTweens.get(object);
    ObjectAnimator anim = null;
    if (tween == null) {
        anim = ObjectAnimator.ofPropertyValuesHolder(object, props.toArray(new PropertyValuesHolder[props.size()]));
        tween = new Tweener(anim);
        sTweens.put(object, tween);
        if (DEBUG)
            Log.v(TAG, "Added new Tweener " + tween);
    } else {
        anim = sTweens.get(object).animator;
        // Cancel all animators for given object
        replace(props, object);
    }
    if (interpolator != null) {
        anim.setInterpolator(interpolator);
    }
    // Update animation with properties discovered in loop above
    anim.setStartDelay(delay);
    anim.setDuration(duration);
    if (updateListener != null) {
        // There should be only one
        anim.removeAllUpdateListeners();
        anim.addUpdateListener(updateListener);
    }
    if (listener != null) {
        // There should be only one.
        anim.removeAllListeners();
        anim.addListener(listener);
    }
    anim.addListener(mCleanupListener);
    return tween;
}
Also used : ObjectAnimator(android.animation.ObjectAnimator) ArrayList(java.util.ArrayList) AnimatorUpdateListener(android.animation.ValueAnimator.AnimatorUpdateListener) TimeInterpolator(android.animation.TimeInterpolator) AnimatorListener(android.animation.Animator.AnimatorListener) PropertyValuesHolder(android.animation.PropertyValuesHolder)

Aggregations

AnimatorListener (android.animation.Animator.AnimatorListener)32 ObjectAnimator (android.animation.ObjectAnimator)25 Animator (android.animation.Animator)24 AnimatorSet (android.animation.AnimatorSet)10 ValueAnimator (android.animation.ValueAnimator)8 View (android.view.View)8 ImageView (android.widget.ImageView)6 TextView (android.widget.TextView)6 BaseItemAnimator (com.dk.animation.effect.BaseItemAnimator)6 SegmentAnimator (com.dk.animation.effect.SegmentAnimator)6 AnimatorUpdateListener (android.animation.ValueAnimator.AnimatorUpdateListener)5 Intent (android.content.Intent)5 ArrayList (java.util.ArrayList)4 PropertyValuesHolder (android.animation.PropertyValuesHolder)3 TimeInterpolator (android.animation.TimeInterpolator)3 ArgbEvaluator (android.animation.ArgbEvaluator)2 DecelerateInterpolator (android.view.animation.DecelerateInterpolator)2 Comparator (java.util.Comparator)2 SuppressLint (android.annotation.SuppressLint)1 Paint (android.graphics.Paint)1