|
@@ -2,18 +2,22 @@ package com.composition.android.ad.gromore.load.request.custom
|
|
|
|
|
|
import android.content.Context
|
|
|
import android.view.ViewGroup
|
|
|
-import android.view.ViewParent
|
|
|
import com.beizi.fusion.AdListener
|
|
|
import com.beizi.fusion.SplashAd
|
|
|
import com.bytedance.sdk.openadsdk.AdSlot
|
|
|
import com.bytedance.sdk.openadsdk.mediation.MediationConstant
|
|
|
+import com.bytedance.sdk.openadsdk.mediation.MediationConstant.AdIsReadyStatus
|
|
|
import com.bytedance.sdk.openadsdk.mediation.bridge.custom.splash.MediationCustomSplashLoader
|
|
|
import com.bytedance.sdk.openadsdk.mediation.custom.MediationCustomServiceConfig
|
|
|
+import com.composition.android.ad.gromore.util.ThreadUtils
|
|
|
import com.composition.android.lib.ad.util.adLogWithFrame
|
|
|
import com.composition.android.lib.ad.util.getScreenHeight
|
|
|
import com.composition.android.lib.ad.util.getScreenHeightDp
|
|
|
import com.composition.android.lib.ad.util.getScreenWidth
|
|
|
import com.composition.android.lib.ad.util.getScreenWidthDp
|
|
|
+import java.util.concurrent.Callable
|
|
|
+import java.util.concurrent.Future
|
|
|
+import java.util.concurrent.TimeUnit
|
|
|
|
|
|
/**
|
|
|
* @author: HuBoWen
|
|
@@ -25,61 +29,84 @@ class CustomBeiZiAppOpenRequestImpl : MediationCustomSplashLoader() {
|
|
|
private var splash: SplashAd? = null
|
|
|
|
|
|
override fun load(context: Context?, adSlot: AdSlot?, serviceConfig: MediationCustomServiceConfig?) {
|
|
|
+ ThreadUtils.runOnUIThread {
|
|
|
+ adLogWithFrame(msg = "scope onAdLoaded")
|
|
|
+ //step3:创建开屏广告请求参数AdSlot,具体参数含义参考文档
|
|
|
+ context?.apply {
|
|
|
+ val splashWidthDp: Float = getScreenWidthDp(context)
|
|
|
+ val splashWidthPx: Int = getScreenWidth(context)
|
|
|
+ val screenHeightPx: Int = getScreenHeight(context)
|
|
|
+ val screenHeightDp: Float = getScreenHeightDp(context)
|
|
|
|
|
|
- adLogWithFrame(msg = "scope onAdLoaded")
|
|
|
- //step3:创建开屏广告请求参数AdSlot,具体参数含义参考文档
|
|
|
- context?.apply {
|
|
|
- val splashWidthDp: Float = getScreenWidthDp(context)
|
|
|
- val splashWidthPx: Int = getScreenWidth(context)
|
|
|
- val screenHeightPx: Int = getScreenHeight(context)
|
|
|
- val screenHeightDp: Float = getScreenHeightDp(context)
|
|
|
+ // 开屏高度 = 屏幕高度 - 下方预留的高度,demo中是预留了屏幕高度的1/5,因此开屏高度传入 屏幕高度*4/5
|
|
|
+ val splashHeightDp: Float = screenHeightDp * 4 / 4f
|
|
|
+ val splashHeightPx: Int = (screenHeightPx * 4 / 4f).toInt()
|
|
|
|
|
|
- // 开屏高度 = 屏幕高度 - 下方预留的高度,demo中是预留了屏幕高度的1/5,因此开屏高度传入 屏幕高度*4/5
|
|
|
- val splashHeightDp: Float = screenHeightDp * 4 / 4f
|
|
|
- val splashHeightPx: Int = (screenHeightPx * 4 / 4f).toInt()
|
|
|
-
|
|
|
- splash = SplashAd(context, null, serviceConfig?.adnNetworkSlotId, object : AdListener {
|
|
|
- override fun onAdLoaded() {
|
|
|
- adLogWithFrame(msg = "scope onAdLoaded")
|
|
|
- if (biddingType == MediationConstant.AD_TYPE_CLIENT_BIDING) {
|
|
|
- var epcm = splash?.ecpm?.toDouble()
|
|
|
- epcm?.apply {
|
|
|
- if (this < 0) {
|
|
|
- epcm = 0.0
|
|
|
+ splash = SplashAd(context, null, serviceConfig?.adnNetworkSlotId, object : AdListener {
|
|
|
+ override fun onAdLoaded() {
|
|
|
+ adLogWithFrame(msg = "scope onAdLoaded")
|
|
|
+ if (biddingType == MediationConstant.AD_TYPE_CLIENT_BIDING) {
|
|
|
+ var epcm = splash?.ecpm?.toDouble()
|
|
|
+ epcm?.apply {
|
|
|
+ if (this < 0) {
|
|
|
+ epcm = 0.0
|
|
|
+ }
|
|
|
+ callLoadSuccess(epcm!!)
|
|
|
}
|
|
|
- callLoadSuccess(epcm!!)
|
|
|
+ } else {
|
|
|
+ callLoadSuccess()
|
|
|
}
|
|
|
- } else {
|
|
|
- callLoadSuccess()
|
|
|
}
|
|
|
- }
|
|
|
|
|
|
- override fun onAdShown() {
|
|
|
- adLogWithFrame(msg = "scope onAdShown")
|
|
|
- }
|
|
|
+ override fun onAdShown() {
|
|
|
+ adLogWithFrame(msg = "scope onAdShown")
|
|
|
+ }
|
|
|
|
|
|
- override fun onAdFailedToLoad(p0: Int) {
|
|
|
- adLogWithFrame(msg = "scope onAdFailedToLoad")
|
|
|
+ override fun onAdFailedToLoad(p0: Int) {
|
|
|
+ adLogWithFrame(msg = "scope onAdFailedToLoad")
|
|
|
// callLoadFail(p0, s)
|
|
|
- }
|
|
|
+ }
|
|
|
|
|
|
- override fun onAdClosed() {
|
|
|
- adLogWithFrame(msg = "scope onAdClosed")
|
|
|
- }
|
|
|
+ override fun onAdClosed() {
|
|
|
+ adLogWithFrame(msg = "scope onAdClosed")
|
|
|
+ callSplashAdSkip()
|
|
|
+ }
|
|
|
|
|
|
- override fun onAdTick(p0: Long) {
|
|
|
- adLogWithFrame(msg = "scope onAdTick")
|
|
|
- }
|
|
|
+ override fun onAdTick(p0: Long) {
|
|
|
+ adLogWithFrame(msg = "scope onAdTick")
|
|
|
+ }
|
|
|
|
|
|
- override fun onAdClicked() {
|
|
|
- adLogWithFrame(msg = "scope onAdClicked")
|
|
|
- }
|
|
|
- }, 5000)
|
|
|
- splash?.loadAd(splashWidthPx, (screenHeightPx - 100))
|
|
|
+ override fun onAdClicked() {
|
|
|
+ adLogWithFrame(msg = "scope onAdClicked")
|
|
|
+ callSplashAdClicked()
|
|
|
+ }
|
|
|
+ }, 5000)
|
|
|
+ splash?.loadAd(splashWidthPx, (screenHeightPx - 100))
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|
|
|
override fun showAd(container: ViewGroup?) {
|
|
|
splash?.show(container)
|
|
|
}
|
|
|
+
|
|
|
+ override fun isReadyCondition(): AdIsReadyStatus {
|
|
|
+ /**
|
|
|
+ * 在子线程中进行广告是否可用的判断
|
|
|
+ */
|
|
|
+ val future: Future<AdIsReadyStatus> = ThreadUtils.runOnThreadPool(Callable {
|
|
|
+ if (splash != null) {
|
|
|
+ AdIsReadyStatus.AD_IS_READY
|
|
|
+ } else {
|
|
|
+ AdIsReadyStatus.AD_IS_NOT_READY
|
|
|
+ }
|
|
|
+ })
|
|
|
+ try {
|
|
|
+ val result = future[500, TimeUnit.MILLISECONDS] //设置500毫秒的总超时,避免线程阻塞
|
|
|
+ return result ?: AdIsReadyStatus.AD_IS_NOT_READY
|
|
|
+ } catch (e: Exception) {
|
|
|
+ e.printStackTrace()
|
|
|
+ }
|
|
|
+ return AdIsReadyStatus.AD_IS_NOT_READY
|
|
|
+ }
|
|
|
}
|