V1.0.3(4) -Liftoff SDK
This commit is contained in:
parent
a9bd32c406
commit
5891a561d2
@ -17,8 +17,8 @@ android {
|
||||
applicationId = "com.sunny.tools.app.soft"
|
||||
minSdk = 23
|
||||
targetSdk = 34
|
||||
versionCode = 3
|
||||
versionName = "1.0.2"
|
||||
versionCode = 4
|
||||
versionName = "1.0.3"
|
||||
setProperty("archivesBaseName", "Custom Keyboard_V" + versionName + "(${versionCode})_$timestamp")
|
||||
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
|
||||
}
|
||||
@ -44,7 +44,7 @@ android {
|
||||
dependencies {
|
||||
|
||||
implementation(libs.androidx.core.ktx)
|
||||
implementation(libs.androidx.appcompat)
|
||||
// implementation(libs.androidx.appcompat)
|
||||
implementation(libs.material)
|
||||
implementation(libs.androidx.activity)
|
||||
implementation(libs.androidx.constraintlayout)
|
||||
@ -65,8 +65,8 @@ dependencies {
|
||||
implementation("com.google.firebase:firebase-analytics-ktx")
|
||||
implementation("com.google.firebase:firebase-crashlytics-ktx")
|
||||
|
||||
|
||||
|
||||
//----------------------Liftoff SDK
|
||||
implementation (libs.vungle.ads)
|
||||
|
||||
|
||||
}
|
||||
@ -2,6 +2,11 @@ package com.sunny.app.soft.timberkeyboardnew
|
||||
|
||||
import android.app.Application
|
||||
import android.content.Context
|
||||
import android.util.Log
|
||||
import com.sunny.app.soft.timberkeyboardnew.liftoff.AdManager
|
||||
import com.vungle.ads.InitializationListener
|
||||
import com.vungle.ads.VungleAds
|
||||
import com.vungle.ads.VungleError
|
||||
|
||||
class App : Application() {
|
||||
|
||||
@ -12,9 +17,11 @@ class App : Application() {
|
||||
const val AD_INIT = "on_action"
|
||||
|
||||
|
||||
|
||||
const val APP_ID ="666919bc88cc429f2d801b21"
|
||||
var SDKOK = false
|
||||
|
||||
const val TAG ="============="
|
||||
|
||||
|
||||
|
||||
|
||||
@ -23,12 +30,21 @@ class App : Application() {
|
||||
override fun onCreate() {
|
||||
super.onCreate()
|
||||
appContext = this
|
||||
initUNity()
|
||||
initLiftoff()
|
||||
|
||||
}
|
||||
|
||||
|
||||
private fun initUNity() {
|
||||
private fun initLiftoff() {
|
||||
VungleAds.init(this, APP_ID, object : InitializationListener {
|
||||
override fun onSuccess() {
|
||||
Log.d(TAG, "Vungle SDK init onSuccess()")
|
||||
AdManager.loadAllAd()
|
||||
}
|
||||
override fun onError(vungleError: VungleError) {
|
||||
Log.d(TAG, "onError(): ${vungleError.localizedMessage}")
|
||||
}
|
||||
})
|
||||
|
||||
}
|
||||
}
|
||||
@ -1,4 +1,10 @@
|
||||
package com.sunny.app.soft.timberkeyboardnew.liftoff
|
||||
|
||||
interface AdCallBack {
|
||||
|
||||
fun onLoaded()
|
||||
|
||||
fun onShowFail()
|
||||
|
||||
fun onClose()
|
||||
}
|
||||
@ -1,4 +1,199 @@
|
||||
package com.sunny.app.soft.timberkeyboardnew.liftoff
|
||||
|
||||
import android.content.Context
|
||||
import android.os.CountDownTimer
|
||||
import android.util.Log
|
||||
import com.sunny.app.soft.timberkeyboardnew.App
|
||||
import com.vungle.ads.AdConfig
|
||||
import com.vungle.ads.BaseAd
|
||||
import com.vungle.ads.BaseAdListener
|
||||
import com.vungle.ads.InterstitialAd
|
||||
import com.vungle.ads.InterstitialAdListener
|
||||
import com.vungle.ads.VungleError
|
||||
|
||||
object AdManager {
|
||||
/**
|
||||
* CUSTOM_KEYBOARD_ANDROID_INTER_OPEN-6034009
|
||||
* CUSTOM_KEYBOARD_ANDROID_INTER_SET-7095031
|
||||
* CUSTOM_KEYBOARD_ANDROID_INTER_THEME-1069696
|
||||
*/
|
||||
const val TAG = "============="
|
||||
const val placementId1 = "CUSTOM_KEYBOARD_ANDROID_INTER_OPEN-6034009"
|
||||
const val placementId2 = "CUSTOM_KEYBOARD_ANDROID_INTER_SET-7095031"
|
||||
const val placementId3 = "CUSTOM_KEYBOARD_ANDROID_INTER_THEME-1069696"
|
||||
|
||||
|
||||
const val adPos_0 = 0
|
||||
const val adPos_1 = 1
|
||||
const val adPos_2 = 2
|
||||
|
||||
const val NO_CACHE = 0
|
||||
const val HAS_CACHE = 1
|
||||
const val SHOW_FAIL = 2
|
||||
const val SHOW_SUCCESS = 3
|
||||
const val SHOW_CLOSE = 4
|
||||
|
||||
val list: MutableList<InterstitialAd> = mutableListOf()
|
||||
fun loadAllAd() {
|
||||
if (list.size <= 0) {
|
||||
var interstitialAd1 = InterstitialAd(App.appContext, placementId1, AdConfig().apply { })
|
||||
var interstitialAd2 = InterstitialAd(App.appContext, placementId2, AdConfig().apply { })
|
||||
var interstitialAd3 = InterstitialAd(App.appContext, placementId3, AdConfig().apply { })
|
||||
list.add(interstitialAd1)
|
||||
list.add(interstitialAd2)
|
||||
list.add(interstitialAd3)
|
||||
}
|
||||
for (ad in list) {
|
||||
if (!ad.canPlayAd()) {
|
||||
//一个广告对象show之后,不能再次load,需要新建对象
|
||||
val newAd = getNewAd(ad.placementId)
|
||||
list[list.indexOf(ad)] = newAd
|
||||
setCallBack(newAd, object : AdCallBack {
|
||||
override fun onLoaded() {
|
||||
|
||||
}
|
||||
|
||||
override fun onShowFail() {
|
||||
|
||||
}
|
||||
|
||||
override fun onClose() {
|
||||
|
||||
}
|
||||
|
||||
})
|
||||
newAd.load()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
private fun getNewAd(place: String): InterstitialAd {
|
||||
|
||||
return InterstitialAd(App.appContext, place, AdConfig().apply { })
|
||||
}
|
||||
|
||||
|
||||
private fun getReadyAd(pos: Int): InterstitialAd? {
|
||||
if (list.size <= 0) {
|
||||
return null
|
||||
}
|
||||
if (list[pos].canPlayAd()) {
|
||||
return list[pos]
|
||||
}
|
||||
for (ad in list) {
|
||||
if (ad.canPlayAd()) {
|
||||
return ad
|
||||
}
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun showWelComeAd(totalTim: Long, actionGoMain: () -> Unit): CountDownTimer {
|
||||
var needShow = true
|
||||
val myTimer = object : CountDownTimer(totalTim, 100) {
|
||||
override fun onTick(millisUntilFinished: Long) {
|
||||
if (needShow) {
|
||||
showAd(adPos_0) {
|
||||
if (it == HAS_CACHE) {
|
||||
needShow = false
|
||||
}
|
||||
if (it == SHOW_FAIL) {
|
||||
needShow = true
|
||||
}
|
||||
if (it == SHOW_CLOSE) {
|
||||
actionGoMain.invoke()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
override fun onFinish() {
|
||||
if (needShow) {
|
||||
showAd(adPos_0) {
|
||||
if (it == SHOW_FAIL || it == NO_CACHE || it == SHOW_CLOSE) {
|
||||
actionGoMain.invoke()
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
myTimer.start()
|
||||
return myTimer
|
||||
}
|
||||
|
||||
fun showAd(firstPos: Int, action: (result: Int) -> Unit) {
|
||||
val readyAd = getReadyAd(firstPos)
|
||||
if (readyAd == null) {
|
||||
action.invoke(NO_CACHE)
|
||||
} else {
|
||||
Log.d(TAG, "-----show Ad=${readyAd.placementId}")
|
||||
action.invoke(HAS_CACHE)
|
||||
setCallBack(readyAd, object : AdCallBack {
|
||||
override fun onLoaded() {
|
||||
|
||||
}
|
||||
|
||||
override fun onShowFail() {
|
||||
action.invoke(SHOW_FAIL)
|
||||
}
|
||||
|
||||
override fun onClose() {
|
||||
action.invoke(SHOW_CLOSE)
|
||||
}
|
||||
|
||||
})
|
||||
readyAd.play()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
fun setCallBack(ad: InterstitialAd, callBack: AdCallBack) {
|
||||
ad.adListener = object : InterstitialAdListener {
|
||||
override fun onAdClicked(baseAd: BaseAd) {
|
||||
|
||||
}
|
||||
|
||||
override fun onAdEnd(baseAd: BaseAd) {
|
||||
callBack.onClose()
|
||||
Log.d(TAG, "onAdEnd:" + baseAd.placementId)
|
||||
loadAllAd()
|
||||
}
|
||||
|
||||
override fun onAdFailedToLoad(baseAd: BaseAd, adError: VungleError) {
|
||||
Log.d(
|
||||
TAG,
|
||||
"onAdFailedToLoad:-----${baseAd.placementId}---------${adError.code} ----${adError.errorMessage}"
|
||||
)
|
||||
}
|
||||
|
||||
override fun onAdFailedToPlay(baseAd: BaseAd, adError: VungleError) {
|
||||
callBack.onShowFail()
|
||||
Log.d(TAG, "onAdFailedToPlay:" + baseAd.placementId)
|
||||
}
|
||||
|
||||
override fun onAdImpression(baseAd: BaseAd) {
|
||||
|
||||
}
|
||||
|
||||
override fun onAdLeftApplication(baseAd: BaseAd) {
|
||||
Log.d(TAG, "onAdLeftApplication:" + baseAd.placementId)
|
||||
}
|
||||
|
||||
override fun onAdLoaded(baseAd: BaseAd) {
|
||||
callBack.onLoaded()
|
||||
Log.d(TAG, "onAdLoaded:" + baseAd.placementId)
|
||||
}
|
||||
|
||||
override fun onAdStart(baseAd: BaseAd) {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -16,6 +16,7 @@ import com.bumptech.glide.request.target.Target
|
||||
import com.sunny.app.soft.timberkeyboardnew.R
|
||||
import com.sunny.app.soft.timberkeyboardnew.data.entity.BackgroundEntity
|
||||
import com.sunny.app.soft.timberkeyboardnew.databinding.ActivityDownloadBinding
|
||||
import com.sunny.app.soft.timberkeyboardnew.liftoff.AdManager
|
||||
import com.sunny.app.soft.timberkeyboardnew.tools.AppConstant
|
||||
import com.sunny.app.soft.timberkeyboardnew.tools.KeyboardManager
|
||||
import com.sunny.app.soft.timberkeyboardnew.tools.ZipTools
|
||||
@ -49,9 +50,6 @@ class DownloadActivity :
|
||||
override fun initView() {
|
||||
super.initView()
|
||||
backgroundEntity = intent.getSerializableExtra(AppConstant.KEY_EXTRA) as BackgroundEntity
|
||||
|
||||
// TODO: load Ad
|
||||
|
||||
sp = getSharedPreferences(
|
||||
AppConstant.SHARE_NAME, Context.MODE_PRIVATE
|
||||
)
|
||||
@ -89,25 +87,12 @@ class DownloadActivity :
|
||||
}
|
||||
|
||||
private fun onShowAd() {
|
||||
// val readyUnitAd = UnityAdManager.getReadyUnitAd()
|
||||
// if (readyUnitAd == null) {
|
||||
// startSetSkin()
|
||||
// } else {
|
||||
// UnityAdManager.showUnityAd(this, readyUnitAd, object : onShowCallBack {
|
||||
// override fun onShowFail() {
|
||||
// startSetSkin()
|
||||
// }
|
||||
//
|
||||
// override fun onShowClose() {
|
||||
// startSetSkin()
|
||||
// }
|
||||
//
|
||||
// override fun onShowSuccess() {
|
||||
//
|
||||
// }
|
||||
//
|
||||
// })
|
||||
// }
|
||||
|
||||
AdManager.showAd(AdManager.adPos_2) {
|
||||
if (it == AdManager.SHOW_FAIL || it == AdManager.NO_CACHE || it == AdManager.SHOW_CLOSE) {
|
||||
startSetSkin()
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ -4,6 +4,7 @@ import android.content.Intent
|
||||
import android.os.CountDownTimer
|
||||
import android.view.View
|
||||
import com.sunny.app.soft.timberkeyboardnew.databinding.ActivityLoadingBinding
|
||||
import com.sunny.app.soft.timberkeyboardnew.liftoff.AdManager
|
||||
|
||||
class LoadingActivity : BaseActivity() {
|
||||
|
||||
@ -11,7 +12,7 @@ class LoadingActivity : BaseActivity() {
|
||||
|
||||
private lateinit var timer: CountDownTimer
|
||||
|
||||
private var hasShow = false
|
||||
private val time = 11000L
|
||||
|
||||
|
||||
override fun setRootView(): View {
|
||||
@ -27,62 +28,12 @@ class LoadingActivity : BaseActivity() {
|
||||
override fun initView() {
|
||||
super.initView()
|
||||
|
||||
timer = object : CountDownTimer(11000, 100) {
|
||||
override fun onTick(millisUntilFinished: Long) {
|
||||
|
||||
if (hasShow) return
|
||||
show(false) {
|
||||
intoMainActivity()
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
override fun onFinish() {
|
||||
|
||||
if (!hasShow) {
|
||||
show(true) {
|
||||
intoMainActivity()
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
timer = AdManager.showWelComeAd(time) {
|
||||
intoMainActivity()
|
||||
}
|
||||
|
||||
timer.start()
|
||||
}
|
||||
|
||||
|
||||
private fun show(isFinish: Boolean, action: (showSuccess: Boolean) -> Unit) {
|
||||
// val readyUnitAd = UnityAdManager.getReadyUnitAd()
|
||||
// if (readyUnitAd != null) {
|
||||
// hasShow = true
|
||||
// UnityAdManager.showUnityAd(this@LoadingActivity, readyUnitAd, object :
|
||||
// onShowCallBack {
|
||||
// override fun onShowFail() {
|
||||
// action.invoke(false)
|
||||
// }
|
||||
//
|
||||
// override fun onShowClose() {
|
||||
// intoMainActivity()
|
||||
// action.invoke(true)
|
||||
// }
|
||||
//
|
||||
// override fun onShowSuccess() {
|
||||
//
|
||||
// }
|
||||
//
|
||||
// })
|
||||
// } else {
|
||||
// if (isFinish) {
|
||||
// action.invoke(false)
|
||||
// }
|
||||
//
|
||||
// }
|
||||
}
|
||||
|
||||
private fun intoMainActivity() {
|
||||
val intent = Intent(this, MainActivity::class.java)
|
||||
startActivity(intent)
|
||||
|
||||
@ -4,11 +4,16 @@ import android.view.View
|
||||
import android.view.ViewParent
|
||||
import androidx.fragment.app.Fragment
|
||||
import androidx.viewpager.widget.ViewPager
|
||||
import com.sunny.app.soft.timberkeyboardnew.App
|
||||
import com.sunny.app.soft.timberkeyboardnew.R
|
||||
import com.sunny.app.soft.timberkeyboardnew.databinding.ActivityMainBinding
|
||||
import com.sunny.app.soft.timberkeyboardnew.liftoff.AdCallBack
|
||||
import com.sunny.app.soft.timberkeyboardnew.liftoff.AdManager
|
||||
import com.sunny.app.soft.timberkeyboardnew.ui.adapter.MainViewPagerAdapter
|
||||
import com.sunny.app.soft.timberkeyboardnew.ui.fragment.HomeFragment
|
||||
import com.sunny.app.soft.timberkeyboardnew.ui.fragment.SettingFragment
|
||||
import com.vungle.ads.AdConfig
|
||||
import com.vungle.ads.InterstitialAd
|
||||
|
||||
class MainActivity :
|
||||
BaseActivity(),
|
||||
@ -25,6 +30,24 @@ class MainActivity :
|
||||
|
||||
override fun initView() {
|
||||
super.initView()
|
||||
InterstitialAd(this, AdManager.placementId1, AdConfig().apply { }).apply {
|
||||
AdManager.setCallBack(this, object : AdCallBack {
|
||||
override fun onLoaded() {
|
||||
|
||||
}
|
||||
|
||||
override fun onShowFail() {
|
||||
|
||||
}
|
||||
|
||||
override fun onClose() {
|
||||
|
||||
}
|
||||
|
||||
})
|
||||
load()
|
||||
}
|
||||
|
||||
initViewPager()
|
||||
initTabButton()
|
||||
}
|
||||
|
||||
@ -7,6 +7,7 @@ import androidx.recyclerview.widget.GridLayoutManager
|
||||
import com.sunny.app.soft.timberkeyboardnew.data.entity.BackgroundEntity
|
||||
import com.sunny.app.soft.timberkeyboardnew.data.entity.CategoryEntity
|
||||
import com.sunny.app.soft.timberkeyboardnew.databinding.ActivitySelectBinding
|
||||
import com.sunny.app.soft.timberkeyboardnew.liftoff.AdManager
|
||||
import com.sunny.app.soft.timberkeyboardnew.tools.AppConstant
|
||||
import com.sunny.app.soft.timberkeyboardnew.ui.adapter.SelectAdapter
|
||||
import com.sunny.app.soft.timberkeyboardnew.ui.listener.OnBgItemClickListener
|
||||
|
||||
@ -8,6 +8,7 @@ import com.sunny.app.soft.timberkeyboardnew.R
|
||||
import com.sunny.app.soft.timberkeyboardnew.data.DataManager
|
||||
import com.sunny.app.soft.timberkeyboardnew.data.entity.CategoryEntity
|
||||
import com.sunny.app.soft.timberkeyboardnew.databinding.FragmentHomeBinding
|
||||
import com.sunny.app.soft.timberkeyboardnew.liftoff.AdManager
|
||||
import com.sunny.app.soft.timberkeyboardnew.tools.AppConstant
|
||||
import com.sunny.app.soft.timberkeyboardnew.ui.activity.SelectActivity
|
||||
import com.sunny.app.soft.timberkeyboardnew.ui.adapter.HomeViewAdapter
|
||||
@ -60,26 +61,11 @@ class HomeFragment :
|
||||
|
||||
|
||||
fun onShowAd() {
|
||||
|
||||
// val readyUnitAd = UnityAdManager.getReadyUnitAd()
|
||||
// if (readyUnitAd == null) {
|
||||
// enterList()
|
||||
// } else {
|
||||
// UnityAdManager.showUnityAd(requireActivity(), readyUnitAd, object : onShowCallBack {
|
||||
// override fun onShowFail() {
|
||||
// enterList()
|
||||
// }
|
||||
//
|
||||
// override fun onShowClose() {
|
||||
// enterList()
|
||||
// }
|
||||
//
|
||||
// override fun onShowSuccess() {
|
||||
//
|
||||
// }
|
||||
//
|
||||
// })
|
||||
// }
|
||||
AdManager.showAd(AdManager.adPos_1) {
|
||||
if (it == AdManager.SHOW_FAIL || it == AdManager.NO_CACHE || it == AdManager.SHOW_CLOSE) {
|
||||
enterList()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
[versions]
|
||||
agp = "8.1.3"
|
||||
agp = "7.4.2"
|
||||
kotlin = "1.9.0"
|
||||
coreKtx = "1.13.1"
|
||||
junit = "4.13.2"
|
||||
@ -9,6 +9,7 @@ appcompat = "1.7.0"
|
||||
material = "1.12.0"
|
||||
activity = "1.9.0"
|
||||
constraintlayout = "2.1.4"
|
||||
vungleAds = "7.4.0"
|
||||
|
||||
[libraries]
|
||||
androidx-core-ktx = { group = "androidx.core", name = "core-ktx", version.ref = "coreKtx" }
|
||||
@ -19,6 +20,7 @@ androidx-appcompat = { group = "androidx.appcompat", name = "appcompat", version
|
||||
material = { group = "com.google.android.material", name = "material", version.ref = "material" }
|
||||
androidx-activity = { group = "androidx.activity", name = "activity", version.ref = "activity" }
|
||||
androidx-constraintlayout = { group = "androidx.constraintlayout", name = "constraintlayout", version.ref = "constraintlayout" }
|
||||
vungle-ads = { module = "com.vungle:vungle-ads", version.ref = "vungleAds" }
|
||||
|
||||
[plugins]
|
||||
android-application = { id = "com.android.application", version.ref = "agp" }
|
||||
|
||||
4
gradle/wrapper/gradle-wrapper.properties
vendored
4
gradle/wrapper/gradle-wrapper.properties
vendored
@ -1,6 +1,6 @@
|
||||
#Tue Jun 04 10:25:08 CST 2024
|
||||
#Fri Jul 12 09:46:22 CST 2024
|
||||
distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-bin.zip
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5-bin.zip
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
zipStorePath=wrapper/dists
|
||||
|
||||
Loading…
Reference in New Issue
Block a user