emi-indo-cordova-plugin-admob 2.0.5 → 2.0.7
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.
- package/README.md +199 -53
- package/example/capacitor.config.json +1 -1
- package/example/config.xml +7 -0
- package/example/package.json +1 -1
- package/example/www/css/index.css +59 -109
- package/example/www/index.html +38 -39
- package/example/www/js/bannerAd.js +7 -62
- package/example/www/js/deviceready.js +6 -6
- package/example/www/js/interstitialAd.js +0 -2
- package/example/www/js/optionalFirebaseAnalytics.js +0 -2
- package/example/www/js/rewardedAd.js +0 -2
- package/package.json +1 -1
- package/plugin.xml +7 -9
- package/src/android/emiAdmobPlugin.kt +438 -256
- package/src/ios/emiAdmobPlugin.m +280 -184
- package/www/emiAdmobPlugin.js +3 -0
@@ -15,6 +15,7 @@ import android.view.Gravity
|
|
15
15
|
import android.view.View
|
16
16
|
import android.view.ViewGroup
|
17
17
|
import android.view.WindowInsets
|
18
|
+
import android.view.WindowManager
|
18
19
|
import android.webkit.WebView
|
19
20
|
import android.widget.FrameLayout
|
20
21
|
import androidx.preference.PreferenceManager
|
@@ -51,7 +52,6 @@ import kotlinx.coroutines.CoroutineScope
|
|
51
52
|
import kotlinx.coroutines.Dispatchers
|
52
53
|
import kotlinx.coroutines.launch
|
53
54
|
import org.apache.cordova.CallbackContext
|
54
|
-
import org.apache.cordova.CordovaInterface
|
55
55
|
import org.apache.cordova.CordovaPlugin
|
56
56
|
import org.apache.cordova.CordovaWebView
|
57
57
|
import org.json.JSONArray
|
@@ -96,20 +96,20 @@ class emiAdmobPlugin : CordovaPlugin() {
|
|
96
96
|
private var isStatusBarShow: Boolean = true
|
97
97
|
|
98
98
|
var adType = ""
|
99
|
+
// var bannerHeightDps: Int = 50
|
99
100
|
|
100
101
|
var isBannerLoad: Boolean = false
|
101
102
|
var isBannerShow: Boolean = false
|
102
103
|
|
103
104
|
var isBannerShows: Boolean = true
|
104
105
|
private var bannerAutoShow = false
|
105
|
-
|
106
|
+
// private var isAutoResize: Boolean = false
|
106
107
|
|
107
108
|
|
108
109
|
var appOpenAutoShow: Boolean = false
|
109
110
|
var intAutoShow: Boolean = false
|
110
111
|
var rewardedAutoShow: Boolean = false
|
111
112
|
var rIntAutoShow: Boolean = false
|
112
|
-
private var isCollapsible: Boolean = false
|
113
113
|
var lock: Boolean = true
|
114
114
|
private var setDebugGeography: Boolean = false
|
115
115
|
|
@@ -119,7 +119,7 @@ class emiAdmobPlugin : CordovaPlugin() {
|
|
119
119
|
|
120
120
|
private var mPreferences: SharedPreferences? = null
|
121
121
|
var mBundleExtra: Bundle? = null
|
122
|
-
private var collapsiblePos: String? =
|
122
|
+
private var collapsiblePos: String? = ""
|
123
123
|
|
124
124
|
// only isUsingAdManagerRequest = true
|
125
125
|
private var customTargetingEnabled: Boolean = false
|
@@ -151,84 +151,46 @@ class emiAdmobPlugin : CordovaPlugin() {
|
|
151
151
|
private var mContext: Context? = null
|
152
152
|
|
153
153
|
|
154
|
-
|
155
|
-
|
154
|
+
private var isFullScreen: Boolean = false
|
155
|
+
private var loadBannerAdNew: Boolean = false
|
156
|
+
private var bannerOverlapping: Boolean = false
|
157
|
+
|
158
|
+
override fun pluginInitialize() {
|
159
|
+
super.pluginInitialize()
|
156
160
|
|
157
161
|
cWebView = webView
|
158
162
|
mActivity = cordova.activity
|
159
163
|
|
160
164
|
if (mActivity != null) {
|
161
|
-
|
162
165
|
mContext = mActivity?.applicationContext
|
163
|
-
|
164
166
|
mPreferences = mContext?.let { PreferenceManager.getDefaultSharedPreferences(it) }
|
165
|
-
|
166
167
|
} else {
|
167
168
|
Log.e("PluginCordova", "Activity is null during initialization")
|
168
169
|
}
|
169
170
|
}
|
170
171
|
|
171
172
|
|
172
|
-
|
173
|
-
|
174
173
|
override fun onConfigurationChanged(newConfig: Configuration) {
|
175
174
|
super.onConfigurationChanged(newConfig)
|
176
175
|
val orientation = newConfig.orientation
|
177
176
|
if (orientation != isOrientation) {
|
178
177
|
cWebView?.loadUrl("javascript:cordova.fireDocumentEvent('on.screen.rotated');")
|
179
178
|
isOrientation = orientation
|
180
|
-
if (this.isAutoResize) {
|
181
|
-
if(mActivity != null) {
|
182
|
-
mActivity?.runOnUiThread {
|
183
|
-
try {
|
184
|
-
bannerOverlappingToZero()
|
185
|
-
if (bannerViewLayout != null && bannerView != null) {
|
186
|
-
val parentView = bannerViewLayout?.parent as ViewGroup
|
187
|
-
parentView.removeView(bannerViewLayout)
|
188
|
-
bannerViewLayout = FrameLayout(mActivity!!)
|
189
|
-
val params = FrameLayout.LayoutParams(
|
190
|
-
FrameLayout.LayoutParams.MATCH_PARENT,
|
191
|
-
FrameLayout.LayoutParams.WRAP_CONTENT
|
192
|
-
)
|
193
|
-
val decorView = mActivity?.window?.decorView as ViewGroup
|
194
|
-
decorView.addView(bannerViewLayout, params)
|
195
|
-
bannerView = AdView(mActivity!!)
|
196
|
-
setBannerPosition(this.isPosition)
|
197
|
-
setBannerSize(this.isSize)
|
198
|
-
bannerView?.adUnitId = bannerAdUnitId!!
|
199
|
-
bannerView?.adListener = bannerAdListener
|
200
|
-
bannerView?.loadAd(buildAdRequest())
|
201
|
-
bannerViewLayout?.addView(bannerView)
|
202
|
-
bannerViewLayout?.bringToFront()
|
203
|
-
bannerViewLayout?.requestFocus();
|
204
|
-
bannerOverlappingToZero()
|
205
|
-
}
|
206
|
-
} catch (e: Exception) {
|
207
|
-
PUBLIC_CALLBACKS?.error("Error adjusting banner size: " + e.message)
|
208
|
-
}
|
209
|
-
}
|
210
|
-
}
|
211
|
-
}
|
212
|
-
|
213
179
|
when (orientation) {
|
214
180
|
Configuration.ORIENTATION_PORTRAIT -> {
|
215
|
-
if (isOverlapping) {
|
216
|
-
bannerOverlapping()
|
217
|
-
}
|
218
181
|
cWebView?.loadUrl("javascript:cordova.fireDocumentEvent('on.orientation.portrait');")
|
219
182
|
}
|
220
183
|
Configuration.ORIENTATION_LANDSCAPE -> {
|
221
|
-
if (isOverlapping) {
|
222
|
-
bannerOverlapping()
|
223
|
-
}
|
224
184
|
cWebView?.loadUrl("javascript:cordova.fireDocumentEvent('on.orientation.landscape');")
|
225
185
|
}
|
226
186
|
Configuration.ORIENTATION_UNDEFINED -> {
|
227
187
|
cWebView?.loadUrl("javascript:cordova.fireDocumentEvent('on.orientation.undefined');")
|
228
188
|
}
|
229
|
-
|
230
|
-
|
189
|
+
else -> {
|
190
|
+
cWebView?.loadUrl("javascript:cordova.fireDocumentEvent('on.orientation.square');")
|
191
|
+
}
|
231
192
|
}
|
193
|
+
|
232
194
|
}
|
233
195
|
}
|
234
196
|
|
@@ -245,7 +207,7 @@ class emiAdmobPlugin : CordovaPlugin() {
|
|
245
207
|
if (action == "initialize") {
|
246
208
|
val options = args.getJSONObject(0)
|
247
209
|
if (mActivity != null) {
|
248
|
-
mActivity
|
210
|
+
mActivity?.runOnUiThread {
|
249
211
|
val setAdRequest = options.optBoolean("isUsingAdManagerRequest")
|
250
212
|
val responseInfo = options.optBoolean("isResponseInfo")
|
251
213
|
val setDebugGeography = options.optBoolean("isConsentDebug")
|
@@ -284,21 +246,16 @@ class emiAdmobPlugin : CordovaPlugin() {
|
|
284
246
|
params,
|
285
247
|
{
|
286
248
|
cWebView!!.loadUrl("javascript:cordova.fireDocumentEvent('on.consent.info.update');")
|
287
|
-
when (consentInformation
|
288
|
-
ConsentInformation.ConsentStatus.NOT_REQUIRED -> cWebView
|
289
|
-
"javascript:cordova.fireDocumentEvent('on.consent.status.not_required');"
|
290
|
-
)
|
249
|
+
when (consentInformation?.getConsentStatus()) {
|
250
|
+
ConsentInformation.ConsentStatus.NOT_REQUIRED -> cWebView?.loadUrl("javascript:cordova.fireDocumentEvent('on.consent.status.not_required');")
|
291
251
|
|
292
|
-
ConsentInformation.ConsentStatus.OBTAINED -> cWebView
|
293
|
-
"javascript:cordova.fireDocumentEvent('on.consent.status.obtained');"
|
294
|
-
)
|
252
|
+
ConsentInformation.ConsentStatus.OBTAINED -> cWebView?.loadUrl( "javascript:cordova.fireDocumentEvent('on.consent.status.obtained');")
|
295
253
|
|
296
|
-
ConsentInformation.ConsentStatus.REQUIRED -> {
|
297
|
-
|
298
|
-
cWebView!!.loadUrl("javascript:cordova.fireDocumentEvent('on.consent.status.required');")
|
254
|
+
ConsentInformation.ConsentStatus.REQUIRED -> { handleConsentForm()
|
255
|
+
cWebView?.loadUrl("javascript:cordova.fireDocumentEvent('on.consent.status.required');")
|
299
256
|
}
|
300
257
|
|
301
|
-
ConsentInformation.ConsentStatus.UNKNOWN -> cWebView
|
258
|
+
ConsentInformation.ConsentStatus.UNKNOWN -> cWebView?.loadUrl("javascript:cordova.fireDocumentEvent('on.consent.status.unknown');")
|
302
259
|
}
|
303
260
|
},
|
304
261
|
{ formError: FormError ->
|
@@ -313,8 +270,8 @@ class emiAdmobPlugin : CordovaPlugin() {
|
|
313
270
|
}
|
314
271
|
}
|
315
272
|
}
|
316
|
-
|
317
273
|
return true
|
274
|
+
|
318
275
|
} else if (action == "targeting") {
|
319
276
|
val options = args.getJSONObject(0)
|
320
277
|
if (mActivity != null) {
|
@@ -329,11 +286,12 @@ class emiAdmobPlugin : CordovaPlugin() {
|
|
329
286
|
targeting(childDirectedTreatment, underAgeOfConsent, contentRating)
|
330
287
|
callbackContext.success();
|
331
288
|
} catch (e: Exception) {
|
332
|
-
callbackContext.error("Error: " + e.message)
|
289
|
+
callbackContext.error("targeting Error: " + e.message)
|
333
290
|
}
|
334
291
|
}
|
335
292
|
}
|
336
293
|
return true
|
294
|
+
|
337
295
|
} else if (action == "targetingAdRequest") {
|
338
296
|
val options = args.getJSONObject(0)
|
339
297
|
if (mActivity != null) {
|
@@ -358,20 +316,15 @@ class emiAdmobPlugin : CordovaPlugin() {
|
|
358
316
|
this.cExclusionsValue = categoryExclusions
|
359
317
|
this.ppIdVl = ppId
|
360
318
|
this.cURLVl = ctURL
|
361
|
-
targetingAdRequest(
|
362
|
-
customTargeting,
|
363
|
-
categoryExclusions,
|
364
|
-
ppId,
|
365
|
-
ctURL,
|
366
|
-
brandSafetyArr
|
367
|
-
)
|
319
|
+
targetingAdRequest( customTargeting, categoryExclusions, ppId, ctURL, brandSafetyArr)
|
368
320
|
callbackContext.success()
|
369
321
|
} catch (e: Exception) {
|
370
|
-
callbackContext.error(e.
|
322
|
+
callbackContext.error("targetingAdRequest Error: " + e.message)
|
371
323
|
}
|
372
324
|
}
|
373
325
|
}
|
374
326
|
return true
|
327
|
+
|
375
328
|
} else if (action == "setPersonalizationState") {
|
376
329
|
val options = args.getJSONObject(0)
|
377
330
|
if (mActivity != null) {
|
@@ -381,11 +334,12 @@ class emiAdmobPlugin : CordovaPlugin() {
|
|
381
334
|
setPersonalizationState(setPPT)
|
382
335
|
callbackContext.success()
|
383
336
|
} catch (e: Exception) {
|
384
|
-
callbackContext.error(e.
|
337
|
+
callbackContext.error("setPersonalizationState Error: " + e.message)
|
385
338
|
}
|
386
339
|
}
|
387
340
|
}
|
388
341
|
return true
|
342
|
+
|
389
343
|
} else if (action == "setPPS") {
|
390
344
|
val options = args.getJSONObject(0)
|
391
345
|
if (mActivity != null) {
|
@@ -399,11 +353,12 @@ class emiAdmobPlugin : CordovaPlugin() {
|
|
399
353
|
setPublisherProvidedSignals(ppsArrValue)
|
400
354
|
callbackContext.success()
|
401
355
|
} catch (e: Exception) {
|
402
|
-
callbackContext.error(e.
|
356
|
+
callbackContext.error("setPPS Error: " + e.message)
|
403
357
|
}
|
404
358
|
}
|
405
359
|
}
|
406
360
|
return true
|
361
|
+
|
407
362
|
} else if (action == "globalSettings") {
|
408
363
|
val options = args.getJSONObject(0)
|
409
364
|
if (mActivity != null) {
|
@@ -414,11 +369,12 @@ class emiAdmobPlugin : CordovaPlugin() {
|
|
414
369
|
try {
|
415
370
|
globalSettings(setAppMuted, setAppVolume, pubIdEnabled)
|
416
371
|
} catch (e: Exception) {
|
417
|
-
callbackContext.error(e.
|
372
|
+
callbackContext.error("globalSettings Error: " + e.message)
|
418
373
|
}
|
419
374
|
}
|
420
375
|
}
|
421
376
|
return true
|
377
|
+
|
422
378
|
} else if (action == "loadAppOpenAd") {
|
423
379
|
val options = args.getJSONObject(0)
|
424
380
|
if (mActivity != null) {
|
@@ -462,7 +418,7 @@ class emiAdmobPlugin : CordovaPlugin() {
|
|
462
418
|
cWebView!!.loadUrl("javascript:cordova.fireDocumentEvent('on.appOpenAd.revenue', ${result})")
|
463
419
|
|
464
420
|
} catch (e: JSONException) {
|
465
|
-
callbackContext.error(e.message)
|
421
|
+
callbackContext.error("loadAppOpenAd Error: " + e.message)
|
466
422
|
}
|
467
423
|
}
|
468
424
|
|
@@ -478,7 +434,7 @@ class emiAdmobPlugin : CordovaPlugin() {
|
|
478
434
|
result.put("getBundleExtra", mBundleExtra.toString())
|
479
435
|
cWebView?.loadUrl("javascript:cordova.fireDocumentEvent('on.appOpenAd.responseInfo', ${result})")
|
480
436
|
} catch (e: JSONException) {
|
481
|
-
callbackContext.error(e.message)
|
437
|
+
callbackContext.error("loadAppOpenAd Error: " + e.message)
|
482
438
|
}
|
483
439
|
|
484
440
|
|
@@ -497,7 +453,7 @@ class emiAdmobPlugin : CordovaPlugin() {
|
|
497
453
|
}
|
498
454
|
}
|
499
455
|
} catch (e: Exception) {
|
500
|
-
PUBLIC_CALLBACKS?.error(e.
|
456
|
+
PUBLIC_CALLBACKS?.error("loadAppOpenAd Error: " + e.message)
|
501
457
|
}
|
502
458
|
}
|
503
459
|
|
@@ -528,11 +484,12 @@ class emiAdmobPlugin : CordovaPlugin() {
|
|
528
484
|
|
529
485
|
})
|
530
486
|
} catch (e: Exception) {
|
531
|
-
callbackContext.error(e.
|
487
|
+
callbackContext.error("loadAppOpenAd Error: " + e.message)
|
532
488
|
}
|
533
489
|
}
|
534
490
|
}
|
535
491
|
return true
|
492
|
+
|
536
493
|
} else if (action == "showAppOpenAd") {
|
537
494
|
|
538
495
|
try {
|
@@ -543,7 +500,7 @@ class emiAdmobPlugin : CordovaPlugin() {
|
|
543
500
|
callbackContext.error("The App Open Ad wasn't ready yet")
|
544
501
|
}
|
545
502
|
} catch (e: Exception) {
|
546
|
-
PUBLIC_CALLBACKS
|
503
|
+
PUBLIC_CALLBACKS?.error("showAppOpenAd Error: " + e.message)
|
547
504
|
}
|
548
505
|
|
549
506
|
return true
|
@@ -581,12 +538,10 @@ class emiAdmobPlugin : CordovaPlugin() {
|
|
581
538
|
result.put("getResponseExtras", responseInfo?.responseExtras)
|
582
539
|
result.put("getMediationAdapterClassName", responseInfo?.mediationAdapterClassName)
|
583
540
|
result.put("getBundleExtra", mBundleExtra.toString())
|
584
|
-
cWebView!!.loadUrl(
|
585
|
-
"javascript:cordova.fireDocumentEvent('on.interstitialAd.responseInfo', ${result});"
|
586
|
-
)
|
541
|
+
cWebView!!.loadUrl( "javascript:cordova.fireDocumentEvent('on.interstitialAd.responseInfo', ${result});")
|
587
542
|
|
588
543
|
} catch (e: JSONException) {
|
589
|
-
callbackContext.error(e.message)
|
544
|
+
callbackContext.error("loadInterstitialAd Error: " + e.message)
|
590
545
|
}
|
591
546
|
}
|
592
547
|
mInterstitialAd?.onPaidEventListener =
|
@@ -601,12 +556,10 @@ class emiAdmobPlugin : CordovaPlugin() {
|
|
601
556
|
result.put("currency", currencyCode)
|
602
557
|
result.put("precision", precision)
|
603
558
|
result.put("adUnitId", interstitialAdUnitId)
|
604
|
-
cWebView?.loadUrl(
|
605
|
-
"javascript:cordova.fireDocumentEvent('on.interstitial.revenue', ${result});"
|
606
|
-
)
|
559
|
+
cWebView?.loadUrl("javascript:cordova.fireDocumentEvent('on.interstitial.revenue', ${result});")
|
607
560
|
|
608
561
|
} catch (e: JSONException) {
|
609
|
-
callbackContext.error(e.message)
|
562
|
+
callbackContext.error("loadInterstitialAd Error: " + e.message)
|
610
563
|
}
|
611
564
|
|
612
565
|
}
|
@@ -646,18 +599,17 @@ class emiAdmobPlugin : CordovaPlugin() {
|
|
646
599
|
put("responseInfoAdapterResponses", adapterResponses)
|
647
600
|
}
|
648
601
|
|
649
|
-
cWebView?.loadUrl(
|
650
|
-
"javascript:cordova.fireDocumentEvent('on.interstitial.failed.load', ${errorData});"
|
651
|
-
)
|
602
|
+
cWebView?.loadUrl("javascript:cordova.fireDocumentEvent('on.interstitial.failed.load', ${errorData});")
|
652
603
|
|
653
604
|
}
|
654
605
|
})
|
655
606
|
} catch (e: Exception) {
|
656
|
-
callbackContext.error(e.
|
607
|
+
callbackContext.error("loadInterstitialAd Error: " + e.message)
|
657
608
|
}
|
658
609
|
}
|
659
610
|
}
|
660
611
|
return true
|
612
|
+
|
661
613
|
} else if (action == "showInterstitialAd") {
|
662
614
|
|
663
615
|
if (mActivity != null && isInterstitialLoad && mInterstitialAd != null) {
|
@@ -703,9 +655,7 @@ class emiAdmobPlugin : CordovaPlugin() {
|
|
703
655
|
|
704
656
|
}
|
705
657
|
|
706
|
-
cWebView?.loadUrl(
|
707
|
-
"javascript:cordova.fireDocumentEvent('on.rewarded.failed.load', ${errorData});"
|
708
|
-
)
|
658
|
+
cWebView?.loadUrl("javascript:cordova.fireDocumentEvent('on.rewarded.failed.load', ${errorData});")
|
709
659
|
|
710
660
|
}
|
711
661
|
|
@@ -720,9 +670,7 @@ class emiAdmobPlugin : CordovaPlugin() {
|
|
720
670
|
|
721
671
|
rewardedAdLoadCallback()
|
722
672
|
|
723
|
-
cWebView?.loadUrl(
|
724
|
-
"javascript:cordova.fireDocumentEvent('on.rewarded.loaded');"
|
725
|
-
)
|
673
|
+
cWebView?.loadUrl( "javascript:cordova.fireDocumentEvent('on.rewarded.loaded');")
|
726
674
|
|
727
675
|
rewardedAd?.onPaidEventListener =
|
728
676
|
OnPaidEventListener { adValue: AdValue ->
|
@@ -736,11 +684,9 @@ class emiAdmobPlugin : CordovaPlugin() {
|
|
736
684
|
result.put("currency", currencyCode)
|
737
685
|
result.put("precision", precision)
|
738
686
|
result.put("adUnitId", rewardedAdAdUnitId)
|
739
|
-
cWebView?.loadUrl(
|
740
|
-
"javascript:cordova.fireDocumentEvent('on.rewarded.revenue', ${result});"
|
741
|
-
)
|
687
|
+
cWebView?.loadUrl("javascript:cordova.fireDocumentEvent('on.rewarded.revenue', ${result});")
|
742
688
|
} catch (e: JSONException) {
|
743
|
-
callbackContext.error(e.message)
|
689
|
+
callbackContext.error("loadRewardedAd Error: " + e.message)
|
744
690
|
}
|
745
691
|
|
746
692
|
}
|
@@ -758,7 +704,7 @@ class emiAdmobPlugin : CordovaPlugin() {
|
|
758
704
|
result.put("getBundleExtra", mBundleExtra.toString())
|
759
705
|
cWebView!!.loadUrl("javascript:cordova.fireDocumentEvent('on.rewardedAd.responseInfo', ${result})")
|
760
706
|
} catch (e: JSONException) {
|
761
|
-
callbackContext.error(e.message)
|
707
|
+
callbackContext.error("loadRewardedAd Error: " + e.message)
|
762
708
|
}
|
763
709
|
}
|
764
710
|
|
@@ -779,11 +725,9 @@ class emiAdmobPlugin : CordovaPlugin() {
|
|
779
725
|
try {
|
780
726
|
result.put("rewardType", rewardType)
|
781
727
|
result.put("rewardAmount", rewardAmount)
|
782
|
-
cWebView?.loadUrl(
|
783
|
-
"javascript:cordova.fireDocumentEvent('on.reward.userEarnedReward', ${result});"
|
784
|
-
)
|
728
|
+
cWebView?.loadUrl("javascript:cordova.fireDocumentEvent('on.reward.userEarnedReward', ${result});")
|
785
729
|
} catch (e: JSONException) {
|
786
|
-
callbackContext.error(e.message)
|
730
|
+
callbackContext.error("loadRewardedAd Error: " + e.message)
|
787
731
|
}
|
788
732
|
|
789
733
|
}
|
@@ -793,11 +737,12 @@ class emiAdmobPlugin : CordovaPlugin() {
|
|
793
737
|
}
|
794
738
|
})
|
795
739
|
} catch (e: Exception) {
|
796
|
-
callbackContext.error(e.
|
740
|
+
callbackContext.error("loadRewardedAd Error: " + e.message)
|
797
741
|
}
|
798
742
|
}
|
799
743
|
}
|
800
744
|
return true
|
745
|
+
|
801
746
|
} else if (action == "showRewardedAd") {
|
802
747
|
if (mActivity != null && isRewardedLoad && rewardedAd != null) {
|
803
748
|
mActivity?.runOnUiThread {
|
@@ -812,7 +757,7 @@ class emiAdmobPlugin : CordovaPlugin() {
|
|
812
757
|
result.put("rewardAmount", rewardAmount)
|
813
758
|
cWebView?.loadUrl("javascript:cordova.fireDocumentEvent('on.reward.userEarnedReward', ${result});")
|
814
759
|
} catch (e: JSONException) {
|
815
|
-
callbackContext.error(e.message)
|
760
|
+
callbackContext.error("showRewardedAd Error: " + e.message)
|
816
761
|
}
|
817
762
|
|
818
763
|
}
|
@@ -824,6 +769,7 @@ class emiAdmobPlugin : CordovaPlugin() {
|
|
824
769
|
callbackContext.error("The rewarded ad wasn't ready yet")
|
825
770
|
}
|
826
771
|
return true
|
772
|
+
|
827
773
|
} else if (action == "loadRewardedInterstitialAd") {
|
828
774
|
val options = args.getJSONObject(0)
|
829
775
|
if (mActivity != null) {
|
@@ -840,9 +786,7 @@ class emiAdmobPlugin : CordovaPlugin() {
|
|
840
786
|
isRewardedInterstitialLoad = true
|
841
787
|
isAdSkip = 0
|
842
788
|
|
843
|
-
cWebView?.loadUrl(
|
844
|
-
"javascript:cordova.fireDocumentEvent('on.rewardedInt.loaded');"
|
845
|
-
)
|
789
|
+
cWebView?.loadUrl("javascript:cordova.fireDocumentEvent('on.rewardedInt.loaded');")
|
846
790
|
|
847
791
|
if (rIntAutoShow) {
|
848
792
|
isRIntAutoShow
|
@@ -862,11 +806,9 @@ class emiAdmobPlugin : CordovaPlugin() {
|
|
862
806
|
result.put("currency", currencyCode)
|
863
807
|
result.put("precision", precision)
|
864
808
|
result.put("adUnitId", rewardedIntAdUnitId)
|
865
|
-
cWebView
|
866
|
-
"javascript:cordova.fireDocumentEvent('on.rewardedInt.revenue', ${result});"
|
867
|
-
)
|
809
|
+
cWebView?.loadUrl("javascript:cordova.fireDocumentEvent('on.rewardedInt.revenue', ${result});")
|
868
810
|
} catch (e: JSONException) {
|
869
|
-
callbackContext.error(e.message)
|
811
|
+
callbackContext.error("loadRewardedInterstitialAd Error: " + e.message)
|
870
812
|
}
|
871
813
|
|
872
814
|
}
|
@@ -881,11 +823,9 @@ class emiAdmobPlugin : CordovaPlugin() {
|
|
881
823
|
result.put("getResponseExtras", responseInfo?.responseExtras)
|
882
824
|
result.put("getMediationAdapterClassName", responseInfo?.mediationAdapterClassName)
|
883
825
|
result.put("getBundleExtra", mBundleExtra.toString())
|
884
|
-
cWebView?.loadUrl(
|
885
|
-
"javascript:cordova.fireDocumentEvent('on.rewardedIntAd.responseInfo', ${result});"
|
886
|
-
)
|
826
|
+
cWebView?.loadUrl("javascript:cordova.fireDocumentEvent('on.rewardedIntAd.responseInfo', ${result});")
|
887
827
|
} catch (e: JSONException) {
|
888
|
-
callbackContext.error(e.message)
|
828
|
+
callbackContext.error("loadRewardedInterstitialAd Error: " + e.message)
|
889
829
|
}
|
890
830
|
}
|
891
831
|
|
@@ -907,11 +847,9 @@ class emiAdmobPlugin : CordovaPlugin() {
|
|
907
847
|
try {
|
908
848
|
result.put("rewardType", rewardType)
|
909
849
|
result.put("rewardAmount", rewardAmount)
|
910
|
-
cWebView?.loadUrl(
|
911
|
-
"javascript:cordova.fireDocumentEvent('on.rewardedInt.userEarnedReward', ${result});"
|
912
|
-
)
|
850
|
+
cWebView?.loadUrl("javascript:cordova.fireDocumentEvent('on.rewardedInt.userEarnedReward', ${result});")
|
913
851
|
} catch (e: JSONException) {
|
914
|
-
callbackContext.error(e.message)
|
852
|
+
callbackContext.error("loadRewardedInterstitialAd Error: " + e.message)
|
915
853
|
}
|
916
854
|
|
917
855
|
}
|
@@ -941,18 +879,17 @@ class emiAdmobPlugin : CordovaPlugin() {
|
|
941
879
|
put("responseInfoMediationAdapterClassName", mediationAdapterClassName)
|
942
880
|
put("responseInfoAdapterResponses", adapterResponses)
|
943
881
|
}
|
944
|
-
cWebView?.loadUrl(
|
945
|
-
"javascript:cordova.fireDocumentEvent('on.rewardedInt.failed.load', ${errorData});"
|
946
|
-
)
|
882
|
+
cWebView?.loadUrl("javascript:cordova.fireDocumentEvent('on.rewardedInt.failed.load', ${errorData});")
|
947
883
|
|
948
884
|
}
|
949
885
|
})
|
950
886
|
} catch (e: Exception) {
|
951
|
-
callbackContext.error(e.
|
887
|
+
callbackContext.error("loadRewardedInterstitialAd Error: " + e.message)
|
952
888
|
}
|
953
889
|
}
|
954
890
|
}
|
955
891
|
return true
|
892
|
+
|
956
893
|
} else if (action == "showRewardedInterstitialAd") {
|
957
894
|
if (mActivity != null) {
|
958
895
|
mActivity?.runOnUiThread {
|
@@ -966,11 +903,9 @@ class emiAdmobPlugin : CordovaPlugin() {
|
|
966
903
|
try {
|
967
904
|
result.put("rewardType", rewardType)
|
968
905
|
result.put("rewardAmount", rewardAmount)
|
969
|
-
cWebView?.loadUrl(
|
970
|
-
"javascript:cordova.fireDocumentEvent('on.rewardedInt.userEarnedReward', ${result});"
|
971
|
-
)
|
906
|
+
cWebView?.loadUrl("javascript:cordova.fireDocumentEvent('on.rewardedInt.userEarnedReward', ${result});")
|
972
907
|
} catch (e: JSONException) {
|
973
|
-
callbackContext.error(e.message)
|
908
|
+
callbackContext.error("loadRewardedInterstitialAd Error: " + e.message)
|
974
909
|
}
|
975
910
|
|
976
911
|
}
|
@@ -981,6 +916,7 @@ class emiAdmobPlugin : CordovaPlugin() {
|
|
981
916
|
}
|
982
917
|
}
|
983
918
|
return true
|
919
|
+
|
984
920
|
} else if (action == "showPrivacyOptionsForm") {
|
985
921
|
if (mActivity != null) {
|
986
922
|
mActivity?.runOnUiThread {
|
@@ -1041,18 +977,19 @@ class emiAdmobPlugin : CordovaPlugin() {
|
|
1041
977
|
})
|
1042
978
|
}
|
1043
979
|
} catch (e: Exception) {
|
1044
|
-
callbackContext.error(e.
|
980
|
+
callbackContext.error("showPrivacyOptionsForm Error: " + e.message)
|
1045
981
|
}
|
1046
982
|
}
|
1047
983
|
}
|
1048
984
|
return true
|
985
|
+
|
1049
986
|
} else if (action == "consentReset") {
|
1050
987
|
if (mActivity != null) {
|
1051
988
|
mActivity?.runOnUiThread {
|
1052
989
|
try {
|
1053
990
|
consentInformation?.reset()
|
1054
991
|
} catch (e: Exception) {
|
1055
|
-
callbackContext.error(e.
|
992
|
+
callbackContext.error("consentReset Error: " + e.message)
|
1056
993
|
}
|
1057
994
|
}
|
1058
995
|
}
|
@@ -1074,17 +1011,17 @@ class emiAdmobPlugin : CordovaPlugin() {
|
|
1074
1011
|
editor.putString("IABTCF_TCString", consentString)
|
1075
1012
|
editor.putLong(LAST_ACCESS_SUFFIX, System.currentTimeMillis())
|
1076
1013
|
editor.apply()
|
1077
|
-
//val key = "IABTCF_TCString"
|
1078
1014
|
getString(consentString.toString())
|
1079
1015
|
callbackContext.success(userInfoJson)
|
1080
1016
|
cWebView?.loadUrl("javascript:cordova.fireDocumentEvent('on.getIabTfc');")
|
1081
1017
|
} catch (e: Exception) {
|
1082
|
-
callbackContext.error(e.
|
1018
|
+
callbackContext.error("getIabTfc Error: " + e.message)
|
1083
1019
|
cWebView?.loadUrl("javascript:cordova.fireDocumentEvent('on.getIabTfc.error');")
|
1084
1020
|
}
|
1085
1021
|
}
|
1086
1022
|
}
|
1087
1023
|
return true
|
1024
|
+
|
1088
1025
|
} else if (action == "loadBannerAd") {
|
1089
1026
|
if (mActivity != null) {
|
1090
1027
|
val options = args.getJSONObject(0)
|
@@ -1093,24 +1030,26 @@ class emiAdmobPlugin : CordovaPlugin() {
|
|
1093
1030
|
val position = options.optString("position")
|
1094
1031
|
val collapsible = options.optString("collapsible")
|
1095
1032
|
val size = options.optString("size")
|
1096
|
-
val autoResize = options.optBoolean("autoResize")
|
1097
1033
|
val autoShow = options.optBoolean("autoShow")
|
1034
|
+
val isOverlapping = options.optBoolean("isOverlapping", false)
|
1035
|
+
val paddingPx = options.optInt("padding")
|
1098
1036
|
this.bannerAdUnitId = adUnitId
|
1099
1037
|
this.isPosition = position
|
1100
1038
|
this.isSize = size
|
1101
1039
|
this.bannerAutoShow = autoShow
|
1102
|
-
this.isAutoResize = autoResize
|
1103
1040
|
this.collapsiblePos = collapsible
|
1041
|
+
this.isOverlapping = isOverlapping
|
1042
|
+
this.paddingInPx = paddingPx
|
1104
1043
|
|
1105
|
-
isCollapsible = collapsible.isNotEmpty()
|
1106
1044
|
try {
|
1107
1045
|
loadBannerAd(adUnitId, position, size)
|
1108
1046
|
} catch (e: Exception) {
|
1109
|
-
callbackContext.error(e.
|
1047
|
+
callbackContext.error("loadBannerAd Error: " + e.message)
|
1110
1048
|
}
|
1111
1049
|
}
|
1112
1050
|
}
|
1113
1051
|
return true
|
1052
|
+
|
1114
1053
|
} else if (action == "showBannerAd") {
|
1115
1054
|
if (mActivity != null) {
|
1116
1055
|
mActivity?.runOnUiThread {
|
@@ -1121,20 +1060,22 @@ class emiAdmobPlugin : CordovaPlugin() {
|
|
1121
1060
|
bannerView?.visibility = View.VISIBLE
|
1122
1061
|
bannerView?.resume()
|
1123
1062
|
|
1124
|
-
|
1125
|
-
bannerOverlapping()
|
1126
|
-
}
|
1063
|
+
bannerOverlapping()
|
1127
1064
|
|
1128
|
-
|
1065
|
+
if(loadBannerAdNew) {
|
1066
|
+
setBannerAdNewApi(adSize)
|
1067
|
+
}
|
1129
1068
|
|
1069
|
+
bannerViewLayout?.requestFocus()
|
1130
1070
|
|
1131
1071
|
} catch (e: Exception) {
|
1132
|
-
callbackContext.error(e.
|
1072
|
+
callbackContext.error("showBannerAd Error: " + e.message)
|
1133
1073
|
}
|
1134
1074
|
}
|
1135
1075
|
}
|
1136
1076
|
}
|
1137
1077
|
return true
|
1078
|
+
|
1138
1079
|
} else if (action == "styleBannerAd") {
|
1139
1080
|
val options = args.getJSONObject(0)
|
1140
1081
|
if (mActivity != null) {
|
@@ -1148,10 +1089,13 @@ class emiAdmobPlugin : CordovaPlugin() {
|
|
1148
1089
|
screenHeight = windowMetrics.bounds.height()
|
1149
1090
|
usableHeight = screenHeight - insets.bottom
|
1150
1091
|
} else {
|
1092
|
+
@Suppress("DEPRECATION")
|
1151
1093
|
val display = cordova.activity.windowManager.defaultDisplay
|
1152
1094
|
val size = Point()
|
1153
1095
|
val realSize = Point()
|
1096
|
+
@Suppress("DEPRECATION")
|
1154
1097
|
display.getSize(size)
|
1098
|
+
@Suppress("DEPRECATION")
|
1155
1099
|
display.getRealSize(realSize)
|
1156
1100
|
|
1157
1101
|
usableHeight = size.y
|
@@ -1188,9 +1132,7 @@ class emiAdmobPlugin : CordovaPlugin() {
|
|
1188
1132
|
}
|
1189
1133
|
""".trimIndent()
|
1190
1134
|
|
1191
|
-
mActivity?.runOnUiThread {
|
1192
|
-
cWebView?.loadUrl("javascript:cordova.fireDocumentEvent('on.style.banner.ad', $eventData)")
|
1193
|
-
}
|
1135
|
+
mActivity?.runOnUiThread { cWebView?.loadUrl("javascript:cordova.fireDocumentEvent('on.style.banner.ad', $eventData)") }
|
1194
1136
|
} catch (e: Exception) {
|
1195
1137
|
callbackContext.error("Error in styleBannerAd: ${e.message}")
|
1196
1138
|
}
|
@@ -1198,6 +1140,7 @@ class emiAdmobPlugin : CordovaPlugin() {
|
|
1198
1140
|
}
|
1199
1141
|
}
|
1200
1142
|
return true
|
1143
|
+
|
1201
1144
|
} else if (action == "metaData") {
|
1202
1145
|
val options = args.getJSONObject(0)
|
1203
1146
|
val useCustomConsentManager = options.optBoolean("useCustomConsentManager")
|
@@ -1220,12 +1163,13 @@ class emiAdmobPlugin : CordovaPlugin() {
|
|
1220
1163
|
isBannerPause = 1
|
1221
1164
|
bannerOverlappingToZero()
|
1222
1165
|
} catch (e: Exception) {
|
1223
|
-
callbackContext.error(e.
|
1166
|
+
callbackContext.error("hideBannerAd Error: " + e.message)
|
1224
1167
|
}
|
1225
1168
|
}
|
1226
1169
|
}
|
1227
1170
|
}
|
1228
1171
|
return true
|
1172
|
+
|
1229
1173
|
} else if (action == "removeBannerAd") {
|
1230
1174
|
if (mActivity != null) {
|
1231
1175
|
mActivity?.runOnUiThread {
|
@@ -1242,7 +1186,7 @@ class emiAdmobPlugin : CordovaPlugin() {
|
|
1242
1186
|
lock = true
|
1243
1187
|
}
|
1244
1188
|
} catch (e: Exception) {
|
1245
|
-
PUBLIC_CALLBACKS
|
1189
|
+
PUBLIC_CALLBACKS?.error("Error removing banner: " + e.message)
|
1246
1190
|
}
|
1247
1191
|
}
|
1248
1192
|
}
|
@@ -1254,7 +1198,7 @@ class emiAdmobPlugin : CordovaPlugin() {
|
|
1254
1198
|
try {
|
1255
1199
|
registerWebView(callbackContext)
|
1256
1200
|
} catch (e: Exception) {
|
1257
|
-
PUBLIC_CALLBACKS
|
1201
|
+
PUBLIC_CALLBACKS?.error("Error register WebView: " + e.message)
|
1258
1202
|
}
|
1259
1203
|
}
|
1260
1204
|
}
|
@@ -1273,6 +1217,33 @@ class emiAdmobPlugin : CordovaPlugin() {
|
|
1273
1217
|
|
1274
1218
|
}
|
1275
1219
|
return true
|
1220
|
+
|
1221
|
+
// Still under development
|
1222
|
+
} else if (action == "loadBannerAdNewApi") {
|
1223
|
+
if (mActivity != null) {
|
1224
|
+
val options = args.getJSONObject(0)
|
1225
|
+
mActivity?.runOnUiThread {
|
1226
|
+
val adUnitId = options.optString("adUnitId")
|
1227
|
+
val position = options.optString("position")
|
1228
|
+
val collapsible = options.optString("collapsible")
|
1229
|
+
val size = options.optString("size")
|
1230
|
+
val autoShow = options.optBoolean("autoShow")
|
1231
|
+
val overlapping = options.optBoolean("overlapping")
|
1232
|
+
this.bannerAdUnitId = adUnitId
|
1233
|
+
this.isPosition = position
|
1234
|
+
this.isSize = size
|
1235
|
+
this.bannerAutoShow = autoShow
|
1236
|
+
this.loadBannerAdNew = true
|
1237
|
+
this.collapsiblePos = collapsible
|
1238
|
+
this.bannerOverlapping = overlapping
|
1239
|
+
try {
|
1240
|
+
loadBannerAd(adUnitId, position, size)
|
1241
|
+
} catch (e: Exception) {
|
1242
|
+
callbackContext.error("loadBannerAdNewApi Error: " + e.message)
|
1243
|
+
}
|
1244
|
+
}
|
1245
|
+
}
|
1246
|
+
return true
|
1276
1247
|
}
|
1277
1248
|
return false
|
1278
1249
|
}
|
@@ -1330,11 +1301,10 @@ class emiAdmobPlugin : CordovaPlugin() {
|
|
1330
1301
|
bannerView?.adListener = bannerAdListener
|
1331
1302
|
bannerView?.loadAd(buildAdRequest())
|
1332
1303
|
} else {
|
1333
|
-
|
1304
|
+
PUBLIC_CALLBACKS?.error("Banner view layout already exists.")
|
1334
1305
|
}
|
1335
1306
|
} catch (e: Exception) {
|
1336
1307
|
PUBLIC_CALLBACKS?.error("Error showing banner: " + e.message)
|
1337
|
-
Log.d(TAG, "Error showing banner: " + e.message)
|
1338
1308
|
}
|
1339
1309
|
}
|
1340
1310
|
|
@@ -1397,7 +1367,7 @@ class emiAdmobPlugin : CordovaPlugin() {
|
|
1397
1367
|
}
|
1398
1368
|
}
|
1399
1369
|
|
1400
|
-
bannerViewLayout
|
1370
|
+
bannerViewLayout?.layoutParams = bannerParams
|
1401
1371
|
}
|
1402
1372
|
|
1403
1373
|
|
@@ -1434,11 +1404,12 @@ class emiAdmobPlugin : CordovaPlugin() {
|
|
1434
1404
|
bannerViewLayout?.bringToFront()
|
1435
1405
|
bannerViewLayout?.requestFocus();
|
1436
1406
|
lock = false
|
1407
|
+
|
1437
1408
|
}
|
1438
1409
|
isBannerShow = true
|
1439
1410
|
} catch (e: Exception) {
|
1440
1411
|
lock = true
|
1441
|
-
PUBLIC_CALLBACKS?.error(e.
|
1412
|
+
PUBLIC_CALLBACKS?.error("Error isShowBannerAds: ${e.message}")
|
1442
1413
|
}
|
1443
1414
|
}
|
1444
1415
|
}
|
@@ -1474,7 +1445,7 @@ class emiAdmobPlugin : CordovaPlugin() {
|
|
1474
1445
|
put("responseInfoAdapterResponses", adapterResponses)
|
1475
1446
|
}
|
1476
1447
|
|
1477
|
-
cWebView
|
1448
|
+
cWebView?.loadUrl("javascript:cordova.fireDocumentEvent('on.banner.failed.load', ${errorData});")
|
1478
1449
|
|
1479
1450
|
bannerOverlappingToZero()
|
1480
1451
|
|
@@ -1489,12 +1460,10 @@ class emiAdmobPlugin : CordovaPlugin() {
|
|
1489
1460
|
lock = true
|
1490
1461
|
}
|
1491
1462
|
|
1492
|
-
|
1493
|
-
|
1494
1463
|
}
|
1495
1464
|
|
1496
1465
|
override fun onAdImpression() {
|
1497
|
-
cWebView
|
1466
|
+
cWebView?.loadUrl("javascript:cordova.fireDocumentEvent('on.banner.impression');")
|
1498
1467
|
}
|
1499
1468
|
|
1500
1469
|
private fun getAdHeightInDp(adSize: AdSize, context: Context): Int {
|
@@ -1505,7 +1474,7 @@ class emiAdmobPlugin : CordovaPlugin() {
|
|
1505
1474
|
|
1506
1475
|
|
1507
1476
|
override fun onAdLoaded() {
|
1508
|
-
|
1477
|
+
|
1509
1478
|
isBannerLoad = true
|
1510
1479
|
isBannerPause = 0
|
1511
1480
|
|
@@ -1513,37 +1482,32 @@ class emiAdmobPlugin : CordovaPlugin() {
|
|
1513
1482
|
isBannerAutoShow()
|
1514
1483
|
}
|
1515
1484
|
|
1516
|
-
|
1517
|
-
|
1518
|
-
}
|
1485
|
+
|
1486
|
+
bannerOverlapping()
|
1519
1487
|
|
1520
1488
|
|
1521
1489
|
val context = cordova.activity.applicationContext
|
1522
|
-
//val adType="fluid";
|
1523
|
-
// Get the AdSize object based on the type
|
1524
1490
|
var currentAdSize = when (adType) {
|
1525
1491
|
"banner" -> AdSize.BANNER
|
1526
1492
|
"large_banner" -> AdSize.LARGE_BANNER
|
1527
1493
|
"medium_rectangle" -> AdSize.MEDIUM_RECTANGLE
|
1528
1494
|
"full_banner" -> AdSize.FULL_BANNER
|
1529
1495
|
"leaderboard" -> AdSize.LEADERBOARD
|
1530
|
-
|
1531
|
-
//"fluid" -> AdSize.FLUID
|
1532
|
-
//"in_line_adaptive" -> AdSize.getCurrentOrientationInlineAdaptiveBannerAdSize(context, adWidth)
|
1533
|
-
|
1534
1496
|
else -> adSize // Default fallback to the adaptive ad size
|
1535
1497
|
}
|
1536
1498
|
|
1537
1499
|
// Calculate the height in dp
|
1538
1500
|
val bannerHeightDp = getAdHeightInDp(currentAdSize, context)
|
1539
1501
|
|
1540
|
-
|
1502
|
+
if(loadBannerAdNew) {
|
1503
|
+
setBannerAdNewApi(currentAdSize)
|
1504
|
+
}
|
1541
1505
|
|
1542
1506
|
|
1543
1507
|
val bannerLoadEventData = String.format(Locale.US, "{\"height\": %d}", bannerHeightDp)
|
1544
1508
|
|
1545
1509
|
|
1546
|
-
cWebView
|
1510
|
+
cWebView?.loadUrl("javascript:cordova.fireDocumentEvent('on.banner.load', $bannerLoadEventData);")
|
1547
1511
|
|
1548
1512
|
val eventData = String.format(
|
1549
1513
|
"{\"collapsible\": \"%s\"}",
|
@@ -1568,16 +1532,16 @@ class emiAdmobPlugin : CordovaPlugin() {
|
|
1568
1532
|
} else {
|
1569
1533
|
result.put("getBundleExtra", JSONObject.NULL)
|
1570
1534
|
}
|
1571
|
-
cWebView
|
1535
|
+
cWebView?.loadUrl("javascript:cordova.fireDocumentEvent('on.bannerAd.responseInfo', ${result});")
|
1572
1536
|
} catch (e: JSONException) {
|
1573
|
-
PUBLIC_CALLBACKS
|
1537
|
+
PUBLIC_CALLBACKS?.error("Error isResponseInfo: ${e.message}")
|
1574
1538
|
}
|
1575
1539
|
}
|
1576
1540
|
}
|
1577
1541
|
|
1578
1542
|
|
1579
1543
|
override fun onAdOpened() {
|
1580
|
-
cWebView
|
1544
|
+
cWebView?.loadUrl("javascript:cordova.fireDocumentEvent('on.banner.open');")
|
1581
1545
|
isBannerShows = false
|
1582
1546
|
}
|
1583
1547
|
}
|
@@ -1590,25 +1554,17 @@ class emiAdmobPlugin : CordovaPlugin() {
|
|
1590
1554
|
try {
|
1591
1555
|
val rootView = (cWebView?.view?.parent as View)
|
1592
1556
|
rootView.post {
|
1593
|
-
// Get the total height of the parent view
|
1594
1557
|
val totalHeight = rootView.height
|
1595
|
-
|
1596
|
-
// Adjust WebView height to match parent height
|
1597
1558
|
val layoutParams = cWebView?.view?.layoutParams
|
1598
1559
|
layoutParams?.height = totalHeight
|
1599
1560
|
cWebView?.view?.layoutParams = layoutParams
|
1600
|
-
|
1601
|
-
// Ensure no padding/margin in WebView or its parent
|
1602
1561
|
cWebView?.view?.setPadding(0, 0, 0, 0)
|
1603
1562
|
(cWebView?.view?.parent as? ViewGroup)?.setPadding(0, 0, 0, 0)
|
1604
|
-
|
1605
|
-
// Force layout update
|
1606
1563
|
cWebView?.view?.requestLayout()
|
1607
1564
|
|
1608
|
-
Log.d("BannerAdjustment", "WebView set to full height: $totalHeight")
|
1609
1565
|
}
|
1610
1566
|
} catch (e: Exception) {
|
1611
|
-
|
1567
|
+
PUBLIC_CALLBACKS?.error("Error bannerOverlappingToZero: ${e.message}")
|
1612
1568
|
}
|
1613
1569
|
}
|
1614
1570
|
}
|
@@ -1616,35 +1572,64 @@ class emiAdmobPlugin : CordovaPlugin() {
|
|
1616
1572
|
|
1617
1573
|
|
1618
1574
|
|
1575
|
+
private fun bannerOverlapping() {
|
1576
|
+
if (bannerView != null && mActivity != null && cWebView != null) {
|
1577
|
+
mActivity?.runOnUiThread {
|
1578
|
+
bannerView?.post {
|
1579
|
+
try {
|
1580
|
+
val measuredBannerHeight = if (bannerView!!.height > 0)
|
1581
|
+
bannerView!!.height
|
1582
|
+
else
|
1583
|
+
adSize.getHeightInPixels(mActivity!!)
|
1584
|
+
|
1585
|
+
val screenHeightInPx = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
|
1586
|
+
val windowMetrics = mActivity!!.windowManager.currentWindowMetrics
|
1587
|
+
val insets = windowMetrics.windowInsets.getInsets(WindowInsets.Type.systemBars())
|
1588
|
+
val height = windowMetrics.bounds.height() - insets.top - insets.bottom
|
1589
|
+
height
|
1590
|
+
} else {
|
1591
|
+
val displayMetrics = DisplayMetrics()
|
1592
|
+
@Suppress("DEPRECATION")
|
1593
|
+
mActivity!!.windowManager.defaultDisplay.getMetrics(displayMetrics)
|
1594
|
+
displayMetrics.heightPixels
|
1595
|
+
}
|
1596
|
+
|
1597
|
+
val webViewHeight = screenHeightInPx - measuredBannerHeight
|
1598
|
+
|
1599
|
+
if (!isFullScreen) {
|
1600
|
+
val navBarHeight = getNavigationBarHeight(mActivity!!)
|
1601
|
+
bannerViewLayout?.let { container ->
|
1602
|
+
container.post {
|
1603
|
+
val params = container.layoutParams
|
1604
|
+
if (params is ViewGroup.MarginLayoutParams) {
|
1605
|
+
params.bottomMargin = navBarHeight
|
1606
|
+
container.layoutParams = params
|
1607
|
+
container.requestLayout()
|
1608
|
+
}
|
1609
|
+
}
|
1610
|
+
}
|
1611
|
+
}
|
1612
|
+
|
1613
|
+
if (!isOverlapping) {
|
1619
1614
|
|
1620
|
-
|
1621
|
-
|
1622
|
-
|
1623
|
-
try {
|
1624
|
-
val displayMetrics = DisplayMetrics()
|
1625
|
-
mActivity!!.windowManager.defaultDisplay.getMetrics(displayMetrics)
|
1626
|
-
val screenHeightInPx = displayMetrics.heightPixels
|
1627
|
-
|
1628
|
-
val webViewHeight = if (isStatusBarShow) {
|
1629
|
-
screenHeightInPx - (adSize.height + overlappingHeight)
|
1630
|
-
} else {
|
1631
|
-
screenHeightInPx + (adSize.height + overlappingHeight)
|
1632
|
-
}
|
1633
|
-
val layoutParams = cWebView!!.view.layoutParams
|
1634
|
-
layoutParams.height = webViewHeight
|
1635
|
-
cWebView!!.view.layoutParams = layoutParams
|
1615
|
+
val layoutParams = cWebView!!.view.layoutParams
|
1616
|
+
layoutParams.height = webViewHeight
|
1617
|
+
cWebView!!.view.layoutParams = layoutParams
|
1636
1618
|
|
1637
|
-
|
1638
|
-
|
1639
|
-
|
1619
|
+
}
|
1620
|
+
|
1621
|
+
} catch (e: Exception) {
|
1622
|
+
PUBLIC_CALLBACKS?.error("Error bannerOverlapping: ${e.message}")
|
1623
|
+
}
|
1624
|
+
}
|
1640
1625
|
}
|
1641
1626
|
}
|
1642
1627
|
}
|
1643
|
-
}
|
1644
1628
|
|
1645
1629
|
|
1646
1630
|
|
1647
|
-
|
1631
|
+
|
1632
|
+
private val bannerPaidAdListener = OnPaidEventListener { adValue ->
|
1648
1633
|
val valueMicros = adValue.valueMicros.takeIf { it > 0 } ?: 0L
|
1649
1634
|
val currencyCode = adValue.currencyCode.ifBlank { "UNKNOWN" }
|
1650
1635
|
val precision = adValue.precisionType.takeIf { it >= 0 } ?: AdValue.PrecisionType.UNKNOWN
|
@@ -1657,9 +1642,9 @@ class emiAdmobPlugin : CordovaPlugin() {
|
|
1657
1642
|
result.put("adUnitId", adUnitId)
|
1658
1643
|
isBannerLoad = false
|
1659
1644
|
isBannerShow = true
|
1660
|
-
cWebView
|
1645
|
+
cWebView?.loadUrl("javascript:cordova.fireDocumentEvent('on.banner.revenue', ${result});")
|
1661
1646
|
} catch (e: JSONException) {
|
1662
|
-
PUBLIC_CALLBACKS
|
1647
|
+
PUBLIC_CALLBACKS?.error("Error bannerPaidAdListener: ${e.message}")
|
1663
1648
|
}
|
1664
1649
|
}
|
1665
1650
|
|
@@ -1738,7 +1723,7 @@ class emiAdmobPlugin : CordovaPlugin() {
|
|
1738
1723
|
val bounds = windowMetrics.bounds
|
1739
1724
|
val widthPixels = bounds.width() - insets.left - insets.right
|
1740
1725
|
outMetrics.widthPixels = widthPixels
|
1741
|
-
outMetrics.density = mActivity
|
1726
|
+
outMetrics.density = mActivity?.resources?.displayMetrics!!.density
|
1742
1727
|
}
|
1743
1728
|
} else {
|
1744
1729
|
@Suppress("DEPRECATION")
|
@@ -1785,13 +1770,7 @@ class emiAdmobPlugin : CordovaPlugin() {
|
|
1785
1770
|
}
|
1786
1771
|
|
1787
1772
|
|
1788
|
-
private fun targetingAdRequest(
|
1789
|
-
customTargeting: JSONArray?,
|
1790
|
-
categoryExclusions: String,
|
1791
|
-
ppId: String,
|
1792
|
-
ctURL: String,
|
1793
|
-
brandSafetyArr: JSONArray?
|
1794
|
-
) {
|
1773
|
+
private fun targetingAdRequest(customTargeting: JSONArray?, categoryExclusions: String, ppId: String, ctURL: String, brandSafetyArr: JSONArray?) {
|
1795
1774
|
try {
|
1796
1775
|
customTargetingList = ArrayList()
|
1797
1776
|
|
@@ -1842,6 +1821,8 @@ class emiAdmobPlugin : CordovaPlugin() {
|
|
1842
1821
|
@SuppressLint("DefaultLocale")
|
1843
1822
|
private fun initializeMobileAdsSdk() {
|
1844
1823
|
|
1824
|
+
isFullScreen = isFullScreenMode(mActivity!!)
|
1825
|
+
|
1845
1826
|
if (isMobileAdsInitializeCalled.getAndSet(true)) {
|
1846
1827
|
return
|
1847
1828
|
}
|
@@ -1888,12 +1869,11 @@ class emiAdmobPlugin : CordovaPlugin() {
|
|
1888
1869
|
""".trimIndent()
|
1889
1870
|
|
1890
1871
|
mActivity?.runOnUiThread {
|
1891
|
-
// Log.d(TAG, "Google Mobile Ads SDK Initialization: $eventData")
|
1892
1872
|
cWebView?.loadUrl("javascript:cordova.fireDocumentEvent('on.sdkInitialization', $eventData)")
|
1893
1873
|
}
|
1894
1874
|
}
|
1895
1875
|
} catch (e: Exception) {
|
1896
|
-
|
1876
|
+
PUBLIC_CALLBACKS?.error("Error during MobileAds initialization: ${e.message}")
|
1897
1877
|
}
|
1898
1878
|
}
|
1899
1879
|
}
|
@@ -1909,7 +1889,7 @@ class emiAdmobPlugin : CordovaPlugin() {
|
|
1909
1889
|
|
1910
1890
|
if (this.customTargetingEnabled) {
|
1911
1891
|
if (customTargetingList!!.isEmpty()) {
|
1912
|
-
|
1892
|
+
// Log.d(TAG, "List is empty")
|
1913
1893
|
PUBLIC_CALLBACKS?.error("List is empty")
|
1914
1894
|
} else {
|
1915
1895
|
builder.addCustomTargeting("age", customTargetingList!!)
|
@@ -1938,7 +1918,7 @@ class emiAdmobPlugin : CordovaPlugin() {
|
|
1938
1918
|
|
1939
1919
|
if (this.brandSafetyEnabled) {
|
1940
1920
|
if (brandSafetyUrls!!.isEmpty()) {
|
1941
|
-
Log.d(TAG, "List is empty")
|
1921
|
+
//Log.d(TAG, "List is empty")
|
1942
1922
|
PUBLIC_CALLBACKS?.error("List is empty")
|
1943
1923
|
} else {
|
1944
1924
|
builder.setNeighboringContentUrls(brandSafetyUrls!!)
|
@@ -1953,7 +1933,7 @@ class emiAdmobPlugin : CordovaPlugin() {
|
|
1953
1933
|
|
1954
1934
|
val bundleExtra = Bundle()
|
1955
1935
|
// bundleExtra.putString("npa", this.Npa); DEPRECATED Beginning January 16, 2024
|
1956
|
-
if (
|
1936
|
+
if (collapsiblePos !== "") {
|
1957
1937
|
bundleExtra.putString("collapsible", this.collapsiblePos)
|
1958
1938
|
}
|
1959
1939
|
bundleExtra.putBoolean("is_designed_for_families", this.isSetTagForChildDirectedTreatment)
|
@@ -1981,7 +1961,7 @@ class emiAdmobPlugin : CordovaPlugin() {
|
|
1981
1961
|
val builder = AdRequest.Builder()
|
1982
1962
|
val bundleExtra = Bundle()
|
1983
1963
|
// bundleExtra.putString("npa", this.Npa); DEPRECATED Beginning January 16, 2024
|
1984
|
-
if (
|
1964
|
+
if (collapsiblePos !== "") {
|
1985
1965
|
bundleExtra.putString("collapsible", this.collapsiblePos)
|
1986
1966
|
}
|
1987
1967
|
|
@@ -2052,19 +2032,19 @@ class emiAdmobPlugin : CordovaPlugin() {
|
|
2052
2032
|
val currentTime = System.currentTimeMillis()
|
2053
2033
|
if (currentTime - lastAccessTime > EXPIRATION_TIME) {
|
2054
2034
|
removeKey(key)
|
2055
|
-
cWebView
|
2035
|
+
cWebView?.loadUrl("javascript:cordova.fireDocumentEvent('on.TCString.expired');")
|
2056
2036
|
}
|
2057
|
-
val editor = mPreferences
|
2058
|
-
editor
|
2059
|
-
editor
|
2037
|
+
val editor = mPreferences?.edit()
|
2038
|
+
editor?.putLong(key + LAST_ACCESS_SUFFIX, currentTime)
|
2039
|
+
editor?.apply()
|
2060
2040
|
}
|
2061
2041
|
|
2062
2042
|
private fun removeKey(key: String) {
|
2063
|
-
val editor = mPreferences
|
2064
|
-
editor
|
2065
|
-
editor
|
2066
|
-
editor
|
2067
|
-
cWebView
|
2043
|
+
val editor = mPreferences?.edit()
|
2044
|
+
editor?.remove(key)
|
2045
|
+
editor?.remove(key + LAST_ACCESS_SUFFIX)
|
2046
|
+
editor?.apply()
|
2047
|
+
cWebView?.loadUrl("javascript:cordova.fireDocumentEvent('on.TCString.remove');")
|
2068
2048
|
}
|
2069
2049
|
|
2070
2050
|
|
@@ -2075,7 +2055,7 @@ class emiAdmobPlugin : CordovaPlugin() {
|
|
2075
2055
|
private fun appOpenAdLoadCallback() {
|
2076
2056
|
appOpenAd?.fullScreenContentCallback = object : FullScreenContentCallback() {
|
2077
2057
|
override fun onAdDismissedFullScreenContent() {
|
2078
|
-
cWebView
|
2058
|
+
cWebView?.loadUrl("javascript:cordova.fireDocumentEvent('on.appOpenAd.dismissed');")
|
2079
2059
|
val mainView: View? = view
|
2080
2060
|
mainView?.requestFocus()
|
2081
2061
|
}
|
@@ -2138,7 +2118,7 @@ class emiAdmobPlugin : CordovaPlugin() {
|
|
2138
2118
|
private fun rewardedAdLoadCallback() {
|
2139
2119
|
rewardedAd?.fullScreenContentCallback = object : FullScreenContentCallback() {
|
2140
2120
|
override fun onAdClicked() {
|
2141
|
-
cWebView
|
2121
|
+
cWebView?.loadUrl("javascript:cordova.fireDocumentEvent('on.rewarded.click');")
|
2142
2122
|
}
|
2143
2123
|
|
2144
2124
|
override fun onAdDismissedFullScreenContent() {
|
@@ -2151,7 +2131,7 @@ class emiAdmobPlugin : CordovaPlugin() {
|
|
2151
2131
|
}
|
2152
2132
|
rewardedAd = null
|
2153
2133
|
isRewardedLoad = false
|
2154
|
-
cWebView
|
2134
|
+
cWebView?.loadUrl("javascript:cordova.fireDocumentEvent('on.rewarded.dismissed');")
|
2155
2135
|
}
|
2156
2136
|
|
2157
2137
|
override fun onAdFailedToShowFullScreenContent(adError: AdError) {
|
@@ -2163,16 +2143,16 @@ class emiAdmobPlugin : CordovaPlugin() {
|
|
2163
2143
|
put("domain", adError.domain)
|
2164
2144
|
put("cause", adError.cause?.toString() ?: "null")
|
2165
2145
|
}
|
2166
|
-
cWebView
|
2146
|
+
cWebView?.loadUrl("javascript:cordova.fireDocumentEvent('on.rewarded.failed.show', ${errorData});")
|
2167
2147
|
}
|
2168
2148
|
|
2169
2149
|
override fun onAdImpression() {
|
2170
|
-
cWebView
|
2150
|
+
cWebView?.loadUrl("javascript:cordova.fireDocumentEvent('on.rewarded.impression');")
|
2171
2151
|
}
|
2172
2152
|
|
2173
2153
|
override fun onAdShowedFullScreenContent() {
|
2174
2154
|
isAdSkip = 1
|
2175
|
-
cWebView
|
2155
|
+
cWebView?.loadUrl("javascript:cordova.fireDocumentEvent('on.rewarded.show');")
|
2176
2156
|
}
|
2177
2157
|
}
|
2178
2158
|
}
|
@@ -2180,20 +2160,20 @@ class emiAdmobPlugin : CordovaPlugin() {
|
|
2180
2160
|
private fun rewardedInterstitialAdLoadCallback() {
|
2181
2161
|
rewardedInterstitialAd?.fullScreenContentCallback = object : FullScreenContentCallback() {
|
2182
2162
|
override fun onAdClicked() {
|
2183
|
-
cWebView
|
2163
|
+
cWebView?.loadUrl("javascript:cordova.fireDocumentEvent('on.rewardedInt.click');")
|
2184
2164
|
}
|
2185
2165
|
|
2186
2166
|
override fun onAdDismissedFullScreenContent() {
|
2187
2167
|
if (isAdSkip != 2) {
|
2188
2168
|
rewardedInterstitialAd = null
|
2189
2169
|
isRewardedInterstitialLoad = false
|
2190
|
-
cWebView
|
2170
|
+
cWebView?.loadUrl("javascript:cordova.fireDocumentEvent('on.rewardedInt.ad.skip');")
|
2191
2171
|
}
|
2192
2172
|
rewardedInterstitialAd = null
|
2193
2173
|
isRewardedInterstitialLoad = false
|
2194
2174
|
val mainView: View? = view
|
2195
2175
|
mainView?.requestFocus()
|
2196
|
-
cWebView
|
2176
|
+
cWebView?.loadUrl("javascript:cordova.fireDocumentEvent('on.rewardedInt.dismissed');")
|
2197
2177
|
}
|
2198
2178
|
|
2199
2179
|
override fun onAdFailedToShowFullScreenContent(adError: AdError) {
|
@@ -2205,17 +2185,16 @@ class emiAdmobPlugin : CordovaPlugin() {
|
|
2205
2185
|
put("domain", adError.domain)
|
2206
2186
|
put("cause", adError.cause?.toString() ?: "null")
|
2207
2187
|
}
|
2208
|
-
cWebView
|
2188
|
+
cWebView?.loadUrl("javascript:cordova.fireDocumentEvent('on.rewardedInt.failed.show', ${errorData});")
|
2209
2189
|
}
|
2210
2190
|
|
2211
2191
|
override fun onAdImpression() {
|
2212
|
-
cWebView
|
2192
|
+
cWebView?.loadUrl("javascript:cordova.fireDocumentEvent('on.rewardedInt.impression');")
|
2213
2193
|
}
|
2214
2194
|
|
2215
2195
|
override fun onAdShowedFullScreenContent() {
|
2216
2196
|
isAdSkip = 1
|
2217
|
-
|
2218
|
-
cWebView!!.loadUrl("javascript:cordova.fireDocumentEvent('on.rewardedInt.showed');")
|
2197
|
+
cWebView?.loadUrl("javascript:cordova.fireDocumentEvent('on.rewardedInt.showed');")
|
2219
2198
|
}
|
2220
2199
|
}
|
2221
2200
|
}
|
@@ -2226,11 +2205,7 @@ class emiAdmobPlugin : CordovaPlugin() {
|
|
2226
2205
|
MobileAds.putPublisherFirstPartyIdEnabled(pubIdEnabled)
|
2227
2206
|
}
|
2228
2207
|
|
2229
|
-
private fun targeting(
|
2230
|
-
childDirectedTreatment: Boolean,
|
2231
|
-
underAgeOfConsent: Boolean,
|
2232
|
-
contentRating: String?
|
2233
|
-
) {
|
2208
|
+
private fun targeting(childDirectedTreatment: Boolean, underAgeOfConsent: Boolean, contentRating: String) {
|
2234
2209
|
val requestConfiguration = MobileAds.getRequestConfiguration().toBuilder()
|
2235
2210
|
requestConfiguration.setTagForChildDirectedTreatment(if (childDirectedTreatment) RequestConfiguration.TAG_FOR_CHILD_DIRECTED_TREATMENT_TRUE else RequestConfiguration.TAG_FOR_CHILD_DIRECTED_TREATMENT_FALSE)
|
2236
2211
|
requestConfiguration.setTagForUnderAgeOfConsent(if (underAgeOfConsent) RequestConfiguration.TAG_FOR_UNDER_AGE_OF_CONSENT_TRUE else RequestConfiguration.TAG_FOR_UNDER_AGE_OF_CONSENT_FALSE)
|
@@ -2244,8 +2219,7 @@ class emiAdmobPlugin : CordovaPlugin() {
|
|
2244
2219
|
MobileAds.setRequestConfiguration(requestConfiguration.build())
|
2245
2220
|
}
|
2246
2221
|
|
2247
|
-
private val isPrivacyOptionsRequired: ConsentInformation.PrivacyOptionsRequirementStatus
|
2248
|
-
get() = consentInformation?.getPrivacyOptionsRequirementStatus() ?: ConsentInformation.PrivacyOptionsRequirementStatus.REQUIRED
|
2222
|
+
private val isPrivacyOptionsRequired: ConsentInformation.PrivacyOptionsRequirementStatus get() = consentInformation?.getPrivacyOptionsRequirementStatus() ?: ConsentInformation.PrivacyOptionsRequirementStatus.REQUIRED
|
2249
2223
|
|
2250
2224
|
|
2251
2225
|
|
@@ -2264,17 +2238,225 @@ class emiAdmobPlugin : CordovaPlugin() {
|
|
2264
2238
|
|
2265
2239
|
|
2266
2240
|
|
2241
|
+
// Still under development
|
2242
|
+
// START loadBannerAdNewApi
|
2243
|
+
|
2244
|
+
|
2245
|
+
private fun setBannerAdNewApi(currentAdSize: AdSize) {
|
2246
|
+
|
2247
|
+
if (loadBannerAdNew && isPosition.equals("top-center", ignoreCase = true)) {
|
2248
|
+
|
2249
|
+
setBannerAdNewApiTop() // loadBannerAdNewApi
|
2250
|
+
|
2251
|
+
} else if (loadBannerAdNew && isPosition.equals("bottom-center", ignoreCase = true)) {
|
2252
|
+
|
2253
|
+
setBannerAdNewApiBottom(currentAdSize) // loadBannerAdNewApi
|
2254
|
+
|
2255
|
+
}
|
2256
|
+
}
|
2257
|
+
|
2258
|
+
|
2259
|
+
|
2260
|
+
private fun isFullScreenMode(activity: Activity): Boolean {
|
2261
|
+
return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
|
2262
|
+
activity.window.decorView.rootWindowInsets?.isVisible(WindowInsets.Type.statusBars()) == false
|
2263
|
+
} else {
|
2264
|
+
@Suppress("DEPRECATION")
|
2265
|
+
(activity.window.attributes.flags and WindowManager.LayoutParams.FLAG_FULLSCREEN) != 0
|
2266
|
+
}
|
2267
|
+
}
|
2268
|
+
|
2269
|
+
|
2270
|
+
|
2271
|
+
@SuppressLint("DiscouragedApi", "InternalInsetResource")
|
2272
|
+
private fun getNavigationBarHeight(context: Context): Int {
|
2273
|
+
return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
|
2274
|
+
// Preferred method for API 30+
|
2275
|
+
val windowMetrics = context.getSystemService(WindowManager::class.java).currentWindowMetrics
|
2276
|
+
val insets = windowMetrics.windowInsets.getInsetsIgnoringVisibility(
|
2277
|
+
WindowInsets.Type.navigationBars()
|
2278
|
+
)
|
2279
|
+
insets.bottom
|
2280
|
+
} else {
|
2281
|
+
val resources = context.resources
|
2282
|
+
val resourceId = resources.getIdentifier("navigation_bar_height", "dimen", "android")
|
2283
|
+
if (resourceId > 0) resources.getDimensionPixelSize(resourceId) else 0
|
2284
|
+
}
|
2285
|
+
}
|
2286
|
+
|
2287
|
+
|
2288
|
+
|
2289
|
+
private fun getScreenMetrics(): Pair<Int, Int> {
|
2290
|
+
mActivity?.let { activity ->
|
2291
|
+
return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
|
2292
|
+
val windowMetrics = activity.windowManager.currentWindowMetrics
|
2293
|
+
val insets = windowMetrics.windowInsets
|
2294
|
+
.getInsetsIgnoringVisibility(WindowInsets.Type.navigationBars())
|
2295
|
+
val screenHeight = windowMetrics.bounds.height()
|
2296
|
+
|
2297
|
+
val usableHeight = screenHeight - insets.bottom
|
2298
|
+
Pair(screenHeight, usableHeight)
|
2299
|
+
} else {
|
2300
|
+
@Suppress("DEPRECATION")
|
2301
|
+
val display = activity.windowManager.defaultDisplay
|
2302
|
+
val size = Point()
|
2303
|
+
val realSize = Point()
|
2304
|
+
@Suppress("DEPRECATION")
|
2305
|
+
display.getSize(size)
|
2306
|
+
@Suppress("DEPRECATION")
|
2307
|
+
display.getRealSize(realSize)
|
2308
|
+
|
2309
|
+
Pair(realSize.y, size.y)
|
2310
|
+
}
|
2311
|
+
} ?: throw IllegalStateException("Activity is null")
|
2312
|
+
}
|
2313
|
+
|
2314
|
+
|
2315
|
+
private fun setBannerAdNewApiBottom(adSize: AdSize) {
|
2316
|
+
|
2317
|
+
mActivity?.let { activity ->
|
2318
|
+
|
2319
|
+
val bannerHeightPx = adSize.getHeightInPixels(activity)
|
2320
|
+
|
2321
|
+
val (screenHeight, usableHeight) = getScreenMetrics()
|
2322
|
+
|
2323
|
+
val navBarHeight = if (!isFullScreen) getNavigationBarHeight(activity) else 0
|
2324
|
+
|
2325
|
+
val adjustment = (bannerHeightPx * 0.3).toInt()
|
2326
|
+
|
2327
|
+
val newWebViewHeight = if (isFullScreen) {
|
2328
|
+
if (bannerOverlapping) {
|
2329
|
+
screenHeight - 0
|
2330
|
+
} else {
|
2331
|
+
screenHeight - bannerHeightPx
|
2332
|
+
}
|
2333
|
+
} else {
|
2334
|
+
if (bannerOverlapping) {
|
2335
|
+
usableHeight - 0 //navBarHeight - bannerHeightPx
|
2336
|
+
} else {
|
2337
|
+
usableHeight - navBarHeight - bannerHeightPx + adjustment
|
2338
|
+
}
|
2339
|
+
}
|
2340
|
+
|
2341
|
+
if (!bannerOverlapping) {
|
2342
|
+
cWebView?.let { webView ->
|
2343
|
+
val layoutParams = webView.view.layoutParams
|
2344
|
+
layoutParams.height = newWebViewHeight.coerceAtLeast(0)
|
2345
|
+
webView.view.layoutParams = layoutParams
|
2346
|
+
webView.view.requestLayout()
|
2347
|
+
}
|
2348
|
+
}
|
2349
|
+
|
2350
|
+
|
2351
|
+
|
2352
|
+
if (!isFullScreen) {
|
2353
|
+
bannerViewLayout?.let { container ->
|
2354
|
+
container.post {
|
2355
|
+
val params = container.layoutParams
|
2356
|
+
if (params is ViewGroup.MarginLayoutParams) {
|
2357
|
+
params.bottomMargin = if (!isFullScreen) navBarHeight else 0
|
2358
|
+
container.layoutParams = params
|
2359
|
+
container.requestLayout()
|
2360
|
+
}
|
2361
|
+
}
|
2362
|
+
}
|
2363
|
+
}
|
2364
|
+
|
2365
|
+
|
2366
|
+
}
|
2367
|
+
}
|
2368
|
+
|
2369
|
+
|
2370
|
+
|
2371
|
+
|
2372
|
+
|
2373
|
+
|
2374
|
+
private fun setBannerAdNewApiTop() {
|
2375
|
+
mActivity?.let { activity ->
|
2376
|
+
bannerView?.post {
|
2377
|
+
val bannerHeightPx = bannerView?.height ?: 0
|
2378
|
+
val statusBarHeight = getStatusBarHeight(activity)
|
2379
|
+
|
2380
|
+
if (isPosition.equals("top-center", ignoreCase = true)) {
|
2381
|
+
val bannerLp = bannerView?.layoutParams as? FrameLayout.LayoutParams
|
2382
|
+
bannerLp?.let { lp ->
|
2383
|
+
if (bannerOverlapping) {
|
2384
|
+
if (isFullScreen) {
|
2385
|
+
lp.topMargin = 0
|
2386
|
+
bannerView?.layoutParams = lp
|
2387
|
+
} else {
|
2388
|
+
lp.topMargin = 0 // bannerHeightPx // + statusBarHeight
|
2389
|
+
bannerView?.layoutParams = lp
|
2390
|
+
}
|
2391
|
+
} else {
|
2392
|
+
if (isFullScreen) {
|
2393
|
+
lp.topMargin = 0
|
2394
|
+
bannerView?.layoutParams = lp
|
2395
|
+
} else {
|
2396
|
+
lp.topMargin = statusBarHeight
|
2397
|
+
bannerView?.layoutParams = lp
|
2398
|
+
}
|
2399
|
+
}
|
2400
|
+
|
2401
|
+
}
|
2402
|
+
}
|
2403
|
+
|
2404
|
+
cWebView?.let { webView ->
|
2405
|
+
val webLp = webView.view.layoutParams as FrameLayout.LayoutParams
|
2406
|
+
if (isPosition.equals("top-center", ignoreCase = true)) {
|
2407
|
+
|
2408
|
+
if (bannerOverlapping) {
|
2409
|
+
if (isFullScreen) {
|
2410
|
+
webLp.topMargin = 0 //+ statusBarHeight
|
2411
|
+
} else {
|
2412
|
+
webLp.topMargin = 0 //bannerHeightPx // + statusBarHeight
|
2413
|
+
}
|
2414
|
+
} else {
|
2415
|
+
if (isFullScreen) {
|
2416
|
+
webLp.topMargin = bannerHeightPx
|
2417
|
+
} else {
|
2418
|
+
webLp.topMargin = bannerHeightPx
|
2419
|
+
}
|
2420
|
+
}
|
2421
|
+
|
2422
|
+
|
2423
|
+
}
|
2424
|
+
|
2425
|
+
webView.view.layoutParams = webLp
|
2426
|
+
webView.view.requestLayout()
|
2427
|
+
}
|
2428
|
+
}}
|
2429
|
+
}
|
2430
|
+
|
2431
|
+
|
2432
|
+
|
2433
|
+
|
2434
|
+
|
2435
|
+
@SuppressLint("InternalInsetResource")
|
2436
|
+
private fun getStatusBarHeight(context: Context): Int {
|
2437
|
+
var result = 0
|
2438
|
+
val resourceId = context.resources.getIdentifier("status_bar_height", "dimen", "android")
|
2439
|
+
if (resourceId > 0) {
|
2440
|
+
result = context.resources.getDimensionPixelSize(resourceId)
|
2441
|
+
}
|
2442
|
+
return result
|
2443
|
+
}
|
2444
|
+
|
2445
|
+
|
2446
|
+
// END loadBannerAdNewApi
|
2447
|
+
|
2448
|
+
|
2267
2449
|
private val view: View?
|
2268
2450
|
get() {
|
2269
2451
|
if (View::class.java.isAssignableFrom(CordovaWebView::class.java)) {
|
2270
2452
|
return cWebView as View?
|
2271
2453
|
}
|
2272
|
-
return mActivity
|
2454
|
+
return mActivity?.window?.decorView?.findViewById(View.generateViewId())
|
2273
2455
|
}
|
2274
2456
|
|
2275
2457
|
override fun onPause(multitasking: Boolean) {
|
2276
2458
|
if (bannerView != null) {
|
2277
|
-
bannerView
|
2459
|
+
bannerView?.pause()
|
2278
2460
|
}
|
2279
2461
|
|
2280
2462
|
super.onPause(multitasking)
|
@@ -2283,7 +2465,7 @@ class emiAdmobPlugin : CordovaPlugin() {
|
|
2283
2465
|
override fun onResume(multitasking: Boolean) {
|
2284
2466
|
super.onResume(multitasking)
|
2285
2467
|
if (bannerView != null) {
|
2286
|
-
bannerView
|
2468
|
+
bannerView?.resume()
|
2287
2469
|
}
|
2288
2470
|
}
|
2289
2471
|
|
@@ -2293,11 +2475,11 @@ class emiAdmobPlugin : CordovaPlugin() {
|
|
2293
2475
|
|
2294
2476
|
override fun onDestroy() {
|
2295
2477
|
if (bannerView != null) {
|
2296
|
-
bannerView
|
2478
|
+
bannerView?.destroy()
|
2297
2479
|
bannerView = null
|
2298
2480
|
}
|
2299
2481
|
if (bannerViewLayout != null) {
|
2300
|
-
val parentView = bannerViewLayout
|
2482
|
+
val parentView = bannerViewLayout?.parent as ViewGroup
|
2301
2483
|
parentView.removeView(bannerViewLayout)
|
2302
2484
|
bannerViewLayout = null
|
2303
2485
|
}
|