Android Open Source - AndroidViewAnimations Yo Yo






From Project

Back to project page AndroidViewAnimations.

License

The source code is released under:

MIT License

If you think the Android project AndroidViewAnimations listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

/*
 * The MIT License (MIT)//  w ww .java2 s  .c  o  m
 *
 * Copyright (c) 2014 daimajia
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all
 * copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */

package com.daimajia.androidanimations.library;

import android.view.View;
import android.view.animation.Interpolator;

import com.nineoldandroids.animation.Animator;

import java.util.ArrayList;
import java.util.List;

public class YoYo {

    private static final long DURATION = BaseViewAnimator.DURATION;
    private static final long NO_DELAY = 0;

    private BaseViewAnimator animator;
    private long duration;
    private long delay;
    private Interpolator interpolator;
    private List<Animator.AnimatorListener> callbacks;
    private View target;

    private YoYo(AnimationComposer animationComposer) {
        animator = animationComposer.animator;
        duration = animationComposer.duration;
        delay = animationComposer.delay;
        interpolator = animationComposer.interpolator;
        callbacks = animationComposer.callbacks;
        target = animationComposer.target;
    }

    public static AnimationComposer with(Techniques techniques) {
        return new AnimationComposer(techniques);
    }

    public static AnimationComposer with(BaseViewAnimator animator) {
        return new AnimationComposer(animator);
    }

    public static final class AnimationComposer {

        private List<Animator.AnimatorListener> callbacks = new ArrayList<Animator.AnimatorListener>();

        private BaseViewAnimator animator;
        private long duration = DURATION;
        private long delay = NO_DELAY;
        private Interpolator interpolator;
        private View target;

        private AnimationComposer(Techniques techniques) {
            this.animator = techniques.getAnimator();
        }

        private AnimationComposer(BaseViewAnimator animator) {
            this.animator = animator;
        }

        public AnimationComposer duration(long duration) {
            this.duration = duration;
            return this;
        }

        public AnimationComposer delay(long delay) {
            this.delay = delay;
            return this;
        }

        public AnimationComposer interpolate(Interpolator interpolator) {
            this.interpolator = interpolator;
            return this;
        }


        public AnimationComposer withListener(Animator.AnimatorListener listener) {
            callbacks.add(listener);
            return this;
        }

        public YoYoString playOn(View target) {
            this.target = target;
            return new YoYoString(new YoYo(this).play(), this.target);
        }

    }

    /**
     * YoYo string, you can use this string to control your YoYo.
     */
    public static final class YoYoString {

        private BaseViewAnimator animator;
        private View target;

        private YoYoString(BaseViewAnimator animator, View target){
            this.target = target;
            this.animator = animator;
        }

        public boolean isStarted(){
            return animator.isStarted();
        }

        public boolean isRunning(){
            return animator.isRunning();
        }

        public void stop(boolean reset){
            animator.cancel();

            if(reset)
                animator.reset(target);
        }

    }

    private BaseViewAnimator play() {
        animator.setTarget(target);
        animator.setDuration(duration)
                .setInterpolator(interpolator)
                .setStartDelay(delay);

        if (callbacks.size() > 0) {
            for (Animator.AnimatorListener callback : callbacks) {
                animator.addAnimatorListener(callback);
            }
        }

        animator.animate();
        return animator;
    }

}




Java Source Code List

com.daimajia.androidanimations.EffectAdapter.java
com.daimajia.androidanimations.ExampleActivity.java
com.daimajia.androidanimations.MyActivity.java
com.daimajia.androidanimations.library.BaseViewAnimator.java
com.daimajia.androidanimations.library.Techniques.java
com.daimajia.androidanimations.library.YoYo.java
com.daimajia.androidanimations.library.attention.BounceAnimator.java
com.daimajia.androidanimations.library.attention.FlashAnimator.java
com.daimajia.androidanimations.library.attention.PulseAnimator.java
com.daimajia.androidanimations.library.attention.RubberBandAnimator.java
com.daimajia.androidanimations.library.attention.ShakeAnimator.java
com.daimajia.androidanimations.library.attention.StandUpAnimator.java
com.daimajia.androidanimations.library.attention.SwingAnimator.java
com.daimajia.androidanimations.library.attention.TadaAnimator.java
com.daimajia.androidanimations.library.attention.WaveAnimator.java
com.daimajia.androidanimations.library.attention.WobbleAnimator.java
com.daimajia.androidanimations.library.bouncing_entrances.BounceInAnimator.java
com.daimajia.androidanimations.library.bouncing_entrances.BounceInDownAnimator.java
com.daimajia.androidanimations.library.bouncing_entrances.BounceInLeftAnimator.java
com.daimajia.androidanimations.library.bouncing_entrances.BounceInRightAnimator.java
com.daimajia.androidanimations.library.bouncing_entrances.BounceInUpAnimator.java
com.daimajia.androidanimations.library.fading_entrances.FadeInAnimator.java
com.daimajia.androidanimations.library.fading_entrances.FadeInDownAnimator.java
com.daimajia.androidanimations.library.fading_entrances.FadeInLeftAnimator.java
com.daimajia.androidanimations.library.fading_entrances.FadeInRightAnimator.java
com.daimajia.androidanimations.library.fading_entrances.FadeInUpAnimator.java
com.daimajia.androidanimations.library.fading_exits.FadeOutAnimator.java
com.daimajia.androidanimations.library.fading_exits.FadeOutDownAnimator.java
com.daimajia.androidanimations.library.fading_exits.FadeOutLeftAnimator.java
com.daimajia.androidanimations.library.fading_exits.FadeOutRightAnimator.java
com.daimajia.androidanimations.library.fading_exits.FadeOutUpAnimator.java
com.daimajia.androidanimations.library.flippers.FlipInXAnimator.java
com.daimajia.androidanimations.library.flippers.FlipOutXAnimator.java
com.daimajia.androidanimations.library.flippers.FlipOutYAnimator.java
com.daimajia.androidanimations.library.flippers.FlipYAnimator.java
com.daimajia.androidanimations.library.rotating_entrances.RotateInAnimator.java
com.daimajia.androidanimations.library.rotating_entrances.RotateInDownLeftAnimator.java
com.daimajia.androidanimations.library.rotating_entrances.RotateInDownRightAnimator.java
com.daimajia.androidanimations.library.rotating_entrances.RotateInUpLeftAnimator.java
com.daimajia.androidanimations.library.rotating_entrances.RotateInUpRightAnimator.java
com.daimajia.androidanimations.library.rotating_exits.RotateOutAnimator.java
com.daimajia.androidanimations.library.rotating_exits.RotateOutDownLeftAnimator.java
com.daimajia.androidanimations.library.rotating_exits.RotateOutDownRightAnimator.java
com.daimajia.androidanimations.library.rotating_exits.RotateOutUpLeftAnimator.java
com.daimajia.androidanimations.library.rotating_exits.RotateOutUpRightAnimator.java
com.daimajia.androidanimations.library.sliders.SlideInDownAnimator.java
com.daimajia.androidanimations.library.sliders.SlideInLeftAnimator.java
com.daimajia.androidanimations.library.sliders.SlideInRightAnimator.java
com.daimajia.androidanimations.library.sliders.SlideInUpAnimator.java
com.daimajia.androidanimations.library.sliders.SlideOutDownAnimator.java
com.daimajia.androidanimations.library.sliders.SlideOutLeftAnimator.java
com.daimajia.androidanimations.library.sliders.SlideOutRightAnimator.java
com.daimajia.androidanimations.library.sliders.SlideOutUpAnimator.java
com.daimajia.androidanimations.library.specials.HingeAnimator.java
com.daimajia.androidanimations.library.specials.RollInAnimator.java
com.daimajia.androidanimations.library.specials.RollOutAnimator.java
com.daimajia.androidanimations.library.specials.in.DropOutAnimator.java
com.daimajia.androidanimations.library.specials.in.LandingAnimator.java
com.daimajia.androidanimations.library.specials.out.TakingOffAnimator.java
com.daimajia.androidanimations.library.zooming_entrances.ZoomInAnimator.java
com.daimajia.androidanimations.library.zooming_entrances.ZoomInDownAnimator.java
com.daimajia.androidanimations.library.zooming_entrances.ZoomInLeftAnimator.java
com.daimajia.androidanimations.library.zooming_entrances.ZoomInRightAnimator.java
com.daimajia.androidanimations.library.zooming_entrances.ZoomInUpAnimator.java
com.daimajia.androidanimations.library.zooming_exits.ZoomOutAnimator.java
com.daimajia.androidanimations.library.zooming_exits.ZoomOutDownAnimator.java
com.daimajia.androidanimations.library.zooming_exits.ZoomOutLeftAnimator.java
com.daimajia.androidanimations.library.zooming_exits.ZoomOutRightAnimator.java
com.daimajia.androidanimations.library.zooming_exits.ZoomOutUpAnimator.java