Load gpx split type from file

This commit is contained in:
Vitaliy 2020-07-07 14:15:48 +03:00
parent c18b5ba25c
commit 2284de7055
6 changed files with 93 additions and 39 deletions

View file

@ -1514,26 +1514,6 @@ public class GPXUtilities {
return new QuadRect(left, top, right, bottom); return new QuadRect(left, top, right, bottom);
} }
public enum GradientScaleType {
SPEED("gradient_speed_color"),
ALTITUDE("gradient_altitude_color"),
SLOPE("gradient_slope_color");
private String typeName;
GradientScaleType(String typeName) {
this.typeName = typeName;
}
public String getTypeName() {
return typeName;
}
}
public void setGradientScaleColor(GradientScaleType gradientScaleType, int gradientScaleSpeedColor) {
getExtensionsToWrite().put(gradientScaleType.getTypeName(), Algorithms.colorToString(gradientScaleSpeedColor));
}
public int getGradientScaleColor(GradientScaleType gradientScaleType, int defColor) { public int getGradientScaleColor(GradientScaleType gradientScaleType, int defColor) {
String clrValue = null; String clrValue = null;
if (extensions != null) { if (extensions != null) {
@ -1542,8 +1522,8 @@ public class GPXUtilities {
return parseColor(clrValue, defColor); return parseColor(clrValue, defColor);
} }
public void setGradientScaleType(GradientScaleType gradientScaleType) { public void setGradientScaleColor(GradientScaleType gradientScaleType, int gradientScaleColor) {
getExtensionsToWrite().put("gradient_scale_type", gradientScaleType != null ? gradientScaleType.name() : null); getExtensionsToWrite().put(gradientScaleType.getTypeName(), Algorithms.colorToString(gradientScaleColor));
} }
public GradientScaleType getGradientScaleType() { public GradientScaleType getGradientScaleType() {
@ -1560,6 +1540,46 @@ public class GPXUtilities {
return null; return null;
} }
public void setGradientScaleType(GradientScaleType gradientScaleType) {
getExtensionsToWrite().put("gradient_scale_type", gradientScaleType != null ? gradientScaleType.name() : null);
}
public GpxSplitType getSplitType() {
if (extensions != null) {
String gradientScaleTypeName = extensions.get("split_type");
if (!Algorithms.isEmpty(gradientScaleTypeName)) {
try {
return GpxSplitType.valueOf(gradientScaleTypeName);
} catch (IllegalArgumentException e) {
log.error("Error reading GpxSplitType", e);
}
}
}
return null;
}
public void setSplitType(GpxSplitType gpxSplitType) {
getExtensionsToWrite().put("split_type", gpxSplitType != null ? gpxSplitType.name() : null);
}
public double getSplitInterval() {
if (extensions != null) {
String splitIntervalStr = extensions.get("split_interval");
if (!Algorithms.isEmpty(splitIntervalStr)) {
try {
return Double.parseDouble(splitIntervalStr);
} catch (NumberFormatException e) {
log.error("Error reading split_interval", e);
}
}
}
return 0;
}
public void setSplitInterval(double splitInterval) {
getExtensionsToWrite().put("split_interval", String.valueOf(splitInterval));
}
public String getWidth(String defWidth) { public String getWidth(String defWidth) {
String widthValue = null; String widthValue = null;
if (extensions != null) { if (extensions != null) {
@ -1595,6 +1615,38 @@ public class GPXUtilities {
public void setShowStartFinish(boolean showStartFinish) { public void setShowStartFinish(boolean showStartFinish) {
getExtensionsToWrite().put("show_start_finish", String.valueOf(showStartFinish)); getExtensionsToWrite().put("show_start_finish", String.valueOf(showStartFinish));
} }
public enum GradientScaleType {
SPEED("gradient_speed_color"),
ALTITUDE("gradient_altitude_color"),
SLOPE("gradient_slope_color");
private String typeName;
GradientScaleType(String typeName) {
this.typeName = typeName;
}
public String getTypeName() {
return typeName;
}
}
public enum GpxSplitType {
NO_SPLIT(-1),
DISTANCE(1),
TIME(2);
private int type;
GpxSplitType(int type) {
this.type = type;
}
public int getType() {
return type;
}
}
} }
public static String asString(GPXFile file) { public static String asString(GPXFile file) {

View file

@ -72,10 +72,6 @@ public class GPXDatabase {
private static final String GPX_COL_GRADIENT_SCALE_TYPE = "gradientScaleType"; private static final String GPX_COL_GRADIENT_SCALE_TYPE = "gradientScaleType";
public static final int GPX_SPLIT_TYPE_NO_SPLIT = -1;
public static final int GPX_SPLIT_TYPE_DISTANCE = 1;
public static final int GPX_SPLIT_TYPE_TIME = 2;
private static final String GPX_TABLE_CREATE = "CREATE TABLE IF NOT EXISTS " + GPX_TABLE_NAME + " (" + private static final String GPX_TABLE_CREATE = "CREATE TABLE IF NOT EXISTS " + GPX_TABLE_NAME + " (" +
GPX_COL_NAME + " TEXT, " + GPX_COL_NAME + " TEXT, " +
GPX_COL_DIR + " TEXT, " + GPX_COL_DIR + " TEXT, " +

View file

@ -8,6 +8,7 @@ import androidx.annotation.Nullable;
import net.osmand.GPXUtilities; import net.osmand.GPXUtilities;
import net.osmand.GPXUtilities.GPXFile; import net.osmand.GPXUtilities.GPXFile;
import net.osmand.GPXUtilities.GPXFile.GpxSplitType;
import net.osmand.GPXUtilities.GPXFile.GradientScaleType; import net.osmand.GPXUtilities.GPXFile.GradientScaleType;
import net.osmand.GPXUtilities.GPXTrackAnalysis; import net.osmand.GPXUtilities.GPXTrackAnalysis;
import net.osmand.plus.GPXDatabase.GpxDataItem; import net.osmand.plus.GPXDatabase.GpxDataItem;
@ -114,8 +115,8 @@ public class GpxDbHelper {
return res; return res;
} }
public boolean updateSplit(@NonNull GpxDataItem item, int splitType, double splitInterval) { public boolean updateSplit(@NonNull GpxDataItem item, @NonNull GpxSplitType splitType, double splitInterval) {
boolean res = db.updateSplit(item, splitType, splitInterval); boolean res = db.updateSplit(item, splitType.getType(), splitInterval);
putToCache(item); putToCache(item);
return res; return res;
} }

View file

@ -11,6 +11,7 @@ import androidx.core.content.ContextCompat;
import net.osmand.GPXUtilities; import net.osmand.GPXUtilities;
import net.osmand.GPXUtilities.GPXFile; import net.osmand.GPXUtilities.GPXFile;
import net.osmand.GPXUtilities.GPXFile.GpxSplitType;
import net.osmand.GPXUtilities.GPXFile.GradientScaleType; import net.osmand.GPXUtilities.GPXFile.GradientScaleType;
import net.osmand.GPXUtilities.GPXTrackAnalysis; import net.osmand.GPXUtilities.GPXTrackAnalysis;
import net.osmand.GPXUtilities.Route; import net.osmand.GPXUtilities.Route;
@ -172,17 +173,17 @@ public class GpxSelectionHelper {
if (selectedGpxFile != null && selectedGpxFile.getGpxFile() != null) { if (selectedGpxFile != null && selectedGpxFile.getGpxFile() != null) {
GPXFile gpxFile = selectedGpxFile.getGpxFile(); GPXFile gpxFile = selectedGpxFile.getGpxFile();
List<GpxDisplayGroup> groups = app.getSelectedGpxHelper().collectDisplayGroups(gpxFile); List<GpxDisplayGroup> groups = app.getSelectedGpxHelper().collectDisplayGroups(gpxFile);
if (dataItem.getSplitType() == GPXDatabase.GPX_SPLIT_TYPE_NO_SPLIT) { if (dataItem.getSplitType() == GpxSplitType.NO_SPLIT.getType()) {
for (GpxDisplayGroup model : groups) { for (GpxDisplayGroup model : groups) {
model.noSplit(app); model.noSplit(app);
} }
selectedGpxFile.setDisplayGroups(groups, app); selectedGpxFile.setDisplayGroups(groups, app);
} else if (dataItem.getSplitType() == GPXDatabase.GPX_SPLIT_TYPE_DISTANCE) { } else if (dataItem.getSplitType() == GpxSplitType.DISTANCE.getType()) {
for (GpxDisplayGroup model : groups) { for (GpxDisplayGroup model : groups) {
model.splitByDistance(app, dataItem.getSplitInterval(), dataItem.isJoinSegments()); model.splitByDistance(app, dataItem.getSplitInterval(), dataItem.isJoinSegments());
} }
selectedGpxFile.setDisplayGroups(groups, app); selectedGpxFile.setDisplayGroups(groups, app);
} else if (dataItem.getSplitType() == GPXDatabase.GPX_SPLIT_TYPE_TIME) { } else if (dataItem.getSplitType() == GpxSplitType.TIME.getType()) {
for (GpxDisplayGroup model : groups) { for (GpxDisplayGroup model : groups) {
model.splitByTime(app, (int) dataItem.getSplitInterval(), dataItem.isJoinSegments()); model.splitByTime(app, (int) dataItem.getSplitInterval(), dataItem.isJoinSegments());
} }

View file

@ -1027,6 +1027,10 @@ public class ImportHelper {
item.setGradientSlopeColor(gpxFile.getGradientScaleColor(GradientScaleType.SLOPE, 0)); item.setGradientSlopeColor(gpxFile.getGradientScaleColor(GradientScaleType.SLOPE, 0));
item.setGradientAltitudeColor(gpxFile.getGradientScaleColor(GradientScaleType.ALTITUDE, 0)); item.setGradientAltitudeColor(gpxFile.getGradientScaleColor(GradientScaleType.ALTITUDE, 0));
app.getGpxDbHelper().add(item); app.getGpxDbHelper().add(item);
if (gpxFile.getSplitType() != null && gpxFile.getSplitInterval() != 0) {
app.getGpxDbHelper().updateSplit(item, gpxFile.getSplitType(), gpxFile.getSplitInterval());
}
} else { } else {
GPXDatabase.GpxDataItem item = app.getGpxDbHelper().getItem(file); GPXDatabase.GpxDataItem item = app.getGpxDbHelper().getItem(file);
if (item != null) { if (item != null) {

View file

@ -39,12 +39,12 @@ import com.squareup.picasso.RequestCreator;
import net.osmand.AndroidUtils; import net.osmand.AndroidUtils;
import net.osmand.GPXUtilities; import net.osmand.GPXUtilities;
import net.osmand.GPXUtilities.GPXFile; import net.osmand.GPXUtilities.GPXFile;
import net.osmand.GPXUtilities.GPXFile.GpxSplitType;
import net.osmand.GPXUtilities.WptPt; import net.osmand.GPXUtilities.WptPt;
import net.osmand.PicassoUtils; import net.osmand.PicassoUtils;
import net.osmand.data.LatLon; import net.osmand.data.LatLon;
import net.osmand.data.PointDescription; import net.osmand.data.PointDescription;
import net.osmand.data.QuadRect; import net.osmand.data.QuadRect;
import net.osmand.plus.GPXDatabase;
import net.osmand.plus.GPXDatabase.GpxDataItem; import net.osmand.plus.GPXDatabase.GpxDataItem;
import net.osmand.plus.GpxSelectionHelper; import net.osmand.plus.GpxSelectionHelper;
import net.osmand.plus.GpxSelectionHelper.GpxDisplayGroup; import net.osmand.plus.GpxSelectionHelper.GpxDisplayGroup;
@ -764,9 +764,9 @@ public class TrackActivityFragmentAdapter implements TrackBitmapDrawerListener {
double splitInterval = getGpxDataItem().getSplitInterval(); double splitInterval = getGpxDataItem().getSplitInterval();
int position = 0; int position = 0;
if (splitType == GPXDatabase.GPX_SPLIT_TYPE_DISTANCE) { if (splitType == GpxSplitType.DISTANCE.getType()) {
position = distanceSplit.indexOf(splitInterval); position = distanceSplit.indexOf(splitInterval);
} else if (splitType == GPXDatabase.GPX_SPLIT_TYPE_TIME) { } else if (splitType == GpxSplitType.TIME.getType()) {
position = timeSplit.indexOf((int) splitInterval); position = timeSplit.indexOf((int) splitInterval);
} }
@ -877,20 +877,20 @@ public class TrackActivityFragmentAdapter implements TrackBitmapDrawerListener {
} }
private void updateSplitInDatabase() { private void updateSplitInDatabase() {
int splitType = 0;
double splitInterval = 0; double splitInterval = 0;
GpxSplitType splitType = null;
if (selectedSplitInterval == 0) { if (selectedSplitInterval == 0) {
splitType = GPXDatabase.GPX_SPLIT_TYPE_NO_SPLIT; splitType = GpxSplitType.NO_SPLIT;
splitInterval = 0; splitInterval = 0;
} else if (distanceSplit.get(selectedSplitInterval) > 0) { } else if (distanceSplit.get(selectedSplitInterval) > 0) {
splitType = GPXDatabase.GPX_SPLIT_TYPE_DISTANCE; splitType = GpxSplitType.DISTANCE;
splitInterval = distanceSplit.get(selectedSplitInterval); splitInterval = distanceSplit.get(selectedSplitInterval);
} else if (timeSplit.get(selectedSplitInterval) > 0) { } else if (timeSplit.get(selectedSplitInterval) > 0) {
splitType = GPXDatabase.GPX_SPLIT_TYPE_TIME; splitType = GpxSplitType.TIME;
splitInterval = timeSplit.get(selectedSplitInterval); splitInterval = timeSplit.get(selectedSplitInterval);
} }
GpxDataItem item = getGpxDataItem(); GpxDataItem item = getGpxDataItem();
if (item != null) { if (item != null && splitType != null) {
app.getGpxDbHelper().updateSplit(item, splitType, splitInterval); app.getGpxDbHelper().updateSplit(item, splitType, splitInterval);
} }
} }