react-native-applovin-max 3.0.1 → 3.2.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.
@@ -15,26 +15,34 @@ import android.view.OrientationEventListener;
15
15
  import android.view.View;
16
16
  import android.view.ViewGroup;
17
17
  import android.view.ViewParent;
18
+ import android.view.WindowManager;
18
19
  import android.widget.LinearLayout;
19
20
  import android.widget.RelativeLayout;
20
21
 
21
22
  import com.applovin.mediation.MaxAd;
22
23
  import com.applovin.mediation.MaxAdFormat;
23
24
  import com.applovin.mediation.MaxAdListener;
25
+ import com.applovin.mediation.MaxAdRevenueListener;
24
26
  import com.applovin.mediation.MaxAdViewAdListener;
27
+ import com.applovin.mediation.MaxAdWaterfallInfo;
25
28
  import com.applovin.mediation.MaxError;
26
29
  import com.applovin.mediation.MaxErrorCode;
30
+ import com.applovin.mediation.MaxMediatedNetworkInfo;
31
+ import com.applovin.mediation.MaxNetworkResponseInfo;
27
32
  import com.applovin.mediation.MaxReward;
28
33
  import com.applovin.mediation.MaxRewardedAdListener;
29
34
  import com.applovin.mediation.ads.MaxAdView;
30
35
  import com.applovin.mediation.ads.MaxInterstitialAd;
31
36
  import com.applovin.mediation.ads.MaxRewardedAd;
37
+ import com.applovin.sdk.AppLovinAdContentRating;
38
+ import com.applovin.sdk.AppLovinGender;
32
39
  import com.applovin.sdk.AppLovinMediationProvider;
33
40
  import com.applovin.sdk.AppLovinPrivacySettings;
34
41
  import com.applovin.sdk.AppLovinSdk;
35
42
  import com.applovin.sdk.AppLovinSdkConfiguration;
36
43
  import com.applovin.sdk.AppLovinSdkSettings;
37
44
  import com.applovin.sdk.AppLovinSdkUtils;
45
+ import com.applovin.sdk.AppLovinUserService;
38
46
  import com.facebook.react.bridge.Arguments;
39
47
  import com.facebook.react.bridge.Callback;
40
48
  import com.facebook.react.bridge.ReactApplicationContext;
@@ -42,6 +50,7 @@ import com.facebook.react.bridge.ReactContextBaseJavaModule;
42
50
  import com.facebook.react.bridge.ReactMethod;
43
51
  import com.facebook.react.bridge.ReadableArray;
44
52
  import com.facebook.react.bridge.ReadableMap;
53
+ import com.facebook.react.bridge.WritableArray;
45
54
  import com.facebook.react.bridge.WritableMap;
46
55
 
47
56
  import java.util.ArrayList;
@@ -63,7 +72,7 @@ import static com.facebook.react.modules.core.DeviceEventManagerModule.RCTDevice
63
72
  */
64
73
  public class AppLovinMAXModule
65
74
  extends ReactContextBaseJavaModule
66
- implements MaxAdListener, MaxAdViewAdListener, MaxRewardedAdListener
75
+ implements MaxAdListener, MaxAdViewAdListener, MaxRewardedAdListener, MaxAdRevenueListener
67
76
  {
68
77
  private static final String SDK_TAG = "AppLovinSdk";
69
78
  private static final String TAG = "AppLovinMAXModule";
@@ -79,6 +88,9 @@ public class AppLovinMAXModule
79
88
  private boolean isSdkInitialized;
80
89
  private AppLovinSdkConfiguration sdkConfiguration;
81
90
 
91
+ private WindowManager windowManager;
92
+ private int lastRotation;
93
+
82
94
  // Store these values if pub attempts to set it before initializing
83
95
  private String userIdToSet;
84
96
  private List<String> testDeviceAdvertisingIdsToSet;
@@ -95,7 +107,6 @@ public class AppLovinMAXModule
95
107
  private final Map<String, String> mAdViewPositions = new HashMap<>( 2 );
96
108
  private final Map<String, Point> mAdViewOffsets = new HashMap<>( 2 );
97
109
  private final Map<String, Integer> mAdViewWidths = new HashMap<>( 2 );
98
- private final Map<String, MaxAdFormat> mVerticalAdViewFormats = new HashMap<>( 2 );
99
110
  private final List<String> mAdUnitIdsToShowAfterCreate = new ArrayList<>( 2 );
100
111
  private final Set<String> mDisabledAdaptiveBannerAdUnitIds = new HashSet<>( 2 );
101
112
 
@@ -252,15 +263,24 @@ public class AppLovinMAXModule
252
263
  sdkConfiguration = configuration;
253
264
  isSdkInitialized = true;
254
265
 
255
- // Enable orientation change listener, so that the position can be updated for vertical banners.
266
+ windowManager = (WindowManager) context.getSystemService( Context.WINDOW_SERVICE );
267
+
268
+ lastRotation = windowManager.getDefaultDisplay().getRotation();
269
+
270
+ // Enable orientation change listener, so that the ad view positions can be updated when the device is rotated.
256
271
  new OrientationEventListener( context )
257
272
  {
258
273
  @Override
259
274
  public void onOrientationChanged(final int orientation)
260
275
  {
261
- for ( final Map.Entry<String, MaxAdFormat> adUnitFormats : mVerticalAdViewFormats.entrySet() )
276
+ int newRotation = windowManager.getDefaultDisplay().getRotation();
277
+ if ( newRotation != lastRotation )
262
278
  {
263
- positionAdView( adUnitFormats.getKey(), adUnitFormats.getValue() );
279
+ lastRotation = newRotation;
280
+ for ( final Map.Entry<String, MaxAdFormat> adUnitFormats : mAdViewAdFormats.entrySet() )
281
+ {
282
+ positionAdView( adUnitFormats.getKey(), adUnitFormats.getValue() );
283
+ }
264
284
  }
265
285
  }
266
286
  }.enable();
@@ -287,13 +307,32 @@ public class AppLovinMAXModule
287
307
  {
288
308
  if ( sdk == null )
289
309
  {
290
- Log.e( "[" + TAG + "]", "Failed to show mediation debugger - please ensure the AppLovin MAX React Native module has been initialized by calling 'AppLovinMAX.initialize(...);'!" );
310
+ logUninitializedAccessError( "showMediationDebugger" );
291
311
  return;
292
312
  }
293
313
 
294
314
  sdk.showMediationDebugger();
295
315
  }
296
316
 
317
+ @ReactMethod()
318
+ public void showConsentDialog(final Callback callback)
319
+ {
320
+ if ( sdk == null )
321
+ {
322
+ logUninitializedAccessError( "showConsentDialog" );
323
+ return;
324
+ }
325
+
326
+ sdk.getUserService().showConsentDialog( maybeGetCurrentActivity(), new AppLovinUserService.OnConsentDialogDismissListener()
327
+ {
328
+ @Override
329
+ public void onDismiss()
330
+ {
331
+ callback.invoke();
332
+ }
333
+ } );
334
+ }
335
+
297
336
  @ReactMethod(isBlockingSynchronousMethod = true)
298
337
  public int getConsentDialogState()
299
338
  {
@@ -427,6 +466,180 @@ public class AppLovinMAXModule
427
466
  @ReactMethod()
428
467
  public void setTermsOfServiceUrl(final String urlString) {}
429
468
 
469
+ // Data Passing
470
+
471
+ @ReactMethod()
472
+ public void setUserSegment(final String name)
473
+ {
474
+ if ( sdk == null )
475
+ {
476
+ logUninitializedAccessError( "setUserSegment" );
477
+ return;
478
+ }
479
+
480
+ sdk.getUserSegment().setName( name );
481
+ }
482
+
483
+ @ReactMethod()
484
+ public void setTargetingDataYearOfBirth(final int yearOfBirth)
485
+ {
486
+ if ( sdk == null )
487
+ {
488
+ logUninitializedAccessError( "setTargetingDataYearOfBirth" );
489
+ return;
490
+ }
491
+
492
+ sdk.getTargetingData().setYearOfBirth( yearOfBirth <= 0 ? null : yearOfBirth );
493
+ }
494
+
495
+ @ReactMethod()
496
+ public void setTargetingDataGender(final String gender)
497
+ {
498
+ if ( sdk == null )
499
+ {
500
+ logUninitializedAccessError( "setTargetingDataGender" );
501
+ return;
502
+ }
503
+
504
+ AppLovinGender alGender = AppLovinGender.UNKNOWN;
505
+
506
+ if ( "F".equals( gender ) )
507
+ {
508
+ alGender = AppLovinGender.FEMALE;
509
+ }
510
+ else if ( "M".equals( gender ) )
511
+ {
512
+ alGender = AppLovinGender.MALE;
513
+ }
514
+ else if ( "O".equals( gender ) )
515
+ {
516
+ alGender = AppLovinGender.OTHER;
517
+ }
518
+
519
+ sdk.getTargetingData().setGender( alGender );
520
+ }
521
+
522
+ @ReactMethod()
523
+ public void setTargetingDataMaximumAdContentRating(final int maximumAdContentRating)
524
+ {
525
+ if ( sdk == null )
526
+ {
527
+ logUninitializedAccessError( "setTargetingDataMaximumAdContentRating" );
528
+ return;
529
+ }
530
+
531
+ AppLovinAdContentRating rating = AppLovinAdContentRating.NONE;
532
+
533
+ if ( maximumAdContentRating == 1 )
534
+ {
535
+ rating = AppLovinAdContentRating.ALL_AUDIENCES;
536
+ }
537
+ else if ( maximumAdContentRating == 2 )
538
+ {
539
+ rating = AppLovinAdContentRating.EVERYONE_OVER_TWELVE;
540
+ }
541
+ else if ( maximumAdContentRating == 3 )
542
+ {
543
+ rating = AppLovinAdContentRating.MATURE_AUDIENCES;
544
+ }
545
+
546
+ sdk.getTargetingData().setMaximumAdContentRating( rating );
547
+ }
548
+
549
+ @ReactMethod()
550
+ public void setTargetingDataEmail(final String email)
551
+ {
552
+ if ( sdk == null )
553
+ {
554
+ logUninitializedAccessError( "setTargetingDataEmail" );
555
+ return;
556
+ }
557
+
558
+ sdk.getTargetingData().setEmail( email );
559
+ }
560
+
561
+ @ReactMethod()
562
+ public void setTargetingDataPhoneNumber(final String phoneNumber)
563
+ {
564
+ if ( sdk == null )
565
+ {
566
+ logUninitializedAccessError( "setTargetingDataPhoneNumber" );
567
+ return;
568
+ }
569
+
570
+ sdk.getTargetingData().setPhoneNumber( phoneNumber );
571
+ }
572
+
573
+ @ReactMethod()
574
+ public void setTargetingDataKeywords(final ReadableArray rawKeywords)
575
+ {
576
+ if ( sdk == null )
577
+ {
578
+ logUninitializedAccessError( "setTargetingDataKeywords" );
579
+ return;
580
+ }
581
+
582
+ List<String> keywords = null;
583
+
584
+ if ( rawKeywords != null )
585
+ {
586
+ keywords = new ArrayList<>( rawKeywords.size() );
587
+ for ( Object rawKeyword : rawKeywords.toArrayList() )
588
+ {
589
+ keywords.add( (String) rawKeyword );
590
+ }
591
+ }
592
+
593
+ sdk.getTargetingData().setKeywords( keywords );
594
+ }
595
+
596
+ @ReactMethod()
597
+ public void setTargetingDataInterests(final ReadableArray rawInterests)
598
+ {
599
+ if ( sdk == null )
600
+ {
601
+ logUninitializedAccessError( "setTargetingDataInterests" );
602
+ return;
603
+ }
604
+
605
+ List<String> interests = null;
606
+
607
+ if ( rawInterests != null )
608
+ {
609
+ interests = new ArrayList<>( rawInterests.size() );
610
+ for ( Object rawInterest : rawInterests.toArrayList() )
611
+ {
612
+ interests.add( (String) rawInterest );
613
+ }
614
+ }
615
+
616
+ sdk.getTargetingData().setInterests( interests );
617
+ }
618
+
619
+ @ReactMethod()
620
+ public void clearAllTargetingData()
621
+ {
622
+ if ( sdk == null )
623
+ {
624
+ logUninitializedAccessError( "clearAllTargetingData" );
625
+ return;
626
+ }
627
+
628
+ sdk.getTargetingData().clearAll();
629
+ }
630
+
631
+ @ReactMethod()
632
+ public void setLocationCollectionEnabled(final boolean locationCollectionEnabled)
633
+ {
634
+ if ( sdk == null )
635
+ {
636
+ logUninitializedAccessError( "setLocationCollectionEnabled" );
637
+ return;
638
+ }
639
+
640
+ sdk.getSettings().setLocationCollectionEnabled( locationCollectionEnabled );
641
+ }
642
+
430
643
  // EVENT TRACKING
431
644
 
432
645
  @ReactMethod()
@@ -472,6 +685,12 @@ public class AppLovinMAXModule
472
685
  setAdViewPlacement( adUnitId, getDeviceSpecificBannerAdViewAdFormat(), placement );
473
686
  }
474
687
 
688
+ @ReactMethod()
689
+ public void setBannerCustomData(final String adUnitId, final String customData)
690
+ {
691
+ setAdViewCustomData( adUnitId, getDeviceSpecificBannerAdViewAdFormat(), customData );
692
+ }
693
+
475
694
  @ReactMethod()
476
695
  public void setBannerWidth(final String adUnitId, final int widthDp)
477
696
  {
@@ -534,6 +753,12 @@ public class AppLovinMAXModule
534
753
  setAdViewPlacement( adUnitId, MaxAdFormat.MREC, placement );
535
754
  }
536
755
 
756
+ @ReactMethod()
757
+ public void setMRecCustomData(final String adUnitId, final String customData)
758
+ {
759
+ setAdViewCustomData( adUnitId, MaxAdFormat.MREC, customData );
760
+ }
761
+
537
762
  @ReactMethod()
538
763
  public void updateMRecPosition(final String adUnitId, final String mrecPosition)
539
764
  {
@@ -581,16 +806,10 @@ public class AppLovinMAXModule
581
806
  }
582
807
 
583
808
  @ReactMethod()
584
- public void showInterstitial(final String adUnitId)
585
- {
586
- showInterstitialWithPlacement( adUnitId, null );
587
- }
588
-
589
- @ReactMethod()
590
- public void showInterstitialWithPlacement(final String adUnitId, final String placement)
809
+ public void showInterstitial(final String adUnitId, final String placement, final String customData)
591
810
  {
592
811
  MaxInterstitialAd interstitial = retrieveInterstitial( adUnitId );
593
- interstitial.showAd( placement );
812
+ interstitial.showAd( placement, customData );
594
813
  }
595
814
 
596
815
  @ReactMethod()
@@ -623,16 +842,10 @@ public class AppLovinMAXModule
623
842
  }
624
843
 
625
844
  @ReactMethod()
626
- public void showRewardedAd(final String adUnitId)
627
- {
628
- showRewardedAdWithPlacement( adUnitId, null );
629
- }
630
-
631
- @ReactMethod()
632
- public void showRewardedAdWithPlacement(final String adUnitId, final String placement)
845
+ public void showRewardedAd(final String adUnitId, final String placement, final String customData)
633
846
  {
634
847
  MaxRewardedAd rewardedAd = retrieveRewardedAd( adUnitId );
635
- rewardedAd.showAd( placement );
848
+ rewardedAd.showAd( placement, customData );
636
849
  }
637
850
 
638
851
  @ReactMethod()
@@ -732,6 +945,7 @@ public class AppLovinMAXModule
732
945
  params.putInt( "code", error.getCode() );
733
946
  params.putString( "message", error.getMessage() );
734
947
  params.putString( "adLoadFailureInfo", error.getAdLoadFailureInfo() );
948
+ params.putMap( "waterfall", createAdWaterfallInfo( error.getWaterfall() ) );
735
949
  }
736
950
  else
737
951
  {
@@ -861,6 +1075,41 @@ public class AppLovinMAXModule
861
1075
  sendReactNativeEvent( ( MaxAdFormat.MREC == adFormat ) ? "OnMRecAdCollapsedEvent" : "OnBannerAdCollapsedEvent", getAdInfo( ad ) );
862
1076
  }
863
1077
 
1078
+ @Override
1079
+ public void onAdRevenuePaid(final MaxAd ad)
1080
+ {
1081
+ final MaxAdFormat adFormat = ad.getFormat();
1082
+ final String name;
1083
+ if ( MaxAdFormat.BANNER == adFormat || MaxAdFormat.LEADER == adFormat )
1084
+ {
1085
+ name = "OnBannerAdRevenuePaid";
1086
+ }
1087
+ else if ( MaxAdFormat.MREC == adFormat )
1088
+ {
1089
+ name = "OnMRecAdRevenuePaid";
1090
+ }
1091
+ else if ( MaxAdFormat.INTERSTITIAL == adFormat )
1092
+ {
1093
+ name = "OnInterstitialAdRevenuePaid";
1094
+ }
1095
+ else if ( MaxAdFormat.REWARDED == adFormat )
1096
+ {
1097
+ name = "OnRewardedAdRevenuePaid";
1098
+ }
1099
+ else
1100
+ {
1101
+ logInvalidAdFormat( adFormat );
1102
+ return;
1103
+ }
1104
+
1105
+ WritableMap adInfo = getAdInfo( ad );
1106
+ adInfo.putString( "networkPlacement", ad.getNetworkPlacement() );
1107
+ adInfo.putString( "revenuePrecision", ad.getRevenuePrecision() );
1108
+ adInfo.putString( "countryCode", sdkConfiguration.getCountryCode() );
1109
+
1110
+ sendReactNativeEvent( name, adInfo );
1111
+ }
1112
+
864
1113
  @Override
865
1114
  public void onRewardedVideoCompleted(final MaxAd ad)
866
1115
  {
@@ -960,6 +1209,27 @@ public class AppLovinMAXModule
960
1209
  } );
961
1210
  }
962
1211
 
1212
+ private void setAdViewCustomData(final String adUnitId, final MaxAdFormat adFormat, final String customData)
1213
+ {
1214
+ getReactApplicationContext().runOnUiQueueThread( new Runnable()
1215
+ {
1216
+ @Override
1217
+ public void run()
1218
+ {
1219
+ d( "Setting custom data \"" + customData + "\" for " + adFormat.getLabel() + " with ad unit id \"" + adUnitId + "\"" );
1220
+
1221
+ final MaxAdView adView = retrieveAdView( adUnitId, adFormat, "", DEFAULT_AD_VIEW_OFFSET );
1222
+ if ( adView == null )
1223
+ {
1224
+ e( adFormat.getLabel() + " does not exist" );
1225
+ return;
1226
+ }
1227
+
1228
+ adView.setCustomData( customData );
1229
+ }
1230
+ } );
1231
+ }
1232
+
963
1233
  private void setAdViewWidth(final String adUnitId, final int widthDp, final MaxAdFormat adFormat)
964
1234
  {
965
1235
  getReactApplicationContext().runOnUiQueueThread( new Runnable()
@@ -1076,6 +1346,7 @@ public class AppLovinMAXModule
1076
1346
  }
1077
1347
 
1078
1348
  adView.setListener( null );
1349
+ adView.setRevenueListener( null );
1079
1350
  adView.destroy();
1080
1351
 
1081
1352
  mAdViews.remove( adUnitId );
@@ -1083,7 +1354,6 @@ public class AppLovinMAXModule
1083
1354
  mAdViewPositions.remove( adUnitId );
1084
1355
  mAdViewOffsets.remove( adUnitId );
1085
1356
  mAdViewWidths.remove( adUnitId );
1086
- mVerticalAdViewFormats.remove( adUnitId );
1087
1357
  }
1088
1358
  } );
1089
1359
  }
@@ -1164,34 +1434,6 @@ public class AppLovinMAXModule
1164
1434
  } );
1165
1435
  }
1166
1436
 
1167
- private void logInvalidAdFormat(MaxAdFormat adFormat)
1168
- {
1169
- logStackTrace( new IllegalStateException( "invalid ad format: " + adFormat ) );
1170
- }
1171
-
1172
- private void logStackTrace(Exception e)
1173
- {
1174
- e( Log.getStackTraceString( e ) );
1175
- }
1176
-
1177
- public static void d(final String message)
1178
- {
1179
- final String fullMessage = "[" + TAG + "] " + message;
1180
- Log.d( SDK_TAG, fullMessage );
1181
- }
1182
-
1183
- public static void w(final String message)
1184
- {
1185
- final String fullMessage = "[" + TAG + "] " + message;
1186
- Log.w( SDK_TAG, fullMessage );
1187
- }
1188
-
1189
- public static void e(final String message)
1190
- {
1191
- final String fullMessage = "[" + TAG + "] " + message;
1192
- Log.e( SDK_TAG, fullMessage );
1193
- }
1194
-
1195
1437
  @Nullable
1196
1438
  private MaxInterstitialAd retrieveInterstitial(String adUnitId)
1197
1439
  {
@@ -1203,6 +1445,7 @@ public class AppLovinMAXModule
1203
1445
  {
1204
1446
  result = new MaxInterstitialAd( adUnitId, sdk, currentActivity );
1205
1447
  result.setListener( this );
1448
+ result.setRevenueListener( this );
1206
1449
 
1207
1450
  mInterstitials.put( adUnitId, result );
1208
1451
  }
@@ -1221,6 +1464,7 @@ public class AppLovinMAXModule
1221
1464
  {
1222
1465
  result = MaxRewardedAd.getInstance( adUnitId, sdk, currentActivity );
1223
1466
  result.setListener( this );
1467
+ result.setRevenueListener( this );
1224
1468
 
1225
1469
  mRewardedAds.put( adUnitId, result );
1226
1470
  }
@@ -1240,6 +1484,7 @@ public class AppLovinMAXModule
1240
1484
  {
1241
1485
  result = new MaxAdView( adUnitId, adFormat, sdk, maybeGetCurrentActivity() );
1242
1486
  result.setListener( this );
1487
+ result.setRevenueListener( this );
1243
1488
 
1244
1489
  mAdViews.put( adUnitId, result );
1245
1490
  mAdViewPositions.put( adUnitId, adViewPosition );
@@ -1326,8 +1571,6 @@ public class AppLovinMAXModule
1326
1571
  adView.setTranslationX( 0 );
1327
1572
  params.setMargins( 0, 0, 0, 0 );
1328
1573
 
1329
- mVerticalAdViewFormats.remove( adUnitId );
1330
-
1331
1574
  if ( "centered".equalsIgnoreCase( adViewPosition ) )
1332
1575
  {
1333
1576
  gravity = Gravity.CENTER_VERTICAL | Gravity.CENTER_HORIZONTAL;
@@ -1366,66 +1609,6 @@ public class AppLovinMAXModule
1366
1609
  {
1367
1610
  params.width = RelativeLayout.LayoutParams.MATCH_PARENT;
1368
1611
  }
1369
-
1370
- // Check if the publisher wants the ad view to be vertical and update the position accordingly ('CenterLeft' or 'CenterRight').
1371
- final boolean containsLeft = adViewPosition.contains( "left" );
1372
- final boolean containsRight = adViewPosition.contains( "right" );
1373
- if ( containsLeft || containsRight )
1374
- {
1375
- // First, center the ad view in the view.
1376
- gravity |= Gravity.CENTER_VERTICAL;
1377
-
1378
- // For banners, set the width to the height of the screen to span the ad across the screen after it is rotated.
1379
- // Android by default clips a view bounds if it goes over the size of the screen. We can overcome it by setting negative margins to match our required size.
1380
- if ( MaxAdFormat.MREC == adFormat )
1381
- {
1382
- gravity |= adViewPosition.contains( "left" ) ? Gravity.LEFT : Gravity.RIGHT;
1383
- }
1384
- else
1385
- {
1386
- /* Align the center of the view such that when rotated it snaps into place.
1387
- *
1388
- * +---+---+-------+
1389
- * | | |
1390
- * | | |
1391
- * | | |
1392
- * | | |
1393
- * | | |
1394
- * | | |
1395
- * +-------------+---+-----------+--+
1396
- * | | + | + | |
1397
- * +-------------+---+-----------+--+
1398
- * | | |
1399
- * | ^ | ^ |
1400
- * | +-----+ |
1401
- * Translation |
1402
- * | | |
1403
- * | | |
1404
- * +---+-----------+
1405
- */
1406
-
1407
- final int windowWidth = windowRect.width();
1408
- final int windowHeight = windowRect.height();
1409
- final int longSide = Math.max( windowWidth, windowHeight );
1410
- final int shortSide = Math.min( windowWidth, windowHeight );
1411
- final int margin = ( longSide - shortSide ) / 2;
1412
- params.setMargins( -margin, 0, -margin, 0 );
1413
-
1414
- // The view is now at the center of the screen and so is it's pivot point. Move its center such that when rotated, it snaps into the vertical position we need.
1415
- final int translationRaw = ( windowWidth / 2 ) - ( heightPx / 2 );
1416
- final int translationX = containsLeft ? -translationRaw : translationRaw;
1417
- adView.setTranslationX( translationX );
1418
-
1419
- // We have the view's center in the correct position. Now rotate it to snap into place.
1420
- adView.setRotation( 270 );
1421
-
1422
- // Store the ad view with format, so that it can be updated when the orientation changes.
1423
- mVerticalAdViewFormats.put( adUnitId, adFormat );
1424
- }
1425
-
1426
- // Hack alert: For the rotation and translation to be applied correctly, need to set the background color (Unity only, similar to what we do in Cross Promo).
1427
- relativeLayout.setBackgroundColor( Color.TRANSPARENT );
1428
- }
1429
1612
  }
1430
1613
  else
1431
1614
  {
@@ -1448,6 +1631,39 @@ public class AppLovinMAXModule
1448
1631
 
1449
1632
  // Utility Methods
1450
1633
 
1634
+ private void logInvalidAdFormat(MaxAdFormat adFormat)
1635
+ {
1636
+ logStackTrace( new IllegalStateException( "invalid ad format: " + adFormat ) );
1637
+ }
1638
+
1639
+ private void logStackTrace(Exception e)
1640
+ {
1641
+ e( Log.getStackTraceString( e ) );
1642
+ }
1643
+
1644
+ private static void logUninitializedAccessError(final String callingMethod)
1645
+ {
1646
+ e( "ERROR: Failed to execute " + callingMethod + "() - please ensure the AppLovin MAX React Native module has been initialized by calling 'AppLovinMAX.initialize(...);'!" );
1647
+ }
1648
+
1649
+ public static void d(final String message)
1650
+ {
1651
+ final String fullMessage = "[" + TAG + "] " + message;
1652
+ Log.d( SDK_TAG, fullMessage );
1653
+ }
1654
+
1655
+ public static void w(final String message)
1656
+ {
1657
+ final String fullMessage = "[" + TAG + "] " + message;
1658
+ Log.w( SDK_TAG, fullMessage );
1659
+ }
1660
+
1661
+ public static void e(final String message)
1662
+ {
1663
+ final String fullMessage = "[" + TAG + "] " + message;
1664
+ Log.e( SDK_TAG, fullMessage );
1665
+ }
1666
+
1451
1667
  private MaxAdFormat getDeviceSpecificBannerAdViewAdFormat()
1452
1668
  {
1453
1669
  return getDeviceSpecificBannerAdViewAdFormat( getReactApplicationContext() );
@@ -1490,6 +1706,13 @@ public class AppLovinMAXModule
1490
1706
  }
1491
1707
  }
1492
1708
 
1709
+ private static Point getOffsetPixels(final float xDp, final float yDp, final Context context)
1710
+ {
1711
+ return new Point( AppLovinSdkUtils.dpToPx( context, (int) xDp ), AppLovinSdkUtils.dpToPx( context, (int) yDp ) );
1712
+ }
1713
+
1714
+ // AD INFO
1715
+
1493
1716
  private WritableMap getAdInfo(final MaxAd ad)
1494
1717
  {
1495
1718
  WritableMap adInfo = Arguments.createMap();
@@ -1498,13 +1721,73 @@ public class AppLovinMAXModule
1498
1721
  adInfo.putString( "networkName", ad.getNetworkName() );
1499
1722
  adInfo.putString( "placement", !TextUtils.isEmpty( ad.getPlacement() ) ? ad.getPlacement() : "" );
1500
1723
  adInfo.putDouble( "revenue", ad.getRevenue() );
1724
+ adInfo.putMap( "waterfall", createAdWaterfallInfo( ad.getWaterfall() ) );
1501
1725
 
1502
1726
  return adInfo;
1503
1727
  }
1504
1728
 
1505
- private static Point getOffsetPixels(final float xDp, final float yDp, final Context context)
1729
+ // AD WATERFALL INFO
1730
+
1731
+ private WritableMap createAdWaterfallInfo(final MaxAdWaterfallInfo waterfallInfo)
1506
1732
  {
1507
- return new Point( AppLovinSdkUtils.dpToPx( context, (int) xDp ), AppLovinSdkUtils.dpToPx( context, (int) yDp ) );
1733
+ WritableMap waterfallInfoObject = Arguments.createMap();
1734
+ if ( waterfallInfo == null ) return waterfallInfoObject;
1735
+
1736
+ waterfallInfoObject.putString( "name", waterfallInfo.getName() );
1737
+ waterfallInfoObject.putString( "testName", waterfallInfo.getTestName() );
1738
+
1739
+ WritableArray networkResponsesArray = Arguments.createArray();
1740
+ for ( MaxNetworkResponseInfo response : waterfallInfo.getNetworkResponses() )
1741
+ {
1742
+ networkResponsesArray.pushMap( createNetworkResponseInfo( response ) );
1743
+ }
1744
+ waterfallInfoObject.putArray( "networkResponses", networkResponsesArray );
1745
+
1746
+ waterfallInfoObject.putDouble( "latencyMillis", waterfallInfo.getLatencyMillis() );
1747
+
1748
+ return waterfallInfoObject;
1749
+ }
1750
+
1751
+ private WritableMap createNetworkResponseInfo(final MaxNetworkResponseInfo response)
1752
+ {
1753
+ WritableMap networkResponseObject = Arguments.createMap();
1754
+ networkResponseObject.putInt( "adLoadState", response.getAdLoadState().ordinal() );
1755
+
1756
+ MaxMediatedNetworkInfo mediatedNetworkInfo = response.getMediatedNetwork();
1757
+ if ( mediatedNetworkInfo != null )
1758
+ {
1759
+ WritableMap networkInfoObject = Arguments.createMap();
1760
+ networkInfoObject.putString( "name", mediatedNetworkInfo.getName() );
1761
+ networkInfoObject.putString( "adapterClassName", mediatedNetworkInfo.getAdapterClassName() );
1762
+ networkInfoObject.putString( "adapterVersion", mediatedNetworkInfo.getAdapterVersion() );
1763
+ networkInfoObject.putString( "sdkVersion", mediatedNetworkInfo.getSdkVersion() );
1764
+
1765
+ networkResponseObject.putMap( "mediatedNetwork", networkInfoObject );
1766
+ }
1767
+
1768
+ Bundle credentialBundle = response.getCredentials();
1769
+ WritableMap credentials = Arguments.createMap();
1770
+ for ( String key : credentialBundle.keySet() )
1771
+ {
1772
+ String value = credentialBundle.getString( key, "" );
1773
+ credentials.putString( key, value );
1774
+ }
1775
+ networkResponseObject.putMap( "credentials", credentials );
1776
+
1777
+ MaxError error = response.getError();
1778
+ if ( error != null )
1779
+ {
1780
+ WritableMap errorObject = Arguments.createMap();
1781
+ errorObject.putString( "message", error.getMessage() );
1782
+ errorObject.putString( "adLoadFailureInfo", error.getAdLoadFailureInfo() );
1783
+ errorObject.putInt( "code", error.getCode() );
1784
+
1785
+ networkResponseObject.putMap( "error", errorObject );
1786
+ }
1787
+
1788
+ networkResponseObject.putDouble( "latencyMillis", response.getLatencyMillis() );
1789
+
1790
+ return networkResponseObject;
1508
1791
  }
1509
1792
 
1510
1793
  // React Native Bridge
@@ -1516,7 +1799,8 @@ public class AppLovinMAXModule
1516
1799
  .emit( name, params );
1517
1800
  }
1518
1801
 
1519
- @Override @Nullable
1802
+ @Override
1803
+ @Nullable
1520
1804
  public Map<String, Object> getConstants()
1521
1805
  {
1522
1806
  return super.getConstants();