emi-indo-cordova-plugin-admob 1.8.9 → 2.0.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.
- package/example/www/js/bannerAd.js +1 -1
- package/package.json +1 -1
- package/plugin.xml +8 -2
- package/src/android/emiAdmobPlugin.kt +47 -12
- package/src/ios/emiAdmobPlugin.m +18 -15
@@ -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
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="
|
3
|
+
id="emi-indo-cordova-plugin-admob" version="2.0.0">
|
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"
|
@@ -75,6 +74,13 @@
|
|
75
74
|
<preference name="ANDROID_X" default="1.2.0" />
|
76
75
|
<framework src="androidx.preference:preference:$ANDROID_X" />
|
77
76
|
|
77
|
+
<preference name="MULTI_WINDOW" default="false" />
|
78
|
+
|
79
|
+
<edit-config file="AndroidManifest.xml" mode="merge" target="/manifest/application/activity[@android:name='MainActivity']">
|
80
|
+
<activity android:resizeableActivity="$MULTI_WINDOW" />
|
81
|
+
</edit-config>
|
82
|
+
|
83
|
+
|
78
84
|
|
79
85
|
<config-file parent="/*" target="AndroidManifest.xml" />
|
80
86
|
<source-file src="src/android/emiAdmobPlugin.kt" target-dir="app/src/main/kotlin/emi/indo/cordova/plugin/admob" />
|
@@ -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
|
-
|
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
|
-
|
1691
|
+
|
1655
1692
|
val displayMetrics = DisplayMetrics()
|
1656
1693
|
mActivity!!.windowManager.defaultDisplay.getMetrics(displayMetrics)
|
1657
1694
|
val screenHeightInPx = displayMetrics.heightPixels
|
1658
1695
|
|
1659
|
-
|
1660
|
-
|
1661
|
-
|
1662
|
-
|
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
|
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
|
+
}
|
package/src/ios/emiAdmobPlugin.m
CHANGED
@@ -504,6 +504,7 @@ BOOL isUsingAdManagerRequest = YES;
|
|
504
504
|
}
|
505
505
|
|
506
506
|
[self setAdRequest];
|
507
|
+
|
507
508
|
|
508
509
|
self.bannerViewLayout = [[UIView alloc] initWithFrame:CGRectZero];
|
509
510
|
self.bannerViewLayout.translatesAutoresizingMaskIntoConstraints = NO;
|
@@ -809,11 +810,12 @@ BOOL isUsingAdManagerRequest = YES;
|
|
809
810
|
NSString *adUnitId = strongSelf.appOpenAd.adUnitID;
|
810
811
|
|
811
812
|
NSDictionary *data = @{
|
812
|
-
@"value": adValue,
|
813
|
-
@"currencyCode": currencyCode,
|
813
|
+
@"value": adValue ?: [NSNull null],
|
814
|
+
@"currencyCode": currencyCode ?: @"",
|
814
815
|
@"precision": @(precision),
|
815
|
-
@"adUnitId": adUnitId
|
816
|
+
@"adUnitId": adUnitId ?: @""
|
816
817
|
};
|
818
|
+
|
817
819
|
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:data options:0 error:nil];
|
818
820
|
NSString *jsonString = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
|
819
821
|
|
@@ -937,11 +939,12 @@ BOOL isUsingAdManagerRequest = YES;
|
|
937
939
|
NSString *adUnitId = strongSelf.interstitial.adUnitID;
|
938
940
|
|
939
941
|
NSDictionary *data = @{
|
940
|
-
@"value": adValue,
|
941
|
-
@"currencyCode": currencyCode,
|
942
|
+
@"value": adValue ?: [NSNull null],
|
943
|
+
@"currencyCode": currencyCode ?: @"",
|
942
944
|
@"precision": @(precision),
|
943
|
-
@"adUnitId": adUnitId
|
945
|
+
@"adUnitId": adUnitId ?: @""
|
944
946
|
};
|
947
|
+
|
945
948
|
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:data options:0 error:nil];
|
946
949
|
NSString *jsonString = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
|
947
950
|
|
@@ -1072,10 +1075,10 @@ BOOL isUsingAdManagerRequest = YES;
|
|
1072
1075
|
NSString *adUnitId = strongSelf.rewardedInterstitialAd.adUnitID;
|
1073
1076
|
|
1074
1077
|
NSDictionary *data = @{
|
1075
|
-
@"value": adValue,
|
1076
|
-
@"currencyCode": currencyCode,
|
1078
|
+
@"value": adValue ?: [NSNull null],
|
1079
|
+
@"currencyCode": currencyCode ?: @"",
|
1077
1080
|
@"precision": @(precision),
|
1078
|
-
@"adUnitId": adUnitId
|
1081
|
+
@"adUnitId": adUnitId ?: @""
|
1079
1082
|
};
|
1080
1083
|
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:data options:0 error:nil];
|
1081
1084
|
NSString *jsonString = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
|
@@ -1229,10 +1232,10 @@ BOOL isUsingAdManagerRequest = YES;
|
|
1229
1232
|
NSString *adUnitId = strongSelf.rewardedAd.adUnitID;
|
1230
1233
|
|
1231
1234
|
NSDictionary *data = @{
|
1232
|
-
@"value": adValue,
|
1233
|
-
@"currencyCode": currencyCode,
|
1235
|
+
@"value": adValue ?: [NSNull null],
|
1236
|
+
@"currencyCode": currencyCode ?: @"",
|
1234
1237
|
@"precision": @(precision),
|
1235
|
-
@"adUnitId": adUnitId
|
1238
|
+
@"adUnitId": adUnitId ?: @""
|
1236
1239
|
};
|
1237
1240
|
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:data options:0 error:nil];
|
1238
1241
|
NSString *jsonString = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
|
@@ -1480,10 +1483,10 @@ BOOL isUsingAdManagerRequest = YES;
|
|
1480
1483
|
NSString *adUnitId = strongSelf.bannerView.adUnitID;
|
1481
1484
|
|
1482
1485
|
NSDictionary *data = @{
|
1483
|
-
@"value": adValue,
|
1484
|
-
@"currencyCode": currencyCode,
|
1486
|
+
@"value": adValue ?: [NSNull null],
|
1487
|
+
@"currencyCode": currencyCode ?: @"",
|
1485
1488
|
@"precision": @(precision),
|
1486
|
-
@"adUnitId": adUnitId
|
1489
|
+
@"adUnitId": adUnitId ?: @""
|
1487
1490
|
};
|
1488
1491
|
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:data options:0 error:nil];
|
1489
1492
|
NSString *jsonString = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
|