Merge branch 'r3.7'

This commit is contained in:
Victor Shcherb 2020-05-20 18:13:32 +02:00
commit e8a168f210
7 changed files with 73 additions and 49 deletions

View file

@ -7,6 +7,7 @@ import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Paint.Style;
import android.graphics.PointF;
import android.graphics.Rect;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
@ -89,14 +90,16 @@ public class AudioNotesLayer extends OsmandMapLayer implements
if (contextMenuLayer.getMoveableObject() instanceof Recording) {
Recording objectInMotion = (Recording) contextMenuLayer.getMoveableObject();
PointF pf = contextMenuLayer.getMovableCenterPoint(tileBox);
drawRecording(canvas, objectInMotion, pf.x, pf.y);
float textScale = activity.getMyApplication().getSettings().TEXT_SCALE.get();
drawRecording(canvas, objectInMotion, pf.x, pf.y, textScale);
}
}
@Override
public void onPrepareBufferImage(Canvas canvas, RotatedTileBox tileBox, DrawSettings settings) {
if (tileBox.getZoom() >= startZoom) {
float iconSize = audio.getWidth() * 3 / 2.5f;
float textScale = activity.getMyApplication().getSettings().TEXT_SCALE.get();
float iconSize = audio.getWidth() * 3 / 2.5f * textScale;
QuadTree<QuadRect> boundIntersections = initBoundIntersections(tileBox);
DataTileManager<Recording> recs = plugin.getRecordings();
@ -111,7 +114,8 @@ public class AudioNotesLayer extends OsmandMapLayer implements
float y = tileBox.getPixYFromLatLon(o.getLatitude(), o.getLongitude());
if (intersects(boundIntersections, x, y, iconSize, iconSize)) {
canvas.drawBitmap(pointSmall, x - pointSmall.getWidth() / 2, y - pointSmall.getHeight() / 2, paintIcon);
Rect destRect = getIconDestinationRect(x, y, pointSmall.getWidth(), pointSmall.getHeight(), textScale);
canvas.drawBitmap(pointSmall, null, destRect, paintIcon);
smallObjectsLatLon.add(new LatLon(o.getLatitude(), o.getLongitude()));
} else {
fullObjects.add(o);
@ -122,14 +126,14 @@ public class AudioNotesLayer extends OsmandMapLayer implements
for (Recording o : fullObjects) {
float x = tileBox.getPixXFromLatLon(o.getLatitude(), o.getLongitude());
float y = tileBox.getPixYFromLatLon(o.getLatitude(), o.getLongitude());
drawRecording(canvas, o, x, y);
drawRecording(canvas, o, x, y, textScale);
}
this.fullObjectsLatLon = fullObjectsLatLon;
this.smallObjectsLatLon = smallObjectsLatLon;
}
}
private void drawRecording(Canvas canvas, Recording o, float x, float y) {
private void drawRecording(Canvas canvas, Recording o, float x, float y, float textScale) {
Bitmap b;
if (o.isPhoto()) {
b = photo;
@ -138,7 +142,8 @@ public class AudioNotesLayer extends OsmandMapLayer implements
} else {
b = video;
}
canvas.drawBitmap(b, x - b.getWidth() / 2, y - b.getHeight() / 2, paintIcon);
Rect destRect = getIconDestinationRect(x, y, b.getWidth(), b.getHeight(), textScale);
canvas.drawBitmap(b, null, destRect, paintIcon);
}
@Override

View file

@ -104,9 +104,6 @@ public class FavoriteImageDrawable extends Drawable {
int offsetY = bounds.centerY() - uiListIcon.getIntrinsicHeight() / 2;
uiListIcon.setBounds(offsetX, offsetY, uiListIcon.getIntrinsicWidth() + offsetX,
uiListIcon.getIntrinsicHeight() + offsetY);
} else if (withShadow) {
bs.inset(bs.width() / 3, bs.height() / 3);
favIcon.setBounds(bs);
}
}
@ -151,17 +148,16 @@ public class FavoriteImageDrawable extends Drawable {
}
public void drawBitmap(@NonNull Canvas canvas, Rect bs, Bitmap bitmap, Paint paintBackground) {
canvas.drawBitmap(bitmap, bs.exactCenterX() - bitmap.getWidth() / 2f,
bs.exactCenterY() - bitmap.getHeight() / 2f, paintBackground);
canvas.drawBitmap(bitmap, null, bs, paintBackground);
}
public void drawBitmapInCenter(Canvas canvas, float x, float y, boolean history) {
public void drawBitmapInCenter(Canvas canvas, Rect destRect, boolean history) {
this.history = history;
float dx = x - getIntrinsicWidth() / 2f;
float dy = y - getIntrinsicHeight() / 2f;
canvas.translate(dx, dy);
setBounds(destRect);
Rect bounds = new Rect(destRect);
bounds.inset(bounds.width() / 3, bounds.height() / 3);
favIcon.setBounds(bounds);
draw(canvas);
canvas.translate(-dx, -dy);
}
@Override

View file

@ -7,6 +7,7 @@ import android.graphics.Paint;
import android.graphics.PointF;
import android.graphics.PorterDuff;
import android.graphics.PorterDuffColorFilter;
import android.graphics.Rect;
import android.util.Pair;
import androidx.annotation.ColorInt;
@ -104,7 +105,8 @@ public class FavouritesLayer extends OsmandMapLayer implements ContextMenuLayer.
FavouritePoint objectInMotion = (FavouritePoint) contextMenuLayer.getMoveableObject();
PointF pf = contextMenuLayer.getMovableCenterPoint(tileBox);
MapMarker mapMarker = mapMarkersHelper.getMapMarker(objectInMotion);
drawBigPoint(canvas, objectInMotion, pf.x, pf.y, mapMarker);
float textScale = this.settings.TEXT_SCALE.get();
drawBigPoint(canvas, objectInMotion, pf.x, pf.y, mapMarker, textScale);
}
}
@ -113,8 +115,9 @@ public class FavouritesLayer extends OsmandMapLayer implements ContextMenuLayer.
cache.clear();
if (this.settings.SHOW_FAVORITES.get() && favorites.isFavoritesLoaded()) {
if (tileBox.getZoom() >= startZoom) {
float textScale = this.settings.TEXT_SCALE.get();
float iconSize = FavoriteImageDrawable.getOrCreate(view.getContext(), 0,
true, (FavouritePoint) null).getIntrinsicWidth() * 3 / 2.5f;
true, (FavouritePoint) null).getIntrinsicWidth() * 3 / 2.5f * textScale;
QuadTree<QuadRect> boundIntersections = initBoundIntersections(tileBox);
// request to load
@ -147,17 +150,15 @@ public class FavouritesLayer extends OsmandMapLayer implements ContextMenuLayer.
color = grayColor;
} else {
color = favorites.getColorWithCategory(o,defaultColor);
// color = o.getColor() == 0 ? defaultColor : o.getColor();
}
paintIcon.setColorFilter(new PorterDuffColorFilter(color, PorterDuff.Mode.SRC_IN));
Bitmap pointSmallTop = getBitmap(o, "top");
Bitmap pointSmallCenter = getBitmap(o, "center");
Bitmap pointSmallBottom = getBitmap(o, "bottom");
float left = x - pointSmallTop.getWidth() / 2f;
float top = y - pointSmallTop.getHeight() / 2f;
canvas.drawBitmap(pointSmallBottom, left, top, null);
canvas.drawBitmap(pointSmallCenter, left, top, paintIcon);
canvas.drawBitmap(pointSmallTop, left, top, null);
Rect destRect = getIconDestinationRect(x, y, pointSmallTop.getWidth(), pointSmallTop.getHeight(), textScale);
canvas.drawBitmap(pointSmallBottom, null, destRect, null);
canvas.drawBitmap(pointSmallCenter, null, destRect, paintIcon);
canvas.drawBitmap(pointSmallTop, null, destRect, null);
smallObjectsLatLon.add(new LatLon(lat, lon));
} else {
fullObjects.add(new Pair<>(o, marker));
@ -169,7 +170,7 @@ public class FavouritesLayer extends OsmandMapLayer implements ContextMenuLayer.
FavouritePoint o = pair.first;
float x = tileBox.getPixXFromLatLon(o.getLatitude(), o.getLongitude());
float y = tileBox.getPixYFromLatLon(o.getLatitude(), o.getLongitude());
drawBigPoint(canvas, o, x, y, pair.second);
drawBigPoint(canvas, o, x, y, pair.second, textScale);
}
}
this.fullObjectsLatLon = fullObjectsLatLon;
@ -190,7 +191,7 @@ public class FavouritesLayer extends OsmandMapLayer implements ContextMenuLayer.
return pointSmall;
}
private void drawBigPoint(Canvas canvas, FavouritePoint o, float x, float y, @Nullable MapMarker marker) {
private void drawBigPoint(Canvas canvas, FavouritePoint o, float x, float y, @Nullable MapMarker marker, float textScale) {
FavoriteImageDrawable fid;
boolean history = false;
if (marker != null) {
@ -199,7 +200,8 @@ public class FavouritesLayer extends OsmandMapLayer implements ContextMenuLayer.
} else {
fid = FavoriteImageDrawable.getOrCreate(view.getContext(), favorites.getColorWithCategory(o,defaultColor), true, o);
}
fid.drawBitmapInCenter(canvas, x, y, history);
Rect destRest = getIconDestinationRect(x, y, fid.getIntrinsicWidth(), fid.getIntrinsicHeight(), textScale);
fid.drawBitmapInCenter(canvas, destRest, history);
}
private int getSmallIconId(String layer, int iconId) {

View file

@ -196,7 +196,8 @@ public class GPXLayer extends OsmandMapLayer implements ContextMenuLayer.IContex
if (gpxFile != null) {
PointF pf = contextMenuLayer.getMovableCenterPoint(tileBox);
MapMarker mapMarker = mapMarkersHelper.getMapMarker(objectInMotion);
drawBigPoint(canvas, objectInMotion, getFileColor(gpxFile), pf.x, pf.y, mapMarker);
float textScale = view.getSettings().TEXT_SCALE.get();
drawBigPoint(canvas, objectInMotion, getFileColor(gpxFile), pf.x, pf.y, mapMarker, textScale);
}
}
}
@ -371,8 +372,9 @@ public class GPXLayer extends OsmandMapLayer implements ContextMenuLayer.IContex
private void drawSelectedFilesPoints(Canvas canvas, RotatedTileBox tileBox, List<SelectedGpxFile> selectedGPXFiles) {
if (tileBox.getZoom() >= startZoom) {
float textScale = view.getSettings().TEXT_SCALE.get();
float iconSize = FavoriteImageDrawable.getOrCreate(view.getContext(), 0,
true, (WptPt) null).getIntrinsicWidth() * 3 / 2.5f;
true, (WptPt) null).getIntrinsicWidth() * 3 / 2.5f * textScale;
QuadTree<QuadRect> boundIntersections = initBoundIntersections(tileBox);
List<LatLon> fullObjectsLatLon = new ArrayList<>();
@ -408,7 +410,8 @@ public class GPXLayer extends OsmandMapLayer implements ContextMenuLayer.IContex
color = getPointColor(o, fileColor);
}
paintIcon.setColorFilter(new PorterDuffColorFilter(color | 0xff000000, PorterDuff.Mode.MULTIPLY));
canvas.drawBitmap(pointSmall, x - pointSmall.getWidth() / 2, y - pointSmall.getHeight() / 2, paintIcon);
Rect destRect = getIconDestinationRect(x, y, pointSmall.getWidth(), pointSmall.getHeight(), textScale);
canvas.drawBitmap(pointSmall, null, destRect, paintIcon);
smallObjectsLatLon.add(new LatLon(o.lat, o.lon));
} else {
fullObjects.add(new Pair<>(o, marker));
@ -423,7 +426,7 @@ public class GPXLayer extends OsmandMapLayer implements ContextMenuLayer.IContex
WptPt o = pair.first;
float x = tileBox.getPixXFromLatLon(o.lat, o.lon);
float y = tileBox.getPixYFromLatLon(o.lat, o.lon);
drawBigPoint(canvas, o, fileColor, x, y, pair.second);
drawBigPoint(canvas, o, fileColor, x, y, pair.second, textScale);
}
}
if (trackChartPoints != null) {
@ -497,7 +500,7 @@ public class GPXLayer extends OsmandMapLayer implements ContextMenuLayer.IContex
return g.getColor() == 0 ? defPointColor : g.getColor();
}
private void drawBigPoint(Canvas canvas, WptPt o, int fileColor, float x, float y, @Nullable MapMarker marker) {
private void drawBigPoint(Canvas canvas, WptPt o, int fileColor, float x, float y, @Nullable MapMarker marker, float textScale) {
int pointColor = getPointColor(o, fileColor);
FavoriteImageDrawable fid;
boolean history = false;
@ -507,7 +510,8 @@ public class GPXLayer extends OsmandMapLayer implements ContextMenuLayer.IContex
} else {
fid = FavoriteImageDrawable.getOrCreate(view.getContext(), pointColor, true, o);
}
fid.drawBitmapInCenter(canvas, x, y, history);
Rect destRest = getIconDestinationRect(x, y, fid.getIntrinsicWidth(), fid.getIntrinsicHeight(), textScale);
fid.drawBitmapInCenter(canvas, destRest, history);
}
@ColorInt

View file

@ -14,6 +14,7 @@ import android.graphics.Path;
import android.graphics.PointF;
import android.graphics.PorterDuff.Mode;
import android.graphics.PorterDuffColorFilter;
import android.graphics.Rect;
import android.graphics.RectF;
import android.graphics.drawable.Drawable;
import android.os.AsyncTask;
@ -624,6 +625,18 @@ public abstract class OsmandMapLayer {
return (int) (r * tb.getDensity());
}
public Rect getIconDestinationRect(float x, float y, int width, int height, float scale) {
int scaledWidth = width;
int scaledHeight = height;
if (scale != 1.0f) {
scaledWidth = (int) (width * scale);
scaledHeight = (int) (height * scale);
}
Rect rect = new Rect(0, 0, scaledWidth, scaledHeight);
rect.offset((int) x - scaledWidth / 2, (int) y - scaledHeight / 2);
return rect;
}
public abstract class MapLayerData<T> {
public int ZOOM_THRESHOLD = 1;
public RotatedTileBox queriedBox;

View file

@ -10,6 +10,7 @@ import android.graphics.Paint;
import android.graphics.PointF;
import android.graphics.PorterDuff;
import android.graphics.PorterDuffColorFilter;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.text.util.Linkify;
import android.util.TypedValue;
@ -220,7 +221,8 @@ public class POIMapLayer extends OsmandMapLayer implements ContextMenuLayer.ICon
data.queryNewData(tileBox);
objects = data.getResults();
if (objects != null) {
float iconSize = poiBackground.getWidth() * 3 / 2;
float textScale = app.getSettings().TEXT_SCALE.get();
float iconSize = poiBackground.getWidth() * 3 / 2 * textScale;
QuadTree<QuadRect> boundIntersections = initBoundIntersections(tileBox);
WaypointHelper wph = app.getWaypointHelper();
@ -233,7 +235,8 @@ public class POIMapLayer extends OsmandMapLayer implements ContextMenuLayer.ICon
if (tileBox.containsPoint(x, y, iconSize)) {
if (intersects(boundIntersections, x, y, iconSize, iconSize) ||
(app.getSettings().SHOW_NEARBY_POI.get() && wph.isRouteCalculated() && !wph.isAmenityNoPassed(o))) {
canvas.drawBitmap(poiBackgroundSmall, x - poiBackgroundSmall.getWidth() / 2, y - poiBackgroundSmall.getHeight() / 2, paintIconBackground);
Rect destRect = getIconDestinationRect(x, y, poiBackgroundSmall.getWidth(), poiBackgroundSmall.getHeight(), textScale);
canvas.drawBitmap(poiBackgroundSmall, null, destRect, paintIconBackground);
smallObjectsLatLon.add(new LatLon(o.getLocation().getLatitude(),
o.getLocation().getLongitude()));
} else {
@ -249,7 +252,8 @@ public class POIMapLayer extends OsmandMapLayer implements ContextMenuLayer.ICon
int y = (int) tileBox.getPixYFromLatLon(o.getLocation().getLatitude(), o.getLocation()
.getLongitude());
if (tileBox.containsPoint(x, y, iconSize)) {
canvas.drawBitmap(poiBackground, x - poiBackground.getWidth() / 2, y - poiBackground.getHeight() / 2, paintIconBackground);
Rect destRect = getIconDestinationRect(x, y, poiBackground.getWidth(), poiBackground.getHeight(), textScale);
canvas.drawBitmap(poiBackground, null, destRect, paintIconBackground);
String id = null;
PoiType st = o.getType().getPoiTypeByKeyName(o.getSubType());
if (st != null) {
@ -262,12 +266,10 @@ public class POIMapLayer extends OsmandMapLayer implements ContextMenuLayer.ICon
if (id != null) {
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);
destRect = getIconDestinationRect(x, y, poiSize, poiSize, textScale);
img.setBounds(destRect);
img.setColorFilter(poiColorFilter);
img.draw(canvas);
canvas.restore();
}
}
}

View file

@ -10,6 +10,7 @@ import android.graphics.Path;
import android.graphics.PointF;
import android.graphics.PorterDuff;
import android.graphics.PorterDuffColorFilter;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.util.DisplayMetrics;
import android.view.WindowManager;
@ -233,7 +234,8 @@ public class TransportStopsLayer extends OsmandMapLayer implements ContextMenuLa
}
if (objects != null) {
float iconSize = stopBus.getWidth() * 3 / 2.5f;
float textScale = mapActivity.getMyApplication().getSettings().TEXT_SCALE.get();
float iconSize = stopBus.getWidth() * 3 / 2.5f * textScale;
QuadTree<QuadRect> boundIntersections = initBoundIntersections(tb);
List<TransportStop> fullObjects = new ArrayList<>();
for (TransportStop o : objects) {
@ -241,7 +243,8 @@ public class TransportStopsLayer extends OsmandMapLayer implements ContextMenuLa
float y = tb.getPixYFromLatLon(o.getLocation().getLatitude(), o.getLocation().getLongitude());
if (intersects(boundIntersections, x, y, iconSize, iconSize)) {
canvas.drawBitmap(stopSmall, x - stopSmall.getWidth() / 2f, y - stopSmall.getHeight() / 2f, paintIcon);
Rect destRect = getIconDestinationRect(x, y, stopSmall.getWidth(), stopSmall.getHeight(), textScale);
canvas.drawBitmap(stopSmall, null, destRect, paintIcon);
} else {
fullObjects.add(o);
}
@ -254,17 +257,16 @@ public class TransportStopsLayer extends OsmandMapLayer implements ContextMenuLa
TransportStopType type = TransportStopType.findType(stopRoute.route.getType());
if (type != null) {
Drawable foregroundIcon = RenderingIcons.getDrawableIcon(mapActivity, type.getResName(), false);
canvas.drawBitmap(backgroundIcon, x - backgroundIconHalfWidth, y - backgroundIconHalfHeight, paintIcon);
canvas.save();
canvas.translate(x - foregroundIcon.getIntrinsicWidth() / 2f, y - foregroundIcon.getIntrinsicHeight() / 2f);
foregroundIcon.setBounds(0, 0, foregroundIcon.getIntrinsicWidth(), foregroundIcon.getIntrinsicHeight());
Rect destRect = getIconDestinationRect(x, y, backgroundIcon.getWidth(), backgroundIcon.getHeight(), textScale);
canvas.drawBitmap(backgroundIcon, null, destRect, paintIcon);
destRect = getIconDestinationRect(x, y, foregroundIcon.getIntrinsicWidth(), foregroundIcon.getIntrinsicHeight(), textScale);
foregroundIcon.setBounds(destRect);
foregroundIcon.setColorFilter(nightMode ? paintDarkIconFilter : paintLightIconFilter);
foregroundIcon.draw(canvas);
canvas.restore();
}
} else {
Bitmap b = stopBus;
canvas.drawBitmap(b, x - b.getWidth() / 2f, y - b.getHeight() / 2f, paintIcon);
Rect destRect = getIconDestinationRect(x, y, stopBus.getWidth(), stopBus.getHeight(), textScale);
canvas.drawBitmap(stopBus, null, destRect, paintIcon);
}
}
}