V1.0.1(2) 广告版本(pangle、liftoff monetize、mintegral、unity ads)
This commit is contained in:
parent
f57bf47542
commit
9e90b9abcd
1
.gitignore
vendored
1
.gitignore
vendored
@ -15,3 +15,4 @@
|
||||
local.properties
|
||||
.idea/
|
||||
app/release/
|
||||
.safedk/
|
||||
|
||||
@ -4,6 +4,12 @@ import java.text.SimpleDateFormat
|
||||
plugins {
|
||||
id("com.android.application")
|
||||
id("org.jetbrains.kotlin.android")
|
||||
id("applovin-quality-service")
|
||||
id("com.google.gms.google-services")
|
||||
id("com.google.firebase.crashlytics")
|
||||
}
|
||||
applovin{
|
||||
apiKey = "UK0pVyI1Qp5ri23EtwRT616OsxRF4fbPtnJ0c25bb3krzmSwnzuzvwmtkZzJ72zJxXBkUE0cUzC4Bq2gIAmSVK"
|
||||
}
|
||||
val timestamp = SimpleDateFormat("MM_dd_HH_mm").format(Date())
|
||||
android {
|
||||
@ -52,4 +58,13 @@ dependencies {
|
||||
|
||||
implementation ("com.github.bumptech.glide:glide:4.16.0")
|
||||
implementation ("com.google.code.gson:gson:2.10.1")
|
||||
|
||||
implementation("com.applovin:applovin-sdk:+")
|
||||
implementation("com.applovin.mediation:vungle-adapter:+")
|
||||
implementation("com.applovin.mediation:bytedance-adapter:+")
|
||||
implementation("com.applovin.mediation:unityads-adapter:+")
|
||||
implementation("com.applovin.mediation:mintegral-adapter:+")
|
||||
implementation(platform("com.google.firebase:firebase-bom:32.3.1"))
|
||||
implementation("com.google.firebase:firebase-analytics-ktx")
|
||||
implementation ("com.google.firebase:firebase-crashlytics-ktx")
|
||||
}
|
||||
29
app/google-services.json
Normal file
29
app/google-services.json
Normal file
@ -0,0 +1,29 @@
|
||||
{
|
||||
"project_info": {
|
||||
"project_number": "583346081799",
|
||||
"project_id": "wallpaper-collection-fc4d2",
|
||||
"storage_bucket": "wallpaper-collection-fc4d2.appspot.com"
|
||||
},
|
||||
"client": [
|
||||
{
|
||||
"client_info": {
|
||||
"mobilesdk_app_id": "1:583346081799:android:394f61d41a1e860187daa2",
|
||||
"android_client_info": {
|
||||
"package_name": "com.quiescent.wallpaper.collection.test"
|
||||
}
|
||||
},
|
||||
"oauth_client": [],
|
||||
"api_key": [
|
||||
{
|
||||
"current_key": "AIzaSyAOy780rpU0PHKVJ5hlTgPU-yuxnLoCmOY"
|
||||
}
|
||||
],
|
||||
"services": {
|
||||
"appinvite_service": {
|
||||
"other_platform_oauth_client": []
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
"configuration_version": "1"
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,81 @@
|
||||
package com.quiescent.wallpaper.collection.test
|
||||
|
||||
import android.app.Activity
|
||||
import com.applovin.mediation.MaxAd
|
||||
import com.applovin.mediation.MaxAdListener
|
||||
import com.applovin.mediation.MaxError
|
||||
import com.applovin.mediation.ads.MaxInterstitialAd
|
||||
|
||||
object InterstitialManager {
|
||||
|
||||
private const val unit1 = "e4c638b430ed484e"
|
||||
private const val unit2 = "136732916feb53dc"
|
||||
private const val unit3 = "9f5d8ac0162a29bc"
|
||||
//private const val unit1 = "4c0e7c1b292301ab"
|
||||
// private const val unit2 = "4c0e7c1b292301a2"
|
||||
// private const val unit3 = "4c0e7c1b292301a1"
|
||||
|
||||
|
||||
|
||||
fun startLoadAd(context: Activity): List<MaxInterstitialAd> {
|
||||
return listOf(
|
||||
MaxInterstitialAd(unit1, context).apply {
|
||||
loadAd()
|
||||
},
|
||||
MaxInterstitialAd(unit2, context).apply {
|
||||
loadAd()
|
||||
},
|
||||
MaxInterstitialAd(unit3, context).apply {
|
||||
loadAd()
|
||||
}
|
||||
)
|
||||
|
||||
}
|
||||
|
||||
fun getReadyAd(adList: List<MaxInterstitialAd>): MaxInterstitialAd? {
|
||||
val shuffled = adList.shuffled()
|
||||
for (ad in shuffled) {
|
||||
if (ad.isReady) {
|
||||
return ad
|
||||
}
|
||||
}
|
||||
return null
|
||||
|
||||
}
|
||||
|
||||
fun MaxInterstitialAd.setMyCallBack(myCallBack: MyCallBack) {
|
||||
setListener(object :MaxAdListener{
|
||||
override fun onAdLoaded(p0: MaxAd) {
|
||||
|
||||
}
|
||||
|
||||
override fun onAdDisplayed(p0: MaxAd) {
|
||||
|
||||
}
|
||||
|
||||
override fun onAdHidden(p0: MaxAd) {
|
||||
myCallBack.adShowHidden()
|
||||
}
|
||||
|
||||
override fun onAdClicked(p0: MaxAd) {
|
||||
|
||||
}
|
||||
|
||||
override fun onAdLoadFailed(p0: String, p1: MaxError) {
|
||||
|
||||
}
|
||||
|
||||
override fun onAdDisplayFailed(p0: MaxAd, p1: MaxError) {
|
||||
myCallBack.adShowFail()
|
||||
}
|
||||
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
interface MyCallBack{
|
||||
fun adShowFail()
|
||||
fun adShowHidden()
|
||||
}
|
||||
|
||||
}
|
||||
@ -1,6 +1,12 @@
|
||||
package com.quiescent.wallpaper.collection.test
|
||||
|
||||
import android.app.Application
|
||||
import android.content.Intent
|
||||
import android.content.IntentFilter
|
||||
import android.util.Log
|
||||
import androidx.localbroadcastmanager.content.LocalBroadcastManager
|
||||
import com.applovin.sdk.AppLovinSdk
|
||||
import com.applovin.sdk.AppLovinSdkInitializationConfiguration
|
||||
import com.google.gson.Gson
|
||||
import com.google.gson.reflect.TypeToken
|
||||
import com.quiescent.wallpaper.collection.test.bean.Info
|
||||
@ -12,12 +18,17 @@ import java.io.StringWriter
|
||||
|
||||
class WallpaperCollection : Application() {
|
||||
|
||||
var list:MutableList<Info> = mutableListOf()
|
||||
var list: MutableList<Info> = mutableListOf()
|
||||
|
||||
companion object {
|
||||
lateinit var instance:WallpaperCollection
|
||||
const val MAX_SDK_CODE = "VNL26CMGzXqLLfS5kMl2Nmz51a6LsHeLK3piaHf4dtiplx5ludvxFe6tU9hdhFWJEPLgH7QyzOpbXT056xw_Bi"
|
||||
const val MAX_PROVIDER = "max"
|
||||
const val INIT_SUCCESS_ACTION = "init_success_action"
|
||||
var INIT_SUCCESS = false
|
||||
lateinit var instance: WallpaperCollection
|
||||
}
|
||||
private fun getJsonString(fileInputStream: InputStream): String {
|
||||
|
||||
private fun getJsonString(fileInputStream: InputStream): String {
|
||||
return try {
|
||||
val charArray = CharArray(fileInputStream.available())
|
||||
var readCount = 0
|
||||
@ -33,17 +44,30 @@ class WallpaperCollection : Application() {
|
||||
""
|
||||
}
|
||||
}
|
||||
|
||||
override fun onCreate() {
|
||||
super.onCreate()
|
||||
instance = this
|
||||
initMaxInter()
|
||||
val open = assets.open("wallpaper.json")
|
||||
val jsonStr = getJsonString(open)
|
||||
val jsonStr = getJsonString(open)
|
||||
list = Gson().fromJson(jsonStr, object : TypeToken<List<Info>>() {}.type)
|
||||
|
||||
}
|
||||
|
||||
private fun initMaxInter() {
|
||||
val localBroadcastManager = LocalBroadcastManager.getInstance(this)
|
||||
AppLovinSdk.getInstance(this)
|
||||
.initialize(
|
||||
AppLovinSdkInitializationConfiguration.builder(MAX_SDK_CODE, this)
|
||||
.setMediationProvider(MAX_PROVIDER).build()
|
||||
) {
|
||||
INIT_SUCCESS = true
|
||||
localBroadcastManager.sendBroadcast(Intent(INIT_SUCCESS_ACTION))
|
||||
}
|
||||
|
||||
|
||||
// AppLovinSdk.getInstance(this).settings.setVerboseLogging(true)
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@ -1,24 +1,99 @@
|
||||
package com.quiescent.wallpaper.collection.test.ui
|
||||
|
||||
import android.content.BroadcastReceiver
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.content.IntentFilter
|
||||
import android.util.Log
|
||||
import androidx.localbroadcastmanager.content.LocalBroadcastManager
|
||||
import com.applovin.mediation.ads.MaxInterstitialAd
|
||||
import com.quiescent.wallpaper.collection.test.InterstitialManager
|
||||
import com.quiescent.wallpaper.collection.test.InterstitialManager.setMyCallBack
|
||||
import com.quiescent.wallpaper.collection.test.WallpaperCollection
|
||||
import com.quiescent.wallpaper.collection.test.databinding.ActivityLauncherBinding
|
||||
import java.util.Timer
|
||||
import java.util.TimerTask
|
||||
|
||||
class ActivityLauncher : BaseActivity<ActivityLauncherBinding>() {
|
||||
|
||||
private lateinit var localBroadcastManager: LocalBroadcastManager
|
||||
|
||||
private lateinit var timer: Timer
|
||||
private var count: Long = 0L
|
||||
|
||||
private var countTime: Long = 0L
|
||||
|
||||
private var interval: Long = 500L
|
||||
|
||||
private var hasShowAd = false
|
||||
|
||||
private lateinit var adList: List<MaxInterstitialAd>
|
||||
override fun getViewBinding(): ActivityLauncherBinding {
|
||||
return ActivityLauncherBinding.inflate(layoutInflater)
|
||||
}
|
||||
|
||||
override fun onViewUi() {
|
||||
Timer().schedule(object :TimerTask(){
|
||||
timer = Timer()
|
||||
localBroadcastManager = LocalBroadcastManager.getInstance(this)
|
||||
checkSDKInit()
|
||||
}
|
||||
|
||||
|
||||
private fun checkSDKInit() {
|
||||
if (!WallpaperCollection.INIT_SUCCESS) {
|
||||
localBroadcastManager.registerReceiver(object : BroadcastReceiver() {
|
||||
override fun onReceive(context: Context?, intent: Intent?) {
|
||||
loadAd()
|
||||
}
|
||||
|
||||
}, IntentFilter(WallpaperCollection.INIT_SUCCESS_ACTION))
|
||||
|
||||
} else {
|
||||
loadAd()
|
||||
}
|
||||
}
|
||||
|
||||
private fun loadAd() {
|
||||
Log.d("-------------","-----------load")
|
||||
adList = InterstitialManager.startLoadAd(this@ActivityLauncher)
|
||||
timer.schedule(object : TimerTask() {
|
||||
override fun run() {
|
||||
startActivity(Intent(this@ActivityLauncher,MainActivity::class.java))
|
||||
finish()
|
||||
count++
|
||||
countTime = count * interval
|
||||
if (!hasShowAd) {
|
||||
val readyAd = InterstitialManager.getReadyAd(adList)
|
||||
if (readyAd == null) {
|
||||
if (countTime >= 12000) {
|
||||
Log.d("-------------","-----------countTime=$countTime")
|
||||
timer.cancel()
|
||||
goMain()
|
||||
}
|
||||
} else {
|
||||
hasShowAd = true
|
||||
timer.cancel()
|
||||
readyAd.setMyCallBack(object : InterstitialManager.MyCallBack {
|
||||
override fun adShowFail() {
|
||||
Log.d("-------------","-----------adShowFail=")
|
||||
goMain()
|
||||
}
|
||||
|
||||
override fun adShowHidden() {
|
||||
Log.d("-------------","-----------adShowHidden=")
|
||||
goMain()
|
||||
}
|
||||
|
||||
})
|
||||
readyAd.showAd()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
},2200)
|
||||
}, 0, interval)
|
||||
}
|
||||
|
||||
private fun goMain() {
|
||||
startActivity(Intent(this@ActivityLauncher, MainActivity::class.java))
|
||||
finish()
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -5,6 +5,7 @@ import android.graphics.BitmapFactory
|
||||
import android.os.Build
|
||||
import android.widget.Toast
|
||||
import androidx.core.view.isVisible
|
||||
import com.applovin.mediation.ads.MaxInterstitialAd
|
||||
import com.quiescent.wallpaper.collection.test.R
|
||||
import com.quiescent.wallpaper.collection.test.bean.InfoList
|
||||
import com.quiescent.wallpaper.collection.test.databinding.ActivitySetWactivityBinding
|
||||
@ -14,6 +15,8 @@ import com.bumptech.glide.load.DataSource
|
||||
import com.bumptech.glide.load.engine.GlideException
|
||||
import com.bumptech.glide.request.RequestListener
|
||||
import com.bumptech.glide.request.target.Target
|
||||
import com.quiescent.wallpaper.collection.test.InterstitialManager
|
||||
import com.quiescent.wallpaper.collection.test.InterstitialManager.setMyCallBack
|
||||
import java.io.File
|
||||
|
||||
class ActivitySetWallpaper : BaseActivity<ActivitySetWactivityBinding>() {
|
||||
@ -27,14 +30,17 @@ class ActivitySetWallpaper : BaseActivity<ActivitySetWactivityBinding>() {
|
||||
private lateinit var wallMan: WallpaperManager
|
||||
|
||||
|
||||
private lateinit var myFilePath:String
|
||||
private lateinit var myFilePath: String
|
||||
|
||||
private var sourceFile:File? = null
|
||||
private var sourceFile: File? = null
|
||||
|
||||
private lateinit var adList: List<MaxInterstitialAd>
|
||||
override fun getViewBinding(): ActivitySetWactivityBinding {
|
||||
return ActivitySetWactivityBinding.inflate(layoutInflater)
|
||||
}
|
||||
|
||||
override fun onViewUi() {
|
||||
adList = InterstitialManager.startLoadAd(this@ActivitySetWallpaper)
|
||||
data = intent.getSerializableExtra(KEY_DATA) as InfoList
|
||||
wallMan = WallpaperManager.getInstance(this)
|
||||
myFilePath = "${applicationContext.cacheDir.path}/${data!!.source.substringAfterLast("/")}"
|
||||
@ -44,6 +50,34 @@ class ActivitySetWallpaper : BaseActivity<ActivitySetWactivityBinding>() {
|
||||
|
||||
}
|
||||
|
||||
override fun onBackPressed() {
|
||||
super.onBackPressed()
|
||||
startShowAd {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private fun startShowAd(action: () -> Unit) {
|
||||
val readyAd = InterstitialManager.getReadyAd(adList)
|
||||
if (readyAd != null) {
|
||||
readyAd.setMyCallBack(object : InterstitialManager.MyCallBack {
|
||||
override fun adShowFail() {
|
||||
action.invoke()
|
||||
}
|
||||
|
||||
override fun adShowHidden() {
|
||||
action.invoke()
|
||||
}
|
||||
|
||||
})
|
||||
readyAd.showAd()
|
||||
|
||||
} else {
|
||||
action.invoke()
|
||||
}
|
||||
}
|
||||
|
||||
private fun display() {
|
||||
data?.source.let {
|
||||
setLoading(true)
|
||||
@ -86,24 +120,31 @@ class ActivitySetWallpaper : BaseActivity<ActivitySetWactivityBinding>() {
|
||||
|
||||
private fun onClick() {
|
||||
binding.backIm.setOnClickListener {
|
||||
finish()
|
||||
startShowAd {
|
||||
finish()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
binding.setBtnTv.setOnClickListener {
|
||||
require(data != null) {
|
||||
|
||||
}
|
||||
setLoading(true)
|
||||
if (File(myFilePath).exists()) {
|
||||
setMyWallpaper(File(myFilePath))
|
||||
setLoading(false)
|
||||
if (data != null) {
|
||||
startShowAd {
|
||||
if (File(myFilePath).exists()) {
|
||||
setMyWallpaper(File(myFilePath))
|
||||
setLoading(false)
|
||||
} else {
|
||||
fileDownload()
|
||||
}
|
||||
}
|
||||
} else {
|
||||
fileDownload()
|
||||
setLoading(false)
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private fun setMyWallpaper(file: File) {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
|
||||
wallMan.setStream(
|
||||
@ -116,17 +157,23 @@ class ActivitySetWallpaper : BaseActivity<ActivitySetWactivityBinding>() {
|
||||
wallMan.setStream(file.inputStream())
|
||||
}
|
||||
finish()
|
||||
Toast.makeText(this@ActivitySetWallpaper, getString(R.string.set_success), Toast.LENGTH_SHORT)
|
||||
Toast.makeText(
|
||||
this@ActivitySetWallpaper,
|
||||
getString(R.string.set_success),
|
||||
Toast.LENGTH_SHORT
|
||||
)
|
||||
.show()
|
||||
}
|
||||
|
||||
private fun setLoading(isLoading: Boolean) {
|
||||
binding.loading.isVisible = isLoading
|
||||
binding.setBtnTv.isEnabled = !isLoading
|
||||
}
|
||||
private fun fileDownload(){
|
||||
if(sourceFile == null){
|
||||
|
||||
private fun fileDownload() {
|
||||
if (sourceFile == null) {
|
||||
display()
|
||||
}else{
|
||||
} else {
|
||||
sourceFile?.let {
|
||||
val copyFile = Utils.fileToCache(it.absolutePath, myFilePath)
|
||||
if (copyFile) {
|
||||
@ -140,9 +187,4 @@ class ActivitySetWallpaper : BaseActivity<ActivitySetWactivityBinding>() {
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
@ -2,4 +2,11 @@
|
||||
plugins {
|
||||
id("com.android.application") version "8.1.3" apply false
|
||||
id("org.jetbrains.kotlin.android") version "1.9.0" apply false
|
||||
id("com.google.gms.google-services") version "4.3.15" apply false
|
||||
id ("com.google.firebase.crashlytics") version "2.9.2" apply false
|
||||
}
|
||||
buildscript{
|
||||
dependencies{
|
||||
classpath("com.applovin.quality:AppLovinQualityServiceGradlePlugin:+")
|
||||
}
|
||||
}
|
||||
@ -3,6 +3,7 @@ pluginManagement {
|
||||
google()
|
||||
mavenCentral()
|
||||
gradlePluginPortal()
|
||||
maven{url = uri("https://artifacts.applovin.com/android")}
|
||||
}
|
||||
}
|
||||
dependencyResolutionManagement {
|
||||
@ -10,6 +11,8 @@ dependencyResolutionManagement {
|
||||
repositories {
|
||||
google()
|
||||
mavenCentral()
|
||||
maven ("https://artifact.bytedance.com/repository/pangle")
|
||||
maven { url = uri("https://dl-maven-android.mintegral.com/repository/mbridge_android_sdk_oversea") }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user