Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Sign in / Register
Toggle navigation
F
Fast File Manager Pro
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
Fast File Manager Pro
Commits
2bf975b2
Commit
2bf975b2
authored
Mar 27, 2024
by
wanglei
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
启动页接大屏广告
parent
3e8083ab
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
333 additions
and
6 deletions
+333
-6
build.gradle.kts
app/build.gradle.kts
+3
-0
AndroidManifest.xml
app/src/main/AndroidManifest.xml
+9
-0
KokoLaunchActivity.kt
...in/java/com/zxhy/fastfilemanagerpro/KokoLaunchActivity.kt
+56
-6
MainActivity.kt
...src/main/java/com/zxhy/fastfilemanagerpro/MainActivity.kt
+6
-0
MyApplication.kt
...rc/main/java/com/zxhy/fastfilemanagerpro/MyApplication.kt
+61
-0
GoogleMobileAdsConsentManager.kt
...stfilemanagerpro/kokoads/GoogleMobileAdsConsentManager.kt
+61
-0
KokoOpenAdManager.kt
.../com/zxhy/fastfilemanagerpro/kokoads/KokoOpenAdManager.kt
+133
-0
libs.versions.toml
gradle/libs.versions.toml
+4
-0
No files found.
app/build.gradle.kts
View file @
2bf975b2
...
...
@@ -80,4 +80,7 @@ dependencies {
implementation
(
libs
.
androidx
.
navigation
.
fragment
.
ktx
)
implementation
(
libs
.
androidx
.
navigation
.
ui
.
ktx
)
implementation
(
libs
.
glide
)
//广告
implementation
(
libs
.
google
.
android
.
playServicesAds
)
}
\ No newline at end of file
app/src/main/AndroidManifest.xml
View file @
2bf975b2
...
...
@@ -2,6 +2,7 @@
<manifest
xmlns:android=
"http://schemas.android.com/apk/res/android"
xmlns:tools=
"http://schemas.android.com/tools"
>
<uses-permission
android:name=
"android.permission.INTERNET"
/>
<uses-permission
android:name=
"android.permission.READ_EXTERNAL_STORAGE"
/>
<uses-permission
android:name=
"android.permission.WRITE_EXTERNAL_STORAGE"
/>
<uses-permission
...
...
@@ -9,6 +10,7 @@
tools:ignore=
"ScopedStorage"
/>
<application
android:name=
".MyApplication"
android:allowBackup=
"true"
android:dataExtractionRules=
"@xml/data_extraction_rules"
android:fullBackupContent=
"@xml/backup_rules"
...
...
@@ -20,6 +22,13 @@
android:supportsRtl=
"true"
android:theme=
"@style/Theme.FastFileManagerPro"
tools:targetApi=
"31"
>
<!-- Sample AdMob App ID: ca-app-pub-3940256099942544~3347511713 -->
<meta-data
android:name=
"com.google.android.gms.ads.APPLICATION_ID"
android:value=
"ca-app-pub-3940256099942544~3347511713"
/>
<activity
android:name=
".kokoInternalstorage.KoInternalkoActivity"
android:exported=
"false"
...
...
app/src/main/java/com/zxhy/fastfilemanagerpro/KokoLaunchActivity.kt
View file @
2bf975b2
...
...
@@ -8,14 +8,20 @@ import androidx.appcompat.app.AppCompatActivity
import
androidx.core.view.ViewCompat
import
androidx.core.view.WindowInsetsCompat
import
androidx.lifecycle.lifecycleScope
import
com.google.android.gms.ads.MobileAds
import
com.zxhy.fastfilemanagerpro.databinding.ActivityKokoLaunchBinding
import
com.zxhy.fastfilemanagerpro.kokoads.GoogleMobileAdsConsentManager
import
kotlinx.coroutines.Dispatchers
import
kotlinx.coroutines.delay
import
kotlinx.coroutines.launch
import
java.util.concurrent.atomic.AtomicBoolean
@SuppressLint
(
"CustomSplashScreen"
)
class
KokoLaunchActivity
:
AppCompatActivity
()
{
private
lateinit
var
binding
:
ActivityKokoLaunchBinding
private
val
isAdsInitializeCalled
=
AtomicBoolean
(
false
)
private
lateinit
var
googleMobileAdsConsentManager
:
GoogleMobileAdsConsentManager
override
fun
onCreate
(
savedInstanceState
:
Bundle
?)
{
super
.
onCreate
(
savedInstanceState
)
...
...
@@ -28,13 +34,57 @@ class KokoLaunchActivity : AppCompatActivity() {
insets
}
lifecycleScope
.
launch
(
Dispatchers
.
Main
)
{
while
(
binding
.
ProgressBar
.
progress
!=
100
)
{
binding
.
ProgressBar
.
progress
+=
2
delay
(
50
)
(
application
as
MyApplication
).
kokoOpenAdManager
.
adShowComplete
=
{
showed
->
if
(
showed
)
{
startActivity
(
Intent
(
this
@KokoLaunchActivity
,
MainActivity
::
class
.
java
))
finish
()
}
else
{
lifecycleScope
.
launch
(
Dispatchers
.
Main
)
{
while
(
binding
.
ProgressBar
.
progress
!=
100
)
{
binding
.
ProgressBar
.
progress
+=
2
delay
(
50
)
}
startActivity
(
Intent
(
this
@KokoLaunchActivity
,
MainActivity
::
class
.
java
))
finish
()
}
}
}
setDebugAdsConsent
()
(
application
as
MyApplication
).
kokoOpenAdManager
.
showAdIfAvailable
(
this
)
}
/**
* 设置Debug广告同意
*/
private
fun
setDebugAdsConsent
()
{
googleMobileAdsConsentManager
=
GoogleMobileAdsConsentManager
.
getInstance
(
applicationContext
)
//获取广告同意设置
googleMobileAdsConsentManager
.
gatherConsent
(
this
)
{
consentError
->
if
(
consentError
!=
null
)
{
}
if
(
googleMobileAdsConsentManager
.
canRequestAds
)
{
initializeMobileAdsSdk
()
}
startActivity
(
Intent
(
this
@KokoLaunchActivity
,
MainActivity
::
class
.
java
))
finish
()
}
if
(
googleMobileAdsConsentManager
.
canRequestAds
)
{
initializeMobileAdsSdk
()
}
}
private
fun
initializeMobileAdsSdk
()
{
if
(
isAdsInitializeCalled
.
getAndSet
(
true
))
{
return
}
MobileAds
.
initialize
(
this
)
{}
(
application
as
MyApplication
).
loadAd
(
this
)
}
}
\ No newline at end of file
app/src/main/java/com/zxhy/fastfilemanagerpro/MainActivity.kt
View file @
2bf975b2
package
com.zxhy.fastfilemanagerpro
import
android.content.Intent
import
android.os.Bundle
import
android.view.MenuItem
import
android.view.View
...
...
@@ -93,6 +94,11 @@ class MainActivity : AppCompatActivity() {
}
}
override
fun
onRestart
()
{
super
.
onRestart
()
startActivity
(
Intent
(
this
,
KokoLaunchActivity
::
class
.
java
))
}
fun
setSystemBarColor
(
@ColorRes
colorRes
:
Int
)
{
// color_b3000000 权限窗口颜色
window
.
statusBarColor
=
ContextCompat
.
getColor
(
this
,
colorRes
)
...
...
app/src/main/java/com/zxhy/fastfilemanagerpro/MyApplication.kt
0 → 100644
View file @
2bf975b2
package
com.zxhy.fastfilemanagerpro
import
android.app.Activity
import
android.app.Application
import
android.app.LauncherActivity
import
android.content.Context
import
android.os.Bundle
import
android.util.Log
import
com.zxhy.fastfilemanagerpro.kokoads.KokoOpenAdManager
@Suppress
(
"NAME_SHADOWING"
)
class
MyApplication
:
Application
(),
Application
.
ActivityLifecycleCallbacks
{
private
val
TAG
=
"MyApplication"
//开屏广告
lateinit
var
kokoOpenAdManager
:
KokoOpenAdManager
private
var
currentActivity
:
Activity
?
=
null
override
fun
onCreate
()
{
super
.
onCreate
()
ApplicationContext
=
this
registerActivityLifecycleCallbacks
(
this
)
initAdManager
()
}
companion
object
{
lateinit
var
ApplicationContext
:
Context
}
//region admob广告
fun
initAdManager
()
{
kokoOpenAdManager
=
KokoOpenAdManager
()
}
fun
loadAd
(
activity
:
Activity
)
{
kokoOpenAdManager
.
loadAd
(
activity
)
}
//endregion
//region Activity生命周期回调
override
fun
onActivityCreated
(
activity
:
Activity
,
savedInstanceState
:
Bundle
?)
=
Unit
override
fun
onActivityStarted
(
activity
:
Activity
)
{
// currentActivity = activity
// Log.e(TAG, "$currentActivity")
// currentActivity?.let { activity ->
// if (activity::class.java.name == KokoLaunchActivity::class.java.name) {
// kokoOpenAdManager.showAdIfAvailable(activity)
// }
// }
}
override
fun
onActivityResumed
(
activity
:
Activity
)
=
Unit
override
fun
onActivityPaused
(
activity
:
Activity
)
=
Unit
override
fun
onActivityStopped
(
activity
:
Activity
)
=
Unit
override
fun
onActivitySaveInstanceState
(
activity
:
Activity
,
outState
:
Bundle
)
=
Unit
override
fun
onActivityDestroyed
(
activity
:
Activity
)
=
Unit
//endregion
}
\ No newline at end of file
app/src/main/java/com/zxhy/fastfilemanagerpro/kokoads/GoogleMobileAdsConsentManager.kt
0 → 100644
View file @
2bf975b2
package
com.zxhy.fastfilemanagerpro.kokoads
import
android.app.Activity
import
android.content.Context
import
com.google.android.ump.ConsentDebugSettings
import
com.google.android.ump.ConsentInformation
import
com.google.android.ump.ConsentRequestParameters
import
com.google.android.ump.FormError
import
com.google.android.ump.UserMessagingPlatform
/**
* 广告同意管理
*/
class
GoogleMobileAdsConsentManager
private
constructor
(
context
:
Context
)
{
//同意信息
private
val
consentInformation
:
ConsentInformation
=
UserMessagingPlatform
.
getConsentInformation
(
context
)
//是否可请求广告
val
canRequestAds
:
Boolean
get
()
=
consentInformation
.
canRequestAds
()
/**
* UMP SDK 获取同意信息可用于展示
*/
fun
gatherConsent
(
activity
:
Activity
,
consentGatheringComplete
:
(
formError
:
FormError
?)
->
Unit
)
{
val
debugSettings
=
ConsentDebugSettings
.
Builder
(
activity
)
.
addTestDeviceHashedId
(
"TEST-DEVICE-HASHED-ID"
)
.
build
()
val
params
=
ConsentRequestParameters
.
Builder
().
setConsentDebugSettings
(
debugSettings
).
build
()
consentInformation
.
requestConsentInfoUpdate
(
activity
,
params
,
{
//同意信息上传成功回调
UserMessagingPlatform
.
loadAndShowConsentFormIfRequired
(
activity
)
{
formError
->
consentGatheringComplete
.
invoke
(
formError
)
}
},
//同意信息上传失败回调
{
requestConsentError
->
consentGatheringComplete
.
invoke
(
requestConsentError
)
}
)
}
companion
object
{
@Volatile
private
var
instance
:
GoogleMobileAdsConsentManager
?
=
null
fun
getInstance
(
context
:
Context
)
=
instance
?:
synchronized
(
this
)
{
instance
?:
GoogleMobileAdsConsentManager
(
context
).
also
{
instance
=
it
}
}
}
}
\ No newline at end of file
app/src/main/java/com/zxhy/fastfilemanagerpro/kokoads/KokoOpenAdManager.kt
0 → 100644
View file @
2bf975b2
package
com.zxhy.fastfilemanagerpro.kokoads
import
android.app.Activity
import
android.content.Context
import
android.util.Log
import
com.google.android.gms.ads.AdError
import
com.google.android.gms.ads.AdRequest
import
com.google.android.gms.ads.FullScreenContentCallback
import
com.google.android.gms.ads.LoadAdError
import
com.google.android.gms.ads.appopen.AppOpenAd
import
com.zxhy.fastfilemanagerpro.MyApplication
import
java.util.Date
class
KokoOpenAdManager
{
private
var
googleMobileAdsConsentManager
:
GoogleMobileAdsConsentManager
=
GoogleMobileAdsConsentManager
.
getInstance
(
MyApplication
.
ApplicationContext
)
private
var
appOpenAd
:
AppOpenAd
?
=
null
private
var
isLoadingAd
=
false
private
var
isShowingAd
=
false
private
var
loadTime
:
Long
=
0
//广告加载的时间
var
adShowComplete
:
((
showed
:
Boolean
)
->
Unit
)?
=
null
/**
* 广告加载回调
*/
private
inner
class
AppOpenAdLoadCallback
:
AppOpenAd
.
AppOpenAdLoadCallback
()
{
override
fun
onAdLoaded
(
ad
:
AppOpenAd
)
{
appOpenAd
=
ad
isLoadingAd
=
false
loadTime
=
Date
().
time
}
override
fun
onAdFailedToLoad
(
loadAdError
:
LoadAdError
)
{
isLoadingAd
=
false
}
}
/**
* 广告全屏回调
*/
inner
class
MyFullScreenContentCallback
(
val
activity
:
Activity
)
:
FullScreenContentCallback
()
{
override
fun
onAdShowedFullScreenContent
()
{
Log
.
d
(
LOG_TAG
,
"onAdShowedFullScreenContent."
)
}
override
fun
onAdDismissedFullScreenContent
()
{
Log
.
d
(
LOG_TAG
,
"onAdDismissedFullScreenContent."
)
appOpenAd
=
null
isShowingAd
=
false
adShowComplete
?.
invoke
(
true
)
//加载新广告
if
(
googleMobileAdsConsentManager
.
canRequestAds
)
{
loadAd
(
activity
)
}
}
override
fun
onAdFailedToShowFullScreenContent
(
adError
:
AdError
)
{
Log
.
d
(
LOG_TAG
,
"onAdDismissedFullScreenContent."
)
appOpenAd
=
null
isShowingAd
=
false
adShowComplete
?.
invoke
(
false
)
//加载新广告
if
(
googleMobileAdsConsentManager
.
canRequestAds
)
{
loadAd
(
activity
)
}
}
}
/**
* 加载广告
*/
fun
loadAd
(
context
:
Context
)
{
if
(
isLoadingAd
||
existOpenAdCanShow
())
{
return
}
isLoadingAd
=
true
val
request
=
AdRequest
.
Builder
().
build
()
AppOpenAd
.
load
(
context
,
AD_UNIT_ID
,
request
,
AppOpenAdLoadCallback
()
)
}
/**
* 显示广告
*/
fun
showAdIfAvailable
(
activity
:
Activity
)
{
if
(
isShowingAd
)
{
return
}
if
(!
existOpenAdCanShow
())
{
adShowComplete
?.
invoke
(
false
)
if
(
googleMobileAdsConsentManager
.
canRequestAds
)
{
loadAd
(
activity
)
}
return
}
appOpenAd
?.
fullScreenContentCallback
=
MyFullScreenContentCallback
(
activity
)
isShowingAd
=
true
appOpenAd
?.
show
(
activity
)
}
/**
* 检查已有广告是否显示
*/
fun
existOpenAdCanShow
():
Boolean
{
return
appOpenAd
!=
null
&&
adLoadLessInterval
(
1
)
}
/**
* ad加载小于时间间隔
*/
private
fun
adLoadLessInterval
(
hours
:
Int
):
Boolean
{
val
dateDifference
:
Long
=
Date
().
time
-
loadTime
val
mSecondsPerHour
:
Long
=
3600000
return
dateDifference
<
mSecondsPerHour
*
hours
}
companion
object
{
private
const
val
LOG_TAG
=
"KokoOpenAdManager"
private
const
val
AD_UNIT_ID
=
"ca-app-pub-3940256099942544/9257395921"
}
}
\ No newline at end of file
gradle/libs.versions.toml
View file @
2bf975b2
...
...
@@ -14,6 +14,8 @@ fragmentKtx = "1.6.2"
navigationFragmentKtx
=
"2.7.7"
navigationUiKtx
=
"2.7.7"
glide
=
"4.16.0"
#广告
playServicesAds
=
"23.0.0"
[libraries]
androidx-core-ktx
=
{
group
=
"androidx.core"
,
name
=
"core-ktx"
,
version.ref
=
"coreKtx"
}
...
...
@@ -29,6 +31,8 @@ androidx-constraintlayout = { group = "androidx.constraintlayout", name = "const
androidx-navigation-fragment-ktx
=
{
group
=
"androidx.navigation"
,
name
=
"navigation-fragment-ktx"
,
version.ref
=
"navigationFragmentKtx"
}
androidx-navigation-ui-ktx
=
{
group
=
"androidx.navigation"
,
name
=
"navigation-ui-ktx"
,
version.ref
=
"navigationUiKtx"
}
glide
=
{
group
=
"com.github.bumptech.glide"
,
name
=
"glide"
,
version.ref
=
"glide"
}
#广告
google-android-playServicesAds
=
{
group
=
"com.google.android.gms"
,
name
=
"play-services-ads"
,
version.ref
=
"playServicesAds"
}
[plugins]
androidApplication
=
{
id
=
"com.android.application"
,
version.ref
=
"agp"
}
...
...
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