emi-indo-cordova-plugin-admob 1.5.8 → 1.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -20,7 +20,7 @@ function loadBanner() {
20
20
  cordova.plugins.emiAdmobPlugin.loadBannerAd({
21
21
  adUnitId: Banner_ID, //Banner_ID,
22
22
  position: "bottom-center",
23
- size: "responsive_adaptive", // autoResize: true (only responsive_adaptive)
23
+ size: "banner", // autoResize: true (only responsive_adaptive)
24
24
  collapsible: "bottom", // position: top | bottom (disable, empty string)
25
25
  autoResize: true, // default false
26
26
  autoShow: true, // default false
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "emi-indo-cordova-plugin-admob",
3
- "version": "1.5.8",
3
+ "version": "1.6.0",
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.8">
3
+ id="emi-indo-cordova-plugin-admob" version="1.6.0">
4
4
 
5
5
  <name>emiAdmobPlugin</name>
6
6
  <description>Cordova Plugin Admob Android IOS</description>
@@ -161,6 +161,7 @@ class emiAdmobPlugin : CordovaPlugin() {
161
161
  if(mActivity != null) {
162
162
  mActivity!!.runOnUiThread {
163
163
  try {
164
+ bannerOverlappingToZero()
164
165
  if (bannerViewLayout != null && bannerView != null) {
165
166
  val parentView = bannerViewLayout!!.parent as ViewGroup
166
167
  parentView.removeView(bannerViewLayout)
@@ -169,22 +170,17 @@ class emiAdmobPlugin : CordovaPlugin() {
169
170
  FrameLayout.LayoutParams.MATCH_PARENT,
170
171
  FrameLayout.LayoutParams.WRAP_CONTENT
171
172
  )
172
- val rootView =
173
- mActivity!!.window.decorView.findViewById<View>(View.generateViewId())
174
- if (rootView is ViewGroup) {
175
- rootView.addView(bannerViewLayout, params)
176
- } else {
177
- mActivity!!.addContentView(bannerViewLayout, params)
178
- }
179
- bannerView = AdView(mContext!!)
173
+ val decorView = mActivity!!.window.decorView as ViewGroup
174
+ decorView.addView(bannerViewLayout, params)
175
+ bannerView = AdView(mActivity!!)
180
176
  setBannerPosition(this.isPosition)
181
177
  setBannerSiz(this.isSize)
182
178
  bannerView!!.adUnitId = bannerAdUnitId!!
183
179
  bannerView!!.adListener = bannerAdListener
184
180
  bannerView!!.loadAd(buildAdRequest())
185
- adjustWebViewForBanner(this.isPosition)
186
181
  bannerViewLayout!!.addView(bannerView)
187
182
  bannerViewLayout!!.bringToFront()
183
+ bannerOverlappingToZero()
188
184
  }
189
185
  } catch (e: Exception) {
190
186
  PUBLIC_CALLBACKS!!.error("Error adjusting banner size: " + e.message)
@@ -195,9 +191,15 @@ class emiAdmobPlugin : CordovaPlugin() {
195
191
 
196
192
  when (orientation) {
197
193
  Configuration.ORIENTATION_PORTRAIT -> {
194
+ if (isOverlapping) {
195
+ bannerOverlapping()
196
+ }
198
197
  cWebView!!.loadUrl("javascript:cordova.fireDocumentEvent('on.orientation.portrait');")
199
198
  }
200
199
  Configuration.ORIENTATION_LANDSCAPE -> {
200
+ if (isOverlapping) {
201
+ bannerOverlapping()
202
+ }
201
203
  cWebView!!.loadUrl("javascript:cordova.fireDocumentEvent('on.orientation.landscape');")
202
204
  }
203
205
  Configuration.ORIENTATION_UNDEFINED -> {
@@ -464,17 +466,17 @@ class emiAdmobPlugin : CordovaPlugin() {
464
466
  }
465
467
 
466
468
  private fun openAutoShow() {
467
- try {
468
- if (mActivity != null && isAppOpenAdShow && appOpenAd != null) {
469
- mActivity!!.runOnUiThread {
470
- appOpenAd!!.show(
471
- mActivity!!
472
- )
473
- }
469
+ try {
470
+ if (mActivity != null && isAppOpenAdShow && appOpenAd != null) {
471
+ mActivity!!.runOnUiThread {
472
+ appOpenAd!!.show(
473
+ mActivity!!
474
+ )
474
475
  }
475
- } catch (e: Exception) {
476
- PUBLIC_CALLBACKS!!.error(e.toString())
477
476
  }
477
+ } catch (e: Exception) {
478
+ PUBLIC_CALLBACKS!!.error(e.toString())
479
+ }
478
480
  }
479
481
 
480
482
  override fun onAdFailedToLoad(loadAdError: LoadAdError) {
@@ -499,16 +501,16 @@ class emiAdmobPlugin : CordovaPlugin() {
499
501
  return true
500
502
  } else if (action == "showAppOpenAd") {
501
503
 
502
- try {
503
- if (mActivity != null && isAppOpenAdShow && appOpenAd != null) {
504
- mActivity!!.runOnUiThread { appOpenAd!!.show(mActivity!!) }
505
- appOpenAdLoadCallback()
506
- } else {
507
- callbackContext.error("The App Open Ad wasn't ready yet")
508
- }
509
- } catch (e: Exception) {
510
- PUBLIC_CALLBACKS!!.error(e.toString())
504
+ try {
505
+ if (mActivity != null && isAppOpenAdShow && appOpenAd != null) {
506
+ mActivity!!.runOnUiThread { appOpenAd!!.show(mActivity!!) }
507
+ appOpenAdLoadCallback()
508
+ } else {
509
+ callbackContext.error("The App Open Ad wasn't ready yet")
511
510
  }
511
+ } catch (e: Exception) {
512
+ PUBLIC_CALLBACKS!!.error(e.toString())
513
+ }
512
514
 
513
515
  return true
514
516
  } else if (action == "loadInterstitialAd") {
@@ -613,12 +615,12 @@ class emiAdmobPlugin : CordovaPlugin() {
613
615
  return true
614
616
  } else if (action == "showInterstitialAd") {
615
617
 
616
- if (mActivity != null && isInterstitialLoad && mInterstitialAd != null) {
617
- mActivity!!.runOnUiThread { mInterstitialAd!!.show(mActivity!!) }
618
- interstitialAdLoadCallback()
619
- } else {
620
- callbackContext.error("The Interstitial ad wasn't ready yet")
621
- }
618
+ if (mActivity != null && isInterstitialLoad && mInterstitialAd != null) {
619
+ mActivity!!.runOnUiThread { mInterstitialAd!!.show(mActivity!!) }
620
+ interstitialAdLoadCallback()
621
+ } else {
622
+ callbackContext.error("The Interstitial ad wasn't ready yet")
623
+ }
622
624
  return true
623
625
  } else if (action == "loadRewardedAd") {
624
626
  val options = args.getJSONObject(0)
@@ -738,8 +740,8 @@ class emiAdmobPlugin : CordovaPlugin() {
738
740
  }
739
741
  }
740
742
  }
743
+ }
741
744
  }
742
- }
743
745
  })
744
746
  } catch (e: Exception) {
745
747
  callbackContext.error(e.toString())
@@ -1071,6 +1073,13 @@ class emiAdmobPlugin : CordovaPlugin() {
1071
1073
  try {
1072
1074
  bannerView!!.visibility = View.VISIBLE
1073
1075
  bannerView!!.resume()
1076
+ // bannerOverlappingToZero()
1077
+
1078
+ if (isOverlapping) {
1079
+ bannerOverlapping()
1080
+ }
1081
+
1082
+
1074
1083
  } catch (e: Exception) {
1075
1084
  callbackContext.error(e.toString())
1076
1085
  }
@@ -1121,6 +1130,7 @@ class emiAdmobPlugin : CordovaPlugin() {
1121
1130
  bannerView!!.pause()
1122
1131
  isBannerLoad = false
1123
1132
  isBannerPause = 1
1133
+ bannerOverlappingToZero()
1124
1134
  } catch (e: Exception) {
1125
1135
  callbackContext.error(e.toString())
1126
1136
  }
@@ -1133,6 +1143,7 @@ class emiAdmobPlugin : CordovaPlugin() {
1133
1143
  mActivity!!.runOnUiThread {
1134
1144
  try {
1135
1145
  if (bannerViewLayout != null && bannerView != null) {
1146
+ bannerOverlappingToZero()
1136
1147
  bannerViewLayout!!.removeView(bannerView)
1137
1148
  bannerView!!.destroy()
1138
1149
  bannerView = null
@@ -1229,6 +1240,11 @@ class emiAdmobPlugin : CordovaPlugin() {
1229
1240
  }
1230
1241
  }
1231
1242
 
1243
+
1244
+
1245
+
1246
+
1247
+
1232
1248
  @SuppressLint("RtlHardcoded")
1233
1249
  private fun setBannerPosition(position: String?) {
1234
1250
  val bannerParams = FrameLayout.LayoutParams(
@@ -1247,6 +1263,7 @@ class emiAdmobPlugin : CordovaPlugin() {
1247
1263
  bannerParams.gravity = Gravity.TOP or Gravity.CENTER_HORIZONTAL
1248
1264
  bannerParams.setMargins(0, marginsInPx, 0, 0)
1249
1265
  bannerViewLayout!!.setPadding(0, paddingInPx, 0, 0)
1266
+
1250
1267
  }
1251
1268
 
1252
1269
  "left" -> {
@@ -1290,7 +1307,7 @@ class emiAdmobPlugin : CordovaPlugin() {
1290
1307
 
1291
1308
  private fun isBannerAutoShow() {
1292
1309
  try {
1293
- if (bannerView != null && bannerViewLayout != null) {
1310
+ if (mActivity != null && bannerView != null && bannerViewLayout != null) {
1294
1311
  if (lock) {
1295
1312
  bannerViewLayout!!.addView(bannerView)
1296
1313
  bannerViewLayout!!.bringToFront()
@@ -1313,7 +1330,7 @@ class emiAdmobPlugin : CordovaPlugin() {
1313
1330
 
1314
1331
  private val isShowBannerAds: Unit
1315
1332
  get() {
1316
- if (isBannerLoad && bannerView != null) {
1333
+ if (mActivity != null && isBannerLoad && bannerView != null) {
1317
1334
  try {
1318
1335
  if (lock) {
1319
1336
  bannerViewLayout!!.addView(bannerView)
@@ -1348,16 +1365,18 @@ class emiAdmobPlugin : CordovaPlugin() {
1348
1365
  put("cause", adError.cause?.toString() ?: "null")
1349
1366
  }
1350
1367
 
1351
- if (bannerViewLayout != null && bannerView != null) {
1352
- bannerViewLayout!!.removeView(bannerView)
1353
- bannerView!!.destroy()
1354
- bannerView = null
1355
- bannerViewLayout = null
1356
- isBannerLoad = false
1357
- isBannerShow = false
1358
- isBannerPause = 2
1359
- lock = true
1360
- }
1368
+ bannerOverlappingToZero()
1369
+
1370
+ if (bannerViewLayout != null && bannerView != null) {
1371
+ bannerViewLayout!!.removeView(bannerView)
1372
+ bannerView!!.destroy()
1373
+ bannerView = null
1374
+ bannerViewLayout = null
1375
+ isBannerLoad = false
1376
+ isBannerShow = false
1377
+ isBannerPause = 2
1378
+ lock = true
1379
+ }
1361
1380
 
1362
1381
 
1363
1382
  cWebView!!.loadUrl("javascript:cordova.fireDocumentEvent('on.banner.failed.load', ${errorData});")
@@ -1424,32 +1443,70 @@ class emiAdmobPlugin : CordovaPlugin() {
1424
1443
  }
1425
1444
 
1426
1445
 
1427
- // fix https://github.com/EMI-INDO/emi-indo-cordova-plugin-admob/issues/26
1428
- private fun bannerOverlapping() {
1446
+
1447
+ private fun bannerOverlappingToZero() {
1429
1448
  if (bannerView != null && mActivity != null && cWebView != null) {
1430
1449
  mActivity!!.runOnUiThread {
1431
1450
  try {
1432
- val bannerHeightInPx = bannerView!!.height
1433
- val displayMetrics = DisplayMetrics()
1434
- mActivity!!.windowManager.defaultDisplay.getMetrics(displayMetrics)
1435
- val screenHeightInPx = displayMetrics.heightPixels
1436
-
1437
- // Adjust the WebView height to account for the banner ad
1438
- val webViewHeight = screenHeightInPx - (adSize.height+overlappingHeight)
1439
- val layoutParams = cWebView!!.view.layoutParams
1440
- layoutParams.height = webViewHeight
1441
- cWebView!!.view.layoutParams = layoutParams
1442
-
1443
- // Log for debugging
1444
- Log.d("BannerAdjustment", "Adjusted WebView height: $webViewHeight")
1451
+ val rootView = (cWebView!!.view.parent as View)
1452
+ rootView.post {
1453
+ // Get the total height of the parent view
1454
+ val totalHeight = rootView.height
1455
+
1456
+ // Adjust WebView height to match parent height
1457
+ val layoutParams = cWebView!!.view.layoutParams
1458
+ layoutParams.height = totalHeight
1459
+ cWebView!!.view.layoutParams = layoutParams
1460
+
1461
+ // Ensure no padding/margin in WebView or its parent
1462
+ cWebView!!.view.setPadding(0, 0, 0, 0)
1463
+ (cWebView!!.view.parent as? ViewGroup)?.setPadding(0, 0, 0, 0)
1464
+
1465
+ // Force layout update
1466
+ cWebView!!.view.requestLayout()
1467
+
1468
+ Log.d("BannerAdjustment", "WebView set to full height: $totalHeight")
1469
+ }
1445
1470
  } catch (e: Exception) {
1446
- Log.e("AdmobPlugin", "Error adjusting WebView for banner: ${e.message}")
1471
+ Log.e("AdmobPlugin", "Error setting WebView to full height: ${e.message}")
1447
1472
  }
1448
1473
  }
1449
1474
  }
1450
1475
  }
1451
1476
 
1452
1477
 
1478
+
1479
+
1480
+
1481
+ // fix https://github.com/EMI-INDO/emi-indo-cordova-plugin-admob/issues/26
1482
+ private fun bannerOverlapping() {
1483
+ if (bannerView != null && mActivity != null && cWebView != null) {
1484
+ mActivity!!.runOnUiThread {
1485
+ try {
1486
+ val bannerHeightInPx = bannerView!!.height
1487
+ val displayMetrics = DisplayMetrics()
1488
+ mActivity!!.windowManager.defaultDisplay.getMetrics(displayMetrics)
1489
+ val screenHeightInPx = displayMetrics.heightPixels
1490
+
1491
+ // Adjust the WebView height to account for the banner ad
1492
+ val webViewHeight = screenHeightInPx - (adSize.height + overlappingHeight)
1493
+ val layoutParams = cWebView!!.view.layoutParams
1494
+ layoutParams.height = webViewHeight
1495
+ cWebView!!.view.layoutParams = layoutParams
1496
+
1497
+ // Log for debugging
1498
+ Log.d("BannerAdjustment", "Adjusted WebView height: $webViewHeight")
1499
+ } catch (e: Exception) {
1500
+ Log.e("AdmobPlugin", "Error adjusting WebView for banner: ${e.message}")
1501
+ }
1502
+ }
1503
+ }
1504
+ }
1505
+
1506
+
1507
+
1508
+
1509
+
1453
1510
  private val bannerPaidAdListener = OnPaidEventListener { adValue ->
1454
1511
  val valueMicros = adValue.valueMicros
1455
1512
  val currencyCode = adValue.currencyCode
@@ -2024,8 +2081,8 @@ class emiAdmobPlugin : CordovaPlugin() {
2024
2081
  return cWebView as View?
2025
2082
  }
2026
2083
 
2027
- return mActivity!!.window.decorView.findViewById(View.generateViewId())
2028
- // return mActivity!!.window.decorView.findViewById(R.id.content)
2084
+ return mActivity!!.window.decorView.findViewById(View.generateViewId())
2085
+ // return mActivity!!.window.decorView.findViewById(R.id.content)
2029
2086
  }
2030
2087
 
2031
2088
  override fun onPause(multitasking: Boolean) {