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
d630076a
Commit
d630076a
authored
Feb 28, 2025
by
wanglei
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
...模块化
parent
3690bb45
Show whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
131 additions
and
18 deletions
+131
-18
BatteryInfoActivity.kt
...src/main/java/com/koko/batteryinfo/BatteryInfoActivity.kt
+9
-1
activity_battery_info.xml
BatteryInfo/src/main/res/layout/activity_battery_info.xml
+2
-3
build.gradle.kts
Router/build.gradle.kts
+2
-0
NativeService.kt
Router/src/main/java/com/koko/router/ad/NativeService.kt
+11
-0
build.gradle.kts
app/build.gradle.kts
+1
-0
MyApplication.kt
app/src/main/java/com/base/appzxhy/MyApplication.kt
+4
-0
AdsMgr.kt
app/src/main/java/com/base/appzxhy/ads/AdsMgr.kt
+13
-5
AdNativeMgr.kt
app/src/main/java/com/base/appzxhy/ads/admob/AdNativeMgr.kt
+57
-8
NativeServiceImp.kt
...main/java/com/base/appzxhy/drouterimp/NativeServiceImp.kt
+27
-0
layout_admob_native_custom.xml
app/src/main/res/layout/layout_admob_native_custom.xml
+1
-0
libs.versions.toml
gradle/libs.versions.toml
+4
-1
No files found.
BatteryInfo/src/main/java/com/koko/batteryinfo/BatteryInfoActivity.kt
View file @
d630076a
...
@@ -11,7 +11,10 @@ import androidx.activity.addCallback
...
@@ -11,7 +11,10 @@ import androidx.activity.addCallback
import
androidx.activity.enableEdgeToEdge
import
androidx.activity.enableEdgeToEdge
import
androidx.core.view.ViewCompat
import
androidx.core.view.ViewCompat
import
androidx.core.view.WindowInsetsCompat
import
androidx.core.view.WindowInsetsCompat
import
com.didi.drouter.api.DRouter
import
com.koko.batteryinfo.databinding.ActivityBatteryInfoBinding
import
com.koko.batteryinfo.databinding.ActivityBatteryInfoBinding
import
com.koko.router.ad.NativeBatteryType
import
com.koko.router.ad.NativeService
import
java.math.BigDecimal
import
java.math.BigDecimal
import
java.math.RoundingMode
import
java.math.RoundingMode
...
@@ -29,7 +32,7 @@ class BatteryInfoActivity : BaseActivity<ActivityBatteryInfoBinding>() {
...
@@ -29,7 +32,7 @@ class BatteryInfoActivity : BaseActivity<ActivityBatteryInfoBinding>() {
useDefaultImmersive
()
useDefaultImmersive
()
initView
()
initView
()
// AdmobNativeUtils.showNativeAd(this, binding.flAdNative, R.layout.layout_admob_document_in
)
showNative
(
)
// if (AdmobHelper.isShowOpenDocumentInter()) {
// if (AdmobHelper.isShowOpenDocumentInter()) {
// AdmobInterstitialUtils.showInterstitialAd(this) {
// AdmobInterstitialUtils.showInterstitialAd(this) {
...
@@ -41,6 +44,11 @@ class BatteryInfoActivity : BaseActivity<ActivityBatteryInfoBinding>() {
...
@@ -41,6 +44,11 @@ class BatteryInfoActivity : BaseActivity<ActivityBatteryInfoBinding>() {
}
}
private
fun
showNative
()
{
val
nativeService
=
DRouter
.
build
(
NativeService
::
class
.
java
).
getService
()
nativeService
.
showNative
(
this
,
binding
.
flAd
,
NativeBatteryType
)
}
override
fun
initView
()
{
override
fun
initView
()
{
registerReceiver
()
registerReceiver
()
onBackPressedDispatcher
.
addCallback
{
onBackPressedDispatcher
.
addCallback
{
...
...
BatteryInfo/src/main/res/layout/activity_battery_info.xml
View file @
d630076a
...
@@ -283,12 +283,11 @@
...
@@ -283,12 +283,11 @@
<FrameLayout
<FrameLayout
android:id=
"@+id/fl
_ad_native
"
android:id=
"@+id/fl
Ad
"
android:layout_width=
"match_parent"
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
android:layout_height=
"wrap_content"
android:layout_marginHorizontal=
"15dp"
android:layout_marginHorizontal=
"15dp"
android:layout_marginTop=
"10dp"
android:layout_marginTop=
"10dp"
android:visibility=
"gone"
app:layout_constraintTop_toBottomOf=
"@id/ll_battery_status"
>
app:layout_constraintTop_toBottomOf=
"@id/ll_battery_status"
>
<ImageView
<ImageView
...
@@ -305,7 +304,7 @@
...
@@ -305,7 +304,7 @@
android:layout_marginTop=
"11dp"
android:layout_marginTop=
"11dp"
android:layout_marginEnd=
"15dp"
android:layout_marginEnd=
"15dp"
android:orientation=
"vertical"
android:orientation=
"vertical"
app:layout_constraintTop_toBottomOf=
"@id/fl
_ad_native
"
>
app:layout_constraintTop_toBottomOf=
"@id/fl
Ad
"
>
<LinearLayout
<LinearLayout
android:id=
"@+id/llTime"
android:id=
"@+id/llTime"
...
...
Router/build.gradle.kts
View file @
d630076a
...
@@ -39,4 +39,6 @@ dependencies {
...
@@ -39,4 +39,6 @@ dependencies {
androidTestImplementation
(
libs
.
androidx
.
espresso
.
core
)
androidTestImplementation
(
libs
.
androidx
.
espresso
.
core
)
api
(
libs
.
drouter
.
api
)
api
(
libs
.
drouter
.
api
)
api
(
libs
.
drouter
.
api
.
page
)
api
(
libs
.
drouter
.
api
.
process
)
}
}
\ No newline at end of file
Router/src/main/java/com/koko/router/ad/NativeService.kt
0 → 100644
View file @
d630076a
package
com.koko.router.ad
import
android.app.Activity
import
android.widget.FrameLayout
const
val
NativeBatteryType
:
String
=
"NativeBatteryType"
interface
NativeService
{
fun
showNative
(
activity
:
Activity
,
flAd
:
FrameLayout
,
nativeType
:
String
)
}
\ No newline at end of file
app/build.gradle.kts
View file @
d630076a
...
@@ -6,6 +6,7 @@ plugins {
...
@@ -6,6 +6,7 @@ plugins {
alias
(
libs
.
plugins
.
kotlin
.
android
)
alias
(
libs
.
plugins
.
kotlin
.
android
)
id
(
"com.google.gms.google-services"
)
id
(
"com.google.gms.google-services"
)
id
(
"com.google.firebase.crashlytics"
)
id
(
"com.google.firebase.crashlytics"
)
id
(
"com.didi.drouter"
)
}
}
android
{
android
{
...
...
app/src/main/java/com/base/appzxhy/MyApplication.kt
View file @
d630076a
...
@@ -30,6 +30,7 @@ import com.base.appzxhy.utils.AppPreferences
...
@@ -30,6 +30,7 @@ import com.base.appzxhy.utils.AppPreferences
import
com.base.appzxhy.utils.LogEx
import
com.base.appzxhy.utils.LogEx
import
com.base.appzxhy.utils.SolarEngineUtils.initSolarEngine
import
com.base.appzxhy.utils.SolarEngineUtils.initSolarEngine
import
com.base.appzxhy.utils.SolarEngineUtils.solarkey
import
com.base.appzxhy.utils.SolarEngineUtils.solarkey
import
com.didi.drouter.api.DRouter
import
com.facebook.FacebookSdk
import
com.facebook.FacebookSdk
import
com.google.android.gms.ads.identifier.AdvertisingIdClient
import
com.google.android.gms.ads.identifier.AdvertisingIdClient
import
com.google.gson.Gson
import
com.google.gson.Gson
...
@@ -67,6 +68,9 @@ class MyApplication : Application() {
...
@@ -67,6 +68,9 @@ class MyApplication : Application() {
override
fun
onCreate
()
{
override
fun
onCreate
()
{
super
.
onCreate
()
super
.
onCreate
()
appContext
=
this
appContext
=
this
DRouter
.
init
(
this
)
initUUid
()
initUUid
()
initGid
()
initGid
()
initApp
()
initApp
()
...
...
app/src/main/java/com/base/appzxhy/ads/AdsMgr.kt
View file @
d630076a
...
@@ -2,7 +2,9 @@ package com.base.appzxhy.ads
...
@@ -2,7 +2,9 @@ package com.base.appzxhy.ads
import
android.app.Activity
import
android.app.Activity
import
android.content.Context
import
android.content.Context
import
android.view.LayoutInflater
import
android.view.ViewGroup
import
android.view.ViewGroup
import
android.widget.FrameLayout
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
...
@@ -27,6 +29,7 @@ import com.base.appzxhy.utils.ToastUtils.toast
...
@@ -27,6 +29,7 @@ import com.base.appzxhy.utils.ToastUtils.toast
import
com.google.android.gms.ads.MobileAds
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
com.google.android.gms.ads.nativead.NativeAdView
import
java.util.Collections
import
java.util.Collections
import
java.util.concurrent.Executors
import
java.util.concurrent.Executors
...
@@ -212,11 +215,12 @@ object AdsMgr {
...
@@ -212,11 +215,12 @@ object AdsMgr {
/**
/**
* 展示原生广告
* 展示原生广告
*
*
* @param
nativeView 需要展示
广告的布局容器
* @param
parent 需要展示原生
广告的布局容器
* @param layout
原生广告布局 ,这里传入的layout要和com.example.mydemo.strategy.ads.admob.NativeView里的id一致
* @param layout
Admob原生根布局必须为 NativeAdView
*/
*/
fun
showNative
(
fun
showNative
(
nativeView
:
NativeParentView
,
activity
:
Activity
,
parent
:
FrameLayout
,
@LayoutRes
layout
:
Int
,
@LayoutRes
layout
:
Int
,
nativeCallBack
:
((
Any
?)
->
Unit
)?
=
null
nativeCallBack
:
((
Any
?)
->
Unit
)?
=
null
)
{
)
{
...
@@ -227,11 +231,15 @@ object AdsMgr {
...
@@ -227,11 +231,15 @@ object AdsMgr {
if
(!
isAdmobInit
)
return
if
(!
isAdmobInit
)
return
val
from
=
activity
::
class
.
java
.
simpleName
if
(
adsConfigBean
.
adSwitch
)
{
if
(
adsConfigBean
.
adSwitch
)
{
adNativeMgr
.
show
(
AdmobEvent
(
"nativeAd"
,
"nativeAd"
),
nativeView
,
layout
,
nativeCallBack
)
val
nativeView
=
LayoutInflater
.
from
(
parent
.
context
).
inflate
(
layout
,
parent
,
false
)
as
NativeAdView
adNativeMgr
.
show
(
AdmobEvent
(
"nativeAd"
,
from
),
parent
,
nativeView
,
nativeCallBack
)
}
else
{
}
else
{
maxNativeMgr
.
show
(
AdMaxEvent
(
"nativeAd"
,
"nativeAd"
),
nativeView
,
layout
,
nativeCallBack
)
// maxNativeMgr.show(AdMaxEvent("nativeAd", "nativeAd"), nativeParent
, layout, nativeCallBack)
}
}
}
}
...
...
app/src/main/java/com/base/appzxhy/ads/admob/AdNativeMgr.kt
View file @
d630076a
package
com.base.appzxhy.ads.admob
package
com.base.appzxhy.ads.admob
import
android.view.LayoutInflater
import
android.view.View
import
android.widget.Button
import
android.widget.FrameLayout
import
android.widget.ImageView
import
android.widget.TextView
import
androidx.core.view.isVisible
import
com.base.appzxhy.GlobalConfig
import
com.base.appzxhy.GlobalConfig
import
com.base.appzxhy.R
import
com.base.appzxhy.ads.AdsType
import
com.base.appzxhy.ads.AdsType
import
com.base.appzxhy.ads.LimitUtils
import
com.base.appzxhy.ads.LimitUtils
import
com.base.appzxhy.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
com.google.android.gms.ads.nativead.NativeAdView
import
java.util.concurrent.ConcurrentLinkedDeque
import
java.util.concurrent.ConcurrentLinkedDeque
/**
/**
...
@@ -29,8 +37,8 @@ class AdNativeMgr {
...
@@ -29,8 +37,8 @@ class AdNativeMgr {
private
fun
loadAd
(
private
fun
loadAd
(
admobEvent
:
AdmobEvent
,
admobEvent
:
AdmobEvent
,
parent
:
NativeParentView
,
parent
:
FrameLayout
,
layout
:
Int
nativeAdView
:
NativeAdView
)
{
)
{
admobEvent
.
adPulStart
()
admobEvent
.
adPulStart
()
...
@@ -47,7 +55,7 @@ class AdNativeMgr {
...
@@ -47,7 +55,7 @@ class AdNativeMgr {
nativeAd
.
setOnPaidEventListener
(
AdmobEvent
.
EventOnPaidEventListener
(
nativeAd
))
nativeAd
.
setOnPaidEventListener
(
AdmobEvent
.
EventOnPaidEventListener
(
nativeAd
))
admobEvent
.
pullAd
(
nativeAd
.
responseInfo
)
admobEvent
.
pullAd
(
nativeAd
.
responseInfo
)
show
(
admobEvent
,
parent
,
layout
)
show
(
admobEvent
,
parent
,
nativeAdView
)
}.
withAdListener
(
object
:
AdListener
()
{
}.
withAdListener
(
object
:
AdListener
()
{
...
@@ -72,8 +80,8 @@ class AdNativeMgr {
...
@@ -72,8 +80,8 @@ class AdNativeMgr {
fun
show
(
fun
show
(
admobEvent
:
AdmobEvent
,
admobEvent
:
AdmobEvent
,
parent
:
NativeParentView
,
nativeParent
:
FrameLayout
,
layout
:
Int
,
nativeAdView
:
NativeAdView
,
nativeCallBack
:
((
Any
?)
->
Unit
)?
=
null
nativeCallBack
:
((
Any
?)
->
Unit
)?
=
null
)
{
)
{
...
@@ -88,16 +96,57 @@ class AdNativeMgr {
...
@@ -88,16 +96,57 @@ class AdNativeMgr {
if
(
nativeAd
==
null
||
!
adAvailable
())
{
if
(
nativeAd
==
null
||
!
adAvailable
())
{
//缓存过期了就清空
//缓存过期了就清空
cacheItems
.
clear
()
cacheItems
.
clear
()
loadAd
(
admobEvent
,
parent
,
layout
)
loadAd
(
admobEvent
,
nativeParent
,
nativeAdView
)
return
return
}
}
nativeCallBack
?.
invoke
(
nativeAd
)
nativeCallBack
?.
invoke
(
nativeAd
)
parent
.
setNativeAd
(
nativeAd
,
layout
)
//添加原生到父布局
nativeParent
.
removeAllViews
()
nativeAdView
.
bindNativeAd
(
nativeAd
)
nativeParent
.
addView
(
nativeAdView
)
nativeParent
.
isVisible
=
true
admobEvent
.
showAd
(
nativeAd
.
responseInfo
)
admobEvent
.
showAd
(
nativeAd
.
responseInfo
)
}
}
private
fun
NativeAdView
.
bindNativeAd
(
nativeAd
:
NativeAd
?)
{
nativeAd
?:
return
mediaView
=
findViewById
(
R
.
id
.
ad_media
)
headlineView
=
findViewById
(
R
.
id
.
ad_headline
)
bodyView
=
findViewById
(
R
.
id
.
ad_body
)
callToActionView
=
findViewById
(
R
.
id
.
ad_call_to_action
)
iconView
=
findViewById
(
R
.
id
.
ad_app_icon
)
(
headlineView
as
TextView
?)
?.
text
=
nativeAd
.
headline
mediaView
?.
mediaContent
=
nativeAd
.
mediaContent
if
(
nativeAd
.
body
==
null
)
{
bodyView
?.
visibility
=
View
.
INVISIBLE
}
else
{
bodyView
?.
visibility
=
View
.
VISIBLE
(
bodyView
as
TextView
?)
?.
text
=
nativeAd
.
body
}
if
(
nativeAd
.
callToAction
==
null
)
{
callToActionView
?.
visibility
=
View
.
INVISIBLE
}
else
{
callToActionView
?.
visibility
=
View
.
VISIBLE
(
callToActionView
as
Button
?)
?.
text
=
nativeAd
.
callToAction
}
if
(
nativeAd
.
icon
==
null
)
{
iconView
?.
visibility
=
View
.
GONE
}
else
{
(
iconView
as
ImageView
?)
?.
setImageDrawable
(
nativeAd
.
icon
?.
drawable
)
iconView
?.
visibility
=
View
.
VISIBLE
}
setNativeAd
(
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
app/src/main/java/com/base/appzxhy/drouterimp/NativeServiceImp.kt
0 → 100644
View file @
d630076a
package
com.base.appzxhy.drouterimp
import
android.app.Activity
import
android.widget.FrameLayout
import
com.base.appzxhy.R
import
com.base.appzxhy.ads.AdsMgr
import
com.base.appzxhy.utils.LogEx
import
com.didi.drouter.annotation.Service
import
com.koko.router.ad.NativeBatteryType
import
com.koko.router.ad.NativeService
@Service
(
function
=
[
NativeService
::
class
])
class
NativeServiceImp
:
NativeService
{
private
val
TAG
=
"NativeServiceImp"
override
fun
showNative
(
activity
:
Activity
,
flAd
:
FrameLayout
,
nativeType
:
String
)
{
LogEx
.
logDebug
(
TAG
,
"activity=${activity::class.java.simpleName}"
)
val
layout
=
when
(
nativeType
)
{
NativeBatteryType
->
R
.
layout
.
layout_admob_native_custom
else
->
R
.
layout
.
layout_admob_native_custom
}
AdsMgr
.
showNative
(
activity
,
flAd
,
layout
)
}
}
\ No newline at end of file
app/src/main/res/layout/layout_admob_native_custom.xml
View file @
d630076a
<com.google.android.gms.ads.nativead.NativeAdView
xmlns:android=
"http://schemas.android.com/apk/res/android"
<com.google.android.gms.ads.nativead.NativeAdView
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: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"
>
...
...
gradle/libs.versions.toml
View file @
d630076a
...
@@ -22,7 +22,8 @@ pangle = "6.3.0.4.0"
...
@@ -22,7 +22,8 @@ pangle = "6.3.0.4.0"
drouterApi
=
"2.4.6"
drouterApi
=
"2.4.6"
drouterPlugin
=
"1.4.0"
drouterPlugin
=
"1.4.0"
drouterApiPage
=
"1.0.0"
drouterApiProcess
=
"1.0.0"
[libraries]
[libraries]
...
@@ -55,6 +56,8 @@ applovin_pangle = { group = "com.applovin.mediation", name = "bytedance-adapter"
...
@@ -55,6 +56,8 @@ applovin_pangle = { group = "com.applovin.mediation", name = "bytedance-adapter"
drouter-api
=
{
module
=
"io.github.didi:drouter-api"
,
version.ref
=
"drouterApi"
}
drouter-api
=
{
module
=
"io.github.didi:drouter-api"
,
version.ref
=
"drouterApi"
}
drouter-plugin
=
{
module
=
"io.github.didi:drouter-plugin"
,
version.ref
=
"drouterPlugin"
}
drouter-plugin
=
{
module
=
"io.github.didi:drouter-plugin"
,
version.ref
=
"drouterPlugin"
}
drouter-api-page
=
{
module
=
"io.github.didi:drouter-api-page"
,
version.ref
=
"drouterApiPage"
}
drouter-api-process
=
{
module
=
"io.github.didi:drouter-api-process"
,
version.ref
=
"drouterApiProcess"
}
...
...
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