Search in sources :

Example 86 with Animator

use of com.nineoldandroids.animation.Animator in project PhotoPicker by donglua.

the class ImagePagerFragment method runExitAnimation.

/**
   * The exit animation is basically a reverse of the enter animation, except that if
   * the orientation has changed we simply scale the picture back into the center of
   * the screen.
   *
   * @param endAction This action gets run after the animation completes (this is
   * when we actually switch activities)
   */
public void runExitAnimation(final Runnable endAction) {
    if (!getArguments().getBoolean(ARG_HAS_ANIM, false) || !hasAnim) {
        endAction.run();
        return;
    }
    final long duration = ANIM_DURATION;
    // Animate image back to thumbnail size/location
    ViewPropertyAnimator.animate(mViewPager).setDuration(duration).setInterpolator(new AccelerateInterpolator()).scaleX((float) thumbnailWidth / mViewPager.getWidth()).scaleY((float) thumbnailHeight / mViewPager.getHeight()).translationX(thumbnailLeft).translationY(thumbnailTop).setListener(new Animator.AnimatorListener() {

        @Override
        public void onAnimationStart(Animator animation) {
        }

        @Override
        public void onAnimationEnd(Animator animation) {
            endAction.run();
        }

        @Override
        public void onAnimationCancel(Animator animation) {
        }

        @Override
        public void onAnimationRepeat(Animator animation) {
        }
    });
    // Fade out background
    ObjectAnimator bgAnim = ObjectAnimator.ofInt(mViewPager.getBackground(), "alpha", 0);
    bgAnim.setDuration(duration);
    bgAnim.start();
    // Animate a color filter to take the image back to grayscale,
    // in parallel with the image scaling and moving into place.
    ObjectAnimator colorizer = ObjectAnimator.ofFloat(ImagePagerFragment.this, "saturation", 1, 0);
    colorizer.setDuration(duration);
    colorizer.start();
}
Also used : Animator(com.nineoldandroids.animation.Animator) ViewPropertyAnimator(com.nineoldandroids.view.ViewPropertyAnimator) ObjectAnimator(com.nineoldandroids.animation.ObjectAnimator) AccelerateInterpolator(android.view.animation.AccelerateInterpolator) ObjectAnimator(com.nineoldandroids.animation.ObjectAnimator)

Example 87 with Animator

use of com.nineoldandroids.animation.Animator in project Meizhi by drakeet.

the class FloatView method translationX.

public void translationX(float fromX, float toX, float formAlpha, final float toAlpha) {
    ObjectAnimator a1 = ObjectAnimator.ofFloat(rootView, "alpha", formAlpha, toAlpha);
    ObjectAnimator a2 = ObjectAnimator.ofFloat(rootView, "translationX", fromX, toX);
    AnimatorSet animatorSet = new AnimatorSet();
    animatorSet.playTogether(a1, a2);
    animatorSet.addListener(new Animator.AnimatorListener() {

        @Override
        public void onAnimationStart(Animator animation) {
        }

        @Override
        public void onAnimationEnd(Animator animation) {
            if (toAlpha == 0) {
                HeadsUpManager.getInstant(getContext()).dismiss();
                cutDown = -1;
                if (velocityTracker != null) {
                    velocityTracker.clear();
                    try {
                        velocityTracker.recycle();
                    } catch (IllegalStateException e) {
                    }
                }
            }
        }

        @Override
        public void onAnimationCancel(Animator animation) {
        }

        @Override
        public void onAnimationRepeat(Animator animation) {
        }
    });
    animatorSet.start();
}
Also used : Animator(com.nineoldandroids.animation.Animator) ObjectAnimator(com.nineoldandroids.animation.ObjectAnimator) ObjectAnimator(com.nineoldandroids.animation.ObjectAnimator) AnimatorSet(com.nineoldandroids.animation.AnimatorSet)

Example 88 with Animator

use of com.nineoldandroids.animation.Animator in project ListViewAnimations by nhaarman.

the class AnimationAdapter method animateViewIfNecessary.

/**
     * Animates given View if necessary.
     *
     * @param position the position of the item the View represents.
     * @param view     the View that should be animated.
     * @param parent   the parent the View is hosted in.
     */
private void animateViewIfNecessary(final int position, @NonNull final View view, @NonNull final ViewGroup parent) {
    assert mViewAnimator != null;
    /* GridView measures the first View which is returned by getView(int, View, ViewGroup), but does not use that View.
           On KitKat, it does this actually multiple times.
           Therefore, we animate all these first Views, and reset the last animated position when we suspect GridView is measuring. */
    mGridViewPossiblyMeasuring = mGridViewPossiblyMeasuring && (mGridViewMeasuringPosition == -1 || mGridViewMeasuringPosition == position);
    if (mGridViewPossiblyMeasuring) {
        mGridViewMeasuringPosition = position;
        mViewAnimator.setLastAnimatedPosition(-1);
    }
    Animator[] childAnimators;
    if (getDecoratedBaseAdapter() instanceof AnimationAdapter) {
        childAnimators = ((AnimationAdapter) getDecoratedBaseAdapter()).getAnimators(parent, view);
    } else {
        childAnimators = new Animator[0];
    }
    Animator[] animators = getAnimators(parent, view);
    Animator alphaAnimator = ObjectAnimator.ofFloat(view, ALPHA, 0, 1);
    Animator[] concatAnimators = AnimatorUtil.concatAnimators(childAnimators, animators, alphaAnimator);
    mViewAnimator.animateViewIfNecessary(position, view, concatAnimators);
}
Also used : ObjectAnimator(com.nineoldandroids.animation.ObjectAnimator) Animator(com.nineoldandroids.animation.Animator)

Example 89 with Animator

use of com.nineoldandroids.animation.Animator in project ListViewAnimations by nhaarman.

the class AnimateAdditionAdapter method getView.

@Override
@NonNull
public View getView(final int position, @Nullable final View convertView, @NonNull final ViewGroup parent) {
    final View view = super.getView(position, convertView, parent);
    if (mInsertQueue.getActiveIndexes().contains(position)) {
        int widthMeasureSpec = View.MeasureSpec.makeMeasureSpec(ViewGroup.LayoutParams.MATCH_PARENT, View.MeasureSpec.AT_MOST);
        int heightMeasureSpec = View.MeasureSpec.makeMeasureSpec(ViewGroup.LayoutParams.WRAP_CONTENT, View.MeasureSpec.UNSPECIFIED);
        view.measure(widthMeasureSpec, heightMeasureSpec);
        int originalHeight = view.getMeasuredHeight();
        ValueAnimator heightAnimator = ValueAnimator.ofInt(1, originalHeight);
        heightAnimator.addUpdateListener(new HeightUpdater(view));
        Animator[] customAnimators = getAdditionalAnimators(view, parent);
        Animator[] animators = new Animator[customAnimators.length + 1];
        animators[0] = heightAnimator;
        System.arraycopy(customAnimators, 0, animators, 1, customAnimators.length);
        AnimatorSet animatorSet = new AnimatorSet();
        animatorSet.playTogether(animators);
        ViewHelper.setAlpha(view, 0);
        ObjectAnimator alphaAnimator = ObjectAnimator.ofFloat(view, ALPHA, 0, 1);
        AnimatorSet allAnimatorsSet = new AnimatorSet();
        allAnimatorsSet.playSequentially(animatorSet, alphaAnimator);
        allAnimatorsSet.setDuration(mInsertionAnimationDurationMs);
        allAnimatorsSet.addListener(new ExpandAnimationListener(position));
        allAnimatorsSet.start();
    }
    return view;
}
Also used : ValueAnimator(com.nineoldandroids.animation.ValueAnimator) Animator(com.nineoldandroids.animation.Animator) ObjectAnimator(com.nineoldandroids.animation.ObjectAnimator) ObjectAnimator(com.nineoldandroids.animation.ObjectAnimator) AnimatorSet(com.nineoldandroids.animation.AnimatorSet) ValueAnimator(com.nineoldandroids.animation.ValueAnimator) AbsListView(android.widget.AbsListView) View(android.view.View) AdapterView(android.widget.AdapterView) ListView(android.widget.ListView) NonNull(android.support.annotation.NonNull)

Example 90 with Animator

use of com.nineoldandroids.animation.Animator in project ListViewAnimations by nhaarman.

the class StickyListHeadersAdapterDecorator method animateViewIfNecessary.

/**
     * Animates given View if necessary.
     *
     * @param position the position of the item the View represents.
     * @param view     the View that should be animated.
     * @param parent   the parent the View is hosted in.
     */
private void animateViewIfNecessary(final int position, @NonNull final View view, @NonNull final ViewGroup parent) {
    Animator[] childAnimators;
    if (getDecoratedBaseAdapter() instanceof AnimationAdapter) {
        childAnimators = ((AnimationAdapter) getDecoratedBaseAdapter()).getAnimators(parent, view);
    } else {
        childAnimators = new Animator[0];
    }
    Animator alphaAnimator = ObjectAnimator.ofFloat(view, ALPHA, 0, 1);
    assert mViewAnimator != null;
    mViewAnimator.animateViewIfNecessary(position, view, AnimatorUtil.concatAnimators(childAnimators, new Animator[0], alphaAnimator));
}
Also used : Animator(com.nineoldandroids.animation.Animator) ObjectAnimator(com.nineoldandroids.animation.ObjectAnimator)

Aggregations

Animator (com.nineoldandroids.animation.Animator)135 ValueAnimator (com.nineoldandroids.animation.ValueAnimator)81 AnimatorListenerAdapter (com.nineoldandroids.animation.AnimatorListenerAdapter)68 ObjectAnimator (com.nineoldandroids.animation.ObjectAnimator)48 StateAnimator (carbon.animation.StateAnimator)29 View (android.view.View)24 AnimatorSet (com.nineoldandroids.animation.AnimatorSet)24 DecelerateInterpolator (android.view.animation.DecelerateInterpolator)11 Interpolator (android.view.animation.Interpolator)11 Reveal (carbon.internal.Reveal)11 RecyclerView (android.support.v7.widget.RecyclerView)5 AccelerateDecelerateInterpolator (android.view.animation.AccelerateDecelerateInterpolator)5 AccelerateInterpolator (android.view.animation.AccelerateInterpolator)5 Paint (android.graphics.Paint)4 SimpleItemAnimator (android.support.v7.widget.SimpleItemAnimator)4 ViewGroup (android.view.ViewGroup)4 OvershootInterpolator (android.view.animation.OvershootInterpolator)4 ArcAnimator (io.codetail.animation.arcanimator.ArcAnimator)4 GestureDetector (android.view.GestureDetector)3 MotionEvent (android.view.MotionEvent)3