Commit 4b752859 authored by wanglei's avatar wanglei

...

parent 30939b41
......@@ -2,6 +2,7 @@ package com.test.easy.easycleanerjunk.activity
import android.annotation.SuppressLint
import android.content.Intent
import android.content.IntentFilter
import androidx.activity.addCallback
import androidx.core.content.ContextCompat
import androidx.core.view.isVisible
......@@ -18,21 +19,34 @@ class BatteryInfoActivity : BaseActivity<ActivityLayoutBatteryInfoBinding>() {
override val binding: ActivityLayoutBatteryInfoBinding by lazy {
ActivityLayoutBatteryInfoBinding.inflate(layoutInflater)
}
private lateinit var batteryReceiver: BatteryReceiver
@SuppressLint("SetTextI18n")
override fun initView() {
batteryReceiver = BatteryReceiver {
aa()
}
registerReceiver(batteryReceiver, IntentFilter().apply {
addAction("android.intent.action.BATTERY_CHANGED")
})
AdmobUtils.showNativeAd(this, binding.idFlAd)
binding.idBatteryLottie.imageAssetsFolder = "battery_scan/images/"
binding.idBatteryLottie.setAnimation("battery_scan/data.json")
binding.idBatteryLottie.playAnimation()
binding.root.postDelayed({
AdmobUtils.showInterstitialAd(this){
AdmobUtils.showInterstitialAd(this) {
binding.idBatteryLottie.clearAnimation()
binding.idConsOne.isVisible = false
}
}, Random.nextLong(3000,4500))
}, Random.nextLong(3000, 4500))
}
@SuppressLint("SetTextI18n")
fun aa() {
val percent = BatteryReceiver.level / BatteryReceiver.scale.toFloat()
binding.idChongdian.isVisible = BatteryReceiver.status==2
binding.idChongdian.isVisible = BatteryReceiver.status == 2
binding.idTvDl.text = "${(percent * 100).toInt()}%"
val p = (percent * 100).toInt()
if (p in 21..49) {
......@@ -75,4 +89,9 @@ class BatteryInfoActivity : BaseActivity<ActivityLayoutBatteryInfoBinding>() {
}
}
}
override fun onDestroy() {
super.onDestroy()
unregisterReceiver(batteryReceiver)
}
}
\ No newline at end of file
package com.test.easy.easycleanerjunk.helps
import android.app.Application
import android.content.IntentFilter
import com.test.easy.easycleanerjunk.service.BatteryReceiver
abstract class BaseApplication : Application() {
companion object {
......@@ -13,9 +11,6 @@ abstract class BaseApplication : Application() {
super.onCreate()
context = this
init()
registerReceiver(BatteryReceiver(), IntentFilter().apply {
addAction("android.intent.action.BATTERY_CHANGED")
})
}
abstract fun init()
......
......@@ -5,7 +5,7 @@ import android.content.Context
import android.content.Intent
import android.os.BatteryManager
class BatteryReceiver : BroadcastReceiver() {
class BatteryReceiver(val change: () -> Unit) : BroadcastReceiver() {
companion object {
var level = 0
var scale = 0
......@@ -33,6 +33,7 @@ class BatteryReceiver : BroadcastReceiver() {
if (chargeCounter != Int.MIN_VALUE && propertyCapacity != Int.MIN_VALUE) {
mAh = (chargeCounter / (propertyCapacity.toFloat() / 100f)) / 1000f
}
change.invoke()
}
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment