Translate voice

This commit is contained in:
vshcherb 2014-04-29 00:44:05 +02:00
parent 63a6ac5965
commit f1b53af947
4 changed files with 44 additions and 41 deletions

View file

@ -3,6 +3,7 @@ package net.osmand.plus;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.lang.reflect.Field;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Comparator; import java.util.Comparator;
@ -1684,6 +1685,23 @@ public class OsmandSettings {
return false; 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 { public enum DayNightMode {
AUTO(R.string.daynight_mode_auto), AUTO(R.string.daynight_mode_auto),
DAY(R.string.daynight_mode_day), DAY(R.string.daynight_mode_day),

View file

@ -67,6 +67,7 @@ public class DownloadIndexActivity extends OsmandExpandableListActivity {
private static final int FILTER_EXISTING_REGIONS = 3; private static final int FILTER_EXISTING_REGIONS = 3;
public static final String FILTER_KEY = "filter"; public static final String FILTER_KEY = "filter";
public static final String FILTER_CAT = "filter_cat";
private static DownloadIndexesThread downloadListIndexThread; private static DownloadIndexesThread downloadListIndexThread;
private DownloadActivityType type = DownloadActivityType.NORMAL_FILE; private DownloadActivityType type = DownloadActivityType.NORMAL_FILE;
@ -76,10 +77,6 @@ public class DownloadIndexActivity extends OsmandExpandableListActivity {
private TextWatcher textWatcher ; private TextWatcher textWatcher ;
private EditText filterText; private EditText filterText;
private OsmandSettings settings; private OsmandSettings settings;
private ArrayAdapter<String> spinnerAdapter;
private View progressView; private View progressView;
private ProgressBar indeterminateProgressBar; private ProgressBar indeterminateProgressBar;
@ -151,10 +148,15 @@ public class DownloadIndexActivity extends OsmandExpandableListActivity {
if (intent != null && intent.getExtras() != null) { if (intent != null && intent.getExtras() != null) {
final String filter = intent.getExtras().getString(FILTER_KEY); final String filter = intent.getExtras().getString(FILTER_KEY);
if (filter != null) { if (filter != null) {
if(filter.equals(getString(R.string.voice))) { filterText.setText(filter);
changeType(DownloadActivityType.VOICE_FILE); }
} else { final String filterCat = intent.getExtras().getString(FILTER_CAT);
filterText.setText(filter); 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(); 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) toString(downloadTypes)
); );
spinnerAdapter.setDropDownViewResource(R.layout.sherlock_spinner_dropdown_item); 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) { private List<String> toString(List<DownloadActivityType> t) {
ArrayList<String> items = new ArrayList<String>(); ArrayList<String> items = new ArrayList<String>();

View file

@ -21,6 +21,7 @@ import net.osmand.plus.ProgressDialogImplementation;
import net.osmand.plus.R; import net.osmand.plus.R;
import net.osmand.plus.Version; import net.osmand.plus.Version;
import net.osmand.plus.base.SuggestExternalDirectoryDialog; import net.osmand.plus.base.SuggestExternalDirectoryDialog;
import net.osmand.plus.download.DownloadActivityType;
import net.osmand.plus.render.NativeOsmandLibrary; import net.osmand.plus.render.NativeOsmandLibrary;
import net.osmand.plus.voice.CommandPlayer; import net.osmand.plus.voice.CommandPlayer;
import net.osmand.render.RenderingRulesStorage; import net.osmand.render.RenderingRulesStorage;
@ -303,7 +304,7 @@ public class SettingsGeneralActivity extends SettingsBaseActivity {
if (MORE_VALUE.equals(newValue)) { if (MORE_VALUE.equals(newValue)) {
// listPref.set(oldValue); // revert the change.. // listPref.set(oldValue); // revert the change..
final Intent intent = new Intent(this, DownloadIndexActivity.class); 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); startActivity(intent);
} else { } else {
super.onPreferenceChange(preference, newValue); super.onPreferenceChange(preference, newValue);
@ -561,7 +562,8 @@ public class SettingsGeneralActivity extends SettingsBaseActivity {
entrieValues[k] = OsmandSettings.VOICE_PROVIDER_NOT_USE; entrieValues[k] = OsmandSettings.VOICE_PROVIDER_NOT_USE;
entries[k++] = getString(R.string.voice_not_use); entries[k++] = getString(R.string.voice_not_use);
for (String s : voiceFiles) { for (String s : voiceFiles) {
entries[k] = s; entries[k] = (s.contains("tts") ? getString(R.string.ttsvoice) +" ":"") +
OsmandSettings.getVoiceName(this, s);
entrieValues[k] = s; entrieValues[k] = s;
k++; k++;
} }

View file

@ -15,6 +15,7 @@ import net.osmand.AndroidUtils;
import net.osmand.IndexConstants; import net.osmand.IndexConstants;
import net.osmand.map.OsmandRegions; import net.osmand.map.OsmandRegions;
import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandSettings;
import net.osmand.plus.R; import net.osmand.plus.R;
import net.osmand.plus.Version; import net.osmand.plus.Version;
import net.osmand.util.Algorithms; import net.osmand.util.Algorithms;
@ -42,6 +43,11 @@ public class DownloadActivityType {
byTag.put(st, this); byTag.put(st, this);
} }
} }
public String getTag() {
return tags[0];
}
public static boolean isCountedInDownloads(DownloadActivityType tp) { public static boolean isCountedInDownloads(DownloadActivityType tp) {
if(tp == NORMAL_FILE || tp == ROADS_FILE){ if(tp == NORMAL_FILE || tp == ROADS_FILE){
@ -182,30 +188,16 @@ public class DownloadActivityType {
return ""; 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) { public String getVisibleName(IndexItem indexItem, Context ctx, OsmandRegions osmandRegions) {
String fileName = indexItem.fileName; String fileName = indexItem.fileName;
if (this == VOICE_FILE) { if (this == VOICE_FILE) {
if (fileName.endsWith(IndexConstants.VOICE_INDEX_EXT_ZIP)) { 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)) { } 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); return getBasename(indexItem);
} }