From d4f3c1b597a89cd00511aa015b90c4319573cf3d Mon Sep 17 00:00:00 2001 From: Dima-1 Date: Wed, 19 Feb 2020 19:12:59 +0200 Subject: [PATCH] Custom fav icon --- .../main/java/net/osmand/GPXUtilities.java | 14 +++++++ .../src/net/osmand/data/FavouritePoint.java | 37 ++++++++++++++++++- .../plus/base/FavoriteImageDrawable.java | 10 ++++- 3 files changed, 59 insertions(+), 2 deletions(-) diff --git a/OsmAnd-java/src/main/java/net/osmand/GPXUtilities.java b/OsmAnd-java/src/main/java/net/osmand/GPXUtilities.java index fe6d1336f1..e80d91ec9c 100644 --- a/OsmAnd-java/src/main/java/net/osmand/GPXUtilities.java +++ b/OsmAnd-java/src/main/java/net/osmand/GPXUtilities.java @@ -44,6 +44,8 @@ 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"; + public static final String BACK_TYPE_EXTENSION = "background"; + private static final String DEFAULT_BACK_TYPE = "bg_point_circle"; 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$ @@ -271,6 +273,18 @@ public class GPXUtilities { getExtensionsToWrite().put(ICON_NAME_EXTENSION, iconName); } + public String getBackType() { + String backType = getExtensionsToRead().get(BACK_TYPE_EXTENSION); + if (backType == null) { + backType = DEFAULT_ICON_NAME; + } + return backType; + } + + public void setBackType(String backType) { + getExtensionsToWrite().put(BACK_TYPE_EXTENSION, backType); + } + @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 4d70bd663b..0ce4dae2c7 100644 --- a/OsmAnd/src/net/osmand/data/FavouritePoint.java +++ b/OsmAnd/src/net/osmand/data/FavouritePoint.java @@ -12,7 +12,6 @@ import net.osmand.plus.FavouritesDbHelper; import net.osmand.plus.R; import net.osmand.util.Algorithms; - public class FavouritePoint implements Serializable, LocationPoint { private static final long serialVersionUID = 729654300829771466L; @@ -30,6 +29,7 @@ public class FavouritePoint implements Serializable, LocationPoint { private int color; private boolean visible = true; private SpecialPointType specialPointType = null; + private BackType backType = null; public FavouritePoint() { } @@ -56,6 +56,7 @@ public class FavouritePoint implements Serializable, LocationPoint { this.originObjectName = favouritePoint.originObjectName; this.address = favouritePoint.address; this.iconId = favouritePoint.iconId; + this.backType = favouritePoint.backType; initPersonalType(); } @@ -196,6 +197,17 @@ public class FavouritePoint implements Serializable, LocationPoint { this.description = description; } + private void setBackType(BackType backType) { + this.backType = backType; + } + + public BackType getBackType() { + if (backType == null) { + return BackType.CIRCLE; + } + return backType; + } + @NonNull @Override public String toString() { @@ -284,6 +296,25 @@ public class FavouritePoint implements Serializable, LocationPoint { } } + public enum BackType { + CIRCLE("CIRCLE", R.drawable.bg_point_circle), + RHOMB("RHOMB", R.drawable.bg_point_rhomb), + SQUARE("SQUARE", R.drawable.bg_point_square); + + private String typeName; + @StringRes + private int iconId; + + BackType(@NonNull String typeName, @DrawableRes int iconId){ + this.typeName = typeName; + this.iconId = iconId; + } + + public int getIconId() { + return iconId; + } + } + public static FavouritePoint fromWpt(@NonNull WptPt pt, @NonNull Context ctx) { String name = pt.name; String categoryName = pt.category != null ? pt.category : ""; @@ -303,6 +334,7 @@ public class FavouritePoint implements Serializable, LocationPoint { if (iconName != null) { fp.setIconIdFromName(ctx, iconName); } + fp.setBackType(BackType.valueOf((pt.getBackType()))); return fp; } @@ -319,6 +351,9 @@ public class FavouritePoint implements Serializable, LocationPoint { if (iconId != 0) { pt.setIconName(getIconEntryName(ctx).substring(3)); } + if(backType != null) { + pt.setBackType(backType.typeName); + } 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 75c5cecdf7..49baf3cddb 100644 --- a/OsmAnd/src/net/osmand/plus/base/FavoriteImageDrawable.java +++ b/OsmAnd/src/net/osmand/plus/base/FavoriteImageDrawable.java @@ -57,8 +57,10 @@ public class FavoriteImageDrawable extends Drawable { } listDrawable = ((OsmandApplication) ctx.getApplicationContext()).getUIUtilities() .getIcon(uiIconId, R.color.color_white); + int backgroundIconId = point!=null ? getMapBackIconId(ctx,point.getBackType().getIconId()):R.drawable.map_white_favorite_shield; int col = color == 0 || color == Color.BLACK ? res.getColor(R.color.color_favorite) : color; - favBackground = BitmapFactory.decodeResource(res, R.drawable.map_white_favorite_shield); + favBackground = BitmapFactory.decodeResource(res,backgroundIconId); +// favBackground = BitmapFactory.decodeResource(res, R.drawable.map_white_favorite_shield); syncedStroke = BitmapFactory.decodeResource(res, R.drawable.map_shield_marker_point_stroke); syncedColor = BitmapFactory.decodeResource(res, R.drawable.map_shield_marker_point_color); syncedShadow = BitmapFactory.decodeResource(res, R.drawable.map_shield_marker_point_shadow); @@ -75,6 +77,12 @@ public class FavoriteImageDrawable extends Drawable { .replaceFirst("mx_", "mm_"), "drawable", ctx.getPackageName()); } + private int getMapBackIconId(Context ctx, int iconId) { + String iconName = ctx.getResources().getResourceEntryName(iconId); + return ctx.getResources().getIdentifier("map_"+iconName + "_center" + , "drawable", ctx.getPackageName()); + } + private void initSimplePaint(Paint paint, int color) { paint.setAntiAlias(true); paint.setStyle(Style.FILL_AND_STROKE);