-
Notifications
You must be signed in to change notification settings - Fork 82
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create Applovin Max banner adapter and configure environment (#416)
* 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
1 parent
7962804
commit bbc6241
Showing
23 changed files
with
525 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -58,3 +58,6 @@ captures/ | |
|
||
# Keystore files | ||
*.jks | ||
|
||
# Applovin Max Ad Review plugin | ||
.safedk/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
77 changes: 77 additions & 0 deletions
77
...emoKotlin/src/main/java/org/prebid/mobile/prebidkotlindemo/ads/inappmax/InAppMaxBanner.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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?) {} | ||
} | ||
} | ||
|
||
} |
4 changes: 4 additions & 0 deletions
4
Example/PrebidDemoKotlin/src/main/res/values-sw600dp/attrs.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,6 +32,7 @@ enum class Tag(val tagName: String) { | |
IN_APP("In-App"), | ||
GAM("GAM"), | ||
ADMOB("AdMob"), | ||
MAX("Max"), | ||
|
||
ALL("All") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
95 changes: 95 additions & 0 deletions
95
PrebidMobile/PrebidMobile-core/src/main/java/org/prebid/mobile/ParametersMatcher.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
1 change: 1 addition & 0 deletions
1
PrebidMobile/PrebidMobile-maxAdapters/src/main/AndroidManifest.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<manifest package="org.prebid.mobile.max.adapters" /> |
Oops, something went wrong.