emi-indo-cordova-plugin-admob 2.0.8 → 2.1.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/README.md CHANGED
@@ -1,4 +1,4 @@
1
- ### emi-indo-cordova-plugin-admob@2.0.8
1
+ ### emi-indo-cordova-plugin-admob@2.1.9
2
2
 
3
3
 
4
4
  ## Features/method
@@ -156,7 +156,7 @@ config.xml
156
156
  ### Check all release notes: https://github.com/EMI-INDO/emi-indo-cordova-plugin-admob/releases/
157
157
 
158
158
 
159
- ### Mobile Ads SDK (Android: 24.1.0) [Release Notes:](https://developers.google.com/admob/android/rel-notes)
159
+ ### Mobile Ads SDK (Android: 24.2.0) [Release Notes:](https://developers.google.com/admob/android/rel-notes)
160
160
  ### User Messaging Platform (UMP Android: 3.2.0) [Release Notes:](https://developers.google.com/admob/android/privacy/release-notes)
161
161
 
162
162
  ### Mobile Ads SDK (IOS: 12.2.0) [Release Notes:](https://developers.google.com/admob/ios/rel-notes)
@@ -18,7 +18,7 @@ function loadBanner() {
18
18
  }
19
19
 
20
20
 
21
-
21
+ // default: Android | IOS
22
22
  cordova.plugins.emiAdmobPlugin.loadBannerAd({
23
23
  adUnitId: Banner_ID, //Banner_ID,
24
24
  position: "bottom-center", // bottom-center | top-center
@@ -30,6 +30,25 @@ function loadBanner() {
30
30
  });
31
31
 
32
32
 
33
+
34
+
35
+
36
+ // NOTE: Do not use loadBannerAd and loadBannerCapacitor together.
37
+
38
+ /*
39
+ // Only Android
40
+ cordova.plugins.emiAdmobPlugin.loadBannerCapacitor({
41
+ adUnitId: Banner_ID, //Banner_ID,
42
+ position: "bottom-center", // bottom-center | top-center
43
+ size: "banner",
44
+ collapsible: "", // position: top | bottom (disable, empty string)
45
+ autoShow: true, // default false
46
+ isOverlapping: false // The height of the body is reduced by the height of the banner.
47
+ // isOverlapping: true // The body height is not reduced, the banner overlaps on top of the body
48
+ });
49
+ */
50
+
51
+
33
52
  }
34
53
 
35
54
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "emi-indo-cordova-plugin-admob",
3
- "version": "2.0.8",
3
+ "version": "2.1.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="2.0.8">
3
+ id="emi-indo-cordova-plugin-admob" version="2.1.9">
4
4
 
5
5
  <name>emiAdmobPlugin</name>
6
6
  <description>Cordova/Quasar/Capacitor Plugin Admob Android IOS</description>
@@ -59,7 +59,7 @@
59
59
  <!-- Sample AdMob app ID: ca-app-pub-3940256099942544~3347511713 -->
60
60
 
61
61
  <preference name="APP_ID_ANDROID" default="ca-app-pub-3940256099942544~3347511713" />
62
- <preference name="PLAY_SERVICES_VERSION" default="24.1.0" />
62
+ <preference name="PLAY_SERVICES_VERSION" default="24.2.0" />
63
63
 
64
64
  <framework src="com.google.android.gms:play-services-ads:$PLAY_SERVICES_VERSION" />
65
65
 
@@ -76,8 +76,6 @@
76
76
  <activity android:resizeableActivity="$MULTI_WINDOW" />
77
77
  </edit-config>
78
78
 
79
-
80
-
81
79
  <config-file parent="/*" target="AndroidManifest.xml" />
82
80
  <source-file src="src/android/emiAdmobPlugin.kt" target-dir="app/src/main/kotlin/emi/indo/cordova/plugin/admob" />
83
81
 
@@ -152,7 +152,8 @@ class emiAdmobPlugin : CordovaPlugin() {
152
152
 
153
153
 
154
154
  private var isFullScreen: Boolean = false
155
- // private var bannerOverlapping: Boolean = false
155
+ private var loadBannerCapacitor: Boolean = false
156
+ private var loadBannerCordova: Boolean = false
156
157
 
157
158
  override fun pluginInitialize() {
158
159
  super.pluginInitialize()
@@ -1030,7 +1031,7 @@ class emiAdmobPlugin : CordovaPlugin() {
1030
1031
  val collapsible = options.optString("collapsible")
1031
1032
  val size = options.optString("size")
1032
1033
  val autoShow = options.optBoolean("autoShow")
1033
- val isOverlapping = options.optBoolean("isOverlapping", false)
1034
+ val isOverlapping = options.optBoolean("isOverlapping")
1034
1035
  val paddingPx = options.optInt("padding")
1035
1036
  this.bannerAdUnitId = adUnitId
1036
1037
  this.isPosition = position
@@ -1039,6 +1040,34 @@ class emiAdmobPlugin : CordovaPlugin() {
1039
1040
  this.collapsiblePos = collapsible
1040
1041
  this.isOverlapping = isOverlapping
1041
1042
  this.paddingInPx = paddingPx
1043
+ this.loadBannerCordova = true
1044
+
1045
+ try {
1046
+ loadBannerAd(adUnitId, position, size)
1047
+ } catch (e: Exception) {
1048
+ callbackContext.error("loadBannerAd Error: " + e.message)
1049
+ }
1050
+ }
1051
+ }
1052
+ return true
1053
+
1054
+ } else if (action == "loadBannerCapacitor") {
1055
+ if (mActivity != null) {
1056
+ val options = args.getJSONObject(0)
1057
+ mActivity?.runOnUiThread {
1058
+ val adUnitId = options.optString("adUnitId")
1059
+ val position = options.optString("position")
1060
+ val collapsible = options.optString("collapsible")
1061
+ val size = options.optString("size")
1062
+ val autoShow = options.optBoolean("autoShow")
1063
+ val isOverlapping = options.optBoolean("isOverlapping")
1064
+ this.bannerAdUnitId = adUnitId
1065
+ this.isPosition = position
1066
+ this.isSize = size
1067
+ this.bannerAutoShow = autoShow
1068
+ this.collapsiblePos = collapsible
1069
+ this.isOverlapping = isOverlapping
1070
+ this.loadBannerCapacitor = true
1042
1071
 
1043
1072
  try {
1044
1073
  loadBannerAd(adUnitId, position, size)
@@ -1059,10 +1088,20 @@ class emiAdmobPlugin : CordovaPlugin() {
1059
1088
  bannerView?.visibility = View.VISIBLE
1060
1089
  bannerView?.resume()
1061
1090
 
1062
- if (isPosition == "top-center") {
1063
- setBannerAdTop()
1064
- } else {
1065
- setBannerAdBottom()
1091
+ if(loadBannerCordova) {
1092
+ if (isPosition == "top-center") {
1093
+ setBannerAdTop()
1094
+ } else {
1095
+ setBannerAdBottom()
1096
+ }
1097
+ }
1098
+
1099
+ if (loadBannerCapacitor) {
1100
+ if (isPosition == "top-center") {
1101
+ setBannerAdTopCapacitor()
1102
+ } else {
1103
+ setBannerAdBottomCapacitor()
1104
+ }
1066
1105
  }
1067
1106
 
1068
1107
  bannerViewLayout?.requestFocus()
@@ -1418,19 +1457,15 @@ class emiAdmobPlugin : CordovaPlugin() {
1418
1457
 
1419
1458
  cWebView?.loadUrl("javascript:cordova.fireDocumentEvent('on.banner.failed.load', ${errorData});")
1420
1459
 
1421
- bannerOverlappingToZero()
1422
1460
 
1423
1461
  if (bannerViewLayout != null && bannerView != null) {
1424
- bannerViewLayout?.removeView(bannerView)
1425
- bannerView?.destroy()
1426
- bannerView = null
1427
- bannerViewLayout = null
1428
1462
  isBannerLoad = false
1429
- isBannerShow = false
1430
1463
  isBannerPause = 2
1431
1464
  lock = true
1432
1465
  }
1433
1466
 
1467
+
1468
+
1434
1469
  }
1435
1470
 
1436
1471
  override fun onAdImpression() {
@@ -1454,10 +1489,20 @@ class emiAdmobPlugin : CordovaPlugin() {
1454
1489
  bannerViewHeight = heightInPx ?: 0
1455
1490
  }
1456
1491
 
1457
- if (isPosition == "top-center") {
1458
- setBannerAdTop()
1459
- } else {
1460
- setBannerAdBottom()
1492
+ if(loadBannerCordova) {
1493
+ if (isPosition == "top-center") {
1494
+ setBannerAdTop()
1495
+ } else {
1496
+ setBannerAdBottom()
1497
+ }
1498
+ }
1499
+
1500
+ if (loadBannerCapacitor) {
1501
+ if (isPosition == "top-center") {
1502
+ setBannerAdTopCapacitor()
1503
+ } else {
1504
+ setBannerAdBottomCapacitor()
1505
+ }
1461
1506
  }
1462
1507
 
1463
1508
  if (bannerAutoShow) {
@@ -1592,6 +1637,8 @@ class emiAdmobPlugin : CordovaPlugin() {
1592
1637
  }
1593
1638
 
1594
1639
 
1640
+
1641
+
1595
1642
  private fun setBannerAdTop() {
1596
1643
  mActivity?.let { activity ->
1597
1644
  bannerView?.post {
@@ -1641,6 +1688,174 @@ class emiAdmobPlugin : CordovaPlugin() {
1641
1688
 
1642
1689
 
1643
1690
 
1691
+
1692
+
1693
+
1694
+ private fun setBannerAdBottomCapacitor() {
1695
+ if (bannerView != null && mActivity != null && cWebView != null) {
1696
+ mActivity?.runOnUiThread {
1697
+ bannerView?.post {
1698
+ try {
1699
+ val measuredBannerHeight = if (bannerView!!.height > 0)
1700
+ bannerView!!.height //167
1701
+
1702
+ //adSize.height
1703
+ else
1704
+ adSize.getHeightInPixels(mActivity!!)
1705
+
1706
+ //61
1707
+
1708
+ val screenHeightInPx = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) { //2186
1709
+
1710
+
1711
+ val windowMetrics = mActivity!!.windowManager.currentWindowMetrics //WindowMetrics:{bounds=Rect(0, 0 - 1080, 2400), windowInsets=null, density=2.75}
1712
+ val insets = windowMetrics.windowInsets.getInsets(WindowInsets.Type.systemBars()) //Insets{left=0, top=84, right=0, bottom=130}
1713
+ val height = windowMetrics.bounds.height() - insets.top - insets.bottom //2186 2400 - 84 - 130
1714
+ height
1715
+ } else {
1716
+ val displayMetrics = DisplayMetrics()
1717
+ @Suppress("DEPRECATION")
1718
+ mActivity!!.windowManager.defaultDisplay.getMetrics(displayMetrics)
1719
+ displayMetrics.heightPixels
1720
+ }
1721
+
1722
+ val webViewHeight = screenHeightInPx// - measuredBannerHeight //2186 - 167
1723
+
1724
+ if (!isFullScreen) {
1725
+ var navBarHeight = 0
1726
+
1727
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
1728
+ val windowMetrics = mActivity!!.windowManager.currentWindowMetrics
1729
+ val insets = windowMetrics.windowInsets.getInsets(WindowInsets.Type.navigationBars())
1730
+ navBarHeight = insets.bottom
1731
+ } else {
1732
+ val decorView = mActivity!!.window.decorView
1733
+ @Suppress("DEPRECATION")
1734
+ val isNavBarVisible = (decorView.systemUiVisibility and View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) == 0
1735
+ if (isNavBarVisible) {
1736
+ navBarHeight = getNavigationBarHeight(mActivity!!)
1737
+ }
1738
+ }
1739
+
1740
+ if (navBarHeight > 0) {
1741
+ bannerViewLayout?.let { container ->
1742
+ container.post {
1743
+ val params = container.layoutParams
1744
+ if (params is ViewGroup.MarginLayoutParams) {
1745
+ params.bottomMargin = navBarHeight
1746
+ container.layoutParams = params
1747
+ container.requestLayout()
1748
+ }
1749
+ }
1750
+ }
1751
+ }
1752
+ }
1753
+
1754
+
1755
+
1756
+ if (!isOverlapping) {
1757
+ val layoutParams = cWebView!!.view.layoutParams
1758
+
1759
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
1760
+ val windowMetrics = mActivity!!.windowManager.currentWindowMetrics
1761
+ val insets = windowMetrics.windowInsets.getInsets(WindowInsets.Type.systemBars())
1762
+ val usableHeight = windowMetrics.bounds.height()
1763
+
1764
+ layoutParams.height = if (isFullScreen) {
1765
+ // In fullscreen, do NOT subtract nav bar height
1766
+ usableHeight - adSize.getHeightInPixels(mActivity!!)
1767
+ } else {
1768
+ usableHeight - getNavigationBarHeight(mActivity!!) - adSize.getHeightInPixels(mActivity!!)
1769
+ }
1770
+ } else {
1771
+
1772
+ layoutParams.height = if (isFullScreen) {
1773
+ webViewHeight - adSize.getHeightInPixels(mActivity!!) + getNavigationBarHeight(mActivity!!)
1774
+ } else {
1775
+ webViewHeight - adSize.getHeightInPixels(mActivity!!) //- getNavigationBarHeight(mActivity!!)
1776
+ }
1777
+ }
1778
+
1779
+ cWebView!!.view.layoutParams = layoutParams
1780
+ }
1781
+
1782
+ val bannerParams = bannerView?.layoutParams as? FrameLayout.LayoutParams
1783
+ bannerParams?.bottomMargin = 0
1784
+ bannerParams?.gravity = Gravity.BOTTOM or Gravity.CENTER_HORIZONTAL //81
1785
+ bannerView?.layoutParams = bannerParams
1786
+
1787
+ bannerViewLayout?.setPadding(0, 0, 0, 0)
1788
+
1789
+
1790
+ } catch (e: Exception) {
1791
+ PUBLIC_CALLBACKS?.error("Error bannerOverlapping: ${e.message}")
1792
+ }
1793
+ }
1794
+ }
1795
+ }
1796
+ }
1797
+
1798
+
1799
+
1800
+ private fun setBannerAdTopCapacitor() {
1801
+ mActivity?.let { activity ->
1802
+ bannerView?.post {
1803
+ val bannerHeightPx = bannerViewHeight
1804
+ val statusBarHeight = getStatusBarHeight(activity)
1805
+
1806
+ if (isPosition.equals("top-center", ignoreCase = true)) {
1807
+ val bannerLp = bannerView?.layoutParams as? FrameLayout.LayoutParams
1808
+ bannerLp?.let { lp ->
1809
+ if (isOverlapping) {
1810
+ if (isFullScreen) {
1811
+ lp.topMargin = 0
1812
+ bannerView?.layoutParams = lp
1813
+ } else {
1814
+ lp.topMargin = 0 // bannerHeightPx // + statusBarHeight
1815
+ bannerView?.layoutParams = lp
1816
+ }
1817
+ } else {
1818
+ if (isFullScreen) {
1819
+ lp.topMargin = 0
1820
+ bannerView?.layoutParams = lp
1821
+ } else {
1822
+ lp.topMargin = statusBarHeight
1823
+ bannerView?.layoutParams = lp
1824
+ }
1825
+ }
1826
+
1827
+ }
1828
+ }
1829
+
1830
+ cWebView?.let { webView ->
1831
+ val webLp = webView.view.layoutParams as FrameLayout.LayoutParams
1832
+ if (isPosition.equals("top-center", ignoreCase = true)) {
1833
+
1834
+ if (isOverlapping) {
1835
+ if (isFullScreen) {
1836
+ webLp.topMargin = 0 //+ statusBarHeight
1837
+ } else {
1838
+ webLp.topMargin = 0 //bannerHeightPx // + statusBarHeight
1839
+ }
1840
+ } else {
1841
+ if (isFullScreen) {
1842
+ webLp.topMargin = bannerHeightPx
1843
+ } else {
1844
+ webLp.topMargin = bannerHeightPx
1845
+ }
1846
+ }
1847
+ }
1848
+
1849
+ webView.view.layoutParams = webLp
1850
+ webView.view.requestLayout()
1851
+ }
1852
+ }}
1853
+ }
1854
+
1855
+
1856
+
1857
+
1858
+
1644
1859
  private val bannerPaidAdListener = OnPaidEventListener { adValue ->
1645
1860
  val valueMicros = adValue.valueMicros.takeIf { it > 0 } ?: 0L
1646
1861
  val currencyCode = adValue.currencyCode.ifBlank { "UNKNOWN" }
@@ -16,16 +16,19 @@ exports.showAppOpenAd = function (success, error) {
16
16
  exec(success, error, 'emiAdmobPlugin', 'showAppOpenAd', []);
17
17
  };
18
18
  exports.styleBannerAd = function (options, success, error) {
19
- exec(success, error, 'emiAdmobPlugin', 'styleBannerAd', [options]);
19
+ exec(success, error, 'emiAdmobPlugin', 'styleBannerAd', [options]);
20
20
  };
21
21
  exports.loadBannerAd = function (options, success, error) {
22
22
  exec(success, error, 'emiAdmobPlugin', 'loadBannerAd', [options]);
23
23
  };
24
+ exports.loadBannerCapacitor = function (options, success, error) {
25
+ exec(success, error, 'emiAdmobPlugin', 'loadBannerCapacitor', [options]);
26
+ };
24
27
  exports.showBannerAd = function (success, error) {
25
28
  exec(success, error, 'emiAdmobPlugin', 'showBannerAd', []);
26
29
  };
27
30
  exports.hideBannerAd = function (success, error) {
28
- exec(success, error, 'emiAdmobPlugin', 'hideBannerAd', []);
31
+ exec(success, error, 'emiAdmobPlugin', 'hideBannerAd', []);
29
32
  };
30
33
  exports.removeBannerAd = function (success, error) {
31
34
  exec(success, error, 'emiAdmobPlugin', 'removeBannerAd', []);
@@ -70,13 +73,13 @@ exports.globalSettings = function (options, success, error) {
70
73
  exec(success, error, 'emiAdmobPlugin', 'globalSettings', [options]);
71
74
  };
72
75
  exports.forceDisplayPrivacyForm = function (success, error) {
73
- exec(success, error, 'emiAdmobPlugin', 'forceDisplayPrivacyForm', []); // only IOS
76
+ exec(success, error, 'emiAdmobPlugin', 'forceDisplayPrivacyForm', []);
74
77
  };
75
78
 
76
79
  exports.metaData = function (options, success, error) {
77
80
  exec(success, error, 'emiAdmobPlugin', 'metaData', [options]);
78
81
  };
79
-
82
+
80
83
  // ( only Android )
81
84
  // only isUsingAdManagerRequest: true
82
85
  // AdManagerAdRequest.Builder