GPXLayer custom icon
This commit is contained in:
parent
e6e841f619
commit
4f39004c5e
3 changed files with 27 additions and 6 deletions
|
@ -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;
|
||||
|
|
|
@ -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());
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue