Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class MainActivity extends AppCompatActivity {
- private ImageView bubble, bubble1, bubble2, bubble3, bubble4, bubble5, bubble6, bubble7, bubble8;
- //Created an array that stores the images
- private ImageView[] IMGS= new ImageView[9];
- private SoundPlayer sound;
- private int deviceHeight;
- private Animation mAnimation;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- sound = new SoundPlayer(this);
- //linked up views
- bubble = findViewById(R.id.bubble);
- bubble1 = findViewById(R.id.bubble1);
- bubble2 = findViewById(R.id.bubble2);
- bubble3 = findViewById(R.id.bubble3);
- bubble4 = findViewById(R.id.bubble4);
- bubble5 = findViewById(R.id.bubble5);
- bubble6 = findViewById(R.id.bubble6);
- bubble7 = findViewById(R.id.bubble7);
- bubble8 = findViewById(R.id.bubble8);
- //assigned the array to the imageviews
- IMGS[0] = bubble;
- IMGS[1] = bubble1;
- IMGS[2] = bubble2;
- IMGS[3] = bubble3;
- IMGS[4] = bubble4;
- IMGS[5] = bubble5;
- IMGS[6] = bubble6;
- IMGS[7] = bubble7;
- IMGS[8] = bubble8;
- getDeviceHeight();
- animateBubble();
- }
- public void animateBubble(){
- //looped thru the array of Imageviews and animated the images stored in it.
- for (ImageView img : IMGS) {
- mAnimation = new TranslateAnimation(0, 0, 0, -deviceHeight);
- mAnimation.setDuration(4000);
- mAnimation.setFillAfter(true);
- bubble.setAnimation(mAnimation);
- bubble.setVisibility(View.VISIBLE);
- img.setAnimation(mAnimation);
- img.setVisibility(View.VISIBLE);
- mAnimation.setAnimationListener(new Animation.AnimationListener() {
- @Override
- public void onAnimationStart(Animation animation) {
- sound.playPopSound();
- }
- @Override
- public void onAnimationEnd(Animation animation) {
- }
- @Override
- public void onAnimationRepeat(Animation animation) {
- }
- });
- }
- }
- public void getDeviceHeight(){
- DisplayMetrics displayMetrics = new DisplayMetrics();
- getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
- deviceHeight = displayMetrics.heightPixels;
- }
- public void playSound(View view) {
- sound.playPopSound();
- }
- }
Add Comment
Please, Sign In to add comment