istereo2

changeset 31:48a0660bac82

fucked up the ads
author John Tsiombikas <nuclear@member.fsf.org>
date Thu, 08 Oct 2015 16:23:27 +0300
parents 900651a2f401
children 622f61160016
files src/android/MainActivity.java src/android/amain.c
diffstat 2 files changed, 25 insertions(+), 19 deletions(-) [+]
line diff
     1.1 --- a/src/android/MainActivity.java	Thu Oct 08 06:54:18 2015 +0300
     1.2 +++ b/src/android/MainActivity.java	Thu Oct 08 16:23:27 2015 +0300
     1.3 @@ -49,7 +49,6 @@
     1.4  		super.onDestroy();
     1.5  	}
     1.6  
     1.7 -	/*
     1.8  	@Override
     1.9  	public void onAttachedToWindow()
    1.10  	{
    1.11 @@ -57,7 +56,6 @@
    1.12  
    1.13  		create_ad_popup();
    1.14  	}
    1.15 -	*/
    1.16  
    1.17  	@Override
    1.18  	public void onWindowFocusChanged(boolean focus)
    1.19 @@ -70,6 +68,7 @@
    1.20  
    1.21  	protected void onResume()
    1.22  	{
    1.23 +		Log.i(tag, "[JAVA] onResume()");
    1.24  		super.onResume();
    1.25  		if(ad_view != null) {
    1.26  			ad_view.resume();
    1.27 @@ -79,6 +78,7 @@
    1.28  
    1.29  	protected void onPause()
    1.30  	{
    1.31 +		Log.i(tag, "[JAVA] onPause()");
    1.32  		super.onPause();
    1.33  		if(ad_view != null) {
    1.34  			ad_view.pause();
    1.35 @@ -115,7 +115,7 @@
    1.36  	// ads ...
    1.37  	public void create_ad_popup()
    1.38  	{
    1.39 -		Log.i(tag, "create_ad_popup called");
    1.40 +		Log.i(tag, "[JAVA] create_ad_popup called");
    1.41  		if(ad_view != null) return;
    1.42  
    1.43  		act = this;
    1.44 @@ -124,7 +124,7 @@
    1.45  			@Override
    1.46  			public void run()
    1.47  			{
    1.48 -				Log.i(tag, "Creating Ad popup");
    1.49 +				Log.i(tag, "[JAVA] Creating Ad popup");
    1.50  
    1.51  				ad_win = new PopupWindow(act);
    1.52  				// set minimum size
    1.53 @@ -152,13 +152,12 @@
    1.54  				ad_layout.addView(ad_view, params);
    1.55  				ad_win.setContentView(ad_layout);
    1.56  
    1.57 -
    1.58  				ad_view.setAdListener(new AdListener() {
    1.59  					@Override
    1.60  					public void onAdLoaded()
    1.61  					{
    1.62 +						Log.i(tag, "[JAVA] ad loaded");
    1.63  						super.onAdLoaded();
    1.64 -						Log.i(tag, "ad loaded");
    1.65  						ad_ready = true;
    1.66  						waiting_for_ad = false;
    1.67  						show_ad();
    1.68 @@ -166,22 +165,22 @@
    1.69  					@Override
    1.70  					public void onAdFailedToLoad(int error_code)
    1.71  					{
    1.72 +						Log.e(tag, "[JAVA] ad failed to load, error code: " + error_code);
    1.73  						super.onAdFailedToLoad(error_code);
    1.74 -						Log.e(tag, "ad failed to load, error code: " + error_code);
    1.75  						ad_ready = false;
    1.76  						waiting_for_ad = false;
    1.77  						request_ad();
    1.78  					}
    1.79  				});
    1.80  
    1.81 -				Log.i(tag, "Done creating ad popup");
    1.82 +				Log.i(tag, "[JAVA] Done creating ad popup");
    1.83  			}
    1.84  		});
    1.85  	}
    1.86  
    1.87  	public void destroy_ad_popup()
    1.88  	{
    1.89 -		Log.i(tag, "destroy_ad_popup called");
    1.90 +		Log.i(tag, "[JAVA] destroy_ad_popup called");
    1.91  
    1.92  		if(ad_view != null) {
    1.93  			ad_view.destroy();
    1.94 @@ -195,7 +194,12 @@
    1.95  
    1.96  	public void request_ad()
    1.97  	{
    1.98 -		Log.i(tag, "requesting ad");
    1.99 +		Log.i(tag, "[JAVA] requesting ad");
   1.100 +
   1.101 +		if(ad_view == null) {
   1.102 +			Log.e(tag, "[JAVA] request_ad called without an ad_view");
   1.103 +			return;
   1.104 +		}
   1.105  
   1.106  		AdRequest.Builder reqbuild = new AdRequest.Builder();
   1.107  		reqbuild.addTestDevice(AdRequest.DEVICE_ID_EMULATOR);
   1.108 @@ -208,26 +212,24 @@
   1.109  
   1.110  	private void show_ad()
   1.111  	{
   1.112 -		Log.i(tag, "show_ad called");
   1.113 -
   1.114 -		if(ad_win == null) {
   1.115 -			create_ad_popup();
   1.116 -		}
   1.117 -
   1.118  		if(ad_ready) {
   1.119 -			//ad_view.setVisibility(View.VISIBLE);
   1.120 +			Log.i(tag, "[JAVA] show_ad called with ad ready");
   1.121 +			ad_view.setVisibility(View.VISIBLE);
   1.122  			ad_win.showAtLocation(ad_main_layout, Gravity.TOP, 0, 0);
   1.123  			ad_win.update();
   1.124  		} else {
   1.125  			if(!waiting_for_ad) {
   1.126 +				Log.i(tag, "[JAVA] show_ad called with ad neither ready nor pending");
   1.127  				request_ad();
   1.128 +			} else {
   1.129 +				Log.i(tag, "[JAVA] show_ad called with ad pending: nop");
   1.130  			}
   1.131  		}
   1.132  	}
   1.133  
   1.134  	private void hide_ad()
   1.135  	{
   1.136 -		Log.i(tag, "hide_ad called");
   1.137 +		Log.i(tag, "[JAVA] hide_ad called");
   1.138  		//ad_view.setVisibility(View.GONE);
   1.139  		ad_win.dismiss();
   1.140  		//ad_win.update();
     2.1 --- a/src/android/amain.c	Thu Oct 08 06:54:18 2015 +0300
     2.2 +++ b/src/android/amain.c	Thu Oct 08 16:23:27 2015 +0300
     2.3 @@ -85,6 +85,8 @@
     2.4  	jmethodID method;
     2.5  	if(!jvm) return;
     2.6  
     2.7 +	printf("ad_banner_show called\n");
     2.8 +
     2.9  	if(!(method = (*jni)->GetMethodID(jni, activity_class, "show_ad", "()V"))) {
    2.10  		fprintf(stderr, "failed to retrieve MainActivity.show_ad method\n");
    2.11  		return;
    2.12 @@ -97,6 +99,8 @@
    2.13  	jmethodID method;
    2.14  	if(!jvm) return;
    2.15  
    2.16 +	printf("ad_banner_hide called\n");
    2.17 +
    2.18  	if(!(method = (*jni)->GetMethodID(jni, activity_class, "hide_ad", "()V"))) {
    2.19  		fprintf(stderr, "failed to retrieve MainActivity.hide_ad method\n");
    2.20  		return;
    2.21 @@ -113,7 +117,7 @@
    2.22  
    2.23  	case APP_CMD_INIT_WINDOW:
    2.24  		printf("APP_CMD_INIT_WINDOW\n");
    2.25 -		ad_banner_show();
    2.26 +		//ad_banner_show();
    2.27  
    2.28  		if(init_gl() == -1) {
    2.29  			exit(1);