emi-indo-cordova-plugin-admob 1.8.9 → 1.9.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.
@@ -13,7 +13,7 @@ function loadBanner() {
13
13
  if (!isPlatformIOS){
14
14
 
15
15
  cordova.plugins.emiAdmobPlugin.styleBannerAd({
16
- isOverlapping: true,
16
+ isOverlapping: true,
17
17
  overlappingHeight: 0, // default 0 (Automatic)
18
18
  padding: 0, // default 0
19
19
  margins: 0 // default 0 (Automatic)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "emi-indo-cordova-plugin-admob",
3
- "version": "1.8.9",
3
+ "version": "1.9.9",
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="1.8.9">
3
+ id="emi-indo-cordova-plugin-admob" version="1.9.9">
4
4
 
5
5
  <name>emiAdmobPlugin</name>
6
6
  <description>Cordova/Quasar/Capacitor Plugin Admob Android IOS</description>
@@ -41,7 +41,6 @@
41
41
  <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
42
42
  </config-file>
43
43
 
44
-
45
44
  <config-file target="AndroidManifest.xml" parent="/manifest/application">
46
45
  <activity
47
46
  android:launchMode="singleTask"
@@ -92,6 +92,8 @@ class emiAdmobPlugin : CordovaPlugin() {
92
92
  private var isOverlapping: Boolean = false
93
93
  private var overlappingHeight: Int = 0
94
94
 
95
+ var adType = ""
96
+
95
97
  var isBannerLoad: Boolean = false
96
98
  var isBannerShow: Boolean = false
97
99
 
@@ -1365,6 +1367,7 @@ class emiAdmobPlugin : CordovaPlugin() {
1365
1367
 
1366
1368
 
1367
1369
  private fun loadBannerAd(adUnitId: String, position: String, size: String) {
1370
+ adType = size;
1368
1371
  try {
1369
1372
  if (bannerViewLayout == null) {
1370
1373
  bannerViewLayout = FrameLayout(mActivity!!)
@@ -1551,6 +1554,12 @@ class emiAdmobPlugin : CordovaPlugin() {
1551
1554
  cWebView!!.loadUrl("javascript:cordova.fireDocumentEvent('on.banner.impression');")
1552
1555
  }
1553
1556
 
1557
+ private fun getAdHeightInDp(adSize: AdSize, context: Context): Int {
1558
+ val heightInPixels = adSize.getHeightInPixels(context)
1559
+ val density = context.resources.displayMetrics.density
1560
+ return (heightInPixels / density).toInt()
1561
+ }
1562
+
1554
1563
 
1555
1564
  override fun onAdLoaded() {
1556
1565
  // Log.d(TAG, "onAdLoaded: Ad finished loading successfully.");
@@ -1565,9 +1574,38 @@ class emiAdmobPlugin : CordovaPlugin() {
1565
1574
  bannerOverlapping()
1566
1575
  }
1567
1576
 
1568
- val bannerHeight= adSize.height;
1569
1577
 
1570
- val bannerLoadEventData = String.format(Locale.US, "{\"height\": %d}", bannerHeight)
1578
+
1579
+
1580
+
1581
+
1582
+ val context = cordova.activity.applicationContext
1583
+ //val adType="fluid";
1584
+ // Get the AdSize object based on the type
1585
+ var currentAdSize = when (adType) {
1586
+ "banner" -> AdSize.BANNER
1587
+ "large_banner" -> AdSize.LARGE_BANNER
1588
+ "medium_rectangle" -> AdSize.MEDIUM_RECTANGLE
1589
+ "full_banner" -> AdSize.FULL_BANNER
1590
+ "leaderboard" -> AdSize.LEADERBOARD
1591
+
1592
+ //"fluid" -> AdSize.FLUID
1593
+ //"in_line_adaptive" -> AdSize.getCurrentOrientationInlineAdaptiveBannerAdSize(context, adWidth)
1594
+
1595
+ else -> adSize // Default fallback to the adaptive ad size
1596
+ }
1597
+
1598
+ // Calculate the height in dp
1599
+ val bannerHeightDp = getAdHeightInDp(currentAdSize, context)
1600
+
1601
+ //bannerHeight=currentAdSize;
1602
+
1603
+
1604
+ val bannerLoadEventData = String.format(Locale.US, "{\"height\": %d}", bannerHeightDp)
1605
+
1606
+
1607
+
1608
+
1571
1609
 
1572
1610
  cWebView!!.loadUrl("javascript:cordova.fireDocumentEvent('on.banner.load', $bannerLoadEventData);")
1573
1611
 
@@ -1646,24 +1684,21 @@ class emiAdmobPlugin : CordovaPlugin() {
1646
1684
 
1647
1685
 
1648
1686
 
1649
- // fix https://github.com/EMI-INDO/emi-indo-cordova-plugin-admob/issues/26
1650
1687
  private fun bannerOverlapping() {
1651
1688
  if (bannerView != null && mActivity != null && cWebView != null) {
1652
1689
  mActivity!!.runOnUiThread {
1653
1690
  try {
1654
- // val bannerHeightInPx = bannerView!!.height
1691
+
1655
1692
  val displayMetrics = DisplayMetrics()
1656
1693
  mActivity!!.windowManager.defaultDisplay.getMetrics(displayMetrics)
1657
1694
  val screenHeightInPx = displayMetrics.heightPixels
1658
1695
 
1659
- // Adjust the WebView height to account for the banner ad
1660
- val webViewHeight = screenHeightInPx - (adSize.height + overlappingHeight)
1661
- val layoutParams = cWebView!!.view.layoutParams
1662
- layoutParams.height = webViewHeight
1663
- cWebView!!.view.layoutParams = layoutParams
1696
+ val webViewHeight = screenHeightInPx - (adSize.height + overlappingHeight)
1697
+ val layoutParams = cWebView!!.view.layoutParams
1698
+ layoutParams.height = webViewHeight
1699
+ cWebView!!.view.layoutParams = layoutParams
1664
1700
 
1665
- // Log for debugging
1666
- Log.d("BannerAdjustment", "Adjusted WebView height: $webViewHeight")
1701
+ // Log.d("BannerAdjustment", "Adjusted WebView height: $webViewHeight")
1667
1702
  } catch (e: Exception) {
1668
1703
  Log.e("AdmobPlugin", "Error adjusting WebView for banner: ${e.message}")
1669
1704
  }
@@ -2321,4 +2356,4 @@ class emiAdmobPlugin : CordovaPlugin() {
2321
2356
  private const val LAST_ACCESS_SUFFIX = "_last_access"
2322
2357
  private const val EXPIRATION_TIME = 360L * 24 * 60 * 60 * 1000
2323
2358
  }
2324
- }
2359
+ }