Skip to content

Instantly share code, notes, and snippets.

@Semper-Viventem
Created January 28, 2020 16:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Semper-Viventem/0960652a66d78c1a7e8bb7cf072e071d to your computer and use it in GitHub Desktop.
Save Semper-Viventem/0960652a66d78c1a7e8bb7cf072e071d to your computer and use it in GitHub Desktop.
override fun drawBackground(
c: Canvas,
p: Paint,
left: Int,
right: Int,
top: Int,
baseline: Int,
bottom: Int,
text: CharSequence,
start: Int,
end: Int,
lnum: Int
) {
val actualWidth = p.measureText(text, start, end) + 2f * padding
val width = if (lnum == 0) {
actualWidth
} else if ((actualWidth < prevWidth) && (abs(prevWidth - actualWidth) < 2f * radius)) {
prevWidth
} else if ((actualWidth > prevWidth) && (abs(prevWidth - actualWidth) < 2f * radius)) {
actualWidth + (2f * radius - abs(prevWidth - actualWidth))
} else {
actualWidth
}
val shiftLeft = 0f - padding
val shiftRight = width + shiftLeft
rect.set(shiftLeft, top.toFloat(), shiftRight, bottom.toFloat())
c.drawRoundRect(rect, radius, radius, paint)
if (lnum > 0) {
drawCornerType1(c, path, rect, radius)
when {
prevWidth < width -> drawCornerType2(c, path, rect, radius)
prevWidth > width -> drawCornerType3(c, path, rect, radius)
else -> drawCornerType4(c, path, rect, radius)
}
}
prevWidth = width
prevLeft = rect.left
prevRight = rect.right
prevBottom = rect.bottom
prevTop = rect.top
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment