Added my location to context menu
This commit is contained in:
parent
8c5bf3b01e
commit
f9d6b4de57
4 changed files with 77 additions and 11 deletions
|
@ -37,6 +37,7 @@ public class PointDescription implements Serializable {
|
||||||
public static final String POINT_TYPE_VIDEO_NOTE = "videonote";
|
public static final String POINT_TYPE_VIDEO_NOTE = "videonote";
|
||||||
public static final String POINT_TYPE_PHOTO_NOTE = "photonote";
|
public static final String POINT_TYPE_PHOTO_NOTE = "photonote";
|
||||||
public static final String POINT_TYPE_LOCATION = "location";
|
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_ALARM = "alarm";
|
||||||
public static final String POINT_TYPE_TARGET = "destination";
|
public static final String POINT_TYPE_TARGET = "destination";
|
||||||
public static final String POINT_TYPE_OSM_BUG = "bug";
|
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);
|
return POINT_TYPE_PARKING_MARKER.equals(type);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isMyLocation() {
|
||||||
|
return POINT_TYPE_MY_LOCATION.equals(type);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
final int prime = 31;
|
final int prime = 31;
|
||||||
|
|
|
@ -15,6 +15,7 @@ import net.osmand.plus.helpers.SearchHistoryHelper;
|
||||||
import net.osmand.plus.mapcontextmenu.details.AmenityMenuController;
|
import net.osmand.plus.mapcontextmenu.details.AmenityMenuController;
|
||||||
import net.osmand.plus.mapcontextmenu.details.FavouritePointMenuController;
|
import net.osmand.plus.mapcontextmenu.details.FavouritePointMenuController;
|
||||||
import net.osmand.plus.mapcontextmenu.details.HistoryMenuController;
|
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.ParkingPositionController;
|
||||||
import net.osmand.plus.mapcontextmenu.details.PointDescriptionMenuController;
|
import net.osmand.plus.mapcontextmenu.details.PointDescriptionMenuController;
|
||||||
|
|
||||||
|
@ -53,6 +54,8 @@ public abstract class MenuController extends BaseMenuController {
|
||||||
} else if (object instanceof LatLon) {
|
} else if (object instanceof LatLon) {
|
||||||
if (pointDescription.isParking()) {
|
if (pointDescription.isParking()) {
|
||||||
menuController = new ParkingPositionController(app, mapActivity, pointDescription, (LatLon) object);
|
menuController = new ParkingPositionController(app, mapActivity, pointDescription, (LatLon) object);
|
||||||
|
} else if (pointDescription.isMyLocation()) {
|
||||||
|
menuController = new MyLocationMenuController(app, mapActivity, pointDescription, (LatLon) object);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -7,17 +7,19 @@ import net.osmand.data.LatLon;
|
||||||
import net.osmand.data.PointDescription;
|
import net.osmand.data.PointDescription;
|
||||||
import net.osmand.plus.ApplicationMode;
|
import net.osmand.plus.ApplicationMode;
|
||||||
import net.osmand.plus.OsmandApplication;
|
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.MapActivity;
|
||||||
import net.osmand.plus.activities.search.SearchHistoryFragment;
|
|
||||||
import net.osmand.plus.mapcontextmenu.MenuBuilder;
|
import net.osmand.plus.mapcontextmenu.MenuBuilder;
|
||||||
import net.osmand.plus.mapcontextmenu.MenuController;
|
import net.osmand.plus.mapcontextmenu.MenuController;
|
||||||
|
|
||||||
public class MyLocationMenuController extends 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);
|
super(new MenuBuilder(app), mapActivity);
|
||||||
|
this.pointDescription = pointDescription;
|
||||||
|
this.latLon = latLon;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -38,10 +40,11 @@ public class MyLocationMenuController extends MenuController {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getNameStr() {
|
public String getNameStr() {
|
||||||
return getMapActivity().getString(R.string.shared_string_my_location);
|
return pointDescription.getTypeName();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void saveEntityState(Bundle bundle, String key) {
|
public void saveEntityState(Bundle bundle, String key) {
|
||||||
|
bundle.putSerializable(key, latLon);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,8 @@ package net.osmand.plus.views;
|
||||||
|
|
||||||
|
|
||||||
import net.osmand.Location;
|
import net.osmand.Location;
|
||||||
|
import net.osmand.data.LatLon;
|
||||||
|
import net.osmand.data.PointDescription;
|
||||||
import net.osmand.data.RotatedTileBox;
|
import net.osmand.data.RotatedTileBox;
|
||||||
import net.osmand.plus.ApplicationMode;
|
import net.osmand.plus.ApplicationMode;
|
||||||
import net.osmand.plus.OsmAndLocationProvider;
|
import net.osmand.plus.OsmAndLocationProvider;
|
||||||
|
@ -12,9 +14,12 @@ import android.graphics.BitmapFactory;
|
||||||
import android.graphics.Canvas;
|
import android.graphics.Canvas;
|
||||||
import android.graphics.Paint;
|
import android.graphics.Paint;
|
||||||
import android.graphics.Paint.Style;
|
import android.graphics.Paint.Style;
|
||||||
|
import android.graphics.PointF;
|
||||||
import android.graphics.RectF;
|
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 int RADIUS = 7;
|
||||||
protected final static float HEADING_ANGLE = 60;
|
protected final static float HEADING_ANGLE = 60;
|
||||||
|
|
||||||
|
@ -125,10 +130,7 @@ public class PointLocationLayer extends OsmandMapLayer {
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isLocationVisible(RotatedTileBox tb, Location l) {
|
public boolean isLocationVisible(RotatedTileBox tb, Location l) {
|
||||||
if(l == null ){
|
return l != null && tb.containsLatLon(l.getLatitude(), l.getLongitude());
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return tb.containsLatLon(l.getLatitude(), l.getLongitude());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -150,4 +152,57 @@ public class PointLocationLayer extends OsmandMapLayer {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void collectObjectsFromPoint(PointF point, RotatedTileBox tileBox, List<Object> 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<? super LatLon> 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue