diff --git a/OsmAnd-java/src/main/java/net/osmand/IndexConstants.java b/OsmAnd-java/src/main/java/net/osmand/IndexConstants.java index 0bde0dca08..9670a029f5 100644 --- a/OsmAnd-java/src/main/java/net/osmand/IndexConstants.java +++ b/OsmAnd-java/src/main/java/net/osmand/IndexConstants.java @@ -68,4 +68,5 @@ public class IndexConstants { public static final String RENDERERS_DIR = "rendering/"; //$NON-NLS-1$ public static final String ROUTING_XML_FILE= "routing.xml"; public static final String SETTINGS_DIR = "settings/"; //$NON-NLS-1$ + public static final String TEMP_DIR = "temp/"; } diff --git a/OsmAnd/src/net/osmand/aidl/IOsmAndAidlInterface.aidl b/OsmAnd/src/net/osmand/aidl/IOsmAndAidlInterface.aidl index af2423cd8b..abb28b3abe 100644 --- a/OsmAnd/src/net/osmand/aidl/IOsmAndAidlInterface.aidl +++ b/OsmAnd/src/net/osmand/aidl/IOsmAndAidlInterface.aidl @@ -179,4 +179,6 @@ interface IOsmAndAidlInterface { boolean registerForOsmandInitListener(in IOsmAndAidlCallback callback); boolean getBitmapForGpx(in CreateGpxBitmapParams file, IOsmAndAidlCallback callback); + + boolean appendDataToFile(in String filename, in byte[] data); } \ No newline at end of file diff --git a/OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java b/OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java index 8ddddd5a51..fd0fa0f23b 100644 --- a/OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java +++ b/OsmAnd/src/net/osmand/aidl/OsmandAidlApi.java @@ -1967,6 +1967,36 @@ public class OsmandAidlApi { gpxAsyncLoaderTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); } + boolean appendDataToFile(final String filename, final byte[] data) { + if (filename.isEmpty() || data == null || data.length == 0) { + return false; + } else { + File f = app.getAppPath(IndexConstants.TEMP_DIR + filename); + + try { + if (!f.exists()) { + f.getParentFile().mkdirs(); + f.createNewFile(); + } + } catch (IOException ioe) { + LOG.debug(ioe.getMessage(), ioe); + } + try { + FileOutputStream outputStream + = new FileOutputStream(IndexConstants.TEMP_DIR+filename, true); + outputStream.write(data); + } catch (IOException ioe) { + LOG.debug(ioe.getMessage(), ioe); + } + + + + + + return true; + } + } + private static class GpxAsyncLoaderTask extends AsyncTask { private final OsmandApplication app; diff --git a/OsmAnd/src/net/osmand/aidl/OsmandAidlService.java b/OsmAnd/src/net/osmand/aidl/OsmandAidlService.java index 949b589fe5..d1e6a487de 100644 --- a/OsmAnd/src/net/osmand/aidl/OsmandAidlService.java +++ b/OsmAnd/src/net/osmand/aidl/OsmandAidlService.java @@ -845,5 +845,11 @@ public class OsmandAidlService extends Service { return false; } } + + @Override + public boolean appendDataToFile(String filename, byte[] data) { + OsmandAidlApi api = getApi("appendDataToFile"); + return api != null && api.appendDataToFile(filename, data); + } }; } diff --git a/OsmAnd/src/net/osmand/plus/GPXUtilities.java b/OsmAnd/src/net/osmand/plus/GPXUtilities.java index f9bfb2a73c..40671a24a6 100644 --- a/OsmAnd/src/net/osmand/plus/GPXUtilities.java +++ b/OsmAnd/src/net/osmand/plus/GPXUtilities.java @@ -82,11 +82,11 @@ public class GPXUtilities { String clrValue = null; if (extensions != null) { clrValue = extensions.get("color"); - if (clrValue == null) { + if (clrValue == null||clrValue.isEmpty()) { clrValue = extensions.get("colour"); } - if (clrValue == null) { - clrValue = extensions.get("displaycolor"); + if (clrValue == null ||clrValue.isEmpty()) { + clrValue = extensions.get("DisplayColor"); } } if (clrValue != null && clrValue.length() > 0) { @@ -1522,6 +1522,25 @@ public class GPXUtilities { return text; } + private static Map readExtensionText(XmlPullParser parser, String key) throws XmlPullParserException, IOException { + int tok; + Map innerTagAndText = new HashMap<>(); + String innerTag = ""; + while ((tok = parser.next()) != XmlPullParser.END_DOCUMENT) { + innerTag = parser.getName(); + log.debug("tag: " + parser.getName()+ ", prefix: " + parser.getPrefix()); + if (tok == XmlPullParser.END_TAG && parser.getName().equals(key)) { + break; + } else if (tok == XmlPullParser.TEXT) { + String text = parser.getText(); + if (text!=null || !text.isEmpty() ) { + innerTagAndText.put(innerTag, text); + } + } + } + return innerTagAndText; + } + public static GPXFile loadGPXFile(Context ctx, File f) { FileInputStream fis = null; try { @@ -1567,15 +1586,24 @@ public class GPXUtilities { Object parse = parserState.peek(); String tag = parser.getName(); if (extensionReadMode && parse != null) { - String value = readText(parser, tag); - if (value != null) { - ((GPXExtensions) parse).getExtensionsToWrite().put(tag.toLowerCase(), value); - if (tag.equals("speed") && parse instanceof WptPt) { - try { - ((WptPt) parse).speed = Float.parseFloat(value); - } catch (NumberFormatException e) {} + if (tag.equals("TrackExtension")) { + Map innerTagAndText = readExtensionText(parser, tag); + for (Map.Entry entity : innerTagAndText.entrySet()) { + ((GPXExtensions) parse).getExtensionsToWrite().put(entity.getKey(), entity.getValue()); + } + + } else { + String value = readText(parser, tag); + if (value != null) { + ((GPXExtensions) parse).getExtensionsToWrite().put(tag, value); + if (tag.equals("speed") && parse instanceof WptPt) { + try { + ((WptPt) parse).speed = Float.parseFloat(value); + } catch (NumberFormatException e) {} + } } } + } else if (parse instanceof GPXExtensions && tag.equals("extensions")) { extensionReadMode = true; } else {