react-native-applovin-max 6.0.1 → 6.1.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.
Files changed (44) hide show
  1. package/android/build.gradle +3 -3
  2. package/android/src/main/java/com/applovin/reactnative/AppLovinMAXModule.java +127 -20
  3. package/ios/AppLovinMAX.m +154 -25
  4. package/ios/Podfile +1 -1
  5. package/ios/Podfile.lock +4 -4
  6. package/package.json +5 -1
  7. package/react-native-applovin-max.podspec +2 -2
  8. package/src/AdView.tsx +58 -43
  9. package/src/AppLovinMAX.ts +8 -10
  10. package/src/AppOpenAd.ts +28 -31
  11. package/src/BannerAd.ts +36 -35
  12. package/src/EventEmitter.ts +9 -9
  13. package/src/InterstitialAd.ts +31 -32
  14. package/src/MRecAd.ts +32 -31
  15. package/src/Privacy.ts +58 -2
  16. package/src/RewardedAd.ts +31 -34
  17. package/src/TargetingData.ts +46 -35
  18. package/src/index.ts +12 -12
  19. package/src/nativeAd/NativeAdView.tsx +64 -55
  20. package/src/nativeAd/NativeAdViewComponents.tsx +38 -29
  21. package/src/nativeAd/NativeAdViewProvider.tsx +16 -13
  22. package/src/types/AdEvent.ts +2 -13
  23. package/src/types/AdInfo.ts +6 -18
  24. package/src/types/AdProps.ts +7 -3
  25. package/src/types/AdViewProps.ts +4 -5
  26. package/src/types/AppLovinMAX.ts +14 -8
  27. package/src/types/AppOpenAd.ts +1 -1
  28. package/src/types/BannerAd.ts +8 -9
  29. package/src/types/Configuration.ts +28 -3
  30. package/src/types/FullscreenAd.ts +19 -19
  31. package/src/types/InterstitialAd.ts +1 -1
  32. package/src/types/MRecAd.ts +3 -4
  33. package/src/types/NativeAd.ts +1 -2
  34. package/src/types/NativeAdViewProps.ts +1 -2
  35. package/src/types/Privacy.ts +28 -16
  36. package/src/types/RewardedAd.ts +4 -5
  37. package/src/types/TargetingData.ts +1 -2
  38. package/src/types/ViewAd.ts +20 -20
  39. package/src/types/index.ts +4 -4
  40. package/android/src/main/java/com/applovin/mediation/adapters/GoogleAdManagerMediationAdapter.java.saved +0 -1616
  41. package/android/src/main/java/com/applovin/mediation/adapters/GoogleMediationAdapter.java.old +0 -1788
  42. package/android/src/main/java/com/applovin/mediation/adapters/MintegralMediationAdapter.java.old +0 -1481
  43. package/android/src/main/java/com/applovin/mediation/adapters/MintegralMediationAdapter.java.saved +0 -1448
  44. package/ios/AppLovinMAX.xcworkspace/xcuserdata/hiroshi.watanabe.xcuserdatad/UserInterfaceState.xcuserstate +0 -0
@@ -1,1481 +0,0 @@
1
- package com.applovin.mediation.adapters;
2
-
3
- import android.app.Activity;
4
- import android.content.Context;
5
- import android.graphics.drawable.Drawable;
6
- import android.net.Uri;
7
- import android.os.Bundle;
8
- import android.text.TextUtils;
9
- import android.view.View;
10
- import android.view.ViewGroup;
11
-
12
- import com.applovin.impl.sdk.utils.BundleUtils;
13
- import com.applovin.mediation.MaxAdFormat;
14
- import com.applovin.mediation.adapter.MaxAdViewAdapter;
15
- import com.applovin.mediation.adapter.MaxAdapterError;
16
- import com.applovin.mediation.adapter.MaxInterstitialAdapter;
17
- import com.applovin.mediation.adapter.MaxRewardedAdapter;
18
- import com.applovin.mediation.adapter.MaxSignalProvider;
19
- import com.applovin.mediation.adapter.listeners.MaxAdViewAdapterListener;
20
- import com.applovin.mediation.adapter.listeners.MaxInterstitialAdapterListener;
21
- import com.applovin.mediation.adapter.listeners.MaxNativeAdAdapterListener;
22
- import com.applovin.mediation.adapter.listeners.MaxRewardedAdapterListener;
23
- import com.applovin.mediation.adapter.listeners.MaxSignalCollectionListener;
24
- import com.applovin.mediation.adapter.parameters.MaxAdapterInitializationParameters;
25
- import com.applovin.mediation.adapter.parameters.MaxAdapterResponseParameters;
26
- import com.applovin.mediation.adapter.parameters.MaxAdapterSignalCollectionParameters;
27
- //import com.applovin.mediation.adapters.mintegral.BuildConfig;
28
- import com.applovin.mediation.nativeAds.MaxNativeAd;
29
- import com.applovin.mediation.nativeAds.MaxNativeAdView;
30
- import com.applovin.sdk.AppLovinSdk;
31
- import com.applovin.sdk.AppLovinSdkUtils;
32
- import com.mbridge.msdk.MBridgeConstans;
33
- import com.mbridge.msdk.MBridgeSDK;
34
- import com.mbridge.msdk.interstitialvideo.out.InterstitialVideoListener;
35
- import com.mbridge.msdk.interstitialvideo.out.MBBidInterstitialVideoHandler;
36
- import com.mbridge.msdk.interstitialvideo.out.MBInterstitialVideoHandler;
37
- import com.mbridge.msdk.mbbid.out.BidConstants;
38
- import com.mbridge.msdk.mbbid.out.BidManager;
39
- import com.mbridge.msdk.nativex.view.MBMediaView;
40
- import com.mbridge.msdk.out.BannerAdListener;
41
- import com.mbridge.msdk.out.BannerSize;
42
- import com.mbridge.msdk.out.Campaign;
43
- import com.mbridge.msdk.out.Frame;
44
- import com.mbridge.msdk.out.MBBannerView;
45
- import com.mbridge.msdk.out.MBBidNativeHandler;
46
- import com.mbridge.msdk.out.MBBidRewardVideoHandler;
47
- import com.mbridge.msdk.out.MBConfiguration;
48
- import com.mbridge.msdk.out.MBRewardVideoHandler;
49
- import com.mbridge.msdk.out.MBridgeIds;
50
- import com.mbridge.msdk.out.MBridgeSDKFactory;
51
- import com.mbridge.msdk.out.NativeListener;
52
- import com.mbridge.msdk.out.OnMBMediaViewListener;
53
- import com.mbridge.msdk.out.RewardInfo;
54
- import com.mbridge.msdk.out.RewardVideoListener;
55
- import com.mbridge.msdk.widget.MBAdChoice;
56
-
57
- import java.util.ArrayList;
58
- import java.util.HashMap;
59
- import java.util.List;
60
- import java.util.Map;
61
- import java.util.concurrent.ExecutorService;
62
- import java.util.concurrent.Executors;
63
- import java.util.concurrent.Future;
64
- import java.util.concurrent.TimeUnit;
65
- import java.util.concurrent.atomic.AtomicBoolean;
66
-
67
- public class MintegralMediationAdapter
68
- extends MediationAdapterBase
69
- implements MaxInterstitialAdapter, MaxRewardedAdapter, MaxAdViewAdapter, MaxSignalProvider /* MaxNativeAdAdapter */
70
- {
71
- private static final MintegralMediationAdapterRouter router;
72
- private static final AtomicBoolean initialized = new AtomicBoolean();
73
- private static final ExecutorService executor = Executors.newCachedThreadPool();
74
-
75
- private static final String APP_ID_PARAMETER = "app_id";
76
- private static final String APP_KEY_PARAMETER = "app_key";
77
-
78
- // Possible ad load error messages received from Mintegral in an email
79
- private final static String NOT_INITIALIZED = "init error";
80
- private final static String NO_FILL_1 = "no ads available can show";
81
- private final static String NO_FILL_2 = "no ads available";
82
- private final static String NO_FILL_3 = "no server ads available";
83
- private final static String NO_FILL_4 = "no ads source";
84
- private final static String NO_FILL_5 = "load no ad";
85
- private final static String NETWORK_ERROR = "network exception";
86
- private final static String BAD_REQUEST = "request parameter is null";
87
- private final static String TIMEOUT = "load timeout";
88
- private final static String UNIT_ID_EMPTY = "UnitId is null";
89
- private final static String NETWORK_IO_ERROR = "Network error,I/O exception";
90
-
91
- // List of Mintegral error codes not defined in API, but in their docs
92
- //
93
- // http://cdn-adn.rayjump.com/cdn-adn/v2/markdown_v2/index.html?file=sdk-m_sdk-android&lang=en#faqs
94
- //
95
- private final static String EXCEPTION_RETURN_EMPTY = "EXCEPTION_RETURN_EMPTY"; // ads no fill
96
- private final static String EXCEPTION_TIMEOUT = "EXCEPTION_TIMEOUT"; // request timeout
97
- private final static String EXCEPTION_IV_RECALLNET_INVALIDATE = "EXCEPTION_IV_RECALLNET_INVALIDATE"; // The network status at the time of the request is incorrect. Generally, because of the SDK initialization is not completed yet when the request has been sent.
98
- private final static String EXCEPTION_SIGN_ERROR = "EXCEPTION_SIGN_ERROR"; // AppID and appKey do not match correctly
99
- private final static String EXCEPTION_UNIT_NOT_FOUND = "EXCEPTION_UNIT_NOT_FOUND"; // Can not find the unitID in dashboard
100
- private final static String EXCEPTION_UNIT_ID_EMPTY = "EXCEPTION_UNIT_ID_EMPTY"; // unitID is empty
101
- private final static String EXCEPTION_UNIT_NOT_FOUND_IN_APP = "EXCEPTION_UNIT_NOT_FOUND_IN_APP"; // Can not find the unitID of the appID
102
- private final static String EXCEPTION_UNIT_ADTYPE_ERROR = "EXCEPTION_UNIT_ADTYPE_ERROR"; // The adtype of the unitID is wrong
103
- private final static String EXCEPTION_APP_ID_EMPTY = "EXCEPTION_APP_ID_EMPTY"; // appID is empty
104
- private final static String EXCEPTION_APP_NOT_FOUND = "EXCEPTION_APP_NOT_FOUND"; // Can not find the appId
105
-
106
- private static String sSdkVersion;
107
-
108
- private static final int DEFAULT_IMAGE_TASK_TIMEOUT_SECONDS = 5; // Mintegral ad load timeout is 10s, so this is 5s.
109
-
110
- // Mintegral suggested we keep a map of unit id -> handler to prevent re-creation / high error rates - https://app.asana.com/0/573104092700345/1166998599374502
111
- private static final Map<String, MBInterstitialVideoHandler> mbInterstitialVideoHandlers = new HashMap<>();
112
- private static final Map<String, MBBidInterstitialVideoHandler> mbBidInterstitialVideoHandlers = new HashMap<>();
113
- private static final Map<String, MBRewardVideoHandler> mbRewardVideoHandlers = new HashMap<>();
114
- private static final Map<String, MBBidRewardVideoHandler> mbBidRewardVideoHandlers = new HashMap<>();
115
-
116
- // Used by the mediation adapter router
117
- private String mbUnitId;
118
-
119
- // Supports video, interactive, and banner ad formats
120
- private MBInterstitialVideoHandler mbInterstitialVideoHandler;
121
- private MBBidInterstitialVideoHandler mbBidInterstitialVideoHandler;
122
- private MBRewardVideoHandler mbRewardVideoHandler;
123
- private MBBidRewardVideoHandler mbBidRewardVideoHandler;
124
- private MBBannerView mbBannerView;
125
- private MBBidNativeHandler mbBidNativeHandler;
126
- private MBBidNativeHandler mbBidNativeAdViewHandler;
127
- private Campaign nativeAdCampaign;
128
- private ViewGroup nativeAdContainer;
129
- private MaxNativeAd nativeAd;
130
- private List<View> clickableViews;
131
-
132
- static
133
- {
134
- router = (MintegralMediationAdapterRouter) MediationAdapterRouter.getSharedInstance( MintegralMediationAdapterRouter.class );
135
- }
136
-
137
- // Explicit default constructor declaration
138
- public MintegralMediationAdapter(final AppLovinSdk sdk) { super( sdk ); }
139
-
140
- @Override
141
- public void initialize(final MaxAdapterInitializationParameters parameters, final Activity activity, final OnCompletionListener onCompletionListener)
142
- {
143
- MBridgeConstans.DEBUG = parameters.isTesting();
144
-
145
- if ( initialized.compareAndSet( false, true ) )
146
- {
147
- final String appId = parameters.getServerParameters().getString( APP_ID_PARAMETER );
148
- final String appKey = parameters.getServerParameters().getString( APP_KEY_PARAMETER );
149
- log( "Initializing Mintegral SDK with app id: " + appId + " and app key: " + appKey + "..." );
150
-
151
- final MBridgeSDK mBridgeSDK = MBridgeSDKFactory.getMBridgeSDK();
152
-
153
- final Context context = getContext( activity );
154
-
155
- // Communicated over email, GDPR status can only be set before SDK initialization
156
- Boolean hasUserConsent = parameters.hasUserConsent();
157
- if ( hasUserConsent != null )
158
- {
159
- int consent = hasUserConsent ? MBridgeConstans.IS_SWITCH_ON : MBridgeConstans.IS_SWITCH_OFF;
160
- mBridgeSDK.setUserPrivateInfoType( context, MBridgeConstans.AUTHORITY_ALL_INFO, consent );
161
- mBridgeSDK.setConsentStatus( context, consent );
162
- }
163
-
164
- // Has to be _before_ their SDK init as well
165
- Boolean isDoNotSell = parameters.isDoNotSell();
166
- if ( isDoNotSell != null && isDoNotSell )
167
- {
168
- mBridgeSDK.setDoNotTrackStatus( context, true );
169
- }
170
-
171
- // Has to be _before_ their SDK init as well
172
- Boolean isAgeRestrictedUser = parameters.isAgeRestrictedUser();
173
- if ( isAgeRestrictedUser != null )
174
- {
175
- mBridgeSDK.setCoppaStatus( context, isAgeRestrictedUser );
176
- }
177
-
178
- // Mintegral Docs - "It is recommended to use the API in the main thread"
179
- Map<String, String> map = mBridgeSDK.getMBConfigurationMap( appId, appKey );
180
- mBridgeSDK.init( map, context );
181
- }
182
-
183
- onCompletionListener.onCompletion( InitializationStatus.DOES_NOT_APPLY, null );
184
- }
185
-
186
- @Override
187
- public String getSdkVersion()
188
- {
189
- // Do not use `MBConfiguration.SDK_VERSION` as this will hardcode the version when the adapter is built
190
- if ( sSdkVersion == null )
191
- {
192
- sSdkVersion = getVersionString( MBConfiguration.class, "SDK_VERSION" );
193
- }
194
-
195
- return sSdkVersion;
196
- }
197
-
198
- @Override
199
- public String getAdapterVersion()
200
- {
201
- // return BuildConfig.VERSION_NAME;
202
- return "16.5.21.0";
203
- }
204
-
205
- @Override
206
- public void onDestroy()
207
- {
208
- if ( mbInterstitialVideoHandler != null )
209
- {
210
- mbInterstitialVideoHandler.setInterstitialVideoListener( null );
211
- mbInterstitialVideoHandler = null;
212
- }
213
-
214
- if ( mbBidInterstitialVideoHandler != null )
215
- {
216
- mbBidInterstitialVideoHandler.setInterstitialVideoListener( null );
217
- mbBidInterstitialVideoHandler = null;
218
- }
219
-
220
- if ( mbRewardVideoHandler != null )
221
- {
222
- mbRewardVideoHandler.setRewardVideoListener( null );
223
- mbRewardVideoHandler = null;
224
- }
225
-
226
- if ( mbBidRewardVideoHandler != null )
227
- {
228
- mbBidRewardVideoHandler.setRewardVideoListener( null );
229
- mbBidRewardVideoHandler = null;
230
- }
231
-
232
- if ( mbBannerView != null )
233
- {
234
- mbBannerView.release();
235
- mbBannerView = null;
236
- }
237
-
238
- if ( mbBidNativeHandler != null )
239
- {
240
- mbBidNativeHandler.unregisterView( nativeAdContainer, clickableViews, nativeAdCampaign );
241
- mbBidNativeHandler.bidRelease();
242
- mbBidNativeHandler.setAdListener( null );
243
- mbBidNativeHandler = null;
244
- }
245
-
246
- if ( mbBidNativeAdViewHandler != null )
247
- {
248
- mbBidNativeAdViewHandler.unregisterView( nativeAdContainer, clickableViews, nativeAdCampaign );
249
- mbBidNativeAdViewHandler.bidRelease();
250
- mbBidNativeAdViewHandler.setAdListener( null );
251
- mbBidNativeAdViewHandler = null;
252
- }
253
-
254
- if ( nativeAd != null )
255
- {
256
- if ( nativeAd.getMediaView() instanceof MBMediaView )
257
- {
258
- ( (MBMediaView) nativeAd.getMediaView() ).destory();
259
- }
260
-
261
- nativeAd = null;
262
- }
263
-
264
- nativeAdCampaign = null;
265
-
266
- router.removeAdapter( this, mbUnitId );
267
- }
268
-
269
- @Override
270
- public void collectSignal(final MaxAdapterSignalCollectionParameters parameters, final Activity activity, final MaxSignalCollectionListener callback)
271
- {
272
- log( "Collecting signal..." );
273
-
274
- String adUnitId = parameters.getAdUnitId();
275
- String signal;
276
-
277
- if ( AppLovinSdkUtils.isValidString( adUnitId ) )
278
- {
279
- Bundle credentials = BundleUtils.getBundle( "credentials", Bundle.EMPTY, parameters.getServerParameters() );
280
- Bundle adUnitCredentials = BundleUtils.getBundle( adUnitId, Bundle.EMPTY, credentials );
281
-
282
- Map<String, String> info = new HashMap<>( 3 );
283
- info.put( BidConstants.BID_FILTER_KEY_PLACEMENT_ID, BundleUtils.getString( "placement_id", "", adUnitCredentials ) );
284
- info.put( BidConstants.BID_FILTER_KEY_UNIT_ID, BundleUtils.getString( "ad_unit_id", "", adUnitCredentials ) );
285
- info.put( BidConstants.BID_FILTER_KEY_AD_TYPE, toMintegralAdType( parameters.getAdFormat() ) );
286
-
287
- signal = BidManager.getBuyerUid( getContext( activity ), info );
288
- }
289
- else
290
- {
291
- signal = BidManager.getBuyerUid( getContext( activity ) );
292
- }
293
-
294
- callback.onSignalCollected( signal );
295
- }
296
-
297
- @Override
298
- public void loadInterstitialAd(final MaxAdapterResponseParameters parameters, final Activity activity, final MaxInterstitialAdapterListener listener)
299
- {
300
- // Overwritten by `mute_state` setting, unless `mute_state` is disabled
301
- final boolean shouldUpdateMuteState = parameters.getServerParameters().containsKey( "is_muted" ); // Introduced in 9.10.0
302
- final int muteState = parameters.getServerParameters().getBoolean( "is_muted" ) ? MBridgeConstans.REWARD_VIDEO_PLAY_MUTE : MBridgeConstans.INTER_ACTIVE_VIDEO_PLAY_NOT_MUTE;
303
-
304
- mbUnitId = parameters.getThirdPartyAdPlacementId();
305
- final String placementId = BundleUtils.getString( "placement_id", parameters.getServerParameters() );
306
-
307
- router.addInterstitialAdapter( this, listener, mbUnitId );
308
-
309
- if ( !TextUtils.isEmpty( parameters.getBidResponse() ) )
310
- {
311
- log( "Loading bidding interstitial ad for unit id: " + mbUnitId + " and placement id: " + placementId + "..." );
312
-
313
- if ( mbBidInterstitialVideoHandlers.containsKey( mbUnitId ) )
314
- {
315
- mbBidInterstitialVideoHandler = mbBidInterstitialVideoHandlers.get( mbUnitId );
316
- }
317
- else
318
- {
319
- mbBidInterstitialVideoHandler = new MBBidInterstitialVideoHandler( activity, placementId, mbUnitId );
320
- mbBidInterstitialVideoHandlers.put( mbUnitId, mbBidInterstitialVideoHandler );
321
- }
322
-
323
- mbBidInterstitialVideoHandler.setInterstitialVideoListener( router.getInterstitialListener() );
324
-
325
- // Update mute state if configured by backend
326
- if ( shouldUpdateMuteState ) mbBidInterstitialVideoHandler.playVideoMute( muteState );
327
-
328
- mbBidInterstitialVideoHandler.loadFromBid( parameters.getBidResponse() );
329
- }
330
- else
331
- {
332
- log( "Loading mediated interstitial ad for unit id: " + mbUnitId + " and placement id: " + placementId + "..." );
333
-
334
- if ( mbInterstitialVideoHandlers.containsKey( mbUnitId ) )
335
- {
336
- mbInterstitialVideoHandler = mbInterstitialVideoHandlers.get( mbUnitId );
337
- }
338
- else
339
- {
340
- mbInterstitialVideoHandler = new MBInterstitialVideoHandler( activity, placementId, mbUnitId );
341
- mbInterstitialVideoHandlers.put( mbUnitId, mbInterstitialVideoHandler );
342
- }
343
-
344
- mbInterstitialVideoHandler.setInterstitialVideoListener( router.getInterstitialListener() );
345
-
346
- if ( mbInterstitialVideoHandler.isReady() )
347
- {
348
- log( "A mediated interstitial ad is ready already" );
349
-
350
- // Passing extra info such as creative id supported in 9.15.0+
351
- if ( AppLovinSdk.VERSION_CODE >= 9150000 && !TextUtils.isEmpty( mbInterstitialVideoHandler.getRequestId() ) )
352
- {
353
- Bundle extraInfo = new Bundle( 1 );
354
- extraInfo.putString( "creative_id", mbInterstitialVideoHandler.getRequestId() );
355
-
356
- router.onAdLoaded( mbUnitId, extraInfo );
357
- }
358
- else
359
- {
360
- router.onAdLoaded( mbUnitId );
361
- }
362
- }
363
- else
364
- {
365
- // Update mute state if configured by backend
366
- if ( shouldUpdateMuteState ) mbInterstitialVideoHandler.playVideoMute( muteState );
367
-
368
- mbInterstitialVideoHandler.load();
369
- }
370
- }
371
- }
372
-
373
- @Override
374
- public void showInterstitialAd(final MaxAdapterResponseParameters parameters, final Activity activity, final MaxInterstitialAdapterListener listener)
375
- {
376
- router.addShowingAdapter( this );
377
-
378
- if ( mbBidInterstitialVideoHandler != null && mbBidInterstitialVideoHandler.isBidReady() )
379
- {
380
- log( "Showing bidding interstitial..." );
381
- mbBidInterstitialVideoHandler.showFromBid();
382
- }
383
- else if ( mbInterstitialVideoHandler != null && mbInterstitialVideoHandler.isReady() )
384
- {
385
- log( "Showing mediated interstitial..." );
386
- mbInterstitialVideoHandler.show();
387
- }
388
- else
389
- {
390
- log( "Unable to show interstitial - no ad loaded..." );
391
-
392
- // Ad load failed
393
- router.onAdDisplayFailed( mbUnitId, new MaxAdapterError( -4205, "Ad Display Failed", 0, "Interstitial ad not ready" ) );
394
- }
395
- }
396
-
397
- @Override
398
- public void loadRewardedAd(final MaxAdapterResponseParameters parameters, final Activity activity, final MaxRewardedAdapterListener listener)
399
- {
400
- // Overwritten by `mute_state` setting, unless `mute_state` is disabled
401
- final boolean shouldUpdateMuteState = parameters.getServerParameters().containsKey( "is_muted" ); // Introduced in 9.10.0
402
- final int muteState = parameters.getServerParameters().getBoolean( "is_muted" ) ? MBridgeConstans.REWARD_VIDEO_PLAY_MUTE : MBridgeConstans.INTER_ACTIVE_VIDEO_PLAY_NOT_MUTE;
403
-
404
- mbUnitId = parameters.getThirdPartyAdPlacementId();
405
- final String placementId = BundleUtils.getString( "placement_id", parameters.getServerParameters() );
406
-
407
- router.addRewardedAdapter( this, listener, mbUnitId );
408
-
409
- if ( !TextUtils.isEmpty( parameters.getBidResponse() ) )
410
- {
411
- log( "Loading bidding rewarded ad for unit id: " + mbUnitId + " and placement id: " + placementId + "..." );
412
-
413
- if ( mbBidRewardVideoHandlers.containsKey( mbUnitId ) )
414
- {
415
- mbBidRewardVideoHandler = mbBidRewardVideoHandlers.get( mbUnitId );
416
- }
417
- else
418
- {
419
- mbBidRewardVideoHandler = new MBBidRewardVideoHandler( activity, placementId, mbUnitId );
420
- mbBidRewardVideoHandlers.put( mbUnitId, mbBidRewardVideoHandler );
421
- }
422
-
423
- mbBidRewardVideoHandler.setRewardVideoListener( router.getRewardedListener() );
424
-
425
- // Update mute state if configured by backend
426
- if ( shouldUpdateMuteState ) mbBidRewardVideoHandler.playVideoMute( muteState );
427
-
428
- mbBidRewardVideoHandler.loadFromBid( parameters.getBidResponse() );
429
- }
430
- else
431
- {
432
- log( "Loading mediated rewarded ad for unit id: " + mbUnitId + " and placement id: " + placementId + "..." );
433
-
434
- if ( mbRewardVideoHandlers.containsKey( mbUnitId ) )
435
- {
436
- mbRewardVideoHandler = mbRewardVideoHandlers.get( mbUnitId );
437
- }
438
- else
439
- {
440
- mbRewardVideoHandler = new MBRewardVideoHandler( activity, placementId, mbUnitId );
441
- mbRewardVideoHandlers.put( mbUnitId, mbRewardVideoHandler );
442
- }
443
-
444
- mbRewardVideoHandler.setRewardVideoListener( router.getRewardedListener() );
445
-
446
- if ( mbRewardVideoHandler.isReady() )
447
- {
448
- log( "A mediated rewarded ad is ready already" );
449
-
450
- // Passing extra info such as creative id supported in 9.15.0+
451
- if ( AppLovinSdk.VERSION_CODE >= 9150000 && !TextUtils.isEmpty( mbRewardVideoHandler.getRequestId() ) )
452
- {
453
- Bundle extraInfo = new Bundle( 1 );
454
- extraInfo.putString( "creative_id", mbRewardVideoHandler.getRequestId() );
455
-
456
- router.onAdLoaded( mbUnitId, extraInfo );
457
- }
458
- else
459
- {
460
- router.onAdLoaded( mbUnitId );
461
- }
462
- }
463
- else
464
- {
465
- // Update mute state if configured by backend
466
- if ( shouldUpdateMuteState ) mbRewardVideoHandler.playVideoMute( muteState );
467
-
468
- mbRewardVideoHandler.load();
469
- }
470
- }
471
- }
472
-
473
- @Override
474
- public void showRewardedAd(final MaxAdapterResponseParameters parameters, final Activity activity, final MaxRewardedAdapterListener listener)
475
- {
476
- router.addShowingAdapter( this );
477
-
478
- // Configure userReward from server.
479
- configureReward( parameters );
480
-
481
- final Bundle serverParameters = parameters.getServerParameters();
482
- final String rewardId = serverParameters.getString( "reward_id", "" );
483
- final String userId = serverParameters.getString( "user_id", "" );
484
-
485
- if ( mbBidRewardVideoHandler != null && mbBidRewardVideoHandler.isBidReady() )
486
- {
487
- log( "Showing bidding rewarded ad..." );
488
- mbBidRewardVideoHandler.showFromBid( rewardId, userId );
489
- }
490
- else if ( mbRewardVideoHandler != null && mbRewardVideoHandler.isReady() )
491
- {
492
- log( "Showing mediated rewarded ad..." );
493
- mbRewardVideoHandler.show( rewardId, userId );
494
- }
495
- else
496
- {
497
- log( "Unable to show rewarded ad - no ad loaded..." );
498
-
499
- // Ad load failed
500
- router.onAdDisplayFailed( mbUnitId, new MaxAdapterError( -4205, "Ad Display Failed", 0, "Rewarded ad not ready" ) );
501
- }
502
- }
503
-
504
- @Override
505
- public void loadAdViewAd(final MaxAdapterResponseParameters parameters, final MaxAdFormat adFormat, final Activity activity, final MaxAdViewAdapterListener listener)
506
- {
507
- mbUnitId = parameters.getThirdPartyAdPlacementId();
508
- final String placementId = BundleUtils.getString( "placement_id", parameters.getServerParameters() );
509
-
510
- final boolean isNative = parameters.getServerParameters().getBoolean( "is_native" );
511
- log( "Loading" + ( isNative ? " native " : " " ) + adFormat.getLabel() + " AdView ad for placement: " + placementId + "..." );
512
-
513
- if ( isNative )
514
- {
515
- Map<String, Object> properties = MBBidNativeHandler.getNativeProperties( placementId, mbUnitId );
516
- properties.put( MBridgeConstans.PROPERTIES_AD_NUM, 1 ); // Only load one ad.
517
- properties.put( MBridgeConstans.NATIVE_VIDEO_SUPPORT, true );
518
-
519
- final NativeAdViewListener nativeAdViewListener = new NativeAdViewListener( parameters, adFormat, getContext( activity ), listener );
520
-
521
- // Native ads do not use the handler maps, because MBNativeHandler.setAdListener fails to update the ad listener after the first assignment.
522
- mbBidNativeAdViewHandler = new MBBidNativeHandler( properties, getContext( activity ) );
523
- mbBidNativeAdViewHandler.setAdListener( nativeAdViewListener );
524
- mbBidNativeAdViewHandler.bidLoad( parameters.getBidResponse() );
525
- }
526
- else
527
- {
528
- mbBannerView = new MBBannerView( getContext( activity ) );
529
- mbBannerView.init( toBannerSize( adFormat ), placementId, mbUnitId );
530
- mbBannerView.setAllowShowCloseBtn( false );
531
- mbBannerView.setRefreshTime( 0 );
532
-
533
- mbBannerView.setBannerAdListener( new BannerAdListener()
534
- {
535
- @Override
536
- public void onLoadSuccessed(final MBridgeIds mBridgeIds)
537
- {
538
- log( "Banner ad loaded for: " + mBridgeIds );
539
-
540
- // Passing extra info such as creative id supported in 9.15.0+
541
- if ( AppLovinSdk.VERSION_CODE >= 9_15_00_00 && AppLovinSdkUtils.isValidString( mbBannerView.getRequestId() ) )
542
- {
543
- Bundle extraInfo = new Bundle( 1 );
544
- extraInfo.putString( "creative_id", mbBannerView.getRequestId() );
545
-
546
- listener.onAdViewAdLoaded( mbBannerView, extraInfo );
547
- }
548
- else
549
- {
550
- listener.onAdViewAdLoaded( mbBannerView );
551
- }
552
- }
553
-
554
- @Override
555
- public void onLoadFailed(final MBridgeIds mBridgeIds, String msg)
556
- {
557
- log( "Banner ad failed to load: " + msg + " for: " + mBridgeIds );
558
- listener.onAdViewAdLoadFailed( toMaxError( msg ) );
559
- }
560
-
561
- @Override
562
- public void onLogImpression(final MBridgeIds mBridgeIds)
563
- {
564
- log( "Banner ad displayed" );
565
- listener.onAdViewAdDisplayed();
566
- }
567
-
568
- @Override
569
- public void onClick(final MBridgeIds mBridgeIds)
570
- {
571
- log( "Banner ad clicked" );
572
- listener.onAdViewAdClicked();
573
- }
574
-
575
- @Override
576
- public void onLeaveApp(final MBridgeIds mBridgeIds)
577
- {
578
- log( "Banner ad will leave application" );
579
- }
580
-
581
- @Override
582
- public void showFullScreen(final MBridgeIds mBridgeIds)
583
- {
584
- log( "Banner ad expanded" );
585
- listener.onAdViewAdExpanded();
586
- }
587
-
588
- @Override
589
- public void closeFullScreen(final MBridgeIds mBridgeIds)
590
- {
591
- log( "Banner ad collapsed" );
592
- listener.onAdViewAdCollapsed();
593
- }
594
-
595
- @Override
596
- public void onCloseBanner(final MBridgeIds mBridgeIds)
597
- {
598
- log( "Banner ad closed" );
599
- }
600
- } );
601
-
602
- if ( AppLovinSdkUtils.isValidString( parameters.getBidResponse() ) )
603
- {
604
- mbBannerView.loadFromBid( parameters.getBidResponse() );
605
- }
606
- else
607
- {
608
- mbBannerView.load();
609
- }
610
- }
611
- }
612
-
613
- @Override
614
- public void loadNativeAd(final MaxAdapterResponseParameters parameters, final Activity activity, final MaxNativeAdAdapterListener listener)
615
- {
616
- mbUnitId = parameters.getThirdPartyAdPlacementId();
617
- final String placementId = BundleUtils.getString( "placement_id", parameters.getServerParameters() );
618
-
619
- log( "Loading bidding native ad for unit id: " + mbUnitId + " and placement id: " + placementId + "..." );
620
-
621
- Map<String, Object> properties = MBBidNativeHandler.getNativeProperties( placementId, mbUnitId );
622
- properties.put( MBridgeConstans.PROPERTIES_AD_NUM, 1 ); // Only load one ad.
623
- properties.put( MBridgeConstans.NATIVE_VIDEO_SUPPORT, true );
624
-
625
- final NativeAdListener nativeAdListener = new NativeAdListener( parameters, getContext( activity ), listener );
626
-
627
- // Native ads do not use the handler maps, because MBNativeHandler.setAdListener fails to update the ad listener after the first assignment.
628
- mbBidNativeHandler = new MBBidNativeHandler( properties, getContext( activity ) );
629
- mbBidNativeHandler.setAdListener( nativeAdListener );
630
- mbBidNativeHandler.bidLoad( parameters.getBidResponse() );
631
- }
632
-
633
- private MaxNativeAdView createMaxNativeAdViewWithNativeAd(final MaxNativeAd maxNativeAd, final String templateName, final Context context)
634
- {
635
- if ( templateName.contains( "vertical" ) )
636
- {
637
- if ( AppLovinSdk.VERSION_CODE < 9_14_05_00 )
638
- {
639
- log( "Vertical native banners are only supported on MAX SDK 9.14.5 and above. Default horizontal native template will be used." );
640
- }
641
-
642
- if ( templateName.equals( "vertical" ) )
643
- {
644
- String verticalTemplateName = ( maxNativeAd.getFormat() == MaxAdFormat.LEADER ) ? "vertical_leader_template" : "vertical_media_banner_template";
645
- return new MaxNativeAdView( maxNativeAd, verticalTemplateName, context );
646
- }
647
- else
648
- {
649
- return new MaxNativeAdView( maxNativeAd, templateName, context );
650
- }
651
- }
652
- else if ( AppLovinSdk.VERSION_CODE < 9_14_05_00 )
653
- {
654
- return new MaxNativeAdView( maxNativeAd,
655
- AppLovinSdkUtils.isValidString( templateName ) ? templateName : "no_body_banner_template",
656
- context );
657
- }
658
- else
659
- {
660
- return new MaxNativeAdView( maxNativeAd,
661
- AppLovinSdkUtils.isValidString( templateName ) ? templateName : "media_banner_template",
662
- context );
663
- }
664
- }
665
-
666
- private ExecutorService getExecutorServiceToUse()
667
- {
668
- if ( AppLovinSdk.VERSION_CODE >= 11_00_00_00 )
669
- {
670
- return getCachingExecutorService();
671
- }
672
- else
673
- {
674
- return executor;
675
- }
676
- }
677
-
678
- private static String toMintegralAdType(final MaxAdFormat adFormat)
679
- {
680
- if ( adFormat == MaxAdFormat.INTERSTITIAL )
681
- {
682
- return BidConstants.BID_FILTER_VALUE_AD_TYPE_INTERSTITIAL_VIDEO;
683
- }
684
- else if ( adFormat == MaxAdFormat.REWARDED )
685
- {
686
- return BidConstants.BID_FILTER_VALUE_AD_TYPE_REWARD_VIDEO;
687
- }
688
- else if ( adFormat == MaxAdFormat.APP_OPEN )
689
- {
690
- return BidConstants.BID_FILTER_VALUE_AD_TYPE_SPLASH;
691
- }
692
- else if ( adFormat == MaxAdFormat.BANNER || adFormat == MaxAdFormat.LEADER || adFormat == MaxAdFormat.MREC )
693
- {
694
- return BidConstants.BID_FILTER_VALUE_AD_TYPE_BANNER;
695
- }
696
- else if ( adFormat == MaxAdFormat.NATIVE )
697
- {
698
- return BidConstants.BID_FILTER_VALUE_AD_TYPE_NATIVE;
699
- }
700
-
701
- return "-1";
702
- }
703
-
704
- private static MaxAdapterError toMaxError(final String mintegralError)
705
- {
706
- // Note: we are using `contains()` in some cases b/c Mintegral prepends the message with `data load failed, errorMsg is `...
707
-
708
- final MaxAdapterError adapterError;
709
- if ( NOT_INITIALIZED.equals( mintegralError ) || mintegralError.contains( EXCEPTION_IV_RECALLNET_INVALIDATE ) )
710
- {
711
- adapterError = MaxAdapterError.NOT_INITIALIZED;
712
- }
713
- else if ( mintegralError.contains( NO_FILL_1 ) || mintegralError.contains( NO_FILL_2 )
714
- || mintegralError.contains( NO_FILL_3 ) || mintegralError.contains( NO_FILL_4 )
715
- || mintegralError.contains( NO_FILL_5 ) || mintegralError.contains( EXCEPTION_RETURN_EMPTY ) )
716
- {
717
- adapterError = MaxAdapterError.NO_FILL;
718
- }
719
- else if ( NETWORK_ERROR.equalsIgnoreCase( mintegralError ) || mintegralError.contains( NETWORK_IO_ERROR ) )
720
- {
721
- adapterError = MaxAdapterError.NO_CONNECTION;
722
- }
723
- else if ( BAD_REQUEST.equalsIgnoreCase( mintegralError ) )
724
- {
725
- adapterError = MaxAdapterError.BAD_REQUEST;
726
- }
727
- else if ( TIMEOUT.equalsIgnoreCase( mintegralError ) || mintegralError.contains( EXCEPTION_TIMEOUT ) )
728
- {
729
- adapterError = MaxAdapterError.TIMEOUT;
730
- }
731
- else if ( mintegralError.contains( EXCEPTION_SIGN_ERROR ) || mintegralError.contains( EXCEPTION_UNIT_NOT_FOUND ) || mintegralError.contains( EXCEPTION_UNIT_ID_EMPTY ) || mintegralError.contains( EXCEPTION_UNIT_NOT_FOUND_IN_APP ) || mintegralError.contains( EXCEPTION_UNIT_ADTYPE_ERROR ) || mintegralError.contains( EXCEPTION_APP_ID_EMPTY ) || mintegralError.contains( EXCEPTION_APP_NOT_FOUND ) || mintegralError.contains( UNIT_ID_EMPTY ) )
732
- {
733
- adapterError = MaxAdapterError.INVALID_CONFIGURATION;
734
- }
735
- else
736
- {
737
- adapterError = MaxAdapterError.UNSPECIFIED;
738
- }
739
-
740
- return new MaxAdapterError( adapterError.getErrorCode(), adapterError.getErrorMessage(), 0, mintegralError );
741
- }
742
-
743
- private Context getContext(Activity activity)
744
- {
745
- // NOTE: `activity` can only be null in 11.1.0+, and `getApplicationContext()` is introduced in 11.1.0
746
- return ( activity != null ) ? activity.getApplicationContext() : getApplicationContext();
747
- }
748
-
749
- private BannerSize toBannerSize(final MaxAdFormat adFormat)
750
- {
751
- if ( adFormat == MaxAdFormat.BANNER || adFormat == MaxAdFormat.LEADER )
752
- {
753
- // Last two parameters are for custom width and height, so we can just use 0.
754
- return new BannerSize( BannerSize.SMART_TYPE, 0, 0 );
755
- }
756
- else if ( adFormat == MaxAdFormat.MREC )
757
- {
758
- return new BannerSize( BannerSize.MEDIUM_TYPE, 0, 0 );
759
- }
760
- else
761
- {
762
- throw new IllegalArgumentException( "Unsupported ad format: " + adFormat );
763
- }
764
- }
765
-
766
- private List<View> getClickableViews(final MaxNativeAdView maxNativeAdView)
767
- {
768
- if ( AppLovinSdk.VERSION_CODE < 11_05_03_00 )
769
- {
770
- final List<View> clickableViews = new ArrayList<>( 5 );
771
- if ( maxNativeAdView.getTitleTextView() != null ) clickableViews.add( maxNativeAdView.getTitleTextView() );
772
- if ( maxNativeAdView.getAdvertiserTextView() != null ) clickableViews.add( maxNativeAdView.getAdvertiserTextView() );
773
- if ( maxNativeAdView.getBodyTextView() != null ) clickableViews.add( maxNativeAdView.getBodyTextView() );
774
- if ( maxNativeAdView.getCallToActionButton() != null ) clickableViews.add( maxNativeAdView.getCallToActionButton() );
775
- if ( maxNativeAdView.getIconImageView() != null ) clickableViews.add( maxNativeAdView.getIconImageView() );
776
-
777
- return clickableViews;
778
- }
779
- else
780
- {
781
- return maxNativeAdView.getClickableViews();
782
- }
783
- }
784
-
785
- private static class MintegralMediationAdapterRouter
786
- extends MediationAdapterRouter
787
- {
788
- private final InterstitialVideoListener interstitialVideoListener = new InterstitialVideoListener()
789
- {
790
- @Override
791
- public void onVideoLoadSuccess(final MBridgeIds mBridgeIds)
792
- {
793
- // Ad has loaded and video has been downloaded
794
- log( "Interstitial successfully loaded and video has been downloaded for: " + mBridgeIds );
795
-
796
- String unitId = mBridgeIds.getUnitId();
797
- MBInterstitialVideoHandler mbInterstitialVideoHandler = MintegralMediationAdapter.mbInterstitialVideoHandlers.get( unitId );
798
- MBBidInterstitialVideoHandler mbBidInterstitialVideoHandler = MintegralMediationAdapter.mbBidInterstitialVideoHandlers.get( unitId );
799
-
800
- String requestId;
801
- if ( mbBidInterstitialVideoHandler != null )
802
- {
803
- requestId = mbBidInterstitialVideoHandler.getRequestId();
804
- }
805
- else
806
- {
807
- requestId = mbInterstitialVideoHandler.getRequestId();
808
- }
809
-
810
- // Passing extra info such as creative id supported in 9.15.0+
811
- if ( AppLovinSdk.VERSION_CODE >= 9150000 && !TextUtils.isEmpty( requestId ) )
812
- {
813
- Bundle extraInfo = new Bundle( 1 );
814
- extraInfo.putString( "creative_id", requestId );
815
-
816
- onAdLoaded( unitId, extraInfo );
817
- }
818
- else
819
- {
820
- onAdLoaded( unitId );
821
- }
822
- }
823
-
824
- @Override
825
- public void onLoadSuccess(final MBridgeIds mBridgeIds)
826
- {
827
- // Ad has loaded but video still needs to be downloaded
828
- log( "Interstitial successfully loaded but video still needs to be downloaded for: " + mBridgeIds );
829
- }
830
-
831
- @Override
832
- public void onVideoLoadFail(final MBridgeIds mBridgeIds, String errorMsg)
833
- {
834
- log( "Interstitial failed to load: " + errorMsg + " for: " + mBridgeIds );
835
- onAdLoadFailed( mBridgeIds.getUnitId(), toMaxError( errorMsg ) );
836
- }
837
-
838
- @Override
839
- public void onAdShow(final MBridgeIds mBridgeIds)
840
- {
841
- log( "Interstitial displayed" );
842
- onAdDisplayed( mBridgeIds.getUnitId() );
843
- }
844
-
845
- @Override
846
- public void onShowFail(final MBridgeIds mBridgeIds, String errorMsg)
847
- {
848
- MaxAdapterError adapterError = new MaxAdapterError( -4205, "Ad Display Failed", 0, errorMsg );
849
- log( "Interstitial failed to show: " + adapterError );
850
- onAdDisplayFailed( mBridgeIds.getUnitId(), adapterError );
851
- }
852
-
853
- @Override
854
- public void onVideoAdClicked(final MBridgeIds mBridgeIds)
855
- {
856
- log( "Interstitial clicked" );
857
- onAdClicked( mBridgeIds.getUnitId() );
858
- }
859
-
860
- @Override
861
- public void onAdClose(final MBridgeIds mBridgeIds, RewardInfo rewardInfo)
862
- {
863
- log( "Interstitial hidden" );
864
- onAdHidden( mBridgeIds.getUnitId() );
865
- }
866
-
867
- @Override
868
- public void onVideoComplete(final MBridgeIds mBridgeIds)
869
- {
870
- log( "Interstitial video completed" );
871
- }
872
-
873
- @Override
874
- public void onAdCloseWithIVReward(final MBridgeIds mBridgeIds, RewardInfo rewardInfo)
875
- {
876
- log( "Interstitial with reward hidden" );
877
- }
878
-
879
- @Override
880
- public void onEndcardShow(final MBridgeIds mBridgeIds)
881
- {
882
- log( "Interstitial endcard shown" );
883
- }
884
- };
885
-
886
- private final RewardVideoListener rewardVideoListener = new RewardVideoListener()
887
- {
888
- @Override
889
- public void onVideoLoadSuccess(final MBridgeIds mBridgeIds)
890
- {
891
- // Ad has loaded and video has been downloaded
892
- log( "Rewarded ad successfully loaded and video has been downloaded for: " + mBridgeIds );
893
-
894
- String unitId = mBridgeIds.getUnitId();
895
- MBRewardVideoHandler mbRewardVideoHandler = MintegralMediationAdapter.mbRewardVideoHandlers.get( unitId );
896
- MBBidRewardVideoHandler mbBidRewardVideoHandler = MintegralMediationAdapter.mbBidRewardVideoHandlers.get( unitId );
897
-
898
- String requestId;
899
- if ( mbBidRewardVideoHandler != null )
900
- {
901
- requestId = mbBidRewardVideoHandler.getRequestId();
902
- }
903
- else
904
- {
905
- requestId = mbRewardVideoHandler.getRequestId();
906
- }
907
-
908
- // Passing extra info such as creative id supported in 9.15.0+
909
- if ( AppLovinSdk.VERSION_CODE >= 9150000 && !TextUtils.isEmpty( requestId ) )
910
- {
911
- Bundle extraInfo = new Bundle( 1 );
912
- extraInfo.putString( "creative_id", requestId );
913
-
914
- onAdLoaded( unitId, extraInfo );
915
- }
916
- else
917
- {
918
- onAdLoaded( unitId );
919
- }
920
- }
921
-
922
- @Override
923
- public void onLoadSuccess(final MBridgeIds mBridgeIds)
924
- {
925
- // Ad has loaded but video still needs to be downloaded
926
- log( "Rewarded ad successfully loaded but video still needs to be downloaded for: " + mBridgeIds );
927
- }
928
-
929
- @Override
930
- public void onVideoLoadFail(final MBridgeIds mBridgeIds, String errorMsg)
931
- {
932
- log( "Rewarded ad failed to load: " + errorMsg + " for: " + mBridgeIds );
933
- onAdLoadFailed( mBridgeIds.getUnitId(), toMaxError( errorMsg ) );
934
- }
935
-
936
- @Override
937
- public void onAdShow(final MBridgeIds mBridgeIds)
938
- {
939
- log( "Rewarded ad displayed" );
940
-
941
- final String unitId = mBridgeIds.getUnitId();
942
- onAdDisplayed( unitId );
943
- onRewardedAdVideoStarted( unitId );
944
- }
945
-
946
- @Override
947
- public void onShowFail(final MBridgeIds mBridgeIds, String errorMsg)
948
- {
949
- MaxAdapterError adapterError = new MaxAdapterError( -4205, "Ad Display Failed", 0, errorMsg );
950
- log( "Rewarded ad failed to show: " + adapterError );
951
- onAdDisplayFailed( mBridgeIds.getUnitId(), adapterError );
952
- }
953
-
954
- @Override
955
- public void onVideoAdClicked(final MBridgeIds mBridgeIds)
956
- {
957
- log( "Rewarded ad clicked" );
958
- onAdClicked( mBridgeIds.getUnitId() );
959
- }
960
-
961
- @Override
962
- public void onAdClose(final MBridgeIds mBridgeIds, RewardInfo rewardInfo)
963
- {
964
- log( "Rewarded ad hidden" );
965
-
966
- final String unitId = mBridgeIds.getUnitId();
967
- if ( rewardInfo.isCompleteView() )
968
- {
969
- onRewardedAdVideoCompleted( unitId );
970
- onUserRewarded( unitId, getReward( unitId ) );
971
- }
972
- else if ( shouldAlwaysRewardUser( unitId ) )
973
- {
974
- onUserRewarded( unitId, getReward( unitId ) );
975
- }
976
-
977
- onAdHidden( unitId );
978
- }
979
-
980
- @Override
981
- public void onVideoComplete(final MBridgeIds mBridgeIds)
982
- {
983
- log( "Rewarded ad video completed" );
984
- }
985
-
986
- @Override
987
- public void onEndcardShow(final MBridgeIds mBridgeIds)
988
- {
989
- log( "Rewarded ad endcard shown" );
990
- }
991
- };
992
-
993
- InterstitialVideoListener getInterstitialListener()
994
- {
995
- return interstitialVideoListener;
996
- }
997
-
998
- RewardVideoListener getRewardedListener()
999
- {
1000
- return rewardVideoListener;
1001
- }
1002
-
1003
- //TODO: marked for deletion, pending SDK change.
1004
- void initialize(final MaxAdapterInitializationParameters parameters, final Activity activity, final OnCompletionListener onCompletionListener) { }
1005
- }
1006
-
1007
- private class NativeAdViewListener
1008
- implements NativeListener.NativeAdListener, OnMBMediaViewListener
1009
- {
1010
- private final Bundle serverParameters;
1011
- private final MaxAdFormat adFormat;
1012
- private final Context context;
1013
- private final MaxAdViewAdapterListener listener;
1014
- private final String unitId;
1015
- private final String placementId;
1016
-
1017
- NativeAdViewListener(final MaxAdapterResponseParameters parameters, final MaxAdFormat adFormat, final Context context, final MaxAdViewAdapterListener listener)
1018
- {
1019
- this.serverParameters = parameters.getServerParameters();
1020
- this.adFormat = adFormat;
1021
- this.context = context;
1022
- this.listener = listener;
1023
-
1024
- unitId = parameters.getThirdPartyAdPlacementId();
1025
- placementId = BundleUtils.getString( "placement_id", parameters.getServerParameters() );
1026
- }
1027
-
1028
- //region NativeListener.NativeAdListener methods
1029
-
1030
- @Override
1031
- public void onAdLoaded(final List<Campaign> campaigns, final int templates)
1032
- {
1033
- if ( campaigns == null || campaigns.isEmpty() )
1034
- {
1035
- log( "Native " + adFormat.getLabel() + " ad failed to load for unit id: " + unitId + " placement id: " + placementId + " with error: no fill" );
1036
- listener.onAdViewAdLoadFailed( MaxAdapterError.NO_FILL );
1037
-
1038
- return;
1039
- }
1040
-
1041
- final Campaign campaign = campaigns.get( 0 );
1042
- if ( TextUtils.isEmpty( campaign.getAppName() ) )
1043
- {
1044
- log( "Native " + adFormat.getLabel() + " ad failed to load for unit id: " + unitId + " placement id: " + placementId + " with error: missing required assets" );
1045
- listener.onAdViewAdLoadFailed( new MaxAdapterError( -5400, "Missing Native Ad Assets" ) );
1046
-
1047
- return;
1048
- }
1049
-
1050
- nativeAdCampaign = campaign;
1051
- log( "Native " + adFormat.getLabel() + " ad loaded for unit id: " + unitId + " placement id: " + placementId );
1052
-
1053
- getExecutorServiceToUse().submit( new Runnable()
1054
- {
1055
- @Override
1056
- public void run()
1057
- {
1058
- final String iconUrl = campaign.getIconUrl();
1059
- final String mainImageUrl = campaign.getImageUrl();
1060
- final Future<Drawable> iconDrawableFuture = createDrawableFuture( iconUrl, context.getResources() );
1061
-
1062
- MaxNativeAd.MaxNativeAdImage iconImage = null;
1063
- Uri uri = Uri.parse( mainImageUrl );
1064
- final MaxNativeAd.MaxNativeAdImage mainImage = new MaxNativeAd.MaxNativeAdImage( uri );
1065
-
1066
- try
1067
- {
1068
- final int imageTaskTimeoutSeconds = BundleUtils.getInt( "image_task_timeout_seconds", DEFAULT_IMAGE_TASK_TIMEOUT_SECONDS, serverParameters );
1069
- final Drawable iconDrawable = iconDrawableFuture.get( imageTaskTimeoutSeconds, TimeUnit.SECONDS );
1070
-
1071
- if ( iconDrawable != null )
1072
- {
1073
- iconImage = new MaxNativeAd.MaxNativeAdImage( iconDrawable );
1074
- }
1075
- }
1076
- catch ( Throwable th )
1077
- {
1078
- log( "Failed to fetch icon image from URL: " + iconUrl, th );
1079
- }
1080
-
1081
- // `iconImage` must be final to be used inside the Runnable.
1082
- final MaxNativeAd.MaxNativeAdImage finalIconImage = iconImage;
1083
- AppLovinSdkUtils.runOnUiThread( new Runnable()
1084
- {
1085
- @Override
1086
- public void run()
1087
- {
1088
- final MBMediaView mediaView = new SelfLayoutMediaView( context );
1089
- mediaView.setNativeAd( campaign );
1090
- mediaView.setOnMediaViewListener( NativeAdViewListener.this );
1091
-
1092
- final MBAdChoice adChoiceView = new MBAdChoice( context );
1093
- adChoiceView.setCampaign( campaign );
1094
-
1095
- MaxNativeAd.Builder builder = new MaxNativeAd.Builder()
1096
- .setAdFormat( adFormat )
1097
- .setTitle( campaign.getAppName() )
1098
- .setBody( campaign.getAppDesc() )
1099
- .setCallToAction( campaign.getAdCall() )
1100
- .setIcon( finalIconImage )
1101
- .setOptionsView( adChoiceView )
1102
- .setMediaView( mediaView );
1103
-
1104
- nativeAd = new MaxMintegralNativeAd( builder );
1105
-
1106
- final String templateName = BundleUtils.getString( "template", "", serverParameters );
1107
- MaxNativeAdView maxNativeAdView = createMaxNativeAdViewWithNativeAd( nativeAd, templateName, context );
1108
-
1109
- nativeAd.prepareForInteraction( getClickableViews( maxNativeAdView ), maxNativeAdView );
1110
- listener.onAdViewAdLoaded( maxNativeAdView );
1111
- }
1112
- } );
1113
- }
1114
- } );
1115
- }
1116
-
1117
- @Override
1118
- public void onAdLoadError(final String message)
1119
- {
1120
- MaxAdapterError error = toMaxError( message );
1121
- log( "Native " + adFormat.getLabel() + " ad failed to load for unit id: " + unitId + " placement id: " + placementId + " with error: " + error );
1122
- listener.onAdViewAdLoadFailed( error );
1123
- }
1124
-
1125
- @Override
1126
- public void onLoggingImpression(final int adSourceType)
1127
- {
1128
- log( "Native " + adFormat.getLabel() + " ad shown for unit id: " + unitId + " placement id: " + placementId );
1129
- listener.onAdViewAdDisplayed( null );
1130
- }
1131
-
1132
- @Override
1133
- public void onAdClick(final Campaign campaign)
1134
- {
1135
- log( "Native " + adFormat.getLabel() + " ad clicked for unit id: " + unitId + " placement id: " + placementId );
1136
- listener.onAdViewAdClicked();
1137
- }
1138
-
1139
- @Override
1140
- public void onAdFramesLoaded(final List<Frame> list)
1141
- {
1142
- log( "Native " + adFormat.getLabel() + " ad frames loaded for unit id: " + unitId + " placement id: " + placementId );
1143
- }
1144
-
1145
- //endregion
1146
-
1147
- //region ONMBMediaViewListener
1148
-
1149
- @Override
1150
- public void onEnterFullscreen()
1151
- {
1152
- log( "Media view entered fullscreen" );
1153
- }
1154
-
1155
- @Override
1156
- public void onExitFullscreen()
1157
- {
1158
- log( "Media view exited fullscreen" );
1159
- }
1160
-
1161
- @Override
1162
- public void onStartRedirection(final Campaign campaign, final String url)
1163
- {
1164
- log( "Media view started redirection with url: " + url );
1165
- }
1166
-
1167
- @Override
1168
- public void onFinishRedirection(final Campaign campaign, final String url)
1169
- {
1170
- log( "Media view finished redirection with url: " + url );
1171
- }
1172
-
1173
- @Override
1174
- public void onRedirectionFailed(final Campaign campaign, final String url)
1175
- {
1176
- log( "Media view redirection failed with url: " + url );
1177
- }
1178
-
1179
- @Override
1180
- public void onVideoAdClicked(final Campaign campaign)
1181
- {
1182
- log( "Media view clicked for unit id: " + unitId + " placement id: " + placementId );
1183
- listener.onAdViewAdClicked();
1184
- }
1185
-
1186
- @Override
1187
- public void onVideoStart()
1188
- {
1189
- log( "Media view video started" );
1190
- }
1191
-
1192
- //endregion
1193
- }
1194
-
1195
- private class NativeAdListener
1196
- implements NativeListener.NativeAdListener, OnMBMediaViewListener
1197
- {
1198
- private final MaxAdapterResponseParameters parameters;
1199
- private final Context context;
1200
- private final MaxNativeAdAdapterListener listener;
1201
- private final String unitId;
1202
- private final String placementId;
1203
-
1204
- NativeAdListener(final MaxAdapterResponseParameters parameters, final Context context, final MaxNativeAdAdapterListener listener)
1205
- {
1206
- this.parameters = parameters;
1207
- this.context = context;
1208
- this.listener = listener;
1209
-
1210
- unitId = parameters.getThirdPartyAdPlacementId();
1211
- placementId = BundleUtils.getString( "placement_id", parameters.getServerParameters() );
1212
- }
1213
-
1214
- //region NativeListener.NativeAdListener methods
1215
-
1216
- @Override
1217
- public void onAdLoaded(final List<Campaign> campaigns, final int templates)
1218
- {
1219
- if ( campaigns == null || campaigns.isEmpty() )
1220
- {
1221
- log( "Native ad failed to load for unit id: " + unitId + " placement id: " + placementId + " with error: no fill" );
1222
- listener.onNativeAdLoadFailed( MaxAdapterError.NO_FILL );
1223
- return;
1224
- }
1225
-
1226
- final Campaign campaign = campaigns.get( 0 );
1227
- final String templateName = BundleUtils.getString( "template", "", parameters.getServerParameters() );
1228
- final boolean isTemplateAd = AppLovinSdkUtils.isValidString( templateName );
1229
- if ( isTemplateAd && TextUtils.isEmpty( campaign.getAppName() ) )
1230
- {
1231
- log( "Native ad failed to load for unit id: " + unitId + " placement id: " + placementId + " with error: missing required assets" );
1232
- listener.onNativeAdLoadFailed( new MaxAdapterError( -5400, "Missing Native Ad Assets" ) );
1233
-
1234
- return;
1235
- }
1236
-
1237
- nativeAdCampaign = campaign;
1238
-
1239
- log( "Native ad loaded for unit id: " + unitId + " placement id: " + placementId );
1240
- processNativeAd( campaign );
1241
- }
1242
-
1243
- @Override
1244
- public void onAdLoadError(final String message)
1245
- {
1246
- MaxAdapterError error = toMaxError( message );
1247
- log( "Native ad failed to load for unit id: " + unitId + " placement id: " + placementId + " with error: " + error );
1248
- listener.onNativeAdLoadFailed( error );
1249
- }
1250
-
1251
- @Override
1252
- public void onLoggingImpression(final int adSourceType)
1253
- {
1254
- log( "Native ad shown for unit id: " + unitId + " placement id: " + placementId );
1255
- listener.onNativeAdDisplayed( null );
1256
- }
1257
-
1258
- @Override
1259
- public void onAdClick(final Campaign campaign)
1260
- {
1261
- log( "Native ad clicked for unit id: " + unitId + " placement id: " + placementId );
1262
- listener.onNativeAdClicked();
1263
- }
1264
-
1265
- @Override
1266
- public void onAdFramesLoaded(final List<Frame> list)
1267
- {
1268
- log( "Native ad frames loaded for unit id: " + unitId + " placement id: " + placementId );
1269
- }
1270
-
1271
- //endregion
1272
-
1273
- //region ONMBMediaViewListener
1274
-
1275
- @Override
1276
- public void onEnterFullscreen()
1277
- {
1278
- android.util.Log.d( "--plugin", "Media view entered fullscreen" );
1279
- }
1280
-
1281
- @Override
1282
- public void onExitFullscreen()
1283
- {
1284
- android.util.Log.d( "--plugin", "Media view exited fullscreen" );
1285
- }
1286
-
1287
- @Override
1288
- public void onStartRedirection(final Campaign campaign, final String url)
1289
- {
1290
- android.util.Log.d( "--plugin", "Media view started redirection with url: " + url );
1291
- }
1292
-
1293
- @Override
1294
- public void onFinishRedirection(final Campaign campaign, final String url)
1295
- {
1296
- log( "Media view finished redirection with url: " + url );
1297
- }
1298
-
1299
- @Override
1300
- public void onRedirectionFailed(final Campaign campaign, final String url)
1301
- {
1302
- android.util.Log.d( "--plugin--", "Media view redirection failed with url: " + url );
1303
- }
1304
-
1305
- @Override
1306
- public void onVideoAdClicked(final Campaign campaign)
1307
- {
1308
- log( "Media view clicked for unit id: " + unitId + " placement id: " + placementId );
1309
- listener.onNativeAdClicked();
1310
- }
1311
-
1312
- @Override
1313
- public void onVideoStart()
1314
- {
1315
- android.util.Log.d( "--plugin--", "Media view video started" );
1316
- }
1317
-
1318
- //endregion
1319
-
1320
- //region NativeAdListener helper methods
1321
-
1322
- private void processNativeAd(final Campaign campaign)
1323
- {
1324
- getExecutorServiceToUse().submit( new Runnable()
1325
- {
1326
- @Override
1327
- public void run()
1328
- {
1329
- final String iconUrl = campaign.getIconUrl();
1330
- final String mainImageUrl = campaign.getImageUrl();
1331
- final Future<Drawable> iconDrawableFuture = createDrawableFuture( iconUrl, context.getResources() );
1332
-
1333
- MaxNativeAd.MaxNativeAdImage iconImage = null;
1334
- Uri uri = Uri.parse( mainImageUrl );
1335
- final MaxNativeAd.MaxNativeAdImage mainImage = new MaxNativeAd.MaxNativeAdImage( uri );
1336
-
1337
- try
1338
- {
1339
- final int imageTaskTimeoutSeconds = BundleUtils.getInt( "image_task_timeout_seconds", DEFAULT_IMAGE_TASK_TIMEOUT_SECONDS, parameters.getServerParameters() );
1340
- final Drawable iconDrawable = iconDrawableFuture.get( imageTaskTimeoutSeconds, TimeUnit.SECONDS );
1341
-
1342
- if ( iconDrawable != null )
1343
- {
1344
- iconImage = new MaxNativeAd.MaxNativeAdImage( iconDrawable );
1345
- }
1346
- }
1347
- catch ( Throwable th )
1348
- {
1349
- log( "Failed to fetch icon image from URL: " + iconUrl, th );
1350
- }
1351
-
1352
- // `iconImage` must be final to be used inside the Runnable.
1353
- final MaxNativeAd.MaxNativeAdImage finalIconImage = iconImage;
1354
- AppLovinSdkUtils.runOnUiThread( new Runnable()
1355
- {
1356
- @Override
1357
- public void run()
1358
- {
1359
- final MBMediaView mediaView = new SelfLayoutMediaView( context );
1360
- mediaView.setNativeAd( campaign );
1361
- //mediaView.setIsAllowFullScreen( false );
1362
- //mediaView.setAllowVideoRefresh( true );
1363
- mediaView.setOnMediaViewListener( NativeAdListener.this );
1364
-
1365
- final MBAdChoice adChoiceView = new MBAdChoice( context );
1366
- adChoiceView.setCampaign( campaign );
1367
-
1368
- MaxNativeAd.Builder builder = new MaxNativeAd.Builder()
1369
- .setAdFormat( MaxAdFormat.NATIVE )
1370
- .setTitle( campaign.getAppName() )
1371
- .setBody( campaign.getAppDesc() )
1372
- .setCallToAction( campaign.getAdCall() )
1373
- .setIcon( finalIconImage )
1374
- .setOptionsView( adChoiceView )
1375
- .setMediaView( mediaView );
1376
- if ( AppLovinSdk.VERSION_CODE >= 11_04_03_99 )
1377
- {
1378
- builder.setMainImage( mainImage );
1379
- }
1380
-
1381
- if ( AppLovinSdk.VERSION_CODE >= 11_07_00_00 )
1382
- {
1383
- // Only Android supports star rating for now
1384
- builder.setStarRating( campaign.getRating() );
1385
- }
1386
-
1387
- nativeAd = new MaxMintegralNativeAd( builder );
1388
- listener.onNativeAdLoaded( nativeAd, null );
1389
- }
1390
- } );
1391
- }
1392
- } );
1393
- }
1394
-
1395
- //endregion
1396
- }
1397
-
1398
- class SelfLayoutMediaView
1399
- extends MBMediaView
1400
- {
1401
- final Runnable ensureLayout = () -> {
1402
- measure(
1403
- MeasureSpec.makeMeasureSpec( getWidth(), MeasureSpec.EXACTLY ),
1404
- MeasureSpec.makeMeasureSpec( getHeight(), MeasureSpec.EXACTLY ) );
1405
- layout( getLeft(), getTop(), getRight(), getBottom() );
1406
- };
1407
-
1408
- SelfLayoutMediaView(Context context)
1409
- {
1410
- super( context );
1411
- post( ensureLayout );
1412
- }
1413
-
1414
- @Override
1415
- protected void onAttachedToWindow()
1416
- {
1417
- super.onAttachedToWindow();
1418
- requestLayout();
1419
- }
1420
-
1421
- @Override
1422
- public void requestLayout()
1423
- {
1424
- super.requestLayout();
1425
- post( ensureLayout );
1426
- }
1427
- }
1428
-
1429
- private class MaxMintegralNativeAd
1430
- extends MaxNativeAd
1431
- {
1432
- public MaxMintegralNativeAd(final Builder builder) { super( builder ); }
1433
-
1434
- @Override
1435
- public void prepareViewForInteraction(final MaxNativeAdView maxNativeAdView)
1436
- {
1437
- prepareForInteraction( MintegralMediationAdapter.this.getClickableViews( maxNativeAdView ), maxNativeAdView );
1438
- }
1439
-
1440
- // @Override
1441
- public boolean prepareForInteraction(final List<View> clickableViews, final ViewGroup container)
1442
- {
1443
- final Campaign nativeAdCampaign = MintegralMediationAdapter.this.nativeAdCampaign;
1444
- if ( nativeAdCampaign == null )
1445
- {
1446
- e( "Failed to register native ad views: native ad is null." );
1447
- return false;
1448
- }
1449
-
1450
- d( "Preparing views for interaction: " + clickableViews + " with container: " + container );
1451
-
1452
- if ( getFormat() == MaxAdFormat.NATIVE )
1453
- {
1454
- if ( mbBidNativeHandler != null )
1455
- {
1456
- mbBidNativeHandler.registerView( container, clickableViews, nativeAdCampaign );
1457
- }
1458
- else
1459
- {
1460
- e( "Failed to register native ad views: mbBidNativeHandler is null." );
1461
- }
1462
- }
1463
- else
1464
- {
1465
- if ( mbBidNativeAdViewHandler != null )
1466
- {
1467
- mbBidNativeAdViewHandler.registerView( container, clickableViews, nativeAdCampaign );
1468
- }
1469
- else
1470
- {
1471
- e( "Failed to register native ad views: mbBidNativeAdViewHandler is null." );
1472
- }
1473
- }
1474
-
1475
- MintegralMediationAdapter.this.nativeAdContainer = container;
1476
- MintegralMediationAdapter.this.clickableViews = clickableViews;
1477
-
1478
- return true;
1479
- }
1480
- }
1481
- }