From d5366368b70ae552145a926fcd21fb34d9145a02 Mon Sep 17 00:00:00 2001 From: max-klaus Date: Thu, 30 Apr 2020 16:31:03 +0300 Subject: [PATCH] Fix poi layer icons --- .../osmand/plus/render/RenderingIcons.java | 22 ++++++++++++++++++- .../net/osmand/plus/views/POIMapLayer.java | 22 ++++++++++--------- 2 files changed, 33 insertions(+), 11 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/render/RenderingIcons.java b/OsmAnd/src/net/osmand/plus/render/RenderingIcons.java index 612ac54b4f..fc6e3f40c1 100644 --- a/OsmAnd/src/net/osmand/plus/render/RenderingIcons.java +++ b/OsmAnd/src/net/osmand/plus/render/RenderingIcons.java @@ -147,7 +147,27 @@ public class RenderingIcons { } return iconsBmp.get(s); } - + + public static Drawable getDrawableIcon(Context ctx, String s, boolean includeShader) { + if (s == null) { + return null; + } + if (includeShader && shaderIcons.containsKey(s)) { + s = "h_" + s; + } + Integer drawableId = s.startsWith("h_") ? shaderIcons.get(s.substring(2)) : smallIcons.get(s); + if (drawableId != null) { + Drawable drawable = ContextCompat.getDrawable(ctx, drawableId); + if (drawable != null) { + if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) { + drawable = (DrawableCompat.wrap(drawable)).mutate(); + } + } + return drawable; + } + return null; + } + public static Integer getResId(String id) { return id.startsWith("h_") ? shaderIcons.get(id.substring(2)) : smallIcons.get(id); } diff --git a/OsmAnd/src/net/osmand/plus/views/POIMapLayer.java b/OsmAnd/src/net/osmand/plus/views/POIMapLayer.java index 04eade58e2..86e1b1be86 100644 --- a/OsmAnd/src/net/osmand/plus/views/POIMapLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/POIMapLayer.java @@ -61,11 +61,11 @@ public class POIMapLayer extends OsmandMapLayer implements ContextMenuLayer.ICon public static final org.apache.commons.logging.Log log = PlatformUtil.getLog(POIMapLayer.class); - private Paint paintIcon; - private Paint paintIconBackground; private Bitmap poiBackground; private Bitmap poiBackgroundSmall; + private PorterDuffColorFilter poiColorFilter; + private int poiSize; private OsmandMapTileView view; @@ -176,11 +176,8 @@ public class POIMapLayer extends OsmandMapLayer implements ContextMenuLayer.ICon public void initLayer(OsmandMapTileView view) { this.view = view; - paintIcon = new Paint(); - //paintIcon.setStrokeWidth(1); - //paintIcon.setStyle(Style.STROKE); - //paintIcon.setColor(Color.BLUE); - paintIcon.setColorFilter(new PorterDuffColorFilter(Color.WHITE, PorterDuff.Mode.SRC_IN)); + poiSize = dpToPx(view.getContext(), 16f); + poiColorFilter = new PorterDuffColorFilter(Color.WHITE, PorterDuff.Mode.SRC_IN); paintIconBackground = new Paint(); poiBackground = BitmapFactory.decodeResource(view.getResources(), R.drawable.map_white_orange_poi_shield); poiBackgroundSmall = BitmapFactory.decodeResource(view.getResources(), R.drawable.map_white_orange_poi_shield_small); @@ -263,9 +260,14 @@ public class POIMapLayer extends OsmandMapLayer implements ContextMenuLayer.ICon } } if (id != null) { - Bitmap bmp = RenderingIcons.getIcon(view.getContext(), id, false); - if (bmp != null) { - canvas.drawBitmap(bmp, x - bmp.getWidth() / 2, y - bmp.getHeight() / 2, paintIcon); + Drawable img = RenderingIcons.getDrawableIcon(view.getContext(), id, false); + if (img != null) { + canvas.save(); + canvas.translate(x - poiSize / 2f, y - poiSize / 2f); + img.setBounds(0, 0, poiSize, poiSize); + img.setColorFilter(poiColorFilter); + img.draw(canvas); + canvas.restore(); } } }