Custom fav icon

This commit is contained in:
Dima-1 2020-02-19 19:12:59 +02:00
parent b6eab65554
commit d4f3c1b597
3 changed files with 59 additions and 2 deletions

View file

@ -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;

View file

@ -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());
}

View file

@ -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);