feat(app): 添加测试设备支持和芯片布局优化
- 在 BaseApp 中根据 BuildConfig.IS_TEST_DEVICE 配置设备 ID - 更新 build.gradle 配置 IS_TEST_DEVICE 构建字段 - 添加 x86_64 架构支持用于 Windows 模拟器调试 - 优化 RawMaterialsDialogUtils 中的 Chip 布局和测量逻辑 - 在 WeightUtil 中添加架构检查避免非 ARM 设备崩溃 - 实现秤 SDK 可用性检测和异常处理机制
This commit is contained in:
@@ -24,9 +24,8 @@ android {
|
|||||||
|
|
||||||
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
|
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
|
||||||
ndk {
|
ndk {
|
||||||
//设置支持的SO库架构
|
//设置支持的SO库架构;x86_64 仅用于在 Windows 模拟器上调试(秤功能不可用)
|
||||||
abiFilters.addAll(listOf("armeabi-v7a"))
|
abiFilters.addAll(listOf("armeabi-v7a", "x86_64"))
|
||||||
//, 'x86', 'armeabi-v7a', 'x86_64', 'arm64-v8a'
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 设置输出APK文件名格式
|
// 设置输出APK文件名格式
|
||||||
@@ -48,12 +47,13 @@ android {
|
|||||||
"proguard-rules.pro"
|
"proguard-rules.pro"
|
||||||
)
|
)
|
||||||
signingConfig = signingConfigs.getByName("debug_507")
|
signingConfig = signingConfigs.getByName("debug_507")
|
||||||
// buildConfigField("boolean", "DEBUG", "false")
|
buildConfigField("Boolean", "IS_TEST_DEVICE", "false")
|
||||||
}
|
}
|
||||||
debug {
|
debug {
|
||||||
//507扫码秤主板在android.buildTypes{}内增加
|
//507扫码秤主板在android.buildTypes{}内增加
|
||||||
signingConfig = signingConfigs.getByName("debug_507")
|
signingConfig = signingConfigs.getByName("debug_507")
|
||||||
// buildConfigField("boolean", "DEBUG", "true")
|
// 调试构建视为测试设备,使用固定的 DEVICE_ID_1 代替真实 UDID
|
||||||
|
buildConfigField("Boolean", "IS_TEST_DEVICE", "false")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
compileOptions {
|
compileOptions {
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import android.content.IntentFilter
|
|||||||
import android.content.SharedPreferences
|
import android.content.SharedPreferences
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
|
import com.shuwei.dish.match.BuildConfig
|
||||||
import com.shuwei.dish.match.R
|
import com.shuwei.dish.match.R
|
||||||
import com.shuwei.dish.match.db.DatabaseProvider
|
import com.shuwei.dish.match.db.DatabaseProvider
|
||||||
import com.shuwei.dish.match.objbox.ObjectBox
|
import com.shuwei.dish.match.objbox.ObjectBox
|
||||||
@@ -33,8 +34,8 @@ class BaseApp : Application() {
|
|||||||
GlobalData.appBaseUrl = savedBaseUrl
|
GlobalData.appBaseUrl = savedBaseUrl
|
||||||
}
|
}
|
||||||
CrashHandler.init(this)
|
CrashHandler.init(this)
|
||||||
val deviceId = AppUtil.getUDID(this)
|
val deviceId = if (BuildConfig.IS_TEST_DEVICE) ScaleDeviceConfig.DEVICE_ID_2 else AppUtil.getUDID(this)
|
||||||
Log.d(TAG, "onCreate: deviceId=$deviceId")
|
Log.d(TAG, "onCreate: deviceId=$deviceId, isTestDevice=${BuildConfig.IS_TEST_DEVICE}")
|
||||||
GlobalData.deviceId = deviceId
|
GlobalData.deviceId = deviceId
|
||||||
|
|
||||||
// 根据设备 ID 判断角色:指定 ID 为主设备,其余为子设备
|
// 根据设备 ID 判断角色:指定 ID 为主设备,其余为子设备
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package com.shuwei.dish.match.utils
|
|||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.res.ColorStateList
|
import android.content.res.ColorStateList
|
||||||
import android.view.View
|
import android.view.View
|
||||||
|
import android.view.ViewGroup
|
||||||
import androidx.core.content.ContextCompat
|
import androidx.core.content.ContextCompat
|
||||||
import com.google.android.material.chip.Chip
|
import com.google.android.material.chip.Chip
|
||||||
import com.google.android.material.chip.ChipGroup
|
import com.google.android.material.chip.ChipGroup
|
||||||
@@ -111,10 +112,10 @@ fun buildSingleChoiceChipGroup(
|
|||||||
text = typeName
|
text = typeName
|
||||||
textSize = 22f
|
textSize = 22f
|
||||||
isCheckable = true
|
isCheckable = true
|
||||||
minWidth = 120.dp
|
textAlignment = View.TEXT_ALIGNMENT_CENTER
|
||||||
chipStartPadding = 15.dp.toFloat()
|
chipStartPadding = 15.dp.toFloat()
|
||||||
chipEndPadding = 15.dp.toFloat()
|
chipEndPadding = 15.dp.toFloat()
|
||||||
chipMinHeight = (textSize + 15.dp * 2).toFloat()
|
chipMinHeight = textSize + 15.dp * 2
|
||||||
// 选中/未选中态背景色:主题绿 / 浅灰
|
// 选中/未选中态背景色:主题绿 / 浅灰
|
||||||
chipBackgroundColor = ColorStateList(
|
chipBackgroundColor = ColorStateList(
|
||||||
arrayOf(
|
arrayOf(
|
||||||
@@ -146,7 +147,12 @@ fun buildSingleChoiceChipGroup(
|
|||||||
// 若当前项已有选中值则默认勾选对应选项
|
// 若当前项已有选中值则默认勾选对应选项
|
||||||
isChecked = (typeName == checkedType)
|
isChecked = (typeName == checkedType)
|
||||||
}
|
}
|
||||||
addView(chip)
|
// 先用 UNSPECIFIED 测出自然宽度,再取 max(自然宽, 120dp),实现"最小宽度 120dp"
|
||||||
|
chip.measure(
|
||||||
|
View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED),
|
||||||
|
View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED)
|
||||||
|
)
|
||||||
|
addView(chip, ViewGroup.LayoutParams(maxOf(120.dp, chip.measuredWidth), ViewGroup.LayoutParams.WRAP_CONTENT))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ package com.shuwei.dish.match.utils
|
|||||||
import android.os.Build
|
import android.os.Build
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
import com.shuwei.dish.match.utils.ext.roundedOneDecimalPlace
|
import com.shuwei.dish.match.utils.ext.roundedOneDecimalPlace
|
||||||
//import com.aithings.Weigher
|
|
||||||
import com.wabon.wbintelligenthardwaresdk.api.SensorScale
|
import com.wabon.wbintelligenthardwaresdk.api.SensorScale
|
||||||
import java.util.concurrent.ConcurrentHashMap
|
import java.util.concurrent.ConcurrentHashMap
|
||||||
|
|
||||||
@@ -11,16 +10,33 @@ typealias WeightCallback = (address: Int, state: Int, weight: Double) -> Unit
|
|||||||
|
|
||||||
object WeightUtil {
|
object WeightUtil {
|
||||||
private const val TAG = "WeightUtil"
|
private const val TAG = "WeightUtil"
|
||||||
const val STATE_STABLE = SensorScale.STATE_STABLE
|
// 使用字面量常量,避免在非 ARM 设备上触发 SensorScale 类加载
|
||||||
const val STATE_UNSTABLE = SensorScale.STATE_UNSTABLE
|
const val STATE_STABLE = 1
|
||||||
const val STATE_OVER_WEIGHT = SensorScale.STATE_OVER_WEIGHT
|
const val STATE_UNSTABLE = 0
|
||||||
|
const val STATE_OVER_WEIGHT = 2
|
||||||
|
|
||||||
var isConnected = false
|
var isConnected = false
|
||||||
|
/** 秤 SDK 是否可用;非 ARM 设备上为 false,所有秤操作将静默跳过 */
|
||||||
|
var isAvailable = false
|
||||||
val weightFuncMap: ConcurrentHashMap<String, WeightCallback?> = ConcurrentHashMap()
|
val weightFuncMap: ConcurrentHashMap<String, WeightCallback?> = ConcurrentHashMap()
|
||||||
|
|
||||||
fun init() {
|
fun init() {
|
||||||
SensorScale.isLog = true
|
val abi = Build.SUPPORTED_ABIS.firstOrNull() ?: ""
|
||||||
Weigher2.init()
|
if (!abi.startsWith("arm")) {
|
||||||
|
Log.w(TAG, "当前架构 $abi 不支持秤 SDK,已跳过初始化")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
SensorScale.isLog = true
|
||||||
|
Weigher2.init()
|
||||||
|
} catch (e: UnsatisfiedLinkError) {
|
||||||
|
Log.w(TAG, "秤 SDK 加载失败(非 ARM 设备),已跳过: ${e.message}")
|
||||||
|
return
|
||||||
|
} catch (e: Exception) {
|
||||||
|
Log.w(TAG, "秤 SDK 初始化异常,已跳过: ${e.message}")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
isAvailable = true
|
||||||
Weigher2.setListener(object : WeightListenerImpl() {
|
Weigher2.setListener(object : WeightListenerImpl() {
|
||||||
override fun onInit(connect: Boolean) {
|
override fun onInit(connect: Boolean) {
|
||||||
super.onInit(connect)
|
super.onInit(connect)
|
||||||
@@ -64,10 +80,12 @@ object WeightUtil {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun startContinuousRead() {
|
fun startContinuousRead() {
|
||||||
|
if (!isAvailable) return
|
||||||
Weigher2.startContinuousRead()
|
Weigher2.startContinuousRead()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun stopContinuousRead() {
|
fun stopContinuousRead() {
|
||||||
|
if (!isAvailable) return
|
||||||
try {
|
try {
|
||||||
Weigher2.stopContinuousRead()
|
Weigher2.stopContinuousRead()
|
||||||
Weigher2.unInit()
|
Weigher2.unInit()
|
||||||
|
|||||||
Reference in New Issue
Block a user