feat(ui): 添加聊天背景绘制功能
- 移除未使用的 ChatModel 导入 - 移除未使用的 Path 注解导入 - 新增 BgChatDrawable 类实现带缺口的边框绘制 - 实现圆形角矩形边框绘制功能 - 添加底部中央镂空区域用于放置加载指示器 - 支持自定义密度适配不同屏幕尺寸
这个提交包含在:
父节点
8288b417cb
当前提交
472f70e833
@ -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
|
||||||
|
}
|
||||||
@ -1,6 +1,5 @@
|
|||||||
package com.nova.brain.glass.repository
|
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.RecognizeModel
|
||||||
import com.nova.brain.glass.model.data.ChatData
|
import com.nova.brain.glass.model.data.ChatData
|
||||||
import com.nova.brain.glass.model.data.RecognizeData
|
import com.nova.brain.glass.model.data.RecognizeData
|
||||||
@ -10,7 +9,6 @@ import okhttp3.ResponseBody
|
|||||||
import retrofit2.http.Body
|
import retrofit2.http.Body
|
||||||
import retrofit2.http.GET
|
import retrofit2.http.GET
|
||||||
import retrofit2.http.POST
|
import retrofit2.http.POST
|
||||||
import retrofit2.http.Path
|
|
||||||
import retrofit2.http.Streaming
|
import retrofit2.http.Streaming
|
||||||
|
|
||||||
interface Service {
|
interface Service {
|
||||||
|
|||||||
正在加载...
在新工单中引用
屏蔽一个用户