Implement colorization type in settings

This commit is contained in:
cepprice 2021-03-08 21:32:19 +05:00
parent 908033e0a9
commit a6cedd2767
11 changed files with 111 additions and 63 deletions

View file

@ -1662,16 +1662,16 @@ public class GPXUtilities {
return new QuadRect(left, top, right, bottom); return new QuadRect(left, top, right, bottom);
} }
public int getGradientScaleColor(String gradientScaleType, int defColor) { public int[] getGradientScaleColor(String gradientScaleType) {
String clrValue = null; String clrValue = null;
if (extensions != null) { if (extensions != null) {
clrValue = extensions.get(gradientScaleType); clrValue = extensions.get(gradientScaleType);
} }
return parseColor(clrValue, defColor); return Algorithms.stringToGradientPalette(clrValue);
} }
public void setGradientScaleColor(String gradientScaleType, int gradientScaleColor) { public void setGradientScaleColor(String gradientScaleType, int[] gradientScalePalette) {
getExtensionsToWrite().put(gradientScaleType, Algorithms.colorToString(gradientScaleColor)); getExtensionsToWrite().put(gradientScaleType, Algorithms.gradientPaletteToString(gradientScalePalette));
} }
public String getGradientScaleType() { public String getGradientScaleType() {

View file

@ -24,11 +24,12 @@ public class RouteColorize {
public static final int DARK_GREY = rgbaToDecimal(92, 92, 92, 255); public static final int DARK_GREY = rgbaToDecimal(92, 92, 92, 255);
public static final int LIGHT_GREY = rgbaToDecimal(200, 200, 200, 255); public static final int LIGHT_GREY = rgbaToDecimal(200, 200, 200, 255);
public static final int RED = rgbaToDecimal(255,1,1,255); public static final int GREEN = rgbaToDecimal(90, 220, 95, 1);
public static final int GREEN = rgbaToDecimal(46,185,0,191); public static final int YELLOW = rgbaToDecimal(212, 239, 50, 1);
public static final int YELLOW = rgbaToDecimal(255,222,2,227); public static final int RED = rgbaToDecimal(243, 55, 77, 1);
public static final int[] colors = new int[] {GREEN, YELLOW, RED};
public enum ValueType { public enum ColorizationType {
ELEVATION, ELEVATION,
SPEED, SPEED,
SLOPE, SLOPE,
@ -42,7 +43,7 @@ public class RouteColorize {
private final int BLUE_COLOR_INDEX = 3;//RGB private final int BLUE_COLOR_INDEX = 3;//RGB
private final int ALPHA_COLOR_INDEX = 4;//RGBA private final int ALPHA_COLOR_INDEX = 4;//RGBA
private ValueType valueType; private ColorizationType colorizationType;
public static int SLOPE_RANGE = 150;//150 meters public static int SLOPE_RANGE = 150;//150 meters
private static final double MIN_DIFFERENCE_SLOPE = 0.05d;//5% private static final double MIN_DIFFERENCE_SLOPE = 0.05d;//5%
@ -73,7 +74,7 @@ public class RouteColorize {
/** /**
* @param type ELEVATION, SPEED, SLOPE * @param type ELEVATION, SPEED, SLOPE
*/ */
public RouteColorize(int zoom, GPXUtilities.GPXFile gpxFile, ValueType type) { public RouteColorize(int zoom, GPXUtilities.GPXFile gpxFile, ColorizationType type) {
if (!gpxFile.hasTrkPt()) { if (!gpxFile.hasTrkPt()) {
LOG.warn("GPX file is not consist of track points"); LOG.warn("GPX file is not consist of track points");
@ -88,7 +89,7 @@ public class RouteColorize {
for (GPXUtilities.WptPt p : ts.points) { for (GPXUtilities.WptPt p : ts.points) {
latList.add(p.lat); latList.add(p.lat);
lonList.add(p.lon); lonList.add(p.lon);
if (type == ValueType.SPEED) { if (type == ColorizationType.SPEED) {
valList.add(p.speed); valList.add(p.speed);
} else { } else {
valList.add(p.ele); valList.add(p.ele);
@ -101,14 +102,14 @@ public class RouteColorize {
latitudes = listToArray(latList); latitudes = listToArray(latList);
longitudes = listToArray(lonList); longitudes = listToArray(lonList);
if (type == ValueType.SLOPE) { if (type == ColorizationType.SLOPE) {
values = calculateSlopesByElevations(latitudes, longitudes, listToArray(valList), SLOPE_RANGE); values = calculateSlopesByElevations(latitudes, longitudes, listToArray(valList), SLOPE_RANGE);
} else { } else {
values = listToArray(valList); values = listToArray(valList);
} }
calculateMinMaxValue(); calculateMinMaxValue();
valueType = type; colorizationType = type;
checkPalette(); checkPalette();
sortPalette(); sortPalette();
} }
@ -282,7 +283,7 @@ public class RouteColorize {
double[][] defaultPalette = { double[][] defaultPalette = {
{minValue, GREEN}, {minValue, GREEN},
{valueType == ValueType.SLOPE ? 0 : (minValue + maxValue) / 2, YELLOW}, {colorizationType == ColorizationType.SLOPE ? 0 : (minValue + maxValue) / 2, YELLOW},
{maxValue, RED} {maxValue, RED}
}; };
palette = defaultPalette; palette = defaultPalette;

View file

@ -2,6 +2,7 @@ package net.osmand.util;
import net.osmand.IProgress; import net.osmand.IProgress;
import net.osmand.PlatformUtil; import net.osmand.PlatformUtil;
import net.osmand.router.RouteColorize;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.xmlpull.v1.XmlPullParser; import org.xmlpull.v1.XmlPullParser;
@ -1027,4 +1028,30 @@ public class Algorithms {
} }
return false; return false;
} }
public static int[] stringToGradientPalette(String str) {
if (Algorithms.isBlank(str)) {
return RouteColorize.colors;
}
String[] arr = str.split(" ");
if (arr.length != 3) {
return RouteColorize.colors;
}
int[] colors = new int[3];
try {
for (int i = 0; i < 3; i++) {
colors[i] = Algorithms.parseColor(arr[i]);
}
} catch (IllegalArgumentException e) {
return RouteColorize.colors;
}
return colors;
}
public static String gradientPaletteToString(int[] colors) {
int[] src = colors.length == 3 ? colors : RouteColorize.colors;
return Algorithms.colorToString(src[0]) + " " +
Algorithms.colorToString(src[1]) + " " +
Algorithms.colorToString(src[2]);
}
} }

View file

@ -178,9 +178,9 @@ public class GPXDatabase {
private String width; private String width;
private GradientScaleType gradientScaleType; private GradientScaleType gradientScaleType;
private int color; private int color;
private int gradientSpeedColor; private int[] gradientSpeedPalette;
private int gradientAltitudeColor; private int[] gradientAltitudePalette;
private int gradientSlopeColor; private int[] gradientSlopePalette;
private int splitType; private int splitType;
private double splitInterval; private double splitInterval;
private long fileLastModifiedTime; private long fileLastModifiedTime;
@ -210,9 +210,9 @@ public class GPXDatabase {
width = gpxFile.getWidth(null); width = gpxFile.getWidth(null);
showArrows = gpxFile.isShowArrows(); showArrows = gpxFile.isShowArrows();
showStartFinish = gpxFile.isShowStartFinish(); showStartFinish = gpxFile.isShowStartFinish();
gradientSpeedColor = gpxFile.getGradientScaleColor(GradientScaleType.SPEED.getColorTypeName(), 0); gradientSpeedPalette = gpxFile.getGradientScaleColor(GradientScaleType.SPEED.getColorTypeName());
gradientSlopeColor = gpxFile.getGradientScaleColor(GradientScaleType.SLOPE.getColorTypeName(), 0); gradientSlopePalette = gpxFile.getGradientScaleColor(GradientScaleType.SLOPE.getColorTypeName());
gradientAltitudeColor = gpxFile.getGradientScaleColor(GradientScaleType.ALTITUDE.getColorTypeName(), 0); gradientAltitudePalette = gpxFile.getGradientScaleColor(GradientScaleType.ALTITUDE.getColorTypeName());
if (!Algorithms.isEmpty(gpxFile.getSplitType()) && gpxFile.getSplitInterval() > 0) { if (!Algorithms.isEmpty(gpxFile.getSplitType()) && gpxFile.getSplitInterval() > 0) {
GpxSplitType gpxSplitType = GpxSplitType.getSplitTypeByName(gpxFile.getSplitType()); GpxSplitType gpxSplitType = GpxSplitType.getSplitTypeByName(gpxFile.getSplitType());
@ -243,23 +243,22 @@ public class GPXDatabase {
return gradientScaleType; return gradientScaleType;
} }
public int getGradientSpeedColor() { public int[] getGradientSpeedPalette() {
return gradientSpeedColor; return gradientSpeedPalette;
} }
public int getGradientAltitudeColor() { public int[] getGradientAltitudePalette() {
return gradientAltitudeColor; return gradientAltitudePalette;
} }
public int getGradientSlopeColor() { public int[] getGradientSlopePalette() {
return gradientSlopeColor; return gradientSlopePalette;
} }
public String getWidth() { public String getWidth() {
return width; return width;
} }
public long getFileLastModifiedTime() { public long getFileLastModifiedTime() {
return fileLastModifiedTime; return fileLastModifiedTime;
} }
@ -507,7 +506,7 @@ public class GPXDatabase {
return false; return false;
} }
public boolean updateGradientScaleColor(@NonNull GpxDataItem item, @NonNull GradientScaleType gradientScaleType, int gradientScaleColor) { public boolean updateGradientScaleColor(@NonNull GpxDataItem item, @NonNull GradientScaleType gradientScaleType, int[] gradientScalePalette) {
SQLiteConnection db = openConnection(false); SQLiteConnection db = openConnection(false);
if (db != null) { if (db != null) {
try { try {
@ -516,17 +515,17 @@ public class GPXDatabase {
String columnName = null; String columnName = null;
if (GradientScaleType.SPEED == gradientScaleType) { if (GradientScaleType.SPEED == gradientScaleType) {
columnName = GPX_COL_GRADIENT_SPEED_COLOR; columnName = GPX_COL_GRADIENT_SPEED_COLOR;
item.gradientSpeedColor = gradientScaleColor; item.gradientSpeedPalette = gradientScalePalette;
} else if (GradientScaleType.ALTITUDE == gradientScaleType) { } else if (GradientScaleType.ALTITUDE == gradientScaleType) {
columnName = GPX_COL_GRADIENT_ALTITUDE_COLOR; columnName = GPX_COL_GRADIENT_ALTITUDE_COLOR;
item.gradientAltitudeColor = gradientScaleColor; item.gradientAltitudePalette = gradientScalePalette;
} else if (GradientScaleType.SLOPE == gradientScaleType) { } else if (GradientScaleType.SLOPE == gradientScaleType) {
columnName = GPX_COL_GRADIENT_SLOPE_COLOR; columnName = GPX_COL_GRADIENT_SLOPE_COLOR;
item.gradientSlopeColor = gradientScaleColor; item.gradientSlopePalette = gradientScalePalette;
} }
db.execSQL("UPDATE " + GPX_TABLE_NAME + " SET " + columnName + " = ? " + db.execSQL("UPDATE " + GPX_TABLE_NAME + " SET " + columnName + " = ? " +
" WHERE " + GPX_COL_NAME + " = ? AND " + GPX_COL_DIR + " = ?", " WHERE " + GPX_COL_NAME + " = ? AND " + GPX_COL_DIR + " = ?",
new Object[] {(gradientScaleColor == 0 ? "" : Algorithms.colorToString(gradientScaleColor)), fileName, fileDir}); new Object[] {Algorithms.gradientPaletteToString(gradientScalePalette), fileName, fileDir});
} finally { } finally {
db.close(); db.close();
} }
@ -729,7 +728,7 @@ public class GPXDatabase {
color, item.file.lastModified(), item.splitType, item.splitInterval, item.apiImported ? 1 : 0, color, item.file.lastModified(), item.splitType, item.splitInterval, item.apiImported ? 1 : 0,
Algorithms.encodeStringSet(item.analysis.wptCategoryNames), item.showAsMarkers ? 1 : 0, Algorithms.encodeStringSet(item.analysis.wptCategoryNames), item.showAsMarkers ? 1 : 0,
item.joinSegments ? 1 : 0, item.showArrows ? 1 : 0, item.showStartFinish ? 1 : 0, item.width, item.joinSegments ? 1 : 0, item.showArrows ? 1 : 0, item.showStartFinish ? 1 : 0, item.width,
item.gradientSpeedColor, item.gradientAltitudeColor, item.gradientSlopeColor, gradientScaleType}); item.gradientSpeedPalette, item.gradientAltitudePalette, item.gradientSlopePalette, gradientScaleType});
} else { } else {
db.execSQL("INSERT INTO " + GPX_TABLE_NAME + "(" + db.execSQL("INSERT INTO " + GPX_TABLE_NAME + "(" +
GPX_COL_NAME + ", " + GPX_COL_NAME + ", " +
@ -752,7 +751,7 @@ public class GPXDatabase {
new Object[] {fileName, fileDir, color, 0, item.splitType, item.splitInterval, new Object[] {fileName, fileDir, color, 0, item.splitType, item.splitInterval,
item.apiImported ? 1 : 0, item.showAsMarkers ? 1 : 0, item.joinSegments ? 1 : 0, item.apiImported ? 1 : 0, item.showAsMarkers ? 1 : 0, item.joinSegments ? 1 : 0,
item.showArrows ? 1 : 0, item.showStartFinish ? 1 : 0, item.width, item.showArrows ? 1 : 0, item.showStartFinish ? 1 : 0, item.width,
item.gradientSpeedColor, item.gradientAltitudeColor, item.gradientSlopeColor, gradientScaleType}); item.gradientSpeedPalette, item.gradientAltitudePalette, item.gradientSlopePalette, gradientScaleType});
} }
} }
@ -836,9 +835,9 @@ public class GPXDatabase {
boolean showArrows = query.getInt(26) == 1; boolean showArrows = query.getInt(26) == 1;
boolean showStartFinish = query.getInt(27) == 1; boolean showStartFinish = query.getInt(27) == 1;
String width = query.getString(28); String width = query.getString(28);
String gradientSpeedColor = query.getString(29); String gradientSpeedPalette = query.getString(29);
String gradientAltitudeColor = query.getString(30); String gradientAltitudePalette = query.getString(30);
String gradientSlopeColor = query.getString(31); String gradientSlopePalette = query.getString(31);
String gradientScaleType = query.getString(32); String gradientScaleType = query.getString(32);
GPXTrackAnalysis a = new GPXTrackAnalysis(); GPXTrackAnalysis a = new GPXTrackAnalysis();
@ -880,9 +879,9 @@ public class GPXDatabase {
item.showArrows = showArrows; item.showArrows = showArrows;
item.showStartFinish = showStartFinish; item.showStartFinish = showStartFinish;
item.width = width; item.width = width;
item.gradientSpeedColor = parseColor(gradientSpeedColor); item.gradientSpeedPalette = Algorithms.stringToGradientPalette(gradientSpeedPalette);
item.gradientAltitudeColor = parseColor(gradientAltitudeColor); item.gradientAltitudePalette = Algorithms.stringToGradientPalette(gradientAltitudePalette);
item.gradientSlopeColor = parseColor(gradientSlopeColor); item.gradientSlopePalette = Algorithms.stringToGradientPalette(gradientSlopePalette);
try { try {
item.gradientScaleType = Algorithms.isEmpty(gradientScaleType) ? null : GradientScaleType.valueOf(gradientScaleType); item.gradientScaleType = Algorithms.isEmpty(gradientScaleType) ? null : GradientScaleType.valueOf(gradientScaleType);

View file

@ -78,8 +78,8 @@ public class GpxDbHelper {
return res; return res;
} }
public boolean updateGradientScaleColor(@NonNull GpxDataItem item, @NonNull GradientScaleType gradientScaleType, int color) { public boolean updateGradientScaleColor(@NonNull GpxDataItem item, @NonNull GradientScaleType gradientScaleType, int[] palette) {
boolean res = db.updateGradientScaleColor(item, gradientScaleType, color); boolean res = db.updateGradientScaleColor(item, gradientScaleType, palette);
putToCache(item); putToCache(item);
return res; return res;
} }

View file

@ -2246,15 +2246,9 @@ public class GpxUiHelper {
if (dataItem.getWidth() != null) { if (dataItem.getWidth() != null) {
gpxFile.setWidth(dataItem.getWidth()); gpxFile.setWidth(dataItem.getWidth());
} }
if (dataItem.getGradientSpeedColor() != 0) { gpxFile.setGradientScaleColor(GradientScaleType.SPEED.getColorTypeName(), dataItem.getGradientSpeedPalette());
gpxFile.setGradientScaleColor(GradientScaleType.SPEED.getColorTypeName(), dataItem.getGradientSpeedColor()); gpxFile.setGradientScaleColor(GradientScaleType.SLOPE.getColorTypeName(), dataItem.getGradientSlopePalette());
} gpxFile.setGradientScaleColor(GradientScaleType.ALTITUDE.getColorTypeName(), dataItem.getGradientAltitudePalette());
if (dataItem.getGradientSlopeColor() != 0) {
gpxFile.setGradientScaleColor(GradientScaleType.SLOPE.getColorTypeName(), dataItem.getGradientSlopeColor());
}
if (dataItem.getGradientAltitudeColor() != 0) {
gpxFile.setGradientScaleColor(GradientScaleType.ALTITUDE.getColorTypeName(), dataItem.getGradientAltitudeColor());
}
if (dataItem.getGradientScaleType() != null) { if (dataItem.getGradientScaleType() != null) {
gpxFile.setGradientScaleType(dataItem.getGradientScaleType().name()); gpxFile.setGradientScaleType(dataItem.getGradientScaleType().name());
} }

View file

@ -50,6 +50,7 @@ import net.osmand.plus.rastermaps.LayerTransparencySeekbarMode;
import net.osmand.plus.render.RendererRegistry; import net.osmand.plus.render.RendererRegistry;
import net.osmand.plus.routing.RouteProvider.RouteService; import net.osmand.plus.routing.RouteProvider.RouteService;
import net.osmand.plus.srtmplugin.TerrainMode; import net.osmand.plus.srtmplugin.TerrainMode;
import net.osmand.plus.track.GradientScaleType;
import net.osmand.plus.views.layers.RadiusRulerControlLayer.RadiusRulerMode; import net.osmand.plus.views.layers.RadiusRulerControlLayer.RadiusRulerMode;
import net.osmand.plus.voice.CommandPlayer; import net.osmand.plus.voice.CommandPlayer;
import net.osmand.plus.wikipedia.WikiArticleShowImages; import net.osmand.plus.wikipedia.WikiArticleShowImages;
@ -1408,6 +1409,7 @@ public class OsmandSettings {
public final OsmandPreference<Long> LAST_UPDATES_CARD_REFRESH = new LongPreference(this, "last_updates_card_refresh", 0).makeGlobal(); public final OsmandPreference<Long> LAST_UPDATES_CARD_REFRESH = new LongPreference(this, "last_updates_card_refresh", 0).makeGlobal();
public final CommonPreference<Integer> CURRENT_TRACK_COLOR = new IntPreference(this, "current_track_color", 0).makeGlobal().makeShared().cache(); public final CommonPreference<Integer> CURRENT_TRACK_COLOR = new IntPreference(this, "current_track_color", 0).makeGlobal().makeShared().cache();
public final CommonPreference<GradientScaleType> CURRENT_TRACK_COLORIZATION = new EnumStringPreference<>(this, "current_track_colorization", null, GradientScaleType.values()).makeGlobal().makeShared().cache();
public final CommonPreference<String> CURRENT_TRACK_WIDTH = new StringPreference(this, "current_track_width", "").makeGlobal().makeShared().cache(); public final CommonPreference<String> CURRENT_TRACK_WIDTH = new StringPreference(this, "current_track_width", "").makeGlobal().makeShared().cache();
public final CommonPreference<Boolean> CURRENT_TRACK_SHOW_ARROWS = new BooleanPreference(this, "current_track_show_arrows", false).makeGlobal().makeShared().cache(); public final CommonPreference<Boolean> CURRENT_TRACK_SHOW_ARROWS = new BooleanPreference(this, "current_track_show_arrows", false).makeGlobal().makeShared().cache();
public final CommonPreference<Boolean> CURRENT_TRACK_SHOW_START_FINISH = new BooleanPreference(this, "current_track_show_start_finish", true).makeGlobal().makeShared().cache(); public final CommonPreference<Boolean> CURRENT_TRACK_SHOW_START_FINISH = new BooleanPreference(this, "current_track_show_start_finish", true).makeGlobal().makeShared().cache();

View file

@ -17,9 +17,9 @@ public class GpxAppearanceInfo {
public String width; public String width;
public GradientScaleType scaleType; public GradientScaleType scaleType;
public int color; public int color;
public int gradientSpeedColor; public int[] gradientSpeedPalette;
public int gradientAltitudeColor; public int[] gradientAltitudePalette;
public int gradientSlopeColor; public int[] gradientSlopePalette;
public int splitType; public int splitType;
public double splitInterval; public double splitInterval;
public boolean showArrows; public boolean showArrows;
@ -41,9 +41,9 @@ public class GpxAppearanceInfo {
splitType = dataItem.getSplitType(); splitType = dataItem.getSplitType();
splitInterval = dataItem.getSplitInterval(); splitInterval = dataItem.getSplitInterval();
scaleType = dataItem.getGradientScaleType(); scaleType = dataItem.getGradientScaleType();
gradientSpeedColor = dataItem.getGradientSpeedColor(); gradientSpeedPalette = dataItem.getGradientSpeedPalette();
gradientSlopeColor = dataItem.getGradientSlopeColor(); gradientSlopePalette = dataItem.getGradientSlopePalette();
gradientAltitudeColor = dataItem.getGradientAltitudeColor(); gradientAltitudePalette = dataItem.getGradientAltitudePalette();
GPXTrackAnalysis analysis = dataItem.getAnalysis(); GPXTrackAnalysis analysis = dataItem.getAnalysis();
if (analysis != null) { if (analysis != null) {
@ -61,9 +61,9 @@ public class GpxAppearanceInfo {
writeParam(json, "split_type", GpxSplitType.getSplitTypeByTypeId(splitType).getTypeName()); writeParam(json, "split_type", GpxSplitType.getSplitTypeByTypeId(splitType).getTypeName());
writeParam(json, "split_interval", splitInterval); writeParam(json, "split_interval", splitInterval);
writeParam(json, "gradient_scale_type", scaleType); writeParam(json, "gradient_scale_type", scaleType);
writeParam(json, GradientScaleType.SPEED.getColorTypeName(), gradientSpeedColor); writeParam(json, GradientScaleType.SPEED.getColorTypeName(), Algorithms.gradientPaletteToString(gradientSpeedPalette));
writeParam(json, GradientScaleType.SLOPE.getColorTypeName(), gradientSlopeColor); writeParam(json, GradientScaleType.ALTITUDE.getColorTypeName(), Algorithms.gradientPaletteToString(gradientAltitudePalette));
writeParam(json, GradientScaleType.ALTITUDE.getColorTypeName(), gradientAltitudeColor); writeParam(json, GradientScaleType.SLOPE.getColorTypeName(), Algorithms.gradientPaletteToString(gradientSlopePalette));
writeParam(json, "time_span", timeSpan); writeParam(json, "time_span", timeSpan);
writeParam(json, "wpt_points", wptPoints); writeParam(json, "wpt_points", wptPoints);
@ -79,9 +79,9 @@ public class GpxAppearanceInfo {
gpxAppearanceInfo.splitType = GpxSplitType.getSplitTypeByName(json.optString("split_type")).getType(); gpxAppearanceInfo.splitType = GpxSplitType.getSplitTypeByName(json.optString("split_type")).getType();
gpxAppearanceInfo.splitInterval = json.optDouble("split_interval"); gpxAppearanceInfo.splitInterval = json.optDouble("split_interval");
gpxAppearanceInfo.scaleType = getScaleType(json.optString("gradient_scale_type")); gpxAppearanceInfo.scaleType = getScaleType(json.optString("gradient_scale_type"));
gpxAppearanceInfo.gradientSpeedColor = json.optInt(GradientScaleType.SPEED.getColorTypeName()); gpxAppearanceInfo.gradientSpeedPalette = getGradientPalette(json, GradientScaleType.SPEED);
gpxAppearanceInfo.gradientSlopeColor = json.optInt(GradientScaleType.SLOPE.getColorTypeName()); gpxAppearanceInfo.gradientAltitudePalette = getGradientPalette(json, GradientScaleType.ALTITUDE);
gpxAppearanceInfo.gradientAltitudeColor = json.optInt(GradientScaleType.ALTITUDE.getColorTypeName()); gpxAppearanceInfo.gradientSlopePalette = getGradientPalette(json, GradientScaleType.SLOPE);
gpxAppearanceInfo.timeSpan = json.optLong("time_span"); gpxAppearanceInfo.timeSpan = json.optLong("time_span");
gpxAppearanceInfo.wptPoints = json.optInt("wpt_points"); gpxAppearanceInfo.wptPoints = json.optInt("wpt_points");
@ -101,6 +101,10 @@ public class GpxAppearanceInfo {
return null; return null;
} }
private static int[] getGradientPalette(JSONObject json, GradientScaleType scaleType) {
return Algorithms.stringToGradientPalette(json.optString(scaleType.getColorTypeName()));
}
private static void writeParam(@NonNull JSONObject json, @NonNull String name, @Nullable Object value) throws JSONException { private static void writeParam(@NonNull JSONObject json, @NonNull String name, @Nullable Object value) throws JSONException {
if (value instanceof Integer) { if (value instanceof Integer) {
if ((Integer) value != 0) { if ((Integer) value != 0) {

View file

@ -9,6 +9,7 @@ import net.osmand.plus.GpxDbHelper;
import net.osmand.plus.GpxDbHelper.GpxDataItemCallback; import net.osmand.plus.GpxDbHelper.GpxDataItemCallback;
import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandApplication;
import net.osmand.plus.track.GpxSplitType; import net.osmand.plus.track.GpxSplitType;
import net.osmand.plus.track.GradientScaleType;
import org.json.JSONException; import org.json.JSONException;
import org.json.JSONObject; import org.json.JSONObject;
@ -83,6 +84,9 @@ public class GpxSettingsItem extends FileSettingsItem {
gpxDbHelper.updateShowStartFinish(dataItem, appearanceInfo.showStartFinish); gpxDbHelper.updateShowStartFinish(dataItem, appearanceInfo.showStartFinish);
gpxDbHelper.updateSplit(dataItem, splitType, appearanceInfo.splitInterval); gpxDbHelper.updateSplit(dataItem, splitType, appearanceInfo.splitInterval);
gpxDbHelper.updateGradientScaleType(dataItem, appearanceInfo.scaleType); gpxDbHelper.updateGradientScaleType(dataItem, appearanceInfo.scaleType);
gpxDbHelper.updateGradientScaleColor(dataItem, GradientScaleType.SPEED, appearanceInfo.gradientSpeedPalette);
gpxDbHelper.updateGradientScaleColor(dataItem, GradientScaleType.ALTITUDE, appearanceInfo.gradientAltitudePalette);
gpxDbHelper.updateGradientScaleColor(dataItem, GradientScaleType.SLOPE, appearanceInfo.gradientSlopePalette);
} }
private void createGpxAppearanceInfo() { private void createGpxAppearanceInfo() {

View file

@ -7,6 +7,7 @@ import androidx.annotation.NonNull;
import androidx.annotation.StringRes; import androidx.annotation.StringRes;
import net.osmand.plus.R; import net.osmand.plus.R;
import net.osmand.router.RouteColorize.ColorizationType;
public enum GradientScaleType { public enum GradientScaleType {
@ -44,6 +45,18 @@ public enum GradientScaleType {
return ctx.getString(resId); return ctx.getString(resId);
} }
public ColorizationType toColorizationType() {
if (this == SPEED) {
return ColorizationType.SPEED;
} else if (this == ALTITUDE) {
return ColorizationType.ELEVATION;
} else if (this == SLOPE) {
return ColorizationType.SLOPE;
} else {
return ColorizationType.NONE;
}
}
public static GradientScaleType getGradientTypeByName(@NonNull String name) { public static GradientScaleType getGradientTypeByName(@NonNull String name) {
for (GradientScaleType scaleType : GradientScaleType.values()) { for (GradientScaleType scaleType : GradientScaleType.values()) {
if (scaleType.name().equalsIgnoreCase(name)) { if (scaleType.name().equalsIgnoreCase(name)) {

View file

@ -159,6 +159,7 @@ public class TrackAppearanceFragment extends ContextMenuScrollFragment implement
if (selectedGpxFile.isShowCurrentTrack()) { if (selectedGpxFile.isShowCurrentTrack()) {
trackDrawInfo = new TrackDrawInfo(true); trackDrawInfo = new TrackDrawInfo(true);
trackDrawInfo.setColor(app.getSettings().CURRENT_TRACK_COLOR.get()); trackDrawInfo.setColor(app.getSettings().CURRENT_TRACK_COLOR.get());
trackDrawInfo.setGradientScaleType(app.getSettings().CURRENT_TRACK_COLORIZATION.get());
trackDrawInfo.setWidth(app.getSettings().CURRENT_TRACK_WIDTH.get()); trackDrawInfo.setWidth(app.getSettings().CURRENT_TRACK_WIDTH.get());
trackDrawInfo.setShowArrows(app.getSettings().CURRENT_TRACK_SHOW_ARROWS.get()); trackDrawInfo.setShowArrows(app.getSettings().CURRENT_TRACK_SHOW_ARROWS.get());
trackDrawInfo.setShowStartFinish(app.getSettings().CURRENT_TRACK_SHOW_START_FINISH.get()); trackDrawInfo.setShowStartFinish(app.getSettings().CURRENT_TRACK_SHOW_START_FINISH.get());
@ -343,6 +344,8 @@ public class TrackAppearanceFragment extends ContextMenuScrollFragment implement
SplitIntervalBottomSheet.showInstance(mapActivity.getSupportFragmentManager(), trackDrawInfo, this); SplitIntervalBottomSheet.showInstance(mapActivity.getSupportFragmentManager(), trackDrawInfo, this);
} else if (card instanceof TrackColoringCard) { } else if (card instanceof TrackColoringCard) {
GradientScaleType currentScaleType = ((TrackColoringCard) card).getSelectedScaleType(); GradientScaleType currentScaleType = ((TrackColoringCard) card).getSelectedScaleType();
trackDrawInfo.setGradientScaleType(currentScaleType);
mapActivity.refreshMap();
if (gradientCard != null) { if (gradientCard != null) {
gradientCard.setSelectedScaleType(currentScaleType); gradientCard.setSelectedScaleType(currentScaleType);
} }
@ -575,6 +578,7 @@ public class TrackAppearanceFragment extends ContextMenuScrollFragment implement
GPXFile gpxFile = selectedGpxFile.getGpxFile(); GPXFile gpxFile = selectedGpxFile.getGpxFile();
if (gpxFile.showCurrentTrack) { if (gpxFile.showCurrentTrack) {
app.getSettings().CURRENT_TRACK_COLOR.set(trackDrawInfo.getColor()); app.getSettings().CURRENT_TRACK_COLOR.set(trackDrawInfo.getColor());
app.getSettings().CURRENT_TRACK_COLORIZATION.set(trackDrawInfo.getGradientScaleType());
app.getSettings().CURRENT_TRACK_WIDTH.set(trackDrawInfo.getWidth()); app.getSettings().CURRENT_TRACK_WIDTH.set(trackDrawInfo.getWidth());
app.getSettings().CURRENT_TRACK_SHOW_ARROWS.set(trackDrawInfo.isShowArrows()); app.getSettings().CURRENT_TRACK_SHOW_ARROWS.set(trackDrawInfo.isShowArrows());
app.getSettings().CURRENT_TRACK_SHOW_START_FINISH.set(trackDrawInfo.isShowStartFinish()); app.getSettings().CURRENT_TRACK_SHOW_START_FINISH.set(trackDrawInfo.isShowStartFinish());