吐盘机: 避免相机关闭后预览画面残留

- 将双击判定窗口时间由300ms延长至600ms,提升触摸屏操作体验
- 为标题时间布局的左右TextView添加最小高度和内边距,优化显示效果
- 相机关闭时清空预览画面,防止TextureView冻结并残留上一用户画面
- 重启相机前先清空残留帧,避免闪现上一用户画面
This commit is contained in:
mazengfei
2026-08-19 17:03:52 +08:00
parent 524837ec20
commit 97e5d74c4b
3 changed files with 30 additions and 0 deletions
@@ -129,12 +129,16 @@ abstract class BaseActivity<VB : ViewBinding> : AppCompatActivity() {
fun updateTime() {
headerBinding?.let {
// 双击判定窗口放宽至 600ms:默认 300ms 对触摸屏上的手动双击过短,
// 两次点击间隔常在 300~600ms,导致设置页"点很多次才进"
it.tvLeftDate.clickWithCoroutines(
doubleClickInterval = 600,
onDoubleClick = {
onLeftDoubleClick()
}
)
it.tvRightTime.clickWithCoroutines(
doubleClickInterval = 600,
onDoubleClick = {
onRightDoubleClick()
}
@@ -698,6 +698,8 @@ class LoginByFaceActivity : BaseActivity<ActivityLoginFaceBinding>(),
override fun onCameraClosed() {
Timber.i("initRgbCamera onCameraClosed: ")
// 相机关闭时清空预览画面,防止 TextureView 冻结残留上一位用户的帧
clearPreviewFrame()
}
override fun onCameraError(e: java.lang.Exception) {
@@ -763,11 +765,30 @@ class LoginByFaceActivity : BaseActivity<ActivityLoginFaceBinding>(),
checkCameraPermission()
}
/**
* 清除预览 TextureView 中缓存的最后一帧画面(提交一帧全黑)。
* 相机关闭后 TextureView 会冻结保留最后一帧,若不清除,
* 下一位用户重启识别时会先闪现上一位用户的画面。
*/
private fun clearPreviewFrame() {
val previewView = binding.dualCameraTexturePreviewRgb
if (!previewView.isAvailable) return
runCatching {
val canvas = previewView.lockCanvas() ?: return@runCatching
canvas.drawColor(android.graphics.Color.BLACK)
previewView.unlockCanvasAndPost(canvas)
}.onFailure {
loadLogInfo("clearPreviewFrame 失败: ${it.message}")
}
}
private fun resumeCamera() {
// isRecognition = true
val helper = rgbCameraHelper
if (helper != null && helper.isStopped) {
loadLogInfo("collectFace,resumeCamera: ")
// 重启相机前先清空残留帧,避免闪现上一位用户的画面
clearPreviewFrame()
isRecognition = true
helper.start()
} else {
@@ -11,6 +11,9 @@
android:id="@+id/tvLeftDate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:minHeight="64dp"
android:gravity="center_vertical"
android:paddingHorizontal="12dp"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintBottom_toBottomOf="parent">
@@ -36,6 +39,8 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:minHeight="64dp"
android:paddingHorizontal="12dp"
android:textColor="#FFF0C8B4"
android:textSize="24sp"
app:layout_constraintEnd_toEndOf="parent"