Translate voice
This commit is contained in:
parent
63a6ac5965
commit
f1b53af947
4 changed files with 44 additions and 41 deletions
|
@ -3,6 +3,7 @@ package net.osmand.plus;
|
|||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Comparator;
|
||||
|
@ -1684,6 +1685,23 @@ public class OsmandSettings {
|
|||
return false;
|
||||
}
|
||||
|
||||
public static String getVoiceName(Context ctx, String basename) {
|
||||
try {
|
||||
String nm = basename.replace('-', '_').replace(' ', '_');
|
||||
if (nm.endsWith("_tts") || nm.endsWith("-tts")) {
|
||||
nm = nm.substring(0, nm.length() - 4);
|
||||
}
|
||||
Field f = R.string.class.getField("lang_"+nm);
|
||||
if (f != null) {
|
||||
Integer in = (Integer) f.get(null);
|
||||
return ctx.getString(in);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
System.err.println(e.getMessage());
|
||||
}
|
||||
return basename;
|
||||
}
|
||||
|
||||
public enum DayNightMode {
|
||||
AUTO(R.string.daynight_mode_auto),
|
||||
DAY(R.string.daynight_mode_day),
|
||||
|
|
|
@ -67,6 +67,7 @@ public class DownloadIndexActivity extends OsmandExpandableListActivity {
|
|||
private static final int FILTER_EXISTING_REGIONS = 3;
|
||||
|
||||
public static final String FILTER_KEY = "filter";
|
||||
public static final String FILTER_CAT = "filter_cat";
|
||||
|
||||
private static DownloadIndexesThread downloadListIndexThread;
|
||||
private DownloadActivityType type = DownloadActivityType.NORMAL_FILE;
|
||||
|
@ -76,10 +77,6 @@ public class DownloadIndexActivity extends OsmandExpandableListActivity {
|
|||
private TextWatcher textWatcher ;
|
||||
private EditText filterText;
|
||||
private OsmandSettings settings;
|
||||
private ArrayAdapter<String> spinnerAdapter;
|
||||
|
||||
|
||||
|
||||
|
||||
private View progressView;
|
||||
private ProgressBar indeterminateProgressBar;
|
||||
|
@ -151,10 +148,15 @@ public class DownloadIndexActivity extends OsmandExpandableListActivity {
|
|||
if (intent != null && intent.getExtras() != null) {
|
||||
final String filter = intent.getExtras().getString(FILTER_KEY);
|
||||
if (filter != null) {
|
||||
if(filter.equals(getString(R.string.voice))) {
|
||||
changeType(DownloadActivityType.VOICE_FILE);
|
||||
} else {
|
||||
filterText.setText(filter);
|
||||
filterText.setText(filter);
|
||||
}
|
||||
final String filterCat = intent.getExtras().getString(FILTER_CAT);
|
||||
if (filterCat != null) {
|
||||
DownloadActivityType type = DownloadActivityType.getIndexType(filterCat.toLowerCase());
|
||||
if (type != null) {
|
||||
this.type = type;
|
||||
downloadTypes.remove(type);
|
||||
downloadTypes.add(0, type);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -179,7 +181,7 @@ public class DownloadIndexActivity extends OsmandExpandableListActivity {
|
|||
showDialogOfFreeDownloadsIfNeeded();
|
||||
}
|
||||
|
||||
spinnerAdapter = new ArrayAdapter<String>(getSupportActionBar().getThemedContext(), R.layout.sherlock_spinner_item,
|
||||
ArrayAdapter<String> spinnerAdapter = new ArrayAdapter<String>(getSupportActionBar().getThemedContext(), R.layout.sherlock_spinner_item,
|
||||
toString(downloadTypes)
|
||||
);
|
||||
spinnerAdapter.setDropDownViewResource(R.layout.sherlock_spinner_dropdown_item);
|
||||
|
@ -409,17 +411,6 @@ public class DownloadIndexActivity extends OsmandExpandableListActivity {
|
|||
}
|
||||
}
|
||||
|
||||
public void selectDownloadType() {
|
||||
Builder bld = new AlertDialog.Builder(this);
|
||||
final List<DownloadActivityType> items = getDownloadTypes();
|
||||
bld.setItems(toString(items).toArray(new String[items.size()]), new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
changeType(items.get(which));
|
||||
}
|
||||
});
|
||||
bld.show();
|
||||
}
|
||||
|
||||
private List<String> toString(List<DownloadActivityType> t) {
|
||||
ArrayList<String> items = new ArrayList<String>();
|
||||
|
|
|
@ -21,6 +21,7 @@ import net.osmand.plus.ProgressDialogImplementation;
|
|||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.Version;
|
||||
import net.osmand.plus.base.SuggestExternalDirectoryDialog;
|
||||
import net.osmand.plus.download.DownloadActivityType;
|
||||
import net.osmand.plus.render.NativeOsmandLibrary;
|
||||
import net.osmand.plus.voice.CommandPlayer;
|
||||
import net.osmand.render.RenderingRulesStorage;
|
||||
|
@ -303,7 +304,7 @@ public class SettingsGeneralActivity extends SettingsBaseActivity {
|
|||
if (MORE_VALUE.equals(newValue)) {
|
||||
// listPref.set(oldValue); // revert the change..
|
||||
final Intent intent = new Intent(this, DownloadIndexActivity.class);
|
||||
intent.putExtra(DownloadIndexActivity.FILTER_KEY, getString(R.string.voice));
|
||||
intent.putExtra(DownloadIndexActivity.FILTER_CAT, DownloadActivityType.VOICE_FILE.getTag());
|
||||
startActivity(intent);
|
||||
} else {
|
||||
super.onPreferenceChange(preference, newValue);
|
||||
|
@ -561,7 +562,8 @@ public class SettingsGeneralActivity extends SettingsBaseActivity {
|
|||
entrieValues[k] = OsmandSettings.VOICE_PROVIDER_NOT_USE;
|
||||
entries[k++] = getString(R.string.voice_not_use);
|
||||
for (String s : voiceFiles) {
|
||||
entries[k] = s;
|
||||
entries[k] = (s.contains("tts") ? getString(R.string.ttsvoice) +" ":"") +
|
||||
OsmandSettings.getVoiceName(this, s);
|
||||
entrieValues[k] = s;
|
||||
k++;
|
||||
}
|
||||
|
|
|
@ -15,6 +15,7 @@ import net.osmand.AndroidUtils;
|
|||
import net.osmand.IndexConstants;
|
||||
import net.osmand.map.OsmandRegions;
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.OsmandSettings;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.Version;
|
||||
import net.osmand.util.Algorithms;
|
||||
|
@ -42,6 +43,11 @@ public class DownloadActivityType {
|
|||
byTag.put(st, this);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public String getTag() {
|
||||
return tags[0];
|
||||
}
|
||||
|
||||
public static boolean isCountedInDownloads(DownloadActivityType tp) {
|
||||
if(tp == NORMAL_FILE || tp == ROADS_FILE){
|
||||
|
@ -182,30 +188,16 @@ public class DownloadActivityType {
|
|||
return "";
|
||||
}
|
||||
|
||||
private String getVoiceName(Context ctx, String basename) {
|
||||
try {
|
||||
String nm = basename.replace('-', '_').replace(' ', '_');
|
||||
if (nm.endsWith("_tts")) {
|
||||
nm = nm.substring(0, nm.length() - 4);
|
||||
}
|
||||
Field f = R.string.class.getField("lang_"+nm);
|
||||
if (f != null) {
|
||||
Integer in = (Integer) f.get(null);
|
||||
return ctx.getString(in);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
System.err.println(e.getMessage());
|
||||
}
|
||||
return basename;
|
||||
}
|
||||
|
||||
public String getVisibleName(IndexItem indexItem, Context ctx, OsmandRegions osmandRegions) {
|
||||
String fileName = indexItem.fileName;
|
||||
|
||||
if (this == VOICE_FILE) {
|
||||
if (fileName.endsWith(IndexConstants.VOICE_INDEX_EXT_ZIP)) {
|
||||
return ctx.getString(R.string.voice) + "\n" + getVoiceName(ctx, getBasename(indexItem));
|
||||
return ctx.getString(R.string.voice) + "\n" +
|
||||
OsmandSettings.getVoiceName(ctx, getBasename(indexItem));
|
||||
} else if (fileName.endsWith(IndexConstants.TTSVOICE_INDEX_EXT_ZIP)) {
|
||||
return ctx.getString(R.string.ttsvoice) + "\n" + getVoiceName(ctx, getBasename(indexItem));
|
||||
return ctx.getString(R.string.ttsvoice) + "\n" +
|
||||
OsmandSettings.getVoiceName(ctx, getBasename(indexItem));
|
||||
}
|
||||
return getBasename(indexItem);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue