Guest User

Untitled

a guest
Jun 19th, 2018
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.13 KB | None | 0 0
  1. public class FlipAnimation implements Animation.AnimationListener {
  2. private Animation animation1;
  3. private Animation animation2;
  4. private boolean isBackOfCardShowing = true;
  5. private ImageView img;
  6. private Context ctx;
  7. private FlipEnd flipped;
  8. Card card;
  9.  
  10. public interface FlipEnd {
  11. void flipEnd(ImageView img, Card card);
  12. }
  13.  
  14. FlipAnimation(Context ctx, ImageView img, Card card) {
  15. this.img = img;
  16. this.ctx = ctx;
  17. this.card = card;
  18. flipped = (FlipEnd) ctx;
  19. animation1 = AnimationUtils.loadAnimation(ctx, R.anim.flip_to_middle);
  20. animation1.setAnimationListener(this);
  21. animation2 = AnimationUtils.loadAnimation(ctx, R.anim.flip_from_middle);
  22. animation2.setAnimationListener(this);
  23.  
  24. img.clearAnimation();
  25. img.setAnimation(animation1);
  26. img.startAnimation(animation1);
  27. }
  28.  
  29. @Override
  30. public void onAnimationStart(Animation animation) {
  31.  
  32. }
  33.  
  34. @Override
  35. public void onAnimationEnd(Animation animation) {
  36. if (animation == animation1) {
  37. if (isBackOfCardShowing) {
  38. Card
  39. img.setImageResource(R.drawable.card_face);
  40. flipped.flipEnd(img,card);
  41. } else {
  42. img.setImageResource(R.drawable.card_back);
  43. }
  44. img.clearAnimation();
  45. img.setAnimation(animation2);
  46. img.startAnimation(animation2);
  47. } else {
  48. isBackOfCardShowing = !isBackOfCardShowing;
  49. }
  50.  
  51. }
  52.  
  53. @Override
  54. public void onAnimationRepeat(Animation animation) {
  55.  
  56. }
  57. }
  58.  
  59. <scale xmlns:android="http://schemas.android.com/apk/res/android"
  60. android:duration="250"
  61. android:fromXScale="1.0"
  62. android:fromYScale="1.0"
  63. android:pivotX="50%"
  64. android:pivotY="50%"
  65. android:toXScale="0.0"
  66. android:toYScale="1.0" />
  67.  
  68. <scale
  69. xmlns:android="http://schemas.android.com/apk/res/android"
  70. android:fromXScale="0.0" android:toXScale="1.0"
  71. android:pivotX="50%"
  72. android:fromYScale="1.0" android:toYScale="1.0"
  73. android:pivotY="50%"
  74. android:duration="250" />
Add Comment
Please, Sign In to add comment