From 0f81841c7980c3b91e1bd42af03a3b65b6174317 Mon Sep 17 00:00:00 2001 From: Skalii Date: Wed, 24 Feb 2021 15:02:39 +0200 Subject: [PATCH 1/4] test adding altitude and timestamp to new favorite --- .../net/osmand/binary/RouteDataObject.java | 210 ++++++++++-------- .../src/net/osmand/data/FavouritePoint.java | 82 ++++++- .../osmand/plus/importfiles/ImportHelper.java | 18 +- .../plus/mapcontextmenu/MapContextMenu.java | 10 +- .../editors/FavoritePointEditor.java | 35 ++- .../editors/FavoritePointEditorFragment.java | 10 +- .../FavoritePointEditorFragmentNew.java | 12 +- .../quickaction/actions/FavoriteAction.java | 2 +- 8 files changed, 248 insertions(+), 131 deletions(-) diff --git a/OsmAnd-java/src/main/java/net/osmand/binary/RouteDataObject.java b/OsmAnd-java/src/main/java/net/osmand/binary/RouteDataObject.java index bc81ca667e..f444a56b04 100644 --- a/OsmAnd-java/src/main/java/net/osmand/binary/RouteDataObject.java +++ b/OsmAnd-java/src/main/java/net/osmand/binary/RouteDataObject.java @@ -4,6 +4,7 @@ import net.osmand.Location; import net.osmand.PlatformUtil; import net.osmand.binary.BinaryMapRouteReaderAdapter.RouteRegion; import net.osmand.binary.BinaryMapRouteReaderAdapter.RouteTypeRule; +import net.osmand.data.LatLon; import net.osmand.util.Algorithms; import net.osmand.util.MapUtils; import net.osmand.util.TransliterationHelper; @@ -37,7 +38,9 @@ public class RouteDataObject { public int[] nameIds; // mixed array [0, height, cumulative_distance height, cumulative_distance, height, ...] - length is length(points)*2 public float[] heightDistanceArray = null; + public float heightByCurrentLocation; private static final Log LOG = PlatformUtil.getLog(RouteDataObject.class); + public RouteDataObject(RouteRegion region) { this.region = region; } @@ -124,7 +127,7 @@ public class RouteDataObject { equals = this.pointTypes[i] == thatObj.pointTypes[i]; } else if (pointTypes[i].length != thatObj.pointTypes[i].length) { equals = false; - } else { + } else { for (int j = 0; j < this.pointTypes[i].length && equals; j++) { String thisTag = region.routeEncodingRules.get(pointTypes[i][j]).getTag(); String thisValue = region.routeEncodingRules.get(pointTypes[i][j]).getValue(); @@ -147,7 +150,7 @@ public class RouteDataObject { equals = this.pointNameTypes[i] == thatObj.pointNameTypes[i]; } else if (pointNameTypes[i].length != thatObj.pointNameTypes[i].length) { equals = false; - } else { + } else { for (int j = 0; j < this.pointNameTypes[i].length && equals; j++) { String thisTag = region.routeEncodingRules.get(pointNameTypes[i][j]).getTag(); String thisValue = pointNames[i][j]; @@ -165,53 +168,67 @@ public class RouteDataObject { } public float[] calculateHeightArray() { - if(heightDistanceArray != null) { + return calculateHeightArray(null); + } + + public float[] calculateHeightArray(LatLon currentLocation) { + if (heightDistanceArray != null) { return heightDistanceArray; } int startHeight = Algorithms.parseIntSilently(getValue("osmand_ele_start"), HEIGHT_UNDEFINED); int endHeight = Algorithms.parseIntSilently(getValue("osmand_ele_end"), startHeight); - if(startHeight == HEIGHT_UNDEFINED) { + if (startHeight == HEIGHT_UNDEFINED) { heightDistanceArray = new float[0]; return heightDistanceArray; } - heightDistanceArray = new float[2*getPointsLength()]; + heightDistanceArray = new float[2 * getPointsLength()]; double plon = 0; double plat = 0; - float prevHeight = startHeight; - for(int k = 0; k < getPointsLength(); k++) { + float prevHeight = heightByCurrentLocation = startHeight; + double prevDistance = 0; + for (int k = 0; k < getPointsLength(); k++) { double lon = MapUtils.get31LongitudeX(getPoint31XTile(k)); double lat = MapUtils.get31LatitudeY(getPoint31YTile(k)); - if(k > 0) { + if (k > 0) { double dd = MapUtils.getDistance(plat, plon, lat, lon); float height = HEIGHT_UNDEFINED; - if(k == getPointsLength() - 1) { + if (k == getPointsLength() - 1) { height = endHeight; } else { String asc = getValue(k, "osmand_ele_asc"); - if(asc != null && asc.length() > 0) { + if (asc != null && asc.length() > 0) { height = (prevHeight + Float.parseFloat(asc)); } else { String desc = getValue(k, "osmand_ele_desc"); - if(desc != null && desc.length() > 0) { + if (desc != null && desc.length() > 0) { height = (prevHeight - Float.parseFloat(desc)); } } } - heightDistanceArray[2*k] = (float) dd; - heightDistanceArray[2*k+1] = height; - if(height != HEIGHT_UNDEFINED) { + heightDistanceArray[2 * k] = (float) dd; + heightDistanceArray[2 * k + 1] = height; + + if (currentLocation != null) { + double distance = MapUtils.getDistance(currentLocation, lat, lon); + if (height != HEIGHT_UNDEFINED && distance < prevDistance) { + prevDistance = distance; + heightByCurrentLocation = height; + } + } + + if (height != HEIGHT_UNDEFINED) { // interpolate undefined double totalDistance = dd; int startUndefined = k; - while(startUndefined - 1 >= 0 && heightDistanceArray[2*(startUndefined - 1)+1] == HEIGHT_UNDEFINED) { - startUndefined --; - totalDistance += heightDistanceArray[2*(startUndefined)]; + while (startUndefined - 1 >= 0 && heightDistanceArray[2 * (startUndefined - 1) + 1] == HEIGHT_UNDEFINED) { + startUndefined--; + totalDistance += heightDistanceArray[2 * (startUndefined)]; } - if(totalDistance > 0) { + if (totalDistance > 0) { double angle = (height - prevHeight) / totalDistance; - for(int j = startUndefined; j < k; j++) { - heightDistanceArray[2*j+1] = (float) ((heightDistanceArray[2*j] * angle) + heightDistanceArray[2*j-1]); + for (int j = startUndefined; j < k; j++) { + heightDistanceArray[2 * j + 1] = (float) ((heightDistanceArray[2 * j] * angle) + heightDistanceArray[2 * j - 1]); } } prevHeight = height; @@ -223,6 +240,9 @@ public class RouteDataObject { } plat = lat; plon = lon; + if (currentLocation != null) { + prevDistance = MapUtils.getDistance(currentLocation, plat, plon); + } } return heightDistanceArray; } @@ -231,34 +251,34 @@ public class RouteDataObject { return id; } - public String getName(){ - if(names != null ) { + public String getName() { + if (names != null) { return names.get(region.nameTypeRule); } return null; } - public String getName(String lang){ + public String getName(String lang) { return getName(lang, false); } - public String getName(String lang, boolean transliterate){ - if(names != null ) { - if(Algorithms.isEmpty(lang)) { + public String getName(String lang, boolean transliterate) { + if (names != null) { + if (Algorithms.isEmpty(lang)) { return names.get(region.nameTypeRule); } int[] kt = names.keys(); - for(int i = 0 ; i < kt.length; i++) { + for (int i = 0; i < kt.length; i++) { int k = kt[i]; - if(region.routeEncodingRules.size() > k) { - if(("name:"+lang).equals(region.routeEncodingRules.get(k).getTag())) { + if (region.routeEncodingRules.size() > k) { + if (("name:" + lang).equals(region.routeEncodingRules.get(k).getTag())) { return names.get(k); } } } String nmDef = names.get(region.nameTypeRule); - if(transliterate && nmDef != null && nmDef.length() > 0) { + if (transliterate && nmDef != null && nmDef.length() > 0) { return TransliterationHelper.transliterate(nmDef); } return nmDef; @@ -279,20 +299,20 @@ public class RouteDataObject { // return getDestinationRef(direction); //} if (names != null) { - if(Algorithms.isEmpty(lang)) { + if (Algorithms.isEmpty(lang)) { return names.get(region.refTypeRule); } int[] kt = names.keys(); - for(int i = 0 ; i < kt.length; i++) { + for (int i = 0; i < kt.length; i++) { int k = kt[i]; - if(region.routeEncodingRules.size() > k) { - if(("ref:"+lang).equals(region.routeEncodingRules.get(k).getTag())) { + if (region.routeEncodingRules.size() > k) { + if (("ref:" + lang).equals(region.routeEncodingRules.get(k).getTag())) { return names.get(k); } } } String refDefault = names.get(region.refTypeRule); - if(transliterate && refDefault != null && refDefault.length() > 0) { + if (transliterate && refDefault != null && refDefault.length() > 0) { return TransliterationHelper.transliterate(refDefault); } return refDefault; @@ -307,13 +327,13 @@ public class RouteDataObject { String refTagDefault = "destination:ref"; String refDefault = null; - for(int i = 0 ; i < kt.length; i++) { + for (int i = 0; i < kt.length; i++) { int k = kt[i]; - if(region.routeEncodingRules.size() > k) { - if(refTag.equals(region.routeEncodingRules.get(k).getTag())) { + if (region.routeEncodingRules.size() > k) { + if (refTag.equals(region.routeEncodingRules.get(k).getTag())) { return names.get(k); } - if(refTagDefault.equals(region.routeEncodingRules.get(k).getTag())) { + if (refTagDefault.equals(region.routeEncodingRules.get(k).getTag())) { refDefault = names.get(k); } } @@ -326,12 +346,12 @@ public class RouteDataObject { return null; } - public String getDestinationName(String lang, boolean transliterate, boolean direction){ + public String getDestinationName(String lang, boolean transliterate, boolean direction) { //Issue #3289: Treat destination:ref like a destination, not like a ref String destRef = ((getDestinationRef(direction) == null) || getDestinationRef(direction).equals(getRef(lang, transliterate, direction))) ? "" : getDestinationRef(direction); String destRef1 = Algorithms.isEmpty(destRef) ? "" : destRef + ", "; - if(names != null) { + if (names != null) { int[] kt = names.keys(); // Issue #3181: Parse destination keys in this order: @@ -341,35 +361,35 @@ public class RouteDataObject { // destination String destinationTagLangFB = "destination:lang:XX"; - if(!Algorithms.isEmpty(lang)) { + if (!Algorithms.isEmpty(lang)) { destinationTagLangFB = (direction == true) ? "destination:lang:" + lang + ":forward" : "destination:lang:" + lang + ":backward"; } String destinationTagFB = (direction == true) ? "destination:forward" : "destination:backward"; String destinationTagLang = "destination:lang:XX"; - if(!Algorithms.isEmpty(lang)) { + if (!Algorithms.isEmpty(lang)) { destinationTagLang = "destination:lang:" + lang; } String destinationTagDefault = "destination"; String destinationDefault = null; - for(int i = 0 ; i < kt.length; i++) { + for (int i = 0; i < kt.length; i++) { int k = kt[i]; - if(region.routeEncodingRules.size() > k) { - if(!Algorithms.isEmpty(lang) && destinationTagLangFB.equals(region.routeEncodingRules.get(k).getTag())) { + if (region.routeEncodingRules.size() > k) { + if (!Algorithms.isEmpty(lang) && destinationTagLangFB.equals(region.routeEncodingRules.get(k).getTag())) { return destRef1 + ((transliterate) ? TransliterationHelper.transliterate(names.get(k)) : names.get(k)); } - if(destinationTagFB.equals(region.routeEncodingRules.get(k).getTag())) { + if (destinationTagFB.equals(region.routeEncodingRules.get(k).getTag())) { return destRef1 + ((transliterate) ? TransliterationHelper.transliterate(names.get(k)) : names.get(k)); } - if(!Algorithms.isEmpty(lang) && destinationTagLang.equals(region.routeEncodingRules.get(k).getTag())) { + if (!Algorithms.isEmpty(lang) && destinationTagLang.equals(region.routeEncodingRules.get(k).getTag())) { return destRef1 + ((transliterate) ? TransliterationHelper.transliterate(names.get(k)) : names.get(k)); } - if(destinationTagDefault.equals(region.routeEncodingRules.get(k).getTag())) { + if (destinationTagDefault.equals(region.routeEncodingRules.get(k).getTag())) { destinationDefault = names.get(k); } } } - if(destinationDefault != null) { + if (destinationDefault != null) { return destRef1 + ((transliterate) ? TransliterationHelper.transliterate(destinationDefault) : destinationDefault); } } @@ -400,14 +420,14 @@ public class RouteDataObject { RestrictionInfo ri = new RestrictionInfo(); ri.toWay = getRestrictionId(k); ri.type = getRestrictionType(k); - if(restrictionsVia != null && k < restrictionsVia.length) { + if (restrictionsVia != null && k < restrictionsVia.length) { ri.viaWay = restrictionsVia[k]; } return ri; } public long getRestrictionVia(int i) { - if(restrictionsVia != null && restrictionsVia.length > i) { + if (restrictionsVia != null && restrictionsVia.length > i) { return restrictionsVia[i]; } return 0; @@ -441,7 +461,7 @@ public class RouteDataObject { } if (insNames) { pointNames = new String[opointNames.length + 1][]; - pointNameTypes = new int[opointNameTypes.length +1][]; + pointNameTypes = new int[opointNameTypes.length + 1][]; } int i = 0; for (; i < pos; i++) { @@ -590,7 +610,7 @@ public class RouteDataObject { } public static float parseSpeed(String v, float def) { - if(v.equals("none")) { + if (v.equals("none")) { return RouteDataObject.NONE_MAX_SPEED; } else { int i = Algorithms.findFirstNumberEndIndex(v); @@ -614,20 +634,20 @@ public class RouteDataObject { f += Float.parseFloat(v.substring(0, i)); String pref = v.substring(i, v.length()).trim(); float add = 0; - for(int ik = 0; ik < pref.length(); ik++) { - if(Algorithms.isDigit(pref.charAt(ik)) || pref.charAt(ik) == '.' || pref.charAt(ik) == '-') { + for (int ik = 0; ik < pref.length(); ik++) { + if (Algorithms.isDigit(pref.charAt(ik)) || pref.charAt(ik) == '.' || pref.charAt(ik) == '-') { int first = Algorithms.findFirstNumberEndIndex(pref.substring(ik)); - if(first != -1) { + if (first != -1) { add = parseLength(pref.substring(ik), 0); pref = pref.substring(0, ik); } break; } } - if(pref.contains("km")) { + if (pref.contains("km")) { f *= 1000; } - if(pref.contains("\"") || pref.contains("in")) { + if (pref.contains("\"") || pref.contains("in")) { f *= 0.0254; } else if (pref.contains("\'") || pref.contains("ft") || pref.contains("feet")) { // foot to meters @@ -673,27 +693,27 @@ public class RouteDataObject { return false; } - public boolean roundabout(){ + public boolean roundabout() { int sz = types.length; - for(int i=0; i endPoint) { + if (startPoint > endPoint) { int k = endPoint; endPoint = startPoint; startPoint = k; } double d = 0; - for(int k = startPoint; k < endPoint && k < getPointsLength() -1; k++) { + for (int k = startPoint; k < endPoint && k < getPointsLength() - 1; k++) { int x = getPoint31XTile(k); int y = getPoint31YTile(k); int kx = getPoint31XTile(k + 1); @@ -974,16 +994,16 @@ public class RouteDataObject { // translate into meters total += simplifyDistance(x, y, px, py); } while (total < dist); - return -Math.atan2( x - px, y - py ); + return -Math.atan2(x - px, y - py); } private double simplifyDistance(int x, int y, int px, int py) { return Math.abs(px - x) * 0.011d + Math.abs(py - y) * 0.01863d; } - private static void assertTrueLength(String vl, float exp){ + private static void assertTrueLength(String vl, float exp) { float dest = parseLength(vl, 0); - if(exp != dest) { + if (exp != dest) { System.err.println("FAIL " + vl + " " + dest); } else { System.out.println("OK " + vl); @@ -992,24 +1012,24 @@ public class RouteDataObject { public static void main(String[] args) { assertTrueLength("10 km", 10000); - assertTrueLength("0.01 km", 10); - assertTrueLength("0.01 km 10 m", 20); - assertTrueLength("10 m", 10); - assertTrueLength("10m", 10); - assertTrueLength("3.4 m", 3.4f); - assertTrueLength("3.40 m", 3.4f); - assertTrueLength("10 m 10m", 20); - assertTrueLength("14'10\"", 4.5212f); - assertTrueLength("14.5'", 4.4196f); - assertTrueLength("14.5 ft", 4.4196f); - assertTrueLength("14'0\"", 4.2672f); - assertTrueLength("15ft", 4.572f); - assertTrueLength("15 ft 1 in", 4.5974f); - assertTrueLength("4.1 metres", 4.1f); - assertTrueLength("14'0''", 4.2672f); - assertTrueLength("14 feet", 4.2672f); - assertTrueLength("14 mile", 22530.76f); - assertTrueLength("14 cm", 0.14f); + assertTrueLength("0.01 km", 10); + assertTrueLength("0.01 km 10 m", 20); + assertTrueLength("10 m", 10); + assertTrueLength("10m", 10); + assertTrueLength("3.4 m", 3.4f); + assertTrueLength("3.40 m", 3.4f); + assertTrueLength("10 m 10m", 20); + assertTrueLength("14'10\"", 4.5212f); + assertTrueLength("14.5'", 4.4196f); + assertTrueLength("14.5 ft", 4.4196f); + assertTrueLength("14'0\"", 4.2672f); + assertTrueLength("15ft", 4.572f); + assertTrueLength("15 ft 1 in", 4.5974f); + assertTrueLength("4.1 metres", 4.1f); + assertTrueLength("14'0''", 4.2672f); + assertTrueLength("14 feet", 4.2672f); + assertTrueLength("14 mile", 22530.76f); + assertTrueLength("14 cm", 0.14f); // float badValue = -1; // assertTrueLength("none", badValue); @@ -1054,7 +1074,7 @@ public class RouteDataObject { public RestrictionInfo next; // optional to simulate linked list public int length() { - if(next == null) { + if (next == null) { return 1; } return next.length() + 1; @@ -1064,16 +1084,16 @@ public class RouteDataObject { public void setRestriction(int k, long to, int type, long viaWay) { long valto = (to << RouteDataObject.RESTRICTION_SHIFT) | ((long) type & RouteDataObject.RESTRICTION_MASK); restrictions[k] = valto; - if(viaWay != 0) { + if (viaWay != 0) { setRestrictionVia(k, viaWay); } } public void setRestrictionVia(int k, long viaWay) { - if(restrictionsVia != null) { + if (restrictionsVia != null) { long[] nrestrictionsVia = new long[Math.max(k + 1, restrictions.length)]; System.arraycopy(restrictions, 0, nrestrictionsVia, 0, restrictions.length); - restrictionsVia = nrestrictionsVia; + restrictionsVia = nrestrictionsVia; } else { restrictionsVia = new long[k + 1]; } diff --git a/OsmAnd/src/net/osmand/data/FavouritePoint.java b/OsmAnd/src/net/osmand/data/FavouritePoint.java index 7205b4a422..181c38d7f9 100644 --- a/OsmAnd/src/net/osmand/data/FavouritePoint.java +++ b/OsmAnd/src/net/osmand/data/FavouritePoint.java @@ -11,6 +11,9 @@ import androidx.annotation.Nullable; import androidx.annotation.StringRes; import net.osmand.GPXUtilities.WptPt; +import net.osmand.Location; +import net.osmand.ResultMatcher; +import net.osmand.binary.RouteDataObject; import net.osmand.plus.FavouritesDbHelper; import net.osmand.plus.OsmandApplication; import net.osmand.plus.settings.backend.BooleanPreference; @@ -42,6 +45,8 @@ public class FavouritePoint implements Serializable, LocationPoint { private boolean visible = true; private SpecialPointType specialPointType = null; private BackgroundType backgroundType = null; + private double altitude; + private long timestamp; public FavouritePoint() { } @@ -50,13 +55,26 @@ public class FavouritePoint implements Serializable, LocationPoint { this.latitude = latitude; this.longitude = longitude; this.category = category; - if(name == null) { + if (name == null) { name = ""; } this.name = name; initPersonalType(); } + public FavouritePoint(double latitude, double longitude, String name, String category, double altitude, long timestamp) { + this.latitude = latitude; + this.longitude = longitude; + this.category = category; + if (name == null) { + name = ""; + } + this.name = name; + this.altitude = altitude; + this.timestamp = timestamp; + initPersonalType(); + } + public FavouritePoint(FavouritePoint favouritePoint) { this.latitude = favouritePoint.latitude; this.longitude = favouritePoint.longitude; @@ -69,25 +87,48 @@ public class FavouritePoint implements Serializable, LocationPoint { this.address = favouritePoint.address; this.iconId = favouritePoint.iconId; this.backgroundType = favouritePoint.backgroundType; + this.altitude = favouritePoint.altitude; + this.timestamp = favouritePoint.timestamp; initPersonalType(); } private void initPersonalType() { - if(FavouritesDbHelper.FavoriteGroup.PERSONAL_CATEGORY.equals(category)) { - for(SpecialPointType p : SpecialPointType.values()) { - if(p.typeName.equals(this.name)) { + if (FavouritesDbHelper.FavoriteGroup.PERSONAL_CATEGORY.equals(category)) { + for (SpecialPointType p : SpecialPointType.values()) { + if (p.typeName.equals(this.name)) { this.specialPointType = p; } } } } + public void initAltitude(final OsmandApplication app, final Runnable callback) { + app.getLocationProvider().getRouteSegment(new Location("", latitude, longitude), null, false, new ResultMatcher() { + + @Override + public boolean publish(RouteDataObject routeDataObject) { + if (routeDataObject != null) { + routeDataObject.calculateHeightArray(new LatLon(latitude, longitude)); + altitude = routeDataObject.heightByCurrentLocation; + } else { + } + callback.run(); + return true; + } + + @Override + public boolean isCancelled() { + return false; + } + }); + } + public SpecialPointType getSpecialPointType() { return specialPointType; } public int getColor() { - return color; + return color; } @Nullable @@ -171,6 +212,22 @@ public class FavouritePoint implements Serializable, LocationPoint { this.longitude = longitude; } + public double getAltitude() { + return altitude; + } + + public void setAltitude(double altitude) { + this.altitude = altitude; + } + + public long getTimestamp() { + return timestamp; + } + + public void setTimestamp(long timestamp) { + this.timestamp = timestamp; + } + public String getCategory() { return category; } @@ -200,7 +257,7 @@ public class FavouritePoint implements Serializable, LocationPoint { initPersonalType(); } - public String getDescription () { + public String getDescription() { return description; } @@ -256,7 +313,8 @@ public class FavouritePoint implements Serializable, LocationPoint { } else if (!originObjectName.equals(fp.originObjectName)) return false; - return (this.latitude == fp.latitude) && (this.longitude == fp.longitude); + return (this.latitude == fp.latitude) && (this.longitude == fp.longitude) && + (this.altitude == fp.altitude) && (this.timestamp == fp.timestamp); } @Override @@ -265,6 +323,8 @@ public class FavouritePoint implements Serializable, LocationPoint { int result = 1; result = prime * result + (int) Math.floor(latitude * 10000); result = prime * result + (int) Math.floor(longitude * 10000); + result = prime * result + (int) Math.floor(altitude * 10000); + result = prime * result + (int) Math.floor(timestamp * 10000); result = prime * result + ((name == null) ? 0 : name.hashCode()); result = prime * result + ((category == null) ? 0 : category.hashCode()); result = prime * result + ((description == null) ? 0 : description.hashCode()); @@ -289,7 +349,9 @@ public class FavouritePoint implements Serializable, LocationPoint { this.iconId = iconId; } - public String getCategory() { return FavouritesDbHelper.FavoriteGroup.PERSONAL_CATEGORY; } + public String getCategory() { + return FavouritesDbHelper.FavoriteGroup.PERSONAL_CATEGORY; + } public String getName() { return typeName; @@ -384,7 +446,7 @@ public class FavouritePoint implements Serializable, LocationPoint { name = ""; } FavouritePoint fp; - fp = new FavouritePoint(pt.lat, pt.lon, name, categoryName); + fp = new FavouritePoint(pt.lat, pt.lon, name, categoryName, pt.ele, pt.time); fp.setDescription(pt.desc); if (pt.comment != null) { fp.setOriginObjectName(pt.comment); @@ -405,6 +467,8 @@ public class FavouritePoint implements Serializable, LocationPoint { WptPt pt = new WptPt(); pt.lat = getLatitude(); pt.lon = getLongitude(); + pt.ele = getAltitude(); + pt.time = getTimestamp(); if (!isVisible()) { pt.getExtensionsToWrite().put(HIDDEN, "true"); } diff --git a/OsmAnd/src/net/osmand/plus/importfiles/ImportHelper.java b/OsmAnd/src/net/osmand/plus/importfiles/ImportHelper.java index e65727b6c1..c4b78541de 100644 --- a/OsmAnd/src/net/osmand/plus/importfiles/ImportHelper.java +++ b/OsmAnd/src/net/osmand/plus/importfiles/ImportHelper.java @@ -212,7 +212,7 @@ public class ImportHelper { public static String getNameFromContentUri(OsmandApplication app, Uri contentUri) { try { String name; - Cursor returnCursor = app.getContentResolver().query(contentUri, new String[] {OpenableColumns.DISPLAY_NAME}, null, null, null); + Cursor returnCursor = app.getContentResolver().query(contentUri, new String[]{OpenableColumns.DISPLAY_NAME}, null, null, null); if (returnCursor != null && returnCursor.moveToFirst()) { int columnIndex = returnCursor.getColumnIndex(OpenableColumns.DISPLAY_NAME); if (columnIndex != -1) { @@ -671,7 +671,7 @@ public class ImportHelper { } public static List asFavourites(OsmandApplication app, List wptPts, String fileName, boolean forceImportFavourites) { - List favourites = new ArrayList<>(); + final List favourites = new ArrayList<>(); for (WptPt p : wptPts) { if (Algorithms.isEmpty(p.name)) { p.name = app.getResources().getString(R.string.shared_string_waypoint); @@ -687,7 +687,7 @@ public class ImportHelper { } else { fpCat = p.category; } - FavouritePoint point = new FavouritePoint(p.lat, p.lon, p.name, fpCat); + final FavouritePoint point = new FavouritePoint(p.lat, p.lon, p.name, fpCat, p.ele, p.time); if (p.desc != null) { point.setDescription(p.desc); } @@ -698,7 +698,17 @@ public class ImportHelper { point.setIconIdFromName(app, iconName); } point.setBackgroundType(BackgroundType.getByTypeName(p.getBackgroundType(), DEFAULT_BACKGROUND_TYPE)); - favourites.add(point); + if (Double.isNaN(p.ele) || p.ele == 0) { + point.initAltitude(app, new Runnable() { + + @Override + public void run() { + favourites.add(point); + } + }); + } else { + favourites.add(point); + } } } return favourites; diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenu.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenu.java index 3fe1e4452b..38bf3feb78 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenu.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/MapContextMenu.java @@ -1036,6 +1036,8 @@ public class MapContextMenu extends MenuTitleController implements StateChangedL title = ""; } String originObjectName = ""; + double altitude = 0; + long timestamp = System.currentTimeMillis(); Object object = getObject(); if (object != null) { if (object instanceof Amenity) { @@ -1043,10 +1045,13 @@ public class MapContextMenu extends MenuTitleController implements StateChangedL } else if (object instanceof TransportStop) { originObjectName = ((TransportStop) object).toStringEn(); } + if (object instanceof WptPt) { + altitude = ((WptPt) object).ele; + } } FavoritePointEditor favoritePointEditor = getFavoritePointEditor(); if (favoritePointEditor != null) { - favoritePointEditor.add(getLatLon(), title, getStreetStr(), originObjectName); + favoritePointEditor.add(getLatLon(), title, getStreetStr(), originObjectName, altitude, timestamp); } } }); @@ -1074,7 +1079,8 @@ public class MapContextMenu extends MenuTitleController implements StateChangedL for (OsmandMapLayer layer : mapActivity.getMapView().getLayers()) { layer.populateObjectContextMenu(latLon, getObject(), menuAdapter, mapActivity); } - mapActivity.getMapActions().addActionsToAdapter(configure ? 0 : latLon.getLatitude(), configure ? 0 : latLon.getLongitude(), menuAdapter, configure ? null : getObject(), configure); } + mapActivity.getMapActions().addActionsToAdapter(configure ? 0 : latLon.getLatitude(), configure ? 0 : latLon.getLongitude(), menuAdapter, configure ? null : getObject(), configure); + } return menuAdapter; } diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/FavoritePointEditor.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/FavoritePointEditor.java index 513cd707d5..4e011ea21a 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/FavoritePointEditor.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/FavoritePointEditor.java @@ -27,8 +27,8 @@ public class FavoritePointEditor extends PointEditor { return favorite; } - public void add(LatLon latLon, String title, String address, String originObjectName) { - MapActivity mapActivity = getMapActivity(); + public void add(LatLon latLon, String title, String address, String originObjectName, double altitude, long timestamp) { + final MapActivity mapActivity = getMapActivity(); if (latLon == null || mapActivity == null) { return; } @@ -37,15 +37,24 @@ public class FavoritePointEditor extends PointEditor { if (!Algorithms.isEmpty(lastCategory) && !app.getFavorites().groupExists(lastCategory)) { lastCategory = ""; } - favorite = new FavouritePoint(latLon.getLatitude(), latLon.getLongitude(), title, lastCategory); + favorite = new FavouritePoint(latLon.getLatitude(), latLon.getLongitude(), title, lastCategory, (float) altitude, timestamp); favorite.setDescription(""); favorite.setAddress(address.isEmpty() ? title : address); favorite.setOriginObjectName(originObjectName); - FavoritePointEditorFragmentNew.showInstance(mapActivity); + if (Double.isNaN(altitude) || altitude == 0) { + favorite.initAltitude(app, new Runnable() { + @Override + public void run() { + FavoritePointEditorFragmentNew.showInstance(mapActivity); + } + }); + } else { + FavoritePointEditorFragmentNew.showInstance(mapActivity); + } } - public void add(LatLon latLon, String title, String originObjectName, String categoryName, int categoryColor, boolean autoFill) { - MapActivity mapActivity = getMapActivity(); + public void add(LatLon latLon, String title, String originObjectName, String categoryName, int categoryColor, final boolean autoFill, double altitude, long timestamp) { + final MapActivity mapActivity = getMapActivity(); if (latLon == null || mapActivity == null) { return; } @@ -60,12 +69,20 @@ public class FavoritePointEditor extends PointEditor { categoryName = ""; } - favorite = new FavouritePoint(latLon.getLatitude(), latLon.getLongitude(), title, categoryName); + favorite = new FavouritePoint(latLon.getLatitude(), latLon.getLongitude(), title, categoryName, (float) altitude, timestamp); favorite.setDescription(""); favorite.setAddress(""); favorite.setOriginObjectName(originObjectName); - - FavoritePointEditorFragmentNew.showAutoFillInstance(mapActivity, autoFill); + if (Double.isNaN(altitude) || altitude == 0) { + favorite.initAltitude(app, new Runnable() { + @Override + public void run() { + FavoritePointEditorFragmentNew.showAutoFillInstance(mapActivity, autoFill); + } + }); + } else { + FavoritePointEditorFragmentNew.showAutoFillInstance(mapActivity, autoFill); + } } public void edit(FavouritePoint favorite) { diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/FavoritePointEditorFragment.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/FavoritePointEditorFragment.java index fe05bf4296..e50b1fe724 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/FavoritePointEditorFragment.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/FavoritePointEditorFragment.java @@ -190,7 +190,7 @@ public class FavoritePointEditorFragment extends PointEditorFragment { final FavouritePoint favorite = getFavorite(); if (favorite != null) { final FavouritePoint point = new FavouritePoint(favorite.getLatitude(), favorite.getLongitude(), - getNameTextValue(), getCategoryTextValue()); + getNameTextValue(), getCategoryTextValue(), favorite.getAltitude(), favorite.getTimestamp()); point.setDescription(getDescriptionTextValue()); point.setAddress(getAddressTextValue()); AlertDialog.Builder builder = FavouritesDbHelper.checkDuplicates(point, helper, getMapActivity()); @@ -198,7 +198,7 @@ public class FavoritePointEditorFragment extends PointEditorFragment { if (favorite.getName().equals(point.getName()) && favorite.getCategory().equals(point.getCategory()) && Algorithms.stringsEqual(favorite.getDescription(), point.getDescription()) && - Algorithms.stringsEqual(favorite.getAddress(),point.getAddress())) { + Algorithms.stringsEqual(favorite.getAddress(), point.getAddress())) { if (needDismiss) { dismiss(false); } @@ -209,7 +209,7 @@ public class FavoritePointEditorFragment extends PointEditorFragment { builder.setPositiveButton(R.string.shared_string_ok, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { - doSave(favorite, point.getName(), point.getCategory(), point.getDescription(),point.getAddress(), needDismiss); + doSave(favorite, point.getName(), point.getCategory(), point.getDescription(), point.getAddress(), needDismiss); } }); builder.create().show(); @@ -225,9 +225,9 @@ public class FavoritePointEditorFragment extends PointEditorFragment { FavoritePointEditor editor = getFavoritePointEditor(); if (editor != null && helper != null) { if (editor.isNew()) { - doAddFavorite(name, category, description,address); + doAddFavorite(name, category, description, address); } else { - helper.editFavouriteName(favorite, name, category, description,address); + helper.editFavouriteName(favorite, name, category, description, address); } } MapActivity mapActivity = getMapActivity(); diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/FavoritePointEditorFragmentNew.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/FavoritePointEditorFragmentNew.java index 3e4093d253..7f175589cd 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/FavoritePointEditorFragmentNew.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/FavoritePointEditorFragmentNew.java @@ -242,7 +242,7 @@ public class FavoritePointEditorFragmentNew extends PointEditorFragmentNew { final FavouritePoint favorite = getFavorite(); if (favorite != null) { final FavouritePoint point = new FavouritePoint(favorite.getLatitude(), favorite.getLongitude(), - getNameTextValue(), getCategoryTextValue()); + getNameTextValue(), getCategoryTextValue(), favorite.getAltitude(), favorite.getTimestamp()); point.setDescription(isDescriptionAvailable() ? getDescriptionTextValue() : null); point.setAddress(isAddressAvailable() ? getAddressTextValue() : null); point.setColor(color); @@ -258,7 +258,7 @@ public class FavoritePointEditorFragmentNew extends PointEditorFragmentNew { final FavouritePoint favorite = getFavorite(); if (favorite != null) { final FavouritePoint point = new FavouritePoint(favorite.getLatitude(), favorite.getLongitude(), - getNameTextValue(), getCategoryTextValue()); + getNameTextValue(), getCategoryTextValue(), favorite.getAltitude(), favorite.getTimestamp()); point.setDescription(isDescriptionAvailable() ? getDescriptionTextValue() : null); point.setAddress(isAddressAvailable() ? getAddressTextValue() : null); point.setColor(color); @@ -302,7 +302,7 @@ public class FavoritePointEditorFragmentNew extends PointEditorFragmentNew { } private void doSave(FavouritePoint favorite, String name, String category, String description, String address, - @ColorInt int color, BackgroundType backgroundType, @DrawableRes int iconId, boolean needDismiss) { + @ColorInt int color, BackgroundType backgroundType, @DrawableRes int iconId, boolean needDismiss) { FavouritesDbHelper helper = getHelper(); FavoritePointEditor editor = getFavoritePointEditor(); if (editor != null && helper != null) { @@ -329,8 +329,8 @@ public class FavoritePointEditorFragmentNew extends PointEditorFragmentNew { } private void doEditFavorite(FavouritePoint favorite, String name, String category, String description, String address, - @ColorInt int color, BackgroundType backgroundType, @DrawableRes int iconId, - FavouritesDbHelper helper) { + @ColorInt int color, BackgroundType backgroundType, @DrawableRes int iconId, + FavouritesDbHelper helper) { OsmandApplication app = getMyApplication(); if (app != null) { app.getSettings().LAST_FAV_CATEGORY_ENTERED.set(category); @@ -342,7 +342,7 @@ public class FavoritePointEditorFragmentNew extends PointEditorFragmentNew { } private void doAddFavorite(String name, String category, String description, String address, @ColorInt int color, - BackgroundType backgroundType, @DrawableRes int iconId) { + BackgroundType backgroundType, @DrawableRes int iconId) { OsmandApplication app = getMyApplication(); FavouritesDbHelper helper = getHelper(); FavouritePoint favorite = getFavorite(); diff --git a/OsmAnd/src/net/osmand/plus/quickaction/actions/FavoriteAction.java b/OsmAnd/src/net/osmand/plus/quickaction/actions/FavoriteAction.java index fbe79b0681..faa72a16f6 100644 --- a/OsmAnd/src/net/osmand/plus/quickaction/actions/FavoriteAction.java +++ b/OsmAnd/src/net/osmand/plus/quickaction/actions/FavoriteAction.java @@ -119,7 +119,7 @@ public class FavoriteAction extends QuickAction { FavoritePointEditor favoritePointEditor = mapActivity.getContextMenu().getFavoritePointEditor(); if (favoritePointEditor != null) { favoritePointEditor.add(latLon, title, "", getParams().get(KEY_CATEGORY_NAME), - Integer.valueOf(getParams().get(KEY_CATEGORY_COLOR)), autoFill); + Integer.valueOf(getParams().get(KEY_CATEGORY_COLOR)), autoFill, 0, 0); } } From a702787f090151d64cb68d2a0549434175c97259 Mon Sep 17 00:00:00 2001 From: Skalii Date: Thu, 25 Feb 2021 03:49:52 +0200 Subject: [PATCH 2/4] some fixes --- .../src/net/osmand/data/FavouritePoint.java | 12 +++++++--- .../plus/importfiles/FavoritesImportTask.java | 6 ++++- .../osmand/plus/importfiles/ImportHelper.java | 14 ++---------- .../editors/FavoritePointEditor.java | 22 ++++++++----------- .../quickaction/actions/FavoriteAction.java | 2 +- 5 files changed, 26 insertions(+), 30 deletions(-) diff --git a/OsmAnd/src/net/osmand/data/FavouritePoint.java b/OsmAnd/src/net/osmand/data/FavouritePoint.java index 181c38d7f9..f4ab5d77b1 100644 --- a/OsmAnd/src/net/osmand/data/FavouritePoint.java +++ b/OsmAnd/src/net/osmand/data/FavouritePoint.java @@ -59,6 +59,7 @@ public class FavouritePoint implements Serializable, LocationPoint { name = ""; } this.name = name; + timestamp = System.currentTimeMillis(); initPersonalType(); } @@ -71,7 +72,7 @@ public class FavouritePoint implements Serializable, LocationPoint { } this.name = name; this.altitude = altitude; - this.timestamp = timestamp; + this.timestamp = timestamp != 0 ? timestamp : System.currentTimeMillis(); initPersonalType(); } @@ -102,6 +103,10 @@ public class FavouritePoint implements Serializable, LocationPoint { } } + public void initAltitude(final OsmandApplication app) { + initAltitude(app, null); + } + public void initAltitude(final OsmandApplication app, final Runnable callback) { app.getLocationProvider().getRouteSegment(new Location("", latitude, longitude), null, false, new ResultMatcher() { @@ -110,9 +115,10 @@ public class FavouritePoint implements Serializable, LocationPoint { if (routeDataObject != null) { routeDataObject.calculateHeightArray(new LatLon(latitude, longitude)); altitude = routeDataObject.heightByCurrentLocation; - } else { } - callback.run(); + if (callback != null) { + callback.run(); + } return true; } diff --git a/OsmAnd/src/net/osmand/plus/importfiles/FavoritesImportTask.java b/OsmAnd/src/net/osmand/plus/importfiles/FavoritesImportTask.java index fd37d049eb..67f7881eb5 100644 --- a/OsmAnd/src/net/osmand/plus/importfiles/FavoritesImportTask.java +++ b/OsmAnd/src/net/osmand/plus/importfiles/FavoritesImportTask.java @@ -24,7 +24,7 @@ class FavoritesImportTask extends BaseLoadAsyncTask { private boolean forceImportFavourites; public FavoritesImportTask(@NonNull FragmentActivity activity, @NonNull GPXFile gpxFile, - @NonNull String fileName, boolean forceImportFavourites) { + @NonNull String fileName, boolean forceImportFavourites) { super(activity); this.gpxFile = gpxFile; this.fileName = fileName; @@ -39,6 +39,10 @@ class FavoritesImportTask extends BaseLoadAsyncTask { for (FavouritePoint favourite : favourites) { favoritesHelper.deleteFavourite(favourite, false); favoritesHelper.addFavourite(favourite, false); + double alt = favourite.getAltitude(); + if (Double.isNaN(alt) || alt == 0) { + favourite.initAltitude(app); + } } favoritesHelper.sortAll(); favoritesHelper.saveCurrentPointsIntoFile(); diff --git a/OsmAnd/src/net/osmand/plus/importfiles/ImportHelper.java b/OsmAnd/src/net/osmand/plus/importfiles/ImportHelper.java index c4b78541de..f32089f9f6 100644 --- a/OsmAnd/src/net/osmand/plus/importfiles/ImportHelper.java +++ b/OsmAnd/src/net/osmand/plus/importfiles/ImportHelper.java @@ -687,7 +687,7 @@ public class ImportHelper { } else { fpCat = p.category; } - final FavouritePoint point = new FavouritePoint(p.lat, p.lon, p.name, fpCat, p.ele, p.time); + final FavouritePoint point = new FavouritePoint(p.lat, p.lon, p.name, fpCat, p.ele, 0); if (p.desc != null) { point.setDescription(p.desc); } @@ -698,17 +698,7 @@ public class ImportHelper { point.setIconIdFromName(app, iconName); } point.setBackgroundType(BackgroundType.getByTypeName(p.getBackgroundType(), DEFAULT_BACKGROUND_TYPE)); - if (Double.isNaN(p.ele) || p.ele == 0) { - point.initAltitude(app, new Runnable() { - - @Override - public void run() { - favourites.add(point); - } - }); - } else { - favourites.add(point); - } + favourites.add(point); } } return favourites; diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/FavoritePointEditor.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/FavoritePointEditor.java index 4e011ea21a..5c0b6f8b59 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/FavoritePointEditor.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/FavoritePointEditor.java @@ -37,7 +37,7 @@ public class FavoritePointEditor extends PointEditor { if (!Algorithms.isEmpty(lastCategory) && !app.getFavorites().groupExists(lastCategory)) { lastCategory = ""; } - favorite = new FavouritePoint(latLon.getLatitude(), latLon.getLongitude(), title, lastCategory, (float) altitude, timestamp); + favorite = new FavouritePoint(latLon.getLatitude(), latLon.getLongitude(), title, lastCategory, altitude, timestamp); favorite.setDescription(""); favorite.setAddress(address.isEmpty() ? title : address); favorite.setOriginObjectName(originObjectName); @@ -53,7 +53,7 @@ public class FavoritePointEditor extends PointEditor { } } - public void add(LatLon latLon, String title, String originObjectName, String categoryName, int categoryColor, final boolean autoFill, double altitude, long timestamp) { + public void add(LatLon latLon, String title, String originObjectName, String categoryName, int categoryColor, final boolean autoFill) { final MapActivity mapActivity = getMapActivity(); if (latLon == null || mapActivity == null) { return; @@ -69,20 +69,16 @@ public class FavoritePointEditor extends PointEditor { categoryName = ""; } - favorite = new FavouritePoint(latLon.getLatitude(), latLon.getLongitude(), title, categoryName, (float) altitude, timestamp); + favorite = new FavouritePoint(latLon.getLatitude(), latLon.getLongitude(), title, categoryName); favorite.setDescription(""); favorite.setAddress(""); favorite.setOriginObjectName(originObjectName); - if (Double.isNaN(altitude) || altitude == 0) { - favorite.initAltitude(app, new Runnable() { - @Override - public void run() { - FavoritePointEditorFragmentNew.showAutoFillInstance(mapActivity, autoFill); - } - }); - } else { - FavoritePointEditorFragmentNew.showAutoFillInstance(mapActivity, autoFill); - } + favorite.initAltitude(app, new Runnable() { + @Override + public void run() { + FavoritePointEditorFragmentNew.showAutoFillInstance(mapActivity, autoFill); + } + }); } public void edit(FavouritePoint favorite) { diff --git a/OsmAnd/src/net/osmand/plus/quickaction/actions/FavoriteAction.java b/OsmAnd/src/net/osmand/plus/quickaction/actions/FavoriteAction.java index faa72a16f6..fbe79b0681 100644 --- a/OsmAnd/src/net/osmand/plus/quickaction/actions/FavoriteAction.java +++ b/OsmAnd/src/net/osmand/plus/quickaction/actions/FavoriteAction.java @@ -119,7 +119,7 @@ public class FavoriteAction extends QuickAction { FavoritePointEditor favoritePointEditor = mapActivity.getContextMenu().getFavoritePointEditor(); if (favoritePointEditor != null) { favoritePointEditor.add(latLon, title, "", getParams().get(KEY_CATEGORY_NAME), - Integer.valueOf(getParams().get(KEY_CATEGORY_COLOR)), autoFill, 0, 0); + Integer.valueOf(getParams().get(KEY_CATEGORY_COLOR)), autoFill); } } From 066ee38de2c16e05099b856d0b914946f2fb1b1a Mon Sep 17 00:00:00 2001 From: Skalii Date: Thu, 25 Feb 2021 05:04:43 +0200 Subject: [PATCH 3/4] fix use a more universal method for adding altitude --- .../net/osmand/plus/FavouritesDbHelper.java | 6 ++++++ .../plus/importfiles/FavoritesImportTask.java | 4 ---- .../editors/FavoritePointEditor.java | 18 ++---------------- 3 files changed, 8 insertions(+), 20 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/FavouritesDbHelper.java b/OsmAnd/src/net/osmand/plus/FavouritesDbHelper.java index 992a0e42c6..2693d76a93 100644 --- a/OsmAnd/src/net/osmand/plus/FavouritesDbHelper.java +++ b/OsmAnd/src/net/osmand/plus/FavouritesDbHelper.java @@ -361,6 +361,9 @@ public class FavouritesDbHelper { } public boolean addFavourite(FavouritePoint p, boolean saveImmediately) { + if (p.getAltitude() == 0) { + p.initAltitude(context); + } if (p.getName().isEmpty() && flatGroups.containsKey(p.getCategory())) { return true; } @@ -543,6 +546,9 @@ public class FavouritesDbHelper { private boolean editFavourite(@NonNull FavouritePoint p, double lat, double lon, @Nullable String description) { cancelAddressRequest(p); + if (p.getLatitude() != lat && p.getLongitude() != lon) { + p.initAltitude(context); + } p.setLatitude(lat); p.setLongitude(lon); if (description != null) { diff --git a/OsmAnd/src/net/osmand/plus/importfiles/FavoritesImportTask.java b/OsmAnd/src/net/osmand/plus/importfiles/FavoritesImportTask.java index 67f7881eb5..b62de4923c 100644 --- a/OsmAnd/src/net/osmand/plus/importfiles/FavoritesImportTask.java +++ b/OsmAnd/src/net/osmand/plus/importfiles/FavoritesImportTask.java @@ -39,10 +39,6 @@ class FavoritesImportTask extends BaseLoadAsyncTask { for (FavouritePoint favourite : favourites) { favoritesHelper.deleteFavourite(favourite, false); favoritesHelper.addFavourite(favourite, false); - double alt = favourite.getAltitude(); - if (Double.isNaN(alt) || alt == 0) { - favourite.initAltitude(app); - } } favoritesHelper.sortAll(); favoritesHelper.saveCurrentPointsIntoFile(); diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/FavoritePointEditor.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/FavoritePointEditor.java index 5c0b6f8b59..26e83413be 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/FavoritePointEditor.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/FavoritePointEditor.java @@ -41,16 +41,7 @@ public class FavoritePointEditor extends PointEditor { favorite.setDescription(""); favorite.setAddress(address.isEmpty() ? title : address); favorite.setOriginObjectName(originObjectName); - if (Double.isNaN(altitude) || altitude == 0) { - favorite.initAltitude(app, new Runnable() { - @Override - public void run() { - FavoritePointEditorFragmentNew.showInstance(mapActivity); - } - }); - } else { - FavoritePointEditorFragmentNew.showInstance(mapActivity); - } + FavoritePointEditorFragmentNew.showInstance(mapActivity); } public void add(LatLon latLon, String title, String originObjectName, String categoryName, int categoryColor, final boolean autoFill) { @@ -73,12 +64,7 @@ public class FavoritePointEditor extends PointEditor { favorite.setDescription(""); favorite.setAddress(""); favorite.setOriginObjectName(originObjectName); - favorite.initAltitude(app, new Runnable() { - @Override - public void run() { - FavoritePointEditorFragmentNew.showAutoFillInstance(mapActivity, autoFill); - } - }); + FavoritePointEditorFragmentNew.showAutoFillInstance(mapActivity, autoFill); } public void edit(FavouritePoint favorite) { From 0d4765142afc949b9a27e01525e82be347bc758a Mon Sep 17 00:00:00 2001 From: Skalii Date: Thu, 25 Feb 2021 05:22:09 +0200 Subject: [PATCH 4/4] rollback some changes; small fixes; --- .../src/net/osmand/data/FavouritePoint.java | 41 ++++++++++--------- .../net/osmand/plus/FavouritesDbHelper.java | 6 +-- .../osmand/plus/importfiles/ImportHelper.java | 4 +- .../editors/FavoritePointEditor.java | 6 +-- 4 files changed, 29 insertions(+), 28 deletions(-) diff --git a/OsmAnd/src/net/osmand/data/FavouritePoint.java b/OsmAnd/src/net/osmand/data/FavouritePoint.java index f4ab5d77b1..f87083363f 100644 --- a/OsmAnd/src/net/osmand/data/FavouritePoint.java +++ b/OsmAnd/src/net/osmand/data/FavouritePoint.java @@ -103,30 +103,33 @@ public class FavouritePoint implements Serializable, LocationPoint { } } - public void initAltitude(final OsmandApplication app) { + public void initAltitude(OsmandApplication app) { initAltitude(app, null); } - public void initAltitude(final OsmandApplication app, final Runnable callback) { - app.getLocationProvider().getRouteSegment(new Location("", latitude, longitude), null, false, new ResultMatcher() { + public void initAltitude(OsmandApplication app, final Runnable callback) { + Location location = new Location("", latitude, longitude); + app.getLocationProvider().getRouteSegment(location, null, false, + new ResultMatcher() { - @Override - public boolean publish(RouteDataObject routeDataObject) { - if (routeDataObject != null) { - routeDataObject.calculateHeightArray(new LatLon(latitude, longitude)); - altitude = routeDataObject.heightByCurrentLocation; - } - if (callback != null) { - callback.run(); - } - return true; - } + @Override + public boolean publish(RouteDataObject routeDataObject) { + if (routeDataObject != null) { + LatLon latLon = new LatLon(latitude, longitude); + routeDataObject.calculateHeightArray(latLon); + altitude = routeDataObject.heightByCurrentLocation; + } + if (callback != null) { + callback.run(); + } + return true; + } - @Override - public boolean isCancelled() { - return false; - } - }); + @Override + public boolean isCancelled() { + return false; + } + }); } public SpecialPointType getSpecialPointType() { diff --git a/OsmAnd/src/net/osmand/plus/FavouritesDbHelper.java b/OsmAnd/src/net/osmand/plus/FavouritesDbHelper.java index 2693d76a93..9fffc074c2 100644 --- a/OsmAnd/src/net/osmand/plus/FavouritesDbHelper.java +++ b/OsmAnd/src/net/osmand/plus/FavouritesDbHelper.java @@ -361,7 +361,7 @@ public class FavouritesDbHelper { } public boolean addFavourite(FavouritePoint p, boolean saveImmediately) { - if (p.getAltitude() == 0) { + if (Double.isNaN(p.getAltitude()) || p.getAltitude() == 0) { p.initAltitude(context); } if (p.getName().isEmpty() && flatGroups.containsKey(p.getCategory())) { @@ -546,11 +546,9 @@ public class FavouritesDbHelper { private boolean editFavourite(@NonNull FavouritePoint p, double lat, double lon, @Nullable String description) { cancelAddressRequest(p); - if (p.getLatitude() != lat && p.getLongitude() != lon) { - p.initAltitude(context); - } p.setLatitude(lat); p.setLongitude(lon); + p.initAltitude(context); if (description != null) { p.setDescription(description); } diff --git a/OsmAnd/src/net/osmand/plus/importfiles/ImportHelper.java b/OsmAnd/src/net/osmand/plus/importfiles/ImportHelper.java index f32089f9f6..3f5510bb4c 100644 --- a/OsmAnd/src/net/osmand/plus/importfiles/ImportHelper.java +++ b/OsmAnd/src/net/osmand/plus/importfiles/ImportHelper.java @@ -671,7 +671,7 @@ public class ImportHelper { } public static List asFavourites(OsmandApplication app, List wptPts, String fileName, boolean forceImportFavourites) { - final List favourites = new ArrayList<>(); + List favourites = new ArrayList<>(); for (WptPt p : wptPts) { if (Algorithms.isEmpty(p.name)) { p.name = app.getResources().getString(R.string.shared_string_waypoint); @@ -687,7 +687,7 @@ public class ImportHelper { } else { fpCat = p.category; } - final FavouritePoint point = new FavouritePoint(p.lat, p.lon, p.name, fpCat, p.ele, 0); + FavouritePoint point = new FavouritePoint(p.lat, p.lon, p.name, fpCat, p.ele, 0); if (p.desc != null) { point.setDescription(p.desc); } diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/FavoritePointEditor.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/FavoritePointEditor.java index 26e83413be..2d2836234c 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/FavoritePointEditor.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/editors/FavoritePointEditor.java @@ -28,7 +28,7 @@ public class FavoritePointEditor extends PointEditor { } public void add(LatLon latLon, String title, String address, String originObjectName, double altitude, long timestamp) { - final MapActivity mapActivity = getMapActivity(); + MapActivity mapActivity = getMapActivity(); if (latLon == null || mapActivity == null) { return; } @@ -44,8 +44,8 @@ public class FavoritePointEditor extends PointEditor { FavoritePointEditorFragmentNew.showInstance(mapActivity); } - public void add(LatLon latLon, String title, String originObjectName, String categoryName, int categoryColor, final boolean autoFill) { - final MapActivity mapActivity = getMapActivity(); + public void add(LatLon latLon, String title, String originObjectName, String categoryName, int categoryColor, boolean autoFill) { + MapActivity mapActivity = getMapActivity(); if (latLon == null || mapActivity == null) { return; }