Fix route chart
This commit is contained in:
parent
3de9e6057d
commit
b5dce44d01
3 changed files with 58 additions and 44 deletions
|
@ -1374,15 +1374,4 @@ public class GPXUtilities {
|
||||||
// set data
|
// set data
|
||||||
mChart.setData(data);
|
mChart.setData(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static TrkSegment buildTrkSegment(float[] heightArray) {
|
|
||||||
TrkSegment segment = new TrkSegment();
|
|
||||||
if (heightArray.length > 0) {
|
|
||||||
for (int i = 0; i < heightArray.length / 2; i++) {
|
|
||||||
WptPt p = new WptPt(0, 0, 0, heightArray[i * 2 + 1], 0, 0);
|
|
||||||
segment.points.add(p);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return segment;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,12 +28,14 @@ import com.github.mikephil.charting.charts.LineChart;
|
||||||
import com.github.mikephil.charting.utils.Utils;
|
import com.github.mikephil.charting.utils.Utils;
|
||||||
|
|
||||||
import net.osmand.Location;
|
import net.osmand.Location;
|
||||||
|
import net.osmand.data.LatLon;
|
||||||
import net.osmand.data.PointDescription;
|
import net.osmand.data.PointDescription;
|
||||||
import net.osmand.plus.GPXUtilities;
|
import net.osmand.plus.GPXUtilities;
|
||||||
import net.osmand.plus.GPXUtilities.Elevation;
|
|
||||||
import net.osmand.plus.GPXUtilities.GPXFile;
|
import net.osmand.plus.GPXUtilities.GPXFile;
|
||||||
import net.osmand.plus.GPXUtilities.GPXTrackAnalysis;
|
import net.osmand.plus.GPXUtilities.GPXTrackAnalysis;
|
||||||
|
import net.osmand.plus.GPXUtilities.Track;
|
||||||
import net.osmand.plus.GPXUtilities.TrkSegment;
|
import net.osmand.plus.GPXUtilities.TrkSegment;
|
||||||
|
import net.osmand.plus.GPXUtilities.WptPt;
|
||||||
import net.osmand.plus.IconsCache;
|
import net.osmand.plus.IconsCache;
|
||||||
import net.osmand.plus.OsmAndFormatter;
|
import net.osmand.plus.OsmAndFormatter;
|
||||||
import net.osmand.plus.OsmandApplication;
|
import net.osmand.plus.OsmandApplication;
|
||||||
|
@ -50,7 +52,6 @@ import java.io.File;
|
||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
import java.io.FileWriter;
|
import java.io.FileWriter;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class ShowRouteInfoDialogFragment extends DialogFragment {
|
public class ShowRouteInfoDialogFragment extends DialogFragment {
|
||||||
|
@ -61,6 +62,7 @@ public class ShowRouteInfoDialogFragment extends DialogFragment {
|
||||||
private View view;
|
private View view;
|
||||||
private ListView listView;
|
private ListView listView;
|
||||||
private RouteInfoAdapter adapter;
|
private RouteInfoAdapter adapter;
|
||||||
|
private GPXFile gpx;
|
||||||
|
|
||||||
public ShowRouteInfoDialogFragment() {
|
public ShowRouteInfoDialogFragment() {
|
||||||
}
|
}
|
||||||
|
@ -160,46 +162,57 @@ public class ShowRouteInfoDialogFragment extends DialogFragment {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
makeGpx();
|
||||||
|
if (!gpx.isEmpty()) {
|
||||||
View headerView = inflater.inflate(R.layout.route_info_header, null);
|
View headerView = inflater.inflate(R.layout.route_info_header, null);
|
||||||
if (buildHeader(headerView)) {
|
buildHeader(headerView);
|
||||||
listView.addHeaderView(headerView);
|
listView.addHeaderView(headerView);
|
||||||
}
|
}
|
||||||
|
|
||||||
return view;
|
return view;
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean buildHeader(View headerView) {
|
private void makeGpx() {
|
||||||
|
double lastHeight = -1;
|
||||||
|
gpx = new GPXFile();
|
||||||
|
Track track = new Track();
|
||||||
|
List<RouteSegmentResult> route = helper.getRoute().getLeftRoute();
|
||||||
|
for (RouteSegmentResult res : route) {
|
||||||
|
TrkSegment seg = new TrkSegment();
|
||||||
|
int inc = res.getStartPointIndex() < res.getEndPointIndex() ? 1 : -1;
|
||||||
|
int indexnext = res.getStartPointIndex();
|
||||||
|
for (int index = res.getStartPointIndex() ; index != res.getEndPointIndex(); ) {
|
||||||
|
index = indexnext;
|
||||||
|
indexnext += inc;
|
||||||
|
LatLon l = res.getPoint(index);
|
||||||
|
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) {
|
||||||
|
point.ele = lastHeight;
|
||||||
|
}
|
||||||
|
seg.points.add(point);
|
||||||
|
}
|
||||||
|
track.segments.add(seg);
|
||||||
|
}
|
||||||
|
gpx.tracks.add(track);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void buildHeader(View headerView) {
|
||||||
OsmandApplication app = getMyApplication();
|
OsmandApplication app = getMyApplication();
|
||||||
OsmandSettings.MetricsConstants mc = app.getSettings().METRIC_SYSTEM.get();
|
OsmandSettings.MetricsConstants mc = app.getSettings().METRIC_SYSTEM.get();
|
||||||
final boolean useFeet = (mc == OsmandSettings.MetricsConstants.MILES_AND_FEET) || (mc == OsmandSettings.MetricsConstants.MILES_AND_YARDS);
|
final boolean useFeet = (mc == OsmandSettings.MetricsConstants.MILES_AND_FEET) || (mc == OsmandSettings.MetricsConstants.MILES_AND_YARDS);
|
||||||
LineChart mChart = (LineChart) headerView.findViewById(R.id.chart);
|
LineChart mChart = (LineChart) headerView.findViewById(R.id.chart);
|
||||||
GPXUtilities.setupGPXChart(mChart, useFeet);
|
GPXUtilities.setupGPXChart(mChart, useFeet);
|
||||||
List<RouteSegmentResult> route = helper.getRoute().getOriginalRoute();
|
|
||||||
List<float[]> heightList = new ArrayList<>();
|
GPXTrackAnalysis analysis = gpx.getAnalysis(0);
|
||||||
int count = 0;
|
|
||||||
for (RouteSegmentResult s : route) {
|
|
||||||
float[] arr = s.getHeightValues();
|
|
||||||
if (arr.length > 0) {
|
|
||||||
heightList.add(arr);
|
|
||||||
count += arr.length;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
float[] heightArray = new float[count];
|
|
||||||
int i = 0;
|
|
||||||
for (float[] arr : heightList) {
|
|
||||||
System.arraycopy(arr, 0, heightArray, i, arr.length);
|
|
||||||
i += arr.length;
|
|
||||||
}
|
|
||||||
TrkSegment seg = GPXUtilities.buildTrkSegment(heightArray);
|
|
||||||
GPXTrackAnalysis analysis = GPXTrackAnalysis.segment(0, seg);
|
|
||||||
i = 0;
|
|
||||||
for (Elevation e : analysis.elevationData) {
|
|
||||||
e.distance = heightArray[i * 2];
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
analysis.totalDistance = helper.getLeftDistance();
|
|
||||||
GPXUtilities.setGPXChartData(mChart, analysis, Utils.getSDKInt() >= 18
|
GPXUtilities.setGPXChartData(mChart, analysis, Utils.getSDKInt() >= 18
|
||||||
? R.drawable.line_chart_fade_orange : R.color.osmand_orange, useFeet);
|
? R.drawable.line_chart_fade_blue : R.color.gpx_time_span_color, useFeet);
|
||||||
|
|
||||||
((TextView) headerView.findViewById(R.id.average_text))
|
((TextView) headerView.findViewById(R.id.average_text))
|
||||||
.setText(OsmAndFormatter.getFormattedAlt(analysis.avgElevation, app));
|
.setText(OsmAndFormatter.getFormattedAlt(analysis.avgElevation, app));
|
||||||
|
@ -222,8 +235,6 @@ public class ShowRouteInfoDialogFragment extends DialogFragment {
|
||||||
.setImageDrawable(app.getIconsCache().getThemedIcon(R.drawable.ic_action_altitude_descent));
|
.setImageDrawable(app.getIconsCache().getThemedIcon(R.drawable.ic_action_altitude_descent));
|
||||||
((ImageView) headerView.findViewById(R.id.ascent_icon))
|
((ImageView) headerView.findViewById(R.id.ascent_icon))
|
||||||
.setImageDrawable(app.getIconsCache().getThemedIcon(R.drawable.ic_action_altitude_ascent));
|
.setImageDrawable(app.getIconsCache().getThemedIcon(R.drawable.ic_action_altitude_ascent));
|
||||||
|
|
||||||
return count > 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void buildMenuButtons() {
|
private void buildMenuButtons() {
|
||||||
|
|
|
@ -194,6 +194,20 @@ public class RouteCalculationResult {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<RouteSegmentResult> getLeftRoute() {
|
||||||
|
int cs = currentRoute > 0 ? currentRoute - 1 : 0;
|
||||||
|
if(cs >= segments.size()) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
List<RouteSegmentResult> list = new ArrayList<RouteSegmentResult>();
|
||||||
|
for (int i = cs; i < segments.size(); i++) {
|
||||||
|
if (i == 0 || segments.get(i - 1) != segments.get(i)) {
|
||||||
|
list.add(segments.get(i));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
public List<RouteSegmentResult> getOriginalRoute() {
|
public List<RouteSegmentResult> getOriginalRoute() {
|
||||||
if (segments.size() == 0) {
|
if (segments.size() == 0) {
|
||||||
return null;
|
return null;
|
||||||
|
|
Loading…
Reference in a new issue