react-native-applovin-max 5.7.1 → 6.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/README.md +1 -1
- package/android/build.gradle +2 -2
- package/android/src/main/java/com/applovin/mediation/adapters/GoogleAdManagerMediationAdapter.java.saved +1616 -0
- package/android/src/main/java/com/applovin/mediation/adapters/GoogleMediationAdapter.java.old +1788 -0
- package/android/src/main/java/com/applovin/mediation/adapters/MintegralMediationAdapter.java.old +1481 -0
- package/android/src/main/java/com/applovin/mediation/adapters/MintegralMediationAdapter.java.saved +1448 -0
- package/ios/AppLovinMAX.m +1 -9
- package/ios/AppLovinMAX.xcodeproj/project.pbxproj +4 -4
- package/ios/AppLovinMAX.xcworkspace/xcuserdata/hiroshi.watanabe.xcuserdatad/UserInterfaceState.xcuserstate +0 -0
- package/ios/AppLovinMAXNativeAdView.m +8 -1
- package/ios/Podfile +1 -1
- package/package.json +2 -1
- package/react-native-applovin-max.podspec +1 -1
- package/src/AdView.tsx +251 -0
- package/src/AppLovinMAX.ts +24 -0
- package/src/AppOpenAd.ts +128 -0
- package/src/BannerAd.ts +175 -0
- package/src/EventEmitter.ts +27 -0
- package/src/InterstitialAd.ts +128 -0
- package/src/MRecAd.ts +147 -0
- package/src/Privacy.ts +6 -0
- package/src/RewardedAd.ts +144 -0
- package/src/TargetingData.ts +168 -0
- package/src/index.ts +21 -0
- package/src/nativeAd/NativeAdView.tsx +161 -0
- package/src/nativeAd/NativeAdViewComponents.tsx +185 -0
- package/src/nativeAd/NativeAdViewProvider.tsx +35 -0
- package/src/types/AdEvent.ts +26 -0
- package/src/types/AdInfo.ts +348 -0
- package/src/types/AdProps.ts +60 -0
- package/src/types/AdViewProps.ts +36 -0
- package/src/types/AppLovinMAX.ts +86 -0
- package/src/types/AppOpenAd.ts +3 -0
- package/src/types/BannerAd.ts +47 -0
- package/src/types/Configuration.ts +11 -0
- package/src/types/FullscreenAd.ts +135 -0
- package/src/types/InterstitialAd.ts +3 -0
- package/src/types/MRecAd.ts +13 -0
- package/src/types/NativeAd.ts +50 -0
- package/src/types/NativeAdViewProps.ts +17 -0
- package/src/types/Privacy.ts +73 -0
- package/src/types/RewardedAd.ts +18 -0
- package/src/types/ViewAd.ts +158 -0
- package/src/types/index.ts +4 -0
- package/ios/AppLovinMAX.xcworkspace/xcuserdata/thomasso.xcuserdatad/UserInterfaceState.xcuserstate +0 -0
- package/ios/AppLovinMAX.xcworkspace/xcuserdata/thomasso.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist +0 -24
- package/src/.idea/modules.xml +0 -8
- package/src/.idea/src.iml +0 -8
- package/src/.idea/vcs.xml +0 -6
- package/src/AppLovinMAXAdView.js +0 -231
- package/src/AppLovinMAXEventListeners.js +0 -419
- package/src/NativeAdComponents.js +0 -208
- package/src/NativeAdView.js +0 -164
- package/src/NativeAdViewProvider.js +0 -19
- package/src/TargetingData.js +0 -104
- package/src/index.js +0 -291
|
@@ -0,0 +1,1788 @@
|
|
|
1
|
+
package com.applovin.mediation.adapters;
|
|
2
|
+
|
|
3
|
+
import android.annotation.SuppressLint;
|
|
4
|
+
import android.app.Activity;
|
|
5
|
+
import android.content.Context;
|
|
6
|
+
import android.graphics.Rect;
|
|
7
|
+
import android.graphics.drawable.Drawable;
|
|
8
|
+
import android.os.Build;
|
|
9
|
+
import android.os.Bundle;
|
|
10
|
+
import android.preference.PreferenceManager;
|
|
11
|
+
import android.text.TextUtils;
|
|
12
|
+
import android.util.DisplayMetrics;
|
|
13
|
+
import android.view.Display;
|
|
14
|
+
import android.view.View;
|
|
15
|
+
import android.view.ViewGroup;
|
|
16
|
+
import android.view.WindowManager;
|
|
17
|
+
import android.view.WindowMetrics;
|
|
18
|
+
import android.widget.FrameLayout;
|
|
19
|
+
import android.widget.ImageView;
|
|
20
|
+
import android.widget.RelativeLayout;
|
|
21
|
+
|
|
22
|
+
import com.applovin.impl.sdk.utils.BundleUtils;
|
|
23
|
+
import com.applovin.mediation.MaxAdFormat;
|
|
24
|
+
import com.applovin.mediation.MaxReward;
|
|
25
|
+
import com.applovin.mediation.adapter.MaxAdViewAdapter;
|
|
26
|
+
import com.applovin.mediation.adapter.MaxAdapterError;
|
|
27
|
+
import com.applovin.mediation.adapter.MaxInterstitialAdapter;
|
|
28
|
+
import com.applovin.mediation.adapter.MaxRewardedAdapter;
|
|
29
|
+
import com.applovin.mediation.adapter.MaxRewardedInterstitialAdapter;
|
|
30
|
+
import com.applovin.mediation.adapter.MaxSignalProvider;
|
|
31
|
+
import com.applovin.mediation.adapter.listeners.MaxAdViewAdapterListener;
|
|
32
|
+
import com.applovin.mediation.adapter.listeners.MaxAppOpenAdapterListener;
|
|
33
|
+
import com.applovin.mediation.adapter.listeners.MaxInterstitialAdapterListener;
|
|
34
|
+
import com.applovin.mediation.adapter.listeners.MaxNativeAdAdapterListener;
|
|
35
|
+
import com.applovin.mediation.adapter.listeners.MaxRewardedAdapterListener;
|
|
36
|
+
import com.applovin.mediation.adapter.listeners.MaxRewardedInterstitialAdapterListener;
|
|
37
|
+
import com.applovin.mediation.adapter.listeners.MaxSignalCollectionListener;
|
|
38
|
+
import com.applovin.mediation.adapter.parameters.MaxAdapterInitializationParameters;
|
|
39
|
+
import com.applovin.mediation.adapter.parameters.MaxAdapterParameters;
|
|
40
|
+
import com.applovin.mediation.adapter.parameters.MaxAdapterResponseParameters;
|
|
41
|
+
import com.applovin.mediation.adapter.parameters.MaxAdapterSignalCollectionParameters;
|
|
42
|
+
import com.applovin.mediation.nativeAds.MaxNativeAd;
|
|
43
|
+
import com.applovin.mediation.nativeAds.MaxNativeAdView;
|
|
44
|
+
import com.applovin.sdk.AppLovinSdk;
|
|
45
|
+
import com.applovin.sdk.AppLovinSdkUtils;
|
|
46
|
+
import com.google.ads.mediation.admob.AdMobAdapter;
|
|
47
|
+
import com.google.android.gms.ads.AdError;
|
|
48
|
+
import com.google.android.gms.ads.AdFormat;
|
|
49
|
+
import com.google.android.gms.ads.AdListener;
|
|
50
|
+
import com.google.android.gms.ads.AdLoader;
|
|
51
|
+
import com.google.android.gms.ads.AdRequest;
|
|
52
|
+
import com.google.android.gms.ads.AdSize;
|
|
53
|
+
import com.google.android.gms.ads.AdView;
|
|
54
|
+
import com.google.android.gms.ads.FullScreenContentCallback;
|
|
55
|
+
import com.google.android.gms.ads.LoadAdError;
|
|
56
|
+
import com.google.android.gms.ads.MediaContent;
|
|
57
|
+
import com.google.android.gms.ads.MobileAds;
|
|
58
|
+
import com.google.android.gms.ads.OnUserEarnedRewardListener;
|
|
59
|
+
import com.google.android.gms.ads.RequestConfiguration;
|
|
60
|
+
import com.google.android.gms.ads.ResponseInfo;
|
|
61
|
+
import com.google.android.gms.ads.appopen.AppOpenAd;
|
|
62
|
+
import com.google.android.gms.ads.initialization.AdapterStatus;
|
|
63
|
+
import com.google.android.gms.ads.initialization.OnInitializationCompleteListener;
|
|
64
|
+
import com.google.android.gms.ads.interstitial.InterstitialAd;
|
|
65
|
+
import com.google.android.gms.ads.interstitial.InterstitialAdLoadCallback;
|
|
66
|
+
import com.google.android.gms.ads.nativead.MediaView;
|
|
67
|
+
import com.google.android.gms.ads.nativead.NativeAd;
|
|
68
|
+
import com.google.android.gms.ads.nativead.NativeAd.OnNativeAdLoadedListener;
|
|
69
|
+
import com.google.android.gms.ads.nativead.NativeAdOptions;
|
|
70
|
+
import com.google.android.gms.ads.nativead.NativeAdView;
|
|
71
|
+
import com.google.android.gms.ads.query.QueryInfo;
|
|
72
|
+
import com.google.android.gms.ads.query.QueryInfoGenerationCallback;
|
|
73
|
+
import com.google.android.gms.ads.rewarded.RewardItem;
|
|
74
|
+
import com.google.android.gms.ads.rewarded.RewardedAd;
|
|
75
|
+
import com.google.android.gms.ads.rewarded.RewardedAdLoadCallback;
|
|
76
|
+
import com.google.android.gms.ads.rewardedinterstitial.RewardedInterstitialAd;
|
|
77
|
+
import com.google.android.gms.ads.rewardedinterstitial.RewardedInterstitialAdLoadCallback;
|
|
78
|
+
|
|
79
|
+
import java.lang.ref.WeakReference;
|
|
80
|
+
import java.util.Collections;
|
|
81
|
+
import java.util.List;
|
|
82
|
+
import java.util.Map;
|
|
83
|
+
import java.util.concurrent.atomic.AtomicBoolean;
|
|
84
|
+
|
|
85
|
+
import androidx.annotation.NonNull;
|
|
86
|
+
import androidx.annotation.Nullable;
|
|
87
|
+
|
|
88
|
+
import static com.applovin.sdk.AppLovinSdkUtils.runOnUiThread;
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* This is a mediation adapterWrapper for Google Play Services
|
|
92
|
+
* <p>
|
|
93
|
+
* Created by basil on 12/7/16.
|
|
94
|
+
*/
|
|
95
|
+
public class GoogleMediationAdapter
|
|
96
|
+
extends MediationAdapterBase
|
|
97
|
+
implements MaxSignalProvider, MaxInterstitialAdapter, /* MaxAppOpenAdapter */ MaxRewardedInterstitialAdapter, MaxRewardedAdapter, MaxAdViewAdapter /* MaxNativeAdAdapter */
|
|
98
|
+
{
|
|
99
|
+
private static final int TITLE_LABEL_TAG = 1;
|
|
100
|
+
private static final int MEDIA_VIEW_CONTAINER_TAG = 2;
|
|
101
|
+
private static final int ICON_VIEW_TAG = 3;
|
|
102
|
+
private static final int BODY_VIEW_TAG = 4;
|
|
103
|
+
private static final int CALL_TO_ACTION_VIEW_TAG = 5;
|
|
104
|
+
private static final int ADVERTISER_VIEW_TAG = 8;
|
|
105
|
+
|
|
106
|
+
private static final AtomicBoolean initialized = new AtomicBoolean();
|
|
107
|
+
private static InitializationStatus status;
|
|
108
|
+
|
|
109
|
+
private InterstitialAd interstitialAd;
|
|
110
|
+
private AppOpenAd appOpenAd;
|
|
111
|
+
private InterstitialAd appOpenInterstitialAd;
|
|
112
|
+
private RewardedInterstitialAd rewardedInterstitialAd;
|
|
113
|
+
private RewardedAd rewardedAd;
|
|
114
|
+
private AdView adView;
|
|
115
|
+
private NativeAd nativeAd;
|
|
116
|
+
private NativeAdView nativeAdView;
|
|
117
|
+
|
|
118
|
+
private AppOpenAdListener appOpenAdListener;
|
|
119
|
+
private AppOpenAdListener appOpenInterstitialAdListener;
|
|
120
|
+
private RewardedInterstitialAdListener rewardedInterstitialAdListener;
|
|
121
|
+
private RewardedAdListener rewardedAdListener;
|
|
122
|
+
|
|
123
|
+
// Explicit default constructor declaration
|
|
124
|
+
public GoogleMediationAdapter(final AppLovinSdk sdk) { super( sdk ); }
|
|
125
|
+
|
|
126
|
+
//region MaxAdapter Methods
|
|
127
|
+
|
|
128
|
+
@SuppressLint("MissingPermission")
|
|
129
|
+
@Override
|
|
130
|
+
public void initialize(final MaxAdapterInitializationParameters parameters, final Activity activity, final OnCompletionListener onCompletionListener)
|
|
131
|
+
{
|
|
132
|
+
log( "Initializing Google SDK..." );
|
|
133
|
+
|
|
134
|
+
if ( initialized.compareAndSet( false, true ) )
|
|
135
|
+
{
|
|
136
|
+
Context context = getContext( activity );
|
|
137
|
+
|
|
138
|
+
// Prevent AdMob SDK from auto-initing its adapters in AB testing environments.
|
|
139
|
+
// NOTE: If MAX makes an ad request to AdMob, and the AdMob account has AL enabled (e.g. AppLovin Bidding) _and_ detects the AdMob<->AppLovin adapter, AdMob will still attempt to initialize AppLovin
|
|
140
|
+
MobileAds.disableMediationAdapterInitialization( context );
|
|
141
|
+
|
|
142
|
+
if ( parameters.getServerParameters().getBoolean( "init_without_callback", false ) )
|
|
143
|
+
{
|
|
144
|
+
status = InitializationStatus.DOES_NOT_APPLY;
|
|
145
|
+
|
|
146
|
+
MobileAds.initialize( context );
|
|
147
|
+
|
|
148
|
+
onCompletionListener.onCompletion( status, null );
|
|
149
|
+
}
|
|
150
|
+
else
|
|
151
|
+
{
|
|
152
|
+
status = InitializationStatus.INITIALIZING;
|
|
153
|
+
|
|
154
|
+
MobileAds.initialize( context, new OnInitializationCompleteListener()
|
|
155
|
+
{
|
|
156
|
+
@Override
|
|
157
|
+
public void onInitializationComplete(@NonNull final com.google.android.gms.ads.initialization.InitializationStatus initializationStatus)
|
|
158
|
+
{
|
|
159
|
+
final AdapterStatus googleAdsStatus = initializationStatus.getAdapterStatusMap().get( "com.google.android.gms.ads.MobileAds" );
|
|
160
|
+
final AdapterStatus.State googleAdsState = googleAdsStatus != null ? googleAdsStatus.getInitializationState() : null;
|
|
161
|
+
log( "Initialization complete with status " + googleAdsState );
|
|
162
|
+
|
|
163
|
+
// NOTE: We were able to load ads even when SDK is in "not ready" init state...
|
|
164
|
+
// AdMob SDK when status "not ready": "The mediation adapter is LESS likely to fill ad requests."
|
|
165
|
+
status = ( AdapterStatus.State.READY == googleAdsState ) ? InitializationStatus.INITIALIZED_SUCCESS : InitializationStatus.INITIALIZED_UNKNOWN;
|
|
166
|
+
onCompletionListener.onCompletion( status, null );
|
|
167
|
+
}
|
|
168
|
+
} );
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
else
|
|
172
|
+
{
|
|
173
|
+
onCompletionListener.onCompletion( status, null );
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
@Override
|
|
178
|
+
public String getSdkVersion()
|
|
179
|
+
{
|
|
180
|
+
return String.valueOf( MobileAds.getVersion() );
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
@Override
|
|
184
|
+
public String getAdapterVersion()
|
|
185
|
+
{
|
|
186
|
+
return "22.4.0.0"; //BuildConfig.VERSION_NAME;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
@Override
|
|
190
|
+
public void onDestroy()
|
|
191
|
+
{
|
|
192
|
+
log( "Destroy called for adapter " + this );
|
|
193
|
+
|
|
194
|
+
if ( interstitialAd != null )
|
|
195
|
+
{
|
|
196
|
+
interstitialAd.setFullScreenContentCallback( null );
|
|
197
|
+
interstitialAd = null;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
if ( appOpenAd != null )
|
|
201
|
+
{
|
|
202
|
+
appOpenAd.setFullScreenContentCallback( null );
|
|
203
|
+
appOpenAd = null;
|
|
204
|
+
appOpenAdListener = null;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
if ( appOpenInterstitialAd != null )
|
|
208
|
+
{
|
|
209
|
+
appOpenInterstitialAd.setFullScreenContentCallback( null );
|
|
210
|
+
appOpenInterstitialAd = null;
|
|
211
|
+
appOpenInterstitialAdListener = null;
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
if ( rewardedInterstitialAd != null )
|
|
215
|
+
{
|
|
216
|
+
rewardedInterstitialAd.setFullScreenContentCallback( null );
|
|
217
|
+
rewardedInterstitialAd = null;
|
|
218
|
+
rewardedInterstitialAdListener = null;
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
if ( rewardedAd != null )
|
|
222
|
+
{
|
|
223
|
+
rewardedAd.setFullScreenContentCallback( null );
|
|
224
|
+
rewardedAd = null;
|
|
225
|
+
rewardedAdListener = null;
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
if ( adView != null )
|
|
229
|
+
{
|
|
230
|
+
adView.destroy();
|
|
231
|
+
adView = null;
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
if ( nativeAd != null )
|
|
235
|
+
{
|
|
236
|
+
nativeAd.destroy();
|
|
237
|
+
nativeAd = null;
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
if ( nativeAdView != null )
|
|
241
|
+
{
|
|
242
|
+
nativeAdView.destroy();
|
|
243
|
+
nativeAdView = null;
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
//endregion
|
|
248
|
+
|
|
249
|
+
//region MaxSignalProvider Methods
|
|
250
|
+
|
|
251
|
+
@Override
|
|
252
|
+
public void collectSignal(final MaxAdapterSignalCollectionParameters parameters, final Activity activity, final MaxSignalCollectionListener callback)
|
|
253
|
+
{
|
|
254
|
+
setRequestConfiguration( parameters );
|
|
255
|
+
|
|
256
|
+
Context context = getContext( activity );
|
|
257
|
+
|
|
258
|
+
AdRequest adRequest = createAdRequestWithParameters( true, parameters.getAdFormat(), parameters, context );
|
|
259
|
+
|
|
260
|
+
QueryInfo.generate( context, toAdFormat( parameters ), adRequest, new QueryInfoGenerationCallback()
|
|
261
|
+
{
|
|
262
|
+
@Override
|
|
263
|
+
public void onSuccess(@NonNull final QueryInfo queryInfo)
|
|
264
|
+
{
|
|
265
|
+
log( "Signal collection successful" );
|
|
266
|
+
callback.onSignalCollected( queryInfo.getQuery() );
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
@Override
|
|
270
|
+
public void onFailure(@NonNull final String errorMessage)
|
|
271
|
+
{
|
|
272
|
+
log( "Signal collection failed with error: " + errorMessage );
|
|
273
|
+
callback.onSignalCollectionFailed( errorMessage );
|
|
274
|
+
}
|
|
275
|
+
} );
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
//endregion
|
|
279
|
+
|
|
280
|
+
//region MaxInterstitialAdapter Methods
|
|
281
|
+
|
|
282
|
+
@Override
|
|
283
|
+
public void loadInterstitialAd(final MaxAdapterResponseParameters parameters, final Activity activity, final MaxInterstitialAdapterListener listener)
|
|
284
|
+
{
|
|
285
|
+
final String placementId = parameters.getThirdPartyAdPlacementId();
|
|
286
|
+
boolean isBiddingAd = AppLovinSdkUtils.isValidString( parameters.getBidResponse() );
|
|
287
|
+
log( "Loading " + ( isBiddingAd ? "bidding " : "" ) + "interstitial ad: " + placementId + "..." );
|
|
288
|
+
|
|
289
|
+
updateMuteState( parameters );
|
|
290
|
+
setRequestConfiguration( parameters );
|
|
291
|
+
AdRequest adRequest = createAdRequestWithParameters( isBiddingAd, MaxAdFormat.INTERSTITIAL, parameters, activity );
|
|
292
|
+
|
|
293
|
+
InterstitialAd.load( activity, placementId, adRequest, new InterstitialAdLoadCallback()
|
|
294
|
+
{
|
|
295
|
+
@Override
|
|
296
|
+
public void onAdLoaded(@NonNull final InterstitialAd ad)
|
|
297
|
+
{
|
|
298
|
+
log( "Interstitial ad loaded: " + placementId + "..." );
|
|
299
|
+
|
|
300
|
+
interstitialAd = ad;
|
|
301
|
+
interstitialAd.setFullScreenContentCallback( new InterstitialAdListener( placementId, listener ) );
|
|
302
|
+
|
|
303
|
+
ResponseInfo responseInfo = interstitialAd.getResponseInfo();
|
|
304
|
+
String responseId = ( responseInfo != null ) ? responseInfo.getResponseId() : null;
|
|
305
|
+
if ( AppLovinSdk.VERSION_CODE >= 9150000 && AppLovinSdkUtils.isValidString( responseId ) )
|
|
306
|
+
{
|
|
307
|
+
Bundle extraInfo = new Bundle( 1 );
|
|
308
|
+
extraInfo.putString( "creative_id", responseId );
|
|
309
|
+
|
|
310
|
+
listener.onInterstitialAdLoaded( extraInfo );
|
|
311
|
+
}
|
|
312
|
+
else
|
|
313
|
+
{
|
|
314
|
+
listener.onInterstitialAdLoaded();
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
@Override
|
|
319
|
+
public void onAdFailedToLoad(@NonNull final LoadAdError loadAdError)
|
|
320
|
+
{
|
|
321
|
+
MaxAdapterError adapterError = toMaxError( loadAdError );
|
|
322
|
+
log( "Interstitial ad (" + placementId + ") failed to load with error: " + adapterError );
|
|
323
|
+
listener.onInterstitialAdLoadFailed( adapterError );
|
|
324
|
+
}
|
|
325
|
+
} );
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
@Override
|
|
329
|
+
public void showInterstitialAd(final MaxAdapterResponseParameters parameters, final Activity activity, final MaxInterstitialAdapterListener listener)
|
|
330
|
+
{
|
|
331
|
+
String placementId = parameters.getThirdPartyAdPlacementId();
|
|
332
|
+
log( "Showing interstitial ad: " + placementId + "..." );
|
|
333
|
+
|
|
334
|
+
if ( interstitialAd != null )
|
|
335
|
+
{
|
|
336
|
+
interstitialAd.show( activity );
|
|
337
|
+
}
|
|
338
|
+
else
|
|
339
|
+
{
|
|
340
|
+
log( "Interstitial ad failed to show: " + placementId );
|
|
341
|
+
listener.onInterstitialAdDisplayFailed( new MaxAdapterError( -4205, "Ad Display Failed", 0, "Interstitial ad not ready" ) );
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
//endregion
|
|
346
|
+
|
|
347
|
+
//region MaxAppOpenAdapter Methods
|
|
348
|
+
|
|
349
|
+
// @Override
|
|
350
|
+
public void loadAppOpenAd(final MaxAdapterResponseParameters parameters, @Nullable Activity activity, final MaxAppOpenAdapterListener listener)
|
|
351
|
+
{
|
|
352
|
+
final String placementId = parameters.getThirdPartyAdPlacementId();
|
|
353
|
+
boolean isBiddingAd = AppLovinSdkUtils.isValidString( parameters.getBidResponse() );
|
|
354
|
+
boolean isInterstitial = parameters.getServerParameters().getBoolean( "is_inter_placement" );
|
|
355
|
+
log( "Loading " + ( isBiddingAd ? "bidding " : "" ) + "app open " + ( isInterstitial ? "interstitial " : "" ) + "ad: " + placementId + "..." );
|
|
356
|
+
|
|
357
|
+
updateMuteState( parameters );
|
|
358
|
+
setRequestConfiguration( parameters );
|
|
359
|
+
Context context = getContext( activity );
|
|
360
|
+
|
|
361
|
+
if ( isInterstitial )
|
|
362
|
+
{
|
|
363
|
+
AdRequest adRequest = createAdRequestWithParameters( isBiddingAd, MaxAdFormat.INTERSTITIAL, parameters, activity );
|
|
364
|
+
InterstitialAd.load( context, placementId, adRequest, new InterstitialAdLoadCallback()
|
|
365
|
+
{
|
|
366
|
+
@Override
|
|
367
|
+
public void onAdLoaded(@NonNull final InterstitialAd ad)
|
|
368
|
+
{
|
|
369
|
+
log( "App open interstitial ad loaded: " + placementId + "..." );
|
|
370
|
+
|
|
371
|
+
appOpenInterstitialAd = ad;
|
|
372
|
+
appOpenInterstitialAdListener = new AppOpenAdListener( placementId, listener );
|
|
373
|
+
appOpenInterstitialAd.setFullScreenContentCallback( appOpenInterstitialAdListener );
|
|
374
|
+
|
|
375
|
+
ResponseInfo responseInfo = appOpenInterstitialAd.getResponseInfo();
|
|
376
|
+
String responseId = responseInfo != null ? responseInfo.getResponseId() : null;
|
|
377
|
+
if ( AppLovinSdkUtils.isValidString( responseId ) )
|
|
378
|
+
{
|
|
379
|
+
Bundle extraInfo = new Bundle( 1 );
|
|
380
|
+
extraInfo.putString( "creative_id", responseId );
|
|
381
|
+
|
|
382
|
+
listener.onAppOpenAdLoaded( extraInfo );
|
|
383
|
+
}
|
|
384
|
+
else
|
|
385
|
+
{
|
|
386
|
+
listener.onAppOpenAdLoaded();
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
@Override
|
|
391
|
+
public void onAdFailedToLoad(@NonNull final LoadAdError loadAdError)
|
|
392
|
+
{
|
|
393
|
+
MaxAdapterError adapterError = toMaxError( loadAdError );
|
|
394
|
+
log( "App open interstitial ad (" + placementId + ") failed to load with error: " + adapterError );
|
|
395
|
+
listener.onAppOpenAdLoadFailed( adapterError );
|
|
396
|
+
}
|
|
397
|
+
} );
|
|
398
|
+
}
|
|
399
|
+
else
|
|
400
|
+
{
|
|
401
|
+
AdRequest adRequest = createAdRequestWithParameters( isBiddingAd, MaxAdFormat.APP_OPEN, parameters, activity );
|
|
402
|
+
int orientation = AppLovinSdkUtils.getOrientation( context );
|
|
403
|
+
AppOpenAd.load( context, placementId, adRequest, orientation, new AppOpenAd.AppOpenAdLoadCallback()
|
|
404
|
+
{
|
|
405
|
+
@Override
|
|
406
|
+
public void onAdLoaded(@NonNull final AppOpenAd ad)
|
|
407
|
+
{
|
|
408
|
+
log( "App open ad loaded: " + placementId + "..." );
|
|
409
|
+
|
|
410
|
+
appOpenAd = ad;
|
|
411
|
+
appOpenAdListener = new AppOpenAdListener( placementId, listener );
|
|
412
|
+
ad.setFullScreenContentCallback( appOpenAdListener );
|
|
413
|
+
|
|
414
|
+
ResponseInfo responseInfo = appOpenAd.getResponseInfo();
|
|
415
|
+
String responseId = responseInfo != null ? responseInfo.getResponseId() : null;
|
|
416
|
+
if ( AppLovinSdkUtils.isValidString( responseId ) )
|
|
417
|
+
{
|
|
418
|
+
Bundle extraInfo = new Bundle( 1 );
|
|
419
|
+
extraInfo.putString( "creative_id", responseId );
|
|
420
|
+
|
|
421
|
+
listener.onAppOpenAdLoaded( extraInfo );
|
|
422
|
+
}
|
|
423
|
+
else
|
|
424
|
+
{
|
|
425
|
+
listener.onAppOpenAdLoaded();
|
|
426
|
+
}
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
@Override
|
|
430
|
+
public void onAdFailedToLoad(@NonNull final LoadAdError loadAdError)
|
|
431
|
+
{
|
|
432
|
+
MaxAdapterError adapterError = toMaxError( loadAdError );
|
|
433
|
+
log( "App open ad (" + placementId + ") failed to load with error: " + adapterError );
|
|
434
|
+
listener.onAppOpenAdLoadFailed( adapterError );
|
|
435
|
+
}
|
|
436
|
+
} );
|
|
437
|
+
}
|
|
438
|
+
}
|
|
439
|
+
|
|
440
|
+
// @Override
|
|
441
|
+
public void showAppOpenAd(final MaxAdapterResponseParameters parameters, @Nullable final Activity activity, final MaxAppOpenAdapterListener listener)
|
|
442
|
+
{
|
|
443
|
+
String placementId = parameters.getThirdPartyAdPlacementId();
|
|
444
|
+
boolean isInterstitial = parameters.getServerParameters().getBoolean( "is_inter_placement" );
|
|
445
|
+
log( "Showing app open " + ( isInterstitial ? "interstitial " : "" ) + "ad: " + placementId + "..." );
|
|
446
|
+
|
|
447
|
+
// Shows ad with null activity properly as tested in SDK version 21.1.0
|
|
448
|
+
if ( appOpenInterstitialAd != null )
|
|
449
|
+
{
|
|
450
|
+
appOpenInterstitialAd.show( activity );
|
|
451
|
+
}
|
|
452
|
+
else if ( appOpenAd != null )
|
|
453
|
+
{
|
|
454
|
+
appOpenAd.show( activity );
|
|
455
|
+
}
|
|
456
|
+
else
|
|
457
|
+
{
|
|
458
|
+
log( "App open ad failed to show: " + placementId );
|
|
459
|
+
listener.onAppOpenAdLoadFailed( new MaxAdapterError( -4205, "Ad display failed", 0, "App open ad not ready" ) );
|
|
460
|
+
}
|
|
461
|
+
}
|
|
462
|
+
|
|
463
|
+
//endregion
|
|
464
|
+
|
|
465
|
+
//region MaxRewardedInterstitialAdapter Methods
|
|
466
|
+
|
|
467
|
+
@Override
|
|
468
|
+
public void loadRewardedInterstitialAd(final MaxAdapterResponseParameters parameters, final Activity activity, final MaxRewardedInterstitialAdapterListener listener)
|
|
469
|
+
{
|
|
470
|
+
final String placementId = parameters.getThirdPartyAdPlacementId();
|
|
471
|
+
boolean isBiddingAd = AppLovinSdkUtils.isValidString( parameters.getBidResponse() );
|
|
472
|
+
log( "Loading " + ( isBiddingAd ? "bidding " : "" ) + "rewarded interstitial ad: " + placementId + "..." );
|
|
473
|
+
|
|
474
|
+
updateMuteState( parameters );
|
|
475
|
+
setRequestConfiguration( parameters );
|
|
476
|
+
AdRequest adRequest = createAdRequestWithParameters( isBiddingAd, MaxAdFormat.REWARDED_INTERSTITIAL, parameters, activity );
|
|
477
|
+
|
|
478
|
+
RewardedInterstitialAd.load( activity, placementId, adRequest, new RewardedInterstitialAdLoadCallback()
|
|
479
|
+
{
|
|
480
|
+
@Override
|
|
481
|
+
public void onAdLoaded(@NonNull final RewardedInterstitialAd ad)
|
|
482
|
+
{
|
|
483
|
+
log( "Rewarded interstitial ad loaded: " + placementId );
|
|
484
|
+
|
|
485
|
+
rewardedInterstitialAd = ad;
|
|
486
|
+
rewardedInterstitialAdListener = new RewardedInterstitialAdListener( placementId, listener );
|
|
487
|
+
rewardedInterstitialAd.setFullScreenContentCallback( rewardedInterstitialAdListener );
|
|
488
|
+
|
|
489
|
+
ResponseInfo responseInfo = rewardedInterstitialAd.getResponseInfo();
|
|
490
|
+
String responseId = ( responseInfo != null ) ? responseInfo.getResponseId() : null;
|
|
491
|
+
if ( AppLovinSdk.VERSION_CODE > 9150000 && AppLovinSdkUtils.isValidString( responseId ) )
|
|
492
|
+
{
|
|
493
|
+
Bundle extraInfo = new Bundle( 1 );
|
|
494
|
+
extraInfo.putString( "creative_id", responseId );
|
|
495
|
+
|
|
496
|
+
listener.onRewardedInterstitialAdLoaded( extraInfo );
|
|
497
|
+
}
|
|
498
|
+
else
|
|
499
|
+
{
|
|
500
|
+
listener.onRewardedInterstitialAdLoaded();
|
|
501
|
+
}
|
|
502
|
+
}
|
|
503
|
+
|
|
504
|
+
@Override
|
|
505
|
+
public void onAdFailedToLoad(@NonNull final LoadAdError loadAdError)
|
|
506
|
+
{
|
|
507
|
+
MaxAdapterError adapterError = toMaxError( loadAdError );
|
|
508
|
+
log( "Rewarded interstitial ad (" + placementId + ") failed to load with error: " + adapterError );
|
|
509
|
+
listener.onRewardedInterstitialAdLoadFailed( adapterError );
|
|
510
|
+
}
|
|
511
|
+
} );
|
|
512
|
+
}
|
|
513
|
+
|
|
514
|
+
@Override
|
|
515
|
+
public void showRewardedInterstitialAd(final MaxAdapterResponseParameters parameters, final Activity activity, final MaxRewardedInterstitialAdapterListener listener)
|
|
516
|
+
{
|
|
517
|
+
final String placementId = parameters.getThirdPartyAdPlacementId();
|
|
518
|
+
log( "Showing rewarded interstitial ad: " + placementId + "..." );
|
|
519
|
+
|
|
520
|
+
if ( rewardedInterstitialAd != null )
|
|
521
|
+
{
|
|
522
|
+
configureReward( parameters );
|
|
523
|
+
rewardedInterstitialAd.show( activity, new OnUserEarnedRewardListener()
|
|
524
|
+
{
|
|
525
|
+
@Override
|
|
526
|
+
public void onUserEarnedReward(@NonNull final RewardItem rewardItem)
|
|
527
|
+
{
|
|
528
|
+
log( "Rewarded interstitial ad user earned reward: " + placementId );
|
|
529
|
+
rewardedInterstitialAdListener.hasGrantedReward = true;
|
|
530
|
+
}
|
|
531
|
+
} );
|
|
532
|
+
}
|
|
533
|
+
else
|
|
534
|
+
{
|
|
535
|
+
log( "Rewarded interstitial ad failed to show: " + placementId );
|
|
536
|
+
listener.onRewardedInterstitialAdDisplayFailed( new MaxAdapterError( -4205, "Ad Display Failed", 0, "Rewarded Interstitial ad not ready" ) );
|
|
537
|
+
}
|
|
538
|
+
}
|
|
539
|
+
|
|
540
|
+
//endregion
|
|
541
|
+
|
|
542
|
+
//region MaxRewardedAdapter Methods
|
|
543
|
+
|
|
544
|
+
@Override
|
|
545
|
+
public void loadRewardedAd(final MaxAdapterResponseParameters parameters, final Activity activity, final MaxRewardedAdapterListener listener)
|
|
546
|
+
{
|
|
547
|
+
final String placementId = parameters.getThirdPartyAdPlacementId();
|
|
548
|
+
boolean isBiddingAd = AppLovinSdkUtils.isValidString( parameters.getBidResponse() );
|
|
549
|
+
log( "Loading " + ( isBiddingAd ? "bidding " : "" ) + "rewarded ad: " + placementId + "..." );
|
|
550
|
+
|
|
551
|
+
updateMuteState( parameters );
|
|
552
|
+
setRequestConfiguration( parameters );
|
|
553
|
+
AdRequest adRequest = createAdRequestWithParameters( isBiddingAd, MaxAdFormat.REWARDED, parameters, activity );
|
|
554
|
+
|
|
555
|
+
RewardedAd.load( activity, placementId, adRequest, new RewardedAdLoadCallback()
|
|
556
|
+
{
|
|
557
|
+
@Override
|
|
558
|
+
public void onAdLoaded(@NonNull final RewardedAd ad)
|
|
559
|
+
{
|
|
560
|
+
log( "Rewarded ad loaded: " + placementId + "..." );
|
|
561
|
+
|
|
562
|
+
rewardedAd = ad;
|
|
563
|
+
rewardedAdListener = new RewardedAdListener( placementId, listener );
|
|
564
|
+
rewardedAd.setFullScreenContentCallback( rewardedAdListener );
|
|
565
|
+
|
|
566
|
+
ResponseInfo responseInfo = rewardedAd.getResponseInfo();
|
|
567
|
+
String responseId = ( responseInfo != null ) ? responseInfo.getResponseId() : null;
|
|
568
|
+
if ( AppLovinSdk.VERSION_CODE >= 9150000 && AppLovinSdkUtils.isValidString( responseId ) )
|
|
569
|
+
{
|
|
570
|
+
Bundle extraInfo = new Bundle( 1 );
|
|
571
|
+
extraInfo.putString( "creative_id", responseId );
|
|
572
|
+
|
|
573
|
+
listener.onRewardedAdLoaded( extraInfo );
|
|
574
|
+
}
|
|
575
|
+
else
|
|
576
|
+
{
|
|
577
|
+
listener.onRewardedAdLoaded();
|
|
578
|
+
}
|
|
579
|
+
}
|
|
580
|
+
|
|
581
|
+
@Override
|
|
582
|
+
public void onAdFailedToLoad(@NonNull final LoadAdError loadAdError)
|
|
583
|
+
{
|
|
584
|
+
MaxAdapterError adapterError = toMaxError( loadAdError );
|
|
585
|
+
log( "Rewarded ad (" + placementId + ") failed to load with error: " + adapterError );
|
|
586
|
+
listener.onRewardedAdLoadFailed( adapterError );
|
|
587
|
+
}
|
|
588
|
+
} );
|
|
589
|
+
}
|
|
590
|
+
|
|
591
|
+
@Override
|
|
592
|
+
public void showRewardedAd(final MaxAdapterResponseParameters parameters, final Activity activity, final MaxRewardedAdapterListener listener)
|
|
593
|
+
{
|
|
594
|
+
final String placementId = parameters.getThirdPartyAdPlacementId();
|
|
595
|
+
log( "Showing rewarded ad: " + placementId + "..." );
|
|
596
|
+
|
|
597
|
+
if ( rewardedAd != null )
|
|
598
|
+
{
|
|
599
|
+
configureReward( parameters );
|
|
600
|
+
|
|
601
|
+
rewardedAd.show( activity, new OnUserEarnedRewardListener()
|
|
602
|
+
{
|
|
603
|
+
@Override
|
|
604
|
+
public void onUserEarnedReward(@NonNull final RewardItem rewardItem)
|
|
605
|
+
{
|
|
606
|
+
log( "Rewarded ad user earned reward: " + placementId );
|
|
607
|
+
rewardedAdListener.hasGrantedReward = true;
|
|
608
|
+
}
|
|
609
|
+
} );
|
|
610
|
+
}
|
|
611
|
+
else
|
|
612
|
+
{
|
|
613
|
+
log( "Rewarded ad failed to show: " + placementId );
|
|
614
|
+
listener.onRewardedAdDisplayFailed( new MaxAdapterError( -4205, "Ad Display Failed", 0, "Rewarded ad not ready" ) );
|
|
615
|
+
}
|
|
616
|
+
}
|
|
617
|
+
|
|
618
|
+
//endregion
|
|
619
|
+
|
|
620
|
+
//region MaxAdViewAdapter Methods
|
|
621
|
+
|
|
622
|
+
@SuppressLint("MissingPermission")
|
|
623
|
+
@Override
|
|
624
|
+
public void loadAdViewAd(final MaxAdapterResponseParameters parameters, final MaxAdFormat adFormat, final Activity activity, final MaxAdViewAdapterListener listener)
|
|
625
|
+
{
|
|
626
|
+
String placementId = parameters.getThirdPartyAdPlacementId();
|
|
627
|
+
boolean isBiddingAd = AppLovinSdkUtils.isValidString( parameters.getBidResponse() );
|
|
628
|
+
boolean isNative = parameters.getServerParameters().getBoolean( "is_native" );
|
|
629
|
+
log( "Loading " + ( isBiddingAd ? "bidding " : "" ) + ( isNative ? "native " : "" ) + adFormat.getLabel() + " ad for placement id: " + placementId + "..." );
|
|
630
|
+
|
|
631
|
+
setRequestConfiguration( parameters );
|
|
632
|
+
|
|
633
|
+
Context context = getContext( activity );
|
|
634
|
+
AdRequest adRequest = createAdRequestWithParameters( isBiddingAd, adFormat, parameters, context );
|
|
635
|
+
|
|
636
|
+
if ( isNative )
|
|
637
|
+
{
|
|
638
|
+
NativeAdOptions.Builder nativeAdOptionsBuilder = new NativeAdOptions.Builder();
|
|
639
|
+
nativeAdOptionsBuilder.setAdChoicesPlacement( getAdChoicesPlacement( parameters ) );
|
|
640
|
+
nativeAdOptionsBuilder.setRequestMultipleImages( adFormat == MaxAdFormat.MREC ); // MRECs can handle multiple images via AdMob's media view
|
|
641
|
+
|
|
642
|
+
// NOTE: Activity context needed on older SDKs
|
|
643
|
+
NativeAdViewListener nativeAdViewListener = new NativeAdViewListener( parameters, adFormat, activity, listener );
|
|
644
|
+
AdLoader adLoader = new AdLoader.Builder( context, placementId )
|
|
645
|
+
.withNativeAdOptions( nativeAdOptionsBuilder.build() )
|
|
646
|
+
.forNativeAd( nativeAdViewListener )
|
|
647
|
+
.withAdListener( nativeAdViewListener )
|
|
648
|
+
.build();
|
|
649
|
+
|
|
650
|
+
adLoader.loadAd( adRequest );
|
|
651
|
+
}
|
|
652
|
+
else
|
|
653
|
+
{
|
|
654
|
+
adView = new AdView( context );
|
|
655
|
+
adView.setAdUnitId( placementId );
|
|
656
|
+
adView.setAdListener( new AdViewListener( placementId, adFormat, listener ) );
|
|
657
|
+
|
|
658
|
+
// Check if adaptive banner sizes should be used
|
|
659
|
+
boolean isAdaptiveBanner = parameters.getServerParameters().getBoolean( "adaptive_banner", false );
|
|
660
|
+
|
|
661
|
+
adView.setAdSize( toAdSize( adFormat, isAdaptiveBanner, parameters, context ) );
|
|
662
|
+
|
|
663
|
+
adView.loadAd( adRequest );
|
|
664
|
+
}
|
|
665
|
+
}
|
|
666
|
+
|
|
667
|
+
//endregion
|
|
668
|
+
|
|
669
|
+
//region MaxNativeAdAdapter Methods
|
|
670
|
+
|
|
671
|
+
@Override
|
|
672
|
+
@SuppressLint("MissingPermission")
|
|
673
|
+
public void loadNativeAd(final MaxAdapterResponseParameters parameters, final Activity activity, final MaxNativeAdAdapterListener listener)
|
|
674
|
+
{
|
|
675
|
+
String placementId = parameters.getThirdPartyAdPlacementId();
|
|
676
|
+
boolean isBiddingAd = AppLovinSdkUtils.isValidString( parameters.getBidResponse() );
|
|
677
|
+
log( "Loading " + ( isBiddingAd ? "bidding " : "" ) + " native ad for placement id: " + placementId + "..." );
|
|
678
|
+
|
|
679
|
+
setRequestConfiguration( parameters );
|
|
680
|
+
|
|
681
|
+
// NOTE: `activity` can only be null in 11.1.0+, and `getApplicationContext()` is introduced in 11.1.0
|
|
682
|
+
Context applicationContext = ( activity != null ) ? activity.getApplicationContext() : getApplicationContext();
|
|
683
|
+
AdRequest adRequest = createAdRequestWithParameters( isBiddingAd, MaxAdFormat.NATIVE, parameters, applicationContext );
|
|
684
|
+
|
|
685
|
+
NativeAdOptions.Builder nativeAdOptionsBuilder = new NativeAdOptions.Builder();
|
|
686
|
+
nativeAdOptionsBuilder.setAdChoicesPlacement( getAdChoicesPlacement( parameters ) );
|
|
687
|
+
|
|
688
|
+
// Medium templates can handle multiple images via AdMob's media view
|
|
689
|
+
String template = BundleUtils.getString( "template", "", parameters.getServerParameters() );
|
|
690
|
+
nativeAdOptionsBuilder.setRequestMultipleImages( template.contains( "medium" ) );
|
|
691
|
+
|
|
692
|
+
NativeAdListener nativeAdListener = new NativeAdListener( parameters, applicationContext, listener );
|
|
693
|
+
AdLoader adLoader = new AdLoader.Builder( applicationContext, placementId )
|
|
694
|
+
.withNativeAdOptions( nativeAdOptionsBuilder.build() )
|
|
695
|
+
.forNativeAd( nativeAdListener )
|
|
696
|
+
.withAdListener( nativeAdListener )
|
|
697
|
+
.build();
|
|
698
|
+
|
|
699
|
+
adLoader.loadAd( adRequest );
|
|
700
|
+
}
|
|
701
|
+
|
|
702
|
+
//endregion
|
|
703
|
+
|
|
704
|
+
//region Helper Methods
|
|
705
|
+
|
|
706
|
+
private static MaxAdapterError toMaxError(final AdError googleAdsError)
|
|
707
|
+
{
|
|
708
|
+
int googleErrorCode = googleAdsError.getCode();
|
|
709
|
+
MaxAdapterError adapterError = MaxAdapterError.UNSPECIFIED;
|
|
710
|
+
switch ( googleErrorCode )
|
|
711
|
+
{
|
|
712
|
+
case AdRequest.ERROR_CODE_NO_FILL:
|
|
713
|
+
case AdRequest.ERROR_CODE_MEDIATION_NO_FILL:
|
|
714
|
+
adapterError = MaxAdapterError.NO_FILL;
|
|
715
|
+
break;
|
|
716
|
+
case AdRequest.ERROR_CODE_NETWORK_ERROR:
|
|
717
|
+
adapterError = MaxAdapterError.NO_CONNECTION;
|
|
718
|
+
break;
|
|
719
|
+
case AdRequest.ERROR_CODE_INTERNAL_ERROR:
|
|
720
|
+
adapterError = MaxAdapterError.INTERNAL_ERROR;
|
|
721
|
+
break;
|
|
722
|
+
case AdRequest.ERROR_CODE_INVALID_REQUEST:
|
|
723
|
+
case AdRequest.ERROR_CODE_REQUEST_ID_MISMATCH:
|
|
724
|
+
adapterError = MaxAdapterError.BAD_REQUEST;
|
|
725
|
+
break;
|
|
726
|
+
case AdRequest.ERROR_CODE_APP_ID_MISSING:
|
|
727
|
+
case AdRequest.ERROR_CODE_INVALID_AD_STRING:
|
|
728
|
+
adapterError = MaxAdapterError.INVALID_CONFIGURATION;
|
|
729
|
+
break;
|
|
730
|
+
}
|
|
731
|
+
|
|
732
|
+
return new MaxAdapterError( adapterError.getErrorCode(),
|
|
733
|
+
adapterError.getErrorMessage(),
|
|
734
|
+
googleErrorCode,
|
|
735
|
+
googleAdsError.getMessage() );
|
|
736
|
+
}
|
|
737
|
+
|
|
738
|
+
private AdSize toAdSize(final MaxAdFormat adFormat,
|
|
739
|
+
final boolean isAdaptiveBanner,
|
|
740
|
+
final MaxAdapterParameters parameters,
|
|
741
|
+
final Context context)
|
|
742
|
+
{
|
|
743
|
+
if ( adFormat == MaxAdFormat.BANNER || adFormat == MaxAdFormat.LEADER )
|
|
744
|
+
{
|
|
745
|
+
if ( isAdaptiveBanner )
|
|
746
|
+
{
|
|
747
|
+
return AdSize.getCurrentOrientationAnchoredAdaptiveBannerAdSize( context, getAdaptiveBannerWidth( parameters, context ) );
|
|
748
|
+
}
|
|
749
|
+
else
|
|
750
|
+
{
|
|
751
|
+
return adFormat == MaxAdFormat.BANNER ? AdSize.BANNER : AdSize.LEADERBOARD;
|
|
752
|
+
}
|
|
753
|
+
}
|
|
754
|
+
else if ( adFormat == MaxAdFormat.MREC )
|
|
755
|
+
{
|
|
756
|
+
return AdSize.MEDIUM_RECTANGLE;
|
|
757
|
+
}
|
|
758
|
+
else
|
|
759
|
+
{
|
|
760
|
+
throw new IllegalArgumentException( "Unsupported ad format: " + adFormat );
|
|
761
|
+
}
|
|
762
|
+
}
|
|
763
|
+
|
|
764
|
+
private int getAdaptiveBannerWidth(final MaxAdapterParameters parameters, final Context context)
|
|
765
|
+
{
|
|
766
|
+
if ( AppLovinSdk.VERSION_CODE >= 11_00_00_00 )
|
|
767
|
+
{
|
|
768
|
+
final Map<String, Object> localExtraParameters = parameters.getLocalExtraParameters();
|
|
769
|
+
Object widthObj = localExtraParameters.get( "adaptive_banner_width" );
|
|
770
|
+
if ( widthObj instanceof Integer )
|
|
771
|
+
{
|
|
772
|
+
return (int) widthObj;
|
|
773
|
+
}
|
|
774
|
+
else if ( widthObj != null )
|
|
775
|
+
{
|
|
776
|
+
e( "Expected parameter \"adaptive_banner_width\" to be of type Integer, received: " + widthObj.getClass() );
|
|
777
|
+
}
|
|
778
|
+
}
|
|
779
|
+
|
|
780
|
+
int deviceWidthPx = getApplicationWindowWidth( context );
|
|
781
|
+
return AppLovinSdkUtils.pxToDp( context, deviceWidthPx );
|
|
782
|
+
}
|
|
783
|
+
|
|
784
|
+
public static int getApplicationWindowWidth(final Context context)
|
|
785
|
+
{
|
|
786
|
+
WindowManager windowManager = (WindowManager) context.getSystemService( Context.WINDOW_SERVICE );
|
|
787
|
+
if ( Build.VERSION.SDK_INT >= Build.VERSION_CODES.R )
|
|
788
|
+
{
|
|
789
|
+
WindowMetrics windowMetrics = windowManager.getCurrentWindowMetrics();
|
|
790
|
+
Rect applicationBounds = windowMetrics.getBounds();
|
|
791
|
+
return applicationBounds.width();
|
|
792
|
+
}
|
|
793
|
+
else
|
|
794
|
+
{
|
|
795
|
+
Display display = windowManager.getDefaultDisplay();
|
|
796
|
+
DisplayMetrics outMetrics = new DisplayMetrics();
|
|
797
|
+
display.getMetrics( outMetrics );
|
|
798
|
+
return outMetrics.widthPixels;
|
|
799
|
+
}
|
|
800
|
+
}
|
|
801
|
+
|
|
802
|
+
private AdFormat toAdFormat(final MaxAdapterSignalCollectionParameters parameters)
|
|
803
|
+
{
|
|
804
|
+
MaxAdFormat adFormat = parameters.getAdFormat();
|
|
805
|
+
boolean isNative = parameters.getServerParameters().getBoolean( "is_native" ) || adFormat == MaxAdFormat.NATIVE;
|
|
806
|
+
if ( isNative )
|
|
807
|
+
{
|
|
808
|
+
return AdFormat.NATIVE;
|
|
809
|
+
}
|
|
810
|
+
else if ( adFormat.isAdViewAd() )
|
|
811
|
+
{
|
|
812
|
+
return AdFormat.BANNER;
|
|
813
|
+
}
|
|
814
|
+
else if ( adFormat == MaxAdFormat.INTERSTITIAL )
|
|
815
|
+
{
|
|
816
|
+
return AdFormat.INTERSTITIAL;
|
|
817
|
+
}
|
|
818
|
+
else if ( adFormat == MaxAdFormat.REWARDED )
|
|
819
|
+
{
|
|
820
|
+
return AdFormat.REWARDED;
|
|
821
|
+
}
|
|
822
|
+
else if ( adFormat == MaxAdFormat.REWARDED_INTERSTITIAL )
|
|
823
|
+
{
|
|
824
|
+
return AdFormat.REWARDED_INTERSTITIAL;
|
|
825
|
+
}
|
|
826
|
+
// NOTE: App open ads were added in AppLovin v11.5.0 and must be checked after all the other ad formats to avoid throwing an exception
|
|
827
|
+
else if ( adFormat == MaxAdFormat.APP_OPEN )
|
|
828
|
+
{
|
|
829
|
+
return AdFormat.APP_OPEN_AD;
|
|
830
|
+
}
|
|
831
|
+
else
|
|
832
|
+
{
|
|
833
|
+
return AdFormat.UNKNOWN;
|
|
834
|
+
}
|
|
835
|
+
}
|
|
836
|
+
|
|
837
|
+
private void setRequestConfiguration(final MaxAdapterParameters parameters)
|
|
838
|
+
{
|
|
839
|
+
RequestConfiguration.Builder requestConfigurationBuilder = MobileAds.getRequestConfiguration().toBuilder();
|
|
840
|
+
|
|
841
|
+
Boolean isAgeRestrictedUser = parameters.isAgeRestrictedUser();
|
|
842
|
+
if ( isAgeRestrictedUser != null )
|
|
843
|
+
{
|
|
844
|
+
int ageRestrictedUserTag = isAgeRestrictedUser ? RequestConfiguration.TAG_FOR_CHILD_DIRECTED_TREATMENT_TRUE : RequestConfiguration.TAG_FOR_CHILD_DIRECTED_TREATMENT_FALSE;
|
|
845
|
+
requestConfigurationBuilder.setTagForChildDirectedTreatment( ageRestrictedUserTag );
|
|
846
|
+
}
|
|
847
|
+
|
|
848
|
+
MobileAds.setRequestConfiguration( requestConfigurationBuilder.build() );
|
|
849
|
+
}
|
|
850
|
+
|
|
851
|
+
@SuppressLint("ApplySharedPref")
|
|
852
|
+
private AdRequest createAdRequestWithParameters(final boolean isBiddingAd, final MaxAdFormat adFormat, final MaxAdapterParameters parameters, final Context context)
|
|
853
|
+
{
|
|
854
|
+
AdRequest.Builder requestBuilder = new AdRequest.Builder();
|
|
855
|
+
Bundle serverParameters = parameters.getServerParameters();
|
|
856
|
+
Bundle networkExtras = new Bundle( 6 );
|
|
857
|
+
boolean isDv360Bidding = false;
|
|
858
|
+
|
|
859
|
+
if ( isBiddingAd )
|
|
860
|
+
{
|
|
861
|
+
String bidderType = BundleUtils.getString( "bidder", "", serverParameters );
|
|
862
|
+
if ( "dv360".equalsIgnoreCase( bidderType ) )
|
|
863
|
+
{
|
|
864
|
+
isDv360Bidding = true;
|
|
865
|
+
}
|
|
866
|
+
|
|
867
|
+
// Requested by Google for signal collection
|
|
868
|
+
networkExtras.putString( "query_info_type", isDv360Bidding ? "requester_type_3" : "requester_type_2" );
|
|
869
|
+
|
|
870
|
+
if ( AppLovinSdk.VERSION_CODE >= 11_00_00_00 && adFormat.isAdViewAd() )
|
|
871
|
+
{
|
|
872
|
+
Object isAdaptiveBannerObj = parameters.getLocalExtraParameters().get( "adaptive_banner" );
|
|
873
|
+
if ( isAdaptiveBannerObj instanceof String && "true".equalsIgnoreCase( (String) isAdaptiveBannerObj ) )
|
|
874
|
+
{
|
|
875
|
+
AdSize adaptiveAdSize = toAdSize( adFormat, true, parameters, context );
|
|
876
|
+
networkExtras.putInt( "adaptive_banner_w", adaptiveAdSize.getWidth() );
|
|
877
|
+
networkExtras.putInt( "adaptive_banner_h", adaptiveAdSize.getHeight() );
|
|
878
|
+
}
|
|
879
|
+
}
|
|
880
|
+
|
|
881
|
+
if ( parameters instanceof MaxAdapterResponseParameters )
|
|
882
|
+
{
|
|
883
|
+
String bidResponse = ( (MaxAdapterResponseParameters) parameters ).getBidResponse();
|
|
884
|
+
if ( AppLovinSdkUtils.isValidString( bidResponse ) )
|
|
885
|
+
{
|
|
886
|
+
requestBuilder.setAdString( bidResponse );
|
|
887
|
+
}
|
|
888
|
+
}
|
|
889
|
+
}
|
|
890
|
+
|
|
891
|
+
if ( serverParameters.getBoolean( "set_mediation_identifier", true ) )
|
|
892
|
+
{
|
|
893
|
+
// Use "applovin" instead of mediationTag for Google's specs
|
|
894
|
+
// "applovin_dv360" is for DV360_BIDDING, which is a separate bidder from regular ADMOB_BIDDING
|
|
895
|
+
requestBuilder.setRequestAgent( isDv360Bidding ? "applovin_dv360" : "applovin" );
|
|
896
|
+
}
|
|
897
|
+
|
|
898
|
+
// Use event id as AdMob's placement request id
|
|
899
|
+
String eventId = BundleUtils.getString( "event_id", serverParameters );
|
|
900
|
+
if ( AppLovinSdkUtils.isValidString( eventId ) )
|
|
901
|
+
{
|
|
902
|
+
networkExtras.putString( "placement_req_id", eventId );
|
|
903
|
+
}
|
|
904
|
+
|
|
905
|
+
Boolean hasUserConsent = parameters.hasUserConsent();
|
|
906
|
+
if ( hasUserConsent != null && !hasUserConsent )
|
|
907
|
+
{
|
|
908
|
+
networkExtras.putString( "npa", "1" ); // Non-personalized ads
|
|
909
|
+
}
|
|
910
|
+
|
|
911
|
+
Boolean isDoNotSell = parameters.isDoNotSell();
|
|
912
|
+
if ( isDoNotSell != null && isDoNotSell )
|
|
913
|
+
{
|
|
914
|
+
networkExtras.putInt( "rdp", 1 ); // Restrict data processing - https://developers.google.com/admob/android/ccpa
|
|
915
|
+
|
|
916
|
+
PreferenceManager.getDefaultSharedPreferences( context )
|
|
917
|
+
.edit()
|
|
918
|
+
.putInt( "gad_rdp", 1 )
|
|
919
|
+
.commit();
|
|
920
|
+
}
|
|
921
|
+
else
|
|
922
|
+
{
|
|
923
|
+
PreferenceManager.getDefaultSharedPreferences( context )
|
|
924
|
+
.edit()
|
|
925
|
+
.remove( "gad_rdp" )
|
|
926
|
+
.commit();
|
|
927
|
+
}
|
|
928
|
+
|
|
929
|
+
if ( AppLovinSdk.VERSION_CODE >= 11_00_00_00 )
|
|
930
|
+
{
|
|
931
|
+
Map<String, Object> localExtraParameters = parameters.getLocalExtraParameters();
|
|
932
|
+
|
|
933
|
+
Object maxContentRating = localExtraParameters.get( "google_max_ad_content_rating" );
|
|
934
|
+
if ( maxContentRating instanceof String )
|
|
935
|
+
{
|
|
936
|
+
networkExtras.putString( "max_ad_content_rating", (String) maxContentRating );
|
|
937
|
+
}
|
|
938
|
+
|
|
939
|
+
Object contentUrlString = localExtraParameters.get( "google_content_url" );
|
|
940
|
+
if ( contentUrlString instanceof String )
|
|
941
|
+
{
|
|
942
|
+
requestBuilder.setContentUrl( (String) contentUrlString );
|
|
943
|
+
}
|
|
944
|
+
|
|
945
|
+
Object neighbouringContentUrlStringsObject = localExtraParameters.get( "google_neighbouring_content_url_strings" );
|
|
946
|
+
if ( neighbouringContentUrlStringsObject instanceof List )
|
|
947
|
+
{
|
|
948
|
+
// try-catching unsafe cast to List<String> in case an incorrect list type is set.
|
|
949
|
+
try
|
|
950
|
+
{
|
|
951
|
+
requestBuilder.setNeighboringContentUrls( (List<String>) neighbouringContentUrlStringsObject );
|
|
952
|
+
}
|
|
953
|
+
catch ( Throwable th )
|
|
954
|
+
{
|
|
955
|
+
e( "Neighbouring content URL strings extra param needs to be of type List<String>.", th );
|
|
956
|
+
}
|
|
957
|
+
}
|
|
958
|
+
}
|
|
959
|
+
|
|
960
|
+
requestBuilder.addNetworkExtrasBundle( AdMobAdapter.class, networkExtras );
|
|
961
|
+
|
|
962
|
+
return requestBuilder.build();
|
|
963
|
+
}
|
|
964
|
+
|
|
965
|
+
/**
|
|
966
|
+
* Update the global mute state for AdMob - must be done _before_ ad load to restrict inventory which requires playing with volume.
|
|
967
|
+
*/
|
|
968
|
+
private static void updateMuteState(final MaxAdapterResponseParameters parameters)
|
|
969
|
+
{
|
|
970
|
+
Bundle serverParameters = parameters.getServerParameters();
|
|
971
|
+
// Overwritten by `mute_state` setting, unless `mute_state` is disabled
|
|
972
|
+
if ( serverParameters.containsKey( "is_muted" ) ) // Introduced in 9.10.0
|
|
973
|
+
{
|
|
974
|
+
MobileAds.setAppMuted( serverParameters.getBoolean( "is_muted" ) );
|
|
975
|
+
}
|
|
976
|
+
}
|
|
977
|
+
|
|
978
|
+
private int getAdChoicesPlacement(MaxAdapterResponseParameters parameters)
|
|
979
|
+
{
|
|
980
|
+
// Publishers can set via nativeAdLoader.setLocalExtraParameter( "admob_ad_choices_placement", ADCHOICES_BOTTOM_LEFT );
|
|
981
|
+
// Note: This feature requires AppLovin v11.0.0+
|
|
982
|
+
if ( AppLovinSdk.VERSION_CODE >= 11_00_00_00 )
|
|
983
|
+
{
|
|
984
|
+
final Map<String, Object> localExtraParams = parameters.getLocalExtraParameters();
|
|
985
|
+
final Object adChoicesPlacementObj = localExtraParams != null ? localExtraParams.get( "admob_ad_choices_placement" ) : null;
|
|
986
|
+
|
|
987
|
+
return isValidAdChoicesPlacement( adChoicesPlacementObj ) ? (Integer) adChoicesPlacementObj : NativeAdOptions.ADCHOICES_TOP_RIGHT;
|
|
988
|
+
}
|
|
989
|
+
|
|
990
|
+
return NativeAdOptions.ADCHOICES_TOP_RIGHT;
|
|
991
|
+
}
|
|
992
|
+
|
|
993
|
+
private boolean isValidAdChoicesPlacement(Object placementObj)
|
|
994
|
+
{
|
|
995
|
+
return ( placementObj instanceof Integer ) &&
|
|
996
|
+
( (Integer) placementObj == NativeAdOptions.ADCHOICES_TOP_LEFT ||
|
|
997
|
+
(Integer) placementObj == NativeAdOptions.ADCHOICES_TOP_RIGHT ||
|
|
998
|
+
(Integer) placementObj == NativeAdOptions.ADCHOICES_BOTTOM_LEFT ||
|
|
999
|
+
(Integer) placementObj == NativeAdOptions.ADCHOICES_BOTTOM_RIGHT );
|
|
1000
|
+
}
|
|
1001
|
+
|
|
1002
|
+
private Context getContext(@Nullable Activity activity)
|
|
1003
|
+
{
|
|
1004
|
+
// NOTE: `activity` can only be null in 11.1.0+, and `getApplicationContext()` is introduced in 11.1.0
|
|
1005
|
+
return ( activity != null ) ? activity.getApplicationContext() : getApplicationContext();
|
|
1006
|
+
}
|
|
1007
|
+
|
|
1008
|
+
//endregion
|
|
1009
|
+
|
|
1010
|
+
private class InterstitialAdListener
|
|
1011
|
+
extends FullScreenContentCallback
|
|
1012
|
+
{
|
|
1013
|
+
private final String placementId;
|
|
1014
|
+
private final MaxInterstitialAdapterListener listener;
|
|
1015
|
+
|
|
1016
|
+
InterstitialAdListener(final String placementId, final MaxInterstitialAdapterListener listener)
|
|
1017
|
+
{
|
|
1018
|
+
this.placementId = placementId;
|
|
1019
|
+
this.listener = listener;
|
|
1020
|
+
}
|
|
1021
|
+
|
|
1022
|
+
@Override
|
|
1023
|
+
public void onAdShowedFullScreenContent()
|
|
1024
|
+
{
|
|
1025
|
+
log( "Interstitial ad shown: " + placementId );
|
|
1026
|
+
}
|
|
1027
|
+
|
|
1028
|
+
@Override
|
|
1029
|
+
public void onAdFailedToShowFullScreenContent(@NonNull final AdError adError)
|
|
1030
|
+
{
|
|
1031
|
+
MaxAdapterError adapterError = new MaxAdapterError( -4205, "Ad Display Failed", adError.getCode(), adError.getMessage() );
|
|
1032
|
+
log( "Interstitial ad (" + placementId + ") failed to show with error: " + adapterError );
|
|
1033
|
+
listener.onInterstitialAdDisplayFailed( adapterError );
|
|
1034
|
+
}
|
|
1035
|
+
|
|
1036
|
+
@Override
|
|
1037
|
+
public void onAdImpression()
|
|
1038
|
+
{
|
|
1039
|
+
log( "Interstitial ad impression recorded: " + placementId );
|
|
1040
|
+
listener.onInterstitialAdDisplayed();
|
|
1041
|
+
}
|
|
1042
|
+
|
|
1043
|
+
@Override
|
|
1044
|
+
public void onAdClicked()
|
|
1045
|
+
{
|
|
1046
|
+
log( "Interstitial ad clicked: " + placementId );
|
|
1047
|
+
listener.onInterstitialAdClicked();
|
|
1048
|
+
}
|
|
1049
|
+
|
|
1050
|
+
@Override
|
|
1051
|
+
public void onAdDismissedFullScreenContent()
|
|
1052
|
+
{
|
|
1053
|
+
log( "Interstitial ad hidden: " + placementId );
|
|
1054
|
+
listener.onInterstitialAdHidden();
|
|
1055
|
+
}
|
|
1056
|
+
}
|
|
1057
|
+
|
|
1058
|
+
private class AppOpenAdListener
|
|
1059
|
+
extends FullScreenContentCallback
|
|
1060
|
+
{
|
|
1061
|
+
private final String placementId;
|
|
1062
|
+
private final MaxAppOpenAdapterListener listener;
|
|
1063
|
+
|
|
1064
|
+
AppOpenAdListener(final String placementId, final MaxAppOpenAdapterListener listener)
|
|
1065
|
+
{
|
|
1066
|
+
this.placementId = placementId;
|
|
1067
|
+
this.listener = listener;
|
|
1068
|
+
}
|
|
1069
|
+
|
|
1070
|
+
@Override
|
|
1071
|
+
public void onAdShowedFullScreenContent()
|
|
1072
|
+
{
|
|
1073
|
+
log( "App open ad shown: " + placementId );
|
|
1074
|
+
}
|
|
1075
|
+
|
|
1076
|
+
@Override
|
|
1077
|
+
public void onAdFailedToShowFullScreenContent(@NonNull final AdError adError)
|
|
1078
|
+
{
|
|
1079
|
+
MaxAdapterError adapterError = new MaxAdapterError( -4205, "Ad display failed", adError.getCode(), adError.getMessage() );
|
|
1080
|
+
log( "App open ad (" + placementId + ") failed to show with error: " + adapterError );
|
|
1081
|
+
listener.onAppOpenAdDisplayFailed( adapterError );
|
|
1082
|
+
}
|
|
1083
|
+
|
|
1084
|
+
@Override
|
|
1085
|
+
public void onAdImpression()
|
|
1086
|
+
{
|
|
1087
|
+
log( "App open ad impression recorded: " + placementId );
|
|
1088
|
+
listener.onAppOpenAdDisplayed();
|
|
1089
|
+
}
|
|
1090
|
+
|
|
1091
|
+
@Override
|
|
1092
|
+
public void onAdClicked()
|
|
1093
|
+
{
|
|
1094
|
+
log( "App open ad clicked: " + placementId );
|
|
1095
|
+
listener.onAppOpenAdClicked();
|
|
1096
|
+
}
|
|
1097
|
+
|
|
1098
|
+
@Override
|
|
1099
|
+
public void onAdDismissedFullScreenContent()
|
|
1100
|
+
{
|
|
1101
|
+
log( "App open ad hidden: " + placementId );
|
|
1102
|
+
listener.onAppOpenAdHidden();
|
|
1103
|
+
}
|
|
1104
|
+
}
|
|
1105
|
+
|
|
1106
|
+
private class RewardedInterstitialAdListener
|
|
1107
|
+
extends FullScreenContentCallback
|
|
1108
|
+
{
|
|
1109
|
+
private final String placementId;
|
|
1110
|
+
private final MaxRewardedInterstitialAdapterListener listener;
|
|
1111
|
+
|
|
1112
|
+
private boolean hasGrantedReward;
|
|
1113
|
+
|
|
1114
|
+
private RewardedInterstitialAdListener(final String placementId, final MaxRewardedInterstitialAdapterListener listener)
|
|
1115
|
+
{
|
|
1116
|
+
this.placementId = placementId;
|
|
1117
|
+
this.listener = listener;
|
|
1118
|
+
}
|
|
1119
|
+
|
|
1120
|
+
@Override
|
|
1121
|
+
public void onAdShowedFullScreenContent()
|
|
1122
|
+
{
|
|
1123
|
+
log( "Rewarded interstitial ad shown: " + placementId );
|
|
1124
|
+
listener.onRewardedInterstitialAdVideoStarted();
|
|
1125
|
+
}
|
|
1126
|
+
|
|
1127
|
+
@Override
|
|
1128
|
+
public void onAdFailedToShowFullScreenContent(@NonNull final AdError adError)
|
|
1129
|
+
{
|
|
1130
|
+
MaxAdapterError adapterError = new MaxAdapterError( -4205, "Ad Display Failed", adError.getCode(), adError.getMessage() );
|
|
1131
|
+
log( "Rewarded interstitial ad (" + placementId + ") failed to show with error: " + adapterError );
|
|
1132
|
+
listener.onRewardedInterstitialAdDisplayFailed( adapterError );
|
|
1133
|
+
}
|
|
1134
|
+
|
|
1135
|
+
@Override
|
|
1136
|
+
public void onAdImpression()
|
|
1137
|
+
{
|
|
1138
|
+
log( "Rewarded interstitial ad impression recorded: " + placementId );
|
|
1139
|
+
listener.onRewardedInterstitialAdDisplayed();
|
|
1140
|
+
}
|
|
1141
|
+
|
|
1142
|
+
@Override
|
|
1143
|
+
public void onAdClicked()
|
|
1144
|
+
{
|
|
1145
|
+
log( "Rewarded interstitial ad clicked: " + placementId );
|
|
1146
|
+
listener.onRewardedInterstitialAdClicked();
|
|
1147
|
+
}
|
|
1148
|
+
|
|
1149
|
+
@Override
|
|
1150
|
+
public void onAdDismissedFullScreenContent()
|
|
1151
|
+
{
|
|
1152
|
+
listener.onRewardedInterstitialAdVideoCompleted();
|
|
1153
|
+
|
|
1154
|
+
if ( hasGrantedReward || shouldAlwaysRewardUser() )
|
|
1155
|
+
{
|
|
1156
|
+
MaxReward reward = getReward();
|
|
1157
|
+
log( "Rewarded interstitial ad rewarded user with reward: " + reward );
|
|
1158
|
+
listener.onUserRewarded( reward );
|
|
1159
|
+
}
|
|
1160
|
+
|
|
1161
|
+
log( "Rewarded interstitial ad hidden: " + placementId );
|
|
1162
|
+
listener.onRewardedInterstitialAdHidden();
|
|
1163
|
+
}
|
|
1164
|
+
}
|
|
1165
|
+
|
|
1166
|
+
private class RewardedAdListener
|
|
1167
|
+
extends FullScreenContentCallback
|
|
1168
|
+
{
|
|
1169
|
+
private final String placementId;
|
|
1170
|
+
private final MaxRewardedAdapterListener listener;
|
|
1171
|
+
|
|
1172
|
+
private boolean hasGrantedReward;
|
|
1173
|
+
|
|
1174
|
+
RewardedAdListener(final String placementId, final MaxRewardedAdapterListener listener)
|
|
1175
|
+
{
|
|
1176
|
+
this.placementId = placementId;
|
|
1177
|
+
this.listener = listener;
|
|
1178
|
+
}
|
|
1179
|
+
|
|
1180
|
+
@Override
|
|
1181
|
+
public void onAdShowedFullScreenContent()
|
|
1182
|
+
{
|
|
1183
|
+
log( "Rewarded ad shown: " + placementId );
|
|
1184
|
+
listener.onRewardedAdVideoStarted();
|
|
1185
|
+
}
|
|
1186
|
+
|
|
1187
|
+
@Override
|
|
1188
|
+
public void onAdFailedToShowFullScreenContent(@NonNull final AdError adError)
|
|
1189
|
+
{
|
|
1190
|
+
MaxAdapterError adapterError = new MaxAdapterError( -4205, "Ad Display Failed", adError.getCode(), adError.getMessage() );
|
|
1191
|
+
log( "Rewarded ad (" + placementId + ") failed to show with error: " + adapterError );
|
|
1192
|
+
listener.onRewardedAdDisplayFailed( adapterError );
|
|
1193
|
+
}
|
|
1194
|
+
|
|
1195
|
+
@Override
|
|
1196
|
+
public void onAdImpression()
|
|
1197
|
+
{
|
|
1198
|
+
log( "Rewarded ad impression recorded: " + placementId );
|
|
1199
|
+
listener.onRewardedAdDisplayed();
|
|
1200
|
+
}
|
|
1201
|
+
|
|
1202
|
+
@Override
|
|
1203
|
+
public void onAdClicked()
|
|
1204
|
+
{
|
|
1205
|
+
log( "Rewarded ad clicked: " + placementId );
|
|
1206
|
+
listener.onRewardedAdClicked();
|
|
1207
|
+
}
|
|
1208
|
+
|
|
1209
|
+
@Override
|
|
1210
|
+
public void onAdDismissedFullScreenContent()
|
|
1211
|
+
{
|
|
1212
|
+
listener.onRewardedAdVideoCompleted();
|
|
1213
|
+
|
|
1214
|
+
if ( hasGrantedReward || shouldAlwaysRewardUser() )
|
|
1215
|
+
{
|
|
1216
|
+
MaxReward reward = getReward();
|
|
1217
|
+
log( "Rewarded user with reward: " + reward );
|
|
1218
|
+
listener.onUserRewarded( reward );
|
|
1219
|
+
}
|
|
1220
|
+
|
|
1221
|
+
log( "Rewarded ad hidden: " + placementId );
|
|
1222
|
+
listener.onRewardedAdHidden();
|
|
1223
|
+
}
|
|
1224
|
+
}
|
|
1225
|
+
|
|
1226
|
+
private class AdViewListener
|
|
1227
|
+
extends AdListener
|
|
1228
|
+
{
|
|
1229
|
+
final String placementId;
|
|
1230
|
+
final MaxAdFormat adFormat;
|
|
1231
|
+
final MaxAdViewAdapterListener listener;
|
|
1232
|
+
|
|
1233
|
+
AdViewListener(final String placementId, final MaxAdFormat adFormat, final MaxAdViewAdapterListener listener)
|
|
1234
|
+
{
|
|
1235
|
+
this.placementId = placementId;
|
|
1236
|
+
this.adFormat = adFormat;
|
|
1237
|
+
this.listener = listener;
|
|
1238
|
+
}
|
|
1239
|
+
|
|
1240
|
+
@Override
|
|
1241
|
+
public void onAdLoaded()
|
|
1242
|
+
{
|
|
1243
|
+
log( adFormat.getLabel() + " ad loaded: " + placementId );
|
|
1244
|
+
|
|
1245
|
+
if ( AppLovinSdk.VERSION_CODE >= 9150000 )
|
|
1246
|
+
{
|
|
1247
|
+
Bundle extraInfo = new Bundle( 3 );
|
|
1248
|
+
|
|
1249
|
+
ResponseInfo responseInfo = adView.getResponseInfo();
|
|
1250
|
+
String responseId = ( responseInfo != null ) ? responseInfo.getResponseId() : null;
|
|
1251
|
+
if ( AppLovinSdkUtils.isValidString( responseId ) )
|
|
1252
|
+
{
|
|
1253
|
+
extraInfo.putString( "creative_id", responseId );
|
|
1254
|
+
}
|
|
1255
|
+
|
|
1256
|
+
AdSize adSize = adView.getAdSize();
|
|
1257
|
+
if ( adSize != null )
|
|
1258
|
+
{
|
|
1259
|
+
extraInfo.putInt( "ad_width", adSize.getWidth() );
|
|
1260
|
+
extraInfo.putInt( "ad_height", adSize.getHeight() );
|
|
1261
|
+
}
|
|
1262
|
+
|
|
1263
|
+
listener.onAdViewAdLoaded( adView, extraInfo );
|
|
1264
|
+
}
|
|
1265
|
+
else
|
|
1266
|
+
{
|
|
1267
|
+
listener.onAdViewAdLoaded( adView );
|
|
1268
|
+
}
|
|
1269
|
+
}
|
|
1270
|
+
|
|
1271
|
+
@Override
|
|
1272
|
+
public void onAdFailedToLoad(@NonNull final LoadAdError loadAdError)
|
|
1273
|
+
{
|
|
1274
|
+
MaxAdapterError adapterError = toMaxError( loadAdError );
|
|
1275
|
+
log( adFormat.getLabel() + " ad (" + placementId + ") failed to load with error code: " + adapterError );
|
|
1276
|
+
listener.onAdViewAdLoadFailed( adapterError );
|
|
1277
|
+
}
|
|
1278
|
+
|
|
1279
|
+
@Override
|
|
1280
|
+
public void onAdImpression()
|
|
1281
|
+
{
|
|
1282
|
+
log( adFormat.getLabel() + " ad shown: " + placementId );
|
|
1283
|
+
listener.onAdViewAdDisplayed();
|
|
1284
|
+
}
|
|
1285
|
+
|
|
1286
|
+
@Override
|
|
1287
|
+
public void onAdOpened()
|
|
1288
|
+
{
|
|
1289
|
+
// Do not track ad view ad opened events (besides clicks) on Android, but do so on iOS
|
|
1290
|
+
log( adFormat.getLabel() + " ad opened" );
|
|
1291
|
+
listener.onAdViewAdClicked();
|
|
1292
|
+
}
|
|
1293
|
+
|
|
1294
|
+
@Override
|
|
1295
|
+
public void onAdClosed()
|
|
1296
|
+
{
|
|
1297
|
+
// NOTE: Do not track ad view ad closed events on Android, but do so on iOS
|
|
1298
|
+
log( adFormat.getLabel() + " ad closed" );
|
|
1299
|
+
}
|
|
1300
|
+
}
|
|
1301
|
+
|
|
1302
|
+
private class NativeAdViewListener
|
|
1303
|
+
extends AdListener
|
|
1304
|
+
implements OnNativeAdLoadedListener
|
|
1305
|
+
{
|
|
1306
|
+
final String placementId;
|
|
1307
|
+
final MaxAdFormat adFormat;
|
|
1308
|
+
final Bundle serverParameters;
|
|
1309
|
+
final WeakReference<Activity> activityRef;
|
|
1310
|
+
final MaxAdViewAdapterListener listener;
|
|
1311
|
+
|
|
1312
|
+
NativeAdViewListener(final MaxAdapterResponseParameters parameters, final MaxAdFormat adFormat, final Activity activity, final MaxAdViewAdapterListener listener)
|
|
1313
|
+
{
|
|
1314
|
+
placementId = parameters.getThirdPartyAdPlacementId();
|
|
1315
|
+
serverParameters = parameters.getServerParameters();
|
|
1316
|
+
activityRef = new WeakReference<>( activity );
|
|
1317
|
+
|
|
1318
|
+
this.adFormat = adFormat;
|
|
1319
|
+
this.listener = listener;
|
|
1320
|
+
}
|
|
1321
|
+
|
|
1322
|
+
@Override
|
|
1323
|
+
public void onNativeAdLoaded(@NonNull final NativeAd nativeAd)
|
|
1324
|
+
{
|
|
1325
|
+
log( "Native " + adFormat.getLabel() + " ad loaded: " + placementId );
|
|
1326
|
+
|
|
1327
|
+
if ( TextUtils.isEmpty( nativeAd.getHeadline() ) )
|
|
1328
|
+
{
|
|
1329
|
+
log( "Native " + adFormat.getLabel() + " ad failed to load: Google native ad is missing one or more required assets" );
|
|
1330
|
+
listener.onAdViewAdLoadFailed( MaxAdapterError.INVALID_CONFIGURATION );
|
|
1331
|
+
|
|
1332
|
+
nativeAd.destroy();
|
|
1333
|
+
|
|
1334
|
+
return;
|
|
1335
|
+
}
|
|
1336
|
+
|
|
1337
|
+
GoogleMediationAdapter.this.nativeAd = nativeAd;
|
|
1338
|
+
|
|
1339
|
+
final Activity activity = activityRef.get();
|
|
1340
|
+
final Context context = getContext( activity );
|
|
1341
|
+
|
|
1342
|
+
final MediaView mediaView = new MediaView( context );
|
|
1343
|
+
MediaContent mediaContent = nativeAd.getMediaContent();
|
|
1344
|
+
if ( mediaContent != null )
|
|
1345
|
+
{
|
|
1346
|
+
mediaView.setMediaContent( mediaContent );
|
|
1347
|
+
}
|
|
1348
|
+
|
|
1349
|
+
final NativeAd.Image icon = nativeAd.getIcon();
|
|
1350
|
+
MaxNativeAd.MaxNativeAdImage maxNativeAdImage = null;
|
|
1351
|
+
if ( icon != null )
|
|
1352
|
+
{
|
|
1353
|
+
if ( icon.getDrawable() != null )
|
|
1354
|
+
{
|
|
1355
|
+
maxNativeAdImage = new MaxNativeAd.MaxNativeAdImage( icon.getDrawable() );
|
|
1356
|
+
}
|
|
1357
|
+
else
|
|
1358
|
+
{
|
|
1359
|
+
maxNativeAdImage = new MaxNativeAd.MaxNativeAdImage( icon.getUri() );
|
|
1360
|
+
}
|
|
1361
|
+
}
|
|
1362
|
+
|
|
1363
|
+
final MaxNativeAd maxNativeAd = new MaxNativeAd.Builder()
|
|
1364
|
+
.setAdFormat( adFormat )
|
|
1365
|
+
.setTitle( nativeAd.getHeadline() )
|
|
1366
|
+
.setBody( nativeAd.getBody() )
|
|
1367
|
+
.setCallToAction( nativeAd.getCallToAction() )
|
|
1368
|
+
.setIcon( maxNativeAdImage )
|
|
1369
|
+
.setMediaView( mediaView )
|
|
1370
|
+
.build();
|
|
1371
|
+
|
|
1372
|
+
final String templateName = BundleUtils.getString( "template", "", serverParameters );
|
|
1373
|
+
if ( templateName.contains( "vertical" ) && AppLovinSdk.VERSION_CODE < 9140500 )
|
|
1374
|
+
{
|
|
1375
|
+
log( "Vertical native banners are only supported on MAX SDK 9.14.5 and above. Default horizontal native template will be used." );
|
|
1376
|
+
}
|
|
1377
|
+
|
|
1378
|
+
runOnUiThread( new Runnable()
|
|
1379
|
+
{
|
|
1380
|
+
@Override
|
|
1381
|
+
public void run()
|
|
1382
|
+
{
|
|
1383
|
+
MaxNativeAdView maxNativeAdView;
|
|
1384
|
+
if ( AppLovinSdk.VERSION_CODE >= 11010000 )
|
|
1385
|
+
{
|
|
1386
|
+
maxNativeAdView = new MaxNativeAdView( maxNativeAd, templateName, context );
|
|
1387
|
+
}
|
|
1388
|
+
else
|
|
1389
|
+
{
|
|
1390
|
+
maxNativeAdView = new MaxNativeAdView( maxNativeAd, templateName, activity );
|
|
1391
|
+
}
|
|
1392
|
+
|
|
1393
|
+
nativeAdView = new NativeAdView( context );
|
|
1394
|
+
nativeAdView.setIconView( maxNativeAdView.getIconContentView() );
|
|
1395
|
+
nativeAdView.setHeadlineView( maxNativeAdView.getTitleTextView() );
|
|
1396
|
+
nativeAdView.setBodyView( maxNativeAdView.getBodyTextView() );
|
|
1397
|
+
nativeAdView.setMediaView( mediaView );
|
|
1398
|
+
nativeAdView.setCallToActionView( maxNativeAdView.getCallToActionButton() );
|
|
1399
|
+
nativeAdView.setNativeAd( nativeAd );
|
|
1400
|
+
|
|
1401
|
+
nativeAdView.addView( maxNativeAdView );
|
|
1402
|
+
|
|
1403
|
+
ResponseInfo responseInfo = nativeAd.getResponseInfo();
|
|
1404
|
+
String responseId = ( responseInfo != null ) ? responseInfo.getResponseId() : null;
|
|
1405
|
+
if ( AppLovinSdk.VERSION_CODE >= 9150000 && AppLovinSdkUtils.isValidString( responseId ) )
|
|
1406
|
+
{
|
|
1407
|
+
Bundle extraInfo = new Bundle( 1 );
|
|
1408
|
+
extraInfo.putString( "creative_id", responseId );
|
|
1409
|
+
|
|
1410
|
+
listener.onAdViewAdLoaded( nativeAdView, extraInfo );
|
|
1411
|
+
}
|
|
1412
|
+
else
|
|
1413
|
+
{
|
|
1414
|
+
listener.onAdViewAdLoaded( nativeAdView );
|
|
1415
|
+
}
|
|
1416
|
+
}
|
|
1417
|
+
} );
|
|
1418
|
+
}
|
|
1419
|
+
|
|
1420
|
+
@Override
|
|
1421
|
+
public void onAdFailedToLoad(@NonNull final LoadAdError loadAdError)
|
|
1422
|
+
{
|
|
1423
|
+
MaxAdapterError adapterError = toMaxError( loadAdError );
|
|
1424
|
+
log( "Native " + adFormat.getLabel() + " ad (" + placementId + ") failed to load with error: " + adapterError );
|
|
1425
|
+
listener.onAdViewAdLoadFailed( adapterError );
|
|
1426
|
+
}
|
|
1427
|
+
|
|
1428
|
+
@Override
|
|
1429
|
+
public void onAdImpression()
|
|
1430
|
+
{
|
|
1431
|
+
log( "Native " + adFormat.getLabel() + " ad shown" );
|
|
1432
|
+
listener.onAdViewAdDisplayed();
|
|
1433
|
+
}
|
|
1434
|
+
|
|
1435
|
+
@Override
|
|
1436
|
+
public void onAdClicked()
|
|
1437
|
+
{
|
|
1438
|
+
log( "Native " + adFormat.getLabel() + " ad clicked" );
|
|
1439
|
+
listener.onAdViewAdClicked();
|
|
1440
|
+
}
|
|
1441
|
+
|
|
1442
|
+
@Override
|
|
1443
|
+
public void onAdOpened()
|
|
1444
|
+
{
|
|
1445
|
+
log( "Native " + adFormat.getLabel() + " ad opened" );
|
|
1446
|
+
listener.onAdViewAdExpanded();
|
|
1447
|
+
}
|
|
1448
|
+
|
|
1449
|
+
@Override
|
|
1450
|
+
public void onAdClosed()
|
|
1451
|
+
{
|
|
1452
|
+
log( "Native " + adFormat.getLabel() + " ad closed" );
|
|
1453
|
+
listener.onAdViewAdCollapsed();
|
|
1454
|
+
}
|
|
1455
|
+
}
|
|
1456
|
+
|
|
1457
|
+
private class NativeAdListener
|
|
1458
|
+
extends AdListener
|
|
1459
|
+
implements OnNativeAdLoadedListener
|
|
1460
|
+
{
|
|
1461
|
+
final String placementId;
|
|
1462
|
+
final Bundle serverParameters;
|
|
1463
|
+
final Context context;
|
|
1464
|
+
final MaxNativeAdAdapterListener listener;
|
|
1465
|
+
|
|
1466
|
+
public NativeAdListener(final MaxAdapterResponseParameters parameters, final Context context, final MaxNativeAdAdapterListener listener)
|
|
1467
|
+
{
|
|
1468
|
+
placementId = parameters.getThirdPartyAdPlacementId();
|
|
1469
|
+
serverParameters = parameters.getServerParameters();
|
|
1470
|
+
|
|
1471
|
+
this.context = context;
|
|
1472
|
+
this.listener = listener;
|
|
1473
|
+
}
|
|
1474
|
+
|
|
1475
|
+
@Override
|
|
1476
|
+
public void onNativeAdLoaded(@NonNull final NativeAd nativeAd)
|
|
1477
|
+
{
|
|
1478
|
+
log( "Native ad loaded: " + placementId );
|
|
1479
|
+
|
|
1480
|
+
GoogleMediationAdapter.this.nativeAd = nativeAd;
|
|
1481
|
+
|
|
1482
|
+
String templateName = BundleUtils.getString( "template", "", serverParameters );
|
|
1483
|
+
final boolean isTemplateAd = AppLovinSdkUtils.isValidString( templateName );
|
|
1484
|
+
if ( isTemplateAd && TextUtils.isEmpty( nativeAd.getHeadline() ) )
|
|
1485
|
+
{
|
|
1486
|
+
e( "Native ad (" + nativeAd + ") does not have required assets." );
|
|
1487
|
+
listener.onNativeAdLoadFailed( new MaxAdapterError( -5400, "Missing Native Ad Assets" ) );
|
|
1488
|
+
|
|
1489
|
+
return;
|
|
1490
|
+
}
|
|
1491
|
+
|
|
1492
|
+
runOnUiThread( new Runnable()
|
|
1493
|
+
{
|
|
1494
|
+
@Override
|
|
1495
|
+
public void run()
|
|
1496
|
+
{
|
|
1497
|
+
View mediaView = null;
|
|
1498
|
+
MediaContent mediaContent = nativeAd.getMediaContent();
|
|
1499
|
+
List<NativeAd.Image> images = nativeAd.getImages();
|
|
1500
|
+
Drawable mainImage = null;
|
|
1501
|
+
float mediaContentAspectRatio = 0.0f;
|
|
1502
|
+
|
|
1503
|
+
if ( mediaContent != null )
|
|
1504
|
+
{
|
|
1505
|
+
MediaView googleMediaView = new MediaView( context );
|
|
1506
|
+
googleMediaView.setMediaContent( mediaContent );
|
|
1507
|
+
mediaView = googleMediaView;
|
|
1508
|
+
|
|
1509
|
+
mainImage = mediaContent.getMainImage();
|
|
1510
|
+
mediaContentAspectRatio = mediaContent.getAspectRatio();
|
|
1511
|
+
}
|
|
1512
|
+
else if ( images != null && images.size() > 0 )
|
|
1513
|
+
{
|
|
1514
|
+
NativeAd.Image mediaImage = images.get( 0 );
|
|
1515
|
+
ImageView mediaImageView = new ImageView( context );
|
|
1516
|
+
Drawable mediaImageDrawable = mediaImage.getDrawable();
|
|
1517
|
+
|
|
1518
|
+
if ( mediaImageDrawable != null )
|
|
1519
|
+
{
|
|
1520
|
+
mediaImageView.setImageDrawable( mediaImageDrawable );
|
|
1521
|
+
mediaView = mediaImageView;
|
|
1522
|
+
|
|
1523
|
+
mediaContentAspectRatio = (float) mediaImageDrawable.getIntrinsicWidth() / (float) mediaImageDrawable.getIntrinsicHeight();
|
|
1524
|
+
}
|
|
1525
|
+
}
|
|
1526
|
+
|
|
1527
|
+
NativeAd.Image icon = nativeAd.getIcon();
|
|
1528
|
+
MaxNativeAd.MaxNativeAdImage iconImage = null;
|
|
1529
|
+
if ( icon != null )
|
|
1530
|
+
{
|
|
1531
|
+
if ( icon.getDrawable() != null )
|
|
1532
|
+
{
|
|
1533
|
+
iconImage = new MaxNativeAd.MaxNativeAdImage( icon.getDrawable() );
|
|
1534
|
+
}
|
|
1535
|
+
else
|
|
1536
|
+
{
|
|
1537
|
+
iconImage = new MaxNativeAd.MaxNativeAdImage( icon.getUri() );
|
|
1538
|
+
}
|
|
1539
|
+
}
|
|
1540
|
+
|
|
1541
|
+
MaxNativeAd.Builder builder = new MaxNativeAd.Builder()
|
|
1542
|
+
.setAdFormat( MaxAdFormat.NATIVE )
|
|
1543
|
+
.setTitle( nativeAd.getHeadline() )
|
|
1544
|
+
.setAdvertiser( nativeAd.getAdvertiser() )
|
|
1545
|
+
.setBody( nativeAd.getBody() )
|
|
1546
|
+
.setCallToAction( nativeAd.getCallToAction() )
|
|
1547
|
+
.setIcon( iconImage )
|
|
1548
|
+
.setMediaView( mediaView );
|
|
1549
|
+
|
|
1550
|
+
if ( AppLovinSdk.VERSION_CODE >= 11_04_03_99 )
|
|
1551
|
+
{
|
|
1552
|
+
builder.setMainImage( new MaxNativeAd.MaxNativeAdImage( mainImage ) );
|
|
1553
|
+
}
|
|
1554
|
+
|
|
1555
|
+
if ( AppLovinSdk.VERSION_CODE >= 11_04_00_00 )
|
|
1556
|
+
{
|
|
1557
|
+
builder.setMediaContentAspectRatio( mediaContentAspectRatio );
|
|
1558
|
+
}
|
|
1559
|
+
|
|
1560
|
+
if ( AppLovinSdk.VERSION_CODE >= 11_07_00_00 )
|
|
1561
|
+
{
|
|
1562
|
+
builder.setStarRating( nativeAd.getStarRating() );
|
|
1563
|
+
}
|
|
1564
|
+
|
|
1565
|
+
MaxNativeAd maxNativeAd = new MaxGoogleNativeAd( builder );
|
|
1566
|
+
|
|
1567
|
+
ResponseInfo responseInfo = nativeAd.getResponseInfo();
|
|
1568
|
+
String responseId = ( responseInfo != null ) ? responseInfo.getResponseId() : null;
|
|
1569
|
+
Bundle extraInfo = new Bundle( 1 );
|
|
1570
|
+
extraInfo.putString( "creative_id", responseId );
|
|
1571
|
+
|
|
1572
|
+
listener.onNativeAdLoaded( maxNativeAd, extraInfo );
|
|
1573
|
+
}
|
|
1574
|
+
} );
|
|
1575
|
+
}
|
|
1576
|
+
|
|
1577
|
+
@Override
|
|
1578
|
+
public void onAdFailedToLoad(@NonNull final LoadAdError loadAdError)
|
|
1579
|
+
{
|
|
1580
|
+
MaxAdapterError adapterError = toMaxError( loadAdError );
|
|
1581
|
+
log( "Native ad (" + placementId + ") failed to load with error: " + adapterError );
|
|
1582
|
+
listener.onNativeAdLoadFailed( adapterError );
|
|
1583
|
+
}
|
|
1584
|
+
|
|
1585
|
+
@Override
|
|
1586
|
+
public void onAdImpression()
|
|
1587
|
+
{
|
|
1588
|
+
log( "Native ad shown" );
|
|
1589
|
+
listener.onNativeAdDisplayed( null );
|
|
1590
|
+
}
|
|
1591
|
+
|
|
1592
|
+
@Override
|
|
1593
|
+
public void onAdClicked()
|
|
1594
|
+
{
|
|
1595
|
+
log( "Native ad clicked" );
|
|
1596
|
+
listener.onNativeAdClicked();
|
|
1597
|
+
}
|
|
1598
|
+
|
|
1599
|
+
@Override
|
|
1600
|
+
public void onAdOpened()
|
|
1601
|
+
{
|
|
1602
|
+
log( "Native ad opened" );
|
|
1603
|
+
}
|
|
1604
|
+
|
|
1605
|
+
@Override
|
|
1606
|
+
public void onAdClosed()
|
|
1607
|
+
{
|
|
1608
|
+
log( "Native ad closed" );
|
|
1609
|
+
}
|
|
1610
|
+
}
|
|
1611
|
+
|
|
1612
|
+
private class MaxGoogleNativeAd
|
|
1613
|
+
extends MaxNativeAd
|
|
1614
|
+
{
|
|
1615
|
+
public MaxGoogleNativeAd(final Builder builder) { super( builder ); }
|
|
1616
|
+
|
|
1617
|
+
@Override
|
|
1618
|
+
public void prepareViewForInteraction(final MaxNativeAdView maxNativeAdView)
|
|
1619
|
+
{
|
|
1620
|
+
prepareForInteraction( Collections.<View>emptyList(), maxNativeAdView );
|
|
1621
|
+
}
|
|
1622
|
+
|
|
1623
|
+
@Override
|
|
1624
|
+
public boolean prepareForInteraction(final List<View> clickableViews, final ViewGroup container)
|
|
1625
|
+
{
|
|
1626
|
+
final NativeAd nativeAd = GoogleMediationAdapter.this.nativeAd;
|
|
1627
|
+
if ( nativeAd == null )
|
|
1628
|
+
{
|
|
1629
|
+
e( "Failed to register native ad views: native ad is null." );
|
|
1630
|
+
return false;
|
|
1631
|
+
}
|
|
1632
|
+
|
|
1633
|
+
nativeAdView = new NativeAdView( container.getContext() );
|
|
1634
|
+
|
|
1635
|
+
// Native integrations
|
|
1636
|
+
if ( container instanceof MaxNativeAdView )
|
|
1637
|
+
{
|
|
1638
|
+
MaxNativeAdView maxNativeAdView = (MaxNativeAdView) container;
|
|
1639
|
+
|
|
1640
|
+
// The Google Native Ad View needs to be wrapped around the main native ad view.
|
|
1641
|
+
View mainView = maxNativeAdView.getMainView();
|
|
1642
|
+
maxNativeAdView.removeView( mainView );
|
|
1643
|
+
nativeAdView.addView( mainView );
|
|
1644
|
+
maxNativeAdView.addView( nativeAdView );
|
|
1645
|
+
|
|
1646
|
+
nativeAdView.setIconView( maxNativeAdView.getIconImageView() );
|
|
1647
|
+
nativeAdView.setHeadlineView( maxNativeAdView.getTitleTextView() );
|
|
1648
|
+
nativeAdView.setAdvertiserView( maxNativeAdView.getAdvertiserTextView() );
|
|
1649
|
+
nativeAdView.setBodyView( maxNativeAdView.getBodyTextView() );
|
|
1650
|
+
nativeAdView.setCallToActionView( maxNativeAdView.getCallToActionButton() );
|
|
1651
|
+
|
|
1652
|
+
View mediaView = getMediaView();
|
|
1653
|
+
if ( mediaView instanceof MediaView )
|
|
1654
|
+
{
|
|
1655
|
+
nativeAdView.setMediaView( (MediaView) mediaView );
|
|
1656
|
+
}
|
|
1657
|
+
else if ( mediaView instanceof ImageView )
|
|
1658
|
+
{
|
|
1659
|
+
nativeAdView.setImageView( mediaView );
|
|
1660
|
+
}
|
|
1661
|
+
|
|
1662
|
+
nativeAdView.setNativeAd( nativeAd );
|
|
1663
|
+
}
|
|
1664
|
+
// Plugins
|
|
1665
|
+
else
|
|
1666
|
+
{
|
|
1667
|
+
for ( View view : clickableViews )
|
|
1668
|
+
{
|
|
1669
|
+
Object viewTag = view.getTag();
|
|
1670
|
+
if ( viewTag == null ) continue;
|
|
1671
|
+
|
|
1672
|
+
int tag = (int) viewTag;
|
|
1673
|
+
|
|
1674
|
+
if ( tag == TITLE_LABEL_TAG )
|
|
1675
|
+
{
|
|
1676
|
+
nativeAdView.setHeadlineView( view );
|
|
1677
|
+
}
|
|
1678
|
+
else if ( tag == ICON_VIEW_TAG )
|
|
1679
|
+
{
|
|
1680
|
+
nativeAdView.setIconView( view );
|
|
1681
|
+
}
|
|
1682
|
+
else if ( tag == BODY_VIEW_TAG )
|
|
1683
|
+
{
|
|
1684
|
+
nativeAdView.setBodyView( view );
|
|
1685
|
+
}
|
|
1686
|
+
else if ( tag == CALL_TO_ACTION_VIEW_TAG )
|
|
1687
|
+
{
|
|
1688
|
+
nativeAdView.setCallToActionView( view );
|
|
1689
|
+
}
|
|
1690
|
+
else if ( tag == ADVERTISER_VIEW_TAG )
|
|
1691
|
+
{
|
|
1692
|
+
nativeAdView.setAdvertiserView( view );
|
|
1693
|
+
}
|
|
1694
|
+
}
|
|
1695
|
+
|
|
1696
|
+
//
|
|
1697
|
+
// Logic required for proper media view rendering in plugins (e.g. Flutter / React Native)
|
|
1698
|
+
//
|
|
1699
|
+
|
|
1700
|
+
View mediaView = getMediaView();
|
|
1701
|
+
if ( mediaView == null ) return true;
|
|
1702
|
+
|
|
1703
|
+
ViewGroup pluginContainer = (ViewGroup) mediaView.getParent();
|
|
1704
|
+
if ( pluginContainer == null ) return true;
|
|
1705
|
+
|
|
1706
|
+
// Re-parent mediaView - mediaView must be a child of nativeAdView for Google native ads
|
|
1707
|
+
|
|
1708
|
+
// 1. Remove mediaView from the plugin
|
|
1709
|
+
pluginContainer.removeView( mediaView );
|
|
1710
|
+
|
|
1711
|
+
// NOTE: Will be false for React Native (will extend `ReactViewGroup`), but true for Flutter
|
|
1712
|
+
boolean hasPluginLayout = ( pluginContainer instanceof RelativeLayout || pluginContainer instanceof FrameLayout );
|
|
1713
|
+
if ( !hasPluginLayout )
|
|
1714
|
+
{
|
|
1715
|
+
if ( mediaView instanceof MediaView )
|
|
1716
|
+
{
|
|
1717
|
+
MediaView googleMediaView = (MediaView) mediaView;
|
|
1718
|
+
MediaContent googleMediaContent = googleMediaView.getMediaContent();
|
|
1719
|
+
if ( googleMediaContent != null && googleMediaContent.hasVideoContent() )
|
|
1720
|
+
{
|
|
1721
|
+
mediaView = new AutoMeasuringMediaView( container.getContext() );
|
|
1722
|
+
googleMediaView.setMediaContent( nativeAd.getMediaContent() );
|
|
1723
|
+
}
|
|
1724
|
+
}
|
|
1725
|
+
}
|
|
1726
|
+
|
|
1727
|
+
// 2. Add mediaView to nativeAdView
|
|
1728
|
+
ViewGroup.LayoutParams mediaViewLayout = new ViewGroup.LayoutParams( ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT );
|
|
1729
|
+
nativeAdView.addView( mediaView, mediaViewLayout );
|
|
1730
|
+
|
|
1731
|
+
// Set mediaView or imageView based on the instance type
|
|
1732
|
+
if ( mediaView instanceof MediaView )
|
|
1733
|
+
{
|
|
1734
|
+
nativeAdView.setMediaView( (MediaView) mediaView );
|
|
1735
|
+
}
|
|
1736
|
+
else if ( mediaView instanceof ImageView )
|
|
1737
|
+
{
|
|
1738
|
+
nativeAdView.setImageView( (ImageView) mediaView );
|
|
1739
|
+
}
|
|
1740
|
+
|
|
1741
|
+
nativeAdView.setNativeAd( nativeAd );
|
|
1742
|
+
|
|
1743
|
+
// 3. Add nativeAdView to the plugin
|
|
1744
|
+
ViewGroup.LayoutParams nativeAdViewLayout = new ViewGroup.LayoutParams( ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT );
|
|
1745
|
+
|
|
1746
|
+
if ( hasPluginLayout )
|
|
1747
|
+
{
|
|
1748
|
+
pluginContainer.addView( nativeAdView, nativeAdViewLayout );
|
|
1749
|
+
}
|
|
1750
|
+
else
|
|
1751
|
+
{
|
|
1752
|
+
nativeAdView.measure(
|
|
1753
|
+
View.MeasureSpec.makeMeasureSpec( pluginContainer.getWidth(), View.MeasureSpec.EXACTLY ),
|
|
1754
|
+
View.MeasureSpec.makeMeasureSpec( pluginContainer.getHeight(), View.MeasureSpec.EXACTLY ) );
|
|
1755
|
+
nativeAdView.layout( 0, 0, pluginContainer.getWidth(), pluginContainer.getHeight() );
|
|
1756
|
+
pluginContainer.addView( nativeAdView );
|
|
1757
|
+
}
|
|
1758
|
+
}
|
|
1759
|
+
|
|
1760
|
+
return true;
|
|
1761
|
+
}
|
|
1762
|
+
}
|
|
1763
|
+
|
|
1764
|
+
private static class AutoMeasuringMediaView
|
|
1765
|
+
extends MediaView
|
|
1766
|
+
{
|
|
1767
|
+
AutoMeasuringMediaView(final Context context) { super( context ); }
|
|
1768
|
+
|
|
1769
|
+
@Override
|
|
1770
|
+
protected void onAttachedToWindow()
|
|
1771
|
+
{
|
|
1772
|
+
super.onAttachedToWindow();
|
|
1773
|
+
requestLayout();
|
|
1774
|
+
}
|
|
1775
|
+
|
|
1776
|
+
@Override
|
|
1777
|
+
public void requestLayout()
|
|
1778
|
+
{
|
|
1779
|
+
super.requestLayout();
|
|
1780
|
+
post( () -> {
|
|
1781
|
+
measure(
|
|
1782
|
+
MeasureSpec.makeMeasureSpec( getWidth(), MeasureSpec.EXACTLY ),
|
|
1783
|
+
MeasureSpec.makeMeasureSpec( getHeight(), MeasureSpec.EXACTLY ) );
|
|
1784
|
+
layout( getLeft(), getTop(), getRight(), getBottom() );
|
|
1785
|
+
} );
|
|
1786
|
+
}
|
|
1787
|
+
}
|
|
1788
|
+
}
|