diff --git a/src/main/java/de/blau/android/layer/data/MapOverlay.java b/src/main/java/de/blau/android/layer/data/MapOverlay.java index 29c92963cf..5f148680af 100644 --- a/src/main/java/de/blau/android/layer/data/MapOverlay.java +++ b/src/main/java/de/blau/android/layer/data/MapOverlay.java @@ -110,10 +110,12 @@ public class MapOverlay extends MapViewLayer private static final int ICON_SELECTED_BORDER = 2; private static final int LABEL_EXTRA = 40; - private static final long AUTOPRUNE_MIN_INTERVAL = 10000; // milli-seconds between autoprunes + private static final long AUTOPRUNE_MIN_INTERVAL = 10000; // milli-seconds between + // autoprunes public static final int DEFAULT_AUTOPRUNE_NODE_LIMIT = 5000; public static final int PAN_AND_ZOOM_LIMIT = 17; - private static final int MP_SIZE_LIMIT = 1000; // max size of MP to render as MP + private static final int MP_SIZE_LIMIT = 1000; // max size of MP to render as + // MP /** half the width/height of a node icon in px */ private final int iconRadius; @@ -1209,15 +1211,7 @@ private void retrieveIcon(@NonNull OsmElement element, boolean isWay, @NonNull W boolean usePresetIcon = style.usePresetIcon(); if (iconPath != null && !usePresetIcon) { - iconDrawable = customIconCache.get(iconPath); - if (iconDrawable == null && !customIconCache.containsKey(iconPath)) { - try (FileInputStream stream = new FileInputStream(iconPath)) { - iconDrawable = PresetIconManager.bitmapDrawableFromStream(context, ICON_SIZE_DP, stream, PresetIconManager.isSvg(iconPath)); - customIconCache.put(iconPath, iconDrawable); - } catch (IOException e) { - Log.e(DEBUG_TAG, "Icon " + iconPath + " not found"); - } - } + iconDrawable = retrieveCustomIcon(iconPath); } else if (tmpPresets != null) { SortedMap tags = element.getTags(); PresetItem match = null; @@ -1246,6 +1240,45 @@ private void retrieveIcon(@NonNull OsmElement element, boolean isWay, @NonNull W map.postInvalidate(); } + /** + * Get a custom icon + * + * @param iconPath configured icon path + */ + @Nullable + public BitmapDrawable retrieveCustomIcon(String iconPath) { + BitmapDrawable iconDrawable = customIconCache.get(iconPath); // NOSONAR computeIfAbsent doesn't exist prior to Android 7 + if (iconDrawable != null || customIconCache.containsKey(iconPath)) { + return iconDrawable; + } + String iconDirPath = DataStyle.getCurrent().getIconDirPath(); + if (iconDirPath != null) { + try (FileInputStream stream = new FileInputStream(iconPath)) { + iconDrawable = PresetIconManager.bitmapDrawableFromStream(context, ICON_SIZE_DP, stream, PresetIconManager.isSvg(iconPath)); + customIconCache.put(iconPath, iconDrawable); + return iconDrawable; + } catch (IOException e) { + Log.w(DEBUG_TAG, "Icon " + iconPath + " not found"); + } + } + // search in all presets + for (Preset preset : App.getCurrentPresets(context)) { + if (preset != null) { + PresetIconManager iconManager = preset.getIconManager(context); + iconDrawable = iconManager.getDrawable(iconPath, ICON_SIZE_DP); + if (iconDrawable != null) { + customIconCache.put(iconPath, iconDrawable); + break; + } + } + } + if (iconDrawable == null) { + Log.w(DEBUG_TAG, "Icon " + iconPath + " not found"); + customIconCache.put(iconPath, null); + } + return iconDrawable; + } + /** * Remove everything from the iconCache */ diff --git a/src/main/java/de/blau/android/presets/Preset.java b/src/main/java/de/blau/android/presets/Preset.java index 6e285e3f96..87868d0bb0 100644 --- a/src/main/java/de/blau/android/presets/Preset.java +++ b/src/main/java/de/blau/android/presets/Preset.java @@ -329,7 +329,7 @@ public Preset(@NonNull List elements) { * @return the PresetIconManager instance */ @NonNull - PresetIconManager getIconManager(@NonNull Context ctx) { + public PresetIconManager getIconManager(@NonNull Context ctx) { if (iconManager == null) { if (directory != null) { if (directory.getName().equals(AdvancedPrefDatabase.ID_DEFAULT)) { @@ -1525,7 +1525,7 @@ public static boolean generateTaginfoJson(@NonNull Context ctx, @NonNull File ou outputStream.println("\"tags\":["); Collection discardedKeys = new DiscardedTags(ctx).getKeys(); - for (String key:discardedKeys) { + for (String key : discardedKeys) { outputStream.println("{\"description\":\"Automatically discarded\",\"key\":\"" + key + "\"},"); } int presetsCount = presets.length; diff --git a/src/main/java/de/blau/android/resources/DataStyle.java b/src/main/java/de/blau/android/resources/DataStyle.java index ff66881845..60ea01a118 100644 --- a/src/main/java/de/blau/android/resources/DataStyle.java +++ b/src/main/java/de/blau/android/resources/DataStyle.java @@ -924,7 +924,7 @@ private void init() { fp.getPaint().setStrokeCap(Cap.ROUND); fp.getPaint().setStrokeJoin(Join.ROUND); internalStyles.put(GPS_TRACK, fp); - + fp = new FeatureStyle(MVT_DEFAULT, baseWayStyle); fp.setColor(Color.BLUE); fp.getPaint().setAlpha(0x7F); @@ -2000,6 +2000,16 @@ public Path getXPath() { return xPath; } + /** + * If a directory is set for custom icons return it + * + * @return the directory path or null + */ + @Nullable + public String getIconDirPath() { + return iconDirPath; + } + /** * @return the name */