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)//www.java2s.com
*
* 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;
publicclass YoYo {
privatestaticfinallong DURATION = BaseViewAnimator.DURATION;
privatestaticfinallong NO_DELAY = 0;
private BaseViewAnimator animator;
privatelong duration;
privatelong 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;
}
publicstatic AnimationComposer with(Techniques techniques) {
returnnew AnimationComposer(techniques);
}
publicstatic AnimationComposer with(BaseViewAnimator animator) {
returnnew AnimationComposer(animator);
}
publicstaticfinalclass AnimationComposer {
private List<Animator.AnimatorListener> callbacks = new ArrayList<Animator.AnimatorListener>();
private BaseViewAnimator animator;
privatelong duration = DURATION;
privatelong 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;
returnthis;
}
public AnimationComposer delay(long delay) {
this.delay = delay;
returnthis;
}
public AnimationComposer interpolate(Interpolator interpolator) {
this.interpolator = interpolator;
returnthis;
}
public AnimationComposer withListener(Animator.AnimatorListener listener) {
callbacks.add(listener);
returnthis;
}
public YoYoString playOn(View target) {
this.target = target;
returnnew YoYoString(new YoYo(this).play(), this.target);
}
}
/**
* YoYo string, you can use this string to control your YoYo.
*/publicstaticfinalclass YoYoString {
private BaseViewAnimator animator;
private View target;
private YoYoString(BaseViewAnimator animator, View target){
this.target = target;
this.animator = animator;
}
publicboolean isStarted(){
return animator.isStarted();
}
publicboolean isRunning(){
return animator.isRunning();
}
publicvoid 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;
}
}