Compare commits
13
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e8735db27b | ||
|
|
e1e4bc5123 | ||
|
|
18f45e7821 | ||
|
|
1826ac0f60 | ||
|
|
d81381ae6f | ||
|
|
f35411a8a0 | ||
|
|
93b46e38d4 | ||
|
|
ba1a364ee8 | ||
|
|
50b1023a44 | ||
|
|
385ada4a0d | ||
|
|
ae708eeeed | ||
|
|
2886e7d4a3 | ||
|
|
66a0c399ec |
@@ -39,7 +39,7 @@ object GlobalData {
|
|||||||
* 具体业务 BaseUrl
|
* 具体业务 BaseUrl
|
||||||
*/
|
*/
|
||||||
const val TEST_BASE_URL: String = "http://192.168.1.201:14801"
|
const val TEST_BASE_URL: String = "http://192.168.1.201:14801"
|
||||||
const val UAT_BASE_URL: String = "https://dev.yixiong-tech.com:8081"
|
const val UAT_BASE_URL: String = "https://dev.yixiong-tech.com:8083"
|
||||||
const val PROD_BASE_URL: String = "https://api.dm.yixiong-tech.com:8443"
|
const val PROD_BASE_URL: String = "https://api.dm.yixiong-tech.com:8443"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -256,6 +256,7 @@ abstract class BaseActivity<VB : ViewBinding> : AppCompatActivity() {
|
|||||||
mDialogWaiting = CustomLoadingDialog(this, view, R.style.MyDialog)
|
mDialogWaiting = CustomLoadingDialog(this, view, R.style.MyDialog)
|
||||||
mDialogWaiting!!.show()
|
mDialogWaiting!!.show()
|
||||||
mDialogWaiting!!.setCancelable(true)
|
mDialogWaiting!!.setCancelable(true)
|
||||||
|
mDialogWaiting!!.setCanceledOnTouchOutside(true)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -54,7 +54,6 @@ import com.sw.platecabinet.utils.BitmapSaver
|
|||||||
import com.sw.platecabinet.utils.CountDownUtil
|
import com.sw.platecabinet.utils.CountDownUtil
|
||||||
import com.sw.platecabinet.utils.Debouncer
|
import com.sw.platecabinet.utils.Debouncer
|
||||||
import com.sw.platecabinet.utils.LogFileUtil
|
import com.sw.platecabinet.utils.LogFileUtil
|
||||||
import com.sw.platecabinet.utils.PlateUtils
|
|
||||||
import com.sw.platecabinet.utils.RegisterCallbackHandler
|
import com.sw.platecabinet.utils.RegisterCallbackHandler
|
||||||
import com.sw.platecabinet.utils.SoundPoolUtil
|
import com.sw.platecabinet.utils.SoundPoolUtil
|
||||||
import com.sw.platecabinet.utils.mego.PlcCallback
|
import com.sw.platecabinet.utils.mego.PlcCallback
|
||||||
@@ -95,15 +94,16 @@ class LoginByFaceActivity : BaseActivity<ActivityLoginFaceBinding>(),
|
|||||||
override fun initialize() {
|
override fun initialize() {
|
||||||
userViewModel.activeEngine()
|
userViewModel.activeEngine()
|
||||||
|
|
||||||
PlcHelper.getInstance(this).openSerialPort(object : PlcCallback<String> {
|
PlcHelper.getInstance(this@LoginByFaceActivity)
|
||||||
override fun onSuccess(result: String) {
|
.openSerialPort(object : PlcCallback<String> {
|
||||||
ToastUtils.showToast("打开串口 → 成功: ${result}")
|
override fun onSuccess(result: String) {
|
||||||
}
|
ToastUtils.showToast("打开串口 → 成功: ${result}")
|
||||||
|
}
|
||||||
|
|
||||||
override fun onError(message: String) {
|
override fun onError(message: String) {
|
||||||
ToastUtils.showToast("打开串口 → 失败: $message")
|
ToastUtils.showToast("打开串口 → 失败: $message")
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
initArcViewModel()
|
initArcViewModel()
|
||||||
initArcView()
|
initArcView()
|
||||||
@@ -221,6 +221,7 @@ class LoginByFaceActivity : BaseActivity<ActivityLoginFaceBinding>(),
|
|||||||
private fun isFitData(userFaceInfo: UserFaceInfo?): Boolean {
|
private fun isFitData(userFaceInfo: UserFaceInfo?): Boolean {
|
||||||
if (userFaceInfo == null) return false
|
if (userFaceInfo == null) return false
|
||||||
val headBmp = userFaceInfo.headBmp
|
val headBmp = userFaceInfo.headBmp
|
||||||
|
loadLogInfo("collectFace,isFitData:w=${headBmp?.width},height=${headBmp?.height}")
|
||||||
if (headBmp == null) return false
|
if (headBmp == null) return false
|
||||||
// if (headBmp.width <= 200 || headBmp.height <= 200) {
|
// if (headBmp.width <= 200 || headBmp.height <= 200) {
|
||||||
// loadLogInfo("collectFace,isFitData:拿到人脸提取特征数据照片过小-----------")
|
// loadLogInfo("collectFace,isFitData:拿到人脸提取特征数据照片过小-----------")
|
||||||
@@ -234,9 +235,12 @@ class LoginByFaceActivity : BaseActivity<ActivityLoginFaceBinding>(),
|
|||||||
recognizeViewModel.prepareRegister()
|
recognizeViewModel.prepareRegister()
|
||||||
recognizeViewModel.setOnRegisterFinishedCallback { facePreviewInfo, userFaceInfo ->
|
recognizeViewModel.setOnRegisterFinishedCallback { facePreviewInfo, userFaceInfo ->
|
||||||
registerHandler?.setCallback {
|
registerHandler?.setCallback {
|
||||||
|
loadLogInfo("collectFace,registerHandler?.setCallback")
|
||||||
if (!isCollectFace || !isCollecting.get()) {
|
if (!isCollectFace || !isCollecting.get()) {
|
||||||
|
loadLogInfo("collectFace,isCollectFace=${isCollectFace},isCollecting=${isCollecting.get()}")
|
||||||
return@setCallback
|
return@setCallback
|
||||||
}
|
}
|
||||||
|
loadLogInfo("collectFace,userFaceInfo==null:${userFaceInfo==null}")
|
||||||
if (this.userFaceInfo == null && isFitData(userFaceInfo)) {
|
if (this.userFaceInfo == null && isFitData(userFaceInfo)) {
|
||||||
val headBmp = userFaceInfo.headBmp ?: run {
|
val headBmp = userFaceInfo.headBmp ?: run {
|
||||||
loadLogInfo("collectFace,isFitData:headBmp 为 null,跳过")
|
loadLogInfo("collectFace,isFitData:headBmp 为 null,跳过")
|
||||||
@@ -295,7 +299,7 @@ class LoginByFaceActivity : BaseActivity<ActivityLoginFaceBinding>(),
|
|||||||
}
|
}
|
||||||
|
|
||||||
recognizeViewModel.recognizeUserId.observe(this) { result: CompareResult? ->
|
recognizeViewModel.recognizeUserId.observe(this) { result: CompareResult? ->
|
||||||
loadLogInfo("collectFace,recognizeUserId observe userId = ${result?.faceEntity?.userName}")
|
loadLogInfo("collectFace,recognizeUserId observe userId=${result?.faceEntity?.userName},similar=${result?.similar},userType=${result?.faceEntity?.userType}")
|
||||||
loadFaceRecognizeResult3(result)
|
loadFaceRecognizeResult3(result)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -319,7 +323,7 @@ class LoginByFaceActivity : BaseActivity<ActivityLoginFaceBinding>(),
|
|||||||
*/
|
*/
|
||||||
private val faceSuccessThreshold by lazy { ConfigUtil.getRecognizeThreshold(this) }
|
private val faceSuccessThreshold by lazy { ConfigUtil.getRecognizeThreshold(this) }
|
||||||
|
|
||||||
private val openPlateDebouncer = Debouncer(5000)
|
private val openPlateDebouncer = Debouncer(3000)
|
||||||
private val isCollecting = AtomicBoolean(false)
|
private val isCollecting = AtomicBoolean(false)
|
||||||
|
|
||||||
private fun loadFaceRecognizeResult3(result: CompareResult?) {
|
private fun loadFaceRecognizeResult3(result: CompareResult?) {
|
||||||
@@ -371,7 +375,7 @@ class LoginByFaceActivity : BaseActivity<ActivityLoginFaceBinding>(),
|
|||||||
currentUserId = userId
|
currentUserId = userId
|
||||||
|
|
||||||
// 防抖,防止重复开闸
|
// 防抖,防止重复开闸
|
||||||
openPlateDebouncer.debounce {
|
openPlateDebouncer.debounce("openPlateDebouncer") {
|
||||||
openPlate(userId)
|
openPlate(userId)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -400,55 +404,73 @@ class LoginByFaceActivity : BaseActivity<ActivityLoginFaceBinding>(),
|
|||||||
text = "新用户采集"
|
text = "新用户采集"
|
||||||
}
|
}
|
||||||
binding.ivCollectPhoto.gone()
|
binding.ivCollectPhoto.gone()
|
||||||
|
openPlateDebouncer.reset()
|
||||||
|
plateEnable = true
|
||||||
resumeCamera()
|
resumeCamera()
|
||||||
}
|
}
|
||||||
|
|
||||||
private var plateEnable = false
|
private var plateEnable = false
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 打开餐盘柜:先获取 PLC 状态,有盘则出盘,无盘则播放提示音
|
* 打开餐盘柜:执行出盘,出盘后查询剩余餐盘状态并播放对应提示音
|
||||||
*/
|
*/
|
||||||
private fun openPlate(userId: String?) {
|
private fun openPlate(userId: String?) {
|
||||||
|
loadLogInfo("collectFace,openPlate: userId=$userId,plateEnable=$plateEnable")
|
||||||
if (plateEnable.not()) return
|
if (plateEnable.not()) return
|
||||||
loadLogInfo("collectFace,openPlate: userId=$userId")
|
|
||||||
showWaitingDialog("检测餐盘中,请稍候……")
|
PlcHelper.getInstance(this@LoginByFaceActivity)
|
||||||
PlcHelper.getInstance(this).getStatus(object : PlcCallback<PlcStatus> {
|
.outPlate(object : PlcCallback<String> {
|
||||||
override fun onSuccess(result: PlcStatus) {
|
override fun onSuccess(result: String) {
|
||||||
hideWaitingDialog()
|
plateEnable = false
|
||||||
if (result.isEmptyPlate) {
|
recognizeCountDownUtil.cancelCountDown()
|
||||||
// 无餐盘,播放提示音并返回首页
|
// result 为 false 时表示出盘后无餐盘,直接播放无盘提示音
|
||||||
loadLogInfo("collectFace,openPlate: 暂无餐盘,isEmptyPlate=true,isCollectFace=$isCollectFace")
|
if (result.equals("false", ignoreCase = true)) {
|
||||||
SoundPoolUtil.getInstance().play(NO_PLATE_REMIND, 0)
|
loadLogInfo("collectFace,openPlate: result=false,餐盘已空")
|
||||||
goInitActivity()
|
SoundPoolUtil.getInstance().play(NO_PLATE_REMIND, 0)
|
||||||
return
|
goInitActivity()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
loadLogInfo("collectFace,openPlate: 出盘完成,result=$result,开始查询剩余餐盘")
|
||||||
|
// result 为 true,出盘成功,再查询是否还有剩余餐盘
|
||||||
|
SoundPoolUtil.getInstance().play(RECOGNIZE_SUCCESS, 0)
|
||||||
|
checkRemainingPlate()
|
||||||
}
|
}
|
||||||
// 有餐盘,播放识别成功音效并调用出盘
|
|
||||||
loadLogInfo("collectFace,openPlate: 检测到餐盘,开始出盘")
|
|
||||||
SoundPoolUtil.getInstance().play(RECOGNIZE_SUCCESS, 0)
|
|
||||||
plateEnable = false
|
|
||||||
recognizeCountDownUtil.cancelCountDown()
|
|
||||||
PlcHelper.getInstance(this@LoginByFaceActivity)
|
|
||||||
.outPlate(object : PlcCallback<String> {
|
|
||||||
override fun onSuccess(result: String) {
|
|
||||||
loadLogInfo("collectFace,openPlate: 出盘成功,result=$result")
|
|
||||||
goInitActivity()
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onError(message: String) {
|
override fun onError(message: String) {
|
||||||
loadLogInfo("collectFace,openPlate: 出盘失败,message=$message")
|
ToastUtils.showToast("出盘失败,message=$message")
|
||||||
goInitActivity()
|
loadLogInfo("collectFace,openPlate: 出盘失败,message=$message")
|
||||||
}
|
goInitActivity()
|
||||||
})
|
}
|
||||||
}
|
})
|
||||||
|
}
|
||||||
|
|
||||||
override fun onError(message: String) {
|
/**
|
||||||
hideWaitingDialog()
|
* 出盘成功后查询剩余餐盘状态,无盘则播放提示音
|
||||||
// 状态获取失败,保底播放无盘提示
|
*/
|
||||||
loadLogInfo("collectFace,openPlate: 获取PLC状态失败,message=$message")
|
private fun checkRemainingPlate() {
|
||||||
SoundPoolUtil.getInstance().play(NO_PLATE_REMIND, 0)
|
PlcHelper.getInstance(this@LoginByFaceActivity)
|
||||||
goInitActivity()
|
.getStatus(object : PlcCallback<PlcStatus> {
|
||||||
}
|
override fun onSuccess(result: PlcStatus) {
|
||||||
})
|
if (isFinishing || isDestroyed) return
|
||||||
|
loadLogInfo("collectFace,checkRemainingPlate: isEmptyPlate=${result.isEmptyPlate}")
|
||||||
|
if (result.isEmptyPlate) {
|
||||||
|
// 餐盘已空,播放无盘提示音
|
||||||
|
SoundPoolUtil.getInstance().play(NO_PLATE_REMIND, 0)
|
||||||
|
//跳转到餐盘设置页面
|
||||||
|
PlcSettingActivity.start(this@LoginByFaceActivity, showTips = true)
|
||||||
|
} else {
|
||||||
|
loadLogInfo("collectFace,checkRemainingPlate: 剩余餐盘,继续使用")
|
||||||
|
goInitActivity()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onError(message: String) {
|
||||||
|
if (isFinishing || isDestroyed) return
|
||||||
|
// 状态查询失败,不影响主流程,直接跳转
|
||||||
|
loadLogInfo("collectFace,checkRemainingPlate: 获取PLC状态失败,message=$message")
|
||||||
|
goInitActivity()
|
||||||
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
private val openDebouncer by lazy { Debouncer(5000) }
|
private val openDebouncer by lazy { Debouncer(5000) }
|
||||||
@@ -467,6 +489,8 @@ class LoginByFaceActivity : BaseActivity<ActivityLoginFaceBinding>(),
|
|||||||
|
|
||||||
recognizeViewModel.destroy()
|
recognizeViewModel.destroy()
|
||||||
|
|
||||||
|
PlcHelper.getInstance(this@LoginByFaceActivity).release()
|
||||||
|
|
||||||
EventBus.getDefault().unregister(this)
|
EventBus.getDefault().unregister(this)
|
||||||
super.onDestroy()
|
super.onDestroy()
|
||||||
}
|
}
|
||||||
@@ -598,9 +622,10 @@ class LoginByFaceActivity : BaseActivity<ActivityLoginFaceBinding>(),
|
|||||||
binding.btnCollect.tag = ""
|
binding.btnCollect.tag = ""
|
||||||
binding.tvSimilarValue.text = ""
|
binding.tvSimilarValue.text = ""
|
||||||
retryFailCount = 0
|
retryFailCount = 0
|
||||||
|
// 人脸离开时,发送空帧清除 ViewModel 内部识别缓存,防止再次进入时使用旧数据
|
||||||
|
recognizeViewModel.onPreviewFrame(emptyFrame, true)
|
||||||
if (binding.llCollectButton.isVisible) {
|
if (binding.llCollectButton.isVisible) {
|
||||||
leftDebouncer.debounce { leftCountDown() }
|
leftDebouncer.debounce("leftDebouncer") { leftCountDown() }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
recognizeViewModel.clearLeftFace(facePreviewInfoList)
|
recognizeViewModel.clearLeftFace(facePreviewInfoList)
|
||||||
@@ -724,6 +749,7 @@ class LoginByFaceActivity : BaseActivity<ActivityLoginFaceBinding>(),
|
|||||||
// private var tempUserId: String = ""
|
// private var tempUserId: String = ""
|
||||||
override fun onResume() {
|
override fun onResume() {
|
||||||
super.onResume()
|
super.onResume()
|
||||||
|
plateEnable = true
|
||||||
try {
|
try {
|
||||||
if (isFirstOpen) {
|
if (isFirstOpen) {
|
||||||
isFirstOpen = false
|
isFirstOpen = false
|
||||||
@@ -764,6 +790,9 @@ class LoginByFaceActivity : BaseActivity<ActivityLoginFaceBinding>(),
|
|||||||
plateEnable = true
|
plateEnable = true
|
||||||
collectCount = 0
|
collectCount = 0
|
||||||
// tempUserId = "${System.currentTimeMillis()}"
|
// tempUserId = "${System.currentTimeMillis()}"
|
||||||
|
openPlateDebouncer.reset()
|
||||||
|
// 清空上次识别结果和 FaceHelper 内部状态,防止短时间内再次识别无法触发
|
||||||
|
recognizeViewModel.resetFaceState()
|
||||||
resumeCamera()
|
resumeCamera()
|
||||||
registerHandler = RegisterCallbackHandler()
|
registerHandler = RegisterCallbackHandler()
|
||||||
|
|
||||||
@@ -772,13 +801,13 @@ class LoginByFaceActivity : BaseActivity<ActivityLoginFaceBinding>(),
|
|||||||
lifecycleScope = lifecycleScope,
|
lifecycleScope = lifecycleScope,
|
||||||
onTick = { remaining ->
|
onTick = { remaining ->
|
||||||
loadLogInfo("resetRecognizeState剩余时间:$remaining 秒")
|
loadLogInfo("resetRecognizeState剩余时间:$remaining 秒")
|
||||||
if (judgeRecognizeState()) return@startCountDown
|
// if (judgeRecognizeState()) return@startCountDown
|
||||||
loadLogInfo("initCountTime onTick = $remaining")
|
loadLogInfo("initCountTime onTick = $remaining")
|
||||||
binding.tvToInit.text = "$remaining"
|
binding.tvToInit.text = "$remaining"
|
||||||
},
|
},
|
||||||
onFinish = {
|
onFinish = {
|
||||||
loadLogInfo("resetRecognizeState倒计时结束")
|
loadLogInfo("resetRecognizeState倒计时结束")
|
||||||
if (judgeRecognizeState()) return@startCountDown
|
// if (judgeRecognizeState()) return@startCountDown
|
||||||
if (facePreviewInfoList.isNullOrEmpty()) {
|
if (facePreviewInfoList.isNullOrEmpty()) {
|
||||||
goInitActivity()
|
goInitActivity()
|
||||||
} else {
|
} else {
|
||||||
@@ -799,23 +828,23 @@ class LoginByFaceActivity : BaseActivity<ActivityLoginFaceBinding>(),
|
|||||||
|
|
||||||
private fun pauseCamera() {
|
private fun pauseCamera() {
|
||||||
isRecognition = false
|
isRecognition = false
|
||||||
// recognizeViewModel.onPreviewFrame(emptyFrame, true)
|
recognizeViewModel.onPreviewFrame(emptyFrame, true)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun judgeRecognizeState(): Boolean {
|
// private fun judgeRecognizeState(): Boolean {
|
||||||
val rectColor = binding.dualCameraFaceRectView.rectColor
|
// val rectColor = binding.dualCameraFaceRectView.rectColor
|
||||||
if (rectColor == RecognizeColor.COLOR_SUCCESS && currentUserId.isNullOrBlank()
|
// if (rectColor == RecognizeColor.COLOR_SUCCESS && currentUserId.isNullOrBlank()
|
||||||
.not() && facePreviewInfoList.isNullOrEmpty().not()
|
// .not() && facePreviewInfoList.isNullOrEmpty().not()
|
||||||
) {
|
// ) {
|
||||||
//人未离开,再次识别
|
// //人未离开,再次识别
|
||||||
loadLogInfo("userId=$currentUserId")
|
// loadLogInfo("userId=$currentUserId")
|
||||||
openPlateDebouncer.debounce {
|
// openPlateDebouncer.debounce {
|
||||||
openPlate(currentUserId)
|
// openPlate(currentUserId)
|
||||||
}
|
// }
|
||||||
return true
|
// return true
|
||||||
}
|
// }
|
||||||
return false
|
// return false
|
||||||
}
|
// }
|
||||||
|
|
||||||
fun goInitActivity() {
|
fun goInitActivity() {
|
||||||
val intent = Intent(context, InitActivity::class.java)
|
val intent = Intent(context, InitActivity::class.java)
|
||||||
@@ -852,7 +881,7 @@ class LoginByFaceActivity : BaseActivity<ActivityLoginFaceBinding>(),
|
|||||||
ToastUtils.showToast("获取人脸照片失败")
|
ToastUtils.showToast("获取人脸照片失败")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
uploadFaceDebouncer.debounce {
|
uploadFaceDebouncer.debounce("uploadFaceDebouncer") {
|
||||||
addUserFace(faceData, imageFile)
|
addUserFace(faceData, imageFile)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,7 +3,9 @@ package com.sw.platecabinet.activity
|
|||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.view.inputmethod.InputMethodManager
|
import android.view.inputmethod.InputMethodManager
|
||||||
|
import androidx.lifecycle.lifecycleScope
|
||||||
import com.sw.plate.utils.ToastUtils
|
import com.sw.plate.utils.ToastUtils
|
||||||
|
import com.sw.plate.utils.arcface.faceserver.FaceServer
|
||||||
import com.sw.platecabinet.databinding.ActivityPlcSettingBinding
|
import com.sw.platecabinet.databinding.ActivityPlcSettingBinding
|
||||||
import com.sw.platecabinet.databinding.ItemTitleTimeBinding
|
import com.sw.platecabinet.databinding.ItemTitleTimeBinding
|
||||||
import com.sw.platecabinet.dialog.EnvSwitchDialog
|
import com.sw.platecabinet.dialog.EnvSwitchDialog
|
||||||
@@ -11,6 +13,9 @@ import com.sw.platecabinet.ext.clickWithDebounce
|
|||||||
import com.sw.platecabinet.utils.mego.PlcCallback
|
import com.sw.platecabinet.utils.mego.PlcCallback
|
||||||
import com.sw.platecabinet.utils.mego.PlcHelper
|
import com.sw.platecabinet.utils.mego.PlcHelper
|
||||||
import com.sw.platecabinet.utils.mego.PlcStatus
|
import com.sw.platecabinet.utils.mego.PlcStatus
|
||||||
|
import kotlinx.coroutines.Dispatchers
|
||||||
|
import kotlinx.coroutines.launch
|
||||||
|
import kotlinx.coroutines.withContext
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* PLC 控制设置界面
|
* PLC 控制设置界面
|
||||||
@@ -19,14 +24,21 @@ import com.sw.platecabinet.utils.mego.PlcStatus
|
|||||||
class PlcSettingActivity : BaseActivity<ActivityPlcSettingBinding>() {
|
class PlcSettingActivity : BaseActivity<ActivityPlcSettingBinding>() {
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
/** Intent Extra 键:是否显示 tips 界面 */
|
||||||
|
private const val EXTRA_SHOW_TIPS = "extra_show_tips"
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 启动 PlcSettingActivity
|
* 启动 PlcSettingActivity
|
||||||
|
* @param showTips 是否显示 tips 界面(暂无餐盘提示)
|
||||||
*/
|
*/
|
||||||
fun start(context: Context) {
|
fun start(context: Context, showTips: Boolean = false) {
|
||||||
context.startActivity(Intent(context, PlcSettingActivity::class.java))
|
val intent = Intent(context, PlcSettingActivity::class.java)
|
||||||
|
intent.putExtra(EXTRA_SHOW_TIPS, showTips)
|
||||||
|
context.startActivity(intent)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
override fun inflateViewBinding(): ActivityPlcSettingBinding {
|
override fun inflateViewBinding(): ActivityPlcSettingBinding {
|
||||||
return ActivityPlcSettingBinding.inflate(layoutInflater)
|
return ActivityPlcSettingBinding.inflate(layoutInflater)
|
||||||
}
|
}
|
||||||
@@ -36,14 +48,40 @@ class PlcSettingActivity : BaseActivity<ActivityPlcSettingBinding>() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun initialize() {
|
override fun initialize() {
|
||||||
|
// 根据传入参数控制 tips 界面显示
|
||||||
|
val showTips = intent.getBooleanExtra(EXTRA_SHOW_TIPS, false)
|
||||||
|
binding.layoutTips.visibility =
|
||||||
|
if (showTips) android.view.View.VISIBLE else android.view.View.GONE
|
||||||
|
|
||||||
initConnectButtons()
|
initConnectButtons()
|
||||||
initOutPlateButton()
|
initOutPlateButton()
|
||||||
initPlatformButtons()
|
initPlatformButtons()
|
||||||
|
initPlatformResetButton()
|
||||||
initAlarmButton()
|
initAlarmButton()
|
||||||
initParamButtons()
|
initParamButtons()
|
||||||
initStatusButton()
|
initStatusButton()
|
||||||
binding.btnSwitchEnv.setOnClickListener {
|
binding.btnSwitchEnv.setOnClickListener {
|
||||||
EnvSwitchDialog(this).show()
|
EnvSwitchDialog(context = this, onEnvChanged = {
|
||||||
|
showWaitingDialog("重置人脸数据中……")
|
||||||
|
lifecycleScope.launch {
|
||||||
|
withContext(Dispatchers.IO) {
|
||||||
|
FaceServer.getInstance().clearAllFaces()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
userViewModel.getUserFaceCache(pageNo = 1, callback = { state, errMsg ->
|
||||||
|
hideWaitingDialog()
|
||||||
|
if (state) {
|
||||||
|
recognizeViewModel.refreshFaceList()
|
||||||
|
ToastUtils.showToast("人脸数据已更新")
|
||||||
|
} else {
|
||||||
|
ToastUtils.showToast(errMsg)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}).show()
|
||||||
|
}
|
||||||
|
|
||||||
|
binding.tvTips.clickWithDebounce {
|
||||||
|
binding.layoutTips.visibility = android.view.View.GONE
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -161,6 +199,38 @@ class PlcSettingActivity : BaseActivity<ActivityPlcSettingBinding>() {
|
|||||||
|
|
||||||
// ==================== 故障处理 ====================
|
// ==================== 故障处理 ====================
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 初始化平台复位按钮:先执行平台上升,成功后自动执行返回营业
|
||||||
|
*/
|
||||||
|
private fun initPlatformResetButton() {
|
||||||
|
binding.btnPlatformReset.clickWithDebounce {
|
||||||
|
showWaitingDialog("正在复位平台……")
|
||||||
|
PlcHelper.getInstance(this).platformUp(object : PlcCallback<String> {
|
||||||
|
override fun onSuccess(result: String) {
|
||||||
|
// 平台上升完成,继续执行返回营业
|
||||||
|
PlcHelper.getInstance(this@PlcSettingActivity)
|
||||||
|
.backToBusiness(object : PlcCallback<String> {
|
||||||
|
override fun onSuccess(result: String) {
|
||||||
|
hideWaitingDialog()
|
||||||
|
ToastUtils.showToast("平台复位成功")
|
||||||
|
finish()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onError(message: String) {
|
||||||
|
hideWaitingDialog()
|
||||||
|
ToastUtils.showToast("返回营业失败:$message")
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onError(message: String) {
|
||||||
|
hideWaitingDialog()
|
||||||
|
ToastUtils.showToast("平台上升失败:$message")
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 初始化故障复位按钮
|
* 初始化故障复位按钮
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -1,6 +1,11 @@
|
|||||||
package com.sw.platecabinet.utils
|
package com.sw.platecabinet.utils
|
||||||
|
|
||||||
|
import timber.log.Timber
|
||||||
|
|
||||||
class Debouncer(private val delayMillis: Long) {
|
class Debouncer(private val delayMillis: Long) {
|
||||||
|
companion object {
|
||||||
|
const val TAG = "Debouncer"
|
||||||
|
}
|
||||||
private var lastActionTime = 0L
|
private var lastActionTime = 0L
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -8,13 +13,15 @@ class Debouncer(private val delayMillis: Long) {
|
|||||||
* @param action 要执行的操作
|
* @param action 要执行的操作
|
||||||
* @return Boolean 是否执行了操作 (true=已执行, false=被防抖)
|
* @return Boolean 是否执行了操作 (true=已执行, false=被防抖)
|
||||||
*/
|
*/
|
||||||
fun debounce(action: () -> Unit): Boolean {
|
fun debounce(tag:String = TAG, action: () -> Unit): Boolean {
|
||||||
val currentTime = System.currentTimeMillis()
|
val currentTime = System.currentTimeMillis()
|
||||||
if (currentTime - lastActionTime >= delayMillis) {
|
if (currentTime - lastActionTime >= delayMillis) {
|
||||||
|
Timber.tag(tag).d("collectFace,recognizeUserId防止重复操作:执行action回调")
|
||||||
lastActionTime = currentTime
|
lastActionTime = currentTime
|
||||||
action()
|
action()
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
Timber.tag(tag).d("collectFace,recognizeUserId防止重复操作-----------------------")
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -19,10 +19,15 @@ import java.io.StringReader;
|
|||||||
import java.text.DecimalFormat;
|
import java.text.DecimalFormat;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.concurrent.ExecutorService;
|
||||||
|
import java.util.concurrent.Executors;
|
||||||
|
|
||||||
public class LogFileUtil {
|
public class LogFileUtil {
|
||||||
private static boolean isSaveLog = true;
|
private static boolean isSaveLog = true;
|
||||||
public static final String FILE_STR_PATH = App.getContext().getExternalCacheDir().getAbsolutePath();
|
// 使用内部存储,不会被系统缓存清理策略影响
|
||||||
|
public static final String FILE_STR_PATH = new File(App.getContext().getFilesDir(), "logs").getAbsolutePath();
|
||||||
|
// 单线程执行器,保证日志串行写入,避免多线程并发竞争
|
||||||
|
private static final ExecutorService LOG_EXECUTOR = Executors.newSingleThreadExecutor();
|
||||||
|
|
||||||
public static final int SIZETYPE_B = 1;//获取文件大小单位为B的double值
|
public static final int SIZETYPE_B = 1;//获取文件大小单位为B的double值
|
||||||
public static final int SIZETYPE_KB = 2;//获取文件大小单位为KB的double值
|
public static final int SIZETYPE_KB = 2;//获取文件大小单位为KB的double值
|
||||||
@@ -610,24 +615,20 @@ public class LogFileUtil {
|
|||||||
if (!isSaveLog) {
|
if (!isSaveLog) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
new Thread() {
|
// 提交到单线程队列,串行执行,避免并发写入竞争
|
||||||
@Override
|
LOG_EXECUTOR.execute(() -> {
|
||||||
public void run() {
|
StringBuilder sb = new StringBuilder();
|
||||||
super.run();
|
for (String log : logs) {
|
||||||
StringBuilder sb = new StringBuilder();
|
sb.append("===")
|
||||||
for (String log : logs) {
|
.append((AppUtil.formatDateGetCurrentTime()))
|
||||||
sb.append("===")
|
.append("===")
|
||||||
.append((AppUtil.formatDateGetCurrentTime()))
|
.append("\n")
|
||||||
.append("===")
|
.append(log)
|
||||||
.append("\n")
|
.append("\n");
|
||||||
.append(log)
|
|
||||||
.append("\n");
|
|
||||||
}
|
|
||||||
String fileName = "log" + AppUtil.formatDateGetDay(System.currentTimeMillis()) + ".txt";
|
|
||||||
LogFileUtil.saveStrFile(sb.toString(), fileName, FILE_STR_PATH, true);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}.start();
|
String fileName = "log" + AppUtil.formatDateGetDay(System.currentTimeMillis()) + ".txt";
|
||||||
|
LogFileUtil.saveStrFile(sb.toString(), fileName, FILE_STR_PATH, true);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final String[][] MIME_MapTable = {
|
private static final String[][] MIME_MapTable = {
|
||||||
|
|||||||
@@ -64,7 +64,7 @@ class UserViewModel : BaseViewModel() {
|
|||||||
SPUtil.getInstance().put(GlobalKey.KEY_FIRST_RUN, true)
|
SPUtil.getInstance().put(GlobalKey.KEY_FIRST_RUN, true)
|
||||||
val list: List<UserFaceModel> = response.data ?: emptyList()
|
val list: List<UserFaceModel> = response.data ?: emptyList()
|
||||||
if (pageNo == 1 && list.isEmpty()) {
|
if (pageNo == 1 && list.isEmpty()) {
|
||||||
callback(true, "暂无数据")
|
callback(false, "暂无数据")
|
||||||
return@launchWithLoading
|
return@launchWithLoading
|
||||||
}
|
}
|
||||||
val faceEntityList = list.map {
|
val faceEntityList = list.map {
|
||||||
|
|||||||
@@ -11,6 +11,29 @@
|
|||||||
android:id="@+id/includeHeader"
|
android:id="@+id/includeHeader"
|
||||||
layout="@layout/item_title_time" />
|
layout="@layout/item_title_time" />
|
||||||
|
|
||||||
|
<RelativeLayout
|
||||||
|
android:id="@+id/layout_tips"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="match_parent">
|
||||||
|
|
||||||
|
<ImageView
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_centerInParent="true"
|
||||||
|
android:src="@mipmap/img_error_tips"
|
||||||
|
tools:ignore="ContentDescription" />
|
||||||
|
|
||||||
|
<TextView android:id="@+id/tv_tips"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_alignParentBottom="true"
|
||||||
|
android:layout_centerHorizontal="true"
|
||||||
|
android:layout_marginBottom="144dp"
|
||||||
|
android:text="暂无餐盘 请联系管理人员"
|
||||||
|
android:textColor="#fff0c8b4"
|
||||||
|
android:textSize="32sp" />
|
||||||
|
</RelativeLayout>
|
||||||
|
|
||||||
<ScrollView
|
<ScrollView
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="0dp"
|
android:layout_height="0dp"
|
||||||
@@ -143,6 +166,17 @@
|
|||||||
android:textColor="#FFCC99"
|
android:textColor="#FFCC99"
|
||||||
android:textSize="22sp" />
|
android:textSize="22sp" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/btnPlatformReset"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="60dp"
|
||||||
|
android:layout_marginTop="12dp"
|
||||||
|
android:background="@drawable/btn_outline"
|
||||||
|
android:gravity="center"
|
||||||
|
android:text="餐盘平台复位"
|
||||||
|
android:textColor="#FFCC99"
|
||||||
|
android:textSize="22sp" />
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
|
|||||||
Binary file not shown.
|
After Width: | Height: | Size: 179 KiB |
@@ -343,6 +343,14 @@ public class FaceHelper implements FaceListener {
|
|||||||
refreshTrackId(faceInfoList);
|
refreshTrackId(faceInfoList);
|
||||||
if (faceInfoList.isEmpty()) {
|
if (faceInfoList.isEmpty()) {
|
||||||
return facePreviewInfoList;
|
return facePreviewInfoList;
|
||||||
|
} else {
|
||||||
|
FaceInfo currentFaceInfo = faceInfoList.get(0);
|
||||||
|
// L.e("currentFaceInfo width=" + currentFaceInfo.getRect().width() +
|
||||||
|
// "---height" + currentFaceInfo.getRect().height());
|
||||||
|
if (currentFaceInfo.getRect().width() < 200) {//距离远(人脸小),不识别
|
||||||
|
clearLeftFace(facePreviewInfoList);
|
||||||
|
return facePreviewInfoList;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (!onlyDetectLiveness) {
|
if (!onlyDetectLiveness) {
|
||||||
code = ftEngine.process(rgbNv21, previewSize.width, previewSize.height, FaceEngine.CP_PAF_NV21, faceInfoList,
|
code = ftEngine.process(rgbNv21, previewSize.width, previewSize.height, FaceEngine.CP_PAF_NV21, faceInfoList,
|
||||||
|
|||||||
@@ -397,6 +397,20 @@ public class RecognizeViewModel extends ViewModel implements RecognizeCallback {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 重置人脸识别状态:清空上次识别结果及 FaceHelper 内部的 recognizeInfoMap,
|
||||||
|
* 使下一帧进入时能重新触发识别流程。
|
||||||
|
* 适用场景:短时间内再次识别、点击重试按钮等需要重新开始识别的时机。
|
||||||
|
*/
|
||||||
|
public void resetFaceState() {
|
||||||
|
// 清空粘性 LiveData,防止旧结果被重新投递给 observer
|
||||||
|
recognizeUserId.postValue(null);
|
||||||
|
// 清空 FaceHelper 内部所有人脸状态,让 trackId 对应的状态回到 TO_RETRY
|
||||||
|
if (faceHelper != null) {
|
||||||
|
faceHelper.clearFacePreviewInfoList();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 释放操作
|
* 释放操作
|
||||||
*/
|
*/
|
||||||
|
|||||||
Reference in New Issue
Block a user