package idsdk.views import android.content.Context import android.graphics.* import android.util.AttributeSet import android.util.Log import android.view.SurfaceView import androidx.core.graphics.toColorInt class FaceDetectionView @JvmOverloads constructor( context: Context, attributeSet: AttributeSet? = null, defStyleAttr: Int = 0 ) : SurfaceView(context, attributeSet, defStyleAttr) { private val backgroundPaint = Paint().apply { color = "#66000000".toColorInt() style = Paint.Style.FILL } private val ovalRect = RectF() private val eraser = Paint().apply { isAntiAlias = true xfermode = PorterDuffXfermode(PorterDuff.Mode.CLEAR) } init { setWillNotDraw(false) } fun updateFaceRect(newRect: RectF) { // Face rectangle highlight is intentionally disabled. try { invalidate() }catch (e: Exception){ Log.e("processDetectRect", e.toString()) } } override fun onSizeChanged(w: Int, h: Int, oldw: Int, oldh: Int) { super.onSizeChanged(w, h, oldw, oldh) ovalRect.set( w * 0.2f, h * 0.2f, w * 0.7f, h * 0.55f ) } override fun onDraw(canvas: Canvas) { // Фон рисуем canvas.drawRect(0f, 0f, width.toFloat(), height.toFloat(), backgroundPaint) // Вычисляем размеры овала с уменьшением на 20% val ovalWidth = width * 0.75f * 0.8f val ovalHeight = ovalWidth * 1.4f val left = (width - ovalWidth) / 2f val top = (height - ovalHeight) / 2f ovalRect.set(left, top, left + ovalWidth, top + ovalHeight) canvas.drawOval(ovalRect, eraser) } }