Skip to content

Commit

Permalink
AdMob adapters (#353)
Browse files Browse the repository at this point in the history
* Prepare project for AdMob integration (#327)

* feat: add event handlers and adapters to deploy script, generate pom files

* feat: edit pom files

* fix(deploying): fix deploying of project with rendering

Deploy script publishes rendering module as aar. Build script generates and saves aar files too. Fix Sonatype exception about javadoc and sources in OpenMeasument SDK. Fix possible exception in DemandFetcher. Move staging url to global build.gradle.

* feat: make separate script for deploying Open Measurement SDK #318

* feat(AdMob): prepare project for AdMob integration #324

* feat(AdMob): corrected imports for staging releases

* Introduce AdMob banner adapter (#334)

* feat: add event handlers and adapters to deploy script, generate pom files

* feat: edit pom files

* fix(deploying): fix deploying of project with rendering

Deploy script publishes rendering module as aar. Build script generates and saves aar files too. Fix Sonatype exception about javadoc and sources in OpenMeasument SDK. Fix possible exception in DemandFetcher. Move staging url to global build.gradle.

* feat: make separate script for deploying Open Measurement SDK #318

* feat(AdMob): prepare project for AdMob integration #324

* feat(AdMob): corrected imports for staging releases

* feat(AdMob): connect AdMob banner #323

Configure AdMob banner. Add example to PrebidDemoJava app. Show logs for uncorrect auto refresh time.

* feat: new mediation delegate's architecture #323

Simplify mediation delegate. Rewrite MoPub adapters using new architecture. Check MoPub examples in PrebidKotlin app.

* feat: rewrite MoPub examples and mediation utils with new architecture #323

Create new mediation utils files for MoPub. Rewrite examples. Fix instrumented test cases.

* fix(UnitTests): rewrite unit tests with new architecture #334

Fix old tests. Create new ones to cover more cases.

* feat: remove reflection calls in MoPub mediation utils #334

Add weak reference for views. Add logs in case of destroying WeakReference.

* feat(AdMob): complete AdMob banner implementation #323

Create ParametersMatcher. Add ability to get bid keywords without pop. Remove PrebidAdMobRequest.

* feat(AdMob): add working ids for AdMob #323

* feat(AdMob): add AdMob banner examples to InternalTestApp #323

Added 320x50, 300x250 and flexible examples.

* feat(AdMob): add visibility check for AdMob banner #323

* Introduce AdMob rewarded adapter (#339)

* feat: add event handlers and adapters to deploy script, generate pom files

* feat: edit pom files

* fix(deploying): fix deploying of project with rendering

Deploy script publishes rendering module as aar. Build script generates and saves aar files too. Fix Sonatype exception about javadoc and sources in OpenMeasument SDK. Fix possible exception in DemandFetcher. Move staging url to global build.gradle.

* feat: make separate script for deploying Open Measurement SDK #318

* feat(AdMob): prepare project for AdMob integration #324

* feat(AdMob): corrected imports for staging releases

* feat(AdMob): connect AdMob banner #323

Configure AdMob banner. Add example to PrebidDemoJava app. Show logs for uncorrect auto refresh time.

* feat: new mediation delegate's architecture #323

Simplify mediation delegate. Rewrite MoPub adapters using new architecture. Check MoPub examples in PrebidKotlin app.

* feat: rewrite MoPub examples and mediation utils with new architecture #323

Create new mediation utils files for MoPub. Rewrite examples. Fix instrumented test cases.

* fix(UnitTests): rewrite unit tests with new architecture #334

Fix old tests. Create new ones to cover more cases.

* feat: remove reflection calls in MoPub mediation utils #334

Add weak reference for views. Add logs in case of destroying WeakReference.

* feat(AdMob): complete AdMob banner implementation #323

Create ParametersMatcher. Add ability to get bid keywords without pop. Remove PrebidAdMobRequest.

* feat(AdMob): add working ids for AdMob #323

* feat(AdMob): add AdMob banner examples to InternalTestApp #323

Added 320x50, 300x250 and flexible examples.

* feat(AdMob): create AdMob rewarded adapter #329

Add example to Kotlin test app.

* feat(AdMob): add visibility check for AdMob banner #323

* feat(AdMob): add rewarded examples to Internal test app #329

* Introduce AdMob interstitial adapter (#340)

* feat: add event handlers and adapters to deploy script, generate pom files

* feat: edit pom files

* fix(deploying): fix deploying of project with rendering

Deploy script publishes rendering module as aar. Build script generates and saves aar files too. Fix Sonatype exception about javadoc and sources in OpenMeasument SDK. Fix possible exception in DemandFetcher. Move staging url to global build.gradle.

* feat: make separate script for deploying Open Measurement SDK #318

* feat(AdMob): prepare project for AdMob integration #324

* feat(AdMob): corrected imports for staging releases

* feat(AdMob): connect AdMob banner #323

Configure AdMob banner. Add example to PrebidDemoJava app. Show logs for uncorrect auto refresh time.

* feat: new mediation delegate's architecture #323

Simplify mediation delegate. Rewrite MoPub adapters using new architecture. Check MoPub examples in PrebidKotlin app.

* feat: rewrite MoPub examples and mediation utils with new architecture #323

Create new mediation utils files for MoPub. Rewrite examples. Fix instrumented test cases.

* fix(UnitTests): rewrite unit tests with new architecture #334

Fix old tests. Create new ones to cover more cases.

* feat: remove reflection calls in MoPub mediation utils #334

Add weak reference for views. Add logs in case of destroying WeakReference.

* feat(AdMob): complete AdMob banner implementation #323

Create ParametersMatcher. Add ability to get bid keywords without pop. Remove PrebidAdMobRequest.

* feat(AdMob): add working ids for AdMob #323

* feat(AdMob): add AdMob banner examples to InternalTestApp #323

Added 320x50, 300x250 and flexible examples.

* feat(AdMob): create AdMob rewarded adapter #329

Add example to Kotlin test app.

* feat(AdMob): add visibility check for AdMob banner #323

* feat(AdMob): add rewarded examples to Internal test app #329

* feat(AdMob): create AdMob interstitial adapter #328

Add example to Kotlin test app.

* feat(AdMob): add interstitial examples to Internal test app #328

* AdMob fixes  (#351)

* feat(AdMob): add display insterstitial examples #343

* feat(AdMob): indicate the status of interstitial ads #344

* fix(AdMob): fix listeners and confg ids for rewarded and interstitial #345

* feat: open measurement version #346

* fix: add additional size to AdMob flexible banner  #349

* Introduce AdMob native adapter (#342)

* feat: add event handlers and adapters to deploy script, generate pom files

* feat: edit pom files

* fix(deploying): fix deploying of project with rendering

Deploy script publishes rendering module as aar. Build script generates and saves aar files too. Fix Sonatype exception about javadoc and sources in OpenMeasument SDK. Fix possible exception in DemandFetcher. Move staging url to global build.gradle.

* feat: make separate script for deploying Open Measurement SDK #318

* feat(AdMob): prepare project for AdMob integration #324

* feat(AdMob): corrected imports for staging releases

* feat(AdMob): connect AdMob banner #323

Configure AdMob banner. Add example to PrebidDemoJava app. Show logs for uncorrect auto refresh time.

* feat: new mediation delegate's architecture #323

Simplify mediation delegate. Rewrite MoPub adapters using new architecture. Check MoPub examples in PrebidKotlin app.

* feat: rewrite MoPub examples and mediation utils with new architecture #323

Create new mediation utils files for MoPub. Rewrite examples. Fix instrumented test cases.

* fix(UnitTests): rewrite unit tests with new architecture #334

Fix old tests. Create new ones to cover more cases.

* feat: remove reflection calls in MoPub mediation utils #334

Add weak reference for views. Add logs in case of destroying WeakReference.

* feat(AdMob): complete AdMob banner implementation #323

Create ParametersMatcher. Add ability to get bid keywords without pop. Remove PrebidAdMobRequest.

* feat(AdMob): add working ids for AdMob #323

* feat(AdMob): add AdMob banner examples to InternalTestApp #323

Added 320x50, 300x250 and flexible examples.

* feat(AdMob): create AdMob rewarded adapter #329

Add example to Kotlin test app.

* feat(AdMob): add visibility check for AdMob banner #323

* feat(AdMob): add rewarded examples to Internal test app #329

* feat(AdMob): create AdMob interstitial adapter #328

Add example to Kotlin test app.

* feat(AdMob): add interstitial examples to Internal test app #328

* feat(AdMob): create AdMob native adapter #341

Create native example for Kotlin test app. Fix accessibility error with NativeAsset. Change PrebidNativeAd image parser.

* feat(AdMob): add native examples to Internal test app #341

* feat(AdMob): migrate mediation logic to MediationNativeAdUnit #341

Renamed some samples of AdMod ads.

* feat(AdMob): configure MediationNativeAdUnit for MoPubNativeMediationUtils #333

Fix PrebidNativeAd exception when listener is null.

* feat(AdMob): rewrite MoPub native examples #341

Remove old renderer, wrapper and mediation utils.

* feat(AdMob): native ads according to IAB specs #347

Make test for parsing NativeAd.

* feat(AdMob): rewrite in-app AdMob native example using original API #331

* feat(AdMob): rewrite in-app AdMob native feed and links examples using original API #331

* feat(AdMob): rewrite in-app GAM native examples using original API #332
  • Loading branch information
ValentinPostindustria committed Feb 15, 2022
1 parent 54d4b7f commit 21cdde5
Show file tree
Hide file tree
Showing 125 changed files with 7,135 additions and 2,409 deletions.
2 changes: 2 additions & 0 deletions Example/PrebidDemoKotlin/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,13 @@ dependencies {
implementation project(':PrebidMobile')
implementation project(':PrebidMobile-gamEventHandlers')
implementation project(':PrebidMobile-mopubAdapters')
implementation project(':PrebidMobile-admobAdapters')

// 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-mopub-adapters:1.13.0-beta2'
// implementation 'org.prebid:prebid-mobile-sdk-admob-adapters:1.13.0-beta2'

// Standard libraries
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
Expand Down
5 changes: 5 additions & 0 deletions Example/PrebidDemoKotlin/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,15 @@
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">

<meta-data
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"/>

<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ import org.prebid.mobile.prebidkotlindemo.ads.GamInterstitial
import org.prebid.mobile.prebidkotlindemo.ads.MoPubBanner
import org.prebid.mobile.prebidkotlindemo.ads.MoPubInterstitial
import org.prebid.mobile.prebidkotlindemo.ads.inapp.*
import org.prebid.mobile.prebidkotlindemo.ads.inappadmob.InAppAdMobBanner
import org.prebid.mobile.prebidkotlindemo.ads.inappadmob.InAppAdMobInterstitial
import org.prebid.mobile.prebidkotlindemo.ads.inappadmob.InAppAdMobNative
import org.prebid.mobile.prebidkotlindemo.ads.inappadmob.InAppAdMobRewarded
import org.prebid.mobile.prebidkotlindemo.ads.inappgam.*
import org.prebid.mobile.prebidkotlindemo.ads.inappmopub.InAppMoPubBanner
import org.prebid.mobile.prebidkotlindemo.ads.inappmopub.InAppMoPubInterstitial
Expand Down Expand Up @@ -100,7 +104,7 @@ object AdTypesRepository {
"Banner 320x50",
onCreate = { _, wrapper, autoRefreshTime ->
InAppBanner.create(
wrapper, autoRefreshTime,
wrapper, autoRefreshTime / 1000,
320, 50,
"50699c03-0910-477c-b4a4-911dbe2b9d42"
)
Expand All @@ -122,7 +126,7 @@ object AdTypesRepository {
"Video Banner",
onCreate = { _, wrapper, autoRefreshTime ->
InAppVideoBanner.create(
wrapper, autoRefreshTime,
wrapper, autoRefreshTime / 1000,
300, 250,
"9007b76d-c73c-49c6-b0a8-1c7890a84b33"
)
Expand Down Expand Up @@ -156,7 +160,7 @@ object AdTypesRepository {
"Banner 320x50",
onCreate = { _, wrapper, autoRefreshTime ->
InAppGamBanner.create(
wrapper, autoRefreshTime,
wrapper, autoRefreshTime / 1000,
320, 50,
"/21808260008/prebid_oxb_320x50_banner",
"50699c03-0910-477c-b4a4-911dbe2b9d42"
Expand All @@ -180,7 +184,7 @@ object AdTypesRepository {
"Video Banner",
onCreate = { _, wrapper, autoRefreshTime ->
InAppGamVideoBanner.create(
wrapper, autoRefreshTime,
wrapper, autoRefreshTime / 1000,
300, 250,
"/21808260008/prebid_oxb_300x250_banner",
"9007b76d-c73c-49c6-b0a8-1c7890a84b33"
Expand Down Expand Up @@ -217,7 +221,7 @@ object AdTypesRepository {
"Banner 320x50",
onCreate = { _, wrapper, autoRefreshTime ->
InAppMoPubBanner.create(
wrapper, autoRefreshTime,
wrapper, autoRefreshTime / 1000,
320, 50,
"093eef131ec7455b9bda52b7eb456c51",
"50699c03-0910-477c-b4a4-911dbe2b9d42"
Expand Down Expand Up @@ -260,7 +264,69 @@ object AdTypesRepository {
},
onDestroy = { InAppMoPubRewardedInterstitial.destroy() }
)
),

"In-App + AdMob" to listOf(
AdType(
"Banner",
onCreate = { activity, wrapper, autoRefreshTime ->
InAppAdMobBanner.create(
activity, wrapper, autoRefreshTime,
320, 50,
"ca-app-pub-1875909575462531/3793078260",
"50699c03-0910-477c-b4a4-911dbe2b9d42"
)
},
onDestroy = { InAppAdMobBanner.destroy() }
),
AdType(
"Display Interstitial",
onCreate = { activity, _, _ ->
InAppAdMobInterstitial.create(
activity,
"ca-app-pub-1875909575462531/6393291067",
"5a4b8dcf-f984-4b04-9448-6529908d6cb6"
)
},
onDestroy = { InAppAdMobInterstitial.destroy() }
),
AdType(
"Video Interstitial",
onCreate = { activity, _, _ ->
InAppAdMobInterstitial.create(
activity,
"ca-app-pub-1875909575462531/6393291067",
"12f58bc2-b664-4672-8d19-638bcc96fd5c"
)
},
onDestroy = { InAppAdMobInterstitial.destroy() }
),
AdType(
"Rewarded",
onCreate = { activity, _, _ ->
InAppAdMobRewarded.create(
activity,
"ca-app-pub-1875909575462531/1908212572",
"9007b76d-c73c-49c6-b0a8-1c7890a84b33"
)
},
onDestroy = { InAppAdMobRewarded.destroy() }
),
AdType(
"Native",
onCreate = { _, wrapper, _ ->
InAppAdMobNative.create(
wrapper,
"ca-app-pub-1875909575462531/9720985924",
"51fe68ba-aff2-401e-9e15-f3ed89d5c036"
)
},
onDestroy = {
InAppAdMobNative.destroy()
}
)
)

)

}
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ import android.util.Log
import android.view.WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON
import android.webkit.WebView
import com.google.android.gms.ads.MobileAds
import com.google.android.gms.ads.RequestConfiguration
import com.mopub.common.MoPub
import com.mopub.common.SdkConfiguration
import com.mopub.common.SdkInitializationListener
import com.mopub.common.logging.MoPubLog
import org.prebid.mobile.Host
import org.prebid.mobile.PrebidMobile
Expand All @@ -39,6 +39,7 @@ class CustomApplication : Application() {
super.onCreate()
initMopubSDK()
initPrebidSDK()
initAdMob()
if (BuildConfig.DEBUG) {
activateKeepScreenOnFlag()
}
Expand Down Expand Up @@ -67,6 +68,16 @@ class CustomApplication : Application() {
PrebidRenderingSettings.setAccountId("0689a263-318d-448b-a3d4-b02e8a709d9d")
}

private fun initAdMob() {
MobileAds.initialize(this) { status ->
Log.d("MobileAds", "Initialization complete.")
}
val configuration = RequestConfiguration.Builder().setTestDeviceIds(
listOf("38250D98D8E3A07A2C03CD3552013B29")
).build()
MobileAds.setRequestConfiguration(configuration)
}

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,90 @@
package org.prebid.mobile.prebidkotlindemo.ads.inappadmob

import android.app.Activity
import android.os.Bundle
import android.util.Log
import android.view.ViewGroup
import com.google.android.gms.ads.*
import com.google.android.gms.ads.initialization.InitializationStatus
import org.prebid.mobile.admob.AdMobBannerMediationUtils
import org.prebid.mobile.admob.PrebidBannerAdapter
import org.prebid.mobile.rendering.bidding.display.MediationBannerAdUnit

object InAppAdMobBanner {

private const val TAG = "InAppAdMobBanner"

private var bannerView: AdView? = null
private var adUnit: MediationBannerAdUnit? = null

fun create(
activity: Activity,
wrapper: ViewGroup,
autoRefreshTime: Int,
width: Int,
height: Int,
adUnitId: String,
configId: String
) {
MobileAds.initialize(wrapper.context) { status ->
Log.d("MobileAds", "Initialization complete.")
logAdaptersInitializationStatus(status)
}

/** Google recommends put activity for mediation ad networks */
bannerView = AdView(activity)
bannerView?.adSize = AdSize.BANNER
bannerView?.adUnitId = adUnitId
bannerView?.adListener = object : AdListener() {
override fun onAdLoaded() {
Log.d("AdListener", "Won ad network: ${bannerView?.responseInfo?.mediationAdapterClassName}")
}

override fun onAdFailedToLoad(p0: LoadAdError) {
Log.d("AdListener", "Failed to load ad $p0")
}
}
wrapper.addView(bannerView)

val extras = Bundle()
val request = AdRequest
.Builder()
.addCustomEventExtrasBundle(PrebidBannerAdapter::class.java, extras)
.build()
val mediationUtils = AdMobBannerMediationUtils(extras, bannerView)

adUnit = MediationBannerAdUnit(
wrapper.context,
configId,
org.prebid.mobile.rendering.bidding.data.AdSize(width, height),
mediationUtils
)
adUnit?.setRefreshInterval(autoRefreshTime / 1000)
adUnit?.fetchDemand { result ->
Log.d("Prebid", "Fetch demand result: $result")
bannerView?.loadAd(request)
}
}

fun destroy() {
bannerView?.destroy()
bannerView = null

adUnit?.destroy()
adUnit = null
}

private fun logAdaptersInitializationStatus(status: InitializationStatus) {
val statusMap = status.adapterStatusMap
for (adapterClass in statusMap.keys) {
val adapterStatus = statusMap[adapterClass]
val adapterDescription = adapterStatus?.description ?: ""
if (adapterDescription.isNotBlank()) {
Log.e("MobileAds", "Mediation adapter: $adapterClass $adapterDescription")
} else {
Log.d("MobileAds", "Mediation adapter: $adapterClass")
}
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package org.prebid.mobile.prebidkotlindemo.ads.inappadmob

import android.app.Activity
import android.os.Bundle
import android.util.Log
import com.google.android.gms.ads.AdRequest
import com.google.android.gms.ads.LoadAdError
import com.google.android.gms.ads.interstitial.InterstitialAd
import com.google.android.gms.ads.interstitial.InterstitialAdLoadCallback
import org.prebid.mobile.admob.AdMobInterstitialMediationUtils
import org.prebid.mobile.admob.PrebidInterstitialAdapter
import org.prebid.mobile.rendering.bidding.display.MediationInterstitialAdUnit
import org.prebid.mobile.rendering.bidding.enums.AdUnitFormat

object InAppAdMobInterstitial {

private var adUnit: MediationInterstitialAdUnit? = null
private var interstitialAd: InterstitialAd? = null

fun create(
activity: Activity,
adUnitId: String,
configId: String
) {
val extras = Bundle()
val request = AdRequest
.Builder()
.addCustomEventExtrasBundle(PrebidInterstitialAdapter::class.java, extras)
.build()
val mediationUtils = AdMobInterstitialMediationUtils(extras)

adUnit = MediationInterstitialAdUnit(
activity,
configId,
AdUnitFormat.DISPLAY,
mediationUtils
)
adUnit?.fetchDemand { result ->
Log.d("Prebid", "Fetch demand result: $result")

InterstitialAd.load(activity, adUnitId, request, object : InterstitialAdLoadCallback() {
override fun onAdLoaded(interstitial: InterstitialAd) {
interstitialAd = interstitial
interstitialAd?.show(activity)
}

override fun onAdFailedToLoad(error: LoadAdError) {
interstitialAd = null
}
})
}
}

fun destroy() {
adUnit?.destroy()
adUnit = null

interstitialAd = null
}

}
Loading

0 comments on commit 21cdde5

Please sign in to comment.