@ququplay/admob 8.0.4 → 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 androidx.core.view.ViewCompat;
|
|
30
|
-
import androidx.core.view.WindowInsetsCompat;
|
|
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,44 +106,37 @@ public class BannerExecutor extends Executor {
|
|
|
105
106
|
break;
|
|
106
107
|
}
|
|
107
108
|
|
|
108
|
-
// Apply window insets for edge-to-edge support
|
|
109
|
-
// Insets will be 0 if not in edge-to-edge mode, so this handles both cases
|
|
110
|
-
View decorView = activitySupplier.get().getWindow().getDecorView();
|
|
111
|
-
ViewCompat.setOnApplyWindowInsetsListener(decorView, (v, insets) -> {
|
|
112
|
-
int bottomInset = insets.getInsets(WindowInsetsCompat.Type.systemBars()).bottom;
|
|
113
|
-
int topInset = insets.getInsets(WindowInsetsCompat.Type.systemBars()).top;
|
|
114
|
-
|
|
115
|
-
if ("TOP_CENTER".equals(adOptions.position)) {
|
|
116
|
-
mAdViewLayoutParams.setMargins(0, topInset, 0, 0);
|
|
117
|
-
} else {
|
|
118
|
-
mAdViewLayoutParams.setMargins(0, 0, 0, bottomInset);
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
mAdViewLayout.setLayoutParams(mAdViewLayoutParams);
|
|
122
|
-
return insets;
|
|
123
|
-
});
|
|
124
|
-
|
|
125
|
-
mAdViewLayout.setLayoutParams(mAdViewLayoutParams);
|
|
126
|
-
|
|
127
109
|
int densityMargin = (int) (adOptions.margin * density);
|
|
128
110
|
|
|
129
111
|
// Center Banner Ads
|
|
130
112
|
int adWidth = (int) (adOptions.adSize.getSize().getWidth() * density);
|
|
131
113
|
|
|
114
|
+
final int baseSideMargin;
|
|
132
115
|
if (adWidth <= 0 || adOptions.adSize.toString().equals("ADAPTIVE_BANNER")) {
|
|
133
116
|
int margin = 0;
|
|
134
117
|
if (fullscreen) {
|
|
135
118
|
margin = (realWidthPixels - defaultWidthPixels) / 2;
|
|
136
119
|
}
|
|
137
|
-
|
|
120
|
+
baseSideMargin = margin;
|
|
138
121
|
} else {
|
|
139
122
|
int sideMargin = ((int) defaultWidthPixels - adWidth) / 2;
|
|
140
123
|
if (fullscreen) {
|
|
141
124
|
sideMargin = (realWidthPixels - adWidth) / 2;
|
|
142
125
|
}
|
|
143
|
-
|
|
126
|
+
baseSideMargin = sideMargin;
|
|
144
127
|
}
|
|
145
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
|
+
});
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
mAdViewLayout.setLayoutParams(mAdViewLayoutParams);
|
|
139
|
+
|
|
146
140
|
createNewAdView(adOptions);
|
|
147
141
|
|
|
148
142
|
call.resolve();
|
|
@@ -232,6 +226,27 @@ public class BannerExecutor extends Executor {
|
|
|
232
226
|
});
|
|
233
227
|
}
|
|
234
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
|
+
|
|
235
250
|
/**
|
|
236
251
|
* Follow iOS method Name:
|
|
237
252
|
* https://developers.google.com/admob/ios/banner?hl=ja
|