Fix #1898
This commit is contained in:
parent
b59e745b2e
commit
a583417eee
2 changed files with 44 additions and 15 deletions
|
@ -23,7 +23,6 @@ import android.support.v7.app.AlertDialog;
|
||||||
import android.widget.EditText;
|
import android.widget.EditText;
|
||||||
import android.widget.LinearLayout;
|
import android.widget.LinearLayout;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
import net.osmand.IProgress;
|
import net.osmand.IProgress;
|
||||||
import net.osmand.IndexConstants;
|
import net.osmand.IndexConstants;
|
||||||
import net.osmand.access.AccessibleToast;
|
import net.osmand.access.AccessibleToast;
|
||||||
|
@ -255,7 +254,8 @@ public class SettingsGeneralActivity extends SettingsBaseActivity {
|
||||||
((ListPreference) screen.findPreference(settings.PREFERRED_LOCALE.getId())).setTitle(getString(R.string.preferred_locale) + " (" + getString(R.string.preferred_locale_no_translate) + ")");
|
((ListPreference) screen.findPreference(settings.PREFERRED_LOCALE.getId())).setTitle(getString(R.string.preferred_locale) + " (" + getString(R.string.preferred_locale_no_translate) + ")");
|
||||||
}
|
}
|
||||||
|
|
||||||
registerListPreference(settings.MAP_PREFERRED_LOCALE, screen, ConfigureMapMenu.getMapNamesValues(this), ConfigureMapMenu.mapNamesIds);
|
String[] ids = ConfigureMapMenu.getSortedMapNamesIds(this);
|
||||||
|
registerListPreference(settings.MAP_PREFERRED_LOCALE, screen, ConfigureMapMenu.getMapNamesValues(this, ids), ids);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -8,7 +8,6 @@ import android.support.v7.app.AlertDialog;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.widget.ArrayAdapter;
|
import android.widget.ArrayAdapter;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
import net.osmand.PlatformUtil;
|
import net.osmand.PlatformUtil;
|
||||||
import net.osmand.access.AccessibleToast;
|
import net.osmand.access.AccessibleToast;
|
||||||
import net.osmand.core.android.MapRendererContext;
|
import net.osmand.core.android.MapRendererContext;
|
||||||
|
@ -39,11 +38,16 @@ import net.osmand.util.Algorithms;
|
||||||
|
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
|
|
||||||
|
import java.text.Collator;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.Comparator;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
import gnu.trove.list.array.TIntArrayList;
|
import gnu.trove.list.array.TIntArrayList;
|
||||||
|
|
||||||
|
@ -369,21 +373,21 @@ public class ConfigureMapMenu {
|
||||||
AlertDialog.Builder b = new AlertDialog.Builder(view.getContext());
|
AlertDialog.Builder b = new AlertDialog.Builder(view.getContext());
|
||||||
// test old descr as title
|
// test old descr as title
|
||||||
b.setTitle(R.string.map_preferred_locale);
|
b.setTitle(R.string.map_preferred_locale);
|
||||||
final String[] txtValues = mapNamesIds;
|
final String[] txtIds = getSortedMapNamesIds(activity);
|
||||||
final String[] txtNames = getMapNamesValues(activity);
|
final String[] txtValues = getMapNamesValues(activity, txtIds);
|
||||||
int selected = -1;
|
int selected = -1;
|
||||||
for (int i = 0; i < txtValues.length; i++) {
|
for (int i = 0; i < txtIds.length; i++) {
|
||||||
if(view.getSettings().MAP_PREFERRED_LOCALE.get().equals(txtValues[i])) {
|
if(view.getSettings().MAP_PREFERRED_LOCALE.get().equals(txtIds[i])) {
|
||||||
selected = i;
|
selected = i;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
b.setSingleChoiceItems(txtNames, selected, new DialogInterface.OnClickListener() {
|
b.setSingleChoiceItems(txtValues, selected, new DialogInterface.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(DialogInterface dialog, int which) {
|
public void onClick(DialogInterface dialog, int which) {
|
||||||
view.getSettings().MAP_PREFERRED_LOCALE.set(txtValues[which]);
|
view.getSettings().MAP_PREFERRED_LOCALE.set(txtIds[which]);
|
||||||
refreshMapComplete(activity);
|
refreshMapComplete(activity);
|
||||||
adapter.setItemDescription(pos, txtValues[which]);
|
adapter.setItemDescription(pos, txtIds[which]);
|
||||||
ad.notifyDataSetInvalidated();
|
ad.notifyDataSetInvalidated();
|
||||||
dialog.dismiss();
|
dialog.dismiss();
|
||||||
}
|
}
|
||||||
|
@ -415,11 +419,36 @@ public class ConfigureMapMenu {
|
||||||
|
|
||||||
public static String[] mapNamesIds = new String[] { "", "en", "als", "af", "ar", "az", "be", "bg", "bn", "bpy", "br", "bs", "ca", "ceb", "cs", "cy", "da", "de", "el", "et", "es", "eu", "fa", "fi", "fr", "fy", "ga", "gl", "he", "hi", "hr", "ht", "hu", "hy", "id", "is", "it", "ja", "ka", "ko", "ku", "la", "lb", "lt", "lv", "mk", "ml", "mr", "ms", "nds", "new", "nl", "nn", "no", "nv", "os", "pl", "pms", "pt", "ro", "ru", "sh", "sc", "sk", "sl", "sq", "sr", "sv", "sw", "ta", "te", "th", "tl", "tr", "uk", "vi", "vo", "zh" };
|
public static String[] mapNamesIds = new String[] { "", "en", "als", "af", "ar", "az", "be", "bg", "bn", "bpy", "br", "bs", "ca", "ceb", "cs", "cy", "da", "de", "el", "et", "es", "eu", "fa", "fi", "fr", "fy", "ga", "gl", "he", "hi", "hr", "ht", "hu", "hy", "id", "is", "it", "ja", "ka", "ko", "ku", "la", "lb", "lt", "lv", "mk", "ml", "mr", "ms", "nds", "new", "nl", "nn", "no", "nv", "os", "pl", "pms", "pt", "ro", "ru", "sh", "sc", "sk", "sl", "sq", "sr", "sv", "sw", "ta", "te", "th", "tl", "tr", "uk", "vi", "vo", "zh" };
|
||||||
|
|
||||||
public static String[] getMapNamesValues(Context ctx) {
|
|
||||||
String[] translates = new String[mapNamesIds.length];
|
public static String[] getSortedMapNamesIds(Context ctx) {
|
||||||
translates[0] = ctx.getString(R.string.local_map_names);
|
String[] vls = getMapNamesValues(ctx, mapNamesIds);
|
||||||
for(int i = 1; i < translates.length; i++) {
|
final Map<String, String> mp = new HashMap<String, String>();
|
||||||
translates[i] = ((OsmandApplication)ctx.getApplicationContext()).getLangTranslation(mapNamesIds[i]);
|
for(int i = 0; i < mapNamesIds.length; i++) {
|
||||||
|
mp.put(mapNamesIds[i], vls[i]);
|
||||||
|
}
|
||||||
|
ArrayList<String> lst = new ArrayList<String>(mp.keySet());
|
||||||
|
Collections.sort(lst, new Comparator<String>() {
|
||||||
|
@Override
|
||||||
|
public int compare(String lhs, String rhs) {
|
||||||
|
int i1 = Algorithms.isEmpty(lhs)? 0 : (lhs.equals("en") ? 1 : 2);
|
||||||
|
int i2 = Algorithms.isEmpty(rhs)? 0 : (rhs.equals("en") ? 1 : 2);
|
||||||
|
if(i1 != i2) {
|
||||||
|
return i1 < i2 ? -1 : 1;
|
||||||
|
}
|
||||||
|
return mp.get(lhs).compareTo(mp.get(rhs));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return lst.toArray(new String[lst.size()]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String[] getMapNamesValues(Context ctx, String[] ids) {
|
||||||
|
String[] translates = new String[ids.length];
|
||||||
|
for(int i = 0; i < translates.length; i++) {
|
||||||
|
if(Algorithms.isEmpty(ids[i])) {
|
||||||
|
translates[i] = ctx.getString(R.string.local_map_names);
|
||||||
|
} else {
|
||||||
|
translates[i] = ((OsmandApplication)ctx.getApplicationContext()).getLangTranslation(ids[i]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return translates;
|
return translates;
|
||||||
|
|
Loading…
Reference in a new issue