diff --git a/src/mahomaps/MahoMapsApp.java b/src/mahomaps/MahoMapsApp.java index 66905006..53898b9f 100644 --- a/src/mahomaps/MahoMapsApp.java +++ b/src/mahomaps/MahoMapsApp.java @@ -70,7 +70,16 @@ public void run() { // just in case } Settings.Read(); // catch(Throwable) inside - tiles = new TilesProvider("ru_RU"); // nothing to fail + try { + tiles = new TilesProvider(Settings.GetLangString()); // wrong lang in settings + } catch (RuntimeException e) { + Form f = new Form("Ошибка", new Item[] { new StringItem("Настройки повреждены", "Переустановите приложение.") }); + f.addCommand(exit); + f.setCommandListener(this); + BringSubScreen(f); + thread = null; + return; + } if (!TryInitFSCache(true)) { // catch(Throwable) inside thread = null; return; diff --git a/src/mahomaps/Settings.java b/src/mahomaps/Settings.java index 414b212e..20ddbdb2 100644 --- a/src/mahomaps/Settings.java +++ b/src/mahomaps/Settings.java @@ -20,6 +20,7 @@ private Settings() { public static boolean proxyTiles = false; public static boolean proxyApi = false; public static int uiSize = 0; + public static int lang = 0; public static String proxyServer = "http://nnp.nnchan.ru:80/mahoproxy.php?u="; @@ -52,6 +53,7 @@ public static boolean Read() { proxyTiles = j.optBoolean("proxy_tiles"); proxyApi = j.optBoolean("proxy_api"); uiSize = j.optInt("ui_size", 0); + lang = j.optInt("lang", 0); return true; } catch (Throwable e) { e.printStackTrace(); @@ -82,6 +84,7 @@ public static String Serialize() { j.put("proxy_tiles", proxyTiles); j.put("proxy_api", proxyApi); j.put("ui_size", uiSize); + j.put("lang", lang); return j.toString(); } @@ -99,4 +102,17 @@ public static void Save() { e.printStackTrace(); } } + + public static String GetLangString() { + switch (lang) { + case 0: + return new String(new char[] {'r','u','_','R','U'}); + case 1: + return new String(new char[] {'e','n','_','U','S'}); + case 2: + return new String(new char[] {'t','r','_','T','R'}); + default: + throw new IndexOutOfBoundsException("Unknown language code!"); + } + } } diff --git a/src/mahomaps/api/YmapsApi.java b/src/mahomaps/api/YmapsApi.java index ebd0e7ee..580203ea 100644 --- a/src/mahomaps/api/YmapsApi.java +++ b/src/mahomaps/api/YmapsApi.java @@ -9,6 +9,7 @@ import org.json.me.JSONException; import org.json.me.JSONObject; +import mahomaps.Settings; import mahomaps.map.Geopoint; public final class YmapsApi extends YmapsApiBase { @@ -27,8 +28,8 @@ public final synchronized void RefreshToken() throws Exception { private final String GetSearchUrl(String text, Geopoint around, double zone) { String[] cs = around.GetRounded(); - return "https://api-maps.yandex.ru/services/search/v2/?format=json&lang=ru_RU&token=" + token - + "&rspn=0&results=40&origin=jsapi2SearchControl" + return "https://api-maps.yandex.ru/services/search/v2/?format=json&lang=" + Settings.GetLangString() + "&token=" + + token + "&rspn=0&results=40&origin=jsapi2SearchControl" + "&snippets=businessrating%2F1.x%2Cmasstransit%2F1.x&ask_direct=1&experimental_maxadv=200&apikey=" + key + "&text=" + EncodeUrl(text) + "&ll=" + cs[1] + "%2C" + cs[0] + "&spn=" + zone + "%2C" + zone; } @@ -47,8 +48,11 @@ private final String GetRouteUrl(Geopoint a, Geopoint b, int type) { default: throw new IllegalArgumentException(); } - return "https://api-maps.yandex.ru/services/route/2.0/?lang=ru_RU&token=" + token + "&rll=" + a.lon + "%2C" - + a.lat + "~" + b.lon + "%2C" + b.lat + "&rtm=dtr&results=1&apikey=" + key + typeS; + String baseUrl = "https://api-maps.yandex.ru/services/route/2.0/?lang="; + String lang = new String(new char[] { baseUrl.charAt(29), baseUrl.charAt(38), '_', + Character.toUpperCase(baseUrl.charAt(29)), 'U' }); + return baseUrl + lang + "&token=" + token + "&rll=" + a.lon + "%2C" + a.lat + "~" + b.lon + "%2C" + b.lat + + "&rtm=dtr&results=1&apikey=" + key + typeS; } public final JSONArray Search(String text, Geopoint around, double zone) diff --git a/src/mahomaps/map/TilesProvider.java b/src/mahomaps/map/TilesProvider.java index 3990136c..a2f6cb4a 100644 --- a/src/mahomaps/map/TilesProvider.java +++ b/src/mahomaps/map/TilesProvider.java @@ -422,7 +422,7 @@ private Image tryLoadFromFS(TileId id) { * @param id Тайл для поиска. * @return Изображение, если тайл сохранён, иначе null. */ - private static Image tryLoadFromRMS(TileId id) { + private Image tryLoadFromRMS(TileId id) { byte[] b = null; try { RecordStore r = RecordStore.openRecordStore(getRmsName(id), true); @@ -563,11 +563,11 @@ private String getUrl(TileId tileId) { } private String getFileName(TileId id) { - return localPath + "tile_" + id.x + "_" + id.y + "_" + id.zoom; + return localPath + "tile_" + lang + "_" + id.x + "_" + id.y + "_" + id.zoom; } - private static String getRmsName(TileId id) { - return "tile_" + id.x + "_" + id.y + "_" + id.zoom; + private String getRmsName(TileId id) { + return "tile_" + lang + "_" + id.x + "_" + id.y + "_" + id.zoom; } } diff --git a/src/mahomaps/screens/SettingsScreen.java b/src/mahomaps/screens/SettingsScreen.java index 9ec33458..aa9fe47e 100644 --- a/src/mahomaps/screens/SettingsScreen.java +++ b/src/mahomaps/screens/SettingsScreen.java @@ -32,6 +32,8 @@ public class SettingsScreen extends Form implements CommandListener { new String[] { "Отключено", "nnchan.ru", }, null); private ChoiceGroup uiSize = new ChoiceGroup("Размер кнопок управления (нужен перезапуск)", Choice.POPUP, new String[] { "Автоматически", "50x50", "30x30" }, null); + private ChoiceGroup lang = new ChoiceGroup("Язык тайлов и поиска (нужен перезапуск)", Choice.POPUP, + new String[] { "Русский", "Английский", "Турецкий" }, null); public SettingsScreen() { super("Настройки"); @@ -68,6 +70,7 @@ public SettingsScreen() { // апи отслеживается отдельно, однако предполагается что оно включено вместе с // тайлами. uiSize.setSelectedIndex(Settings.uiSize, true); + lang.setSelectedIndex(Settings.lang, true); append(focusZoom); append(geoLook); @@ -77,6 +80,7 @@ public SettingsScreen() { append(download); append(proxyTiles); append(uiSize); + append(lang); } private void Apply() { @@ -89,6 +93,7 @@ private void Apply() { Settings.proxyTiles = proxyTiles.getSelectedIndex() == 1; Settings.proxyApi = proxyTiles.getSelectedIndex() == 1; Settings.uiSize = uiSize.getSelectedIndex(); + Settings.lang = lang.getSelectedIndex(); if (Settings.allowDownload) { MahoMapsApp.tiles.ForceMissingDownload(); }