From cae73da448089551e082b4cb316b69cecacfc014 Mon Sep 17 00:00:00 2001 From: Pavol Zibrita Date: Fri, 9 Dec 2011 02:28:31 +0100 Subject: [PATCH] Fixed issue 745, text not readable in night mode --- .../osmand/plus/views/MapControlsLayer.java | 14 ++++---- .../net/osmand/plus/views/MapInfoControl.java | 13 +------ .../src/net/osmand/plus/views/ShadowText.java | 36 +++++++++++++++++++ .../plus/views/TransportStopsLayer.java | 1 - 4 files changed, 44 insertions(+), 20 deletions(-) create mode 100644 OsmAnd/src/net/osmand/plus/views/ShadowText.java diff --git a/OsmAnd/src/net/osmand/plus/views/MapControlsLayer.java b/OsmAnd/src/net/osmand/plus/views/MapControlsLayer.java index 633b8624c7..9e50b0189e 100644 --- a/OsmAnd/src/net/osmand/plus/views/MapControlsLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/MapControlsLayer.java @@ -188,15 +188,15 @@ public class MapControlsLayer extends OsmandMapLayer { private void drawZoomLevel(Canvas canvas) { - String zoomText = view.getZoom() + ""; - float length = zoomTextPaint.measureText(zoomText); + ShadowText zoomText = ShadowText.create(view.getZoom() + ""); + float length = zoomTextPaint.measureText(zoomText.getText()); if (zoomShadow.getBounds().width() == 0) { zoomShadow.setBounds(zoomInButton.getLeft() - 2, zoomInButton.getTop() - (int) (18 * scaleCoefficient), zoomInButton.getRight(), zoomInButton.getBottom()); } zoomShadow.draw(canvas); - canvas.drawText(zoomText, zoomInButton.getLeft() + (zoomInButton.getWidth() - length - 2) / 2, + zoomText.draw(canvas, zoomInButton.getLeft() + (zoomInButton.getWidth() - length - 2) / 2, zoomInButton.getTop() + 4 * scaleCoefficient, zoomTextPaint); } @@ -372,7 +372,7 @@ public class MapControlsLayer extends OsmandMapLayer { /////////////////////// Ruler /////////////////// // cache values for ruler - String cacheRulerText = null; + ShadowText cacheRulerText = null; int cacheRulerZoom = 0; double cacheRulerTileX = 0; double cacheRulerTileY = 0; @@ -397,8 +397,8 @@ public class MapControlsLayer extends OsmandMapLayer { double roundedDist = OsmAndFormatter.calculateRoundedDist(dist * screenRulerPercent, view.getContext()); int cacheRulerDistPix = (int) (pixDensity * roundedDist); - cacheRulerText = OsmAndFormatter.getFormattedDistance((float) roundedDist, view.getContext()); - cacheRulerTextLen = zoomTextPaint.measureText(cacheRulerText); + cacheRulerText = ShadowText.create(OsmAndFormatter.getFormattedDistance((float) roundedDist, view.getContext())); + cacheRulerTextLen = zoomTextPaint.measureText(cacheRulerText.getText()); Rect bounds = rulerDrawable.getBounds(); bounds.right = (int) (view.getWidth() - 7 * scaleCoefficient); @@ -410,7 +410,7 @@ public class MapControlsLayer extends OsmandMapLayer { if (cacheRulerText != null) { rulerDrawable.draw(canvas); Rect bounds = rulerDrawable.getBounds(); - canvas.drawText(cacheRulerText, bounds.left + (bounds.width() - cacheRulerTextLen) / 2, bounds.bottom - 8 * scaleCoefficient, + cacheRulerText.draw(canvas, bounds.left + (bounds.width() - cacheRulerTextLen) / 2, bounds.bottom - 8 * scaleCoefficient, rulerTextPaint); } } diff --git a/OsmAnd/src/net/osmand/plus/views/MapInfoControl.java b/OsmAnd/src/net/osmand/plus/views/MapInfoControl.java index 358a297118..2829350f59 100644 --- a/OsmAnd/src/net/osmand/plus/views/MapInfoControl.java +++ b/OsmAnd/src/net/osmand/plus/views/MapInfoControl.java @@ -2,10 +2,8 @@ package net.osmand.plus.views; import android.content.Context; import android.graphics.Canvas; -import android.graphics.Color; import android.graphics.Paint; import android.graphics.Rect; -import android.graphics.Paint.Style; import android.graphics.drawable.Drawable; import android.view.View; @@ -48,16 +46,7 @@ public abstract class MapInfoControl extends View { } protected void drawShadowText(Canvas cv, String text, float centerX, float centerY, Paint textPaint) { - int c = textPaint.getColor(); - textPaint.setStyle(Style.STROKE); - textPaint.setColor(Color.WHITE); - textPaint.setStrokeWidth(4); - cv.drawText(text, centerX, centerY, textPaint); - // reset - textPaint.setStrokeWidth(1); - textPaint.setStyle(Style.FILL); - textPaint.setColor(c); - cv.drawText(text, centerX, centerY, textPaint); + ShadowText.create(text).draw(cv, centerX, centerY, textPaint); } @Override diff --git a/OsmAnd/src/net/osmand/plus/views/ShadowText.java b/OsmAnd/src/net/osmand/plus/views/ShadowText.java new file mode 100644 index 0000000000..eab1cf4838 --- /dev/null +++ b/OsmAnd/src/net/osmand/plus/views/ShadowText.java @@ -0,0 +1,36 @@ +package net.osmand.plus.views; + +import android.graphics.Canvas; +import android.graphics.Color; +import android.graphics.Paint; +import android.graphics.Paint.Style; + +public class ShadowText { + + private final String text; + + ShadowText(String text) { + this.text = text; + } + + public static ShadowText create(String text) { + return new ShadowText(text); + } + + protected void draw(Canvas cv, float centerX, float centerY, Paint textPaint) { + int c = textPaint.getColor(); + textPaint.setStyle(Style.STROKE); + textPaint.setColor(Color.WHITE); + textPaint.setStrokeWidth(4); + cv.drawText(text, centerX, centerY, textPaint); + // reset + textPaint.setStrokeWidth(1); + textPaint.setStyle(Style.FILL); + textPaint.setColor(c); + cv.drawText(text, centerX, centerY, textPaint); + } + + public String getText() { + return text; + } +} diff --git a/OsmAnd/src/net/osmand/plus/views/TransportStopsLayer.java b/OsmAnd/src/net/osmand/plus/views/TransportStopsLayer.java index 6cdd7fb90c..0eeeca29f7 100644 --- a/OsmAnd/src/net/osmand/plus/views/TransportStopsLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/TransportStopsLayer.java @@ -7,7 +7,6 @@ import net.osmand.data.TransportStop; import net.osmand.osm.LatLon; import net.osmand.plus.R; import net.osmand.plus.TransportIndexRepository; -import net.osmand.plus.views.OsmBugsLayer.OpenStreetBug; import android.content.Context; import android.content.DialogInterface.OnClickListener; import android.graphics.Canvas;