Commit 802e3204 authored by wanglei's avatar wanglei

[移除]移除admob和max广告代码

parent 0260b885
......@@ -15,7 +15,8 @@ android {
compileSdk = 35
defaultConfig {
applicationId = "com.link.play.fit.ai.test1"// "com.link.play.fit.ai.test1"
// com.union_test.internationad
applicationId = "com.union_test.internationad"// "com.link.play.fit.ai.test1"
minSdk = 24
targetSdk = 35
versionCode = 1
......@@ -179,19 +180,19 @@ dependencies {
//广告
//admob渠道
implementation(libs.vungle)
implementation(libs.facebook)
implementation(libs.mintegral)
implementation(libs.pangle)
// implementation(libs.vungle)
// implementation(libs.facebook)
// implementation(libs.mintegral)
// implementation(libs.pangle)
//applovin sdk
implementation(libs.applovin)
// implementation(libs.applovin)
//applovin渠道
implementation(libs.applovin.google)
implementation(libs.applovin.admob)
implementation(libs.applovin.facebook) //meta
implementation(libs.applovin.mintegral)//mintegral
implementation(libs.applovin.pangle) //pangle
implementation(libs.applovin.vungle) //vungle
// implementation(libs.applovin.google)
// implementation(libs.applovin.admob)
// implementation(libs.applovin.facebook) //meta
// implementation(libs.applovin.mintegral)//mintegral
// implementation(libs.applovin.pangle) //pangle
// implementation(libs.applovin.vungle) //vungle
val work_version = "2.8.1"
implementation("androidx.work:work-runtime-ktx:$work_version")
......@@ -201,4 +202,10 @@ dependencies {
implementation("com.android.billingclient:billing-ktx:$billing_version")
implementation("com.google.android.gms:play-services-ads-identifier:18.2.0")
// If you use a version below 7.1.0.0, it depends on 'ads-sdk'
//implementation ('com.pangle.global:ads-sdk:6.5.0.6')
// If you use version 7.1.0.0 and above, it depends on 'pag-sdk'
implementation("com.pangle.global:pag-sdk:7.1.0.4")
}
\ No newline at end of file
......@@ -9,7 +9,7 @@
"client_info": {
"mobilesdk_app_id": "1:291586696477:android:44c70b7d2517719de66df4",
"android_client_info": {
"package_name": "com.link.play.fit.ai.test1"
"package_name": "com.union_test.internationad"
}
},
"oauth_client": [],
......
......@@ -62,4 +62,6 @@
# public static *** i(...);
# public static *** w(...);
# public static *** e(...);
#}
\ No newline at end of file
#}
-keep class com.bytedance.sdk.** { *; }
\ No newline at end of file
......@@ -3,6 +3,8 @@
xmlns:tools="http://schemas.android.com/tools">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission
android:name="android.permission.BATTERY_STATS"
tools:ignore="ProtectedPermissions" />
......@@ -47,11 +49,11 @@
android:screenOrientation="portrait"
android:theme="@style/splash.theme"
tools:ignore="DiscouragedApi,LockedOrientationActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<!-- <intent-filter>-->
<!-- <action android:name="android.intent.action.MAIN" />-->
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<!-- <category android:name="android.intent.category.LAUNCHER" />-->
<!-- </intent-filter>-->
</activity>
<activity
android:name=".ui.main.MainActivity"
......@@ -66,6 +68,16 @@
<!-- <category android:name="android.intent.category.LAUNCHER" /> -->
<!-- </intent-filter> -->
</activity>
<activity
android:name=".business.pangle.PangleActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".ui.language.LanguageActivity"
android:exported="false"
......@@ -214,9 +226,16 @@
</intent-filter>
</receiver>
<!-- <meta-data-->
<!-- android:name="com.google.android.gms.ads.APPLICATION_ID"-->
<!-- android:value="ca-app-pub-3940256099942544~3347511713" />-->
<meta-data
android:name="com.google.android.gms.ads.APPLICATION_ID"
android:value="ca-app-pub-3940256099942544~3347511713" />
android:value="ca-app-pub-2547387438729744~9596900917" />
<meta-data
android:name="com.google.android.gms.version"
android:value="@integer/google_play_services_version" />
<meta-data
android:name="com.facebook.sdk.ApplicationId"
android:value="@string/facebook_app_id" />
......
......@@ -55,4 +55,9 @@ object GlobalConfig {
inline val ID_MAX_OPEN get() = if (BuildConfig.DEBUG) "ad4efa4a0bc2a585" else "ad4efa4a0bc2a585"
inline val ID_MAX_BANNER get() = if (BuildConfig.DEBUG) "" else ""
inline val ID_MAX_REWARD get() = if (BuildConfig.DEBUG) "" else ""
inline val ID_PANGLE_APPLICATION get() = "8025677"
inline val ID_PANGLE_OPEN get() = "890000078"
inline val ID_PANGLE_INTER get() = "980088188"
}
\ No newline at end of file
......@@ -71,7 +71,7 @@ class MyApplication : Application() {
initUUid()
initGid()
initApp()
initLifeListener()
// initLifeListener()
initLanguage()
}
......
......@@ -6,7 +6,7 @@ package com.base.appzxhy.bean.config
*/
data class ConfigBean(
var isInBlackList: Boolean = false,
// var isInBlackList: Boolean = false,
val ut: Int = 0,
var vpnCanUse: Boolean = true,
val adConfigBean: AdConfigBean = AdConfigBean(),
......
package com.base.appzxhy.bean.push
import android.graphics.Bitmap
import kotlinx.serialization.Serializable
@Serializable
data class NotificationInfoBean(
val id: Int,
val title: String,
......
......@@ -5,29 +5,34 @@ import android.content.Context
import android.view.View
import android.view.ViewGroup
import androidx.annotation.LayoutRes
import com.applovin.sdk.AppLovinMediationProvider
import com.applovin.sdk.AppLovinSdk
import com.applovin.sdk.AppLovinSdkInitializationConfiguration
import com.base.appzxhy.BuildConfig
//import com.applovin.sdk.AppLovinMediationProvider
//import com.applovin.sdk.AppLovinSdk
//import com.applovin.sdk.AppLovinSdkInitializationConfiguration
//import com.base.appzxhy.BuildConfig
import com.base.appzxhy.GlobalConfig
import com.base.appzxhy.R
import com.base.appzxhy.bean.config.AdConfigBean.Companion.adsConfigBean
import com.base.appzxhy.bean.config.ConfigBean.Companion.configBean
import com.base.appzxhy.business.ads.admob.AdBannerMgr
import com.base.appzxhy.business.ads.admob.AdInterMgr
import com.base.appzxhy.business.ads.admob.AdNativeMgr
import com.base.appzxhy.business.ads.admob.AdOpenMgr
import com.base.appzxhy.business.ads.admob.AdmobEvent
import com.base.appzxhy.business.ads.applovin.AdMaxEvent
import com.base.appzxhy.business.ads.applovin.MaxInsertMgr
import com.base.appzxhy.business.ads.applovin.MaxNativeMgr
import com.base.appzxhy.business.ads.applovin.MaxOpenMgr
//import com.base.appzxhy.business.ads.admob.AdBannerMgr
//import com.base.appzxhy.business.ads.admob.AdInterMgr
//import com.base.appzxhy.business.ads.admob.AdNativeMgr
//import com.base.appzxhy.business.ads.admob.AdOpenMgr
//import com.base.appzxhy.business.ads.admob.AdmobEvent
//import com.base.appzxhy.business.ads.applovin.AdMaxEvent
//import com.base.appzxhy.business.ads.applovin.MaxInsertMgr
//import com.base.appzxhy.business.ads.applovin.MaxNativeMgr
//import com.base.appzxhy.business.ads.applovin.MaxOpenMgr
import com.base.appzxhy.business.helper.EventUtils
import com.base.appzxhy.business.pangle.PangleOpenMgr
import com.base.appzxhy.utils.AppPreferences
import com.base.appzxhy.utils.LogEx
import com.base.appzxhy.utils.ToastUtils.toast
import com.google.android.gms.ads.MobileAds
import com.bytedance.sdk.openadsdk.api.init.PAGConfig
import com.bytedance.sdk.openadsdk.api.init.PAGSdk
import com.bytedance.sdk.openadsdk.api.init.PAGSdk.PAGInitCallback
//import com.google.android.gms.ads.MobileAds
import com.google.android.gms.ads.identifier.AdvertisingIdClient
import com.google.android.gms.ads.initialization.AdapterStatus
//import com.google.android.gms.ads.initialization.AdapterStatus
import java.util.Collections
import java.util.concurrent.Executors
......@@ -36,40 +41,44 @@ import java.util.concurrent.Executors
*/
object AdsMgr {
private val adOpenMgr by lazy {
AdOpenMgr()
}
private val adInterMgr by lazy {
AdInterMgr()
}
private val adNativeMgr by lazy {
AdNativeMgr()
}
private val adBannerMgr by lazy {
AdBannerMgr()
}
private val maxOpenMgr by lazy {
MaxOpenMgr()
}
private val maxInsertMgr by lazy {
MaxInsertMgr()
}
private val maxNativeMgr by lazy {
MaxNativeMgr()
// private val adOpenMgr by lazy {
// AdOpenMgr()
// }
// private val adInterMgr by lazy {
// AdInterMgr()
// }
// private val adNativeMgr by lazy {
// AdNativeMgr()
// }
// private val adBannerMgr by lazy {
// AdBannerMgr()
// }
// private val maxOpenMgr by lazy {
// MaxOpenMgr()
// }
// private val maxInsertMgr by lazy {
// MaxInsertMgr()
// }
// private val maxNativeMgr by lazy {
// MaxNativeMgr()
// }
private val pangleOpenMgr by lazy {
PangleOpenMgr()
}
/**
* 是否初始化
*/
var isAdmobInit = false
private set
// var isAdmobInit = false
// private set
/**
* 是否初始化
*/
var isMaxInit = false
private set
// var isMaxInit = false
// private set
var isAdUtEvent = false
......@@ -86,73 +95,99 @@ object AdsMgr {
* @param context 这里最好是appContext,因为是耗时操作,等它初始化完毕马上加载开屏和插屏广告
*/
fun init(context: Context) {
if (configBean.isInBlackList) {
EventUtils.event("isInBlackList", value = "isInBlackList=${configBean.isInBlackList}")
return
}
initAdmob(context)
initMax(context)
initPangle(context)
// if (configBean.isInBlackList) {
// EventUtils.event("isInBlackList", value = "isInBlackList=${configBean.isInBlackList}")
// return
// }
// initAdmob(context)
// initMax(context)
}
private fun initAdmob(context: Context) {
if (isAdmobInit) return
MobileAds.initialize(context) {
val readyAdapter = it.adapterStatusMap.entries.find { entry ->
entry.value.initializationState == AdapterStatus.State.READY
}
isAdmobInit = readyAdapter != null
EventUtils.event("AdmobInit", "AdmobInit=$isAdmobInit")
// context.toast("admob init")
if (adsConfigBean.adSwitch) {
admobInitCallBack?.invoke()
admobInitCallBack = null
adNativeMgr.loadAd(context, AdmobEvent("nativeAd", context::class.java.simpleName))
adOpenMgr.loadAd(context, AdmobEvent("openAd", context::class.java.simpleName))
adInterMgr.loadAd(context, AdmobEvent("interAd", context::class.java.simpleName))
}
}
// private fun initAdmob(context: Context) {
// if (isAdmobInit) return
// MobileAds.initialize(context) {
// val readyAdapter = it.adapterStatusMap.entries.find { entry ->
// entry.value.initializationState == AdapterStatus.State.READY
// }
// isAdmobInit = readyAdapter != null
// EventUtils.event("AdmobInit", "AdmobInit=$isAdmobInit")
//// context.toast("admob init")
//
// if (adsConfigBean.adSwitch) {
// admobInitCallBack?.invoke()
// admobInitCallBack = null
// adNativeMgr.loadAd(context, AdmobEvent("nativeAd", context::class.java.simpleName))
// adOpenMgr.loadAd(context, AdmobEvent("openAd", context::class.java.simpleName))
// adInterMgr.loadAd(context, AdmobEvent("interAd", context::class.java.simpleName))
// }
// }
//
// }
// private fun initMax(context: Context) = kotlin.runCatching {
// if (isMaxInit) return@runCatching
// val executor = Executors.newSingleThreadExecutor()
//
// executor.execute {
// val currentGaid = AdvertisingIdClient.getAdvertisingIdInfo(context).id
// AppPreferences.getInstance().getString("gid", currentGaid)
//
// val build = AppLovinSdkInitializationConfiguration
// .builder(GlobalConfig.KEY_MAX, context)
//
// build.mediationProvider = AppLovinMediationProvider.MAX
// if (BuildConfig.DEBUG) {
// build.testDeviceAdvertisingIds = Collections.singletonList(currentGaid)
// }
// val initConfig = build.build()
// runCatching {
// AppLovinSdk.getInstance(context).initialize(initConfig) {
// isMaxInit = true
//// maxOpenMgr.loadAd(context)
// if (!adsConfigBean.adSwitch) {
//// maxInsertMgr.loadAd(context, AdMaxEvent("interAd", context::class.java.simpleName))
// context.toast("max init")
// maxInitCallBack?.invoke()
// maxInitCallBack = null
// }
// }
// }
//
// }
//
// }
// var admobInitCallBack: (() -> Unit)? = null
// var maxInitCallBack: (() -> Unit)? = null
private fun buildNewConfig(context: Context): PAGConfig? {
return PAGConfig.Builder()
.appId(GlobalConfig.ID_PANGLE_APPLICATION)
.appIcon(R.mipmap.logo)
.debugLog(true)
.supportMultiProcess(false)
.build()
}
private fun initMax(context: Context) = kotlin.runCatching {
if (isMaxInit) return@runCatching
val executor = Executors.newSingleThreadExecutor()
fun initPangle(context: Context) {
executor.execute {
val currentGaid = AdvertisingIdClient.getAdvertisingIdInfo(context).id
AppPreferences.getInstance().getString("gid", currentGaid)
val build = AppLovinSdkInitializationConfiguration
.builder(GlobalConfig.KEY_MAX, context)
val pAGInitConfig = buildNewConfig(context)
PAGSdk.init(context, pAGInitConfig, object : PAGInitCallback {
override fun success() {
build.mediationProvider = AppLovinMediationProvider.MAX
if (BuildConfig.DEBUG) {
build.testDeviceAdvertisingIds = Collections.singletonList(currentGaid)
val version = PAGSdk.getSDKVersion()
val isInitSuccess = PAGSdk.isInitSuccess()
context.toast("pangle init success $version")
}
val initConfig = build.build()
runCatching {
AppLovinSdk.getInstance(context).initialize(initConfig) {
isMaxInit = true
// maxOpenMgr.loadAd(context)
if (!adsConfigBean.adSwitch) {
maxInsertMgr.loadAd(context, AdMaxEvent("interAd", context::class.java.simpleName))
context.toast("max init")
maxInitCallBack?.invoke()
maxInitCallBack = null
}
}
}
}
override fun fail(code: Int, msg: String?) {
context.toast("pangle init fail code=$code msg=$msg")
}
})
}
var admobInitCallBack: (() -> Unit)? = null
var maxInitCallBack: (() -> Unit)? = null
/**
* 展示开屏广告
......@@ -172,31 +207,25 @@ object AdsMgr {
return
}
if (configBean.isInBlackList) {
EventUtils.event("isInBlackList", "isInBlackList=${configBean.isInBlackList}")
showCallBack?.failed()
return
}
// if (configBean.isInBlackList) {
// EventUtils.event("isInBlackList", "isInBlackList=${configBean.isInBlackList}")
// showCallBack?.failed()
// return
// }
val from = activity::class.java.simpleName
if (adsConfigBean.adSwitch) {
val admobEvent = AdmobEvent("openAd", from).apply { this.isUnLimit = isUnLimit }
if (isAdmobInit) {
adOpenMgr.show(activity, admobEvent, showCallBack)
} else {
admobInitCallBack = {
}
adOpenMgr.show(activity, admobEvent, showCallBack)
}
} else {
if (isMaxInit) {
maxOpenMgr.show(activity, isUnLimit, AdMaxEvent("openAd", from), showCallBack)
} else {
maxInitCallBack = {
maxOpenMgr.show(activity, isUnLimit, AdMaxEvent("openAd", from), showCallBack)
}
}
}
// if (false) {
// val admobEvent = AdmobEvent("openAd", from).apply { this.isUnLimit = isUnLimit }
// if (isAdmobInit) {
// adOpenMgr.show(activity, admobEvent, showCallBack)
// } else {
// admobInitCallBack = {
// }
// adOpenMgr.show(activity, admobEvent, showCallBack)
// }
// } else {
pangleOpenMgr.show(activity, showCallBack)
// }
}
......@@ -219,18 +248,18 @@ object AdsMgr {
return
}
if (configBean.isInBlackList) {
EventUtils.event("isInBlackList", configBean.isInBlackList.toString())
showCallBack?.failed()
return
}
// if (configBean.isInBlackList) {
// EventUtils.event("isInBlackList", configBean.isInBlackList.toString())
// showCallBack?.failed()
// return
// }
LogEx.logDebug("showAd", "adSwitch=${adsConfigBean.adSwitch}")
val from = activity::class.java.simpleName
if (adsConfigBean.adSwitch) {
adInterMgr.show(activity, AdmobEvent("interAd", from).apply { this.isUnLimit = isUnLimit }, showCallBack)
} else {
maxInsertMgr.show(activity, isUnLimit, AdMaxEvent("interAd", from), showCallBack)
}
// if (true) {
// adInterMgr.show(activity, AdmobEvent("interAd", from).apply { this.isUnLimit = isUnLimit }, showCallBack)
// } else {
// maxInsertMgr.show(activity, isUnLimit, AdMaxEvent("interAd", from), showCallBack)
// }
}
/**
......@@ -250,24 +279,24 @@ object AdsMgr {
return
}
nativeView.visibility = View.VISIBLE
if (configBean.isInBlackList) {
EventUtils.event("isInBlackList", configBean.isInBlackList.toString())
return
}
// if (configBean.isInBlackList) {
// EventUtils.event("isInBlackList", configBean.isInBlackList.toString())
// return
// }
val showNative = {
if (adsConfigBean.adSwitch) {
adNativeMgr.show(AdmobEvent("nativeAd", "nativeAd"), nativeView, layout, nativeCallBack)
if (true) {
// adNativeMgr.show(AdmobEvent("nativeAd", "nativeAd"), nativeView, layout, nativeCallBack)
} else {
maxNativeMgr.show(AdMaxEvent("nativeAd", "nativeAd"), nativeView, layout, nativeCallBack)
// maxNativeMgr.show(AdMaxEvent("nativeAd", "nativeAd"), nativeView, layout, nativeCallBack)
}
}
if (isAdmobInit) {
showNative.invoke()
} else {
admobInitCallBack = { showNative.invoke() }
}
// if (isAdmobInit) {
// showNative.invoke()
// } else {
// admobInitCallBack = { showNative.invoke() }
// }
}
......@@ -282,12 +311,12 @@ object AdsMgr {
return
}
parent.visibility = View.VISIBLE
if (configBean.isInBlackList) {
EventUtils.event("isInBlackList", configBean.isInBlackList.toString())
return
}
if (adsConfigBean.adSwitch) {
adBannerMgr.show(parent, collapsible, adClose)
}
// if (configBean.isInBlackList) {
// EventUtils.event("isInBlackList", configBean.isInBlackList.toString())
// return
// }
// if (adsConfigBean.adSwitch) {
// adBannerMgr.show(parent, collapsible, adClose)
// }
}
}
\ No newline at end of file
......@@ -9,13 +9,13 @@ import android.widget.FrameLayout
import android.widget.ImageView
import android.widget.TextView
import androidx.annotation.LayoutRes
import com.applovin.mediation.MaxAd
import com.applovin.mediation.nativeAds.MaxNativeAdLoader
import com.applovin.mediation.nativeAds.MaxNativeAdView
import com.applovin.mediation.nativeAds.MaxNativeAdViewBinder
//import com.applovin.mediation.MaxAd
//import com.applovin.mediation.nativeAds.MaxNativeAdLoader
//import com.applovin.mediation.nativeAds.MaxNativeAdView
//import com.applovin.mediation.nativeAds.MaxNativeAdViewBinder
import com.base.appzxhy.R
import com.google.android.gms.ads.nativead.NativeAd
import com.google.android.gms.ads.nativead.NativeAdView
//import com.google.android.gms.ads.nativead.NativeAd
//import com.google.android.gms.ads.nativead.NativeAdView
import androidx.core.content.withStyledAttributes
@SuppressLint("ViewConstructor")
......@@ -40,84 +40,84 @@ class NativeParentView(context: Context, attrs: AttributeSet? = null) :
}
fun setNativeAd(
nativeAd: NativeAd,
@LayoutRes resource: Int? = null,
) {
val layout = resource ?: R.layout.layout_admob_native_custom
val adView =
layout.let { LayoutInflater.from(context).inflate(it, null) } as NativeAdView
adView.mediaView = adView.findViewById(R.id.ad_media)
adView.headlineView = adView.findViewById(R.id.ad_headline)
adView.bodyView = adView.findViewById(R.id.ad_body)
adView.callToActionView = adView.findViewById(R.id.ad_call_to_action)
adView.iconView = adView.findViewById(R.id.ad_app_icon)
(adView.headlineView as TextView?)?.text = nativeAd.headline
adView.mediaView?.mediaContent = nativeAd.mediaContent
if (nativeAd.body == null) {
adView.bodyView?.visibility = INVISIBLE
} else {
adView.bodyView?.visibility = VISIBLE
(adView.bodyView as TextView?)?.text = nativeAd.body
}
if (nativeAd.callToAction == null) {
adView.callToActionView?.visibility = INVISIBLE
} else {
adView.callToActionView?.visibility = VISIBLE
(adView.callToActionView as Button?)?.text = nativeAd.callToAction
}
if (nativeAd.icon == null) {
adView.iconView?.visibility = GONE
} else {
(adView.iconView as ImageView?)?.setImageDrawable(
nativeAd.icon?.drawable
)
adView.iconView?.visibility = VISIBLE
}
adView.setNativeAd(nativeAd)
setBackgroundResource(0)
if (removeAll) {
removeAllViews()
}
val params = LayoutParams(
LayoutParams.MATCH_PARENT,
LayoutParams.WRAP_CONTENT
)
params.gravity = adGravity
addView(adView, params)
}
fun setNativeAd(
nativeAdLoader: MaxNativeAdLoader,
nativeAd: MaxAd,
@LayoutRes resource: Int? = null
) {
val layout = resource ?: R.layout.layout_max_native_custom
val binder: MaxNativeAdViewBinder =
MaxNativeAdViewBinder.Builder(layout)
.setTitleTextViewId(R.id.title_text_view)
.setBodyTextViewId(R.id.body_text_view)
.setAdvertiserTextViewId(R.id.advertiser_text_view)
.setIconImageViewId(R.id.icon_image_view)
.setMediaContentViewGroupId(R.id.media_view_container)
.setOptionsContentViewGroupId(R.id.options_view)
.setStarRatingContentViewGroupId(R.id.star_rating_view)
.setCallToActionButtonId(R.id.cta_button)
.build()
val adView = MaxNativeAdView(binder, context)
nativeAdLoader.render(adView, nativeAd)
setBackgroundResource(0)
removeAllViews()
val params = LayoutParams(
LayoutParams.MATCH_PARENT,
LayoutParams.WRAP_CONTENT
)
params.gravity = adGravity
addView(adView, params)
}
// fun setNativeAd(
// nativeAd: NativeAd,
// @LayoutRes resource: Int? = null,
// ) {
//
// val layout = resource ?: R.layout.layout_admob_native_custom
// val adView =
// layout.let { LayoutInflater.from(context).inflate(it, null) } as NativeAdView
// adView.mediaView = adView.findViewById(R.id.ad_media)
// adView.headlineView = adView.findViewById(R.id.ad_headline)
// adView.bodyView = adView.findViewById(R.id.ad_body)
// adView.callToActionView = adView.findViewById(R.id.ad_call_to_action)
// adView.iconView = adView.findViewById(R.id.ad_app_icon)
// (adView.headlineView as TextView?)?.text = nativeAd.headline
// adView.mediaView?.mediaContent = nativeAd.mediaContent
// if (nativeAd.body == null) {
// adView.bodyView?.visibility = INVISIBLE
// } else {
// adView.bodyView?.visibility = VISIBLE
// (adView.bodyView as TextView?)?.text = nativeAd.body
// }
// if (nativeAd.callToAction == null) {
// adView.callToActionView?.visibility = INVISIBLE
// } else {
// adView.callToActionView?.visibility = VISIBLE
// (adView.callToActionView as Button?)?.text = nativeAd.callToAction
// }
// if (nativeAd.icon == null) {
// adView.iconView?.visibility = GONE
// } else {
// (adView.iconView as ImageView?)?.setImageDrawable(
// nativeAd.icon?.drawable
// )
// adView.iconView?.visibility = VISIBLE
// }
// adView.setNativeAd(nativeAd)
// setBackgroundResource(0)
// if (removeAll) {
// removeAllViews()
// }
//
// val params = LayoutParams(
// LayoutParams.MATCH_PARENT,
// LayoutParams.WRAP_CONTENT
// )
// params.gravity = adGravity
//
// addView(adView, params)
// }
//
// fun setNativeAd(
// nativeAdLoader: MaxNativeAdLoader,
// nativeAd: MaxAd,
// @LayoutRes resource: Int? = null
// ) {
// val layout = resource ?: R.layout.layout_max_native_custom
// val binder: MaxNativeAdViewBinder =
// MaxNativeAdViewBinder.Builder(layout)
// .setTitleTextViewId(R.id.title_text_view)
// .setBodyTextViewId(R.id.body_text_view)
// .setAdvertiserTextViewId(R.id.advertiser_text_view)
// .setIconImageViewId(R.id.icon_image_view)
// .setMediaContentViewGroupId(R.id.media_view_container)
// .setOptionsContentViewGroupId(R.id.options_view)
// .setStarRatingContentViewGroupId(R.id.star_rating_view)
// .setCallToActionButtonId(R.id.cta_button)
// .build()
// val adView = MaxNativeAdView(binder, context)
// nativeAdLoader.render(adView, nativeAd)
// setBackgroundResource(0)
// removeAllViews()
//
// val params = LayoutParams(
// LayoutParams.MATCH_PARENT,
// LayoutParams.WRAP_CONTENT
// )
// params.gravity = adGravity
//
// addView(adView, params)
// }
}
package com.base.appzxhy.business.ads
import com.base.appzxhy.GlobalConfig
import com.google.android.gms.ads.appopen.AppOpenAd
import com.google.android.gms.ads.interstitial.InterstitialAd
import com.google.android.gms.ads.nativead.NativeAd
import com.google.android.gms.ads.rewarded.RewardedAd
import com.reyun.solar.engine.SolarEngineManager
import com.reyun.solar.engine.infos.SEAdImpEventModel
import org.json.JSONObject
/**
* https://help.solar-engine.com/cn/docs/yu-ding-yi-shi-jian
*/
object SolarEngineEvent {
fun eventSolar(ad: Any?, valueMicros: Long) {
val json = JSONObject()
//变现平台
val adNetworkPlatform = "AdMob"
//聚合平台标识
val mediationPlatform = "admob"
//广告的类型
// adType 为激励视频时,只需要传入 1
// 1:激励视频
// 2:开屏
// 3:插屏
// 4:全屏视频
// 5:Banner
// 6:信息流
// 7:短视频信息流
// 8:大横幅
// 9:视频贴片
// 10:中等尺寸横幅
// 0:其它
var adType = -1
//变现平台的应用 ID
val adNetworkAppID = GlobalConfig.ID_ADMOB_APPLICATION
//变现平台的变现广告位 ID
var adNetworkADID = ""
//广告 ecpm,单位:元(广告千次展现的变现收入,0或负值表示没传,单位为元)
val ecpm = valueMicros / 1000.0
//货币种类
val currencyType = "USD"
when (ad) {
is AppOpenAd -> {
adType = 2
adNetworkADID = ad.adUnitId
}
is InterstitialAd -> {
adType = 3
adNetworkADID = ad.adUnitId
}
is NativeAd -> {
adType = 6
adNetworkADID = GlobalConfig.ID_ADMOB_NATIVE
}
is RewardedAd -> {
adType = 1
adNetworkADID = ad.adUnitId
}
else -> {//banner
adType = 5
adNetworkADID = GlobalConfig.ID_ADMOB_BANNER
}
}
try {
val seAdImpEventModel = SEAdImpEventModel(
adNetworkPlatform,
mediationPlatform,
adType,
adNetworkAppID,
adNetworkADID,
ecpm,
currencyType,
true,
json
)
SolarEngineManager.getInstance().trackAdImpression(seAdImpEventModel)
} catch (e: Exception) {
//
}
}
}
\ No newline at end of file
//package com.base.appzxhy.business.ads
//
//import com.base.appzxhy.GlobalConfig
//import com.google.android.gms.ads.appopen.AppOpenAd
//import com.google.android.gms.ads.interstitial.InterstitialAd
//import com.google.android.gms.ads.nativead.NativeAd
//import com.google.android.gms.ads.rewarded.RewardedAd
//import com.reyun.solar.engine.SolarEngineManager
//import com.reyun.solar.engine.infos.SEAdImpEventModel
//import org.json.JSONObject
//
///**
// * https://help.solar-engine.com/cn/docs/yu-ding-yi-shi-jian
// */
//object SolarEngineEvent {
//
// fun eventSolar(ad: Any?, valueMicros: Long) {
//
// val json = JSONObject()
// //变现平台
// val adNetworkPlatform = "AdMob"
// //聚合平台标识
// val mediationPlatform = "admob"
// //广告的类型
//// adType 为激励视频时,只需要传入 1
//// 1:激励视频
//// 2:开屏
//// 3:插屏
//// 4:全屏视频
//// 5:Banner
//// 6:信息流
//// 7:短视频信息流
//// 8:大横幅
//// 9:视频贴片
//// 10:中等尺寸横幅
//// 0:其它
// var adType = -1
// //变现平台的应用 ID
// val adNetworkAppID = GlobalConfig.ID_ADMOB_APPLICATION
// //变现平台的变现广告位 ID
// var adNetworkADID = ""
// //广告 ecpm,单位:元(广告千次展现的变现收入,0或负值表示没传,单位为元)
// val ecpm = valueMicros / 1000.0
// //货币种类
// val currencyType = "USD"
//
// when (ad) {
// is AppOpenAd -> {
// adType = 2
// adNetworkADID = ad.adUnitId
// }
//
// is InterstitialAd -> {
// adType = 3
// adNetworkADID = ad.adUnitId
// }
//
// is NativeAd -> {
// adType = 6
// adNetworkADID = GlobalConfig.ID_ADMOB_NATIVE
// }
//
// is RewardedAd -> {
// adType = 1
// adNetworkADID = ad.adUnitId
// }
//
// else -> {//banner
// adType = 5
// adNetworkADID = GlobalConfig.ID_ADMOB_BANNER
// }
// }
//
// try {
// val seAdImpEventModel = SEAdImpEventModel(
// adNetworkPlatform,
// mediationPlatform,
// adType,
// adNetworkAppID,
// adNetworkADID,
// ecpm,
// currencyType,
// true,
// json
// )
// SolarEngineManager.getInstance().trackAdImpression(seAdImpEventModel)
// } catch (e: Exception) {
// //
// }
//
// }
//}
\ No newline at end of file
package com.base.appzxhy.business.ads.admob
import android.os.Bundle
import android.view.ViewGroup
import android.view.ViewTreeObserver
import com.base.appzxhy.GlobalConfig
import com.base.appzxhy.bean.config.AdConfigBean
import com.base.appzxhy.business.ads.AdsType
import com.base.appzxhy.business.ads.LimitUtils
import com.google.ads.mediation.admob.AdMobAdapter
import com.google.android.gms.ads.AdListener
import com.google.android.gms.ads.AdRequest
import com.google.android.gms.ads.AdSize
import com.google.android.gms.ads.AdView
import com.google.android.gms.ads.LoadAdError
import java.util.UUID
/**
*banner广告加载显示管理类
*/
class AdBannerMgr {
private var adView: AdView? = null
private var listener: ViewTreeObserver.OnGlobalLayoutListener? = null
fun show(parent: ViewGroup, collapsible: Boolean, adClose: (() -> Unit)? = null) {
if (!AdConfigBean.adsConfigBean.adSwitch) {
return
}
val admobEvent = AdmobEvent("banner", "banner")
if (!LimitUtils.isAdShow(AdsType.BANNER, admobEvent)) {
adView = null
return
}
parent.removeAllViews()
adView?.destroy()
adView = null
adView = AdView(parent.context)
parent.addView(adView)
adView?.let { it.onPaidEventListener = AdmobOnPaidEventListener(it, admobEvent.scope) }
listener = ViewTreeObserver.OnGlobalLayoutListener {
val screenPixelDensity = parent.context.resources.displayMetrics.density
val adWidth = (parent.width / screenPixelDensity).toInt()
val adSize =
AdSize.getCurrentOrientationAnchoredAdaptiveBannerAdSize(parent.context, adWidth)
adView?.adUnitId = GlobalConfig.ID_ADMOB_BANNER
adView?.setAdSize(adSize)
loadAd(admobEvent, collapsible, adClose)
parent.viewTreeObserver.removeOnGlobalLayoutListener(listener)
}
parent.viewTreeObserver.addOnGlobalLayoutListener(listener)
}
fun loadAd(admobEvent: AdmobEvent, collapsible: Boolean, adClose: (() -> Unit)?) {
val build = AdRequest.Builder()
if (collapsible) {
val extras = Bundle()
extras.putString("collapsible", "bottom")
extras.putString("collapsible_request_id", UUID.randomUUID().toString())
build.addNetworkExtrasBundle(AdMobAdapter::class.java, extras)
}
val adRequest = build.build()
adView?.adListener =
object : AdListener() {
override fun onAdFailedToLoad(loadAdError: LoadAdError) {
super.onAdFailedToLoad(loadAdError)
admobEvent.pullAd(loadAdError.responseInfo, loadAdError)
}
override fun onAdLoaded() {
admobEvent.pullAd(adView?.responseInfo)
}
override fun onAdOpened() {
}
override fun onAdClosed() {
super.onAdClosed()
adClose?.invoke()
}
}
admobEvent.adPulStart()
adView?.loadAd(adRequest)
}
}
\ No newline at end of file
//package com.base.appzxhy.business.ads.admob
//
//import android.os.Bundle
//import android.view.ViewGroup
//import android.view.ViewTreeObserver
//import com.base.appzxhy.GlobalConfig
//import com.base.appzxhy.bean.config.AdConfigBean
//import com.base.appzxhy.business.ads.AdsType
//import com.base.appzxhy.business.ads.LimitUtils
//import com.google.ads.mediation.admob.AdMobAdapter
//import com.google.android.gms.ads.AdListener
//import com.google.android.gms.ads.AdRequest
//import com.google.android.gms.ads.AdSize
//import com.google.android.gms.ads.AdView
//import com.google.android.gms.ads.LoadAdError
//import java.util.UUID
//
///**
// *banner广告加载显示管理类
// */
//class AdBannerMgr {
//
// private var adView: AdView? = null
// private var listener: ViewTreeObserver.OnGlobalLayoutListener? = null
//
// fun show(parent: ViewGroup, collapsible: Boolean, adClose: (() -> Unit)? = null) {
//
// if (!AdConfigBean.adsConfigBean.adSwitch) {
// return
// }
// val admobEvent = AdmobEvent("banner", "banner")
//
// if (!LimitUtils.isAdShow(AdsType.BANNER, admobEvent)) {
// adView = null
// return
// }
//
// parent.removeAllViews()
//
// adView?.destroy()
// adView = null
//
// adView = AdView(parent.context)
// parent.addView(adView)
// adView?.let { it.onPaidEventListener = AdmobOnPaidEventListener(it, admobEvent.scope) }
//
// listener = ViewTreeObserver.OnGlobalLayoutListener {
// val screenPixelDensity = parent.context.resources.displayMetrics.density
// val adWidth = (parent.width / screenPixelDensity).toInt()
// val adSize =
// AdSize.getCurrentOrientationAnchoredAdaptiveBannerAdSize(parent.context, adWidth)
// adView?.adUnitId = GlobalConfig.ID_ADMOB_BANNER
// adView?.setAdSize(adSize)
// loadAd(admobEvent, collapsible, adClose)
// parent.viewTreeObserver.removeOnGlobalLayoutListener(listener)
// }
// parent.viewTreeObserver.addOnGlobalLayoutListener(listener)
// }
//
//
// fun loadAd(admobEvent: AdmobEvent, collapsible: Boolean, adClose: (() -> Unit)?) {
// val build = AdRequest.Builder()
//
// if (collapsible) {
// val extras = Bundle()
// extras.putString("collapsible", "bottom")
// extras.putString("collapsible_request_id", UUID.randomUUID().toString())
// build.addNetworkExtrasBundle(AdMobAdapter::class.java, extras)
// }
// val adRequest = build.build()
// adView?.adListener =
// object : AdListener() {
// override fun onAdFailedToLoad(loadAdError: LoadAdError) {
// super.onAdFailedToLoad(loadAdError)
// admobEvent.pullAd(loadAdError.responseInfo, loadAdError)
// }
//
// override fun onAdLoaded() {
// admobEvent.pullAd(adView?.responseInfo)
// }
//
// override fun onAdOpened() {
//
// }
//
// override fun onAdClosed() {
// super.onAdClosed()
// adClose?.invoke()
// }
// }
// admobEvent.adPulStart()
// adView?.loadAd(adRequest)
//
// }
//}
\ No newline at end of file
package com.base.appzxhy.business.ads.admob
import android.app.Activity
import android.content.Context
import com.base.appzxhy.GlobalConfig
import com.base.appzxhy.MyApplication
import com.base.appzxhy.bean.config.AdConfigBean
import com.base.appzxhy.business.ads.AdCountDownDialog.createUICountdownTimer
import com.base.appzxhy.business.ads.AdCountDownDialog.showAdCountDownDialog
import com.base.appzxhy.business.ads.AdEvent
import com.base.appzxhy.business.ads.AdState
import com.base.appzxhy.business.ads.AdsShowCallBack
import com.base.appzxhy.business.ads.AdsType
import com.base.appzxhy.business.ads.LimitUtils
import com.base.appzxhy.utils.LogEx
import com.google.android.gms.ads.AdError
import com.google.android.gms.ads.AdRequest
import com.google.android.gms.ads.FullScreenContentCallback
import com.google.android.gms.ads.LoadAdError
import com.google.android.gms.ads.interstitial.InterstitialAd
import com.google.android.gms.ads.interstitial.InterstitialAdLoadCallback
/**
*插屏广告加载显示管理类
*/
class AdInterMgr {
private val TAG = "AdInterMgr"
private var adState = AdState<InterstitialAd>()
private var showCallBack: AdsShowCallBack? = null
//正在加载回调
private var loadingCallBack: (() -> Unit)? = null
fun show(
activity: Activity,
adEvent: AdEvent,
showCallBack: AdsShowCallBack? = null
) {
if (activity.isFinishing || activity.isDestroyed) {
return
}
val nowAdEvent = adEvent
//currentAdEvent!=null 表示有缓存广告,关联reqId
adState.currentAdEvent?.let { nowAdEvent.reqId = it.reqId }
if (!nowAdEvent.isUnLimit) {
if (!LimitUtils.isAdShow(AdsType.INSERT, nowAdEvent)) {
showCallBack?.failed(2)
return
}
if (LimitUtils.isIntervalLimited(nowAdEvent)) {
showCallBack?.failed(3)
return
}
}
val needLoad = !adState.adAvailable()
// adState.activityRef = WeakReference(activity)
this.showCallBack = showCallBack
if (adState.adDialog == null) {
adState.adDialog = activity.showAdCountDownDialog()
} else {
adState.adDialog?.dismiss()
}
nowAdEvent.adPrepareShow()
LogEx.logDebug(adEvent.TAG, "needLoad=$needLoad")
if (needLoad) {
if (!adState.loadingAd) {
LogEx.logDebug(adEvent.TAG, "inter adState !loadingAd")
loadAd(activity, nowAdEvent) {
showReadyAd(activity, nowAdEvent)
}
} else {
LogEx.logDebug(adEvent.TAG, "inter adState is loadingAd")
loadingCallBack = {
showReadyAd(activity, nowAdEvent)
}
}
} else {
LogEx.logDebug(adEvent.TAG, "inter ad ready")
showReadyAd(activity, nowAdEvent)
}
}
private fun showReadyAd(ac: Activity, adEvent: AdEvent) {
// val ac = adState.activityRef?.get()
val admobEvent = (adEvent as AdmobEvent)
val tag = adEvent.TAG
LogEx.logDebug(tag, "showReadyAd ac=$ac currentAd=${adState.currentAd}")
if (ac.isFinishing || ac.isDestroyed || adState.currentAd == null) {
LogEx.logDebug(tag, "showReadyAd ac=null isFinishing isDestroyed")
showCallBack?.failed()
adState.onAdDisplayFailed()
return
}
adState.currentAd?.run {
fullScreenContentCallback = object : FullScreenContentCallback() {
override fun onAdShowedFullScreenContent() {
super.onAdShowedFullScreenContent()
admobEvent.showAd(responseInfo, ac)
adState.onAdDisplayed()
showCallBack?.show()
LimitUtils.addDisplayNum()
}
override fun onAdFailedToShowFullScreenContent(adError: AdError) {
super.onAdFailedToShowFullScreenContent(adError)
adState.onAdDisplayFailed()
showCallBack?.adFailed()
showCallBack = null
admobEvent.adShowError(adError)
}
override fun onAdDismissedFullScreenContent() {
super.onAdDismissedFullScreenContent()
adState.onAdHidden()
showCallBack?.close()
showCallBack = null
loadAd(MyApplication.appContext, AdmobEvent("interAd", "preload"))
}
override fun onAdClicked() {
super.onAdClicked()
admobEvent.clickAd(responseInfo)
//计数
LimitUtils.addClickNum()
}
}
// val activity = adState.activityRef?.get()
if (AdConfigBean.adsConfigBean.showCountdown) {
createUICountdownTimer(adState.adDialog) {
show(ac)
}
} else {
show(ac)
}
}
}
fun loadAd(
context: Context,
adEvent: AdEvent,
loadCallBack: (() -> Unit)? = null
) {
if (!adEvent.isUnLimit) {
if (!LimitUtils.isAdShow(AdsType.INSERT, adEvent)) {
this.showCallBack?.close(4)
this.showCallBack = null
adState.onAdLoadFailed()
return
}
}
//避免无效预加载
if (adState.loadingAd && loadCallBack == null && loadingCallBack == null) {
//容错机制
adState.loadingAd = false
return
}
adState.loadingAd = true
adEvent.adPulStart()
InterstitialAd.load(
context, GlobalConfig.ID_ADMOB_INTER, AdRequest.Builder().build(),
object : InterstitialAdLoadCallback() {
override fun onAdLoaded(ad: InterstitialAd) {
val event = (adEvent as AdmobEvent)
ad.onPaidEventListener = AdmobOnPaidEventListener(ad, adEvent.scope)
adState.onAdLoaded(ad, adEvent)
loadCallBack?.invoke()
loadingCallBack?.invoke()
loadingCallBack = null
LimitUtils.addRequestNum()
event.pullAd(ad.responseInfo)
}
override fun onAdFailedToLoad(loadAdError: LoadAdError) {
adState.onAdLoadFailed()
if (loadCallBack != null) {
adState.onAdDisplayFailed()
}
showCallBack?.adFailed()
showCallBack = null
(adEvent as AdmobEvent).pullAd(loadAdError.responseInfo, loadAdError)
}
}
)
}
}
\ No newline at end of file
//package com.base.appzxhy.business.ads.admob
//
//import android.app.Activity
//import android.content.Context
//import com.base.appzxhy.GlobalConfig
//import com.base.appzxhy.MyApplication
//import com.base.appzxhy.bean.config.AdConfigBean
//import com.base.appzxhy.business.ads.AdCountDownDialog.createUICountdownTimer
//import com.base.appzxhy.business.ads.AdCountDownDialog.showAdCountDownDialog
//import com.base.appzxhy.business.ads.AdEvent
//import com.base.appzxhy.business.ads.AdState
//import com.base.appzxhy.business.ads.AdsShowCallBack
//import com.base.appzxhy.business.ads.AdsType
//import com.base.appzxhy.business.ads.LimitUtils
//import com.base.appzxhy.utils.LogEx
//import com.google.android.gms.ads.AdError
//import com.google.android.gms.ads.AdRequest
//import com.google.android.gms.ads.FullScreenContentCallback
//import com.google.android.gms.ads.LoadAdError
//import com.google.android.gms.ads.interstitial.InterstitialAd
//import com.google.android.gms.ads.interstitial.InterstitialAdLoadCallback
//
//
///**
// *插屏广告加载显示管理类
// */
//class AdInterMgr {
//
// private val TAG = "AdInterMgr"
// private var adState = AdState<InterstitialAd>()
// private var showCallBack: AdsShowCallBack? = null
//
// //正在加载回调
// private var loadingCallBack: (() -> Unit)? = null
//
// fun show(
// activity: Activity,
// adEvent: AdEvent,
// showCallBack: AdsShowCallBack? = null
// ) {
//
// if (activity.isFinishing || activity.isDestroyed) {
// return
// }
//
// val nowAdEvent = adEvent
// //currentAdEvent!=null 表示有缓存广告,关联reqId
// adState.currentAdEvent?.let { nowAdEvent.reqId = it.reqId }
//
// if (!nowAdEvent.isUnLimit) {
// if (!LimitUtils.isAdShow(AdsType.INSERT, nowAdEvent)) {
// showCallBack?.failed(2)
// return
// }
// if (LimitUtils.isIntervalLimited(nowAdEvent)) {
// showCallBack?.failed(3)
// return
// }
// }
//
//
// val needLoad = !adState.adAvailable()
//// adState.activityRef = WeakReference(activity)
// this.showCallBack = showCallBack
//
// if (adState.adDialog == null) {
// adState.adDialog = activity.showAdCountDownDialog()
// } else {
// adState.adDialog?.dismiss()
// }
//
// nowAdEvent.adPrepareShow()
//
// LogEx.logDebug(adEvent.TAG, "needLoad=$needLoad")
// if (needLoad) {
// if (!adState.loadingAd) {
// LogEx.logDebug(adEvent.TAG, "inter adState !loadingAd")
// loadAd(activity, nowAdEvent) {
// showReadyAd(activity, nowAdEvent)
// }
// } else {
// LogEx.logDebug(adEvent.TAG, "inter adState is loadingAd")
// loadingCallBack = {
// showReadyAd(activity, nowAdEvent)
// }
// }
// } else {
// LogEx.logDebug(adEvent.TAG, "inter ad ready")
// showReadyAd(activity, nowAdEvent)
// }
//
// }
//
//
// private fun showReadyAd(ac: Activity, adEvent: AdEvent) {
//
//// val ac = adState.activityRef?.get()
// val admobEvent = (adEvent as AdmobEvent)
// val tag = adEvent.TAG
//
// LogEx.logDebug(tag, "showReadyAd ac=$ac currentAd=${adState.currentAd}")
// if (ac.isFinishing || ac.isDestroyed || adState.currentAd == null) {
// LogEx.logDebug(tag, "showReadyAd ac=null isFinishing isDestroyed")
// showCallBack?.failed()
// adState.onAdDisplayFailed()
// return
// }
//
// adState.currentAd?.run {
//
// fullScreenContentCallback = object : FullScreenContentCallback() {
// override fun onAdShowedFullScreenContent() {
// super.onAdShowedFullScreenContent()
//
// admobEvent.showAd(responseInfo, ac)
//
// adState.onAdDisplayed()
// showCallBack?.show()
//
// LimitUtils.addDisplayNum()
// }
//
// override fun onAdFailedToShowFullScreenContent(adError: AdError) {
// super.onAdFailedToShowFullScreenContent(adError)
//
// adState.onAdDisplayFailed()
// showCallBack?.adFailed()
// showCallBack = null
//
// admobEvent.adShowError(adError)
// }
//
// override fun onAdDismissedFullScreenContent() {
// super.onAdDismissedFullScreenContent()
//
// adState.onAdHidden()
//
// showCallBack?.close()
// showCallBack = null
// loadAd(MyApplication.appContext, AdmobEvent("interAd", "preload"))
// }
//
// override fun onAdClicked() {
// super.onAdClicked()
// admobEvent.clickAd(responseInfo)
// //计数
// LimitUtils.addClickNum()
// }
// }
//// val activity = adState.activityRef?.get()
// if (AdConfigBean.adsConfigBean.showCountdown) {
// createUICountdownTimer(adState.adDialog) {
// show(ac)
// }
// } else {
// show(ac)
// }
// }
// }
//
// fun loadAd(
// context: Context,
// adEvent: AdEvent,
// loadCallBack: (() -> Unit)? = null
// ) {
// if (!adEvent.isUnLimit) {
// if (!LimitUtils.isAdShow(AdsType.INSERT, adEvent)) {
// this.showCallBack?.close(4)
// this.showCallBack = null
// adState.onAdLoadFailed()
// return
// }
// }
//
// //避免无效预加载
// if (adState.loadingAd && loadCallBack == null && loadingCallBack == null) {
// //容错机制
// adState.loadingAd = false
// return
// }
//
// adState.loadingAd = true
// adEvent.adPulStart()
//
// InterstitialAd.load(
// context, GlobalConfig.ID_ADMOB_INTER, AdRequest.Builder().build(),
// object : InterstitialAdLoadCallback() {
// override fun onAdLoaded(ad: InterstitialAd) {
// val event = (adEvent as AdmobEvent)
// ad.onPaidEventListener = AdmobOnPaidEventListener(ad, adEvent.scope)
// adState.onAdLoaded(ad, adEvent)
//
// loadCallBack?.invoke()
// loadingCallBack?.invoke()
// loadingCallBack = null
//
// LimitUtils.addRequestNum()
// event.pullAd(ad.responseInfo)
// }
//
// override fun onAdFailedToLoad(loadAdError: LoadAdError) {
// adState.onAdLoadFailed()
// if (loadCallBack != null) {
// adState.onAdDisplayFailed()
// }
// showCallBack?.adFailed()
// showCallBack = null
// (adEvent as AdmobEvent).pullAd(loadAdError.responseInfo, loadAdError)
//
// }
// }
// )
//
// }
//
//
//}
\ No newline at end of file
package com.base.appzxhy.business.ads.admob
import android.content.Context
import android.util.Log
import com.base.appzxhy.GlobalConfig
import com.base.appzxhy.MyApplication
import com.base.appzxhy.business.ads.AdsType
import com.base.appzxhy.business.ads.LimitUtils
import com.base.appzxhy.business.ads.NativeParentView
import com.google.android.gms.ads.AdListener
import com.google.android.gms.ads.AdLoader
import com.google.android.gms.ads.AdRequest
import com.google.android.gms.ads.LoadAdError
import com.google.android.gms.ads.nativead.NativeAd
import com.google.android.gms.ads.nativead.NativeAdOptions
import java.util.concurrent.ConcurrentLinkedDeque
/**
*原生广告加载显示管理类
*/
class AdNativeMgr {
private val TAG = "AdNativeMgr"
/**
* 上一次的缓存成功时间
*/
protected var lastTime: Long = 0
/**
* 原生广告缓存队列
*/
private val cacheItems = ConcurrentLinkedDeque<NativeAd>()
fun loadAd(
context: Context,
admobEvent: AdmobEvent,
showAction: ((ad: NativeAd) -> Unit)? = null
) {
admobEvent.adPulStart()
if (!LimitUtils.isAdShow(AdsType.NATIVE, admobEvent)) {
// Log.e(TAG, "loadAd return")
return
}
var currentNativeAd: NativeAd? = null
val adLoader = AdLoader.Builder(
context,
GlobalConfig.ID_ADMOB_NATIVE
).forNativeAd { nativeAd ->
lastTime = System.currentTimeMillis()
nativeAd.setOnPaidEventListener(AdmobOnPaidEventListener(nativeAd, admobEvent.scope))
currentNativeAd = nativeAd
admobEvent.pullAd(nativeAd.responseInfo)
if (showAction != null) {
showAction.invoke(nativeAd)
} else {
// Log.e(TAG, "offer ad")
cacheItems.offer(nativeAd)
}
}.withAdListener(object : AdListener() {
override fun onAdFailedToLoad(error: LoadAdError) {
admobEvent.pullAd(error.responseInfo, error)
}
override fun onAdClicked() {
super.onAdClicked()
admobEvent.clickAd(currentNativeAd?.responseInfo)
}
override fun onAdClosed() {
super.onAdClosed()
}
}).withNativeAdOptions(
NativeAdOptions.Builder().build()
).build()
adLoader.loadAds(AdRequest.Builder().build(), 1)
}
fun show(
admobEvent: AdmobEvent,
parent: NativeParentView,
layout: Int,
nativeCallBack: ((Any?) -> Unit)? = null
) {
admobEvent.adPrepareShow()
if (!LimitUtils.isAdShow(AdsType.NATIVE, admobEvent)) {
Log.e(TAG, "!isAdShow")
cacheItems.clear()
return
}
if (!LimitUtils.isShowNative(AdsType.NATIVE, admobEvent)) {
return
}
Log.e(TAG, "adNative can show")
if (!adAvailable()) {
//缓存过期了就清空
Log.e(TAG, "cacheItems clear")
cacheItems.clear()
}
val nativeAd = cacheItems.peek()
var showAction: (ad: NativeAd) -> Unit = { ad ->
parent.isAdShowed = true
nativeCallBack?.invoke(ad)
parent.setNativeAd(ad, layout)
admobEvent.showAd(ad.responseInfo)
//添加原生数量
LimitUtils.addNativeDisplayNum()
loadAd(MyApplication.appContext, AdmobEvent("nativeAd", "preload"), null)
}
if (nativeAd == null) {
loadAd(parent.context, admobEvent) { ad ->
Log.e(TAG, "load show")
showAction.invoke(ad)
}
} else {
val flag = cacheItems.remove(nativeAd)
Log.e(TAG, "ready show remove=$flag size=${cacheItems.size}")
showAction.invoke(nativeAd)
}
}
private fun adAvailable(): Boolean {
return (lastTime == 0L) || ((System.currentTimeMillis() - lastTime) / 1000 / 60).toInt() < 30
}
}
\ No newline at end of file
//package com.base.appzxhy.business.ads.admob
//
//import android.content.Context
//import android.util.Log
//import com.base.appzxhy.GlobalConfig
//import com.base.appzxhy.MyApplication
//import com.base.appzxhy.business.ads.AdsType
//import com.base.appzxhy.business.ads.LimitUtils
//import com.base.appzxhy.business.ads.NativeParentView
//import com.google.android.gms.ads.AdListener
//import com.google.android.gms.ads.AdLoader
//import com.google.android.gms.ads.AdRequest
//import com.google.android.gms.ads.LoadAdError
//import com.google.android.gms.ads.nativead.NativeAd
//import com.google.android.gms.ads.nativead.NativeAdOptions
//import java.util.concurrent.ConcurrentLinkedDeque
//
///**
// *原生广告加载显示管理类
// */
//class AdNativeMgr {
//
// private val TAG = "AdNativeMgr"
//
// /**
// * 上一次的缓存成功时间
// */
// protected var lastTime: Long = 0
//
// /**
// * 原生广告缓存队列
// */
// private val cacheItems = ConcurrentLinkedDeque<NativeAd>()
//
// fun loadAd(
// context: Context,
// admobEvent: AdmobEvent,
// showAction: ((ad: NativeAd) -> Unit)? = null
// ) {
// admobEvent.adPulStart()
//
// if (!LimitUtils.isAdShow(AdsType.NATIVE, admobEvent)) {
//// Log.e(TAG, "loadAd return")
// return
// }
//
// var currentNativeAd: NativeAd? = null
//
// val adLoader = AdLoader.Builder(
// context,
// GlobalConfig.ID_ADMOB_NATIVE
// ).forNativeAd { nativeAd ->
//
// lastTime = System.currentTimeMillis()
// nativeAd.setOnPaidEventListener(AdmobOnPaidEventListener(nativeAd, admobEvent.scope))
// currentNativeAd = nativeAd
// admobEvent.pullAd(nativeAd.responseInfo)
//
//
// if (showAction != null) {
// showAction.invoke(nativeAd)
// } else {
//// Log.e(TAG, "offer ad")
// cacheItems.offer(nativeAd)
// }
//
// }.withAdListener(object : AdListener() {
//
// override fun onAdFailedToLoad(error: LoadAdError) {
// admobEvent.pullAd(error.responseInfo, error)
// }
//
// override fun onAdClicked() {
// super.onAdClicked()
// admobEvent.clickAd(currentNativeAd?.responseInfo)
// }
//
// override fun onAdClosed() {
// super.onAdClosed()
// }
// }).withNativeAdOptions(
// NativeAdOptions.Builder().build()
// ).build()
// adLoader.loadAds(AdRequest.Builder().build(), 1)
// }
//
// fun show(
// admobEvent: AdmobEvent,
// parent: NativeParentView,
// layout: Int,
// nativeCallBack: ((Any?) -> Unit)? = null
// ) {
//
// admobEvent.adPrepareShow()
//
// if (!LimitUtils.isAdShow(AdsType.NATIVE, admobEvent)) {
// Log.e(TAG, "!isAdShow")
// cacheItems.clear()
// return
// }
// if (!LimitUtils.isShowNative(AdsType.NATIVE, admobEvent)) {
// return
// }
//
// Log.e(TAG, "adNative can show")
//
// if (!adAvailable()) {
// //缓存过期了就清空
// Log.e(TAG, "cacheItems clear")
// cacheItems.clear()
// }
//
// val nativeAd = cacheItems.peek()
//
// var showAction: (ad: NativeAd) -> Unit = { ad ->
// parent.isAdShowed = true
// nativeCallBack?.invoke(ad)
// parent.setNativeAd(ad, layout)
// admobEvent.showAd(ad.responseInfo)
// //添加原生数量
// LimitUtils.addNativeDisplayNum()
// loadAd(MyApplication.appContext, AdmobEvent("nativeAd", "preload"), null)
// }
//
// if (nativeAd == null) {
//
// loadAd(parent.context, admobEvent) { ad ->
// Log.e(TAG, "load show")
// showAction.invoke(ad)
// }
// } else {
// val flag = cacheItems.remove(nativeAd)
// Log.e(TAG, "ready show remove=$flag size=${cacheItems.size}")
// showAction.invoke(nativeAd)
// }
//
// }
//
// private fun adAvailable(): Boolean {
// return (lastTime == 0L) || ((System.currentTimeMillis() - lastTime) / 1000 / 60).toInt() < 30
// }
//}
\ No newline at end of file
package com.base.appzxhy.business.ads.admob
import android.app.Activity
import android.content.Context
import com.base.appzxhy.GlobalConfig
import com.base.appzxhy.MyApplication
import com.base.appzxhy.business.ads.AdEvent
import com.base.appzxhy.business.ads.AdState
import com.base.appzxhy.business.ads.AdsShowCallBack
import com.base.appzxhy.business.ads.AdsType
import com.base.appzxhy.business.ads.LimitUtils
import com.base.appzxhy.utils.LogEx
import com.google.android.gms.ads.AdError
import com.google.android.gms.ads.AdRequest
import com.google.android.gms.ads.FullScreenContentCallback
import com.google.android.gms.ads.LoadAdError
import com.google.android.gms.ads.appopen.AppOpenAd
/**
* 开屏广告加载显示管理类
*/
class AdOpenMgr {
private val TAG = "AdOpenMgr"
private val adState = AdState<AppOpenAd>()
private var showCallBack: AdsShowCallBack? = null
//正在加载回调
private var loadingCallBack: (() -> Unit)? = null
fun show(
activity: Activity,
adEvent: AdEvent,
showCallBack: AdsShowCallBack?
) {
if (activity.isFinishing || activity.isDestroyed) {
return
}
val nowAdEvent = adEvent
adState.currentAdEvent?.let { nowAdEvent.reqId = it.reqId }
if (!nowAdEvent.isUnLimit) {
if (!LimitUtils.isAdShow(AdsType.OPEN, nowAdEvent)) {
showCallBack?.failed()
return
}
if (LimitUtils.isIntervalLimited(nowAdEvent)) {
showCallBack?.failed()
return
}
}
val needLoad = !adState.adAvailable()
this.showCallBack = showCallBack
nowAdEvent.adPrepareShow()
if (needLoad) {
if (!adState.loadingAd) {
LogEx.logDebug(adEvent.TAG, "open adState !loadingAd")
loadAd(activity, adEvent) {
showReadyAd(activity)
}
} else {
LogEx.logDebug(adEvent.TAG, "open adState is loadingAd")
loadingCallBack = {
showReadyAd(activity)
}
}
} else {
LogEx.logDebug(adEvent.TAG, "open ad ready")
showReadyAd(activity)
}
}
private fun showReadyAd(ac: Activity) {
// val ac = adState.activityRef?.get()
if (ac.isFinishing || ac.isDestroyed || adState.currentAd == null) {
LogEx.logDebug(TAG, "showReadyAd ac=null isFinishing isDestroyed")
return
}
adState.currentAd?.run {
val adEvent = adState.currentAdEvent as AdmobEvent?
fullScreenContentCallback = object : FullScreenContentCallback() {
override fun onAdShowedFullScreenContent() {
adEvent?.showAd(this@run.responseInfo, ac)
showCallBack?.show()
adState.onAdDisplayed()
//计数
LimitUtils.addDisplayNum()
}
override fun onAdFailedToShowFullScreenContent(adError: AdError) {
super.onAdFailedToShowFullScreenContent(adError)
showCallBack?.adFailed()
showCallBack = null
adState.onAdDisplayFailed()
adEvent?.adShowError(adError)
}
override fun onAdDismissedFullScreenContent() {
super.onAdDismissedFullScreenContent()
showCallBack?.close()
showCallBack = null
adState.onAdHidden()
//预加载,“Timeout for show call succeed.”预加载的广告大概率,
loadAd(MyApplication.appContext, AdmobEvent("openAd", "preload"))
}
override fun onAdClicked() {
adEvent?.clickAd(this@run.responseInfo)
//计数
LimitUtils.addClickNum()
}
}
show(ac)
}
}
fun loadAd(
context: Context,
adEvent: AdEvent,
loadCallBack: (() -> Unit)? = null
) {
if (!adEvent.isUnLimit) {
if (!LimitUtils.isAdShow(AdsType.OPEN, adEvent)) {
this.showCallBack?.failed()
this.showCallBack = null
adState.onAdLoadFailed()
return
}
}
//避免无效预加载
if (adState.loadingAd && loadCallBack == null && loadingCallBack == null) {
//容错机制
adState.loadingAd = false
return
}
adState.loadingAd = true
adEvent.adPulStart()
AppOpenAd.load(
context,
GlobalConfig.ID_ADMOB_OPEN,
AdRequest.Builder().build(),
object : AppOpenAd.AppOpenAdLoadCallback() {
override fun onAdLoaded(appOpenAd: AppOpenAd) {
adState.onAdLoaded(appOpenAd, adEvent)
loadCallBack?.invoke()
loadingCallBack?.invoke()
loadingCallBack = null
(adEvent as AdmobEvent).pullAd(appOpenAd.responseInfo)
appOpenAd.onPaidEventListener = AdmobOnPaidEventListener(appOpenAd, adEvent.scope)
LimitUtils.addRequestNum()
}
override fun onAdFailedToLoad(loadAdError: LoadAdError) {
showCallBack?.adFailed()
showCallBack = null
adState.onAdLoadFailed()
(adEvent as AdmobEvent).pullAd(loadAdError.responseInfo, loadAdError)
}
}
)
}
}
\ No newline at end of file
//package com.base.appzxhy.business.ads.admob
//
//import android.app.Activity
//import android.content.Context
//import com.base.appzxhy.GlobalConfig
//import com.base.appzxhy.MyApplication
//import com.base.appzxhy.business.ads.AdEvent
//import com.base.appzxhy.business.ads.AdState
//import com.base.appzxhy.business.ads.AdsShowCallBack
//import com.base.appzxhy.business.ads.AdsType
//import com.base.appzxhy.business.ads.LimitUtils
//import com.base.appzxhy.utils.LogEx
//import com.google.android.gms.ads.AdError
//import com.google.android.gms.ads.AdRequest
//import com.google.android.gms.ads.FullScreenContentCallback
//import com.google.android.gms.ads.LoadAdError
//import com.google.android.gms.ads.appopen.AppOpenAd
//
//
///**
// * 开屏广告加载显示管理类
// */
//class AdOpenMgr {
//
// private val TAG = "AdOpenMgr"
// private val adState = AdState<AppOpenAd>()
// private var showCallBack: AdsShowCallBack? = null
//
// //正在加载回调
// private var loadingCallBack: (() -> Unit)? = null
//
// fun show(
// activity: Activity,
// adEvent: AdEvent,
// showCallBack: AdsShowCallBack?
// ) {
// if (activity.isFinishing || activity.isDestroyed) {
// return
// }
//
// val nowAdEvent = adEvent
// adState.currentAdEvent?.let { nowAdEvent.reqId = it.reqId }
//
// if (!nowAdEvent.isUnLimit) {
// if (!LimitUtils.isAdShow(AdsType.OPEN, nowAdEvent)) {
// showCallBack?.failed()
// return
// }
// if (LimitUtils.isIntervalLimited(nowAdEvent)) {
// showCallBack?.failed()
// return
// }
// }
//
// val needLoad = !adState.adAvailable()
// this.showCallBack = showCallBack
//
// nowAdEvent.adPrepareShow()
// if (needLoad) {
// if (!adState.loadingAd) {
// LogEx.logDebug(adEvent.TAG, "open adState !loadingAd")
// loadAd(activity, adEvent) {
// showReadyAd(activity)
// }
// } else {
// LogEx.logDebug(adEvent.TAG, "open adState is loadingAd")
// loadingCallBack = {
// showReadyAd(activity)
// }
// }
// } else {
// LogEx.logDebug(adEvent.TAG, "open ad ready")
// showReadyAd(activity)
// }
// }
//
// private fun showReadyAd(ac: Activity) {
//
//// val ac = adState.activityRef?.get()
// if (ac.isFinishing || ac.isDestroyed || adState.currentAd == null) {
// LogEx.logDebug(TAG, "showReadyAd ac=null isFinishing isDestroyed")
// return
// }
//
// adState.currentAd?.run {
//
// val adEvent = adState.currentAdEvent as AdmobEvent?
//
// fullScreenContentCallback = object : FullScreenContentCallback() {
// override fun onAdShowedFullScreenContent() {
//
// adEvent?.showAd(this@run.responseInfo, ac)
//
// showCallBack?.show()
//
// adState.onAdDisplayed()
// //计数
// LimitUtils.addDisplayNum()
//
// }
//
// override fun onAdFailedToShowFullScreenContent(adError: AdError) {
// super.onAdFailedToShowFullScreenContent(adError)
//
// showCallBack?.adFailed()
// showCallBack = null
// adState.onAdDisplayFailed()
//
// adEvent?.adShowError(adError)
//
// }
//
// override fun onAdDismissedFullScreenContent() {
// super.onAdDismissedFullScreenContent()
//
// showCallBack?.close()
// showCallBack = null
//
// adState.onAdHidden()
//
// //预加载,“Timeout for show call succeed.”预加载的广告大概率,
// loadAd(MyApplication.appContext, AdmobEvent("openAd", "preload"))
//
// }
//
// override fun onAdClicked() {
// adEvent?.clickAd(this@run.responseInfo)
// //计数
// LimitUtils.addClickNum()
// }
// }
// show(ac)
// }
// }
//
// fun loadAd(
// context: Context,
// adEvent: AdEvent,
// loadCallBack: (() -> Unit)? = null
// ) {
//
// if (!adEvent.isUnLimit) {
// if (!LimitUtils.isAdShow(AdsType.OPEN, adEvent)) {
// this.showCallBack?.failed()
// this.showCallBack = null
// adState.onAdLoadFailed()
// return
// }
// }
//
// //避免无效预加载
// if (adState.loadingAd && loadCallBack == null && loadingCallBack == null) {
// //容错机制
// adState.loadingAd = false
// return
// }
//
// adState.loadingAd = true
// adEvent.adPulStart()
//
// AppOpenAd.load(
// context,
// GlobalConfig.ID_ADMOB_OPEN,
// AdRequest.Builder().build(),
// object : AppOpenAd.AppOpenAdLoadCallback() {
// override fun onAdLoaded(appOpenAd: AppOpenAd) {
// adState.onAdLoaded(appOpenAd, adEvent)
//
// loadCallBack?.invoke()
// loadingCallBack?.invoke()
// loadingCallBack = null
//
// (adEvent as AdmobEvent).pullAd(appOpenAd.responseInfo)
// appOpenAd.onPaidEventListener = AdmobOnPaidEventListener(appOpenAd, adEvent.scope)
// LimitUtils.addRequestNum()
// }
//
// override fun onAdFailedToLoad(loadAdError: LoadAdError) {
// showCallBack?.adFailed()
// showCallBack = null
// adState.onAdLoadFailed()
// (adEvent as AdmobEvent).pullAd(loadAdError.responseInfo, loadAdError)
// }
// }
// )
// }
//
//}
\ No newline at end of file
package com.base.appzxhy.business.ads.admob
import android.app.Activity
import android.os.Bundle
import com.base.appzxhy.MyApplication
import com.base.appzxhy.bean.config.AdConfigBean
import com.base.appzxhy.business.ads.AdEvent
import com.base.appzxhy.business.ads.SolarEngineEvent
import com.base.appzxhy.business.ads.taichiPref
import com.base.appzxhy.business.ads.taichiSharedPreferencesEditor
import com.base.appzxhy.business.helper.EventUtils
import com.base.appzxhy.utils.LogEx
import com.facebook.appevents.AppEventsConstants
import com.facebook.appevents.AppEventsLogger
import com.google.android.gms.ads.AdError
import com.google.android.gms.ads.AdValue
import com.google.android.gms.ads.AdView
import com.google.android.gms.ads.LoadAdError
import com.google.android.gms.ads.OnPaidEventListener
import com.google.android.gms.ads.ResponseInfo
import com.google.android.gms.ads.appopen.AppOpenAd
import com.google.android.gms.ads.interstitial.InterstitialAd
import com.google.android.gms.ads.nativead.NativeAd
import com.google.android.gms.ads.rewarded.RewardedAd
import com.google.firebase.analytics.FirebaseAnalytics
import com.google.firebase.analytics.ktx.analytics
import com.google.firebase.ktx.Firebase
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.SupervisorJob
import kotlinx.coroutines.launch
import org.json.JSONObject
import java.math.BigDecimal
import java.util.Currency
import kotlin.random.Random
class AdmobEvent : AdEvent {
override val TAG: String = "AdmobEvent"
val scope = CoroutineScope(SupervisorJob() + Dispatchers.IO)
constructor(adUnit: String, from: String) : super() {
this.adUnit = adUnit
this.from = from
}
fun pullAd(
responseInfo: ResponseInfo?,
error: LoadAdError? = null,
) = scope.launch {
var key = "ad_pull"
val obj = JSONObject()
obj.put("ad_unit", adUnit)
obj.put("from", from)
obj.put("req_id", reqId)
if (responseInfo != null) {
val response = responseInfo.adapterResponses.getOrNull(0)
if (response != null) {
obj.put("source", response.adSourceName)
val credentials = mapOf(
"placementid" to response.credentials.get("placementid"),
"appid" to response.credentials.get("appid"),
"pubid" to response.credentials.get("pubid")
)
obj.put("credentials", credentials.toString())
}
obj.put("session_id", responseInfo.responseId)
}
obj.put("networkname", responseInfo?.mediationAdapterClassName)
if (error == null) {
obj.put("status", "1")
} else {
obj.put("errMsg", error.toString())
obj.put("status", "2")
key = "ad_pull_error"
}
EventUtils.event(key, ext = obj)
LogEx.logDebug(TAG, "$key obj=$obj")
}
fun clickAd(responseInfo: ResponseInfo?) = scope.launch {
val response = responseInfo?.adapterResponses?.getOrNull(0)
val obj = JSONObject()
obj.put("req_id", reqId)
obj.put("source", response?.adSourceName)
obj.put("ad_unit", adUnit)
val credentials = mapOf(
"placementid" to response?.credentials?.get("placementid"),
"appid" to response?.credentials?.get("appid"),
"pubid" to response?.credentials?.get("pubid")
)
obj.put("credentials", credentials.toString())
obj.put("session_id", responseInfo?.responseId)
obj.put("from", from)
obj.put("networkname", responseInfo?.mediationAdapterClassName)
if (adUnit != "nativeAd") {
EventUtils.event("ad_click", ext = obj)
} else {
EventUtils.event("ad_click", ext = obj)
}
}
fun showAd(responseInfo: ResponseInfo?, activity: Activity? = null) = scope.launch {
val response = responseInfo?.adapterResponses?.getOrNull(0)
val obj = JSONObject()
obj.put("ad_unit", adUnit)
obj.put("from", activity?.javaClass?.simpleName)
obj.put("req_id", reqId)
obj.put("source", response?.adSourceName)
obj.put("networkname", responseInfo?.mediationAdapterClassName)
val credentials = mapOf(
"placementid" to response?.credentials?.get("placementid"),
"appid" to response?.credentials?.get("appid"),
"pubid" to response?.credentials?.get("pubid")
)
obj.put("credentials", credentials.toString())
obj.put("session_id", responseInfo?.responseId)
if (adUnit != "nativeAd") {
EventUtils.event("ad_show", ext = obj)
} else {
EventUtils.event("ad_show", ext = obj)
}
LogEx.logDebug(TAG, "ad_show $obj")
}
fun adShowError(adError: AdError) = scope.launch {
val obj = JSONObject()
obj.put("req_id", reqId)
obj.put("reason", adError.message)
obj.put("code", adError.code)
obj.put("from", from)
obj.put("ad_unit", "openAd")
EventUtils.event("ad_show_error", ext = obj)
LogEx.logDebug(TAG, "ad_show_error $obj")
}
}
class AdmobOnPaidEventListener(
private val ad: Any,
private val coroutineScope: CoroutineScope = CoroutineScope(SupervisorJob() + Dispatchers.IO)
) : OnPaidEventListener {
override fun onPaidEvent(adValue: AdValue) {
onPaidEvent2(ad, adValue)
}
fun onPaidEvent2(ad: Any, adValue: AdValue) {
// coroutineScope.launch {
try {
val flag = eventAdRatio()
val valueS = adValue.valueMicros > 0
if (flag && valueS) {
SolarEngineEvent.eventSolar(ad, adValue.valueMicros)
eventFireBase(adValue)
eventEvent(adValue)
}
} catch (e: Exception) {
EventUtils.event("onPaidEvent_Error")
}
//package com.base.appzxhy.business.ads.admob
//
//import android.app.Activity
//import android.os.Bundle
//import com.base.appzxhy.MyApplication
//import com.base.appzxhy.bean.config.AdConfigBean
//import com.base.appzxhy.business.ads.AdEvent
//import com.base.appzxhy.business.ads.SolarEngineEvent
//import com.base.appzxhy.business.ads.taichiPref
//import com.base.appzxhy.business.ads.taichiSharedPreferencesEditor
//import com.base.appzxhy.business.helper.EventUtils
//import com.base.appzxhy.utils.LogEx
//import com.facebook.appevents.AppEventsConstants
//import com.facebook.appevents.AppEventsLogger
//import com.google.android.gms.ads.AdError
//import com.google.android.gms.ads.AdValue
//import com.google.android.gms.ads.AdView
//import com.google.android.gms.ads.LoadAdError
//import com.google.android.gms.ads.OnPaidEventListener
//import com.google.android.gms.ads.ResponseInfo
//import com.google.android.gms.ads.appopen.AppOpenAd
//import com.google.android.gms.ads.interstitial.InterstitialAd
//import com.google.android.gms.ads.nativead.NativeAd
//import com.google.android.gms.ads.rewarded.RewardedAd
//import com.google.firebase.analytics.FirebaseAnalytics
//import com.google.firebase.analytics.ktx.analytics
//import com.google.firebase.ktx.Firebase
//import kotlinx.coroutines.CoroutineScope
//import kotlinx.coroutines.Dispatchers
//import kotlinx.coroutines.SupervisorJob
//import kotlinx.coroutines.launch
//import org.json.JSONObject
//import java.math.BigDecimal
//import java.util.Currency
//import kotlin.random.Random
//
//class AdmobEvent : AdEvent {
//
// override val TAG: String = "AdmobEvent"
//
// val scope = CoroutineScope(SupervisorJob() + Dispatchers.IO)
//
// constructor(adUnit: String, from: String) : super() {
// this.adUnit = adUnit
// this.from = from
// }
//
// fun pullAd(
// responseInfo: ResponseInfo?,
// error: LoadAdError? = null,
// ) = scope.launch {
// var key = "ad_pull"
// val obj = JSONObject()
// obj.put("ad_unit", adUnit)
// obj.put("from", from)
// obj.put("req_id", reqId)
// if (responseInfo != null) {
// val response = responseInfo.adapterResponses.getOrNull(0)
// if (response != null) {
// obj.put("source", response.adSourceName)
//
// val credentials = mapOf(
// "placementid" to response.credentials.get("placementid"),
// "appid" to response.credentials.get("appid"),
// "pubid" to response.credentials.get("pubid")
// )
// obj.put("credentials", credentials.toString())
// }
// obj.put("session_id", responseInfo.responseId)
// }
}
fun eventAdRatio(): Boolean {
val adRatio = AdConfigBean.Companion.adsConfigBean.adRatio
val random = Random.Default.nextInt(1, 100)
if (random > adRatio) {
taichiSharedPreferencesEditor.putFloat("TaichiTroasCache", 0f)
taichiSharedPreferencesEditor.commit()
EventUtils.event("ad_price_limit")
return false
}
return true
}
/**
* 上报给firebase
*/
fun eventFireBase(adValue: AdValue) {
val valueMicros = adValue.valueMicros
val currencyCode = adValue.currencyCode
val currentImpressionRevenue = adValue.valueMicros.toDouble() / 1000000.0
//sp里面的价格值
val previousTaichiTroasCache = taichiPref.getFloat("TaichiTroasCache", 0f)
//当前缓存加个值
val currentTaichiTroasCache = (previousTaichiTroasCache + currentImpressionRevenue).toFloat()
//价值上报阀值
val taichiAdValue = AdConfigBean.Companion.adsConfigBean.taichiAdValue / 100f
val params = Bundle()
params.putDouble(FirebaseAnalytics.Param.VALUE, currentImpressionRevenue)
params.putString(FirebaseAnalytics.Param.CURRENCY, "USD")
LogEx.logDebug("EventOnPaidEventListener", "precisionType=${adValue.precisionType}")
val precisionType = when (adValue.precisionType) {
0 -> "UNKNOWN"
1 -> "ESTIMATED"
2 -> "PUBLISHER_PROVIDED"
3 -> "PRECISE"
else -> "Invalid"
}
params.putString("precisionType", precisionType)
val fbLogger = AppEventsLogger.newLogger(MyApplication.Companion.appContext)
//上报
fbLogger.logPurchase(BigDecimal.valueOf(currentImpressionRevenue), Currency.getInstance(currencyCode))
//上报ad_price
Firebase.analytics.logEvent("ad_price", Bundle().apply {
putDouble("valueMicros", currentImpressionRevenue)
})
//上报Ad_Impression_Revenue
Firebase.analytics.logEvent("Ad_Impression_Revenue", params)
//上报Total_Ads_Revenue_001
if (currentTaichiTroasCache >= taichiAdValue) {//如果超过0.01就触发一次tROAS taichi事件
val roasbundle = Bundle()
roasbundle.putDouble(FirebaseAnalytics.Param.VALUE, currentTaichiTroasCache.toDouble())
roasbundle.putString(FirebaseAnalytics.Param.CURRENCY, "USD")
Firebase.analytics.logEvent("Total_Ads_Revenue_001", roasbundle)
taichiSharedPreferencesEditor.putFloat("TaichiTroasCache", 0f)//重新清零,开始计算
val parameters = Bundle()
parameters.putString(AppEventsConstants.EVENT_PARAM_CURRENCY, "USD")
fbLogger.logEvent("ad_value", currentTaichiTroasCache.toDouble(), parameters)
} else {
taichiSharedPreferencesEditor.putFloat("TaichiTroasCache", currentTaichiTroasCache)
}
taichiSharedPreferencesEditor.commit()
}
/**
* 上报给服务器
*/
fun eventEvent(adValue: AdValue) {
val valueMicros = adValue.valueMicros
val currencyCode = adValue.currencyCode
val precision = adValue.precisionType
val obj = JSONObject()
obj.put("valueMicros", valueMicros)
obj.put("currencyCode", currencyCode)
obj.put("precision", precision)
var key = "ad_price"
when (ad) {
is AppOpenAd -> {
val adUnitId = ad.adUnitId
val loadedAdapterResponseInfo = ad.responseInfo.loadedAdapterResponseInfo
val adSourceName = loadedAdapterResponseInfo?.adSourceName
val adSourceId = loadedAdapterResponseInfo?.adSourceId
val adSourceInstanceName = loadedAdapterResponseInfo?.adSourceInstanceName
val adSourceInstanceId = loadedAdapterResponseInfo?.adSourceInstanceId
val sessionId = ad.responseInfo.responseId
val extras = ad.responseInfo.responseExtras
val mediationGroupName = extras.getString("mediation_group_name")
val mediationABTestName = extras.getString("mediation_ab_test_name")
val mediationABTestVariant = extras.getString("mediation_ab_test_variant")
obj.put("ad_unit", "openAd")
obj.put("adUnitId", adUnitId)
obj.put("adSourceName", adSourceName)
obj.put("adSourceId", adSourceId)
obj.put("adSourceInstanceName", adSourceInstanceName)
obj.put("adSourceInstanceId", adSourceInstanceId)
obj.put("mediationGroupName", mediationGroupName)
obj.put("mediationABTestName", mediationABTestName)
obj.put("mediationABTestVariant", mediationABTestVariant)
obj.put("session_id", sessionId)
}
is InterstitialAd -> {
val adUnitId = ad.adUnitId
val loadedAdapterResponseInfo = ad.responseInfo.loadedAdapterResponseInfo
val adSourceName = loadedAdapterResponseInfo?.adSourceName
val adSourceId = loadedAdapterResponseInfo?.adSourceId
val adSourceInstanceName = loadedAdapterResponseInfo?.adSourceInstanceName
val adSourceInstanceId = loadedAdapterResponseInfo?.adSourceInstanceId
val sessionId = ad.responseInfo.responseId
val extras = ad.responseInfo.responseExtras
val mediationGroupName = extras.getString("mediation_group_name")
val mediationABTestName = extras.getString("mediation_ab_test_name")
val mediationABTestVariant = extras.getString("mediation_ab_test_variant")
obj.put("ad_unit", "interAd")
obj.put("adUnitId", adUnitId)
obj.put("adSourceName", adSourceName)
obj.put("adSourceId", adSourceId)
obj.put("adSourceInstanceName", adSourceInstanceName)
obj.put("adSourceInstanceId", adSourceInstanceId)
obj.put("mediationGroupName", mediationGroupName)
obj.put("mediationABTestName", mediationABTestName)
obj.put("mediationABTestVariant", mediationABTestVariant)
obj.put("session_id", sessionId)
}
is RewardedAd -> {
val loadedAdapterResponseInfo = ad.responseInfo.loadedAdapterResponseInfo
val adSourceName = loadedAdapterResponseInfo?.adSourceName
val adSourceId = loadedAdapterResponseInfo?.adSourceId
val adSourceInstanceName = loadedAdapterResponseInfo?.adSourceInstanceName
val adSourceInstanceId = loadedAdapterResponseInfo?.adSourceInstanceId
val sessionId = ad.responseInfo.responseId
val extras = ad.responseInfo.responseExtras
val mediationGroupName = extras.getString("mediation_group_name")
val mediationABTestName = extras.getString("mediation_ab_test_name")
val mediationABTestVariant = extras.getString("mediation_ab_test_variant")
obj.put("adSourceName", adSourceName)
obj.put("adSourceId", adSourceId)
obj.put("adSourceInstanceName", adSourceInstanceName)
obj.put("adSourceInstanceId", adSourceInstanceId)
obj.put("mediationGroupName", mediationGroupName)
obj.put("mediationABTestName", mediationABTestName)
obj.put("mediationABTestVariant", mediationABTestVariant)
obj.put("session_id", sessionId)
}
is NativeAd -> {
key = "ad_price"
val loadedAdapterResponseInfo = ad.responseInfo?.loadedAdapterResponseInfo
val adSourceName = loadedAdapterResponseInfo?.adSourceName
val adSourceId = loadedAdapterResponseInfo?.adSourceId
val adSourceInstanceName = loadedAdapterResponseInfo?.adSourceInstanceName
val adSourceInstanceId = loadedAdapterResponseInfo?.adSourceInstanceId
val sessionId = ad.responseInfo?.responseId
val extras = ad.responseInfo?.responseExtras
val mediationGroupName = extras?.getString("mediation_group_name")
val mediationABTestName = extras?.getString("mediation_ab_test_name")
val mediationABTestVariant = extras?.getString("mediation_ab_test_variant")
obj.put("ad_unit", "nativeAd")
obj.put("adSourceName", adSourceName)
obj.put("adSourceId", adSourceId)
obj.put("adSourceInstanceName", adSourceInstanceName)
obj.put("adSourceInstanceId", adSourceInstanceId)
obj.put("mediationGroupName", mediationGroupName)
obj.put("mediationABTestName", mediationABTestName)
obj.put("mediationABTestVariant", mediationABTestVariant)
obj.put("session_id", sessionId)
}
else -> {
runCatching {
val adView = ad as AdView
val adUnitId = adView.adUnitId
val loadedAdapterResponseInfo = adView.responseInfo?.loadedAdapterResponseInfo
val adSourceName = loadedAdapterResponseInfo?.adSourceName
val adSourceId = loadedAdapterResponseInfo?.adSourceId
val adSourceInstanceName = loadedAdapterResponseInfo?.adSourceInstanceName
val adSourceInstanceId = loadedAdapterResponseInfo?.adSourceInstanceId
val sessionId = adView.responseInfo?.responseId
val extras = adView.responseInfo?.responseExtras
val mediationGroupName = extras?.getString("mediation_group_name")
val mediationABTestName = extras?.getString("mediation_ab_test_name")
val mediationABTestVariant = extras?.getString("mediation_ab_test_variant")
obj.put("ad_unit", "banner")
obj.put("adUnitId", adUnitId)
obj.put("adSourceName", adSourceName)
obj.put("adSourceId", adSourceId)
obj.put("adSourceInstanceName", adSourceInstanceName)
obj.put("adSourceInstanceId", adSourceInstanceId)
obj.put("mediationGroupName", mediationGroupName)
obj.put("mediationABTestName", mediationABTestName)
obj.put("mediationABTestVariant", mediationABTestVariant)
obj.put("session_id", sessionId)
}
}
}
EventUtils.event(key, ext = obj)
}
}
\ No newline at end of file
// obj.put("networkname", responseInfo?.mediationAdapterClassName)
// if (error == null) {
// obj.put("status", "1")
// } else {
// obj.put("errMsg", error.toString())
// obj.put("status", "2")
// key = "ad_pull_error"
// }
// EventUtils.event(key, ext = obj)
// LogEx.logDebug(TAG, "$key obj=$obj")
// }
//
// fun clickAd(responseInfo: ResponseInfo?) = scope.launch {
//
// val response = responseInfo?.adapterResponses?.getOrNull(0)
// val obj = JSONObject()
// obj.put("req_id", reqId)
// obj.put("source", response?.adSourceName)
// obj.put("ad_unit", adUnit)
//
// val credentials = mapOf(
// "placementid" to response?.credentials?.get("placementid"),
// "appid" to response?.credentials?.get("appid"),
// "pubid" to response?.credentials?.get("pubid")
// )
// obj.put("credentials", credentials.toString())
// obj.put("session_id", responseInfo?.responseId)
// obj.put("from", from)
// obj.put("networkname", responseInfo?.mediationAdapterClassName)
// if (adUnit != "nativeAd") {
// EventUtils.event("ad_click", ext = obj)
// } else {
// EventUtils.event("ad_click", ext = obj)
// }
// }
//
// fun showAd(responseInfo: ResponseInfo?, activity: Activity? = null) = scope.launch {
// val response = responseInfo?.adapterResponses?.getOrNull(0)
// val obj = JSONObject()
// obj.put("ad_unit", adUnit)
// obj.put("from", activity?.javaClass?.simpleName)
// obj.put("req_id", reqId)
// obj.put("source", response?.adSourceName)
// obj.put("networkname", responseInfo?.mediationAdapterClassName)
// val credentials = mapOf(
// "placementid" to response?.credentials?.get("placementid"),
// "appid" to response?.credentials?.get("appid"),
// "pubid" to response?.credentials?.get("pubid")
// )
// obj.put("credentials", credentials.toString())
// obj.put("session_id", responseInfo?.responseId)
// if (adUnit != "nativeAd") {
// EventUtils.event("ad_show", ext = obj)
// } else {
// EventUtils.event("ad_show", ext = obj)
// }
// LogEx.logDebug(TAG, "ad_show $obj")
// }
//
// fun adShowError(adError: AdError) = scope.launch {
// val obj = JSONObject()
// obj.put("req_id", reqId)
// obj.put("reason", adError.message)
// obj.put("code", adError.code)
// obj.put("from", from)
// obj.put("ad_unit", "openAd")
// EventUtils.event("ad_show_error", ext = obj)
// LogEx.logDebug(TAG, "ad_show_error $obj")
// }
//}
//
//
//class AdmobOnPaidEventListener(
// private val ad: Any,
// private val coroutineScope: CoroutineScope = CoroutineScope(SupervisorJob() + Dispatchers.IO)
//) : OnPaidEventListener {
//
// override fun onPaidEvent(adValue: AdValue) {
// onPaidEvent2(ad, adValue)
// }
//
// fun onPaidEvent2(ad: Any, adValue: AdValue) {
//// coroutineScope.launch {
// try {
// val flag = eventAdRatio()
// val valueS = adValue.valueMicros > 0
// if (flag && valueS) {
// SolarEngineEvent.eventSolar(ad, adValue.valueMicros)
// eventFireBase(adValue)
// eventEvent(adValue)
// }
// } catch (e: Exception) {
// EventUtils.event("onPaidEvent_Error")
// }
//// }
// }
//
// fun eventAdRatio(): Boolean {
// val adRatio = AdConfigBean.Companion.adsConfigBean.adRatio
// val random = Random.Default.nextInt(1, 100)
// if (random > adRatio) {
// taichiSharedPreferencesEditor.putFloat("TaichiTroasCache", 0f)
// taichiSharedPreferencesEditor.commit()
// EventUtils.event("ad_price_limit")
// return false
// }
// return true
// }
//
// /**
// * 上报给firebase
// */
// fun eventFireBase(adValue: AdValue) {
//
// val valueMicros = adValue.valueMicros
// val currencyCode = adValue.currencyCode
// val currentImpressionRevenue = adValue.valueMicros.toDouble() / 1000000.0
//
// //sp里面的价格值
// val previousTaichiTroasCache = taichiPref.getFloat("TaichiTroasCache", 0f)
//
// //当前缓存加个值
// val currentTaichiTroasCache = (previousTaichiTroasCache + currentImpressionRevenue).toFloat()
//
// //价值上报阀值
// val taichiAdValue = AdConfigBean.Companion.adsConfigBean.taichiAdValue / 100f
//
// val params = Bundle()
// params.putDouble(FirebaseAnalytics.Param.VALUE, currentImpressionRevenue)
// params.putString(FirebaseAnalytics.Param.CURRENCY, "USD")
// LogEx.logDebug("EventOnPaidEventListener", "precisionType=${adValue.precisionType}")
// val precisionType = when (adValue.precisionType) {
// 0 -> "UNKNOWN"
// 1 -> "ESTIMATED"
// 2 -> "PUBLISHER_PROVIDED"
// 3 -> "PRECISE"
// else -> "Invalid"
// }
// params.putString("precisionType", precisionType)
//
//
// val fbLogger = AppEventsLogger.newLogger(MyApplication.Companion.appContext)
//
// //上报
// fbLogger.logPurchase(BigDecimal.valueOf(currentImpressionRevenue), Currency.getInstance(currencyCode))
//
//
// //上报ad_price
// Firebase.analytics.logEvent("ad_price", Bundle().apply {
// putDouble("valueMicros", currentImpressionRevenue)
// })
//
// //上报Ad_Impression_Revenue
// Firebase.analytics.logEvent("Ad_Impression_Revenue", params)
//
// //上报Total_Ads_Revenue_001
// if (currentTaichiTroasCache >= taichiAdValue) {//如果超过0.01就触发一次tROAS taichi事件
// val roasbundle = Bundle()
// roasbundle.putDouble(FirebaseAnalytics.Param.VALUE, currentTaichiTroasCache.toDouble())
// roasbundle.putString(FirebaseAnalytics.Param.CURRENCY, "USD")
// Firebase.analytics.logEvent("Total_Ads_Revenue_001", roasbundle)
// taichiSharedPreferencesEditor.putFloat("TaichiTroasCache", 0f)//重新清零,开始计算
//
// val parameters = Bundle()
// parameters.putString(AppEventsConstants.EVENT_PARAM_CURRENCY, "USD")
// fbLogger.logEvent("ad_value", currentTaichiTroasCache.toDouble(), parameters)
// } else {
// taichiSharedPreferencesEditor.putFloat("TaichiTroasCache", currentTaichiTroasCache)
// }
// taichiSharedPreferencesEditor.commit()
// }
//
// /**
// * 上报给服务器
// */
// fun eventEvent(adValue: AdValue) {
// val valueMicros = adValue.valueMicros
// val currencyCode = adValue.currencyCode
// val precision = adValue.precisionType
//
// val obj = JSONObject()
// obj.put("valueMicros", valueMicros)
// obj.put("currencyCode", currencyCode)
// obj.put("precision", precision)
//
// var key = "ad_price"
// when (ad) {
// is AppOpenAd -> {
// val adUnitId = ad.adUnitId
// val loadedAdapterResponseInfo = ad.responseInfo.loadedAdapterResponseInfo
// val adSourceName = loadedAdapterResponseInfo?.adSourceName
// val adSourceId = loadedAdapterResponseInfo?.adSourceId
// val adSourceInstanceName = loadedAdapterResponseInfo?.adSourceInstanceName
// val adSourceInstanceId = loadedAdapterResponseInfo?.adSourceInstanceId
// val sessionId = ad.responseInfo.responseId
// val extras = ad.responseInfo.responseExtras
// val mediationGroupName = extras.getString("mediation_group_name")
// val mediationABTestName = extras.getString("mediation_ab_test_name")
// val mediationABTestVariant = extras.getString("mediation_ab_test_variant")
// obj.put("ad_unit", "openAd")
// obj.put("adUnitId", adUnitId)
// obj.put("adSourceName", adSourceName)
// obj.put("adSourceId", adSourceId)
// obj.put("adSourceInstanceName", adSourceInstanceName)
// obj.put("adSourceInstanceId", adSourceInstanceId)
// obj.put("mediationGroupName", mediationGroupName)
// obj.put("mediationABTestName", mediationABTestName)
// obj.put("mediationABTestVariant", mediationABTestVariant)
// obj.put("session_id", sessionId)
// }
//
// is InterstitialAd -> {
// val adUnitId = ad.adUnitId
// val loadedAdapterResponseInfo = ad.responseInfo.loadedAdapterResponseInfo
// val adSourceName = loadedAdapterResponseInfo?.adSourceName
// val adSourceId = loadedAdapterResponseInfo?.adSourceId
// val adSourceInstanceName = loadedAdapterResponseInfo?.adSourceInstanceName
// val adSourceInstanceId = loadedAdapterResponseInfo?.adSourceInstanceId
// val sessionId = ad.responseInfo.responseId
// val extras = ad.responseInfo.responseExtras
// val mediationGroupName = extras.getString("mediation_group_name")
// val mediationABTestName = extras.getString("mediation_ab_test_name")
// val mediationABTestVariant = extras.getString("mediation_ab_test_variant")
// obj.put("ad_unit", "interAd")
// obj.put("adUnitId", adUnitId)
// obj.put("adSourceName", adSourceName)
// obj.put("adSourceId", adSourceId)
// obj.put("adSourceInstanceName", adSourceInstanceName)
// obj.put("adSourceInstanceId", adSourceInstanceId)
// obj.put("mediationGroupName", mediationGroupName)
// obj.put("mediationABTestName", mediationABTestName)
// obj.put("mediationABTestVariant", mediationABTestVariant)
// obj.put("session_id", sessionId)
// }
//
// is RewardedAd -> {
// val loadedAdapterResponseInfo = ad.responseInfo.loadedAdapterResponseInfo
// val adSourceName = loadedAdapterResponseInfo?.adSourceName
// val adSourceId = loadedAdapterResponseInfo?.adSourceId
// val adSourceInstanceName = loadedAdapterResponseInfo?.adSourceInstanceName
// val adSourceInstanceId = loadedAdapterResponseInfo?.adSourceInstanceId
// val sessionId = ad.responseInfo.responseId
// val extras = ad.responseInfo.responseExtras
// val mediationGroupName = extras.getString("mediation_group_name")
// val mediationABTestName = extras.getString("mediation_ab_test_name")
// val mediationABTestVariant = extras.getString("mediation_ab_test_variant")
// obj.put("adSourceName", adSourceName)
// obj.put("adSourceId", adSourceId)
// obj.put("adSourceInstanceName", adSourceInstanceName)
// obj.put("adSourceInstanceId", adSourceInstanceId)
// obj.put("mediationGroupName", mediationGroupName)
// obj.put("mediationABTestName", mediationABTestName)
// obj.put("mediationABTestVariant", mediationABTestVariant)
// obj.put("session_id", sessionId)
// }
//
// is NativeAd -> {
// key = "ad_price"
// val loadedAdapterResponseInfo = ad.responseInfo?.loadedAdapterResponseInfo
// val adSourceName = loadedAdapterResponseInfo?.adSourceName
// val adSourceId = loadedAdapterResponseInfo?.adSourceId
// val adSourceInstanceName = loadedAdapterResponseInfo?.adSourceInstanceName
// val adSourceInstanceId = loadedAdapterResponseInfo?.adSourceInstanceId
// val sessionId = ad.responseInfo?.responseId
// val extras = ad.responseInfo?.responseExtras
// val mediationGroupName = extras?.getString("mediation_group_name")
// val mediationABTestName = extras?.getString("mediation_ab_test_name")
// val mediationABTestVariant = extras?.getString("mediation_ab_test_variant")
// obj.put("ad_unit", "nativeAd")
// obj.put("adSourceName", adSourceName)
// obj.put("adSourceId", adSourceId)
// obj.put("adSourceInstanceName", adSourceInstanceName)
// obj.put("adSourceInstanceId", adSourceInstanceId)
// obj.put("mediationGroupName", mediationGroupName)
// obj.put("mediationABTestName", mediationABTestName)
// obj.put("mediationABTestVariant", mediationABTestVariant)
// obj.put("session_id", sessionId)
// }
//
// else -> {
// runCatching {
// val adView = ad as AdView
// val adUnitId = adView.adUnitId
// val loadedAdapterResponseInfo = adView.responseInfo?.loadedAdapterResponseInfo
// val adSourceName = loadedAdapterResponseInfo?.adSourceName
// val adSourceId = loadedAdapterResponseInfo?.adSourceId
// val adSourceInstanceName = loadedAdapterResponseInfo?.adSourceInstanceName
// val adSourceInstanceId = loadedAdapterResponseInfo?.adSourceInstanceId
// val sessionId = adView.responseInfo?.responseId
// val extras = adView.responseInfo?.responseExtras
// val mediationGroupName = extras?.getString("mediation_group_name")
// val mediationABTestName = extras?.getString("mediation_ab_test_name")
// val mediationABTestVariant = extras?.getString("mediation_ab_test_variant")
// obj.put("ad_unit", "banner")
// obj.put("adUnitId", adUnitId)
// obj.put("adSourceName", adSourceName)
// obj.put("adSourceId", adSourceId)
// obj.put("adSourceInstanceName", adSourceInstanceName)
// obj.put("adSourceInstanceId", adSourceInstanceId)
// obj.put("mediationGroupName", mediationGroupName)
// obj.put("mediationABTestName", mediationABTestName)
// obj.put("mediationABTestVariant", mediationABTestVariant)
// obj.put("session_id", sessionId)
// }
// }
// }
// EventUtils.event(key, ext = obj)
//
// }
//}
\ No newline at end of file
package com.base.appzxhy.business.ads.applovin
import android.os.Bundle
import com.applovin.mediation.MaxAd
import com.applovin.mediation.MaxAdRevenueListener
import com.applovin.mediation.MaxError
import com.applovin.sdk.AppLovinSdk
import com.base.appzxhy.MyApplication
import com.base.appzxhy.business.ads.AdEvent
import com.base.appzxhy.business.ads.taichiPref
import com.base.appzxhy.business.ads.taichiSharedPreferencesEditor
import com.base.appzxhy.business.helper.EventUtils
import com.base.appzxhy.utils.LogEx.logDebug
import com.facebook.appevents.AppEventsConstants
import com.facebook.appevents.AppEventsLogger
import com.google.firebase.analytics.FirebaseAnalytics
import org.json.JSONObject
class AdMaxEvent : AdEvent {
override val TAG: String = "AdMaxEvent"
constructor(adUnit: String, from: String) : super() {
this.adUnit = adUnit
this.from = from
}
fun pullAd(
ad: MaxAd?,
error: MaxError? = null
) {
val obj = JSONObject()
obj.put("UnitId", ad?.adUnitId)
obj.put("ad_unit", adUnit)
obj.put(
"creativeId",
ad?.creativeId
)
obj.put("req_id", reqId)
obj.put("from", from)
obj.put("status", if (ad == null) "0" else "1")
obj.put("networkname", ad?.networkName)
obj.put("placement", ad?.placement)
obj.put("networkplacement", ad?.networkPlacement)
obj.put("latency", ad?.requestLatencyMillis)
obj.put("valueMicros", ad?.revenue)
if (error == null) {
obj.put("status", "1")
} else {
obj.put("errMsg", error)
obj.put("status", "2")
}
EventUtils.event("ad_pull", ext = obj)
logDebug(TAG, "ad_pull $obj")
}
fun clickAd(ad: MaxAd?) {
val obj = JSONObject()
obj.put("UnitId", ad?.adUnitId)
obj.put("ad_unit", adUnit)
obj.put(
"creativeId",
ad?.creativeId
)
obj.put("networkname", ad?.networkName)
obj.put("placement", ad?.placement)
obj.put("networkplacement", ad?.networkPlacement)
obj.put("latency", ad?.requestLatencyMillis)
obj.put("valueMicros", ad?.revenue)
if (!adUnit.equals("nativeAd")) {
EventUtils.event("ad_click", ext = obj)
} else {
EventUtils.event("ad_click", ext = obj)
}
}
fun showAd(ad: MaxAd?, activity: String?) {
val obj = JSONObject()
obj.put("UnitId", ad?.adUnitId)
obj.put("ad_unit", adUnit)
obj.put(
"creativeId",
ad?.creativeId
)
obj.put("networkname", ad?.networkName)
obj.put("placement", ad?.placement)
obj.put("networkplacement", ad?.networkPlacement)
obj.put("latency", ad?.requestLatencyMillis)
obj.put("valueMicros", ad?.revenue)
obj.put("from", activity)
obj.put("mediation", "applovin")
if (adUnit != "nativeAd") {
EventUtils.event("ad_show", ext = obj)
} else {
EventUtils.event("ad_show", ext = obj)
}
}
class EventOnPaidEventListener : MaxAdRevenueListener {
override fun onAdRevenuePaid(ad: MaxAd) {
val params = Bundle()
val currentImpressionRevenue: Double = ad.revenue // In USD
val mFirebaseAnalytics = FirebaseAnalytics.getInstance(MyApplication.appContext)
params.putString(FirebaseAnalytics.Param.AD_PLATFORM, "appLovin")
params.putString(FirebaseAnalytics.Param.AD_SOURCE, ad.networkName)
params.putString(FirebaseAnalytics.Param.AD_FORMAT, ad.format.getDisplayName())
params.putString(FirebaseAnalytics.Param.AD_UNIT_NAME, ad.adUnitId)
params.putDouble(FirebaseAnalytics.Param.VALUE, currentImpressionRevenue)
params.putString(FirebaseAnalytics.Param.CURRENCY, "USD")
mFirebaseAnalytics.logEvent(FirebaseAnalytics.Event.AD_IMPRESSION, params)
mFirebaseAnalytics.logEvent("Ad_Impression_Revenue", params)
val previousTaichiTroasCache = taichiPref.getFloat("TaichiTroasCache", 0f)
val currentTaichiTroasCache = previousTaichiTroasCache + currentImpressionRevenue
if (currentTaichiTroasCache >= 0.01) {
val roasbundle = Bundle()
roasbundle.putDouble(FirebaseAnalytics.Param.VALUE, currentTaichiTroasCache)
roasbundle.putString(FirebaseAnalytics.Param.CURRENCY, "USD")///(Required)tROAS事件必须
mFirebaseAnalytics.logEvent("Total_Ads_Revenue_001", roasbundle) // 给Taichi用
taichiSharedPreferencesEditor.putFloat("TaichiTroasCache", 0f)//重新清零,开始计算
val logger = AppEventsLogger.newLogger(MyApplication.appContext)
val parameters = Bundle()
parameters.putString(AppEventsConstants.EVENT_PARAM_CURRENCY, "USD")
logger.logEvent("ad_value", currentTaichiTroasCache, parameters)
} else {
taichiSharedPreferencesEditor.putFloat(
"TaichiTroasCache",
currentTaichiTroasCache.toFloat()
)
taichiSharedPreferencesEditor.commit()
}
val obj = JSONObject()
val revenue = ad.revenue
val countryCode =
AppLovinSdk.getInstance(MyApplication.appContext).configuration.countryCode
val networkName = ad.networkName
val adUnitId = ad.adUnitId
val adFormat = ad.format
val placement = ad.placement
val networkPlacement = ad.networkPlacement
obj.put("valueMicros", revenue)
obj.put("currencyCode", countryCode)
obj.put("adUnitId", adUnitId)
obj.put("networkName", networkName)
obj.put("adFormat", adFormat)
obj.put("placement", placement)
obj.put("networkPlacement", networkPlacement)
EventUtils.event("ad_price", ext = obj)
}
}
}
\ No newline at end of file
//package com.base.appzxhy.business.ads.applovin
//
//import android.os.Bundle
//import com.applovin.mediation.MaxAd
//import com.applovin.mediation.MaxAdRevenueListener
//import com.applovin.mediation.MaxError
//import com.applovin.sdk.AppLovinSdk
//import com.base.appzxhy.MyApplication
//import com.base.appzxhy.business.ads.AdEvent
//import com.base.appzxhy.business.ads.taichiPref
//import com.base.appzxhy.business.ads.taichiSharedPreferencesEditor
//import com.base.appzxhy.business.helper.EventUtils
//import com.base.appzxhy.utils.LogEx.logDebug
//import com.facebook.appevents.AppEventsConstants
//import com.facebook.appevents.AppEventsLogger
//import com.google.firebase.analytics.FirebaseAnalytics
//import org.json.JSONObject
//
//
//class AdMaxEvent : AdEvent {
//
// override val TAG: String = "AdMaxEvent"
//
// constructor(adUnit: String, from: String) : super() {
// this.adUnit = adUnit
// this.from = from
// }
//
// fun pullAd(
// ad: MaxAd?,
// error: MaxError? = null
// ) {
// val obj = JSONObject()
// obj.put("UnitId", ad?.adUnitId)
// obj.put("ad_unit", adUnit)
// obj.put(
// "creativeId",
// ad?.creativeId
// )
// obj.put("req_id", reqId)
// obj.put("from", from)
// obj.put("status", if (ad == null) "0" else "1")
// obj.put("networkname", ad?.networkName)
// obj.put("placement", ad?.placement)
// obj.put("networkplacement", ad?.networkPlacement)
// obj.put("latency", ad?.requestLatencyMillis)
// obj.put("valueMicros", ad?.revenue)
// if (error == null) {
// obj.put("status", "1")
// } else {
// obj.put("errMsg", error)
// obj.put("status", "2")
// }
// EventUtils.event("ad_pull", ext = obj)
// logDebug(TAG, "ad_pull $obj")
// }
//
// fun clickAd(ad: MaxAd?) {
//
// val obj = JSONObject()
// obj.put("UnitId", ad?.adUnitId)
// obj.put("ad_unit", adUnit)
// obj.put(
// "creativeId",
// ad?.creativeId
// )
// obj.put("networkname", ad?.networkName)
// obj.put("placement", ad?.placement)
// obj.put("networkplacement", ad?.networkPlacement)
// obj.put("latency", ad?.requestLatencyMillis)
// obj.put("valueMicros", ad?.revenue)
// if (!adUnit.equals("nativeAd")) {
// EventUtils.event("ad_click", ext = obj)
// } else {
// EventUtils.event("ad_click", ext = obj)
// }
//
// }
//
// fun showAd(ad: MaxAd?, activity: String?) {
// val obj = JSONObject()
// obj.put("UnitId", ad?.adUnitId)
// obj.put("ad_unit", adUnit)
// obj.put(
// "creativeId",
// ad?.creativeId
// )
// obj.put("networkname", ad?.networkName)
// obj.put("placement", ad?.placement)
// obj.put("networkplacement", ad?.networkPlacement)
// obj.put("latency", ad?.requestLatencyMillis)
// obj.put("valueMicros", ad?.revenue)
// obj.put("from", activity)
// obj.put("mediation", "applovin")
// if (adUnit != "nativeAd") {
// EventUtils.event("ad_show", ext = obj)
// } else {
// EventUtils.event("ad_show", ext = obj)
// }
//
// }
//
//
// class EventOnPaidEventListener : MaxAdRevenueListener {
// override fun onAdRevenuePaid(ad: MaxAd) {
// val params = Bundle()
// val currentImpressionRevenue: Double = ad.revenue // In USD
// val mFirebaseAnalytics = FirebaseAnalytics.getInstance(MyApplication.appContext)
// params.putString(FirebaseAnalytics.Param.AD_PLATFORM, "appLovin")
// params.putString(FirebaseAnalytics.Param.AD_SOURCE, ad.networkName)
// params.putString(FirebaseAnalytics.Param.AD_FORMAT, ad.format.getDisplayName())
// params.putString(FirebaseAnalytics.Param.AD_UNIT_NAME, ad.adUnitId)
// params.putDouble(FirebaseAnalytics.Param.VALUE, currentImpressionRevenue)
// params.putString(FirebaseAnalytics.Param.CURRENCY, "USD")
// mFirebaseAnalytics.logEvent(FirebaseAnalytics.Event.AD_IMPRESSION, params)
// mFirebaseAnalytics.logEvent("Ad_Impression_Revenue", params)
// val previousTaichiTroasCache = taichiPref.getFloat("TaichiTroasCache", 0f)
// val currentTaichiTroasCache = previousTaichiTroasCache + currentImpressionRevenue
// if (currentTaichiTroasCache >= 0.01) {
// val roasbundle = Bundle()
// roasbundle.putDouble(FirebaseAnalytics.Param.VALUE, currentTaichiTroasCache)
// roasbundle.putString(FirebaseAnalytics.Param.CURRENCY, "USD")///(Required)tROAS事件必须
// mFirebaseAnalytics.logEvent("Total_Ads_Revenue_001", roasbundle) // 给Taichi用
// taichiSharedPreferencesEditor.putFloat("TaichiTroasCache", 0f)//重新清零,开始计算
//
// val logger = AppEventsLogger.newLogger(MyApplication.appContext)
// val parameters = Bundle()
// parameters.putString(AppEventsConstants.EVENT_PARAM_CURRENCY, "USD")
// logger.logEvent("ad_value", currentTaichiTroasCache, parameters)
// } else {
// taichiSharedPreferencesEditor.putFloat(
// "TaichiTroasCache",
// currentTaichiTroasCache.toFloat()
// )
// taichiSharedPreferencesEditor.commit()
// }
// val obj = JSONObject()
// val revenue = ad.revenue
// val countryCode =
// AppLovinSdk.getInstance(MyApplication.appContext).configuration.countryCode
// val networkName = ad.networkName
// val adUnitId = ad.adUnitId
// val adFormat = ad.format
// val placement = ad.placement
// val networkPlacement = ad.networkPlacement
// obj.put("valueMicros", revenue)
// obj.put("currencyCode", countryCode)
// obj.put("adUnitId", adUnitId)
// obj.put("networkName", networkName)
// obj.put("adFormat", adFormat)
// obj.put("placement", placement)
// obj.put("networkPlacement", networkPlacement)
// EventUtils.event("ad_price", ext = obj)
// }
// }
//
//}
\ No newline at end of file
package com.base.appzxhy.business.ads.applovin
import android.app.Activity
import android.content.Context
import com.applovin.mediation.MaxAd
import com.applovin.mediation.MaxAdListener
import com.applovin.mediation.MaxError
import com.applovin.mediation.ads.MaxInterstitialAd
import com.base.appzxhy.GlobalConfig
import com.base.appzxhy.business.ads.AdCountDownDialog.showAdCountDownDialog
import com.base.appzxhy.business.ads.AdEvent
import com.base.appzxhy.business.ads.AdState
import com.base.appzxhy.business.ads.AdsShowCallBack
import com.base.appzxhy.business.ads.AdsType
import com.base.appzxhy.business.ads.LimitUtils
/**
*插屏广告加载显示管理类
*/
class MaxInsertMgr {
private var adState = AdState<MaxInterstitialAd>()
private var showCallBack: AdsShowCallBack? = null
fun show(
activity: Activity,
isUnLimit: Boolean,
adEvent: AdEvent,
showCallBack: AdsShowCallBack?
) {
if (activity.isFinishing || activity.isDestroyed) {
return
}
if (!adState.loadingAd) {
if (!isUnLimit) {
if (!LimitUtils.isAdShow(AdsType.INSERT, adEvent)) {
showCallBack?.failed(3)
return
}
if (LimitUtils.isIntervalLimited(adEvent)) {
showCallBack?.failed(4)
return
}
}
if (!adAvailable() || adState.currentAd == null) {
loadAd(activity, adEvent)
return
}
if (showCallBack != null) {
this.showCallBack = showCallBack
if (adState.adDialog == null) {
adState.adDialog = activity.showAdCountDownDialog()
}
adEvent.adPrepareShow()
}
if (adState.currentAd?.isReady == false) {
loadAd(activity, adEvent)
return
}
showReadyAd(adEvent)
}
}
private fun showReadyAd(adEvent: AdEvent) {
adState.currentAd?.run {
setListener(object : MaxAdListener {
override fun onAdLoaded(p0: MaxAd) = Unit
override fun onAdLoadFailed(p0: String, p1: MaxError) = Unit
override fun onAdDisplayed(ad: MaxAd) {
adState.onAdDisplayed()
showCallBack?.show()
(adEvent as AdMaxEvent).showAd(ad, activity::class.simpleName)
//计数
LimitUtils.addDisplayNum()
}
override fun onAdDisplayFailed(ad: MaxAd, error: MaxError) {
adState.onAdDisplayFailed()
showCallBack?.adFailed()
showCallBack = null
(adEvent as AdMaxEvent).adShowError(error)
}
override fun onAdHidden(p0: MaxAd) {
adState.onAdHidden()
showCallBack?.close()
loadAd(activity.applicationContext, AdMaxEvent("interAd", "preload"))
}
override fun onAdClicked(ad: MaxAd) {
(adEvent as AdMaxEvent).clickAd(ad)
//计数
LimitUtils.addClickNum()
}
})
setRevenueListener(AdMaxEvent.EventOnPaidEventListener())
showAd(activity)
}
}
fun loadAd(
context: Context,
adEvent: AdEvent,
loadCallback: (() -> Unit)? = null
) {
if (!adEvent.isUnLimit) {
if (!LimitUtils.isAdShow(AdsType.INSERT, adEvent)) {
this.showCallBack?.close(4)
this.showCallBack = null
return
}
}
if (!adState.loadingAd) {
adState.loadingAd = true
adEvent.adPulStart()
adState.currentAd = MaxInterstitialAd(GlobalConfig.ID_MAX_INTER, context)
adState.currentAd?.setListener(object : MaxAdListener {
override fun onAdDisplayed(p0: MaxAd) = Unit
override fun onAdHidden(p0: MaxAd) = Unit
override fun onAdClicked(p0: MaxAd) = Unit
override fun onAdDisplayFailed(p0: MaxAd, p1: MaxError) = Unit
override fun onAdLoaded(ad: MaxAd) {
adState.onAdLoaded(null, adEvent)
loadCallback?.invoke()
(adEvent as AdMaxEvent).pullAd(ad)
LimitUtils.addRequestNum()
}
override fun onAdLoadFailed(ad: String, error: MaxError) {
adState.onAdLoadFailed()
(adEvent as AdMaxEvent).pullAd(null, error)
showCallBack?.adFailed(5)
showCallBack = null
}
})
adState.currentAd?.loadAd()
}
}
private fun adAvailable() = ((System.currentTimeMillis() - adState.lastLoadTime) / 1000 / 60).toInt() < 30
}
\ No newline at end of file
//package com.base.appzxhy.business.ads.applovin
//
//import android.app.Activity
//import android.content.Context
//import com.applovin.mediation.MaxAd
//import com.applovin.mediation.MaxAdListener
//import com.applovin.mediation.MaxError
//import com.applovin.mediation.ads.MaxInterstitialAd
//import com.base.appzxhy.GlobalConfig
//import com.base.appzxhy.business.ads.AdCountDownDialog.showAdCountDownDialog
//import com.base.appzxhy.business.ads.AdEvent
//import com.base.appzxhy.business.ads.AdState
//import com.base.appzxhy.business.ads.AdsShowCallBack
//import com.base.appzxhy.business.ads.AdsType
//import com.base.appzxhy.business.ads.LimitUtils
//
///**
// *插屏广告加载显示管理类
// */
//class MaxInsertMgr {
//
// private var adState = AdState<MaxInterstitialAd>()
// private var showCallBack: AdsShowCallBack? = null
//
// fun show(
// activity: Activity,
// isUnLimit: Boolean,
// adEvent: AdEvent,
// showCallBack: AdsShowCallBack?
// ) {
//
// if (activity.isFinishing || activity.isDestroyed) {
// return
// }
//
//
// if (!adState.loadingAd) {
// if (!isUnLimit) {
// if (!LimitUtils.isAdShow(AdsType.INSERT, adEvent)) {
// showCallBack?.failed(3)
// return
// }
// if (LimitUtils.isIntervalLimited(adEvent)) {
// showCallBack?.failed(4)
// return
// }
// }
//
// if (!adAvailable() || adState.currentAd == null) {
// loadAd(activity, adEvent)
// return
// }
//
// if (showCallBack != null) {
// this.showCallBack = showCallBack
// if (adState.adDialog == null) {
// adState.adDialog = activity.showAdCountDownDialog()
// }
// adEvent.adPrepareShow()
// }
//
//
// if (adState.currentAd?.isReady == false) {
// loadAd(activity, adEvent)
// return
// }
// showReadyAd(adEvent)
// }
//
// }
//
//
// private fun showReadyAd(adEvent: AdEvent) {
// adState.currentAd?.run {
// setListener(object : MaxAdListener {
// override fun onAdLoaded(p0: MaxAd) = Unit
// override fun onAdLoadFailed(p0: String, p1: MaxError) = Unit
//
// override fun onAdDisplayed(ad: MaxAd) {
//
// adState.onAdDisplayed()
// showCallBack?.show()
//
// (adEvent as AdMaxEvent).showAd(ad, activity::class.simpleName)
// //计数
// LimitUtils.addDisplayNum()
// }
//
// override fun onAdDisplayFailed(ad: MaxAd, error: MaxError) {
// adState.onAdDisplayFailed()
// showCallBack?.adFailed()
// showCallBack = null
//
// (adEvent as AdMaxEvent).adShowError(error)
// }
//
// override fun onAdHidden(p0: MaxAd) {
//
// adState.onAdHidden()
// showCallBack?.close()
//
// loadAd(activity.applicationContext, AdMaxEvent("interAd", "preload"))
// }
//
// override fun onAdClicked(ad: MaxAd) {
// (adEvent as AdMaxEvent).clickAd(ad)
// //计数
// LimitUtils.addClickNum()
// }
//
//
// })
// setRevenueListener(AdMaxEvent.EventOnPaidEventListener())
//
// showAd(activity)
// }
// }
//
//
// fun loadAd(
// context: Context,
// adEvent: AdEvent,
// loadCallback: (() -> Unit)? = null
// ) {
// if (!adEvent.isUnLimit) {
// if (!LimitUtils.isAdShow(AdsType.INSERT, adEvent)) {
// this.showCallBack?.close(4)
// this.showCallBack = null
// return
// }
// }
//
// if (!adState.loadingAd) {
// adState.loadingAd = true
//
// adEvent.adPulStart()
//
// adState.currentAd = MaxInterstitialAd(GlobalConfig.ID_MAX_INTER, context)
// adState.currentAd?.setListener(object : MaxAdListener {
//
// override fun onAdDisplayed(p0: MaxAd) = Unit
// override fun onAdHidden(p0: MaxAd) = Unit
// override fun onAdClicked(p0: MaxAd) = Unit
// override fun onAdDisplayFailed(p0: MaxAd, p1: MaxError) = Unit
//
// override fun onAdLoaded(ad: MaxAd) {
// adState.onAdLoaded(null, adEvent)
// loadCallback?.invoke()
//
// (adEvent as AdMaxEvent).pullAd(ad)
// LimitUtils.addRequestNum()
// }
//
// override fun onAdLoadFailed(ad: String, error: MaxError) {
// adState.onAdLoadFailed()
//
// (adEvent as AdMaxEvent).pullAd(null, error)
//
// showCallBack?.adFailed(5)
// showCallBack = null
// }
//
// })
// adState.currentAd?.loadAd()
// }
// }
//
//
// private fun adAvailable() = ((System.currentTimeMillis() - adState.lastLoadTime) / 1000 / 60).toInt() < 30
//}
\ No newline at end of file
package com.base.appzxhy.business.ads.applovin
import androidx.annotation.LayoutRes
import com.applovin.mediation.MaxAd
import com.applovin.mediation.MaxError
import com.applovin.mediation.nativeAds.MaxNativeAdListener
import com.applovin.mediation.nativeAds.MaxNativeAdLoader
import com.applovin.mediation.nativeAds.MaxNativeAdView
import com.base.appzxhy.GlobalConfig
import com.base.appzxhy.business.ads.AdsType
import com.base.appzxhy.business.ads.LimitUtils
import com.base.appzxhy.business.ads.NativeParentView
import com.base.appzxhy.business.helper.EventUtils
import org.json.JSONObject
import java.util.UUID
/**
*原生广告加载显示管理类
*/
class MaxNativeMgr {
/**
* 上一次的缓存成功时间
*/
protected var lastTime: Long = 0
/**
* 原生广告
*/
private var currentAd: MaxAd? = null
private var currentLoader: MaxNativeAdLoader? = null
private fun loadAd(
adMaxEvent: AdMaxEvent,
parent: NativeParentView,
@LayoutRes layout: Int
) {
if (!LimitUtils.isAdShow(AdsType.NATIVE, adMaxEvent)) return
val reqId = UUID.randomUUID().toString()
val obj = JSONObject()
obj.put("req_id", reqId)
obj.put("ad_type", "nativeAd")
val nativeAdLoader = MaxNativeAdLoader(GlobalConfig.ID_MAX_NATIVE, parent.context)
nativeAdLoader.setNativeAdListener(object : MaxNativeAdListener() {
override fun onNativeAdLoaded(nativeAdView: MaxNativeAdView?, ad: MaxAd) {
currentLoader = nativeAdLoader
currentAd = ad
lastTime = System.currentTimeMillis()
adMaxEvent.pullAd(ad)
nativeAdLoader.setRevenueListener(AdMaxEvent.EventOnPaidEventListener())
show(adMaxEvent, parent, layout)
}
override fun onNativeAdLoadFailed(adUnitId: String, error: MaxError) {
adMaxEvent.pullAd(null, error)
}
override fun onNativeAdClicked(ad: MaxAd) {
}
})
nativeAdLoader.loadAd()
}
fun show(
adMaxEvent: AdMaxEvent,
parent: NativeParentView,
@LayoutRes layout: Int,
nativeCallBack: ((Any?) -> Unit)? = null
) {
if (!LimitUtils.isAdShow(AdsType.NATIVE, adMaxEvent)) {
currentLoader = null
currentAd = null
return
}
val nativeAd = currentAd
val nativeLoader = currentLoader
if ((nativeAd == null || nativeLoader == null).also {
if (it) {
val obj2 = JSONObject()
obj2.put("reason", "no_ad")
obj2.put("ad_unit", "nativeAd")
EventUtils.event("ad_show_error", ext = obj2)
}
} || (!adAvailable()).also {
if (it) {
val obj2 = JSONObject()
obj2.put("ad_unit", "nativeAd")
EventUtils.event("ad_expire", ext = obj2)
}
}) {
//缓存过期了就清空
currentLoader = null
currentAd = null
loadAd(AdMaxEvent("nativeAd", "preload"), parent, layout)
return
}
val obj = JSONObject()
obj.put("ad_unit", "nativeAd")
EventUtils.event("ad_prepare_show", ext = obj)
parent.setNativeAd(nativeLoader!!, nativeAd!!, layout)
nativeCallBack?.invoke(nativeAd)
}
private fun adAvailable(): Boolean {
return ((System.currentTimeMillis() - lastTime) / 1000 / 60).toInt() < 30
}
}
\ No newline at end of file
//package com.base.appzxhy.business.ads.applovin
//
//import androidx.annotation.LayoutRes
//import com.applovin.mediation.MaxAd
//import com.applovin.mediation.MaxError
//import com.applovin.mediation.nativeAds.MaxNativeAdListener
//import com.applovin.mediation.nativeAds.MaxNativeAdLoader
//import com.applovin.mediation.nativeAds.MaxNativeAdView
//import com.base.appzxhy.GlobalConfig
//import com.base.appzxhy.business.ads.AdsType
//import com.base.appzxhy.business.ads.LimitUtils
//import com.base.appzxhy.business.ads.NativeParentView
//import com.base.appzxhy.business.helper.EventUtils
//import org.json.JSONObject
//import java.util.UUID
//
///**
// *原生广告加载显示管理类
// */
//class MaxNativeMgr {
//
// /**
// * 上一次的缓存成功时间
// */
// protected var lastTime: Long = 0
//
// /**
// * 原生广告
// */
// private var currentAd: MaxAd? = null
// private var currentLoader: MaxNativeAdLoader? = null
//
//
// private fun loadAd(
// adMaxEvent: AdMaxEvent,
// parent: NativeParentView,
// @LayoutRes layout: Int
// ) {
//
// if (!LimitUtils.isAdShow(AdsType.NATIVE, adMaxEvent)) return
//
// val reqId = UUID.randomUUID().toString()
// val obj = JSONObject()
// obj.put("req_id", reqId)
// obj.put("ad_type", "nativeAd")
//
// val nativeAdLoader = MaxNativeAdLoader(GlobalConfig.ID_MAX_NATIVE, parent.context)
//
// nativeAdLoader.setNativeAdListener(object : MaxNativeAdListener() {
//
// override fun onNativeAdLoaded(nativeAdView: MaxNativeAdView?, ad: MaxAd) {
// currentLoader = nativeAdLoader
// currentAd = ad
// lastTime = System.currentTimeMillis()
// adMaxEvent.pullAd(ad)
// nativeAdLoader.setRevenueListener(AdMaxEvent.EventOnPaidEventListener())
// show(adMaxEvent, parent, layout)
// }
//
// override fun onNativeAdLoadFailed(adUnitId: String, error: MaxError) {
// adMaxEvent.pullAd(null, error)
// }
//
// override fun onNativeAdClicked(ad: MaxAd) {
//
// }
//
// })
// nativeAdLoader.loadAd()
// }
//
// fun show(
// adMaxEvent: AdMaxEvent,
// parent: NativeParentView,
// @LayoutRes layout: Int,
// nativeCallBack: ((Any?) -> Unit)? = null
// ) {
// if (!LimitUtils.isAdShow(AdsType.NATIVE, adMaxEvent)) {
// currentLoader = null
// currentAd = null
// return
// }
// val nativeAd = currentAd
// val nativeLoader = currentLoader
// if ((nativeAd == null || nativeLoader == null).also {
// if (it) {
// val obj2 = JSONObject()
// obj2.put("reason", "no_ad")
// obj2.put("ad_unit", "nativeAd")
// EventUtils.event("ad_show_error", ext = obj2)
// }
// } || (!adAvailable()).also {
// if (it) {
// val obj2 = JSONObject()
// obj2.put("ad_unit", "nativeAd")
// EventUtils.event("ad_expire", ext = obj2)
// }
// }) {
// //缓存过期了就清空
// currentLoader = null
// currentAd = null
// loadAd(AdMaxEvent("nativeAd", "preload"), parent, layout)
// return
// }
// val obj = JSONObject()
// obj.put("ad_unit", "nativeAd")
// EventUtils.event("ad_prepare_show", ext = obj)
// parent.setNativeAd(nativeLoader!!, nativeAd!!, layout)
// nativeCallBack?.invoke(nativeAd)
// }
//
// private fun adAvailable(): Boolean {
// return ((System.currentTimeMillis() - lastTime) / 1000 / 60).toInt() < 30
// }
//}
\ No newline at end of file
package com.base.appzxhy.business.ads.applovin
import android.app.Activity
import android.content.Context
import com.applovin.mediation.MaxAd
import com.applovin.mediation.MaxAdListener
import com.applovin.mediation.MaxError
import com.applovin.mediation.ads.MaxAppOpenAd
import com.base.appzxhy.GlobalConfig
import com.base.appzxhy.business.ads.AdEvent
import com.base.appzxhy.business.ads.AdState
import com.base.appzxhy.business.ads.AdsShowCallBack
import com.base.appzxhy.business.ads.AdsType
import com.base.appzxhy.business.ads.LimitUtils
/**
* 开屏广告加载显示管理类
*/
class MaxOpenMgr {
private val adState = AdState<MaxAppOpenAd>()
private var showCallBack: AdsShowCallBack? = null
fun show(activity: Activity, isUnLimit: Boolean, adEvent: AdEvent, showCallBack: AdsShowCallBack?) {
if (activity.isFinishing || activity.isDestroyed) {
return
}
if (showCallBack != null) {
this.showCallBack = showCallBack
adEvent.adPrepareShow()
}
if (!adState.loadingAd) {
if (!isUnLimit) {
if (!LimitUtils.isAdShow(AdsType.OPEN, adEvent)) {
showCallBack?.failed()
return
}
if (LimitUtils.isIntervalLimited(adEvent)) {
showCallBack?.failed()
return
}
}
if (!adAvailable() || adState.currentAd == null) {
loadAd(activity, isUnLimit, adEvent)
return
}
if (adState.currentAd?.isReady != true) {
loadAd(activity, isUnLimit, adEvent)
return
}
showReadyAd(activity, adEvent)
}
}
private fun showReadyAd(activity: Activity, adEvent: AdEvent) {
adState.currentAd?.run {
setListener(object : MaxAdListener {
override fun onAdLoaded(p0: MaxAd) {
}
override fun onAdDisplayed(ad: MaxAd) {
adState.onAdDisplayed()
showCallBack?.show()
LimitUtils.addDisplayNum()
(adEvent as AdMaxEvent).showAd(ad, activity::class.simpleName)
}
override fun onAdHidden(p0: MaxAd) {
adState.onAdHidden()
showCallBack?.close()
showCallBack = null
loadAd(activity.applicationContext, false, AdMaxEvent("openAd", "preload"))
}
override fun onAdClicked(ad: MaxAd) {
(adEvent as AdMaxEvent).clickAd(ad)
//计数
LimitUtils.addClickNum()
}
override fun onAdLoadFailed(p0: String, p1: MaxError) {
}
override fun onAdDisplayFailed(p0: MaxAd, error: MaxError) {
adState.onAdDisplayFailed()
showCallBack?.adFailed()
showCallBack = null
adEvent.adShowError(error)
}
})
showAd()
}
}
fun loadAd(context: Context, isUnLimit: Boolean, adEvent: AdEvent) {
if (!isUnLimit) {
if (!LimitUtils.isAdShow(AdsType.OPEN, adEvent)) {
this.showCallBack?.close()
this.showCallBack = null
return
}
}
if (!adState.loadingAd) {
adState.loadingAd = true
adEvent.adPulStart()
adState.currentAd = MaxAppOpenAd(GlobalConfig.ID_MAX_OPEN, context)
adState.currentAd?.setListener(object : MaxAdListener {
override fun onAdLoaded(ad: MaxAd) {
adState.onAdLoaded(null, adEvent)
(adEvent as AdMaxEvent).pullAd(ad)
LimitUtils.addRequestNum()
}
override fun onAdDisplayed(p0: MaxAd) {
}
override fun onAdHidden(p0: MaxAd) {
}
override fun onAdClicked(p0: MaxAd) {
}
override fun onAdLoadFailed(p0: String, error: MaxError) {
adState.onAdLoadFailed()
showCallBack?.adFailed()
showCallBack = null
(adEvent as AdMaxEvent).pullAd(null, error)
}
override fun onAdDisplayFailed(p0: MaxAd, p1: MaxError) {
}
})
adState.currentAd?.loadAd()
}
}
fun adAvailable() = ((System.currentTimeMillis() - adState.lastLoadTime) / 1000 / 60).toInt() < 30
}
\ No newline at end of file
//package com.base.appzxhy.business.ads.applovin
//
//import android.app.Activity
//import android.content.Context
//import com.applovin.mediation.MaxAd
//import com.applovin.mediation.MaxAdListener
//import com.applovin.mediation.MaxError
//import com.applovin.mediation.ads.MaxAppOpenAd
//import com.base.appzxhy.GlobalConfig
//import com.base.appzxhy.business.ads.AdEvent
//import com.base.appzxhy.business.ads.AdState
//import com.base.appzxhy.business.ads.AdsShowCallBack
//import com.base.appzxhy.business.ads.AdsType
//import com.base.appzxhy.business.ads.LimitUtils
//
///**
// * 开屏广告加载显示管理类
// */
//class MaxOpenMgr {
//
// private val adState = AdState<MaxAppOpenAd>()
// private var showCallBack: AdsShowCallBack? = null
//
// fun show(activity: Activity, isUnLimit: Boolean, adEvent: AdEvent, showCallBack: AdsShowCallBack?) {
// if (activity.isFinishing || activity.isDestroyed) {
// return
// }
//
// if (showCallBack != null) {
// this.showCallBack = showCallBack
// adEvent.adPrepareShow()
// }
//
// if (!adState.loadingAd) {
//
// if (!isUnLimit) {
// if (!LimitUtils.isAdShow(AdsType.OPEN, adEvent)) {
// showCallBack?.failed()
// return
// }
// if (LimitUtils.isIntervalLimited(adEvent)) {
// showCallBack?.failed()
// return
// }
// }
//
// if (!adAvailable() || adState.currentAd == null) {
// loadAd(activity, isUnLimit, adEvent)
// return
// }
//
// if (adState.currentAd?.isReady != true) {
// loadAd(activity, isUnLimit, adEvent)
// return
// }
// showReadyAd(activity, adEvent)
// }
//
//
// }
//
//
// private fun showReadyAd(activity: Activity, adEvent: AdEvent) {
// adState.currentAd?.run {
// setListener(object : MaxAdListener {
// override fun onAdLoaded(p0: MaxAd) {
//
// }
//
// override fun onAdDisplayed(ad: MaxAd) {
// adState.onAdDisplayed()
// showCallBack?.show()
//
// LimitUtils.addDisplayNum()
// (adEvent as AdMaxEvent).showAd(ad, activity::class.simpleName)
// }
//
// override fun onAdHidden(p0: MaxAd) {
// adState.onAdHidden()
// showCallBack?.close()
// showCallBack = null
//
// loadAd(activity.applicationContext, false, AdMaxEvent("openAd", "preload"))
// }
//
// override fun onAdClicked(ad: MaxAd) {
// (adEvent as AdMaxEvent).clickAd(ad)
// //计数
// LimitUtils.addClickNum()
// }
//
// override fun onAdLoadFailed(p0: String, p1: MaxError) {
//
// }
//
// override fun onAdDisplayFailed(p0: MaxAd, error: MaxError) {
// adState.onAdDisplayFailed()
// showCallBack?.adFailed()
// showCallBack = null
// adEvent.adShowError(error)
// }
//
// })
//
// showAd()
// }
// }
//
// fun loadAd(context: Context, isUnLimit: Boolean, adEvent: AdEvent) {
//
// if (!isUnLimit) {
// if (!LimitUtils.isAdShow(AdsType.OPEN, adEvent)) {
// this.showCallBack?.close()
// this.showCallBack = null
// return
// }
// }
//
// if (!adState.loadingAd) {
// adState.loadingAd = true
//
// adEvent.adPulStart()
//
// adState.currentAd = MaxAppOpenAd(GlobalConfig.ID_MAX_OPEN, context)
// adState.currentAd?.setListener(object : MaxAdListener {
// override fun onAdLoaded(ad: MaxAd) {
// adState.onAdLoaded(null, adEvent)
// (adEvent as AdMaxEvent).pullAd(ad)
// LimitUtils.addRequestNum()
// }
//
// override fun onAdDisplayed(p0: MaxAd) {
//
// }
//
// override fun onAdHidden(p0: MaxAd) {
//
// }
//
// override fun onAdClicked(p0: MaxAd) {
// }
//
// override fun onAdLoadFailed(p0: String, error: MaxError) {
// adState.onAdLoadFailed()
// showCallBack?.adFailed()
// showCallBack = null
// (adEvent as AdMaxEvent).pullAd(null, error)
// }
//
// override fun onAdDisplayFailed(p0: MaxAd, p1: MaxError) {
//
// }
//
// })
// adState.currentAd?.loadAd()
// }
// }
//
//
// fun adAvailable() = ((System.currentTimeMillis() - adState.lastLoadTime) / 1000 / 60).toInt() < 30
//}
\ No newline at end of file
package com.base.appzxhy.business.pangle
import android.content.Context
import android.os.Bundle
import androidx.activity.enableEdgeToEdge
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
import com.base.appzxhy.GlobalConfig
import com.base.appzxhy.R
import com.base.appzxhy.business.ads.AdsMgr
import com.base.appzxhy.business.ads.AdsShowCallBack
import com.base.appzxhy.databinding.ActivityPangleBinding
import com.base.appzxhy.utils.ToastUtils.toast
import com.bytedance.sdk.openadsdk.api.init.PAGConfig
import com.bytedance.sdk.openadsdk.api.init.PAGSdk
import com.bytedance.sdk.openadsdk.api.init.PAGSdk.PAGInitCallback
class PangleActivity : AppCompatActivity() {
private lateinit var binding: ActivityPangleBinding
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
enableEdgeToEdge()
binding = ActivityPangleBinding.inflate(layoutInflater)
setContentView(binding.root)
ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main)) { v, insets ->
val systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars())
v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom)
insets
}
binding.initSdk.setOnClickListener {
AdsMgr.initPangle(this)
}
binding.showOpen.setOnClickListener {
AdsMgr.showOpen(this, showCallBack = object : AdsShowCallBack() {
override fun next() {
}
})
}
}
}
\ No newline at end of file
package com.base.appzxhy.business.pangle
import android.util.Log
import com.base.appzxhy.GlobalConfig
import com.base.appzxhy.business.ads.AdsShowCallBack
import com.base.appzxhy.utils.LogEx
import com.bytedance.sdk.openadsdk.api.interstitial.PAGInterstitialAd
import com.bytedance.sdk.openadsdk.api.interstitial.PAGInterstitialAdLoadListener
import com.bytedance.sdk.openadsdk.api.interstitial.PAGInterstitialRequest
class PangleInterMgr {
private val TAG = "PangleInterMgr"
private var interstitialAd: PAGInterstitialAd? = null
private var showCallBack: AdsShowCallBack? = null
fun load(callback: ((flag: Boolean) -> Unit)? = null) {
PAGInterstitialAd.loadAd(
GlobalConfig.ID_PANGLE_INTER,
PAGInterstitialRequest(),
object : PAGInterstitialAdLoadListener {
override fun onError(code: Int, message: String?) {
LogEx.logDebug(TAG, "loadAd onError code=$code message=$message")
callback?.invoke(false)
}
override fun onAdLoaded(pagInterstitialAd: PAGInterstitialAd?) {
LogEx.logDebug(TAG, "onAdLoaded")
interstitialAd = pagInterstitialAd
callback?.invoke(true)
}
})
}
}
\ No newline at end of file
package com.base.appzxhy.business.pangle
import android.app.Activity
import com.base.appzxhy.GlobalConfig
import com.base.appzxhy.business.ads.AdsShowCallBack
import com.base.appzxhy.utils.LogEx
import com.bytedance.sdk.openadsdk.api.open.PAGAppOpenAd
import com.bytedance.sdk.openadsdk.api.open.PAGAppOpenAdInteractionListener
import com.bytedance.sdk.openadsdk.api.open.PAGAppOpenAdLoadListener
import com.bytedance.sdk.openadsdk.api.open.PAGAppOpenRequest
class PangleOpenMgr {
private val TAG = "PangleOpenMgr"
private var ttAppOpenAd: PAGAppOpenAd? = null
private var showCallBack: AdsShowCallBack? = null
private val slotId: String = GlobalConfig.ID_PANGLE_OPEN
fun load(callback: ((flag: Boolean) -> Unit)? = null) {
val request = PAGAppOpenRequest()
request.timeout = 3000
PAGAppOpenAd.loadAd(slotId, request, object : PAGAppOpenAdLoadListener {
override fun onError(code: Int, message: String?) {
LogEx.logDebug(TAG, "loadAd onError code=$code message=$message")
callback?.invoke(false)
}
override fun onAdLoaded(pagAppOpenAd: PAGAppOpenAd?) {
LogEx.logDebug(TAG, "onAdLoaded")
ttAppOpenAd = pagAppOpenAd
callback?.invoke(true)
}
})
}
fun show(activity: Activity, showCallBack: AdsShowCallBack?) {
if (activity.isFinishing || activity.isDestroyed) {
return
}
this.showCallBack = showCallBack
if (ttAppOpenAd == null) {
LogEx.logDebug(TAG, "ttAppOpenAd load")
load {
if (it) {
showReadyAd(activity)
} else {
showCallBack?.adFailed()
}
}
} else {
LogEx.logDebug(TAG, "ttAppOpenAd ready")
showReadyAd(activity)
}
}
private fun showReadyAd(ac: Activity) {
if (ac.isFinishing || ac.isDestroyed) {
return
}
if (ttAppOpenAd == null) {
showCallBack?.failed()
return
}
LogEx.logDebug(TAG, "ttAppOpenAd show")
ttAppOpenAd?.setAdInteractionListener(object : PAGAppOpenAdInteractionListener {
override fun onAdShowed() {
showCallBack?.show()
ttAppOpenAd = null
load()
}
override fun onAdClicked() {
}
override fun onAdDismissed() {
showCallBack?.close()
}
})
ttAppOpenAd?.show(ac)
}
}
......@@ -12,10 +12,10 @@ import androidx.core.graphics.createBitmap
import com.base.appzxhy.bean.push.NotificationInfoBean
import com.google.gson.Gson
import com.google.gson.reflect.TypeToken
import com.mbridge.msdk.thrid.okhttp.OkHttpClient
import com.mbridge.msdk.thrid.okhttp.Request
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext
import okhttp3.OkHttpClient
import okhttp3.Request
import java.io.InputStream
import java.util.LinkedList
......@@ -57,7 +57,7 @@ object NotificationBeanUtils {
if (!response.isSuccessful) {
return@withContext null
}
val inputStream: InputStream = response.body()!!.byteStream()
val inputStream: InputStream = response.body!!.byteStream()
val bitmap = BitmapFactory.decodeStream(inputStream)
val roundedBitmap = getRoundedCornersBitmap(bitmap, 8f)
roundedBitmap
......
......@@ -42,8 +42,8 @@ import com.base.appzxhy.ui.main.MainActivity
import com.base.appzxhy.utils.LogEx
import com.base.appzxhy.utils.PermissionUtils.checkStorePermission
import com.base.appzxhy.utils.PermissionUtils.requestStoragePermission
import com.base.appzxhy.utils.UmpUtils
import com.base.appzxhy.utils.umpCalled
//import com.base.appzxhy.utils.UmpUtils
//import com.base.appzxhy.utils.umpCalled
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import java.util.concurrent.atomic.AtomicBoolean
......@@ -153,28 +153,28 @@ class SplashActivity : BaseActivity<ActivitySplashBinding>(ActivitySplashBinding
}
private fun initUMP(callBack: () -> Unit) {
if (AdConfigBean.adsConfigBean.requestUmp && !umpCalled) {
umpCalled = true
val ump = UmpUtils(this)
if (ump.consentInformation.canRequestAds()) {
callBack.invoke()
} else {
ump.callback = {
callBack.invoke()
}
LogEx.logDebug(TAG, "requestUMP")
ump.requestUMP()
}
} else {
callBack.invoke()
}
}
// private fun initUMP(callBack: () -> Unit) {
//
// if (AdConfigBean.adsConfigBean.requestUmp && !umpCalled) {
// umpCalled = true
//
// val ump = UmpUtils(this)
// if (ump.consentInformation.canRequestAds()) {
// callBack.invoke()
// } else {
// ump.callback = {
// callBack.invoke()
// }
// LogEx.logDebug(TAG, "requestUMP")
// ump.requestUMP()
// }
//
// } else {
// callBack.invoke()
// }
//
//
// }
private fun showLoadingAd() {
binding.clBottomStart.visibility = if (ifAgreePrivacy) View.GONE else View.VISIBLE
......@@ -184,39 +184,39 @@ class SplashActivity : BaseActivity<ActivitySplashBinding>(ActivitySplashBinding
if (ifAgreePrivacy) {
val acAction = {
initUMP {
LogEx.logDebug(TAG, "initUMP callback")
// initUMP {
LogEx.logDebug(TAG, "initUMP callback")
AdsMgr.showOpen(this, showCallBack = object : AdsShowCallBack() {
override fun show() {
super.show()
viewModel.stopCountdown()
binding.progressBar.setProgress(100, true)
}
AdsMgr.showOpen(this, showCallBack = object : AdsShowCallBack() {
override fun show() {
super.show()
viewModel.stopCountdown()
override fun next() {
val action = {
LogEx.logDebug(TAG, "next")
viewModel.overCountDown()
binding.progressBar.setProgress(100, true)
binding.root.postDelayed({ jumpNext() }, 250)
}
override fun next() {
val action = {
LogEx.logDebug(TAG, "next")
viewModel.overCountDown()
binding.progressBar.setProgress(100, true)
binding.root.postDelayed({ jumpNext() }, 250)
}
LogEx.logDebug("AdmobEvent", "inter adShowed=${adShowed}")
if (adShowed) {
action.invoke()
} else {
LogEx.logDebug("AdmobEvent", "inter open show inter")
AdsMgr.showInsert(this@SplashActivity, showCallBack = object : AdsShowCallBack() {
override fun next() {
action.invoke()
}
})
}
LogEx.logDebug("AdmobEvent", "inter adShowed=${adShowed}")
if (adShowed) {
action.invoke()
} else {
LogEx.logDebug("AdmobEvent", "inter open show inter")
AdsMgr.showInsert(this@SplashActivity, showCallBack = object : AdsShowCallBack() {
override fun next() {
action.invoke()
}
})
}
})
}
}
})
// }
}
if (spConfig.isNotEmpty()) {
......
package com.base.appzxhy.utils
import android.app.Activity
import android.content.Context
import com.base.appzxhy.BuildConfig
import com.google.android.ump.ConsentDebugSettings
import com.google.android.ump.ConsentForm
import com.google.android.ump.ConsentInformation
import com.google.android.ump.ConsentRequestParameters
import com.google.android.ump.FormError
import com.google.android.ump.UserMessagingPlatform
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.MainScope
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
var umpCanAd = true
get() {
return AppPreferences.getInstance().getBoolean("umpCanAd", field)
}
set(value) {
field = value
AppPreferences.getInstance().put("umpCanAd", value, true)
}
var umpCalled = false
get() {
return AppPreferences.getInstance().getBoolean("umpCalled", field)
}
set(value) {
field = value
AppPreferences.getInstance().put("umpCalled", value, true)
}
class UmpUtils(
val activity: Activity
) {
private fun Context.umpTest(): ConsentDebugSettings {
val debugSettings = ConsentDebugSettings.Builder(this)
debugSettings.setDebugGeography(ConsentDebugSettings.DebugGeography.DEBUG_GEOGRAPHY_EEA)
//通过TEST-DEVICE-HASHED-ID log过滤ConsentDebugSettings 打印测试id,使用测试id来测试
// debugSettings.addTestDeviceHashedId("TEST-DEVICE-HASHED-ID")
debugSettings.addTestDeviceHashedId("E136C135912795B2B1121AFD737A0F0E")
return debugSettings.build()
}
var callback: ((canAd: Boolean) -> Unit)? = null
private val TAG = "UmpUtils"
val consentInformation: ConsentInformation = UserMessagingPlatform.getConsentInformation(activity)
fun requestUMP() {
val paramsBuild = ConsentRequestParameters.Builder()
if (BuildConfig.DEBUG) {
paramsBuild.setConsentDebugSettings(activity.umpTest())
}
// 指示用户是否低于同意年龄; true 低于同意年龄
// 未满同意年龄的用户不会收到 GDPR 消息表单
paramsBuild.setTagForUnderAgeOfConsent(false)
val params = paramsBuild.build()
if (BuildConfig.DEBUG) {
consentInformation.reset()
}
val updateSuccessListener = ConsentInformation.OnConsentInfoUpdateSuccessListener {
LogEx.logDebug(TAG, "isConsentFormAvailable=${consentInformation.isConsentFormAvailable}")
if (consentInformation.isConsentFormAvailable) {
MainScope().launch(Dispatchers.Main) {
delay(500)
loadAndShowConsentFormIfRequired(activity, consentInformation)
}
} else {
callback?.invoke(true)
callback = null
}
}
val updateFailureListener = ConsentInformation.OnConsentInfoUpdateFailureListener {
LogEx.logDebug(TAG, "message=${it.message} errorCode=${it.errorCode}")
callback?.invoke(true)
callback = null
}
consentInformation.requestConsentInfoUpdate(activity, params, updateSuccessListener, updateFailureListener)
}
private fun loadAndShowConsentFormIfRequired(activity: Activity, consentInformation: ConsentInformation) {
UserMessagingPlatform.loadConsentForm(
activity,
object : UserMessagingPlatform.OnConsentFormLoadSuccessListener {
override fun onConsentFormLoadSuccess(consentForm: ConsentForm) {
LogEx.logDebug(TAG, "onConsentFormLoadSuccess")
consentForm.show(activity) {
callback?.invoke(consentInformation.canRequestAds())
callback = null
}
}
},
object : UserMessagingPlatform.OnConsentFormLoadFailureListener {
override fun onConsentFormLoadFailure(p0: FormError) {
//https://groups.google.com/g/google-admob-ads-sdk/c/x-fyDOfMSqU/m/MeZX3mO4AAAJ
LogEx.logDebug(TAG, "onConsentFormLoadFailure ${p0.message} ${p0.errorCode}")
callback?.invoke(true)
callback = null
}
})
}
}
\ No newline at end of file
//package com.base.appzxhy.utils
//
//import android.app.Activity
//import android.content.Context
//import com.base.appzxhy.BuildConfig
//import com.google.android.ump.ConsentDebugSettings
//import com.google.android.ump.ConsentForm
//import com.google.android.ump.ConsentInformation
//import com.google.android.ump.ConsentRequestParameters
//import com.google.android.ump.FormError
//import com.google.android.ump.UserMessagingPlatform
//import kotlinx.coroutines.Dispatchers
//import kotlinx.coroutines.MainScope
//import kotlinx.coroutines.delay
//import kotlinx.coroutines.launch
//
//
//var umpCanAd = true
// get() {
// return AppPreferences.getInstance().getBoolean("umpCanAd", field)
// }
// set(value) {
// field = value
// AppPreferences.getInstance().put("umpCanAd", value, true)
// }
//var umpCalled = false
// get() {
// return AppPreferences.getInstance().getBoolean("umpCalled", field)
// }
// set(value) {
// field = value
// AppPreferences.getInstance().put("umpCalled", value, true)
// }
//
//class UmpUtils(
// val activity: Activity
//) {
//
// private fun Context.umpTest(): ConsentDebugSettings {
// val debugSettings = ConsentDebugSettings.Builder(this)
// debugSettings.setDebugGeography(ConsentDebugSettings.DebugGeography.DEBUG_GEOGRAPHY_EEA)
// //通过TEST-DEVICE-HASHED-ID log过滤ConsentDebugSettings 打印测试id,使用测试id来测试
//// debugSettings.addTestDeviceHashedId("TEST-DEVICE-HASHED-ID")
// debugSettings.addTestDeviceHashedId("E136C135912795B2B1121AFD737A0F0E")
// return debugSettings.build()
// }
//
// var callback: ((canAd: Boolean) -> Unit)? = null
//
//
// private val TAG = "UmpUtils"
//
// val consentInformation: ConsentInformation = UserMessagingPlatform.getConsentInformation(activity)
//
//
// fun requestUMP() {
//
// val paramsBuild = ConsentRequestParameters.Builder()
//
// if (BuildConfig.DEBUG) {
// paramsBuild.setConsentDebugSettings(activity.umpTest())
// }
//
// // 指示用户是否低于同意年龄; true 低于同意年龄
// // 未满同意年龄的用户不会收到 GDPR 消息表单
// paramsBuild.setTagForUnderAgeOfConsent(false)
// val params = paramsBuild.build()
//
//
// if (BuildConfig.DEBUG) {
// consentInformation.reset()
// }
//
// val updateSuccessListener = ConsentInformation.OnConsentInfoUpdateSuccessListener {
// LogEx.logDebug(TAG, "isConsentFormAvailable=${consentInformation.isConsentFormAvailable}")
// if (consentInformation.isConsentFormAvailable) {
// MainScope().launch(Dispatchers.Main) {
// delay(500)
// loadAndShowConsentFormIfRequired(activity, consentInformation)
// }
// } else {
// callback?.invoke(true)
// callback = null
// }
// }
// val updateFailureListener = ConsentInformation.OnConsentInfoUpdateFailureListener {
// LogEx.logDebug(TAG, "message=${it.message} errorCode=${it.errorCode}")
// callback?.invoke(true)
// callback = null
// }
//
// consentInformation.requestConsentInfoUpdate(activity, params, updateSuccessListener, updateFailureListener)
// }
//
// private fun loadAndShowConsentFormIfRequired(activity: Activity, consentInformation: ConsentInformation) {
//
// UserMessagingPlatform.loadConsentForm(
// activity,
// object : UserMessagingPlatform.OnConsentFormLoadSuccessListener {
// override fun onConsentFormLoadSuccess(consentForm: ConsentForm) {
// LogEx.logDebug(TAG, "onConsentFormLoadSuccess")
// consentForm.show(activity) {
// callback?.invoke(consentInformation.canRequestAds())
// callback = null
// }
// }
//
// },
// object : UserMessagingPlatform.OnConsentFormLoadFailureListener {
// override fun onConsentFormLoadFailure(p0: FormError) {
// //https://groups.google.com/g/google-admob-ads-sdk/c/x-fyDOfMSqU/m/MeZX3mO4AAAJ
// LogEx.logDebug(TAG, "onConsentFormLoadFailure ${p0.message} ${p0.errorCode}")
// callback?.invoke(true)
// callback = null
// }
// })
// }
//}
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".business.pangle.PangleActivity">
<androidx.appcompat.widget.AppCompatButton
android:id="@+id/initSdk"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginVertical="@dimen/dp_3"
android:text="初始化" />
<androidx.appcompat.widget.AppCompatButton
android:id="@+id/showOpen"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginVertical="@dimen/dp_3"
android:text="展示开屏" />
</LinearLayout>
\ No newline at end of file
<com.google.android.gms.ads.nativead.NativeAdView xmlns:android="http://schemas.android.com/apk/res/android"
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/nativeAdView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:background="#f2f2f2"
android:baselineAligned="false">
<com.google.android.gms.ads.nativead.MediaView
android:id="@+id/ad_media"
android:layout_width="91dp"
android:layout_height="91dp"
android:layout_gravity="center_vertical"
android:layout_marginStart="5dp" />
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginHorizontal="8dp"
android:layout_weight="1"
android:orientation="vertical">
<TextView
android:id="@+id/ad_headline"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ellipsize="end"
android:maxLines="2"
android:textColor="@color/black"
android:textSize="14sp"
android:textStyle="bold" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:background="@color/colorPrimary"
android:padding="2dp"
android:text="Ad"
android:textColor="@color/white"
android:textSize="12sp"
tools:ignore="HardcodedText,TextContrastCheck" />
<TextView
android:id="@+id/ad_body"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginEnd="10dp"
android:ellipsize="end"
android:maxLines="2"
android:singleLine="true"
android:textColor="@color/black"
android:textSize="12sp" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingVertical="5dp">
<ImageView
android:id="@+id/ad_app_icon"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_gravity="center_vertical"
tools:ignore="ContentDescription" />
<androidx.appcompat.widget.AppCompatButton
android:id="@+id/ad_call_to_action"
android:layout_width="match_parent"
android:layout_height="26dp"
android:layout_gravity="center_vertical"
android:layout_marginHorizontal="12dp"
android:background="@drawable/bg_btn_ad"
android:gravity="center"
android:textColor="@color/white"
android:textSize="15sp"
tools:ignore="SpeakableTextPresentCheck,TouchTargetSizeCheck,VisualLintButtonSize" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
</com.google.android.gms.ads.nativead.NativeAdView>
\ No newline at end of file
<!-- <LinearLayout-->
<!-- android:layout_width="match_parent"-->
<!-- android:layout_height="wrap_content"-->
<!-- android:layout_gravity="center"-->
<!-- android:background="#f2f2f2"-->
<!-- android:baselineAligned="false">-->
<!-- <com.google.android.gms.ads.nativead.MediaView-->
<!-- android:id="@+id/ad_media"-->
<!-- android:layout_width="91dp"-->
<!-- android:layout_height="91dp"-->
<!-- android:layout_gravity="center_vertical"-->
<!-- android:layout_marginStart="5dp" />-->
<!-- <LinearLayout-->
<!-- android:layout_width="0dp"-->
<!-- android:layout_height="wrap_content"-->
<!-- android:layout_gravity="center_vertical"-->
<!-- android:layout_marginHorizontal="8dp"-->
<!-- android:layout_weight="1"-->
<!-- android:orientation="vertical">-->
<!-- <TextView-->
<!-- android:id="@+id/ad_headline"-->
<!-- android:layout_width="match_parent"-->
<!-- android:layout_height="wrap_content"-->
<!-- android:ellipsize="end"-->
<!-- android:maxLines="2"-->
<!-- android:textColor="@color/black"-->
<!-- android:textSize="14sp"-->
<!-- android:textStyle="bold" />-->
<!-- <LinearLayout-->
<!-- android:layout_width="match_parent"-->
<!-- android:layout_height="wrap_content"-->
<!-- android:gravity="center_vertical"-->
<!-- android:orientation="horizontal">-->
<!-- <TextView-->
<!-- android:layout_width="wrap_content"-->
<!-- android:layout_height="wrap_content"-->
<!-- android:layout_gravity="center_vertical"-->
<!-- android:background="@color/colorPrimary"-->
<!-- android:padding="2dp"-->
<!-- android:text="Ad"-->
<!-- android:textColor="@color/white"-->
<!-- android:textSize="12sp"-->
<!-- tools:ignore="HardcodedText,TextContrastCheck" />-->
<!-- <TextView-->
<!-- android:id="@+id/ad_body"-->
<!-- android:layout_width="match_parent"-->
<!-- android:layout_height="wrap_content"-->
<!-- android:layout_marginStart="8dp"-->
<!-- android:layout_marginEnd="10dp"-->
<!-- android:ellipsize="end"-->
<!-- android:maxLines="2"-->
<!-- android:singleLine="true"-->
<!-- android:textColor="@color/black"-->
<!-- android:textSize="12sp" />-->
<!-- </LinearLayout>-->
<!-- <LinearLayout-->
<!-- android:layout_width="match_parent"-->
<!-- android:layout_height="wrap_content"-->
<!-- android:paddingVertical="5dp">-->
<!-- <ImageView-->
<!-- android:id="@+id/ad_app_icon"-->
<!-- android:layout_width="30dp"-->
<!-- android:layout_height="30dp"-->
<!-- android:layout_gravity="center_vertical"-->
<!-- tools:ignore="ContentDescription" />-->
<!-- <androidx.appcompat.widget.AppCompatButton-->
<!-- android:id="@+id/ad_call_to_action"-->
<!-- android:layout_width="match_parent"-->
<!-- android:layout_height="26dp"-->
<!-- android:layout_gravity="center_vertical"-->
<!-- android:layout_marginHorizontal="12dp"-->
<!-- android:background="@drawable/bg_btn_ad"-->
<!-- android:gravity="center"-->
<!-- android:textColor="@color/white"-->
<!-- android:textSize="15sp"-->
<!-- tools:ignore="SpeakableTextPresentCheck,TouchTargetSizeCheck,VisualLintButtonSize" />-->
<!-- </LinearLayout>-->
<!-- </LinearLayout>-->
<!-- </LinearLayout>-->
</FrameLayout>
\ No newline at end of file
<com.google.android.gms.ads.nativead.NativeAdView xmlns:android="http://schemas.android.com/apk/res/android"
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/nativeAdView"
......@@ -7,89 +7,89 @@
android:layout_margin="10dp">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<!-- <androidx.constraintlayout.widget.ConstraintLayout-->
<!-- android:layout_width="match_parent"-->
<!-- android:layout_height="wrap_content">-->
<com.google.android.gms.ads.nativead.MediaView
android:id="@+id/ad_media"
android:layout_width="match_parent"
android:layout_height="@dimen/dp_138"
android:layout_gravity="center_vertical"
android:layout_marginStart="5dp"
app:layout_constraintTop_toTopOf="parent" />
<!-- <com.google.android.gms.ads.nativead.MediaView-->
<!-- android:id="@+id/ad_media"-->
<!-- android:layout_width="match_parent"-->
<!-- android:layout_height="@dimen/dp_138"-->
<!-- android:layout_gravity="center_vertical"-->
<!-- android:layout_marginStart="5dp"-->
<!-- app:layout_constraintTop_toTopOf="parent" />-->
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/bg_ad"
android:gravity="center"
android:paddingHorizontal="@dimen/dp_12"
android:paddingVertical="@dimen/dp_2"
android:text="AD"
android:textColor="@color/white"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:ignore="HardcodedText" />
<!-- <TextView-->
<!-- android:layout_width="wrap_content"-->
<!-- android:layout_height="wrap_content"-->
<!-- android:background="@drawable/bg_ad"-->
<!-- android:gravity="center"-->
<!-- android:paddingHorizontal="@dimen/dp_12"-->
<!-- android:paddingVertical="@dimen/dp_2"-->
<!-- android:text="AD"-->
<!-- android:textColor="@color/white"-->
<!-- app:layout_constraintStart_toStartOf="parent"-->
<!-- app:layout_constraintTop_toTopOf="parent"-->
<!-- tools:ignore="HardcodedText" />-->
<ImageView
android:id="@+id/ad_app_icon"
android:layout_width="@dimen/dp_42"
android:layout_height="@dimen/dp_42"
android:layout_gravity="center_vertical"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/ad_media"
tools:ignore="ContentDescription" />
<!-- <ImageView-->
<!-- android:id="@+id/ad_app_icon"-->
<!-- android:layout_width="@dimen/dp_42"-->
<!-- android:layout_height="@dimen/dp_42"-->
<!-- android:layout_gravity="center_vertical"-->
<!-- app:layout_constraintBottom_toBottomOf="parent"-->
<!-- app:layout_constraintStart_toStartOf="parent"-->
<!-- app:layout_constraintTop_toBottomOf="@id/ad_media"-->
<!-- tools:ignore="ContentDescription" />-->
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginHorizontal="@dimen/dp_6"
android:orientation="vertical"
app:layout_constraintBottom_toBottomOf="@id/ad_app_icon"
app:layout_constraintEnd_toStartOf="@+id/ad_call_to_action"
app:layout_constraintStart_toEndOf="@id/ad_app_icon"
app:layout_constraintTop_toTopOf="@id/ad_app_icon">
<!-- <LinearLayout-->
<!-- android:layout_width="0dp"-->
<!-- android:layout_height="wrap_content"-->
<!-- android:layout_marginHorizontal="@dimen/dp_6"-->
<!-- android:orientation="vertical"-->
<!-- app:layout_constraintBottom_toBottomOf="@id/ad_app_icon"-->
<!-- app:layout_constraintEnd_toStartOf="@+id/ad_call_to_action"-->
<!-- app:layout_constraintStart_toEndOf="@id/ad_app_icon"-->
<!-- app:layout_constraintTop_toTopOf="@id/ad_app_icon">-->
<TextView
android:id="@+id/ad_headline"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ellipsize="end"
android:maxLines="2"
android:textColor="@color/black"
android:textSize="14sp"
android:textStyle="bold" />
<!-- <TextView-->
<!-- android:id="@+id/ad_headline"-->
<!-- android:layout_width="match_parent"-->
<!-- android:layout_height="wrap_content"-->
<!-- android:ellipsize="end"-->
<!-- android:maxLines="2"-->
<!-- android:textColor="@color/black"-->
<!-- android:textSize="14sp"-->
<!-- android:textStyle="bold" />-->
<TextView
android:id="@+id/ad_body"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ellipsize="end"
android:maxLines="2"
android:singleLine="true"
android:textColor="@color/black"
android:textSize="12sp" />
<!-- <TextView-->
<!-- android:id="@+id/ad_body"-->
<!-- android:layout_width="match_parent"-->
<!-- android:layout_height="wrap_content"-->
<!-- android:ellipsize="end"-->
<!-- android:maxLines="2"-->
<!-- android:singleLine="true"-->
<!-- android:textColor="@color/black"-->
<!-- android:textSize="12sp" />-->
</LinearLayout>
<!-- </LinearLayout>-->
<androidx.appcompat.widget.AppCompatButton
android:id="@+id/ad_call_to_action"
android:layout_width="wrap_content"
android:layout_height="@dimen/dp_50"
android:layout_gravity="center_vertical"
android:background="@drawable/bg_btn_ad"
android:gravity="center"
android:textColor="@color/white"
android:textSize="15sp"
app:layout_constraintBottom_toBottomOf="@id/ad_app_icon"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="@id/ad_app_icon"
tools:ignore="SpeakableTextPresentCheck,TouchTargetSizeCheck,VisualLintButtonSize" />
<!-- <androidx.appcompat.widget.AppCompatButton-->
<!-- android:id="@+id/ad_call_to_action"-->
<!-- android:layout_width="wrap_content"-->
<!-- android:layout_height="@dimen/dp_50"-->
<!-- android:layout_gravity="center_vertical"-->
<!-- android:background="@drawable/bg_btn_ad"-->
<!-- android:gravity="center"-->
<!-- android:textColor="@color/white"-->
<!-- android:textSize="15sp"-->
<!-- app:layout_constraintBottom_toBottomOf="@id/ad_app_icon"-->
<!-- app:layout_constraintEnd_toEndOf="parent"-->
<!-- app:layout_constraintTop_toTopOf="@id/ad_app_icon"-->
<!-- tools:ignore="SpeakableTextPresentCheck,TouchTargetSizeCheck,VisualLintButtonSize" />-->
</androidx.constraintlayout.widget.ConstraintLayout>
<!-- </androidx.constraintlayout.widget.ConstraintLayout>-->
</com.google.android.gms.ads.nativead.NativeAdView>
\ No newline at end of file
</FrameLayout>
\ No newline at end of file
<com.google.android.gms.ads.nativead.NativeAdView xmlns:android="http://schemas.android.com/apk/res/android"
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:background="@color/white"
android:baselineAligned="false"
android:orientation="vertical">
<!-- <LinearLayout-->
<!-- android:layout_width="match_parent"-->
<!-- android:layout_height="match_parent"-->
<!-- android:layout_gravity="center"-->
<!-- android:background="@color/white"-->
<!-- android:baselineAligned="false"-->
<!-- android:orientation="vertical">-->
<com.google.android.gms.ads.nativead.MediaView
android:id="@+id/ad_media"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_gravity="center_horizontal"
android:layout_marginHorizontal="@dimen/dp_16"
android:layout_weight="1" />
<!-- <com.google.android.gms.ads.nativead.MediaView-->
<!-- android:id="@+id/ad_media"-->
<!-- android:layout_width="match_parent"-->
<!-- android:layout_height="0dp"-->
<!-- android:layout_gravity="center_horizontal"-->
<!-- android:layout_marginHorizontal="@dimen/dp_16"-->
<!-- android:layout_weight="1" />-->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginHorizontal="@dimen/dp_15"
android:gravity="center_vertical">
<!-- <LinearLayout-->
<!-- android:layout_width="match_parent"-->
<!-- android:layout_height="wrap_content"-->
<!-- android:layout_marginHorizontal="@dimen/dp_15"-->
<!-- android:gravity="center_vertical">-->
<ImageView
android:id="@+id/ad_app_icon"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_gravity="center_vertical"
tools:ignore="ContentDescription" />
<!-- <ImageView-->
<!-- android:id="@+id/ad_app_icon"-->
<!-- android:layout_width="30dp"-->
<!-- android:layout_height="30dp"-->
<!-- android:layout_gravity="center_vertical"-->
<!-- tools:ignore="ContentDescription" />-->
<TextView
android:id="@+id/ad_headline"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginHorizontal="@dimen/dp_2"
android:layout_weight="1"
android:ellipsize="end"
android:maxLines="2"
android:textColor="@color/black"
android:textSize="@dimen/sp_16"
android:textStyle="bold"
tools:text="Ad Headline" />
<!-- <TextView-->
<!-- android:id="@+id/ad_headline"-->
<!-- android:layout_width="0dp"-->
<!-- android:layout_height="wrap_content"-->
<!-- android:layout_marginHorizontal="@dimen/dp_2"-->
<!-- android:layout_weight="1"-->
<!-- android:ellipsize="end"-->
<!-- android:maxLines="2"-->
<!-- android:textColor="@color/black"-->
<!-- android:textSize="@dimen/sp_16"-->
<!-- android:textStyle="bold"-->
<!-- tools:text="Ad Headline" />-->
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:background="@color/colorPrimary"
android:padding="2dp"
android:text="Ad"
android:textColor="@color/white"
android:textSize="12sp"
tools:ignore="HardcodedText,TextContrastCheck" />
</LinearLayout>
<!-- <TextView-->
<!-- android:layout_width="wrap_content"-->
<!-- android:layout_height="wrap_content"-->
<!-- android:layout_gravity="center_vertical"-->
<!-- android:background="@color/colorPrimary"-->
<!-- android:padding="2dp"-->
<!-- android:text="Ad"-->
<!-- android:textColor="@color/white"-->
<!-- android:textSize="12sp"-->
<!-- tools:ignore="HardcodedText,TextContrastCheck" />-->
<!-- </LinearLayout>-->
<TextView
android:id="@+id/ad_body"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginHorizontal="@dimen/dp_15"
android:ellipsize="end"
android:maxLines="2"
android:textColor="#808080"
android:textSize="@dimen/sp_12"
tools:text="Earn more from your apps. Get started and sign up for AdMob today." />
<!-- <TextView-->
<!-- android:id="@+id/ad_body"-->
<!-- android:layout_width="match_parent"-->
<!-- android:layout_height="wrap_content"-->
<!-- android:layout_marginHorizontal="@dimen/dp_15"-->
<!-- android:ellipsize="end"-->
<!-- android:maxLines="2"-->
<!-- android:textColor="#808080"-->
<!-- android:textSize="@dimen/sp_12"-->
<!-- tools:text="Earn more from your apps. Get started and sign up for AdMob today." />-->
<androidx.appcompat.widget.AppCompatButton
android:id="@+id/ad_call_to_action"
android:layout_width="match_parent"
android:layout_height="@dimen/dp_40"
android:layout_gravity="center_vertical"
android:layout_marginHorizontal="@dimen/dp_15"
android:layout_marginTop="@dimen/dp_8"
android:layout_marginBottom="@dimen/dp_20"
android:background="@drawable/bg_btn_ad"
android:gravity="center"
android:textColor="@color/white"
android:textSize="15sp"
tools:ignore="SpeakableTextPresentCheck,TouchTargetSizeCheck" />
<!-- <androidx.appcompat.widget.AppCompatButton-->
<!-- android:id="@+id/ad_call_to_action"-->
<!-- android:layout_width="match_parent"-->
<!-- android:layout_height="@dimen/dp_40"-->
<!-- android:layout_gravity="center_vertical"-->
<!-- android:layout_marginHorizontal="@dimen/dp_15"-->
<!-- android:layout_marginTop="@dimen/dp_8"-->
<!-- android:layout_marginBottom="@dimen/dp_20"-->
<!-- android:background="@drawable/bg_btn_ad"-->
<!-- android:gravity="center"-->
<!-- android:textColor="@color/white"-->
<!-- android:textSize="15sp"-->
<!-- tools:ignore="SpeakableTextPresentCheck,TouchTargetSizeCheck" />-->
</LinearLayout>
<!-- </LinearLayout>-->
</com.google.android.gms.ads.nativead.NativeAdView>
\ No newline at end of file
</FrameLayout>
\ No newline at end of file
......@@ -104,7 +104,6 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:backgroundTint="@color/applovin_sdk_brand_color"
android:textColor="@android:color/white"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toBottomOf="@+id/media_view_container"
......
......@@ -24,11 +24,12 @@ dependencyResolutionManagement {
google()
mavenCentral()
maven("https://artifact.bytedance.com/repository/pangle")
maven("https://s01.oss.sonatype.org/content/groups/public")
maven("https://jitpack.io")
maven("https://android-sdk.is.com")
maven("https://dl-maven-android.mintegral.com/repository/mbridge_android_sdk_oversea")
maven("https://artifact.bytedance.com/repository/pangle")
maven("https://dl-maven-android.mintegral.com/repository/se_sdk_for_android/")
// 添加国内插件镜像
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment