This commit is contained in:
Alexey Kulish 2016-09-18 16:48:22 +03:00
parent 5cba154a6a
commit acd020db50
13 changed files with 191 additions and 33 deletions

View file

@ -144,6 +144,10 @@ public class Amenity extends MapObject {
}
}
@Override
public String toStringEn() {
return super.toStringEn() + ":" + type.getKeyName() + ":" + subType;
}
@Override
public String toString() {

View file

@ -206,6 +206,10 @@ public abstract class MapObject implements Comparable<MapObject> {
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$

View file

@ -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;

View file

@ -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);

View file

@ -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")) {

View file

@ -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<ApplicationMode>,
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);
}
});
}

View file

@ -113,7 +113,7 @@ public class MenuBuilder {
return firstRow;
}
protected void rowBuilt() {
public void rowBuilt() {
firstRow = false;
}

View file

@ -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;

View file

@ -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<Amenity> 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<TransportStop> res = app.getResourceManager().searchTransportSync(rect.top, rect.left,
rect.bottom, rect.right, new ResultMatcher<TransportStop>() {
@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;
}
}

View file

@ -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);
}
}
}

View file

@ -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);
}
}
}

View file

@ -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() {

View file

@ -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);
}