Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit f3c5036

Browse files
Restore AdRequest overload for native ad views
1 parent e3defb6 commit f3c5036

File tree

2 files changed

+22
-5
lines changed

2 files changed

+22
-5
lines changed

‎app/src/main/java/com/d4rk/androidtutorials/java/ads/managers/NativeAdLoader.java‎

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,17 +29,25 @@ public class NativeAdLoader {
2929
private static final String TAG = "NativeAdLoader";
3030

3131
public static void load(@NonNull Context context, @NonNull ViewGroup container) {
32-
load(context, container, R.layout.ad_home_banner_large, null);
32+
load(context, container, R.layout.ad_home_banner_large, newAdRequest.Builder().build(), null);
3333
}
3434

3535
public static void load(@NonNull Context context, @NonNull ViewGroup container, @LayoutRes int layoutRes) {
36-
load(context, container, layoutRes, null);
36+
load(context, container, layoutRes, newAdRequest.Builder().build(), null);
3737
}
3838

3939
public static void load(@NonNull Context context,
4040
@NonNull ViewGroup container,
4141
@LayoutRes int layoutRes,
4242
@androidx.annotation.Nullable AdListener listener) {
43+
load(context, container, layoutRes, new AdRequest.Builder().build(), listener);
44+
}
45+
46+
public static void load(@NonNull Context context,
47+
@NonNull ViewGroup container,
48+
@LayoutRes int layoutRes,
49+
@NonNull AdRequest adRequest,
50+
@androidx.annotation.Nullable AdListener listener) {
4351
AdLoader.Builder builder = new AdLoader.Builder(context, context.getString(R.string.native_ad_banner_unit_id))
4452
.forNativeAd(nativeAd -> {
4553
LayoutInflater inflater = LayoutInflater.from(context);
@@ -66,7 +74,7 @@ public void onAdFailedToLoad(@NonNull LoadAdError loadAdError) {
6674
});
6775

6876
AdLoader adLoader = builder.build();
69-
adLoader.loadAd(newAdRequest.Builder().build());
77+
adLoader.loadAd(adRequest);
7078
}
7179

7280
private static void populateNativeAdView(@NonNull NativeAd nativeAd, @NonNull NativeAdView adView) {

‎app/src/main/java/com/d4rk/androidtutorials/java/ads/views/NativeAdBannerView.java‎

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import com.d4rk.androidtutorials.java.R;
1313
import com.d4rk.androidtutorials.java.ads.managers.NativeAdLoader;
1414
import com.google.android.gms.ads.AdListener;
15+
import com.google.android.gms.ads.AdRequest;
1516

1617
/**
1718
* Custom view that acts as a drop-in replacement for AdView and loads
@@ -45,11 +46,19 @@ private void init(@NonNull Context context, @Nullable AttributeSet attrs, int de
4546
}
4647

4748
public void loadAd() {
48-
loadAd(null);
49+
loadAd(newAdRequest.Builder().build(), null);
4950
}
5051

5152
public void loadAd(@Nullable AdListener listener) {
52-
NativeAdLoader.load(getContext(), this, layoutRes, listener);
53+
loadAd(new AdRequest.Builder().build(), listener);
54+
}
55+
56+
public void loadAd(@NonNull AdRequest request) {
57+
loadAd(request, null);
58+
}
59+
60+
public void loadAd(@NonNull AdRequest request, @Nullable AdListener listener) {
61+
NativeAdLoader.load(getContext(), this, layoutRes, request, listener);
5362
}
5463

5564
public void setNativeAdLayout(@LayoutRes int layoutRes) {

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /