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

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/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.5.9",
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.5.9">
4
4
 
5
5
  <name>emiAdmobPlugin</name>
6
6
  <description>Cordova Plugin Admob Android IOS</description>
@@ -464,17 +464,17 @@ class emiAdmobPlugin : CordovaPlugin() {
464
464
  }
465
465
 
466
466
  private fun openAutoShow() {
467
- try {
468
- if (mActivity != null && isAppOpenAdShow && appOpenAd != null) {
469
- mActivity!!.runOnUiThread {
470
- appOpenAd!!.show(
471
- mActivity!!
472
- )
473
- }
467
+ try {
468
+ if (mActivity != null && isAppOpenAdShow && appOpenAd != null) {
469
+ mActivity!!.runOnUiThread {
470
+ appOpenAd!!.show(
471
+ mActivity!!
472
+ )
474
473
  }
475
- } catch (e: Exception) {
476
- PUBLIC_CALLBACKS!!.error(e.toString())
477
474
  }
475
+ } catch (e: Exception) {
476
+ PUBLIC_CALLBACKS!!.error(e.toString())
477
+ }
478
478
  }
479
479
 
480
480
  override fun onAdFailedToLoad(loadAdError: LoadAdError) {
@@ -499,16 +499,16 @@ class emiAdmobPlugin : CordovaPlugin() {
499
499
  return true
500
500
  } else if (action == "showAppOpenAd") {
501
501
 
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())
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")
511
508
  }
509
+ } catch (e: Exception) {
510
+ PUBLIC_CALLBACKS!!.error(e.toString())
511
+ }
512
512
 
513
513
  return true
514
514
  } else if (action == "loadInterstitialAd") {
@@ -613,12 +613,12 @@ class emiAdmobPlugin : CordovaPlugin() {
613
613
  return true
614
614
  } else if (action == "showInterstitialAd") {
615
615
 
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
- }
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
+ }
622
622
  return true
623
623
  } else if (action == "loadRewardedAd") {
624
624
  val options = args.getJSONObject(0)
@@ -738,8 +738,8 @@ class emiAdmobPlugin : CordovaPlugin() {
738
738
  }
739
739
  }
740
740
  }
741
+ }
741
742
  }
742
- }
743
743
  })
744
744
  } catch (e: Exception) {
745
745
  callbackContext.error(e.toString())
@@ -1071,6 +1071,12 @@ class emiAdmobPlugin : CordovaPlugin() {
1071
1071
  try {
1072
1072
  bannerView!!.visibility = View.VISIBLE
1073
1073
  bannerView!!.resume()
1074
+
1075
+ if (isOverlapping) {
1076
+ bannerOverlapping()
1077
+ }
1078
+
1079
+
1074
1080
  } catch (e: Exception) {
1075
1081
  callbackContext.error(e.toString())
1076
1082
  }
@@ -1121,6 +1127,7 @@ class emiAdmobPlugin : CordovaPlugin() {
1121
1127
  bannerView!!.pause()
1122
1128
  isBannerLoad = false
1123
1129
  isBannerPause = 1
1130
+ bannerOverlappingToZero()
1124
1131
  } catch (e: Exception) {
1125
1132
  callbackContext.error(e.toString())
1126
1133
  }
@@ -1133,6 +1140,7 @@ class emiAdmobPlugin : CordovaPlugin() {
1133
1140
  mActivity!!.runOnUiThread {
1134
1141
  try {
1135
1142
  if (bannerViewLayout != null && bannerView != null) {
1143
+ bannerOverlappingToZero()
1136
1144
  bannerViewLayout!!.removeView(bannerView)
1137
1145
  bannerView!!.destroy()
1138
1146
  bannerView = null
@@ -1229,6 +1237,11 @@ class emiAdmobPlugin : CordovaPlugin() {
1229
1237
  }
1230
1238
  }
1231
1239
 
1240
+
1241
+
1242
+
1243
+
1244
+
1232
1245
  @SuppressLint("RtlHardcoded")
1233
1246
  private fun setBannerPosition(position: String?) {
1234
1247
  val bannerParams = FrameLayout.LayoutParams(
@@ -1247,6 +1260,7 @@ class emiAdmobPlugin : CordovaPlugin() {
1247
1260
  bannerParams.gravity = Gravity.TOP or Gravity.CENTER_HORIZONTAL
1248
1261
  bannerParams.setMargins(0, marginsInPx, 0, 0)
1249
1262
  bannerViewLayout!!.setPadding(0, paddingInPx, 0, 0)
1263
+
1250
1264
  }
1251
1265
 
1252
1266
  "left" -> {
@@ -1290,7 +1304,7 @@ class emiAdmobPlugin : CordovaPlugin() {
1290
1304
 
1291
1305
  private fun isBannerAutoShow() {
1292
1306
  try {
1293
- if (bannerView != null && bannerViewLayout != null) {
1307
+ if (mActivity != null && bannerView != null && bannerViewLayout != null) {
1294
1308
  if (lock) {
1295
1309
  bannerViewLayout!!.addView(bannerView)
1296
1310
  bannerViewLayout!!.bringToFront()
@@ -1313,7 +1327,7 @@ class emiAdmobPlugin : CordovaPlugin() {
1313
1327
 
1314
1328
  private val isShowBannerAds: Unit
1315
1329
  get() {
1316
- if (isBannerLoad && bannerView != null) {
1330
+ if (mActivity != null && isBannerLoad && bannerView != null) {
1317
1331
  try {
1318
1332
  if (lock) {
1319
1333
  bannerViewLayout!!.addView(bannerView)
@@ -1348,16 +1362,16 @@ class emiAdmobPlugin : CordovaPlugin() {
1348
1362
  put("cause", adError.cause?.toString() ?: "null")
1349
1363
  }
1350
1364
 
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
- }
1365
+ if (bannerViewLayout != null && bannerView != null) {
1366
+ bannerViewLayout!!.removeView(bannerView)
1367
+ bannerView!!.destroy()
1368
+ bannerView = null
1369
+ bannerViewLayout = null
1370
+ isBannerLoad = false
1371
+ isBannerShow = false
1372
+ isBannerPause = 2
1373
+ lock = true
1374
+ }
1361
1375
 
1362
1376
 
1363
1377
  cWebView!!.loadUrl("javascript:cordova.fireDocumentEvent('on.banner.failed.load', ${errorData});")
@@ -1424,32 +1438,71 @@ class emiAdmobPlugin : CordovaPlugin() {
1424
1438
  }
1425
1439
 
1426
1440
 
1427
- // fix https://github.com/EMI-INDO/emi-indo-cordova-plugin-admob/issues/26
1428
- private fun bannerOverlapping() {
1441
+
1442
+
1443
+ private fun bannerOverlappingToZero() {
1429
1444
  if (bannerView != null && mActivity != null && cWebView != null) {
1430
1445
  mActivity!!.runOnUiThread {
1431
1446
  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")
1447
+ val rootView = (cWebView!!.view.parent as View)
1448
+ rootView.post {
1449
+ // Get the total height of the parent view
1450
+ val totalHeight = rootView.height
1451
+
1452
+ // Adjust WebView height to match parent height
1453
+ val layoutParams = cWebView!!.view.layoutParams
1454
+ layoutParams.height = totalHeight
1455
+ cWebView!!.view.layoutParams = layoutParams
1456
+
1457
+ // Ensure no padding/margin in WebView or its parent
1458
+ cWebView!!.view.setPadding(0, 0, 0, 0)
1459
+ (cWebView!!.view.parent as? ViewGroup)?.setPadding(0, 0, 0, 0)
1460
+
1461
+ // Force layout update
1462
+ cWebView!!.view.requestLayout()
1463
+
1464
+ Log.d("BannerAdjustment", "WebView set to full height: $totalHeight")
1465
+ }
1445
1466
  } catch (e: Exception) {
1446
- Log.e("AdmobPlugin", "Error adjusting WebView for banner: ${e.message}")
1467
+ Log.e("AdmobPlugin", "Error setting WebView to full height: ${e.message}")
1447
1468
  }
1448
1469
  }
1449
1470
  }
1450
1471
  }
1451
1472
 
1452
1473
 
1474
+
1475
+
1476
+
1477
+ // fix https://github.com/EMI-INDO/emi-indo-cordova-plugin-admob/issues/26
1478
+ private fun bannerOverlapping() {
1479
+ if (bannerView != null && mActivity != null && cWebView != null) {
1480
+ mActivity!!.runOnUiThread {
1481
+ try {
1482
+ val bannerHeightInPx = bannerView!!.height
1483
+ val displayMetrics = DisplayMetrics()
1484
+ mActivity!!.windowManager.defaultDisplay.getMetrics(displayMetrics)
1485
+ val screenHeightInPx = displayMetrics.heightPixels
1486
+
1487
+ // Adjust the WebView height to account for the banner ad
1488
+ val webViewHeight = screenHeightInPx - (adSize.height+overlappingHeight)
1489
+ val layoutParams = cWebView!!.view.layoutParams
1490
+ layoutParams.height = webViewHeight
1491
+ cWebView!!.view.layoutParams = layoutParams
1492
+
1493
+ // Log for debugging
1494
+ Log.d("BannerAdjustment", "Adjusted WebView height: $webViewHeight")
1495
+ } catch (e: Exception) {
1496
+ Log.e("AdmobPlugin", "Error adjusting WebView for banner: ${e.message}")
1497
+ }
1498
+ }
1499
+ }
1500
+ }
1501
+
1502
+
1503
+
1504
+
1505
+
1453
1506
  private val bannerPaidAdListener = OnPaidEventListener { adValue ->
1454
1507
  val valueMicros = adValue.valueMicros
1455
1508
  val currencyCode = adValue.currencyCode
@@ -2024,8 +2077,8 @@ class emiAdmobPlugin : CordovaPlugin() {
2024
2077
  return cWebView as View?
2025
2078
  }
2026
2079
 
2027
- return mActivity!!.window.decorView.findViewById(View.generateViewId())
2028
- // return mActivity!!.window.decorView.findViewById(R.id.content)
2080
+ return mActivity!!.window.decorView.findViewById(View.generateViewId())
2081
+ // return mActivity!!.window.decorView.findViewById(R.id.content)
2029
2082
  }
2030
2083
 
2031
2084
  override fun onPause(multitasking: Boolean) {