From 472f70e8339801a8cc03d0024439bc6e6da0e290 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BE=90=E5=8B=A4=E6=B0=91?= Date: Thu, 16 Apr 2026 16:48:45 +0800 Subject: [PATCH] =?UTF-8?q?feat(ui):=20=E6=B7=BB=E5=8A=A0=E8=81=8A?= =?UTF-8?q?=E5=A4=A9=E8=83=8C=E6=99=AF=E7=BB=98=E5=88=B6=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 移除未使用的 ChatModel 导入 - 移除未使用的 Path 注解导入 - 新增 BgChatDrawable 类实现带缺口的边框绘制 - 实现圆形角矩形边框绘制功能 - 添加底部中央镂空区域用于放置加载指示器 - 支持自定义密度适配不同屏幕尺寸 --- .../nova/brain/glass/helper/BgChatDrawable.kt | 75 +++++++++++++++++++ .../nova/brain/glass/repository/Service.kt | 2 - 2 files changed, 75 insertions(+), 2 deletions(-) create mode 100644 app/src/main/java/com/nova/brain/glass/helper/BgChatDrawable.kt diff --git a/app/src/main/java/com/nova/brain/glass/helper/BgChatDrawable.kt b/app/src/main/java/com/nova/brain/glass/helper/BgChatDrawable.kt new file mode 100644 index 0000000..c827fd8 --- /dev/null +++ b/app/src/main/java/com/nova/brain/glass/helper/BgChatDrawable.kt @@ -0,0 +1,75 @@ +package com.nova.brain.glass.helper + +import android.graphics.* +import android.graphics.drawable.Drawable + +/** + * 带底部缺口的边框 Drawable。 + * 绘制完整的矩形圆角边框,但底边中央留出 [cutoutDp]dp 的镂空, + * 用于放置 loading 指示器。 + */ +class BgChatDrawable(private val density: Float) : Drawable() { + + private val strokeWidthPx = 2f * density + private val cornerRadiusPx = 4f * density + private val cutoutPx = 50f * density + + private val paint = Paint(Paint.ANTI_ALIAS_FLAG).apply { + color = Color.parseColor("#FF40FF5E") + style = Paint.Style.STROKE + strokeWidth = strokeWidthPx + strokeCap = Paint.Cap.BUTT + } + + private val path = Path() + + override fun draw(canvas: Canvas) { + val b = bounds + val half = strokeWidthPx / 2f + val l = b.left + half + val t = b.top + half + val r = b.right - half + val bot = b.bottom - half + val cx = (l + r) / 2f + val cutHalf = cutoutPx / 2f + val cr = cornerRadiusPx + + path.rewind() + + // 顶边(左上角 → 右上角) + path.moveTo(l + cr, t) + path.lineTo(r - cr, t) + path.arcTo(r - 2 * cr, t, r, t + 2 * cr, -90f, 90f, false) + + // 右边(右上角 → 右下角) + path.lineTo(r, bot - cr) + path.arcTo(r - 2 * cr, bot - 2 * cr, r, bot, 0f, 90f, false) + + // 底边右半段(右下角 → 缺口右侧) + path.lineTo(cx + cutHalf, bot) + + // 跳过底边中央 50dp(镂空) + path.moveTo(cx - cutHalf, bot) + + // 底边左半段(缺口左侧 → 左下角) + path.lineTo(l + cr, bot) + path.arcTo(l, bot - 2 * cr, l + 2 * cr, bot, 90f, 90f, false) + + // 左边(左下角 → 左上角) + path.lineTo(l, t + cr) + path.arcTo(l, t, l + 2 * cr, t + 2 * cr, 180f, 90f, false) + + canvas.drawPath(path, paint) + } + + override fun setAlpha(alpha: Int) { + paint.alpha = alpha + } + + override fun setColorFilter(colorFilter: ColorFilter?) { + paint.colorFilter = colorFilter + } + + @Suppress("OVERRIDE_DEPRECATION") + override fun getOpacity(): Int = PixelFormat.TRANSLUCENT +} \ No newline at end of file diff --git a/app/src/main/java/com/nova/brain/glass/repository/Service.kt b/app/src/main/java/com/nova/brain/glass/repository/Service.kt index dc62e59..f87726b 100644 --- a/app/src/main/java/com/nova/brain/glass/repository/Service.kt +++ b/app/src/main/java/com/nova/brain/glass/repository/Service.kt @@ -1,6 +1,5 @@ package com.nova.brain.glass.repository -import com.nova.brain.glass.model.ChatModel import com.nova.brain.glass.model.RecognizeModel import com.nova.brain.glass.model.data.ChatData import com.nova.brain.glass.model.data.RecognizeData @@ -10,7 +9,6 @@ import okhttp3.ResponseBody import retrofit2.http.Body import retrofit2.http.GET import retrofit2.http.POST -import retrofit2.http.Path import retrofit2.http.Streaming interface Service {