diff --git a/OsmAnd-java/src/main/java/net/osmand/IndexConstants.java b/OsmAnd-java/src/main/java/net/osmand/IndexConstants.java
index 26a4e252ed..78216f3616 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_FILE_EXT = ".xml";
+ public static final String ROUTING_AND_RENDERING_FILE_EXT = ".xml";
public static final String RENDERER_INDEX_EXT = ".render.xml"; //$NON-NLS-1$
diff --git a/OsmAnd-java/src/main/java/net/osmand/router/RoutingConfiguration.java b/OsmAnd-java/src/main/java/net/osmand/router/RoutingConfiguration.java
index fb3432d4aa..14f26123a5 100644
--- a/OsmAnd-java/src/main/java/net/osmand/router/RoutingConfiguration.java
+++ b/OsmAnd-java/src/main/java/net/osmand/router/RoutingConfiguration.java
@@ -236,9 +236,9 @@ public class RoutingConfiguration {
String id = parser.getAttributeValue("", "id");
String type = parser.getAttributeValue("", "type");
boolean defaultValue = Boolean.parseBoolean(parser.getAttributeValue("", "default"));
- if (type.equalsIgnoreCase("boolean")) {
+ if ("boolean".equalsIgnoreCase(type)) {
currentRouter.registerBooleanParameter(id, Algorithms.isEmpty(group) ? null : group, name, description, defaultValue);
- } else if(type.equalsIgnoreCase("numeric")) {
+ } else if ("numeric".equalsIgnoreCase(type)) {
String values = parser.getAttributeValue("", "values");
String valueDescriptions = parser.getAttributeValue("", "valueDescriptions");
String[] strValues = values.split(",");
@@ -292,7 +292,7 @@ public class RoutingConfiguration {
for (int i = 0; i < stack.size(); i++) {
addSubclause(stack.get(i), ctx);
}
- } else if(stack.size() > 0 && stack.peek().tagName.equals("select")) {
+ } else if (stack.size() > 0 && "select".equals(stack.peek().tagName)) {
addSubclause(rr, ctx);
}
stack.push(rr);
@@ -312,11 +312,11 @@ public class RoutingConfiguration {
if (!Algorithms.isEmpty(rr.t)) {
ctx.getLastRule().registerAndTagValueCondition(rr.t, Algorithms.isEmpty(rr.v) ? null : rr.v, not);
}
- if (rr.tagName.equals("gt")) {
+ if ("gt".equals(rr.tagName)) {
ctx.getLastRule().registerGreatCondition(rr.value1, rr.value2, rr.type);
- } else if (rr.tagName.equals("le")) {
+ } else if ("le".equals(rr.tagName)) {
ctx.getLastRule().registerLessCondition(rr.value1, rr.value2, rr.type);
- } else if (rr.tagName.equals("eq")) {
+ } else if ("eq".equals(rr.tagName)) {
ctx.getLastRule().registerEqualCondition(rr.value1, rr.value2, rr.type);
}
}
diff --git a/OsmAnd/res/values/strings.xml b/OsmAnd/res/values/strings.xml
index 6984349329..f9d10b1567 100644
--- a/OsmAnd/res/values/strings.xml
+++ b/OsmAnd/res/values/strings.xml
@@ -11,6 +11,7 @@
Thx - Hardy
-->
+ Import rendering file
Custom profile
Angle: %s°
Angle
diff --git a/OsmAnd/src/net/osmand/plus/AppInitializer.java b/OsmAnd/src/net/osmand/plus/AppInitializer.java
index ad022d3051..9d609b2bb7 100644
--- a/OsmAnd/src/net/osmand/plus/AppInitializer.java
+++ b/OsmAnd/src/net/osmand/plus/AppInitializer.java
@@ -617,7 +617,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_FILE_EXT) && f.canRead()) {
+ if (f.isFile() && f.getName().endsWith(IndexConstants.ROUTING_AND_RENDERING_FILE_EXT) && f.canRead()) {
try {
String fileName = f.getName();
RoutingConfiguration.Builder builder = new RoutingConfiguration.Builder(defaultAttributes);
diff --git a/OsmAnd/src/net/osmand/plus/OsmandApplication.java b/OsmAnd/src/net/osmand/plus/OsmandApplication.java
index b71dec40ec..361f05dc7f 100644
--- a/OsmAnd/src/net/osmand/plus/OsmandApplication.java
+++ b/OsmAnd/src/net/osmand/plus/OsmandApplication.java
@@ -90,7 +90,7 @@ import java.util.concurrent.ConcurrentHashMap;
import btools.routingapp.BRouterServiceConnection;
import btools.routingapp.IBRouterService;
-import static net.osmand.IndexConstants.ROUTING_FILE_EXT;
+import static net.osmand.IndexConstants.ROUTING_AND_RENDERING_FILE_EXT;
public class OsmandApplication extends MultiDexApplication {
public static final String EXCEPTION_PATH = "exception.log";
@@ -840,9 +840,9 @@ public class OsmandApplication extends MultiDexApplication {
RoutingConfiguration.Builder builder = null;
String routingProfileKey = mode.getRoutingProfile();
if (!Algorithms.isEmpty(routingProfileKey)) {
- int index = routingProfileKey.indexOf(ROUTING_FILE_EXT);
+ int index = routingProfileKey.indexOf(ROUTING_AND_RENDERING_FILE_EXT);
if (index != -1) {
- String configKey = routingProfileKey.substring(0, index + ROUTING_FILE_EXT.length());
+ String configKey = routingProfileKey.substring(0, index + ROUTING_AND_RENDERING_FILE_EXT.length());
builder = customRoutingConfigs.get(configKey);
}
}
diff --git a/OsmAnd/src/net/osmand/plus/helpers/ImportHelper.java b/OsmAnd/src/net/osmand/plus/helpers/ImportHelper.java
index d599458d78..9cb66f91d9 100644
--- a/OsmAnd/src/net/osmand/plus/helpers/ImportHelper.java
+++ b/OsmAnd/src/net/osmand/plus/helpers/ImportHelper.java
@@ -6,6 +6,7 @@ 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;
@@ -19,7 +20,13 @@ import android.support.v4.app.FragmentManager;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
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 net.osmand.AndroidUtils;
@@ -41,6 +48,7 @@ import net.osmand.plus.OsmandPlugin;
import net.osmand.plus.R;
import net.osmand.plus.SettingsHelper;
import net.osmand.plus.SettingsHelper.SettingsImportListener;
+import net.osmand.plus.UiUtilities;
import net.osmand.plus.activities.ActivityResultListener;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.activities.TrackActivity;
@@ -76,7 +84,7 @@ 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_FILE_EXT;
+import static net.osmand.IndexConstants.ROUTING_AND_RENDERING_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;
@@ -99,7 +107,7 @@ public class ImportHelper {
public enum ImportType {
SETTINGS(IndexConstants.OSMAND_SETTINGS_FILE_EXT),
- ROUTING(ROUTING_FILE_EXT);
+ ROUTING(ROUTING_AND_RENDERING_FILE_EXT);
ImportType(String extension) {
this.extension = extension;
@@ -184,8 +192,8 @@ public class ImportHelper {
handleSqliteTileImport(intentUri, fileName);
} else if (fileName != null && fileName.endsWith(OSMAND_SETTINGS_FILE_EXT)) {
handleOsmAndSettingsImport(intentUri, fileName, extras, true, null);
- } else if (fileName != null && fileName.endsWith(ROUTING_FILE_EXT)) {
- handleRoutingFileImport(intentUri, fileName, null);
+ } else if (fileName != null && fileName.endsWith(ROUTING_AND_RENDERING_FILE_EXT)) {
+ handleXmlFileImport(intentUri, fileName);
} else {
handleFavouritesImport(intentUri, fileName, saveFile, useImportDir, false);
}
@@ -818,6 +826,123 @@ public class ImportHelper {
return !activity.isFinishing();
}
+ 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() {
+
+ String mFileName;
+ ProgressDialog progress;
+
+ @Override
+ protected void onPreExecute() {
+ progress = ProgressDialog.show(activity, app.getString(R.string.loading_smth, ""), app.getString(R.string.loading_data));
+ mFileName = fileName;
+ }
+
+ @Override
+ protected String doInBackground(Void... voids) {
+ File renderingDir = app.getAppPath(IndexConstants.RENDERERS_DIR);
+ if (!renderingDir.exists()) {
+ renderingDir.mkdirs();
+ }
+ File dest = new File(renderingDir, mFileName);
+ while (dest.exists()) {
+ mFileName = AndroidUtils.createNewFileName(mFileName);
+ dest = new File(renderingDir, mFileName);
+ }
+ return copyFile(app, dest, intentUri, true);
+ }
+
+ @Override
+ protected void onPostExecute(String error) {
+ File renderingDir = app.getAppPath(IndexConstants.RENDERERS_DIR);
+ File file = new File(renderingDir, mFileName);
+ if (error == null && file.exists()) {
+ app.getRendererRegistry().updateExternalRenderers();
+ } else {
+ app.showShortToastMessage(app.getString(R.string.file_import_error, mFileName, error));
+ }
+ if (isActivityNotDestroyed(activity)) {
+ progress.dismiss();
+ }
+ }
+ };
+ if (app.isApplicationInitializing()) {
+ app.getAppInitializer().addListener(new AppInitializer.AppInitializeListener() {
+ @Override
+ public void onProgress(AppInitializer init, AppInitializer.InitEvents event) {
+ }
+
+ @Override
+ public void onFinish(AppInitializer init) {
+ renderingImportTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
+ }
+ });
+ } else {
+ renderingImportTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
+ }
+ }
+
private void handleResult(final GPXFile result, final String name, final boolean save,
final boolean useImportDir, boolean forceImportFavourites) {
if (result != null) {
diff --git a/OsmAnd/src/net/osmand/plus/render/RendererRegistry.java b/OsmAnd/src/net/osmand/plus/render/RendererRegistry.java
index a5bfc2d7bc..ca8cb00d11 100644
--- a/OsmAnd/src/net/osmand/plus/render/RendererRegistry.java
+++ b/OsmAnd/src/net/osmand/plus/render/RendererRegistry.java
@@ -257,9 +257,9 @@ public class RendererRegistry {
File[] lf = file.listFiles();
if (lf != null) {
for (File f : lf) {
- if (f != null && f.getName().endsWith(IndexConstants.RENDERER_INDEX_EXT)) {
+ if (f != null && f.getName().endsWith(IndexConstants.ROUTING_AND_RENDERING_FILE_EXT)) {
if(!internalRenderers.containsValue(f.getName())) {
- String name = f.getName().substring(0, f.getName().length() - IndexConstants.RENDERER_INDEX_EXT.length());
+ String name = f.getName().substring(0, f.getName().length() - IndexConstants.ROUTING_AND_RENDERING_FILE_EXT.length());
externalRenderers.put(name.replace('_', ' ').replace('-', ' '), f);
}
}