Last active
November 11, 2017 13:48
-
-
Save Krishan14sharma/5e116565b8659228381ba8f85f967849 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
override fun onDraw(canvas: Canvas) { | |
super.onDraw(canvas) | |
drawVerticalLines(canvas) | |
drawHorizontalLines(canvas) | |
drawSquareStates(canvas) // <------- here | |
if (touching) { | |
drawHighlightRectangle(canvas) | |
} | |
} | |
private fun drawSquareStates(canvas: Canvas) { | |
for ((i, textArray) in squareData.withIndex()) { | |
for ((j, text) in textArray.withIndex()) { | |
if (text.isNotEmpty()) { | |
drawTextInsideRectangle(canvas, squares[i][j], text) | |
} | |
} | |
} | |
} | |
// created in the previous post | |
private fun drawTextInsideRectangle(canvas: Canvas, rect: Rect, str: String) { | |
val xOffset = textPaint.measureText(str) * 0.5f | |
val yOffset = textPaint.fontMetrics.ascent * -0.4f | |
val textX = (rect.exactCenterX()) - xOffset | |
val textY = (rect.exactCenterY()) + yOffset | |
canvas.drawText(str, textX, textY, textPaint) | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment