diff --git a/OsmAnd/src/net/osmand/plus/activities/SettingsNavigationActivity.java b/OsmAnd/src/net/osmand/plus/activities/SettingsNavigationActivity.java index 1a1302853f..79c75a4456 100644 --- a/OsmAnd/src/net/osmand/plus/activities/SettingsNavigationActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/SettingsNavigationActivity.java @@ -52,6 +52,8 @@ import java.util.List; import java.util.Map; import java.util.Set; +import static net.osmand.plus.mapcontextmenu.other.RoutePreferencesMenu.getVoiceFiles; + public class SettingsNavigationActivity extends SettingsBaseActivity { public static final String MORE_VALUE = "MORE_VALUE"; @@ -244,7 +246,7 @@ public class SettingsNavigationActivity extends SettingsBaseActivity { private void reloadVoiceListPreference(PreferenceScreen screen) { String[] entries; String[] entrieValues; - Set voiceFiles = getVoiceFiles(); + Set voiceFiles = getVoiceFiles(this); entries = new String[voiceFiles.size() + 2]; entrieValues = new String[voiceFiles.size() + 2]; int k = 0; @@ -262,34 +264,6 @@ public class SettingsNavigationActivity extends SettingsBaseActivity { registerListPreference(settings.VOICE_PROVIDER, screen, entries, entrieValues); } - private Set getVoiceFiles() { - // read available voice data - File extStorage = ((OsmandApplication) getApplication()).getAppPath(IndexConstants.VOICE_INDEX_DIR); - Set setFiles = new LinkedHashSet(); - boolean addJS = settings.USE_JS_VOICE_GUIDANCE.get(); - if (extStorage.exists()) { - for (File f : extStorage.listFiles()) { - if (f.isDirectory()) { - if (addJS && hasJavaScript(f)) { - setFiles.add(f.getName()); - } else if (!addJS) { - setFiles.add(f.getName()); - } - - } - } - } - return setFiles; - } - - private boolean hasJavaScript(File f) { - for (File file : f.listFiles()) { - if (file.getName().endsWith(IndexConstants.TTSVOICE_INDEX_EXT_JS)) { - return true; - } - } - return false; - } private void addVoicePrefs(PreferenceGroup cat) { if (!Version.isBlackberry((OsmandApplication) getApplication())) { diff --git a/OsmAnd/src/net/osmand/plus/development/TestVoiceActivity.java b/OsmAnd/src/net/osmand/plus/development/TestVoiceActivity.java index 4349c0c5a8..fd5951b010 100644 --- a/OsmAnd/src/net/osmand/plus/development/TestVoiceActivity.java +++ b/OsmAnd/src/net/osmand/plus/development/TestVoiceActivity.java @@ -40,6 +40,8 @@ import java.util.Set; import alice.tuprolog.Struct; import alice.tuprolog.Term; +import static net.osmand.plus.mapcontextmenu.other.RoutePreferencesMenu.getVoiceFiles; + /** * Test Voice activity @@ -84,41 +86,11 @@ public class TestVoiceActivity extends OsmandActionBarActivity { selectVoice(ll); } - - private Set getVoiceFiles() { - // read available voice data - File extStorage = ((OsmandApplication) getApplication()).getAppPath(IndexConstants.VOICE_INDEX_DIR); - Set setFiles = new LinkedHashSet(); - OsmandApplication app = (OsmandApplication) getApplication(); - boolean addJS = app.getSettings().USE_JS_VOICE_GUIDANCE.get(); - if (extStorage.exists()) { - for (File f : extStorage.listFiles()) { - if (f.isDirectory()) { - if (addJS && hasJavaScript(f)) { - setFiles.add(f.getName()); - } else if (!addJS) { - setFiles.add(f.getName()); - } - - } - } - } - return setFiles; - } - - private boolean hasJavaScript(File f) { - for (File file : f.listFiles()) { - if (file.getName().endsWith(IndexConstants.TTSVOICE_INDEX_EXT_JS)) { - return true; - } - } - return false; - } private void selectVoice(final LinearLayout ll) { String[] entries; final String[] entrieValues; - Set voiceFiles = getVoiceFiles(); + Set voiceFiles = getVoiceFiles(this); entries = new String[voiceFiles.size() ]; entrieValues = new String[voiceFiles.size() ]; int k = 0; diff --git a/OsmAnd/src/net/osmand/plus/mapcontextmenu/other/RoutePreferencesMenu.java b/OsmAnd/src/net/osmand/plus/mapcontextmenu/other/RoutePreferencesMenu.java index 070c0a61c6..c40e66a608 100644 --- a/OsmAnd/src/net/osmand/plus/mapcontextmenu/other/RoutePreferencesMenu.java +++ b/OsmAnd/src/net/osmand/plus/mapcontextmenu/other/RoutePreferencesMenu.java @@ -1,5 +1,6 @@ package net.osmand.plus.mapcontextmenu.other; +import android.app.Activity; import android.content.Context; import android.content.DialogInterface; import android.content.Intent; @@ -329,20 +330,36 @@ public class RoutePreferencesMenu { app.initVoiceCommandPlayer(mapActivity, app.getRoutingHelper().getAppMode(), false, null, true, false); } - private static Set getVoiceFiles(MapActivity mapActivity) { + public static Set getVoiceFiles(Activity activity) { // read available voice data - File extStorage = mapActivity.getMyApplication().getAppPath(IndexConstants.VOICE_INDEX_DIR); - Set setFiles = new LinkedHashSet<>(); + OsmandApplication app = ((OsmandApplication) activity.getApplication()); + File extStorage = app.getAppPath(IndexConstants.VOICE_INDEX_DIR); + Set setFiles = new LinkedHashSet(); + boolean addJS = app.getSettings().USE_JS_VOICE_GUIDANCE.get(); if (extStorage.exists()) { for (File f : extStorage.listFiles()) { if (f.isDirectory()) { - setFiles.add(f.getName()); + if (addJS && hasJavaScript(f)) { + setFiles.add(f.getName()); + } else if (!addJS) { + setFiles.add(f.getName()); + } + } } } return setFiles; } + private static boolean hasJavaScript(File f) { + for (File file : f.listFiles()) { + if (file.getName().endsWith(IndexConstants.TTSVOICE_INDEX_EXT_JS)) { + return true; + } + } + return false; + } + public OnItemClickListener getItemClickListener(final ArrayAdapter listAdapter) { return new OnItemClickListener() { @Override