Skip to content

Commit

Permalink
Merge branch 'main' into more-routes
Browse files Browse the repository at this point in the history
  • Loading branch information
Feodor0090 committed May 29, 2023
2 parents 3949b28 + 3ab0906 commit ff06466
Show file tree
Hide file tree
Showing 8 changed files with 57 additions and 14 deletions.
2 changes: 1 addition & 1 deletion Application Descriptor
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Nokia-MIDlet-Background-Event: pause
MIDlet-Version: 1.0.1
MIDlet-Version: 1.0.2
MIDlet-Info-URL: https://github.com/mahomaps
MicroEdition-Configuration: CLDC-1.1
MIDlet-Name: MahoMaps v1
Expand Down
19 changes: 18 additions & 1 deletion src/mahomaps/MahoMapsApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,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;
Expand Down Expand Up @@ -313,4 +322,12 @@ public void commandAction(Command c, Displayable d) {
startApp();
}
}

public static String getConnectionParams() {
if (platform.toLowerCase().indexOf("blackberry") == -1) {
return "";
}
// сделать поддержку 3г когда-нибудь
return ";deviceside=true;interface=wifi";
}
}
16 changes: 16 additions & 0 deletions src/mahomaps/Settings.java
Original file line number Diff line number Diff line change
Expand Up @@ -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=";

Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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();
}

Expand All @@ -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!");
}
}
}
2 changes: 1 addition & 1 deletion src/mahomaps/UpdateCheckThread.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public void run() {
InputStream is = null;
ByteArrayOutputStream o = new ByteArrayOutputStream();
try {
hc = (HttpConnection) Connector.open(url);
hc = (HttpConnection) Connector.open(url + MahoMapsApp.getConnectionParams());
hc.setRequestMethod("GET");
int r = hc.getResponseCode();
is = hc.openInputStream();
Expand Down
12 changes: 8 additions & 4 deletions src/mahomaps/api/YmapsApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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;
}
Expand All @@ -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)
Expand Down
5 changes: 3 additions & 2 deletions src/mahomaps/api/YmapsApiBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import org.json.me.JSONArray;
import org.json.me.JSONObject;

import mahomaps.MahoMapsApp;
import mahomaps.Settings;

public abstract class YmapsApiBase {
Expand All @@ -31,7 +32,7 @@ protected final String GetToken(String key) throws Exception {
url = Settings.proxyServer + YmapsApiBase.EncodeUrl(url);
}
try {
hc = (HttpConnection) Connector.open(url);
hc = (HttpConnection) Connector.open(url + MahoMapsApp.getConnectionParams());
hc.setRequestMethod("GET");
hc.setRequestProperty("User-Agent",
"Mozilla/5.0 (Windows NT 6.3; WOW64; rv:49.0) Gecko/20100101 Firefox/49.0");
Expand Down Expand Up @@ -102,7 +103,7 @@ protected String GetUtf(String url) throws IOException, Http403Exception, Securi
url = Settings.proxyServer + YmapsApiBase.EncodeUrl(url);
}
System.out.println("GET " + url);
HttpConnection hc = (HttpConnection) Connector.open(url);
HttpConnection hc = (HttpConnection) Connector.open(url + MahoMapsApp.getConnectionParams());
InputStream is = null;
ByteArrayOutputStream o = null;
try {
Expand Down
10 changes: 5 additions & 5 deletions src/mahomaps/map/TilesProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ private Image download(TileId id) throws InterruptedException {
HttpConnection hc = null;
FileConnection fc = null;
try {
hc = (HttpConnection) Connector.open(getUrl(id));
hc = (HttpConnection) Connector.open(getUrl(id) + MahoMapsApp.getConnectionParams());
int len = (int) hc.getLength();
if (len <= 0)
throw new IOException("Empty responce");
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
}

}
5 changes: 5 additions & 0 deletions src/mahomaps/screens/SettingsScreen.java
Original file line number Diff line number Diff line change
Expand Up @@ -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("Настройки");
Expand Down Expand Up @@ -68,6 +70,7 @@ public SettingsScreen() {
// апи отслеживается отдельно, однако предполагается что оно включено вместе с
// тайлами.
uiSize.setSelectedIndex(Settings.uiSize, true);
lang.setSelectedIndex(Settings.lang, true);

append(focusZoom);
append(geoLook);
Expand All @@ -77,6 +80,7 @@ public SettingsScreen() {
append(download);
append(proxyTiles);
append(uiSize);
append(lang);
}

private void Apply() {
Expand All @@ -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();
}
Expand Down

0 comments on commit ff06466

Please sign in to comment.