Skip to content

Commit

Permalink
Fix : scale bar texts missing on devices with api 23 (#72)
Browse files Browse the repository at this point in the history
  • Loading branch information
ravenfeld authored Oct 17, 2024
1 parent 4a439a4 commit 256967a
Showing 1 changed file with 8 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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,
Expand All @@ -121,13 +115,15 @@ protected void onDraw(Canvas canvas) {
}

String distanceText = getDistanceText(unitDistance * i);
textPaint.getTextPath(distanceText, 0, distanceText.length(), marginLeft + unitBarWidth * i,
textSize + marginTop, path);
drawText(canvas, distanceText, marginLeft + unitBarWidth * i, textSize + marginTop);

}

private void drawText(Canvas canvas, String text, Float x, Float y) {
if (showTextBorder) {
canvas.drawPath(path, strokePaint);
canvas.drawText(text, x, y, strokePaint);
}
canvas.drawPath(path, textPaint);

canvas.drawText(text, x, y, textPaint);
}

/**
Expand Down

0 comments on commit 256967a

Please sign in to comment.