Update Android app login, home, and face verification flows.

Sync current local UI and activity changes to remote repository.

Made-with: Cursor
This commit is contained in:
2026-04-27 15:39:47 +08:00
parent 2e6aba459c
commit b47704b281
24 changed files with 876 additions and 204 deletions

View File

@@ -1,4 +1,44 @@
package com.example.defenseapplication.view
class FaceAnalyzer {
import android.os.Handler
import android.os.Looper
import android.util.Log
import androidx.camera.core.ExperimentalGetImage
import androidx.camera.core.ImageAnalysis
import androidx.camera.core.ImageProxy
import com.google.mlkit.vision.common.InputImage
import com.google.mlkit.vision.face.FaceDetector
/*
* 人脸分析器
* */
@ExperimentalGetImage
class FaceAnalyzer(
private val detector: FaceDetector?,
private val overlayView: FaceOverlayView
) : ImageAnalysis.Analyzer {
override fun analyze(imageProxy: ImageProxy) {
if (detector == null) {
imageProxy.close()
return
}
val mediaImage = imageProxy.image ?: run {
imageProxy.close()
return
}
val image = InputImage.fromMediaImage(mediaImage, imageProxy.imageInfo.rotationDegrees)
detector.process(image)
.addOnSuccessListener { faces ->
Handler(Looper.getMainLooper()).post {
overlayView.setFaces(faces)
}
}
.addOnFailureListener { e ->
Log.e("FaceAnalyzer", "人脸检测失败", e)
}
.addOnCompleteListener {
imageProxy.close()
}
}
}

View File

@@ -1,2 +1,36 @@
package com.example.defenseapplication.view
import android.content.Context
import android.graphics.Canvas
import android.graphics.Color
import android.graphics.Paint
import android.util.AttributeSet
import android.view.View
import com.google.mlkit.vision.face.Face
class FaceOverlayView(context: Context, attrs: AttributeSet?) : View(context, attrs) {
private val paint = Paint().apply {
color = Color.GREEN
style = Paint.Style.STROKE
strokeWidth = 4f
}
private val textPaint = Paint().apply {
color = Color.YELLOW
textSize = 40f
}
private var faces = mutableListOf<Face>()
fun setFaces(faces: List<Face>) {
this.faces = faces.toMutableList()
invalidate() // 触发 onDraw
}
override fun onDraw(canvas: Canvas) {
super.onDraw(canvas)
for (face in faces) {
val rect = face.boundingBox
canvas.drawRect(rect, paint)
canvas.drawText("Face", rect.left.toFloat(), rect.top - 10f, textPaint)
}
}
}