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,
......
......@@ -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.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.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.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
......@@ -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"
......
This diff is collapsed.
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