Merge pull request #8203 from osmandapp/Fix_7084

Fix_7084
This commit is contained in:
max-klaus 2020-01-10 14:36:00 +03:00 committed by GitHub
commit 1368066253
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 84 additions and 52 deletions

View file

@ -873,7 +873,7 @@ public class GPXUtilities {
WptPt point = segment.points.get(k);
if (k > 0) {
double currentSegment = 0;
if (!(segment.generalSegment && joinSegments && point.firstPoint)) {
if (!(segment.generalSegment && !joinSegments && point.firstPoint)) {
currentSegment = metric.metric(prev, point);
secondaryMetricEnd += secondaryMetric.metric(prev, point);
}

View file

@ -8,20 +8,17 @@ import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.content.ContextCompat;
import java.util.Map;
import java.util.Map.Entry;
import net.osmand.GPXUtilities;
import net.osmand.IProgress;
import net.osmand.PlatformUtil;
import net.osmand.data.LatLon;
import net.osmand.plus.GPXDatabase.GpxDataItem;
import net.osmand.GPXUtilities.GPXFile;
import net.osmand.GPXUtilities.GPXTrackAnalysis;
import net.osmand.GPXUtilities.Route;
import net.osmand.GPXUtilities.Track;
import net.osmand.GPXUtilities.TrkSegment;
import net.osmand.GPXUtilities.WptPt;
import net.osmand.IProgress;
import net.osmand.PlatformUtil;
import net.osmand.data.LatLon;
import net.osmand.plus.GPXDatabase.GpxDataItem;
import net.osmand.plus.MapMarkersHelper.MapMarkersGroup;
import net.osmand.plus.OsmandSettings.MetricsConstants;
import net.osmand.plus.activities.SavingTrackHelper;
@ -39,6 +36,8 @@ import java.io.File;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
public class GpxSelectionHelper {
@ -48,6 +47,7 @@ public class GpxSelectionHelper {
private static final String BACKUPMODIFIEDTIME = "backupTime";
private static final String COLOR = "color";
private static final String SELECTED_BY_USER = "selected_by_user";
private OsmandApplication app;
@NonNull
private List<SelectedGpxFile> selectedGPXFiles = new java.util.ArrayList<>();
@ -64,7 +64,7 @@ public class GpxSelectionHelper {
public void clearAllGpxFilesToShow(boolean backupSelection) {
selectedGpxFilesBackUp.clear();
if (backupSelection) {
for(SelectedGpxFile s : selectedGPXFiles) {
for (SelectedGpxFile s : selectedGPXFiles) {
selectedGpxFilesBackUp.put(s.gpxFile, s.modifiedTime);
}
}
@ -512,7 +512,7 @@ public class GpxSelectionHelper {
}
if (gpx.error != null) {
save = true;
} else if(obj.has(BACKUP)) {
} else if (obj.has(BACKUP)) {
selectedGpxFilesBackUp.put(gpx, gpx.modifiedTime);
} else {
selectGpxFile(gpx, true, false, true, selectedByUser, false);
@ -561,7 +561,7 @@ public class GpxSelectionHelper {
if (s != null) {
try {
JSONObject obj = new JSONObject();
if(Algorithms.isEmpty(s.getKey().path)) {
if (Algorithms.isEmpty(s.getKey().path)) {
obj.put(CURRENT_TRACK, true);
} else {
obj.put(FILE, s.getKey().path);
@ -595,8 +595,11 @@ public class GpxSelectionHelper {
displayed = sf != null;
if (show && sf == null) {
sf = new SelectedGpxFile();
if (dataItem != null && dataItem.getColor() != 0) {
gpx.setColor(dataItem.getColor());
if (dataItem != null) {
if (dataItem.getColor() != 0) {
gpx.setColor(dataItem.getColor());
}
sf.setJoinSegments(dataItem.isJoinSegments());
}
sf.setGpxFile(gpx, app);
sf.notShowNavigationDialog = notShowNavigationDialog;
@ -661,7 +664,6 @@ public class GpxSelectionHelper {
}
private void syncGpxWithMarkers(GPXFile gpxFile) {
File gpx = new File(gpxFile.path);
MapMarkersHelper mapMarkersHelper = app.getMapMarkersHelper();
MapMarkersGroup group = mapMarkersHelper.getMarkersGroup(gpxFile);
if (group != null) {
@ -669,22 +671,25 @@ public class GpxSelectionHelper {
}
}
public static class SelectedGpxFile {
public boolean notShowNavigationDialog = false;
public boolean selectedByUser = true;
private boolean showCurrentTrack;
private GPXFile gpxFile;
private int color;
private GPXTrackAnalysis trackAnalysis;
private long modifiedTime = -1;
private boolean splitProcessed = false;
private List<TrkSegment> processedPointsToDisplay = new ArrayList<>();
private boolean routePoints;
private List<TrkSegment> processedPointsToDisplay = new ArrayList<>();
private List<GpxDisplayGroup> displayGroups;
private int color;
private long modifiedTime = -1;
private boolean routePoints;
private boolean joinSegments;
private boolean showCurrentTrack;
private boolean splitProcessed = false;
public void setGpxFile(GPXFile gpxFile, OsmandApplication app) {
this.gpxFile = gpxFile;
if (gpxFile.tracks.size() > 0) {
@ -723,7 +728,7 @@ public class GpxSelectionHelper {
}
public List<TrkSegment> getPointsToDisplay() {
return processedPointsToDisplay;
return joinSegments ? gpxFile.getGeneralTrack().segments : processedPointsToDisplay;
}
public List<TrkSegment> getModifiablePointsToDisplay() {
@ -747,6 +752,14 @@ public class GpxSelectionHelper {
this.showCurrentTrack = showCurrentTrack;
}
public boolean isJoinSegments() {
return joinSegments;
}
public void setJoinSegments(boolean joinSegments) {
this.joinSegments = joinSegments;
}
public int getColor() {
return color;
}

View file

@ -412,7 +412,13 @@ public class TrackActivity extends TabActivity {
public boolean setJoinSegments(boolean joinSegments) {
if (gpxDataItem != null) {
return app.getGpxDbHelper().updateJoinSegments(gpxDataItem, joinSegments);
boolean updated = app.getGpxDbHelper().updateJoinSegments(gpxDataItem, joinSegments);
SelectedGpxFile selectedGpxFile = app.getSelectedGpxHelper().getSelectedFileByPath(gpxFile.path);
if (updated && selectedGpxFile != null) {
selectedGpxFile.setJoinSegments(joinSegments);
}
return updated;
}
return false;
}

View file

@ -1230,7 +1230,7 @@ public class GpxUiHelper {
}
private static List<Entry> calculateElevationArray(GPXTrackAnalysis analysis, GPXDataSetAxisType axisType,
float divX, float convEle, boolean useGeneralTrackPoints) {
float divX, float convEle, boolean useGeneralTrackPoints, boolean calcGaps) {
List<Entry> values = new ArrayList<>();
List<Elevation> elevationData = analysis.elevationData;
float nextX = 0;
@ -1252,7 +1252,9 @@ public class GpxUiHelper {
x = e.distance;
}
if (x > 0) {
nextX += x / divX;
if (!(!calcGaps && e.firstPoint && lastEntry != null)) {
nextX += x / divX;
}
if (!Float.isNaN(e.elevation)) {
elev = e.elevation;
if (prevElevOrig != -80000) {
@ -1383,7 +1385,8 @@ public class GpxUiHelper {
@NonNull GPXTrackAnalysis analysis,
@NonNull GPXDataSetAxisType axisType,
boolean useRightAxis,
boolean drawFilled) {
boolean drawFilled,
boolean calcGaps) {
OsmandSettings settings = ctx.getSettings();
OsmandSettings.MetricsConstants mc = settings.METRIC_SYSTEM.get();
boolean useFeet = (mc == OsmandSettings.MetricsConstants.MILES_AND_FEET) || (mc == OsmandSettings.MetricsConstants.MILES_AND_YARDS);
@ -1393,11 +1396,11 @@ public class GpxUiHelper {
float divX;
XAxis xAxis = mChart.getXAxis();
if (axisType == GPXDataSetAxisType.TIME && analysis.isTimeSpecified()) {
divX = setupXAxisTime(xAxis, analysis.timeSpan);
divX = setupXAxisTime(xAxis, calcGaps ? analysis.timeSpan : analysis.timeSpanWithoutGaps);
} else if (axisType == GPXDataSetAxisType.TIMEOFDAY && analysis.isTimeSpecified()) {
divX = setupXAxisTimeOfDay(xAxis, analysis.startTime);
} else {
divX = setupAxisDistance(ctx, xAxis, analysis.totalDistance);
divX = setupAxisDistance(ctx, xAxis, calcGaps ? analysis.totalDistance : analysis.totalDistanceWithoutGaps);
}
final String mainUnitY = useFeet ? ctx.getString(R.string.foot) : ctx.getString(R.string.m);
@ -1421,7 +1424,7 @@ public class GpxUiHelper {
}
});
List<Entry> values = calculateElevationArray(analysis, axisType, divX, convEle, true);
List<Entry> values = calculateElevationArray(analysis, axisType, divX, convEle, true, calcGaps);
OrderedLineDataSet dataSet = new OrderedLineDataSet(values, "", GPXDataSetType.ALTITUDE, axisType);
dataSet.priority = (float) (analysis.avgElevation - analysis.minElevation) * convEle;
@ -1640,7 +1643,8 @@ public class GpxUiHelper {
@NonNull GPXDataSetAxisType axisType,
@Nullable List<Entry> eleValues,
boolean useRightAxis,
boolean drawFilled) {
boolean drawFilled,
boolean calcGaps) {
if (axisType == GPXDataSetAxisType.TIME || axisType == GPXDataSetAxisType.TIMEOFDAY) {
return null;
}
@ -1649,10 +1653,10 @@ public class GpxUiHelper {
OsmandSettings.MetricsConstants mc = settings.METRIC_SYSTEM.get();
boolean useFeet = (mc == OsmandSettings.MetricsConstants.MILES_AND_FEET) || (mc == OsmandSettings.MetricsConstants.MILES_AND_YARDS);
final float convEle = useFeet ? 3.28084f : 1.0f;
final float totalDistance = analysis.totalDistance;
final float totalDistance = calcGaps ? analysis.totalDistance : analysis.totalDistanceWithoutGaps;
XAxis xAxis = mChart.getXAxis();
float divX = setupAxisDistance(ctx, xAxis, analysis.totalDistance);
float divX = setupAxisDistance(ctx, xAxis, calcGaps ? analysis.totalDistance : analysis.totalDistanceWithoutGaps);
final String mainUnitY = "%";
@ -1677,7 +1681,7 @@ public class GpxUiHelper {
List<Entry> values;
if (eleValues == null) {
values = calculateElevationArray(analysis, GPXDataSetAxisType.DISTANCE, 1f, 1f, false);
values = calculateElevationArray(analysis, GPXDataSetAxisType.DISTANCE, 1f, 1f, false, calcGaps);
} else {
values = new ArrayList<>(eleValues.size());
for (Entry e : eleValues) {

View file

@ -586,7 +586,7 @@ public class TrackDetailsMenu {
switch (gpxItem.chartTypes[i]) {
case ALTITUDE:
dataSet = GpxUiHelper.createGPXElevationDataSet(app, chart, analysis,
gpxItem.chartAxisType, false, true);
gpxItem.chartAxisType, false, true, false);
break;
case SPEED:
dataSet = GpxUiHelper.createGPXSpeedDataSet(app, chart, analysis,
@ -594,7 +594,7 @@ public class TrackDetailsMenu {
break;
case SLOPE:
dataSet = GpxUiHelper.createGPXSlopeDataSet(app, chart, analysis,
gpxItem.chartAxisType, null, gpxItem.chartTypes.length > 1, true);
gpxItem.chartAxisType, null, gpxItem.chartTypes.length > 1, true, false);
break;
}
if (dataSet != null) {

View file

@ -529,7 +529,7 @@ public class SplitSegmentDialogFragment extends DialogFragment {
TextView distanceOrTimeSpanText = (TextView) convertView.findViewById(R.id.distance_or_time_span_text);
if (position == 0) {
distanceOrTimeSpanImageView.setImageDrawable(ic.getIcon(R.drawable.ic_action_track_16, app.getSettings().isLightContent() ? R.color.gpx_split_segment_icon_color : 0));
float totalDistance = joinSegments && gpxItem.isGeneralTrack() ? analysis.totalDistanceWithoutGaps : analysis.totalDistance;
float totalDistance = joinSegments && gpxItem.isGeneralTrack() ? analysis.totalDistance : analysis.totalDistanceWithoutGaps;
distanceOrTimeSpanValue.setText(OsmAndFormatter.getFormattedDistance(totalDistance, app));
distanceOrTimeSpanText.setText(app.getString(R.string.distance));
} else {

View file

@ -12,13 +12,13 @@ import android.support.annotation.Nullable;
import android.support.v4.content.ContextCompat;
import net.osmand.AndroidUtils;
import net.osmand.GPXUtilities;
import net.osmand.GPXUtilities.GPXFile;
import net.osmand.GPXUtilities.TrkSegment;
import net.osmand.data.LatLon;
import net.osmand.data.QuadRect;
import net.osmand.data.RotatedTileBox;
import net.osmand.plus.GPXDatabase.GpxDataItem;
import net.osmand.GPXUtilities;
import net.osmand.GPXUtilities.GPXFile;
import net.osmand.GPXUtilities.TrkSegment;
import net.osmand.plus.GpxSelectionHelper;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R;
@ -60,9 +60,11 @@ public class TrackBitmapDrawer {
public interface TrackBitmapDrawerListener {
void onTrackBitmapDrawing();
void onTrackBitmapDrawn();
boolean isTrackBitmapSelectionSupported();
void drawTrackBitmap(Bitmap bitmap);
}
@ -205,7 +207,10 @@ public class TrackBitmapDrawer {
if (gpxFile.showCurrentTrack) {
sf = app.getSavingTrackHelper().getCurrentTrack();
} else {
sf = new GpxSelectionHelper.SelectedGpxFile();
sf = app.getSelectedGpxHelper().getSelectedFileByPath(gpxFile.path);
if (sf == null) {
sf = new GpxSelectionHelper.SelectedGpxFile();
}
sf.setGpxFile(gpxFile, app);
}
Bitmap bmp = mapBitmap.copy(mapBitmap.getConfig(), true);

View file

@ -435,8 +435,10 @@ public class TrackSegmentFragment extends OsmAndListFragment implements TrackBit
analysis, GPXDataSetAxisType.DISTANCE, true, true);
}
if (analysis.hasElevationData) {
GpxDataItem gpxDataItem = getGpxDataItem();
boolean calcGaps = gpxDataItem != null && gpxDataItem.isJoinSegments() && gpxItem.isGeneralTrack() || !gpxItem.isGeneralTrack();
elevationDataSet = GpxUiHelper.createGPXElevationDataSet(app, chart,
analysis, GPXDataSetAxisType.DISTANCE, false, true);
analysis, GPXDataSetAxisType.DISTANCE, false, true, calcGaps);
}
if (speedDataSet != null) {
dataSets.add(speedDataSet);
@ -451,15 +453,17 @@ public class TrackSegmentFragment extends OsmAndListFragment implements TrackBit
break;
}
case GPX_TAB_ITEM_ALTITUDE: {
GpxDataItem gpxDataItem = getGpxDataItem();
boolean calcGaps = gpxDataItem != null && gpxDataItem.isJoinSegments() && gpxItem.isGeneralTrack() || !gpxItem.isGeneralTrack();
OrderedLineDataSet elevationDataSet = GpxUiHelper.createGPXElevationDataSet(app, chart,
analysis, GPXDataSetAxisType.DISTANCE, false, true);
analysis, GPXDataSetAxisType.DISTANCE, false, true, calcGaps);
if (elevationDataSet != null) {
dataSets.add(elevationDataSet);
}
if (analysis.hasElevationData) {
List<Entry> eleValues = elevationDataSet != null && !gpxItem.isGeneralTrack() ? elevationDataSet.getValues() : null;
OrderedLineDataSet slopeDataSet = GpxUiHelper.createGPXSlopeDataSet(app, chart,
analysis, GPXDataSetAxisType.DISTANCE, eleValues, true, true);
analysis, GPXDataSetAxisType.DISTANCE, eleValues, true, true, calcGaps);
if (slopeDataSet != null) {
dataSets.add(slopeDataSet);
}
@ -720,7 +724,7 @@ public class TrackSegmentFragment extends OsmAndListFragment implements TrackBit
public void onClick(View v) {
TrackActivity activity = getTrackActivity();
if (activity != null && activity.setJoinSegments(!activity.isJoinSegments())) {
updateSplitView();
updateContent();
for (int i = 0; i < getCount(); i++) {
View view = getViewAtPosition(i);
updateJoinGapsInfo(view, i);
@ -1156,14 +1160,14 @@ public class TrackSegmentFragment extends OsmAndListFragment implements TrackBit
((SwitchCompat) view.findViewById(R.id.gpx_join_gaps_switch)).setChecked(joinSegments);
if (analysis != null) {
if (tabType.equals(GPXTabItemType.GPX_TAB_ITEM_GENERAL)) {
float totalDistance = joinSegments && gpxItem.isGeneralTrack() ? analysis.totalDistanceWithoutGaps : analysis.totalDistance;
float timeSpan = joinSegments && gpxItem.isGeneralTrack() ? analysis.timeSpanWithoutGaps : analysis.timeSpan;
float totalDistance = !joinSegments && gpxItem.isGeneralTrack() ? analysis.totalDistanceWithoutGaps : analysis.totalDistance;
float timeSpan = !joinSegments && gpxItem.isGeneralTrack() ? analysis.timeSpanWithoutGaps : analysis.timeSpan;
((TextView) view.findViewById(R.id.distance_text)).setText(OsmAndFormatter.getFormattedDistance(totalDistance, app));
((TextView) view.findViewById(R.id.duration_text)).setText(Algorithms.formatDuration((int) (timeSpan / 1000), app.accessibilityEnabled()));
} else if (tabType.equals(GPXTabItemType.GPX_TAB_ITEM_SPEED)) {
long timeMoving = joinSegments && gpxItem.isGeneralTrack() ? analysis.timeMovingWithoutGaps : analysis.timeMoving;
float totalDistanceMoving = joinSegments && gpxItem.isGeneralTrack() ? analysis.totalDistanceMovingWithoutGaps : analysis.totalDistanceMoving;
long timeMoving = !joinSegments && gpxItem.isGeneralTrack() ? analysis.timeMovingWithoutGaps : analysis.timeMoving;
float totalDistanceMoving = !joinSegments && gpxItem.isGeneralTrack() ? analysis.totalDistanceMovingWithoutGaps : analysis.totalDistanceMoving;
((TextView) view.findViewById(R.id.time_moving_text)).setText(Algorithms.formatDuration((int) (timeMoving / 1000), app.accessibilityEnabled()));
((TextView) view.findViewById(R.id.distance_text)).setText(OsmAndFormatter.getFormattedDistance(totalDistanceMoving, app));

View file

@ -244,11 +244,11 @@ public class RouteStatisticCard extends BaseCard {
List<ILineDataSet> dataSets = new ArrayList<>();
OrderedLineDataSet slopeDataSet = null;
OrderedLineDataSet elevationDataSet = GpxUiHelper.createGPXElevationDataSet(app, mChart, analysis,
GPXDataSetAxisType.DISTANCE, false, true);
GPXDataSetAxisType.DISTANCE, false, true, false);
if (elevationDataSet != null) {
dataSets.add(elevationDataSet);
slopeDataSet = GpxUiHelper.createGPXSlopeDataSet(app, mChart, analysis,
GPXDataSetAxisType.DISTANCE, elevationDataSet.getValues(), true, true);
GPXDataSetAxisType.DISTANCE, elevationDataSet.getValues(), true, true, false);
}
if (slopeDataSet != null) {
dataSets.add(slopeDataSet);

View file

@ -120,11 +120,11 @@ public class SimpleRouteCard extends BaseCard {
List<ILineDataSet> dataSets = new ArrayList<>();
OrderedLineDataSet slopeDataSet = null;
OrderedLineDataSet elevationDataSet = GpxUiHelper.createGPXElevationDataSet(app, mChart, analysis,
GpxUiHelper.GPXDataSetAxisType.DISTANCE, false, true);
GpxUiHelper.GPXDataSetAxisType.DISTANCE, false, true, false);
if (elevationDataSet != null) {
dataSets.add(elevationDataSet);
slopeDataSet = GpxUiHelper.createGPXSlopeDataSet(app, mChart, analysis,
GpxUiHelper.GPXDataSetAxisType.DISTANCE, elevationDataSet.getValues(), true, true);
GpxUiHelper.GPXDataSetAxisType.DISTANCE, elevationDataSet.getValues(), true, true, false);
}
if (slopeDataSet != null) {
dataSets.add(slopeDataSet);