Advertisement
Guest User

Untitled

a guest
Apr 24th, 2017
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.88 KB | None | 0 0
  1. ```java
  2. public class MainActivity extends Activity {
  3.  
  4. ImageView maru_button,batsu_button,qbutton,rbutton;
  5. private SoundPool mSoundPool;
  6. private int maru_SoundId,batsu_SoundId,q_SoundId,r_SoundId;
  7.  
  8. InterstitialAd mInterstitialAd;
  9.  
  10. @Override
  11. protected void onCreate(Bundle savedInstanceState) {
  12. super.onCreate(savedInstanceState);
  13. setContentView(R.layout.activity_main);
  14.  
  15. maru_button = (ImageView) findViewById(R.id.maru);
  16. batsu_button = (ImageView) findViewById(R.id.batsu);
  17. qbutton = (ImageView) findViewById(R.id.qbutton);
  18. rbutton = (ImageView) findViewById(R.id.rbutton);
  19.  
  20. maru_button.setOnClickListener(new View.OnClickListener() {
  21. @Override
  22. public void onClick(View v) {
  23. //音声
  24. if (mInterstitialAd.isLoaded()) {
  25. mInterstitialAd.show();
  26. } else {
  27. mSoundPool.play(maru_SoundId, 1.0F, 1.0F, 0, 0, 1.0F);
  28. }
  29. }
  30. });
  31.  
  32. batsu_button.setOnClickListener(new View.OnClickListener() {
  33. @Override
  34. public void onClick(View v) {
  35. mSoundPool.play(batsu_SoundId, 1.0F, 1.0F, 0, 0, 1.0F);
  36. }
  37. });
  38.  
  39. qbutton.setOnClickListener(new View.OnClickListener() {
  40. @Override
  41. public void onClick(View v) {
  42. mSoundPool.play(q_SoundId, 1.0F, 1.0F, 0, 0, 1.0F);
  43. }
  44. });
  45.  
  46. rbutton.setOnClickListener(new View.OnClickListener() {
  47. @Override
  48. public void onClick(View v) {
  49. mSoundPool.play(r_SoundId, 1.0F, 1.0F, 0, 0, 1.0F);
  50. }
  51. });
  52.  
  53. AdView mAdView = (AdView) findViewById(R.id.adView);
  54. AdRequest adRequest = new AdRequest.Builder().build();
  55. mAdView.loadAd(adRequest);
  56.  
  57. mInterstitialAd = new InterstitialAd(this);
  58. mInterstitialAd.setAdUnitId("ca-app-pub-3940256099942544/1033173712");
  59.  
  60. mInterstitialAd.setAdListener(new AdListener() {
  61. @Override
  62. public void onAdClosed() {
  63. requestNewInterstitial();
  64. }
  65. });
  66.  
  67. requestNewInterstitial();
  68.  
  69. }
  70.  
  71.  
  72. private void requestNewInterstitial() {
  73. AdRequest adRequest = new AdRequest.Builder()
  74. .addTestDevice("SEE_YOUR_LOGCAT_TO_GET_YOUR_DEVICE_ID")
  75. .build();
  76.  
  77. mInterstitialAd.loadAd(adRequest);
  78. }
  79.  
  80. @Override
  81. protected void onResume() {
  82. super.onResume();
  83. //音声
  84. mSoundPool = new SoundPool(4, AudioManager.STREAM_MUSIC, 0);
  85. maru_SoundId = mSoundPool.load(getApplicationContext(), R.raw.correct, 0);
  86. batsu_SoundId = mSoundPool.load(getApplicationContext(),R.raw.wrong,0);
  87. q_SoundId = mSoundPool.load(getApplicationContext(),R.raw.question,0);
  88. r_SoundId = mSoundPool.load(getApplicationContext(),R.raw.result,0);
  89. }
  90.  
  91. @Override
  92. protected void onPause() {
  93. super.onPause();
  94. // リリース
  95. mSoundPool.release();
  96. }
  97. }
  98. ```
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement