diff --git a/OsmAnd/res/layout/route_info_header.xml b/OsmAnd/res/layout/route_info_header.xml index 181a9a7da5..3379102afa 100644 --- a/OsmAnd/res/layout/route_info_header.xml +++ b/OsmAnd/res/layout/route_info_header.xml @@ -12,19 +12,10 @@ android:background="?attr/bg_color" android:paddingTop="8dp"> - - @@ -179,49 +170,6 @@ android:orientation="horizontal" android:paddingLeft="16dp"> - - - - - - - - - - - - - - + + + + + + + + + + + + + + diff --git a/OsmAnd/src/net/osmand/plus/activities/ShowRouteInfoDialogFragment.java b/OsmAnd/src/net/osmand/plus/activities/ShowRouteInfoDialogFragment.java index 21d6db3bed..1338dbab0e 100644 --- a/OsmAnd/src/net/osmand/plus/activities/ShowRouteInfoDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/activities/ShowRouteInfoDialogFragment.java @@ -54,6 +54,8 @@ import java.io.FileWriter; import java.io.IOException; import java.util.List; +import static net.osmand.binary.RouteDataObject.HEIGHT_UNDEFINED; + public class ShowRouteInfoDialogFragment extends DialogFragment { public static final String TAG = "ShowRouteInfoDialogFragment"; @@ -63,6 +65,7 @@ public class ShowRouteInfoDialogFragment extends DialogFragment { private ListView listView; private RouteInfoAdapter adapter; private GPXFile gpx; + private boolean hasHeights; public ShowRouteInfoDialogFragment() { } @@ -163,7 +166,7 @@ public class ShowRouteInfoDialogFragment extends DialogFragment { }); makeGpx(); - if (!gpx.isEmpty()) { + if (hasHeights) { View headerView = inflater.inflate(R.layout.route_info_header, null); buildHeader(headerView); listView.addHeaderView(headerView); @@ -173,13 +176,17 @@ public class ShowRouteInfoDialogFragment extends DialogFragment { } private void makeGpx() { - double lastHeight = -1; + double lastHeight = HEIGHT_UNDEFINED; gpx = new GPXFile(); List route = helper.getRoute().getLeftRoute(); if (route != null) { Track track = new Track(); for (RouteSegmentResult res : route) { TrkSegment seg = new TrkSegment(); + float[] vls = res.getObject().calculateHeightArray(); + if (!hasHeights && vls != null && vls.length > 0) { + hasHeights = true; + } int inc = res.getStartPointIndex() < res.getEndPointIndex() ? 1 : -1; int indexnext = res.getStartPointIndex(); for (int index = res.getStartPointIndex(); index != res.getEndPointIndex(); ) { @@ -189,12 +196,11 @@ public class ShowRouteInfoDialogFragment extends DialogFragment { WptPt point = new WptPt(); point.lat = l.getLatitude(); point.lon = l.getLongitude(); - float[] vls = res.getObject().calculateHeightArray(); if (vls != null && index * 2 + 1 < vls.length) { point.ele = vls[2 * index + 1]; //point.desc = (res.getObject().getId() >> (BinaryInspector.SHIFT_ID )) + " " + index; lastHeight = vls[2 * index + 1]; - } else if (lastHeight > 0) { + } else if (lastHeight != HEIGHT_UNDEFINED) { point.ele = lastHeight; } seg.points.add(point); diff --git a/OsmAnd/src/net/osmand/plus/routing/RouteCalculationResult.java b/OsmAnd/src/net/osmand/plus/routing/RouteCalculationResult.java index 2bd0b1c8f9..60868ed80b 100644 --- a/OsmAnd/src/net/osmand/plus/routing/RouteCalculationResult.java +++ b/OsmAnd/src/net/osmand/plus/routing/RouteCalculationResult.java @@ -18,6 +18,8 @@ import net.osmand.util.Algorithms; import net.osmand.util.MapUtils; import android.content.Context; +import static net.osmand.binary.RouteDataObject.HEIGHT_UNDEFINED; + public class RouteCalculationResult { private static double distanceClosestToIntermediate = 400; // could not be null and immodifiable! @@ -229,9 +231,11 @@ public class RouteCalculationResult { List alarms, OsmandApplication ctx) { float prevDirectionTime = 0; float prevDirectionDistance = 0; + double lastHeight = HEIGHT_UNDEFINED; List segmentsToPopulate = new ArrayList(); for (int routeInd = 0; routeInd < list.size(); routeInd++) { RouteSegmentResult s = list.get(routeInd); + float[] vls = s.getObject().calculateHeightArray(); boolean plus = s.getStartPointIndex() < s.getEndPointIndex(); int i = s.getStartPointIndex(); int prevLocationSize = locations.size(); @@ -243,6 +247,12 @@ public class RouteCalculationResult { if (i == s.getEndPointIndex() && routeInd != list.size() - 1) { break; } + if (vls != null && i * 2 + 1 < vls.length) { + n.setAltitude(vls[2 * i + 1]); + lastHeight = vls[2 * i + 1]; + } else if (lastHeight != HEIGHT_UNDEFINED) { + n.setAltitude(lastHeight); + } locations.add(n); attachAlarmInfo(alarms, s, i, locations.size()); segmentsToPopulate.add(s);