diff --git a/OsmAnd/src/net/osmand/plus/GPXDatabase.java b/OsmAnd/src/net/osmand/plus/GPXDatabase.java index ba538f1b1d..5403c814ca 100644 --- a/OsmAnd/src/net/osmand/plus/GPXDatabase.java +++ b/OsmAnd/src/net/osmand/plus/GPXDatabase.java @@ -210,26 +210,19 @@ public class GPXDatabase { width = gpxFile.getWidth(null); showArrows = gpxFile.isShowArrows(); showStartFinish = gpxFile.isShowStartFinish(); - gradientSpeedColor = gpxFile.getGradientScaleColor(GradientScaleType.SPEED.getTypeName(), 0); - gradientSlopeColor = gpxFile.getGradientScaleColor(GradientScaleType.SLOPE.getTypeName(), 0); - gradientAltitudeColor = gpxFile.getGradientScaleColor(GradientScaleType.ALTITUDE.getTypeName(), 0); + gradientSpeedColor = gpxFile.getGradientScaleColor(GradientScaleType.SPEED.getColorTypeName(), 0); + gradientSlopeColor = gpxFile.getGradientScaleColor(GradientScaleType.SLOPE.getColorTypeName(), 0); + gradientAltitudeColor = gpxFile.getGradientScaleColor(GradientScaleType.ALTITUDE.getColorTypeName(), 0); - if (!Algorithms.isEmpty(gpxFile.getSplitType()) && gpxFile.getSplitInterval() != 0) { - for (GpxSplitType gpxSplitType : GpxSplitType.values()) { - if (gpxSplitType.name().equalsIgnoreCase(gpxFile.getSplitType())) { - splitType = gpxSplitType.getType(); - splitInterval = gpxFile.getSplitInterval(); - break; - } + if (!Algorithms.isEmpty(gpxFile.getSplitType()) && gpxFile.getSplitInterval() > 0) { + GpxSplitType gpxSplitType = GpxSplitType.getSplitTypeByName(gpxFile.getSplitType()); + if (gpxSplitType != null) { + splitType = gpxSplitType.getType(); + splitInterval = gpxFile.getSplitInterval(); } } if (!Algorithms.isEmpty(gpxFile.getGradientScaleType())) { - for (GradientScaleType scaleType : GradientScaleType.values()) { - if (scaleType.name().equalsIgnoreCase(gpxFile.getGradientScaleType())) { - gradientScaleType = scaleType; - break; - } - } + gradientScaleType = GradientScaleType.getGradientTypeByName(gpxFile.getGradientScaleType()); } } @@ -547,7 +540,7 @@ public class GPXDatabase { String fileDir = getFileDir(item.file); db.execSQL("UPDATE " + GPX_TABLE_NAME + " SET " + GPX_COL_GRADIENT_SCALE_TYPE + " = ? " + " WHERE " + GPX_COL_NAME + " = ? AND " + GPX_COL_DIR + " = ?", - new Object[] {(gradientScaleType == null ? "" : gradientScaleType.name()), fileName, fileDir}); + new Object[] {(gradientScaleType == null ? "" : gradientScaleType.getTypeName()), fileName, fileDir}); item.gradientScaleType = gradientScaleType; } finally { db.close(); @@ -723,7 +716,7 @@ public class GPXDatabase { } else { color = Algorithms.colorToString(item.color); } - String gradientScaleType = item.gradientScaleType != null ? item.gradientScaleType.name() : null; + String gradientScaleType = item.gradientScaleType != null ? item.gradientScaleType.getTypeName() : null; if (a != null) { db.execSQL( "INSERT INTO " + GPX_TABLE_NAME + " VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", diff --git a/OsmAnd/src/net/osmand/plus/GpxSelectionHelper.java b/OsmAnd/src/net/osmand/plus/GpxSelectionHelper.java index 687ede9f28..39ddfcfd96 100644 --- a/OsmAnd/src/net/osmand/plus/GpxSelectionHelper.java +++ b/OsmAnd/src/net/osmand/plus/GpxSelectionHelper.java @@ -173,19 +173,21 @@ public class GpxSelectionHelper { if (selectedGpxFile != null && selectedGpxFile.getGpxFile() != null) { GPXFile gpxFile = selectedGpxFile.getGpxFile(); List groups = app.getSelectedGpxHelper().collectDisplayGroups(gpxFile); - if (dataItem.getSplitType() == GpxSplitType.NO_SPLIT.getType()) { - for (GpxDisplayGroup model : groups) { - model.noSplit(app); - } - selectedGpxFile.setDisplayGroups(groups, app); - } else if (dataItem.getSplitType() == GpxSplitType.DISTANCE.getType()) { - for (GpxDisplayGroup model : groups) { - model.splitByDistance(app, dataItem.getSplitInterval(), dataItem.isJoinSegments()); - } - selectedGpxFile.setDisplayGroups(groups, app); - } else if (dataItem.getSplitType() == GpxSplitType.TIME.getType()) { - for (GpxDisplayGroup model : groups) { - model.splitByTime(app, (int) dataItem.getSplitInterval(), dataItem.isJoinSegments()); + + GpxSplitType splitType = GpxSplitType.getSplitTypeByTypeId(dataItem.getSplitType()); + if (splitType != null) { + if (splitType == GpxSplitType.NO_SPLIT) { + for (GpxDisplayGroup model : groups) { + model.noSplit(app); + } + } else if (splitType == GpxSplitType.DISTANCE) { + for (GpxDisplayGroup model : groups) { + model.splitByDistance(app, dataItem.getSplitInterval(), dataItem.isJoinSegments()); + } + } else if (splitType == GpxSplitType.TIME) { + for (GpxDisplayGroup model : groups) { + model.splitByTime(app, (int) dataItem.getSplitInterval(), dataItem.isJoinSegments()); + } } selectedGpxFile.setDisplayGroups(groups, app); } @@ -522,9 +524,9 @@ public class GpxSelectionHelper { gpx.setColor(clr); } for (GradientScaleType scaleType : GradientScaleType.values()) { - if (obj.has(scaleType.getTypeName())) { - int clr = Algorithms.parseColor(obj.getString(scaleType.getTypeName())); - gpx.setGradientScaleColor(scaleType.getTypeName(), clr); + if (obj.has(scaleType.getColorTypeName())) { + int clr = Algorithms.parseColor(obj.getString(scaleType.getColorTypeName())); + gpx.setGradientScaleColor(scaleType.getColorTypeName(), clr); } } if (obj.has(SHOW_ARROWS)) { @@ -587,9 +589,9 @@ public class GpxSelectionHelper { obj.put(SHOW_ARROWS, s.gpxFile.isShowArrows()); obj.put(SHOW_START_FINISH, s.gpxFile.isShowStartFinish()); for (GradientScaleType scaleType : GradientScaleType.values()) { - int gradientScaleColor = s.gpxFile.getGradientScaleColor(scaleType.getTypeName(), 0); + int gradientScaleColor = s.gpxFile.getGradientScaleColor(scaleType.getColorTypeName(), 0); if (gradientScaleColor != 0) { - obj.put(scaleType.getTypeName(), Algorithms.colorToString(gradientScaleColor)); + obj.put(scaleType.getColorTypeName(), Algorithms.colorToString(gradientScaleColor)); } } } @@ -645,16 +647,16 @@ public class GpxSelectionHelper { gpx.setColor(dataItem.getColor()); } if (dataItem.getGradientSpeedColor() != 0) { - gpx.setGradientScaleColor(GradientScaleType.SPEED.getTypeName(), dataItem.getGradientSpeedColor()); + gpx.setGradientScaleColor(GradientScaleType.SPEED.getColorTypeName(), dataItem.getGradientSpeedColor()); } if (dataItem.getGradientAltitudeColor() != 0) { - gpx.setGradientScaleColor(GradientScaleType.ALTITUDE.getTypeName(), dataItem.getGradientAltitudeColor()); + gpx.setGradientScaleColor(GradientScaleType.ALTITUDE.getColorTypeName(), dataItem.getGradientAltitudeColor()); } if (dataItem.getGradientSlopeColor() != 0) { - gpx.setGradientScaleColor(GradientScaleType.SLOPE.getTypeName(), dataItem.getGradientSlopeColor()); + gpx.setGradientScaleColor(GradientScaleType.SLOPE.getColorTypeName(), dataItem.getGradientSlopeColor()); } if (dataItem.getGradientScaleType() != null) { - gpx.setGradientScaleType(dataItem.getGradientScaleType().name()); + gpx.setGradientScaleType(dataItem.getGradientScaleType().getTypeName()); } if (dataItem.getWidth() != null) { gpx.setWidth(dataItem.getWidth()); diff --git a/OsmAnd/src/net/osmand/plus/track/GpxSplitType.java b/OsmAnd/src/net/osmand/plus/track/GpxSplitType.java index 76659a36ce..ee539b8302 100644 --- a/OsmAnd/src/net/osmand/plus/track/GpxSplitType.java +++ b/OsmAnd/src/net/osmand/plus/track/GpxSplitType.java @@ -9,15 +9,17 @@ import net.osmand.plus.R; public enum GpxSplitType { - NO_SPLIT(-1, R.string.shared_string_none), - DISTANCE(1, R.string.distance), - TIME(2, R.string.shared_string_time); + NO_SPLIT("no_split", -1, R.string.shared_string_none), + DISTANCE("distance", 1, R.string.distance), + TIME("time", 2, R.string.shared_string_time); + private String typeName; private int type; @StringRes private int resId; - GpxSplitType(int type, @StringRes int resId) { + GpxSplitType(@NonNull String typeName, int type, @StringRes int resId) { + this.typeName = typeName; this.type = type; this.resId = resId; } @@ -26,7 +28,29 @@ public enum GpxSplitType { return type; } + public String getTypeName() { + return typeName; + } + public String getHumanString(@NonNull Context ctx) { return ctx.getString(resId); } + + public static GpxSplitType getSplitTypeByName(@NonNull String name) { + for (GpxSplitType splitType : GpxSplitType.values()) { + if (splitType.name().equalsIgnoreCase(name)) { + return splitType; + } + } + return null; + } + + public static GpxSplitType getSplitTypeByTypeId(int typeId) { + for (GpxSplitType splitType : GpxSplitType.values()) { + if (splitType.getType() == typeId) { + return splitType; + } + } + return null; + } } \ No newline at end of file diff --git a/OsmAnd/src/net/osmand/plus/track/GradientScaleType.java b/OsmAnd/src/net/osmand/plus/track/GradientScaleType.java index a9fd56aef4..f237c1e721 100644 --- a/OsmAnd/src/net/osmand/plus/track/GradientScaleType.java +++ b/OsmAnd/src/net/osmand/plus/track/GradientScaleType.java @@ -10,18 +10,20 @@ import net.osmand.plus.R; public enum GradientScaleType { - SPEED("gradient_speed_color", R.string.map_widget_speed, R.drawable.ic_action_speed), - ALTITUDE("gradient_altitude_color", R.string.altitude, R.drawable.ic_action_altitude_average), - SLOPE("gradient_slope_color", R.string.shared_string_slope, R.drawable.ic_action_altitude_ascent); + SPEED("speed", "gradient_speed_color", R.string.map_widget_speed, R.drawable.ic_action_speed), + ALTITUDE("altitude", "gradient_altitude_color", R.string.altitude, R.drawable.ic_action_altitude_average), + SLOPE("slope", "gradient_slope_color", R.string.shared_string_slope, R.drawable.ic_action_altitude_ascent); private String typeName; + private String colorTypeName; @StringRes private int resId; @DrawableRes private int iconId; - GradientScaleType(@NonNull String typeName, @StringRes int resId, @DrawableRes int iconId) { + GradientScaleType(@NonNull String typeName, @NonNull String colorTypeName, @StringRes int resId, @DrawableRes int iconId) { this.typeName = typeName; + this.colorTypeName = colorTypeName; this.resId = resId; this.iconId = iconId; } @@ -30,6 +32,10 @@ public enum GradientScaleType { return typeName; } + public String getColorTypeName() { + return colorTypeName; + } + public int getIconId() { return iconId; } @@ -37,4 +43,13 @@ public enum GradientScaleType { public String getHumanString(@NonNull Context ctx) { return ctx.getString(resId); } + + public static GradientScaleType getGradientTypeByName(@NonNull String name) { + for (GradientScaleType scaleType : GradientScaleType.values()) { + if (scaleType.name().equalsIgnoreCase(name)) { + return scaleType; + } + } + return null; + } } \ No newline at end of file diff --git a/OsmAnd/src/net/osmand/plus/track/TrackAppearanceFragment.java b/OsmAnd/src/net/osmand/plus/track/TrackAppearanceFragment.java index 8f72e95087..ef578f90f2 100644 --- a/OsmAnd/src/net/osmand/plus/track/TrackAppearanceFragment.java +++ b/OsmAnd/src/net/osmand/plus/track/TrackAppearanceFragment.java @@ -311,11 +311,9 @@ public class TrackAppearanceFragment extends ContextMenuFragment implements Card } gpxFile.setColor(trackDrawInfo.getColor()); - for (GpxSplitType gpxSplitType : GpxSplitType.values()) { - if (gpxSplitType.getType() == trackDrawInfo.getSplitType()) { - gpxFile.setSplitType(gpxSplitType.name()); - break; - } + GpxSplitType splitType = GpxSplitType.getSplitTypeByTypeId(trackDrawInfo.getSplitType()); + if (splitType != null) { + gpxFile.setSplitType(splitType.getTypeName()); } gpxFile.setSplitInterval(trackDrawInfo.getSplitInterval()); @@ -334,12 +332,8 @@ public class TrackAppearanceFragment extends ContextMenuFragment implements Card int timeSplit = (int) gpxDataItem.getSplitInterval(); double distanceSplit = gpxDataItem.getSplitInterval(); - GpxSplitType splitType; - if (gpxDataItem.getSplitType() == GpxSplitType.DISTANCE.getType()) { - splitType = GpxSplitType.DISTANCE; - } else if (gpxDataItem.getSplitType() == GpxSplitType.TIME.getType()) { - splitType = GpxSplitType.TIME; - } else { + GpxSplitType splitType = GpxSplitType.getSplitTypeByTypeId(gpxDataItem.getSplitType()); + if (splitType == null) { splitType = GpxSplitType.NO_SPLIT; } SplitTrackAsyncTask.SplitTrackListener splitTrackListener = new SplitTrackAsyncTask.SplitTrackListener() { diff --git a/OsmAnd/src/net/osmand/plus/track/TrackColoringCard.java b/OsmAnd/src/net/osmand/plus/track/TrackColoringCard.java index 14a2313c1c..fbc9eebcdc 100644 --- a/OsmAnd/src/net/osmand/plus/track/TrackColoringCard.java +++ b/OsmAnd/src/net/osmand/plus/track/TrackColoringCard.java @@ -72,7 +72,7 @@ public class TrackColoringCard extends BaseCard { items.add(new TrackAppearanceItem(SOLID_COLOR, app.getString(R.string.track_coloring_solid), R.drawable.ic_action_circle)); // for (GradientScaleType scaleType : GradientScaleType.values()) { -// items.add(new TrackAppearanceItem(scaleType.name(), scaleType.getHumanString(app), scaleType.getIconId())); +// items.add(new TrackAppearanceItem(scaleType.getTypeName(), scaleType.getHumanString(app), scaleType.getIconId())); // } return items; @@ -139,7 +139,7 @@ public class TrackColoringCard extends BaseCard { GradientScaleType scaleType = trackDrawInfo.getGradientScaleType(); for (TrackAppearanceItem item : appearanceItems) { if (scaleType == null && item.getAttrName().equals(SOLID_COLOR) - || scaleType != null && scaleType.name().equals(item.getAttrName())) { + || scaleType != null && scaleType.getTypeName().equals(item.getAttrName())) { selectedAppearanceItem = item; break; } diff --git a/OsmAnd/src/net/osmand/plus/track/TrackDrawInfo.java b/OsmAnd/src/net/osmand/plus/track/TrackDrawInfo.java index a2934cebea..d915e8c519 100644 --- a/OsmAnd/src/net/osmand/plus/track/TrackDrawInfo.java +++ b/OsmAnd/src/net/osmand/plus/track/TrackDrawInfo.java @@ -123,7 +123,7 @@ public class TrackDrawInfo { protected void saveToBundle(@NonNull Bundle bundle) { bundle.putString(TRACK_FILE_PATH, filePath); bundle.putString(TRACK_WIDTH, width); - bundle.putString(TRACK_GRADIENT_SCALE_TYPE, gradientScaleType != null ? gradientScaleType.name() : ""); + bundle.putString(TRACK_GRADIENT_SCALE_TYPE, gradientScaleType != null ? gradientScaleType.getTypeName() : ""); bundle.putInt(TRACK_COLOR, color); bundle.putInt(TRACK_SPLIT_TYPE, splitType); bundle.putDouble(TRACK_SPLIT_INTERVAL, splitInterval);