Compare commits

...

1 commit
master ... r3.3

Author SHA1 Message Date
Alexey Kulish
3d0d79136a Fix chart crash at route details 2019-04-24 15:31:27 +03:00
2 changed files with 63 additions and 49 deletions

View file

@ -213,10 +213,12 @@ public class TrackDetailsMenu {
updateView(main);
}
private TrkSegment getTrackSegment(LineChart chart) {
@Nullable
private TrkSegment getTrackSegment(@NonNull LineChart chart) {
TrkSegment segment = this.segment;
if (segment == null) {
List<ILineDataSet> ds = chart.getLineData().getDataSets();
LineData lineData = chart.getLineData();
List<ILineDataSet> ds = lineData != null ? lineData.getDataSets() : null;
GpxDisplayItem gpxItem = getGpxItem();
if (ds != null && ds.size() > 0 && gpxItem != null) {
for (GPXUtilities.Track t : gpxItem.group.getGpx().tracks) {
@ -236,12 +238,17 @@ public class TrackDetailsMenu {
return segment;
}
@Nullable
private LatLon getLocationAtPos(LineChart chart, float pos) {
LatLon latLon = null;
List<ILineDataSet> ds = chart.getLineData().getDataSets();
LineData lineData = chart.getLineData();
List<ILineDataSet> ds = lineData != null ? lineData.getDataSets() : null;
GpxDisplayItem gpxItem = getGpxItem();
if (ds != null && ds.size() > 0 && gpxItem != null) {
TrkSegment segment = getTrackSegment(chart);
if (segment == null) {
return null;
}
OrderedLineDataSet dataSet = (OrderedLineDataSet) ds.get(0);
if (gpxItem.chartAxisType == GPXDataSetAxisType.TIME ||
gpxItem.chartAxisType == GPXDataSetAxisType.TIMEOFDAY) {
@ -295,10 +302,12 @@ public class TrackDetailsMenu {
private QuadRect getRect(LineChart chart, float startPos, float endPos) {
double left = 0, right = 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();
if (ds != null && ds.size() > 0 && gpxItem != null) {
TrkSegment segment = getTrackSegment(chart);
if (segment != null) {
OrderedLineDataSet dataSet = (OrderedLineDataSet) ds.get(0);
if (gpxItem.chartAxisType == GPXDataSetAxisType.TIME || gpxItem.chartAxisType == GPXDataSetAxisType.TIMEOFDAY) {
float startTime = startPos * 1000;
@ -346,13 +355,14 @@ public class TrackDetailsMenu {
}
}
}
}
return new QuadRect(left, top, right, bottom);
}
private void fitTrackOnMap(LineChart chart, LatLon location, boolean forceFit) {
QuadRect rect = getRect(chart, chart.getLowestVisibleX(), chart.getHighestVisibleX());
MapActivity mapActivity = getMapActivity();
if (mapActivity != null) {
if (mapActivity != null && rect.left != 0 && rect.right != 0) {
RotatedTileBox tb = mapActivity.getMapView().getCurrentRotatedTileBox().copy();
int tileBoxWidthPx = 0;
int tileBoxHeightPx = 0;
@ -454,17 +464,19 @@ public class TrackDetailsMenu {
private List<LatLon> getXAxisPoints(LineChart chart) {
float[] entries = chart.getXAxis().mEntries;
float maxXValue = chart.getLineData().getXMax();
if (entries.length >= 2) {
LineData lineData = chart.getLineData();
float maxXValue = lineData != null ? lineData.getXMax() : -1;
if (entries.length >= 2 && lineData != null) {
float interval = entries[1] - entries[0];
if (interval > 0) {
xAxisPoints = new ArrayList<>();
List<LatLon> xAxisPoints = new ArrayList<>();
float currentPointEntry = interval;
while (currentPointEntry < maxXValue) {
LatLon location = getLocationAtPos(chart, currentPointEntry);
xAxisPoints.add(location);
currentPointEntry += interval;
}
this.xAxisPoints = xAxisPoints;
}
}
return xAxisPoints;

View file

@ -477,7 +477,8 @@ public class TrackSegmentFragment extends OsmAndListFragment implements TrackBit
private TrkSegment getTrackSegment(LineChart chart) {
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) {
for (GPXUtilities.Track t : gpxItem.group.getGpx().tracks) {
for (TrkSegment s : t.segments) {
@ -497,7 +498,8 @@ public class TrackSegmentFragment extends OsmAndListFragment implements TrackBit
private WptPt getPoint(LineChart chart, float pos) {
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) {
TrkSegment segment = getTrackSegment(chart);
OrderedLineDataSet dataSet = (OrderedLineDataSet) ds.get(0);