Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions src/android/com/google/cordova/plugin/AdMobPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import org.json.JSONObject;

import android.util.Log;
import android.view.View;

import com.google.ads.Ad;
import com.google.ads.AdListener;
Expand Down Expand Up @@ -42,6 +43,7 @@ public class AdMobPlugin extends CordovaPlugin {
public static final String ACTION_CREATE_INTERSTITIAL_VIEW = "createInterstitialView";
public static final String ACTION_REQUEST_AD = "requestAd";
public static final String KILL_AD = "killAd";
public static final String SHOW_AD = "showAd";

/**
* This is the main method for the AdMob plugin. All API calls go through
Expand Down Expand Up @@ -73,6 +75,9 @@ public boolean execute(String action, JSONArray inputs,
} else if (KILL_AD.equals(action)) {
executeKillAd(callbackContext);
return true;
} else if (SHOW_AD.equals(action)) {
executeShowAd(inputs,callbackContext);
return true;
} else {
Log.d(LOGTAG, String.format("Invalid action passed: %s", action));
callbackContext.error("Invalid Action");
Expand Down Expand Up @@ -365,6 +370,33 @@ public void run() {

this.cordova.getActivity().runOnUiThread(runnable);
}


private void executeShowAd(JSONArray inputs,final CallbackContext callbackContext) {
final boolean show;
if(adView!=null){
// Get the input data.
try {
show = inputs.getBoolean( 0 );
cordova.getActivity().runOnUiThread(new Runnable() {
public void run() {
if (show) {
adView.setVisibility(View.VISIBLE);
} else {
adView.setVisibility(View.GONE);
}
callbackContext.success();
}
});
} catch (JSONException exception) {
Log.w(LOGTAG, String.format("Got JSON Exception: %s", exception.getMessage()));
callbackContext.error("errInput");
}
}else{
callbackContext.error("errAdViewNull");
}

}

/**
* This class implements the AdMob ad listener events. It forwards the
Expand Down
13 changes: 12 additions & 1 deletion www/AdMobPlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,18 @@ var admob = {
failureCallback,
'AdMobPlugin',
'killAd',[{}]);
}
},


showAd :function( show, successCallback, failureCallback) {
if (show === undefined) {
show = true;
}else{
show=!!show;
}
cordova.exec(successCallback,failureCallback,'AdMobPlugin','showAd', [ show ]);
}


};

Expand Down