react-native-applovin-max 3.1.0 → 3.2.2

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,15 +15,20 @@ 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;
@@ -45,6 +50,7 @@ import com.facebook.react.bridge.ReactContextBaseJavaModule;
45
50
  import com.facebook.react.bridge.ReactMethod;
46
51
  import com.facebook.react.bridge.ReadableArray;
47
52
  import com.facebook.react.bridge.ReadableMap;
53
+ import com.facebook.react.bridge.WritableArray;
48
54
  import com.facebook.react.bridge.WritableMap;
49
55
 
50
56
  import java.util.ArrayList;
@@ -66,7 +72,7 @@ import static com.facebook.react.modules.core.DeviceEventManagerModule.RCTDevice
66
72
  */
67
73
  public class AppLovinMAXModule
68
74
  extends ReactContextBaseJavaModule
69
- implements MaxAdListener, MaxAdViewAdListener, MaxRewardedAdListener
75
+ implements MaxAdListener, MaxAdViewAdListener, MaxRewardedAdListener, MaxAdRevenueListener
70
76
  {
71
77
  private static final String SDK_TAG = "AppLovinSdk";
72
78
  private static final String TAG = "AppLovinMAXModule";
@@ -82,6 +88,9 @@ public class AppLovinMAXModule
82
88
  private boolean isSdkInitialized;
83
89
  private AppLovinSdkConfiguration sdkConfiguration;
84
90
 
91
+ private WindowManager windowManager;
92
+ private int lastRotation;
93
+
85
94
  // Store these values if pub attempts to set it before initializing
86
95
  private String userIdToSet;
87
96
  private List<String> testDeviceAdvertisingIdsToSet;
@@ -98,7 +107,6 @@ public class AppLovinMAXModule
98
107
  private final Map<String, String> mAdViewPositions = new HashMap<>( 2 );
99
108
  private final Map<String, Point> mAdViewOffsets = new HashMap<>( 2 );
100
109
  private final Map<String, Integer> mAdViewWidths = new HashMap<>( 2 );
101
- private final Map<String, MaxAdFormat> mVerticalAdViewFormats = new HashMap<>( 2 );
102
110
  private final List<String> mAdUnitIdsToShowAfterCreate = new ArrayList<>( 2 );
103
111
  private final Set<String> mDisabledAdaptiveBannerAdUnitIds = new HashSet<>( 2 );
104
112
 
@@ -255,15 +263,24 @@ public class AppLovinMAXModule
255
263
  sdkConfiguration = configuration;
256
264
  isSdkInitialized = true;
257
265
 
258
- // 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.
259
271
  new OrientationEventListener( context )
260
272
  {
261
273
  @Override
262
274
  public void onOrientationChanged(final int orientation)
263
275
  {
264
- for ( final Map.Entry<String, MaxAdFormat> adUnitFormats : mVerticalAdViewFormats.entrySet() )
276
+ int newRotation = windowManager.getDefaultDisplay().getRotation();
277
+ if ( newRotation != lastRotation )
265
278
  {
266
- 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
+ }
267
284
  }
268
285
  }
269
286
  }.enable();
@@ -276,168 +293,6 @@ public class AppLovinMAXModule
276
293
  } );
277
294
  }
278
295
 
279
- // Data Passing
280
-
281
- @ReactMethod()
282
- public void setTargetingDataYearOfBirth(final int yearOfBirth)
283
- {
284
- if ( sdk == null )
285
- {
286
- logUninitializedAccessError( "setTargetingDataYearOfBirth" );
287
- return;
288
- }
289
-
290
- sdk.getTargetingData().setYearOfBirth( yearOfBirth <= 0 ? null : yearOfBirth );
291
- }
292
-
293
- @ReactMethod()
294
- public void setTargetingDataGender(final String gender)
295
- {
296
- if ( sdk == null )
297
- {
298
- logUninitializedAccessError( "setTargetingDataGender" );
299
- return;
300
- }
301
-
302
- AppLovinGender alGender = AppLovinGender.UNKNOWN;
303
-
304
- if ( "F".equals( gender ) )
305
- {
306
- alGender = AppLovinGender.FEMALE;
307
- }
308
- else if ( "M".equals( gender ) )
309
- {
310
- alGender = AppLovinGender.MALE;
311
- }
312
- else if ( "O".equals( gender ) )
313
- {
314
- alGender = AppLovinGender.OTHER;
315
- }
316
-
317
- sdk.getTargetingData().setGender( alGender );
318
- }
319
-
320
- @ReactMethod()
321
- public void setTargetingDataMaximumAdContentRating(final int maximumAdContentRating)
322
- {
323
- if ( sdk == null )
324
- {
325
- logUninitializedAccessError( "setTargetingDataMaximumAdContentRating" );
326
- return;
327
- }
328
-
329
- AppLovinAdContentRating rating = AppLovinAdContentRating.NONE;
330
-
331
- if ( maximumAdContentRating == 1 )
332
- {
333
- rating = AppLovinAdContentRating.ALL_AUDIENCES;
334
- }
335
- else if ( maximumAdContentRating == 2 )
336
- {
337
- rating = AppLovinAdContentRating.EVERYONE_OVER_TWELVE;
338
- }
339
- else if ( maximumAdContentRating == 3 )
340
- {
341
- rating = AppLovinAdContentRating.MATURE_AUDIENCES;
342
- }
343
-
344
- sdk.getTargetingData().setMaximumAdContentRating( rating );
345
- }
346
-
347
- @ReactMethod()
348
- public void setTargetingDataEmail(final String email)
349
- {
350
- if ( sdk == null )
351
- {
352
- logUninitializedAccessError( "setTargetingDataEmail" );
353
- return;
354
- }
355
-
356
- sdk.getTargetingData().setEmail( email );
357
- }
358
-
359
- @ReactMethod()
360
- public void setTargetingDataPhoneNumber(final String phoneNumber)
361
- {
362
- if ( sdk == null )
363
- {
364
- logUninitializedAccessError( "setTargetingDataPhoneNumber" );
365
- return;
366
- }
367
-
368
- sdk.getTargetingData().setPhoneNumber( phoneNumber );
369
- }
370
-
371
- @ReactMethod()
372
- public void setTargetingDataKeywords(final ReadableArray rawKeywords)
373
- {
374
- if ( sdk == null )
375
- {
376
- logUninitializedAccessError( "setTargetingDataKeywords" );
377
- return;
378
- }
379
-
380
- List<String> keywords = null;
381
-
382
- if ( rawKeywords != null )
383
- {
384
- keywords = new ArrayList<>( rawKeywords.size() );
385
- for ( Object rawKeyword : rawKeywords.toArrayList() )
386
- {
387
- keywords.add( (String) rawKeyword );
388
- }
389
- }
390
-
391
- sdk.getTargetingData().setKeywords( keywords );
392
- }
393
-
394
- @ReactMethod()
395
- public void setTargetingDataInterests(final ReadableArray rawInterests)
396
- {
397
- if ( sdk == null )
398
- {
399
- logUninitializedAccessError( "setTargetingDataInterests" );
400
- return;
401
- }
402
-
403
- List<String> interests = null;
404
-
405
- if ( rawInterests != null )
406
- {
407
- interests = new ArrayList<>( rawInterests.size() );
408
- for ( Object rawInterest : rawInterests.toArrayList() )
409
- {
410
- interests.add( (String) rawInterest );
411
- }
412
- }
413
-
414
- sdk.getTargetingData().setInterests( interests );
415
- }
416
-
417
- @ReactMethod()
418
- public void clearAllTargetingData()
419
- {
420
- if ( sdk == null )
421
- {
422
- logUninitializedAccessError( "clearAllTargetingData" );
423
- return;
424
- }
425
-
426
- sdk.getTargetingData().clearAll();
427
- }
428
-
429
- @ReactMethod()
430
- public void setLocationCollectionEnabled(final boolean locationCollectionEnabled)
431
- {
432
- if ( sdk == null )
433
- {
434
- logUninitializedAccessError( "setLocationCollectionEnabled" );
435
- return;
436
- }
437
-
438
- sdk.getSettings().setLocationCollectionEnabled( locationCollectionEnabled );
439
- }
440
-
441
296
  // General Public API
442
297
 
443
298
  @ReactMethod(isBlockingSynchronousMethod = true)
@@ -611,6 +466,180 @@ public class AppLovinMAXModule
611
466
  @ReactMethod()
612
467
  public void setTermsOfServiceUrl(final String urlString) {}
613
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
+
614
643
  // EVENT TRACKING
615
644
 
616
645
  @ReactMethod()
@@ -656,6 +685,12 @@ public class AppLovinMAXModule
656
685
  setAdViewPlacement( adUnitId, getDeviceSpecificBannerAdViewAdFormat(), placement );
657
686
  }
658
687
 
688
+ @ReactMethod()
689
+ public void setBannerCustomData(final String adUnitId, final String customData)
690
+ {
691
+ setAdViewCustomData( adUnitId, getDeviceSpecificBannerAdViewAdFormat(), customData );
692
+ }
693
+
659
694
  @ReactMethod()
660
695
  public void setBannerWidth(final String adUnitId, final int widthDp)
661
696
  {
@@ -718,6 +753,12 @@ public class AppLovinMAXModule
718
753
  setAdViewPlacement( adUnitId, MaxAdFormat.MREC, placement );
719
754
  }
720
755
 
756
+ @ReactMethod()
757
+ public void setMRecCustomData(final String adUnitId, final String customData)
758
+ {
759
+ setAdViewCustomData( adUnitId, MaxAdFormat.MREC, customData );
760
+ }
761
+
721
762
  @ReactMethod()
722
763
  public void updateMRecPosition(final String adUnitId, final String mrecPosition)
723
764
  {
@@ -765,16 +806,10 @@ public class AppLovinMAXModule
765
806
  }
766
807
 
767
808
  @ReactMethod()
768
- public void showInterstitial(final String adUnitId)
769
- {
770
- showInterstitialWithPlacement( adUnitId, null );
771
- }
772
-
773
- @ReactMethod()
774
- public void showInterstitialWithPlacement(final String adUnitId, final String placement)
809
+ public void showInterstitial(final String adUnitId, final String placement, final String customData)
775
810
  {
776
811
  MaxInterstitialAd interstitial = retrieveInterstitial( adUnitId );
777
- interstitial.showAd( placement );
812
+ interstitial.showAd( placement, customData );
778
813
  }
779
814
 
780
815
  @ReactMethod()
@@ -807,16 +842,10 @@ public class AppLovinMAXModule
807
842
  }
808
843
 
809
844
  @ReactMethod()
810
- public void showRewardedAd(final String adUnitId)
811
- {
812
- showRewardedAdWithPlacement( adUnitId, null );
813
- }
814
-
815
- @ReactMethod()
816
- public void showRewardedAdWithPlacement(final String adUnitId, final String placement)
845
+ public void showRewardedAd(final String adUnitId, final String placement, final String customData)
817
846
  {
818
847
  MaxRewardedAd rewardedAd = retrieveRewardedAd( adUnitId );
819
- rewardedAd.showAd( placement );
848
+ rewardedAd.showAd( placement, customData );
820
849
  }
821
850
 
822
851
  @ReactMethod()
@@ -916,6 +945,7 @@ public class AppLovinMAXModule
916
945
  params.putInt( "code", error.getCode() );
917
946
  params.putString( "message", error.getMessage() );
918
947
  params.putString( "adLoadFailureInfo", error.getAdLoadFailureInfo() );
948
+ params.putMap( "waterfall", createAdWaterfallInfo( error.getWaterfall() ) );
919
949
  }
920
950
  else
921
951
  {
@@ -1045,6 +1075,41 @@ public class AppLovinMAXModule
1045
1075
  sendReactNativeEvent( ( MaxAdFormat.MREC == adFormat ) ? "OnMRecAdCollapsedEvent" : "OnBannerAdCollapsedEvent", getAdInfo( ad ) );
1046
1076
  }
1047
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
+
1048
1113
  @Override
1049
1114
  public void onRewardedVideoCompleted(final MaxAd ad)
1050
1115
  {
@@ -1144,6 +1209,27 @@ public class AppLovinMAXModule
1144
1209
  } );
1145
1210
  }
1146
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
+
1147
1233
  private void setAdViewWidth(final String adUnitId, final int widthDp, final MaxAdFormat adFormat)
1148
1234
  {
1149
1235
  getReactApplicationContext().runOnUiQueueThread( new Runnable()
@@ -1260,6 +1346,7 @@ public class AppLovinMAXModule
1260
1346
  }
1261
1347
 
1262
1348
  adView.setListener( null );
1349
+ adView.setRevenueListener( null );
1263
1350
  adView.destroy();
1264
1351
 
1265
1352
  mAdViews.remove( adUnitId );
@@ -1267,7 +1354,6 @@ public class AppLovinMAXModule
1267
1354
  mAdViewPositions.remove( adUnitId );
1268
1355
  mAdViewOffsets.remove( adUnitId );
1269
1356
  mAdViewWidths.remove( adUnitId );
1270
- mVerticalAdViewFormats.remove( adUnitId );
1271
1357
  }
1272
1358
  } );
1273
1359
  }
@@ -1348,39 +1434,6 @@ public class AppLovinMAXModule
1348
1434
  } );
1349
1435
  }
1350
1436
 
1351
- private void logInvalidAdFormat(MaxAdFormat adFormat)
1352
- {
1353
- logStackTrace( new IllegalStateException( "invalid ad format: " + adFormat ) );
1354
- }
1355
-
1356
- private void logStackTrace(Exception e)
1357
- {
1358
- e( Log.getStackTraceString( e ) );
1359
- }
1360
-
1361
- private static void logUninitializedAccessError(final String callingMethod)
1362
- {
1363
- e( "ERROR: Failed to execute " + callingMethod + "() - please ensure the AppLovin MAX React Native module has been initialized by calling 'AppLovinMAX.initialize(...);'!" );
1364
- }
1365
-
1366
- public static void d(final String message)
1367
- {
1368
- final String fullMessage = "[" + TAG + "] " + message;
1369
- Log.d( SDK_TAG, fullMessage );
1370
- }
1371
-
1372
- public static void w(final String message)
1373
- {
1374
- final String fullMessage = "[" + TAG + "] " + message;
1375
- Log.w( SDK_TAG, fullMessage );
1376
- }
1377
-
1378
- public static void e(final String message)
1379
- {
1380
- final String fullMessage = "[" + TAG + "] " + message;
1381
- Log.e( SDK_TAG, fullMessage );
1382
- }
1383
-
1384
1437
  @Nullable
1385
1438
  private MaxInterstitialAd retrieveInterstitial(String adUnitId)
1386
1439
  {
@@ -1392,6 +1445,7 @@ public class AppLovinMAXModule
1392
1445
  {
1393
1446
  result = new MaxInterstitialAd( adUnitId, sdk, currentActivity );
1394
1447
  result.setListener( this );
1448
+ result.setRevenueListener( this );
1395
1449
 
1396
1450
  mInterstitials.put( adUnitId, result );
1397
1451
  }
@@ -1410,6 +1464,7 @@ public class AppLovinMAXModule
1410
1464
  {
1411
1465
  result = MaxRewardedAd.getInstance( adUnitId, sdk, currentActivity );
1412
1466
  result.setListener( this );
1467
+ result.setRevenueListener( this );
1413
1468
 
1414
1469
  mRewardedAds.put( adUnitId, result );
1415
1470
  }
@@ -1429,6 +1484,7 @@ public class AppLovinMAXModule
1429
1484
  {
1430
1485
  result = new MaxAdView( adUnitId, adFormat, sdk, maybeGetCurrentActivity() );
1431
1486
  result.setListener( this );
1487
+ result.setRevenueListener( this );
1432
1488
 
1433
1489
  mAdViews.put( adUnitId, result );
1434
1490
  mAdViewPositions.put( adUnitId, adViewPosition );
@@ -1515,8 +1571,6 @@ public class AppLovinMAXModule
1515
1571
  adView.setTranslationX( 0 );
1516
1572
  params.setMargins( 0, 0, 0, 0 );
1517
1573
 
1518
- mVerticalAdViewFormats.remove( adUnitId );
1519
-
1520
1574
  if ( "centered".equalsIgnoreCase( adViewPosition ) )
1521
1575
  {
1522
1576
  gravity = Gravity.CENTER_VERTICAL | Gravity.CENTER_HORIZONTAL;
@@ -1555,66 +1609,6 @@ public class AppLovinMAXModule
1555
1609
  {
1556
1610
  params.width = RelativeLayout.LayoutParams.MATCH_PARENT;
1557
1611
  }
1558
-
1559
- // Check if the publisher wants the ad view to be vertical and update the position accordingly ('CenterLeft' or 'CenterRight').
1560
- final boolean containsLeft = adViewPosition.contains( "left" );
1561
- final boolean containsRight = adViewPosition.contains( "right" );
1562
- if ( containsLeft || containsRight )
1563
- {
1564
- // First, center the ad view in the view.
1565
- gravity |= Gravity.CENTER_VERTICAL;
1566
-
1567
- // For banners, set the width to the height of the screen to span the ad across the screen after it is rotated.
1568
- // 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.
1569
- if ( MaxAdFormat.MREC == adFormat )
1570
- {
1571
- gravity |= adViewPosition.contains( "left" ) ? Gravity.LEFT : Gravity.RIGHT;
1572
- }
1573
- else
1574
- {
1575
- /* Align the center of the view such that when rotated it snaps into place.
1576
- *
1577
- * +---+---+-------+
1578
- * | | |
1579
- * | | |
1580
- * | | |
1581
- * | | |
1582
- * | | |
1583
- * | | |
1584
- * +-------------+---+-----------+--+
1585
- * | | + | + | |
1586
- * +-------------+---+-----------+--+
1587
- * | | |
1588
- * | ^ | ^ |
1589
- * | +-----+ |
1590
- * Translation |
1591
- * | | |
1592
- * | | |
1593
- * +---+-----------+
1594
- */
1595
-
1596
- final int windowWidth = windowRect.width();
1597
- final int windowHeight = windowRect.height();
1598
- final int longSide = Math.max( windowWidth, windowHeight );
1599
- final int shortSide = Math.min( windowWidth, windowHeight );
1600
- final int margin = ( longSide - shortSide ) / 2;
1601
- params.setMargins( -margin, 0, -margin, 0 );
1602
-
1603
- // 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.
1604
- final int translationRaw = ( windowWidth / 2 ) - ( heightPx / 2 );
1605
- final int translationX = containsLeft ? -translationRaw : translationRaw;
1606
- adView.setTranslationX( translationX );
1607
-
1608
- // We have the view's center in the correct position. Now rotate it to snap into place.
1609
- adView.setRotation( 270 );
1610
-
1611
- // Store the ad view with format, so that it can be updated when the orientation changes.
1612
- mVerticalAdViewFormats.put( adUnitId, adFormat );
1613
- }
1614
-
1615
- // 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).
1616
- relativeLayout.setBackgroundColor( Color.TRANSPARENT );
1617
- }
1618
1612
  }
1619
1613
  else
1620
1614
  {
@@ -1637,6 +1631,39 @@ public class AppLovinMAXModule
1637
1631
 
1638
1632
  // Utility Methods
1639
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
+
1640
1667
  private MaxAdFormat getDeviceSpecificBannerAdViewAdFormat()
1641
1668
  {
1642
1669
  return getDeviceSpecificBannerAdViewAdFormat( getReactApplicationContext() );
@@ -1679,6 +1706,13 @@ public class AppLovinMAXModule
1679
1706
  }
1680
1707
  }
1681
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
+
1682
1716
  private WritableMap getAdInfo(final MaxAd ad)
1683
1717
  {
1684
1718
  WritableMap adInfo = Arguments.createMap();
@@ -1687,13 +1721,74 @@ public class AppLovinMAXModule
1687
1721
  adInfo.putString( "networkName", ad.getNetworkName() );
1688
1722
  adInfo.putString( "placement", !TextUtils.isEmpty( ad.getPlacement() ) ? ad.getPlacement() : "" );
1689
1723
  adInfo.putDouble( "revenue", ad.getRevenue() );
1724
+ adInfo.putMap( "waterfall", createAdWaterfallInfo( ad.getWaterfall() ) );
1725
+ adInfo.putString( "dspName", !TextUtils.isEmpty( ad.getDspName() ) ? ad.getDspName() : "" );
1690
1726
 
1691
1727
  return adInfo;
1692
1728
  }
1693
1729
 
1694
- private static Point getOffsetPixels(final float xDp, final float yDp, final Context context)
1730
+ // AD WATERFALL INFO
1731
+
1732
+ private WritableMap createAdWaterfallInfo(final MaxAdWaterfallInfo waterfallInfo)
1695
1733
  {
1696
- return new Point( AppLovinSdkUtils.dpToPx( context, (int) xDp ), AppLovinSdkUtils.dpToPx( context, (int) yDp ) );
1734
+ WritableMap waterfallInfoObject = Arguments.createMap();
1735
+ if ( waterfallInfo == null ) return waterfallInfoObject;
1736
+
1737
+ waterfallInfoObject.putString( "name", waterfallInfo.getName() );
1738
+ waterfallInfoObject.putString( "testName", waterfallInfo.getTestName() );
1739
+
1740
+ WritableArray networkResponsesArray = Arguments.createArray();
1741
+ for ( MaxNetworkResponseInfo response : waterfallInfo.getNetworkResponses() )
1742
+ {
1743
+ networkResponsesArray.pushMap( createNetworkResponseInfo( response ) );
1744
+ }
1745
+ waterfallInfoObject.putArray( "networkResponses", networkResponsesArray );
1746
+
1747
+ waterfallInfoObject.putDouble( "latencyMillis", waterfallInfo.getLatencyMillis() );
1748
+
1749
+ return waterfallInfoObject;
1750
+ }
1751
+
1752
+ private WritableMap createNetworkResponseInfo(final MaxNetworkResponseInfo response)
1753
+ {
1754
+ WritableMap networkResponseObject = Arguments.createMap();
1755
+ networkResponseObject.putInt( "adLoadState", response.getAdLoadState().ordinal() );
1756
+
1757
+ MaxMediatedNetworkInfo mediatedNetworkInfo = response.getMediatedNetwork();
1758
+ if ( mediatedNetworkInfo != null )
1759
+ {
1760
+ WritableMap networkInfoObject = Arguments.createMap();
1761
+ networkInfoObject.putString( "name", mediatedNetworkInfo.getName() );
1762
+ networkInfoObject.putString( "adapterClassName", mediatedNetworkInfo.getAdapterClassName() );
1763
+ networkInfoObject.putString( "adapterVersion", mediatedNetworkInfo.getAdapterVersion() );
1764
+ networkInfoObject.putString( "sdkVersion", mediatedNetworkInfo.getSdkVersion() );
1765
+
1766
+ networkResponseObject.putMap( "mediatedNetwork", networkInfoObject );
1767
+ }
1768
+
1769
+ Bundle credentialBundle = response.getCredentials();
1770
+ WritableMap credentials = Arguments.createMap();
1771
+ for ( String key : credentialBundle.keySet() )
1772
+ {
1773
+ String value = credentialBundle.getString( key, "" );
1774
+ credentials.putString( key, value );
1775
+ }
1776
+ networkResponseObject.putMap( "credentials", credentials );
1777
+
1778
+ MaxError error = response.getError();
1779
+ if ( error != null )
1780
+ {
1781
+ WritableMap errorObject = Arguments.createMap();
1782
+ errorObject.putString( "message", error.getMessage() );
1783
+ errorObject.putString( "adLoadFailureInfo", error.getAdLoadFailureInfo() );
1784
+ errorObject.putInt( "code", error.getCode() );
1785
+
1786
+ networkResponseObject.putMap( "error", errorObject );
1787
+ }
1788
+
1789
+ networkResponseObject.putDouble( "latencyMillis", response.getLatencyMillis() );
1790
+
1791
+ return networkResponseObject;
1697
1792
  }
1698
1793
 
1699
1794
  // React Native Bridge
@@ -1705,7 +1800,8 @@ public class AppLovinMAXModule
1705
1800
  .emit( name, params );
1706
1801
  }
1707
1802
 
1708
- @Override @Nullable
1803
+ @Override
1804
+ @Nullable
1709
1805
  public Map<String, Object> getConstants()
1710
1806
  {
1711
1807
  return super.getConstants();