Я пытаюсь создать маску для использования в Android, которая будет перед видом, отображающим камеру.Прямо сейчас у меня есть это, но я хочу, чтобы углы были скруглены.
вот как я создаю этот эффект (я рисую 4rects с цветом # 80000000)
class ViewMaskQRCode(
context: Context,
text: String,
colorMask: String,
alphaMask: Int,
typeface: Typeface,
sizeText: Int
) : View(context) {
private var mFramingRect: Rect? = null
private lateinit var maskBackground: Paint
private var textBottom: String? = text
private var mTypeface: Typeface? = typeface
private var mSizeText: Int = sizeText
init {
setupViewMask(colorMask, alphaMask)
}
private fun setupViewMask(colorMask: String, alphaMask: Int) {
maskBackground = Paint()
maskBackground.color = Color.parseColor(colorMask)
maskBackground.alpha = alphaMask
calculateSize()
invalidate()
}
private fun calculateSize() {
val viewResolution = Point(width, height)
var width: Int
width = (getWidth() * 0.65).toInt()
if (width > getWidth()) {
width = getWidth() - 50
}
val leftOffset = (viewResolution.x - width) / 2
val topOffset = (viewResolution.y - width) / 5
mFramingRect =
Rect(leftOffset, topOffset, leftOffset + width, topOffset + width)
}
override fun onSizeChanged(xNew: Int, yNew: Int, xOld: Int, yOld: Int) {
calculateSize()
}
override fun onDraw(canvas: Canvas) {
super.onDraw(canvas)
drawViewMask(canvas)
if (textBottom != null && !textBottom!!.isEmpty())
drawViewText(canvas)
}
private fun drawViewMask(canvas: Canvas) {
val width = canvas.width
val height = canvas.height
val framingRect = mFramingRect
canvas.drawRoundRect(RectF(
0F,
0F,
width.toFloat(),
framingRect!!.top.toFloat()),
0F, 0F,
maskBackground
)
canvas.drawRoundRect(RectF(
0F,
framingRect.top.toFloat(),
framingRect.left.toFloat(),
(framingRect.bottom + 1).toFloat()),
0F, 0F,
maskBackground
)
canvas.drawRoundRect(RectF(
(framingRect.right + 1).toFloat(),
framingRect.top.toFloat(),
width.toFloat(),
(framingRect.bottom + 1).toFloat()),
0F, 0F,
maskBackground
)
canvas.drawRoundRect(RectF(
0F,
(framingRect.bottom + 1).toFloat(),
width.toFloat(),
height.toFloat()),
0F, 0F,
maskBackground
)
}
@Suppress("DEPRECATION")
private fun drawViewText(canvas: Canvas) {
val framingRect = mFramingRect
val offsetTop = 90
val padding = 100
val paint = TextPaint()
paint.style = Paint.Style.FILL
paint.color = Color.WHITE
paint.textSize = mSizeText.toFloat()
paint.isFakeBoldText = true
paint.typeface = mTypeface
val width = canvas.width - padding
val textLayout = StaticLayout(
textBottom,
paint,
width,
Layout.Alignment.ALIGN_CENTER,
1.0f,
0.0f,
false)
canvas.save()
canvas.translate(
(framingRect!!.centerX() - width / 2).toFloat(),
(framingRect.bottom + offsetTop).toFloat())
textLayout.draw(canvas)
}
}
Как мне сделать закругленные углы?