Search in sources :

Example 6 with ValueAnimator

use of com.nineoldandroids.animation.ValueAnimator in project ElasticDownload by Tibolte.

the class PathAnimatorInflater method loadAnimator.

/**
     * Creates a new animation whose parameters come from the specified context
     * and attributes set.
     *
     * @param res   The resources
     * @param attrs The set of attributes holding the animation parameters
     * @param anim  Null if this is a ValueAnimator, otherwise this is an
     *              ObjectAnimator
     */
private static ValueAnimator loadAnimator(Context c, Resources res, Resources.Theme theme, AttributeSet attrs, ValueAnimator anim, float pathErrorScale) throws Resources.NotFoundException {
    TypedArray arrayAnimator = null;
    TypedArray arrayObjectAnimator = null;
    if (theme != null) {
        arrayAnimator = theme.obtainStyledAttributes(attrs, R.styleable.Animator, 0, 0);
    } else {
        arrayAnimator = res.obtainAttributes(attrs, R.styleable.Animator);
    }
    // If anim is not null, then it is an object animator.
    if (anim != null) {
        if (theme != null) {
            arrayObjectAnimator = theme.obtainStyledAttributes(attrs, R.styleable.PropertyAnimator, 0, 0);
        } else {
            arrayObjectAnimator = res.obtainAttributes(attrs, R.styleable.PropertyAnimator);
        }
    }
    if (anim == null) {
        anim = new ValueAnimator();
    }
    parseAnimatorFromTypeArray(anim, arrayAnimator, arrayObjectAnimator);
    final int resId = arrayAnimator.getResourceId(R.styleable.Animator_android_interpolator, 0);
    if (resId > 0) {
        anim.setInterpolator(AnimationUtils.loadInterpolator(c, resId));
    }
    arrayAnimator.recycle();
    if (arrayObjectAnimator != null) {
        arrayObjectAnimator.recycle();
    }
    return anim;
}
Also used : TypedArray(android.content.res.TypedArray) ValueAnimator(com.nineoldandroids.animation.ValueAnimator)

Example 7 with ValueAnimator

use of com.nineoldandroids.animation.ValueAnimator in project Signal-Android by WhisperSystems.

the class TransferControlView method getWidthAnimator.

private Animator getWidthAnimator(final int from, final int to) {
    final ValueAnimator anim = ValueAnimator.ofInt(from, to);
    anim.addUpdateListener(new AnimatorUpdateListener() {

        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            final int val = (Integer) animation.getAnimatedValue();
            final ViewGroup.LayoutParams layoutParams = getLayoutParams();
            layoutParams.width = val;
            setLayoutParams(layoutParams);
        }
    });
    anim.setInterpolator(new FastOutSlowInInterpolator());
    anim.setDuration(TRANSITION_MS);
    return anim;
}
Also used : FastOutSlowInInterpolator(android.support.v4.view.animation.FastOutSlowInInterpolator) AnimatorUpdateListener(com.nineoldandroids.animation.ValueAnimator.AnimatorUpdateListener) ValueAnimator(com.nineoldandroids.animation.ValueAnimator)

Example 8 with ValueAnimator

use of com.nineoldandroids.animation.ValueAnimator in project SuperRecyclerView by Malinskiy.

the class SwipeDismissRecyclerViewTouchListener 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(mRecyclerView, dismissPositions);
                // Reset mDownPosition to avoid MotionEvent.ACTION_UP trying to start a dismiss 
                // animation with a stale position
                mDownPosition = INVALID_POSITION;
                ViewGroup.LayoutParams lp;
                for (PendingDismissData pendingDismiss : mPendingDismisses) {
                    // Reset view presentation
                    setAlpha(pendingDismiss.view, 1f);
                    setTranslationX(pendingDismiss.view, 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);
                mRecyclerView.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.nineoldandroids.animation.ValueAnimator) Animator(com.nineoldandroids.animation.Animator) ViewGroup(android.view.ViewGroup) AnimatorListenerAdapter(com.nineoldandroids.animation.AnimatorListenerAdapter) ValueAnimator(com.nineoldandroids.animation.ValueAnimator) SuppressLint(android.annotation.SuppressLint) MotionEvent(android.view.MotionEvent)

Example 9 with ValueAnimator

use of com.nineoldandroids.animation.ValueAnimator in project CoCoin by Nightonke.

the class RiseNumberTextView method runFloat.

private void runFloat() {
    ValueAnimator valueAnimator = ValueAnimator.ofFloat(fromNumber, number);
    valueAnimator.setDuration(duration);
    valueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {

        @Override
        public void onAnimationUpdate(ValueAnimator valueAnimator) {
            setText(fnum.format(Float.parseFloat(valueAnimator.getAnimatedValue().toString())));
            if (valueAnimator.getAnimatedFraction() >= 1) {
                mPlayingState = STOPPED;
                if (mEndListener != null)
                    mEndListener.onEndFinish();
            }
        }
    });
    valueAnimator.start();
}
Also used : ValueAnimator(com.nineoldandroids.animation.ValueAnimator)

Example 10 with ValueAnimator

use of com.nineoldandroids.animation.ValueAnimator in project CoCoin by Nightonke.

the class RiseNumberTextView method runInt.

private void runInt() {
    ValueAnimator valueAnimator = ValueAnimator.ofInt((int) fromNumber, (int) number);
    valueAnimator.setDuration(duration);
    valueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {

        @Override
        public void onAnimationUpdate(ValueAnimator valueAnimator) {
            setText(valueAnimator.getAnimatedValue().toString());
            if (valueAnimator.getAnimatedFraction() >= 1) {
                mPlayingState = STOPPED;
                if (mEndListener != null)
                    mEndListener.onEndFinish();
            }
        }
    });
    valueAnimator.start();
}
Also used : ValueAnimator(com.nineoldandroids.animation.ValueAnimator)

Aggregations

ValueAnimator (com.nineoldandroids.animation.ValueAnimator)105 Animator (com.nineoldandroids.animation.Animator)55 AnimatorListenerAdapter (com.nineoldandroids.animation.AnimatorListenerAdapter)46 StateAnimator (carbon.animation.StateAnimator)30 DecelerateInterpolator (android.view.animation.DecelerateInterpolator)19 View (android.view.View)17 AccelerateDecelerateInterpolator (android.view.animation.AccelerateDecelerateInterpolator)15 Interpolator (android.view.animation.Interpolator)11 Reveal (carbon.internal.Reveal)11 Paint (android.graphics.Paint)7 ObjectAnimator (com.nineoldandroids.animation.ObjectAnimator)6 AccelerateInterpolator (android.view.animation.AccelerateInterpolator)5 RecyclerView (android.support.v7.widget.RecyclerView)4 SimpleItemAnimator (android.support.v7.widget.SimpleItemAnimator)4 FrameLayout (android.widget.FrameLayout)4 ImageView (android.widget.ImageView)4 ArrayList (java.util.ArrayList)4 MotionEvent (android.view.MotionEvent)3 TouchInterceptionFrameLayout (com.github.ksoichiro.android.observablescrollview.TouchInterceptionFrameLayout)3 AnimatorUpdateListener (com.nineoldandroids.animation.ValueAnimator.AnimatorUpdateListener)3