Skip to content

Commit e46da56

Browse files
committed
Remove deprecation with StaticLayout
1 parent 97256f5 commit e46da56

File tree

1 file changed

+22
-16
lines changed

1 file changed

+22
-16
lines changed

chartLib/src/main/kotlin/info/appdev/charting/renderer/PieChartRenderer.kt

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -680,24 +680,30 @@ open class PieChartRenderer(
680680
val width = centerTextLastBounds.width()
681681

682682
// If width is 0, it will crash. Always have a minimum of 1
683-
centerTextLayout = StaticLayout(
684-
centerText, 0, centerText.length, paintCenterText, max(ceil(width.toDouble()), 1.0).toInt(), Layout.Alignment.ALIGN_CENTER, 1f, 0f, false
685-
)
686-
}
687-
688-
val layoutHeight = centerTextLayout!!.height.toFloat()
689-
690-
canvas.withSave {
691-
val path = mDrawCenterTextPathBuffer
692-
path.reset()
693-
path.addOval(holeRect, Path.Direction.CW)
694-
clipPath(path)
695-
696-
translate(boundingRect.left, boundingRect.top + (boundingRect.height() - layoutHeight) / 2f)
697-
centerTextLayout!!.draw(this)
683+
centerTextLayout = StaticLayout.Builder.obtain(
684+
centerText,
685+
0,
686+
centerText.length,
687+
paintCenterText,
688+
max(ceil(width.toDouble()), 1.0).toInt()
689+
).setAlignment(Layout.Alignment.ALIGN_NORMAL)
690+
.setLineSpacing(0.0f, 1.0f)
691+
.setIncludePad(true)
692+
.build()
693+
694+
val layoutHeight = centerTextLayout!!.height.toFloat()
695+
696+
canvas.withSave {
697+
val path = mDrawCenterTextPathBuffer
698+
path.reset()
699+
path.addOval(holeRect, Path.Direction.CW)
700+
clipPath(path)
701+
702+
translate(boundingRect.left, boundingRect.top + (boundingRect.height() - layoutHeight) / 2f)
703+
centerTextLayout!!.draw(this)
698704

705+
}
699706
}
700-
701707
PointF.recycleInstance(center)
702708
PointF.recycleInstance(offset)
703709
}

0 commit comments

Comments
 (0)