Guest User

Untitled

a guest
Jan 22nd, 2019
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.60 KB | None | 0 0
  1. public class MainActivity extends AppCompatActivity {
  2.  
  3. private ImageView bubble, bubble1, bubble2, bubble3, bubble4, bubble5, bubble6, bubble7, bubble8;
  4.  
  5. //Created an array that stores the images
  6. private ImageView[] IMGS= new ImageView[9];
  7. private SoundPlayer sound;
  8.  
  9.  
  10. private int deviceHeight;
  11.  
  12. private Animation mAnimation;
  13.  
  14.  
  15. @Override
  16. protected void onCreate(Bundle savedInstanceState) {
  17. super.onCreate(savedInstanceState);
  18. setContentView(R.layout.activity_main);
  19. sound = new SoundPlayer(this);
  20.  
  21.  
  22. //linked up views
  23. bubble = findViewById(R.id.bubble);
  24. bubble1 = findViewById(R.id.bubble1);
  25. bubble2 = findViewById(R.id.bubble2);
  26. bubble3 = findViewById(R.id.bubble3);
  27. bubble4 = findViewById(R.id.bubble4);
  28. bubble5 = findViewById(R.id.bubble5);
  29. bubble6 = findViewById(R.id.bubble6);
  30. bubble7 = findViewById(R.id.bubble7);
  31. bubble8 = findViewById(R.id.bubble8);
  32.  
  33. //assigned the array to the imageviews
  34. IMGS[0] = bubble;
  35. IMGS[1] = bubble1;
  36. IMGS[2] = bubble2;
  37. IMGS[3] = bubble3;
  38. IMGS[4] = bubble4;
  39. IMGS[5] = bubble5;
  40. IMGS[6] = bubble6;
  41. IMGS[7] = bubble7;
  42. IMGS[8] = bubble8;
  43.  
  44. getDeviceHeight();
  45. animateBubble();
  46. }
  47.  
  48.  
  49.  
  50.  
  51.  
  52. public void animateBubble(){
  53. //looped thru the array of Imageviews and animated the images stored in it.
  54.  
  55. for (ImageView img : IMGS) {
  56. mAnimation = new TranslateAnimation(0, 0, 0, -deviceHeight);
  57. mAnimation.setDuration(4000);
  58. mAnimation.setFillAfter(true);
  59. bubble.setAnimation(mAnimation);
  60. bubble.setVisibility(View.VISIBLE);
  61. img.setAnimation(mAnimation);
  62. img.setVisibility(View.VISIBLE);
  63.  
  64. mAnimation.setAnimationListener(new Animation.AnimationListener() {
  65. @Override
  66. public void onAnimationStart(Animation animation) {
  67. sound.playPopSound();
  68.  
  69.  
  70. }
  71.  
  72. @Override
  73. public void onAnimationEnd(Animation animation) {
  74.  
  75.  
  76.  
  77. }
  78.  
  79. @Override
  80. public void onAnimationRepeat(Animation animation) {
  81.  
  82. }
  83. });
  84. }
  85.  
  86.  
  87. }
  88.  
  89.  
  90. public void getDeviceHeight(){
  91. DisplayMetrics displayMetrics = new DisplayMetrics();
  92. getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
  93. deviceHeight = displayMetrics.heightPixels;
  94. }
  95.  
  96.  
  97. public void playSound(View view) {
  98. sound.playPopSound();
  99. }
  100. }
Add Comment
Please, Sign In to add comment