From 8942cc81a97992d14b8bad82f5e255745b69f3c0 Mon Sep 17 00:00:00 2001 From: Alexey Kulish Date: Mon, 20 Mar 2017 11:02:40 +0300 Subject: [PATCH] Fix #3563 --- OsmAnd/src/net/osmand/plus/GPXUtilities.java | 21 ++++ .../other/TrackDetailsMenu.java | 111 +++++++++--------- .../plus/myplaces/TrackSegmentFragment.java | 2 +- 3 files changed, 80 insertions(+), 54 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/GPXUtilities.java b/OsmAnd/src/net/osmand/plus/GPXUtilities.java index c07d4963c0..899e6ab536 100644 --- a/OsmAnd/src/net/osmand/plus/GPXUtilities.java +++ b/OsmAnd/src/net/osmand/plus/GPXUtilities.java @@ -286,6 +286,11 @@ public class GPXUtilities { public WptPt locationStart; public WptPt locationEnd; + public double left = 0; + public double right = 0; + public double top = 0; + public double bottom = 0; + public boolean isTimeSpecified() { return startTime != Long.MAX_VALUE && startTime != 0; } @@ -298,6 +303,10 @@ public class GPXUtilities { return maxElevation != -100; } + public boolean isBoundsCalculated() { + return left !=0 && right != 0 && top != 0 && bottom != 0; + } + public List elevationData; public List speedData; @@ -359,6 +368,18 @@ public class GPXUtilities { endTime = Math.max(endTime, time); } + if (left == 0 && right == 0) { + left = point.getLongitude(); + right = point.getLongitude(); + top = point.getLatitude(); + bottom = point.getLatitude(); + } else { + left = Math.min(left, point.getLongitude()); + right = Math.max(right, point.getLongitude()); + top = Math.max(top, point.getLatitude()); + bottom = Math.min(bottom, point.getLatitude()); + } + double elevation = point.ele; Elevation elevation1 = new Elevation(); if (!Double.isNaN(elevation)) { diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/other/TrackDetailsMenu.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/other/TrackDetailsMenu.java index 9fb3d207ff..08d694bbab 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/other/TrackDetailsMenu.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/other/TrackDetailsMenu.java @@ -305,6 +305,16 @@ public class TrackDetailsMenu { } private void updateView(final View parentView) { + GPXTrackAnalysis analysis = gpxItem.analysis; + if (analysis == null || gpxItem.chartTypes == null) { + parentView.setVisibility(View.GONE); + if (analysis != null && analysis.isBoundsCalculated()) { + mapActivity.getMapView() + .fitRectToMap(analysis.left, analysis.right, analysis.top, analysis.bottom, 0, 0, 0); + } + return; + } + final LineChart chart = (LineChart) parentView.findViewById(R.id.chart); chart.setOnChartValueSelectedListener(new OnChartValueSelectedListener() { @Override @@ -380,71 +390,66 @@ public class TrackDetailsMenu { final OsmandApplication app = mapActivity.getMyApplication(); final IconsCache ic = app.getIconsCache(); - GPXTrackAnalysis analysis = gpxItem.analysis; - if (analysis != null) { - GpxUiHelper.setupGPXChart(app, chart, 4); - if (gpxItem.chartTypes != null) { - List dataSets = new ArrayList<>(); - if (gpxItem.chartTypes != null && gpxItem.chartTypes.length > 0) { - for (int i = 0; i < gpxItem.chartTypes.length; i++) { - OrderedLineDataSet dataSet = null; - switch (gpxItem.chartTypes[i]) { - case ALTITUDE: - dataSet = GpxUiHelper.createGPXElevationDataSet(app, chart, analysis, - gpxItem.chartAxisType, false, true); - break; - case SPEED: - dataSet = GpxUiHelper.createGPXSpeedDataSet(app, chart, analysis, - gpxItem.chartAxisType, gpxItem.chartTypes.length > 1, true); - break; - case SLOPE: - dataSet = GpxUiHelper.createGPXSlopeDataSet(app, chart, analysis, - gpxItem.chartAxisType, null, gpxItem.chartTypes.length > 1, true); - break; - } - if (dataSet != null) { - dataSets.add(dataSet); - } - } + GpxUiHelper.setupGPXChart(app, chart, 4); + + List dataSets = new ArrayList<>(); + if (gpxItem.chartTypes != null && gpxItem.chartTypes.length > 0) { + for (int i = 0; i < gpxItem.chartTypes.length; i++) { + OrderedLineDataSet dataSet = null; + switch (gpxItem.chartTypes[i]) { + case ALTITUDE: + dataSet = GpxUiHelper.createGPXElevationDataSet(app, chart, analysis, + gpxItem.chartAxisType, false, true); + break; + case SPEED: + dataSet = GpxUiHelper.createGPXSpeedDataSet(app, chart, analysis, + gpxItem.chartAxisType, gpxItem.chartTypes.length > 1, true); + break; + case SLOPE: + dataSet = GpxUiHelper.createGPXSlopeDataSet(app, chart, analysis, + gpxItem.chartAxisType, null, gpxItem.chartTypes.length > 1, true); + break; + } + if (dataSet != null) { + dataSets.add(dataSet); } - - Collections.sort(dataSets, new Comparator() { - @Override - public int compare(ILineDataSet ds1, ILineDataSet ds2) { - OrderedLineDataSet dataSet1 = (OrderedLineDataSet) ds1; - OrderedLineDataSet dataSet2 = (OrderedLineDataSet) ds2; - return dataSet1.getPriority() > dataSet2.getPriority() ? -1 : (dataSet1.getPriority() == dataSet2.getPriority() ? 0 : 1); - } - }); - chart.setData(new LineData(dataSets)); - updateChart(chart); } } + Collections.sort(dataSets, new Comparator() { + @Override + public int compare(ILineDataSet ds1, ILineDataSet ds2) { + OrderedLineDataSet dataSet1 = (OrderedLineDataSet) ds1; + OrderedLineDataSet dataSet2 = (OrderedLineDataSet) ds2; + return dataSet1.getPriority() > dataSet2.getPriority() ? -1 : (dataSet1.getPriority() == dataSet2.getPriority() ? 0 : 1); + } + }); + chart.setData(new LineData(dataSets)); + updateChart(chart); + View yAxis = parentView.findViewById(R.id.y_axis); ImageView yAxisIcon = (ImageView) parentView.findViewById(R.id.y_axis_icon); TextView yAxisTitle = (TextView) parentView.findViewById(R.id.y_axis_title); View yAxisArrow = parentView.findViewById(R.id.y_axis_arrow); final List availableTypes = new ArrayList<>(); boolean hasSlopeChart = false; - if (analysis != null) { - if (analysis.hasElevationData) { - availableTypes.add(new GPXDataSetType[] { GPXDataSetType.ALTITUDE }); - if (gpxItem.chartAxisType != GPXDataSetAxisType.TIME) { - availableTypes.add(new GPXDataSetType[]{GPXDataSetType.SLOPE}); - } - } - if (analysis.hasSpeedData) { - availableTypes.add(new GPXDataSetType[] { GPXDataSetType.SPEED }); - } - if (analysis.hasElevationData && gpxItem.chartAxisType != GPXDataSetAxisType.TIME) { - availableTypes.add(new GPXDataSetType[] { GPXDataSetType.ALTITUDE, GPXDataSetType.SLOPE }); - } - if (analysis.hasElevationData && analysis.hasSpeedData) { - availableTypes.add(new GPXDataSetType[] { GPXDataSetType.ALTITUDE, GPXDataSetType.SPEED }); + if (analysis.hasElevationData) { + availableTypes.add(new GPXDataSetType[] { GPXDataSetType.ALTITUDE }); + if (gpxItem.chartAxisType != GPXDataSetAxisType.TIME) { + availableTypes.add(new GPXDataSetType[]{GPXDataSetType.SLOPE}); } } + if (analysis.hasSpeedData) { + availableTypes.add(new GPXDataSetType[] { GPXDataSetType.SPEED }); + } + if (analysis.hasElevationData && gpxItem.chartAxisType != GPXDataSetAxisType.TIME) { + availableTypes.add(new GPXDataSetType[] { GPXDataSetType.ALTITUDE, GPXDataSetType.SLOPE }); + } + if (analysis.hasElevationData && analysis.hasSpeedData) { + availableTypes.add(new GPXDataSetType[] { GPXDataSetType.ALTITUDE, GPXDataSetType.SPEED }); + } + for (GPXDataSetType t : gpxItem.chartTypes) { if (t == GPXDataSetType.SLOPE) { hasSlopeChart = true; @@ -494,7 +499,7 @@ public class TrackDetailsMenu { xAxisIcon.setImageDrawable(ic.getThemedIcon(R.drawable.ic_action_marker_dark)); xAxisTitle.setText(app.getString(R.string.distance)); } - if (analysis != null && analysis.isTimeSpecified() && !hasSlopeChart) { + if (analysis.isTimeSpecified() && !hasSlopeChart) { xAxis.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { diff --git a/OsmAnd/src/net/osmand/plus/myplaces/TrackSegmentFragment.java b/OsmAnd/src/net/osmand/plus/myplaces/TrackSegmentFragment.java index 94d54786b4..0dfcbaa587 100644 --- a/OsmAnd/src/net/osmand/plus/myplaces/TrackSegmentFragment.java +++ b/OsmAnd/src/net/osmand/plus/myplaces/TrackSegmentFragment.java @@ -812,7 +812,7 @@ public class TrackSegmentFragment extends OsmAndListFragment { List tabTypeList = new ArrayList<>(); tabTypeList.add(GPXTabItemType.GPX_TAB_ITEM_GENERAL); if (gpxItem != null && gpxItem.analysis != null) { - if (gpxItem.analysis.elevationData != null) { + if (gpxItem.analysis.hasElevationData) { tabTypeList.add(GPXTabItemType.GPX_TAB_ITEM_ALTITUDE); } if (gpxItem.analysis.isSpeedSpecified()) {