From 653ac526f90b5d5172b74315e3b3a8ab46919bcb Mon Sep 17 00:00:00 2001 From: Alexis Lecanu Date: Sun, 13 Oct 2024 10:59:24 +0200 Subject: [PATCH] Fix : scale bar texts missing on devices with api 23 --- .../plugins/scalebar/ScaleBarWidget.java | 21 +++++++------------ 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/plugin-scalebar/src/main/java/org/maplibre/android/plugins/scalebar/ScaleBarWidget.java b/plugin-scalebar/src/main/java/org/maplibre/android/plugins/scalebar/ScaleBarWidget.java index 9b2bdb76..6641c192 100644 --- a/plugin-scalebar/src/main/java/org/maplibre/android/plugins/scalebar/ScaleBarWidget.java +++ b/plugin-scalebar/src/main/java/org/maplibre/android/plugins/scalebar/ScaleBarWidget.java @@ -4,7 +4,6 @@ import android.graphics.Canvas; import android.graphics.Color; import android.graphics.Paint; -import android.graphics.Path; import android.os.Handler; import android.os.Message; import android.util.Pair; @@ -45,7 +44,6 @@ public class ScaleBarWidget extends View { private String unit; private final RefreshHandler refreshHandler; private DecimalFormat decimalFormat = new DecimalFormat("0.#"); - private Path path = new Path(); ScaleBarWidget(@NonNull Context context) { super(context); @@ -107,11 +105,7 @@ protected void onDraw(Canvas canvas) { barPaint.setColor(i % 2 == 0 ? primaryColor : secondaryColor); String text = i == 0 ? String.valueOf(unitDistance * i) : getDistanceText(unitDistance * i); - textPaint.getTextPath(text, 0, text.length(), marginLeft + unitBarWidth * i, textSize + marginTop, path); - if (showTextBorder) { - canvas.drawPath(path, strokePaint); - } - canvas.drawPath(path, textPaint); + drawText(canvas, text, marginLeft + unitBarWidth * i, textSize + marginTop); canvas.drawRect(marginLeft + unitBarWidth * i, textBarMargin + textSize + marginTop, @@ -121,15 +115,16 @@ protected void onDraw(Canvas canvas) { } String distanceText = getDistanceText(unitDistance * i); - textPaint.getTextPath(distanceText, 0, distanceText.length(), marginLeft + unitBarWidth * i, - textSize + marginTop, path); - if (showTextBorder) { - canvas.drawPath(path, strokePaint); - } - canvas.drawPath(path, textPaint); + drawText(canvas, distanceText, marginLeft + unitBarWidth * i, textSize + marginTop); } + private void drawText(Canvas canvas, String text, Float x, Float y) { + if (showTextBorder) { + canvas.drawText(text, x, y, strokePaint); + } + canvas.drawText(text, x, y, textPaint); + } /** * Update the scale when mapView's scale has changed. *