Small fixes & saving gradient palette of speed/altitude/slope scale types

This commit is contained in:
cepprice 2021-03-12 20:04:51 +05:00
parent 772df1dd46
commit 979c10aba4
13 changed files with 136 additions and 100 deletions

View file

@ -209,7 +209,7 @@ public class RouteColorize {
} }
setPalette(new double[][] { setPalette(new double[][] {
{minValue, gradientPalette[0]}, {minValue, gradientPalette[0]},
{colorizationType == ColorizationType.SLOPE ? 0 : (minValue + maxValue) / 2}, {colorizationType == ColorizationType.SLOPE ? 0 : (minValue + maxValue) / 2, gradientPalette[1]},
{maxValue, gradientPalette[2]} {maxValue, gradientPalette[2]}
}); });
} }

View file

@ -3,7 +3,7 @@
xmlns:osmand="http://schemas.android.com/apk/res-auto" xmlns:osmand="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools" xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="wrap_content"
android:orientation="vertical" android:orientation="vertical"
android:padding="@dimen/content_padding" android:padding="@dimen/content_padding"
android:paddingStart="@dimen/content_padding" android:paddingStart="@dimen/content_padding"

View file

@ -1,8 +1,5 @@
package net.osmand.plus; package net.osmand.plus;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import net.osmand.GPXUtilities.GPXFile; import net.osmand.GPXUtilities.GPXFile;
import net.osmand.GPXUtilities.GPXTrackAnalysis; import net.osmand.GPXUtilities.GPXTrackAnalysis;
import net.osmand.IndexConstants; import net.osmand.IndexConstants;
@ -16,6 +13,9 @@ import java.io.File;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
public class GPXDatabase { public class GPXDatabase {
private static final int DB_VERSION = 11; private static final int DB_VERSION = 11;
@ -751,7 +751,9 @@ 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.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); item.gradientSlopePalette = Algorithms.stringToGradientPalette(gradientSlopePalette);
try { try {
item.gradientScaleType = Algorithms.isEmpty(gradientScaleType) ? null : GradientScaleType.valueOf(gradientScaleType.toUpperCase()); item.gradientScaleType = GradientScaleType.getGradientTypeByName(gradientScaleType);
} catch (IllegalArgumentException e) { } catch (IllegalArgumentException e) {
item.gradientScaleType = null; item.gradientScaleType = null;
} }

View file

@ -78,7 +78,7 @@ public class GpxDbHelper {
return res; 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); boolean res = db.updateGradientScaleColor(item, gradientScaleType, palette);
putToCache(item); putToCache(item);
return res; return res;

View file

@ -12,7 +12,8 @@ public class EnumStringPreference<E extends Enum<E>> extends CommonPreference<E>
@Override @Override
protected E getValue(Object prefs, E defaultValue) { protected E getValue(Object prefs, E defaultValue) {
try { 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); E value = parseString(name);
return value != null ? value : defaultValue; return value != null ? value : defaultValue;
} catch (ClassCastException ex) { } catch (ClassCastException ex) {
@ -23,7 +24,8 @@ public class EnumStringPreference<E extends Enum<E>> extends CommonPreference<E>
@Override @Override
public boolean setValue(Object prefs, E val) { 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 @Override

View file

@ -1409,29 +1409,10 @@ 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 CommonPreference<GradientScaleType>(this, "current_track_colorization", null) { public final CommonPreference<GradientScaleType> CURRENT_TRACK_COLORIZATION = new EnumStringPreference<>(this, "current_track_colorization", null, GradientScaleType.values()).makeGlobal().makeShared().cache();
@Override public final CommonPreference<String> CURRENT_TRACK_SPEED_GRADIENT_PALETTE = new StringPreference(this, "current_track_speed_gradient_palette", null).makeGlobal().makeShared().cache();
protected GradientScaleType getValue(Object prefs, GradientScaleType defaultValue) { public final CommonPreference<String> CURRENT_TRACK_ALTITUDE_GRADIENT_PALETTE = new StringPreference(this, "current_track_altitude_gradient_palette", null).makeGlobal().makeShared().cache();
String name = getSettingsAPI().getString(prefs, getId(), null); public final CommonPreference<String> CURRENT_TRACK_SLOPE_GRADIENT_PALETTE = new StringPreference(this, "current_track_slope_gradient_palette", null).makeGlobal().makeShared().cache();
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<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

@ -84,9 +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.updateGradientScalePalette(dataItem, GradientScaleType.SPEED, appearanceInfo.gradientSpeedPalette);
gpxDbHelper.updateGradientScaleColor(dataItem, GradientScaleType.ALTITUDE, appearanceInfo.gradientAltitudePalette); gpxDbHelper.updateGradientScalePalette(dataItem, GradientScaleType.ALTITUDE, appearanceInfo.gradientAltitudePalette);
gpxDbHelper.updateGradientScaleColor(dataItem, GradientScaleType.SLOPE, appearanceInfo.gradientSlopePalette); gpxDbHelper.updateGradientScalePalette(dataItem, GradientScaleType.SLOPE, appearanceInfo.gradientSlopePalette);
} }
private void createGpxAppearanceInfo() { private void createGpxAppearanceInfo() {

View file

@ -14,15 +14,17 @@ import net.osmand.plus.helpers.AndroidUiHelper;
import net.osmand.plus.routepreparationmenu.cards.BaseCard; import net.osmand.plus.routepreparationmenu.cards.BaseCard;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
public class GradientCard extends BaseCard { public class GradientCard extends BaseCard {
private GPXTrackAnalysis gpxTrackAnalysis; 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); super(mapActivity);
this.gpxTrackAnalysis = gpxTrackAnalysis; this.gpxTrackAnalysis = gpxTrackAnalysis;
this.selectedScaleType = selectedScaleType;
} }
@Override @Override
@ -72,10 +74,11 @@ public class GradientCard extends BaseCard {
return (int) value + " %"; return (int) value + " %";
} }
String speed = OsmAndFormatter.getFormattedSpeed(value, app); String speed = OsmAndFormatter.getFormattedSpeed(value, app);
String speedUnit = app.getSettings().SPEED_SYSTEM.get().toShortString(app);
Spannable formattedSpeed = new SpannableString(speed); Spannable formattedSpeed = new SpannableString(speed);
formattedSpeed.setSpan( formattedSpeed.setSpan(
new ForegroundColorSpan(AndroidUtils.getColorFromAttr(app, android.R.attr.textColorSecondary)), 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; return formattedSpeed;
} }
} }

View file

@ -160,6 +160,9 @@ public class TrackAppearanceFragment extends ContextMenuScrollFragment implement
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.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.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());
@ -579,12 +582,18 @@ public class TrackAppearanceFragment extends ContextMenuScrollFragment implement
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_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_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());
} else if (gpxDataItem != null) { } else if (gpxDataItem != null) {
GpxSplitType splitType = GpxSplitType.getSplitTypeByTypeId(trackDrawInfo.getSplitType()); GpxSplitType splitType = GpxSplitType.getSplitTypeByTypeId(trackDrawInfo.getSplitType());
gpxDbHelper.updateColor(gpxDataItem, trackDrawInfo.getColor()); 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.updateWidth(gpxDataItem, trackDrawInfo.getWidth());
gpxDbHelper.updateShowArrows(gpxDataItem, trackDrawInfo.isShowArrows()); gpxDbHelper.updateShowArrows(gpxDataItem, trackDrawInfo.isShowArrows());
// gpxDbHelper.updateShowStartFinish(gpxDataItem, trackDrawInfo.isShowStartFinish()); // gpxDbHelper.updateShowStartFinish(gpxDataItem, trackDrawInfo.isShowStartFinish());
@ -662,9 +671,8 @@ public class TrackAppearanceFragment extends ContextMenuScrollFragment implement
setupColorsCard(cardsContainer); setupColorsCard(cardsContainer);
gradientCard = new GradientCard(mapActivity, selectedGpxFile.getTrackAnalysis(app)); gradientCard = new GradientCard(mapActivity, selectedGpxFile.getTrackAnalysis(app), trackDrawInfo.getGradientScaleType());
AndroidUiHelper.updateVisibility(gradientCard.build(mapActivity), false); cardsContainer.addView(gradientCard.build(mapActivity));
cardsContainer.addView(gradientCard.getView());
trackWidthCard = new TrackWidthCard(mapActivity, trackDrawInfo, new OnNeedScrollListener() { trackWidthCard = new TrackWidthCard(mapActivity, trackDrawInfo, new OnNeedScrollListener() {
@ -692,7 +700,8 @@ public class TrackAppearanceFragment extends ContextMenuScrollFragment implement
List<Integer> colors = getTrackColors(); List<Integer> colors = getTrackColors();
colorsCard = new ColorsCard(mapActivity, trackDrawInfo.getColor(), this, colors, app.getSettings().CUSTOM_TRACK_COLORS, null); colorsCard = new ColorsCard(mapActivity, trackDrawInfo.getColor(), this, colors, app.getSettings().CUSTOM_TRACK_COLORS, null);
colorsCard.setListener(this); colorsCard.setListener(this);
cardsContainer.addView(colorsCard.build(mapActivity)); AndroidUiHelper.updateVisibility(colorsCard.build(mapActivity), trackDrawInfo.getGradientScaleType() == null);
cardsContainer.addView(colorsCard.getView());
} }
} }

View file

@ -1,5 +1,6 @@
package net.osmand.plus.track; package net.osmand.plus.track;
import android.content.Context;
import android.graphics.drawable.GradientDrawable; import android.graphics.drawable.GradientDrawable;
import android.os.Build; import android.os.Build;
import android.view.LayoutInflater; import android.view.LayoutInflater;
@ -188,6 +189,7 @@ public class TrackColoringCard extends BaseCard {
private void updateButtonBg(TrackAppearanceViewHolder holder, TrackAppearanceItem item) { private void updateButtonBg(TrackAppearanceViewHolder holder, TrackAppearanceItem item) {
GradientDrawable rectContourDrawable = (GradientDrawable) AppCompatResources.getDrawable(app, R.drawable.bg_select_group_button_outline); GradientDrawable rectContourDrawable = (GradientDrawable) AppCompatResources.getDrawable(app, R.drawable.bg_select_group_button_outline);
if (rectContourDrawable != null) { if (rectContourDrawable != null) {
Context ctx = holder.itemView.getContext();
boolean itemSelected = getSelectedAppearanceItem() != null && getSelectedAppearanceItem().equals(item); boolean itemSelected = getSelectedAppearanceItem() != null && getSelectedAppearanceItem().equals(item);
int strokeColor; int strokeColor;
@ -195,39 +197,40 @@ public class TrackColoringCard extends BaseCard {
int strokeWidth; int strokeWidth;
if (itemSelected) { if (itemSelected) {
strokeColor = AndroidUtils.getColorFromAttr(app, R.attr.pstsIndicatorColor); strokeColor = AndroidUtils.getColorFromAttr(ctx, R.attr.colorPrimary);
backgroundColor = 0; backgroundColor = 0;
strokeWidth = 2; strokeWidth = 2;
} else if (!item.isActive()) { } else if (!item.isActive()) {
strokeColor = AndroidUtils.getColorFromAttr(app, R.attr.stroked_buttons_and_links_outline); strokeColor = AndroidUtils.getColorFromAttr(ctx, R.attr.stroked_buttons_and_links_outline);
backgroundColor = AndroidUtils.getColorFromAttr(app, R.attr.ctx_menu_card_btn); backgroundColor = AndroidUtils.getColorFromAttr(ctx, R.attr.ctx_menu_card_btn);
strokeWidth = 2; strokeWidth = 2;
} else { } 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; backgroundColor = 0;
strokeWidth = 1; strokeWidth = 1;
} }
rectContourDrawable.mutate(); rectContourDrawable.mutate();
rectContourDrawable.setColor(backgroundColor); rectContourDrawable.setColor(backgroundColor);
rectContourDrawable.setStroke(AndroidUtils.dpToPx(app, strokeWidth), strokeColor); rectContourDrawable.setStroke(AndroidUtils.dpToPx(ctx, strokeWidth), strokeColor);
holder.button.setImageDrawable(rectContourDrawable); holder.button.setImageDrawable(rectContourDrawable);
} }
} }
private void updateTextAndIconColor(TrackAppearanceViewHolder holder, TrackAppearanceItem item) { private void updateTextAndIconColor(TrackAppearanceViewHolder holder, TrackAppearanceItem item) {
Context ctx = holder.itemView.getContext();
boolean isSelected = item.getAttrName().equals(getSelectedAppearanceItem().getAttrName()); boolean isSelected = item.getAttrName().equals(getSelectedAppearanceItem().getAttrName());
int iconColorId; int iconColorId;
int textColorId; int textColorId;
if (isSelected) { if (isSelected) {
iconColorId = AndroidUtils.getColorFromAttr(app, R.attr.default_icon_color); iconColorId = AndroidUtils.getColorFromAttr(ctx, R.attr.default_icon_color);
textColorId = AndroidUtils.getColorFromAttr(app, android.R.attr.textColor); textColorId = AndroidUtils.getColorFromAttr(ctx, android.R.attr.textColor);
} else if (!item.isActive()) { } else if (!item.isActive()) {
iconColorId = AndroidUtils.getColorFromAttr(app, R.attr.default_icon_color); iconColorId = AndroidUtils.getColorFromAttr(ctx, R.attr.default_icon_color);
textColorId = AndroidUtils.getColorFromAttr(app, android.R.attr.textColorSecondary); textColorId = AndroidUtils.getColorFromAttr(ctx, android.R.attr.textColorSecondary);
} else { } else {
iconColorId = AndroidUtils.getColorFromAttr(app, R.attr.pstsIndicatorColor); iconColorId = AndroidUtils.getColorFromAttr(ctx, R.attr.colorPrimary);
textColorId = iconColorId; textColorId = iconColorId;
} }

View file

@ -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() { public int getSplitType() {
return splitType; return splitType;
} }

View file

@ -6,8 +6,6 @@ import android.graphics.Paint;
import android.graphics.Path; import android.graphics.Path;
import android.graphics.Shader; import android.graphics.Shader;
import androidx.annotation.NonNull;
import net.osmand.GPXUtilities; import net.osmand.GPXUtilities;
import net.osmand.GPXUtilities.WptPt; import net.osmand.GPXUtilities.WptPt;
import net.osmand.data.QuadRect; import net.osmand.data.QuadRect;
@ -27,6 +25,8 @@ import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicInteger;
import androidx.annotation.NonNull;
public class Renderable { public class Renderable {
@ -103,12 +103,18 @@ public class Renderable {
protected abstract void startCuller(double newZoom); 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 (points.size() < 2) {
return;
}
updateLocalPaint(p);
canvas.rotate(-tileBox.getRotate(), tileBox.getCenterPixelX(), tileBox.getCenterPixelY());
if (scaleType != null) { if (scaleType != null) {
drawGradient(getPointsForDrawing(), p, canvas, tileBox); drawGradient(getPointsForDrawing(), p, canvas, tileBox);
scaleType = null;
} else { } else {
drawSolid(getPointsForDrawing(), p, canvas, tileBox); drawSolid(getPointsForDrawing(), p, canvas, tileBox);
} }
canvas.rotate(tileBox.getRotate(), tileBox.getCenterPixelX(), tileBox.getCenterPixelY());
} }
@ -139,17 +145,13 @@ public class Renderable {
} }
protected void drawSolid(List<WptPt> pts, Paint p, Canvas canvas, RotatedTileBox tileBox) { protected void drawSolid(List<WptPt> 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(); QuadRect tileBounds = tileBox.getLatLonBounds();
WptPt lastPt = pts.get(0); WptPt lastPt = pts.get(0);
boolean recalculateLastXY = true; boolean recalculateLastXY = true;
Path path = new Path(); Path path = new Path();
for (int i = 1; i < pts.size(); i++) { for (int i = 1; i < pts.size(); i++) {
WptPt pt = pts.get(i); WptPt pt = pts.get(i);
if (Math.min(pt.lon, lastPt.lon) < tileBounds.right && Math.max(pt.lon, lastPt.lon) > tileBounds.left if (arePointsInsideTile(pt, lastPt, tileBounds)) {
&& Math.min(pt.lat, lastPt.lat) < tileBounds.top && Math.max(pt.lat, lastPt.lat) > tileBounds.bottom) {
if (recalculateLastXY) { if (recalculateLastXY) {
recalculateLastXY = false; recalculateLastXY = false;
float lastX = tileBox.getPixXFromLatLon(lastPt.lat, lastPt.lon); float lastX = tileBox.getPixXFromLatLon(lastPt.lat, lastPt.lon);
@ -171,23 +173,16 @@ public class Renderable {
if (!path.isEmpty()) { if (!path.isEmpty()) {
canvas.drawPath(path, paint); canvas.drawPath(path, paint);
} }
canvas.rotate(tileBox.getRotate(), tileBox.getCenterPixelX(), tileBox.getCenterPixelY());
}
} }
protected void drawGradient(List<WptPt> pts, Paint p, Canvas canvas, RotatedTileBox tileBox) { protected void drawGradient(List<WptPt> 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(); QuadRect tileBounds = tileBox.getLatLonBounds();
Path path = new Path();
Paint paint = new Paint(this.paint);
WptPt prevPt = pts.get(0); WptPt prevPt = pts.get(0);
for (int i = 1; i < pts.size(); i++) { for (int i = 1; i < pts.size(); i++) {
WptPt currentPt = pts.get(i); WptPt currentPt = pts.get(i);
if (Math.min(currentPt.lon, prevPt.lon) < tileBounds.right && Math.max(currentPt.lon, prevPt.lon) > tileBounds.left if (arePointsInsideTile(currentPt, prevPt, tileBounds)) {
&& Math.min(currentPt.lat, prevPt.lat) < tileBounds.top && Math.max(currentPt.lat, prevPt.lat) > tileBounds.bottom) {
float startX = tileBox.getPixXFromLatLon(prevPt.lat, prevPt.lon); float startX = tileBox.getPixXFromLatLon(prevPt.lat, prevPt.lon);
float startY = tileBox.getPixYFromLatLon(prevPt.lat, prevPt.lon); float startY = tileBox.getPixYFromLatLon(prevPt.lat, prevPt.lon);
float endX = tileBox.getPixXFromLatLon(currentPt.lat, currentPt.lon); float endX = tileBox.getPixXFromLatLon(currentPt.lat, currentPt.lon);
@ -195,16 +190,19 @@ public class Renderable {
int prevColor = prevPt.getColor(scaleType.toColorizationType()); int prevColor = prevPt.getColor(scaleType.toColorizationType());
int currentColor = currentPt.getColor(scaleType.toColorizationType()); int currentColor = currentPt.getColor(scaleType.toColorizationType());
LinearGradient gradient = new LinearGradient(startX, startY, endX, endY, prevColor, currentColor, Shader.TileMode.CLAMP); LinearGradient gradient = new LinearGradient(startX, startY, endX, endY, prevColor, currentColor, Shader.TileMode.CLAMP);
Paint paint = new Paint(this.paint);
paint.setShader(gradient); paint.setShader(gradient);
Path path = new Path(); path.reset();
path.moveTo(startX, startY); path.moveTo(startX, startY);
path.lineTo(endX, endY); path.lineTo(endX, endY);
canvas.drawPath(path, paint); canvas.drawPath(path, paint);
} }
prevPt = currentPt; 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;
} }
} }

View file

@ -145,6 +145,9 @@ public class GPXLayer extends OsmandMapLayer implements IContextMenuProvider, IM
private CommonPreference<Integer> currentTrackColorPref; private CommonPreference<Integer> currentTrackColorPref;
private CommonPreference<GradientScaleType> currentTrackScaleType; private CommonPreference<GradientScaleType> currentTrackScaleType;
private CommonPreference<String> currentTrackSpeedGradientPalette;
private CommonPreference<String> currentTrackAltitudeGradientPalette;
private CommonPreference<String> currentTrackSlopeGradientPalette;
private CommonPreference<String> currentTrackWidthPref; private CommonPreference<String> currentTrackWidthPref;
private CommonPreference<Boolean> currentTrackShowArrowsPref; private CommonPreference<Boolean> currentTrackShowArrowsPref;
private CommonPreference<Boolean> currentTrackShowStartFinishPref; private CommonPreference<Boolean> currentTrackShowStartFinishPref;
@ -159,6 +162,9 @@ public class GPXLayer extends OsmandMapLayer implements IContextMenuProvider, IM
currentTrackColorPref = view.getSettings().CURRENT_TRACK_COLOR; currentTrackColorPref = view.getSettings().CURRENT_TRACK_COLOR;
currentTrackScaleType = view.getSettings().CURRENT_TRACK_COLORIZATION; 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; currentTrackWidthPref = view.getSettings().CURRENT_TRACK_WIDTH;
currentTrackShowArrowsPref = view.getSettings().CURRENT_TRACK_SHOW_ARROWS; currentTrackShowArrowsPref = view.getSettings().CURRENT_TRACK_SHOW_ARROWS;
currentTrackShowStartFinishPref = view.getSettings().CURRENT_TRACK_SHOW_START_FINISH; 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); updatePaints(color, width, selectedGpxFile.isRoutePoints(), currentTrack, settings, tileBox);
if (ts.renderer instanceof Renderable.RenderableSegment) { if (ts.renderer instanceof Renderable.RenderableSegment) {
Renderable.RenderableSegment renderableSegment = (Renderable.RenderableSegment) ts.renderer; Renderable.RenderableSegment renderableSegment = (Renderable.RenderableSegment) ts.renderer;
if (scaleType != null) {
renderableSegment.setGradientScaleType(scaleType); renderableSegment.setGradientScaleType(scaleType);
}
renderableSegment.drawSegment(view.getZoom(), paint, canvas, tileBox); 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) { private int[] getColorizationPalette(GPXFile gpxFile, GradientScaleType scaleType) {
if (hasTrackDrawInfoForTrack(gpxFile)) { if (hasTrackDrawInfoForTrack(gpxFile)) {
return trackDrawInfo.getGradientPalette(scaleType); 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)); GpxDataItem dataItem = gpxDbHelper.getItem(new File(gpxFile.path));
if (dataItem == null) { if (dataItem == null) {