Merge pull request #9330 from osmandapp/gpx_appearance

Gpx track appearance
This commit is contained in:
max-klaus 2020-07-13 12:35:14 +03:00 committed by GitHub
commit 29e8e1facc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
12 changed files with 1154 additions and 577 deletions

View file

@ -1,6 +1,7 @@
package net.osmand;
import net.osmand.data.QuadRect;
import net.osmand.util.Algorithms;
@ -42,7 +43,9 @@ import java.util.Stack;
import java.util.TimeZone;
public class GPXUtilities {
public final static Log log = PlatformUtil.getLog(GPXUtilities.class);
private static final String ICON_NAME_EXTENSION = "icon";
private static final String DEFAULT_ICON_NAME = "special_star";
private static final String BACKGROUND_TYPE_EXTENSION = "background";
@ -115,6 +118,13 @@ public class GPXUtilities {
return extensions;
}
public Map<String, String> getExtensionsToWrite() {
if (extensions == null) {
extensions = new LinkedHashMap<>();
}
return extensions;
}
public GPXExtensionsWriter getExtensionsWriter() {
return extensionsWriter;
}
@ -148,14 +158,7 @@ public class GPXUtilities {
getExtensionsToWrite().remove("color");
}
public Map<String, String> getExtensionsToWrite() {
if (extensions == null) {
extensions = new LinkedHashMap<>();
}
return extensions;
}
private int parseColor(String colorString, int defColor) {
protected int parseColor(String colorString, int defColor) {
if (!Algorithms.isEmpty(colorString)) {
if (colorString.charAt(0) == '#') {
long color = Long.parseLong(colorString.substring(1), 16);
@ -1510,6 +1513,139 @@ public class GPXUtilities {
}
return new QuadRect(left, top, right, bottom);
}
public int getGradientScaleColor(GradientScaleType gradientScaleType, int defColor) {
String clrValue = null;
if (extensions != null) {
clrValue = extensions.get(gradientScaleType.getTypeName());
}
return parseColor(clrValue, defColor);
}
public void setGradientScaleColor(GradientScaleType gradientScaleType, int gradientScaleColor) {
getExtensionsToWrite().put(gradientScaleType.getTypeName(), Algorithms.colorToString(gradientScaleColor));
}
public GradientScaleType getGradientScaleType() {
if (extensions != null) {
String gradientScaleTypeName = extensions.get("gradient_scale_type");
if (!Algorithms.isEmpty(gradientScaleTypeName)) {
try {
return GradientScaleType.valueOf(gradientScaleTypeName);
} catch (IllegalArgumentException e) {
log.error("Error reading gradientScaleType", e);
}
}
}
return null;
}
public void setGradientScaleType(GradientScaleType gradientScaleType) {
getExtensionsToWrite().put("gradient_scale_type", gradientScaleType.name());
}
public GpxSplitType getSplitType() {
if (extensions != null) {
String gradientScaleTypeName = extensions.get("split_type");
if (!Algorithms.isEmpty(gradientScaleTypeName)) {
try {
return GpxSplitType.valueOf(gradientScaleTypeName);
} catch (IllegalArgumentException e) {
log.error("Error reading GpxSplitType", e);
}
}
}
return null;
}
public void setSplitType(GpxSplitType gpxSplitType) {
getExtensionsToWrite().put("split_type", gpxSplitType.name());
}
public double getSplitInterval() {
if (extensions != null) {
String splitIntervalStr = extensions.get("split_interval");
if (!Algorithms.isEmpty(splitIntervalStr)) {
try {
return Double.parseDouble(splitIntervalStr);
} catch (NumberFormatException e) {
log.error("Error reading split_interval", e);
}
}
}
return 0;
}
public void setSplitInterval(double splitInterval) {
getExtensionsToWrite().put("split_interval", String.valueOf(splitInterval));
}
public String getWidth(String defWidth) {
String widthValue = null;
if (extensions != null) {
widthValue = extensions.get("width");
}
return widthValue != null ? widthValue : defWidth;
}
public void setWidth(String width) {
getExtensionsToWrite().put("width", width);
}
public boolean isShowArrows() {
String showArrows = null;
if (extensions != null) {
showArrows = extensions.get("show_arrows");
}
return Boolean.parseBoolean(showArrows);
}
public void setShowArrows(boolean showArrows) {
getExtensionsToWrite().put("show_arrows", String.valueOf(showArrows));
}
public boolean isShowStartFinish() {
if (extensions != null && extensions.containsKey("show_start_finish")) {
return Boolean.parseBoolean(extensions.get("show_start_finish"));
}
return true;
}
public void setShowStartFinish(boolean showStartFinish) {
getExtensionsToWrite().put("show_start_finish", String.valueOf(showStartFinish));
}
public enum GradientScaleType {
SPEED("gradient_speed_color"),
ALTITUDE("gradient_altitude_color"),
SLOPE("gradient_slope_color");
private String typeName;
GradientScaleType(String typeName) {
this.typeName = typeName;
}
public String getTypeName() {
return typeName;
}
}
public enum GpxSplitType {
NO_SPLIT(-1),
DISTANCE(1),
TIME(2);
private int type;
GpxSplitType(int type) {
this.type = type;
}
public int getType() {
return type;
}
}
}
public static String asString(GPXFile file) {

View file

@ -43,6 +43,7 @@ import net.osmand.data.PointDescription;
import net.osmand.plus.AppInitializer;
import net.osmand.plus.AppInitializer.AppInitializeListener;
import net.osmand.plus.AppInitializer.InitEvents;
import net.osmand.plus.dialogs.GpxAppearanceAdapter;
import net.osmand.plus.settings.backend.ApplicationMode;
import net.osmand.plus.ContextMenuAdapter;
import net.osmand.plus.ContextMenuItem;
@ -60,7 +61,6 @@ import net.osmand.plus.SQLiteTileSource;
import net.osmand.plus.settings.backend.SettingsHelper;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.audionotes.AudioVideoNotesPlugin;
import net.osmand.plus.dialogs.ConfigureMapMenu;
import net.osmand.plus.helpers.ColorDialogs;
import net.osmand.plus.helpers.ExternalApiHelper;
import net.osmand.plus.mapcontextmenu.MapContextMenu;
@ -1146,7 +1146,7 @@ public class OsmandAidlApi {
@SuppressLint("StaticFieldLeak")
private void finishGpxImport(boolean destinationExists, File destination, String color, boolean show) {
final int col = ConfigureMapMenu.GpxAppearanceAdapter.parseTrackColor(
final int col = GpxAppearanceAdapter.parseTrackColor(
app.getRendererRegistry().getCurrentSelectedRenderer(), color);
if (!destinationExists) {
GpxDataItem gpxDataItem = new GpxDataItem(destination, col);
@ -1390,7 +1390,7 @@ public class OsmandAidlApi {
int color = dataItem.getColor();
String colorName = "";
if (color != 0) {
colorName = ConfigureMapMenu.GpxAppearanceAdapter.parseTrackColorName(app.getRendererRegistry().getCurrentSelectedRenderer(), color);
colorName = GpxAppearanceAdapter.parseTrackColorName(app.getRendererRegistry().getCurrentSelectedRenderer(), color);
}
net.osmand.aidlapi.gpx.AGpxFileDetails details = null;
GPXTrackAnalysis analysis = dataItem.getAnalysis();
@ -1431,7 +1431,7 @@ public class OsmandAidlApi {
if (file.getName().equals(gpxFileName)) {
int color = dataItem.getColor();
if (color != 0) {
return ConfigureMapMenu.GpxAppearanceAdapter.parseTrackColorName(app.getRendererRegistry().getCurrentSelectedRenderer(), color);
return GpxAppearanceAdapter.parseTrackColorName(app.getRendererRegistry().getCurrentSelectedRenderer(), color);
}
}
}

View file

@ -3,6 +3,8 @@ package net.osmand.plus;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import net.osmand.GPXUtilities.GPXFile;
import net.osmand.GPXUtilities.GPXFile.GradientScaleType;
import net.osmand.GPXUtilities.GPXTrackAnalysis;
import net.osmand.IndexConstants;
import net.osmand.plus.api.SQLiteAPI.SQLiteConnection;
@ -15,8 +17,9 @@ import java.util.List;
public class GPXDatabase {
private static final int DB_VERSION = 11;
private static final String DB_NAME = "gpx_database";
private static final int DB_VERSION = 10;
private static final String GPX_TABLE_NAME = "gpxTable";
private static final String GPX_COL_NAME = "fileName";
private static final String GPX_COL_DIR = "fileDir";
@ -56,9 +59,19 @@ public class GPXDatabase {
private static final String GPX_COL_JOIN_SEGMENTS = "joinSegments";
public static final int GPX_SPLIT_TYPE_NO_SPLIT = -1;
public static final int GPX_SPLIT_TYPE_DISTANCE = 1;
public static final int GPX_SPLIT_TYPE_TIME = 2;
private static final String GPX_COL_SHOW_ARROWS = "showArrows";
private static final String GPX_COL_SHOW_START_FINISH = "showStartFinish";
private static final String GPX_COL_WIDTH = "width";
private static final String GPX_COL_GRADIENT_SPEED_COLOR = "gradientSpeedColor";
private static final String GPX_COL_GRADIENT_ALTITUDE_COLOR = "gradientAltitudeColor";
private static final String GPX_COL_GRADIENT_SLOPE_COLOR = "gradientSlopeColor";
private static final String GPX_COL_GRADIENT_SCALE_TYPE = "gradientScaleType";
private static final String GPX_TABLE_CREATE = "CREATE TABLE IF NOT EXISTS " + GPX_TABLE_NAME + " (" +
GPX_COL_NAME + " TEXT, " +
@ -89,7 +102,14 @@ public class GPXDatabase {
GPX_COL_API_IMPORTED + " int, " + // 1 = true, 0 = false
GPX_COL_WPT_CATEGORY_NAMES + " TEXT, " +
GPX_COL_SHOW_AS_MARKERS + " int, " + // 1 = true, 0 = false
GPX_COL_JOIN_SEGMENTS + " int);"; // 1 = true, 0 = false
GPX_COL_JOIN_SEGMENTS + " int, " + // 1 = true, 0 = false
GPX_COL_SHOW_ARROWS + " int, " + // 1 = true, 0 = false
GPX_COL_SHOW_START_FINISH + " int, " + // 1 = true, 0 = false
GPX_COL_WIDTH + " TEXT, " +
GPX_COL_GRADIENT_SPEED_COLOR + " TEXT, " +
GPX_COL_GRADIENT_ALTITUDE_COLOR + " TEXT, " +
GPX_COL_GRADIENT_SLOPE_COLOR + " TEXT, " +
GPX_COL_GRADIENT_SCALE_TYPE+ " TEXT);";
private static final String GPX_TABLE_SELECT = "SELECT " +
GPX_COL_NAME + ", " +
@ -117,8 +137,15 @@ public class GPXDatabase {
GPX_COL_API_IMPORTED + ", " +
GPX_COL_WPT_CATEGORY_NAMES + ", " +
GPX_COL_SHOW_AS_MARKERS + ", " +
GPX_COL_JOIN_SEGMENTS +
" FROM " + GPX_TABLE_NAME;
GPX_COL_JOIN_SEGMENTS + ", " +
GPX_COL_SHOW_ARROWS + ", " +
GPX_COL_SHOW_START_FINISH + ", " +
GPX_COL_WIDTH + ", " +
GPX_COL_GRADIENT_SPEED_COLOR + ", " +
GPX_COL_GRADIENT_ALTITUDE_COLOR + ", " +
GPX_COL_GRADIENT_SLOPE_COLOR + ", " +
GPX_COL_GRADIENT_SCALE_TYPE +
" FROM " + GPX_TABLE_NAME;
private static final String GPX_TABLE_UPDATE_ANALYSIS = "UPDATE " +
GPX_TABLE_NAME + " SET " +
@ -144,15 +171,23 @@ public class GPXDatabase {
private OsmandApplication context;
public static class GpxDataItem {
private File file;
private GPXTrackAnalysis analysis;
private String width;
private GradientScaleType gradientScaleType;
private int color;
private long fileLastModifiedTime;
private int gradientSpeedColor;
private int gradientAltitudeColor;
private int gradientSlopeColor;
private int splitType;
private double splitInterval;
private long fileLastModifiedTime;
private boolean apiImported;
private boolean showAsMarkers;
private boolean joinSegments;
private boolean showArrows;
private boolean showStartFinish;
public GpxDataItem(File file, GPXTrackAnalysis analysis) {
this.file = file;
@ -164,6 +199,22 @@ public class GPXDatabase {
this.color = color;
}
public GpxDataItem(File file, @NonNull GPXFile gpxFile) {
this.file = file;
color = gpxFile.getColor(0);
width = gpxFile.getWidth(null);
showArrows = gpxFile.isShowArrows();
showStartFinish = gpxFile.isShowStartFinish();
gradientScaleType = gpxFile.getGradientScaleType();
gradientSpeedColor = gpxFile.getGradientScaleColor(GradientScaleType.SPEED, 0);
gradientSlopeColor = gpxFile.getGradientScaleColor(GradientScaleType.SLOPE, 0);
gradientAltitudeColor = gpxFile.getGradientScaleColor(GradientScaleType.ALTITUDE, 0);
if (gpxFile.getSplitType() != null && gpxFile.getSplitInterval() != 0) {
splitType = gpxFile.getSplitType().getType();
splitInterval = gpxFile.getSplitInterval();
}
}
public File getFile() {
return file;
}
@ -177,6 +228,27 @@ public class GPXDatabase {
return color;
}
public GradientScaleType getGradientScaleType() {
return gradientScaleType;
}
public int getGradientSpeedColor() {
return gradientSpeedColor;
}
public int getGradientAltitudeColor() {
return gradientAltitudeColor;
}
public int getGradientSlopeColor() {
return gradientSlopeColor;
}
public String getWidth() {
return width;
}
public long getFileLastModifiedTime() {
return fileLastModifiedTime;
}
@ -209,8 +281,12 @@ public class GPXDatabase {
return joinSegments;
}
public void setJoinSegments(boolean joinSegments) {
this.joinSegments = joinSegments;
public boolean isShowArrows() {
return showArrows;
}
public boolean isShowStartFinish() {
return showStartFinish;
}
@Override
@ -273,7 +349,7 @@ public class GPXDatabase {
if (oldVersion < 3) {
db.execSQL("ALTER TABLE " + GPX_TABLE_NAME + " ADD " + GPX_COL_FILE_LAST_MODIFIED_TIME + " long");
}
if (oldVersion < 4) {
db.execSQL("ALTER TABLE " + GPX_TABLE_NAME + " ADD " + GPX_COL_SPLIT_TYPE + " int");
db.execSQL("ALTER TABLE " + GPX_TABLE_NAME + " ADD " + GPX_COL_SPLIT_INTERVAL + " double");
@ -341,6 +417,20 @@ public class GPXDatabase {
" SET " + GPX_COL_JOIN_SEGMENTS + " = ? " +
"WHERE " + GPX_COL_JOIN_SEGMENTS + " IS NULL", new Object[]{0});
}
if (oldVersion < 11) {
db.execSQL("ALTER TABLE " + GPX_TABLE_NAME + " ADD " + GPX_COL_SHOW_ARROWS + " int");
db.execSQL("ALTER TABLE " + GPX_TABLE_NAME + " ADD " + GPX_COL_SHOW_START_FINISH + " int");
db.execSQL("ALTER TABLE " + GPX_TABLE_NAME + " ADD " + GPX_COL_WIDTH + " TEXT");
db.execSQL("ALTER TABLE " + GPX_TABLE_NAME + " ADD " + GPX_COL_GRADIENT_SPEED_COLOR + " TEXT");
db.execSQL("ALTER TABLE " + GPX_TABLE_NAME + " ADD " + GPX_COL_GRADIENT_ALTITUDE_COLOR + " TEXT");
db.execSQL("ALTER TABLE " + GPX_TABLE_NAME + " ADD " + GPX_COL_GRADIENT_SLOPE_COLOR + " TEXT");
db.execSQL("ALTER TABLE " + GPX_TABLE_NAME + " ADD " + GPX_COL_GRADIENT_SCALE_TYPE + " TEXT");
db.execSQL("UPDATE " + GPX_TABLE_NAME + " SET " + GPX_COL_SHOW_ARROWS + " = ? " +
"WHERE " + GPX_COL_SHOW_ARROWS + " IS NULL", new Object[]{0});
db.execSQL("UPDATE " + GPX_TABLE_NAME + " SET " + GPX_COL_SHOW_START_FINISH + " = ? " +
"WHERE " + GPX_COL_SHOW_START_FINISH + " IS NULL", new Object[]{1});
}
db.execSQL("CREATE INDEX IF NOT EXISTS " + GPX_INDEX_NAME_DIR + " ON " + GPX_TABLE_NAME + " (" + GPX_COL_NAME + ", " + GPX_COL_DIR + ");");
}
@ -391,8 +481,7 @@ public class GPXDatabase {
try {
String fileName = getFileName(item.file);
String fileDir = getFileDir(item.file);
db.execSQL("UPDATE " + GPX_TABLE_NAME + " SET " +
GPX_COL_COLOR + " = ? " +
db.execSQL("UPDATE " + GPX_TABLE_NAME + " SET " + GPX_COL_COLOR + " = ? " +
" WHERE " + GPX_COL_NAME + " = ? AND " + GPX_COL_DIR + " = ?",
new Object[] { (color == 0 ? "" : Algorithms.colorToString(color)), fileName, fileDir });
item.color = color;
@ -404,6 +493,106 @@ public class GPXDatabase {
return false;
}
public boolean updateGradientScaleColor(@NonNull GpxDataItem item, @NonNull GradientScaleType gradientScaleType, int gradientScaleColor) {
SQLiteConnection db = openConnection(false);
if (db != null) {
try {
String fileName = getFileName(item.file);
String fileDir = getFileDir(item.file);
String columnName = null;
if (GradientScaleType.SPEED == gradientScaleType) {
columnName = GPX_COL_GRADIENT_SPEED_COLOR;
item.gradientSpeedColor = gradientScaleColor;
} else if (GradientScaleType.ALTITUDE == gradientScaleType) {
columnName = GPX_COL_GRADIENT_ALTITUDE_COLOR;
item.gradientAltitudeColor = gradientScaleColor;
} else if (GradientScaleType.SLOPE == gradientScaleType) {
columnName = GPX_COL_GRADIENT_SLOPE_COLOR;
item.gradientSlopeColor = gradientScaleColor;
}
db.execSQL("UPDATE " + GPX_TABLE_NAME + " SET " + columnName + " = ? " +
" WHERE " + GPX_COL_NAME + " = ? AND " + GPX_COL_DIR + " = ?",
new Object[] {(gradientScaleColor == 0 ? "" : Algorithms.colorToString(gradientScaleColor)), fileName, fileDir});
} finally {
db.close();
}
return true;
}
return false;
}
public boolean updateGradientScaleType(@NonNull GpxDataItem item, GradientScaleType gradientScaleType) {
SQLiteConnection db = openConnection(false);
if (db != null) {
try {
String fileName = getFileName(item.file);
String fileDir = getFileDir(item.file);
db.execSQL("UPDATE " + GPX_TABLE_NAME + " SET " + GPX_COL_GRADIENT_SCALE_TYPE + " = ? " +
" WHERE " + GPX_COL_NAME + " = ? AND " + GPX_COL_DIR + " = ?",
new Object[] {(gradientScaleType == null ? "" : gradientScaleType.name()), fileName, fileDir});
item.gradientScaleType = gradientScaleType;
} finally {
db.close();
}
return true;
}
return false;
}
public boolean updateShowArrows(GpxDataItem item, boolean showArrows) {
SQLiteConnection db = openConnection(false);
if (db != null) {
try {
String fileName = getFileName(item.file);
String fileDir = getFileDir(item.file);
db.execSQL("UPDATE " + GPX_TABLE_NAME + " SET " + GPX_COL_SHOW_ARROWS + " = ? " +
" WHERE " + GPX_COL_NAME + " = ? AND " + GPX_COL_DIR + " = ?",
new Object[] {showArrows ? 1 : 0, fileName, fileDir});
item.showArrows = showArrows;
} finally {
db.close();
}
return true;
}
return false;
}
public boolean updateShowStartFinish(GpxDataItem item, boolean showStartFinish) {
SQLiteConnection db = openConnection(false);
if (db != null) {
try {
String fileName = getFileName(item.file);
String fileDir = getFileDir(item.file);
db.execSQL("UPDATE " + GPX_TABLE_NAME + " SET " + GPX_COL_SHOW_START_FINISH + " = ? " +
" WHERE " + GPX_COL_NAME + " = ? AND " + GPX_COL_DIR + " = ?",
new Object[] {showStartFinish ? 1 : 0, fileName, fileDir});
item.showStartFinish = showStartFinish;
} finally {
db.close();
}
return true;
}
return false;
}
public boolean updateWidth(GpxDataItem item, String width) {
SQLiteConnection db = openConnection(false);
if (db != null) {
try {
String fileName = getFileName(item.file);
String fileDir = getFileDir(item.file);
db.execSQL("UPDATE " + GPX_TABLE_NAME + " SET " + GPX_COL_WIDTH + " = ? " +
" WHERE " + GPX_COL_NAME + " = ? AND " + GPX_COL_DIR + " = ?",
new Object[] {width, fileName, fileDir});
item.width = width;
} finally {
db.close();
}
return true;
}
return false;
}
public boolean updateShowAsMarkers(GpxDataItem item, boolean showAsMarkers) {
SQLiteConnection db = openConnection(false);
if (db != null) {
@ -433,7 +622,7 @@ public class GPXDatabase {
GPX_COL_JOIN_SEGMENTS + " = ? " +
" WHERE " + GPX_COL_NAME + " = ? AND " + GPX_COL_DIR + " = ?",
new Object[]{joinSegments ? 1 : 0, fileName, fileDir});
item.setJoinSegments(joinSegments);
item.joinSegments = joinSegments;
} finally {
db.close();
}
@ -516,14 +705,17 @@ public class GPXDatabase {
} else {
color = Algorithms.colorToString(item.color);
}
String gradientScaleType = item.gradientScaleType != null ? item.gradientScaleType.name() : null;
if (a != null) {
db.execSQL(
"INSERT INTO " + GPX_TABLE_NAME + " VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
"INSERT INTO " + GPX_TABLE_NAME + " VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
new Object[] {fileName, fileDir, a.totalDistance, a.totalTracks, a.startTime, a.endTime,
a.timeSpan, a.timeMoving, a.totalDistanceMoving, a.diffElevationUp, a.diffElevationDown,
a.avgElevation, a.minElevation, a.maxElevation, a.maxSpeed, a.avgSpeed, a.points, a.wptPoints,
color, item.file.lastModified(), item.splitType, item.splitInterval, item.apiImported ? 1 : 0,
Algorithms.encodeStringSet(item.analysis.wptCategoryNames), item.showAsMarkers ? 1 : 0, item.joinSegments ? 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.gradientSpeedColor, item.gradientAltitudeColor, item.gradientSlopeColor, gradientScaleType});
} else {
db.execSQL("INSERT INTO " + GPX_TABLE_NAME + "(" +
GPX_COL_NAME + ", " +
@ -534,9 +726,19 @@ public class GPXDatabase {
GPX_COL_SPLIT_INTERVAL + ", " +
GPX_COL_API_IMPORTED + ", " +
GPX_COL_SHOW_AS_MARKERS + ", " +
GPX_COL_JOIN_SEGMENTS +
") VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)",
new Object[] {fileName, fileDir, color, 0, item.splitType, item.splitInterval, item.apiImported ? 1 : 0, item.showAsMarkers ? 1 : 0, item.joinSegments ? 1 : 0});
GPX_COL_JOIN_SEGMENTS + ", " +
GPX_COL_SHOW_ARROWS + ", " +
GPX_COL_SHOW_START_FINISH + ", " +
GPX_COL_WIDTH + ", " +
GPX_COL_GRADIENT_SPEED_COLOR + ", " +
GPX_COL_GRADIENT_ALTITUDE_COLOR + ", " +
GPX_COL_GRADIENT_SLOPE_COLOR + ", " +
GPX_COL_GRADIENT_SCALE_TYPE +
") VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
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.gradientSpeedColor, item.gradientAltitudeColor, item.gradientSlopeColor, gradientScaleType});
}
}
@ -617,6 +819,13 @@ public class GPXDatabase {
String wptCategoryNames = query.getString(23);
boolean showAsMarkers = query.getInt(24) == 1;
boolean joinSegments = query.getInt(25) == 1;
boolean showArrows = query.getInt(26) == 1;
boolean showStartFinish = query.getInt(27) == 1;
String width = query.getString(28);
String gradientSpeedColor = query.getString(29);
String gradientAltitudeColor = query.getString(30);
String gradientSlopeColor = query.getString(31);
String gradientScaleType = query.getString(32);
GPXTrackAnalysis a = new GPXTrackAnalysis();
a.totalDistance = totalDistance;
@ -647,20 +856,37 @@ public class GPXDatabase {
dir = context.getAppPath(IndexConstants.GPX_INDEX_DIR);
}
GpxDataItem item = new GpxDataItem(new File(dir, fileName), a);
try {
item.color = Algorithms.isEmpty(color) ? 0 : Algorithms.parseColor(color);
} catch (IllegalArgumentException e) {
item.color = 0;
}
item.color = parseColor(color);
item.fileLastModifiedTime = fileLastModifiedTime;
item.splitType = splitType;
item.splitInterval = splitInterval;
item.apiImported = apiImported;
item.showAsMarkers = showAsMarkers;
item.joinSegments = joinSegments;
item.showArrows = showArrows;
item.showStartFinish = showStartFinish;
item.width = width;
item.gradientSpeedColor = parseColor(gradientSpeedColor);
item.gradientAltitudeColor = parseColor(gradientAltitudeColor);
item.gradientSlopeColor = parseColor(gradientSlopeColor);
try {
item.gradientScaleType = Algorithms.isEmpty(gradientScaleType) ? null : GradientScaleType.valueOf(gradientScaleType);
} catch (IllegalArgumentException e) {
item.gradientScaleType = null;
}
return item;
}
private int parseColor(String color) {
try {
return Algorithms.isEmpty(color) ? 0 : Algorithms.parseColor(color);
} catch (IllegalArgumentException e) {
return 0;
}
}
@NonNull
public List<GpxDataItem> getItems() {
List<GpxDataItem> items = new ArrayList<>();

View file

@ -8,6 +8,8 @@ import androidx.annotation.Nullable;
import net.osmand.GPXUtilities;
import net.osmand.GPXUtilities.GPXFile;
import net.osmand.GPXUtilities.GPXFile.GpxSplitType;
import net.osmand.GPXUtilities.GPXFile.GradientScaleType;
import net.osmand.GPXUtilities.GPXTrackAnalysis;
import net.osmand.plus.GPXDatabase.GpxDataItem;
import net.osmand.plus.api.SQLiteAPI.SQLiteConnection;
@ -77,19 +79,49 @@ public class GpxDbHelper {
return res;
}
public boolean updateGradientScaleColor(@NonNull GpxDataItem item, @NonNull GradientScaleType gradientScaleType, int color) {
boolean res = db.updateGradientScaleColor(item, gradientScaleType, color);
putToCache(item);
return res;
}
public boolean updateGradientScaleType(@NonNull GpxDataItem item, @Nullable GradientScaleType gradientScaleType) {
boolean res = db.updateGradientScaleType(item, gradientScaleType);
putToCache(item);
return res;
}
public boolean updateShowAsMarkers(GpxDataItem item, boolean showAsMarkers) {
boolean res = db.updateShowAsMarkers(item, showAsMarkers);
putToCache(item);
return res;
}
public boolean updateSplit(@NonNull GpxDataItem item, int splitType, double splitInterval) {
boolean res = db.updateSplit(item, splitType, splitInterval);
public boolean updateShowArrows(GpxDataItem item, boolean showArrows) {
boolean res = db.updateShowArrows(item, showArrows);
putToCache(item);
return res;
}
public boolean updateJoinSegments(@NonNull GpxDataItem item, boolean joinSegments) {
public boolean updateShowStartFinish(GpxDataItem item, boolean showStartFinish) {
boolean res = db.updateShowStartFinish(item, showStartFinish);
putToCache(item);
return res;
}
public boolean updateWidth(GpxDataItem item, String width) {
boolean res = db.updateWidth(item, width);
putToCache(item);
return res;
}
public boolean updateSplit(@NonNull GpxDataItem item, @NonNull GpxSplitType splitType, double splitInterval) {
boolean res = db.updateSplit(item, splitType.getType(), splitInterval);
putToCache(item);
return res;
}
public boolean updateJoinSegments(@NonNull GpxDataItem item, boolean joinSegments) {
boolean res = db.updateJoinSegments(item, joinSegments);
putToCache(item);
return res;
@ -157,7 +189,7 @@ public class GpxDbHelper {
}
private void readGpxItem(@NonNull File gpxFile, @Nullable GpxDataItem item, @Nullable GpxDataItemCallback callback) {
readingItemsMap.put(gpxFile, item != null ? item : new GpxDataItem(null, null));
readingItemsMap.put(gpxFile, item != null ? item : new GpxDataItem(null, (GPXTrackAnalysis) null));
if (callback != null) {
readingItemsCallbacks.put(gpxFile, callback);
}

View file

@ -11,6 +11,8 @@ import androidx.core.content.ContextCompat;
import net.osmand.GPXUtilities;
import net.osmand.GPXUtilities.GPXFile;
import net.osmand.GPXUtilities.GPXFile.GpxSplitType;
import net.osmand.GPXUtilities.GPXFile.GradientScaleType;
import net.osmand.GPXUtilities.GPXTrackAnalysis;
import net.osmand.GPXUtilities.Route;
import net.osmand.GPXUtilities.Track;
@ -51,7 +53,11 @@ public class GpxSelectionHelper {
private static final String BACKUP = "backup";
private static final String BACKUPMODIFIEDTIME = "backupTime";
private static final String COLOR = "color";
private static final String WIDTH = "width";
private static final String SELECTED_BY_USER = "selected_by_user";
private static final String SHOW_ARROWS = "show_arrows";
private static final String GRADIENT_SCALE_TYPE = "gradient_scale_type";
private static final String SHOW_START_FINISH = "show_start_finish";
private OsmandApplication app;
@NonNull
@ -167,17 +173,17 @@ public class GpxSelectionHelper {
if (selectedGpxFile != null && selectedGpxFile.getGpxFile() != null) {
GPXFile gpxFile = selectedGpxFile.getGpxFile();
List<GpxDisplayGroup> groups = app.getSelectedGpxHelper().collectDisplayGroups(gpxFile);
if (dataItem.getSplitType() == GPXDatabase.GPX_SPLIT_TYPE_NO_SPLIT) {
if (dataItem.getSplitType() == GpxSplitType.NO_SPLIT.getType()) {
for (GpxDisplayGroup model : groups) {
model.noSplit(app);
}
selectedGpxFile.setDisplayGroups(groups, app);
} else if (dataItem.getSplitType() == GPXDatabase.GPX_SPLIT_TYPE_DISTANCE) {
} else if (dataItem.getSplitType() == GpxSplitType.DISTANCE.getType()) {
for (GpxDisplayGroup model : groups) {
model.splitByDistance(app, dataItem.getSplitInterval(), dataItem.isJoinSegments());
}
selectedGpxFile.setDisplayGroups(groups, app);
} else if (dataItem.getSplitType() == GPXDatabase.GPX_SPLIT_TYPE_TIME) {
} else if (dataItem.getSplitType() == GpxSplitType.TIME.getType()) {
for (GpxDisplayGroup model : groups) {
model.splitByTime(app, (int) dataItem.getSplitInterval(), dataItem.isJoinSegments());
}
@ -515,6 +521,29 @@ public class GpxSelectionHelper {
int clr = Algorithms.parseColor(obj.getString(COLOR));
gpx.setColor(clr);
}
for (GradientScaleType scaleType : GradientScaleType.values()) {
if (obj.has(scaleType.getTypeName())) {
int clr = Algorithms.parseColor(obj.getString(scaleType.getTypeName()));
gpx.setGradientScaleColor(scaleType, clr);
}
}
if (obj.has(SHOW_ARROWS)) {
boolean showArrows = obj.optBoolean(SHOW_ARROWS, false);
gpx.setShowArrows(showArrows);
}
if (obj.has(GRADIENT_SCALE_TYPE)) {
String gradientScaleTypeName = obj.optString(GRADIENT_SCALE_TYPE);
if (!Algorithms.isEmpty(gradientScaleTypeName)) {
gpx.setGradientScaleType(GradientScaleType.valueOf(gradientScaleTypeName));
}
}
if (obj.has(SHOW_START_FINISH)) {
boolean showStartFinish = obj.optBoolean(SHOW_START_FINISH, false);
gpx.setShowStartFinish(showStartFinish);
}
if (obj.has(WIDTH)) {
gpx.setWidth(obj.getString(WIDTH));
}
if (gpx.error != null) {
save = true;
} else if (obj.has(BACKUP)) {
@ -554,6 +583,20 @@ public class GpxSelectionHelper {
if (s.gpxFile.getColor(0) != 0) {
obj.put(COLOR, Algorithms.colorToString(s.gpxFile.getColor(0)));
}
if (s.gpxFile.getWidth(null) != null) {
obj.put(WIDTH, s.gpxFile.getWidth(null));
}
if (s.gpxFile.getGradientScaleType() != null) {
obj.put(GRADIENT_SCALE_TYPE, s.gpxFile.getGradientScaleType());
}
obj.put(SHOW_ARROWS, s.gpxFile.isShowArrows());
obj.put(SHOW_START_FINISH, s.gpxFile.isShowStartFinish());
for (GradientScaleType scaleType : GradientScaleType.values()) {
int gradientScaleColor = s.gpxFile.getGradientScaleColor(scaleType, 0);
if (gradientScaleColor != 0) {
obj.put(scaleType.getTypeName(), Algorithms.colorToString(gradientScaleColor));
}
}
}
obj.put(SELECTED_BY_USER, s.selectedByUser);
} catch (JSONException e) {
@ -606,6 +649,23 @@ public class GpxSelectionHelper {
if (dataItem.getColor() != 0) {
gpx.setColor(dataItem.getColor());
}
if (dataItem.getGradientSpeedColor() != 0) {
gpx.setGradientScaleColor(GradientScaleType.SPEED, dataItem.getGradientSpeedColor());
}
if (dataItem.getGradientAltitudeColor() != 0) {
gpx.setGradientScaleColor(GradientScaleType.ALTITUDE, dataItem.getGradientAltitudeColor());
}
if (dataItem.getGradientSlopeColor() != 0) {
gpx.setGradientScaleColor(GradientScaleType.SLOPE, dataItem.getGradientSlopeColor());
}
if (dataItem.getGradientScaleType() != null) {
gpx.setGradientScaleType(dataItem.getGradientScaleType());
}
if (dataItem.getWidth() != null) {
gpx.setWidth(dataItem.getWidth());
}
gpx.setShowArrows(dataItem.isShowArrows());
gpx.setShowStartFinish(dataItem.isShowStartFinish());
sf.setJoinSegments(dataItem.isJoinSegments());
}
sf.setGpxFile(gpx, app);
@ -1024,13 +1084,13 @@ public class GpxSelectionHelper {
@Override
protected void onProgressUpdate(Void... values) {
gpxTaskListener.gpxSelectionInProgress();
gpxTaskListener.gpxSelectionInProgress();
}
@Override
protected void onPreExecute() {
collectSelectedItems();
gpxTaskListener.gpxSelectionStarted();
gpxTaskListener.gpxSelectionStarted();
}
private void collectSelectedItems() {

View file

@ -2,9 +2,7 @@ package net.osmand.plus.dialogs;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Build;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
@ -25,8 +23,6 @@ import androidx.appcompat.widget.SwitchCompat;
import androidx.core.content.ContextCompat;
import net.osmand.AndroidUtils;
import net.osmand.CallbackWithObject;
import net.osmand.GPXUtilities;
import net.osmand.IndexConstants;
import net.osmand.PlatformUtil;
import net.osmand.core.android.MapRendererContext;
@ -35,20 +31,14 @@ import net.osmand.plus.ContextMenuAdapter.ItemClickListener;
import net.osmand.plus.ContextMenuAdapter.OnRowItemClick;
import net.osmand.plus.ContextMenuItem;
import net.osmand.plus.DialogListItemAdapter;
import net.osmand.plus.GpxSelectionHelper;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandPlugin;
import net.osmand.plus.R;
import net.osmand.plus.UiUtilities;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.activities.MapActivityLayers;
import net.osmand.plus.activities.PluginActivity;
import net.osmand.plus.activities.SettingsActivity;
import net.osmand.plus.dashboard.DashboardOnMap;
import net.osmand.plus.inapp.InAppPurchaseHelper;
import net.osmand.plus.poi.PoiFiltersHelper;
import net.osmand.plus.poi.PoiUIFilter;
import net.osmand.plus.rastermaps.OsmandRasterMapsPlugin;
import net.osmand.plus.render.RendererRegistry;
import net.osmand.plus.settings.backend.OsmandSettings;
import net.osmand.plus.settings.backend.OsmandSettings.CommonPreference;
@ -57,8 +47,6 @@ import net.osmand.plus.srtmplugin.SRTMPlugin;
import net.osmand.plus.transport.TransportLinesMenu;
import net.osmand.plus.views.OsmandMapTileView;
import net.osmand.plus.views.corenative.NativeCoreContext;
import net.osmand.plus.wikipedia.WikipediaPoiMenu;
import net.osmand.render.RenderingRule;
import net.osmand.render.RenderingRuleProperty;
import net.osmand.render.RenderingRuleStorageProperties;
import net.osmand.render.RenderingRulesStorage;
@ -67,7 +55,6 @@ import net.osmand.util.SunriseSunset;
import org.apache.commons.logging.Log;
import java.io.File;
import java.text.DateFormat;
import java.util.ArrayList;
import java.util.Arrays;
@ -101,7 +88,6 @@ import static net.osmand.aidlapi.OsmAndCustomizationConstants.ROUTES_ID;
import static net.osmand.aidlapi.OsmAndCustomizationConstants.SHOW_CATEGORY_ID;
import static net.osmand.aidlapi.OsmAndCustomizationConstants.TEXT_SIZE_ID;
import static net.osmand.aidlapi.OsmAndCustomizationConstants.TRANSPORT_ID;
import static net.osmand.aidlapi.OsmAndCustomizationConstants.WIKIPEDIA_ID;
import static net.osmand.plus.ContextMenuAdapter.makeDeleteAction;
import static net.osmand.plus.srtmplugin.SRTMPlugin.CONTOUR_DENSITY_ATTR;
import static net.osmand.plus.srtmplugin.SRTMPlugin.CONTOUR_LINES_ATTR;
@ -181,188 +167,12 @@ public class ConfigureMapMenu {
return customRules;
}
private final class LayerMenuListener extends OnRowItemClick {
private MapActivity ma;
private ContextMenuAdapter cm;
private LayerMenuListener(MapActivity ma, ContextMenuAdapter cm) {
this.ma = ma;
this.cm = cm;
}
private List<String> getAlreadySelectedGpx() {
GpxSelectionHelper selectedGpxHelper = ma.getMyApplication().getSelectedGpxHelper();
List<GpxSelectionHelper.SelectedGpxFile> selectedGpxFiles = selectedGpxHelper.getSelectedGPXFiles();
List<String> files = new ArrayList<>();
for (GpxSelectionHelper.SelectedGpxFile file : selectedGpxFiles) {
files.add(file.getGpxFile().path);
}
if (selectedGpxFiles.isEmpty()) {
Map<GPXUtilities.GPXFile, Long> fls = selectedGpxHelper.getSelectedGpxFilesBackUp();
for(Map.Entry<GPXUtilities.GPXFile, Long> f : fls.entrySet()) {
if(!Algorithms.isEmpty(f.getKey().path)) {
File file = new File(f.getKey().path);
if(file.exists() && !file.isDirectory()) {
files.add(f.getKey().path);
}
}
}
}
return files;
}
@Override
public boolean onRowItemClick(final ArrayAdapter<ContextMenuItem> adapter, View view, int itemId, int pos) {
if (itemId == R.string.layer_poi) {
showPoiFilterDialog(adapter, adapter.getItem(pos));
return false;
} else if (itemId == R.string.layer_gpx_layer && cm.getItem(pos).getSelected()) {
showGpxSelectionDialog(adapter, adapter.getItem(pos));
return false;
} else if (itemId == R.string.rendering_category_transport) {
final ContextMenuItem item = adapter.getItem(pos);
TransportLinesMenu.showTransportsDialog(ma, new CallbackWithObject<Boolean>() {
@Override
public boolean processResult(Boolean result) {
if (item != null) {
item.setSelected(result);
item.setColorRes(result ? R.color.osmand_orange : ContextMenuItem.INVALID_ID);
adapter.notifyDataSetChanged();
}
return true;
}
});
boolean selected = TransportLinesMenu.isShowLines(ma.getMyApplication());
if (!selected && item != null) {
item.setSelected(true);
item.setColorRes(R.color.osmand_orange);
adapter.notifyDataSetChanged();
}
return false;
} else {
CompoundButton btn = (CompoundButton) view.findViewById(R.id.toggle_item);
if (btn != null && btn.getVisibility() == View.VISIBLE) {
btn.setChecked(!btn.isChecked());
cm.getItem(pos).setColorRes(btn.isChecked() ? R.color.osmand_orange : ContextMenuItem.INVALID_ID);
adapter.notifyDataSetChanged();
return false;
} else {
return onContextMenuClick(adapter, itemId, pos, false, null);
}
}
}
@Override
public boolean onContextMenuClick(final ArrayAdapter<ContextMenuItem> adapter, int itemId,
final int pos, boolean isChecked, int[] viewCoordinates) {
final OsmandSettings settings = ma.getMyApplication().getSettings();
final PoiFiltersHelper poiFiltersHelper = ma.getMyApplication().getPoiFilters();
final ContextMenuItem item = cm.getItem(pos);
if (item.getSelected() != null) {
item.setColorRes(isChecked ? R.color.osmand_orange : ContextMenuItem.INVALID_ID);
}
if (itemId == R.string.layer_poi) {
PoiUIFilter wiki = poiFiltersHelper.getTopWikiPoiFilter();
poiFiltersHelper.clearSelectedPoiFilters(wiki);
if (isChecked) {
showPoiFilterDialog(adapter, adapter.getItem(pos));
} else {
adapter.getItem(pos).setDescription(
poiFiltersHelper.getSelectedPoiFiltersName(wiki));
}
} else if (itemId == R.string.layer_amenity_label) {
settings.SHOW_POI_LABEL.set(isChecked);
} else if (itemId == R.string.shared_string_favorites) {
settings.SHOW_FAVORITES.set(isChecked);
} else if (itemId == R.string.layer_gpx_layer) {
final GpxSelectionHelper selectedGpxHelper = ma.getMyApplication().getSelectedGpxHelper();
if (selectedGpxHelper.isShowingAnyGpxFiles()) {
selectedGpxHelper.clearAllGpxFilesToShow(true);
adapter.getItem(pos).setDescription(selectedGpxHelper.getGpxDescription());
} else {
showGpxSelectionDialog(adapter, adapter.getItem(pos));
}
} else if (itemId == R.string.rendering_category_transport) {
boolean selected = TransportLinesMenu.isShowLines(ma.getMyApplication());
TransportLinesMenu.toggleTransportLines(ma, !selected, new CallbackWithObject<Boolean>() {
@Override
public boolean processResult(Boolean result) {
item.setSelected(result);
item.setColorRes(result ? R.color.osmand_orange : ContextMenuItem.INVALID_ID);
adapter.notifyDataSetChanged();
return true;
}
});
} else if (itemId == R.string.map_markers) {
settings.SHOW_MAP_MARKERS.set(isChecked);
} else if (itemId == R.string.layer_map) {
if (OsmandPlugin.getEnabledPlugin(OsmandRasterMapsPlugin.class) == null) {
Intent intent = new Intent(ma, PluginActivity.class);
intent.putExtra(PluginActivity.EXTRA_PLUGIN_ID, OsmandRasterMapsPlugin.ID);
ma.startActivity(intent);
} else {
ContextMenuItem it = adapter.getItem(pos);
ma.getMapLayers().selectMapLayer(ma.getMapView(), it, adapter);
}
}
adapter.notifyDataSetChanged();
ma.getMapLayers().updateLayers(ma.getMapView());
ma.getMapView().refreshMap();
return false;
}
private void showGpxSelectionDialog(final ArrayAdapter<ContextMenuItem> adapter,
final ContextMenuItem item) {
AlertDialog dialog = ma.getMapLayers().showGPXFileLayer(getAlreadySelectedGpx(),
ma.getMapView());
dialog.setOnDismissListener(new DialogInterface.OnDismissListener() {
@Override
public void onDismiss(DialogInterface dialog) {
OsmandApplication app = ma.getMyApplication();
boolean selected = app.getSelectedGpxHelper().isShowingAnyGpxFiles();
item.setSelected(selected);
item.setDescription(app.getSelectedGpxHelper().getGpxDescription());
item.setColorRes(selected ? R.color.osmand_orange : ContextMenuItem.INVALID_ID);
adapter.notifyDataSetChanged();
}
});
}
protected void showPoiFilterDialog(final ArrayAdapter<ContextMenuItem> adapter,
final ContextMenuItem item) {
final PoiFiltersHelper poiFiltersHelper = ma.getMyApplication().getPoiFilters();
final PoiUIFilter wiki = poiFiltersHelper.getTopWikiPoiFilter();
MapActivityLayers.DismissListener dismissListener =
new MapActivityLayers.DismissListener() {
@Override
public void dismiss() {
PoiFiltersHelper pf = ma.getMyApplication().getPoiFilters();
boolean selected = pf.isShowingAnyPoi(wiki);
item.setSelected(selected);
item.setDescription(pf.getSelectedPoiFiltersName(wiki));
item.setColorRes(selected ? R.color.osmand_orange : ContextMenuItem.INVALID_ID);
adapter.notifyDataSetChanged();
}
};
if (poiFiltersHelper.isShowingAnyPoi(wiki)) {
ma.getMapLayers().showMultichoicePoiFilterDialog(ma.getMapView(),
dismissListener);
} else {
ma.getMapLayers().showSingleChoicePoiFilterDialog(ma.getMapView(),
dismissListener);
}
}
}
private void createLayersItems(List<RenderingRuleProperty> customRules, ContextMenuAdapter adapter,
final MapActivity activity, final int themeRes, final boolean nightMode) {
final OsmandApplication app = activity.getMyApplication();
final OsmandSettings settings = app.getSettings();
final int selectedProfileColorRes = settings.getApplicationMode().getIconColorInfo().getColor(nightMode);
final int selectedProfileColor = ContextCompat.getColor(app, selectedProfileColorRes);
LayerMenuListener l = new LayerMenuListener(activity, adapter);
MapLayerMenuListener l = new MapLayerMenuListener(activity, adapter);
adapter.addItem(new ContextMenuItem.ItemBuilder()
.setId(SHOW_CATEGORY_ID)
.setTitleId(R.string.shared_string_show, activity)
@ -1299,230 +1109,35 @@ public class ConfigureMapMenu {
}
}
private class StringSpinnerArrayAdapter extends ArrayAdapter<String> {
private static class StringSpinnerArrayAdapter extends ArrayAdapter<String> {
private boolean nightMode;
public StringSpinnerArrayAdapter(Context context, boolean nightMode) {
super(context, android.R.layout.simple_spinner_item);
setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
OsmandApplication app = (OsmandApplication )getContext().getApplicationContext();
this.nightMode = nightMode;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
TextView label = (TextView) super.getView(position, convertView, parent);
String text = getItem(position);
label.setText(text);
label.setTextColor(nightMode ?
ContextCompat.getColorStateList(getContext(), R.color.text_color_primary_dark) : ContextCompat.getColorStateList(getContext(), R.color.text_color_primary_light));
return label;
}
@Override
public View getDropDownView(int position, View convertView, ViewGroup parent) {
TextView label = (TextView) super.getDropDownView(position, convertView, parent);
String text = getItem(position);
label.setText(text);
label.setTextColor(nightMode ?
ContextCompat.getColorStateList(getContext(), R.color.text_color_primary_dark) : ContextCompat.getColorStateList(getContext(), R.color.text_color_primary_light));
return label;
}
}
public static class GpxAppearanceAdapter extends ArrayAdapter<AppearanceListItem> {
private OsmandApplication app;
private int currentColor;
private GpxAppearanceAdapterType adapterType = GpxAppearanceAdapterType.TRACK_WIDTH_COLOR;
public enum GpxAppearanceAdapterType {
TRACK_WIDTH,
TRACK_COLOR,
TRACK_WIDTH_COLOR
}
public GpxAppearanceAdapter(Context context, String currentColorValue, GpxAppearanceAdapterType adapterType) {
super(context, R.layout.rendering_prop_menu_item);
this.app = (OsmandApplication) getContext().getApplicationContext();
this.adapterType = adapterType;
RenderingRulesStorage renderer = app.getRendererRegistry().getCurrentSelectedRenderer();
this.currentColor = parseTrackColor(renderer, currentColorValue);
init();
}
public GpxAppearanceAdapter(Context context, int currentColor, GpxAppearanceAdapterType adapterType) {
super(context, R.layout.rendering_prop_menu_item);
this.app = (OsmandApplication) getContext().getApplicationContext();
this.adapterType = adapterType;
this.currentColor = currentColor;
init();
}
public void init() {
RenderingRuleProperty trackWidthProp = null;
RenderingRuleProperty trackColorProp = null;
RenderingRulesStorage renderer = app.getRendererRegistry().getCurrentSelectedRenderer();
if (renderer != null) {
if (adapterType == GpxAppearanceAdapterType.TRACK_WIDTH || adapterType == GpxAppearanceAdapterType.TRACK_WIDTH_COLOR) {
trackWidthProp = renderer.PROPS.getCustomRule(CURRENT_TRACK_WIDTH_ATTR);
}
if (adapterType == GpxAppearanceAdapterType.TRACK_COLOR || adapterType == GpxAppearanceAdapterType.TRACK_WIDTH_COLOR) {
trackColorProp = renderer.PROPS.getCustomRule(CURRENT_TRACK_COLOR_ATTR);
}
}
if (trackWidthProp != null) {
AppearanceListItem item = new AppearanceListItem(CURRENT_TRACK_WIDTH_ATTR, "",
SettingsActivity.getStringPropertyValue(getContext(), trackWidthProp.getDefaultValueDescription()));
add(item);
for (int j = 0; j < trackWidthProp.getPossibleValues().length; j++) {
item = new AppearanceListItem(CURRENT_TRACK_WIDTH_ATTR,
trackWidthProp.getPossibleValues()[j],
SettingsActivity.getStringPropertyValue(getContext(), trackWidthProp.getPossibleValues()[j]));
add(item);
}
item.setLastItem(true);
}
if (trackColorProp != null) {
AppearanceListItem item = new AppearanceListItem(CURRENT_TRACK_COLOR_ATTR, "",
SettingsActivity.getStringPropertyValue(getContext(), trackColorProp.getDefaultValueDescription()),
parseTrackColor(renderer, ""));
add(item);
for (int j = 0; j < trackColorProp.getPossibleValues().length; j++) {
item = new AppearanceListItem(CURRENT_TRACK_COLOR_ATTR,
trackColorProp.getPossibleValues()[j],
SettingsActivity.getStringPropertyValue(getContext(), trackColorProp.getPossibleValues()[j]),
parseTrackColor(renderer, trackColorProp.getPossibleValues()[j]));
add(item);
}
item.setLastItem(true);
}
}
public static int parseTrackColor(RenderingRulesStorage renderer, String colorName) {
int defaultColor = -1;
RenderingRule gpxRule = null;
if (renderer != null) {
gpxRule = renderer.getRenderingAttributeRule("gpx");
}
if (gpxRule != null && gpxRule.getIfElseChildren().size() > 0) {
List<RenderingRule> rules = gpxRule.getIfElseChildren().get(0).getIfElseChildren();
for (RenderingRule r : rules) {
String cName = r.getStringPropertyValue(CURRENT_TRACK_COLOR_ATTR);
if (!Algorithms.isEmpty(cName) && cName.equals(colorName)) {
return r.getIntPropertyValue(COLOR_ATTR);
}
if (cName == null && defaultColor == -1) {
defaultColor = r.getIntPropertyValue(COLOR_ATTR);
}
}
}
return defaultColor;
}
public static String parseTrackColorName(RenderingRulesStorage renderer, int color) {
RenderingRule gpxRule = null;
if (renderer != null) {
gpxRule = renderer.getRenderingAttributeRule("gpx");
}
if (gpxRule != null && gpxRule.getIfElseChildren().size() > 0) {
List<RenderingRule> rules = gpxRule.getIfElseChildren().get(0).getIfElseChildren();
for (RenderingRule r : rules) {
String cName = r.getStringPropertyValue(CURRENT_TRACK_COLOR_ATTR);
if (!Algorithms.isEmpty(cName) && color == r.getIntPropertyValue(COLOR_ATTR)) {
return cName;
}
}
}
return Algorithms.colorToString(color);
}
@NonNull
@Override
public View getView(int position, View convertView, @NonNull ViewGroup parent) {
AppearanceListItem item = getItem(position);
View v = convertView;
if (v == null) {
v = LayoutInflater.from(getContext()).inflate(R.layout.rendering_prop_menu_item, null);
}
if (item != null) {
TextView textView = (TextView) v.findViewById(R.id.text1);
textView.setText(item.localizedValue);
if (item.attrName == CURRENT_TRACK_WIDTH_ATTR) {
int iconId;
if (item.value.equals("bold")) {
iconId = R.drawable.ic_action_gpx_width_bold;
} else if (item.value.equals("medium")) {
iconId = R.drawable.ic_action_gpx_width_medium;
} else {
iconId = R.drawable.ic_action_gpx_width_thin;
}
textView.setCompoundDrawablesWithIntrinsicBounds(null, null,
app.getUIUtilities().getPaintedIcon(iconId, currentColor), null);
} else {
if (item.color == -1) {
textView.setCompoundDrawablesWithIntrinsicBounds(null, null,
app.getUIUtilities().getThemedIcon(R.drawable.ic_action_circle), null);
} else {
textView.setCompoundDrawablesWithIntrinsicBounds(null, null,
app.getUIUtilities().getPaintedIcon(R.drawable.ic_action_circle, item.color), null);
}
}
textView.setCompoundDrawablePadding(AndroidUtils.dpToPx(getContext(), 10f));
v.findViewById(R.id.divider).setVisibility(item.lastItem
&& position < getCount() - 1 ? View.VISIBLE : View.GONE);
}
return v;
}
}
public static class AppearanceListItem {
private String attrName;
private String value;
private String localizedValue;
private int color;
private boolean lastItem;
public AppearanceListItem(String attrName, String value, String localizedValue) {
this.attrName = attrName;
this.value = value;
this.localizedValue = localizedValue;
TextView label = (TextView) super.getView(position, convertView, parent);
setupLabel(label, getItem(position));
return label;
}
public AppearanceListItem(String attrName, String value, String localizedValue, int color) {
this.attrName = attrName;
this.value = value;
this.localizedValue = localizedValue;
this.color = color;
@Override
public View getDropDownView(int position, View convertView, @NonNull ViewGroup parent) {
TextView label = (TextView) super.getDropDownView(position, convertView, parent);
setupLabel(label, getItem(position));
return label;
}
public String getAttrName() {
return attrName;
}
public String getValue() {
return value;
}
public String getLocalizedValue() {
return localizedValue;
}
public int getColor() {
return color;
}
public boolean isLastItem() {
return lastItem;
}
public void setLastItem(boolean lastItem) {
this.lastItem = lastItem;
private void setupLabel(TextView label, String text) {
int colorId = nightMode ? R.color.text_color_primary_dark : R.color.text_color_primary_light;
label.setText(text);
label.setTextColor(ContextCompat.getColorStateList(getContext(), colorId));
}
}
}

View file

@ -0,0 +1,214 @@
package net.osmand.plus.dialogs;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;
import androidx.annotation.NonNull;
import net.osmand.AndroidUtils;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R;
import net.osmand.plus.activities.SettingsActivity;
import net.osmand.render.RenderingRule;
import net.osmand.render.RenderingRuleProperty;
import net.osmand.render.RenderingRulesStorage;
import net.osmand.util.Algorithms;
import java.util.List;
public class GpxAppearanceAdapter extends ArrayAdapter<GpxAppearanceAdapter.AppearanceListItem> {
private OsmandApplication app;
private GpxAppearanceAdapterType adapterType;
private int currentColor;
public enum GpxAppearanceAdapterType {
TRACK_WIDTH,
TRACK_COLOR,
TRACK_WIDTH_COLOR
}
public GpxAppearanceAdapter(Context context, String currentColorValue, GpxAppearanceAdapterType adapterType) {
super(context, R.layout.rendering_prop_menu_item);
this.app = (OsmandApplication) context.getApplicationContext();
this.adapterType = adapterType;
RenderingRulesStorage renderer = app.getRendererRegistry().getCurrentSelectedRenderer();
this.currentColor = parseTrackColor(renderer, currentColorValue);
init();
}
public GpxAppearanceAdapter(Context context, int currentColor, GpxAppearanceAdapterType adapterType) {
super(context, R.layout.rendering_prop_menu_item);
this.app = (OsmandApplication) context.getApplicationContext();
this.adapterType = adapterType;
this.currentColor = currentColor;
init();
}
@NonNull
@Override
public View getView(int position, View convertView, @NonNull ViewGroup parent) {
AppearanceListItem item = getItem(position);
View v = convertView;
if (v == null) {
v = LayoutInflater.from(getContext()).inflate(R.layout.rendering_prop_menu_item, null);
}
if (item != null) {
TextView textView = (TextView) v.findViewById(R.id.text1);
textView.setText(item.localizedValue);
if (ConfigureMapMenu.CURRENT_TRACK_WIDTH_ATTR.equals(item.attrName)) {
int iconId;
if ("bold".equals(item.value)) {
iconId = R.drawable.ic_action_gpx_width_bold;
} else if ("medium".equals(item.value)) {
iconId = R.drawable.ic_action_gpx_width_medium;
} else {
iconId = R.drawable.ic_action_gpx_width_thin;
}
textView.setCompoundDrawablesWithIntrinsicBounds(null, null,
app.getUIUtilities().getPaintedIcon(iconId, currentColor), null);
} else {
if (item.color == -1) {
textView.setCompoundDrawablesWithIntrinsicBounds(null, null,
app.getUIUtilities().getThemedIcon(R.drawable.ic_action_circle), null);
} else {
textView.setCompoundDrawablesWithIntrinsicBounds(null, null,
app.getUIUtilities().getPaintedIcon(R.drawable.ic_action_circle, item.color), null);
}
}
textView.setCompoundDrawablePadding(AndroidUtils.dpToPx(getContext(), 10f));
v.findViewById(R.id.divider).setVisibility(item.lastItem
&& position < getCount() - 1 ? View.VISIBLE : View.GONE);
}
return v;
}
public void init() {
RenderingRuleProperty trackWidthProp = null;
RenderingRuleProperty trackColorProp = null;
RenderingRulesStorage renderer = app.getRendererRegistry().getCurrentSelectedRenderer();
if (renderer != null) {
if (adapterType == GpxAppearanceAdapterType.TRACK_WIDTH || adapterType == GpxAppearanceAdapterType.TRACK_WIDTH_COLOR) {
trackWidthProp = renderer.PROPS.getCustomRule(ConfigureMapMenu.CURRENT_TRACK_WIDTH_ATTR);
}
if (adapterType == GpxAppearanceAdapterType.TRACK_COLOR || adapterType == GpxAppearanceAdapterType.TRACK_WIDTH_COLOR) {
trackColorProp = renderer.PROPS.getCustomRule(ConfigureMapMenu.CURRENT_TRACK_COLOR_ATTR);
}
}
if (trackWidthProp != null) {
AppearanceListItem item = new AppearanceListItem(ConfigureMapMenu.CURRENT_TRACK_WIDTH_ATTR, "",
SettingsActivity.getStringPropertyValue(getContext(), trackWidthProp.getDefaultValueDescription()));
add(item);
for (int j = 0; j < trackWidthProp.getPossibleValues().length; j++) {
item = new AppearanceListItem(ConfigureMapMenu.CURRENT_TRACK_WIDTH_ATTR,
trackWidthProp.getPossibleValues()[j],
SettingsActivity.getStringPropertyValue(getContext(), trackWidthProp.getPossibleValues()[j]));
add(item);
}
item.setLastItem(true);
}
if (trackColorProp != null) {
AppearanceListItem item = new AppearanceListItem(ConfigureMapMenu.CURRENT_TRACK_COLOR_ATTR, "",
SettingsActivity.getStringPropertyValue(getContext(), trackColorProp.getDefaultValueDescription()),
parseTrackColor(renderer, ""));
add(item);
for (int j = 0; j < trackColorProp.getPossibleValues().length; j++) {
item = new AppearanceListItem(ConfigureMapMenu.CURRENT_TRACK_COLOR_ATTR,
trackColorProp.getPossibleValues()[j],
SettingsActivity.getStringPropertyValue(getContext(), trackColorProp.getPossibleValues()[j]),
parseTrackColor(renderer, trackColorProp.getPossibleValues()[j]));
add(item);
}
item.setLastItem(true);
}
}
public static int parseTrackColor(RenderingRulesStorage renderer, String colorName) {
int defaultColor = -1;
RenderingRule gpxRule = null;
if (renderer != null) {
gpxRule = renderer.getRenderingAttributeRule("gpx");
}
if (gpxRule != null && gpxRule.getIfElseChildren().size() > 0) {
List<RenderingRule> rules = gpxRule.getIfElseChildren().get(0).getIfElseChildren();
for (RenderingRule r : rules) {
String cName = r.getStringPropertyValue(ConfigureMapMenu.CURRENT_TRACK_COLOR_ATTR);
if (!Algorithms.isEmpty(cName) && cName.equals(colorName)) {
return r.getIntPropertyValue(ConfigureMapMenu.COLOR_ATTR);
}
if (cName == null && defaultColor == -1) {
defaultColor = r.getIntPropertyValue(ConfigureMapMenu.COLOR_ATTR);
}
}
}
return defaultColor;
}
public static String parseTrackColorName(RenderingRulesStorage renderer, int color) {
RenderingRule gpxRule = null;
if (renderer != null) {
gpxRule = renderer.getRenderingAttributeRule("gpx");
}
if (gpxRule != null && gpxRule.getIfElseChildren().size() > 0) {
List<RenderingRule> rules = gpxRule.getIfElseChildren().get(0).getIfElseChildren();
for (RenderingRule r : rules) {
String cName = r.getStringPropertyValue(ConfigureMapMenu.CURRENT_TRACK_COLOR_ATTR);
if (!Algorithms.isEmpty(cName) && color == r.getIntPropertyValue(ConfigureMapMenu.COLOR_ATTR)) {
return cName;
}
}
}
return Algorithms.colorToString(color);
}
public static class AppearanceListItem {
private String attrName;
private String value;
private String localizedValue;
private int color;
private boolean lastItem;
public AppearanceListItem(String attrName, String value, String localizedValue) {
this.attrName = attrName;
this.value = value;
this.localizedValue = localizedValue;
}
public AppearanceListItem(String attrName, String value, String localizedValue, int color) {
this.attrName = attrName;
this.value = value;
this.localizedValue = localizedValue;
this.color = color;
}
public String getAttrName() {
return attrName;
}
public String getValue() {
return value;
}
public String getLocalizedValue() {
return localizedValue;
}
public int getColor() {
return color;
}
public boolean isLastItem() {
return lastItem;
}
public void setLastItem(boolean lastItem) {
this.lastItem = lastItem;
}
}
}

View file

@ -0,0 +1,210 @@
package net.osmand.plus.dialogs;
import android.content.DialogInterface;
import android.content.Intent;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.CompoundButton;
import androidx.appcompat.app.AlertDialog;
import net.osmand.CallbackWithObject;
import net.osmand.GPXUtilities.GPXFile;
import net.osmand.plus.ContextMenuAdapter;
import net.osmand.plus.ContextMenuAdapter.OnRowItemClick;
import net.osmand.plus.ContextMenuItem;
import net.osmand.plus.GpxSelectionHelper;
import net.osmand.plus.GpxSelectionHelper.SelectedGpxFile;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandPlugin;
import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.activities.MapActivityLayers;
import net.osmand.plus.activities.PluginActivity;
import net.osmand.plus.poi.PoiFiltersHelper;
import net.osmand.plus.poi.PoiUIFilter;
import net.osmand.plus.rastermaps.OsmandRasterMapsPlugin;
import net.osmand.plus.settings.backend.OsmandSettings;
import net.osmand.plus.transport.TransportLinesMenu;
import net.osmand.util.Algorithms;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
final class MapLayerMenuListener extends OnRowItemClick {
private MapActivity mapActivity;
private ContextMenuAdapter menuAdapter;
MapLayerMenuListener(MapActivity mapActivity, ContextMenuAdapter menuAdapter) {
this.mapActivity = mapActivity;
this.menuAdapter = menuAdapter;
}
private List<String> getAlreadySelectedGpx() {
GpxSelectionHelper selectedGpxHelper = mapActivity.getMyApplication().getSelectedGpxHelper();
List<SelectedGpxFile> selectedGpxFiles = selectedGpxHelper.getSelectedGPXFiles();
List<String> files = new ArrayList<>();
for (SelectedGpxFile file : selectedGpxFiles) {
files.add(file.getGpxFile().path);
}
if (selectedGpxFiles.isEmpty()) {
Map<GPXFile, Long> fls = selectedGpxHelper.getSelectedGpxFilesBackUp();
for (Map.Entry<GPXFile, Long> f : fls.entrySet()) {
if (!Algorithms.isEmpty(f.getKey().path)) {
File file = new File(f.getKey().path);
if (file.exists() && !file.isDirectory()) {
files.add(f.getKey().path);
}
}
}
}
return files;
}
@Override
public boolean onRowItemClick(final ArrayAdapter<ContextMenuItem> adapter, View view, int itemId, int pos) {
if (itemId == R.string.layer_poi) {
showPoiFilterDialog(adapter, adapter.getItem(pos));
return false;
} else if (itemId == R.string.layer_gpx_layer && menuAdapter.getItem(pos).getSelected()) {
showGpxSelectionDialog(adapter, adapter.getItem(pos));
return false;
} else if (itemId == R.string.rendering_category_transport) {
final ContextMenuItem item = adapter.getItem(pos);
TransportLinesMenu.showTransportsDialog(mapActivity, new CallbackWithObject<Boolean>() {
@Override
public boolean processResult(Boolean result) {
if (item != null) {
item.setSelected(result);
item.setColorRes(result ? R.color.osmand_orange : ContextMenuItem.INVALID_ID);
adapter.notifyDataSetChanged();
}
return true;
}
});
boolean selected = TransportLinesMenu.isShowLines(mapActivity.getMyApplication());
if (!selected && item != null) {
item.setSelected(true);
item.setColorRes(R.color.osmand_orange);
adapter.notifyDataSetChanged();
}
return false;
} else {
CompoundButton btn = (CompoundButton) view.findViewById(R.id.toggle_item);
if (btn != null && btn.getVisibility() == View.VISIBLE) {
btn.setChecked(!btn.isChecked());
menuAdapter.getItem(pos).setColorRes(btn.isChecked() ? R.color.osmand_orange : ContextMenuItem.INVALID_ID);
adapter.notifyDataSetChanged();
return false;
} else {
return onContextMenuClick(adapter, itemId, pos, false, null);
}
}
}
@Override
public boolean onContextMenuClick(final ArrayAdapter<ContextMenuItem> adapter, int itemId,
final int pos, boolean isChecked, int[] viewCoordinates) {
final OsmandSettings settings = mapActivity.getMyApplication().getSettings();
final PoiFiltersHelper poiFiltersHelper = mapActivity.getMyApplication().getPoiFilters();
final ContextMenuItem item = menuAdapter.getItem(pos);
if (item.getSelected() != null) {
item.setColorRes(isChecked ? R.color.osmand_orange : ContextMenuItem.INVALID_ID);
}
if (itemId == R.string.layer_poi) {
PoiUIFilter wiki = poiFiltersHelper.getTopWikiPoiFilter();
poiFiltersHelper.clearSelectedPoiFilters(wiki);
if (isChecked) {
showPoiFilterDialog(adapter, adapter.getItem(pos));
} else {
adapter.getItem(pos).setDescription(
poiFiltersHelper.getSelectedPoiFiltersName(wiki));
}
} else if (itemId == R.string.layer_amenity_label) {
settings.SHOW_POI_LABEL.set(isChecked);
} else if (itemId == R.string.shared_string_favorites) {
settings.SHOW_FAVORITES.set(isChecked);
} else if (itemId == R.string.layer_gpx_layer) {
final GpxSelectionHelper selectedGpxHelper = mapActivity.getMyApplication().getSelectedGpxHelper();
if (selectedGpxHelper.isShowingAnyGpxFiles()) {
selectedGpxHelper.clearAllGpxFilesToShow(true);
adapter.getItem(pos).setDescription(selectedGpxHelper.getGpxDescription());
} else {
showGpxSelectionDialog(adapter, adapter.getItem(pos));
}
} else if (itemId == R.string.rendering_category_transport) {
boolean selected = TransportLinesMenu.isShowLines(mapActivity.getMyApplication());
TransportLinesMenu.toggleTransportLines(mapActivity, !selected, new CallbackWithObject<Boolean>() {
@Override
public boolean processResult(Boolean result) {
item.setSelected(result);
item.setColorRes(result ? R.color.osmand_orange : ContextMenuItem.INVALID_ID);
adapter.notifyDataSetChanged();
return true;
}
});
} else if (itemId == R.string.map_markers) {
settings.SHOW_MAP_MARKERS.set(isChecked);
} else if (itemId == R.string.layer_map) {
if (OsmandPlugin.getEnabledPlugin(OsmandRasterMapsPlugin.class) == null) {
Intent intent = new Intent(mapActivity, PluginActivity.class);
intent.putExtra(PluginActivity.EXTRA_PLUGIN_ID, OsmandRasterMapsPlugin.ID);
mapActivity.startActivity(intent);
} else {
ContextMenuItem it = adapter.getItem(pos);
mapActivity.getMapLayers().selectMapLayer(mapActivity.getMapView(), it, adapter);
}
}
adapter.notifyDataSetChanged();
mapActivity.getMapLayers().updateLayers(mapActivity.getMapView());
mapActivity.getMapView().refreshMap();
return false;
}
private void showGpxSelectionDialog(final ArrayAdapter<ContextMenuItem> adapter,
final ContextMenuItem item) {
AlertDialog dialog = mapActivity.getMapLayers().showGPXFileLayer(getAlreadySelectedGpx(),
mapActivity.getMapView());
dialog.setOnDismissListener(new DialogInterface.OnDismissListener() {
@Override
public void onDismiss(DialogInterface dialog) {
OsmandApplication app = mapActivity.getMyApplication();
boolean selected = app.getSelectedGpxHelper().isShowingAnyGpxFiles();
item.setSelected(selected);
item.setDescription(app.getSelectedGpxHelper().getGpxDescription());
item.setColorRes(selected ? R.color.osmand_orange : ContextMenuItem.INVALID_ID);
adapter.notifyDataSetChanged();
}
});
}
protected void showPoiFilterDialog(final ArrayAdapter<ContextMenuItem> adapter,
final ContextMenuItem item) {
final PoiFiltersHelper poiFiltersHelper = mapActivity.getMyApplication().getPoiFilters();
final PoiUIFilter wiki = poiFiltersHelper.getTopWikiPoiFilter();
MapActivityLayers.DismissListener dismissListener =
new MapActivityLayers.DismissListener() {
@Override
public void dismiss() {
PoiFiltersHelper pf = mapActivity.getMyApplication().getPoiFilters();
boolean selected = pf.isShowingAnyPoi(wiki);
item.setSelected(selected);
item.setDescription(pf.getSelectedPoiFiltersName(wiki));
item.setColorRes(selected ? R.color.osmand_orange : ContextMenuItem.INVALID_ID);
adapter.notifyDataSetChanged();
}
};
if (poiFiltersHelper.isShowingAnyPoi(wiki)) {
mapActivity.getMapLayers().showMultichoicePoiFilterDialog(mapActivity.getMapView(),
dismissListener);
} else {
mapActivity.getMapLayers().showSingleChoicePoiFilterDialog(mapActivity.getMapView(),
dismissListener);
}
}
}

View file

@ -80,7 +80,6 @@ import net.osmand.plus.OsmAndConstants;
import net.osmand.plus.OsmAndFormatter;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandPlugin;
import net.osmand.plus.settings.backend.OsmandSettings;
import net.osmand.plus.R;
import net.osmand.plus.UiUtilities;
import net.osmand.plus.Version;
@ -90,10 +89,11 @@ import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.activities.PluginActivity;
import net.osmand.plus.activities.SettingsActivity;
import net.osmand.plus.dialogs.ConfigureMapMenu;
import net.osmand.plus.dialogs.ConfigureMapMenu.AppearanceListItem;
import net.osmand.plus.dialogs.ConfigureMapMenu.GpxAppearanceAdapter;
import net.osmand.plus.dialogs.GpxAppearanceAdapter;
import net.osmand.plus.dialogs.GpxAppearanceAdapter.AppearanceListItem;
import net.osmand.plus.monitoring.OsmandMonitoringPlugin;
import net.osmand.plus.routing.RouteCalculationResult;
import net.osmand.plus.settings.backend.OsmandSettings;
import net.osmand.render.RenderingRuleProperty;
import net.osmand.render.RenderingRulesStorage;
import net.osmand.router.RouteStatisticsHelper;
@ -540,9 +540,9 @@ public class GpxUiHelper {
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
AppearanceListItem item = gpxApprAdapter.getItem(position);
if (item != null) {
if (item.getAttrName() == CURRENT_TRACK_WIDTH_ATTR) {
if (CURRENT_TRACK_WIDTH_ATTR.equals(item.getAttrName())) {
gpxAppearanceParams.put(CURRENT_TRACK_WIDTH_ATTR, item.getValue());
} else if (item.getAttrName() == CURRENT_TRACK_COLOR_ATTR) {
} else if (CURRENT_TRACK_COLOR_ATTR.equals(item.getAttrName())) {
gpxAppearanceParams.put(CURRENT_TRACK_COLOR_ATTR, item.getValue());
}
}
@ -592,7 +592,7 @@ public class GpxUiHelper {
}
dialog.dismiss();
loadGPXFileInDifferentThread(activity, callbackWithObject, dir, currentGPX,
s.toArray(new String[s.size()]));
s.toArray(new String[0]));
}
});
builder.setNegativeButton(R.string.shared_string_cancel, null);

View file

@ -32,7 +32,7 @@ import net.osmand.data.FavouritePoint.BackgroundType;
import net.osmand.plus.AppInitializer;
import net.osmand.plus.CustomOsmandPlugin;
import net.osmand.plus.FavouritesDbHelper;
import net.osmand.plus.GPXDatabase;
import net.osmand.plus.GPXDatabase.GpxDataItem;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandPlugin;
import net.osmand.plus.R;
@ -1017,10 +1017,10 @@ public class ImportHelper {
gpxFile.path = toWrite.getAbsolutePath();
File file = new File(gpxFile.path);
if (!destinationExists) {
GPXDatabase.GpxDataItem item = new GPXDatabase.GpxDataItem(file, gpxFile.getColor(0));
GpxDataItem item = new GpxDataItem(file, gpxFile);
app.getGpxDbHelper().add(item);
} else {
GPXDatabase.GpxDataItem item = app.getGpxDbHelper().getItem(file);
GpxDataItem item = app.getGpxDbHelper().getItem(file);
if (item != null) {
app.getGpxDbHelper().clearAnalysis(item);
}

View file

@ -1,5 +1,6 @@
package net.osmand.plus.myplaces;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
@ -14,8 +15,10 @@ import android.view.LayoutInflater;
import android.view.View;
import android.widget.AbsListView;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.ProgressBar;
import android.widget.TextView;
@ -36,12 +39,12 @@ import com.squareup.picasso.RequestCreator;
import net.osmand.AndroidUtils;
import net.osmand.GPXUtilities;
import net.osmand.GPXUtilities.GPXFile;
import net.osmand.GPXUtilities.GPXFile.GpxSplitType;
import net.osmand.GPXUtilities.WptPt;
import net.osmand.PicassoUtils;
import net.osmand.data.LatLon;
import net.osmand.data.PointDescription;
import net.osmand.data.QuadRect;
import net.osmand.plus.GPXDatabase;
import net.osmand.plus.GPXDatabase.GpxDataItem;
import net.osmand.plus.GpxSelectionHelper;
import net.osmand.plus.GpxSelectionHelper.GpxDisplayGroup;
@ -49,13 +52,16 @@ import net.osmand.plus.GpxSelectionHelper.GpxDisplayItemType;
import net.osmand.plus.GpxSelectionHelper.SelectedGpxFile;
import net.osmand.plus.OsmAndFormatter;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.settings.backend.OsmandSettings;
import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.activities.TrackActivity;
import net.osmand.plus.dialogs.ConfigureMapMenu;
import net.osmand.plus.dialogs.GpxAppearanceAdapter;
import net.osmand.plus.dialogs.GpxAppearanceAdapter.AppearanceListItem;
import net.osmand.plus.dialogs.GpxAppearanceAdapter.GpxAppearanceAdapterType;
import net.osmand.plus.measurementtool.NewGpxData;
import net.osmand.plus.myplaces.TrackBitmapDrawer.TrackBitmapDrawerListener;
import net.osmand.plus.settings.backend.OsmandSettings;
import net.osmand.plus.settings.backend.OsmandSettings.CommonPreference;
import net.osmand.plus.widgets.tools.CropCircleTransformation;
import net.osmand.plus.wikipedia.WikiArticleHelper;
import net.osmand.plus.wikivoyage.WikivoyageUtils;
@ -71,6 +77,7 @@ import java.util.Map;
import gnu.trove.list.array.TIntArrayList;
import static net.osmand.plus.dialogs.ConfigureMapMenu.CURRENT_TRACK_COLOR_ATTR;
import static net.osmand.plus.dialogs.ConfigureMapMenu.CURRENT_TRACK_WIDTH_ATTR;
public class TrackActivityFragmentAdapter implements TrackBitmapDrawerListener {
@ -356,50 +363,27 @@ public class TrackActivityFragmentAdapter implements TrackBitmapDrawerListener {
@Override
public void onClick(View v) {
TrackActivity activity = getTrackActivity();
if (activity != null) {
colorListPopupWindow = new ListPopupWindow(activity);
colorListPopupWindow.setAnchorView(colorView);
colorListPopupWindow.setContentWidth(AndroidUtils.dpToPx(app, 200f));
colorListPopupWindow.setModal(true);
colorListPopupWindow.setDropDownGravity(Gravity.RIGHT | Gravity.TOP);
colorListPopupWindow.setVerticalOffset(AndroidUtils.dpToPx(app, -48f));
colorListPopupWindow.setHorizontalOffset(AndroidUtils.dpToPx(app, -6f));
GPXFile gpxFile = getGpx();
final ConfigureMapMenu.GpxAppearanceAdapter gpxApprAdapter = new ConfigureMapMenu.GpxAppearanceAdapter(activity,
gpxFile.getColor(0), ConfigureMapMenu.GpxAppearanceAdapter.GpxAppearanceAdapterType.TRACK_COLOR);
colorListPopupWindow.setAdapter(gpxApprAdapter);
colorListPopupWindow.setOnItemClickListener(new AdapterView.OnItemClickListener() {
final GPXFile gpxFile = getGpx();
if (activity != null && gpxFile != null) {
final GpxAppearanceAdapter appearanceAdapter = new GpxAppearanceAdapter(activity,
gpxFile.getColor(0), GpxAppearanceAdapterType.TRACK_WIDTH_COLOR);
OnItemClickListener itemClickListener = new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
ConfigureMapMenu.AppearanceListItem item = gpxApprAdapter.getItem(position);
AppearanceListItem item = appearanceAdapter.getItem(position);
if (item != null) {
if (CURRENT_TRACK_COLOR_ATTR.equals(item.getAttrName())) {
GPXFile gpx = getGpx();
int clr = item.getColor();
if (vis.isChecked()) {
if (gpx != null) {
SelectedGpxFile sf = app.getSelectedGpxHelper().selectGpxFile(gpx, vis.isChecked(), false);
if (clr != 0 && sf.getModifiableGpxFile() != null) {
sf.getModifiableGpxFile().setColor(clr);
if (getGpxDataItem() != null) {
app.getGpxDbHelper().updateColor(getGpxDataItem(), clr);
}
}
}
} else if (getGpxDataItem() != null) {
app.getGpxDbHelper().updateColor(getGpxDataItem(), clr);
}
if (gpx != null && gpx.showCurrentTrack) {
app.getSettings().CURRENT_TRACK_COLOR.set(clr);
}
refreshTrackBitmap();
setGpxColor(item, gpxFile);
} else if (CURRENT_TRACK_WIDTH_ATTR.equals(item.getAttrName())) {
setGpxWidth(item, gpxFile);
}
}
colorListPopupWindow.dismiss();
updateColorView(colorView);
}
});
};
colorListPopupWindow = createPopupWindow(activity, splitIntervalView, appearanceAdapter, itemClickListener);
colorListPopupWindow.show();
}
}
@ -415,16 +399,8 @@ public class TrackActivityFragmentAdapter implements TrackBitmapDrawerListener {
public void onClick(View v) {
TrackActivity activity = getTrackActivity();
if (activity != null) {
splitListPopupWindow = new ListPopupWindow(activity);
splitListPopupWindow.setAnchorView(splitIntervalView);
splitListPopupWindow.setContentWidth(AndroidUtils.dpToPx(app, 200f));
splitListPopupWindow.setModal(true);
splitListPopupWindow.setDropDownGravity(Gravity.RIGHT | Gravity.TOP);
splitListPopupWindow.setVerticalOffset(AndroidUtils.dpToPx(app, -48f));
splitListPopupWindow.setHorizontalOffset(AndroidUtils.dpToPx(app, -6f));
splitListPopupWindow.setAdapter(new ArrayAdapter<>(activity,
R.layout.popup_list_text_item, options));
splitListPopupWindow.setOnItemClickListener(new AdapterView.OnItemClickListener() {
ListAdapter adapter = new ArrayAdapter<>(activity, R.layout.popup_list_text_item, options);
OnItemClickListener itemClickListener = new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
@ -433,7 +409,8 @@ public class TrackActivityFragmentAdapter implements TrackBitmapDrawerListener {
splitListPopupWindow.dismiss();
updateSplitIntervalView(splitIntervalView);
}
});
};
splitListPopupWindow = createPopupWindow(activity, splitIntervalView, adapter, itemClickListener);
splitListPopupWindow.show();
}
}
@ -451,6 +428,55 @@ public class TrackActivityFragmentAdapter implements TrackBitmapDrawerListener {
}
}
private void setGpxColor(AppearanceListItem item, GPXFile gpxFile) {
int color = item.getColor();
if (vis.isChecked()) {
SelectedGpxFile sf = app.getSelectedGpxHelper().selectGpxFile(gpxFile, vis.isChecked(), false);
if (color != 0 && sf.getModifiableGpxFile() != null) {
sf.getModifiableGpxFile().setColor(color);
if (getGpxDataItem() != null) {
app.getGpxDbHelper().updateColor(getGpxDataItem(), color);
}
}
} else if (getGpxDataItem() != null) {
app.getGpxDbHelper().updateColor(getGpxDataItem(), color);
}
if (gpxFile.showCurrentTrack) {
app.getSettings().CURRENT_TRACK_COLOR.set(color);
}
refreshTrackBitmap();
}
private void setGpxWidth(AppearanceListItem item, GPXFile gpxFile) {
String width = item.getValue();
if (vis.isChecked()) {
SelectedGpxFile sf = app.getSelectedGpxHelper().selectGpxFile(gpxFile, vis.isChecked(), false);
if (width != null && sf.getModifiableGpxFile() != null) {
sf.getModifiableGpxFile().setWidth(width);
if (getGpxDataItem() != null) {
app.getGpxDbHelper().updateWidth(getGpxDataItem(), width);
}
}
} else if (getGpxDataItem() != null) {
app.getGpxDbHelper().updateWidth(getGpxDataItem(), width);
}
refreshTrackBitmap();
}
private ListPopupWindow createPopupWindow(Activity activity, View anchorView, ListAdapter adapter, OnItemClickListener itemClickListener) {
ListPopupWindow popupWindow = new ListPopupWindow(activity);
popupWindow.setAnchorView(anchorView);
popupWindow.setContentWidth(AndroidUtils.dpToPx(app, 200f));
popupWindow.setModal(true);
popupWindow.setDropDownGravity(Gravity.RIGHT | Gravity.TOP);
popupWindow.setVerticalOffset(AndroidUtils.dpToPx(app, -48f));
popupWindow.setHorizontalOffset(AndroidUtils.dpToPx(app, -6f));
popupWindow.setAdapter(adapter);
popupWindow.setOnItemClickListener(itemClickListener);
return popupWindow;
}
@Nullable
private View getDescriptionCardView(Context context) {
GPXFile gpx = getGpx();
@ -729,7 +755,7 @@ public class TrackActivityFragmentAdapter implements TrackBitmapDrawerListener {
text.setText(options.get(selectedSplitInterval));
}
}
private int getSelectedSplitInterval() {
if (getGpxDataItem() == null) {
return 0;
@ -737,14 +763,14 @@ public class TrackActivityFragmentAdapter implements TrackBitmapDrawerListener {
int splitType = getGpxDataItem().getSplitType();
double splitInterval = getGpxDataItem().getSplitInterval();
int position = 0;
if (splitType == GPXDatabase.GPX_SPLIT_TYPE_DISTANCE) {
if (splitType == GpxSplitType.DISTANCE.getType()) {
position = distanceSplit.indexOf(splitInterval);
} else if (splitType == GPXDatabase.GPX_SPLIT_TYPE_TIME) {
} else if (splitType == GpxSplitType.TIME.getType()) {
position = timeSplit.indexOf((int) splitInterval);
}
return position > 0 ? position : 0;
return Math.max(position, 0);
}
private void updateColorView(View colorView) {
@ -759,10 +785,9 @@ public class TrackActivityFragmentAdapter implements TrackBitmapDrawerListener {
}
}
if (color == 0) {
final RenderingRulesStorage renderer = app.getRendererRegistry().getCurrentSelectedRenderer();
final OsmandSettings.CommonPreference<String> prefColor
= app.getSettings().getCustomRenderProperty(CURRENT_TRACK_COLOR_ATTR);
color = ConfigureMapMenu.GpxAppearanceAdapter.parseTrackColor(renderer, prefColor.get());
RenderingRulesStorage renderer = app.getRendererRegistry().getCurrentSelectedRenderer();
CommonPreference<String> prefColor = app.getSettings().getCustomRenderProperty(CURRENT_TRACK_COLOR_ATTR);
color = GpxAppearanceAdapter.parseTrackColor(renderer, prefColor.get());
}
if (color == 0) {
colorImageView.setImageDrawable(app.getUIUtilities().getThemedIcon(R.drawable.ic_action_circle));
@ -852,20 +877,20 @@ public class TrackActivityFragmentAdapter implements TrackBitmapDrawerListener {
}
private void updateSplitInDatabase() {
int splitType = 0;
double splitInterval = 0;
GpxSplitType splitType = null;
if (selectedSplitInterval == 0) {
splitType = GPXDatabase.GPX_SPLIT_TYPE_NO_SPLIT;
splitType = GpxSplitType.NO_SPLIT;
splitInterval = 0;
} else if (distanceSplit.get(selectedSplitInterval) > 0) {
splitType = GPXDatabase.GPX_SPLIT_TYPE_DISTANCE;
splitType = GpxSplitType.DISTANCE;
splitInterval = distanceSplit.get(selectedSplitInterval);
} else if (timeSplit.get(selectedSplitInterval) > 0) {
splitType = GPXDatabase.GPX_SPLIT_TYPE_TIME;
splitType = GpxSplitType.TIME;
splitInterval = timeSplit.get(selectedSplitInterval);
}
GpxDataItem item = getGpxDataItem();
if (item != null) {
if (item != null && splitType != null) {
app.getGpxDbHelper().updateSplit(item, splitType, splitInterval);
}
}

View file

@ -2,7 +2,6 @@ package net.osmand.plus.views;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.ColorFilter;
import android.graphics.Paint;
import android.graphics.Paint.Align;
import android.graphics.Paint.Style;
@ -11,6 +10,7 @@ import android.graphics.PorterDuff.Mode;
import android.graphics.PorterDuffColorFilter;
import android.graphics.Rect;
import android.graphics.RectF;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.LayerDrawable;
import android.os.AsyncTask;
import android.util.Pair;
@ -21,11 +21,13 @@ import androidx.annotation.Nullable;
import androidx.appcompat.content.res.AppCompatResources;
import androidx.core.content.ContextCompat;
import net.osmand.AndroidUtils;
import net.osmand.GPXUtilities;
import net.osmand.GPXUtilities.GPXFile;
import net.osmand.GPXUtilities.TrkSegment;
import net.osmand.GPXUtilities.WptPt;
import net.osmand.Location;
import net.osmand.PlatformUtil;
import net.osmand.data.LatLon;
import net.osmand.data.PointDescription;
import net.osmand.data.QuadRect;
@ -40,6 +42,7 @@ import net.osmand.plus.MapMarkersHelper.MapMarker;
import net.osmand.plus.MapMarkersHelper.MapMarkersGroup;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R;
import net.osmand.plus.UiUtilities;
import net.osmand.plus.base.PointImageDrawable;
import net.osmand.plus.mapcontextmenu.controllers.SelectedGpxMenuController.SelectedGpxPoint;
import net.osmand.plus.mapcontextmenu.other.TrackChartPoints;
@ -55,6 +58,8 @@ import net.osmand.render.RenderingRulesStorage;
import net.osmand.util.Algorithms;
import net.osmand.util.MapUtils;
import org.apache.commons.logging.Log;
import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
@ -67,29 +72,30 @@ import static net.osmand.plus.dialogs.ConfigureMapMenu.CURRENT_TRACK_WIDTH_ATTR;
public class GPXLayer extends OsmandMapLayer implements IContextMenuProvider, IMoveObjectProvider, MapTextProvider<WptPt> {
private static final Log log = PlatformUtil.getLog(GPXLayer.class);
private static final double TOUCH_RADIUS_MULTIPLIER = 1.5;
private static final int DEFAULT_WIDTH_MULTIPLIER = 7;
private static final int START_ZOOM = 7;
private OsmandMapTileView view;
private Paint paint;
private Paint paint2;
private boolean isPaint2;
private Paint shadowPaint;
private boolean isShadowPaint;
private Paint paint_1;
private boolean isPaint_1;
private Paint paintIcon;
private int cachedHash;
private int cachedColor;
private Paint paintIcon;
private int currentTrackColor;
private float defaultTrackWidth;
private Map<String, Float> cachedTrackWidth = new HashMap<>();
private Drawable startPointIcon;
private Drawable finishPointIcon;
private LayerDrawable selectedPoint;
private TrackChartPoints trackChartPoints;
private GpxSelectionHelper selectedGpxHelper;
private MapMarkersHelper mapMarkersHelper;
private Paint paintBmp;
private List<WptPt> cache = new ArrayList<>();
private Map<WptPt, SelectedGpxFile> pointFileMap = new HashMap<>();
private MapTextLayer textLayer;
@ -134,26 +140,14 @@ public class GPXLayer extends OsmandMapLayer implements IContextMenuProvider, IM
paint = new Paint();
paint.setStyle(Style.STROKE);
paint.setAntiAlias(true);
paint2 = new Paint();
paint2.setStyle(Style.STROKE);
paint2.setAntiAlias(true);
shadowPaint = new Paint();
shadowPaint.setStyle(Style.STROKE);
shadowPaint.setAntiAlias(true);
paint_1 = new Paint();
paint_1.setStyle(Style.STROKE);
paint_1.setAntiAlias(true);
paintBmp = new Paint();
paintBmp.setAntiAlias(true);
paintBmp.setFilterBitmap(true);
paintBmp.setDither(true);
paintTextIcon = new Paint();
paintTextIcon.setTextSize(10 * view.getDensity());
paintTextIcon.setTextAlign(Align.CENTER);
paintTextIcon.setFakeBoldText(true);
// paintTextIcon.setColor(Color.WHITE);
paintTextIcon.setAntiAlias(true);
textLayer = view.getLayerByClass(MapTextLayer.class);
@ -164,21 +158,24 @@ public class GPXLayer extends OsmandMapLayer implements IContextMenuProvider, IM
paintOuterRect = new Paint();
paintOuterRect.setStyle(Style.STROKE);
paintOuterRect.setAntiAlias(true);
// paintOuterRect.setColor(Color.WHITE);
paintOuterRect.setStrokeWidth(3);
paintOuterRect.setAlpha(255);
paintGridCircle = new Paint();
paintGridCircle.setStyle(Style.FILL_AND_STROKE);
paintGridCircle.setAntiAlias(true);
paintGridOuterCircle = new Paint();
paintGridOuterCircle.setStyle(Style.FILL_AND_STROKE);
paintGridOuterCircle.setAntiAlias(true);
paintGridOuterCircle.setColor(Color.WHITE);
paintGridOuterCircle.setAlpha(204);
paintGridOuterCircle = new Paint();
paintGridOuterCircle.setStyle(Style.FILL_AND_STROKE);
paintGridOuterCircle.setAntiAlias(true);
paintGridOuterCircle.setColor(Color.WHITE);
paintGridOuterCircle.setAlpha(204);
paintIcon = new Paint();
selectedPoint = (LayerDrawable) AppCompatResources.getDrawable(view.getContext(), R.drawable.map_location_default);
UiUtilities iconsCache = view.getApplication().getUIUtilities();
startPointIcon = iconsCache.getIcon(R.drawable.map_track_point_start);
finishPointIcon = iconsCache.getIcon(R.drawable.map_track_point_finish);
contextMenuLayer = view.getLayerByClass(ContextMenuLayer.class);
visitedColor = ContextCompat.getColor(view.getApplication(), R.color.color_ok);
@ -213,6 +210,7 @@ public class GPXLayer extends OsmandMapLayer implements IContextMenuProvider, IM
}
drawSelectedFilesSplits(canvas, tileBox, selectedGPXFiles, settings);
drawSelectedFilesPoints(canvas, tileBox, selectedGPXFiles);
drawSelectedFilesStartEndPoints(canvas, tileBox, selectedGPXFiles);
}
if (textLayer != null && isTextVisible()) {
textLayer.putData(this, cache);
@ -220,29 +218,28 @@ public class GPXLayer extends OsmandMapLayer implements IContextMenuProvider, IM
}
private int updatePaints(int color, boolean routePoints, boolean currentTrack, DrawSettings nightMode, RotatedTileBox tileBox) {
private int updatePaints(int color, String width, boolean routePoints, boolean currentTrack, DrawSettings drawSettings, RotatedTileBox tileBox) {
RenderingRulesStorage rrs = view.getApplication().getRendererRegistry().getCurrentSelectedRenderer();
final boolean isNight = nightMode != null && nightMode.isNightMode();
int hsh = calculateHash(rrs, routePoints, isNight, tileBox.getMapDensity(), tileBox.getZoom(),
currentTrackColorPref.get(), currentTrackWidthPref.get());
if (hsh != cachedHash) {
cachedHash = hsh;
boolean nightMode = drawSettings != null && drawSettings.isNightMode();
int hash = calculateHash(rrs, cachedTrackWidth, routePoints, nightMode, tileBox.getMapDensity(), tileBox.getZoom(),
currentTrackColorPref.get(), currentTrackWidthPref.get());
if (hash != cachedHash) {
cachedHash = hash;
cachedColor = ContextCompat.getColor(view.getApplication(), R.color.gpx_track);
defaultTrackWidth = DEFAULT_WIDTH_MULTIPLIER * view.getDensity();
if (rrs != null) {
RenderingRuleSearchRequest req = new RenderingRuleSearchRequest(rrs);
req.setBooleanFilter(rrs.PROPS.R_NIGHT_MODE, isNight);
CommonPreference<String> p = view.getSettings().getCustomRenderProperty(CURRENT_TRACK_COLOR_ATTR);
if (p != null && p.isSet()) {
req.setBooleanFilter(rrs.PROPS.R_NIGHT_MODE, nightMode);
if (currentTrackColorPref != null && currentTrackColorPref.isSet()) {
RenderingRuleProperty ctColor = rrs.PROPS.get(CURRENT_TRACK_COLOR_ATTR);
if (ctColor != null) {
req.setStringFilter(ctColor, p.get());
req.setStringFilter(ctColor, currentTrackColorPref.get());
}
}
CommonPreference<String> p2 = view.getSettings().getCustomRenderProperty(CURRENT_TRACK_WIDTH_ATTR);
if (p2 != null && p2.isSet()) {
if (currentTrackWidthPref != null && currentTrackWidthPref.isSet()) {
RenderingRuleProperty ctWidth = rrs.PROPS.get(CURRENT_TRACK_WIDTH_ATTR);
if (ctWidth != null) {
req.setStringFilter(ctWidth, p2.get());
req.setStringFilter(ctWidth, currentTrackWidthPref.get());
}
}
String additional = "";
@ -262,32 +259,60 @@ public class GPXLayer extends OsmandMapLayer implements IContextMenuProvider, IM
rc.setDensityValue((float) tileBox.getMapDensity());
cachedColor = req.getIntPropertyValue(rrs.PROPS.R_COLOR);
osmandRenderer.updatePaint(req, paint, 0, false, rc);
isPaint2 = osmandRenderer.updatePaint(req, paint2, 1, false, rc);
isPaint_1 = osmandRenderer.updatePaint(req, paint_1, -1, false, rc);
isShadowPaint = req.isSpecified(rrs.PROPS.R_SHADOW_RADIUS);
if (isShadowPaint) {
ColorFilter cf = new PorterDuffColorFilter(req.getIntPropertyValue(rrs.PROPS.R_SHADOW_COLOR),
Mode.SRC_IN);
shadowPaint.setColorFilter(cf);
shadowPaint.setStrokeWidth(paint.getStrokeWidth() + 2
* rc.getComplexValue(req, rrs.PROPS.R_SHADOW_RADIUS));
if (req.isSpecified(rrs.PROPS.R_SHADOW_RADIUS)) {
int shadowColor = req.getIntPropertyValue(rrs.PROPS.R_SHADOW_COLOR);
float shadowRadius = rc.getComplexValue(req, rrs.PROPS.R_SHADOW_RADIUS);
shadowPaint.setColorFilter(new PorterDuffColorFilter(shadowColor, Mode.SRC_IN));
shadowPaint.setStrokeWidth(paint.getStrokeWidth() + 2 * shadowRadius);
}
for (String key : cachedTrackWidth.keySet()) {
acquireTrackWidth(key, rrs, req, rc);
}
} else {
System.err.println("Rendering attribute gpx is not found !");
paint.setStrokeWidth(7 * view.getDensity());
log.error("Rendering attribute gpx is not found !");
for (String key : cachedTrackWidth.keySet()) {
cachedTrackWidth.put(key, defaultTrackWidth);
}
}
}
}
paint.setColor(color == 0 ? cachedColor : color);
Float strikeWidth = cachedTrackWidth.get(width);
if (strikeWidth != null) {
paint.setStrokeWidth(strikeWidth);
}
return cachedColor;
}
private void acquireTrackWidth(String widthKey, RenderingRulesStorage rrs, RenderingRuleSearchRequest req, RenderingContext rc) {
if (!Algorithms.isEmpty(widthKey) && Algorithms.isInt(widthKey)) {
try {
int widthDp = Integer.parseInt(widthKey);
float widthF = AndroidUtils.dpToPx(view.getApplication(), widthDp);
cachedTrackWidth.put(widthKey, widthF);
} catch (NumberFormatException e) {
log.error(e.getMessage(), e);
cachedTrackWidth.put(widthKey, defaultTrackWidth);
}
} else {
RenderingRuleProperty ctWidth = rrs.PROPS.get(CURRENT_TRACK_WIDTH_ATTR);
if (ctWidth != null) {
req.setStringFilter(ctWidth, widthKey);
}
if (req.searchRenderingAttribute("gpx")) {
float widthF = rc.getComplexValue(req, req.ALL.R_STROKE_WIDTH);
cachedTrackWidth.put(widthKey, widthF);
}
}
}
private int calculateHash(Object... o) {
return Arrays.hashCode(o);
}
private void drawSelectedFilesSplits(Canvas canvas, RotatedTileBox tileBox, List<SelectedGpxFile> selectedGPXFiles,
DrawSettings settings) {
DrawSettings settings) {
if (tileBox.getZoom() >= START_ZOOM) {
// request to load
for (SelectedGpxFile g : selectedGPXFiles) {
@ -354,11 +379,11 @@ public class GPXLayer extends OsmandMapLayer implements IContextMenuProvider, IM
paintTextIcon.getTextBounds(nm, 0, nm.length(), bounds);
int nmWidth = bounds.width();
int nmHeight = bounds.height();
RectF rect = new RectF(x - nmWidth / 2 - 2 * (float) Math.ceil(tileBox.getDensity()),
y + nmHeight / 2 + 3 * (float) Math.ceil(tileBox.getDensity()),
x + nmWidth / 2 + 3 * (float) Math.ceil(tileBox.getDensity()),
y - nmHeight / 2 - 2 * (float) Math.ceil(tileBox.getDensity()));
canvas.drawRoundRect(rect, 0, 0, paintInnerRect);
RectF rect = new RectF(x - nmWidth / 2 - 2 * (float) Math.ceil(tileBox.getDensity()),
y + nmHeight / 2 + 3 * (float) Math.ceil(tileBox.getDensity()),
x + nmWidth / 2 + 3 * (float) Math.ceil(tileBox.getDensity()),
y - nmHeight / 2 - 2 * (float) Math.ceil(tileBox.getDensity()));
canvas.drawRoundRect(rect, 0, 0, paintInnerRect);
canvas.drawRoundRect(rect, 0, 0, paintOuterRect);
// canvas.drawRect(rect, paintInnerRect);
// canvas.drawRect(rect, paintOuterRect);
@ -368,6 +393,34 @@ public class GPXLayer extends OsmandMapLayer implements IContextMenuProvider, IM
}
}
private void drawSelectedFilesStartEndPoints(Canvas canvas, RotatedTileBox tileBox, List<SelectedGpxFile> selectedGPXFiles) {
if (tileBox.getZoom() >= START_ZOOM) {
for (SelectedGpxFile selectedGpxFile : selectedGPXFiles) {
if (selectedGpxFile.getGpxFile().isShowStartFinish()) {
List<TrkSegment> segments = selectedGpxFile.getPointsToDisplay();
TrkSegment endSegment = segments.get(segments.size() - 1);
WptPt start = segments.get(0).points.get(0);
WptPt end = endSegment.points.get(endSegment.points.size() - 1);
drawPoint(canvas, tileBox, start, startPointIcon);
drawPoint(canvas, tileBox, end, finishPointIcon);
}
}
}
}
private void drawPoint(Canvas canvas, RotatedTileBox tileBox, WptPt wptPt, Drawable icon) {
int pointX = (int) tileBox.getPixXFromLatLon(wptPt.lat, wptPt.lon);
int pointY = (int) tileBox.getPixYFromLatLon(wptPt.lat, wptPt.lon);
icon.setBounds(pointX - icon.getIntrinsicWidth() / 2,
pointY - icon.getIntrinsicHeight() / 2,
pointX + icon.getIntrinsicWidth() / 2,
pointY + icon.getIntrinsicHeight() / 2);
icon.draw(canvas);
}
private void drawSelectedFilesPoints(Canvas canvas, RotatedTileBox tileBox, List<SelectedGpxFile> selectedGPXFiles) {
if (tileBox.getZoom() >= START_ZOOM) {
float textScale = view.getSettings().TEXT_SCALE.get();
@ -463,7 +516,7 @@ public class GPXLayer extends OsmandMapLayer implements IContextMenuProvider, IM
trackChartPoints.setSegmentColor(color);
}
paintGridCircle.setColor(color);
paintGridCircle.setAlpha(255);
paintGridCircle.setAlpha(255);
QuadRect latLonBounds = tileBox.getLatLonBounds();
float r = 3 * tileBox.getDensity();
List<LatLon> xAxisPoints = trackChartPoints.getXAxisPoints();
@ -517,8 +570,13 @@ public class GPXLayer extends OsmandMapLayer implements IContextMenuProvider, IM
}
private void drawSelectedFilesSegments(Canvas canvas, RotatedTileBox tileBox,
List<SelectedGpxFile> selectedGPXFiles, DrawSettings settings) {
List<SelectedGpxFile> selectedGPXFiles, DrawSettings settings) {
for (SelectedGpxFile selectedGpxFile : selectedGPXFiles) {
String width = selectedGpxFile.getGpxFile().getWidth(currentTrackWidthPref.get());
if (!cachedTrackWidth.containsKey(width)) {
cachedTrackWidth.put(width, null);
}
}
SelectedGpxFile currentTrack = null;
for (SelectedGpxFile g : selectedGPXFiles) {
if (g.isShowCurrentTrack()) {
@ -536,6 +594,7 @@ public class GPXLayer extends OsmandMapLayer implements IContextMenuProvider, IM
RotatedTileBox tileBox, DrawSettings settings) {
List<TrkSegment> segments = selectedGpxFile.getPointsToDisplay();
for (TrkSegment ts : segments) {
String width = selectedGpxFile.getGpxFile().getWidth(currentTrackWidthPref.get());
int color = selectedGpxFile.getGpxFile().getColor(0);
if (currentTrack) {
color = currentTrackColor;
@ -550,8 +609,8 @@ public class GPXLayer extends OsmandMapLayer implements IContextMenuProvider, IM
ts.renderer = new Renderable.StandardTrack(ts.points, 17.2);
}
}
updatePaints(color, selectedGpxFile.isRoutePoints(), currentTrack, settings, tileBox);
if(ts.renderer instanceof Renderable.RenderableSegment) {
updatePaints(color, width, selectedGpxFile.isRoutePoints(), currentTrack, settings, tileBox);
if (ts.renderer instanceof Renderable.RenderableSegment) {
((Renderable.RenderableSegment) ts.renderer).drawSegment(view.getZoom(), paint, canvas, tileBox);
}
}