吐盘机: 避免相机关闭后预览画面残留
- 将双击判定窗口时间由300ms延长至600ms,提升触摸屏操作体验 - 为标题时间布局的左右TextView添加最小高度和内边距,优化显示效果 - 相机关闭时清空预览画面,防止TextureView冻结并残留上一用户画面 - 重启相机前先清空残留帧,避免闪现上一用户画面
This commit is contained in:
@@ -129,12 +129,16 @@ abstract class BaseActivity<VB : ViewBinding> : AppCompatActivity() {
|
|||||||
|
|
||||||
fun updateTime() {
|
fun updateTime() {
|
||||||
headerBinding?.let {
|
headerBinding?.let {
|
||||||
|
// 双击判定窗口放宽至 600ms:默认 300ms 对触摸屏上的手动双击过短,
|
||||||
|
// 两次点击间隔常在 300~600ms,导致设置页"点很多次才进"
|
||||||
it.tvLeftDate.clickWithCoroutines(
|
it.tvLeftDate.clickWithCoroutines(
|
||||||
|
doubleClickInterval = 600,
|
||||||
onDoubleClick = {
|
onDoubleClick = {
|
||||||
onLeftDoubleClick()
|
onLeftDoubleClick()
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
it.tvRightTime.clickWithCoroutines(
|
it.tvRightTime.clickWithCoroutines(
|
||||||
|
doubleClickInterval = 600,
|
||||||
onDoubleClick = {
|
onDoubleClick = {
|
||||||
onRightDoubleClick()
|
onRightDoubleClick()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -698,6 +698,8 @@ class LoginByFaceActivity : BaseActivity<ActivityLoginFaceBinding>(),
|
|||||||
|
|
||||||
override fun onCameraClosed() {
|
override fun onCameraClosed() {
|
||||||
Timber.i("initRgbCamera onCameraClosed: ")
|
Timber.i("initRgbCamera onCameraClosed: ")
|
||||||
|
// 相机关闭时清空预览画面,防止 TextureView 冻结残留上一位用户的帧
|
||||||
|
clearPreviewFrame()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onCameraError(e: java.lang.Exception) {
|
override fun onCameraError(e: java.lang.Exception) {
|
||||||
@@ -763,11 +765,30 @@ class LoginByFaceActivity : BaseActivity<ActivityLoginFaceBinding>(),
|
|||||||
checkCameraPermission()
|
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() {
|
private fun resumeCamera() {
|
||||||
// isRecognition = true
|
// isRecognition = true
|
||||||
val helper = rgbCameraHelper
|
val helper = rgbCameraHelper
|
||||||
if (helper != null && helper.isStopped) {
|
if (helper != null && helper.isStopped) {
|
||||||
loadLogInfo("collectFace,resumeCamera: ")
|
loadLogInfo("collectFace,resumeCamera: ")
|
||||||
|
// 重启相机前先清空残留帧,避免闪现上一位用户的画面
|
||||||
|
clearPreviewFrame()
|
||||||
isRecognition = true
|
isRecognition = true
|
||||||
helper.start()
|
helper.start()
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -11,6 +11,9 @@
|
|||||||
android:id="@+id/tvLeftDate"
|
android:id="@+id/tvLeftDate"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
|
android:minHeight="64dp"
|
||||||
|
android:gravity="center_vertical"
|
||||||
|
android:paddingHorizontal="12dp"
|
||||||
app:layout_constraintTop_toTopOf="parent"
|
app:layout_constraintTop_toTopOf="parent"
|
||||||
app:layout_constraintStart_toStartOf="parent"
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
app:layout_constraintBottom_toBottomOf="parent">
|
app:layout_constraintBottom_toBottomOf="parent">
|
||||||
@@ -36,6 +39,8 @@
|
|||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:gravity="center_vertical"
|
android:gravity="center_vertical"
|
||||||
|
android:minHeight="64dp"
|
||||||
|
android:paddingHorizontal="12dp"
|
||||||
android:textColor="#FFF0C8B4"
|
android:textColor="#FFF0C8B4"
|
||||||
android:textSize="24sp"
|
android:textSize="24sp"
|
||||||
app:layout_constraintEnd_toEndOf="parent"
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
|
|||||||
Reference in New Issue
Block a user