Search in sources :

Example 11 with AnimatorListenerAdapter

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

the class ContextualUndoListViewTouchListener method handleUpCancelEvent.

@SuppressWarnings("UnusedParameters")
private boolean handleUpCancelEvent(final View view, final MotionEvent motionEvent) {
    mDisallowSwipe = false;
    if (mVelocityTracker == null) {
        return false;
    }
    float deltaX = motionEvent.getRawX() - mDownX;
    mVelocityTracker.addMovement(motionEvent);
    mVelocityTracker.computeCurrentVelocity(1000);
    float velocityX = Math.abs(mVelocityTracker.getXVelocity());
    float velocityY = Math.abs(mVelocityTracker.getYVelocity());
    boolean dismiss = false;
    boolean dismissRight = false;
    final float absDeltaX = Math.abs(deltaX);
    if (absDeltaX > mViewWidth / 2) {
        dismiss = true;
        dismissRight = deltaX > 0;
    } else if (mMinFlingVelocity <= velocityX && velocityX <= mMaxFlingVelocity && velocityY < velocityX && absDeltaX > mSlop) {
        dismiss = true;
        dismissRight = mVelocityTracker.getXVelocity() > 0;
    }
    if (dismiss) {
        // dismiss
        final long itemId = ((ContextualUndoView) mDownView).getItemId();
        // before animation ends
        final int downPosition = mDownPosition;
        animate(mDownView).translationX(dismissRight ? mViewWidth : -mViewWidth).alpha(0).setDuration(mAnimationTime).setListener(new AnimatorListenerAdapter() {

            @Override
            public void onAnimationEnd(final Animator animation) {
                mCallback.onViewSwiped(itemId, downPosition);
            }
        });
    } else {
        // cancel
        animate(mDownView).translationX(0).alpha(1).setDuration(mAnimationTime).setListener(null);
    }
    mVelocityTracker.recycle();
    mVelocityTracker = null;
    mDownX = 0;
    mDownView = null;
    mDownPosition = AdapterView.INVALID_POSITION;
    mSwiping = false;
    return false;
}
Also used : Animator(com.marshalchen.common.uimodule.nineoldandroids.animation.Animator) AnimatorListenerAdapter(com.marshalchen.common.uimodule.nineoldandroids.animation.AnimatorListenerAdapter)

Example 12 with AnimatorListenerAdapter

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

the class PanningViewAttacher method animate.

private void animate(float start, float end, long duration) {
    Log.d(TAG, "startPanning : " + start + " to " + end + ", in " + duration + "ms");
    mCurrentAnimator = ValueAnimator.ofFloat(start, end);
    mCurrentAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {

        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            float value = (Float) animation.getAnimatedValue();
            mMatrix.reset();
            applyScaleOnMatrix();
            if (mIsPortrait) {
                mMatrix.postTranslate(value, 0);
            } else {
                mMatrix.postTranslate(0, value);
            }
            refreshDisplayRect();
            mCurrentPlayTime = animation.getCurrentPlayTime();
            setCurrentImageMatrix();
        }
    });
    mCurrentAnimator.addListener(new AnimatorListenerAdapter() {

        @Override
        public void onAnimationEnd(Animator animation) {
            Log.d(TAG, "animation has finished, startPanning in the other way");
            changeWay();
            animate_();
        }

        @Override
        public void onAnimationCancel(Animator animation) {
            Log.d(TAG, "panning animation canceled");
        }
    });
    mCurrentAnimator.setDuration(duration);
    mCurrentAnimator.setInterpolator(mLinearInterpolator);
    mCurrentAnimator.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 13 with AnimatorListenerAdapter

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

the class AnimateDismissAdapter method animateDismiss.

/**
     * Animate dismissal of the items at given positions.
     */
public void animateDismiss(final Collection<Integer> positions) {
    final List<Integer> positionsCopy = new ArrayList<Integer>(positions);
    if (getAbsListView() == null) {
        throw new IllegalStateException("Call setAbsListView() on this AnimateDismissAdapter before calling setAdapter()!");
    }
    List<View> views = getVisibleViewsForPositions(positionsCopy);
    if (!views.isEmpty()) {
        List<Animator> animators = new ArrayList<Animator>();
        for (final View view : views) {
            animators.add(createAnimatorForView(view));
        }
        AnimatorSet animatorSet = new AnimatorSet();
        Animator[] animatorsArray = new Animator[animators.size()];
        for (int i = 0; i < animatorsArray.length; i++) {
            animatorsArray[i] = animators.get(i);
        }
        animatorSet.playTogether(animatorsArray);
        animatorSet.addListener(new AnimatorListenerAdapter() {

            @Override
            public void onAnimationEnd(final Animator animator) {
                invokeCallback(positionsCopy);
            }
        });
        animatorSet.start();
    } else {
        invokeCallback(positionsCopy);
    }
}
Also used : AnimatorSet(com.marshalchen.common.uimodule.nineoldandroids.animation.AnimatorSet) View(android.view.View) ValueAnimator(com.marshalchen.common.uimodule.nineoldandroids.animation.ValueAnimator) Animator(com.marshalchen.common.uimodule.nineoldandroids.animation.Animator) AnimatorListenerAdapter(com.marshalchen.common.uimodule.nineoldandroids.animation.AnimatorListenerAdapter)

Example 14 with AnimatorListenerAdapter

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

the class FilckerAnimationListView method doAnimation.

private void doAnimation() {
    setEnabled(false);
    animating = true;
    final float durationUnit = (float) MAX_ANIM_DURATION / getHeight();
    animatePreLayout(durationUnit, new AnimatorListenerAdapter() {

        @Override
        public void onAnimationEnd(final Animator animation) {
            adapter.notifyDataSetChanged();
            getViewTreeObserver().addOnPreDrawListener(new OnPreDrawListener() {

                @Override
                public boolean onPreDraw() {
                    getViewTreeObserver().removeOnPreDrawListener(this);
                    animatePostLayout(durationUnit);
                    return true;
                }
            });
        }
    });
}
Also used : Animator(com.marshalchen.common.uimodule.nineoldandroids.animation.Animator) ObjectAnimator(com.marshalchen.common.uimodule.nineoldandroids.animation.ObjectAnimator) AnimatorListenerAdapter(com.marshalchen.common.uimodule.nineoldandroids.animation.AnimatorListenerAdapter) OnPreDrawListener(android.view.ViewTreeObserver.OnPreDrawListener)

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