emi-indo-cordova-plugin-admob 2.0.1 → 2.0.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.
@@ -17,6 +17,10 @@
17
17
 
18
18
  <p> <button onclick="loadAppOpen();">Auto Show App Open Ad</button></p>
19
19
 
20
+ <p> <button onclick="loadBanner();">load a show Banner Ad</button></p>
21
+ <p> <button onclick="showBanner();">show Banner Ad</button></p>
22
+ <p> <button onclick="hideBanner();">hide Banner Ad</button></p>
23
+ <p> <button onclick="removeBanner();">remove Banner Ad</button></p>
20
24
 
21
25
  <p> <button onclick="loadInterstitial();">Load Interstitial Ad</button></p>
22
26
  <p> <button onclick="showInterstitial();">Show Interstitial Ad</button></p>
@@ -10,16 +10,16 @@ function loadBanner() {
10
10
 
11
11
  if (typeof cordova !== 'undefined') {
12
12
 
13
- if (!isPlatformIOS){
14
-
13
+
15
14
  cordova.plugins.emiAdmobPlugin.styleBannerAd({
16
- isOverlapping: true,
17
- overlappingHeight: 0, // default 0 (Automatic)
18
- padding: 0, // default 0
19
- margins: 0 // default 0 (Automatic)
15
+ isOverlapping: true, // default false IOS | Android
16
+ isStatusBarShow: true, // default true Only Android
17
+ paddingWebView: 1.0, // Only IOS > padding banner Container and webView Container
18
+ overlappingHeight: 0, // default 0 (Automatic) Only Android
19
+ padding: 0, // default 0 Only Android
20
+ margins: 0 // default 0 (Automatic) Only Android
20
21
  });
21
22
 
22
- }
23
23
 
24
24
 
25
25
  cordova.plugins.emiAdmobPlugin.loadBannerAd({
@@ -37,6 +37,30 @@ function loadBanner() {
37
37
 
38
38
 
39
39
 
40
+ function showBanner() {
41
+
42
+ if (typeof cordova !== 'undefined') {
43
+ cordova.plugins.emiAdmobPlugin.showBannerAd();
44
+ }
45
+
46
+ }
47
+
48
+ function hideBanner() {
49
+
50
+ if (typeof cordova !== 'undefined') {
51
+ cordova.plugins.emiAdmobPlugin.hideBannerAd();
52
+ }
53
+
54
+ }
55
+
56
+
57
+ function removeBanner() {
58
+
59
+ if (typeof cordova !== 'undefined') {
60
+ cordova.plugins.emiAdmobPlugin.removeBannerAd();
61
+ }
62
+
63
+ }
40
64
 
41
65
 
42
66
  /* ///////<<<< bannerAd position >>>>>>\\\\\\\
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "emi-indo-cordova-plugin-admob",
3
- "version": "2.0.1",
3
+ "version": "2.0.3",
4
4
  "description": "Cordova/Quasar/Capacitor 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="2.0.1">
3
+ id="emi-indo-cordova-plugin-admob" version="2.0.3">
4
4
 
5
5
  <name>emiAdmobPlugin</name>
6
6
  <description>Cordova/Quasar/Capacitor Plugin Admob Android IOS</description>
@@ -51,8 +51,6 @@
51
51
  android:value="$APP_ID_ANDROID" />
52
52
  <meta-data android:name="com.google.android.gms.ads.DELAY_APP_MEASUREMENT_INIT"
53
53
  android:value="true" />
54
- <meta-data android:name="com.google.android.gms.ads.flag.OPTIMIZE_INITIALIZATION"
55
- android:value="true" />
56
54
  <meta-data android:name="com.google.android.gms.ads.flag.OPTIMIZE_AD_LOADING"
57
55
  android:value="true" />
58
56
  <meta-data
@@ -99,7 +97,7 @@
99
97
 
100
98
  <config-file parent="/*" target="config.xml">
101
99
  <!--minimum deployment-target: 12.2 -->
102
- <preference name="deployment-target" value="12.3" />
100
+ <preference name="deployment-target" value="13.0" />
103
101
  <preference name="SwiftVersion" value="5.10" />
104
102
  </config-file>
105
103
 
@@ -93,6 +93,7 @@ class emiAdmobPlugin : CordovaPlugin() {
93
93
 
94
94
  private var isOverlapping: Boolean = false
95
95
  private var overlappingHeight: Int = 0
96
+ private var isStatusBarShow: Boolean = true
96
97
 
97
98
  var adType = ""
98
99
 
@@ -111,8 +112,7 @@ class emiAdmobPlugin : CordovaPlugin() {
111
112
  private var isCollapsible: Boolean = false
112
113
  var lock: Boolean = true
113
114
  private var setDebugGeography: Boolean = false
114
- private var mActivity: Activity? = null
115
- private var mContext: Context? = null
115
+
116
116
  private var mInterstitialAd: InterstitialAd? = null
117
117
  private var appOpenAd: AppOpenAd? = null
118
118
  private var isOrientation: Int = 1
@@ -145,55 +145,64 @@ class emiAdmobPlugin : CordovaPlugin() {
145
145
 
146
146
  private var isCustomConsentManager = false
147
147
 
148
+ private var mActivity: Activity? = null
149
+ private var mContext: Context? = null
150
+
148
151
 
149
152
  override fun initialize(cordova: CordovaInterface, webView: CordovaWebView) {
150
153
  super.initialize(cordova, webView)
154
+
151
155
  cWebView = webView
152
- mActivity = this.cordova.activity
153
- mActivity?.let {
154
- mContext = it.applicationContext
155
- }
156
+ mActivity = cordova.activity
156
157
 
157
- mPreferences = mContext?.let { PreferenceManager.getDefaultSharedPreferences(it) }
158
+ if (mActivity != null) {
158
159
 
160
+ mContext = mActivity?.applicationContext
161
+
162
+ mPreferences = mContext?.let { PreferenceManager.getDefaultSharedPreferences(it) }
163
+
164
+ } else {
165
+ Log.e("PluginCordova", "Activity is null during initialization")
166
+ }
159
167
  }
160
168
 
161
169
 
162
170
 
171
+
163
172
  override fun onConfigurationChanged(newConfig: Configuration) {
164
173
  super.onConfigurationChanged(newConfig)
165
174
  val orientation = newConfig.orientation
166
175
  if (orientation != isOrientation) {
167
- cWebView!!.loadUrl("javascript:cordova.fireDocumentEvent('on.screen.rotated');")
176
+ cWebView?.loadUrl("javascript:cordova.fireDocumentEvent('on.screen.rotated');")
168
177
  isOrientation = orientation
169
178
  if (this.isAutoResize) {
170
179
  if(mActivity != null) {
171
- mActivity!!.runOnUiThread {
180
+ mActivity?.runOnUiThread {
172
181
  try {
173
182
  bannerOverlappingToZero()
174
183
  if (bannerViewLayout != null && bannerView != null) {
175
- val parentView = bannerViewLayout!!.parent as ViewGroup
184
+ val parentView = bannerViewLayout?.parent as ViewGroup
176
185
  parentView.removeView(bannerViewLayout)
177
186
  bannerViewLayout = FrameLayout(mActivity!!)
178
187
  val params = FrameLayout.LayoutParams(
179
188
  FrameLayout.LayoutParams.MATCH_PARENT,
180
189
  FrameLayout.LayoutParams.WRAP_CONTENT
181
190
  )
182
- val decorView = mActivity!!.window.decorView as ViewGroup
191
+ val decorView = mActivity?.window?.decorView as ViewGroup
183
192
  decorView.addView(bannerViewLayout, params)
184
193
  bannerView = AdView(mActivity!!)
185
194
  setBannerPosition(this.isPosition)
186
195
  setBannerSize(this.isSize)
187
- bannerView!!.adUnitId = bannerAdUnitId!!
188
- bannerView!!.adListener = bannerAdListener
189
- bannerView!!.loadAd(buildAdRequest())
190
- bannerViewLayout!!.addView(bannerView)
191
- bannerViewLayout!!.bringToFront()
192
- bannerViewLayout!!.requestFocus();
196
+ bannerView?.adUnitId = bannerAdUnitId!!
197
+ bannerView?.adListener = bannerAdListener
198
+ bannerView?.loadAd(buildAdRequest())
199
+ bannerViewLayout?.addView(bannerView)
200
+ bannerViewLayout?.bringToFront()
201
+ bannerViewLayout?.requestFocus();
193
202
  bannerOverlappingToZero()
194
203
  }
195
204
  } catch (e: Exception) {
196
- PUBLIC_CALLBACKS!!.error("Error adjusting banner size: " + e.message)
205
+ PUBLIC_CALLBACKS?.error("Error adjusting banner size: " + e.message)
197
206
  }
198
207
  }
199
208
  }
@@ -204,16 +213,16 @@ class emiAdmobPlugin : CordovaPlugin() {
204
213
  if (isOverlapping) {
205
214
  bannerOverlapping()
206
215
  }
207
- cWebView!!.loadUrl("javascript:cordova.fireDocumentEvent('on.orientation.portrait');")
216
+ cWebView?.loadUrl("javascript:cordova.fireDocumentEvent('on.orientation.portrait');")
208
217
  }
209
218
  Configuration.ORIENTATION_LANDSCAPE -> {
210
219
  if (isOverlapping) {
211
220
  bannerOverlapping()
212
221
  }
213
- cWebView!!.loadUrl("javascript:cordova.fireDocumentEvent('on.orientation.landscape');")
222
+ cWebView?.loadUrl("javascript:cordova.fireDocumentEvent('on.orientation.landscape');")
214
223
  }
215
224
  Configuration.ORIENTATION_UNDEFINED -> {
216
- cWebView!!.loadUrl("javascript:cordova.fireDocumentEvent('on.orientation.undefined');")
225
+ cWebView?.loadUrl("javascript:cordova.fireDocumentEvent('on.orientation.undefined');")
217
226
  }
218
227
 
219
228
 
@@ -411,7 +420,7 @@ class emiAdmobPlugin : CordovaPlugin() {
411
420
  } else if (action == "loadAppOpenAd") {
412
421
  val options = args.getJSONObject(0)
413
422
  if (mActivity != null) {
414
- mActivity!!.runOnUiThread {
423
+ mActivity?.runOnUiThread {
415
424
  val adUnitId = options.optString("adUnitId")
416
425
  val autoShow = options.optBoolean("autoShow")
417
426
  try {
@@ -428,7 +437,7 @@ class emiAdmobPlugin : CordovaPlugin() {
428
437
  openAutoShow()
429
438
  }
430
439
 
431
- cWebView!!.loadUrl(
440
+ cWebView?.loadUrl(
432
441
  "javascript:cordova.fireDocumentEvent('on.appOpenAd.loaded');"
433
442
  )
434
443
 
@@ -465,7 +474,7 @@ class emiAdmobPlugin : CordovaPlugin() {
465
474
  result.put("getResponseExtras", responseInfo?.responseExtras.toString())
466
475
  result.put("getMediationAdapterClassName", responseInfo?.mediationAdapterClassName.toString())
467
476
  result.put("getBundleExtra", mBundleExtra.toString())
468
- cWebView!!.loadUrl("javascript:cordova.fireDocumentEvent('on.appOpenAd.responseInfo', ${result})")
477
+ cWebView?.loadUrl("javascript:cordova.fireDocumentEvent('on.appOpenAd.responseInfo', ${result})")
469
478
  } catch (e: JSONException) {
470
479
  callbackContext.error(e.message)
471
480
  }
@@ -479,14 +488,14 @@ class emiAdmobPlugin : CordovaPlugin() {
479
488
  private fun openAutoShow() {
480
489
  try {
481
490
  if (mActivity != null && isAppOpenAdShow && appOpenAd != null) {
482
- mActivity!!.runOnUiThread {
483
- appOpenAd!!.show(
491
+ mActivity?.runOnUiThread {
492
+ appOpenAd?.show(
484
493
  mActivity!!
485
- )
494
+ ) ?: callbackContext.error("Failed to show App Open Ad")
486
495
  }
487
496
  }
488
497
  } catch (e: Exception) {
489
- PUBLIC_CALLBACKS!!.error(e.toString())
498
+ PUBLIC_CALLBACKS?.error(e.toString())
490
499
  }
491
500
  }
492
501
 
@@ -526,7 +535,7 @@ class emiAdmobPlugin : CordovaPlugin() {
526
535
 
527
536
  try {
528
537
  if (mActivity != null && isAppOpenAdShow && appOpenAd != null) {
529
- mActivity!!.runOnUiThread { appOpenAd!!.show(mActivity!!) }
538
+ mActivity?.runOnUiThread { appOpenAd?.show(mActivity!!) ?: callbackContext.error("Failed to show App Open Ad") }
530
539
  appOpenAdLoadCallback()
531
540
  } else {
532
541
  callbackContext.error("The App Open Ad wasn't ready yet")
@@ -539,7 +548,7 @@ class emiAdmobPlugin : CordovaPlugin() {
539
548
  } else if (action == "loadInterstitialAd") {
540
549
  val options = args.getJSONObject(0)
541
550
  if (mActivity != null) {
542
- mActivity!!.runOnUiThread {
551
+ mActivity?.runOnUiThread {
543
552
  val adUnitId = options.optString("adUnitId")
544
553
  val autoShow = options.optBoolean("autoShow")
545
554
  try {
@@ -555,7 +564,7 @@ class emiAdmobPlugin : CordovaPlugin() {
555
564
  isIntAutoShow
556
565
  }
557
566
 
558
- cWebView!!.loadUrl(
567
+ cWebView?.loadUrl(
559
568
  "javascript:cordova.fireDocumentEvent('on.interstitial.loaded');"
560
569
  )
561
570
 
@@ -590,7 +599,7 @@ class emiAdmobPlugin : CordovaPlugin() {
590
599
  result.put("currency", currencyCode)
591
600
  result.put("precision", precision)
592
601
  result.put("adUnitId", interstitialAdUnitId)
593
- cWebView!!.loadUrl(
602
+ cWebView?.loadUrl(
594
603
  "javascript:cordova.fireDocumentEvent('on.interstitial.revenue', ${result});"
595
604
  )
596
605
 
@@ -604,10 +613,10 @@ class emiAdmobPlugin : CordovaPlugin() {
604
613
  private val isIntAutoShow: Unit
605
614
  get() {
606
615
  if (mActivity != null && isInterstitialLoad && mInterstitialAd != null) {
607
- mActivity!!.runOnUiThread {
608
- mInterstitialAd!!.show(
616
+ mActivity?.runOnUiThread {
617
+ mInterstitialAd?.show(
609
618
  mActivity!!
610
- )
619
+ ) ?: callbackContext.error("Failed to show Interstitial Ad")
611
620
  }
612
621
  }
613
622
  }
@@ -635,7 +644,7 @@ class emiAdmobPlugin : CordovaPlugin() {
635
644
  put("responseInfoAdapterResponses", adapterResponses)
636
645
  }
637
646
 
638
- cWebView!!.loadUrl(
647
+ cWebView?.loadUrl(
639
648
  "javascript:cordova.fireDocumentEvent('on.interstitial.failed.load', ${errorData});"
640
649
  )
641
650
 
@@ -650,7 +659,7 @@ class emiAdmobPlugin : CordovaPlugin() {
650
659
  } else if (action == "showInterstitialAd") {
651
660
 
652
661
  if (mActivity != null && isInterstitialLoad && mInterstitialAd != null) {
653
- mActivity!!.runOnUiThread { mInterstitialAd!!.show(mActivity!!) }
662
+ mActivity?.runOnUiThread { mInterstitialAd?.show(mActivity!!) ?: callbackContext.error("Failed to show Interstitial Ad") }
654
663
  interstitialAdLoadCallback()
655
664
  } else {
656
665
  callbackContext.error("The Interstitial ad wasn't ready yet")
@@ -659,7 +668,7 @@ class emiAdmobPlugin : CordovaPlugin() {
659
668
  } else if (action == "loadRewardedAd") {
660
669
  val options = args.getJSONObject(0)
661
670
  if (mActivity != null) {
662
- mActivity!!.runOnUiThread {
671
+ mActivity?.runOnUiThread {
663
672
  val adUnitId = options.optString("adUnitId")
664
673
  val autoShow = options.optBoolean("autoShow")
665
674
  try {
@@ -692,7 +701,7 @@ class emiAdmobPlugin : CordovaPlugin() {
692
701
 
693
702
  }
694
703
 
695
- cWebView!!.loadUrl(
704
+ cWebView?.loadUrl(
696
705
  "javascript:cordova.fireDocumentEvent('on.rewarded.failed.load', ${errorData});"
697
706
  )
698
707
 
@@ -709,7 +718,7 @@ class emiAdmobPlugin : CordovaPlugin() {
709
718
 
710
719
  rewardedAdLoadCallback()
711
720
 
712
- cWebView!!.loadUrl(
721
+ cWebView?.loadUrl(
713
722
  "javascript:cordova.fireDocumentEvent('on.rewarded.loaded');"
714
723
  )
715
724
 
@@ -725,7 +734,7 @@ class emiAdmobPlugin : CordovaPlugin() {
725
734
  result.put("currency", currencyCode)
726
735
  result.put("precision", precision)
727
736
  result.put("adUnitId", rewardedAdAdUnitId)
728
- cWebView!!.loadUrl(
737
+ cWebView?.loadUrl(
729
738
  "javascript:cordova.fireDocumentEvent('on.rewarded.revenue', ${result});"
730
739
  )
731
740
  } catch (e: JSONException) {
@@ -757,10 +766,10 @@ class emiAdmobPlugin : CordovaPlugin() {
757
766
  private val isRewardedAutoShow: Unit
758
767
  get() {
759
768
  if (mActivity != null) {
760
- mActivity!!.runOnUiThread {
769
+ mActivity?.runOnUiThread {
761
770
  if (isRewardedLoad && rewardedAd != null) {
762
771
  isAdSkip = 1
763
- rewardedAd!!.show(mActivity!!) { rewardItem: RewardItem ->
772
+ rewardedAd?.show(mActivity!!) { rewardItem: RewardItem ->
764
773
  isAdSkip = 2
765
774
  val rewardAmount = rewardItem.amount
766
775
  val rewardType = rewardItem.type
@@ -768,7 +777,7 @@ class emiAdmobPlugin : CordovaPlugin() {
768
777
  try {
769
778
  result.put("rewardType", rewardType)
770
779
  result.put("rewardAmount", rewardAmount)
771
- cWebView!!.loadUrl(
780
+ cWebView?.loadUrl(
772
781
  "javascript:cordova.fireDocumentEvent('on.reward.userEarnedReward', ${result});"
773
782
  )
774
783
  } catch (e: JSONException) {
@@ -789,9 +798,9 @@ class emiAdmobPlugin : CordovaPlugin() {
789
798
  return true
790
799
  } else if (action == "showRewardedAd") {
791
800
  if (mActivity != null && isRewardedLoad && rewardedAd != null) {
792
- mActivity!!.runOnUiThread {
801
+ mActivity?.runOnUiThread {
793
802
  isAdSkip = 1
794
- rewardedAd!!.show(mActivity!!) { rewardItem: RewardItem ->
803
+ rewardedAd?.show(mActivity!!) { rewardItem: RewardItem ->
795
804
  isAdSkip = 2
796
805
  val rewardAmount = rewardItem.amount
797
806
  val rewardType = rewardItem.type
@@ -799,7 +808,7 @@ class emiAdmobPlugin : CordovaPlugin() {
799
808
  try {
800
809
  result.put("rewardType", rewardType)
801
810
  result.put("rewardAmount", rewardAmount)
802
- cWebView!!.loadUrl("javascript:cordova.fireDocumentEvent('on.reward.userEarnedReward', ${result});")
811
+ cWebView?.loadUrl("javascript:cordova.fireDocumentEvent('on.reward.userEarnedReward', ${result});")
803
812
  } catch (e: JSONException) {
804
813
  callbackContext.error(e.message)
805
814
  }
@@ -816,7 +825,7 @@ class emiAdmobPlugin : CordovaPlugin() {
816
825
  } else if (action == "loadRewardedInterstitialAd") {
817
826
  val options = args.getJSONObject(0)
818
827
  if (mActivity != null) {
819
- mActivity!!.runOnUiThread {
828
+ mActivity?.runOnUiThread {
820
829
  val adUnitId = options.optString("adUnitId")
821
830
  val autoShow = options.optBoolean("autoShow")
822
831
  try {
@@ -829,7 +838,7 @@ class emiAdmobPlugin : CordovaPlugin() {
829
838
  isRewardedInterstitialLoad = true
830
839
  isAdSkip = 0
831
840
 
832
- cWebView!!.loadUrl(
841
+ cWebView?.loadUrl(
833
842
  "javascript:cordova.fireDocumentEvent('on.rewardedInt.loaded');"
834
843
  )
835
844
 
@@ -870,7 +879,7 @@ class emiAdmobPlugin : CordovaPlugin() {
870
879
  result.put("getResponseExtras", responseInfo?.responseExtras)
871
880
  result.put("getMediationAdapterClassName", responseInfo?.mediationAdapterClassName)
872
881
  result.put("getBundleExtra", mBundleExtra.toString())
873
- cWebView!!.loadUrl(
882
+ cWebView?.loadUrl(
874
883
  "javascript:cordova.fireDocumentEvent('on.rewardedIntAd.responseInfo', ${result});"
875
884
  )
876
885
  } catch (e: JSONException) {
@@ -885,10 +894,10 @@ class emiAdmobPlugin : CordovaPlugin() {
885
894
  private val isRIntAutoShow: Unit
886
895
  get() {
887
896
  if (mActivity !== null) {
888
- mActivity!!.runOnUiThread {
897
+ mActivity?.runOnUiThread {
889
898
  if (isRewardedInterstitialLoad && rewardedInterstitialAd != null) {
890
899
  isAdSkip = 1
891
- rewardedInterstitialAd!!.show(mActivity!!) { rewardItem: RewardItem ->
900
+ rewardedInterstitialAd?.show(mActivity!!) { rewardItem: RewardItem ->
892
901
  isAdSkip = 2
893
902
  val rewardAmount = rewardItem.amount
894
903
  val rewardType = rewardItem.type
@@ -896,7 +905,7 @@ class emiAdmobPlugin : CordovaPlugin() {
896
905
  try {
897
906
  result.put("rewardType", rewardType)
898
907
  result.put("rewardAmount", rewardAmount)
899
- cWebView!!.loadUrl(
908
+ cWebView?.loadUrl(
900
909
  "javascript:cordova.fireDocumentEvent('on.rewardedInt.userEarnedReward', ${result});"
901
910
  )
902
911
  } catch (e: JSONException) {
@@ -930,7 +939,7 @@ class emiAdmobPlugin : CordovaPlugin() {
930
939
  put("responseInfoMediationAdapterClassName", mediationAdapterClassName)
931
940
  put("responseInfoAdapterResponses", adapterResponses)
932
941
  }
933
- cWebView!!.loadUrl(
942
+ cWebView?.loadUrl(
934
943
  "javascript:cordova.fireDocumentEvent('on.rewardedInt.failed.load', ${errorData});"
935
944
  )
936
945
 
@@ -944,10 +953,10 @@ class emiAdmobPlugin : CordovaPlugin() {
944
953
  return true
945
954
  } else if (action == "showRewardedInterstitialAd") {
946
955
  if (mActivity != null) {
947
- mActivity!!.runOnUiThread {
956
+ mActivity?.runOnUiThread {
948
957
  if (isRewardedInterstitialLoad && rewardedInterstitialAd != null) {
949
958
  isAdSkip = 1
950
- rewardedInterstitialAd!!.show(mActivity!!) { rewardItem: RewardItem ->
959
+ rewardedInterstitialAd?.show(mActivity!!) { rewardItem: RewardItem ->
951
960
  isAdSkip = 2
952
961
  val rewardAmount = rewardItem.amount
953
962
  val rewardType = rewardItem.type
@@ -955,7 +964,7 @@ class emiAdmobPlugin : CordovaPlugin() {
955
964
  try {
956
965
  result.put("rewardType", rewardType)
957
966
  result.put("rewardAmount", rewardAmount)
958
- cWebView!!.loadUrl(
967
+ cWebView?.loadUrl(
959
968
  "javascript:cordova.fireDocumentEvent('on.rewardedInt.userEarnedReward', ${result});"
960
969
  )
961
970
  } catch (e: JSONException) {
@@ -972,7 +981,7 @@ class emiAdmobPlugin : CordovaPlugin() {
972
981
  return true
973
982
  } else if (action == "showPrivacyOptionsForm") {
974
983
  if (mActivity != null) {
975
- mActivity!!.runOnUiThread {
984
+ mActivity?.runOnUiThread {
976
985
  try {
977
986
  val params: ConsentRequestParameters
978
987
  if (this.setDebugGeography) {
@@ -1005,8 +1014,8 @@ class emiAdmobPlugin : CordovaPlugin() {
1005
1014
  it1
1006
1015
  ) { loadAndShowError: FormError? ->
1007
1016
  if (loadAndShowError != null) {
1008
- mActivity!!.runOnUiThread {
1009
- cWebView!!.loadUrl("javascript:cordova.fireDocumentEvent('on.consent.failed.show', { message: '" + loadAndShowError.message + "' });")
1017
+ mActivity?.runOnUiThread {
1018
+ cWebView?.loadUrl("javascript:cordova.fireDocumentEvent('on.consent.failed.show', { message: '" + loadAndShowError.message + "' });")
1010
1019
  }
1011
1020
  }
1012
1021
  if (isPrivacyOptionsRequired == ConsentInformation.PrivacyOptionsRequirementStatus.REQUIRED) {
@@ -1015,8 +1024,8 @@ class emiAdmobPlugin : CordovaPlugin() {
1015
1024
  it2
1016
1025
  ) { formError: FormError? ->
1017
1026
  if (formError != null) {
1018
- mActivity!!.runOnUiThread {
1019
- cWebView!!.loadUrl("javascript:cordova.fireDocumentEvent('on.consent.failed.show.options', { message: '" + formError.message + "' });")
1027
+ mActivity?.runOnUiThread {
1028
+ cWebView?.loadUrl("javascript:cordova.fireDocumentEvent('on.consent.failed.show.options', { message: '" + formError.message + "' });")
1020
1029
  }
1021
1030
  }
1022
1031
  }
@@ -1026,7 +1035,7 @@ class emiAdmobPlugin : CordovaPlugin() {
1026
1035
  }
1027
1036
  },
1028
1037
  { requestConsentError: FormError ->
1029
- cWebView!!.loadUrl("javascript:cordova.fireDocumentEvent('on.consent.info.update.failed', { message: '" + requestConsentError.message + "' });")
1038
+ cWebView?.loadUrl("javascript:cordova.fireDocumentEvent('on.consent.info.update.failed', { message: '" + requestConsentError.message + "' });")
1030
1039
  })
1031
1040
  }
1032
1041
  } catch (e: Exception) {
@@ -1037,9 +1046,9 @@ class emiAdmobPlugin : CordovaPlugin() {
1037
1046
  return true
1038
1047
  } else if (action == "consentReset") {
1039
1048
  if (mActivity != null) {
1040
- mActivity!!.runOnUiThread {
1049
+ mActivity?.runOnUiThread {
1041
1050
  try {
1042
- consentInformation!!.reset()
1051
+ consentInformation?.reset()
1043
1052
  } catch (e: Exception) {
1044
1053
  callbackContext.error(e.toString())
1045
1054
  }
@@ -1048,11 +1057,11 @@ class emiAdmobPlugin : CordovaPlugin() {
1048
1057
  return true
1049
1058
  } else if (action == "getIabTfc") {
1050
1059
  if (mActivity != null) {
1051
- mActivity!!.runOnUiThread {
1052
- val gdprApplies = mPreferences!!.getInt("IABTCF_gdprApplies", 0)
1053
- val purposeConsents = mPreferences!!.getString("IABTCF_PurposeConsents", "")
1054
- val vendorConsents = mPreferences!!.getString("IABTCF_VendorConsents", "")
1055
- val consentString = mPreferences!!.getString("IABTCF_TCString", "")
1060
+ mActivity?.runOnUiThread {
1061
+ val gdprApplies = mPreferences?.getInt("IABTCF_gdprApplies", 0)
1062
+ val purposeConsents = mPreferences?.getString("IABTCF_PurposeConsents", "")
1063
+ val vendorConsents = mPreferences?.getString("IABTCF_VendorConsents", "")
1064
+ val consentString = mPreferences?.getString("IABTCF_TCString", "")
1056
1065
  val userInfoJson = JSONObject()
1057
1066
  try {
1058
1067
  userInfoJson.put("IABTCF_gdprApplies", gdprApplies)
@@ -1066,10 +1075,10 @@ class emiAdmobPlugin : CordovaPlugin() {
1066
1075
  //val key = "IABTCF_TCString"
1067
1076
  getString(consentString.toString())
1068
1077
  callbackContext.success(userInfoJson)
1069
- cWebView!!.loadUrl("javascript:cordova.fireDocumentEvent('on.getIabTfc');")
1078
+ cWebView?.loadUrl("javascript:cordova.fireDocumentEvent('on.getIabTfc');")
1070
1079
  } catch (e: Exception) {
1071
1080
  callbackContext.error(e.toString())
1072
- cWebView!!.loadUrl("javascript:cordova.fireDocumentEvent('on.getIabTfc.error');")
1081
+ cWebView?.loadUrl("javascript:cordova.fireDocumentEvent('on.getIabTfc.error');")
1073
1082
  }
1074
1083
  }
1075
1084
  }
@@ -1077,7 +1086,7 @@ class emiAdmobPlugin : CordovaPlugin() {
1077
1086
  } else if (action == "loadBannerAd") {
1078
1087
  if (mActivity != null) {
1079
1088
  val options = args.getJSONObject(0)
1080
- mActivity!!.runOnUiThread {
1089
+ mActivity?.runOnUiThread {
1081
1090
  val adUnitId = options.optString("adUnitId")
1082
1091
  val position = options.optString("position")
1083
1092
  val collapsible = options.optString("collapsible")
@@ -1102,19 +1111,19 @@ class emiAdmobPlugin : CordovaPlugin() {
1102
1111
  return true
1103
1112
  } else if (action == "showBannerAd") {
1104
1113
  if (mActivity != null) {
1105
- mActivity!!.runOnUiThread {
1114
+ mActivity?.runOnUiThread {
1106
1115
  if (isBannerPause == 0) {
1107
1116
  isShowBannerAds
1108
1117
  } else if (isBannerPause == 1) {
1109
1118
  try {
1110
- bannerView!!.visibility = View.VISIBLE
1111
- bannerView!!.resume()
1119
+ bannerView?.visibility = View.VISIBLE
1120
+ bannerView?.resume()
1112
1121
 
1113
1122
  if (isOverlapping) {
1114
1123
  bannerOverlapping()
1115
1124
  }
1116
1125
 
1117
- bannerViewLayout!!.requestFocus();
1126
+ bannerViewLayout?.requestFocus();
1118
1127
 
1119
1128
 
1120
1129
  } catch (e: Exception) {
@@ -1127,7 +1136,7 @@ class emiAdmobPlugin : CordovaPlugin() {
1127
1136
  } else if (action == "styleBannerAd") {
1128
1137
  val options = args.getJSONObject(0)
1129
1138
  if (mActivity != null) {
1130
- mActivity!!.runOnUiThread {
1139
+ mActivity?.runOnUiThread {
1131
1140
  val screenHeight: Int
1132
1141
  val usableHeight: Int
1133
1142
 
@@ -1150,6 +1159,7 @@ class emiAdmobPlugin : CordovaPlugin() {
1150
1159
  val navBarHeight = maxOf(0, screenHeight - usableHeight)
1151
1160
 
1152
1161
  val isOverlapping = options.optBoolean("isOverlapping", false)
1162
+ val setStatusBarShow = options.optBoolean("isStatusBarShow", true)
1153
1163
  val overlappingHeight = options.optInt("overlappingHeight", navBarHeight)
1154
1164
  val paddingPx = options.optInt("padding", 0)
1155
1165
  val marginsPx = options.optInt("margins", navBarHeight)
@@ -1158,6 +1168,7 @@ class emiAdmobPlugin : CordovaPlugin() {
1158
1168
  try {
1159
1169
  // Make sure to only set variables if they have the correct values
1160
1170
  this.isOverlapping = isOverlapping
1171
+ this.isStatusBarShow = setStatusBarShow
1161
1172
  this.overlappingHeight = if (overlappingHeight > 0) overlappingHeight else navBarHeight
1162
1173
  this.paddingInPx = paddingPx
1163
1174
  this.marginsInPx = if (marginsPx > 0) marginsPx else navBarHeight
@@ -1193,11 +1204,11 @@ class emiAdmobPlugin : CordovaPlugin() {
1193
1204
  return true
1194
1205
  } else if (action == "hideBannerAd") {
1195
1206
  if (mActivity != null) {
1196
- mActivity!!.runOnUiThread {
1207
+ mActivity?.runOnUiThread {
1197
1208
  if (isBannerShow) {
1198
1209
  try {
1199
- bannerView!!.visibility = View.GONE
1200
- bannerView!!.pause()
1210
+ bannerView?.visibility = View.GONE
1211
+ bannerView?.pause()
1201
1212
  isBannerLoad = false
1202
1213
  isBannerPause = 1
1203
1214
  bannerOverlappingToZero()
@@ -1210,12 +1221,12 @@ class emiAdmobPlugin : CordovaPlugin() {
1210
1221
  return true
1211
1222
  } else if (action == "removeBannerAd") {
1212
1223
  if (mActivity != null) {
1213
- mActivity!!.runOnUiThread {
1224
+ mActivity?.runOnUiThread {
1214
1225
  try {
1215
1226
  if (bannerViewLayout != null && bannerView != null) {
1216
1227
  bannerOverlappingToZero()
1217
- bannerViewLayout!!.removeView(bannerView)
1218
- bannerView!!.destroy()
1228
+ bannerViewLayout?.removeView(bannerView)
1229
+ bannerView?.destroy()
1219
1230
  bannerView = null
1220
1231
  bannerViewLayout = null
1221
1232
  isBannerLoad = false
@@ -1232,7 +1243,7 @@ class emiAdmobPlugin : CordovaPlugin() {
1232
1243
 
1233
1244
  } else if (action == "registerWebView") {
1234
1245
  if (mActivity != null) {
1235
- mActivity!!.runOnUiThread {
1246
+ mActivity?.runOnUiThread {
1236
1247
  try {
1237
1248
  registerWebView(callbackContext)
1238
1249
  } catch (e: Exception) {
@@ -1245,11 +1256,11 @@ class emiAdmobPlugin : CordovaPlugin() {
1245
1256
  val options = args.getJSONObject(0)
1246
1257
  if (mActivity != null) {
1247
1258
  val url = options.optString("url")
1248
- mActivity!!.runOnUiThread {
1259
+ mActivity?.runOnUiThread {
1249
1260
  try {
1250
1261
  loadUrl(url, callbackContext)
1251
1262
  } catch (e: Exception) {
1252
- PUBLIC_CALLBACKS!!.error("Error load Url: " + e.message)
1263
+ PUBLIC_CALLBACKS?.error("Error load Url: " + e.message)
1253
1264
  }
1254
1265
  }
1255
1266
 
@@ -1303,19 +1314,19 @@ class emiAdmobPlugin : CordovaPlugin() {
1303
1314
  FrameLayout.LayoutParams.MATCH_PARENT,
1304
1315
  FrameLayout.LayoutParams.MATCH_PARENT
1305
1316
  )
1306
- val decorView = mActivity!!.window.decorView as ViewGroup
1317
+ val decorView = mActivity?.window?.decorView as ViewGroup
1307
1318
  decorView.addView(bannerViewLayout, params)
1308
1319
  bannerView = AdView(mActivity!!)
1309
1320
  setBannerPosition(position)
1310
1321
  setBannerSize(size)
1311
- bannerView!!.adUnitId = adUnitId
1312
- bannerView!!.adListener = bannerAdListener
1313
- bannerView!!.loadAd(buildAdRequest())
1322
+ bannerView?.adUnitId = adUnitId
1323
+ bannerView?.adListener = bannerAdListener
1324
+ bannerView?.loadAd(buildAdRequest())
1314
1325
  } else {
1315
1326
  Log.d(TAG, "Banner view layout already exists.")
1316
1327
  }
1317
1328
  } catch (e: Exception) {
1318
- PUBLIC_CALLBACKS!!.error("Error showing banner: " + e.message)
1329
+ PUBLIC_CALLBACKS?.error("Error showing banner: " + e.message)
1319
1330
  Log.d(TAG, "Error showing banner: " + e.message)
1320
1331
  }
1321
1332
  }
@@ -1387,9 +1398,9 @@ class emiAdmobPlugin : CordovaPlugin() {
1387
1398
  try {
1388
1399
  if (mActivity != null && bannerView != null && bannerViewLayout != null) {
1389
1400
  if (lock) {
1390
- bannerViewLayout!!.addView(bannerView)
1391
- bannerViewLayout!!.bringToFront()
1392
- bannerViewLayout!!.requestFocus();
1401
+ bannerViewLayout?.addView(bannerView)
1402
+ bannerViewLayout?.bringToFront()
1403
+ bannerViewLayout?.requestFocus();
1393
1404
  lock = false
1394
1405
  }
1395
1406
  isBannerPause = 0
@@ -1397,12 +1408,12 @@ class emiAdmobPlugin : CordovaPlugin() {
1397
1408
  } else {
1398
1409
  val errorMessage = "Error showing banner: bannerView or bannerViewLayout is null."
1399
1410
  // Log.e("isBannerAutoShow", errorMessage)
1400
- PUBLIC_CALLBACKS!!.error(errorMessage)
1411
+ PUBLIC_CALLBACKS?.error(errorMessage)
1401
1412
  }
1402
1413
  } catch (e: Exception) {
1403
1414
  val errorMessage = "Error showing banner: " + e.message
1404
1415
  // Log.e("isBannerAutoShow", errorMessage, e)
1405
- PUBLIC_CALLBACKS!!.error(errorMessage)
1416
+ PUBLIC_CALLBACKS?.error(errorMessage)
1406
1417
  }
1407
1418
  }
1408
1419
 
@@ -1412,15 +1423,15 @@ class emiAdmobPlugin : CordovaPlugin() {
1412
1423
  if (mActivity != null && isBannerLoad && bannerView != null) {
1413
1424
  try {
1414
1425
  if (lock) {
1415
- bannerViewLayout!!.addView(bannerView)
1416
- bannerViewLayout!!.bringToFront()
1417
- bannerViewLayout!!.requestFocus();
1426
+ bannerViewLayout?.addView(bannerView)
1427
+ bannerViewLayout?.bringToFront()
1428
+ bannerViewLayout?.requestFocus();
1418
1429
  lock = false
1419
1430
  }
1420
1431
  isBannerShow = true
1421
1432
  } catch (e: Exception) {
1422
1433
  lock = true
1423
- PUBLIC_CALLBACKS!!.error(e.toString())
1434
+ PUBLIC_CALLBACKS?.error(e.toString())
1424
1435
  }
1425
1436
  }
1426
1437
  }
@@ -1461,8 +1472,8 @@ class emiAdmobPlugin : CordovaPlugin() {
1461
1472
  bannerOverlappingToZero()
1462
1473
 
1463
1474
  if (bannerViewLayout != null && bannerView != null) {
1464
- bannerViewLayout!!.removeView(bannerView)
1465
- bannerView!!.destroy()
1475
+ bannerViewLayout?.removeView(bannerView)
1476
+ bannerView?.destroy()
1466
1477
  bannerView = null
1467
1478
  bannerViewLayout = null
1468
1479
  isBannerLoad = false
@@ -1532,7 +1543,7 @@ class emiAdmobPlugin : CordovaPlugin() {
1532
1543
  if (bannerView!!.isCollapsible) "collapsible" else "not collapsible"
1533
1544
  )
1534
1545
 
1535
- cWebView!!.loadUrl("javascript:cordova.fireDocumentEvent('on.is.collapsible', $eventData)")
1546
+ cWebView?.loadUrl("javascript:cordova.fireDocumentEvent('on.is.collapsible', $eventData)")
1536
1547
 
1537
1548
  bannerView?.onPaidEventListener = bannerPaidAdListener
1538
1549
 
@@ -1568,24 +1579,24 @@ class emiAdmobPlugin : CordovaPlugin() {
1568
1579
 
1569
1580
  private fun bannerOverlappingToZero() {
1570
1581
  if (bannerView != null && mActivity != null && cWebView != null) {
1571
- mActivity!!.runOnUiThread {
1582
+ mActivity?.runOnUiThread {
1572
1583
  try {
1573
- val rootView = (cWebView!!.view.parent as View)
1584
+ val rootView = (cWebView?.view?.parent as View)
1574
1585
  rootView.post {
1575
1586
  // Get the total height of the parent view
1576
1587
  val totalHeight = rootView.height
1577
1588
 
1578
1589
  // Adjust WebView height to match parent height
1579
- val layoutParams = cWebView!!.view.layoutParams
1580
- layoutParams.height = totalHeight
1581
- cWebView!!.view.layoutParams = layoutParams
1590
+ val layoutParams = cWebView?.view?.layoutParams
1591
+ layoutParams?.height = totalHeight
1592
+ cWebView?.view?.layoutParams = layoutParams
1582
1593
 
1583
1594
  // Ensure no padding/margin in WebView or its parent
1584
- cWebView!!.view.setPadding(0, 0, 0, 0)
1585
- (cWebView!!.view.parent as? ViewGroup)?.setPadding(0, 0, 0, 0)
1595
+ cWebView?.view?.setPadding(0, 0, 0, 0)
1596
+ (cWebView?.view?.parent as? ViewGroup)?.setPadding(0, 0, 0, 0)
1586
1597
 
1587
1598
  // Force layout update
1588
- cWebView!!.view.requestLayout()
1599
+ cWebView?.view?.requestLayout()
1589
1600
 
1590
1601
  Log.d("BannerAdjustment", "WebView set to full height: $totalHeight")
1591
1602
  }
@@ -1599,27 +1610,30 @@ class emiAdmobPlugin : CordovaPlugin() {
1599
1610
 
1600
1611
 
1601
1612
 
1602
- private fun bannerOverlapping() {
1603
- if (bannerView != null && mActivity != null && cWebView != null) {
1604
- mActivity!!.runOnUiThread {
1605
- try {
1606
-
1607
- val displayMetrics = DisplayMetrics()
1608
- mActivity!!.windowManager.defaultDisplay.getMetrics(displayMetrics)
1609
- val screenHeightInPx = displayMetrics.heightPixels
1610
-
1611
- val webViewHeight = screenHeightInPx - (adSize.height + overlappingHeight)
1612
- val layoutParams = cWebView!!.view.layoutParams
1613
- layoutParams.height = webViewHeight
1614
- cWebView!!.view.layoutParams = layoutParams
1615
-
1616
- // Log.d("BannerAdjustment", "Adjusted WebView height: $webViewHeight")
1617
- } catch (e: Exception) {
1618
- Log.e("AdmobPlugin", "Error adjusting WebView for banner: ${e.message}")
1613
+ private fun bannerOverlapping() {
1614
+ if (bannerView != null && mActivity != null && cWebView != null) {
1615
+ mActivity?.runOnUiThread {
1616
+ try {
1617
+ val displayMetrics = DisplayMetrics()
1618
+ mActivity!!.windowManager.defaultDisplay.getMetrics(displayMetrics)
1619
+ val screenHeightInPx = displayMetrics.heightPixels
1620
+
1621
+ val webViewHeight = if (isStatusBarShow) {
1622
+ screenHeightInPx - (adSize.height + overlappingHeight)
1623
+ } else {
1624
+ screenHeightInPx + (adSize.height + overlappingHeight)
1619
1625
  }
1626
+ val layoutParams = cWebView!!.view.layoutParams
1627
+ layoutParams.height = webViewHeight
1628
+ cWebView!!.view.layoutParams = layoutParams
1629
+
1630
+ // Log.d("BannerAdjustment", "Adjusted WebView height: $webViewHeight")
1631
+ } catch (e: Exception) {
1632
+ Log.e("AdmobPlugin", "Error adjusting WebView for banner: ${e.message}")
1620
1633
  }
1621
1634
  }
1622
1635
  }
1636
+ }
1623
1637
 
1624
1638
 
1625
1639
 
@@ -1649,31 +1663,31 @@ class emiAdmobPlugin : CordovaPlugin() {
1649
1663
 
1650
1664
  private fun setBannerSize(size: String?) {
1651
1665
  when (size) {
1652
- "responsive_adaptive" -> bannerView!!.setAdSize(adSize)
1653
- "anchored_adaptive" -> bannerView!!.setAdSize(
1666
+ "responsive_adaptive" -> bannerView?.setAdSize(adSize)
1667
+ "anchored_adaptive" -> bannerView?.setAdSize(
1654
1668
  AdSize.getCurrentOrientationAnchoredAdaptiveBannerAdSize(
1655
1669
  mActivity!!, adWidth
1656
1670
  )
1657
1671
  )
1658
1672
 
1659
- "full_width_adaptive" -> bannerView!!.setAdSize(
1673
+ "full_width_adaptive" -> bannerView?.setAdSize(
1660
1674
  AdSize.getCurrentOrientationAnchoredAdaptiveBannerAdSize(
1661
1675
  mActivity!!, adWidth
1662
1676
  )
1663
1677
  )
1664
1678
 
1665
- "in_line_adaptive" -> bannerView!!.setAdSize(
1679
+ "in_line_adaptive" -> bannerView?.setAdSize(
1666
1680
  AdSize.getCurrentOrientationInlineAdaptiveBannerAdSize(
1667
1681
  mActivity!!, adWidth
1668
1682
  )
1669
1683
  )
1670
1684
 
1671
- "banner" -> bannerView!!.setAdSize(AdSize.BANNER)
1672
- "large_banner" -> bannerView!!.setAdSize(AdSize.LARGE_BANNER)
1673
- "medium_rectangle" -> bannerView!!.setAdSize(AdSize.MEDIUM_RECTANGLE)
1674
- "full_banner" -> bannerView!!.setAdSize(AdSize.FULL_BANNER)
1675
- "leaderboard" -> bannerView!!.setAdSize(AdSize.LEADERBOARD)
1676
- "fluid" -> bannerView!!.setAdSize(AdSize.FLUID)
1685
+ "banner" -> bannerView?.setAdSize(AdSize.BANNER)
1686
+ "large_banner" -> bannerView?.setAdSize(AdSize.LARGE_BANNER)
1687
+ "medium_rectangle" -> bannerView?.setAdSize(AdSize.MEDIUM_RECTANGLE)
1688
+ "full_banner" -> bannerView?.setAdSize(AdSize.FULL_BANNER)
1689
+ "leaderboard" -> bannerView?.setAdSize(AdSize.LEADERBOARD)
1690
+ "fluid" -> bannerView?.setAdSize(AdSize.FLUID)
1677
1691
  }
1678
1692
  }
1679
1693
 
@@ -1692,7 +1706,7 @@ class emiAdmobPlugin : CordovaPlugin() {
1692
1706
  outMetrics.density = mActivity!!.resources.displayMetrics.density
1693
1707
  } else {
1694
1708
  @Suppress("DEPRECATION")
1695
- mActivity!!.windowManager.defaultDisplay.getMetrics(outMetrics)
1709
+ mActivity?.windowManager?.defaultDisplay?.getMetrics(outMetrics)
1696
1710
  }
1697
1711
 
1698
1712
  val density = outMetrics.density
@@ -1739,15 +1753,15 @@ class emiAdmobPlugin : CordovaPlugin() {
1739
1753
  it1
1740
1754
  ) { formError: FormError? ->
1741
1755
  if (formError != null) {
1742
- mActivity!!.runOnUiThread {
1743
- cWebView!!.loadUrl("javascript:cordova.fireDocumentEvent('on.consent.failed.show', { message: '" + formError.message + "' });")
1756
+ mActivity?.runOnUiThread {
1757
+ cWebView?.loadUrl("javascript:cordova.fireDocumentEvent('on.consent.failed.show', { message: '" + formError.message + "' });")
1744
1758
  }
1745
1759
  }
1746
1760
  }
1747
1761
  }
1748
1762
  },
1749
1763
  { formError: FormError ->
1750
- cWebView!!.loadUrl("javascript:cordova.fireDocumentEvent('on.consent.failed.load.from', { message: '" + formError.message + "' });")
1764
+ cWebView?.loadUrl("javascript:cordova.fireDocumentEvent('on.consent.failed.load.from', { message: '" + formError.message + "' });")
1751
1765
  }
1752
1766
  )
1753
1767
  }
@@ -2053,11 +2067,11 @@ class emiAdmobPlugin : CordovaPlugin() {
2053
2067
  put("domain", adError.domain)
2054
2068
  put("cause", adError.cause?.toString() ?: "null")
2055
2069
  }
2056
- cWebView!!.loadUrl("javascript:cordova.fireDocumentEvent('on.appOpenAd.failed.show', ${errorData});")
2070
+ cWebView?.loadUrl("javascript:cordova.fireDocumentEvent('on.appOpenAd.failed.show', ${errorData});")
2057
2071
  }
2058
2072
 
2059
2073
  override fun onAdShowedFullScreenContent() {
2060
- cWebView!!.loadUrl("javascript:cordova.fireDocumentEvent('on.appOpenAd.show');")
2074
+ cWebView?.loadUrl("javascript:cordova.fireDocumentEvent('on.appOpenAd.show');")
2061
2075
  }
2062
2076
  }
2063
2077
  }
@@ -2066,7 +2080,7 @@ class emiAdmobPlugin : CordovaPlugin() {
2066
2080
  private fun interstitialAdLoadCallback() {
2067
2081
  mInterstitialAd?.fullScreenContentCallback = object : FullScreenContentCallback() {
2068
2082
  override fun onAdClicked() {
2069
- cWebView!!.loadUrl("javascript:cordova.fireDocumentEvent('on.interstitial.click');")
2083
+ cWebView?.loadUrl("javascript:cordova.fireDocumentEvent('on.interstitial.click');")
2070
2084
  }
2071
2085
 
2072
2086
  override fun onAdDismissedFullScreenContent() {
@@ -2074,7 +2088,7 @@ class emiAdmobPlugin : CordovaPlugin() {
2074
2088
  isInterstitialLoad = false
2075
2089
  val mainView: View? = view
2076
2090
  mainView?.requestFocus()
2077
- cWebView!!.loadUrl("javascript:cordova.fireDocumentEvent('on.interstitial.dismissed');")
2091
+ cWebView?.loadUrl("javascript:cordova.fireDocumentEvent('on.interstitial.dismissed');")
2078
2092
  }
2079
2093
 
2080
2094
  override fun onAdFailedToShowFullScreenContent(adError: AdError) {
@@ -2086,15 +2100,15 @@ class emiAdmobPlugin : CordovaPlugin() {
2086
2100
  put("domain", adError.domain)
2087
2101
  put("cause", adError.cause?.toString() ?: "null")
2088
2102
  }
2089
- cWebView!!.loadUrl("javascript:cordova.fireDocumentEvent('on.interstitial.failed.show', ${errorData});")
2103
+ cWebView?.loadUrl("javascript:cordova.fireDocumentEvent('on.interstitial.failed.show', ${errorData});")
2090
2104
  }
2091
2105
 
2092
2106
  override fun onAdImpression() {
2093
- cWebView!!.loadUrl("javascript:cordova.fireDocumentEvent('on.interstitial.impression');")
2107
+ cWebView?.loadUrl("javascript:cordova.fireDocumentEvent('on.interstitial.impression');")
2094
2108
  }
2095
2109
 
2096
2110
  override fun onAdShowedFullScreenContent() {
2097
- cWebView!!.loadUrl("javascript:cordova.fireDocumentEvent('on.interstitial.show');")
2111
+ cWebView?.loadUrl("javascript:cordova.fireDocumentEvent('on.interstitial.show');")
2098
2112
  }
2099
2113
  }
2100
2114
  }
@@ -2111,7 +2125,7 @@ class emiAdmobPlugin : CordovaPlugin() {
2111
2125
  isRewardedLoad = false
2112
2126
  val mainView: View? = view
2113
2127
  mainView?.requestFocus()
2114
- cWebView!!.loadUrl("javascript:cordova.fireDocumentEvent('on.rewarded.ad.skip');")
2128
+ cWebView?.loadUrl("javascript:cordova.fireDocumentEvent('on.rewarded.ad.skip');")
2115
2129
  }
2116
2130
  rewardedAd = null
2117
2131
  isRewardedLoad = false
@@ -17,6 +17,8 @@
17
17
  @property (nonatomic, assign) BOOL isUsingAdManagerRequest;
18
18
  @property (nonatomic, assign) CGFloat viewWidth;
19
19
  @property (nonatomic, strong) UIView *bannerViewLayout;
20
+ @property (nonatomic, strong) UIView *bannerContainer;
21
+ @property (nonatomic, strong) UIView *webViewContainer;
20
22
 
21
23
  - (void)initialize:(CDVInvokedUrlCommand *)command;
22
24
  - (void)requestIDFA:(CDVInvokedUrlCommand *)command;
@@ -26,6 +28,7 @@
26
28
  - (void)getIabTfc:(CDVInvokedUrlCommand *)command;
27
29
  - (void)loadAppOpenAd:(CDVInvokedUrlCommand *)command;
28
30
  - (void)showAppOpenAd:(CDVInvokedUrlCommand *)command;
31
+ - (void)styleBannerAd:(CDVInvokedUrlCommand *)command;
29
32
  - (void)loadBannerAd:(CDVInvokedUrlCommand *)command;
30
33
  - (void)showBannerAd:(CDVInvokedUrlCommand *)command;
31
34
  - (void)hideBannerAd:(CDVInvokedUrlCommand *)command;
@@ -38,3 +41,4 @@
38
41
  - (void)showRewardedAd:(CDVInvokedUrlCommand *)command;
39
42
  - (void) fireEvent:(NSString *)obj event:(NSString *)eventName withData:(NSString *)jsonStr;
40
43
  @end
44
+
@@ -4,6 +4,7 @@
4
4
  #import <Cordova/CDVPlugin.h>
5
5
  #import <Foundation/Foundation.h>
6
6
  #import <UserMessagingPlatform/UserMessagingPlatform.h>
7
+ #import <Cordova/CDVViewController.h>
7
8
  @implementation emiAdmobPlugin
8
9
  @synthesize appOpenAd;
9
10
  @synthesize bannerView;
@@ -18,6 +19,7 @@ int attStatus = 0;
18
19
  int Consent_Status = 0;
19
20
  int adFormat = 0;
20
21
  int adWidth = 320; // Default
22
+
21
23
  BOOL auto_Show = NO;
22
24
  // NSString *Npa = @"1"; // Deprecated
23
25
  NSString *setPosition = @"bottom-center"; // Default
@@ -26,6 +28,11 @@ NSString *bannerSaveAdUnitId = @""; // autoResize dependency = true
26
28
  BOOL isCollapsible = NO;
27
29
  BOOL isAutoResize = NO;
28
30
 
31
+
32
+ CGFloat paddingWebView = 0; // Default
33
+ BOOL isSetOverlapping = NO; // Default
34
+ CGFloat bannerHeightFinal = 50; // Default
35
+
29
36
  int isAdSkip = 0;
30
37
  BOOL UnderAgeOfConsent = NO;
31
38
  BOOL isPrivacyOptions = NO;
@@ -33,6 +40,7 @@ BOOL isDebugGeography = NO;
33
40
  BOOL isResponseInfo = NO;
34
41
  BOOL isUsingAdManagerRequest = YES;
35
42
 
43
+
36
44
  - (BOOL)canRequestAds {
37
45
  return UMPConsentInformation.sharedInstance.canRequestAds;
38
46
  }
@@ -259,7 +267,7 @@ BOOL isUsingAdManagerRequest = YES;
259
267
  } else {
260
268
  [UMPConsentForm presentPrivacyOptionsFormFromViewController:self.viewController completionHandler:^(NSError *_Nullable formError) {
261
269
  if (formError) {
262
- // NSLog(@"Error when displaying the form: %@", formError);
270
+ NSLog(@"Error when displaying the form: %@", formError);
263
271
  }
264
272
  }];
265
273
  }
@@ -324,8 +332,7 @@ BOOL isUsingAdManagerRequest = YES;
324
332
 
325
333
  - (BOOL)isPrivacyOptionsRequired {
326
334
  UMPPrivacyOptionsRequirementStatus status = UMPConsentInformation.sharedInstance.privacyOptionsRequirementStatus;
327
- // NSLog(@"[isPrivacyOptionsRequired] Privacy option status: %ld",
328
- // (long)status);
335
+
329
336
  return status == UMPPrivacyOptionsRequirementStatusRequired;
330
337
  }
331
338
 
@@ -347,9 +354,6 @@ BOOL isUsingAdManagerRequest = YES;
347
354
  Consent_Status = UMPConsentStatusObtained;
348
355
  }
349
356
 
350
- /* NSLog(@"The Consent "
351
- @"Status %i",
352
- Consent_Status); */
353
357
  CDVPluginResult *pluginResult =
354
358
  [CDVPluginResult resultWithStatus:CDVCommandStatus_OK
355
359
  messageAsInt:Consent_Status];
@@ -448,7 +452,7 @@ BOOL isUsingAdManagerRequest = YES;
448
452
  requestConfiguration.maxAdContentRating =
449
453
  GADMaxAdContentRatingMatureAudience;
450
454
  } else {
451
- // NSLog(@"Unknown content rating: %@", contentRating);
455
+ NSLog(@"Unknown content rating: %@", contentRating);
452
456
  }
453
457
  }
454
458
 
@@ -538,9 +542,7 @@ BOOL isUsingAdManagerRequest = YES;
538
542
  [self.bannerViewLayout bringSubviewToFront:self.bannerView];
539
543
 
540
544
  } @catch (NSException *exception) {
541
- // NSLog(@"Error adjusting banner size: %@", exception.reason);
542
- // PUBLIC_CALLBACKS.error([NSString stringWithFormat:@"Error adjusting
543
- // banner size: %@", exception.reason]);
545
+ // banner size: %@", exception.reason]);
544
546
  }
545
547
  });
546
548
  }
@@ -631,37 +633,12 @@ BOOL isUsingAdManagerRequest = YES;
631
633
 
632
634
 
633
635
 
634
- - (GADAdSize)__AdSizeFromString:(NSString *)size {
635
-
636
- if (self.viewWidth == 0) {
637
- self.viewWidth = [UIScreen mainScreen].bounds.size.width;
638
- }
639
-
640
- if ([size isEqualToString:@"responsive_adaptive"]) {
641
- return GADCurrentOrientationAnchoredAdaptiveBannerAdSizeWithWidth(
642
- self.viewWidth);
643
- } else if ([size isEqualToString:@"in_line_adaptive"]) {
644
- return GADCurrentOrientationInlineAdaptiveBannerAdSizeWithWidth(
645
- self.viewWidth);
646
- } else if ([size isEqualToString:@"banner"]) {
647
- return GADAdSizeBanner;
648
- } else if ([size isEqualToString:@"large_banner"]) {
649
- return GADAdSizeLargeBanner;
650
- } else if ([size isEqualToString:@"full_banner"]) {
651
- return GADAdSizeFullBanner;
652
- } else if ([size isEqualToString:@"leaderboard"]) {
653
- return GADAdSizeLeaderboard;
654
- } else {
655
- return GADAdSizeBanner;
656
- }
657
- }
658
-
659
636
  - (void)showBannerAd:(CDVInvokedUrlCommand *)command {
660
637
  CDVPluginResult *pluginResult;
661
638
  NSString *callbackId = command.callbackId;
662
639
  if (self.bannerView) {
663
640
  self.bannerView.hidden = NO;
664
- [self addBannerViewToView:command];
641
+ [self addBannerViewToView:command];
665
642
  pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
666
643
  } else {
667
644
  [self fireEvent:@"" event:@"on.banner.failed.show" withData:nil];
@@ -730,13 +707,162 @@ BOOL isUsingAdManagerRequest = YES;
730
707
  constant:0]
731
708
  ]];
732
709
  }
710
+ [self bannerOverlapping];
733
711
  }
712
+
713
+
714
+
715
+
716
+
717
+ - (void)bannerOverlapping {
718
+ if (!self.bannerView || !self.webView) {
719
+ NSLog(@"[AdPlugin] Error: Missing bannerView or webView. Adjustment skipped.");
720
+ return;
721
+ }
722
+
723
+ if (isSetOverlapping){
724
+
725
+ dispatch_async(dispatch_get_main_queue(), ^{
726
+ @try {
727
+
728
+ CGFloat screenWidth = UIScreen.mainScreen.bounds.size.width;
729
+ CGFloat screenHeight = UIScreen.mainScreen.bounds.size.height;
730
+
731
+ CGFloat navigationBarHeight = 0.0;
732
+ if (@available(iOS 11.0, *)) {
733
+ navigationBarHeight = self.viewController.view.safeAreaInsets.bottom;
734
+ }
735
+
736
+ if (!self.bannerContainer) {
737
+ self.bannerContainer = [[UIView alloc] initWithFrame:CGRectZero];
738
+ // self.bannerContainer.backgroundColor = [UIColor redColor]; // Debug
739
+ [self.viewController.view addSubview:self.bannerContainer];
740
+ }
741
+
742
+ if (!self.webViewContainer) {
743
+ self.webViewContainer = [[UIView alloc] initWithFrame:CGRectZero];
744
+ // self.webViewContainer.backgroundColor = [UIColor blueColor]; // Debug
745
+ [self.viewController.view addSubview:self.webViewContainer];
746
+ }
747
+
748
+ CGRect bannerContainerFrame = CGRectZero;
749
+ if ([setPosition isEqualToString:@"top-center"]) {
750
+ bannerContainerFrame = CGRectMake(0, 0, screenWidth, bannerHeightFinal);
751
+ } else if ([setPosition isEqualToString:@"bottom-center"]) {
752
+ bannerContainerFrame = CGRectMake(0, screenHeight - paddingWebView - bannerHeightFinal - navigationBarHeight, screenWidth, bannerHeightFinal);
753
+ }
754
+ self.bannerContainer.frame = bannerContainerFrame;
755
+
756
+ self.bannerView.frame = self.bannerContainer.bounds;
757
+ [self.bannerContainer addSubview:self.bannerView];
758
+
759
+ CGRect webViewContainerFrame = CGRectZero;
760
+ if ([setPosition isEqualToString:@"top-center"]) {
761
+ webViewContainerFrame = CGRectMake(0, bannerHeightFinal, screenWidth, screenHeight - bannerHeightFinal);
762
+ } else if ([setPosition isEqualToString:@"bottom-center"]) {
763
+
764
+ webViewContainerFrame = CGRectMake(0, 0, screenWidth, screenHeight - bannerHeightFinal - paddingWebView - navigationBarHeight);
765
+
766
+ }
767
+ self.webViewContainer.frame = webViewContainerFrame;
768
+
769
+ self.webView.frame = self.webViewContainer.bounds;
770
+ [self.webViewContainer addSubview:self.webView];
771
+
772
+ [self.bannerContainer setNeedsLayout];
773
+ [self.bannerContainer layoutIfNeeded];
774
+ [self.webViewContainer setNeedsLayout];
775
+ [self.webViewContainer layoutIfNeeded];
776
+
777
+
778
+ NSLog(@"[AdPlugin] Banner and WebView are now in separate containers with proper sizing.");
779
+ } @catch (NSException *exception) {
780
+ NSLog(@"[AdPlugin] Error adjusting layout for banner and WebView: %@", exception.reason);
781
+ }
782
+
783
+ });
784
+ }
785
+ }
786
+
787
+
788
+
789
+
790
+
791
+ - (void)styleBannerAd:(CDVInvokedUrlCommand *)command {
792
+
793
+ NSDictionary *options = [command.arguments objectAtIndex:0];
794
+ BOOL isOverlapping = [[options valueForKey:@"isOverlapping"] boolValue];
795
+ CGFloat paddingContainer = [[options valueForKey:@"paddingWebView"] floatValue];
796
+
797
+ isSetOverlapping = isOverlapping;
798
+ paddingWebView = paddingContainer;
799
+
800
+ }
801
+
802
+
803
+ - (GADAdSize)__AdSizeFromString:(NSString *)size {
804
+
805
+ if (self.viewWidth == 0) {
806
+ self.viewWidth = [UIScreen mainScreen].bounds.size.width;
807
+ }
808
+
809
+ if ([size isEqualToString:@"responsive_adaptive"]) {
810
+ return GADCurrentOrientationAnchoredAdaptiveBannerAdSizeWithWidth(
811
+ self.viewWidth);
812
+ } else if ([size isEqualToString:@"in_line_adaptive"]) {
813
+ return GADCurrentOrientationInlineAdaptiveBannerAdSizeWithWidth(
814
+ self.viewWidth);
815
+ } else if ([size isEqualToString:@"banner"]) {
816
+ return GADAdSizeBanner;
817
+ } else if ([size isEqualToString:@"large_banner"]) {
818
+ return GADAdSizeLargeBanner;
819
+ } else if ([size isEqualToString:@"full_banner"]) {
820
+ return GADAdSizeFullBanner;
821
+ } else if ([size isEqualToString:@"leaderboard"]) {
822
+ return GADAdSizeLeaderboard;
823
+ } else {
824
+ return GADAdSizeBanner;
825
+ }
826
+ }
827
+
828
+
829
+
830
+
831
+
832
+
833
+ - (void)resetWebViewHeight {
834
+ if (!self.webView) {
835
+ NSLog(@"[AdPlugin] Error: WebView is missing. Reset skipped.");
836
+ return;
837
+ }
838
+
839
+ dispatch_async(dispatch_get_main_queue(), ^{
840
+ @try {
841
+
842
+ CGFloat screenHeightInPx = UIScreen.mainScreen.bounds.size.height;
843
+
844
+ CGRect webViewFrame = self.webView.frame;
845
+ webViewFrame.size.height = screenHeightInPx;
846
+ self.webView.frame = webViewFrame;
847
+
848
+ [self.webView setNeedsLayout];
849
+ [self.webView layoutIfNeeded];
850
+
851
+ } @catch (NSException *exception) {
852
+ NSLog(@"[AdPlugin] Error resetting WebView height: %@", exception.reason);
853
+ }
854
+ });
855
+ }
856
+
857
+
858
+
734
859
  - (void)hideBannerAd:(CDVInvokedUrlCommand *)command {
735
860
  CDVPluginResult *pluginResult;
736
861
  NSString *callbackId = command.callbackId;
737
862
  if (self.bannerView) {
738
863
  dispatch_async(dispatch_get_main_queue(), ^{
739
864
  self.bannerView.hidden = YES;
865
+ [self resetWebViewHeight];
740
866
  [self fireEvent:@"" event:@"on.banner.hide" withData:nil];
741
867
  });
742
868
  pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
@@ -753,6 +879,7 @@ BOOL isUsingAdManagerRequest = YES;
753
879
  self.bannerView.hidden = YES;
754
880
  [self.bannerView removeFromSuperview];
755
881
  self.bannerView = nil;
882
+ [self resetWebViewHeight];
756
883
  [self fireEvent:@"" event:@"on.banner.remove" withData:nil];
757
884
  });
758
885
  pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
@@ -1436,6 +1563,15 @@ BOOL isUsingAdManagerRequest = YES;
1436
1563
  return hexString;
1437
1564
  }
1438
1565
 
1566
+
1567
+
1568
+
1569
+
1570
+
1571
+
1572
+
1573
+
1574
+
1439
1575
  #pragma mark GADBannerViewDelegate implementation
1440
1576
 
1441
1577
  - (void)bannerViewDidReceiveAd:(GADBannerView *)bannerView {
@@ -1452,9 +1588,9 @@ BOOL isUsingAdManagerRequest = YES;
1452
1588
 
1453
1589
  // Get the banner height
1454
1590
  CGFloat bannerHeight = bannerView.bounds.size.height;
1591
+ bannerHeightFinal = bannerHeight;
1455
1592
 
1456
1593
 
1457
-
1458
1594
  // Prepare height data for banner load event
1459
1595
  NSDictionary *bannerLoadData = @{@"height" : @(bannerHeight)};
1460
1596
  NSData *bannerLoadJsonData = [NSJSONSerialization dataWithJSONObject:bannerLoadData options:0 error:&error];
@@ -1465,7 +1601,7 @@ BOOL isUsingAdManagerRequest = YES;
1465
1601
 
1466
1602
  if (auto_Show && self.bannerView) {
1467
1603
  [self addBannerViewToView:command];
1468
- self.bannerView.hidden = NO;
1604
+ [self showBannerAd:command];
1469
1605
  } else {
1470
1606
  [self fireEvent:@"" event:@"on.banner.failed.show" withData:nil];
1471
1607
  }