diff --git a/OsmAnd/src/net/osmand/data/PointDescription.java b/OsmAnd/src/net/osmand/data/PointDescription.java index ff8459ee7a..0b1eaca61b 100644 --- a/OsmAnd/src/net/osmand/data/PointDescription.java +++ b/OsmAnd/src/net/osmand/data/PointDescription.java @@ -37,6 +37,7 @@ public class PointDescription implements Serializable { public static final String POINT_TYPE_VIDEO_NOTE = "videonote"; public static final String POINT_TYPE_PHOTO_NOTE = "photonote"; public static final String POINT_TYPE_LOCATION = "location"; + public static final String POINT_TYPE_MY_LOCATION = "my_location"; public static final String POINT_TYPE_ALARM = "alarm"; public static final String POINT_TYPE_TARGET = "destination"; public static final String POINT_TYPE_OSM_BUG = "bug"; @@ -188,6 +189,10 @@ public class PointDescription implements Serializable { return POINT_TYPE_PARKING_MARKER.equals(type); } + public boolean isMyLocation() { + return POINT_TYPE_MY_LOCATION.equals(type); + } + @Override public int hashCode() { final int prime = 31; diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuController.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuController.java index c8de77e6c7..1fda77762f 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuController.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuController.java @@ -15,6 +15,7 @@ import net.osmand.plus.helpers.SearchHistoryHelper; import net.osmand.plus.mapcontextmenu.details.AmenityMenuController; import net.osmand.plus.mapcontextmenu.details.FavouritePointMenuController; import net.osmand.plus.mapcontextmenu.details.HistoryMenuController; +import net.osmand.plus.mapcontextmenu.details.MyLocationMenuController; import net.osmand.plus.mapcontextmenu.details.ParkingPositionController; import net.osmand.plus.mapcontextmenu.details.PointDescriptionMenuController; @@ -53,6 +54,8 @@ public abstract class MenuController extends BaseMenuController { } else if (object instanceof LatLon) { if (pointDescription.isParking()) { menuController = new ParkingPositionController(app, mapActivity, pointDescription, (LatLon) object); + } else if (pointDescription.isMyLocation()) { + menuController = new MyLocationMenuController(app, mapActivity, pointDescription, (LatLon) object); } } } else { diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/details/MyLocationMenuController.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/details/MyLocationMenuController.java index 89cab3ae0a..75b86b388b 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/details/MyLocationMenuController.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/details/MyLocationMenuController.java @@ -7,17 +7,19 @@ import net.osmand.data.LatLon; import net.osmand.data.PointDescription; import net.osmand.plus.ApplicationMode; import net.osmand.plus.OsmandApplication; -import net.osmand.plus.OsmandSettings; -import net.osmand.plus.R; import net.osmand.plus.activities.MapActivity; -import net.osmand.plus.activities.search.SearchHistoryFragment; import net.osmand.plus.mapcontextmenu.MenuBuilder; import net.osmand.plus.mapcontextmenu.MenuController; public class MyLocationMenuController extends MenuController { - public MyLocationMenuController(OsmandApplication app, MapActivity mapActivity) { + private LatLon latLon; + private PointDescription pointDescription; + + public MyLocationMenuController(OsmandApplication app, MapActivity mapActivity, final PointDescription pointDescription, LatLon latLon) { super(new MenuBuilder(app), mapActivity); + this.pointDescription = pointDescription; + this.latLon = latLon; } @Override @@ -38,10 +40,11 @@ public class MyLocationMenuController extends MenuController { @Override public String getNameStr() { - return getMapActivity().getString(R.string.shared_string_my_location); + return pointDescription.getTypeName(); } @Override public void saveEntityState(Bundle bundle, String key) { + bundle.putSerializable(key, latLon); } } diff --git a/OsmAnd/src/net/osmand/plus/views/PointLocationLayer.java b/OsmAnd/src/net/osmand/plus/views/PointLocationLayer.java index eb0786a0ee..8cd21bd5a4 100644 --- a/OsmAnd/src/net/osmand/plus/views/PointLocationLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/PointLocationLayer.java @@ -2,6 +2,8 @@ package net.osmand.plus.views; import net.osmand.Location; +import net.osmand.data.LatLon; +import net.osmand.data.PointDescription; import net.osmand.data.RotatedTileBox; import net.osmand.plus.ApplicationMode; import net.osmand.plus.OsmAndLocationProvider; @@ -12,9 +14,12 @@ import android.graphics.BitmapFactory; import android.graphics.Canvas; import android.graphics.Paint; import android.graphics.Paint.Style; +import android.graphics.PointF; import android.graphics.RectF; -public class PointLocationLayer extends OsmandMapLayer { +import java.util.List; + +public class PointLocationLayer extends OsmandMapLayer implements ContextMenuLayer.IContextMenuProvider { protected final static int RADIUS = 7; protected final static float HEADING_ANGLE = 60; @@ -124,11 +129,8 @@ public class PointLocationLayer extends OsmandMapLayer { } } - public boolean isLocationVisible(RotatedTileBox tb, Location l){ - if(l == null ){ - return false; - } - return tb.containsLatLon(l.getLatitude(), l.getLongitude()); + public boolean isLocationVisible(RotatedTileBox tb, Location l) { + return l != null && tb.containsLatLon(l.getLatitude(), l.getLongitude()); } @@ -150,4 +152,57 @@ public class PointLocationLayer extends OsmandMapLayer { } + @Override + public void collectObjectsFromPoint(PointF point, RotatedTileBox tileBox, List o) { + getMyLocationFromPoint(tileBox, point, o); + } + + @Override + public LatLon getObjectLocation(Object o) { + return getMyLocation(); + } + + @Override + public String getObjectDescription(Object o) { + return view.getResources().getString(R.string.shared_string_my_location); + } + + @Override + public PointDescription getObjectName(Object o) { + return new PointDescription(PointDescription.POINT_TYPE_MY_LOCATION, + view.getContext().getString(R.string.shared_string_my_location), ""); + } + + @Override + public boolean disableSingleTap() { + return false; + } + + @Override + public boolean disableLongPressOnMap() { + return false; + } + + private LatLon getMyLocation() { + Location location = locationProvider.getLastKnownLocation(); + if (location != null) { + return new LatLon(location.getLatitude(), location.getLongitude()); + } else { + return null; + } + } + + private void getMyLocationFromPoint(RotatedTileBox tb, PointF point, List myLocation) { + LatLon location = getMyLocation(); + if (location != null && view != null) { + int ex = (int) point.x; + int ey = (int) point.y; + int x = (int) tb.getPixXFromLatLon(location.getLatitude(), location.getLongitude()); + int y = (int) tb.getPixYFromLatLon(location.getLatitude(), location.getLongitude()); + int rad = (int) (18 * tb.getDensity()); + if (Math.abs(x - ex) <= rad && (ey - y) <= rad && (y - ey) <= 2.5 * rad) { + myLocation.add(location); + } + } + } }