Search in sources :

Example 1 with GenericAd

use of admob.plus.core.GenericAd in project admob-plus by admob-plus.

the class AdMob method execute.

@Override
public boolean execute(String actionKey, JSONArray args, CallbackContext callbackContext) {
    Log.d(TAG, String.format("Execute %s", actionKey));
    ExecuteContext ctx = new ExecuteContext(actionKey, args, callbackContext);
    switch(actionKey) {
        case Actions.READY:
            return executeReady(callbackContext);
        case Actions.START:
            MobileAds.initialize(cordova.getActivity(), status -> {
                helper.configForTestLab();
                callbackContext.success(new JSONObject(new HashMap<String, Object>() {

                    {
                        put("version", MobileAds.getVersionString());
                    }
                }));
            });
            break;
        case Actions.CONFIGURE:
        case Actions.CONFIG_REQUEST:
            ctx.configure(helper);
            break;
        case Actions.AD_CREATE:
            String adClass = ctx.optString("cls");
            if (adClass == null) {
                ctx.reject("ad cls is missing");
            } else {
                GenericAd ad = null;
                switch(adClass) {
                    case "AppOpenAd":
                        ad = new AppOpen(ctx);
                        break;
                    case "BannerAd":
                        ad = new Banner(ctx);
                        break;
                    case "InterstitialAd":
                        ad = new Interstitial(ctx);
                        break;
                    case "NativeAd":
                        ad = new Native(ctx);
                        break;
                    case "RewardedAd":
                        ad = new Rewarded(ctx);
                        break;
                    case "RewardedInterstitialAd":
                        ad = new RewardedInterstitial(ctx);
                        break;
                }
                if (ad != null) {
                    ctx.resolve();
                } else {
                    ctx.reject("ad cls is not supported");
                }
            }
            break;
        case Actions.AD_IS_LOADED:
            return executeAdIsLoaded_(ctx);
        case Actions.AD_LOAD:
            return executeAdLoad(ctx);
        case Actions.AD_SHOW:
            return executeAdShow(ctx);
        case Actions.AD_HIDE:
            return executeAdHide(ctx);
        case Actions.SET_APP_MUTED:
            {
                boolean value = args.optBoolean(0);
                MobileAds.setAppMuted(value);
                callbackContext.success();
                break;
            }
        case Actions.SET_APP_VOLUME:
            {
                float value = BigDecimal.valueOf(args.optDouble(0)).floatValue();
                MobileAds.setAppVolume(value);
                callbackContext.success();
                break;
            }
        default:
            return false;
    }
    return true;
}
Also used : Native(admob.plus.cordova.ads.Native) JSONObject(org.json.JSONObject) HashMap(java.util.HashMap) Banner(admob.plus.cordova.ads.Banner) RewardedInterstitial(admob.plus.cordova.ads.RewardedInterstitial) AppOpen(admob.plus.cordova.ads.AppOpen) GenericAd(admob.plus.core.GenericAd) Interstitial(admob.plus.cordova.ads.Interstitial) RewardedInterstitial(admob.plus.cordova.ads.RewardedInterstitial) Rewarded(admob.plus.cordova.ads.Rewarded)

Example 2 with GenericAd

use of admob.plus.core.GenericAd in project admob-plus by admob-plus.

the class AdMobPlusPlugin method adHide.

@PluginMethod
public void adHide(PluginCall call) {
    final ExecuteContext ctx = new ExecuteContext(call);
    getBridge().executeOnMainThread(() -> {
        GenericAd ad = (GenericAd) ctx.optAdOrError();
        if (ad != null) {
            ad.hide(ctx);
        }
    });
}
Also used : GenericAd(admob.plus.core.GenericAd) PluginMethod(com.getcapacitor.PluginMethod)

Example 3 with GenericAd

use of admob.plus.core.GenericAd in project admob-plus by admob-plus.

the class AdMobPlusPlugin method adLoad.

@PluginMethod
public void adLoad(PluginCall call) {
    final ExecuteContext ctx = new ExecuteContext(call);
    getBridge().executeOnMainThread(() -> {
        GenericAd ad = (GenericAd) ctx.optAdOrError();
        if (ad != null) {
            ad.load(ctx);
        }
    });
}
Also used : GenericAd(admob.plus.core.GenericAd) PluginMethod(com.getcapacitor.PluginMethod)

Example 4 with GenericAd

use of admob.plus.core.GenericAd in project admob-plus by admob-plus.

the class AdMobPlusRNModule method adShow.

@ReactMethod
public void adShow(ReadableMap opts, Promise promise) {
    final ExecuteContext ctx = new ExecuteContext(opts, promise);
    new Handler(Looper.getMainLooper()).post(() -> {
        GenericAd ad = (GenericAd) ctx.optAdOrError();
        if (ad != null) {
            if (ad.isLoaded()) {
                ad.show(ctx);
            } else {
                ctx.reject("ad is not loaded");
            }
        }
    });
}
Also used : Handler(android.os.Handler) GenericAd(admob.plus.core.GenericAd) ReactMethod(com.facebook.react.bridge.ReactMethod)

Example 5 with GenericAd

use of admob.plus.core.GenericAd in project admob-plus by admob-plus.

the class AdMobPlusRNModule method adLoad.

@ReactMethod
public void adLoad(ReadableMap opts, Promise promise) {
    final ExecuteContext ctx = new ExecuteContext(opts, promise);
    new Handler(Looper.getMainLooper()).post(() -> {
        GenericAd ad = (GenericAd) ctx.optAdOrError();
        if (ad != null) {
            ad.load(ctx);
        }
    });
}
Also used : Handler(android.os.Handler) GenericAd(admob.plus.core.GenericAd) ReactMethod(com.facebook.react.bridge.ReactMethod)

Aggregations

GenericAd (admob.plus.core.GenericAd)8 PluginMethod (com.getcapacitor.PluginMethod)4 Handler (android.os.Handler)3 ReactMethod (com.facebook.react.bridge.ReactMethod)3 AppOpen (admob.plus.cordova.ads.AppOpen)1 Banner (admob.plus.cordova.ads.Banner)1 Interstitial (admob.plus.cordova.ads.Interstitial)1 Native (admob.plus.cordova.ads.Native)1 Rewarded (admob.plus.cordova.ads.Rewarded)1 RewardedInterstitial (admob.plus.cordova.ads.RewardedInterstitial)1 HashMap (java.util.HashMap)1 JSONObject (org.json.JSONObject)1