Merge pull request #5816 from osmandapp/js_voice_routing
Added automatic js tts download for the exsisting tts voices
This commit is contained in:
commit
83fe86470c
5 changed files with 35 additions and 4 deletions
|
@ -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;
|
||||
|
|
|
@ -67,6 +67,9 @@ public class SettingsDevelopmentActivity extends SettingsBaseActivity {
|
|||
useJSVoiceGuidanceListener = new StateChangedListener<Boolean>() {
|
||||
@Override
|
||||
public void stateChanged(Boolean change) {
|
||||
if (change) {
|
||||
getMyApplication().getResourceManager().copyMissingJSAssets();
|
||||
}
|
||||
getMyApplication().getDownloadThread().runReloadIndexFilesSilent();
|
||||
}
|
||||
};
|
||||
|
|
|
@ -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")));
|
||||
|
|
|
@ -124,7 +124,7 @@ public class DownloadOsmandIndexesHelper {
|
|||
return result;
|
||||
}
|
||||
|
||||
private static Map<String, String> assetMapping(AssetManager assetManager) throws XmlPullParserException, IOException {
|
||||
public static Map<String, String> assetMapping(AssetManager assetManager) throws XmlPullParserException, IOException {
|
||||
XmlPullParser xmlParser = XmlPullParserFactory.newInstance().newPullParser();
|
||||
InputStream isBundledAssetsXml = assetManager.open("bundled_assets.xml");
|
||||
xmlParser.setInput(isBundledAssetsXml, "UTF-8");
|
||||
|
|
|
@ -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).
|
||||
|
@ -419,6 +421,25 @@ public class ResourceManager {
|
|||
return warnings;
|
||||
}
|
||||
|
||||
public void copyMissingJSAssets() {
|
||||
try {
|
||||
Map<String, String> mapping = assetMapping(context.getAssets());
|
||||
File appPath = context.getAppPath(null);
|
||||
if (appPath.canWrite()) {
|
||||
for (Map.Entry<String,String> 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<String> checkAssets(IProgress progress, boolean forceUpdate) {
|
||||
String fv = Version.getFullVersion(context);
|
||||
if (!fv.equalsIgnoreCase(context.getSettings().PREVIOUS_INSTALLED_VERSION.get()) || forceUpdate) {
|
||||
|
|
Loading…
Reference in a new issue