From ec9f46f23379b85bba8eb766ebc6d23c8b8ec222 Mon Sep 17 00:00:00 2001 From: Dima-1 Date: Thu, 25 Jun 2020 14:16:39 +0300 Subject: [PATCH] Add offset to shape --- .../net/osmand/plus/osmedit/OsmBugsLayer.java | 9 +++--- .../osmand/plus/views/ContextMenuLayer.java | 29 +++++++++++-------- 2 files changed, 22 insertions(+), 16 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/osmedit/OsmBugsLayer.java b/OsmAnd/src/net/osmand/plus/osmedit/OsmBugsLayer.java index ff288cba84..9421acb84d 100644 --- a/OsmAnd/src/net/osmand/plus/osmedit/OsmBugsLayer.java +++ b/OsmAnd/src/net/osmand/plus/osmedit/OsmBugsLayer.java @@ -16,7 +16,7 @@ import androidx.core.content.ContextCompat; import net.osmand.AndroidUtils; import net.osmand.PlatformUtil; -import net.osmand.data.FavouritePoint; +import net.osmand.data.FavouritePoint.BackgroundType; import net.osmand.data.LatLon; import net.osmand.data.PointDescription; import net.osmand.data.QuadRect; @@ -157,8 +157,9 @@ public class OsmBugsLayer extends OsmandMapLayer implements IContextMenuProvider } PointImageDrawable pointImageDrawable = PointImageDrawable.getOrCreate(activity, ContextCompat.getColor(activity, backgroundColorRes), true, false, iconId, - FavouritePoint.BackgroundType.COMMENT); - pointImageDrawable.drawPoint(canvas, x, y, textScale, false); + BackgroundType.COMMENT); + int offsetY = pointImageDrawable.getIntrinsicHeight() / 2; + pointImageDrawable.drawPoint(canvas, x, y - offsetY, textScale, false); } this.fullObjectsLatLon = fullObjectsLatLon; this.smallObjectsLatLon = smallObjectsLatLon; @@ -201,7 +202,7 @@ public class OsmBugsLayer extends OsmandMapLayer implements IContextMenuProvider int ex = (int) point.x; int ey = (int) point.y; final int rad = getScaledTouchRadius(activity.getMyApplication(), getRadiusBug(tb)); - int radius = rad * 3 / 2; + int radius = rad * 3; int small = rad * 3 / 4; boolean showClosed = activity.getMyApplication().getSettings().SHOW_CLOSED_OSM_BUGS.get(); try { diff --git a/OsmAnd/src/net/osmand/plus/views/ContextMenuLayer.java b/OsmAnd/src/net/osmand/plus/views/ContextMenuLayer.java index e7e1338362..64e6073dc3 100644 --- a/OsmAnd/src/net/osmand/plus/views/ContextMenuLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/ContextMenuLayer.java @@ -42,10 +42,10 @@ import net.osmand.core.jni.ObfMapObject; import net.osmand.core.jni.PointI; import net.osmand.core.jni.QStringList; import net.osmand.core.jni.QStringStringHash; -import net.osmand.core.jni.ResourcesManager; import net.osmand.core.jni.Utilities; import net.osmand.data.Amenity; import net.osmand.data.FavouritePoint; +import net.osmand.data.FavouritePoint.BackgroundType; import net.osmand.data.LatLon; import net.osmand.data.PointDescription; import net.osmand.data.RotatedTileBox; @@ -101,8 +101,8 @@ public class ContextMenuLayer extends OsmandMapLayer { private ImageView contextMarker; private Paint paint; private Paint outlinePaint; - private Map pressedLatLonFull = new HashMap<>(); - private Map pressedLatLonSmall = new HashMap<>(); + private Map pressedLatLonFull = new HashMap<>(); + private Map pressedLatLonSmall = new HashMap<>(); private GestureDetector movementListener; @@ -233,14 +233,19 @@ public class ContextMenuLayer extends OsmandMapLayer { int x = (int) box.getPixXFromLatLon(latLon.getLatitude(), latLon.getLongitude()); int y = (int) box.getPixYFromLatLon(latLon.getLatitude(), latLon.getLongitude()); 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); } for (LatLon latLon : pressedLatLonFull.keySet()) { int x = (int) box.getPixXFromLatLon(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); } @@ -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(); Resources res = view.getResources(); String iconName = res.getResourceEntryName(backgroundType.getIconId()); @@ -898,8 +903,8 @@ public class ContextMenuLayer extends OsmandMapLayer { private Map selectObjectsForContextMenu(RotatedTileBox tileBox, PointF point, boolean acquireObjLatLon, boolean unknownLocation) { - Map pressedLatLonFull = new HashMap<>(); - Map pressedLatLonSmall = new HashMap<>(); + Map pressedLatLonFull = new HashMap<>(); + Map pressedLatLonSmall = new HashMap<>(); Map selectedObjects = new HashMap<>(); List s = new ArrayList<>(); for (OsmandMapLayer lt : view.getLayers()) { @@ -911,15 +916,15 @@ public class ContextMenuLayer extends OsmandMapLayer { selectedObjects.put(o, l); if (acquireObjLatLon && l.isObjectClickable(o)) { LatLon latLon = l.getObjectLocation(o); - FavouritePoint.BackgroundType backgroundType = DEFAULT_BACKGROUND_TYPE; + BackgroundType backgroundType = DEFAULT_BACKGROUND_TYPE; if (o instanceof OsmBugsLayer.OpenStreetNote) { - backgroundType = FavouritePoint.BackgroundType.COMMENT; + backgroundType = BackgroundType.COMMENT; } if (o instanceof FavouritePoint) { backgroundType = ((FavouritePoint) o).getBackgroundType(); } if (o instanceof GPXUtilities.WptPt) { - backgroundType = FavouritePoint.BackgroundType.getByTypeName( + backgroundType = BackgroundType.getByTypeName( ((GPXUtilities.WptPt) o).getBackgroundType(), DEFAULT_BACKGROUND_TYPE); } if (lt.isPresentInFullObjects(latLon) && !pressedLatLonFull.keySet().contains(latLon)) {