Merge pull request #9316 from osmandapp/Shape_OSM_Notes

Add offset to OSM notes shape
This commit is contained in:
vshcherb 2020-06-25 14:42:16 +02:00 committed by GitHub
commit 5ed7ba037f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 16 deletions

View file

@ -16,7 +16,7 @@ import androidx.core.content.ContextCompat;
import net.osmand.AndroidUtils; import net.osmand.AndroidUtils;
import net.osmand.PlatformUtil; import net.osmand.PlatformUtil;
import net.osmand.data.FavouritePoint; import net.osmand.data.FavouritePoint.BackgroundType;
import net.osmand.data.LatLon; import net.osmand.data.LatLon;
import net.osmand.data.PointDescription; import net.osmand.data.PointDescription;
import net.osmand.data.QuadRect; import net.osmand.data.QuadRect;
@ -157,8 +157,9 @@ public class OsmBugsLayer extends OsmandMapLayer implements IContextMenuProvider
} }
PointImageDrawable pointImageDrawable = PointImageDrawable.getOrCreate(activity, PointImageDrawable pointImageDrawable = PointImageDrawable.getOrCreate(activity,
ContextCompat.getColor(activity, backgroundColorRes), true, false, iconId, ContextCompat.getColor(activity, backgroundColorRes), true, false, iconId,
FavouritePoint.BackgroundType.COMMENT); BackgroundType.COMMENT);
pointImageDrawable.drawPoint(canvas, x, y, textScale, false); int offsetY = pointImageDrawable.getIntrinsicHeight() / 2;
pointImageDrawable.drawPoint(canvas, x, y - offsetY, textScale, false);
} }
this.fullObjectsLatLon = fullObjectsLatLon; this.fullObjectsLatLon = fullObjectsLatLon;
this.smallObjectsLatLon = smallObjectsLatLon; this.smallObjectsLatLon = smallObjectsLatLon;
@ -201,7 +202,7 @@ public class OsmBugsLayer extends OsmandMapLayer implements IContextMenuProvider
int ex = (int) point.x; int ex = (int) point.x;
int ey = (int) point.y; int ey = (int) point.y;
final int rad = getScaledTouchRadius(activity.getMyApplication(), getRadiusBug(tb)); final int rad = getScaledTouchRadius(activity.getMyApplication(), getRadiusBug(tb));
int radius = rad * 3 / 2; int radius = rad * 3;
int small = rad * 3 / 4; int small = rad * 3 / 4;
boolean showClosed = activity.getMyApplication().getSettings().SHOW_CLOSED_OSM_BUGS.get(); boolean showClosed = activity.getMyApplication().getSettings().SHOW_CLOSED_OSM_BUGS.get();
try { try {

View file

@ -42,10 +42,10 @@ import net.osmand.core.jni.ObfMapObject;
import net.osmand.core.jni.PointI; import net.osmand.core.jni.PointI;
import net.osmand.core.jni.QStringList; import net.osmand.core.jni.QStringList;
import net.osmand.core.jni.QStringStringHash; import net.osmand.core.jni.QStringStringHash;
import net.osmand.core.jni.ResourcesManager;
import net.osmand.core.jni.Utilities; import net.osmand.core.jni.Utilities;
import net.osmand.data.Amenity; import net.osmand.data.Amenity;
import net.osmand.data.FavouritePoint; import net.osmand.data.FavouritePoint;
import net.osmand.data.FavouritePoint.BackgroundType;
import net.osmand.data.LatLon; import net.osmand.data.LatLon;
import net.osmand.data.PointDescription; import net.osmand.data.PointDescription;
import net.osmand.data.RotatedTileBox; import net.osmand.data.RotatedTileBox;
@ -101,8 +101,8 @@ public class ContextMenuLayer extends OsmandMapLayer {
private ImageView contextMarker; private ImageView contextMarker;
private Paint paint; private Paint paint;
private Paint outlinePaint; private Paint outlinePaint;
private Map<LatLon, FavouritePoint.BackgroundType> pressedLatLonFull = new HashMap<>(); private Map<LatLon, BackgroundType> pressedLatLonFull = new HashMap<>();
private Map<LatLon, FavouritePoint.BackgroundType> pressedLatLonSmall = new HashMap<>(); private Map<LatLon, BackgroundType> pressedLatLonSmall = new HashMap<>();
private GestureDetector movementListener; private GestureDetector movementListener;
@ -233,14 +233,19 @@ public class ContextMenuLayer extends OsmandMapLayer {
int x = (int) box.getPixXFromLatLon(latLon.getLatitude(), latLon.getLongitude()); int x = (int) box.getPixXFromLatLon(latLon.getLatitude(), latLon.getLongitude());
int y = (int) box.getPixYFromLatLon(latLon.getLatitude(), latLon.getLongitude()); int y = (int) box.getPixYFromLatLon(latLon.getLatitude(), latLon.getLongitude());
Bitmap pressedBitmapSmall = getBackground(pressedLatLonSmall.get(latLon), true); Bitmap pressedBitmapSmall = getBackground(pressedLatLonSmall.get(latLon), true);
Rect destRect = getIconDestinationRect(x, y, pressedBitmapSmall.getWidth(), pressedBitmapSmall.getHeight(), scale); Rect destRect = getIconDestinationRect(
x, y, pressedBitmapSmall.getWidth(), pressedBitmapSmall.getHeight(), scale);
canvas.drawBitmap(pressedBitmapSmall, null, destRect, paint); canvas.drawBitmap(pressedBitmapSmall, null, destRect, paint);
} }
for (LatLon latLon : pressedLatLonFull.keySet()) { for (LatLon latLon : pressedLatLonFull.keySet()) {
int x = (int) box.getPixXFromLatLon(latLon.getLatitude(), latLon.getLongitude()); int x = (int) box.getPixXFromLatLon(latLon.getLatitude(), latLon.getLongitude());
int y = (int) box.getPixYFromLatLon(latLon.getLatitude(), latLon.getLongitude()); int y = (int) box.getPixYFromLatLon(latLon.getLatitude(), latLon.getLongitude());
Bitmap pressedBitmap = getBackground(pressedLatLonFull.get(latLon), false);
Rect destRect = getIconDestinationRect(x, y, pressedBitmap.getWidth(), pressedBitmap.getHeight(), scale); BackgroundType background = pressedLatLonFull.get(latLon);
Bitmap pressedBitmap = getBackground(background, false);
int offsetY = BackgroundType.COMMENT.equals(background) ? pressedBitmap.getHeight() / 2 : 0;
Rect destRect = getIconDestinationRect(
x, y - offsetY, pressedBitmap.getWidth(), pressedBitmap.getHeight(), scale);
canvas.drawBitmap(pressedBitmap, null, destRect, paint); canvas.drawBitmap(pressedBitmap, null, destRect, paint);
} }
@ -266,7 +271,7 @@ public class ContextMenuLayer extends OsmandMapLayer {
} }
} }
private Bitmap getBackground(FavouritePoint.BackgroundType backgroundType, boolean isSmall) { private Bitmap getBackground(BackgroundType backgroundType, boolean isSmall) {
Context ctx = view.getContext(); Context ctx = view.getContext();
Resources res = view.getResources(); Resources res = view.getResources();
String iconName = res.getResourceEntryName(backgroundType.getIconId()); String iconName = res.getResourceEntryName(backgroundType.getIconId());
@ -898,8 +903,8 @@ public class ContextMenuLayer extends OsmandMapLayer {
private Map<Object, IContextMenuProvider> selectObjectsForContextMenu(RotatedTileBox tileBox, private Map<Object, IContextMenuProvider> selectObjectsForContextMenu(RotatedTileBox tileBox,
PointF point, boolean acquireObjLatLon, PointF point, boolean acquireObjLatLon,
boolean unknownLocation) { boolean unknownLocation) {
Map<LatLon, FavouritePoint.BackgroundType> pressedLatLonFull = new HashMap<>(); Map<LatLon, BackgroundType> pressedLatLonFull = new HashMap<>();
Map<LatLon, FavouritePoint.BackgroundType> pressedLatLonSmall = new HashMap<>(); Map<LatLon, BackgroundType> pressedLatLonSmall = new HashMap<>();
Map<Object, IContextMenuProvider> selectedObjects = new HashMap<>(); Map<Object, IContextMenuProvider> selectedObjects = new HashMap<>();
List<Object> s = new ArrayList<>(); List<Object> s = new ArrayList<>();
for (OsmandMapLayer lt : view.getLayers()) { for (OsmandMapLayer lt : view.getLayers()) {
@ -911,15 +916,15 @@ public class ContextMenuLayer extends OsmandMapLayer {
selectedObjects.put(o, l); selectedObjects.put(o, l);
if (acquireObjLatLon && l.isObjectClickable(o)) { if (acquireObjLatLon && l.isObjectClickable(o)) {
LatLon latLon = l.getObjectLocation(o); LatLon latLon = l.getObjectLocation(o);
FavouritePoint.BackgroundType backgroundType = DEFAULT_BACKGROUND_TYPE; BackgroundType backgroundType = DEFAULT_BACKGROUND_TYPE;
if (o instanceof OsmBugsLayer.OpenStreetNote) { if (o instanceof OsmBugsLayer.OpenStreetNote) {
backgroundType = FavouritePoint.BackgroundType.COMMENT; backgroundType = BackgroundType.COMMENT;
} }
if (o instanceof FavouritePoint) { if (o instanceof FavouritePoint) {
backgroundType = ((FavouritePoint) o).getBackgroundType(); backgroundType = ((FavouritePoint) o).getBackgroundType();
} }
if (o instanceof GPXUtilities.WptPt) { if (o instanceof GPXUtilities.WptPt) {
backgroundType = FavouritePoint.BackgroundType.getByTypeName( backgroundType = BackgroundType.getByTypeName(
((GPXUtilities.WptPt) o).getBackgroundType(), DEFAULT_BACKGROUND_TYPE); ((GPXUtilities.WptPt) o).getBackgroundType(), DEFAULT_BACKGROUND_TYPE);
} }
if (lt.isPresentInFullObjects(latLon) && !pressedLatLonFull.keySet().contains(latLon)) { if (lt.isPresentInFullObjects(latLon) && !pressedLatLonFull.keySet().contains(latLon)) {