This commit is contained in:
Victor Shcherb 2020-05-19 16:08:04 +02:00
parent 4c0abd6918
commit 8febf17ea4
2 changed files with 11 additions and 39 deletions

View file

@ -10,7 +10,6 @@ import android.graphics.Paint;
import android.graphics.PointF; import android.graphics.PointF;
import android.graphics.PorterDuff; import android.graphics.PorterDuff;
import android.graphics.PorterDuffColorFilter; import android.graphics.PorterDuffColorFilter;
import android.graphics.RectF;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
import android.text.util.Linkify; import android.text.util.Linkify;
import android.util.TypedValue; import android.util.TypedValue;
@ -66,7 +65,6 @@ public class POIMapLayer extends OsmandMapLayer implements ContextMenuLayer.ICon
private Bitmap poiBackground; private Bitmap poiBackground;
private Bitmap poiBackgroundSmall; private Bitmap poiBackgroundSmall;
private PorterDuffColorFilter poiColorFilter; private PorterDuffColorFilter poiColorFilter;
private float textScale;
private int poiSize; private int poiSize;
private OsmandMapTileView view; private OsmandMapTileView view;
@ -86,7 +84,6 @@ public class POIMapLayer extends OsmandMapLayer implements ContextMenuLayer.ICon
routingHelper = activity.getRoutingHelper(); routingHelper = activity.getRoutingHelper();
routingHelper.addListener(this); routingHelper.addListener(this);
app = activity.getMyApplication(); app = activity.getMyApplication();
textScale = app.getSettings().TEXT_SCALE.get();
data = new OsmandMapLayer.MapLayerData<List<Amenity>>() { data = new OsmandMapLayer.MapLayerData<List<Amenity>>() {
Set<PoiUIFilter> calculatedFilters; Set<PoiUIFilter> calculatedFilters;
@ -223,8 +220,7 @@ public class POIMapLayer extends OsmandMapLayer implements ContextMenuLayer.ICon
data.queryNewData(tileBox); data.queryNewData(tileBox);
objects = data.getResults(); objects = data.getResults();
if (objects != null) { if (objects != null) {
textScale = app.getSettings().TEXT_SCALE.get(); float iconSize = poiBackground.getWidth() * 3 / 2;
float iconSize = poiBackground.getWidth() * 3 / 2 * textScale;
QuadTree<QuadRect> boundIntersections = initBoundIntersections(tileBox); QuadTree<QuadRect> boundIntersections = initBoundIntersections(tileBox);
WaypointHelper wph = app.getWaypointHelper(); WaypointHelper wph = app.getWaypointHelper();
@ -237,11 +233,7 @@ public class POIMapLayer extends OsmandMapLayer implements ContextMenuLayer.ICon
if (tileBox.containsPoint(x, y, iconSize)) { if (tileBox.containsPoint(x, y, iconSize)) {
if (intersects(boundIntersections, x, y, iconSize, iconSize) || if (intersects(boundIntersections, x, y, iconSize, iconSize) ||
(app.getSettings().SHOW_NEARBY_POI.get() && wph.isRouteCalculated() && !wph.isAmenityNoPassed(o))) { (app.getSettings().SHOW_NEARBY_POI.get() && wph.isRouteCalculated() && !wph.isAmenityNoPassed(o))) {
float scaledWidth = poiBackgroundSmall.getWidth() * textScale; canvas.drawBitmap(poiBackgroundSmall, x - poiBackgroundSmall.getWidth() / 2, y - poiBackgroundSmall.getHeight() / 2, paintIconBackground);
float scaledHeight = poiBackgroundSmall.getHeight() * textScale;
RectF rct = new RectF(0, 0, scaledWidth, scaledHeight);
rct.offset(x - scaledWidth / 2f, y - scaledHeight / 2f);
canvas.drawBitmap(poiBackgroundSmall, null, rct, paintIconBackground);
smallObjectsLatLon.add(new LatLon(o.getLocation().getLatitude(), smallObjectsLatLon.add(new LatLon(o.getLocation().getLatitude(),
o.getLocation().getLongitude())); o.getLocation().getLongitude()));
} else { } else {
@ -257,11 +249,7 @@ public class POIMapLayer extends OsmandMapLayer implements ContextMenuLayer.ICon
int y = (int) tileBox.getPixYFromLatLon(o.getLocation().getLatitude(), o.getLocation() int y = (int) tileBox.getPixYFromLatLon(o.getLocation().getLatitude(), o.getLocation()
.getLongitude()); .getLongitude());
if (tileBox.containsPoint(x, y, iconSize)) { if (tileBox.containsPoint(x, y, iconSize)) {
float scaledWidth = poiBackground.getWidth() * textScale; canvas.drawBitmap(poiBackground, x - poiBackground.getWidth() / 2, y - poiBackground.getHeight() / 2, paintIconBackground);
float scaledHeight = poiBackground.getHeight() * textScale;
RectF rct = new RectF(0, 0, scaledWidth, scaledHeight);
rct.offset(x - scaledWidth / 2f, y - scaledHeight / 2f);
canvas.drawBitmap(poiBackground, null, rct, paintIconBackground);
String id = null; String id = null;
PoiType st = o.getType().getPoiTypeByKeyName(o.getSubType()); PoiType st = o.getType().getPoiTypeByKeyName(o.getSubType());
if (st != null) { if (st != null) {
@ -274,10 +262,9 @@ public class POIMapLayer extends OsmandMapLayer implements ContextMenuLayer.ICon
if (id != null) { if (id != null) {
Drawable img = RenderingIcons.getDrawableIcon(view.getContext(), id, false); Drawable img = RenderingIcons.getDrawableIcon(view.getContext(), id, false);
if (img != null) { if (img != null) {
int scaledPoiSize = (int) (poiSize * textScale);
canvas.save(); canvas.save();
canvas.translate(x - scaledPoiSize / 2f, y - scaledPoiSize / 2f); canvas.translate(x - poiSize / 2f, y - poiSize / 2f);
img.setBounds(0, 0, scaledPoiSize, scaledPoiSize); img.setBounds(0, 0, poiSize, poiSize);
img.setColorFilter(poiColorFilter); img.setColorFilter(poiColorFilter);
img.draw(canvas); img.draw(canvas);
canvas.restore(); canvas.restore();

View file

@ -10,8 +10,6 @@ import android.graphics.Path;
import android.graphics.PointF; import android.graphics.PointF;
import android.graphics.PorterDuff; import android.graphics.PorterDuff;
import android.graphics.PorterDuffColorFilter; import android.graphics.PorterDuffColorFilter;
import android.graphics.Rect;
import android.graphics.RectF;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
import android.util.DisplayMetrics; import android.util.DisplayMetrics;
import android.view.WindowManager; import android.view.WindowManager;
@ -27,7 +25,7 @@ import net.osmand.data.RotatedTileBox;
import net.osmand.data.TransportStop; import net.osmand.data.TransportStop;
import net.osmand.osm.edit.Node; import net.osmand.osm.edit.Node;
import net.osmand.osm.edit.Way; import net.osmand.osm.edit.Way;
import net.osmand.plus.OsmandSettings; import net.osmand.plus.settings.backend.OsmandSettings;
import net.osmand.plus.R; import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity; import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.render.RenderingIcons; import net.osmand.plus.render.RenderingIcons;
@ -67,13 +65,11 @@ public class TransportStopsLayer extends OsmandMapLayer implements ContextMenuLa
private Path path; private Path path;
private float backgroundIconHalfWidth; private float backgroundIconHalfWidth;
private float backgroundIconHalfHeight; private float backgroundIconHalfHeight;
private float textScale;
public TransportStopsLayer(MapActivity mapActivity) { public TransportStopsLayer(MapActivity mapActivity) {
this.mapActivity = mapActivity; this.mapActivity = mapActivity;
OsmandSettings settings = mapActivity.getMyApplication().getSettings(); OsmandSettings settings = mapActivity.getMyApplication().getSettings();
showTransportStops = settings.getCustomRenderBooleanProperty(TRANSPORT_STOPS_OVER_MAP).cache(); showTransportStops = settings.getCustomRenderBooleanProperty(TRANSPORT_STOPS_OVER_MAP).cache();
textScale = settings.TEXT_SCALE.get();
} }
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
@ -237,8 +233,7 @@ public class TransportStopsLayer extends OsmandMapLayer implements ContextMenuLa
} }
if (objects != null) { if (objects != null) {
textScale = mapActivity.getMyApplication().getSettings().TEXT_SCALE.get(); float iconSize = stopBus.getWidth() * 3 / 2.5f;
float iconSize = stopBus.getWidth() * 3 / 2.5f * textScale;
QuadTree<QuadRect> boundIntersections = initBoundIntersections(tb); QuadTree<QuadRect> boundIntersections = initBoundIntersections(tb);
List<TransportStop> fullObjects = new ArrayList<>(); List<TransportStop> fullObjects = new ArrayList<>();
for (TransportStop o : objects) { for (TransportStop o : objects) {
@ -259,27 +254,17 @@ public class TransportStopsLayer extends OsmandMapLayer implements ContextMenuLa
TransportStopType type = TransportStopType.findType(stopRoute.route.getType()); TransportStopType type = TransportStopType.findType(stopRoute.route.getType());
if (type != null) { if (type != null) {
Drawable foregroundIcon = RenderingIcons.getDrawableIcon(mapActivity, type.getResName(), false); Drawable foregroundIcon = RenderingIcons.getDrawableIcon(mapActivity, type.getResName(), false);
float scaledWidth = backgroundIcon.getWidth() * textScale; canvas.drawBitmap(backgroundIcon, x - backgroundIconHalfWidth, y - backgroundIconHalfHeight, paintIcon);
float scaledHeight = backgroundIcon.getHeight() * textScale;
RectF rct = new RectF(0, 0, scaledWidth, scaledHeight);
rct.offset(x - scaledWidth / 2f, y - scaledHeight / 2f);
canvas.drawBitmap(backgroundIcon, null, rct, paintIcon);
canvas.save(); canvas.save();
scaledWidth = foregroundIcon.getIntrinsicWidth() * textScale; canvas.translate(x - foregroundIcon.getIntrinsicWidth() / 2f, y - foregroundIcon.getIntrinsicHeight() / 2f);
scaledHeight = foregroundIcon.getIntrinsicHeight() * textScale; foregroundIcon.setBounds(0, 0, foregroundIcon.getIntrinsicWidth(), foregroundIcon.getIntrinsicHeight());
canvas.translate(x - scaledWidth / 2f, y - scaledHeight / 2f);
foregroundIcon.setBounds(0, 0, (int) scaledWidth, (int) scaledHeight);
foregroundIcon.setColorFilter(nightMode ? paintDarkIconFilter : paintLightIconFilter); foregroundIcon.setColorFilter(nightMode ? paintDarkIconFilter : paintLightIconFilter);
foregroundIcon.draw(canvas); foregroundIcon.draw(canvas);
canvas.restore(); canvas.restore();
} }
} else { } else {
Bitmap b = stopBus; Bitmap b = stopBus;
float scaledWidth = b.getWidth() * textScale; canvas.drawBitmap(b, x - b.getWidth() / 2f, y - b.getHeight() / 2f, paintIcon);
float scaledHeight = b.getHeight() * textScale;
RectF rct = new RectF(0, 0, scaledWidth, scaledHeight);
rct.offset(x - scaledWidth / 2f, y - scaledHeight / 2f);
canvas.drawBitmap(b, null, rct, paintIcon);
} }
} }
} }