Fix rendering file extension and remove import xml file dialog
This commit is contained in:
parent
f924e7327b
commit
ddf505025e
10 changed files with 77 additions and 107 deletions
|
@ -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$
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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() {
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -631,6 +631,22 @@ public abstract class OsmandPlugin {
|
|||
return null;
|
||||
}
|
||||
|
||||
public static List<String> getDisabledRendererNames() {
|
||||
List<String> l = new ArrayList<String>();
|
||||
for (OsmandPlugin plugin : getNotEnabledPlugins()) {
|
||||
l.addAll(plugin.getRendererNames());
|
||||
}
|
||||
return l;
|
||||
}
|
||||
|
||||
public static List<String> getDisabledRouterNames() {
|
||||
List<String> l = new ArrayList<String>();
|
||||
for (OsmandPlugin plugin : getNotEnabledPlugins()) {
|
||||
l.addAll(plugin.getRouterNames());
|
||||
}
|
||||
return l;
|
||||
}
|
||||
|
||||
public static List<String> onIndexingFiles(IProgress progress) {
|
||||
List<String> l = new ArrayList<String>();
|
||||
for (OsmandPlugin plugin : getEnabledPlugins()) {
|
||||
|
|
|
@ -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<String, String> renderers = getMyApplication().getRendererRegistry().getRenderers();
|
||||
List<String> disabledRendererNames = OsmandPlugin.getDisabledRendererNames();
|
||||
|
||||
List<String> names = new ArrayList<>(getMyApplication().getRendererRegistry().getRendererNames());
|
||||
for (OsmandPlugin plugin : OsmandPlugin.getNotEnabledPlugins()) {
|
||||
for (String name : plugin.getRendererNames()) {
|
||||
names.remove(name);
|
||||
if (!Algorithms.isEmpty(disabledRendererNames)) {
|
||||
Iterator<Map.Entry<String, String>> iterator = renderers.entrySet().iterator();
|
||||
while (iterator.hasNext()) {
|
||||
String rendererVal = iterator.next().getValue();
|
||||
String rendererFileName = Algorithms.getFileWithoutDirs(rendererVal);
|
||||
if (disabledRendererNames.contains(rendererFileName)) {
|
||||
iterator.remove();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
List<String> names = new ArrayList<>(renderers.keySet());
|
||||
for (String name : names) {
|
||||
String translation = RendererRegistry.getTranslatedRendererName(context, name);
|
||||
if (translation == null) {
|
||||
|
|
|
@ -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<String> singleChoiceAdapter = new ArrayAdapter<String>(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<Void, Void, String> renderingImportTask = new AsyncTask<Void, Void, String>() {
|
||||
|
@ -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));
|
||||
}
|
||||
|
|
|
@ -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<String> {
|
||||
|
||||
|
@ -157,15 +159,22 @@ public class MapStyleAction extends SwitchableAction<String> {
|
|||
AlertDialog.Builder bld = new AlertDialog.Builder(themedContext);
|
||||
bld.setTitle(R.string.renderers);
|
||||
|
||||
final List<String> visibleNamesList = new ArrayList<>();
|
||||
final ArrayList<String> items = new ArrayList<>(app.getRendererRegistry().getRendererNames());
|
||||
Map<String, String> renderers = app.getRendererRegistry().getRenderers();
|
||||
List<String> disabledRendererNames = OsmandPlugin.getDisabledRendererNames();
|
||||
|
||||
for (OsmandPlugin plugin : OsmandPlugin.getNotEnabledPlugins()) {
|
||||
for (String name : plugin.getRendererNames()) {
|
||||
items.remove(name);
|
||||
if (!Algorithms.isEmpty(disabledRendererNames)) {
|
||||
Iterator<Map.Entry<String, String>> iterator = renderers.entrySet().iterator();
|
||||
while (iterator.hasNext()) {
|
||||
String rendererVal = iterator.next().getValue();
|
||||
String rendererFileName = Algorithms.getFileWithoutDirs(rendererVal);
|
||||
if (disabledRendererNames.contains(rendererFileName)) {
|
||||
iterator.remove();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
List<String> visibleNamesList = new ArrayList<>();
|
||||
final List<String> items = new ArrayList<>(renderers.keySet());
|
||||
for (String item : items) {
|
||||
String translation = RendererRegistry.getTranslatedRendererName(activity, item);
|
||||
visibleNamesList.add(translation != null ? translation
|
||||
|
|
|
@ -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<String> getRendererNames(){
|
||||
LinkedHashSet<String> names = new LinkedHashSet<String>();
|
||||
names.add(DEFAULT_RENDER);
|
||||
names.addAll(internalRenderers.keySet());
|
||||
names.addAll(externalRenderers.keySet());
|
||||
return names;
|
||||
@NonNull
|
||||
public Map<String, String> getRenderers() {
|
||||
Map<String, String> renderers = new LinkedHashMap<String, String>();
|
||||
renderers.put(DEFAULT_RENDER, DEFAULT_RENDER_FILE_PATH);
|
||||
renderers.putAll(internalRenderers);
|
||||
|
||||
for (Map.Entry<String, File> entry : externalRenderers.entrySet()) {
|
||||
renderers.put(entry.getKey(), entry.getValue().getName());
|
||||
}
|
||||
return renderers;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
|
|
|
@ -222,11 +222,7 @@ public class NavigationFragment extends BaseSettingsFragment {
|
|||
false, null));
|
||||
}
|
||||
|
||||
List<String> disabledRouterNames = new ArrayList<>();
|
||||
for (OsmandPlugin plugin : OsmandPlugin.getNotEnabledPlugins()) {
|
||||
disabledRouterNames.addAll(plugin.getRouterNames());
|
||||
}
|
||||
|
||||
List<String> disabledRouterNames = OsmandPlugin.getDisabledRouterNames();
|
||||
for (RoutingConfiguration.Builder builder : context.getAllRoutingConfigs()) {
|
||||
collectRoutingProfilesFromConfig(context, builder, profilesObjects, disabledRouterNames);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue