// Path: mapsforge-map-android/src/main/java/org/mapsforge/map/android/rendertheme/AssetsRenderTheme.java
// public class AssetsRenderTheme implements XmlRenderTheme {
// 
//     private final AssetManager assetManager;
//     private final String fileName;
//     private XmlRenderThemeMenuCallback menuCallback;
//     private final String relativePathPrefix;
//     private XmlThemeResourceProvider resourceProvider;
// 
//     /**
//      * @param assetManager       the Android asset manager.
//      * @param relativePathPrefix the prefix for all relative resource paths.
//      * @param fileName           the path to the XML render theme file.
//      */
//     public AssetsRenderTheme(AssetManager assetManager, String relativePathPrefix, String fileName) {
//         this(assetManager, relativePathPrefix, fileName, null);
//     }
// 
//     /**
//      * @param assetManager       the Android asset manager.
//      * @param relativePathPrefix the prefix for all relative resource paths.
//      * @param fileName           the path to the XML render theme file.
//      * @param menuCallback       the interface callback to create a settings menu on the fly.
//      */
//     public AssetsRenderTheme(AssetManager assetManager, String relativePathPrefix, String fileName, XmlRenderThemeMenuCallback menuCallback) {
//         this.assetManager = assetManager;
//         this.relativePathPrefix = relativePathPrefix;
//         this.fileName = fileName;
//         this.menuCallback = menuCallback;
//     }
// 
//     @Override
//     public boolean equals(Object obj) {
//         if (this == obj) {
//             return true;
//         } else if (!(obj instanceof AssetsRenderTheme)) {
//             return false;
//         }
//         AssetsRenderTheme other = (AssetsRenderTheme) obj;
//         try {
//             if (getRenderThemeAsStream() != other.getRenderThemeAsStream()) {
//                 return false;
//             }
//         } catch (IOException e) {
//             e.printStackTrace();
//             return false;
//         }
//         if (!Utils.equals(this.relativePathPrefix, other.relativePathPrefix)) {
//             return false;
//         }
//         return true;
//     }
// 
//     @Override
//     public XmlRenderThemeMenuCallback getMenuCallback() {
//         return this.menuCallback;
//     }
// 
//     @Override
//     public String getRelativePathPrefix() {
//         return this.relativePathPrefix;
//     }
// 
//     @Override
//     public InputStream getRenderThemeAsStream() throws IOException {
//         return this.assetManager.open((TextUtils.isEmpty(this.relativePathPrefix) ? "" : this.relativePathPrefix) + this.fileName);
//     }
// 
//     @Override
//     public XmlThemeResourceProvider getResourceProvider() {
//         return this.resourceProvider;
//     }
// 
//     @Override
//     public int hashCode() {
//         final int prime = 31;
//         int result = 1;
//         InputStream inputStream = null;
//         try {
//             inputStream = getRenderThemeAsStream();
//         } catch (IOException e) {
//             e.printStackTrace();
//         }
//         result = prime * result + ((inputStream == null) ? 0 : inputStream.hashCode());
//         result = prime * result + ((this.relativePathPrefix == null) ? 0 : this.relativePathPrefix.hashCode());
//         return result;
//     }
// 
//     @Override
//     public void setMenuCallback(XmlRenderThemeMenuCallback menuCallback) {
//         this.menuCallback = menuCallback;
//     }
// 
//     @Override
//     public void setResourceProvider(XmlThemeResourceProvider resourceProvider) {
//         this.resourceProvider = resourceProvider;
//     }
// }
// 
// Path: mapsforge-map/src/main/java/org/mapsforge/map/rendertheme/XmlRenderTheme.java
// public interface XmlRenderTheme {
//     /**
//      * @return the interface callback to create a settings menu on the fly.
//      */
//     XmlRenderThemeMenuCallback getMenuCallback();
// 
//     /**
//      * @return the prefix for all relative resource paths.
//      */
//     String getRelativePathPrefix();
// 
//     /**
//      * @return an InputStream to read the render theme data from.
//      * @throws IOException if the render theme file cannot be found.
//      */
//     InputStream getRenderThemeAsStream() throws IOException;
// 
//     /**
//      * @return a custom provider to retrieve resources internally referenced by "src" attribute (e.g. images, icons).
//      */
//     XmlThemeResourceProvider getResourceProvider();
// 
//     /**
//      * @param menuCallback the interface callback to create a settings menu on the fly.
//      */
//     void setMenuCallback(XmlRenderThemeMenuCallback menuCallback);
// 
//     /**
//      * @param resourceProvider a custom provider to retrieve resources internally referenced by "src" attribute (e.g. images, icons).
//      */
//     void setResourceProvider(XmlThemeResourceProvider resourceProvider);
// }


import android.content.SharedPreferences;
import android.util.Log;
import org.mapsforge.map.android.rendertheme.AssetsRenderTheme;
import org.mapsforge.map.android.util.AndroidUtil;
import org.mapsforge.map.layer.cache.TileCache;
import org.mapsforge.map.rendertheme.XmlRenderTheme;
import org.mapsforge.map.rendertheme.XmlRenderThemeMenuCallback;
import org.mapsforge.map.rendertheme.XmlRenderThemeStyleLayer;
import org.mapsforge.map.rendertheme.XmlRenderThemeStyleMenu;
import java.util.Set;
            Log.w(SamplesApplication.TAG, "Invalid style " + id);
            return null;
        }
        Set<String> result = baseLayer.getCategories();

        // add the categories from overlays that are enabled
        for (XmlRenderThemeStyleLayer overlay : baseLayer.getOverlays()) {
            if (this.sharedPreferences.getBoolean(overlay.getId(), overlay.isEnabled())) {
                result.addAll(overlay.getCategories());
            }
        }

        return result;
    }

    protected String getRenderThemeFile() {
        return "mapsforge/stylemenu.xml";
    }

    @Override
    public void onSharedPreferenceChanged(SharedPreferences preferences, String key) {
        super.onSharedPreferenceChanged(preferences, key);
        // difficult to know which render theme options have changed since we
        // do not know all the keys, so we just purge the caches and redraw
        // the map whenever there is a change in the settings.
        // TODO: for real applications it is essential to know when the style menu has
        // changed. It would be good to find a way of identifying when a key is
        // for the style menu.
        Log.i(SamplesApplication.TAG, "Purging tile caches");

// Path: mapsforge-map-android/src/main/java/org/mapsforge/map/android/rendertheme/AssetsRenderTheme.java
// public class AssetsRenderTheme implements XmlRenderTheme {
// 
//     private final AssetManager assetManager;
//     private final String fileName;
//     private XmlRenderThemeMenuCallback menuCallback;
//     private final String relativePathPrefix;
//     private XmlThemeResourceProvider resourceProvider;
// 
//     /**
//      * @param assetManager       the Android asset manager.
//      * @param relativePathPrefix the prefix for all relative resource paths.
//      * @param fileName           the path to the XML render theme file.
//      */
//     public AssetsRenderTheme(AssetManager assetManager, String relativePathPrefix, String fileName) {
//         this(assetManager, relativePathPrefix, fileName, null);
//     }
// 
//     /**
//      * @param assetManager       the Android asset manager.
//      * @param relativePathPrefix the prefix for all relative resource paths.
//      * @param fileName           the path to the XML render theme file.
//      * @param menuCallback       the interface callback to create a settings menu on the fly.
//      */
//     public AssetsRenderTheme(AssetManager assetManager, String relativePathPrefix, String fileName, XmlRenderThemeMenuCallback menuCallback) {
//         this.assetManager = assetManager;
//         this.relativePathPrefix = relativePathPrefix;
//         this.fileName = fileName;
//         this.menuCallback = menuCallback;
//     }
// 
//     @Override
//     public boolean equals(Object obj) {
//         if (this == obj) {
//             return true;
//         } else if (!(obj instanceof AssetsRenderTheme)) {
//             return false;
//         }
//         AssetsRenderTheme other = (AssetsRenderTheme) obj;
//         try {
//             if (getRenderThemeAsStream() != other.getRenderThemeAsStream()) {
//                 return false;
//             }
//         } catch (IOException e) {
//             e.printStackTrace();
//             return false;
//         }
//         if (!Utils.equals(this.relativePathPrefix, other.relativePathPrefix)) {
//             return false;
//         }
//         return true;
//     }
// 
//     @Override
//     public XmlRenderThemeMenuCallback getMenuCallback() {
//         return this.menuCallback;
//     }
// 
//     @Override
//     public String getRelativePathPrefix() {
//         return this.relativePathPrefix;
//     }
// 
//     @Override
//     public InputStream getRenderThemeAsStream() throws IOException {
//         return this.assetManager.open((TextUtils.isEmpty(this.relativePathPrefix) ? "" : this.relativePathPrefix) + this.fileName);
//     }
// 
//     @Override
//     public XmlThemeResourceProvider getResourceProvider() {
//         return this.resourceProvider;
//     }
// 
//     @Override
//     public int hashCode() {
//         final int prime = 31;
//         int result = 1;
//         InputStream inputStream = null;
//         try {
//             inputStream = getRenderThemeAsStream();
//         } catch (IOException e) {
//             e.printStackTrace();
//         }
//         result = prime * result + ((inputStream == null) ? 0 : inputStream.hashCode());
//         result = prime * result + ((this.relativePathPrefix == null) ? 0 : this.relativePathPrefix.hashCode());
//         return result;
//     }
// 
//     @Override
//     public void setMenuCallback(XmlRenderThemeMenuCallback menuCallback) {
//         this.menuCallback = menuCallback;
//     }
// 
//     @Override
//     public void setResourceProvider(XmlThemeResourceProvider resourceProvider) {
//         this.resourceProvider = resourceProvider;
//     }
// }
// 
// Path: mapsforge-map/src/main/java/org/mapsforge/map/rendertheme/XmlRenderTheme.java
// public interface XmlRenderTheme {
//     /**
//      * @return the interface callback to create a settings menu on the fly.
//      */
//     XmlRenderThemeMenuCallback getMenuCallback();
// 
//     /**
//      * @return the prefix for all relative resource paths.
//      */
//     String getRelativePathPrefix();
// 
//     /**
//      * @return an InputStream to read the render theme data from.
//      * @throws IOException if the render theme file cannot be found.
//      */
//     InputStream getRenderThemeAsStream() throws IOException;
// 
//     /**
//      * @return a custom provider to retrieve resources internally referenced by "src" attribute (e.g. images, icons).
//      */
//     XmlThemeResourceProvider getResourceProvider();
// 
//     /**
//      * @param menuCallback the interface callback to create a settings menu on the fly.
//      */
//     void setMenuCallback(XmlRenderThemeMenuCallback menuCallback);
// 
//     /**
//      * @param resourceProvider a custom provider to retrieve resources internally referenced by "src" attribute (e.g. images, icons).
//      */
//     void setResourceProvider(XmlThemeResourceProvider resourceProvider);
// }


// Path: mapsforge-samples-android/src/main/java/org/mapsforge/samples/android/StyleMenuMapViewer.java
import android.content.SharedPreferences;
import android.util.Log;
import org.mapsforge.map.android.rendertheme.AssetsRenderTheme;
import org.mapsforge.map.android.util.AndroidUtil;
import org.mapsforge.map.layer.cache.TileCache;
import org.mapsforge.map.rendertheme.XmlRenderTheme;
import org.mapsforge.map.rendertheme.XmlRenderThemeMenuCallback;
import org.mapsforge.map.rendertheme.XmlRenderThemeStyleLayer;
import org.mapsforge.map.rendertheme.XmlRenderThemeStyleMenu;
import java.util.Set;

            Log.w(SamplesApplication.TAG, "Invalid style " + id);
            return null;
        }
        Set<String> result = baseLayer.getCategories();

        // add the categories from overlays that are enabled
        for (XmlRenderThemeStyleLayer overlay : baseLayer.getOverlays()) {
            if (this.sharedPreferences.getBoolean(overlay.getId(), overlay.isEnabled())) {
                result.addAll(overlay.getCategories());
            }
        }

        return result;
    }

    protected String getRenderThemeFile() {
        return "mapsforge/stylemenu.xml";
    }

    @Override
    public void onSharedPreferenceChanged(SharedPreferences preferences, String key) {
        super.onSharedPreferenceChanged(preferences, key);
        // difficult to know which render theme options have changed since we
        // do not know all the keys, so we just purge the caches and redraw
        // the map whenever there is a change in the settings.
        // TODO: for real applications it is essential to know when the style menu has
        // changed. It would be good to find a way of identifying when a key is
        // for the style menu.
        Log.i(SamplesApplication.TAG, "Purging tile caches");

        for (TileCache tileCache : tileCaches) {