Search in sources :

Example 6 with AnimatorListenerAdapter

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

the class SwipeDismissListViewTouchListener method performDismiss.

protected void performDismiss(final PendingDismissData data) {
    // Animate the dismissed list item to zero-height and fire the
    // dismiss callback when all dismissed list item animations have
    // completed.
    final ViewGroup.LayoutParams lp = data.view.getLayoutParams();
    final int originalHeight = data.view.getHeight();
    ValueAnimator animator = ValueAnimator.ofInt(originalHeight, 1).setDuration(mAnimationTime);
    animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {

        @Override
        public void onAnimationUpdate(final ValueAnimator valueAnimator) {
            lp.height = (Integer) valueAnimator.getAnimatedValue();
            data.view.setLayoutParams(lp);
        }
    });
    animator.addListener(new AnimatorListenerAdapter() {

        @Override
        public void onAnimationEnd(final Animator animation) {
            finalizeDismiss();
        }
    });
    animator.start();
}
Also used : ValueAnimator(com.marshalchen.common.uimodule.nineoldandroids.animation.ValueAnimator) Animator(com.marshalchen.common.uimodule.nineoldandroids.animation.Animator) ViewPropertyAnimator(com.marshalchen.common.uimodule.nineoldandroids.view.ViewPropertyAnimator) AnimatorListenerAdapter(com.marshalchen.common.uimodule.nineoldandroids.animation.AnimatorListenerAdapter) ValueAnimator(com.marshalchen.common.uimodule.nineoldandroids.animation.ValueAnimator) SuppressLint(android.annotation.SuppressLint)

Example 7 with AnimatorListenerAdapter

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

Example 8 with AnimatorListenerAdapter

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

the class FilckerAnimationListView method animatePostLayout.

/**
	 * Animate items that just appeared and items that move within the screen.
	 */
private void animatePostLayout(final float durationUnit) {
    final AnimatorSet animatorSet = new AnimatorSet();
    for (int i = 0; i < getChildCount(); i++) {
        final View child = getChildAt(i);
        final long id = getItemIdAtPosition(getFirstVisiblePosition() + i);
        ObjectAnimator anim = null;
        ViewHelper.setAlpha(child, 1f);
        if (yMap.containsKey(id)) {
            // moved within visible area
            // log("Moved within visible area id: " + id);
            final float oldY = yMap.remove(id);
            final float newY = ViewHelper.getY(child);
            if (oldY != newY) {
                anim = animateY(child, oldY, newY, durationUnit);
            }
        } else {
            if (beforeVisible.contains(id)) {
                // moved from top
                final float newY = ViewHelper.getY(child);
                final float oldY = -child.getHeight();
                anim = animateY(child, oldY, newY, durationUnit);
            } else if (afterVisible.contains(id)) {
                // moved from bottom
                final float newY = ViewHelper.getY(child);
                final float oldY = getHeight();
                anim = animateY(child, oldY, newY, durationUnit);
            } else {
                // entirely new
                ViewHelper.setAlpha(child, 0f);
                anim = animateAlpha(child, true);
                anim.setStartDelay(MIN_ANIM_DURATION);
            }
        }
        if (anim != null) {
            animatorSet.play(anim);
        }
    }
    animatorSet.addListener(new AnimatorListenerAdapter() {

        @Override
        public void onAnimationEnd(final Animator animation) {
            finishAnimation();
        }

        ;
    });
    animatorSet.start();
}
Also used : Animator(com.marshalchen.common.uimodule.nineoldandroids.animation.Animator) ObjectAnimator(com.marshalchen.common.uimodule.nineoldandroids.animation.ObjectAnimator) ObjectAnimator(com.marshalchen.common.uimodule.nineoldandroids.animation.ObjectAnimator) AnimatorListenerAdapter(com.marshalchen.common.uimodule.nineoldandroids.animation.AnimatorListenerAdapter) AnimatorSet(com.marshalchen.common.uimodule.nineoldandroids.animation.AnimatorSet) View(android.view.View) ListView(android.widget.ListView)

Example 9 with AnimatorListenerAdapter

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

the class SwipeDismissListViewTouchListener method performDismiss.

private void performDismiss(final View dismissView, final int dismissPosition) {
    // Animate the dismissed list item to zero-height and fire the dismiss callback when
    // all dismissed list item animations have completed. This triggers layout on each animation
    // frame; in the future we may want to do something smarter and more performant.
    final ViewGroup.LayoutParams lp = dismissView.getLayoutParams();
    final int originalHeight = dismissView.getHeight();
    ValueAnimator animator = ValueAnimator.ofInt(originalHeight, 1).setDuration(mAnimationTime);
    animator.addListener(new AnimatorListenerAdapter() {

        @Override
        public void onAnimationEnd(Animator animation) {
            --mDismissAnimationRefCount;
            if (mDismissAnimationRefCount == 0) {
                // No active animations, process all pending dismisses.
                // Sort by descending position
                Collections.sort(mPendingDismisses);
                int[] dismissPositions = new int[mPendingDismisses.size()];
                for (int i = mPendingDismisses.size() - 1; i >= 0; i--) {
                    dismissPositions[i] = mPendingDismisses.get(i).position;
                }
                mCallbacks.onDismiss(mListView, dismissPositions);
                // Reset mDownPosition to avoid MotionEvent.ACTION_UP trying to start a dismiss
                // animation with a stale position
                mDownPosition = ListView.INVALID_POSITION;
                ViewGroup.LayoutParams lp;
                for (PendingDismissData pendingDismiss : mPendingDismisses) {
                    // Reset view presentation
                    AnimatorProxy.wrap(pendingDismiss.view).setAlpha(1f);
                    AnimatorProxy.wrap(pendingDismiss.view).setTranslationX(0);
                    lp = pendingDismiss.view.getLayoutParams();
                    lp.height = originalHeight;
                    pendingDismiss.view.setLayoutParams(lp);
                }
                // Send a cancel event
                long time = SystemClock.uptimeMillis();
                MotionEvent cancelEvent = MotionEvent.obtain(time, time, MotionEvent.ACTION_CANCEL, 0, 0, 0);
                mListView.dispatchTouchEvent(cancelEvent);
                mPendingDismisses.clear();
            }
        }
    });
    animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {

        @Override
        public void onAnimationUpdate(ValueAnimator valueAnimator) {
            lp.height = (Integer) valueAnimator.getAnimatedValue();
            dismissView.setLayoutParams(lp);
        }
    });
    mPendingDismisses.add(new PendingDismissData(dismissPosition, dismissView));
    animator.start();
}
Also used : ValueAnimator(com.marshalchen.common.uimodule.nineoldandroids.animation.ValueAnimator) Animator(com.marshalchen.common.uimodule.nineoldandroids.animation.Animator) AnimatorListenerAdapter(com.marshalchen.common.uimodule.nineoldandroids.animation.AnimatorListenerAdapter) ValueAnimator(com.marshalchen.common.uimodule.nineoldandroids.animation.ValueAnimator)

Example 10 with AnimatorListenerAdapter

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

the class ContextualUndoAdapter method swipeView.

private void swipeView(final View view, final int dismissPosition) {
    ObjectAnimator animator = ObjectAnimator.ofFloat(view, X, view.getMeasuredWidth());
    animator.addListener(new AnimatorListenerAdapter() {

        @Override
        public void onAnimationEnd(final Animator animator) {
            onViewSwiped(((ContextualUndoView) view).getItemId(), dismissPosition);
        }
    });
    animator.start();
}
Also used : ValueAnimator(com.marshalchen.common.uimodule.nineoldandroids.animation.ValueAnimator) ObjectAnimator(com.marshalchen.common.uimodule.nineoldandroids.animation.ObjectAnimator) Animator(com.marshalchen.common.uimodule.nineoldandroids.animation.Animator) ObjectAnimator(com.marshalchen.common.uimodule.nineoldandroids.animation.ObjectAnimator) AnimatorListenerAdapter(com.marshalchen.common.uimodule.nineoldandroids.animation.AnimatorListenerAdapter)

Aggregations

Animator (com.marshalchen.common.uimodule.nineoldandroids.animation.Animator)14 AnimatorListenerAdapter (com.marshalchen.common.uimodule.nineoldandroids.animation.AnimatorListenerAdapter)14 ValueAnimator (com.marshalchen.common.uimodule.nineoldandroids.animation.ValueAnimator)10 ObjectAnimator (com.marshalchen.common.uimodule.nineoldandroids.animation.ObjectAnimator)4 ViewPropertyAnimator (com.marshalchen.common.uimodule.nineoldandroids.view.ViewPropertyAnimator)4 View (android.view.View)3 ListView (android.widget.ListView)3 AnimatorSet (com.marshalchen.common.uimodule.nineoldandroids.animation.AnimatorSet)3 SuppressLint (android.annotation.SuppressLint)1 Rect (android.graphics.Rect)1 ViewGroup (android.view.ViewGroup)1 OnPreDrawListener (android.view.ViewTreeObserver.OnPreDrawListener)1 AccelerateInterpolator (android.view.animation.AccelerateInterpolator)1 AbsListView (android.widget.AbsListView)1 AnimatorUpdateListener (com.marshalchen.common.uimodule.nineoldandroids.animation.ValueAnimator.AnimatorUpdateListener)1 AnimatorProxy (com.marshalchen.common.uimodule.nineoldandroids.view.animation.AnimatorProxy)1 Entry (java.util.Map.Entry)1