emi-indo-cordova-plugin-admob 1.5.2 → 1.5.3

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 CHANGED
@@ -8,7 +8,7 @@
8
8
 
9
9
  ### Mobile Ads SDK (IOS: 11.10.0) [Release Notes:](https://developers.google.com/admob/ios/rel-notes)
10
10
 
11
- ### User Messaging Platform Android (UMP IOS: 2.6.0) [Release Notes:](https://developers.google.com/ad-manager/mobile-ads-sdk/ios/privacy/download)
11
+ ### User Messaging Platform (UMP IOS: 2.6.0) [Release Notes:](https://developers.google.com/ad-manager/mobile-ads-sdk/ios/privacy/download)
12
12
  ### IAB Europe Transparency & Consent Framework (CPM: 2.2.0)
13
13
 
14
14
 
@@ -380,8 +380,8 @@ autoShow: false
380
380
  cordova.plugins.emiAdmobPlugin.loadAppOpenAd({config});
381
381
  cordova.plugins.emiAdmobPlugin.showAppOpenAd(); // default
382
382
 
383
- // Advanced Show (Optional)
384
- cordova.plugins.emiAdmobPlugin.showAppOpenAd(
383
+ // Advanced load (Optional)
384
+ cordova.plugins.emiAdmobPlugin.loadAppOpenAd(config,
385
385
 
386
386
  (data) => {
387
387
 
@@ -472,7 +472,7 @@ const bannerConfig = [
472
472
  */
473
473
 
474
474
  // NEW
475
-
475
+ ```
476
476
  const bannerConfig = {
477
477
 
478
478
  adUnitId: "ca-app-pub-3940256099942544/9214589741", //Banner_ID,
@@ -484,14 +484,10 @@ const bannerConfig = {
484
484
 
485
485
  }
486
486
 
487
- cordova.plugins.emiAdmobPlugin.loadBannerAd(bannerConfig);
488
-
489
-
490
- // Advanced Show (Optional)
491
- cordova.plugins.emiAdmobPlugin.showBannerAd(
492
-
493
- (data) => {
494
-
487
+ cordova.plugins.emiAdmobPlugin.loadBannerAd(bannerConfig,
488
+ // Advanced load (Optional)
489
+ (data) => {
490
+ // this data will be displayed after showBannerAd() applies to all ad types
495
491
  console.log("Micros: " + data.micros);
496
492
  console.log("Currency: " + data.currency);
497
493
  console.log("Precision: " + data.precision);
@@ -502,7 +498,11 @@ cordova.plugins.emiAdmobPlugin.loadBannerAd(bannerConfig);
502
498
 
503
499
  console.error("Error: " + error);
504
500
 
505
- });
501
+ }
502
+
503
+ );
504
+ ```
505
+
506
506
 
507
507
  </pre>
508
508
  </details>
@@ -593,8 +593,8 @@ console.log("Collapsible Status: " + event.collapsible);
593
593
  cordova.plugins.emiAdmobPlugin.loadInterstitialAd({config});
594
594
  cordova.plugins.emiAdmobPlugin.showInterstitialAd(); // default
595
595
 
596
- // Advanced Show (Optional)
597
- cordova.plugins.emiAdmobPlugin.showInterstitialAd(
596
+ // Advanced load (Optional)
597
+ cordova.plugins.emiAdmobPlugin.loadInterstitialAd(config,
598
598
 
599
599
  (data) => {
600
600
 
@@ -688,8 +688,8 @@ cordova.plugins.emiAdmobPlugin.showRewardedInterstitialAd(); // default
688
688
 
689
689
  cordova.plugins.emiAdmobPlugin.loadRewardedInterstitialAd({ adUnitId: Rewarded_Interstitial_ID, autoShow: true });
690
690
 
691
- // Advanced Show (Optional)
692
- cordova.plugins.emiAdmobPlugin.showRewardedInterstitialAd(
691
+ // Advanced load (Optional)
692
+ cordova.plugins.emiAdmobPlugin.loadRewardedInterstitialAd(config,
693
693
 
694
694
  (data) => {
695
695
 
@@ -769,8 +769,8 @@ cordova.plugins.emiAdmobPlugin.showRewardedAd(); // default
769
769
 
770
770
  cordova.plugins.emiAdmobPlugin.loadRewardedAd({ adUnitId: Rewarded_ID, autoShow: true });
771
771
 
772
- // Advanced Show (Optional)
773
- cordova.plugins.emiAdmobPlugin.showRewardedAd(
772
+ // Advanced load (Optional)
773
+ cordova.plugins.emiAdmobPlugin.loadRewardedAd(config,
774
774
 
775
775
  (data) => {
776
776
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "emi-indo-cordova-plugin-admob",
3
- "version": "1.5.2",
3
+ "version": "1.5.3",
4
4
  "description": "Cordova Plugin Admob Android IOS",
5
5
  "cordova": {
6
6
  "id": "emi-indo-cordova-plugin-admob",
package/plugin.xml CHANGED
@@ -1,6 +1,6 @@
1
1
  <plugin xmlns="http://apache.org/cordova/ns/plugins/1.0"
2
2
  xmlns:android="http://schemas.android.com/apk/res/android"
3
- id="emi-indo-cordova-plugin-admob" version="1.5.2">
3
+ id="emi-indo-cordova-plugin-admob" version="1.5.3">
4
4
 
5
5
  <name>emiAdmobPlugin</name>
6
6
  <description>Cordova Plugin Admob Android IOS</description>
@@ -26,6 +26,7 @@
26
26
  <config-file parent="/*" target="res/xml/config.xml">
27
27
  <feature name="emiAdmobPlugin">
28
28
  <param name="android-package" value="emi.indo.cordova.plugin.admob.emiAdmobPlugin" />
29
+ <param name="onload" value="true" />
29
30
  </feature>
30
31
  </config-file>
31
32
 
@@ -6,13 +6,16 @@ import android.content.Context
6
6
  import android.content.Intent
7
7
  import android.content.SharedPreferences
8
8
  import android.content.res.Configuration
9
+ import android.os.Build
9
10
  import android.os.Bundle
10
11
  import android.provider.Settings
11
12
  import android.util.DisplayMetrics
12
13
  import android.util.Log
14
+ import android.view.Gravity
13
15
  import android.view.View
14
16
  import android.view.ViewGroup
15
- import android.widget.RelativeLayout
17
+ import android.view.WindowInsets
18
+ import android.widget.FrameLayout
16
19
  import androidx.preference.PreferenceManager
17
20
  import com.google.ads.mediation.admob.AdMobAdapter
18
21
  import com.google.android.gms.ads.AdError
@@ -70,21 +73,20 @@ class emiAdmobPlugin : CordovaPlugin() {
70
73
  private var isRewardedInterstitialLoad = false
71
74
  private var isRewardedLoad = false
72
75
  private var isBannerPause = 0
73
- private var Position: String? = null
74
- private var Size: String? = null
76
+ private var isPosition: String? = null
77
+ private var isSize: String? = null
75
78
 
76
79
  private var paddingInPx = 0
77
80
  private var marginsInPx = 0
78
- var ResponseInfo: Boolean = false
81
+ var isResponseInfo: Boolean = false
79
82
  private var isAdSkip = 0
80
- private var SetTagForChildDirectedTreatment: Boolean = false
81
- private var SetTagForUnderAgeOfConsent: Boolean = false
82
- private var SetMaxAdContentRating: String = "G"
83
+ private var isSetTagForChildDirectedTreatment: Boolean = false
84
+ private var isSetTagForUnderAgeOfConsent: Boolean = false
85
+ private var isSetMaxAdContentRating: String = "G"
83
86
  private var bannerAdUnitId: String? = null
84
87
 
85
88
  private var consentInformation: ConsentInformation? = null
86
- private var bannerViewLayout: RelativeLayout? = null
87
- private var bannerView: AdView? = null
89
+
88
90
  var isBannerLoad: Boolean = false
89
91
  var isBannerShow: Boolean = false
90
92
 
@@ -123,6 +125,8 @@ class emiAdmobPlugin : CordovaPlugin() {
123
125
  private var brandSafetyEnabled: Boolean = false
124
126
  private var brandSafetyUrls: MutableList<String>? = null
125
127
 
128
+ private var bannerViewLayout: FrameLayout? = null
129
+ private var bannerView: AdView? = null
126
130
 
127
131
  private val isMobileAdsInitializeCalled = AtomicBoolean(false)
128
132
 
@@ -138,8 +142,11 @@ class emiAdmobPlugin : CordovaPlugin() {
138
142
  }
139
143
 
140
144
  mPreferences = mContext?.let { PreferenceManager.getDefaultSharedPreferences(it) }
145
+
141
146
  }
142
147
 
148
+
149
+
143
150
  override fun onConfigurationChanged(newConfig: Configuration) {
144
151
  super.onConfigurationChanged(newConfig)
145
152
  val orientation = newConfig.orientation
@@ -151,25 +158,25 @@ class emiAdmobPlugin : CordovaPlugin() {
151
158
  try {
152
159
  if (bannerViewLayout != null && bannerView != null) {
153
160
  val parentView = bannerViewLayout!!.parent as ViewGroup
154
- parentView?.removeView(bannerViewLayout)
155
- bannerViewLayout = RelativeLayout(mActivity)
156
- val params = RelativeLayout.LayoutParams(
157
- RelativeLayout.LayoutParams.MATCH_PARENT,
158
- RelativeLayout.LayoutParams.WRAP_CONTENT
161
+ parentView.removeView(bannerViewLayout)
162
+ bannerViewLayout = FrameLayout(mActivity!!)
163
+ val params = FrameLayout.LayoutParams(
164
+ FrameLayout.LayoutParams.MATCH_PARENT,
165
+ FrameLayout.LayoutParams.WRAP_CONTENT
159
166
  )
160
- val rootView =
161
- mActivity!!.window.decorView.findViewById<View>(R.id.content)
167
+ val rootView = mActivity!!.window.decorView.findViewById<View>(View.generateViewId())
162
168
  if (rootView is ViewGroup) {
163
169
  rootView.addView(bannerViewLayout, params)
164
170
  } else {
165
171
  mActivity!!.addContentView(bannerViewLayout, params)
166
172
  }
167
173
  bannerView = AdView(mContext!!)
168
- setBannerPosition(this.Position)
169
- setBannerSiz(this.Size)
174
+ setBannerPosition(this.isPosition)
175
+ setBannerSiz(this.isSize)
170
176
  bannerView!!.adUnitId = bannerAdUnitId!!
171
177
  bannerView!!.adListener = bannerAdListener
172
178
  bannerView!!.loadAd(buildAdRequest())
179
+ adjustWebViewForBanner(this.isPosition)
173
180
  bannerViewLayout!!.addView(bannerView)
174
181
  bannerViewLayout!!.bringToFront()
175
182
  }
@@ -179,17 +186,24 @@ class emiAdmobPlugin : CordovaPlugin() {
179
186
  }
180
187
  }
181
188
 
182
- if (orientation == Configuration.ORIENTATION_PORTRAIT) {
183
- cWebView!!.loadUrl("javascript:cordova.fireDocumentEvent('on.orientation.portrait');")
184
- } else if (orientation == Configuration.ORIENTATION_LANDSCAPE) {
185
- cWebView!!.loadUrl("javascript:cordova.fireDocumentEvent('on.orientation.landscape');")
186
- } else if (orientation == Configuration.ORIENTATION_UNDEFINED) {
187
- cWebView!!.loadUrl("javascript:cordova.fireDocumentEvent('on.orientation.undefined');")
189
+ when (orientation) {
190
+ Configuration.ORIENTATION_PORTRAIT -> {
191
+ cWebView!!.loadUrl("javascript:cordova.fireDocumentEvent('on.orientation.portrait');")
192
+ }
193
+ Configuration.ORIENTATION_LANDSCAPE -> {
194
+ cWebView!!.loadUrl("javascript:cordova.fireDocumentEvent('on.orientation.landscape');")
195
+ }
196
+ Configuration.ORIENTATION_UNDEFINED -> {
197
+ cWebView!!.loadUrl("javascript:cordova.fireDocumentEvent('on.orientation.undefined');")
198
+ }
199
+
200
+
188
201
  }
189
202
  }
190
203
  }
191
204
 
192
205
 
206
+
193
207
  @Throws(JSONException::class)
194
208
  override fun execute(
195
209
  action: String,
@@ -205,7 +219,7 @@ class emiAdmobPlugin : CordovaPlugin() {
205
219
  val responseInfo = options.optBoolean("isResponseInfo")
206
220
  val setDebugGeography = options.optBoolean("isConsentDebug")
207
221
  setUsingAdManagerRequest(setAdRequest)
208
- this.ResponseInfo = responseInfo
222
+ this.isResponseInfo = responseInfo
209
223
  this.setDebugGeography = setDebugGeography
210
224
  val params: ConsentRequestParameters
211
225
  if (this.setDebugGeography) {
@@ -220,7 +234,7 @@ class emiAdmobPlugin : CordovaPlugin() {
220
234
  .setConsentDebugSettings(debugSettings).build()
221
235
  } else {
222
236
  params = ConsentRequestParameters.Builder()
223
- .setTagForUnderAgeOfConsent(this.SetTagForUnderAgeOfConsent).build()
237
+ .setTagForUnderAgeOfConsent(this.isSetTagForUnderAgeOfConsent).build()
224
238
  }
225
239
 
226
240
  consentInformation = mContext?.let { UserMessagingPlatform.getConsentInformation(it) }
@@ -261,10 +275,10 @@ class emiAdmobPlugin : CordovaPlugin() {
261
275
  val childDirectedTreatment = options.optBoolean("childDirectedTreatment")
262
276
  val underAgeOfConsent = options.optBoolean("underAgeOfConsent")
263
277
  val contentRating = options.optString("contentRating")
264
- this.SetTagForChildDirectedTreatment = childDirectedTreatment
265
- this.SetTagForUnderAgeOfConsent = underAgeOfConsent
266
- this.SetMaxAdContentRating = contentRating
267
- _Targeting(childDirectedTreatment, underAgeOfConsent, contentRating)
278
+ this.isSetTagForChildDirectedTreatment = childDirectedTreatment
279
+ this.isSetTagForUnderAgeOfConsent = underAgeOfConsent
280
+ this.isSetMaxAdContentRating = contentRating
281
+ Targeting(childDirectedTreatment, underAgeOfConsent, contentRating)
268
282
  // callbackContext.success();
269
283
  } catch (e: Exception) {
270
284
  callbackContext.error("Error: " + e.message)
@@ -342,7 +356,7 @@ class emiAdmobPlugin : CordovaPlugin() {
342
356
  val setAppVolume = options.optInt("setAppVolume").toFloat()
343
357
  val pubIdEnabled = options.optBoolean("pubIdEnabled")
344
358
  try {
345
- _globalSettings(setAppMuted, setAppVolume, pubIdEnabled)
359
+ globalSettings(setAppMuted, setAppVolume, pubIdEnabled)
346
360
  // callbackContext.success();
347
361
  } catch (e: Exception) {
348
362
  callbackContext.error(e.toString())
@@ -359,15 +373,16 @@ class emiAdmobPlugin : CordovaPlugin() {
359
373
  AppOpenAd.load(
360
374
  mActivity!!, adUnitId, buildAdRequest(),
361
375
  object : AppOpenAdLoadCallback() {
376
+ @SuppressLint("DefaultLocale")
362
377
  override fun onAdLoaded(ad: AppOpenAd) {
363
378
  appOpenAd = ad
364
379
  isAppOpenAdShow = true
365
380
 
366
381
  if (appOpenAutoShow) {
367
- OpenAutoShow()
382
+ openAutoShow()
368
383
  }
369
384
 
370
- _appOpenAdLoadCallback(callbackContext)
385
+ appOpenAdLoadCallback(callbackContext)
371
386
 
372
387
  appOpenAd!!.onPaidEventListener =
373
388
  OnPaidEventListener { adValue: AdValue ->
@@ -375,6 +390,7 @@ class emiAdmobPlugin : CordovaPlugin() {
375
390
  val currencyCode = adValue.currencyCode
376
391
  val precision = adValue.precisionType
377
392
  val appOpenAdAdUnitId = appOpenAd!!.adUnitId
393
+
378
394
  val result = JSONObject()
379
395
  try {
380
396
  result.put("micros", valueMicros)
@@ -382,17 +398,14 @@ class emiAdmobPlugin : CordovaPlugin() {
382
398
  result.put("precision", precision)
383
399
  result.put("adUnitId", appOpenAdAdUnitId)
384
400
  callbackContext.success(result)
385
- cWebView!!.loadUrl(
386
- "javascript:cordova.fireDocumentEvent('on.appOpenAd.revenue');"
387
- )
401
+ cWebView!!.loadUrl("javascript:cordova.fireDocumentEvent('on.appOpenAd.revenue')")
402
+
388
403
  } catch (e: JSONException) {
389
404
  callbackContext.error(e.message)
390
405
  }
391
406
  }
392
- cWebView!!.loadUrl(
393
- "javascript:cordova.fireDocumentEvent('on.appOpenAd.loaded');"
394
- )
395
- if (ResponseInfo) {
407
+
408
+ if (isResponseInfo) {
396
409
  val result = JSONObject()
397
410
  val responseInfo = ad.responseInfo
398
411
  try {
@@ -412,9 +425,14 @@ class emiAdmobPlugin : CordovaPlugin() {
412
425
  callbackContext.error(e.message)
413
426
  }
414
427
  }
428
+
429
+ cWebView!!.loadUrl(
430
+ "javascript:cordova.fireDocumentEvent('on.appOpenAd.loaded');"
431
+ )
432
+
415
433
  }
416
434
 
417
- private fun OpenAutoShow() {
435
+ private fun openAutoShow() {
418
436
  try {
419
437
  if (isAppOpenAdShow && appOpenAd != null) {
420
438
  mActivity!!.runOnUiThread { appOpenAd!!.show(mActivity!!) }
@@ -441,7 +459,7 @@ class emiAdmobPlugin : CordovaPlugin() {
441
459
  try {
442
460
  if (isAppOpenAdShow && appOpenAd != null) {
443
461
  mActivity!!.runOnUiThread { appOpenAd!!.show(mActivity!!) }
444
- _appOpenAdLoadCallback(callbackContext)
462
+ appOpenAdLoadCallback(callbackContext)
445
463
  } else {
446
464
  callbackContext.error("The App Open Ad wasn't ready yet")
447
465
  }
@@ -468,12 +486,12 @@ class emiAdmobPlugin : CordovaPlugin() {
468
486
  isIntAutoShow
469
487
  }
470
488
 
471
- _interstitialAdLoadCallback(callbackContext)
489
+ interstitialAdLoadCallback(callbackContext)
472
490
 
473
491
  cWebView!!.loadUrl(
474
492
  "javascript:cordova.fireDocumentEvent('on.interstitial.loaded');"
475
493
  )
476
- if (ResponseInfo) {
494
+ if (isResponseInfo) {
477
495
  val result = JSONObject()
478
496
  val responseInfo = mInterstitialAd!!.responseInfo
479
497
  try {
@@ -539,7 +557,7 @@ class emiAdmobPlugin : CordovaPlugin() {
539
557
  } else if (action == "showInterstitialAd") {
540
558
  if (isInterstitialLoad && mInterstitialAd != null) {
541
559
  mActivity!!.runOnUiThread { mInterstitialAd!!.show(mActivity!!) }
542
- _interstitialAdLoadCallback(callbackContext)
560
+ interstitialAdLoadCallback(callbackContext)
543
561
  } else {
544
562
  callbackContext.error("The Interstitial ad wasn't ready yet")
545
563
  }
@@ -571,8 +589,8 @@ class emiAdmobPlugin : CordovaPlugin() {
571
589
  isRewardedAutoShow
572
590
  }
573
591
  cWebView!!.loadUrl("javascript:cordova.fireDocumentEvent('on.rewarded.loaded');")
574
- _rewardedAdLoadCallback(callbackContext)
575
- if (ResponseInfo) {
592
+ rewardedAdLoadCallback(callbackContext)
593
+ if (isResponseInfo) {
576
594
  val result = JSONObject()
577
595
  val responseInfo = ad.responseInfo
578
596
  try {
@@ -661,7 +679,7 @@ class emiAdmobPlugin : CordovaPlugin() {
661
679
  }
662
680
  cWebView!!.loadUrl("javascript:cordova.fireDocumentEvent('on.reward.userEarnedReward');")
663
681
  }
664
- _rewardedAdLoadCallback(callbackContext)
682
+ rewardedAdLoadCallback(callbackContext)
665
683
  } else {
666
684
  callbackContext.error("The rewarded ad wasn't ready yet")
667
685
  }
@@ -685,7 +703,7 @@ class emiAdmobPlugin : CordovaPlugin() {
685
703
  if (rIntAutoShow) {
686
704
  isRIntAutoShow
687
705
  }
688
- _rewardedInterstitialAdLoadCallback(callbackContext)
706
+ rewardedInterstitialAdLoadCallback(callbackContext)
689
707
  responseAdLoad()
690
708
  revenueAd()
691
709
 
@@ -719,7 +737,7 @@ class emiAdmobPlugin : CordovaPlugin() {
719
737
  }
720
738
 
721
739
  private fun responseAdLoad() {
722
- if (ResponseInfo) {
740
+ if (isResponseInfo) {
723
741
  val result = JSONObject()
724
742
  val responseInfo = rewardedInterstitialAd!!.responseInfo
725
743
  try {
@@ -799,7 +817,7 @@ class emiAdmobPlugin : CordovaPlugin() {
799
817
  )
800
818
  }
801
819
 
802
- _rewardedInterstitialAdLoadCallback(callbackContext)
820
+ rewardedInterstitialAdLoadCallback(callbackContext)
803
821
  } else {
804
822
  callbackContext.error("The rewarded ad wasn't ready yet")
805
823
  }
@@ -821,7 +839,7 @@ class emiAdmobPlugin : CordovaPlugin() {
821
839
  .setConsentDebugSettings(debugSettings).build()
822
840
  } else {
823
841
  params = ConsentRequestParameters.Builder()
824
- .setTagForUnderAgeOfConsent(this.SetTagForUnderAgeOfConsent).build()
842
+ .setTagForUnderAgeOfConsent(this.isSetTagForUnderAgeOfConsent).build()
825
843
  }
826
844
  consentInformation = mContext?.let {
827
845
  UserMessagingPlatform.getConsentInformation(
@@ -912,20 +930,15 @@ class emiAdmobPlugin : CordovaPlugin() {
912
930
  val autoResize = options.optBoolean("autoResize")
913
931
  val autoShow = options.optBoolean("autoShow")
914
932
  this.bannerAdUnitId = adUnitId
915
- this.Position = position
916
- this.Size = size
933
+ this.isPosition = position
934
+ this.isSize = size
917
935
  this.bannerAutoShow = autoShow
918
936
  this.isAutoResize = autoResize
919
937
  this.collapsiblePos = collapsible
920
938
 
921
-
922
- isCollapsible = if (collapsible.isEmpty()) {
923
- false
924
- } else {
925
- true
926
- }
939
+ isCollapsible = collapsible.isNotEmpty()
927
940
  try {
928
- _loadBannerAd(adUnitId, position, size)
941
+ loadBannerAd(adUnitId, position, size)
929
942
  } catch (e: Exception) {
930
943
  callbackContext.error(e.toString())
931
944
  }
@@ -1038,29 +1051,25 @@ class emiAdmobPlugin : CordovaPlugin() {
1038
1051
  }
1039
1052
 
1040
1053
 
1041
- private fun _loadBannerAd(adUnitId: String, position: String, size: String) {
1054
+
1055
+
1056
+ private fun loadBannerAd(adUnitId: String, position: String, size: String) {
1042
1057
  try {
1043
1058
  if (bannerViewLayout == null) {
1044
- bannerViewLayout = RelativeLayout(mActivity)
1045
-
1046
- val params = RelativeLayout.LayoutParams(
1047
- RelativeLayout.LayoutParams.MATCH_PARENT,
1048
- RelativeLayout.LayoutParams.WRAP_CONTENT
1059
+ bannerViewLayout = FrameLayout(mContext!!)
1060
+ val params = FrameLayout.LayoutParams(
1061
+ FrameLayout.LayoutParams.MATCH_PARENT,
1062
+ FrameLayout.LayoutParams.MATCH_PARENT
1049
1063
  )
1050
-
1051
- val rootView = mActivity!!.window.decorView.findViewById<View>(R.id.content)
1052
- if (rootView is ViewGroup) {
1053
- rootView.addView(bannerViewLayout, params)
1054
- } else {
1055
- mActivity!!.addContentView(bannerViewLayout, params)
1056
- }
1057
-
1064
+ val decorView = mActivity!!.window.decorView as ViewGroup
1065
+ decorView.addView(bannerViewLayout, params)
1058
1066
  bannerView = AdView(mContext!!)
1059
1067
  setBannerPosition(position)
1060
1068
  setBannerSiz(size)
1061
1069
  bannerView!!.adUnitId = adUnitId
1062
1070
  bannerView!!.adListener = bannerAdListener
1063
1071
  bannerView!!.loadAd(buildAdRequest())
1072
+ adjustWebViewForBanner(position)
1064
1073
  } else {
1065
1074
  Log.d(TAG, "Banner view layout already exists.")
1066
1075
  }
@@ -1070,6 +1079,84 @@ class emiAdmobPlugin : CordovaPlugin() {
1070
1079
  }
1071
1080
  }
1072
1081
 
1082
+ private fun adjustWebViewForBanner(position: String?) {
1083
+ val rootView = bannerViewLayout
1084
+ val webView = rootView?.findViewById<View>(View.generateViewId())
1085
+
1086
+ if (webView != null) {
1087
+ when (position) {
1088
+ "bottom-center", "bottom-right" -> {
1089
+ webView.setPadding(0, 0, 0, bannerView!!.height)
1090
+ }
1091
+ "top-center", "top-right" -> {
1092
+ webView.setPadding(0, bannerView!!.height, 0, 0)
1093
+ }
1094
+ else -> {
1095
+ webView.setPadding(0, 0, 0, 0)
1096
+ }
1097
+ }
1098
+ webView.requestLayout()
1099
+ }
1100
+ }
1101
+
1102
+ @SuppressLint("RtlHardcoded")
1103
+ private fun setBannerPosition(position: String?) {
1104
+ val bannerParams = FrameLayout.LayoutParams(
1105
+ FrameLayout.LayoutParams.WRAP_CONTENT,
1106
+ FrameLayout.LayoutParams.WRAP_CONTENT
1107
+ )
1108
+
1109
+ when (position) {
1110
+ "top-right" -> {
1111
+ bannerParams.gravity = Gravity.TOP or Gravity.RIGHT
1112
+ bannerParams.setMargins(0, marginsInPx, marginsInPx, 0)
1113
+ bannerViewLayout!!.setPadding(0, paddingInPx, paddingInPx, 0)
1114
+ }
1115
+
1116
+ "top-center" -> {
1117
+ bannerParams.gravity = Gravity.TOP or Gravity.CENTER_HORIZONTAL
1118
+ bannerParams.setMargins(0, marginsInPx, 0, 0)
1119
+ bannerViewLayout!!.setPadding(0, paddingInPx, 0, 0)
1120
+ }
1121
+
1122
+ "left" -> {
1123
+ bannerParams.gravity = Gravity.LEFT or Gravity.CENTER_VERTICAL
1124
+ bannerParams.setMargins(marginsInPx, 0, 0, 0)
1125
+ bannerViewLayout!!.setPadding(paddingInPx, 0, 0, 0)
1126
+ }
1127
+
1128
+ "center" -> {
1129
+ bannerParams.gravity = Gravity.CENTER
1130
+ }
1131
+
1132
+ "right" -> {
1133
+ bannerParams.gravity = Gravity.RIGHT or Gravity.CENTER_VERTICAL
1134
+ bannerParams.setMargins(0, 0, marginsInPx, 0)
1135
+ bannerViewLayout!!.setPadding(0, 0, paddingInPx, 0)
1136
+ }
1137
+
1138
+ "bottom-center" -> {
1139
+ bannerParams.gravity = Gravity.BOTTOM or Gravity.CENTER_HORIZONTAL
1140
+ bannerParams.setMargins(0, 0, 0, marginsInPx)
1141
+ bannerViewLayout!!.setPadding(0, 0, 0, paddingInPx)
1142
+ }
1143
+
1144
+ "bottom-right" -> {
1145
+ bannerParams.gravity = Gravity.BOTTOM or Gravity.RIGHT
1146
+ bannerParams.setMargins(0, 0, marginsInPx, marginsInPx)
1147
+ bannerViewLayout!!.setPadding(0, 0, paddingInPx, paddingInPx)
1148
+ }
1149
+
1150
+ else -> {
1151
+ bannerParams.gravity = Gravity.CENTER_HORIZONTAL or Gravity.BOTTOM
1152
+ bannerParams.setMargins(marginsInPx, 0, 0, marginsInPx)
1153
+ bannerViewLayout!!.setPadding(paddingInPx, 0, 0, paddingInPx)
1154
+ }
1155
+ }
1156
+
1157
+ bannerViewLayout!!.layoutParams = bannerParams
1158
+ }
1159
+
1073
1160
 
1074
1161
  private fun isBannerAutoShow() {
1075
1162
  try {
@@ -1083,12 +1170,12 @@ class emiAdmobPlugin : CordovaPlugin() {
1083
1170
  isBannerLoad = true
1084
1171
  } else {
1085
1172
  val errorMessage = "Error showing banner: bannerView or bannerViewLayout is null."
1086
- Log.e("isBannerAutoShow", errorMessage)
1173
+ // Log.e("isBannerAutoShow", errorMessage)
1087
1174
  PUBLIC_CALLBACKS!!.error(errorMessage)
1088
1175
  }
1089
1176
  } catch (e: Exception) {
1090
1177
  val errorMessage = "Error showing banner: " + e.message
1091
- Log.e("isBannerAutoShow", errorMessage, e)
1178
+ // Log.e("isBannerAutoShow", errorMessage, e)
1092
1179
  PUBLIC_CALLBACKS!!.error(errorMessage)
1093
1180
  }
1094
1181
  }
@@ -1169,7 +1256,7 @@ class emiAdmobPlugin : CordovaPlugin() {
1169
1256
 
1170
1257
  bannerView!!.onPaidEventListener = bannerPaidAdListener
1171
1258
 
1172
- if (ResponseInfo) {
1259
+ if (isResponseInfo) {
1173
1260
  val result = JSONObject()
1174
1261
  val responseInfo = bannerView!!.responseInfo
1175
1262
  try {
@@ -1257,9 +1344,21 @@ class emiAdmobPlugin : CordovaPlugin() {
1257
1344
 
1258
1345
  private val adSize: AdSize
1259
1346
  get() {
1260
- val display = mActivity!!.windowManager.defaultDisplay
1261
1347
  val outMetrics = DisplayMetrics()
1262
- display.getMetrics(outMetrics)
1348
+
1349
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
1350
+ val windowMetrics = mActivity!!.windowManager.currentWindowMetrics
1351
+ val insets = windowMetrics.windowInsets
1352
+ .getInsetsIgnoringVisibility(WindowInsets.Type.systemBars())
1353
+ val bounds = windowMetrics.bounds
1354
+ val widthPixels = bounds.width() - insets.left - insets.right
1355
+ outMetrics.widthPixels = widthPixels
1356
+ outMetrics.density = mActivity!!.resources.displayMetrics.density
1357
+ } else {
1358
+ @Suppress("DEPRECATION")
1359
+ mActivity!!.windowManager.defaultDisplay.getMetrics(outMetrics)
1360
+ }
1361
+
1263
1362
  val density = outMetrics.density
1264
1363
  val adWidthPixels =
1265
1364
  if (bannerViewLayout != null && bannerViewLayout!!.width > 0) bannerViewLayout!!.width else outMetrics.widthPixels
@@ -1267,11 +1366,24 @@ class emiAdmobPlugin : CordovaPlugin() {
1267
1366
  return AdSize.getCurrentOrientationAnchoredAdaptiveBannerAdSize(mContext!!, adWidth)
1268
1367
  }
1269
1368
 
1369
+
1270
1370
  private val adWidth: Int
1271
1371
  get() {
1272
- val display = mActivity!!.windowManager.defaultDisplay
1273
1372
  val outMetrics = DisplayMetrics()
1274
- display.getMetrics(outMetrics)
1373
+
1374
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
1375
+ val windowMetrics = mActivity!!.windowManager.currentWindowMetrics
1376
+ val insets = windowMetrics.windowInsets
1377
+ .getInsetsIgnoringVisibility(WindowInsets.Type.systemBars())
1378
+ val bounds = windowMetrics.bounds
1379
+ val widthPixels = bounds.width() - insets.left - insets.right
1380
+ outMetrics.widthPixels = widthPixels
1381
+ outMetrics.density = mActivity!!.resources.displayMetrics.density
1382
+ } else {
1383
+ @Suppress("DEPRECATION")
1384
+ mActivity!!.windowManager.defaultDisplay.getMetrics(outMetrics)
1385
+ }
1386
+
1275
1387
  val density = outMetrics.density
1276
1388
  val adWidthPixels =
1277
1389
  (if (bannerViewLayout != null && bannerViewLayout!!.width > 0) bannerViewLayout!!.width else outMetrics.widthPixels).toFloat()
@@ -1279,71 +1391,9 @@ class emiAdmobPlugin : CordovaPlugin() {
1279
1391
  }
1280
1392
 
1281
1393
 
1282
- private fun setBannerPosition(position: String?) {
1283
- val bannerParams = RelativeLayout.LayoutParams(
1284
- RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT
1285
- )
1286
-
1287
- when (position) {
1288
- "top-right" -> {
1289
- bannerParams.addRule(RelativeLayout.ALIGN_PARENT_TOP)
1290
- bannerParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT)
1291
- bannerParams.setMargins(0, marginsInPx, marginsInPx, 0)
1292
- bannerViewLayout!!.setPadding(0, paddingInPx, paddingInPx, 0)
1293
- }
1294
-
1295
- "top-center" -> {
1296
- bannerParams.addRule(RelativeLayout.ALIGN_PARENT_TOP)
1297
- bannerParams.addRule(RelativeLayout.CENTER_HORIZONTAL)
1298
- bannerParams.setMargins(0, marginsInPx, 0, 0)
1299
- bannerViewLayout!!.setPadding(0, paddingInPx, 0, 0)
1300
- }
1301
-
1302
- "left" -> {
1303
- bannerParams.addRule(RelativeLayout.ALIGN_PARENT_LEFT)
1304
- bannerParams.addRule(RelativeLayout.CENTER_VERTICAL)
1305
- bannerParams.setMargins(marginsInPx, 0, 0, 0)
1306
- bannerViewLayout!!.setPadding(paddingInPx, 0, 0, 0)
1307
- }
1308
-
1309
- "center" -> {
1310
- bannerParams.addRule(RelativeLayout.CENTER_HORIZONTAL)
1311
- bannerParams.addRule(RelativeLayout.CENTER_VERTICAL)
1312
- }
1313
-
1314
- "right" -> {
1315
- bannerParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT)
1316
- bannerParams.addRule(RelativeLayout.CENTER_VERTICAL)
1317
- bannerParams.setMargins(0, 0, marginsInPx, 0)
1318
- bannerViewLayout!!.setPadding(0, 0, paddingInPx, 0)
1319
- }
1320
-
1321
- "bottom-center" -> {
1322
- bannerParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM)
1323
- bannerParams.addRule(RelativeLayout.CENTER_HORIZONTAL)
1324
- bannerParams.setMargins(0, 0, 0, marginsInPx)
1325
- bannerViewLayout!!.setPadding(0, 0, 0, paddingInPx)
1326
- }
1327
-
1328
- "bottom-right" -> {
1329
- bannerParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM)
1330
- bannerParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT)
1331
- bannerParams.setMargins(0, 0, marginsInPx, marginsInPx)
1332
- bannerViewLayout!!.setPadding(0, 0, paddingInPx, paddingInPx)
1333
- }
1334
-
1335
- else -> {
1336
- bannerParams.addRule(RelativeLayout.CENTER_HORIZONTAL)
1337
- bannerParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM)
1338
- bannerParams.setMargins(marginsInPx, 0, 0, marginsInPx)
1339
- bannerViewLayout!!.setPadding(paddingInPx, 0, 0, paddingInPx)
1340
- }
1341
- }
1342
- bannerView!!.layoutParams = bannerParams
1343
- }
1344
1394
 
1345
1395
 
1346
- fun setUsingAdManagerRequest(isUsingAdManagerRequest: Boolean) {
1396
+ private fun setUsingAdManagerRequest(isUsingAdManagerRequest: Boolean) {
1347
1397
  this.isUsingAdManagerRequest = isUsingAdManagerRequest
1348
1398
  }
1349
1399
 
@@ -1508,9 +1558,9 @@ class emiAdmobPlugin : CordovaPlugin() {
1508
1558
  if (isCollapsible) {
1509
1559
  bundleExtra.putString("collapsible", this.collapsiblePos)
1510
1560
  }
1511
- bundleExtra.putBoolean("is_designed_for_families", this.SetTagForChildDirectedTreatment)
1512
- bundleExtra.putBoolean("under_age_of_consent", this.SetTagForUnderAgeOfConsent)
1513
- bundleExtra.putString("max_ad_content_rating", this.SetMaxAdContentRating)
1561
+ bundleExtra.putBoolean("is_designed_for_families", this.isSetTagForChildDirectedTreatment)
1562
+ bundleExtra.putBoolean("under_age_of_consent", this.isSetTagForUnderAgeOfConsent)
1563
+ bundleExtra.putString("max_ad_content_rating", this.isSetMaxAdContentRating)
1514
1564
  builder.addNetworkExtrasBundle(AdMobAdapter::class.java, bundleExtra)
1515
1565
 
1516
1566
  if (this.ppsEnabled) {
@@ -1536,9 +1586,9 @@ class emiAdmobPlugin : CordovaPlugin() {
1536
1586
  if (isCollapsible) {
1537
1587
  bundleExtra.putString("collapsible", this.collapsiblePos)
1538
1588
  }
1539
- bundleExtra.putBoolean("is_designed_for_families", this.SetTagForChildDirectedTreatment)
1540
- bundleExtra.putBoolean("under_age_of_consent", this.SetTagForUnderAgeOfConsent)
1541
- bundleExtra.putString("max_ad_content_rating", this.SetMaxAdContentRating)
1589
+ bundleExtra.putBoolean("is_designed_for_families", this.isSetTagForChildDirectedTreatment)
1590
+ bundleExtra.putBoolean("under_age_of_consent", this.isSetTagForUnderAgeOfConsent)
1591
+ bundleExtra.putString("max_ad_content_rating", this.isSetMaxAdContentRating)
1542
1592
  builder.addNetworkExtrasBundle(AdMobAdapter::class.java, bundleExtra)
1543
1593
  mBundleExtra = bundleExtra
1544
1594
 
@@ -1547,7 +1597,7 @@ class emiAdmobPlugin : CordovaPlugin() {
1547
1597
  }
1548
1598
 
1549
1599
 
1550
- val deviceId: String?
1600
+ private val deviceId: String?
1551
1601
  get() {
1552
1602
  var algorithm = "SHA-256"
1553
1603
  try {
@@ -1592,7 +1642,7 @@ class emiAdmobPlugin : CordovaPlugin() {
1592
1642
  }
1593
1643
 
1594
1644
 
1595
- fun getString(key: String) {
1645
+ private fun getString(key: String) {
1596
1646
  val lastAccessTime = mPreferences!!.getLong(key + LAST_ACCESS_SUFFIX, 0)
1597
1647
  val currentTime = System.currentTimeMillis()
1598
1648
  if (currentTime - lastAccessTime > EXPIRATION_TIME) {
@@ -1617,16 +1667,12 @@ class emiAdmobPlugin : CordovaPlugin() {
1617
1667
 
1618
1668
 
1619
1669
 
1620
- private fun _appOpenAdLoadCallback(callbackContext: CallbackContext) {
1670
+ private fun appOpenAdLoadCallback(callbackContext: CallbackContext) {
1621
1671
  appOpenAd!!.fullScreenContentCallback = object : FullScreenContentCallback() {
1622
1672
  override fun onAdDismissedFullScreenContent() {
1623
1673
  cWebView!!.loadUrl("javascript:cordova.fireDocumentEvent('on.appOpenAd.dismissed');")
1624
-
1625
- // Akses langsung ke properti view tanpa menggunakan 'this'
1626
1674
  val mainView: View? = view
1627
- if (mainView != null) {
1628
- mainView.requestFocus()
1629
- }
1675
+ mainView?.requestFocus()
1630
1676
  }
1631
1677
 
1632
1678
  override fun onAdFailedToShowFullScreenContent(adError: AdError) {
@@ -1642,7 +1688,7 @@ class emiAdmobPlugin : CordovaPlugin() {
1642
1688
  }
1643
1689
 
1644
1690
 
1645
- private fun _interstitialAdLoadCallback(callbackContext: CallbackContext) {
1691
+ private fun interstitialAdLoadCallback(callbackContext: CallbackContext) {
1646
1692
  mInterstitialAd!!.fullScreenContentCallback = object : FullScreenContentCallback() {
1647
1693
  override fun onAdClicked() {
1648
1694
  cWebView!!.loadUrl("javascript:cordova.fireDocumentEvent('on.interstitial.click');")
@@ -1673,7 +1719,7 @@ class emiAdmobPlugin : CordovaPlugin() {
1673
1719
  }
1674
1720
  }
1675
1721
 
1676
- private fun _rewardedAdLoadCallback(callbackContext: CallbackContext) {
1722
+ private fun rewardedAdLoadCallback(callbackContext: CallbackContext) {
1677
1723
  rewardedAd!!.fullScreenContentCallback = object : FullScreenContentCallback() {
1678
1724
  override fun onAdClicked() {
1679
1725
  cWebView!!.loadUrl("javascript:cordova.fireDocumentEvent('on.rewarded.click');")
@@ -1710,7 +1756,7 @@ class emiAdmobPlugin : CordovaPlugin() {
1710
1756
  }
1711
1757
  }
1712
1758
 
1713
- private fun _rewardedInterstitialAdLoadCallback(callbackContext: CallbackContext) {
1759
+ private fun rewardedInterstitialAdLoadCallback(callbackContext: CallbackContext) {
1714
1760
  rewardedInterstitialAd!!.fullScreenContentCallback = object : FullScreenContentCallback() {
1715
1761
  override fun onAdClicked() {
1716
1762
  cWebView!!.loadUrl("javascript:cordova.fireDocumentEvent('on.rewardedInt.click');")
@@ -1748,13 +1794,13 @@ class emiAdmobPlugin : CordovaPlugin() {
1748
1794
  }
1749
1795
  }
1750
1796
 
1751
- fun _globalSettings(setAppMuted: Boolean, setAppVolume: Float, pubIdEnabled: Boolean) {
1797
+ private fun globalSettings(setAppMuted: Boolean, setAppVolume: Float, pubIdEnabled: Boolean) {
1752
1798
  MobileAds.setAppMuted(setAppMuted)
1753
1799
  MobileAds.setAppVolume(setAppVolume)
1754
1800
  MobileAds.putPublisherFirstPartyIdEnabled(pubIdEnabled)
1755
1801
  }
1756
1802
 
1757
- fun _Targeting(
1803
+ private fun Targeting(
1758
1804
  childDirectedTreatment: Boolean,
1759
1805
  underAgeOfConsent: Boolean,
1760
1806
  contentRating: String?
@@ -1772,7 +1818,7 @@ class emiAdmobPlugin : CordovaPlugin() {
1772
1818
  MobileAds.setRequestConfiguration(requestConfiguration.build())
1773
1819
  }
1774
1820
 
1775
- val isPrivacyOptionsRequired: ConsentInformation.PrivacyOptionsRequirementStatus
1821
+ private val isPrivacyOptionsRequired: ConsentInformation.PrivacyOptionsRequirementStatus
1776
1822
  get() = consentInformation
1777
1823
  ?.getPrivacyOptionsRequirementStatus() ?: ConsentInformation.PrivacyOptionsRequirementStatus.REQUIRED
1778
1824
 
@@ -1811,7 +1857,7 @@ class emiAdmobPlugin : CordovaPlugin() {
1811
1857
  override fun onResume(multitasking: Boolean) {
1812
1858
  super.onResume(multitasking)
1813
1859
  if (bannerView != null) {
1814
- bannerView!!.resume() // ini berfungsi
1860
+ bannerView!!.resume()
1815
1861
  }
1816
1862
  }
1817
1863
 
@@ -1826,12 +1872,13 @@ class emiAdmobPlugin : CordovaPlugin() {
1826
1872
  }
1827
1873
  if (bannerViewLayout != null) {
1828
1874
  val parentView = bannerViewLayout!!.parent as ViewGroup
1829
- parentView?.removeView(bannerViewLayout)
1875
+ parentView.removeView(bannerViewLayout)
1830
1876
  bannerViewLayout = null
1831
1877
  }
1832
1878
  super.onDestroy()
1833
1879
  }
1834
1880
 
1881
+
1835
1882
  companion object {
1836
1883
  private const val TAG = "emiAdmobPlugin"
1837
1884