Fix chart crash at route details
This commit is contained in:
parent
7a28768c50
commit
3d0d79136a
2 changed files with 63 additions and 49 deletions
|
@ -213,10 +213,12 @@ public class TrackDetailsMenu {
|
||||||
updateView(main);
|
updateView(main);
|
||||||
}
|
}
|
||||||
|
|
||||||
private TrkSegment getTrackSegment(LineChart chart) {
|
@Nullable
|
||||||
|
private TrkSegment getTrackSegment(@NonNull LineChart chart) {
|
||||||
TrkSegment segment = this.segment;
|
TrkSegment segment = this.segment;
|
||||||
if (segment == null) {
|
if (segment == null) {
|
||||||
List<ILineDataSet> ds = chart.getLineData().getDataSets();
|
LineData lineData = chart.getLineData();
|
||||||
|
List<ILineDataSet> ds = lineData != null ? lineData.getDataSets() : null;
|
||||||
GpxDisplayItem gpxItem = getGpxItem();
|
GpxDisplayItem gpxItem = getGpxItem();
|
||||||
if (ds != null && ds.size() > 0 && gpxItem != null) {
|
if (ds != null && ds.size() > 0 && gpxItem != null) {
|
||||||
for (GPXUtilities.Track t : gpxItem.group.getGpx().tracks) {
|
for (GPXUtilities.Track t : gpxItem.group.getGpx().tracks) {
|
||||||
|
@ -236,12 +238,17 @@ public class TrackDetailsMenu {
|
||||||
return segment;
|
return segment;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
private LatLon getLocationAtPos(LineChart chart, float pos) {
|
private LatLon getLocationAtPos(LineChart chart, float pos) {
|
||||||
LatLon latLon = null;
|
LatLon latLon = null;
|
||||||
List<ILineDataSet> ds = chart.getLineData().getDataSets();
|
LineData lineData = chart.getLineData();
|
||||||
|
List<ILineDataSet> ds = lineData != null ? lineData.getDataSets() : null;
|
||||||
GpxDisplayItem gpxItem = getGpxItem();
|
GpxDisplayItem gpxItem = getGpxItem();
|
||||||
if (ds != null && ds.size() > 0 && gpxItem != null) {
|
if (ds != null && ds.size() > 0 && gpxItem != null) {
|
||||||
TrkSegment segment = getTrackSegment(chart);
|
TrkSegment segment = getTrackSegment(chart);
|
||||||
|
if (segment == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
OrderedLineDataSet dataSet = (OrderedLineDataSet) ds.get(0);
|
OrderedLineDataSet dataSet = (OrderedLineDataSet) ds.get(0);
|
||||||
if (gpxItem.chartAxisType == GPXDataSetAxisType.TIME ||
|
if (gpxItem.chartAxisType == GPXDataSetAxisType.TIME ||
|
||||||
gpxItem.chartAxisType == GPXDataSetAxisType.TIMEOFDAY) {
|
gpxItem.chartAxisType == GPXDataSetAxisType.TIMEOFDAY) {
|
||||||
|
@ -295,52 +302,55 @@ public class TrackDetailsMenu {
|
||||||
private QuadRect getRect(LineChart chart, float startPos, float endPos) {
|
private QuadRect getRect(LineChart chart, float startPos, float endPos) {
|
||||||
double left = 0, right = 0;
|
double left = 0, right = 0;
|
||||||
double top = 0, bottom = 0;
|
double top = 0, bottom = 0;
|
||||||
List<ILineDataSet> ds = chart.getLineData().getDataSets();
|
LineData lineData = chart.getLineData();
|
||||||
|
List<ILineDataSet> ds = lineData != null ? lineData.getDataSets() : null;
|
||||||
GpxDisplayItem gpxItem = getGpxItem();
|
GpxDisplayItem gpxItem = getGpxItem();
|
||||||
if (ds != null && ds.size() > 0 && gpxItem != null) {
|
if (ds != null && ds.size() > 0 && gpxItem != null) {
|
||||||
TrkSegment segment = getTrackSegment(chart);
|
TrkSegment segment = getTrackSegment(chart);
|
||||||
OrderedLineDataSet dataSet = (OrderedLineDataSet) ds.get(0);
|
if (segment != null) {
|
||||||
if (gpxItem.chartAxisType == GPXDataSetAxisType.TIME || gpxItem.chartAxisType == GPXDataSetAxisType.TIMEOFDAY) {
|
OrderedLineDataSet dataSet = (OrderedLineDataSet) ds.get(0);
|
||||||
float startTime = startPos * 1000;
|
if (gpxItem.chartAxisType == GPXDataSetAxisType.TIME || gpxItem.chartAxisType == GPXDataSetAxisType.TIMEOFDAY) {
|
||||||
float endTime = endPos * 1000;
|
float startTime = startPos * 1000;
|
||||||
for (WptPt p : segment.points) {
|
float endTime = endPos * 1000;
|
||||||
if (p.time - gpxItem.analysis.startTime >= startTime && p.time - gpxItem.analysis.startTime <= endTime) {
|
for (WptPt p : segment.points) {
|
||||||
if (left == 0 && right == 0) {
|
if (p.time - gpxItem.analysis.startTime >= startTime && p.time - gpxItem.analysis.startTime <= endTime) {
|
||||||
left = p.getLongitude();
|
if (left == 0 && right == 0) {
|
||||||
right = p.getLongitude();
|
left = p.getLongitude();
|
||||||
top = p.getLatitude();
|
right = p.getLongitude();
|
||||||
bottom = p.getLatitude();
|
top = p.getLatitude();
|
||||||
} else {
|
bottom = p.getLatitude();
|
||||||
left = Math.min(left, p.getLongitude());
|
} else {
|
||||||
right = Math.max(right, p.getLongitude());
|
left = Math.min(left, p.getLongitude());
|
||||||
top = Math.max(top, p.getLatitude());
|
right = Math.max(right, p.getLongitude());
|
||||||
bottom = Math.min(bottom, p.getLatitude());
|
top = Math.max(top, p.getLatitude());
|
||||||
|
bottom = Math.min(bottom, p.getLatitude());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
} else {
|
float startDistance = startPos * dataSet.getDivX();
|
||||||
float startDistance = startPos * dataSet.getDivX();
|
float endDistance = endPos * dataSet.getDivX();
|
||||||
float endDistance = endPos * dataSet.getDivX();
|
double previousSplitDistance = 0;
|
||||||
double previousSplitDistance = 0;
|
for (int i = 0; i < segment.points.size(); i++) {
|
||||||
for (int i = 0; i < segment.points.size(); i++) {
|
WptPt currentPoint = segment.points.get(i);
|
||||||
WptPt currentPoint = segment.points.get(i);
|
if (i != 0) {
|
||||||
if (i != 0) {
|
WptPt previousPoint = segment.points.get(i - 1);
|
||||||
WptPt previousPoint = segment.points.get(i - 1);
|
if (currentPoint.distance < previousPoint.distance) {
|
||||||
if (currentPoint.distance < previousPoint.distance) {
|
previousSplitDistance += previousPoint.distance;
|
||||||
previousSplitDistance += previousPoint.distance;
|
}
|
||||||
}
|
}
|
||||||
}
|
if (previousSplitDistance + currentPoint.distance >= startDistance && previousSplitDistance + currentPoint.distance <= endDistance) {
|
||||||
if (previousSplitDistance + currentPoint.distance >= startDistance && previousSplitDistance + currentPoint.distance <= endDistance) {
|
if (left == 0 && right == 0) {
|
||||||
if (left == 0 && right == 0) {
|
left = currentPoint.getLongitude();
|
||||||
left = currentPoint.getLongitude();
|
right = currentPoint.getLongitude();
|
||||||
right = currentPoint.getLongitude();
|
top = currentPoint.getLatitude();
|
||||||
top = currentPoint.getLatitude();
|
bottom = currentPoint.getLatitude();
|
||||||
bottom = currentPoint.getLatitude();
|
} else {
|
||||||
} else {
|
left = Math.min(left, currentPoint.getLongitude());
|
||||||
left = Math.min(left, currentPoint.getLongitude());
|
right = Math.max(right, currentPoint.getLongitude());
|
||||||
right = Math.max(right, currentPoint.getLongitude());
|
top = Math.max(top, currentPoint.getLatitude());
|
||||||
top = Math.max(top, currentPoint.getLatitude());
|
bottom = Math.min(bottom, currentPoint.getLatitude());
|
||||||
bottom = Math.min(bottom, currentPoint.getLatitude());
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -352,7 +362,7 @@ public class TrackDetailsMenu {
|
||||||
private void fitTrackOnMap(LineChart chart, LatLon location, boolean forceFit) {
|
private void fitTrackOnMap(LineChart chart, LatLon location, boolean forceFit) {
|
||||||
QuadRect rect = getRect(chart, chart.getLowestVisibleX(), chart.getHighestVisibleX());
|
QuadRect rect = getRect(chart, chart.getLowestVisibleX(), chart.getHighestVisibleX());
|
||||||
MapActivity mapActivity = getMapActivity();
|
MapActivity mapActivity = getMapActivity();
|
||||||
if (mapActivity != null) {
|
if (mapActivity != null && rect.left != 0 && rect.right != 0) {
|
||||||
RotatedTileBox tb = mapActivity.getMapView().getCurrentRotatedTileBox().copy();
|
RotatedTileBox tb = mapActivity.getMapView().getCurrentRotatedTileBox().copy();
|
||||||
int tileBoxWidthPx = 0;
|
int tileBoxWidthPx = 0;
|
||||||
int tileBoxHeightPx = 0;
|
int tileBoxHeightPx = 0;
|
||||||
|
@ -454,17 +464,19 @@ public class TrackDetailsMenu {
|
||||||
|
|
||||||
private List<LatLon> getXAxisPoints(LineChart chart) {
|
private List<LatLon> getXAxisPoints(LineChart chart) {
|
||||||
float[] entries = chart.getXAxis().mEntries;
|
float[] entries = chart.getXAxis().mEntries;
|
||||||
float maxXValue = chart.getLineData().getXMax();
|
LineData lineData = chart.getLineData();
|
||||||
if (entries.length >= 2) {
|
float maxXValue = lineData != null ? lineData.getXMax() : -1;
|
||||||
|
if (entries.length >= 2 && lineData != null) {
|
||||||
float interval = entries[1] - entries[0];
|
float interval = entries[1] - entries[0];
|
||||||
if (interval > 0) {
|
if (interval > 0) {
|
||||||
xAxisPoints = new ArrayList<>();
|
List<LatLon> xAxisPoints = new ArrayList<>();
|
||||||
float currentPointEntry = interval;
|
float currentPointEntry = interval;
|
||||||
while (currentPointEntry < maxXValue) {
|
while (currentPointEntry < maxXValue) {
|
||||||
LatLon location = getLocationAtPos(chart, currentPointEntry);
|
LatLon location = getLocationAtPos(chart, currentPointEntry);
|
||||||
xAxisPoints.add(location);
|
xAxisPoints.add(location);
|
||||||
currentPointEntry += interval;
|
currentPointEntry += interval;
|
||||||
}
|
}
|
||||||
|
this.xAxisPoints = xAxisPoints;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return xAxisPoints;
|
return xAxisPoints;
|
||||||
|
|
|
@ -477,7 +477,8 @@ public class TrackSegmentFragment extends OsmAndListFragment implements TrackBit
|
||||||
|
|
||||||
private TrkSegment getTrackSegment(LineChart chart) {
|
private TrkSegment getTrackSegment(LineChart chart) {
|
||||||
if (segment == null) {
|
if (segment == null) {
|
||||||
List<ILineDataSet> ds = chart.getLineData().getDataSets();
|
LineData lineData = chart.getLineData();
|
||||||
|
List<ILineDataSet> ds = lineData != null ? lineData.getDataSets() : null;
|
||||||
if (ds != null && ds.size() > 0) {
|
if (ds != null && ds.size() > 0) {
|
||||||
for (GPXUtilities.Track t : gpxItem.group.getGpx().tracks) {
|
for (GPXUtilities.Track t : gpxItem.group.getGpx().tracks) {
|
||||||
for (TrkSegment s : t.segments) {
|
for (TrkSegment s : t.segments) {
|
||||||
|
@ -497,7 +498,8 @@ public class TrackSegmentFragment extends OsmAndListFragment implements TrackBit
|
||||||
|
|
||||||
private WptPt getPoint(LineChart chart, float pos) {
|
private WptPt getPoint(LineChart chart, float pos) {
|
||||||
WptPt wpt = null;
|
WptPt wpt = null;
|
||||||
List<ILineDataSet> ds = chart.getLineData().getDataSets();
|
LineData lineData = chart.getLineData();
|
||||||
|
List<ILineDataSet> ds = lineData != null ? lineData.getDataSets() : null;
|
||||||
if (ds != null && ds.size() > 0) {
|
if (ds != null && ds.size() > 0) {
|
||||||
TrkSegment segment = getTrackSegment(chart);
|
TrkSegment segment = getTrackSegment(chart);
|
||||||
OrderedLineDataSet dataSet = (OrderedLineDataSet) ds.get(0);
|
OrderedLineDataSet dataSet = (OrderedLineDataSet) ds.get(0);
|
||||||
|
|
Loading…
Reference in a new issue