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