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 7b9f46c108..8fb0046bb4 100644 --- a/OsmAnd-java/src/main/java/net/osmand/router/RouteColorize.java +++ b/OsmAnd-java/src/main/java/net/osmand/router/RouteColorize.java @@ -209,7 +209,7 @@ public class RouteColorize { } setPalette(new double[][] { {minValue, gradientPalette[0]}, - {colorizationType == ColorizationType.SLOPE ? 0 : (minValue + maxValue) / 2}, + {colorizationType == ColorizationType.SLOPE ? 0 : (minValue + maxValue) / 2, gradientPalette[1]}, {maxValue, gradientPalette[2]} }); } diff --git a/OsmAnd/res/layout/gradient_card.xml b/OsmAnd/res/layout/gradient_card.xml index ff0834bee0..a4edba9be2 100644 --- a/OsmAnd/res/layout/gradient_card.xml +++ b/OsmAnd/res/layout/gradient_card.xml @@ -3,7 +3,7 @@ xmlns:osmand="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" - android:layout_height="match_parent" + android:layout_height="wrap_content" android:orientation="vertical" android:padding="@dimen/content_padding" android:paddingStart="@dimen/content_padding" diff --git a/OsmAnd/src/net/osmand/plus/GPXDatabase.java b/OsmAnd/src/net/osmand/plus/GPXDatabase.java index 0f70144a73..385ec79484 100644 --- a/OsmAnd/src/net/osmand/plus/GPXDatabase.java +++ b/OsmAnd/src/net/osmand/plus/GPXDatabase.java @@ -1,8 +1,5 @@ package net.osmand.plus; -import androidx.annotation.NonNull; -import androidx.annotation.Nullable; - import net.osmand.GPXUtilities.GPXFile; import net.osmand.GPXUtilities.GPXTrackAnalysis; import net.osmand.IndexConstants; @@ -16,6 +13,9 @@ import java.io.File; import java.util.ArrayList; import java.util.List; +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; + public class GPXDatabase { private static final int DB_VERSION = 11; @@ -751,7 +751,9 @@ public class GPXDatabase { new Object[] {fileName, fileDir, color, 0, item.splitType, item.splitInterval, item.apiImported ? 1 : 0, item.showAsMarkers ? 1 : 0, item.joinSegments ? 1 : 0, item.showArrows ? 1 : 0, item.showStartFinish ? 1 : 0, item.width, - item.gradientSpeedPalette, item.gradientAltitudePalette, item.gradientSlopePalette, gradientScaleType}); + Algorithms.gradientPaletteToString(item.gradientSpeedPalette), + Algorithms.gradientPaletteToString(item.gradientAltitudePalette), + Algorithms.gradientPaletteToString(item.gradientSlopePalette), gradientScaleType}); } } @@ -884,7 +886,7 @@ public class GPXDatabase { item.gradientSlopePalette = Algorithms.stringToGradientPalette(gradientSlopePalette); try { - item.gradientScaleType = Algorithms.isEmpty(gradientScaleType) ? null : GradientScaleType.valueOf(gradientScaleType.toUpperCase()); + item.gradientScaleType = GradientScaleType.getGradientTypeByName(gradientScaleType); } catch (IllegalArgumentException e) { item.gradientScaleType = null; } diff --git a/OsmAnd/src/net/osmand/plus/GpxDbHelper.java b/OsmAnd/src/net/osmand/plus/GpxDbHelper.java index ef93703190..21154d5819 100644 --- a/OsmAnd/src/net/osmand/plus/GpxDbHelper.java +++ b/OsmAnd/src/net/osmand/plus/GpxDbHelper.java @@ -78,7 +78,7 @@ public class GpxDbHelper { return res; } - public boolean updateGradientScaleColor(@NonNull GpxDataItem item, @NonNull GradientScaleType gradientScaleType, int[] palette) { + public boolean updateGradientScalePalette(@NonNull GpxDataItem item, @NonNull GradientScaleType gradientScaleType, int[] palette) { boolean res = db.updateGradientScaleColor(item, gradientScaleType, palette); putToCache(item); return res; diff --git a/OsmAnd/src/net/osmand/plus/settings/backend/EnumStringPreference.java b/OsmAnd/src/net/osmand/plus/settings/backend/EnumStringPreference.java index d51deca152..a88a17fed3 100644 --- a/OsmAnd/src/net/osmand/plus/settings/backend/EnumStringPreference.java +++ b/OsmAnd/src/net/osmand/plus/settings/backend/EnumStringPreference.java @@ -12,7 +12,8 @@ public class EnumStringPreference> extends CommonPreference @Override protected E getValue(Object prefs, E defaultValue) { try { - String name = getSettingsAPI().getString(prefs, getId(), defaultValue.name()); + String defaultValueName = defaultValue == null ? null : defaultValue.name(); + String name = getSettingsAPI().getString(prefs, getId(), defaultValueName); E value = parseString(name); return value != null ? value : defaultValue; } catch (ClassCastException ex) { @@ -23,7 +24,8 @@ public class EnumStringPreference> extends CommonPreference @Override public boolean setValue(Object prefs, E val) { - return getSettingsAPI().edit(prefs).putString(getId(), val.name()).commit(); + String name = val == null ? null : val.name(); + return getSettingsAPI().edit(prefs).putString(getId(), name).commit(); } @Override diff --git a/OsmAnd/src/net/osmand/plus/settings/backend/OsmandSettings.java b/OsmAnd/src/net/osmand/plus/settings/backend/OsmandSettings.java index 7abb6245d6..1a2658870b 100644 --- a/OsmAnd/src/net/osmand/plus/settings/backend/OsmandSettings.java +++ b/OsmAnd/src/net/osmand/plus/settings/backend/OsmandSettings.java @@ -1409,29 +1409,10 @@ 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 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_COLORIZATION = new EnumStringPreference<>(this, "current_track_colorization", null, GradientScaleType.values()).makeGlobal().makeShared().cache(); + public final CommonPreference CURRENT_TRACK_SPEED_GRADIENT_PALETTE = new StringPreference(this, "current_track_speed_gradient_palette", null).makeGlobal().makeShared().cache(); + public final CommonPreference CURRENT_TRACK_ALTITUDE_GRADIENT_PALETTE = new StringPreference(this, "current_track_altitude_gradient_palette", null).makeGlobal().makeShared().cache(); + public final CommonPreference CURRENT_TRACK_SLOPE_GRADIENT_PALETTE = new StringPreference(this, "current_track_slope_gradient_palette", 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/settings/backend/backup/GpxSettingsItem.java b/OsmAnd/src/net/osmand/plus/settings/backend/backup/GpxSettingsItem.java index 2eca72fba1..fe6fd9b67a 100644 --- a/OsmAnd/src/net/osmand/plus/settings/backend/backup/GpxSettingsItem.java +++ b/OsmAnd/src/net/osmand/plus/settings/backend/backup/GpxSettingsItem.java @@ -84,9 +84,9 @@ public class GpxSettingsItem extends FileSettingsItem { gpxDbHelper.updateShowStartFinish(dataItem, appearanceInfo.showStartFinish); gpxDbHelper.updateSplit(dataItem, splitType, appearanceInfo.splitInterval); 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); + gpxDbHelper.updateGradientScalePalette(dataItem, GradientScaleType.SPEED, appearanceInfo.gradientSpeedPalette); + gpxDbHelper.updateGradientScalePalette(dataItem, GradientScaleType.ALTITUDE, appearanceInfo.gradientAltitudePalette); + gpxDbHelper.updateGradientScalePalette(dataItem, GradientScaleType.SLOPE, appearanceInfo.gradientSlopePalette); } private void createGpxAppearanceInfo() { diff --git a/OsmAnd/src/net/osmand/plus/track/GradientCard.java b/OsmAnd/src/net/osmand/plus/track/GradientCard.java index 77d881574e..217ad2a8f1 100644 --- a/OsmAnd/src/net/osmand/plus/track/GradientCard.java +++ b/OsmAnd/src/net/osmand/plus/track/GradientCard.java @@ -14,15 +14,17 @@ import net.osmand.plus.helpers.AndroidUiHelper; import net.osmand.plus.routepreparationmenu.cards.BaseCard; import androidx.annotation.NonNull; +import androidx.annotation.Nullable; public class GradientCard extends BaseCard { private GPXTrackAnalysis gpxTrackAnalysis; - private GradientScaleType selectedScaleType = null; + private GradientScaleType selectedScaleType; - public GradientCard(@NonNull MapActivity mapActivity, @NonNull GPXTrackAnalysis gpxTrackAnalysis) { + public GradientCard(@NonNull MapActivity mapActivity, @NonNull GPXTrackAnalysis gpxTrackAnalysis, @Nullable GradientScaleType selectedScaleType) { super(mapActivity); this.gpxTrackAnalysis = gpxTrackAnalysis; + this.selectedScaleType = selectedScaleType; } @Override @@ -72,10 +74,11 @@ public class GradientCard extends BaseCard { return (int) value + " %"; } String speed = OsmAndFormatter.getFormattedSpeed(value, app); + String speedUnit = app.getSettings().SPEED_SYSTEM.get().toShortString(app); Spannable formattedSpeed = new SpannableString(speed); formattedSpeed.setSpan( new ForegroundColorSpan(AndroidUtils.getColorFromAttr(app, android.R.attr.textColorSecondary)), - speed.indexOf(" "), speed.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); + speed.indexOf(speedUnit), speed.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); return formattedSpeed; } } \ 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 98831141bc..3aaeebccae 100644 --- a/OsmAnd/src/net/osmand/plus/track/TrackAppearanceFragment.java +++ b/OsmAnd/src/net/osmand/plus/track/TrackAppearanceFragment.java @@ -160,6 +160,9 @@ public class TrackAppearanceFragment extends ContextMenuScrollFragment implement trackDrawInfo = new TrackDrawInfo(true); trackDrawInfo.setColor(app.getSettings().CURRENT_TRACK_COLOR.get()); trackDrawInfo.setGradientScaleType(app.getSettings().CURRENT_TRACK_COLORIZATION.get()); + trackDrawInfo.setSpeedGradientPalette(Algorithms.stringToArray(app.getSettings().CURRENT_TRACK_SPEED_GRADIENT_PALETTE.get())); + trackDrawInfo.setAltitudeGradientPalette(Algorithms.stringToArray(app.getSettings().CURRENT_TRACK_ALTITUDE_GRADIENT_PALETTE.get())); + trackDrawInfo.setSlopeGradientPalette(Algorithms.stringToArray(app.getSettings().CURRENT_TRACK_SLOPE_GRADIENT_PALETTE.get())); trackDrawInfo.setWidth(app.getSettings().CURRENT_TRACK_WIDTH.get()); trackDrawInfo.setShowArrows(app.getSettings().CURRENT_TRACK_SHOW_ARROWS.get()); trackDrawInfo.setShowStartFinish(app.getSettings().CURRENT_TRACK_SHOW_START_FINISH.get()); @@ -579,12 +582,18 @@ public class TrackAppearanceFragment extends ContextMenuScrollFragment implement if (gpxFile.showCurrentTrack) { app.getSettings().CURRENT_TRACK_COLOR.set(trackDrawInfo.getColor()); app.getSettings().CURRENT_TRACK_COLORIZATION.set(trackDrawInfo.getGradientScaleType()); + app.getSettings().CURRENT_TRACK_SPEED_GRADIENT_PALETTE.set(Algorithms.arrayToString(trackDrawInfo.getSpeedGradientPalette())); + app.getSettings().CURRENT_TRACK_ALTITUDE_GRADIENT_PALETTE.set(Algorithms.arrayToString(trackDrawInfo.getAltitudeGradientPalette())); + app.getSettings().CURRENT_TRACK_SLOPE_GRADIENT_PALETTE.set(Algorithms.arrayToString(trackDrawInfo.getSlopeGradientPalette())); app.getSettings().CURRENT_TRACK_WIDTH.set(trackDrawInfo.getWidth()); app.getSettings().CURRENT_TRACK_SHOW_ARROWS.set(trackDrawInfo.isShowArrows()); app.getSettings().CURRENT_TRACK_SHOW_START_FINISH.set(trackDrawInfo.isShowStartFinish()); } else if (gpxDataItem != null) { GpxSplitType splitType = GpxSplitType.getSplitTypeByTypeId(trackDrawInfo.getSplitType()); gpxDbHelper.updateColor(gpxDataItem, trackDrawInfo.getColor()); + gpxDbHelper.updateGradientScalePalette(gpxDataItem, GradientScaleType.SPEED, trackDrawInfo.getSpeedGradientPalette()); + gpxDbHelper.updateGradientScalePalette(gpxDataItem, GradientScaleType.ALTITUDE, trackDrawInfo.getAltitudeGradientPalette()); + gpxDbHelper.updateGradientScalePalette(gpxDataItem, GradientScaleType.SLOPE, trackDrawInfo.getSlopeGradientPalette()); gpxDbHelper.updateWidth(gpxDataItem, trackDrawInfo.getWidth()); gpxDbHelper.updateShowArrows(gpxDataItem, trackDrawInfo.isShowArrows()); // gpxDbHelper.updateShowStartFinish(gpxDataItem, trackDrawInfo.isShowStartFinish()); @@ -662,9 +671,8 @@ public class TrackAppearanceFragment extends ContextMenuScrollFragment implement setupColorsCard(cardsContainer); - gradientCard = new GradientCard(mapActivity, selectedGpxFile.getTrackAnalysis(app)); - AndroidUiHelper.updateVisibility(gradientCard.build(mapActivity), false); - cardsContainer.addView(gradientCard.getView()); + gradientCard = new GradientCard(mapActivity, selectedGpxFile.getTrackAnalysis(app), trackDrawInfo.getGradientScaleType()); + cardsContainer.addView(gradientCard.build(mapActivity)); trackWidthCard = new TrackWidthCard(mapActivity, trackDrawInfo, new OnNeedScrollListener() { @@ -692,7 +700,8 @@ public class TrackAppearanceFragment extends ContextMenuScrollFragment implement List colors = getTrackColors(); colorsCard = new ColorsCard(mapActivity, trackDrawInfo.getColor(), this, colors, app.getSettings().CUSTOM_TRACK_COLORS, null); colorsCard.setListener(this); - cardsContainer.addView(colorsCard.build(mapActivity)); + AndroidUiHelper.updateVisibility(colorsCard.build(mapActivity), trackDrawInfo.getGradientScaleType() == null); + cardsContainer.addView(colorsCard.getView()); } } diff --git a/OsmAnd/src/net/osmand/plus/track/TrackColoringCard.java b/OsmAnd/src/net/osmand/plus/track/TrackColoringCard.java index 44645180ea..41e17ac37e 100644 --- a/OsmAnd/src/net/osmand/plus/track/TrackColoringCard.java +++ b/OsmAnd/src/net/osmand/plus/track/TrackColoringCard.java @@ -1,5 +1,6 @@ package net.osmand.plus.track; +import android.content.Context; import android.graphics.drawable.GradientDrawable; import android.os.Build; import android.view.LayoutInflater; @@ -188,6 +189,7 @@ public class TrackColoringCard extends BaseCard { private void updateButtonBg(TrackAppearanceViewHolder holder, TrackAppearanceItem item) { GradientDrawable rectContourDrawable = (GradientDrawable) AppCompatResources.getDrawable(app, R.drawable.bg_select_group_button_outline); if (rectContourDrawable != null) { + Context ctx = holder.itemView.getContext(); boolean itemSelected = getSelectedAppearanceItem() != null && getSelectedAppearanceItem().equals(item); int strokeColor; @@ -195,39 +197,40 @@ public class TrackColoringCard extends BaseCard { int strokeWidth; if (itemSelected) { - strokeColor = AndroidUtils.getColorFromAttr(app, R.attr.pstsIndicatorColor); + strokeColor = AndroidUtils.getColorFromAttr(ctx, R.attr.colorPrimary); backgroundColor = 0; strokeWidth = 2; } else if (!item.isActive()) { - strokeColor = AndroidUtils.getColorFromAttr(app, R.attr.stroked_buttons_and_links_outline); - backgroundColor = AndroidUtils.getColorFromAttr(app, R.attr.ctx_menu_card_btn); + strokeColor = AndroidUtils.getColorFromAttr(ctx, R.attr.stroked_buttons_and_links_outline); + backgroundColor = AndroidUtils.getColorFromAttr(ctx, R.attr.ctx_menu_card_btn); strokeWidth = 2; } else { - strokeColor = AndroidUtils.getColorFromAttr(app, R.attr.stroked_buttons_and_links_outline); + strokeColor = AndroidUtils.getColorFromAttr(ctx, R.attr.stroked_buttons_and_links_outline); backgroundColor = 0; strokeWidth = 1; } rectContourDrawable.mutate(); rectContourDrawable.setColor(backgroundColor); - rectContourDrawable.setStroke(AndroidUtils.dpToPx(app, strokeWidth), strokeColor); + rectContourDrawable.setStroke(AndroidUtils.dpToPx(ctx, strokeWidth), strokeColor); holder.button.setImageDrawable(rectContourDrawable); } } private void updateTextAndIconColor(TrackAppearanceViewHolder holder, TrackAppearanceItem item) { + Context ctx = holder.itemView.getContext(); boolean isSelected = item.getAttrName().equals(getSelectedAppearanceItem().getAttrName()); int iconColorId; int textColorId; if (isSelected) { - iconColorId = AndroidUtils.getColorFromAttr(app, R.attr.default_icon_color); - textColorId = AndroidUtils.getColorFromAttr(app, android.R.attr.textColor); + iconColorId = AndroidUtils.getColorFromAttr(ctx, R.attr.default_icon_color); + textColorId = AndroidUtils.getColorFromAttr(ctx, android.R.attr.textColor); } else if (!item.isActive()) { - iconColorId = AndroidUtils.getColorFromAttr(app, R.attr.default_icon_color); - textColorId = AndroidUtils.getColorFromAttr(app, android.R.attr.textColorSecondary); + iconColorId = AndroidUtils.getColorFromAttr(ctx, R.attr.default_icon_color); + textColorId = AndroidUtils.getColorFromAttr(ctx, android.R.attr.textColorSecondary); } else { - iconColorId = AndroidUtils.getColorFromAttr(app, R.attr.pstsIndicatorColor); + iconColorId = AndroidUtils.getColorFromAttr(ctx, R.attr.colorPrimary); textColorId = iconColorId; } diff --git a/OsmAnd/src/net/osmand/plus/track/TrackDrawInfo.java b/OsmAnd/src/net/osmand/plus/track/TrackDrawInfo.java index d3531c0c9d..2f3d0a2c32 100644 --- a/OsmAnd/src/net/osmand/plus/track/TrackDrawInfo.java +++ b/OsmAnd/src/net/osmand/plus/track/TrackDrawInfo.java @@ -98,6 +98,30 @@ public class TrackDrawInfo { } } + public int[] getSpeedGradientPalette() { + return speedGradientPalette; + } + + public int[] getAltitudeGradientPalette() { + return altitudeGradientPalette; + } + + public int[] getSlopeGradientPalette() { + return slopeGradientPalette; + } + + public void setSpeedGradientPalette(int[] palette) { + this.speedGradientPalette = palette; + } + + public void setAltitudeGradientPalette(int[] palette) { + this.altitudeGradientPalette = palette; + } + + public void setSlopeGradientPalette(int[] palette) { + this.slopeGradientPalette = palette; + } + public int getSplitType() { return splitType; } diff --git a/OsmAnd/src/net/osmand/plus/views/Renderable.java b/OsmAnd/src/net/osmand/plus/views/Renderable.java index a8d8351967..5053f46a69 100644 --- a/OsmAnd/src/net/osmand/plus/views/Renderable.java +++ b/OsmAnd/src/net/osmand/plus/views/Renderable.java @@ -6,8 +6,6 @@ import android.graphics.Paint; import android.graphics.Path; import android.graphics.Shader; -import androidx.annotation.NonNull; - import net.osmand.GPXUtilities; import net.osmand.GPXUtilities.WptPt; import net.osmand.data.QuadRect; @@ -27,6 +25,8 @@ import java.util.concurrent.ThreadPoolExecutor; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicInteger; +import androidx.annotation.NonNull; + public class Renderable { @@ -103,12 +103,18 @@ public class Renderable { protected abstract void startCuller(double newZoom); protected void drawSingleSegment(double zoom, Paint p, Canvas canvas, RotatedTileBox tileBox) { + if (points.size() < 2) { + return; + } + + updateLocalPaint(p); + canvas.rotate(-tileBox.getRotate(), tileBox.getCenterPixelX(), tileBox.getCenterPixelY()); if (scaleType != null) { drawGradient(getPointsForDrawing(), p, canvas, tileBox); - scaleType = null; } else { drawSolid(getPointsForDrawing(), p, canvas, tileBox); } + canvas.rotate(tileBox.getRotate(), tileBox.getCenterPixelX(), tileBox.getCenterPixelY()); } @@ -139,55 +145,44 @@ public class Renderable { } protected void drawSolid(List pts, Paint p, Canvas canvas, RotatedTileBox tileBox) { - if (pts.size() > 1) { - updateLocalPaint(p); - canvas.rotate(-tileBox.getRotate(), tileBox.getCenterPixelX(), tileBox.getCenterPixelY()); - QuadRect tileBounds = tileBox.getLatLonBounds(); - WptPt lastPt = pts.get(0); - boolean recalculateLastXY = true; - Path path = new Path(); - for (int i = 1; i < pts.size(); i++) { - WptPt pt = pts.get(i); - if (Math.min(pt.lon, lastPt.lon) < tileBounds.right && Math.max(pt.lon, lastPt.lon) > tileBounds.left - && Math.min(pt.lat, lastPt.lat) < tileBounds.top && Math.max(pt.lat, lastPt.lat) > tileBounds.bottom) { - if (recalculateLastXY) { - recalculateLastXY = false; - float lastX = tileBox.getPixXFromLatLon(lastPt.lat, lastPt.lon); - float lastY = tileBox.getPixYFromLatLon(lastPt.lat, lastPt.lon); - if (!path.isEmpty()) { - canvas.drawPath(path, paint); - } - path.reset(); - path.moveTo(lastX, lastY); + QuadRect tileBounds = tileBox.getLatLonBounds(); + WptPt lastPt = pts.get(0); + boolean recalculateLastXY = true; + Path path = new Path(); + for (int i = 1; i < pts.size(); i++) { + WptPt pt = pts.get(i); + if (arePointsInsideTile(pt, lastPt, tileBounds)) { + if (recalculateLastXY) { + recalculateLastXY = false; + float lastX = tileBox.getPixXFromLatLon(lastPt.lat, lastPt.lon); + float lastY = tileBox.getPixYFromLatLon(lastPt.lat, lastPt.lon); + if (!path.isEmpty()) { + canvas.drawPath(path, paint); } - float x = tileBox.getPixXFromLatLon(pt.lat, pt.lon); - float y = tileBox.getPixYFromLatLon(pt.lat, pt.lon); - path.lineTo(x, y); - } else { - recalculateLastXY = true; + path.reset(); + path.moveTo(lastX, lastY); } - lastPt = pt; + float x = tileBox.getPixXFromLatLon(pt.lat, pt.lon); + float y = tileBox.getPixYFromLatLon(pt.lat, pt.lon); + path.lineTo(x, y); + } else { + recalculateLastXY = true; } - if (!path.isEmpty()) { - canvas.drawPath(path, paint); - } - canvas.rotate(tileBox.getRotate(), tileBox.getCenterPixelX(), tileBox.getCenterPixelY()); + lastPt = pt; + } + if (!path.isEmpty()) { + canvas.drawPath(path, paint); } } protected void drawGradient(List pts, Paint p, Canvas canvas, RotatedTileBox tileBox) { - if (pts.size() < 2) { - return; - } - - updateLocalPaint(p); - canvas.rotate(-tileBox.getRotate(), tileBox.getCenterPixelX(), tileBox.getCenterPixelY()); QuadRect tileBounds = tileBox.getLatLonBounds(); + Path path = new Path(); + Paint paint = new Paint(this.paint); WptPt prevPt = pts.get(0); for (int i = 1; i < pts.size(); i++) { WptPt currentPt = pts.get(i); - if (Math.min(currentPt.lon, prevPt.lon) < tileBounds.right && Math.max(currentPt.lon, prevPt.lon) > tileBounds.left - && Math.min(currentPt.lat, prevPt.lat) < tileBounds.top && Math.max(currentPt.lat, prevPt.lat) > tileBounds.bottom) { + if (arePointsInsideTile(currentPt, prevPt, tileBounds)) { float startX = tileBox.getPixXFromLatLon(prevPt.lat, prevPt.lon); float startY = tileBox.getPixYFromLatLon(prevPt.lat, prevPt.lon); float endX = tileBox.getPixXFromLatLon(currentPt.lat, currentPt.lon); @@ -195,16 +190,19 @@ public class Renderable { int prevColor = prevPt.getColor(scaleType.toColorizationType()); int currentColor = currentPt.getColor(scaleType.toColorizationType()); LinearGradient gradient = new LinearGradient(startX, startY, endX, endY, prevColor, currentColor, Shader.TileMode.CLAMP); - Paint paint = new Paint(this.paint); paint.setShader(gradient); - Path path = new Path(); + path.reset(); path.moveTo(startX, startY); path.lineTo(endX, endY); canvas.drawPath(path, paint); } prevPt = currentPt; } - canvas.rotate(tileBox.getRotate(), tileBox.getCenterPixelX(), tileBox.getCenterPixelY()); + } + + protected boolean arePointsInsideTile(WptPt first, WptPt second, QuadRect tileBounds) { + return Math.min(first.lon, second.lon) < tileBounds.right && Math.max(first.lon, second.lon) > tileBounds.left + && Math.min(first.lat, second.lat) < tileBounds.top && Math.max(first.lat, second.lat) > tileBounds.bottom; } } diff --git a/OsmAnd/src/net/osmand/plus/views/layers/GPXLayer.java b/OsmAnd/src/net/osmand/plus/views/layers/GPXLayer.java index abb99e8428..033437d27c 100644 --- a/OsmAnd/src/net/osmand/plus/views/layers/GPXLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/layers/GPXLayer.java @@ -145,6 +145,9 @@ public class GPXLayer extends OsmandMapLayer implements IContextMenuProvider, IM private CommonPreference currentTrackColorPref; private CommonPreference currentTrackScaleType; + private CommonPreference currentTrackSpeedGradientPalette; + private CommonPreference currentTrackAltitudeGradientPalette; + private CommonPreference currentTrackSlopeGradientPalette; private CommonPreference currentTrackWidthPref; private CommonPreference currentTrackShowArrowsPref; private CommonPreference currentTrackShowStartFinishPref; @@ -159,6 +162,9 @@ public class GPXLayer extends OsmandMapLayer implements IContextMenuProvider, IM currentTrackColorPref = view.getSettings().CURRENT_TRACK_COLOR; currentTrackScaleType = view.getSettings().CURRENT_TRACK_COLORIZATION; + currentTrackSpeedGradientPalette = view.getSettings().CURRENT_TRACK_SPEED_GRADIENT_PALETTE; + currentTrackAltitudeGradientPalette = view.getSettings().CURRENT_TRACK_ALTITUDE_GRADIENT_PALETTE; + currentTrackSlopeGradientPalette = view.getSettings().CURRENT_TRACK_SLOPE_GRADIENT_PALETTE; currentTrackWidthPref = view.getSettings().CURRENT_TRACK_WIDTH; currentTrackShowArrowsPref = view.getSettings().CURRENT_TRACK_SHOW_ARROWS; currentTrackShowStartFinishPref = view.getSettings().CURRENT_TRACK_SHOW_START_FINISH; @@ -694,9 +700,7 @@ public class GPXLayer extends OsmandMapLayer implements IContextMenuProvider, IM updatePaints(color, width, selectedGpxFile.isRoutePoints(), currentTrack, settings, tileBox); if (ts.renderer instanceof Renderable.RenderableSegment) { Renderable.RenderableSegment renderableSegment = (Renderable.RenderableSegment) ts.renderer; - if (scaleType != null) { - renderableSegment.setGradientScaleType(scaleType); - } + renderableSegment.setGradientScaleType(scaleType); renderableSegment.drawSegment(view.getZoom(), paint, canvas, tileBox); } } @@ -769,6 +773,16 @@ public class GPXLayer extends OsmandMapLayer implements IContextMenuProvider, IM private int[] getColorizationPalette(GPXFile gpxFile, GradientScaleType scaleType) { if (hasTrackDrawInfoForTrack(gpxFile)) { return trackDrawInfo.getGradientPalette(scaleType); + } else if (gpxFile.showCurrentTrack) { + String palette; + if (scaleType == GradientScaleType.SPEED) { + palette = currentTrackSpeedGradientPalette.get(); + } else if (scaleType == GradientScaleType.ALTITUDE) { + palette = currentTrackAltitudeGradientPalette.get(); + } else { + palette = currentTrackSlopeGradientPalette.get(); + } + return Algorithms.stringToArray(palette); } GpxDataItem dataItem = gpxDbHelper.getItem(new File(gpxFile.path)); if (dataItem == null) {