Last active
May 6, 2018 04:34
-
-
Save cesco89/9ddb738eef1cead8fea7 to your computer and use it in GitHub Desktop.
Listen to FragmentTransaction animation events
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.app.Fragment; | |
/** | |
* Created by francesco on 14/10/14. | |
*/ | |
public class ObservableFragment extends Fragment { | |
private TransitionListener mListener; | |
@Override | |
public Animator onCreateAnimator(int transit, boolean enter, int nextAnim) { | |
if(nextAnim != 0x0) { | |
Animator animator = AnimatorInflater.loadAnimator(getActivity(), nextAnim); | |
if (mListener != null) { | |
animator.addListener(new Animator.AnimatorListener() { | |
@Override | |
public void onAnimationStart(Animator animation) { | |
mListener.onTransitionStarted(); | |
} | |
@Override | |
public void onAnimationEnd(Animator animation) { | |
mListener.onTransitionEnded(); | |
} | |
@Override | |
public void onAnimationCancel(Animator animation) { | |
mListener.onTransitionCancel(); | |
} | |
@Override | |
public void onAnimationRepeat(Animator animation) { | |
mListener.onTransitionRepeated(); | |
} | |
}); | |
} | |
return animator; | |
} | |
return null; | |
} | |
public void setTransitionListener(TransitionListener listener) { | |
this.mListener = listener; | |
} | |
public interface TransitionListener { | |
public void onTransitionStarted(); | |
public void onTransitionCancel(); | |
public void onTransitionEnded(); | |
public void onTransitionRepeated(); | |
} | |
} |
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
ObservableFragment f = new MyFragment(); | |
f.setTransitionListener(new ObservableFragment.TransitionListener() { | |
@Override | |
public void onTransitionStarted() { | |
}; | |
@Override | |
public void onTransitionCancel(){ | |
}; | |
@Override | |
public void onTransitionEnded(){ | |
}; | |
@Override | |
public void onTransitionRepeated(){ | |
}; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment