From 4f39004c5e589621086959ed6067a87637182996 Mon Sep 17 00:00:00 2001 From: Dima-1 Date: Thu, 23 Jan 2020 14:08:18 +0200 Subject: [PATCH] GPXLayer custom icon --- .../src/main/java/net/osmand/GPXUtilities.java | 9 +++++++++ OsmAnd/src/net/osmand/data/FavouritePoint.java | 11 +++++++---- .../net/osmand/plus/base/FavoriteImageDrawable.java | 13 +++++++++++-- 3 files changed, 27 insertions(+), 6 deletions(-) diff --git a/OsmAnd-java/src/main/java/net/osmand/GPXUtilities.java b/OsmAnd-java/src/main/java/net/osmand/GPXUtilities.java index 8acf7b4106..47705ec8ed 100644 --- a/OsmAnd-java/src/main/java/net/osmand/GPXUtilities.java +++ b/OsmAnd-java/src/main/java/net/osmand/GPXUtilities.java @@ -42,6 +42,7 @@ import java.util.TimeZone; public class GPXUtilities { public final static Log log = PlatformUtil.getLog(GPXUtilities.class); + private static final String ICON_NAME_EXTENSION = "icon_name"; private final static String GPX_TIME_FORMAT = "yyyy-MM-dd'T'HH:mm:ss'Z'"; //$NON-NLS-1$ private final static String GPX_TIME_FORMAT_MILLIS = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"; //$NON-NLS-1$ @@ -257,6 +258,14 @@ public class GPXUtilities { return true; } + public String getIconName() { + return getExtensionsToRead().get(ICON_NAME_EXTENSION); + } + + public void setIconName(String iconName) { + getExtensionsToWrite().put(ICON_NAME_EXTENSION, iconName); + } + @Override public int hashCode() { final int prime = 31; diff --git a/OsmAnd/src/net/osmand/data/FavouritePoint.java b/OsmAnd/src/net/osmand/data/FavouritePoint.java index 2fabe85346..d62003b645 100644 --- a/OsmAnd/src/net/osmand/data/FavouritePoint.java +++ b/OsmAnd/src/net/osmand/data/FavouritePoint.java @@ -18,7 +18,6 @@ public class FavouritePoint implements Serializable, LocationPoint { private static final String HIDDEN = "hidden"; private static final String ADDRESS_EXTENSION = "address"; - private static final String ICON_NAME_EXTENSION = "icon_name"; protected String name = ""; protected String description; @@ -98,6 +97,10 @@ public class FavouritePoint implements Serializable, LocationPoint { this.iconId = iconId; } + public void setIconIdFromName(Context ctx, String iconName) { + this.iconId = ctx.getResources().getIdentifier(iconName, "drawable", ctx.getPackageName()); + } + public boolean isSpecialPoint() { return specialPointType != null; } @@ -293,9 +296,9 @@ public class FavouritePoint implements Serializable, LocationPoint { fp.setColor(pt.getColor(0)); fp.setVisible(!pt.getExtensionsToRead().containsKey(HIDDEN)); fp.setAddress(pt.getExtensionsToRead().get(ADDRESS_EXTENSION)); - String iconName = pt.getExtensionsToRead().get(ICON_NAME_EXTENSION); + String iconName = pt.getIconName(); if (iconName != null) { - fp.setIconId(ctx.getResources().getIdentifier(iconName, "drawable", ctx.getPackageName())); + fp.setIconIdFromName(ctx, iconName); } return fp; } @@ -311,7 +314,7 @@ public class FavouritePoint implements Serializable, LocationPoint { pt.getExtensionsToWrite().put(ADDRESS_EXTENSION, getAddress()); } if (iconId != 0) { - pt.getExtensionsToWrite().put(ICON_NAME_EXTENSION, ctx.getResources().getResourceEntryName(iconId)); + pt.setIconName(ctx.getResources().getResourceEntryName(iconId)); } if (getColor() != 0) { pt.setColor(getColor()); diff --git a/OsmAnd/src/net/osmand/plus/base/FavoriteImageDrawable.java b/OsmAnd/src/net/osmand/plus/base/FavoriteImageDrawable.java index 3c316a6f1c..d590e8a796 100644 --- a/OsmAnd/src/net/osmand/plus/base/FavoriteImageDrawable.java +++ b/OsmAnd/src/net/osmand/plus/base/FavoriteImageDrawable.java @@ -173,7 +173,7 @@ public class FavoriteImageDrawable extends Drawable { } public static FavoriteImageDrawable getOrCreate(Context a, int color, boolean withShadow, GPXUtilities.WptPt pt) { - return getOrCreate(a, color, withShadow, false, null); + return getOrCreate(a, color, withShadow, false, getFavouriteFromWpt(a, pt)); } public static FavoriteImageDrawable getOrCreateSyncedIcon(Context a, int color, FavouritePoint point) { @@ -181,6 +181,15 @@ public class FavoriteImageDrawable extends Drawable { } public static FavoriteImageDrawable getOrCreateSyncedIcon(Context a, int color, GPXUtilities.WptPt pt) { - return getOrCreate(a, color, false, true, null); + return getOrCreate(a, color, false, true, getFavouriteFromWpt(a, pt)); + } + + private static FavouritePoint getFavouriteFromWpt(Context a, GPXUtilities.WptPt pt) { + FavouritePoint point = null; + if (pt != null) { + point = new FavouritePoint(pt.getLatitude(), pt.getLongitude(), pt.name, pt.category); + point.setIconIdFromName(a, pt.getIconName()); + } + return point; } }