优化
This commit is contained in:
@@ -425,7 +425,7 @@ abstract class BaseActivity<VB : ViewBinding> : AppCompatActivity() {
|
||||
// private val initialDelay = 5 * 60 * 1000L
|
||||
// private val dealyMillis = 10 * 60 * 1000L
|
||||
private val initialDelay = 1 * 60 * 1000L
|
||||
private val dealyMillis = 1 * 60 * 1000L
|
||||
private val dealyMillis = 5 * 60 * 1000L
|
||||
private var taskPageNo = 1
|
||||
fun startFaceTask() {
|
||||
faceTaskJob =
|
||||
|
||||
@@ -53,37 +53,37 @@ class DeviceInitActivity : BaseActivity<ActivityDeviceInitBinding>() {
|
||||
// }, 1000)
|
||||
initPlateList()
|
||||
showWaitingDialog("加载中……")
|
||||
clearAllFace {
|
||||
viewModel.getUserFaceCache()
|
||||
viewModel.getDeviceConfig { deviceConfig ->
|
||||
runOnUiThread {
|
||||
if (deviceConfig == null) {
|
||||
hideWaitingDialog()
|
||||
ToastUtils.showToast("获取设备配置数据失败")
|
||||
hideWaitingDialog()
|
||||
goLoginActivity()
|
||||
return@runOnUiThread
|
||||
}
|
||||
GlobalData.appId = deviceConfig.arcsoftAppId ?: ""
|
||||
GlobalData.sdkKey = deviceConfig.arcsoftSdkKey ?: ""
|
||||
GlobalData.activeKey = deviceConfig.arcsoftActiveKey ?: ""
|
||||
binding.root.postDelayed({
|
||||
hideWaitingDialog()
|
||||
goLoginActivity()
|
||||
}, 500)
|
||||
}
|
||||
}
|
||||
}
|
||||
// goLoginActivity()
|
||||
}
|
||||
|
||||
private fun clearAllFace(block: () -> Unit) {
|
||||
Thread {
|
||||
val faceDao = FaceDatabase.getInstance(App.getContext()).faceDao()
|
||||
faceDao.deleteAll()
|
||||
faceDao.resetId()
|
||||
// runOnUiThread {
|
||||
// viewModel.getUserFaceCache {
|
||||
// recognizeViewModel.refreshFaceList()
|
||||
// }
|
||||
// }
|
||||
runOnUiThread { block() }
|
||||
}.start()
|
||||
viewModel.getUserFaceCache()
|
||||
viewModel.getDeviceConfig { deviceConfig ->
|
||||
runOnUiThread {
|
||||
if (deviceConfig == null) {
|
||||
hideWaitingDialog()
|
||||
ToastUtils.showToast("获取设备配置数据失败")
|
||||
hideWaitingDialog()
|
||||
goLoginActivity()
|
||||
return@runOnUiThread
|
||||
}
|
||||
GlobalData.appId = deviceConfig.arcsoftAppId ?: ""
|
||||
GlobalData.sdkKey = deviceConfig.arcsoftSdkKey ?: ""
|
||||
GlobalData.activeKey = deviceConfig.arcsoftActiveKey ?: ""
|
||||
binding.root.postDelayed({
|
||||
hideWaitingDialog()
|
||||
goLoginActivity()
|
||||
}, 500)
|
||||
}
|
||||
}
|
||||
|
||||
// goLoginActivity()
|
||||
}
|
||||
|
||||
override fun registerDataChange() {
|
||||
|
||||
@@ -190,9 +190,17 @@ class LoginByFaceActivity : BaseActivity<ActivityLoginFaceBinding>(),
|
||||
recognizeViewModel.prepareRegister()
|
||||
recognizeViewModel.setOnRegisterFinishedCallback { facePreviewInfo, userFaceInfo ->
|
||||
//Log.d(TAG, "initArcViewModel: userFaceInfo == null : ${userFaceInfo == null}")
|
||||
if (!isCollectFace) {
|
||||
return@setOnRegisterFinishedCallback
|
||||
}
|
||||
if (this.userFaceInfo == null && userFaceInfo != null) {
|
||||
recognizeViewModel.updateRegisterStatus(RecognizeViewModel.REGISTER_STATUS_DONE)
|
||||
this.userFaceInfo = userFaceInfo
|
||||
getFaceDataBlock { faceData ->
|
||||
Thread {
|
||||
saveFaceInfo(faceData)
|
||||
}.start()
|
||||
}
|
||||
return@setOnRegisterFinishedCallback
|
||||
}
|
||||
}
|
||||
@@ -295,6 +303,7 @@ class LoginByFaceActivity : BaseActivity<ActivityLoginFaceBinding>(),
|
||||
Log.d(TAG, "openPlate: item2:${item}")
|
||||
if (item == null) {
|
||||
//暂无餐盘
|
||||
Log.d(TAG, "collectFace,openPlate: 暂无餐盘,请联系管理人员,isCollectFace=$isCollectFace")
|
||||
ToastUtils.showToast("暂无餐盘,请联系管理人员!")
|
||||
goInitActivity()
|
||||
return@getPlateData
|
||||
@@ -350,7 +359,7 @@ class LoginByFaceActivity : BaseActivity<ActivityLoginFaceBinding>(),
|
||||
EventBus.getDefault().unregister(this)
|
||||
// countDownJob?.cancel()
|
||||
// checkFaceJob?.cancel()
|
||||
getFaceScheduler?.shutdown()
|
||||
// getFaceScheduler?.shutdown()
|
||||
checkFaceScheduler?.shutdown()
|
||||
super.onDestroy()
|
||||
}
|
||||
@@ -476,6 +485,7 @@ class LoginByFaceActivity : BaseActivity<ActivityLoginFaceBinding>(),
|
||||
if (facePreviewInfoList.isNullOrEmpty()) {
|
||||
currentPlateInfo = null
|
||||
currentUserId = null
|
||||
userFaceInfo = null
|
||||
// checkFaceJob?.cancel()
|
||||
// getFaceJob?.cancel()
|
||||
}
|
||||
@@ -571,6 +581,7 @@ class LoginByFaceActivity : BaseActivity<ActivityLoginFaceBinding>(),
|
||||
return
|
||||
}
|
||||
faceDataList.clear()
|
||||
isCollectFace = false
|
||||
plateEnable = true
|
||||
collectCount = 0
|
||||
tempUserId = "${System.currentTimeMillis()}"
|
||||
@@ -628,38 +639,35 @@ class LoginByFaceActivity : BaseActivity<ActivityLoginFaceBinding>(),
|
||||
loadLogInfo("collectFace: -----------1,开始采集人脸,开始时间:${DateTimeUtils.getDateTimeString()}----------")
|
||||
if (isFirstOpen) return
|
||||
loadLogInfo("collectFace: ----------2,isFirstOpen=false-----------")
|
||||
if (facePreviewInfoList.isNullOrEmpty()) {
|
||||
loadLogInfo("collectFace: ----------3,未检测到人脸信息-----------")
|
||||
return
|
||||
}
|
||||
// if (facePreviewInfoList.isNullOrEmpty()) {
|
||||
// loadLogInfo("collectFace: ----------3,未检测到人脸信息-----------")
|
||||
// return
|
||||
// }
|
||||
loadLogInfo("collectFace: ----------4,检测到人脸信息-----------")
|
||||
currentUserId = null
|
||||
userFaceInfo = null
|
||||
recognizeViewModel.updateRegisterStatus(REGISTER_STATUS_READY)
|
||||
loadLogInfo("collectFace: ----------5,人脸采集中-----------")
|
||||
getFaceData { faceData ->
|
||||
if (faceDataList.isNotEmpty()) {
|
||||
return@getFaceData
|
||||
}
|
||||
faceDataList.add(faceData)
|
||||
|
||||
checkFaceScheduler?.shutdown()
|
||||
getFaceScheduler?.shutdown()
|
||||
// checkFaceJob?.cancel()
|
||||
// getFaceJob?.cancel()
|
||||
recognizeViewModel.updateRegisterStatus(RecognizeViewModel.REGISTER_STATUS_DONE)
|
||||
// userFaceInfo = null
|
||||
Thread {
|
||||
// val faceDao = FaceDatabase.getInstance(App.getContext()).faceDao()
|
||||
// val entity = faceDao.queryByUserName(tempUserId)
|
||||
// if (entity != null) {
|
||||
// //已存在用户
|
||||
// loadLogInfo("collectFace,saveFaceInfo: ----------9,数据库已存在该人脸数据-----------")
|
||||
// return@Thread
|
||||
// }
|
||||
saveFaceInfo(faceData)
|
||||
}.start()
|
||||
}
|
||||
// getFaceData { faceData ->
|
||||
// if (faceDataList.isNotEmpty()) {
|
||||
// return@getFaceData
|
||||
// }
|
||||
// faceDataList.add(faceData)
|
||||
//
|
||||
// checkFaceScheduler?.shutdown()
|
||||
// getFaceScheduler?.shutdown()
|
||||
// recognizeViewModel.updateRegisterStatus(RecognizeViewModel.REGISTER_STATUS_DONE)
|
||||
// Thread {
|
||||
//// val faceDao = FaceDatabase.getInstance(App.getContext()).faceDao()
|
||||
//// val entity = faceDao.queryByUserName(tempUserId)
|
||||
//// if (entity != null) {
|
||||
//// //已存在用户
|
||||
//// loadLogInfo("collectFace,saveFaceInfo: ----------9,数据库已存在该人脸数据-----------")
|
||||
//// return@Thread
|
||||
//// }
|
||||
// saveFaceInfo(faceData)
|
||||
// }.start()
|
||||
// }
|
||||
}
|
||||
|
||||
private fun sendFaceData(faceData: String) {
|
||||
@@ -673,21 +681,21 @@ class LoginByFaceActivity : BaseActivity<ActivityLoginFaceBinding>(),
|
||||
tcpClient?.send(jsonObject)
|
||||
}
|
||||
|
||||
private var getFaceScheduler: ScheduledExecutorService? = null
|
||||
// private var getFaceScheduler: ScheduledExecutorService? = null
|
||||
private var checkFaceScheduler: ScheduledExecutorService? = null
|
||||
|
||||
private fun initFaceScheduler() {
|
||||
getFaceScheduler = Executors.newScheduledThreadPool(1)
|
||||
// getFaceScheduler = Executors.newScheduledThreadPool(1)
|
||||
checkFaceScheduler = Executors.newScheduledThreadPool(1)
|
||||
}
|
||||
|
||||
|
||||
private fun getFaceData(block: (String) -> Unit) {
|
||||
getFaceScheduler?.scheduleWithFixedDelay(
|
||||
{
|
||||
getFaceDataBlock(block)
|
||||
}, 5L, 5L, TimeUnit.MILLISECONDS
|
||||
)
|
||||
// getFaceScheduler?.scheduleWithFixedDelay(
|
||||
// {
|
||||
// getFaceDataBlock(block)
|
||||
// }, 5L, 5L, TimeUnit.MILLISECONDS
|
||||
// )
|
||||
// runBlocking {
|
||||
// getFaceJob = executor.startIntervalTask(5) {
|
||||
|
||||
@@ -698,7 +706,7 @@ class LoginByFaceActivity : BaseActivity<ActivityLoginFaceBinding>(),
|
||||
}
|
||||
|
||||
private fun getFaceDataBlock(block: (String) -> Unit) {
|
||||
if (userFaceInfo == null) {
|
||||
if (userFaceInfo == null || userFaceInfo?.faceFeature?.featureData == null) {
|
||||
return
|
||||
}
|
||||
val faceData: String? = Base64.encode(userFaceInfo?.faceFeature?.featureData)
|
||||
@@ -719,7 +727,8 @@ class LoginByFaceActivity : BaseActivity<ActivityLoginFaceBinding>(),
|
||||
private var facePreviewInfoList: MutableList<FacePreviewInfo>? = null
|
||||
private var userFaceInfo: UserFaceInfo? = null
|
||||
private var countDownJob: Job? = null
|
||||
// private var getFaceJob: Job? = null
|
||||
|
||||
// private var getFaceJob: Job? = null
|
||||
val executor = IntervalExecutor()
|
||||
private var currentUserId: String? = null
|
||||
private fun countDown() {
|
||||
@@ -856,9 +865,10 @@ class LoginByFaceActivity : BaseActivity<ActivityLoginFaceBinding>(),
|
||||
}.start()
|
||||
}
|
||||
|
||||
private val WAITING_TIME = 1 * 1000L
|
||||
private val WAITING_TIME = 3 * 1000L
|
||||
private var checkStartTime = 0L
|
||||
// private var checkFaceJob: Job? = null
|
||||
|
||||
// private var checkFaceJob: Job? = null
|
||||
private fun checkFaceState() {
|
||||
checkStartTime = System.currentTimeMillis()
|
||||
|
||||
@@ -872,16 +882,20 @@ class LoginByFaceActivity : BaseActivity<ActivityLoginFaceBinding>(),
|
||||
//
|
||||
// }
|
||||
}
|
||||
|
||||
private var isCollectFace = false
|
||||
private fun checkFaceBlock() {
|
||||
Log.d("Login", "collectFace,currentUserId=${currentUserId}")
|
||||
if (currentUserId.isNullOrBlank().not()) {
|
||||
// checkFaceJob?.cancel()
|
||||
isCollectFace = false
|
||||
|
||||
checkFaceScheduler?.shutdown()
|
||||
return
|
||||
}
|
||||
if (System.currentTimeMillis() - checkStartTime >= WAITING_TIME) {
|
||||
//超过5秒采集人脸并识别
|
||||
//超过1秒采集人脸并识别
|
||||
checkFaceScheduler?.shutdown()
|
||||
isCollectFace = true
|
||||
collectFace()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user