Removed copy-paste code
This commit is contained in:
parent
1eb9b1a87b
commit
87ae02f88c
3 changed files with 27 additions and 64 deletions
|
@ -52,6 +52,8 @@ import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
|
import static net.osmand.plus.mapcontextmenu.other.RoutePreferencesMenu.getVoiceFiles;
|
||||||
|
|
||||||
public class SettingsNavigationActivity extends SettingsBaseActivity {
|
public class SettingsNavigationActivity extends SettingsBaseActivity {
|
||||||
|
|
||||||
public static final String MORE_VALUE = "MORE_VALUE";
|
public static final String MORE_VALUE = "MORE_VALUE";
|
||||||
|
@ -244,7 +246,7 @@ public class SettingsNavigationActivity extends SettingsBaseActivity {
|
||||||
private void reloadVoiceListPreference(PreferenceScreen screen) {
|
private void reloadVoiceListPreference(PreferenceScreen screen) {
|
||||||
String[] entries;
|
String[] entries;
|
||||||
String[] entrieValues;
|
String[] entrieValues;
|
||||||
Set<String> voiceFiles = getVoiceFiles();
|
Set<String> voiceFiles = getVoiceFiles(this);
|
||||||
entries = new String[voiceFiles.size() + 2];
|
entries = new String[voiceFiles.size() + 2];
|
||||||
entrieValues = new String[voiceFiles.size() + 2];
|
entrieValues = new String[voiceFiles.size() + 2];
|
||||||
int k = 0;
|
int k = 0;
|
||||||
|
@ -262,34 +264,6 @@ public class SettingsNavigationActivity extends SettingsBaseActivity {
|
||||||
registerListPreference(settings.VOICE_PROVIDER, screen, entries, entrieValues);
|
registerListPreference(settings.VOICE_PROVIDER, screen, entries, entrieValues);
|
||||||
}
|
}
|
||||||
|
|
||||||
private Set<String> getVoiceFiles() {
|
|
||||||
// read available voice data
|
|
||||||
File extStorage = ((OsmandApplication) getApplication()).getAppPath(IndexConstants.VOICE_INDEX_DIR);
|
|
||||||
Set<String> setFiles = new LinkedHashSet<String>();
|
|
||||||
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) {
|
private void addVoicePrefs(PreferenceGroup cat) {
|
||||||
if (!Version.isBlackberry((OsmandApplication) getApplication())) {
|
if (!Version.isBlackberry((OsmandApplication) getApplication())) {
|
||||||
|
|
|
@ -40,6 +40,8 @@ import java.util.Set;
|
||||||
import alice.tuprolog.Struct;
|
import alice.tuprolog.Struct;
|
||||||
import alice.tuprolog.Term;
|
import alice.tuprolog.Term;
|
||||||
|
|
||||||
|
import static net.osmand.plus.mapcontextmenu.other.RoutePreferencesMenu.getVoiceFiles;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test Voice activity
|
* Test Voice activity
|
||||||
|
@ -85,40 +87,10 @@ public class TestVoiceActivity extends OsmandActionBarActivity {
|
||||||
selectVoice(ll);
|
selectVoice(ll);
|
||||||
}
|
}
|
||||||
|
|
||||||
private Set<String> getVoiceFiles() {
|
|
||||||
// read available voice data
|
|
||||||
File extStorage = ((OsmandApplication) getApplication()).getAppPath(IndexConstants.VOICE_INDEX_DIR);
|
|
||||||
Set<String> setFiles = new LinkedHashSet<String>();
|
|
||||||
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) {
|
private void selectVoice(final LinearLayout ll) {
|
||||||
String[] entries;
|
String[] entries;
|
||||||
final String[] entrieValues;
|
final String[] entrieValues;
|
||||||
Set<String> voiceFiles = getVoiceFiles();
|
Set<String> voiceFiles = getVoiceFiles(this);
|
||||||
entries = new String[voiceFiles.size() ];
|
entries = new String[voiceFiles.size() ];
|
||||||
entrieValues = new String[voiceFiles.size() ];
|
entrieValues = new String[voiceFiles.size() ];
|
||||||
int k = 0;
|
int k = 0;
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package net.osmand.plus.mapcontextmenu.other;
|
package net.osmand.plus.mapcontextmenu.other;
|
||||||
|
|
||||||
|
import android.app.Activity;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.DialogInterface;
|
import android.content.DialogInterface;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
|
@ -329,20 +330,36 @@ public class RoutePreferencesMenu {
|
||||||
app.initVoiceCommandPlayer(mapActivity, app.getRoutingHelper().getAppMode(), false, null, true, false);
|
app.initVoiceCommandPlayer(mapActivity, app.getRoutingHelper().getAppMode(), false, null, true, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Set<String> getVoiceFiles(MapActivity mapActivity) {
|
public static Set<String> getVoiceFiles(Activity activity) {
|
||||||
// read available voice data
|
// read available voice data
|
||||||
File extStorage = mapActivity.getMyApplication().getAppPath(IndexConstants.VOICE_INDEX_DIR);
|
OsmandApplication app = ((OsmandApplication) activity.getApplication());
|
||||||
Set<String> setFiles = new LinkedHashSet<>();
|
File extStorage = app.getAppPath(IndexConstants.VOICE_INDEX_DIR);
|
||||||
|
Set<String> setFiles = new LinkedHashSet<String>();
|
||||||
|
boolean addJS = app.getSettings().USE_JS_VOICE_GUIDANCE.get();
|
||||||
if (extStorage.exists()) {
|
if (extStorage.exists()) {
|
||||||
for (File f : extStorage.listFiles()) {
|
for (File f : extStorage.listFiles()) {
|
||||||
if (f.isDirectory()) {
|
if (f.isDirectory()) {
|
||||||
setFiles.add(f.getName());
|
if (addJS && hasJavaScript(f)) {
|
||||||
|
setFiles.add(f.getName());
|
||||||
|
} else if (!addJS) {
|
||||||
|
setFiles.add(f.getName());
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return setFiles;
|
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) {
|
public OnItemClickListener getItemClickListener(final ArrayAdapter<?> listAdapter) {
|
||||||
return new OnItemClickListener() {
|
return new OnItemClickListener() {
|
||||||
@Override
|
@Override
|
||||||
|
|
Loading…
Reference in a new issue