Skip to content

Commit

Permalink
Fix : scale bar texts missing on devices with api 23
Browse files Browse the repository at this point in the history
  • Loading branch information
ravenfeld committed Oct 13, 2024
1 parent 8f2efaf commit 653ac52
Showing 1 changed file with 8 additions and 13 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,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.
*
Expand Down

0 comments on commit 653ac52

Please sign in to comment.