Fix custom favorite icons
This commit is contained in:
parent
db080a9447
commit
ac87261ade
4 changed files with 28 additions and 14 deletions
|
@ -42,7 +42,8 @@ import java.util.TimeZone;
|
||||||
|
|
||||||
public class GPXUtilities {
|
public class GPXUtilities {
|
||||||
public final static Log log = PlatformUtil.getLog(GPXUtilities.class);
|
public final static Log log = PlatformUtil.getLog(GPXUtilities.class);
|
||||||
private static final String ICON_NAME_EXTENSION = "icon_name";
|
private static final String ICON_NAME_EXTENSION = "icon";
|
||||||
|
private static final String DEFAULT_ICON_NAME = "special_star";
|
||||||
|
|
||||||
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 = "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$
|
private final static String GPX_TIME_FORMAT_MILLIS = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"; //$NON-NLS-1$
|
||||||
|
@ -259,7 +260,11 @@ public class GPXUtilities {
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getIconName() {
|
public String getIconName() {
|
||||||
return getExtensionsToRead().get(ICON_NAME_EXTENSION);
|
String iconName = getExtensionsToRead().get(ICON_NAME_EXTENSION);
|
||||||
|
if (iconName == null) {
|
||||||
|
iconName = DEFAULT_ICON_NAME;
|
||||||
|
}
|
||||||
|
return iconName;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setIconName(String iconName) {
|
public void setIconName(String iconName) {
|
||||||
|
|
|
@ -53,7 +53,9 @@
|
||||||
android:layout_gravity="center_vertical"
|
android:layout_gravity="center_vertical"
|
||||||
android:layout_weight="1"
|
android:layout_weight="1"
|
||||||
android:orientation="vertical"
|
android:orientation="vertical"
|
||||||
android:paddingRight="@dimen/list_content_padding">
|
android:paddingTop="6dp"
|
||||||
|
android:paddingRight="@dimen/list_content_padding"
|
||||||
|
android:paddingBottom="6dp">
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/favourite_label"
|
android:id="@+id/favourite_label"
|
||||||
|
|
|
@ -3,6 +3,7 @@ package net.osmand.data;
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.content.res.Resources;
|
||||||
import android.support.annotation.DrawableRes;
|
import android.support.annotation.DrawableRes;
|
||||||
import android.support.annotation.NonNull;
|
import android.support.annotation.NonNull;
|
||||||
import android.support.annotation.StringRes;
|
import android.support.annotation.StringRes;
|
||||||
|
@ -18,6 +19,7 @@ public class FavouritePoint implements Serializable, LocationPoint {
|
||||||
|
|
||||||
private static final String HIDDEN = "hidden";
|
private static final String HIDDEN = "hidden";
|
||||||
private static final String ADDRESS_EXTENSION = "address";
|
private static final String ADDRESS_EXTENSION = "address";
|
||||||
|
private static final String DEFAULT_ICON_NAME = "special_star";
|
||||||
|
|
||||||
protected String name = "";
|
protected String name = "";
|
||||||
protected String description;
|
protected String description;
|
||||||
|
@ -93,6 +95,10 @@ public class FavouritePoint implements Serializable, LocationPoint {
|
||||||
return iconId;
|
return iconId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getIconEntryName(Context ctx) {
|
||||||
|
return ctx.getResources().getResourceEntryName(getOverlayIconId());
|
||||||
|
}
|
||||||
|
|
||||||
public void setIconId(int iconId) {
|
public void setIconId(int iconId) {
|
||||||
this.iconId = iconId;
|
this.iconId = iconId;
|
||||||
}
|
}
|
||||||
|
@ -314,7 +320,7 @@ public class FavouritePoint implements Serializable, LocationPoint {
|
||||||
pt.getExtensionsToWrite().put(ADDRESS_EXTENSION, getAddress());
|
pt.getExtensionsToWrite().put(ADDRESS_EXTENSION, getAddress());
|
||||||
}
|
}
|
||||||
if (iconId != 0) {
|
if (iconId != 0) {
|
||||||
pt.setIconName(ctx.getResources().getResourceEntryName(iconId).substring(3));
|
pt.setIconName(getIconEntryName(ctx).substring(3));
|
||||||
}
|
}
|
||||||
if (getColor() != 0) {
|
if (getColor() != 0) {
|
||||||
pt.setColor(getColor());
|
pt.setColor(getColor());
|
||||||
|
|
|
@ -14,7 +14,6 @@ import android.graphics.PorterDuffColorFilter;
|
||||||
import android.graphics.Rect;
|
import android.graphics.Rect;
|
||||||
import android.graphics.drawable.Drawable;
|
import android.graphics.drawable.Drawable;
|
||||||
import android.support.annotation.NonNull;
|
import android.support.annotation.NonNull;
|
||||||
import android.support.v4.content.res.ResourcesCompat;
|
|
||||||
|
|
||||||
import net.osmand.GPXUtilities;
|
import net.osmand.GPXUtilities;
|
||||||
import net.osmand.data.FavouritePoint;
|
import net.osmand.data.FavouritePoint;
|
||||||
|
@ -47,15 +46,17 @@ public class FavoriteImageDrawable extends Drawable {
|
||||||
this.synced = synced;
|
this.synced = synced;
|
||||||
Resources res = ctx.getResources();
|
Resources res = ctx.getResources();
|
||||||
int overlayIconId = point != null ? point.getOverlayIconId() : 0;
|
int overlayIconId = point != null ? point.getOverlayIconId() : 0;
|
||||||
|
int uiIconId;
|
||||||
if (overlayIconId != 0) {
|
if (overlayIconId != 0) {
|
||||||
favIcon = ((OsmandApplication) ctx.getApplicationContext()).getUIUtilities()
|
favIcon = ((OsmandApplication) ctx.getApplicationContext()).getUIUtilities()
|
||||||
.getIcon(getMapIconId(ctx, overlayIconId), R.color.color_white);
|
.getIcon(getMapIconId(ctx, overlayIconId), R.color.color_white);
|
||||||
listDrawable = ((OsmandApplication) ctx.getApplicationContext()).getUIUtilities()
|
uiIconId = overlayIconId;
|
||||||
.getIcon(overlayIconId, R.color.color_white);
|
|
||||||
} else {
|
} else {
|
||||||
favIcon = res.getDrawable(R.drawable.map_favorite);
|
favIcon = res.getDrawable(R.drawable.mm_special_star);
|
||||||
listDrawable = ResourcesCompat.getDrawable(res, R.drawable.ic_action_fav_dark, null).mutate();
|
uiIconId = R.drawable.mx_special_star;
|
||||||
}
|
}
|
||||||
|
listDrawable = ((OsmandApplication) ctx.getApplicationContext()).getUIUtilities()
|
||||||
|
.getIcon(uiIconId, R.color.color_white);
|
||||||
int col = color == 0 || color == Color.BLACK ? res.getColor(R.color.color_favorite) : color;
|
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, R.drawable.map_white_favorite_shield);
|
||||||
syncedStroke = BitmapFactory.decodeResource(res, R.drawable.map_shield_marker_point_stroke);
|
syncedStroke = BitmapFactory.decodeResource(res, R.drawable.map_shield_marker_point_stroke);
|
||||||
|
@ -151,17 +152,17 @@ public class FavoriteImageDrawable extends Drawable {
|
||||||
|
|
||||||
private static TreeMap<String, FavoriteImageDrawable> cache = new TreeMap<>();
|
private static TreeMap<String, FavoriteImageDrawable> cache = new TreeMap<>();
|
||||||
|
|
||||||
private static FavoriteImageDrawable getOrCreate(Context a, int color, boolean withShadow, boolean synced, FavouritePoint point) {
|
private static FavoriteImageDrawable getOrCreate(Context ctx, int color, boolean withShadow, boolean synced, FavouritePoint point) {
|
||||||
String pointName = "";
|
String iconName = "";
|
||||||
if (point != null) {
|
if (point != null) {
|
||||||
pointName = point.getName();
|
iconName = point.getIconEntryName(ctx);
|
||||||
}
|
}
|
||||||
color = color | 0xff000000;
|
color = color | 0xff000000;
|
||||||
int hash = (color << 4) + ((withShadow ? 1 : 0) << 2) + ((synced ? 3 : 0) << 2);
|
int hash = (color << 4) + ((withShadow ? 1 : 0) << 2) + ((synced ? 3 : 0) << 2);
|
||||||
String uniqueId = hash + pointName;
|
String uniqueId = hash + iconName;
|
||||||
FavoriteImageDrawable drawable = cache.get(uniqueId);
|
FavoriteImageDrawable drawable = cache.get(uniqueId);
|
||||||
if (drawable == null) {
|
if (drawable == null) {
|
||||||
drawable = new FavoriteImageDrawable(a, color, withShadow, synced, point);
|
drawable = new FavoriteImageDrawable(ctx, color, withShadow, synced, point);
|
||||||
drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight());
|
drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight());
|
||||||
cache.put(uniqueId, drawable);
|
cache.put(uniqueId, drawable);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue