From f1b53af947588cb3f2a2df5249ef1f23c6c5500a Mon Sep 17 00:00:00 2001 From: vshcherb Date: Tue, 29 Apr 2014 00:44:05 +0200 Subject: [PATCH] Translate voice --- .../src/net/osmand/plus/OsmandSettings.java | 18 +++++++++++ .../activities/DownloadIndexActivity.java | 31 +++++++------------ .../activities/SettingsGeneralActivity.java | 6 ++-- .../plus/download/DownloadActivityType.java | 30 +++++++----------- 4 files changed, 44 insertions(+), 41 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/OsmandSettings.java b/OsmAnd/src/net/osmand/plus/OsmandSettings.java index 45d119a022..a9e4c13535 100644 --- a/OsmAnd/src/net/osmand/plus/OsmandSettings.java +++ b/OsmAnd/src/net/osmand/plus/OsmandSettings.java @@ -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), diff --git a/OsmAnd/src/net/osmand/plus/activities/DownloadIndexActivity.java b/OsmAnd/src/net/osmand/plus/activities/DownloadIndexActivity.java index 3b8a093594..d9b26cf9f5 100644 --- a/OsmAnd/src/net/osmand/plus/activities/DownloadIndexActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/DownloadIndexActivity.java @@ -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 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(getSupportActionBar().getThemedContext(), R.layout.sherlock_spinner_item, + ArrayAdapter spinnerAdapter = new ArrayAdapter(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 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 toString(List t) { ArrayList items = new ArrayList(); diff --git a/OsmAnd/src/net/osmand/plus/activities/SettingsGeneralActivity.java b/OsmAnd/src/net/osmand/plus/activities/SettingsGeneralActivity.java index 9a769775d7..6f518c4709 100644 --- a/OsmAnd/src/net/osmand/plus/activities/SettingsGeneralActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/SettingsGeneralActivity.java @@ -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++; } diff --git a/OsmAnd/src/net/osmand/plus/download/DownloadActivityType.java b/OsmAnd/src/net/osmand/plus/download/DownloadActivityType.java index 7d3503156c..6bccec5502 100644 --- a/OsmAnd/src/net/osmand/plus/download/DownloadActivityType.java +++ b/OsmAnd/src/net/osmand/plus/download/DownloadActivityType.java @@ -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); }