Merge remote-tracking branch 'origin/master'

This commit is contained in:
Weblate 2017-03-20 09:03:22 +01:00
commit c9369560ba
3 changed files with 80 additions and 54 deletions

View file

@ -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<Elevation> elevationData;
public List<Speed> 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)) {

View file

@ -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<ILineDataSet> 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<ILineDataSet> 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<ILineDataSet>() {
@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<ILineDataSet>() {
@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<GPXDataSetType[]> 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) {

View file

@ -812,7 +812,7 @@ public class TrackSegmentFragment extends OsmAndListFragment {
List<GPXTabItemType> 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()) {