@ququplay/admob 8.0.3 → 8.0.5
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,6 +13,8 @@ import android.widget.RelativeLayout;
|
|
|
13
13
|
import androidx.annotation.NonNull;
|
|
14
14
|
import androidx.coordinatorlayout.widget.CoordinatorLayout;
|
|
15
15
|
import androidx.core.util.Supplier;
|
|
16
|
+
import androidx.core.view.ViewCompat;
|
|
17
|
+
import androidx.core.view.WindowInsetsCompat;
|
|
16
18
|
import com.getcapacitor.JSObject;
|
|
17
19
|
import com.getcapacitor.PluginCall;
|
|
18
20
|
import com.getcapacitor.community.admob.helpers.AdViewIdHelper;
|
|
@@ -26,8 +28,6 @@ import com.google.android.gms.ads.AdSize;
|
|
|
26
28
|
import com.google.android.gms.ads.AdView;
|
|
27
29
|
import com.google.android.gms.ads.LoadAdError;
|
|
28
30
|
import com.google.android.gms.common.util.BiConsumer;
|
|
29
|
-
import android.view.Window;
|
|
30
|
-
import androidx.core.view.WindowCompat;
|
|
31
31
|
|
|
32
32
|
public class BannerExecutor extends Executor {
|
|
33
33
|
|
|
@@ -35,6 +35,7 @@ public class BannerExecutor extends Executor {
|
|
|
35
35
|
private RelativeLayout mAdViewLayout;
|
|
36
36
|
private AdView mAdView;
|
|
37
37
|
private ViewGroup mViewGroup;
|
|
38
|
+
private CoordinatorLayout.LayoutParams mAdViewLayoutParams;
|
|
38
39
|
|
|
39
40
|
public BannerExecutor(
|
|
40
41
|
Supplier<Context> contextSupplier,
|
|
@@ -87,7 +88,7 @@ public class BannerExecutor extends Executor {
|
|
|
87
88
|
mAdViewLayout.setHorizontalGravity(Gravity.CENTER_HORIZONTAL);
|
|
88
89
|
mAdViewLayout.setVerticalGravity(Gravity.BOTTOM);
|
|
89
90
|
|
|
90
|
-
|
|
91
|
+
mAdViewLayoutParams = new CoordinatorLayout.LayoutParams(
|
|
91
92
|
CoordinatorLayout.LayoutParams.WRAP_CONTENT,
|
|
92
93
|
CoordinatorLayout.LayoutParams.WRAP_CONTENT
|
|
93
94
|
);
|
|
@@ -105,47 +106,37 @@ public class BannerExecutor extends Executor {
|
|
|
105
106
|
break;
|
|
106
107
|
}
|
|
107
108
|
|
|
108
|
-
// set Safe Area only for Android 15+
|
|
109
|
-
Window window = activitySupplier.get().getWindow();
|
|
110
|
-
boolean isEdgeToEdge = !WindowCompat.isDecorFitsSystemWindows(window);
|
|
111
|
-
if (isEdgeToEdge) {
|
|
112
|
-
View rootView = activitySupplier.get().getWindow().getDecorView();
|
|
113
|
-
rootView.setOnApplyWindowInsetsListener((v, insets) -> {
|
|
114
|
-
int bottomInset = insets.getSystemWindowInsetBottom();
|
|
115
|
-
int topInset = insets.getSystemWindowInsetTop();
|
|
116
|
-
|
|
117
|
-
if ("TOP_CENTER".equals(adOptions.position)) {
|
|
118
|
-
mAdViewLayoutParams.setMargins(0, topInset, 0, 0);
|
|
119
|
-
} else {
|
|
120
|
-
mAdViewLayoutParams.setMargins(0, 0, 0, bottomInset);
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
mAdViewLayout.setLayoutParams(mAdViewLayoutParams);
|
|
124
|
-
return insets;
|
|
125
|
-
});
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
mAdViewLayout.setLayoutParams(mAdViewLayoutParams);
|
|
129
|
-
|
|
130
109
|
int densityMargin = (int) (adOptions.margin * density);
|
|
131
110
|
|
|
132
111
|
// Center Banner Ads
|
|
133
112
|
int adWidth = (int) (adOptions.adSize.getSize().getWidth() * density);
|
|
134
113
|
|
|
114
|
+
final int baseSideMargin;
|
|
135
115
|
if (adWidth <= 0 || adOptions.adSize.toString().equals("ADAPTIVE_BANNER")) {
|
|
136
116
|
int margin = 0;
|
|
137
117
|
if (fullscreen) {
|
|
138
118
|
margin = (realWidthPixels - defaultWidthPixels) / 2;
|
|
139
119
|
}
|
|
140
|
-
|
|
120
|
+
baseSideMargin = margin;
|
|
141
121
|
} else {
|
|
142
122
|
int sideMargin = ((int) defaultWidthPixels - adWidth) / 2;
|
|
143
123
|
if (fullscreen) {
|
|
144
124
|
sideMargin = (realWidthPixels - adWidth) / 2;
|
|
145
125
|
}
|
|
146
|
-
|
|
126
|
+
baseSideMargin = sideMargin;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
applyBannerMargins(adOptions, baseSideMargin, densityMargin);
|
|
130
|
+
|
|
131
|
+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.VANILLA_ICE_CREAM) {
|
|
132
|
+
ViewCompat.setOnApplyWindowInsetsListener(mAdViewLayout, (v, insets) -> {
|
|
133
|
+
applyBannerMargins(adOptions, baseSideMargin, densityMargin);
|
|
134
|
+
return insets;
|
|
135
|
+
});
|
|
147
136
|
}
|
|
148
137
|
|
|
138
|
+
mAdViewLayout.setLayoutParams(mAdViewLayoutParams);
|
|
139
|
+
|
|
149
140
|
createNewAdView(adOptions);
|
|
150
141
|
|
|
151
142
|
call.resolve();
|
|
@@ -235,6 +226,27 @@ public class BannerExecutor extends Executor {
|
|
|
235
226
|
});
|
|
236
227
|
}
|
|
237
228
|
|
|
229
|
+
private void applyBannerMargins(AdOptions adOptions, int sideMargin, int densityMargin) {
|
|
230
|
+
int topInset = 0;
|
|
231
|
+
int bottomInset = 0;
|
|
232
|
+
|
|
233
|
+
WindowInsetsCompat insets = ViewCompat.getRootWindowInsets(mAdViewLayout != null ? mAdViewLayout : mViewGroup);
|
|
234
|
+
if (insets != null) {
|
|
235
|
+
topInset = insets.getInsets(WindowInsetsCompat.Type.systemBars()).top;
|
|
236
|
+
bottomInset = insets.getInsets(WindowInsetsCompat.Type.systemBars()).bottom;
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
if ("TOP_CENTER".equals(adOptions.position)) {
|
|
240
|
+
mAdViewLayoutParams.setMargins(sideMargin, densityMargin + topInset, sideMargin, 0);
|
|
241
|
+
} else {
|
|
242
|
+
mAdViewLayoutParams.setMargins(sideMargin, densityMargin, sideMargin, densityMargin + bottomInset);
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
if (mAdViewLayout != null) {
|
|
246
|
+
mAdViewLayout.setLayoutParams(mAdViewLayoutParams);
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
|
|
238
250
|
/**
|
|
239
251
|
* Follow iOS method Name:
|
|
240
252
|
* https://developers.google.com/admob/ios/banner?hl=ja
|