diff --git a/OsmAnd-java/src/main/java/net/osmand/router/RouteColorize.java b/OsmAnd-java/src/main/java/net/osmand/router/RouteColorize.java index 301a69a101..a259a8ebb6 100644 --- a/OsmAnd-java/src/main/java/net/osmand/router/RouteColorize.java +++ b/OsmAnd-java/src/main/java/net/osmand/router/RouteColorize.java @@ -204,7 +204,7 @@ public class RouteColorize { } public void setPalette(int[] gradientPalette) { - if (gradientPalette.length != 3) { + if (gradientPalette == null || gradientPalette.length != 3) { return; } setPalette(new double[][] { diff --git a/OsmAnd/src/net/osmand/plus/GPXDatabase.java b/OsmAnd/src/net/osmand/plus/GPXDatabase.java index b08013017f..0f70144a73 100644 --- a/OsmAnd/src/net/osmand/plus/GPXDatabase.java +++ b/OsmAnd/src/net/osmand/plus/GPXDatabase.java @@ -176,8 +176,8 @@ public class GPXDatabase { private File file; private GPXTrackAnalysis analysis; private String width; - private GradientScaleType gradientScaleType; private int color; + private GradientScaleType gradientScaleType; private int[] gradientSpeedPalette; private int[] gradientAltitudePalette; private int[] gradientSlopePalette; @@ -884,7 +884,7 @@ public class GPXDatabase { item.gradientSlopePalette = Algorithms.stringToGradientPalette(gradientSlopePalette); try { - item.gradientScaleType = Algorithms.isEmpty(gradientScaleType) ? null : GradientScaleType.valueOf(gradientScaleType); + item.gradientScaleType = Algorithms.isEmpty(gradientScaleType) ? null : GradientScaleType.valueOf(gradientScaleType.toUpperCase()); } catch (IllegalArgumentException e) { item.gradientScaleType = null; } diff --git a/OsmAnd/src/net/osmand/plus/settings/backend/OsmandSettings.java b/OsmAnd/src/net/osmand/plus/settings/backend/OsmandSettings.java index 0635f8d7c1..7abb6245d6 100644 --- a/OsmAnd/src/net/osmand/plus/settings/backend/OsmandSettings.java +++ b/OsmAnd/src/net/osmand/plus/settings/backend/OsmandSettings.java @@ -1409,7 +1409,29 @@ public class OsmandSettings { public final OsmandPreference LAST_UPDATES_CARD_REFRESH = new LongPreference(this, "last_updates_card_refresh", 0).makeGlobal(); public final CommonPreference CURRENT_TRACK_COLOR = new IntPreference(this, "current_track_color", 0).makeGlobal().makeShared().cache(); - public final CommonPreference CURRENT_TRACK_COLORIZATION = new EnumStringPreference<>(this, "current_track_colorization", null, GradientScaleType.values()).makeGlobal().makeShared().cache(); + public final CommonPreference CURRENT_TRACK_COLORIZATION = new CommonPreference(this, "current_track_colorization", null) { + @Override + protected GradientScaleType getValue(Object prefs, GradientScaleType defaultValue) { + String name = getSettingsAPI().getString(prefs, getId(), null); + return parseString(name); + } + + @Override + protected boolean setValue(Object prefs, GradientScaleType val) { + String name = val == null ? null : val.getTypeName(); + return getSettingsAPI().edit(prefs).putString(getId(), name).commit(); + } + + @Override + public GradientScaleType parseString(String s) { + for (GradientScaleType value : GradientScaleType.values()) { + if (value.name().equals(s)) { + return value; + } + } + return null; + } + }.makeGlobal().makeShared().cache(); public final CommonPreference CURRENT_TRACK_WIDTH = new StringPreference(this, "current_track_width", "").makeGlobal().makeShared().cache(); public final CommonPreference CURRENT_TRACK_SHOW_ARROWS = new BooleanPreference(this, "current_track_show_arrows", false).makeGlobal().makeShared().cache(); public final CommonPreference CURRENT_TRACK_SHOW_START_FINISH = new BooleanPreference(this, "current_track_show_start_finish", true).makeGlobal().makeShared().cache(); diff --git a/OsmAnd/src/net/osmand/plus/track/TrackDrawInfo.java b/OsmAnd/src/net/osmand/plus/track/TrackDrawInfo.java index f08f87546d..d3531c0c9d 100644 --- a/OsmAnd/src/net/osmand/plus/track/TrackDrawInfo.java +++ b/OsmAnd/src/net/osmand/plus/track/TrackDrawInfo.java @@ -47,8 +47,8 @@ public class TrackDrawInfo { public TrackDrawInfo(@NonNull OsmandApplication app, @NonNull GpxDataItem gpxDataItem, boolean currentRecording) { filePath = gpxDataItem.getFile().getPath(); width = gpxDataItem.getWidth(); - gradientScaleType = gpxDataItem.getGradientScaleType(); color = gpxDataItem.getColor(); + gradientScaleType = gpxDataItem.getGradientScaleType(); speedGradientPalette = gpxDataItem.getGradientSpeedPalette(); altitudeGradientPalette = gpxDataItem.getGradientAltitudePalette(); slopeGradientPalette = gpxDataItem.getGradientSlopePalette(); diff --git a/OsmAnd/src/net/osmand/plus/views/Renderable.java b/OsmAnd/src/net/osmand/plus/views/Renderable.java index e8d4a6183f..a8d8351967 100644 --- a/OsmAnd/src/net/osmand/plus/views/Renderable.java +++ b/OsmAnd/src/net/osmand/plus/views/Renderable.java @@ -102,7 +102,14 @@ public class Renderable { protected abstract void startCuller(double newZoom); - protected void drawSingleSegment(double zoom, Paint p, Canvas canvas, RotatedTileBox tileBox) {} + protected void drawSingleSegment(double zoom, Paint p, Canvas canvas, RotatedTileBox tileBox) { + if (scaleType != null) { + drawGradient(getPointsForDrawing(), p, canvas, tileBox); + scaleType = null; + } else { + drawSolid(getPointsForDrawing(), p, canvas, tileBox); + } + } public void drawSegment(double zoom, Paint p, Canvas canvas, RotatedTileBox tileBox) { @@ -230,15 +237,6 @@ public class Renderable { } } } - - @Override public void drawSingleSegment(double zoom, Paint p, Canvas canvas, RotatedTileBox tileBox) { - if (scaleType != null) { - drawGradient(getPointsForDrawing(), p, canvas, tileBox); - scaleType = null; - } else { - drawSolid(getPointsForDrawing(), p, canvas, tileBox); - } - } } public static class CurrentTrack extends RenderableSegment { @@ -257,9 +255,5 @@ public class Renderable { } @Override protected void startCuller(double newZoom) {} - - @Override public void drawSingleSegment(double zoom, Paint p, Canvas canvas, RotatedTileBox tileBox) { - drawSolid(points, p, canvas, tileBox); - } } }