cordova-admob-tomitank 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (114) hide show
  1. package/CHANGELOG.md +0 -0
  2. package/README.md +17 -0
  3. package/esm/admob.d.ts +3 -0
  4. package/esm/admob.js +22 -0
  5. package/esm/admob.js.map +1 -0
  6. package/esm/api.d.ts +61 -0
  7. package/esm/api.js +232 -0
  8. package/esm/api.js.map +1 -0
  9. package/esm/app-open.d.ts +17 -0
  10. package/esm/app-open.js +83 -0
  11. package/esm/app-open.js.map +1 -0
  12. package/esm/banner.d.ts +33 -0
  13. package/esm/banner.js +143 -0
  14. package/esm/banner.js.map +1 -0
  15. package/esm/generated.d.ts +77 -0
  16. package/esm/generated.js +104 -0
  17. package/esm/generated.js.map +1 -0
  18. package/esm/index.d.ts +31 -0
  19. package/esm/index.js +95 -0
  20. package/esm/index.js.map +1 -0
  21. package/esm/interstitial.d.ts +7 -0
  22. package/esm/interstitial.js +35 -0
  23. package/esm/interstitial.js.map +1 -0
  24. package/esm/native.d.ts +19 -0
  25. package/esm/native.js +134 -0
  26. package/esm/native.js.map +1 -0
  27. package/esm/rewarded-interstitial.d.ts +10 -0
  28. package/esm/rewarded-interstitial.js +35 -0
  29. package/esm/rewarded-interstitial.js.map +1 -0
  30. package/esm/rewarded.d.ts +14 -0
  31. package/esm/rewarded.js +35 -0
  32. package/esm/rewarded.js.map +1 -0
  33. package/esm/shared.d.ts +2 -0
  34. package/esm/shared.js +3 -0
  35. package/esm/shared.js.map +1 -0
  36. package/lib/admob.d.ts +3 -0
  37. package/lib/admob.js +50 -0
  38. package/lib/admob.js.map +1 -0
  39. package/lib/api.d.ts +61 -0
  40. package/lib/api.js +240 -0
  41. package/lib/api.js.map +1 -0
  42. package/lib/app-open.d.ts +17 -0
  43. package/lib/app-open.js +85 -0
  44. package/lib/app-open.js.map +1 -0
  45. package/lib/banner.d.ts +33 -0
  46. package/lib/banner.js +145 -0
  47. package/lib/banner.js.map +1 -0
  48. package/lib/generated.d.ts +77 -0
  49. package/lib/generated.js +110 -0
  50. package/lib/generated.js.map +1 -0
  51. package/lib/index.d.ts +31 -0
  52. package/lib/index.js +120 -0
  53. package/lib/index.js.map +1 -0
  54. package/lib/interstitial.d.ts +7 -0
  55. package/lib/interstitial.js +37 -0
  56. package/lib/interstitial.js.map +1 -0
  57. package/lib/native.d.ts +19 -0
  58. package/lib/native.js +136 -0
  59. package/lib/native.js.map +1 -0
  60. package/lib/rewarded-interstitial.d.ts +10 -0
  61. package/lib/rewarded-interstitial.js +37 -0
  62. package/lib/rewarded-interstitial.js.map +1 -0
  63. package/lib/rewarded.d.ts +14 -0
  64. package/lib/rewarded.js +37 -0
  65. package/lib/rewarded.js.map +1 -0
  66. package/lib/shared.d.ts +2 -0
  67. package/lib/shared.js +19 -0
  68. package/lib/shared.js.map +1 -0
  69. package/package.json +73 -0
  70. package/plugin.xml +333 -0
  71. package/scripts/iosNSAppTransportSecurity.js +29 -0
  72. package/scripts/iosNSAppTransportSecurity.ts +33 -0
  73. package/scripts/tsconfig.json +5 -0
  74. package/scripts/util.js +34 -0
  75. package/scripts/util.ts +44 -0
  76. package/src/android/cordova/AdMob.java +256 -0
  77. package/src/android/cordova/ExecuteContext.java +174 -0
  78. package/src/android/cordova/Generated.java +72 -0
  79. package/src/android/cordova/ads/AdBase.java +54 -0
  80. package/src/android/cordova/ads/AppOpen.java +98 -0
  81. package/src/android/cordova/ads/Banner.java +370 -0
  82. package/src/android/cordova/ads/Interstitial.java +101 -0
  83. package/src/android/cordova/ads/Native.java +162 -0
  84. package/src/android/cordova/ads/Rewarded.java +108 -0
  85. package/src/android/cordova/ads/RewardedInterstitial.java +108 -0
  86. package/src/android/core/Ad.java +73 -0
  87. package/src/android/core/Context.java +186 -0
  88. package/src/android/core/GenericAd.java +22 -0
  89. package/src/android/core/Helper.java +134 -0
  90. package/src/browser/AdMobProxy.js +33 -0
  91. package/src/ios/AMBAdBase.swift +72 -0
  92. package/src/ios/AMBAppOpenAd.swift +87 -0
  93. package/src/ios/AMBBanner.swift +294 -0
  94. package/src/ios/AMBContext.swift +166 -0
  95. package/src/ios/AMBCore.swift +232 -0
  96. package/src/ios/AMBGenerated.swift +45 -0
  97. package/src/ios/AMBInterstitial.swift +69 -0
  98. package/src/ios/AMBNativeAd.swift +128 -0
  99. package/src/ios/AMBPlugin.swift +198 -0
  100. package/src/ios/AMBRewarded.swift +72 -0
  101. package/src/ios/AMBRewardedInterstitial.swift +72 -0
  102. package/src/www/admob.ts +26 -0
  103. package/src/www/api.ts +156 -0
  104. package/src/www/app-open.ts +27 -0
  105. package/src/www/banner.ts +102 -0
  106. package/src/www/cordova.d.ts +9 -0
  107. package/src/www/generated.ts +125 -0
  108. package/src/www/index.ts +88 -0
  109. package/src/www/interstitial.ts +17 -0
  110. package/src/www/native.ts +54 -0
  111. package/src/www/rewarded-interstitial.ts +20 -0
  112. package/src/www/rewarded.ts +26 -0
  113. package/src/www/shared.ts +2 -0
  114. package/www/admob.js +675 -0
@@ -0,0 +1,256 @@
1
+ package admob.plus.cordova;
2
+
3
+ import android.app.Activity;
4
+ import android.content.res.Configuration;
5
+ import android.util.Log;
6
+
7
+ import com.google.android.gms.ads.MobileAds;
8
+
9
+ import org.apache.cordova.CallbackContext;
10
+ import org.apache.cordova.CordovaPlugin;
11
+ import org.apache.cordova.PluginResult;
12
+ import org.json.JSONArray;
13
+ import org.json.JSONObject;
14
+
15
+ import java.math.BigDecimal;
16
+ import java.util.ArrayList;
17
+ import java.util.HashMap;
18
+ import java.util.Map;
19
+
20
+ import admob.plus.cordova.Generated.Actions;
21
+ import admob.plus.cordova.ads.AdBase;
22
+ import admob.plus.cordova.ads.AppOpen;
23
+ import admob.plus.cordova.ads.Banner;
24
+ import admob.plus.cordova.ads.Interstitial;
25
+ import admob.plus.cordova.ads.Native;
26
+ import admob.plus.cordova.ads.Rewarded;
27
+ import admob.plus.cordova.ads.RewardedInterstitial;
28
+ import admob.plus.core.GenericAd;
29
+ import admob.plus.core.Helper;
30
+
31
+ import static admob.plus.core.Helper.ads;
32
+
33
+
34
+ public class AdMob extends CordovaPlugin implements Helper.Adapter {
35
+ public static final String NATIVE_VIEW_DEFAULT = Native.VIEW_DEFAULT_KEY;
36
+ private static final String TAG = "AdMobPlus";
37
+ private final ArrayList<PluginResult> eventQueue = new ArrayList<PluginResult>();
38
+ public Helper helper;
39
+ private CallbackContext readyCallbackContext = null;
40
+
41
+ public static void registerNativeAdViewProviders(Map<String, Native.ViewProvider> providers) {
42
+ Native.providers.putAll(providers);
43
+ }
44
+
45
+ @Override
46
+ protected void pluginInitialize() {
47
+ super.pluginInitialize();
48
+ Log.i(TAG, "Initialize plugin");
49
+
50
+ helper = new Helper(this);
51
+ ExecuteContext.plugin = this;
52
+ }
53
+
54
+ @Override
55
+ public boolean execute(String actionKey, JSONArray args, CallbackContext callbackContext) {
56
+ Log.d(TAG, String.format("Execute %s", actionKey));
57
+ ExecuteContext ctx = new ExecuteContext(actionKey, args, callbackContext);
58
+
59
+ switch (actionKey) {
60
+ case Actions.READY:
61
+ return executeReady(callbackContext);
62
+ case Actions.START:
63
+ MobileAds.initialize(cordova.getActivity(), status -> {
64
+ helper.configForTestLab();
65
+ callbackContext.success(new JSONObject(new HashMap<String, Object>() {{
66
+ put("version", MobileAds.getVersion());
67
+ }}));
68
+ });
69
+ break;
70
+ case Actions.CONFIGURE:
71
+ case Actions.CONFIG_REQUEST:
72
+ ctx.configure(helper);
73
+ break;
74
+ case Actions.AD_CREATE:
75
+ String adClass = ctx.optString("cls");
76
+ if (adClass == null) {
77
+ ctx.reject("ad cls is missing");
78
+ } else {
79
+ GenericAd ad = null;
80
+ switch (adClass) {
81
+ case "AppOpenAd":
82
+ ad = new AppOpen(ctx);
83
+ break;
84
+ case "BannerAd":
85
+ ad = new Banner(ctx);
86
+ break;
87
+ case "InterstitialAd":
88
+ ad = new Interstitial(ctx);
89
+ break;
90
+ case "NativeAd":
91
+ ad = new Native(ctx);
92
+ break;
93
+ case "RewardedAd":
94
+ ad = new Rewarded(ctx);
95
+ break;
96
+ case "RewardedInterstitialAd":
97
+ ad = new RewardedInterstitial(ctx);
98
+ break;
99
+ }
100
+ if (ad != null) {
101
+ ctx.resolve();
102
+ } else {
103
+ ctx.reject("ad cls is not supported");
104
+ }
105
+ }
106
+ break;
107
+ case Actions.AD_IS_LOADED:
108
+ return executeAdIsLoaded_(ctx);
109
+ case Actions.AD_LOAD:
110
+ return executeAdLoad(ctx);
111
+ case Actions.AD_SHOW:
112
+ return executeAdShow(ctx);
113
+ case Actions.AD_HIDE:
114
+ return executeAdHide(ctx);
115
+ case Actions.SET_APP_MUTED: {
116
+ boolean value = args.optBoolean(0);
117
+ MobileAds.setAppMuted(value);
118
+ callbackContext.success();
119
+ break;
120
+ }
121
+ case Actions.SET_APP_VOLUME: {
122
+ float value = BigDecimal.valueOf(args.optDouble(0)).floatValue();
123
+ MobileAds.setAppVolume(value);
124
+ callbackContext.success();
125
+ break;
126
+ }
127
+ default:
128
+ return false;
129
+ }
130
+
131
+ return true;
132
+ }
133
+
134
+ private boolean executeReady(CallbackContext callbackContext) {
135
+ if (readyCallbackContext == null) {
136
+ for (PluginResult result : eventQueue) {
137
+ callbackContext.sendPluginResult(result);
138
+ }
139
+ eventQueue.clear();
140
+ } else {
141
+ Log.e(TAG, "Ready action should only be called once.");
142
+ }
143
+ readyCallbackContext = callbackContext;
144
+ emit(Generated.Events.READY, new HashMap<String, Object>() {{
145
+ put("isRunningInTestLab", helper.isRunningInTestLab());
146
+ }});
147
+ return true;
148
+ }
149
+
150
+ private boolean executeAdIsLoaded_(ExecuteContext ctx) {
151
+ cordova.getActivity().runOnUiThread(() -> {
152
+ GenericAd ad = (GenericAd) ctx.optAdOrError();
153
+ if (ad != null) {
154
+ ctx.resolve(ad.isLoaded());
155
+ }
156
+ });
157
+ return true;
158
+ }
159
+
160
+ private boolean executeAdLoad(ExecuteContext ctx) {
161
+ cordova.getActivity().runOnUiThread(() -> {
162
+ GenericAd ad = (GenericAd) ctx.optAdOrError();
163
+ if (ad != null) {
164
+ ad.load(ctx);
165
+ }
166
+ });
167
+ return true;
168
+ }
169
+
170
+ private boolean executeAdShow(ExecuteContext ctx) {
171
+ cordova.getActivity().runOnUiThread(() -> {
172
+ GenericAd ad = (GenericAd) ctx.optAdOrError();
173
+ if (ad != null) {
174
+ if (ad.isLoaded()) {
175
+ ad.show(ctx);
176
+ } else {
177
+ ctx.resolve(false);
178
+ }
179
+ }
180
+ });
181
+ return true;
182
+ }
183
+
184
+ private boolean executeAdHide(ExecuteContext ctx) {
185
+ cordova.getActivity().runOnUiThread(() -> {
186
+ GenericAd ad = (GenericAd) ctx.optAdOrError();
187
+ if (ad != null) {
188
+ ad.hide(ctx);
189
+ }
190
+ });
191
+ return true;
192
+ }
193
+
194
+ @Override
195
+ public void onConfigurationChanged(Configuration newConfig) {
196
+ super.onConfigurationChanged(newConfig);
197
+
198
+ for (int i = 0; i < ads.size(); i++) {
199
+ AdBase ad = (AdBase) ads.valueAt(i);
200
+ ad.onConfigurationChanged(newConfig);
201
+ }
202
+ }
203
+
204
+ @Override
205
+ public void onPause(boolean multitasking) {
206
+ for (int i = 0; i < ads.size(); i++) {
207
+ AdBase ad = (AdBase) ads.valueAt(i);
208
+ ad.onPause(multitasking);
209
+ }
210
+ super.onPause(multitasking);
211
+ }
212
+
213
+ @Override
214
+ public void onResume(boolean multitasking) {
215
+ super.onResume(multitasking);
216
+ for (int i = 0; i < ads.size(); i++) {
217
+ AdBase ad = (AdBase) ads.valueAt(i);
218
+ ad.onResume(multitasking);
219
+ }
220
+ }
221
+
222
+ @Override
223
+ public void onDestroy() {
224
+ readyCallbackContext = null;
225
+
226
+ for (int i = 0; i < ads.size(); i++) {
227
+ AdBase ad = (AdBase) ads.valueAt(i);
228
+ ad.onDestroy();
229
+ }
230
+
231
+ Banner.destroyParentView();
232
+
233
+ super.onDestroy();
234
+ }
235
+
236
+ @Override
237
+ public Activity getActivity() {
238
+ return cordova.getActivity();
239
+ }
240
+
241
+ @Override
242
+ public void emit(String eventName, Map<String, Object> data) {
243
+ JSONObject event = new JSONObject(new HashMap<String, Object>() {{
244
+ put("type", eventName);
245
+ put("data", data);
246
+ }});
247
+
248
+ PluginResult result = new PluginResult(PluginResult.Status.OK, event);
249
+ result.setKeepCallback(true);
250
+ if (readyCallbackContext == null) {
251
+ eventQueue.add(result);
252
+ } else {
253
+ readyCallbackContext.sendPluginResult(result);
254
+ }
255
+ }
256
+ }
@@ -0,0 +1,174 @@
1
+ package admob.plus.cordova;
2
+
3
+ import android.app.Activity;
4
+ import android.content.res.Resources;
5
+
6
+ import androidx.annotation.NonNull;
7
+ import androidx.annotation.Nullable;
8
+
9
+ import com.google.android.gms.ads.AdSize;
10
+
11
+ import org.apache.cordova.CallbackContext;
12
+ import org.apache.cordova.PluginResult;
13
+ import org.json.JSONArray;
14
+ import org.json.JSONObject;
15
+
16
+ import java.lang.reflect.InvocationTargetException;
17
+ import java.util.List;
18
+
19
+ import admob.plus.cordova.ads.Banner.AdSizeType;
20
+ import admob.plus.core.Ad;
21
+ import admob.plus.core.Context;
22
+ import admob.plus.core.Helper;
23
+
24
+ import static admob.plus.core.Helper.jsonArray2stringList;
25
+
26
+ public class ExecuteContext implements Context {
27
+ public static AdMob plugin;
28
+ public final String actionKey;
29
+ public final JSONArray args;
30
+ public final CallbackContext callbackContext;
31
+ public final JSONObject opts;
32
+
33
+ ExecuteContext(String actionKey, JSONArray args, CallbackContext callbackContext) {
34
+ this.actionKey = actionKey;
35
+ this.args = args;
36
+ this.callbackContext = callbackContext;
37
+ this.opts = args.optJSONObject(0);
38
+ }
39
+
40
+ @Override
41
+ public boolean has(String name) {
42
+ return opts.has(name);
43
+ }
44
+
45
+ @Nullable
46
+ @Override
47
+ public Object opt(@Nullable String name) {
48
+ return opts.opt(name);
49
+ }
50
+
51
+ @Nullable
52
+ @Override
53
+ public Boolean optBoolean(@Nullable String name) {
54
+ if (!opts.has(name)) return null;
55
+ return opts.optBoolean(name);
56
+ }
57
+
58
+ @Nullable
59
+ @Override
60
+ public Double optDouble(@Nullable String name) {
61
+ if (!opts.has(name)) return null;
62
+ return opts.optDouble(name);
63
+ }
64
+
65
+ @Nullable
66
+ @Override
67
+ public Integer optInt(@Nullable String name) {
68
+ if (!opts.has(name)) return null;
69
+ return opts.optInt(name);
70
+ }
71
+
72
+ @Nullable
73
+ @Override
74
+ public String optString(String name) {
75
+ if (!opts.has(name)) return null;
76
+ return opts.optString(name);
77
+ }
78
+
79
+ @NonNull
80
+ @Override
81
+ public List<String> optStringList(@Nullable String name) {
82
+ return jsonArray2stringList(opts.optJSONArray(name));
83
+ }
84
+
85
+ @Nullable
86
+ @Override
87
+ public JSONObject optObject(@Nullable String name) {
88
+ return opts.optJSONObject(name);
89
+ }
90
+
91
+ @Override
92
+ public void resolve() {
93
+ callbackContext.success();
94
+ }
95
+
96
+ @Override
97
+ public void resolve(boolean data) {
98
+ PluginResult result = new PluginResult(PluginResult.Status.OK, data);
99
+ sendResult(result);
100
+ }
101
+
102
+ @Override
103
+ public void reject(String msg) {
104
+ callbackContext.error(msg);
105
+ }
106
+
107
+ @Nullable
108
+ public Integer optOffset() {
109
+ if (opts.has("offset")) {
110
+ return opts.optInt("offset");
111
+ }
112
+ return null;
113
+ }
114
+
115
+ @Nullable
116
+ public <T extends Ad> T optAdOrCreate(Class<T> type) {
117
+ Ad adOrNull = optAd();
118
+ if (adOrNull != null) {
119
+ try {
120
+ return type.cast(adOrNull);
121
+ } catch (ClassCastException e) {
122
+ this.reject("Wrong ad type");
123
+ return null;
124
+ }
125
+ }
126
+ try {
127
+ return type.getDeclaredConstructor(ExecuteContext.class).newInstance(this);
128
+ } catch (IllegalAccessException | InstantiationException | InvocationTargetException | NoSuchMethodException e) {
129
+ e.printStackTrace();
130
+ this.reject("Fail to create ad");
131
+ }
132
+ return null;
133
+ }
134
+
135
+ public AdSize optAdSize() {
136
+ final String name = "size";
137
+ if (!opts.has(name)) {
138
+ return AdSize.SMART_BANNER;
139
+ }
140
+ JSONObject adSizeObj = opts.optJSONObject(name);
141
+ AdSize adSize = AdSizeType.getAdSize(opts.optInt(name));
142
+ if (adSizeObj == null) {
143
+ if (adSize != null) {
144
+ return adSize;
145
+ }
146
+ return AdSize.SMART_BANNER;
147
+ }
148
+ String adaptive = adSizeObj.optString("adaptive");
149
+ int w = Helper.pxToDp(adSizeObj.has("width") ? adSizeObj.optInt("width") : Resources.getSystem().getDisplayMetrics().widthPixels);
150
+ if ("inline".equals(adaptive)) {
151
+ if (adSizeObj.has("maxHeight")) {
152
+ return AdSize.getInlineAdaptiveBannerAdSize(w, Helper.pxToDp(adSizeObj.optInt("maxHeight")));
153
+ }
154
+ } else {
155
+ switch (adSizeObj.optString("orientation")) {
156
+ case "portrait":
157
+ return AdSize.getPortraitAnchoredAdaptiveBannerAdSize(getActivity(), w);
158
+ case "landscape":
159
+ return AdSize.getLandscapeAnchoredAdaptiveBannerAdSize(getActivity(), w);
160
+ default:
161
+ return AdSize.getCurrentOrientationAnchoredAdaptiveBannerAdSize(getActivity(), w);
162
+ }
163
+ }
164
+ return new AdSize(w, Helper.pxToDp(adSizeObj.optInt("height")));
165
+ }
166
+
167
+ public Activity getActivity() {
168
+ return plugin.cordova.getActivity();
169
+ }
170
+
171
+ public void sendResult(PluginResult result) {
172
+ callbackContext.sendPluginResult(result);
173
+ }
174
+ }
@@ -0,0 +1,72 @@
1
+ // THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
2
+ package admob.plus.cordova;
3
+
4
+ public final class Generated {
5
+ public static final class Actions {
6
+ public static final String AD_CREATE = "adCreate";
7
+ public static final String AD_HIDE = "adHide";
8
+ public static final String AD_IS_LOADED = "adIsLoaded";
9
+ public static final String AD_LOAD = "adLoad";
10
+ public static final String AD_SHOW = "adShow";
11
+ public static final String BANNER_CONFIG = "bannerConfig";
12
+ public static final String BANNER_HIDE = "bannerHide";
13
+ public static final String BANNER_LOAD = "bannerLoad";
14
+ public static final String BANNER_SHOW = "bannerShow";
15
+ public static final String CONFIGURE = "configure";
16
+ public static final String CONFIG_REQUEST = "configRequest";
17
+ public static final String INTERSTITIAL_IS_LOADED = "interstitialIsLoaded";
18
+ public static final String INTERSTITIAL_LOAD = "interstitialLoad";
19
+ public static final String INTERSTITIAL_SHOW = "interstitialShow";
20
+ public static final String READY = "ready";
21
+ public static final String REQUEST_TRACKING_AUTHORIZATION = "requestTrackingAuthorization";
22
+ public static final String REWARDED_INTERSTITIAL_IS_LOADED = "rewardedInterstitialIsLoaded";
23
+ public static final String REWARDED_INTERSTITIAL_LOAD = "rewardedInterstitialLoad";
24
+ public static final String REWARDED_INTERSTITIAL_SHOW = "rewardedInterstitialShow";
25
+ public static final String REWARDED_IS_LOADED = "rewardedIsLoaded";
26
+ public static final String REWARDED_LOAD = "rewardedLoad";
27
+ public static final String REWARDED_SHOW = "rewardedShow";
28
+ public static final String SET_APP_MUTED = "setAppMuted";
29
+ public static final String SET_APP_VOLUME = "setAppVolume";
30
+ public static final String START = "start";
31
+ }
32
+
33
+ public static final class Events {
34
+ public static final String AD_CLICK = "admob.ad.click";
35
+ public static final String AD_DISMISS = "admob.ad.dismiss";
36
+ public static final String AD_IMPRESSION = "admob.ad.impression";
37
+ public static final String AD_LOAD = "admob.ad.load";
38
+ public static final String AD_LOAD_FAIL = "admob.ad.loadfail";
39
+ public static final String AD_REWARD = "admob.ad.reward";
40
+ public static final String AD_SHOW = "admob.ad.show";
41
+ public static final String AD_SHOW_FAIL = "admob.ad.showfail";
42
+ public static final String BANNER_CLICK = "admob.banner.click";
43
+ public static final String BANNER_CLOSE = "admob.banner.close";
44
+ public static final String BANNER_IMPRESSION = "admob.banner.impression";
45
+ public static final String BANNER_LOAD = "admob.banner.load";
46
+ public static final String BANNER_LOAD_FAIL = "admob.banner.loadfail";
47
+ public static final String BANNER_OPEN = "admob.banner.open";
48
+ public static final String BANNER_SIZE = "admob.banner.size";
49
+ public static final String BANNER_SIZE_CHANGE = "admob.banner.sizechange";
50
+ public static final String INTERSTITIAL_DISMISS = "admob.interstitial.dismiss";
51
+ public static final String INTERSTITIAL_IMPRESSION = "admob.interstitial.impression";
52
+ public static final String INTERSTITIAL_LOAD = "admob.interstitial.load";
53
+ public static final String INTERSTITIAL_LOAD_FAIL = "admob.interstitial.loadfail";
54
+ public static final String INTERSTITIAL_SHOW = "admob.interstitial.show";
55
+ public static final String INTERSTITIAL_SHOW_FAIL = "admob.interstitial.showfail";
56
+ public static final String READY = "admob.ready";
57
+ public static final String REWARDED_DISMISS = "admob.rewarded.dismiss";
58
+ public static final String REWARDED_IMPRESSION = "admob.rewarded.impression";
59
+ public static final String REWARDED_INTERSTITIAL_DISMISS = "admob.rewardedi.dismiss";
60
+ public static final String REWARDED_INTERSTITIAL_IMPRESSION = "admob.rewardedi.impression";
61
+ public static final String REWARDED_INTERSTITIAL_LOAD = "admob.rewardedi.load";
62
+ public static final String REWARDED_INTERSTITIAL_LOAD_FAIL = "admob.rewardedi.loadfail";
63
+ public static final String REWARDED_INTERSTITIAL_REWARD = "admob.rewardedi.reward";
64
+ public static final String REWARDED_INTERSTITIAL_SHOW = "admob.rewardedi.show";
65
+ public static final String REWARDED_INTERSTITIAL_SHOW_FAIL = "admob.rewardedi.showfail";
66
+ public static final String REWARDED_LOAD = "admob.rewarded.load";
67
+ public static final String REWARDED_LOAD_FAIL = "admob.rewarded.loadfail";
68
+ public static final String REWARDED_REWARD = "admob.rewarded.reward";
69
+ public static final String REWARDED_SHOW = "admob.rewarded.show";
70
+ public static final String REWARDED_SHOW_FAIL = "admob.rewarded.showfail";
71
+ }
72
+ }
@@ -0,0 +1,54 @@
1
+ package admob.plus.cordova.ads;
2
+
3
+ import android.app.Activity;
4
+ import android.content.res.Configuration;
5
+ import android.view.View;
6
+ import android.view.ViewGroup;
7
+
8
+ import com.google.android.gms.ads.AdRequest;
9
+
10
+ import org.apache.cordova.CordovaWebView;
11
+
12
+ import admob.plus.cordova.ExecuteContext;
13
+ import admob.plus.core.Ad;
14
+ import admob.plus.core.GenericAd;
15
+ import admob.plus.core.Helper;
16
+
17
+ public abstract class AdBase extends Ad implements GenericAd {
18
+ protected AdRequest adRequest;
19
+
20
+ public AdBase(ExecuteContext ctx) {
21
+ super(ctx);
22
+ adRequest = ctx.optAdRequest();
23
+ }
24
+
25
+ public void onConfigurationChanged(Configuration newConfig) {
26
+ }
27
+
28
+ public void onPause(boolean multitasking) {
29
+ }
30
+
31
+ public void onResume(boolean multitasking) {
32
+ }
33
+
34
+ public void onDestroy() {
35
+ super.destroy();
36
+ }
37
+
38
+ protected CordovaWebView getCordovaWebView() {
39
+ return ExecuteContext.plugin.webView;
40
+ }
41
+
42
+ protected View getWebView() {
43
+ return getCordovaWebView().getView();
44
+ }
45
+
46
+ protected ViewGroup getWebViewParent() {
47
+ return (ViewGroup) getWebView().getParent();
48
+ }
49
+
50
+ @Override
51
+ protected Helper.Adapter getAdapter() {
52
+ return ExecuteContext.plugin;
53
+ }
54
+ }
@@ -0,0 +1,98 @@
1
+ package admob.plus.cordova.ads;
2
+
3
+ import com.google.android.gms.ads.AdError;
4
+ import com.google.android.gms.ads.AdRequest;
5
+ import com.google.android.gms.ads.FullScreenContentCallback;
6
+ import com.google.android.gms.ads.LoadAdError;
7
+ import com.google.android.gms.ads.appopen.AppOpenAd;
8
+
9
+ import admob.plus.cordova.ExecuteContext;
10
+ import admob.plus.cordova.Generated.Events;
11
+ import admob.plus.core.Context;
12
+
13
+ public class AppOpen extends AdBase {
14
+ private final AdRequest mAdRequest;
15
+ private final int mOrientation;
16
+ private AppOpenAd mAd = null;
17
+
18
+ public AppOpen(ExecuteContext ctx) {
19
+ super(ctx);
20
+
21
+ mAdRequest = ctx.optAdRequest();
22
+
23
+ Integer o = ctx.optInt("orientation");
24
+ mOrientation = o == null || o == 1 || o == 2 ? AppOpenAd.APP_OPEN_AD_ORIENTATION_PORTRAIT : AppOpenAd.APP_OPEN_AD_ORIENTATION_LANDSCAPE;
25
+ }
26
+
27
+ @Override
28
+ public void onDestroy() {
29
+ clear();
30
+
31
+ super.onDestroy();
32
+ }
33
+
34
+ @Override
35
+ public void load(Context ctx) {
36
+ clear();
37
+
38
+ AppOpenAd.load(getActivity(),
39
+ adUnitId,
40
+ mAdRequest,
41
+ mOrientation, new AppOpenAd.AppOpenAdLoadCallback() {
42
+ @Override
43
+ public void onAdLoaded(AppOpenAd ad) {
44
+ mAd = ad;
45
+ ad.setFullScreenContentCallback(new FullScreenContentCallback() {
46
+ @Override
47
+ public void onAdDismissedFullScreenContent() {
48
+ clear();
49
+ emit(Events.AD_DISMISS);
50
+ }
51
+
52
+ @Override
53
+ public void onAdFailedToShowFullScreenContent(AdError adError) {
54
+ clear();
55
+ emit(Events.AD_SHOW_FAIL, adError);
56
+ }
57
+
58
+ @Override
59
+ public void onAdShowedFullScreenContent() {
60
+ emit(Events.AD_SHOW);
61
+ }
62
+
63
+ @Override
64
+ public void onAdImpression() {
65
+ emit(Events.AD_IMPRESSION);
66
+ }
67
+ });
68
+
69
+ emit(Events.AD_LOAD);
70
+ ctx.resolve();
71
+ }
72
+
73
+ @Override
74
+ public void onAdFailedToLoad(LoadAdError loadAdError) {
75
+ clear();
76
+ emit(Events.AD_LOAD_FAIL, loadAdError);
77
+ ctx.reject(loadAdError.toString());
78
+ }
79
+ });
80
+ }
81
+
82
+ @Override
83
+ public boolean isLoaded() {
84
+ return mAd != null;
85
+ }
86
+
87
+ @Override
88
+ public void show(Context ctx) {
89
+ mAd.show(getActivity());
90
+ ctx.resolve(true);
91
+ }
92
+
93
+ private void clear() {
94
+ if (mAd != null) {
95
+ mAd = null;
96
+ }
97
+ }
98
+ }