Last active
September 8, 2016 09:30
-
-
Save olivierperez/132f21d74ec87f225380aefaff6c78fc to your computer and use it in GitHub Desktop.
This file contains hidden or 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
TextViewAnimator animator = new TextViewAnimator(); | |
animator.flip(myTextView, label); | |
// animator.fade(myTextView, label); |
This file contains hidden or 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
package fr.o80.android.animator; | |
import android.animation.Animator; | |
/** | |
* @author Olivier Perez | |
*/ | |
abstract class BaseAnimatorListener implements Animator.AnimatorListener { | |
@Override | |
public void onAnimationStart(Animator animation) { | |
} | |
@Override | |
public void onAnimationEnd(Animator animation) { | |
} | |
@Override | |
public void onAnimationCancel(Animator animation) { | |
} | |
@Override | |
public void onAnimationRepeat(Animator animation) { | |
} | |
} |
This file contains hidden or 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
package fr.o80.android.animator; | |
import android.animation.Animator; | |
import android.animation.ObjectAnimator; | |
import android.widget.TextView; | |
import BaseAnimatorListener; | |
/** | |
* @author Olivier Perez | |
*/ | |
public class TextViewAnimator { | |
private static final long ANIMATION_SHORT = 300; | |
public void fade(final TextView textView, final String label) { | |
final ObjectAnimator fadeOut = ObjectAnimator | |
.ofFloat(textView, "alpha", 0) | |
.setDuration(ANIMATION_SHORT / 2); | |
final ObjectAnimator fadeIn = ObjectAnimator | |
.ofFloat(textView, "alpha", 1) | |
.setDuration(ANIMATION_SHORT / 2); | |
fadeOut.addListener(new BaseAnimatorListener() { | |
@Override | |
public void onAnimationEnd(Animator animation) { | |
textView.setText(label); | |
fadeIn.start(); | |
} | |
}); | |
fadeOut.start(); | |
} | |
public void flip(final TextView textView, final String label) { | |
final ObjectAnimator flipOut = ObjectAnimator | |
.ofFloat(textView, "scaleY", 0) | |
.setDuration(ANIMATION_SHORT / 2); | |
final ObjectAnimator flipIn = ObjectAnimator | |
.ofFloat(textView, "scaleY", 1) | |
.setDuration(ANIMATION_SHORT / 2); | |
flipOut.addListener(new BaseAnimatorListener() { | |
@Override | |
public void onAnimationEnd(Animator animation) { | |
textView.setText(label); | |
flipIn.start(); | |
} | |
}); | |
flipOut.start(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment