From 6f95bb2802d8f6dfe5b03f4df548f1a6aae7cc48 Mon Sep 17 00:00:00 2001 From: Hannes Achleitner Date: Mon, 5 Jan 2026 08:13:02 +0100 Subject: [PATCH 1/2] Remove deprecation with StaticLayout --- .../charting/renderer/PieChartRenderer.kt | 42 ++++++++++++------- 1 file changed, 26 insertions(+), 16 deletions(-) diff --git a/chartLib/src/main/kotlin/info/appdev/charting/renderer/PieChartRenderer.kt b/chartLib/src/main/kotlin/info/appdev/charting/renderer/PieChartRenderer.kt index ba05989e2..16610ed5c 100644 --- a/chartLib/src/main/kotlin/info/appdev/charting/renderer/PieChartRenderer.kt +++ b/chartLib/src/main/kotlin/info/appdev/charting/renderer/PieChartRenderer.kt @@ -688,31 +688,41 @@ open class PieChartRenderer( val width = centerTextLastBounds.width() // If width is 0, it will crash. Always have a minimum of 1 - centerTextLayout = StaticLayout( +// centerTextLayout = StaticLayout( +// centerText, +// 0, +// centerText.length, +// paintCenterText, +// max(ceil(width.toDouble()), 1.0).toInt(), +// Layout.Alignment.ALIGN_CENTER, +// 1f, +// 0f, +// false +// ) + centerTextLayout = StaticLayout.Builder.obtain( centerText, 0, centerText.length, paintCenterText, - max(ceil(width.toDouble()), 1.0).toInt(), - Layout.Alignment.ALIGN_CENTER, - 1f, - 0f, - false - ) - } + max(ceil(width.toDouble()), 1.0).toInt() + ).setAlignment(Layout.Alignment.ALIGN_CENTER) + .setLineSpacing(0f, 1f) + .setIncludePad(false) + .build() - val layoutHeight = centerTextLayout!!.height.toFloat() + val layoutHeight = centerTextLayout!!.height.toFloat() - canvas.withSave { - mDrawCenterTextPathBuffer.reset() - mDrawCenterTextPathBuffer.addOval(holeRect, Path.Direction.CW) - clipPath(mDrawCenterTextPathBuffer) + canvas.withSave { + mDrawCenterTextPathBuffer.reset() + mDrawCenterTextPathBuffer.addOval(holeRect, Path.Direction.CW) + clipPath(mDrawCenterTextPathBuffer) - translate(boundingRect.left, boundingRect.top + (boundingRect.height() - layoutHeight) / 2f) - centerTextLayout!!.draw(this) + translate(boundingRect.left, boundingRect.top + (boundingRect.height() - layoutHeight) / 2f) + centerTextLayout!!.draw(this) - } + } + } PointF.recycleInstance(center) PointF.recycleInstance(offset) } From 037a284041bc8e2687abe35154f3d7f477ca47b5 Mon Sep 17 00:00:00 2001 From: Hannes Achleitner Date: Sun, 1 Feb 2026 14:04:28 +0100 Subject: [PATCH 2/2] Next try --- .../charting/renderer/PieChartRenderer.kt | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/chartLib/src/main/kotlin/info/appdev/charting/renderer/PieChartRenderer.kt b/chartLib/src/main/kotlin/info/appdev/charting/renderer/PieChartRenderer.kt index 16610ed5c..f94c2301d 100644 --- a/chartLib/src/main/kotlin/info/appdev/charting/renderer/PieChartRenderer.kt +++ b/chartLib/src/main/kotlin/info/appdev/charting/renderer/PieChartRenderer.kt @@ -709,19 +709,17 @@ open class PieChartRenderer( .setLineSpacing(0f, 1f) .setIncludePad(false) .build() + } - val layoutHeight = centerTextLayout!!.height.toFloat() - - canvas.withSave { - mDrawCenterTextPathBuffer.reset() - mDrawCenterTextPathBuffer.addOval(holeRect, Path.Direction.CW) - clipPath(mDrawCenterTextPathBuffer) - - translate(boundingRect.left, boundingRect.top + (boundingRect.height() - layoutHeight) / 2f) - centerTextLayout!!.draw(this) + val layoutHeight = centerTextLayout!!.height.toFloat() - } + canvas.withSave { + mDrawCenterTextPathBuffer.reset() + mDrawCenterTextPathBuffer.addOval(holeRect, Path.Direction.CW) + clipPath(mDrawCenterTextPathBuffer) + translate(boundingRect.left, boundingRect.top + (boundingRect.height() - layoutHeight) / 2f) + centerTextLayout!!.draw(this) } PointF.recycleInstance(center) PointF.recycleInstance(offset)