# HG changeset patch # User John Tsiombikas # Date 1444310607 -10800 # Node ID 48a0660bac82de71bd48ce5a0cc0a27eec999e22 # Parent 900651a2f401a5c18aa00d102ec03b8f6db889a0 fucked up the ads diff -r 900651a2f401 -r 48a0660bac82 src/android/MainActivity.java --- a/src/android/MainActivity.java Thu Oct 08 06:54:18 2015 +0300 +++ b/src/android/MainActivity.java Thu Oct 08 16:23:27 2015 +0300 @@ -49,7 +49,6 @@ super.onDestroy(); } - /* @Override public void onAttachedToWindow() { @@ -57,7 +56,6 @@ create_ad_popup(); } - */ @Override public void onWindowFocusChanged(boolean focus) @@ -70,6 +68,7 @@ protected void onResume() { + Log.i(tag, "[JAVA] onResume()"); super.onResume(); if(ad_view != null) { ad_view.resume(); @@ -79,6 +78,7 @@ protected void onPause() { + Log.i(tag, "[JAVA] onPause()"); super.onPause(); if(ad_view != null) { ad_view.pause(); @@ -115,7 +115,7 @@ // ads ... public void create_ad_popup() { - Log.i(tag, "create_ad_popup called"); + Log.i(tag, "[JAVA] create_ad_popup called"); if(ad_view != null) return; act = this; @@ -124,7 +124,7 @@ @Override public void run() { - Log.i(tag, "Creating Ad popup"); + Log.i(tag, "[JAVA] Creating Ad popup"); ad_win = new PopupWindow(act); // set minimum size @@ -152,13 +152,12 @@ ad_layout.addView(ad_view, params); ad_win.setContentView(ad_layout); - ad_view.setAdListener(new AdListener() { @Override public void onAdLoaded() { + Log.i(tag, "[JAVA] ad loaded"); super.onAdLoaded(); - Log.i(tag, "ad loaded"); ad_ready = true; waiting_for_ad = false; show_ad(); @@ -166,22 +165,22 @@ @Override public void onAdFailedToLoad(int error_code) { + Log.e(tag, "[JAVA] ad failed to load, error code: " + error_code); super.onAdFailedToLoad(error_code); - Log.e(tag, "ad failed to load, error code: " + error_code); ad_ready = false; waiting_for_ad = false; request_ad(); } }); - Log.i(tag, "Done creating ad popup"); + Log.i(tag, "[JAVA] Done creating ad popup"); } }); } public void destroy_ad_popup() { - Log.i(tag, "destroy_ad_popup called"); + Log.i(tag, "[JAVA] destroy_ad_popup called"); if(ad_view != null) { ad_view.destroy(); @@ -195,7 +194,12 @@ public void request_ad() { - Log.i(tag, "requesting ad"); + Log.i(tag, "[JAVA] requesting ad"); + + if(ad_view == null) { + Log.e(tag, "[JAVA] request_ad called without an ad_view"); + return; + } AdRequest.Builder reqbuild = new AdRequest.Builder(); reqbuild.addTestDevice(AdRequest.DEVICE_ID_EMULATOR); @@ -208,26 +212,24 @@ private void show_ad() { - Log.i(tag, "show_ad called"); - - if(ad_win == null) { - create_ad_popup(); - } - if(ad_ready) { - //ad_view.setVisibility(View.VISIBLE); + Log.i(tag, "[JAVA] show_ad called with ad ready"); + ad_view.setVisibility(View.VISIBLE); ad_win.showAtLocation(ad_main_layout, Gravity.TOP, 0, 0); ad_win.update(); } else { if(!waiting_for_ad) { + Log.i(tag, "[JAVA] show_ad called with ad neither ready nor pending"); request_ad(); + } else { + Log.i(tag, "[JAVA] show_ad called with ad pending: nop"); } } } private void hide_ad() { - Log.i(tag, "hide_ad called"); + Log.i(tag, "[JAVA] hide_ad called"); //ad_view.setVisibility(View.GONE); ad_win.dismiss(); //ad_win.update(); diff -r 900651a2f401 -r 48a0660bac82 src/android/amain.c --- a/src/android/amain.c Thu Oct 08 06:54:18 2015 +0300 +++ b/src/android/amain.c Thu Oct 08 16:23:27 2015 +0300 @@ -85,6 +85,8 @@ jmethodID method; if(!jvm) return; + printf("ad_banner_show called\n"); + if(!(method = (*jni)->GetMethodID(jni, activity_class, "show_ad", "()V"))) { fprintf(stderr, "failed to retrieve MainActivity.show_ad method\n"); return; @@ -97,6 +99,8 @@ jmethodID method; if(!jvm) return; + printf("ad_banner_hide called\n"); + if(!(method = (*jni)->GetMethodID(jni, activity_class, "hide_ad", "()V"))) { fprintf(stderr, "failed to retrieve MainActivity.hide_ad method\n"); return; @@ -113,7 +117,7 @@ case APP_CMD_INIT_WINDOW: printf("APP_CMD_INIT_WINDOW\n"); - ad_banner_show(); + //ad_banner_show(); if(init_gl() == -1) { exit(1);