Guest User

Untitled

a guest
Dec 14th, 2019
144
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. package com.animalsounds123.animalsounds123;
  2.  
  3. import android.app.Activity;
  4. import android.media.MediaPlayer;
  5. import android.os.Bundle;
  6. import android.util.Log;
  7. import android.view.View;
  8. import android.widget.Button;
  9.  
  10. import androidx.appcompat.app.AppCompatActivity;
  11.  
  12. import com.google.android.gms.ads.AdListener;
  13. import com.google.android.gms.ads.AdRequest;
  14. import com.google.android.gms.ads.InterstitialAd;
  15. import com.google.android.gms.ads.MobileAds;
  16. import com.google.android.gms.ads.initialization.InitializationStatus;
  17. import com.google.android.gms.ads.initialization.OnInitializationCompleteListener;
  18.  
  19. public class MainActivity extends AppCompatActivity {
  20.  
  21. private InterstitialAd mInterstitialAd;
  22. //final Activity activity = this;
  23.  
  24. @Override
  25. protected void onCreate(Bundle savedInstanceState) {
  26. super.onCreate(savedInstanceState);
  27. setContentView(R.layout.activity_main);
  28.  
  29. final Activity activity = this;
  30.  
  31. MobileAds.initialize(this, new OnInitializationCompleteListener() {
  32. @Override
  33. public void onInitializationComplete(InitializationStatus initializationStatus) {
  34. Log.d("TAG", "Ads just loaded");
  35. }
  36. });
  37. mInterstitialAd = new InterstitialAd(this);
  38. mInterstitialAd.setAdUnitId("ca-app-pub-5586185520040340/4903201456");
  39.  
  40. final MediaPlayer dogSoundMP = MediaPlayer.create(this, R.raw.angrydog);
  41.  
  42. Button playDogBark = (Button) this.findViewById(R.id.button);
  43.  
  44. playDogBark.setOnClickListener(new View.OnClickListener() {
  45. @Override
  46. public void onClick(View view) {
  47. dogSoundMP.start();
  48. mInterstitialAd.loadAd(new AdRequest.Builder().build());
  49. mInterstitialAd.setAdListener(new AdListener() {
  50. @Override
  51. public void onAdLoaded() {
  52. super.onAdLoaded();
  53. if (!activity.isFinishing()) {
  54. mInterstitialAd.show();
  55. }
  56. }
  57. });
  58. }
  59. });
  60.  
  61. /*private void showInterstitial() {
  62. // Show the ad if it's ready. Otherwise toast and restart the game.
  63. if (mInterstitialAd != null && mInterstitialAd.isLoaded()) {
  64. mInterstitialAd.show();
  65. } else {
  66. Toast.makeText(this, "Ad did not load", Toast.LENGTH_SHORT).show();
  67. //startGame();
  68. }
  69. }*/
  70.  
  71. final MediaPlayer catSoundMP = MediaPlayer.create(this, R.raw.cat);
  72.  
  73. Button playCatBark = (Button) this.findViewById(R.id.button2);
  74.  
  75. playCatBark.setOnClickListener(new View.OnClickListener() {
  76. @Override
  77. public void onClick(View view) {
  78. catSoundMP.start();
  79. }
  80. });
  81.  
  82. final MediaPlayer monkeySoundMP = MediaPlayer.create(this, R.raw.monkey);
  83.  
  84. Button playmonkeyBark = (Button) this.findViewById(R.id.button6);
  85.  
  86. playmonkeyBark.setOnClickListener(new View.OnClickListener() {
  87. @Override
  88. public void onClick(View view) {
  89. monkeySoundMP.start();
  90. }
  91. });
  92.  
  93. final MediaPlayer birdSoundMP = MediaPlayer.create(this, R.raw.bird);
  94.  
  95. Button playbirdBark = (Button) this.findViewById(R.id.button3);
  96.  
  97. playbirdBark.setOnClickListener(new View.OnClickListener() {
  98. @Override
  99. public void onClick(View view) {
  100. birdSoundMP.start();
  101. }
  102. });
  103.  
  104. final MediaPlayer pigSoundMP = MediaPlayer.create(this, R.raw.pig);
  105.  
  106. Button playpigBark = (Button) this.findViewById(R.id.button4);
  107.  
  108. playpigBark.setOnClickListener(new View.OnClickListener() {
  109. @Override
  110. public void onClick(View view) {
  111. pigSoundMP.start();
  112. }
  113. });
  114.  
  115. final MediaPlayer bearSoundMP = MediaPlayer.create(this, R.raw.bear);
  116.  
  117. Button playbearBark = (Button) this.findViewById(R.id.button5);
  118.  
  119. playbearBark.setOnClickListener(new View.OnClickListener() {
  120. @Override
  121. public void onClick(View view) {
  122. bearSoundMP.start();
  123. }
  124. });
  125.  
  126. final MediaPlayer rodentSoundMP = MediaPlayer.create(this, R.raw.rodent);
  127.  
  128. Button playrodentBark = (Button) this.findViewById(R.id.button7);
  129.  
  130. playrodentBark.setOnClickListener(new View.OnClickListener() {
  131. @Override
  132. public void onClick(View view) {
  133. rodentSoundMP.start();
  134. }
  135. });
  136. }
  137. }
RAW Paste Data