feat: statusBar ui

This commit is contained in:
2025-11-13 17:55:24 +08:00
parent ca99eaa3e4
commit 4193326b92
4 changed files with 75 additions and 12 deletions
@@ -5,6 +5,7 @@ import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import android.content.IntentFilter
import android.os.BatteryManager
import com.rokid.dcg.sprite.service.IInstructListener
import com.rokid.dcg.sprite.service.IInstructService
import com.rokid.dcg.sprite.service.ISpriteMediaService
@@ -45,6 +46,12 @@ class DeviceServiceManager(val context: Application) {
private val _instructState = MutableStateFlow<InstructState>(InstructState.None)
val instructState = _instructState.asStateFlow()
/**
* 系统电量
*/
private val _batteryPercentage = MutableStateFlow(-1)
val batteryPercentage = _batteryPercentage.asStateFlow()
lateinit var sn: String
private set
@@ -56,13 +63,15 @@ class DeviceServiceManager(val context: Application) {
private var wakeTimeoutJob: Job? = null
init {
val filter = IntentFilter()
filter.addAction(SysKeyAction.SPRITE_BUTTON_DOWN)
filter.addAction(SysKeyAction.SPRITE_BUTTON_UP)
filter.addAction(SysKeyAction.SPRITE_BUTTON_CLICK)
filter.addAction(SysKeyAction.SPRITE_BUTTON_LONG_PRESS)
filter.addAction(SysKeyAction.SPRITE_BUTTON_VERY_VERY_LONG_PRESS)
filter.addAction(SysKeyAction.TOUCH_BAR_LONG_PRESS)
val filter = IntentFilter().apply {
addAction(SysKeyAction.SPRITE_BUTTON_DOWN)
addAction(SysKeyAction.SPRITE_BUTTON_UP)
addAction(SysKeyAction.SPRITE_BUTTON_CLICK)
addAction(SysKeyAction.SPRITE_BUTTON_LONG_PRESS)
addAction(SysKeyAction.SPRITE_BUTTON_VERY_VERY_LONG_PRESS)
addAction(SysKeyAction.TOUCH_BAR_LONG_PRESS)
addAction(Intent.ACTION_BATTERY_CHANGED) // 监听电量
}
context.registerReceiver(SysKeyReceiver(), filter)
scope.launch {
@@ -226,6 +235,15 @@ class DeviceServiceManager(val context: Application) {
override fun onReceive(context: Context?, intent: Intent?) {
val action = intent?.action ?: return
when (action) {
Intent.ACTION_BATTERY_CHANGED -> {
val level = intent.getIntExtra(BatteryManager.EXTRA_LEVEL, -1)
val scale = intent.getIntExtra(BatteryManager.EXTRA_SCALE, -1)
if (level == -1 || scale == -1)
return
val batteryPercentage = (level / scale.toFloat() * 100).toInt()
_batteryPercentage.update { batteryPercentage }
}
SysKeyAction.SPRITE_BUTTON_DOWN -> {
Timber.d("按下拍照键 SPRITE_BUTTON_DOWN")
}