增加实时日志查询
This commit is contained in:
@@ -15,6 +15,7 @@ import androidx.activity.viewModels
|
|||||||
import androidx.annotation.RequiresApi
|
import androidx.annotation.RequiresApi
|
||||||
import androidx.lifecycle.Observer
|
import androidx.lifecycle.Observer
|
||||||
import androidx.lifecycle.lifecycleScope
|
import androidx.lifecycle.lifecycleScope
|
||||||
|
import androidx.recyclerview.widget.LinearLayoutManager
|
||||||
import com.arcsoft.face.ErrorInfo
|
import com.arcsoft.face.ErrorInfo
|
||||||
import com.google.gson.Gson
|
import com.google.gson.Gson
|
||||||
import com.sw.platecabinet.socket.TcpClientListenerImpl
|
import com.sw.platecabinet.socket.TcpClientListenerImpl
|
||||||
@@ -42,6 +43,7 @@ import com.sw.plate.utils.arcface.viewmodel.RecognizeViewModel.REGISTER_STATUS_R
|
|||||||
import com.sw.platecabinet.GlobalData
|
import com.sw.platecabinet.GlobalData
|
||||||
import com.sw.platecabinet.MyApp
|
import com.sw.platecabinet.MyApp
|
||||||
import com.sw.platecabinet.R
|
import com.sw.platecabinet.R
|
||||||
|
import com.sw.platecabinet.adapter.LogAdapter
|
||||||
import com.sw.platecabinet.databinding.ActivityLoginFaceBinding
|
import com.sw.platecabinet.databinding.ActivityLoginFaceBinding
|
||||||
import com.sw.platecabinet.databinding.ItemTitleTimeBinding
|
import com.sw.platecabinet.databinding.ItemTitleTimeBinding
|
||||||
import com.sw.platecabinet.ext.gone
|
import com.sw.platecabinet.ext.gone
|
||||||
@@ -97,6 +99,8 @@ class LoginByFaceActivity : BaseActivity<ActivityLoginFaceBinding>(),
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private var logList: MutableList<String> = mutableListOf()
|
||||||
|
private val logAdapter by lazy { LogAdapter(logList) }
|
||||||
|
|
||||||
override fun initialize() {
|
override fun initialize() {
|
||||||
instance = this
|
instance = this
|
||||||
@@ -121,6 +125,19 @@ class LoginByFaceActivity : BaseActivity<ActivityLoginFaceBinding>(),
|
|||||||
|
|
||||||
// binding.btnCollectFace.setOnClickListener { collectFace() }
|
// binding.btnCollectFace.setOnClickListener { collectFace() }
|
||||||
|
|
||||||
|
|
||||||
|
binding.rvLogInfo.let {
|
||||||
|
it.layoutManager = LinearLayoutManager(this, LinearLayoutManager.VERTICAL, true)
|
||||||
|
it.adapter = logAdapter
|
||||||
|
}
|
||||||
|
|
||||||
|
binding.btnLogState.let {
|
||||||
|
it.tag = false
|
||||||
|
it.setOnClickListener { v ->
|
||||||
|
binding.rvLogInfo.visible()
|
||||||
|
it.tag = it.tag.toString().toBoolean().not()
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun checkCameraPermission() {
|
private fun checkCameraPermission() {
|
||||||
@@ -569,38 +586,27 @@ class LoginByFaceActivity : BaseActivity<ActivityLoginFaceBinding>(),
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun collectFace() {
|
private fun collectFace() {
|
||||||
Log.d(TAG, "collectFace: -----------开始采集人脸111111----------")
|
loadLogInfo("collectFace: -----------1,开始采集人脸,开始时间:${DateTimeUtils.getDateTimeString()}----------")
|
||||||
if (isFirstOpen) return
|
if (isFirstOpen) return
|
||||||
Log.d(TAG, "collectFace: ----------22222222-----------")
|
loadLogInfo("collectFace: ----------2,isFirstOpen=false-----------")
|
||||||
|
logAdapter.addData("collectFace: ----------22222222,isFirstOpen=false-----------")
|
||||||
if (facePreviewInfoList.isNullOrEmpty()) {
|
if (facePreviewInfoList.isNullOrEmpty()) {
|
||||||
//ToastUtils.showToast("未检测到人脸信息")
|
loadLogInfo("collectFace: ----------3,未检测到人脸信息-----------")
|
||||||
Log.d(TAG, "collectFace: ----------33333333-----------")
|
|
||||||
Log.d(TAG, "collectFace: 未检测到人脸信息")
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
Log.d(TAG, "collectFace: ----------44444444-----------")
|
loadLogInfo("collectFace: ----------4,检测到人脸信息-----------")
|
||||||
// if (currentUserId != null) {
|
|
||||||
// currentUserId = null
|
|
||||||
//// ToastUtils.showToast("您已采集过人脸信息")
|
|
||||||
// return
|
|
||||||
// }
|
|
||||||
currentUserId = null
|
currentUserId = null
|
||||||
userFaceInfo = null
|
userFaceInfo = null
|
||||||
recognizeViewModel.updateRegisterStatus(REGISTER_STATUS_READY)
|
recognizeViewModel.updateRegisterStatus(REGISTER_STATUS_READY)
|
||||||
Log.d(TAG, "collectFace: 人脸采集中……")
|
loadLogInfo("collectFace: ----------5,人脸采集中-----------")
|
||||||
// binding.tvFaceTip.gone()
|
|
||||||
// binding.btnCollectFace.invisible()
|
|
||||||
// binding.layoutState.visible()
|
|
||||||
// binding.pbCollectLoading.visible()
|
|
||||||
// binding.tvCollectState.text = "采集中......"
|
|
||||||
getFaceData { faceData ->
|
getFaceData { faceData ->
|
||||||
Log.d("LoginByFaceActivity", "collectFace,faceData: $faceData")
|
|
||||||
userFaceInfo = null
|
userFaceInfo = null
|
||||||
saveFaceInfo(faceData)
|
saveFaceInfo(faceData)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun sendFaceData(faceData: String) {
|
private fun sendFaceData(faceData: String) {
|
||||||
|
loadLogInfo("collectFace,sendFaceData: ----------11,发生人脸数据-----------")
|
||||||
Log.d(TAG, "collectFace,sendFaceData: ---------------------------")
|
Log.d(TAG, "collectFace,sendFaceData: ---------------------------")
|
||||||
// 给某个客户端发送
|
// 给某个客户端发送
|
||||||
val jsonObject = JSONObject().also {
|
val jsonObject = JSONObject().also {
|
||||||
@@ -617,16 +623,22 @@ class LoginByFaceActivity : BaseActivity<ActivityLoginFaceBinding>(),
|
|||||||
// toast("您已采集过人脸信息")
|
// toast("您已采集过人脸信息")
|
||||||
// return@startIntervalTask
|
// return@startIntervalTask
|
||||||
// }
|
// }
|
||||||
|
loadLogInfo("collectFace,getFaceData: ----------6,正在获人脸取特征数据")
|
||||||
if (userFaceInfo == null) {
|
if (userFaceInfo == null) {
|
||||||
return@startIntervalTask
|
return@startIntervalTask
|
||||||
}
|
}
|
||||||
|
loadLogInfo("collectFace,getFaceData: ----------7,拿到人脸取特征数据-----------")
|
||||||
val faceData = Base64.encode(userFaceInfo!!.faceFeature!!.featureData)
|
val faceData = Base64.encode(userFaceInfo!!.faceFeature!!.featureData)
|
||||||
block(faceData)
|
block(faceData)
|
||||||
checkFaceJob?.cancel()
|
checkFaceJob?.cancel()
|
||||||
job?.cancel()
|
job?.cancel()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun loadLogInfo(msg: String) {
|
||||||
|
Log.d(TAG, msg)
|
||||||
|
logAdapter.addData(msg)
|
||||||
}
|
}
|
||||||
|
|
||||||
private var facePreviewInfoList: MutableList<FacePreviewInfo>? = null
|
private var facePreviewInfoList: MutableList<FacePreviewInfo>? = null
|
||||||
@@ -656,13 +668,14 @@ class LoginByFaceActivity : BaseActivity<ActivityLoginFaceBinding>(),
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun saveFaceInfo(faceData: String) {
|
private fun saveFaceInfo(faceData: String) {
|
||||||
Log.d(TAG, "collectFace,saveFaceInfo: $faceData")
|
|
||||||
Thread {
|
Thread {
|
||||||
try {
|
try {
|
||||||
|
loadLogInfo("collectFace,saveFaceInfo: ----------8,保存人脸取特征数据-----------")
|
||||||
val faceDao = FaceDatabase.getInstance(this).faceDao()
|
val faceDao = FaceDatabase.getInstance(this).faceDao()
|
||||||
val entity = faceDao.queryByUserName(tempUserId)
|
val entity = faceDao.queryByUserName(tempUserId)
|
||||||
if (entity != null) {
|
if (entity != null) {
|
||||||
//已存在用户
|
//已存在用户
|
||||||
|
loadLogInfo("collectFace,saveFaceInfo: ----------9,数据库已存在该人脸数据-----------")
|
||||||
return@Thread
|
return@Thread
|
||||||
}
|
}
|
||||||
val faceEntity = FaceEntity(
|
val faceEntity = FaceEntity(
|
||||||
@@ -673,17 +686,21 @@ class LoginByFaceActivity : BaseActivity<ActivityLoginFaceBinding>(),
|
|||||||
it.userType = "2"
|
it.userType = "2"
|
||||||
}
|
}
|
||||||
faceDao.insert(faceEntity)
|
faceDao.insert(faceEntity)
|
||||||
|
loadLogInfo("collectFace,saveFaceInfo: ----------10,人脸数据保存完成-----------")
|
||||||
recognizeViewModel.refreshFaceList()
|
recognizeViewModel.refreshFaceList()
|
||||||
|
loadLogInfo("collectFace,saveFaceInfo: ----------11,刷新人脸数据-----------")
|
||||||
sendFaceData(faceData)
|
sendFaceData(faceData)
|
||||||
Log.d(TAG, "collectFace,saveFaceInfo: 人脸采集完成")
|
loadLogInfo("collectFace,saveFaceInfo: ----------12,人脸数据发送完成时间:${DateTimeUtils.getDateTimeString()}-----------")
|
||||||
|
loadLogInfo("---------------------------------")
|
||||||
collectCount = 0
|
collectCount = 0
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
e.printStackTrace()
|
e.printStackTrace()
|
||||||
Log.d(TAG, "collectFace,saveFaceInfo: 人脸采集异常:${e.message}")
|
loadLogInfo("collectFace,saveFaceInfo: ----------13,人脸采集异常:${e.message}-----------")
|
||||||
collectCount++
|
collectCount++
|
||||||
if (collectCount <= 5) {
|
if (collectCount <= 5) {
|
||||||
collectFace()
|
collectFace()
|
||||||
} else {
|
} else {
|
||||||
|
loadLogInfo("collectFace,saveFaceInfo: ----------14,${collectCount}次人脸采集异常:${e.message}-----------")
|
||||||
ToastUtils.showToast("人脸采集异常:${e.message}")
|
ToastUtils.showToast("人脸采集异常:${e.message}")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -709,22 +726,25 @@ class LoginByFaceActivity : BaseActivity<ActivityLoginFaceBinding>(),
|
|||||||
tcpClient?.setListener(object : TcpClientListenerImpl() {
|
tcpClient?.setListener(object : TcpClientListenerImpl() {
|
||||||
override fun onSendSuccess(json: JSONObject?) {
|
override fun onSendSuccess(json: JSONObject?) {
|
||||||
super.onSendSuccess(json)
|
super.onSendSuccess(json)
|
||||||
|
loadLogInfo("TcpClientListener发送成功:$json")
|
||||||
// toast("发送成功")
|
// toast("发送成功")
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onSendFailed(json: JSONObject?, e: java.lang.Exception?) {
|
override fun onSendFailed(json: JSONObject?, e: java.lang.Exception?) {
|
||||||
super.onSendFailed(json, e)
|
super.onSendFailed(json, e)
|
||||||
ToastUtils.showToast("发送失败${e?.message}")
|
ToastUtils.showToast("发送失败${e?.message}")
|
||||||
|
loadLogInfo("TcpClientListener人脸数据发送失败:${e?.message}")
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onMessage(json: JSONObject?) {
|
override fun onMessage(json: JSONObject?) {
|
||||||
super.onMessage(json)
|
super.onMessage(json)
|
||||||
|
loadLogInfo("TcpClientListener收到消息:$json")
|
||||||
val type = json?.getInt("type")
|
val type = json?.getInt("type")
|
||||||
// 根据服务端消息类型处理删除新增临时用户人脸数据---------------------
|
// 根据服务端消息类型处理删除新增临时用户人脸数据---------------------
|
||||||
when (type) {
|
when (type) {
|
||||||
LanServer.TYPE_ADD_FACE_DATA -> {
|
LanServer.TYPE_ADD_FACE_DATA -> {
|
||||||
//采集设备id自己生成,不接收服务端的,在本地只判断是否存在同一人脸数据
|
//采集设备id自己生成,不接收服务端的,在本地只判断是否存在同一人脸数据
|
||||||
|
loadLogInfo("TcpClientListener收到消息,新增用户:采集设备id自己生成,不接收服务端的,在本地只判断是否存在同一人脸数据")
|
||||||
}
|
}
|
||||||
|
|
||||||
LanServer.TYPE_CLEAR_FACE_DATA -> {
|
LanServer.TYPE_CLEAR_FACE_DATA -> {
|
||||||
@@ -756,7 +776,8 @@ class LoginByFaceActivity : BaseActivity<ActivityLoginFaceBinding>(),
|
|||||||
Thread {
|
Thread {
|
||||||
val faceDao = FaceDatabase.getInstance(this).faceDao()
|
val faceDao = FaceDatabase.getInstance(this).faceDao()
|
||||||
faceDao.deleteTempUserFaceData()
|
faceDao.deleteTempUserFaceData()
|
||||||
recognizeViewModel.refreshFaceList();
|
recognizeViewModel.refreshFaceList()
|
||||||
|
loadLogInfo("TcpClientListener收到消息,已删除并刷新人脸数据")
|
||||||
}.start()
|
}.start()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,30 @@
|
|||||||
|
package com.sw.platecabinet.adapter
|
||||||
|
|
||||||
|
import android.view.LayoutInflater
|
||||||
|
import android.view.ViewGroup
|
||||||
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
|
import com.sw.platecabinet.databinding.ListItemLogInfoBinding
|
||||||
|
|
||||||
|
class LogAdapter(var list: MutableList<String>) : RecyclerView.Adapter<LogAdapter.ViewHolder> {
|
||||||
|
|
||||||
|
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
|
||||||
|
holder.binding.tvLogText.text = list[position]
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
|
||||||
|
val binding =
|
||||||
|
ListItemLogInfoBinding.inflate(LayoutInflater.from(parent.context), parent, false)
|
||||||
|
return ViewHolder(binding)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun getItemCount() = list.size
|
||||||
|
|
||||||
|
inner class ViewHolder(var binding: ListItemLogInfoBinding) :
|
||||||
|
RecyclerView.ViewHolder(binding.root)
|
||||||
|
|
||||||
|
fun addData(logInfo: String) {
|
||||||
|
list.add(logInfo)
|
||||||
|
notifyDataSetChanged()
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Binary file not shown.
|
After Width: | Height: | Size: 1.9 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 2.2 KiB |
@@ -0,0 +1,5 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<shape xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
|
<solid android:color="@color/white"/>
|
||||||
|
<corners android:radius="30dp"/>
|
||||||
|
</shape>
|
||||||
@@ -49,7 +49,8 @@
|
|||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:layout_marginTop="0dp"
|
android:layout_marginTop="0dp"
|
||||||
android:background="@drawable/bg_face"
|
android:scaleType="centerCrop"
|
||||||
|
android:src="@drawable/bg_face"
|
||||||
android:visibility="visible" />
|
android:visibility="visible" />
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
@@ -143,8 +144,24 @@
|
|||||||
<androidx.recyclerview.widget.RecyclerView
|
<androidx.recyclerview.widget.RecyclerView
|
||||||
android:id="@+id/rvLogInfo"
|
android:id="@+id/rvLogInfo"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="300dp"
|
android:layout_height="match_parent"
|
||||||
android:layout_gravity="bottom"/>
|
android:layout_gravity="bottom"
|
||||||
|
android:overScrollMode="never"
|
||||||
|
android:visibility="gone"
|
||||||
|
android:background="@color/black"
|
||||||
|
tools:listitem="@layout/list_item_log_info" />
|
||||||
|
|
||||||
|
<ImageView
|
||||||
|
android:id="@+id/btnLogState"
|
||||||
|
android:layout_width="60dp"
|
||||||
|
android:layout_height="60dp"
|
||||||
|
android:layout_gravity="bottom|end"
|
||||||
|
android:background="@drawable/shape_white_circle"
|
||||||
|
android:padding="10dp"
|
||||||
|
android:layout_marginEnd="10dp"
|
||||||
|
android:layout_marginBottom="10dp"
|
||||||
|
android:src="@drawable/ic_log_show"
|
||||||
|
android:textSize="16sp" />
|
||||||
|
|
||||||
</FrameLayout>
|
</FrameLayout>
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|||||||
@@ -0,0 +1,23 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:orientation="vertical">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/tvLogText"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginHorizontal="20dp"
|
||||||
|
android:layout_marginVertical="10dp"
|
||||||
|
android:textColor="@color/white"
|
||||||
|
android:textSize="26sp"
|
||||||
|
tools:text="log" />
|
||||||
|
|
||||||
|
<View
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="1dp"
|
||||||
|
android:layout_marginHorizontal="20dp"
|
||||||
|
android:background="#30FFFFFF" />
|
||||||
|
</LinearLayout>
|
||||||
Reference in New Issue
Block a user