diff --git a/OsmAnd-java/src/net/osmand/data/Amenity.java b/OsmAnd-java/src/net/osmand/data/Amenity.java index ded7390f05..31cfd725d9 100644 --- a/OsmAnd-java/src/net/osmand/data/Amenity.java +++ b/OsmAnd-java/src/net/osmand/data/Amenity.java @@ -144,6 +144,10 @@ public class Amenity extends MapObject { } } + @Override + public String toStringEn() { + return super.toStringEn() + ":" + type.getKeyName() + ":" + subType; + } @Override public String toString() { diff --git a/OsmAnd-java/src/net/osmand/data/MapObject.java b/OsmAnd-java/src/net/osmand/data/MapObject.java index ff472c9bce..ab5a32b339 100644 --- a/OsmAnd-java/src/net/osmand/data/MapObject.java +++ b/OsmAnd-java/src/net/osmand/data/MapObject.java @@ -206,6 +206,10 @@ public abstract class MapObject implements Comparable { this.fileOffset = fileOffset; } + public String toStringEn() { + return getClass().getSimpleName() + ":" + getEnName(true); + } + @Override public String toString() { return getClass().getSimpleName() + " " + name + "(" + id + ")"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ diff --git a/OsmAnd/src/net/osmand/data/FavouritePoint.java b/OsmAnd/src/net/osmand/data/FavouritePoint.java index d398311f6f..fa9efc4585 100644 --- a/OsmAnd/src/net/osmand/data/FavouritePoint.java +++ b/OsmAnd/src/net/osmand/data/FavouritePoint.java @@ -9,6 +9,7 @@ public class FavouritePoint implements Serializable, LocationPoint { private String name = ""; private String description; private String category = ""; + private String originObjectName = ""; private double latitude; private double longitude; private int color; @@ -35,6 +36,7 @@ public class FavouritePoint implements Serializable, LocationPoint { this.color = favouritePoint.color; this.description = favouritePoint.description; this.visible = favouritePoint.visible; + this.originObjectName = favouritePoint.originObjectName; } public int getColor() { @@ -61,7 +63,14 @@ public class FavouritePoint implements Serializable, LocationPoint { public void setVisible(boolean visible) { this.visible = visible; } - + + public String getOriginObjectName() { + return originObjectName; + } + + public void setOriginObjectName(String originObjectName) { + this.originObjectName = originObjectName; + } public double getLatitude() { return latitude; diff --git a/OsmAnd/src/net/osmand/plus/FavouritesDbHelper.java b/OsmAnd/src/net/osmand/plus/FavouritesDbHelper.java index ff0bb831f5..23dc035513 100644 --- a/OsmAnd/src/net/osmand/plus/FavouritesDbHelper.java +++ b/OsmAnd/src/net/osmand/plus/FavouritesDbHelper.java @@ -405,6 +405,9 @@ public class FavouritesDbHelper { pt.desc = p.getDescription(); if (p.getCategory().length() > 0) pt.category = p.getCategory(); + if (p.getOriginObjectName().length() > 0) { + pt.comment = p.getOriginObjectName(); + } gpx.points.add(pt); } return gpx; @@ -559,6 +562,9 @@ public class FavouritesDbHelper { } FavouritePoint fp = new FavouritePoint(p.lat, p.lon, name, categoryName); fp.setDescription(p.desc); + if (p.comment != null) { + fp.setOriginObjectName(p.comment); + } fp.setColor(p.getColor(0)); fp.setVisible(!p.getExtensionsToRead().containsKey(HIDDEN)); points.put(getKey(fp), fp); diff --git a/OsmAnd/src/net/osmand/plus/GPXUtilities.java b/OsmAnd/src/net/osmand/plus/GPXUtilities.java index d504c3fb1d..c7c500ac7f 100644 --- a/OsmAnd/src/net/osmand/plus/GPXUtilities.java +++ b/OsmAnd/src/net/osmand/plus/GPXUtilities.java @@ -99,6 +99,7 @@ public class GPXUtilities { // previous undocumented feature 'category' ,now 'type' public String category = null; public String desc = null; + public String comment = null; // by default public long time = 0; public double ele = Double.NaN; @@ -182,6 +183,7 @@ public class GPXUtilities { result = prime * result + ((name == null) ? 0 : name.hashCode()); result = prime * result + ((category == null) ? 0 : category.hashCode()); result = prime * result + ((desc == null) ? 0 : desc.hashCode()); + result = prime * result + ((comment == null) ? 0 : comment.hashCode()); result = prime * result + ((lat == 0) ? 0 : Double.valueOf(lat).hashCode()); result = prime * result + ((lon == 0) ? 0 : Double.valueOf(lon).hashCode()); return result; @@ -933,6 +935,9 @@ public class GPXUtilities { serializer.endTag(null, "link"); } writeNotNullText(serializer, "type", p.category); + if (p.comment != null) { + writeNotNullText(serializer, "cmt", p.comment); + } if (!Double.isNaN(p.hdop)) { writeNotNullText(serializer, "hdop", p.hdop + ""); } @@ -1093,6 +1098,8 @@ public class GPXUtilities { ((WptPt) parse).name = readText(parser, "name"); } else if (parser.getName().equals("desc")) { ((WptPt) parse).desc = readText(parser, "desc"); + } else if (parser.getName().equals("cmt")) { + ((WptPt) parse).comment = readText(parser, "cmt"); } else if (parser.getName().equals("link")) { ((WptPt) parse).link = parser.getAttributeValue("", "href"); } else if (tag.equals("category")) { diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenu.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenu.java index ab39847f79..c475f38f93 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenu.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenu.java @@ -1,14 +1,22 @@ package net.osmand.plus.mapcontextmenu; -import java.lang.ref.WeakReference; -import java.util.LinkedList; -import java.util.List; +import android.app.Dialog; +import android.app.ProgressDialog; +import android.content.DialogInterface; +import android.support.annotation.NonNull; +import android.support.annotation.Nullable; +import android.support.v4.app.Fragment; +import android.support.v7.app.AlertDialog; +import android.view.View; +import android.widget.LinearLayout; import net.osmand.CallbackWithObject; import net.osmand.StateChangedListener; +import net.osmand.data.Amenity; import net.osmand.data.FavouritePoint; import net.osmand.data.LatLon; import net.osmand.data.PointDescription; +import net.osmand.data.TransportStop; import net.osmand.plus.ApplicationMode; import net.osmand.plus.ContextMenuAdapter; import net.osmand.plus.GPXUtilities.GPXFile; @@ -18,12 +26,10 @@ import net.osmand.plus.MapMarkersHelper.MapMarker; import net.osmand.plus.MapMarkersHelper.MapMarkerChangedListener; import net.osmand.plus.OsmandSettings; import net.osmand.plus.R; -import net.osmand.plus.TargetPointsHelper; import net.osmand.plus.TargetPointsHelper.TargetPoint; import net.osmand.plus.TargetPointsHelper.TargetPointChangedListener; import net.osmand.plus.activities.MapActivity; import net.osmand.plus.dashboard.DashboardOnMap; -import net.osmand.plus.dialogs.DirectionsDialogs; import net.osmand.plus.helpers.GpxUiHelper; import net.osmand.plus.mapcontextmenu.MenuController.ContextMenuToolbarController; import net.osmand.plus.mapcontextmenu.MenuController.MenuState; @@ -42,16 +48,10 @@ import net.osmand.plus.views.OsmandMapLayer; import net.osmand.plus.views.mapwidgets.MapInfoWidgetsFactory.TopToolbarController; import net.osmand.plus.views.mapwidgets.MapInfoWidgetsFactory.TopToolbarControllerType; import net.osmand.util.MapUtils; -import android.app.Dialog; -import android.app.ProgressDialog; -import android.content.DialogInterface; -import android.support.annotation.NonNull; -import android.support.annotation.Nullable; -import android.support.v4.app.Fragment; -import android.support.v7.app.AlertDialog; -import android.support.v7.app.AlertDialog.Builder; -import android.view.View; -import android.widget.LinearLayout; + +import java.lang.ref.WeakReference; +import java.util.LinkedList; +import java.util.List; public class MapContextMenu extends MenuTitleController implements StateChangedListener, MapMarkerChangedListener, TargetPointChangedListener { @@ -673,7 +673,15 @@ public class MapContextMenu extends MenuTitleController implements StateChangedL if (pointDescription.isFavorite() || !hasValidTitle()) { title = ""; } - getFavoritePointEditor().add(latLon, title); + String originObjectName = ""; + if (object != null) { + if (object instanceof Amenity) { + originObjectName = ((Amenity) object).toStringEn(); + } else if (object instanceof TransportStop) { + originObjectName = ((TransportStop) object).toStringEn(); + } + } + getFavoritePointEditor().add(latLon, title, originObjectName); } }); } diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuBuilder.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuBuilder.java index 5f10b0967d..7bc6c299de 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuBuilder.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuBuilder.java @@ -113,7 +113,7 @@ public class MenuBuilder { return firstRow; } - protected void rowBuilt() { + public void rowBuilt() { firstRow = false; } diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuController.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuController.java index 3da20de9f6..37fb67486b 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuController.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MenuController.java @@ -76,7 +76,7 @@ public abstract class MenuController extends BaseMenuController { MULTI_LINE } - private MenuBuilder builder; + protected MenuBuilder builder; private int currentMenuState; private MenuType menuType = MenuType.STANDARD; private PointDescription pointDescription; diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/FavouritePointMenuBuilder.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/FavouritePointMenuBuilder.java index da871965d4..89c8ecdf85 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/FavouritePointMenuBuilder.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/builders/FavouritePointMenuBuilder.java @@ -2,32 +2,104 @@ package net.osmand.plus.mapcontextmenu.builders; import android.view.View; +import net.osmand.ResultMatcher; +import net.osmand.binary.BinaryMapIndexReader; +import net.osmand.data.Amenity; import net.osmand.data.FavouritePoint; +import net.osmand.data.QuadRect; +import net.osmand.data.TransportStop; +import net.osmand.osm.PoiCategory; import net.osmand.plus.OsmandApplication; -import net.osmand.plus.R; import net.osmand.plus.mapcontextmenu.MenuBuilder; -import net.osmand.util.Algorithms; +import net.osmand.util.MapUtils; + +import java.util.List; public class FavouritePointMenuBuilder extends MenuBuilder { private final FavouritePoint fav; + private Object originObject; public FavouritePointMenuBuilder(OsmandApplication app, final FavouritePoint fav) { super(app); this.fav = fav; + acquireOriginObject(); } - @Override - protected boolean needBuildPlainMenuItems() { - return false; + public void acquireOriginObject() + { + String originObjectName = fav.getOriginObjectName(); + if (originObjectName.length() > 0) { + if (originObjectName.startsWith(Amenity.class.getSimpleName())) { + originObject = findAmenity(originObjectName, fav.getLatitude(), fav.getLongitude()); + } else if (originObjectName.startsWith(TransportStop.class.getSimpleName())) { + originObject = findTransportStop(originObjectName, fav.getLatitude(), fav.getLongitude()); + } + } + } + + public Object getOriginObject() { + return originObject; } @Override public void buildInternal(View view) { - if (!Algorithms.isEmpty(fav.getDescription())) { - buildRow(view, R.drawable.ic_action_note_dark, fav.getDescription(), 0, true, 0, false, null); + if (originObject != null) { + if (originObject instanceof Amenity) { + AmenityMenuBuilder builder = new AmenityMenuBuilder(app, (Amenity) originObject); + builder.setLight(light); + builder.buildInternal(view); + } } + } - buildPlainMenuItems(view); + private Amenity findAmenity(String nameStringEn, double lat, double lon) { + QuadRect rect = MapUtils.calculateLatLonBbox(lat, lon, 15); + List amenities = app.getResourceManager().searchAmenities( + new BinaryMapIndexReader.SearchPoiTypeFilter() { + @Override + public boolean accept(PoiCategory type, String subcategory) { + return true; + } + + @Override + public boolean isEmpty() { + return false; + } + }, rect.top, rect.left, rect.bottom, rect.right, -1, null); + + for (Amenity amenity : amenities) { + String stringEn = amenity.toStringEn(); + if (stringEn.equals(nameStringEn)) { + return amenity; + } + } + return null; + } + + private TransportStop findTransportStop(String nameStringEn, double lat, double lon) { + + QuadRect rect = MapUtils.calculateLatLonBbox(lat, lon, 15); + List res = app.getResourceManager().searchTransportSync(rect.top, rect.left, + rect.bottom, rect.right, new ResultMatcher() { + + @Override + public boolean publish(TransportStop object) { + return true; + } + + @Override + public boolean isCancelled() { + return false; + } + }); + + for (TransportStop stop : res) { + String stringEn = stop.toStringEn(); + if (stringEn.equals(nameStringEn)) { + return stop; + } + } + return null; } } diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/AmenityMenuController.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/AmenityMenuController.java index 3dab566229..cd332bdfac 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/AmenityMenuController.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/AmenityMenuController.java @@ -8,6 +8,7 @@ import net.osmand.osm.PoiType; import net.osmand.plus.OsmandApplication; import net.osmand.plus.R; import net.osmand.plus.activities.MapActivity; +import net.osmand.plus.mapcontextmenu.MenuBuilder; import net.osmand.plus.mapcontextmenu.MenuController; import net.osmand.plus.mapcontextmenu.builders.AmenityMenuBuilder; import net.osmand.plus.render.RenderingIcons; @@ -52,6 +53,10 @@ public class AmenityMenuController extends MenuController { @Override public int getLeftIconId() { + return getLeftIconId(amenity); + } + + public static int getLeftIconId(Amenity amenity) { String id = null; PoiType st = amenity.getType().getPoiTypeByKeyName(amenity.getSubType()); if (st != null) { @@ -74,6 +79,10 @@ public class AmenityMenuController extends MenuController { @Override public String getTypeStr() { + return getTypeStr(amenity); + } + + public static String getTypeStr(Amenity amenity) { PoiCategory pc = amenity.getType(); PoiType pt = pc.getPoiTypeByKeyName(amenity.getSubType()); String typeStr = amenity.getSubType(); @@ -93,8 +102,12 @@ public class AmenityMenuController extends MenuController { @Override public void addPlainMenuItems(String typeStr, PointDescription pointDescription, LatLon latLon) { + addPlainMenuItems(amenity, typeStr, builder); + } + + public static void addPlainMenuItems(Amenity amenity, String typeStr, MenuBuilder builder) { if (!Algorithms.isEmpty(typeStr)) { - int resId = getLeftIconId(); + int resId = getLeftIconId(amenity); if (resId == 0) { PoiCategory pc = amenity.getType(); resId = RenderingIcons.getBigIconResourceId(pc.getIconKeyName()); @@ -102,7 +115,7 @@ public class AmenityMenuController extends MenuController { if (resId == 0) { resId = R.drawable.ic_action_folder_stroke; } - addPlainMenuItem(resId, typeStr, false, false, null); + builder.addPlainMenuItem(resId, typeStr, false, false, null); } } } diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/FavouritePointMenuController.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/FavouritePointMenuController.java index 476ec74d8b..c737043cf4 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/FavouritePointMenuController.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/FavouritePointMenuController.java @@ -3,8 +3,11 @@ package net.osmand.plus.mapcontextmenu.controllers; import android.graphics.drawable.Drawable; import android.support.v4.app.Fragment; +import net.osmand.data.Amenity; import net.osmand.data.FavouritePoint; +import net.osmand.data.LatLon; import net.osmand.data.PointDescription; +import net.osmand.data.TransportStop; import net.osmand.plus.OsmandApplication; import net.osmand.plus.R; import net.osmand.plus.activities.MapActivity; @@ -13,6 +16,7 @@ import net.osmand.plus.mapcontextmenu.MenuController; import net.osmand.plus.mapcontextmenu.builders.FavouritePointMenuBuilder; import net.osmand.plus.mapcontextmenu.editors.FavoritePointEditor; import net.osmand.plus.mapcontextmenu.editors.FavoritePointEditorFragment; +import net.osmand.util.Algorithms; public class FavouritePointMenuController extends MenuController { @@ -90,4 +94,30 @@ public class FavouritePointMenuController extends MenuController { return fav.getCategory().length() == 0 ? getMapActivity().getString(R.string.shared_string_favorites) : fav.getCategory(); } + + private FavouritePointMenuBuilder getBuilder() { + return (FavouritePointMenuBuilder) builder; + } + + @Override + public void addPlainMenuItems(String typeStr, PointDescription pointDescription, LatLon latLon) { + if (!Algorithms.isEmpty(fav.getDescription())) { + addPlainMenuItem(R.drawable.ic_action_note_dark, fav.getDescription(), true, false, null); + } + Object originObject = getBuilder().getOriginObject(); + if (originObject != null) { + if (originObject instanceof Amenity) { + Amenity amenity = (Amenity) originObject; + AmenityMenuController.addPlainMenuItems(amenity, AmenityMenuController.getTypeStr(amenity), builder); + } else if (originObject instanceof TransportStop) { + TransportStop stop = (TransportStop) originObject; + TransportStopController transportStopController = + new TransportStopController(getMapActivity().getMyApplication(), getMapActivity(), pointDescription, stop); + transportStopController.addPlainMenuItems(builder, latLon); + addMyLocationToPlainItems(latLon); + } + } else { + addMyLocationToPlainItems(latLon); + } + } } diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/TransportStopController.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/TransportStopController.java index 685388c1c1..ce5f9b8bdb 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/TransportStopController.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/controllers/TransportStopController.java @@ -129,6 +129,11 @@ public class TransportStopController extends MenuController { @Override public void addPlainMenuItems(String typeStr, PointDescription pointDescription, final LatLon latLon) { + addPlainMenuItems(builder, latLon); + super.addPlainMenuItems(typeStr, pointDescription, latLon); + } + + public void addPlainMenuItems(MenuBuilder builder, final LatLon latLon) { for (final TransportStopRoute r : routes) { OnClickListener listener = new OnClickListener() { @Override @@ -144,14 +149,13 @@ public class TransportStopController extends MenuController { } }; if (r.type == null) { - addPlainMenuItem(R.drawable.ic_action_polygom_dark, r.getDescription(getMapActivity().getMyApplication(), true), + builder.addPlainMenuItem(R.drawable.ic_action_polygom_dark, r.getDescription(getMapActivity().getMyApplication(), true), false, false, listener ); } else { - addPlainMenuItem(r.type.getResourceId(), r.getDescription(getMapActivity().getMyApplication(), true), + builder.addPlainMenuItem(r.type.getResourceId(), r.getDescription(getMapActivity().getMyApplication(), true), false, false, listener); } } - super.addPlainMenuItems(typeStr, pointDescription, latLon); } private void processTransportStop() { diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/FavoritePointEditor.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/FavoritePointEditor.java index c7e051e77e..34a82e3df4 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/FavoritePointEditor.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/FavoritePointEditor.java @@ -24,7 +24,7 @@ public class FavoritePointEditor extends PointEditor { return favorite; } - public void add(LatLon latLon, String title) { + public void add(LatLon latLon, String title, String originObjectName) { if (latLon == null) { return; } @@ -35,6 +35,7 @@ public class FavoritePointEditor extends PointEditor { } favorite = new FavouritePoint(latLon.getLatitude(), latLon.getLongitude(), title, lastCategory); favorite.setDescription(""); + favorite.setOriginObjectName(originObjectName); FavoritePointEditorFragment.showInstance(mapActivity); }