Skip to content

Commit

Permalink
release 6.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
mobile-ads-github committed Aug 31, 2023
1 parent 06ce05c commit eec405b
Show file tree
Hide file tree
Showing 64 changed files with 898 additions and 413 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ EULA is available at [EULA website] [LICENSE]
##### Add YandexMobileAds SDK:

```sh
implementation 'com.yandex.android:mobileads:5.10.0'
implementation 'com.yandex.android:mobileads:6.0.0'
```

##### Or you can use our library with all available mediations:
Expand All @@ -31,7 +31,7 @@ implementation 'com.yandex.android:mobileads:5.10.0'

dependencies {
...
implementation 'com.yandex.android:mobileads-mediation:5.10.0.0'
implementation 'com.yandex.android:mobileads-mediation:6.0.0.0'
}
```

Expand Down
3 changes: 2 additions & 1 deletion YandexMobileAdsExample/app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ android {

dependencies {
// Yandex Mobile Ads SDK with mediation adapters
implementation("com.yandex.android:mobileads-mediation:5.10.0.0")
implementation("com.yandex.android:mobileads-mediation:6.0.0.0")

implementation("androidx.appcompat:appcompat:1.5.1")
implementation("androidx.activity:activity-ktx:1.6.1")
Expand All @@ -63,4 +63,5 @@ dependencies {
implementation("androidx.coordinatorlayout:coordinatorlayout:1.2.0")
implementation("com.google.android.material:material:1.7.0")
implementation("com.google.android.exoplayer:exoplayer:2.18.1")
implementation("androidx.lifecycle:lifecycle-process:2.4.1")
}
5 changes: 3 additions & 2 deletions YandexMobileAdsExample/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,12 @@
android:name="com.yandex.ads.sample.adunits.InterstitialAdActivity"
android:exported="false" />
<activity
android:name="com.yandex.ads.sample.adunits.FlexBannerAdActivity"
android:name="com.yandex.ads.sample.adunits.InlineBannerAdActivity"
android:exported="false" />
<activity
android:name="com.yandex.ads.sample.adunits.StickyBannerAdActivity"
android:exported="false" />
<activity android:name=".adunits.AppOpenAdActivity" android:exported="false"/>
<activity
android:name=".HomeActivity"
android:exported="true">
Expand All @@ -59,7 +60,7 @@
android:value="@integer/google_play_services_version" />
<meta-data
android:name="com.google.android.gms.ads.APPLICATION_ID"
android:value="ca-app-pub-3940256099942544~3347511713" />
android:value="ca-app-pub-4449457472880521~8476795127" />

<receiver
android:name="com.vungle.warren.NetworkProviderReceiver"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ package com.yandex.ads.sample
import androidx.multidex.MultiDexApplication
import androidx.preference.PreferenceManager
import com.google.android.material.color.DynamicColors
import com.yandex.ads.sample.appopenad.AppOpenAdManager
import com.yandex.ads.sample.settings.CoppaDialogFragment
import com.yandex.ads.sample.settings.GdprDialogFragment
import com.yandex.ads.sample.settings.LocationDialogFragment
Expand All @@ -21,6 +22,8 @@ import com.yandex.mobile.ads.instream.MobileInstreamAds

class Application : MultiDexApplication() {

private val appOpenAdManager by lazy { AppOpenAdManager(this) }

override fun onCreate() {
super.onCreate()
Logger.initialize(this)
Expand All @@ -33,6 +36,8 @@ class Application : MultiDexApplication() {
MobileInstreamAds.setAdGroupPreloading(INSTREAM_AD_GROUP_PRELOADING_ENABLED)
MobileAds.initialize(this) {
Logger.debug("SDK initialized")
// wait until sdk initialized before using Ads
initAppOpenAdManager()
}
MobileAds.enableLogging(true)
}
Expand All @@ -46,6 +51,10 @@ class Application : MultiDexApplication() {
}
}

private fun initAppOpenAdManager() {
appOpenAdManager.initialize()
}

private companion object {
private const val INSTREAM_AD_GROUP_PRELOADING_ENABLED = true
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@ import androidx.preference.PreferenceManager
import androidx.recyclerview.widget.GridLayoutManager
import androidx.recyclerview.widget.LinearLayoutManager
import com.yandex.ads.sample.databinding.ActivityHomeBinding
import com.yandex.ads.sample.adunits.AppOpenAdActivity
import com.yandex.ads.sample.adunits.CustomNativeAdActivity
import com.yandex.ads.sample.adunits.FlexBannerAdActivity
import com.yandex.ads.sample.adunits.InlineBannerAdActivity
import com.yandex.ads.sample.adunits.InstreamAdBinderActivity
import com.yandex.ads.sample.adunits.InstreamAdInrollActivity
import com.yandex.ads.sample.adunits.InterstitialAdActivity
Expand Down Expand Up @@ -70,8 +71,8 @@ class HomeActivity : AppCompatActivity(R.layout.activity_home) {
),
NavigationItem(
R.drawable.ic_outline_aspect_ratio_24,
R.string.flex_banner_title,
FlexBannerAdActivity::class.java,
R.string.inline_banner_title,
InlineBannerAdActivity::class.java,
),
NavigationItem(
R.drawable.ic_outline_fullscreen_24,
Expand Down Expand Up @@ -113,6 +114,11 @@ class HomeActivity : AppCompatActivity(R.layout.activity_home) {
R.string.policies,
PoliciesActivity::class.java,
),
NavigationItem(
R.drawable.ic_full_coverage_24px,
R.string.appopenad_title,
AppOpenAdActivity::class.java,
),
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class NetworkWarningDialogFragment : DialogFragment() {
return MaterialAlertDialogBuilder(requireContext())
.setTitle(R.string.warning)
.setMessage(R.string.network_warning)
.setPositiveButton(R.string.ok) { _, _ -> setDialogShown() }
.setPositiveButton(R.string.ok_button) { _, _ -> setDialogShown() }
.create()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class AdInfoFragment : Fragment(R.layout.fragment_ad_info) {

var onLoadClickListener: (() -> Unit)? = null

private val binding get() = _binding!!
private val binding get() = requireNotNull(_binding)

private var selectedIndex = 0
private var _binding: FragmentAdInfoBinding? = null
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* This file is a part of the Yandex Advertising Network
*
* Version for Android (C) 2022 YANDEX
*
* You may not use this file except in compliance with the License.
* You may obtain a copy of the License at https://legal.yandex.com/partner_ch/
*/

package com.yandex.ads.sample.adunits

import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import com.yandex.ads.sample.R
import com.yandex.ads.sample.databinding.ActivityAppOpenAdBinding

class AppOpenAdActivity : AppCompatActivity(R.layout.activity_app_open_ad) {

private lateinit var binding: ActivityAppOpenAdBinding

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
binding = ActivityAppOpenAdBinding.inflate(layoutInflater)
binding.toolbar.setNavigationOnClickListener { onBackPressedDispatcher.onBackPressed() }
setContentView(binding.root)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import com.yandex.mobile.ads.nativeads.NativeAdViewBinder
class CustomNativeAdActivity : AppCompatActivity(R.layout.activity_custom_native_ad) {

private val nativeAdView get() = binding.nativeAd.root
private val adInfoFragment get() = _adInfoFragment!!
private val adInfoFragment get() = requireNotNull(_adInfoFragment)
private val eventLogger = NativeAdEventLogger()

private var nativeAdLoader: NativeAdLoader? = null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,36 +10,36 @@
package com.yandex.ads.sample.adunits

import android.os.Bundle
import android.view.ViewTreeObserver
import androidx.appcompat.app.AppCompatActivity
import androidx.constraintlayout.widget.ConstraintLayout
import androidx.fragment.app.commit
import com.yandex.ads.sample.R
import com.yandex.ads.sample.databinding.ActivityFlexBannerAdBinding
import com.yandex.ads.sample.databinding.ActivityInlineBannerAdBinding
import com.yandex.ads.sample.network.Network
import com.yandex.ads.sample.utils.ScreenUtil.screenHeight
import com.yandex.ads.sample.utils.ScreenUtil.screenWidth
import com.yandex.mobile.ads.banner.AdSize
import com.yandex.mobile.ads.banner.BannerAdEventListener
import com.yandex.mobile.ads.banner.BannerAdSize
import com.yandex.mobile.ads.banner.BannerAdView
import com.yandex.mobile.ads.common.AdRequest
import com.yandex.mobile.ads.common.AdRequestError
import com.yandex.mobile.ads.common.ImpressionData
import kotlin.math.roundToInt

class FlexBannerAdActivity : AppCompatActivity(R.layout.activity_flex_banner_ad) {
class InlineBannerAdActivity : AppCompatActivity(R.layout.activity_inline_banner_ad) {

private val adInfoFragment get() = _adInfoFragment!!
private val adInfoFragment get() = requireNotNull(_adInfoFragment)
private val eventLogger = BannerAdEventLogger()

private var bannerWidth = 0
private var bannerHeight = 0
private var _adInfoFragment: AdInfoFragment? = null
private var bannerAd: BannerAdView? = null
private var currentAdUnitId: String? = null
private var bannerAdSize: BannerAdSize? = null

private lateinit var binding: ActivityFlexBannerAdBinding
private lateinit var binding: ActivityInlineBannerAdBinding

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
binding = ActivityFlexBannerAdBinding.inflate(layoutInflater)
binding = ActivityInlineBannerAdBinding.inflate(layoutInflater)
binding.toolbar.setNavigationOnClickListener { onBackPressedDispatcher.onBackPressed() }
setContentView(binding.root)

Expand All @@ -49,31 +49,45 @@ class FlexBannerAdActivity : AppCompatActivity(R.layout.activity_flex_banner_ad)
setReorderingAllowed(true)
replace(R.id.ad_info, adInfoFragment)
}
initBanner()
bannerAd = binding.banner
configureBannerAdSize()
}

private fun initBanner() {
bannerAd = binding.banner
bannerWidth = screenWidth
bannerHeight = screenHeight / 3
private fun configureBannerAdSize() {
binding.coordinatorLayout.viewTreeObserver.addOnGlobalLayoutListener(object :
ViewTreeObserver.OnGlobalLayoutListener {
override fun onGlobalLayout() {
binding.coordinatorLayout.viewTreeObserver.removeOnGlobalLayoutListener(this)
val screenHeight = resources.displayMetrics.run { heightPixels / density }.roundToInt()
// Calculate the width of the ad, taking into account the padding in the ad container.
val adWidthPixels = binding.coordinatorLayout.width
val adWidth = (adWidthPixels / resources.displayMetrics.density).roundToInt()
val maxAdHeight = screenHeight / 3
bannerAdSize = BannerAdSize.inlineSize(this@InlineBannerAdActivity, adWidth, maxAdHeight)
}
})
}

private fun loadBanner() {
destroyBanner()
createBanner()
val adRequest = if (adInfoFragment.selectedNetwork.titleId == R.string.adfox_title) {
adFoxRequest
} else {
AdRequest.Builder().build()
fun loadBanner() {
bannerAdSize?.let { bannerAdSize ->
val selectedAdUnitId = adInfoFragment.selectedNetwork.adUnitId
if (currentAdUnitId != selectedAdUnitId) {
destroyBanner()
createBanner(selectedAdUnitId, bannerAdSize)
}
val adRequest = AdRequest.Builder()
.setParameters(getRequestParameters())
.build()
bannerAd?.loadAd(adRequest)
}
bannerAd?.loadAd(adRequest)
}

private fun createBanner() {
private fun createBanner(adUnitId: String, bannerAdSize: BannerAdSize) {
bannerAd = BannerAdView(this).apply {
id = R.id.banner
setAdUnitId(adInfoFragment.selectedNetwork.adUnitId)
setAdSize(AdSize.flexibleSize(bannerWidth, bannerHeight))
setAdUnitId(adUnitId)
currentAdUnitId = adUnitId
setAdSize(bannerAdSize)
setBannerAdEventListener(eventLogger)
}
val params = ConstraintLayout.LayoutParams(
Expand All @@ -91,6 +105,7 @@ class FlexBannerAdActivity : AppCompatActivity(R.layout.activity_flex_banner_ad)
binding.root.removeView(it)
}
bannerAd = null
currentAdUnitId = null
}

override fun onDestroy() {
Expand All @@ -99,6 +114,12 @@ class FlexBannerAdActivity : AppCompatActivity(R.layout.activity_flex_banner_ad)
super.onDestroy()
}

private fun getRequestParameters(): Map<String, String> {
return if (adInfoFragment.selectedNetwork.titleId == R.string.adfox_title) {
return mapOf("adf_ownerid" to "270901", "adf_p1" to "cqtgg", "adf_p2" to "fhlx")
} else emptyMap()
}

private inner class BannerAdEventLogger : BannerAdEventListener {

override fun onAdLoaded() {
Expand Down Expand Up @@ -139,14 +160,10 @@ class FlexBannerAdActivity : AppCompatActivity(R.layout.activity_flex_banner_ad)
Network(R.drawable.ic_applovin_icon_24, R.string.applovin_title, "demo-banner-applovin"),
Network(R.drawable.ic_chartboost_icon, R.string.chartboost_title, "demo-banner-chartboost"),
Network(R.drawable.ic_mintegral_logo, R.string.mintegral_title, "demo-banner-mintegral"),
Network(R.drawable.ic_mytarget_icon_24, R.string.my_target_title, "demo-banner-mytarget"),
Network(R.drawable.ic_mytarget_icon_24, R.string.my_target_title, "demo-banner-mytarget-mrec"),
Network(R.drawable.ic_startapp_icon_24, R.string.startapp_title, "demo-banner-startapp"),
Network(R.drawable.ic_vungle_icon_24, R.string.vungle_title, "demo-banner-vungle"),
Network(R.drawable.ic_adfox_icon, R.string.adfox_title, "R-M-243655-8"),
)

private val adFoxRequest = AdRequest.Builder().setParameters(
mapOf("adf_ownerid" to "270901", "adf_p1" to "cqtgh", "adf_p2" to "fkbd")
).build()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import com.yandex.mobile.ads.instream.InstreamAdRequestConfiguration

class InstreamAdBinderActivity : AppCompatActivity(R.layout.activity_instream_ad_binder) {

private val adInfoFragment get() = _adInfoFragment!!
private val adInfoFragment get() = requireNotNull(_adInfoFragment)
private val eventLogger = InstreamAdEventLogger()

private var instreamAdLoader: InstreamAdLoader? = null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import com.yandex.mobile.ads.instream.inroll.InrollQueueProvider

class InstreamAdInrollActivity : AppCompatActivity(R.layout.activity_instream_ad_inroll) {

private val adInfoFragment get() = _adInfoFragment!!
private val adInfoFragment get() = requireNotNull(_adInfoFragment)
private val eventLogger = InstreamAdEventLogger()

private var instreamAdPlayer: SampleInstreamAdPlayer? = null
Expand Down
Loading

0 comments on commit eec405b

Please sign in to comment.