diff --git a/OsmAnd/src/net/osmand/plus/AppInitializer.java b/OsmAnd/src/net/osmand/plus/AppInitializer.java index 8c84c0d85d..630296671d 100644 --- a/OsmAnd/src/net/osmand/plus/AppInitializer.java +++ b/OsmAnd/src/net/osmand/plus/AppInitializer.java @@ -13,6 +13,7 @@ import android.content.res.Configuration; import android.content.res.Resources; import android.os.Build; import android.support.v7.app.AlertDialog; + import net.osmand.IProgress; import net.osmand.IndexConstants; import net.osmand.PlatformUtil; @@ -69,6 +70,7 @@ import java.util.Locale; import java.util.Random; import btools.routingapp.BRouterServiceConnection; + import static net.osmand.plus.liveupdates.LiveUpdatesHelper.getPendingIntent; import static net.osmand.plus.liveupdates.LiveUpdatesHelper.preferenceLastCheck; import static net.osmand.plus.liveupdates.LiveUpdatesHelper.preferenceLiveUpdatesOn; @@ -84,6 +86,8 @@ public class AppInitializer implements IProgress { public static final int VERSION_2_2 = 22; // 23 - 2.3 public static final int VERSION_2_3 = 23; + // 32 - 3.2 + public static final int VERSION_3_2 = 32; public static final boolean TIPS_AND_TRICKS = false; @@ -164,7 +168,7 @@ public class AppInitializer implements IProgress { firstTime = true; startPrefs.edit().putBoolean(FIRST_TIME_APP_RUN, true).commit(); startPrefs.edit().putString(VERSION_INSTALLED, Version.getFullVersion(app)).commit(); - startPrefs.edit().putInt(VERSION_INSTALLED_NUMBER, VERSION_2_3).commit(); + startPrefs.edit().putInt(VERSION_INSTALLED_NUMBER, VERSION_3_2).commit(); } else if (!Version.getFullVersion(app).equals(startPrefs.getString(VERSION_INSTALLED, ""))) { prevAppVersion = startPrefs.getInt(VERSION_INSTALLED_NUMBER, 0); if(prevAppVersion < VERSION_2_2) { @@ -175,6 +179,9 @@ public class AppInitializer implements IProgress { } if(prevAppVersion < VERSION_2_3) { startPrefs.edit().putInt(VERSION_INSTALLED_NUMBER, VERSION_2_3).commit(); + } else if (prevAppVersion < VERSION_3_2) { + app.getResourceManager().copyMissingJSAssets(); + startPrefs.edit().putInt(VERSION_INSTALLED_NUMBER, VERSION_3_2).commit(); } startPrefs.edit().putString(VERSION_INSTALLED, Version.getFullVersion(app)).commit(); appVersionChanged = true; diff --git a/OsmAnd/src/net/osmand/plus/development/SettingsDevelopmentActivity.java b/OsmAnd/src/net/osmand/plus/development/SettingsDevelopmentActivity.java index 70665ad117..6b18844ad7 100644 --- a/OsmAnd/src/net/osmand/plus/development/SettingsDevelopmentActivity.java +++ b/OsmAnd/src/net/osmand/plus/development/SettingsDevelopmentActivity.java @@ -67,6 +67,9 @@ public class SettingsDevelopmentActivity extends SettingsBaseActivity { useJSVoiceGuidanceListener = new StateChangedListener() { @Override public void stateChanged(Boolean change) { + if (change) { + getMyApplication().getResourceManager().copyMissingJSAssets(); + } getMyApplication().getDownloadThread().runReloadIndexFilesSilent(); } }; diff --git a/OsmAnd/src/net/osmand/plus/development/TestVoiceActivity.java b/OsmAnd/src/net/osmand/plus/development/TestVoiceActivity.java index fd5951b010..45e2bc42ef 100644 --- a/OsmAnd/src/net/osmand/plus/development/TestVoiceActivity.java +++ b/OsmAnd/src/net/osmand/plus/development/TestVoiceActivity.java @@ -251,7 +251,7 @@ public class TestVoiceActivity extends OsmandActionBarActivity { addButton(ll, "Roundabouts: prepareTurn, makeTurnIn, turn:", builder(p)); addButton(ll, "\u25BA (5.1) After 1250m enter a roundabout", !isJS ? builder(p).prepareRoundAbout(1250, 3, street(p,"", "I 15", "Los Angeles")) : jsBuilder(p).prepareRoundAbout(1250, 3, jsStreet(p,"", "I 15", "Los Angeles"))); - addButton(ll, "\u25BA (5.2) In 450m enter the roundabout and take the 1st exit onto 'I 15' toward 'Los Angeles'", isJS ? builder(p).roundAbout(450, 0, 1, street(p,"", "I 15", "Los Angeles")) : + addButton(ll, "\u25BA (5.2) In 450m enter the roundabout and take the 1st exit onto 'I 15' toward 'Los Angeles'", !isJS ? builder(p).roundAbout(450, 0, 1, street(p,"", "I 15", "Los Angeles")) : jsBuilder(p).roundAbout(450, 0, 1, jsStreet(p,"", "I 15", "Los Angeles"))); addButton(ll, "\u25BA (5.3) Roundabout: Take the 2nd exit onto 'Highway 60'", !isJS ? builder(p).roundAbout(0, 2, street(p, "Highway 60")) : jsBuilder(p).roundAbout(0, 2, jsStreet(p, "Highway 60"))); diff --git a/OsmAnd/src/net/osmand/plus/download/DownloadOsmandIndexesHelper.java b/OsmAnd/src/net/osmand/plus/download/DownloadOsmandIndexesHelper.java index 2927a3f579..b90c28631a 100644 --- a/OsmAnd/src/net/osmand/plus/download/DownloadOsmandIndexesHelper.java +++ b/OsmAnd/src/net/osmand/plus/download/DownloadOsmandIndexesHelper.java @@ -124,7 +124,7 @@ public class DownloadOsmandIndexesHelper { return result; } - private static Map assetMapping(AssetManager assetManager) throws XmlPullParserException, IOException { + public static Map assetMapping(AssetManager assetManager) throws XmlPullParserException, IOException { XmlPullParser xmlParser = XmlPullParserFactory.newInstance().newPullParser(); InputStream isBundledAssetsXml = assetManager.open("bundled_assets.xml"); xmlParser.setInput(isBundledAssetsXml, "UTF-8"); @@ -141,7 +141,7 @@ public class DownloadOsmandIndexesHelper { return assets; } - private static void listVoiceAssets(IndexFileList result, AssetManager amanager, PackageManager pm, + private static void listVoiceAssets(IndexFileList result, AssetManager amanager, PackageManager pm, OsmandSettings settings) { try { String ext = DownloadActivityType.addVersionToExt(IndexConstants.TTSVOICE_INDEX_EXT_ZIP, IndexConstants.TTSVOICE_VERSION); diff --git a/OsmAnd/src/net/osmand/plus/resources/ResourceManager.java b/OsmAnd/src/net/osmand/plus/resources/ResourceManager.java index 04bb769fcb..a5b73a46c7 100644 --- a/OsmAnd/src/net/osmand/plus/resources/ResourceManager.java +++ b/OsmAnd/src/net/osmand/plus/resources/ResourceManager.java @@ -68,6 +68,8 @@ import java.util.List; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; +import static net.osmand.plus.download.DownloadOsmandIndexesHelper.assetMapping; + /** * Resource manager is responsible to work with all resources * that could consume memory (especially with file resources). @@ -418,6 +420,25 @@ public class ResourceManager { } return warnings; } + + public void copyMissingJSAssets() { + try { + Map mapping = assetMapping(context.getAssets()); + File appPath = context.getAppPath(null); + if (appPath.canWrite()) { + for (Map.Entry entry : mapping.entrySet()) { + File jsFile = new File(appPath, entry.getValue()); + if (jsFile.getParentFile().exists() && !jsFile.exists()) { + ResourceManager.copyAssets(context.getAssets(), entry.getKey(), jsFile); + } + } + } + } catch (XmlPullParserException e) { + log.error("Error while loading tts files from assets", e); + } catch (IOException e) { + log.error("Error while loading tts files from assets", e); + } + } public List checkAssets(IProgress progress, boolean forceUpdate) { String fv = Version.getFullVersion(context);