emi-indo-cordova-plugin-admob 1.5.7 → 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 +1 -1
- package/plugin.xml +1 -1
- package/src/android/emiAdmobPlugin.kt +114 -61
package/package.json
CHANGED
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.
|
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
|
-
|
468
|
-
|
469
|
-
|
470
|
-
|
471
|
-
|
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
|
-
|
503
|
-
|
504
|
-
|
505
|
-
|
506
|
-
|
507
|
-
|
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
|
-
|
617
|
-
|
618
|
-
|
619
|
-
|
620
|
-
|
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
|
@@ -1186,14 +1194,14 @@ class emiAdmobPlugin : CordovaPlugin() {
|
|
1186
1194
|
private fun loadBannerAd(adUnitId: String, position: String, size: String) {
|
1187
1195
|
try {
|
1188
1196
|
if (bannerViewLayout == null) {
|
1189
|
-
bannerViewLayout = FrameLayout(
|
1197
|
+
bannerViewLayout = FrameLayout(mActivity!!)
|
1190
1198
|
val params = FrameLayout.LayoutParams(
|
1191
1199
|
FrameLayout.LayoutParams.MATCH_PARENT,
|
1192
1200
|
FrameLayout.LayoutParams.MATCH_PARENT
|
1193
1201
|
)
|
1194
1202
|
val decorView = mActivity!!.window.decorView as ViewGroup
|
1195
1203
|
decorView.addView(bannerViewLayout, params)
|
1196
|
-
bannerView = AdView(
|
1204
|
+
bannerView = AdView(mActivity!!)
|
1197
1205
|
setBannerPosition(position)
|
1198
1206
|
setBannerSiz(size)
|
1199
1207
|
bannerView!!.adUnitId = adUnitId
|
@@ -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
|
-
|
1352
|
-
|
1353
|
-
|
1354
|
-
|
1355
|
-
|
1356
|
-
|
1357
|
-
|
1358
|
-
|
1359
|
-
|
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
|
-
|
1428
|
-
|
1441
|
+
|
1442
|
+
|
1443
|
+
private fun bannerOverlappingToZero() {
|
1429
1444
|
if (bannerView != null && mActivity != null && cWebView != null) {
|
1430
1445
|
mActivity!!.runOnUiThread {
|
1431
1446
|
try {
|
1432
|
-
val
|
1433
|
-
|
1434
|
-
|
1435
|
-
|
1436
|
-
|
1437
|
-
|
1438
|
-
|
1439
|
-
|
1440
|
-
|
1441
|
-
|
1442
|
-
|
1443
|
-
|
1444
|
-
|
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
|
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
|
@@ -1475,19 +1528,19 @@ class emiAdmobPlugin : CordovaPlugin() {
|
|
1475
1528
|
"responsive_adaptive" -> bannerView!!.setAdSize(adSize)
|
1476
1529
|
"anchored_adaptive" -> bannerView!!.setAdSize(
|
1477
1530
|
AdSize.getCurrentOrientationAnchoredAdaptiveBannerAdSize(
|
1478
|
-
|
1531
|
+
mActivity!!, adWidth
|
1479
1532
|
)
|
1480
1533
|
)
|
1481
1534
|
|
1482
1535
|
"full_width_adaptive" -> bannerView!!.setAdSize(
|
1483
1536
|
AdSize.getCurrentOrientationAnchoredAdaptiveBannerAdSize(
|
1484
|
-
|
1537
|
+
mActivity!!, adWidth
|
1485
1538
|
)
|
1486
1539
|
)
|
1487
1540
|
|
1488
1541
|
"in_line_adaptive" -> bannerView!!.setAdSize(
|
1489
1542
|
AdSize.getCurrentOrientationInlineAdaptiveBannerAdSize(
|
1490
|
-
|
1543
|
+
mActivity!!, adWidth
|
1491
1544
|
)
|
1492
1545
|
)
|
1493
1546
|
|
@@ -1522,7 +1575,7 @@ class emiAdmobPlugin : CordovaPlugin() {
|
|
1522
1575
|
val adWidthPixels =
|
1523
1576
|
if (bannerViewLayout != null && bannerViewLayout!!.width > 0) bannerViewLayout!!.width else outMetrics.widthPixels
|
1524
1577
|
val adWidth = (adWidthPixels / density).toInt()
|
1525
|
-
return AdSize.getCurrentOrientationAnchoredAdaptiveBannerAdSize(
|
1578
|
+
return AdSize.getCurrentOrientationAnchoredAdaptiveBannerAdSize(mActivity!!, adWidth)
|
1526
1579
|
}
|
1527
1580
|
|
1528
1581
|
|
@@ -2024,8 +2077,8 @@ class emiAdmobPlugin : CordovaPlugin() {
|
|
2024
2077
|
return cWebView as View?
|
2025
2078
|
}
|
2026
2079
|
|
2027
|
-
|
2028
|
-
|
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) {
|