Feature request: retain the original color coding when importing GPX #6386 - in progress
This commit is contained in:
parent
dd58cac831
commit
2d9fbc9ad6
3 changed files with 33 additions and 3 deletions
|
@ -646,6 +646,23 @@ public class Algorithms {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static String colorNameToString(String colorName) {
|
||||||
|
Map<String, String> colorTable = new HashMap<>();
|
||||||
|
colorTable.put("black", "#000000");
|
||||||
|
colorTable.put("white", "#FFFFFF");
|
||||||
|
colorTable.put("red", "#ff0000");
|
||||||
|
colorTable.put("orange", "#ff8800");
|
||||||
|
colorTable.put("green", "#23b03b");
|
||||||
|
colorTable.put("blue", "#2f7af5");
|
||||||
|
for (String key : colorTable.keySet()) {
|
||||||
|
if(colorName.toLowerCase().contains(key)) {
|
||||||
|
return colorTable.get(key);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return "#FF0000";
|
||||||
|
}
|
||||||
|
|
||||||
private static String format(int i, String hexString) {
|
private static String format(int i, String hexString) {
|
||||||
while (hexString.length() < i) {
|
while (hexString.length() < i) {
|
||||||
hexString = "0" + hexString;
|
hexString = "0" + hexString;
|
||||||
|
|
|
@ -99,6 +99,10 @@ public class GPXUtilities {
|
||||||
getExtensionsToWrite().put("color", Algorithms.colorToString(color));
|
getExtensionsToWrite().put("color", Algorithms.colorToString(color));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setColor(String colorName) {
|
||||||
|
getExtensionsToWrite().put("color", Algorithms.colorNameToString(colorName));
|
||||||
|
}
|
||||||
|
|
||||||
public void removeColor() {
|
public void removeColor() {
|
||||||
getExtensionsToWrite().remove("color");
|
getExtensionsToWrite().remove("color");
|
||||||
}
|
}
|
||||||
|
@ -1510,18 +1514,26 @@ public class GPXUtilities {
|
||||||
if (tok == XmlPullParser.START_TAG) {
|
if (tok == XmlPullParser.START_TAG) {
|
||||||
Object parse = parserState.peek();
|
Object parse = parserState.peek();
|
||||||
String tag = parser.getName();
|
String tag = parser.getName();
|
||||||
if (extensionReadMode && parse instanceof GPXExtensions) {
|
if (extensionReadMode && parse != null) {
|
||||||
String value = readText(parser, tag);
|
String value = readText(parser, tag);
|
||||||
if (value != null) {
|
if (value != null) {
|
||||||
((GPXExtensions) parse).getExtensionsToWrite().put(tag.toLowerCase(), value);
|
((GPXExtensions) parse).getExtensionsToWrite().put(tag.toLowerCase(), value);
|
||||||
if (tag.equals("speed") && parse instanceof WptPt) {
|
if (tag.equals("speed") && parse instanceof WptPt) {
|
||||||
try {
|
try {
|
||||||
((WptPt) parse).speed = Float.parseFloat(value);
|
((WptPt) parse).speed = Float.parseFloat(value);
|
||||||
} catch (NumberFormatException e) {
|
} catch (NumberFormatException e) {}
|
||||||
|
}
|
||||||
|
if (tag.equals("trackextension") || tag.equals("color") || tag.equals("colour") || tag.equals("displaycolor")) {
|
||||||
|
int color;
|
||||||
|
try {
|
||||||
|
color = Integer.parseInt(value);
|
||||||
|
((GPXExtensions) parse).setColor(color);
|
||||||
|
} catch (NumberFormatException nfe) {
|
||||||
|
((GPXExtensions) parse).setColor(value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
}
|
||||||
} else if (parse instanceof GPXExtensions && tag.equals("extensions")) {
|
} else if (parse instanceof GPXExtensions && tag.equals("extensions")) {
|
||||||
extensionReadMode = true;
|
extensionReadMode = true;
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -261,6 +261,7 @@ public class ImportHelper {
|
||||||
final List<FavouritePoint> favourites = asFavourites(gpxFile.getPoints(), fileName, forceImportFavourites);
|
final List<FavouritePoint> favourites = asFavourites(gpxFile.getPoints(), fileName, forceImportFavourites);
|
||||||
final FavouritesDbHelper favoritesHelper = app.getFavorites();
|
final FavouritesDbHelper favoritesHelper = app.getFavorites();
|
||||||
for (final FavouritePoint favourite : favourites) {
|
for (final FavouritePoint favourite : favourites) {
|
||||||
|
favoritesHelper.deleteFavourite(favourite, false);
|
||||||
favoritesHelper.addFavourite(favourite, false);
|
favoritesHelper.addFavourite(favourite, false);
|
||||||
}
|
}
|
||||||
favoritesHelper.sortAll();
|
favoritesHelper.sortAll();
|
||||||
|
|
Loading…
Reference in a new issue