增加实时日志查询
This commit is contained in:
@@ -15,6 +15,7 @@ import androidx.activity.viewModels
|
||||
import androidx.annotation.RequiresApi
|
||||
import androidx.lifecycle.Observer
|
||||
import androidx.lifecycle.lifecycleScope
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import com.arcsoft.face.ErrorInfo
|
||||
import com.google.gson.Gson
|
||||
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.MyApp
|
||||
import com.sw.platecabinet.R
|
||||
import com.sw.platecabinet.adapter.LogAdapter
|
||||
import com.sw.platecabinet.databinding.ActivityLoginFaceBinding
|
||||
import com.sw.platecabinet.databinding.ItemTitleTimeBinding
|
||||
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() {
|
||||
instance = this
|
||||
@@ -121,6 +125,19 @@ class LoginByFaceActivity : BaseActivity<ActivityLoginFaceBinding>(),
|
||||
|
||||
// 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() {
|
||||
@@ -569,38 +586,27 @@ class LoginByFaceActivity : BaseActivity<ActivityLoginFaceBinding>(),
|
||||
}
|
||||
|
||||
private fun collectFace() {
|
||||
Log.d(TAG, "collectFace: -----------开始采集人脸111111----------")
|
||||
loadLogInfo("collectFace: -----------1,开始采集人脸,开始时间:${DateTimeUtils.getDateTimeString()}----------")
|
||||
if (isFirstOpen) return
|
||||
Log.d(TAG, "collectFace: ----------22222222-----------")
|
||||
loadLogInfo("collectFace: ----------2,isFirstOpen=false-----------")
|
||||
logAdapter.addData("collectFace: ----------22222222,isFirstOpen=false-----------")
|
||||
if (facePreviewInfoList.isNullOrEmpty()) {
|
||||
//ToastUtils.showToast("未检测到人脸信息")
|
||||
Log.d(TAG, "collectFace: ----------33333333-----------")
|
||||
Log.d(TAG, "collectFace: 未检测到人脸信息")
|
||||
loadLogInfo("collectFace: ----------3,未检测到人脸信息-----------")
|
||||
return
|
||||
}
|
||||
Log.d(TAG, "collectFace: ----------44444444-----------")
|
||||
// if (currentUserId != null) {
|
||||
// currentUserId = null
|
||||
//// ToastUtils.showToast("您已采集过人脸信息")
|
||||
// return
|
||||
// }
|
||||
loadLogInfo("collectFace: ----------4,检测到人脸信息-----------")
|
||||
currentUserId = null
|
||||
userFaceInfo = null
|
||||
recognizeViewModel.updateRegisterStatus(REGISTER_STATUS_READY)
|
||||
Log.d(TAG, "collectFace: 人脸采集中……")
|
||||
// binding.tvFaceTip.gone()
|
||||
// binding.btnCollectFace.invisible()
|
||||
// binding.layoutState.visible()
|
||||
// binding.pbCollectLoading.visible()
|
||||
// binding.tvCollectState.text = "采集中......"
|
||||
loadLogInfo("collectFace: ----------5,人脸采集中-----------")
|
||||
getFaceData { faceData ->
|
||||
Log.d("LoginByFaceActivity", "collectFace,faceData: $faceData")
|
||||
userFaceInfo = null
|
||||
saveFaceInfo(faceData)
|
||||
}
|
||||
}
|
||||
|
||||
private fun sendFaceData(faceData: String) {
|
||||
loadLogInfo("collectFace,sendFaceData: ----------11,发生人脸数据-----------")
|
||||
Log.d(TAG, "collectFace,sendFaceData: ---------------------------")
|
||||
// 给某个客户端发送
|
||||
val jsonObject = JSONObject().also {
|
||||
@@ -617,16 +623,22 @@ class LoginByFaceActivity : BaseActivity<ActivityLoginFaceBinding>(),
|
||||
// toast("您已采集过人脸信息")
|
||||
// return@startIntervalTask
|
||||
// }
|
||||
loadLogInfo("collectFace,getFaceData: ----------6,正在获人脸取特征数据")
|
||||
if (userFaceInfo == null) {
|
||||
return@startIntervalTask
|
||||
}
|
||||
loadLogInfo("collectFace,getFaceData: ----------7,拿到人脸取特征数据-----------")
|
||||
val faceData = Base64.encode(userFaceInfo!!.faceFeature!!.featureData)
|
||||
block(faceData)
|
||||
checkFaceJob?.cancel()
|
||||
job?.cancel()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun loadLogInfo(msg: String) {
|
||||
Log.d(TAG, msg)
|
||||
logAdapter.addData(msg)
|
||||
}
|
||||
|
||||
private var facePreviewInfoList: MutableList<FacePreviewInfo>? = null
|
||||
@@ -656,13 +668,14 @@ class LoginByFaceActivity : BaseActivity<ActivityLoginFaceBinding>(),
|
||||
}
|
||||
|
||||
private fun saveFaceInfo(faceData: String) {
|
||||
Log.d(TAG, "collectFace,saveFaceInfo: $faceData")
|
||||
Thread {
|
||||
try {
|
||||
loadLogInfo("collectFace,saveFaceInfo: ----------8,保存人脸取特征数据-----------")
|
||||
val faceDao = FaceDatabase.getInstance(this).faceDao()
|
||||
val entity = faceDao.queryByUserName(tempUserId)
|
||||
if (entity != null) {
|
||||
//已存在用户
|
||||
loadLogInfo("collectFace,saveFaceInfo: ----------9,数据库已存在该人脸数据-----------")
|
||||
return@Thread
|
||||
}
|
||||
val faceEntity = FaceEntity(
|
||||
@@ -673,17 +686,21 @@ class LoginByFaceActivity : BaseActivity<ActivityLoginFaceBinding>(),
|
||||
it.userType = "2"
|
||||
}
|
||||
faceDao.insert(faceEntity)
|
||||
loadLogInfo("collectFace,saveFaceInfo: ----------10,人脸数据保存完成-----------")
|
||||
recognizeViewModel.refreshFaceList()
|
||||
loadLogInfo("collectFace,saveFaceInfo: ----------11,刷新人脸数据-----------")
|
||||
sendFaceData(faceData)
|
||||
Log.d(TAG, "collectFace,saveFaceInfo: 人脸采集完成")
|
||||
loadLogInfo("collectFace,saveFaceInfo: ----------12,人脸数据发送完成时间:${DateTimeUtils.getDateTimeString()}-----------")
|
||||
loadLogInfo("---------------------------------")
|
||||
collectCount = 0
|
||||
} catch (e: Exception) {
|
||||
e.printStackTrace()
|
||||
Log.d(TAG, "collectFace,saveFaceInfo: 人脸采集异常:${e.message}")
|
||||
loadLogInfo("collectFace,saveFaceInfo: ----------13,人脸采集异常:${e.message}-----------")
|
||||
collectCount++
|
||||
if (collectCount <= 5) {
|
||||
collectFace()
|
||||
} else {
|
||||
loadLogInfo("collectFace,saveFaceInfo: ----------14,${collectCount}次人脸采集异常:${e.message}-----------")
|
||||
ToastUtils.showToast("人脸采集异常:${e.message}")
|
||||
}
|
||||
}
|
||||
@@ -709,22 +726,25 @@ class LoginByFaceActivity : BaseActivity<ActivityLoginFaceBinding>(),
|
||||
tcpClient?.setListener(object : TcpClientListenerImpl() {
|
||||
override fun onSendSuccess(json: JSONObject?) {
|
||||
super.onSendSuccess(json)
|
||||
loadLogInfo("TcpClientListener发送成功:$json")
|
||||
// toast("发送成功")
|
||||
}
|
||||
|
||||
override fun onSendFailed(json: JSONObject?, e: java.lang.Exception?) {
|
||||
super.onSendFailed(json, e)
|
||||
ToastUtils.showToast("发送失败${e?.message}")
|
||||
loadLogInfo("TcpClientListener人脸数据发送失败:${e?.message}")
|
||||
}
|
||||
|
||||
override fun onMessage(json: JSONObject?) {
|
||||
super.onMessage(json)
|
||||
|
||||
loadLogInfo("TcpClientListener收到消息:$json")
|
||||
val type = json?.getInt("type")
|
||||
// 根据服务端消息类型处理删除新增临时用户人脸数据---------------------
|
||||
when (type) {
|
||||
LanServer.TYPE_ADD_FACE_DATA -> {
|
||||
//采集设备id自己生成,不接收服务端的,在本地只判断是否存在同一人脸数据
|
||||
loadLogInfo("TcpClientListener收到消息,新增用户:采集设备id自己生成,不接收服务端的,在本地只判断是否存在同一人脸数据")
|
||||
}
|
||||
|
||||
LanServer.TYPE_CLEAR_FACE_DATA -> {
|
||||
@@ -756,7 +776,8 @@ class LoginByFaceActivity : BaseActivity<ActivityLoginFaceBinding>(),
|
||||
Thread {
|
||||
val faceDao = FaceDatabase.getInstance(this).faceDao()
|
||||
faceDao.deleteTempUserFaceData()
|
||||
recognizeViewModel.refreshFaceList();
|
||||
recognizeViewModel.refreshFaceList()
|
||||
loadLogInfo("TcpClientListener收到消息,已删除并刷新人脸数据")
|
||||
}.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_height="match_parent"
|
||||
android:layout_marginTop="0dp"
|
||||
android:background="@drawable/bg_face"
|
||||
android:scaleType="centerCrop"
|
||||
android:src="@drawable/bg_face"
|
||||
android:visibility="visible" />
|
||||
|
||||
<TextView
|
||||
@@ -94,57 +95,73 @@
|
||||
android:textSize="36sp"
|
||||
tools:text="30" />
|
||||
|
||||
<!-- <LinearLayout-->
|
||||
<!-- android:layout_width="wrap_content"-->
|
||||
<!-- android:layout_height="wrap_content"-->
|
||||
<!-- android:gravity="center_horizontal"-->
|
||||
<!-- android:layout_gravity="bottom|center_horizontal"-->
|
||||
<!-- android:layout_marginBottom="130dp"-->
|
||||
<!-- android:orientation="vertical">-->
|
||||
<!-- <LinearLayout-->
|
||||
<!-- android:layout_width="wrap_content"-->
|
||||
<!-- android:layout_height="wrap_content"-->
|
||||
<!-- android:gravity="center_horizontal"-->
|
||||
<!-- android:layout_gravity="bottom|center_horizontal"-->
|
||||
<!-- android:layout_marginBottom="130dp"-->
|
||||
<!-- android:orientation="vertical">-->
|
||||
|
||||
<!-- <LinearLayout-->
|
||||
<!-- android:id="@+id/layoutState"-->
|
||||
<!-- android:layout_width="wrap_content"-->
|
||||
<!-- android:layout_height="50dp"-->
|
||||
<!-- android:gravity="center_vertical"-->
|
||||
<!-- android:orientation="horizontal"-->
|
||||
<!-- android:visibility="invisible">-->
|
||||
<!-- <LinearLayout-->
|
||||
<!-- android:id="@+id/layoutState"-->
|
||||
<!-- android:layout_width="wrap_content"-->
|
||||
<!-- android:layout_height="50dp"-->
|
||||
<!-- android:gravity="center_vertical"-->
|
||||
<!-- android:orientation="horizontal"-->
|
||||
<!-- android:visibility="invisible">-->
|
||||
|
||||
<!-- <ProgressBar-->
|
||||
<!-- android:id="@+id/pbCollectLoading"-->
|
||||
<!-- android:layout_width="32dp"-->
|
||||
<!-- android:layout_height="32dp"-->
|
||||
<!-- android:indeterminateTint="@color/white" />-->
|
||||
<!-- <ProgressBar-->
|
||||
<!-- android:id="@+id/pbCollectLoading"-->
|
||||
<!-- android:layout_width="32dp"-->
|
||||
<!-- android:layout_height="32dp"-->
|
||||
<!-- android:indeterminateTint="@color/white" />-->
|
||||
|
||||
<!-- <TextView-->
|
||||
<!-- android:id="@+id/tvCollectState"-->
|
||||
<!-- android:layout_width="wrap_content"-->
|
||||
<!-- android:layout_height="wrap_content"-->
|
||||
<!-- android:layout_marginStart="10dp"-->
|
||||
<!-- android:text="采集中......"-->
|
||||
<!-- android:textColor="@color/white"-->
|
||||
<!-- android:textSize="24sp" />-->
|
||||
<!-- </LinearLayout>-->
|
||||
<!-- <TextView-->
|
||||
<!-- android:id="@+id/tvCollectState"-->
|
||||
<!-- android:layout_width="wrap_content"-->
|
||||
<!-- android:layout_height="wrap_content"-->
|
||||
<!-- android:layout_marginStart="10dp"-->
|
||||
<!-- android:text="采集中......"-->
|
||||
<!-- android:textColor="@color/white"-->
|
||||
<!-- android:textSize="24sp" />-->
|
||||
<!-- </LinearLayout>-->
|
||||
|
||||
<!-- <TextView-->
|
||||
<!-- android:id="@+id/btnCollectFace"-->
|
||||
<!-- android:layout_width="wrap_content"-->
|
||||
<!-- android:layout_height="60dp"-->
|
||||
<!-- android:background="@drawable/btn_outline"-->
|
||||
<!-- android:gravity="center"-->
|
||||
<!-- android:layout_marginTop="10dp"-->
|
||||
<!-- android:paddingHorizontal="45dp"-->
|
||||
<!-- android:text="开始采集"-->
|
||||
<!-- android:textColor="#FFCC99"-->
|
||||
<!-- android:textSize="24sp"-->
|
||||
<!-- tools:ignore="HardcodedText" />-->
|
||||
<!-- </LinearLayout>-->
|
||||
<!-- <TextView-->
|
||||
<!-- android:id="@+id/btnCollectFace"-->
|
||||
<!-- android:layout_width="wrap_content"-->
|
||||
<!-- android:layout_height="60dp"-->
|
||||
<!-- android:background="@drawable/btn_outline"-->
|
||||
<!-- android:gravity="center"-->
|
||||
<!-- android:layout_marginTop="10dp"-->
|
||||
<!-- android:paddingHorizontal="45dp"-->
|
||||
<!-- android:text="开始采集"-->
|
||||
<!-- android:textColor="#FFCC99"-->
|
||||
<!-- android:textSize="24sp"-->
|
||||
<!-- tools:ignore="HardcodedText" />-->
|
||||
<!-- </LinearLayout>-->
|
||||
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:id="@+id/rvLogInfo"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="300dp"
|
||||
android:layout_gravity="bottom"/>
|
||||
android:layout_height="match_parent"
|
||||
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>
|
||||
</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