feat(boot): 新增前台服务中转实现开机自启动

使用 BootService 前台服务绕过 Android 10+ 后台启动 Activity 限制,
通过 setFullScreenIntent 触发 InitActivity,兼容主从设备差异。
同时优化 MasterScaleActivity、SettingActivity 及相关布局。
This commit is contained in:
2026-04-09 18:20:50 +08:00
parent 9ae0d709f2
commit 904ccdbb06
9 changed files with 160 additions and 36 deletions
@@ -9,6 +9,7 @@ import android.widget.TextView
import androidx.lifecycle.lifecycleScope
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.shuwei.dish.match.R
import com.shuwei.dish.match.base.BaseActivity
import com.shuwei.dish.match.databinding.ActivityMasterScaleBinding
import com.shuwei.dish.match.databinding.ListItemScaleDataBinding
@@ -16,6 +17,7 @@ import com.shuwei.dish.match.scale.ScaleData
import com.shuwei.dish.match.scale.ScaleServiceManager
import com.shuwei.dish.match.utils.NetworkUtil
import com.shuwei.dish.match.utils.WeightUtil
import com.shuwei.dish.match.utils.ext.dp
import kotlinx.coroutines.flow.collectLatest
import kotlinx.coroutines.launch
@@ -138,7 +140,7 @@ class MasterScaleActivity : BaseActivity() {
layoutParams = LinearLayout.LayoutParams(
LinearLayout.LayoutParams.MATCH_PARENT,
LinearLayout.LayoutParams.WRAP_CONTENT
).also { it.topMargin = 4.dpToPx() }
).also { it.topMargin = 4.dp }
}
row.addView(makeTextView("${scale.address}", 22, weight = 1f))
row.addView(makeTextView("${scale.weight} g", 26, bold = true, weight = 2f))
@@ -158,15 +160,11 @@ class MasterScaleActivity : BaseActivity() {
textSize = spSize.toFloat()
if (bold) setTypeface(null, android.graphics.Typeface.BOLD)
setTextColor(
if (bold) getColor(com.shuwei.dish.match.R.color.home_title)
else getColor(com.shuwei.dish.match.R.color.home_sub_title)
if (bold) getColor(R.color.home_title)
else getColor(R.color.home_sub_title)
)
layoutParams = LinearLayout.LayoutParams(0, LinearLayout.LayoutParams.WRAP_CONTENT, weight)
}
}
/** dp 转 px 工具 */
private fun Int.dpToPx(): Int =
(this * resources.displayMetrics.density + 0.5f).toInt()
}
@@ -81,9 +81,9 @@ class SettingActivity : BaseActivity() {
updateButtonColors(isDeviceConfigSelected = false)
}
// 设备角色只读展示,角色由设备 ID 决定,不可手动切换
updateRoleButtonText()
binding.btnDeviceRole.isEnabled = false
// // 设备角色只读展示,角色由设备 ID 决定,不可手动切换
// updateRoleButtonText()
// binding.btnDeviceRole.isEnabled = false
// 主设备显示「秤数据监控」入口
if (GlobalData.deviceRole == DeviceRole.MASTER) {
@@ -97,11 +97,11 @@ class SettingActivity : BaseActivity() {
updateButtonColors(isDeviceConfigSelected = true)
}
/** 刷新角色按钮文字 */
private fun updateRoleButtonText() {
val roleLabel = if (GlobalData.deviceRole == DeviceRole.MASTER) "主设备" else "子设备"
binding.btnDeviceRole.text = "设备角色:$roleLabel"
}
// /** 刷新角色按钮文字 */
// private fun updateRoleButtonText() {
// val roleLabel = if (GlobalData.deviceRole == DeviceRole.MASTER) "主设备" else "子设备"
// binding.btnDeviceRole.text = "设备角色:$roleLabel"
// }
/**
* 更新底部菜单按钮的颜色状态