Skip to content

Commit ba48469

Browse files
Mobile Ads Developer Relationscopybara-github
authored andcommitted
This change refactors the Unity plugin's Android implementation for Native Ads to use the new Decagon SDK. It includes:
- Creating `UnityNativeTemplateAdNextgen` and related Java classes to interface with Decagon's `NativeAdLoader` and `NativeAd`. - Forking and adapting `TemplateView` to `TemplateViewNextgen` to work with Decagon's `NativeAdView` and `MediaView`. PiperOrigin-RevId: 917262890
1 parent 0609f2f commit ba48469

15 files changed

Lines changed: 2451 additions & 2 deletions

source/plugin/Assets/Plugins/Android/GoogleMobileAdsPlugin.androidlib/src/main/java/com/google/unity/ads/nativead/UnityNativeTemplateStyle.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,8 @@ public int hashCode() {
138138
tertiaryTextStyle);
139139
}
140140

141-
private NativeTemplateStyle asNativeTemplateStyle() {
141+
@NonNull
142+
public NativeTemplateStyle asNativeTemplateStyle() {
142143
NativeTemplateStyle.Builder builder = new NativeTemplateStyle.Builder();
143144
if (mainBackgroundColor != null) {
144145
builder.withMainBackgroundColor(mainBackgroundColor);

source/plugin/Assets/Plugins/Android/GoogleMobileAdsPlugin.androidlib/src/main/java/com/google/unity/ads/nextgen/AdWrapper.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package com.google.unity.ads.nextgen;
22

33
import com.google.android.libraries.ads.mobile.sdk.appopen.AppOpenAd;
4+
import com.google.android.libraries.ads.mobile.sdk.banner.BannerAd;
5+
import com.google.android.libraries.ads.mobile.sdk.banner.BannerAdRequest;
46
import com.google.android.libraries.ads.mobile.sdk.common.AdLoadCallback;
57
import com.google.android.libraries.ads.mobile.sdk.common.AdRequest;
68
import com.google.android.libraries.ads.mobile.sdk.interstitial.InterstitialAd;
@@ -35,6 +37,22 @@ public static AdWrapper<AppOpenAd> forAppOpen() {
3537
return new AdWrapper<>(AppOpenAd::load);
3638
}
3739

40+
/** Creates a new AdWrapper for loading BannerAds. */
41+
public static AdWrapper<BannerAd> forBanner() {
42+
return new AdWrapper<BannerAd>(
43+
new AdLoader<BannerAd>() {
44+
@Override
45+
public void load(AdRequest adRequest, AdLoadCallback<BannerAd> callback) {
46+
if (adRequest instanceof BannerAdRequest) {
47+
BannerAd.load((BannerAdRequest) adRequest, callback);
48+
} else {
49+
throw new IllegalArgumentException(
50+
"AdRequest must be of type BannerAdRequest for Banner Ads");
51+
}
52+
}
53+
});
54+
}
55+
3856
/** Creates a new AdWrapper for loading InterstitialAds. */
3957
public static AdWrapper<InterstitialAd> forInterstitial() {
4058
return new AdWrapper<>(InterstitialAd::load);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
package com.google.unity.ads.nextgen;
2+
3+
import com.google.android.libraries.ads.mobile.sdk.common.VideoOptions;
4+
5+
/**
6+
* DECAGON CONTEXT NOTE FOR PORTING
7+
*
8+
* <p>In legacy Nonagon (GMS), configuring Native Ads uses an `AdLoader.Builder` taking a Decagon
9+
* separate `NativeAdOptions` class. However, Decagon removes this Class completely!
10+
*
11+
* <p>All properties are now set directly onto `NativeAdRequest.Builder`.
12+
*
13+
* <p>To avoid breaking reflection signatures where the Unity C# layer still attempts to instantiate
14+
* and pass a POJO for options, we create this local Adapter Shim
15+
* (`com.google.unity.ads.nextgen.NativeAdOptions`).
16+
*
17+
* <p>We mimic the properties provided by `GoogleMobileAds/Api/Core/NativeAdOptions.cs` and pipe
18+
* them during the `loadAd` phase inside `UnityNativeTemplateAdNextgen`.
19+
*/
20+
public class NativeAdOptions {
21+
22+
private int mediaAspectRatio;
23+
private int adChoicesPlacement;
24+
private VideoOptions videoOptions;
25+
26+
public int getMediaAspectRatio() {
27+
return mediaAspectRatio;
28+
}
29+
30+
public void setMediaAspectRatio(int mediaAspectRatio) {
31+
this.mediaAspectRatio = mediaAspectRatio;
32+
}
33+
34+
public int getAdChoicesPlacement() {
35+
return adChoicesPlacement;
36+
}
37+
38+
public void setAdChoicesPlacement(int adChoicesPlacement) {
39+
this.adChoicesPlacement = adChoicesPlacement;
40+
}
41+
42+
public VideoOptions getVideoOptions() {
43+
return videoOptions;
44+
}
45+
46+
public void setVideoOptions(VideoOptions videoOptions) {
47+
this.videoOptions = videoOptions;
48+
}
49+
}

0 commit comments

Comments
 (0)