Fixed issue 745, text not readable in night mode
This commit is contained in:
parent
1fc2f9369a
commit
cae73da448
4 changed files with 44 additions and 20 deletions
|
@ -188,15 +188,15 @@ public class MapControlsLayer extends OsmandMapLayer {
|
||||||
|
|
||||||
|
|
||||||
private void drawZoomLevel(Canvas canvas) {
|
private void drawZoomLevel(Canvas canvas) {
|
||||||
String zoomText = view.getZoom() + "";
|
ShadowText zoomText = ShadowText.create(view.getZoom() + "");
|
||||||
float length = zoomTextPaint.measureText(zoomText);
|
float length = zoomTextPaint.measureText(zoomText.getText());
|
||||||
if (zoomShadow.getBounds().width() == 0) {
|
if (zoomShadow.getBounds().width() == 0) {
|
||||||
zoomShadow.setBounds(zoomInButton.getLeft() - 2, zoomInButton.getTop() - (int) (18 * scaleCoefficient), zoomInButton.getRight(),
|
zoomShadow.setBounds(zoomInButton.getLeft() - 2, zoomInButton.getTop() - (int) (18 * scaleCoefficient), zoomInButton.getRight(),
|
||||||
zoomInButton.getBottom());
|
zoomInButton.getBottom());
|
||||||
}
|
}
|
||||||
zoomShadow.draw(canvas);
|
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);
|
zoomInButton.getTop() + 4 * scaleCoefficient, zoomTextPaint);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -372,7 +372,7 @@ public class MapControlsLayer extends OsmandMapLayer {
|
||||||
|
|
||||||
/////////////////////// Ruler ///////////////////
|
/////////////////////// Ruler ///////////////////
|
||||||
// cache values for ruler
|
// cache values for ruler
|
||||||
String cacheRulerText = null;
|
ShadowText cacheRulerText = null;
|
||||||
int cacheRulerZoom = 0;
|
int cacheRulerZoom = 0;
|
||||||
double cacheRulerTileX = 0;
|
double cacheRulerTileX = 0;
|
||||||
double cacheRulerTileY = 0;
|
double cacheRulerTileY = 0;
|
||||||
|
@ -397,8 +397,8 @@ public class MapControlsLayer extends OsmandMapLayer {
|
||||||
double roundedDist = OsmAndFormatter.calculateRoundedDist(dist * screenRulerPercent, view.getContext());
|
double roundedDist = OsmAndFormatter.calculateRoundedDist(dist * screenRulerPercent, view.getContext());
|
||||||
|
|
||||||
int cacheRulerDistPix = (int) (pixDensity * roundedDist);
|
int cacheRulerDistPix = (int) (pixDensity * roundedDist);
|
||||||
cacheRulerText = OsmAndFormatter.getFormattedDistance((float) roundedDist, view.getContext());
|
cacheRulerText = ShadowText.create(OsmAndFormatter.getFormattedDistance((float) roundedDist, view.getContext()));
|
||||||
cacheRulerTextLen = zoomTextPaint.measureText(cacheRulerText);
|
cacheRulerTextLen = zoomTextPaint.measureText(cacheRulerText.getText());
|
||||||
|
|
||||||
Rect bounds = rulerDrawable.getBounds();
|
Rect bounds = rulerDrawable.getBounds();
|
||||||
bounds.right = (int) (view.getWidth() - 7 * scaleCoefficient);
|
bounds.right = (int) (view.getWidth() - 7 * scaleCoefficient);
|
||||||
|
@ -410,7 +410,7 @@ public class MapControlsLayer extends OsmandMapLayer {
|
||||||
if (cacheRulerText != null) {
|
if (cacheRulerText != null) {
|
||||||
rulerDrawable.draw(canvas);
|
rulerDrawable.draw(canvas);
|
||||||
Rect bounds = rulerDrawable.getBounds();
|
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);
|
rulerTextPaint);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,10 +2,8 @@ package net.osmand.plus.views;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.graphics.Canvas;
|
import android.graphics.Canvas;
|
||||||
import android.graphics.Color;
|
|
||||||
import android.graphics.Paint;
|
import android.graphics.Paint;
|
||||||
import android.graphics.Rect;
|
import android.graphics.Rect;
|
||||||
import android.graphics.Paint.Style;
|
|
||||||
import android.graphics.drawable.Drawable;
|
import android.graphics.drawable.Drawable;
|
||||||
import android.view.View;
|
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) {
|
protected void drawShadowText(Canvas cv, String text, float centerX, float centerY, Paint textPaint) {
|
||||||
int c = textPaint.getColor();
|
ShadowText.create(text).draw(cv, centerX, centerY, textPaint);
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
36
OsmAnd/src/net/osmand/plus/views/ShadowText.java
Normal file
36
OsmAnd/src/net/osmand/plus/views/ShadowText.java
Normal file
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
|
@ -7,7 +7,6 @@ import net.osmand.data.TransportStop;
|
||||||
import net.osmand.osm.LatLon;
|
import net.osmand.osm.LatLon;
|
||||||
import net.osmand.plus.R;
|
import net.osmand.plus.R;
|
||||||
import net.osmand.plus.TransportIndexRepository;
|
import net.osmand.plus.TransportIndexRepository;
|
||||||
import net.osmand.plus.views.OsmBugsLayer.OpenStreetBug;
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.DialogInterface.OnClickListener;
|
import android.content.DialogInterface.OnClickListener;
|
||||||
import android.graphics.Canvas;
|
import android.graphics.Canvas;
|
||||||
|
|
Loading…
Reference in a new issue