|
|
@@ -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
|
|
|
+}
|