Created
May 7, 2015 09:27
-
-
Save a-klimashevsky/65652cf74229c02efbde to your computer and use it in GitHub Desktop.
Simple wrapper for playing Animator with android.support.v4.app.Fragment. Useful if you need to deal with libraries, which required of using support fragments.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import android.animation.Animator; | |
import android.animation.AnimatorInflater; | |
import android.support.v4.app.Fragment; | |
import android.view.animation.Animation; | |
import android.view.animation.Transformation; | |
/** | |
* Created by Alex Klimashevsky on 5/7/15. | |
* Simple wrapper for playing Animator with android.support.v4.app.Fragment | |
*/ | |
public class AnimatorFragment extends Fragment{ | |
@Override | |
public Animation onCreateAnimation(int transit, boolean enter, int nextAnim) { | |
if(nextAnim != 0) { | |
Animator a = AnimatorInflater.loadAnimator(getActivity(), nextAnim); | |
a.setTarget(getView()); | |
return new AnimatorAnimationWrapper(a); | |
} | |
return null; | |
} | |
/** | |
* Animator wrapper | |
*/ | |
private static class AnimatorAnimationWrapper extends Animation{ | |
private Animator mAnimator; | |
public AnimatorAnimationWrapper(Animator animator) { | |
mAnimator = animator; | |
} | |
@Override | |
protected void applyTransformation(float interpolatedTime, Transformation t) { | |
if(interpolatedTime == 0){ | |
mAnimator.start(); | |
} | |
} | |
@Override | |
public boolean willChangeBounds() { | |
return true; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment