istereo2
changeset 33:3784a2d4bed5
more ad fuckery
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Sat, 10 Oct 2015 16:38:19 +0300 |
parents | 622f61160016 |
children | 33ba8618972c |
files | src/android/MainActivity.java |
diffstat | 1 files changed, 45 insertions(+), 15 deletions(-) [+] |
line diff
1.1 --- a/src/android/MainActivity.java Fri Oct 09 05:17:11 2015 +0300 1.2 +++ b/src/android/MainActivity.java Sat Oct 10 16:38:19 2015 +0300 1.3 @@ -25,7 +25,9 @@ 1.4 PopupWindow ad_win; 1.5 LinearLayout ad_layout, ad_main_layout; 1.6 boolean ad_ready = false; 1.7 - boolean waiting_for_ad = false; 1.8 + boolean ad_visible = false; 1.9 + boolean ad_show_pending = false; 1.10 + AdRequest ad_request; 1.11 1.12 @Override 1.13 protected void onCreate(Bundle saved_inst) 1.14 @@ -120,10 +122,11 @@ 1.15 1.16 act = this; 1.17 1.18 + /* 1.19 this.runOnUiThread(new Runnable() { 1.20 @Override 1.21 public void run() 1.22 - { 1.23 + {*/ 1.24 Log.i(tag, "[JAVA] Creating Ad popup"); 1.25 1.26 ad_win = new PopupWindow(act); 1.27 @@ -159,7 +162,6 @@ 1.28 Log.i(tag, "[JAVA] ad loaded"); 1.29 super.onAdLoaded(); 1.30 ad_ready = true; 1.31 - waiting_for_ad = false; 1.32 show_ad(); 1.33 } 1.34 @Override 1.35 @@ -168,18 +170,28 @@ 1.36 Log.e(tag, "[JAVA] ad failed to load, error code: " + error_code); 1.37 super.onAdFailedToLoad(error_code); 1.38 ad_ready = false; 1.39 - waiting_for_ad = false; 1.40 request_ad(); 1.41 } 1.42 }); 1.43 1.44 - if(!waiting_for_ad) { 1.45 + /*if(!ad_view.isLoading()) { 1.46 request_ad(); 1.47 - } 1.48 + }*/ 1.49 + AdRequest.Builder reqbuild = new AdRequest.Builder(); 1.50 + reqbuild.addTestDevice(AdRequest.DEVICE_ID_EMULATOR); 1.51 + reqbuild.addTestDevice(dev_id_gnexus); 1.52 + reqbuild.addTestDevice(dev_id_nexus7); 1.53 + ad_request = reqbuild.build(); 1.54 + 1.55 + ad_win.showAtLocation(ad_main_layout, Gravity.TOP, 0, 0); 1.56 + ad_win.update(); 1.57 + 1.58 + show_ad(); 1.59 1.60 Log.i(tag, "[JAVA] Done creating ad popup"); 1.61 + /* 1.62 } 1.63 - }); 1.64 + });*/ 1.65 } 1.66 1.67 public void destroy_ad_popup() 1.68 @@ -210,36 +222,54 @@ 1.69 reqbuild.addTestDevice(dev_id_gnexus); 1.70 reqbuild.addTestDevice(dev_id_nexus7); 1.71 ad_view.loadAd(reqbuild.build()); 1.72 - 1.73 - waiting_for_ad = true; 1.74 } 1.75 1.76 private void show_ad() 1.77 { 1.78 + Log.i(tag, "[JAVA] show_ad called"); 1.79 + if(ad_view == null || ad_request == null) { 1.80 + ad_show_pending = true; 1.81 + return; 1.82 + } 1.83 + /*if(!ad_visible) { 1.84 + ad_view.resume(); 1.85 + }*/ 1.86 + if(!ad_ready && !ad_view.isLoading()) { 1.87 + ad_view.loadAd(ad_request); 1.88 + return; 1.89 + } 1.90 + ad_view.setVisibility(View.VISIBLE); 1.91 + ad_view.resume(); 1.92 + ad_win.update(); 1.93 + ad_show_pending = false; 1.94 + /* 1.95 if(ad_ready) { 1.96 Log.i(tag, "[JAVA] show_ad called with ad ready"); 1.97 - ad_view.setVisibility(View.VISIBLE); 1.98 ad_win.showAtLocation(ad_main_layout, Gravity.TOP, 0, 0); 1.99 ad_win.update(); 1.100 } else { 1.101 - if(!waiting_for_ad) { 1.102 + if(!ad_view.isLoading()) { 1.103 Log.i(tag, "[JAVA] show_ad called with ad neither ready nor pending"); 1.104 request_ad(); 1.105 } else { 1.106 Log.i(tag, "[JAVA] show_ad called with ad pending: nop"); 1.107 } 1.108 } 1.109 + */ 1.110 } 1.111 1.112 private void hide_ad() 1.113 { 1.114 Log.i(tag, "[JAVA] hide_ad called"); 1.115 - //ad_view.setVisibility(View.GONE); 1.116 - ad_win.dismiss(); 1.117 - //ad_win.update(); 1.118 + ad_view.destroy(); 1.119 + ad_view.setVisibility(View.GONE); 1.120 + ad_view.pause(); 1.121 + //ad_win.dismiss(); 1.122 + ad_win.update(); 1.123 //destroy_ad_popup(); 1.124 ad_ready = false; 1.125 - waiting_for_ad = false; 1.126 + ad_visible = false; 1.127 + ad_show_pending = false; 1.128 } 1.129 1.130