首页人脸识别区域改为圆形
This commit is contained in:
Generated
+2
-2
@@ -4,10 +4,10 @@
|
||||
<selectionStates>
|
||||
<SelectionState runConfigName="app">
|
||||
<option name="selectionMode" value="DROPDOWN" />
|
||||
<DropdownSelection timestamp="2026-02-02T06:44:20.183314400Z">
|
||||
<DropdownSelection timestamp="2026-02-06T02:13:05.230327500Z">
|
||||
<Target type="DEFAULT_BOOT">
|
||||
<handle>
|
||||
<DeviceId pluginId="Default" identifier="serial=192.168.1.32:5555;connection=c1793c60" />
|
||||
<DeviceId pluginId="Default" identifier="serial=192.168.1.170:5555;connection=1ec19d1e" />
|
||||
</handle>
|
||||
</Target>
|
||||
</DropdownSelection>
|
||||
|
||||
@@ -345,6 +345,7 @@ class MainScreenPresentation(
|
||||
|
||||
binding.flCameraView.visible()
|
||||
binding.ivFaceRecMask.gone()
|
||||
binding.llCircleArea.gone()
|
||||
binding.tvFaceTip.gone()
|
||||
binding.tvFoodRecPrompt.gone()
|
||||
binding.llPriceInfo.visible()
|
||||
@@ -432,6 +433,7 @@ class MainScreenPresentation(
|
||||
binding.flCameraView.visible()
|
||||
binding.ivFaceRecMask.gone()
|
||||
binding.tvFaceTip.gone()
|
||||
binding.llCircleArea.gone()
|
||||
binding.tvFoodRecPrompt.gone()
|
||||
binding.llPriceInfo.gone()
|
||||
//binding.ivRecImage.gone()
|
||||
@@ -502,6 +504,7 @@ class MainScreenPresentation(
|
||||
binding.ivPreviewImage.visible()
|
||||
binding.ivFaceRecMask.gone()
|
||||
binding.tvFaceTip.gone()
|
||||
binding.llCircleArea.gone()
|
||||
binding.llPriceInfo.gone()
|
||||
binding.flFace.gone()
|
||||
binding.ivFrame.gone()
|
||||
@@ -546,6 +549,7 @@ class MainScreenPresentation(
|
||||
binding.flCameraView.visible()
|
||||
binding.ivFaceRecMask.visible()
|
||||
binding.tvFaceTip.visible()
|
||||
binding.llCircleArea.visible()
|
||||
binding.tvFoodRecPrompt.visible()
|
||||
binding.llPriceInfo.gone()
|
||||
|
||||
@@ -946,8 +950,10 @@ class MainScreenPresentation(
|
||||
//layoutParams.height = 768
|
||||
// val w = 600.dp //(912.dp * scale).toInt()
|
||||
// val h = 900.dp //684.dp
|
||||
val w = 500.dp
|
||||
val h = 850.dp
|
||||
// val w = 500.dp
|
||||
// val h = 850.dp
|
||||
val w = 720.dp
|
||||
val h = 1280.dp
|
||||
//(1024*scale).toInt()
|
||||
val layoutParams = FrameLayout.LayoutParams(w, h);
|
||||
// val layoutParams = FrameLayout.LayoutParams(480, 320);
|
||||
|
||||
@@ -0,0 +1,67 @@
|
||||
package com.sw.dualscreen.view
|
||||
|
||||
import android.content.Context
|
||||
import android.graphics.*
|
||||
import android.util.AttributeSet
|
||||
import android.view.View
|
||||
import androidx.core.content.ContextCompat
|
||||
import androidx.core.graphics.toColorInt
|
||||
import kotlin.math.roundToInt
|
||||
|
||||
class HollowCircleRectView @JvmOverloads constructor(
|
||||
context: Context,
|
||||
attrs: AttributeSet? = null,
|
||||
defStyleAttr: Int = 0
|
||||
) : View(context, attrs, defStyleAttr) {
|
||||
|
||||
// 1. 先定义dp值,再统一转px(避免多次转换误差)
|
||||
private val rectWidthDp = 400f
|
||||
private val rectHeightDp = 510f
|
||||
private val circleRadiusDp = 200f // 直径400dp → 半径200dp(固定正圆关键)
|
||||
|
||||
// 2. 转px后的值(只计算一次,避免onDraw重复计算)
|
||||
private val rectWidthPx: Float = dp2px(rectWidthDp)
|
||||
private val rectHeightPx: Float = dp2px(rectHeightDp)
|
||||
private val circleRadiusPx: Float = dp2px(circleRadiusDp)
|
||||
|
||||
// 画笔和路径(复用避免重复创建)
|
||||
private val paint = Paint(Paint.ANTI_ALIAS_FLAG)
|
||||
private val path = Path()
|
||||
|
||||
init {
|
||||
// paint.color = "#FFE7EFF8".toColorInt()
|
||||
paint.color = "#FFF4FAFF".toColorInt()
|
||||
paint.style = Paint.Style.FILL
|
||||
// 强制关闭硬件加速可能的渲染偏差(关键)
|
||||
setLayerType(LAYER_TYPE_SOFTWARE, null)
|
||||
}
|
||||
|
||||
override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) {
|
||||
// 强制View尺寸为精准px值,避免父布局干扰
|
||||
setMeasuredDimension(rectWidthPx.toInt(), rectHeightPx.toInt())
|
||||
}
|
||||
|
||||
override fun onDraw(canvas: Canvas) {
|
||||
super.onDraw(canvas)
|
||||
path.reset()
|
||||
|
||||
// 1. 添加矩形路径(精准px值,无偏差)
|
||||
path.addRect(0f, 0f, rectWidthPx, rectHeightPx, Path.Direction.CW)
|
||||
|
||||
// 2. 添加圆形路径(固定半径,绝对正圆)
|
||||
val circleX = rectWidthPx / 2 // 水平居中:200dp转px
|
||||
val circleY = rectHeightPx / 2 // 垂直居中:340dp转px
|
||||
// 核心修复:用固定半径circleRadiusPx,而非直径/2(避免浮点运算偏差)
|
||||
path.addCircle(circleX, circleY, circleRadiusPx, Path.Direction.CW)
|
||||
|
||||
// 3. 填充规则+绘制
|
||||
path.fillType = Path.FillType.EVEN_ODD
|
||||
canvas.drawPath(path, paint)
|
||||
}
|
||||
|
||||
// 精准dp转px(四舍五入避免小数偏差)
|
||||
private fun dp2px(dp: Float): Float {
|
||||
val density = context.resources.displayMetrics.density
|
||||
return (dp * density).roundToInt().toFloat() // 四舍五入到整数px
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<item
|
||||
android:width="300dp"
|
||||
android:height="510dp">
|
||||
<shape android:shape="rectangle">
|
||||
<stroke
|
||||
android:width="1dp"
|
||||
android:color="@color/teal_200" />
|
||||
</shape>
|
||||
</item>
|
||||
|
||||
<item
|
||||
android:width="300dp"
|
||||
android:height="300dp">
|
||||
<shape android:shape="oval">
|
||||
|
||||
<!-- <solid android:color="@color/transparent" />-->
|
||||
<!-- <size-->
|
||||
<!-- android:width="300dp"-->
|
||||
<!-- android:height="300dp" />-->
|
||||
<stroke
|
||||
android:width="20dp"
|
||||
android:color="@color/white" />
|
||||
|
||||
</shape>
|
||||
</item>
|
||||
|
||||
</layer-list>
|
||||
@@ -30,10 +30,10 @@
|
||||
android:textSize="40sp"
|
||||
android:textStyle="bold" />
|
||||
|
||||
<!-- android:layout_width="300dp"-->
|
||||
<!-- android:layout_height="450dp"-->
|
||||
<!-- android:layout_width="330dp"-->
|
||||
<!-- android:layout_height="495dp"-->
|
||||
<!-- android:layout_width="300dp"-->
|
||||
<!-- android:layout_height="450dp"-->
|
||||
<!-- android:layout_width="330dp"-->
|
||||
<!-- android:layout_height="495dp"-->
|
||||
<FrameLayout
|
||||
android:id="@+id/flCameraView"
|
||||
android:layout_width="match_parent"
|
||||
@@ -42,12 +42,16 @@
|
||||
android:layout_marginHorizontal="28dp"
|
||||
android:visibility="visible">
|
||||
|
||||
<!-- android:layout_width="300dp"-->
|
||||
<!-- android:layout_height="510dp"-->
|
||||
<FrameLayout
|
||||
android:id="@+id/flFace"
|
||||
android:layout_width="300dp"
|
||||
android:layout_height="510dp"
|
||||
android:layout_width="400dp"
|
||||
android:layout_height="680dp"
|
||||
android:layout_gravity="center_horizontal"
|
||||
android:layout_marginTop="-85dp"
|
||||
android:visibility="gone">
|
||||
|
||||
<TextureView
|
||||
android:id="@+id/dual_camera_texture_preview_rgb"
|
||||
android:layout_width="match_parent"
|
||||
@@ -68,44 +72,84 @@
|
||||
android:src="@drawable/face_mask"
|
||||
android:visibility="gone" />
|
||||
|
||||
<!-- <TextView-->
|
||||
<!-- android:id="@+id/tvFaceTip"-->
|
||||
<!-- android:layout_width="wrap_content"-->
|
||||
<!-- android:layout_height="wrap_content"-->
|
||||
<!-- android:layout_gravity="bottom|center"-->
|
||||
<!-- android:layout_marginBottom="56dp"-->
|
||||
<!-- android:text="请正视屏幕进行面部识别..."-->
|
||||
<!-- android:textColor="@color/white"-->
|
||||
<!-- android:textSize="22sp"-->
|
||||
<!-- android:visibility="gone" />-->
|
||||
|
||||
<!-- <ImageView-->
|
||||
<!-- android:layout_width="match_parent"-->
|
||||
<!-- android:layout_height="match_parent"-->
|
||||
<!-- android:layout_margin="28dp"-->
|
||||
<!-- android:background="@drawable/ic_camera_rect" />-->
|
||||
|
||||
</FrameLayout>
|
||||
|
||||
<FrameLayout
|
||||
android:id="@+id/llCircleArea"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:visibility="gone">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="center_vertical">
|
||||
|
||||
<View
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="1"
|
||||
android:background="#FFF4FAFF" />
|
||||
|
||||
<com.sw.dualscreen.view.HollowCircleRectView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center_horizontal" />
|
||||
|
||||
<View
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_weight="1"
|
||||
android:background="#FFF4FAFF" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tvFaceTip"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="bottom|center"
|
||||
android:layout_marginBottom="56dp"
|
||||
android:layout_marginBottom="0dp"
|
||||
android:layout_gravity="bottom|center_horizontal"
|
||||
android:text="请正视屏幕进行面部识别..."
|
||||
android:textColor="@color/white"
|
||||
android:textSize="22sp"
|
||||
android:visibility="gone" />
|
||||
|
||||
<ImageView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_margin="28dp"
|
||||
android:background="@drawable/ic_camera_rect" />
|
||||
|
||||
android:textColor="#FF0A1428"
|
||||
android:textSize="22sp" />
|
||||
</FrameLayout>
|
||||
|
||||
<!-- android:layout_height="456dp"-->
|
||||
<com.google.android.material.imageview.ShapeableImageView
|
||||
android:id="@+id/ivPreviewImage"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:scaleType="centerCrop"
|
||||
app:strokeColor="@android:color/transparent"
|
||||
app:shapeAppearance="@style/round10dpCornerStyle"
|
||||
tools:src="@mipmap/ic_launcher"/>
|
||||
app:strokeColor="@android:color/transparent"
|
||||
tools:src="@mipmap/ic_launcher" />
|
||||
|
||||
<com.google.android.material.imageview.ShapeableImageView
|
||||
android:id="@+id/ivRecImage"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:scaleType="centerCrop"
|
||||
tools:src="@mipmap/ic_launcher_round"
|
||||
app:strokeColor="@android:color/transparent"
|
||||
android:visibility="gone"
|
||||
app:shapeAppearance="@style/round10dpCornerStyle"
|
||||
android:visibility="gone"/>
|
||||
app:strokeColor="@android:color/transparent"
|
||||
tools:src="@mipmap/ic_launcher_round" />
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/ivFrame"
|
||||
@@ -120,8 +164,8 @@
|
||||
android:id="@+id/llPriceInfo"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="26dp"
|
||||
android:layout_gravity="center_horizontal"
|
||||
android:layout_marginTop="26dp"
|
||||
android:gravity="center_vertical"
|
||||
android:visibility="gone">
|
||||
|
||||
@@ -171,6 +215,7 @@
|
||||
android:id="@+id/tvFoodRecPrompt"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:background="@drawable/setting_border"
|
||||
android:gravity="center"
|
||||
android:shadowColor="#ffffffff"
|
||||
android:shadowDx="0"
|
||||
@@ -179,8 +224,7 @@
|
||||
android:text="先识别 后取餐"
|
||||
android:textColor="#ffff3232"
|
||||
android:textSize="80sp"
|
||||
android:textStyle="bold"
|
||||
android:background="@drawable/setting_border" />
|
||||
android:textStyle="bold" />
|
||||
|
||||
<include
|
||||
android:id="@+id/calorieInclude"
|
||||
@@ -232,6 +276,8 @@
|
||||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="554dp"
|
||||
android:layout_marginTop="28dp"
|
||||
android:background="@drawable/setting_border"
|
||||
android:gravity="center"
|
||||
android:shadowColor="#ffffffff"
|
||||
android:shadowDx="0"
|
||||
@@ -240,9 +286,7 @@
|
||||
android:text="先识别 后取餐"
|
||||
android:textColor="#ffff3232"
|
||||
android:textSize="80sp"
|
||||
android:textStyle="bold"
|
||||
android:layout_marginTop="28dp"
|
||||
android:background="@drawable/setting_border" />
|
||||
android:textStyle="bold" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user