diff --git a/OsmAnd-java/src/main/java/net/osmand/IndexConstants.java b/OsmAnd-java/src/main/java/net/osmand/IndexConstants.java index 579d05ff82..877b95c119 100644 --- a/OsmAnd-java/src/main/java/net/osmand/IndexConstants.java +++ b/OsmAnd-java/src/main/java/net/osmand/IndexConstants.java @@ -42,7 +42,7 @@ public class IndexConstants { public static final String OSMAND_SETTINGS_FILE_EXT = ".osf"; - public static final String ROUTING_AND_RENDERING_FILE_EXT = ".xml"; + public static final String ROUTING_FILE_EXT = ".xml"; public static final String RENDERER_INDEX_EXT = ".render.xml"; //$NON-NLS-1$ diff --git a/OsmAnd/src/net/osmand/plus/AppInitializer.java b/OsmAnd/src/net/osmand/plus/AppInitializer.java index ca4f35aeab..2d71a8827a 100644 --- a/OsmAnd/src/net/osmand/plus/AppInitializer.java +++ b/OsmAnd/src/net/osmand/plus/AppInitializer.java @@ -618,7 +618,7 @@ public class AppInitializer implements IProgress { File[] fl = routingFolder.listFiles(); if (fl != null && fl.length > 0) { for (File f : fl) { - if (f.isFile() && f.getName().endsWith(IndexConstants.ROUTING_AND_RENDERING_FILE_EXT) && f.canRead()) { + if (f.isFile() && f.getName().endsWith(IndexConstants.ROUTING_FILE_EXT) && f.canRead()) { try { String fileName = f.getName(); RoutingConfiguration.Builder builder = new RoutingConfiguration.Builder(defaultAttributes); diff --git a/OsmAnd/src/net/osmand/plus/CustomOsmandPlugin.java b/OsmAnd/src/net/osmand/plus/CustomOsmandPlugin.java index 9dc6cbc9dc..271263a212 100644 --- a/OsmAnd/src/net/osmand/plus/CustomOsmandPlugin.java +++ b/OsmAnd/src/net/osmand/plus/CustomOsmandPlugin.java @@ -24,7 +24,6 @@ import net.osmand.plus.helpers.AvoidSpecificRoads; import net.osmand.plus.poi.PoiUIFilter; import net.osmand.plus.quickaction.QuickAction; import net.osmand.plus.quickaction.QuickActionRegistry; -import net.osmand.plus.render.RendererRegistry; import net.osmand.util.Algorithms; import org.apache.commons.logging.Log; @@ -356,12 +355,13 @@ public class CustomOsmandPlugin extends OsmandPlugin { } public void addRouter(String fileName) { - routerNames.add(fileName); + String routerName = Algorithms.getFileWithoutDirs(fileName); + routerNames.add(routerName); } public void addRenderer(String fileName) { - String renderer = RendererRegistry.formatRendererFileName(fileName); - rendererNames.add(renderer.replace('_', ' ').replace('-', ' ')); + String rendererName = Algorithms.getFileWithoutDirs(fileName); + rendererNames.add(rendererName); } public void loadResources() { diff --git a/OsmAnd/src/net/osmand/plus/OsmandApplication.java b/OsmAnd/src/net/osmand/plus/OsmandApplication.java index fef0fdb7cb..c47476edd5 100644 --- a/OsmAnd/src/net/osmand/plus/OsmandApplication.java +++ b/OsmAnd/src/net/osmand/plus/OsmandApplication.java @@ -91,7 +91,7 @@ import java.util.concurrent.ConcurrentHashMap; import btools.routingapp.BRouterServiceConnection; import btools.routingapp.IBRouterService; -import static net.osmand.IndexConstants.ROUTING_AND_RENDERING_FILE_EXT; +import static net.osmand.IndexConstants.ROUTING_FILE_EXT; public class OsmandApplication extends MultiDexApplication { public static final String EXCEPTION_PATH = "exception.log"; @@ -844,9 +844,9 @@ public class OsmandApplication extends MultiDexApplication { RoutingConfiguration.Builder builder = null; String routingProfileKey = mode.getRoutingProfile(); if (!Algorithms.isEmpty(routingProfileKey)) { - int index = routingProfileKey.indexOf(ROUTING_AND_RENDERING_FILE_EXT); + int index = routingProfileKey.indexOf(ROUTING_FILE_EXT); if (index != -1) { - String configKey = routingProfileKey.substring(0, index + ROUTING_AND_RENDERING_FILE_EXT.length()); + String configKey = routingProfileKey.substring(0, index + ROUTING_FILE_EXT.length()); builder = customRoutingConfigs.get(configKey); } } diff --git a/OsmAnd/src/net/osmand/plus/OsmandPlugin.java b/OsmAnd/src/net/osmand/plus/OsmandPlugin.java index d3df587776..67858a269c 100644 --- a/OsmAnd/src/net/osmand/plus/OsmandPlugin.java +++ b/OsmAnd/src/net/osmand/plus/OsmandPlugin.java @@ -631,6 +631,22 @@ public abstract class OsmandPlugin { return null; } + public static List getDisabledRendererNames() { + List l = new ArrayList(); + for (OsmandPlugin plugin : getNotEnabledPlugins()) { + l.addAll(plugin.getRendererNames()); + } + return l; + } + + public static List getDisabledRouterNames() { + List l = new ArrayList(); + for (OsmandPlugin plugin : getNotEnabledPlugins()) { + l.addAll(plugin.getRouterNames()); + } + return l; + } + public static List onIndexingFiles(IProgress progress) { List l = new ArrayList(); for (OsmandPlugin plugin : getEnabledPlugins()) { diff --git a/OsmAnd/src/net/osmand/plus/dialogs/SelectMapStyleBottomSheetDialogFragment.java b/OsmAnd/src/net/osmand/plus/dialogs/SelectMapStyleBottomSheetDialogFragment.java index e15c8d169f..93d05d86d7 100644 --- a/OsmAnd/src/net/osmand/plus/dialogs/SelectMapStyleBottomSheetDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/dialogs/SelectMapStyleBottomSheetDialogFragment.java @@ -32,9 +32,11 @@ import net.osmand.plus.base.bottomsheetmenu.simpleitems.TitleItem; import net.osmand.plus.render.RendererRegistry; import net.osmand.plus.views.OsmandMapTileView; import net.osmand.render.RenderingRulesStorage; +import net.osmand.util.Algorithms; import java.util.ArrayList; import java.util.Comparator; +import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.TreeMap; @@ -175,13 +177,21 @@ public class SelectMapStyleBottomSheetDialogFragment extends MenuBottomSheetDial return collator.compare(string1, string2); } }); + Map renderers = getMyApplication().getRendererRegistry().getRenderers(); + List disabledRendererNames = OsmandPlugin.getDisabledRendererNames(); - List names = new ArrayList<>(getMyApplication().getRendererRegistry().getRendererNames()); - for (OsmandPlugin plugin : OsmandPlugin.getNotEnabledPlugins()) { - for (String name : plugin.getRendererNames()) { - names.remove(name); + if (!Algorithms.isEmpty(disabledRendererNames)) { + Iterator> iterator = renderers.entrySet().iterator(); + while (iterator.hasNext()) { + String rendererVal = iterator.next().getValue(); + String rendererFileName = Algorithms.getFileWithoutDirs(rendererVal); + if (disabledRendererNames.contains(rendererFileName)) { + iterator.remove(); + } } } + + List names = new ArrayList<>(renderers.keySet()); for (String name : names) { String translation = RendererRegistry.getTranslatedRendererName(context, name); if (translation == null) { diff --git a/OsmAnd/src/net/osmand/plus/helpers/ImportHelper.java b/OsmAnd/src/net/osmand/plus/helpers/ImportHelper.java index b75d8e92ba..83e394cf0d 100644 --- a/OsmAnd/src/net/osmand/plus/helpers/ImportHelper.java +++ b/OsmAnd/src/net/osmand/plus/helpers/ImportHelper.java @@ -5,7 +5,6 @@ import android.app.ProgressDialog; import android.content.DialogInterface; import android.content.Intent; import android.database.Cursor; -import android.graphics.drawable.Drawable; import android.net.Uri; import android.os.AsyncTask; import android.os.Build; @@ -14,13 +13,7 @@ import android.os.ParcelFileDescriptor; import android.provider.OpenableColumns; import android.provider.Settings; import android.text.style.ForegroundColorSpan; -import android.util.TypedValue; -import android.view.LayoutInflater; import android.view.View; -import android.view.ViewGroup; -import android.widget.ArrayAdapter; -import android.widget.ImageView; -import android.widget.TextView; import android.widget.Toast; import androidx.annotation.NonNull; @@ -53,7 +46,6 @@ import net.osmand.plus.SettingsHelper.PluginSettingsItem; import net.osmand.plus.SettingsHelper.SettingsCollectListener; import net.osmand.plus.SettingsHelper.SettingsImportListener; import net.osmand.plus.SettingsHelper.SettingsItem; -import net.osmand.plus.UiUtilities; import net.osmand.plus.activities.ActivityResultListener; import net.osmand.plus.activities.MapActivity; import net.osmand.plus.activities.TrackActivity; @@ -89,7 +81,8 @@ import java.util.zip.ZipInputStream; import static android.app.Activity.RESULT_OK; import static net.osmand.IndexConstants.OSMAND_SETTINGS_FILE_EXT; -import static net.osmand.IndexConstants.ROUTING_AND_RENDERING_FILE_EXT; +import static net.osmand.IndexConstants.RENDERER_INDEX_EXT; +import static net.osmand.IndexConstants.ROUTING_FILE_EXT; import static net.osmand.plus.AppInitializer.loadRoutingFiles; import static net.osmand.plus.myplaces.FavoritesActivity.FAV_TAB; import static net.osmand.plus.myplaces.FavoritesActivity.GPX_TAB; @@ -111,8 +104,8 @@ public class ImportHelper { public final static int IMPORT_FILE_REQUEST = 1006; public enum ImportType { - SETTINGS(IndexConstants.OSMAND_SETTINGS_FILE_EXT), - ROUTING(ROUTING_AND_RENDERING_FILE_EXT); + SETTINGS(OSMAND_SETTINGS_FILE_EXT), + ROUTING(ROUTING_FILE_EXT); ImportType(String extension) { this.extension = extension; @@ -197,8 +190,10 @@ public class ImportHelper { handleSqliteTileImport(intentUri, fileName); } else if (fileName != null && fileName.endsWith(OSMAND_SETTINGS_FILE_EXT)) { handleOsmAndSettingsImport(intentUri, fileName, extras, null); - } else if (fileName != null && fileName.endsWith(ROUTING_AND_RENDERING_FILE_EXT)) { - handleXmlFileImport(intentUri, fileName); + } else if (fileName != null && fileName.endsWith(RENDERER_INDEX_EXT)) { + handleRenderingFileImport(intentUri, fileName); + } else if (fileName != null && fileName.endsWith(ROUTING_FILE_EXT)) { + handleRoutingFileImport(intentUri, fileName, null); } else { handleFavouritesImport(intentUri, fileName, saveFile, useImportDir, false); } @@ -869,66 +864,6 @@ public class ImportHelper { }); } - private void handleXmlFileImport(final Uri intentUri, final String fileName) { - AlertDialog.Builder builder = new AlertDialog.Builder(activity); - - final boolean nightMode; - if (activity instanceof MapActivity) { - nightMode = app.getDaynightHelper().isNightModeForMapControls(); - } else { - nightMode = !app.getSettings().isLightContent(); - } - final LayoutInflater themedInflater = UiUtilities.getInflater(activity, nightMode); - - View dialogTitle = themedInflater.inflate(R.layout.bottom_sheet_item_simple, null); - dialogTitle.findViewById(R.id.icon).setVisibility(View.GONE); - TextView tvTitle = dialogTitle.findViewById(R.id.title); - tvTitle.setText(R.string.import_from_file); - int textSize = (int) app.getResources().getDimension(R.dimen.dialog_header_text_size); - tvTitle.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize); - builder.setCustomTitle(dialogTitle); - - String[] strings = new String[2]; - strings[0] = app.getString(R.string.import_routing_file); - strings[1] = app.getString(R.string.import_rendering_file); - - final int[] icons = new int[2]; - icons[0] = R.drawable.ic_action_gdirections_dark; - icons[1] = R.drawable.ic_map; - - ArrayAdapter singleChoiceAdapter = new ArrayAdapter(activity, R.layout.bottom_sheet_item_simple, R.id.title, strings) { - @NonNull - @Override - public View getView(int position, View convertView, @NonNull ViewGroup parent) { - View v = convertView; - if (v == null) { - v = themedInflater.inflate(R.layout.bottom_sheet_item_simple, parent, false); - } - int activeColor = nightMode ? R.color.active_color_primary_dark : R.color.active_color_primary_light; - Drawable icon = app.getUIUtilities().getIcon(icons[position], activeColor); - ((TextView) v.findViewById(R.id.title)).setText(getItem(position)); - ((ImageView) v.findViewById(R.id.icon)).setImageDrawable(icon); - return v; - } - }; - - builder.setAdapter(singleChoiceAdapter, new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { - if (which == 0) { - handleRoutingFileImport(intentUri, fileName, null); - } else { - handleRenderingFileImport(intentUri, fileName); - } - } - }); - - builder.setNegativeButton(R.string.shared_string_cancel, null); - AlertDialog dialog = builder.create(); - dialog.getListView().setDividerHeight(0); - dialog.show(); - } - @SuppressLint("StaticFieldLeak") private void handleRenderingFileImport(final Uri intentUri, final String fileName) { final AsyncTask renderingImportTask = new AsyncTask() { @@ -964,6 +899,7 @@ public class ImportHelper { File file = new File(renderingDir, mFileName); if (error == null && file.exists()) { app.getRendererRegistry().updateExternalRenderers(); + app.showShortToastMessage(app.getString(R.string.file_imported_successfully, mFileName)); } else { app.showShortToastMessage(app.getString(R.string.file_import_error, mFileName, error)); } diff --git a/OsmAnd/src/net/osmand/plus/quickaction/actions/MapStyleAction.java b/OsmAnd/src/net/osmand/plus/quickaction/actions/MapStyleAction.java index c2a2197563..aff229fdc4 100644 --- a/OsmAnd/src/net/osmand/plus/quickaction/actions/MapStyleAction.java +++ b/OsmAnd/src/net/osmand/plus/quickaction/actions/MapStyleAction.java @@ -27,7 +27,9 @@ import net.osmand.util.Algorithms; import java.util.ArrayList; import java.util.Collections; +import java.util.Iterator; import java.util.List; +import java.util.Map; public class MapStyleAction extends SwitchableAction { @@ -157,15 +159,22 @@ public class MapStyleAction extends SwitchableAction { AlertDialog.Builder bld = new AlertDialog.Builder(themedContext); bld.setTitle(R.string.renderers); - final List visibleNamesList = new ArrayList<>(); - final ArrayList items = new ArrayList<>(app.getRendererRegistry().getRendererNames()); + Map renderers = app.getRendererRegistry().getRenderers(); + List disabledRendererNames = OsmandPlugin.getDisabledRendererNames(); - for (OsmandPlugin plugin : OsmandPlugin.getNotEnabledPlugins()) { - for (String name : plugin.getRendererNames()) { - items.remove(name); + if (!Algorithms.isEmpty(disabledRendererNames)) { + Iterator> iterator = renderers.entrySet().iterator(); + while (iterator.hasNext()) { + String rendererVal = iterator.next().getValue(); + String rendererFileName = Algorithms.getFileWithoutDirs(rendererVal); + if (disabledRendererNames.contains(rendererFileName)) { + iterator.remove(); + } } } + List visibleNamesList = new ArrayList<>(); + final List items = new ArrayList<>(renderers.keySet()); for (String item : items) { String translation = RendererRegistry.getTranslatedRendererName(activity, item); visibleNamesList.add(translation != null ? translation diff --git a/OsmAnd/src/net/osmand/plus/render/RendererRegistry.java b/OsmAnd/src/net/osmand/plus/render/RendererRegistry.java index 9fc9f1b994..17dc572bc4 100644 --- a/OsmAnd/src/net/osmand/plus/render/RendererRegistry.java +++ b/OsmAnd/src/net/osmand/plus/render/RendererRegistry.java @@ -25,10 +25,8 @@ import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; -import java.util.Collection; import java.util.Iterator; import java.util.LinkedHashMap; -import java.util.LinkedHashSet; import java.util.Map; import java.util.Map.Entry; @@ -259,7 +257,7 @@ public class RendererRegistry { File[] lf = file.listFiles(); if (lf != null) { for (File f : lf) { - if (f != null && f.getName().endsWith(IndexConstants.ROUTING_AND_RENDERING_FILE_EXT)) { + if (f != null && f.getName().endsWith(IndexConstants.RENDERER_INDEX_EXT)) { if (!internalRenderers.containsValue(f.getName())) { String name = formatRendererFileName(f.getName()); externalRenderers.put(name, f); @@ -272,16 +270,21 @@ public class RendererRegistry { } public static String formatRendererFileName(String fileName) { - String name = fileName.substring(0, fileName.length() - IndexConstants.ROUTING_AND_RENDERING_FILE_EXT.length()); - return name.replace('_', ' ').replace('-', ' '); + String name = fileName.substring(0, fileName.length() - IndexConstants.RENDERER_INDEX_EXT.length()); + name = name.replace('_', ' ').replace('-', ' '); + return Algorithms.capitalizeFirstLetter(name); } - public Collection getRendererNames(){ - LinkedHashSet names = new LinkedHashSet(); - names.add(DEFAULT_RENDER); - names.addAll(internalRenderers.keySet()); - names.addAll(externalRenderers.keySet()); - return names; + @NonNull + public Map getRenderers() { + Map renderers = new LinkedHashMap(); + renderers.put(DEFAULT_RENDER, DEFAULT_RENDER_FILE_PATH); + renderers.putAll(internalRenderers); + + for (Map.Entry entry : externalRenderers.entrySet()) { + renderers.put(entry.getKey(), entry.getValue().getName()); + } + return renderers; } @Nullable diff --git a/OsmAnd/src/net/osmand/plus/settings/NavigationFragment.java b/OsmAnd/src/net/osmand/plus/settings/NavigationFragment.java index 07b2206a05..4ea473d948 100644 --- a/OsmAnd/src/net/osmand/plus/settings/NavigationFragment.java +++ b/OsmAnd/src/net/osmand/plus/settings/NavigationFragment.java @@ -222,11 +222,7 @@ public class NavigationFragment extends BaseSettingsFragment { false, null)); } - List disabledRouterNames = new ArrayList<>(); - for (OsmandPlugin plugin : OsmandPlugin.getNotEnabledPlugins()) { - disabledRouterNames.addAll(plugin.getRouterNames()); - } - + List disabledRouterNames = OsmandPlugin.getDisabledRouterNames(); for (RoutingConfiguration.Builder builder : context.getAllRoutingConfigs()) { collectRoutingProfilesFromConfig(context, builder, profilesObjects, disabledRouterNames); }