Search in sources :

Example 1 with AnimatorProxy

use of com.marshalchen.common.uimodule.nineoldandroids.view.animation.AnimatorProxy in project UltimateAndroid by cymcsg.

the class FilckerAnimationListView method animatePreLayout.

/**
	 * Animate items that are deleted entirely and items that move out of
	 * bounds.
	 */
private void animatePreLayout(final float durationUnit, final Animator.AnimatorListener listener) {
    final AnimatorSet animatorSet = new AnimatorSet();
    final int firstVisiblePosition = getFirstVisiblePosition();
    final int childCount = getChildCount();
    for (final Iterator<Entry<Long, Float>> iter = yMap.entrySet().iterator(); iter.hasNext(); ) {
        final Entry<Long, Float> entry = iter.next();
        final long id = entry.getKey();
        final int oldPos = positionMap.get(id);
        final View child = getChildAt(oldPos - firstVisiblePosition);
        final int newPos = getPositionForId(id);
        // fade out items that disappear
        if (newPos == -1) {
            final ObjectAnimator anim = animateAlpha(child, false);
            animatorSet.play(anim);
            iter.remove();
            positionMap.remove(id);
            continue;
        }
        // translate items that move out of bounds
        if (newPos < firstVisiblePosition || newPos > firstVisiblePosition + childCount) {
            final float offset;
            if (newPos < firstVisiblePosition) {
                offset = -getHeight();
            } else {
                offset = getHeight();
            }
            final AnimatorProxy proxy = AnimatorProxy.wrap(child);
            final ObjectAnimator anim = ObjectAnimator.ofFloat(proxy, "translationY", 0f, offset);
            final int finalDuration = getDuration(0, getHeight() / 2, durationUnit);
            anim.setInterpolator(new AccelerateInterpolator());
            anim.setDuration((long) (finalDuration * animationDurationFactor));
            animatorSet.addListener(new AnimatorListenerAdapter() {

                @Override
                public void onAnimationEnd(final Animator animation) {
                    child.post(new Runnable() {

                        @Override
                        public void run() {
                            proxy.setTranslationY(0f);
                        }
                    });
                }
            });
            animatorSet.play(anim);
            iter.remove();
            positionMap.remove(id);
            continue;
        }
    }
    if (!animatorSet.getChildAnimations().isEmpty()) {
        animatorSet.addListener(listener);
        animatorSet.start();
    } else {
        listener.onAnimationEnd(animatorSet);
    }
}
Also used : AccelerateInterpolator(android.view.animation.AccelerateInterpolator) ObjectAnimator(com.marshalchen.common.uimodule.nineoldandroids.animation.ObjectAnimator) AnimatorSet(com.marshalchen.common.uimodule.nineoldandroids.animation.AnimatorSet) View(android.view.View) ListView(android.widget.ListView) Entry(java.util.Map.Entry) Animator(com.marshalchen.common.uimodule.nineoldandroids.animation.Animator) ObjectAnimator(com.marshalchen.common.uimodule.nineoldandroids.animation.ObjectAnimator) AnimatorListenerAdapter(com.marshalchen.common.uimodule.nineoldandroids.animation.AnimatorListenerAdapter) AnimatorProxy(com.marshalchen.common.uimodule.nineoldandroids.view.animation.AnimatorProxy)

Aggregations

View (android.view.View)1 AccelerateInterpolator (android.view.animation.AccelerateInterpolator)1 ListView (android.widget.ListView)1 Animator (com.marshalchen.common.uimodule.nineoldandroids.animation.Animator)1 AnimatorListenerAdapter (com.marshalchen.common.uimodule.nineoldandroids.animation.AnimatorListenerAdapter)1 AnimatorSet (com.marshalchen.common.uimodule.nineoldandroids.animation.AnimatorSet)1 ObjectAnimator (com.marshalchen.common.uimodule.nineoldandroids.animation.ObjectAnimator)1 AnimatorProxy (com.marshalchen.common.uimodule.nineoldandroids.view.animation.AnimatorProxy)1 Entry (java.util.Map.Entry)1