From 05226df630c623da2c4b72ca0920a854d498e409 Mon Sep 17 00:00:00 2001 From: Thomas So Date: Tue, 17 Jul 2018 16:21:20 -0700 Subject: [PATCH 01/10] Initial banner advanced bidding implementation --- .../com/applovin/mediation/AppLovinUtils.java | 45 +++++- .../applovin/mediation/ApplovinAdapter.java | 28 +--- .../mediation/rtb/AppLovinBannerRenderer.java | 152 ++++++++++++++++++ .../mediation/rtb/AppLovinRtbAdapter.java | 139 ++++++++++++++++ 4 files changed, 335 insertions(+), 29 deletions(-) create mode 100644 ThirdPartyAdapters/applovin/applovin/src/main/java/com/applovin/mediation/rtb/AppLovinBannerRenderer.java create mode 100644 ThirdPartyAdapters/applovin/applovin/src/main/java/com/applovin/mediation/rtb/AppLovinRtbAdapter.java diff --git a/ThirdPartyAdapters/applovin/applovin/src/main/java/com/applovin/mediation/AppLovinUtils.java b/ThirdPartyAdapters/applovin/applovin/src/main/java/com/applovin/mediation/AppLovinUtils.java index efb3d3b09..5fb2b9fb9 100644 --- a/ThirdPartyAdapters/applovin/applovin/src/main/java/com/applovin/mediation/AppLovinUtils.java +++ b/ThirdPartyAdapters/applovin/applovin/src/main/java/com/applovin/mediation/AppLovinUtils.java @@ -4,18 +4,25 @@ import android.os.Bundle; import android.text.TextUtils; +import com.applovin.sdk.AppLovinAdSize; import com.applovin.sdk.AppLovinErrorCodes; import com.applovin.sdk.AppLovinMediationProvider; import com.applovin.sdk.AppLovinSdk; import com.applovin.sdk.AppLovinSdkSettings; +import com.applovin.sdk.BuildConfig; import com.google.android.gms.ads.AdRequest; +import com.google.android.gms.ads.AdSize; /* * A helper class used by {@link AppLovinAdapter}. */ -class AppLovinUtils { +public class AppLovinUtils +{ private static final String DEFAULT_ZONE = ""; + private static final int BANNER_STANDARD_HEIGHT = 50; + private static final int BANNER_HEIGHT_OFFSET_TOLERANCE = 10; + /** * Keys for retrieving values from the server parameters. */ @@ -29,8 +36,9 @@ private static class ServerParameterKeys { * Retrieves the appropriate instance of AppLovin's SDK from the SDK key given in the server * parameters, or Android Manifest. */ - static AppLovinSdk retrieveSdk(Bundle serverParameters, Context context) { - final String sdkKey = serverParameters.getString(ServerParameterKeys.SDK_KEY); + public static AppLovinSdk retrieveSdk(Bundle serverParameters, Context context) + { + final String sdkKey = (serverParameters != null) ? serverParameters.getString( ServerParameterKeys.SDK_KEY ) : null; final AppLovinSdk sdk; if (!TextUtils.isEmpty(sdkKey)) { @@ -93,4 +101,35 @@ static int toAdMobErrorCode(int applovinErrorCode) { return AdRequest.ERROR_CODE_INTERNAL_ERROR; } } + + /** + * Get the {@link AppLovinAdSize} from a given {@link AdSize} from AdMob. + */ + public static AppLovinAdSize appLovinAdSizeFromAdMobAdSize(AdSize adSize) + { + final boolean isSmartBanner = ( adSize.getWidth() == AdSize.FULL_WIDTH ) && + ( adSize.getHeight() == AdSize.AUTO_HEIGHT ); + + if ( AdSize.BANNER.equals( adSize ) || AdSize.LARGE_BANNER.equals( adSize ) || isSmartBanner ) + { + return AppLovinAdSize.BANNER; + } + else if ( AdSize.MEDIUM_RECTANGLE.equals( adSize ) ) + { + return AppLovinAdSize.MREC; + } + else if ( AdSize.LEADERBOARD.equals( adSize ) ) + { + return AppLovinAdSize.LEADER; + } + + // Assume fluid width, and check for height with offset tolerance + final int offset = Math.abs( BANNER_STANDARD_HEIGHT - adSize.getHeight() ); + if ( offset <= BANNER_HEIGHT_OFFSET_TOLERANCE ) + { + return AppLovinAdSize.BANNER; + } + + return null; + } } diff --git a/ThirdPartyAdapters/applovin/applovin/src/main/java/com/applovin/mediation/ApplovinAdapter.java b/ThirdPartyAdapters/applovin/applovin/src/main/java/com/applovin/mediation/ApplovinAdapter.java index 9518c8dcb..3b8d8f67a 100644 --- a/ThirdPartyAdapters/applovin/applovin/src/main/java/com/applovin/mediation/ApplovinAdapter.java +++ b/ThirdPartyAdapters/applovin/applovin/src/main/java/com/applovin/mediation/ApplovinAdapter.java @@ -43,10 +43,7 @@ public class ApplovinAdapter implements MediationBannerAdapter, MediationInterstitialAdapter, MediationRewardedVideoAdAdapter, OnContextChangedListener { private static final boolean LOGGING_ENABLED = true; - private static final String DEFAULT_ZONE = ""; - - private static final int BANNER_STANDARD_HEIGHT = 50; - private static final int BANNER_HEIGHT_OFFSET_TOLERANCE = 10; + private static final String DEFAULT_ZONE = ""; // Interstitial globals. private static final HashMap> INTERSTITIAL_AD_QUEUES = @@ -338,9 +335,9 @@ public void requestBannerAd(Context context, + mZoneId + " and placement: " + mPlacement); // Convert requested size to AppLovin Ad Size. - final AppLovinAdSize appLovinAdSize = appLovinAdSizeFromAdMobAdSize(adSize); if (appLovinAdSize != null) { mAdView = new AppLovinAdView(mSdk, appLovinAdSize, context); + final AppLovinAdSize appLovinAdSize = AppLovinUtils.appLovinAdSizeFromAdMobAdSize( adSize ); final AppLovinBannerAdListener listener = new AppLovinBannerAdListener( mZoneId, mPlacement, mAdView, this, mediationBannerListener); @@ -372,27 +369,6 @@ public View getBannerView() { } //endregion - private AppLovinAdSize appLovinAdSizeFromAdMobAdSize(AdSize adSize) { - final boolean isSmartBanner = (adSize.getWidth() == AdSize.FULL_WIDTH) && - (adSize.getHeight() == AdSize.AUTO_HEIGHT); - - if (AdSize.BANNER.equals(adSize) || AdSize.LARGE_BANNER.equals(adSize) || isSmartBanner) { - return AppLovinAdSize.BANNER; - } else if (AdSize.MEDIUM_RECTANGLE.equals(adSize)) { - return AppLovinAdSize.MREC; - } else if (AdSize.LEADERBOARD.equals(adSize)) { - return AppLovinAdSize.LEADER; - } - - // Assume fluid width, and check for height with offset tolerance - final int offset = Math.abs( BANNER_STANDARD_HEIGHT - adSize.getHeight() ); - if (offset <= BANNER_HEIGHT_OFFSET_TOLERANCE) { - return AppLovinAdSize.BANNER; - } - - return null; - } - //region MediationAdapter. @Override public void onPause() { diff --git a/ThirdPartyAdapters/applovin/applovin/src/main/java/com/applovin/mediation/rtb/AppLovinBannerRenderer.java b/ThirdPartyAdapters/applovin/applovin/src/main/java/com/applovin/mediation/rtb/AppLovinBannerRenderer.java new file mode 100644 index 000000000..fbabc2474 --- /dev/null +++ b/ThirdPartyAdapters/applovin/applovin/src/main/java/com/applovin/mediation/rtb/AppLovinBannerRenderer.java @@ -0,0 +1,152 @@ +package com.applovin.mediation.rtb; + +import android.support.annotation.NonNull; +import android.util.Log; +import android.view.View; + +import com.applovin.adview.AppLovinAdView; +import com.applovin.adview.AppLovinAdViewDisplayErrorCode; +import com.applovin.adview.AppLovinAdViewEventListener; +import com.applovin.mediation.AppLovinUtils; +import com.applovin.sdk.AppLovinAd; +import com.applovin.sdk.AppLovinAdClickListener; +import com.applovin.sdk.AppLovinAdDisplayListener; +import com.applovin.sdk.AppLovinAdLoadListener; +import com.applovin.sdk.AppLovinAdSize; +import com.applovin.sdk.AppLovinSdk; +import com.google.android.gms.ads.AdSize; +import com.google.android.gms.ads.mediation.rtb.AdRenderingCallback; +import com.google.android.gms.ads.mediation.rtb.BannerAd; +import com.google.android.gms.ads.mediation.rtb.BannerEventListener; +import com.google.android.gms.ads.mediation.rtb.RtbAdConfiguration; + +/** + * Created by Thomas So on July 17 2018 + */ +public final class AppLovinBannerRenderer + implements BannerAd, AppLovinAdLoadListener, AppLovinAdDisplayListener, AppLovinAdClickListener, AppLovinAdViewEventListener +{ + private static final String TAG = "AppLovinBannerRenderer"; + + /** + * Data used to render an RTB banner ad. + */ + private final RtbAdConfiguration adConfiguration; + + /** + * Callback object to notify the Google Mobile Ads SDK if ad rendering succeeded or failed. + */ + private final AdRenderingCallback callback; + + /** + * Listener object to notify the Google Mobile Ads SDK of banner presentation events. + */ + private BannerEventListener listener; + + private final AppLovinSdk sdk; + private final AppLovinAdSize adSize; + private AppLovinAdView adView; + + public AppLovinBannerRenderer(RtbAdConfiguration adConfiguration, + AdSize adSize, + AdRenderingCallback callback) + { + this.adConfiguration = adConfiguration; + this.callback = callback; + + // Convert requested size to AppLovin Ad Size. + this.adSize = AppLovinUtils.appLovinAdSizeFromAdMobAdSize( adSize ); + this.sdk = AppLovinUtils.retrieveSdk( adConfiguration.serverParameters, adConfiguration.context ); + } + + public void render() + { + if ( adSize != null ) + { + adView = new AppLovinAdView( sdk, adSize, adConfiguration.context ); + adView.setAdDisplayListener( this ); + adView.setAdClickListener( this ); + adView.setAdViewEventListener( this ); + sdk.getAdService().loadNextAdForAdToken( adConfiguration.bidResponse, this ); + } + else + { + callback.onFailure( "Failed to request banner with unsupported size" ); + } + } + + @NonNull + @Override + public View getView() + { + return adView; + } + + //region AppLovin Listeners + @Override + public void adReceived(AppLovinAd ad) + { + Log.d( TAG, "Banner did load ad: " + ad.getAdIdNumber() ); + + listener = callback.onSuccess( AppLovinBannerRenderer.this ); + + adView.renderAd( ad ); + } + + @Override + public void failedToReceiveAd(int code) + { + Log.e( TAG, "Failed to load banner ad with error: " + code ); + + int admobErrorCode = AppLovinUtils.toAdMobErrorCode( code ); + callback.onFailure( Integer.toString( admobErrorCode ) ); + } + + @Override + public void adDisplayed(AppLovinAd ad) + { + Log.d( TAG, "Banner dismissed" ); + listener.reportAdImpression(); + } + + @Override + public void adHidden(AppLovinAd ad) + { + Log.d( TAG, "Banner hidden" ); + } + + @Override + public void adClicked(AppLovinAd ad) + { + Log.d( TAG, "Banner clicked" ); + listener.reportAdClicked(); + } + + @Override + public void adOpenedFullscreen(AppLovinAd ad, AppLovinAdView adView) + { + Log.d( TAG, "Banner opened fullscreen" ); + listener.onAdOpened(); + } + + @Override + public void adClosedFullscreen(AppLovinAd ad, AppLovinAdView adView) + { + Log.d( TAG, "Banner closed fullscreen" ); + listener.onAdClosed(); + } + + @Override + public void adLeftApplication(AppLovinAd ad, AppLovinAdView adView) + { + Log.d( TAG, "Banner left application" ); + listener.onAdLeftApplication(); + } + + @Override + public void adFailedToDisplay(AppLovinAd ad, AppLovinAdView adView, AppLovinAdViewDisplayErrorCode code) + { + Log.e( TAG, "Banner failed to display: " + code ); + } + //endregion +} diff --git a/ThirdPartyAdapters/applovin/applovin/src/main/java/com/applovin/mediation/rtb/AppLovinRtbAdapter.java b/ThirdPartyAdapters/applovin/applovin/src/main/java/com/applovin/mediation/rtb/AppLovinRtbAdapter.java new file mode 100644 index 000000000..6240799f3 --- /dev/null +++ b/ThirdPartyAdapters/applovin/applovin/src/main/java/com/applovin/mediation/rtb/AppLovinRtbAdapter.java @@ -0,0 +1,139 @@ +package com.applovin.mediation.rtb; + +import android.app.Application; +import android.util.Log; + +import com.applovin.mediation.AppLovinUtils; +import com.applovin.sdk.AppLovinSdk; +import com.applovin.sdk.AppLovinSdkUtils; +import com.google.ads.mediation.sample.adapter.BuildConfig; +import com.google.ads.mediation.sample.adapter.rtb.SampleRtbBannerRenderer; +import com.google.ads.mediation.sample.adapter.rtb.SampleRtbInterstitialRenderer; +import com.google.ads.mediation.sample.adapter.rtb.SampleRtbRewardedRenderer; +import com.google.android.gms.ads.AdSize; +import com.google.android.gms.ads.mediation.rtb.AdRenderingCallback; +import com.google.android.gms.ads.mediation.rtb.BannerAd; +import com.google.android.gms.ads.mediation.rtb.BannerEventListener; +import com.google.android.gms.ads.mediation.rtb.InterstitialAd; +import com.google.android.gms.ads.mediation.rtb.InterstitialEventListener; +import com.google.android.gms.ads.mediation.rtb.RewardedAd; +import com.google.android.gms.ads.mediation.rtb.RewardedEventListener; +import com.google.android.gms.ads.mediation.rtb.RtbAdConfiguration; +import com.google.android.gms.ads.mediation.rtb.RtbAdapter; +import com.google.android.gms.ads.mediation.rtb.RtbConfiguration; +import com.google.android.gms.ads.mediation.rtb.RtbSignalData; +import com.google.android.gms.ads.mediation.rtb.SignalCallbacks; +import com.google.android.gms.ads.mediation.rtb.VersionInfo; + +import java.util.List; + +/** + * Created by Thomas So on July 17 2018 + */ +public class AppLovinRtbAdapter + extends RtbAdapter +{ + private static final String TAG = AppLovinRtbAdapter.class.getSimpleName(); + + // @Override + // Why is this not in the base adapter + public void setUp() + { + AppLovinSdk.getInstance( new Application() ).initializeSdk(); + } + + @Override + public void initialize() + { + AppLovinSdk.getInstance( new Application() ).initializeSdk(); + } + + @Override + public void updateConfiguration(final List list) + { + super.updateConfiguration( list ); + } + + @Override + public VersionInfo getSdkVersion() + { + String versionString = AppLovinSdk.VERSION; + String splits[] = versionString.split( "\\." ); + int major = Integer.parseInt( splits[0] ); + int minor = Integer.parseInt( splits[1] ); + int patch = Integer.parseInt( splits[2] ); + + return new VersionInfo( major, minor, patch ); + } + + @Override + public VersionInfo getAdapterVersion() + { + String versionString = BuildConfig.VERSION_NAME; + String splits[] = versionString.split( "\\." ); + int major = Integer.parseInt( splits[0] ); + int minor = Integer.parseInt( splits[1] ); + // Adapter versions have 2 patch versions. Multiply the first patch by 100. + int micro = Integer.parseInt( splits[2] ) * 100 + Integer.parseInt( splits[3] ); + + return new VersionInfo( major, minor, micro ); + } + + @Override + public void collectSignals(final RtbSignalData rtbSignalData, final SignalCallbacks signalCallbacks) + { + // TODO: I hope that we do not use the SDK Key and Context from here to initialize SDK / get bid token with... + // Check if the publisher provided extra parameters + if ( rtbSignalData.extras != null ) + { + Log.i( TAG, "Extras that adapter gets: " + rtbSignalData.extras ); + } + + + AppLovinSdk sdk = AppLovinUtils.retrieveSdk( rtbSignalData.extras, rtbSignalData.context ); + String bidToken = sdk.getAdService().getBidToken(); + + Log.i( TAG, "Generated bid token: " + bidToken ); + + signalCallbacks.onSuccess( bidToken ); + } + + @Override + public void renderBannerAd(RtbAdConfiguration adConfiguration, AdSize adSize, AdRenderingCallback callback) + { + AppLovinBannerRenderer bannerRenderer = new AppLovinBannerRenderer( adConfiguration, adSize, callback ); + bannerRenderer.render(); + } + + @Override + public void renderInterstitialAd( + RtbAdConfiguration adConfiguration, + AdRenderingCallback callback) + { + Log.e( "Test", "renderInterstitial" ); + Log.e( "Test", "Bid Response: " + adConfiguration.bidResponse ); + if ( adConfiguration.mediationExtras != null ) + { + Log.e( "Test", "Extras that renderInterstitial gets: " + adConfiguration.mediationExtras.toString() ); + } + SampleRtbInterstitialRenderer interstitialRenderer = + new SampleRtbInterstitialRenderer( adConfiguration, callback ); + interstitialRenderer.render(); + } + + @Override + public void renderRewardedAd( + RtbAdConfiguration adConfiguration, + AdRenderingCallback callback) + { + Log.e( "Test", "renderRewarded" ); + Log.e( "Test", "Bid Response: " + adConfiguration.bidResponse ); + if ( adConfiguration.mediationExtras != null ) + { + Log.e( "Test", "Extras that renderRewarded gets: " + adConfiguration.mediationExtras.toString() ); + } + SampleRtbRewardedRenderer rewardedRenderer = + new SampleRtbRewardedRenderer( adConfiguration, callback ); + rewardedRenderer.render(); + } +} From 8d11d4f04c531d08cfe3b5ab9db2c594de14f505 Mon Sep 17 00:00:00 2001 From: Thomas So Date: Tue, 17 Jul 2018 16:46:20 -0700 Subject: [PATCH 02/10] Clean up code for Chris --- .../mediation/rtb/AppLovinRtbAdapter.java | 51 +++++++------------ 1 file changed, 17 insertions(+), 34 deletions(-) diff --git a/ThirdPartyAdapters/applovin/applovin/src/main/java/com/applovin/mediation/rtb/AppLovinRtbAdapter.java b/ThirdPartyAdapters/applovin/applovin/src/main/java/com/applovin/mediation/rtb/AppLovinRtbAdapter.java index 6240799f3..79f35cfe9 100644 --- a/ThirdPartyAdapters/applovin/applovin/src/main/java/com/applovin/mediation/rtb/AppLovinRtbAdapter.java +++ b/ThirdPartyAdapters/applovin/applovin/src/main/java/com/applovin/mediation/rtb/AppLovinRtbAdapter.java @@ -1,15 +1,12 @@ package com.applovin.mediation.rtb; import android.app.Application; +import android.text.TextUtils; import android.util.Log; import com.applovin.mediation.AppLovinUtils; import com.applovin.sdk.AppLovinSdk; -import com.applovin.sdk.AppLovinSdkUtils; import com.google.ads.mediation.sample.adapter.BuildConfig; -import com.google.ads.mediation.sample.adapter.rtb.SampleRtbBannerRenderer; -import com.google.ads.mediation.sample.adapter.rtb.SampleRtbInterstitialRenderer; -import com.google.ads.mediation.sample.adapter.rtb.SampleRtbRewardedRenderer; import com.google.android.gms.ads.AdSize; import com.google.android.gms.ads.mediation.rtb.AdRenderingCallback; import com.google.android.gms.ads.mediation.rtb.BannerAd; @@ -80,22 +77,28 @@ public VersionInfo getAdapterVersion() } @Override - public void collectSignals(final RtbSignalData rtbSignalData, final SignalCallbacks signalCallbacks) + public void collectSignals(RtbSignalData rtbSignalData, SignalCallbacks signalCallbacks) { // TODO: I hope that we do not use the SDK Key and Context from here to initialize SDK / get bid token with... // Check if the publisher provided extra parameters if ( rtbSignalData.extras != null ) { - Log.i( TAG, "Extras that adapter gets: " + rtbSignalData.extras ); + Log.i( TAG, "Extras for signal collection: " + rtbSignalData.extras ); } - AppLovinSdk sdk = AppLovinUtils.retrieveSdk( rtbSignalData.extras, rtbSignalData.context ); String bidToken = sdk.getAdService().getBidToken(); - Log.i( TAG, "Generated bid token: " + bidToken ); - - signalCallbacks.onSuccess( bidToken ); + if ( !TextUtils.isEmpty( bidToken ) ) + { + Log.i( TAG, "Generated bid token: " + bidToken ); + signalCallbacks.onSuccess( bidToken ); + } + else + { + Log.e( TAG, "Failed to generate bid token" ); + signalCallbacks.onFailure( null ); + } } @Override @@ -106,34 +109,14 @@ public void renderBannerAd(RtbAdConfiguration adConfiguration, AdSize adSize, Ad } @Override - public void renderInterstitialAd( - RtbAdConfiguration adConfiguration, - AdRenderingCallback callback) + public void renderInterstitialAd(RtbAdConfiguration adConfiguration, AdRenderingCallback callback) { - Log.e( "Test", "renderInterstitial" ); - Log.e( "Test", "Bid Response: " + adConfiguration.bidResponse ); - if ( adConfiguration.mediationExtras != null ) - { - Log.e( "Test", "Extras that renderInterstitial gets: " + adConfiguration.mediationExtras.toString() ); - } - SampleRtbInterstitialRenderer interstitialRenderer = - new SampleRtbInterstitialRenderer( adConfiguration, callback ); - interstitialRenderer.render(); + } @Override - public void renderRewardedAd( - RtbAdConfiguration adConfiguration, - AdRenderingCallback callback) + public void renderRewardedAd(RtbAdConfiguration adConfiguration, AdRenderingCallback callback) { - Log.e( "Test", "renderRewarded" ); - Log.e( "Test", "Bid Response: " + adConfiguration.bidResponse ); - if ( adConfiguration.mediationExtras != null ) - { - Log.e( "Test", "Extras that renderRewarded gets: " + adConfiguration.mediationExtras.toString() ); - } - SampleRtbRewardedRenderer rewardedRenderer = - new SampleRtbRewardedRenderer( adConfiguration, callback ); - rewardedRenderer.render(); + } } From b352217f369a12a98a2b57b31132b5aca346208c Mon Sep 17 00:00:00 2001 From: Thomas So Date: Tue, 17 Jul 2018 16:47:10 -0700 Subject: [PATCH 03/10] Missed some lines --- .../main/java/com/applovin/mediation/ApplovinAdapter.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/ThirdPartyAdapters/applovin/applovin/src/main/java/com/applovin/mediation/ApplovinAdapter.java b/ThirdPartyAdapters/applovin/applovin/src/main/java/com/applovin/mediation/ApplovinAdapter.java index 3b8d8f67a..7ec43fcab 100644 --- a/ThirdPartyAdapters/applovin/applovin/src/main/java/com/applovin/mediation/ApplovinAdapter.java +++ b/ThirdPartyAdapters/applovin/applovin/src/main/java/com/applovin/mediation/ApplovinAdapter.java @@ -335,9 +335,10 @@ public void requestBannerAd(Context context, + mZoneId + " and placement: " + mPlacement); // Convert requested size to AppLovin Ad Size. - if (appLovinAdSize != null) { - mAdView = new AppLovinAdView(mSdk, appLovinAdSize, context); final AppLovinAdSize appLovinAdSize = AppLovinUtils.appLovinAdSizeFromAdMobAdSize( adSize ); + if ( appLovinAdSize != null ) + { + mAdView = new AppLovinAdView( mSdk, appLovinAdSize, context ); final AppLovinBannerAdListener listener = new AppLovinBannerAdListener( mZoneId, mPlacement, mAdView, this, mediationBannerListener); From 3c00d83a854b9c89e73521942d0d3978ccd1d9c6 Mon Sep 17 00:00:00 2001 From: Thomas So Date: Tue, 17 Jul 2018 17:25:41 -0700 Subject: [PATCH 04/10] Initial interstitial advanced bidding implementation --- .../rtb/AppLovinInterstitialRenderer.java | 128 ++++++++++++++++++ .../mediation/rtb/AppLovinRtbAdapter.java | 3 +- 2 files changed, 130 insertions(+), 1 deletion(-) create mode 100644 ThirdPartyAdapters/applovin/applovin/src/main/java/com/applovin/mediation/rtb/AppLovinInterstitialRenderer.java diff --git a/ThirdPartyAdapters/applovin/applovin/src/main/java/com/applovin/mediation/rtb/AppLovinInterstitialRenderer.java b/ThirdPartyAdapters/applovin/applovin/src/main/java/com/applovin/mediation/rtb/AppLovinInterstitialRenderer.java new file mode 100644 index 000000000..5a70e678b --- /dev/null +++ b/ThirdPartyAdapters/applovin/applovin/src/main/java/com/applovin/mediation/rtb/AppLovinInterstitialRenderer.java @@ -0,0 +1,128 @@ +package com.applovin.mediation.rtb; + +import android.util.Log; + +import com.applovin.adview.AppLovinInterstitialAd; +import com.applovin.adview.AppLovinInterstitialAdDialog; +import com.applovin.mediation.AppLovinUtils; +import com.applovin.sdk.AppLovinAd; +import com.applovin.sdk.AppLovinAdClickListener; +import com.applovin.sdk.AppLovinAdDisplayListener; +import com.applovin.sdk.AppLovinAdLoadListener; +import com.applovin.sdk.AppLovinAdVideoPlaybackListener; +import com.applovin.sdk.AppLovinSdk; +import com.google.android.gms.ads.mediation.rtb.AdRenderingCallback; +import com.google.android.gms.ads.mediation.rtb.InterstitialAd; +import com.google.android.gms.ads.mediation.rtb.InterstitialEventListener; +import com.google.android.gms.ads.mediation.rtb.RtbAdConfiguration; + +/** + * Created by Thomas So on July 17 2018 + */ +public final class AppLovinInterstitialRenderer + implements InterstitialAd, AppLovinAdLoadListener, AppLovinAdDisplayListener, AppLovinAdClickListener, AppLovinAdVideoPlaybackListener +{ + private static final String TAG = "AppLovinInterRenderer"; + + /** + * Data used to render an RTB interstitial ad. + */ + private final RtbAdConfiguration adConfiguration; + + /** + * Callback object to notify the Google Mobile Ads SDK if ad rendering succeeded or failed. + */ + private final AdRenderingCallback callback; + + /** + * Listener object to notify the Google Mobile Ads SDK of interstitial presentation events. + */ + private InterstitialEventListener listener; + + + private final AppLovinSdk sdk; + private AppLovinAd ad; + + public AppLovinInterstitialRenderer(RtbAdConfiguration adConfiguration, AdRenderingCallback callback) + { + this.adConfiguration = adConfiguration; + this.callback = callback; + + this.sdk = AppLovinUtils.retrieveSdk( adConfiguration.serverParameters, adConfiguration.context ); + } + + // TODO: Rename + public void render() + { + sdk.getAdService().loadNextAdForAdToken( adConfiguration.bidResponse, this ); + } + + @Override + public void showAd() + { + // Update mute state + boolean muted = AppLovinUtils.shouldMuteAudio( adConfiguration.mediationExtras ); + sdk.getSettings().setMuted( muted ); + + final AppLovinInterstitialAdDialog interstitialAd = AppLovinInterstitialAd.create( sdk, adConfiguration.context ); + interstitialAd.setAdDisplayListener( this ); + interstitialAd.setAdClickListener( this ); + interstitialAd.setAdVideoPlaybackListener( this ); + interstitialAd.showAndRender( ad ); + } + + //region AppLovin Listeners + @Override + public void adReceived(AppLovinAd ad) + { + Log.d( TAG, "Interstitial did load ad: " + ad.getAdIdNumber() ); + + this.ad = ad; + + listener = callback.onSuccess( AppLovinInterstitialRenderer.this ); + } + + @Override + public void failedToReceiveAd(int code) + { + Log.e( TAG, "Failed to load interstitial ad with error: " + code ); + + int admobErrorCode = AppLovinUtils.toAdMobErrorCode( code ); + callback.onFailure( Integer.toString( admobErrorCode ) ); + } + + @Override + public void adDisplayed(AppLovinAd ad) + { + Log.d( TAG, "Interstitial dismissed" ); + listener.reportAdImpression(); + } + + @Override + public void adHidden(AppLovinAd ad) + { + Log.d( TAG, "Interstitial hidden" ); + listener.onAdClosed(); + } + + @Override + public void adClicked(AppLovinAd ad) + { + Log.d( TAG, "Interstitial clicked" ); + listener.reportAdClicked(); + listener.onAdLeftApplication(); + } + + @Override + public void videoPlaybackBegan(AppLovinAd ad) + { + Log.d( TAG, "Interstitial video playback began" ); + } + + @Override + public void videoPlaybackEnded(AppLovinAd ad, double percentViewed, boolean fullyWatched) + { + Log.d( TAG, "Interstitial video playback ended at playback percent: " + percentViewed + "%" ); + } + //endregion +} diff --git a/ThirdPartyAdapters/applovin/applovin/src/main/java/com/applovin/mediation/rtb/AppLovinRtbAdapter.java b/ThirdPartyAdapters/applovin/applovin/src/main/java/com/applovin/mediation/rtb/AppLovinRtbAdapter.java index 79f35cfe9..c4a263039 100644 --- a/ThirdPartyAdapters/applovin/applovin/src/main/java/com/applovin/mediation/rtb/AppLovinRtbAdapter.java +++ b/ThirdPartyAdapters/applovin/applovin/src/main/java/com/applovin/mediation/rtb/AppLovinRtbAdapter.java @@ -111,7 +111,8 @@ public void renderBannerAd(RtbAdConfiguration adConfiguration, AdSize adSize, Ad @Override public void renderInterstitialAd(RtbAdConfiguration adConfiguration, AdRenderingCallback callback) { - + AppLovinInterstitialRenderer interstitialRenderer = new AppLovinInterstitialRenderer( adConfiguration, callback ); + interstitialRenderer.render(); } @Override From 58adcca613eb0180968778fc9a34f5ef3441840c Mon Sep 17 00:00:00 2001 From: Thomas So Date: Tue, 17 Jul 2018 17:31:09 -0700 Subject: [PATCH 05/10] Rename method --- .../com/applovin/mediation/rtb/AppLovinBannerRenderer.java | 2 +- .../applovin/mediation/rtb/AppLovinInterstitialRenderer.java | 3 +-- .../java/com/applovin/mediation/rtb/AppLovinRtbAdapter.java | 4 ++-- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/ThirdPartyAdapters/applovin/applovin/src/main/java/com/applovin/mediation/rtb/AppLovinBannerRenderer.java b/ThirdPartyAdapters/applovin/applovin/src/main/java/com/applovin/mediation/rtb/AppLovinBannerRenderer.java index fbabc2474..4e46a3ba8 100644 --- a/ThirdPartyAdapters/applovin/applovin/src/main/java/com/applovin/mediation/rtb/AppLovinBannerRenderer.java +++ b/ThirdPartyAdapters/applovin/applovin/src/main/java/com/applovin/mediation/rtb/AppLovinBannerRenderer.java @@ -59,7 +59,7 @@ public AppLovinBannerRenderer(RtbAdConfiguration adConfiguration, this.sdk = AppLovinUtils.retrieveSdk( adConfiguration.serverParameters, adConfiguration.context ); } - public void render() + public void loadAd() { if ( adSize != null ) { diff --git a/ThirdPartyAdapters/applovin/applovin/src/main/java/com/applovin/mediation/rtb/AppLovinInterstitialRenderer.java b/ThirdPartyAdapters/applovin/applovin/src/main/java/com/applovin/mediation/rtb/AppLovinInterstitialRenderer.java index 5a70e678b..82e457859 100644 --- a/ThirdPartyAdapters/applovin/applovin/src/main/java/com/applovin/mediation/rtb/AppLovinInterstitialRenderer.java +++ b/ThirdPartyAdapters/applovin/applovin/src/main/java/com/applovin/mediation/rtb/AppLovinInterstitialRenderer.java @@ -51,8 +51,7 @@ public AppLovinInterstitialRenderer(RtbAdConfiguration adConfiguration, AdRender this.sdk = AppLovinUtils.retrieveSdk( adConfiguration.serverParameters, adConfiguration.context ); } - // TODO: Rename - public void render() + public void loadAd() { sdk.getAdService().loadNextAdForAdToken( adConfiguration.bidResponse, this ); } diff --git a/ThirdPartyAdapters/applovin/applovin/src/main/java/com/applovin/mediation/rtb/AppLovinRtbAdapter.java b/ThirdPartyAdapters/applovin/applovin/src/main/java/com/applovin/mediation/rtb/AppLovinRtbAdapter.java index c4a263039..94dd6ef86 100644 --- a/ThirdPartyAdapters/applovin/applovin/src/main/java/com/applovin/mediation/rtb/AppLovinRtbAdapter.java +++ b/ThirdPartyAdapters/applovin/applovin/src/main/java/com/applovin/mediation/rtb/AppLovinRtbAdapter.java @@ -105,14 +105,14 @@ public void collectSignals(RtbSignalData rtbSignalData, SignalCallbacks signalCa public void renderBannerAd(RtbAdConfiguration adConfiguration, AdSize adSize, AdRenderingCallback callback) { AppLovinBannerRenderer bannerRenderer = new AppLovinBannerRenderer( adConfiguration, adSize, callback ); - bannerRenderer.render(); + bannerRenderer.loadAd(); } @Override public void renderInterstitialAd(RtbAdConfiguration adConfiguration, AdRenderingCallback callback) { AppLovinInterstitialRenderer interstitialRenderer = new AppLovinInterstitialRenderer( adConfiguration, callback ); - interstitialRenderer.render(); + interstitialRenderer.loadAd(); } @Override From b97fc2c2cd8fbf91d072f32e4a8e342f90c094a5 Mon Sep 17 00:00:00 2001 From: Thomas So Date: Tue, 17 Jul 2018 18:52:57 -0700 Subject: [PATCH 06/10] Initial reward advanced bidding implementation --- .../AppLovinIncentivizedAdListener.java | 24 --- .../mediation/AppLovinRewardItem.java | 31 +++ .../mediation/rtb/AppLovinRtbAdapter.java | 19 +- ...er.java => AppLovinRtbBannerRenderer.java} | 15 +- ...a => AppLovinRtbInterstitialRenderer.java} | 25 +-- .../rtb/AppLovinRtbRewardedRenderer.java | 179 ++++++++++++++++++ 6 files changed, 243 insertions(+), 50 deletions(-) create mode 100644 ThirdPartyAdapters/applovin/applovin/src/main/java/com/applovin/mediation/AppLovinRewardItem.java rename ThirdPartyAdapters/applovin/applovin/src/main/java/com/applovin/mediation/rtb/{AppLovinBannerRenderer.java => AppLovinRtbBannerRenderer.java} (90%) rename ThirdPartyAdapters/applovin/applovin/src/main/java/com/applovin/mediation/rtb/{AppLovinInterstitialRenderer.java => AppLovinRtbInterstitialRenderer.java} (84%) create mode 100644 ThirdPartyAdapters/applovin/applovin/src/main/java/com/applovin/mediation/rtb/AppLovinRtbRewardedRenderer.java diff --git a/ThirdPartyAdapters/applovin/applovin/src/main/java/com/applovin/mediation/AppLovinIncentivizedAdListener.java b/ThirdPartyAdapters/applovin/applovin/src/main/java/com/applovin/mediation/AppLovinIncentivizedAdListener.java index d4e64c3d8..3583ca8d4 100644 --- a/ThirdPartyAdapters/applovin/applovin/src/main/java/com/applovin/mediation/AppLovinIncentivizedAdListener.java +++ b/ThirdPartyAdapters/applovin/applovin/src/main/java/com/applovin/mediation/AppLovinIncentivizedAdListener.java @@ -116,28 +116,4 @@ public void userRewardVerified(AppLovinAd ad, Map response) { ApplovinAdapter.log(DEBUG, "Rewarded " + amount + " " + currency); mRewardItem = new AppLovinRewardItem(amount, currency); } - - /** - * Reward item wrapper class. - */ - private static final class AppLovinRewardItem - implements RewardItem { - private final int mAmount; - private final String mType; - - private AppLovinRewardItem(int amount, final String type) { - mAmount = amount; - mType = type; - } - - @Override - public String getType() { - return mType; - } - - @Override - public int getAmount() { - return mAmount; - } - } } diff --git a/ThirdPartyAdapters/applovin/applovin/src/main/java/com/applovin/mediation/AppLovinRewardItem.java b/ThirdPartyAdapters/applovin/applovin/src/main/java/com/applovin/mediation/AppLovinRewardItem.java new file mode 100644 index 000000000..58176e445 --- /dev/null +++ b/ThirdPartyAdapters/applovin/applovin/src/main/java/com/applovin/mediation/AppLovinRewardItem.java @@ -0,0 +1,31 @@ +package com.applovin.mediation; + +import com.google.android.gms.ads.reward.RewardItem; + +/** + * Created by Thomas So on July 17 2018 + */ +public final class AppLovinRewardItem + implements RewardItem +{ + private final int mAmount; + private final String mType; + + public AppLovinRewardItem(int amount, String type) + { + mAmount = amount; + mType = type; + } + + @Override + public String getType() + { + return mType; + } + + @Override + public int getAmount() + { + return mAmount; + } +} diff --git a/ThirdPartyAdapters/applovin/applovin/src/main/java/com/applovin/mediation/rtb/AppLovinRtbAdapter.java b/ThirdPartyAdapters/applovin/applovin/src/main/java/com/applovin/mediation/rtb/AppLovinRtbAdapter.java index 94dd6ef86..bec0b91d5 100644 --- a/ThirdPartyAdapters/applovin/applovin/src/main/java/com/applovin/mediation/rtb/AppLovinRtbAdapter.java +++ b/ThirdPartyAdapters/applovin/applovin/src/main/java/com/applovin/mediation/rtb/AppLovinRtbAdapter.java @@ -30,14 +30,14 @@ public class AppLovinRtbAdapter extends RtbAdapter { - private static final String TAG = AppLovinRtbAdapter.class.getSimpleName(); + private static final String TAG = "AppLovinRtbAdapter"; + // TODO: Why is this not in the base adapter?! // @Override - // Why is this not in the base adapter - public void setUp() - { - AppLovinSdk.getInstance( new Application() ).initializeSdk(); - } + // public void setUp() + // { + // AppLovinSdk.getInstance( new Application() ).initializeSdk(); + // } @Override public void initialize() @@ -104,20 +104,21 @@ public void collectSignals(RtbSignalData rtbSignalData, SignalCallbacks signalCa @Override public void renderBannerAd(RtbAdConfiguration adConfiguration, AdSize adSize, AdRenderingCallback callback) { - AppLovinBannerRenderer bannerRenderer = new AppLovinBannerRenderer( adConfiguration, adSize, callback ); + AppLovinRtbBannerRenderer bannerRenderer = new AppLovinRtbBannerRenderer( adConfiguration, adSize, callback ); bannerRenderer.loadAd(); } @Override public void renderInterstitialAd(RtbAdConfiguration adConfiguration, AdRenderingCallback callback) { - AppLovinInterstitialRenderer interstitialRenderer = new AppLovinInterstitialRenderer( adConfiguration, callback ); + AppLovinRtbInterstitialRenderer interstitialRenderer = new AppLovinRtbInterstitialRenderer( adConfiguration, callback ); interstitialRenderer.loadAd(); } @Override public void renderRewardedAd(RtbAdConfiguration adConfiguration, AdRenderingCallback callback) { - + AppLovinRtbRewardedRenderer rewardedRenderer = new AppLovinRtbRewardedRenderer( adConfiguration, callback ); + rewardedRenderer.loadAd(); } } diff --git a/ThirdPartyAdapters/applovin/applovin/src/main/java/com/applovin/mediation/rtb/AppLovinBannerRenderer.java b/ThirdPartyAdapters/applovin/applovin/src/main/java/com/applovin/mediation/rtb/AppLovinRtbBannerRenderer.java similarity index 90% rename from ThirdPartyAdapters/applovin/applovin/src/main/java/com/applovin/mediation/rtb/AppLovinBannerRenderer.java rename to ThirdPartyAdapters/applovin/applovin/src/main/java/com/applovin/mediation/rtb/AppLovinRtbBannerRenderer.java index 4e46a3ba8..da10a791c 100644 --- a/ThirdPartyAdapters/applovin/applovin/src/main/java/com/applovin/mediation/rtb/AppLovinBannerRenderer.java +++ b/ThirdPartyAdapters/applovin/applovin/src/main/java/com/applovin/mediation/rtb/AppLovinRtbBannerRenderer.java @@ -23,10 +23,10 @@ /** * Created by Thomas So on July 17 2018 */ -public final class AppLovinBannerRenderer +public final class AppLovinRtbBannerRenderer implements BannerAd, AppLovinAdLoadListener, AppLovinAdDisplayListener, AppLovinAdClickListener, AppLovinAdViewEventListener { - private static final String TAG = "AppLovinBannerRenderer"; + private static final String TAG = "AppLovinRtbBannerRenderer"; /** * Data used to render an RTB banner ad. @@ -47,9 +47,9 @@ public final class AppLovinBannerRenderer private final AppLovinAdSize adSize; private AppLovinAdView adView; - public AppLovinBannerRenderer(RtbAdConfiguration adConfiguration, - AdSize adSize, - AdRenderingCallback callback) + public AppLovinRtbBannerRenderer(RtbAdConfiguration adConfiguration, + AdSize adSize, + AdRenderingCallback callback) { this.adConfiguration = adConfiguration; this.callback = callback; @@ -63,10 +63,13 @@ public void loadAd() { if ( adSize != null ) { + // Create adview object adView = new AppLovinAdView( sdk, adSize, adConfiguration.context ); adView.setAdDisplayListener( this ); adView.setAdClickListener( this ); adView.setAdViewEventListener( this ); + + // Load ad! sdk.getAdService().loadNextAdForAdToken( adConfiguration.bidResponse, this ); } else @@ -88,7 +91,7 @@ public void adReceived(AppLovinAd ad) { Log.d( TAG, "Banner did load ad: " + ad.getAdIdNumber() ); - listener = callback.onSuccess( AppLovinBannerRenderer.this ); + listener = callback.onSuccess( AppLovinRtbBannerRenderer.this ); adView.renderAd( ad ); } diff --git a/ThirdPartyAdapters/applovin/applovin/src/main/java/com/applovin/mediation/rtb/AppLovinInterstitialRenderer.java b/ThirdPartyAdapters/applovin/applovin/src/main/java/com/applovin/mediation/rtb/AppLovinRtbInterstitialRenderer.java similarity index 84% rename from ThirdPartyAdapters/applovin/applovin/src/main/java/com/applovin/mediation/rtb/AppLovinInterstitialRenderer.java rename to ThirdPartyAdapters/applovin/applovin/src/main/java/com/applovin/mediation/rtb/AppLovinRtbInterstitialRenderer.java index 82e457859..e19f23ea6 100644 --- a/ThirdPartyAdapters/applovin/applovin/src/main/java/com/applovin/mediation/rtb/AppLovinInterstitialRenderer.java +++ b/ThirdPartyAdapters/applovin/applovin/src/main/java/com/applovin/mediation/rtb/AppLovinRtbInterstitialRenderer.java @@ -19,10 +19,10 @@ /** * Created by Thomas So on July 17 2018 */ -public final class AppLovinInterstitialRenderer +public final class AppLovinRtbInterstitialRenderer implements InterstitialAd, AppLovinAdLoadListener, AppLovinAdDisplayListener, AppLovinAdClickListener, AppLovinAdVideoPlaybackListener { - private static final String TAG = "AppLovinInterRenderer"; + private static final String TAG = "AppLovinRtbInterstitialRenderer"; /** * Data used to render an RTB interstitial ad. @@ -39,11 +39,11 @@ public final class AppLovinInterstitialRenderer */ private InterstitialEventListener listener; + private final AppLovinSdk sdk; + private AppLovinInterstitialAdDialog interstitialAd; + private AppLovinAd ad; - private final AppLovinSdk sdk; - private AppLovinAd ad; - - public AppLovinInterstitialRenderer(RtbAdConfiguration adConfiguration, AdRenderingCallback callback) + public AppLovinRtbInterstitialRenderer(RtbAdConfiguration adConfiguration, AdRenderingCallback callback) { this.adConfiguration = adConfiguration; this.callback = callback; @@ -53,6 +53,13 @@ public AppLovinInterstitialRenderer(RtbAdConfiguration adConfiguration, AdRender public void loadAd() { + // Create interstitial object + interstitialAd = AppLovinInterstitialAd.create( sdk, adConfiguration.context ); + interstitialAd.setAdDisplayListener( this ); + interstitialAd.setAdClickListener( this ); + interstitialAd.setAdVideoPlaybackListener( this ); + + // Load ad! sdk.getAdService().loadNextAdForAdToken( adConfiguration.bidResponse, this ); } @@ -63,10 +70,6 @@ public void showAd() boolean muted = AppLovinUtils.shouldMuteAudio( adConfiguration.mediationExtras ); sdk.getSettings().setMuted( muted ); - final AppLovinInterstitialAdDialog interstitialAd = AppLovinInterstitialAd.create( sdk, adConfiguration.context ); - interstitialAd.setAdDisplayListener( this ); - interstitialAd.setAdClickListener( this ); - interstitialAd.setAdVideoPlaybackListener( this ); interstitialAd.showAndRender( ad ); } @@ -78,7 +81,7 @@ public void adReceived(AppLovinAd ad) this.ad = ad; - listener = callback.onSuccess( AppLovinInterstitialRenderer.this ); + listener = callback.onSuccess( AppLovinRtbInterstitialRenderer.this ); } @Override diff --git a/ThirdPartyAdapters/applovin/applovin/src/main/java/com/applovin/mediation/rtb/AppLovinRtbRewardedRenderer.java b/ThirdPartyAdapters/applovin/applovin/src/main/java/com/applovin/mediation/rtb/AppLovinRtbRewardedRenderer.java new file mode 100644 index 000000000..04e094210 --- /dev/null +++ b/ThirdPartyAdapters/applovin/applovin/src/main/java/com/applovin/mediation/rtb/AppLovinRtbRewardedRenderer.java @@ -0,0 +1,179 @@ +package com.applovin.mediation.rtb; + +import android.util.Log; + +import com.applovin.adview.AppLovinIncentivizedInterstitial; +import com.applovin.mediation.AppLovinRewardItem; +import com.applovin.mediation.AppLovinUtils; +import com.applovin.sdk.AppLovinAd; +import com.applovin.sdk.AppLovinAdClickListener; +import com.applovin.sdk.AppLovinAdDisplayListener; +import com.applovin.sdk.AppLovinAdLoadListener; +import com.applovin.sdk.AppLovinAdRewardListener; +import com.applovin.sdk.AppLovinAdVideoPlaybackListener; +import com.applovin.sdk.AppLovinSdk; +import com.google.android.gms.ads.mediation.rtb.AdRenderingCallback; +import com.google.android.gms.ads.mediation.rtb.RewardedAd; +import com.google.android.gms.ads.mediation.rtb.RewardedEventListener; +import com.google.android.gms.ads.mediation.rtb.RtbAdConfiguration; + +import java.util.Map; + +/** + * Created by Thomas So on July 17 2018 + */ +public final class AppLovinRtbRewardedRenderer + implements RewardedAd, AppLovinAdLoadListener, AppLovinAdDisplayListener, AppLovinAdClickListener, AppLovinAdVideoPlaybackListener, AppLovinAdRewardListener +{ + private static final String TAG = "AppLovinRtbRewardedRenderer"; + + /** + * Data used to render an RTB rewarded ad. + */ + private RtbAdConfiguration adConfiguration; + + /** + * Callback object to notify the Google Mobile Ads SDK if ad rendering succeeded or failed. + */ + private final AdRenderingCallback callback; + + /** + * Listener object to notify the Google Mobile Ads SDK of rewarded presentation events. + */ + private RewardedEventListener listener; + + private final AppLovinSdk sdk; + private AppLovinIncentivizedInterstitial incentivizedInterstitial; + private AppLovinAd ad; + private boolean fullyWatched; + private AppLovinRewardItem rewardItem; + + public AppLovinRtbRewardedRenderer(RtbAdConfiguration adConfiguration, AdRenderingCallback callback) + { + this.adConfiguration = adConfiguration; + this.callback = callback; + + this.sdk = AppLovinUtils.retrieveSdk( adConfiguration.serverParameters, adConfiguration.context ); + } + + public void loadAd() + { + // Create rewarded video object + incentivizedInterstitial = AppLovinIncentivizedInterstitial.create( sdk ); + + // Load ad! + sdk.getAdService().loadNextAdForAdToken( adConfiguration.bidResponse, this ); + } + + @Override + public void showAd() + { + incentivizedInterstitial.show( ad, adConfiguration.context, this, this, this, this ); + } + + //region AppLovin Listeners + @Override + public void adReceived(AppLovinAd ad) + { + Log.d( TAG, "Rewarded video did load ad: " + ad.getAdIdNumber() ); + + this.ad = ad; + + listener = callback.onSuccess( AppLovinRtbRewardedRenderer.this ); + } + + @Override + public void failedToReceiveAd(int code) + { + Log.e( TAG, "Failed to load rewarded video with error: " + code ); + + int admobErrorCode = AppLovinUtils.toAdMobErrorCode( code ); + callback.onFailure( Integer.toString( admobErrorCode ) ); + } + + @Override + public void adDisplayed(AppLovinAd ad) + { + Log.d( TAG, "Rewarded video dismissed" ); + listener.reportAdImpression(); + } + + @Override + public void adHidden(AppLovinAd ad) + { + Log.d( TAG, "Rewarded video hidden" ); + + if ( fullyWatched && rewardItem != null ) + { + listener.onRewarded( rewardItem ); + } + + listener.onAdClosed(); + + // Clear states in the case this listener gets re-used in the future. + fullyWatched = false; + rewardItem = null; + } + + @Override + public void adClicked(AppLovinAd ad) + { + Log.d( TAG, "Rewarded video clicked" ); + listener.reportAdClicked(); + listener.onAdLeftApplication(); + } + + @Override + public void videoPlaybackBegan(AppLovinAd ad) + { + Log.d( TAG, "Rewarded video playback began" ); + listener.onVideoStarted(); + } + + @Override + public void videoPlaybackEnded(AppLovinAd ad, double percentViewed, boolean fullyWatched) + { + Log.d( TAG, "Rewarded video playback ended at playback percent: " + percentViewed + "%" ); + listener.onVideoCompleted(); + } + //endregion + + //region AppLovin Reward Listener + @Override + public void userOverQuota(AppLovinAd ad, Map response) + { + Log.e( TAG, "Rewarded video validation request for ad did exceed quota with response: " + response ); + } + + @Override + public void validationRequestFailed(AppLovinAd ad, int code) + { + Log.e( TAG, "Rewarded video validation request for ad failed with error code: " + code ); + } + + @Override + public void userRewardRejected(AppLovinAd ad, Map response) + { + Log.e( TAG, "Rewarded video validation request was rejected with response: " + response ); + } + + @Override + public void userDeclinedToViewAd(AppLovinAd ad) + { + Log.e( TAG, "User declined to view rewarded video" ); + } + + @Override + public void userRewardVerified(AppLovinAd ad, Map response) + { + final String currency = response.get( "currency" ); + final String amountStr = response.get( "amount" ); + + // AppLovin returns amount as double. + final int amount = (int) Double.parseDouble( amountStr ); + + Log.d( TAG, "Rewarded " + amount + " " + currency ); + rewardItem = new AppLovinRewardItem( amount, currency ); + } + //endregion +} From 829ce9d17a88b62c69ca45a0367bbbd633ce6983 Mon Sep 17 00:00:00 2001 From: Thomas So Date: Tue, 17 Jul 2018 18:54:21 -0700 Subject: [PATCH 07/10] Visibility changes --- .../main/java/com/applovin/mediation/AppLovinUtils.java | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/ThirdPartyAdapters/applovin/applovin/src/main/java/com/applovin/mediation/AppLovinUtils.java b/ThirdPartyAdapters/applovin/applovin/src/main/java/com/applovin/mediation/AppLovinUtils.java index 5fb2b9fb9..cf77728d7 100644 --- a/ThirdPartyAdapters/applovin/applovin/src/main/java/com/applovin/mediation/AppLovinUtils.java +++ b/ThirdPartyAdapters/applovin/applovin/src/main/java/com/applovin/mediation/AppLovinUtils.java @@ -81,14 +81,16 @@ static String retrieveZoneId(Bundle serverParameters) { /** * Retrieves whether or not to mute the ad that is about to be rendered. */ - static boolean shouldMuteAudio(Bundle networkExtras) { - return networkExtras != null && networkExtras.getBoolean(AppLovinExtras.Keys.MUTE_AUDIO); + public static boolean shouldMuteAudio(Bundle networkExtras) + { + return networkExtras != null && networkExtras.getBoolean( AppLovinExtras.Keys.MUTE_AUDIO ); } /** * Convert the given AppLovin SDK error code into the appropriate AdMob error code. */ - static int toAdMobErrorCode(int applovinErrorCode) { + public static int toAdMobErrorCode(int applovinErrorCode) + { // // TODO: Be more exhaustive // From a6395398f55e6e505f8b6fe99b88025b23ff3e99 Mon Sep 17 00:00:00 2001 From: Thomas So Date: Tue, 17 Jul 2018 19:52:55 -0700 Subject: [PATCH 08/10] Don't forget to update mute state:) --- .../applovin/mediation/rtb/AppLovinRtbRewardedRenderer.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/ThirdPartyAdapters/applovin/applovin/src/main/java/com/applovin/mediation/rtb/AppLovinRtbRewardedRenderer.java b/ThirdPartyAdapters/applovin/applovin/src/main/java/com/applovin/mediation/rtb/AppLovinRtbRewardedRenderer.java index 04e094210..313a89df8 100644 --- a/ThirdPartyAdapters/applovin/applovin/src/main/java/com/applovin/mediation/rtb/AppLovinRtbRewardedRenderer.java +++ b/ThirdPartyAdapters/applovin/applovin/src/main/java/com/applovin/mediation/rtb/AppLovinRtbRewardedRenderer.java @@ -68,6 +68,10 @@ public void loadAd() @Override public void showAd() { + // Update mute state + boolean muted = AppLovinUtils.shouldMuteAudio( adConfiguration.mediationExtras ); + sdk.getSettings().setMuted( muted ); + incentivizedInterstitial.show( ad, adConfiguration.context, this, this, this, this ); } From 7a491a2a810e9d488beee51050dc4456048e6d3e Mon Sep 17 00:00:00 2001 From: Thomas So Date: Tue, 17 Jul 2018 21:50:56 -0700 Subject: [PATCH 09/10] Add error message on bid token generation error --- .../java/com/applovin/mediation/rtb/AppLovinRtbAdapter.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/ThirdPartyAdapters/applovin/applovin/src/main/java/com/applovin/mediation/rtb/AppLovinRtbAdapter.java b/ThirdPartyAdapters/applovin/applovin/src/main/java/com/applovin/mediation/rtb/AppLovinRtbAdapter.java index bec0b91d5..c74bf5873 100644 --- a/ThirdPartyAdapters/applovin/applovin/src/main/java/com/applovin/mediation/rtb/AppLovinRtbAdapter.java +++ b/ThirdPartyAdapters/applovin/applovin/src/main/java/com/applovin/mediation/rtb/AppLovinRtbAdapter.java @@ -96,8 +96,9 @@ public void collectSignals(RtbSignalData rtbSignalData, SignalCallbacks signalCa } else { - Log.e( TAG, "Failed to generate bid token" ); - signalCallbacks.onFailure( null ); + String errorMessage = "Failed to generate bid token"; + Log.e( TAG, errorMessage ); + signalCallbacks.onFailure( errorMessage ); } } From eb75a4ffe49373cc9ce7cd831cb574ce91b02dd9 Mon Sep 17 00:00:00 2001 From: Thomas So Date: Wed, 18 Jul 2018 23:19:04 -0700 Subject: [PATCH 10/10] Fix logging --- .../com/applovin/mediation/rtb/AppLovinRtbBannerRenderer.java | 2 +- .../applovin/mediation/rtb/AppLovinRtbInterstitialRenderer.java | 2 +- .../com/applovin/mediation/rtb/AppLovinRtbRewardedRenderer.java | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/ThirdPartyAdapters/applovin/applovin/src/main/java/com/applovin/mediation/rtb/AppLovinRtbBannerRenderer.java b/ThirdPartyAdapters/applovin/applovin/src/main/java/com/applovin/mediation/rtb/AppLovinRtbBannerRenderer.java index da10a791c..1d06e471f 100644 --- a/ThirdPartyAdapters/applovin/applovin/src/main/java/com/applovin/mediation/rtb/AppLovinRtbBannerRenderer.java +++ b/ThirdPartyAdapters/applovin/applovin/src/main/java/com/applovin/mediation/rtb/AppLovinRtbBannerRenderer.java @@ -108,7 +108,7 @@ public void failedToReceiveAd(int code) @Override public void adDisplayed(AppLovinAd ad) { - Log.d( TAG, "Banner dismissed" ); + Log.d( TAG, "Banner displayed" ); listener.reportAdImpression(); } diff --git a/ThirdPartyAdapters/applovin/applovin/src/main/java/com/applovin/mediation/rtb/AppLovinRtbInterstitialRenderer.java b/ThirdPartyAdapters/applovin/applovin/src/main/java/com/applovin/mediation/rtb/AppLovinRtbInterstitialRenderer.java index e19f23ea6..7096e4518 100644 --- a/ThirdPartyAdapters/applovin/applovin/src/main/java/com/applovin/mediation/rtb/AppLovinRtbInterstitialRenderer.java +++ b/ThirdPartyAdapters/applovin/applovin/src/main/java/com/applovin/mediation/rtb/AppLovinRtbInterstitialRenderer.java @@ -96,7 +96,7 @@ public void failedToReceiveAd(int code) @Override public void adDisplayed(AppLovinAd ad) { - Log.d( TAG, "Interstitial dismissed" ); + Log.d( TAG, "Interstitial displayed" ); listener.reportAdImpression(); } diff --git a/ThirdPartyAdapters/applovin/applovin/src/main/java/com/applovin/mediation/rtb/AppLovinRtbRewardedRenderer.java b/ThirdPartyAdapters/applovin/applovin/src/main/java/com/applovin/mediation/rtb/AppLovinRtbRewardedRenderer.java index 313a89df8..38e85f455 100644 --- a/ThirdPartyAdapters/applovin/applovin/src/main/java/com/applovin/mediation/rtb/AppLovinRtbRewardedRenderer.java +++ b/ThirdPartyAdapters/applovin/applovin/src/main/java/com/applovin/mediation/rtb/AppLovinRtbRewardedRenderer.java @@ -98,7 +98,7 @@ public void failedToReceiveAd(int code) @Override public void adDisplayed(AppLovinAd ad) { - Log.d( TAG, "Rewarded video dismissed" ); + Log.d( TAG, "Rewarded video displayed" ); listener.reportAdImpression(); }