Merge pull request #3889 from osmandapp/gpx_improvements

Gpx improvements
This commit is contained in:
Alexey 2017-06-07 13:24:12 +03:00 committed by GitHub
commit 21b986a354
4 changed files with 44 additions and 2 deletions

View file

@ -239,6 +239,7 @@
<color name="gpx_chart_orange">#ff8800</color> <color name="gpx_chart_orange">#ff8800</color>
<color name="gpx_chart_red">#ff0000</color> <color name="gpx_chart_red">#ff0000</color>
<color name="gpx_chart_green">#23b03b</color> <color name="gpx_chart_green">#23b03b</color>
<color name="gpx_chart_black_grid">#000000</color>
<color name="gpx_chart_blue_grid">#c32561c2</color> <color name="gpx_chart_blue_grid">#c32561c2</color>
<color name="gpx_chart_orange_grid">#c3b35f00</color> <color name="gpx_chart_orange_grid">#c3b35f00</color>
<color name="gpx_chart_red_grid">#c3b30000</color> <color name="gpx_chart_red_grid">#c3b30000</color>

View file

@ -103,6 +103,8 @@ public class GPXUtilities {
} }
public static class WptPt extends GPXExtensions implements LocationPoint { public static class WptPt extends GPXExtensions implements LocationPoint {
public boolean firstPoint = false;
public boolean lastPoint = false;
public double lat; public double lat;
public double lon; public double lon;
public String name = null; public String name = null;
@ -214,6 +216,8 @@ public class GPXUtilities {
} }
public static class TrkSegment extends GPXExtensions { public static class TrkSegment extends GPXExtensions {
public boolean generalSegment = false;
public List<WptPt> points = new ArrayList<>(); public List<WptPt> points = new ArrayList<>();
public List<Renderable.RenderableSegment> renders = new ArrayList<>(); public List<Renderable.RenderableSegment> renders = new ArrayList<>();
@ -326,6 +330,9 @@ public class GPXUtilities {
public GPXTrackAnalysis prepareInformation(long filestamp, SplitSegment... splitSegments) { public GPXTrackAnalysis prepareInformation(long filestamp, SplitSegment... splitSegments) {
float[] calculations = new float[1]; float[] calculations = new float[1];
long startTimeOfSingleSegment = 0;
long endTimeOfSingleSegment = 0;
float totalElevation = 0; float totalElevation = 0;
int elevationPoints = 0; int elevationPoints = 0;
int speedCount = 0; int speedCount = 0;
@ -365,6 +372,18 @@ public class GPXUtilities {
} }
long time = point.time; long time = point.time;
if (time != 0) { if (time != 0) {
if (s.segment.generalSegment) {
if (point.firstPoint) {
startTimeOfSingleSegment = time;
} else if (point.lastPoint) {
endTimeOfSingleSegment = time;
}
if (startTimeOfSingleSegment != 0 && endTimeOfSingleSegment != 0) {
timeSpan += endTimeOfSingleSegment - startTimeOfSingleSegment;
startTimeOfSingleSegment = 0;
endTimeOfSingleSegment = 0;
}
}
startTime = Math.min(startTime, time); startTime = Math.min(startTime, time);
endTime = Math.max(endTime, time); endTime = Math.max(endTime, time);
} }
@ -527,7 +546,9 @@ public class GPXUtilities {
// OUTPUT: // OUTPUT:
// 1. Total distance, Start time, End time // 1. Total distance, Start time, End time
// 2. Time span // 2. Time span
timeSpan = endTime - startTime; if (timeSpan == 0) {
timeSpan = endTime - startTime;
}
// 3. Time moving, if any // 3. Time moving, if any
// 4. Elevation, eleUp, eleDown, if recorded // 4. Elevation, eleUp, eleDown, if recorded
@ -767,11 +788,14 @@ public class GPXUtilities {
for (WptPt wptPt : s.points) { for (WptPt wptPt : s.points) {
waypoints.add(new WptPt(wptPt)); waypoints.add(new WptPt(wptPt));
} }
waypoints.get(0).firstPoint = true;
waypoints.get(waypoints.size() - 1).lastPoint = true;
segment.points.addAll(waypoints); segment.points.addAll(waypoints);
} }
} }
} }
if (segment.points.size() > 0) { if (segment.points.size() > 0) {
segment.generalSegment = true;
generalSegment = segment; generalSegment = segment;
} }
} }

View file

@ -952,7 +952,10 @@ public class GpxUiHelper {
XAxis xAxis = mChart.getXAxis(); XAxis xAxis = mChart.getXAxis();
xAxis.setDrawAxisLine(false); xAxis.setDrawAxisLine(false);
xAxis.setDrawGridLines(false); xAxis.setDrawGridLines(true);
xAxis.setGridLineWidth(1.5f);
xAxis.setGridColor(ActivityCompat.getColor(mChart.getContext(), R.color.gpx_chart_black_grid));
xAxis.enableGridDashedLine(25f, Float.MAX_VALUE, 0f);
xAxis.setPosition(BOTTOM); xAxis.setPosition(BOTTOM);
xAxis.setTextColor(light ? mChart.getResources().getColor(R.color.secondary_text_light) : mChart.getResources().getColor(R.color.secondary_text_dark)); xAxis.setTextColor(light ? mChart.getResources().getColor(R.color.secondary_text_light) : mChart.getResources().getColor(R.color.secondary_text_dark));

View file

@ -819,6 +819,7 @@ public class TrackSegmentFragment extends OsmAndListFragment {
private String[] titles; private String[] titles;
private Map<GPXTabItemType, List<ILineDataSet>> dataSetsMap = new HashMap<>(); private Map<GPXTabItemType, List<ILineDataSet>> dataSetsMap = new HashMap<>();
private TrkSegment segment; private TrkSegment segment;
private float listViewYPos;
GPXItemPagerAdapter(PagerSlidingTabStrip tabs, GpxDisplayItem gpxItem) { GPXItemPagerAdapter(PagerSlidingTabStrip tabs, GpxDisplayItem gpxItem) {
super(); super();
@ -964,6 +965,10 @@ public class TrackSegmentFragment extends OsmAndListFragment {
return wpt; return wpt;
} }
private void scrollBy(int px) {
getListView().setSelectionFromTop(getListView().getFirstVisiblePosition(), getListView().getChildAt(0).getTop() - px);
}
@Override @Override
public int getCount() { public int getCount() {
return tabTypes.length; return tabTypes.length;
@ -999,6 +1004,15 @@ public class TrackSegmentFragment extends OsmAndListFragment {
@Override @Override
public boolean onTouch(View v, MotionEvent event) { public boolean onTouch(View v, MotionEvent event) {
getListView().requestDisallowInterceptTouchEvent(true); getListView().requestDisallowInterceptTouchEvent(true);
switch (event.getAction()) {
case android.view.MotionEvent.ACTION_DOWN:
listViewYPos = event.getRawY();
break;
case android.view.MotionEvent.ACTION_MOVE:
scrollBy(Math.round(listViewYPos - event.getRawY()));
listViewYPos = event.getRawY();
break;
}
return false; return false;
} }
}); });