Skip to content

Commit

Permalink
Create Applovin Max banner adapter and configure environment (#416)
Browse files Browse the repository at this point in the history
* feat(max-adapters): create max adapters module #401

* feat(max-adapters): add max page into Internal test app #401

* feat(max-adapters): connect banner example to Kotlin app #401

* feat(max-adapters): create max banner adapter #401
  • Loading branch information
ValentinPostindustria committed Apr 18, 2022
1 parent 7962804 commit bbc6241
Show file tree
Hide file tree
Showing 23 changed files with 525 additions and 17 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,6 @@ captures/

# Keystore files
*.jks

# Applovin Max Ad Review plugin
.safedk/
11 changes: 9 additions & 2 deletions Example/PrebidDemoKotlin/build.gradle
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
apply plugin: 'com.android.application'

apply plugin: 'kotlin-android'

apply plugin: 'kotlin-android-extensions'
apply plugin: 'applovin-quality-service'

applovin {
apiKey "GFK71zBxyxVAos4h_nh9NHqmym-hXdJisa0oDLiZ6CpGo6TaA-C08qHDlWcvguArWJJF03h77gL4dqJ3e9ubnn"
}

android {
compileSdkVersion 30
Expand Down Expand Up @@ -35,11 +38,13 @@ dependencies {
implementation project(':PrebidMobile')
implementation project(':PrebidMobile-gamEventHandlers')
implementation project(':PrebidMobile-admobAdapters')
implementation project(':PrebidMobile-maxAdapters')

// For testing staging releases
// implementation 'org.prebid:prebid-mobile-sdk:1.13.0-beta2'
// implementation 'org.prebid:prebid-mobile-sdk-gam-event-handlers:1.13.0-beta2'
// implementation 'org.prebid:prebid-mobile-sdk-admob-adapters:1.13.0-beta2'
// implementation 'org.prebid:prebid-mobile-sdk-max-adapters:1.13.0-beta2'

// Standard libraries
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
Expand All @@ -48,6 +53,8 @@ dependencies {

// Advertisement
implementation 'com.google.android.gms:play-services-ads:20.4.0'
implementation "com.applovin:applovin-sdk:11.3.2"
implementation "com.google.android.gms:play-services-ads-identifier:18.0.1" // For Applovin Max


// Multidex
Expand Down
18 changes: 11 additions & 7 deletions Example/PrebidDemoKotlin/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,25 @@
android:theme="@style/AppTheme">

<meta-data
android:name="com.google.android.gms.ads.AD_MANAGER_APP"
android:value="true"/>
android:name="com.google.android.gms.ads.AD_MANAGER_APP"
android:value="true" />

<meta-data
android:name="com.google.android.gms.ads.APPLICATION_ID"
android:value="ca-app-pub-1875909575462531~6255590079"/>
android:name="com.google.android.gms.ads.APPLICATION_ID"
android:value="ca-app-pub-1875909575462531~6255590079" />

<meta-data
android:name="applovin.sdk.key"
android:value="1tLUnP4cVQqpHuHH2yMtfdESvvUhTB05NdbCoDTceDDNVnhd_T8kwIzXDN9iwbdULTboByF-TtNaiTmsoVbxZw" />

<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER"/>
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".DemoActivity"/>
<activity android:name=".DemoActivity" />



Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,22 @@ object AdTypesRepository {
InAppAdMobNative.destroy()
}
)
),

"In-App + Applovin Max" to listOf(
AdType(
"Banner",
onCreate = { activity, wrapper, autoRefreshTime ->
useTestServer()
PrebidMobile.setStoredAuctionResponse("response-prebid-banner-320-50")
InAppMaxBanner.create(
wrapper, autoRefreshTime / 1000,
"3d8a0bcbb6d571d5",
"imp-prebid-banner-320-50"
)
},
onDestroy = { InAppMaxBanner.destroy() }
),
)
)

Expand All @@ -277,5 +293,4 @@ object AdTypesRepository {
PrebidMobile.setPrebidServerHost(Host.createCustomHost("https://prebid-server-test-j.prebid.org/openrtb2/auction"))
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ import android.os.Bundle
import android.util.Log
import android.view.WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON
import android.webkit.WebView
import com.applovin.sdk.AppLovinSdk
import com.applovin.sdk.AppLovinSdkConfiguration
import com.google.android.gms.ads.MobileAds
import com.google.android.gms.ads.RequestConfiguration

Expand All @@ -35,6 +37,7 @@ class CustomApplication : Application() {
super.onCreate()
initPrebidSDK()
initAdMob()
initApplovinMax()
if (BuildConfig.DEBUG) {
activateKeepScreenOnFlag()
}
Expand All @@ -61,6 +64,12 @@ class CustomApplication : Application() {
MobileAds.setRequestConfiguration(configuration)
}

private fun initApplovinMax() {
AppLovinSdk.getInstance(this).mediationProvider = "max"
AppLovinSdk.getInstance(this).initializeSdk { configuration: AppLovinSdkConfiguration -> }
// AppLovinSdk.getInstance(this).settings.setVerboseLogging(true);
}

private fun activateKeepScreenOnFlag() {
sendBroadcast(Intent(Intent.ACTION_CLOSE_SYSTEM_DIALOGS))
this.registerActivityLifecycleCallbacks(object : ActivityLifecycleCallbacks {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
package org.prebid.mobile.prebidkotlindemo.ads.inappmax

import android.util.Log
import android.view.ViewGroup
import android.widget.FrameLayout
import com.applovin.mediation.MaxAd
import com.applovin.mediation.MaxAdViewAdListener
import com.applovin.mediation.MaxError
import com.applovin.mediation.adapters.MaxBannerMediationUtils
import com.applovin.mediation.adapters.PrebidMAXMediationAdapter
import com.applovin.mediation.ads.MaxAdView
import org.prebid.mobile.AdSize
import org.prebid.mobile.prebidkotlindemo.R
import org.prebid.mobile.rendering.bidding.display.MediationBannerAdUnit

object InAppMaxBanner {

private const val TAG = "InAppMaxBanner"

private var adView: MaxAdView? = null
private var adUnit: MediationBannerAdUnit? = null

fun create(
wrapper: ViewGroup,
autoRefreshTime: Int,
adUnitId: String,
configId: String
) {
adView = MaxAdView(adUnitId, wrapper.context)
adView?.setListener(createListener())

adView?.layoutParams = FrameLayout.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT,
wrapper.context.resources.getDimensionPixelSize(R.dimen.banner_height)
)
adView?.setLocalExtraParameter(PrebidMAXMediationAdapter.EXTRA_RESPONSE_ID, "Lol")

wrapper.addView(adView)

val mediationUtils = MaxBannerMediationUtils(adView)
adUnit = MediationBannerAdUnit(
wrapper.context,
configId,
AdSize(320, 50),
mediationUtils
)
adUnit?.setRefreshInterval(autoRefreshTime)
adUnit?.fetchDemand {
adView?.loadAd()
}
}

fun destroy() {
adView?.stopAutoRefresh()
adView?.destroy()
}

private fun createListener(): MaxAdViewAdListener {
return object : MaxAdViewAdListener {
override fun onAdLoaded(ad: MaxAd?) {
Log.d(TAG, "onAdLoaded()")
}

override fun onAdLoadFailed(adUnitId: String?, error: MaxError?) {
Log.d(TAG, "onAdLoadFailed(): ${error?.message}")
}

override fun onAdHidden(ad: MaxAd?) {}
override fun onAdClicked(ad: MaxAd?) {}
override fun onAdExpanded(ad: MaxAd?) {}
override fun onAdCollapsed(ad: MaxAd?) {}
override fun onAdDisplayed(ad: MaxAd?) {}
override fun onAdDisplayFailed(ad: MaxAd?, error: MaxError?) {}
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<dimen name="banner_height">90dp</dimen>
</resources>
4 changes: 4 additions & 0 deletions Example/PrebidDemoKotlin/src/main/res/values/attrs.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<dimen name="banner_height">50dp</dimen>
</resources>
2 changes: 2 additions & 0 deletions Example/PrebidInternalTestApp/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,13 @@ dependencies {
implementation project(':PrebidMobile')
implementation project(':PrebidMobile-gamEventHandlers')
implementation project(':PrebidMobile-admobAdapters')
implementation project(':PrebidMobile-maxAdapters')

// For testing staging releases
// implementation 'org.prebid:prebid-mobile-sdk:1.13.0-beta2'
// implementation 'org.prebid:prebid-mobile-sdk-gam-event-handlers:1.13.0-beta2'
// implementation 'org.prebid:prebid-mobile-sdk-admob-adapters:1.13.0-beta2'
// implementation 'org.prebid:prebid-mobile-sdk-max-adapters:1.13.0-beta2'

// Base dependencies
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ enum class Tag(val tagName: String) {
IN_APP("In-App"),
GAM("GAM"),
ADMOB("AdMob"),
MAX("Max"),

ALL("All")
}
2 changes: 2 additions & 0 deletions Example/PrebidInternalTestApp/src/main/res/values/arrays.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
<item>@string/segment_title_in_app</item>
<item>@string/segment_title_gam</item>
<item>@string/segment_title_admob</item>
<item>@string/segment_title_max</item>
<item>@string/segment_title_all</item>
</string-array>

Expand All @@ -40,5 +41,6 @@
<string name="segment_title_all">All</string>
<string name="segment_title_gam">GAM</string>
<string name="segment_title_admob">AdMob</string>
<string name="segment_title_max">Max</string>
<string name="segment_title_in_app">In-App</string>
</resources>
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
package org.prebid.mobile;

import android.os.Bundle;
import androidx.annotation.Nullable;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.HashMap;
import java.util.Iterator;

public class ParametersMatcher {

private static final String TAG = "ParametersMatcher";

public static boolean doParametersMatch(
@Nullable String serverParametersJsonString,
@Nullable HashMap<String, String> prebidParameters
) {
HashMap<String, String> serverParameters = jsonStringToHashMap(serverParametersJsonString);
return doParametersMatch(serverParameters, prebidParameters);
}

public static boolean doParametersMatch(
@Nullable Bundle serverParametersBundle,
@Nullable HashMap<String, String> prebidParameters
) {
HashMap<String, String> serverParameters = bundleToHashMap(serverParametersBundle);
return doParametersMatch(serverParameters, prebidParameters);
}

public static boolean doParametersMatch(
@Nullable HashMap<String, String> serverParameters,
@Nullable HashMap<String, String> prebidParameters
) {
if (serverParameters == null || prebidParameters == null) {
return false;
}

try {
for (String serverKey : serverParameters.keySet()) {
if (prebidParameters.containsKey(serverKey)) {
String prebidValue = prebidParameters.get(serverKey);
String serverValue = serverParameters.get(serverKey);
if (prebidValue == null || !prebidValue.equals(serverValue)) {
return false;
}
} else {
return false;
}
}
return true;
} catch (NullPointerException e) {
LogUtil.error(TAG, "Null pointer exception");
}
return false;
}

@Nullable
private static HashMap<String, String> bundleToHashMap(@Nullable Bundle bundle) {
if (bundle == null) {
return null;
}

HashMap<String, String> parameters = new HashMap<>();
for (String bundleKey : bundle.keySet()) {
String bundleValue = bundle.getString(bundleKey);
if (bundleValue != null) {
parameters.put(bundleKey, bundleValue);
}
}
return parameters;
}

@Nullable
private static HashMap<String, String> jsonStringToHashMap(@Nullable String jsonString) {
if (jsonString == null || jsonString.trim().length() == 0) {
return null;
}

try {
JSONObject root = new JSONObject(jsonString);
HashMap<String, String> parameters = new HashMap<>();
Iterator<String> keys = root.keys();
while (keys.hasNext()) {
String key = keys.next();
parameters.put(key, root.getString(key));
}
return parameters;
} catch (JSONException e) {
LogUtil.error(TAG, "Can't parse parameters");
return null;
}
}

}
8 changes: 8 additions & 0 deletions PrebidMobile/PrebidMobile-maxAdapters/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
apply from: '../android.gradle'
apply from: '../publisher.gradle'
apply from: '../tests.gradle'

dependencies {
implementation project(":PrebidMobile")
implementation "com.applovin:applovin-sdk:11.3.2"
}
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<manifest package="org.prebid.mobile.max.adapters" />
Loading

0 comments on commit bbc6241

Please sign in to comment.