From 9050c44f76383d2bc7c46440f3a4417b81188405 Mon Sep 17 00:00:00 2001 From: PavelRatushnyi Date: Tue, 17 Oct 2017 18:26:14 +0300 Subject: [PATCH] FIx crash in proxy setting --- OsmAnd/res/values/strings.xml | 1 + .../activities/SettingsGeneralActivity.java | 18 +++++++++++++++--- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/OsmAnd/res/values/strings.xml b/OsmAnd/res/values/strings.xml index 340d70a08a..a9418a8cd0 100644 --- a/OsmAnd/res/values/strings.xml +++ b/OsmAnd/res/values/strings.xml @@ -9,6 +9,7 @@ 3. All your modified/created strings are in the top of the file (to make easier find what\'s translated). PLEASE: Have a look at http://code.google.com/p/osmand/wiki/UIConsistency, it may really improve your and our work :-) Thx - Hardy --> + Wrong format Road Show map Route is calculated diff --git a/OsmAnd/src/net/osmand/plus/activities/SettingsGeneralActivity.java b/OsmAnd/src/net/osmand/plus/activities/SettingsGeneralActivity.java index 3ad0466430..860662b3d4 100644 --- a/OsmAnd/src/net/osmand/plus/activities/SettingsGeneralActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/SettingsGeneralActivity.java @@ -58,6 +58,12 @@ import java.util.List; public class SettingsGeneralActivity extends SettingsBaseActivity implements OnRequestPermissionsResultCallback { + private static final String IP_ADDRESS_PATTERN = + "^([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\." + + "([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\." + + "([01]?\\d\\d?|2[0-4]\\d|25[0-5])\\." + + "([01]?\\d\\d?|2[0-4]\\d|25[0-5])$"; + private Preference applicationDir; private ListPreference applicationModePreference; private Preference drivingRegionPreference; @@ -366,9 +372,15 @@ public class SettingsGeneralActivity extends SettingsBaseActivity implements OnR hostPref.setOnPreferenceChangeListener(new OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(Preference preference, Object newValue) { - settings.PROXY_HOST.set((String) newValue); - enableProxy(NetworkUtils.getProxy() != null); - return true; + String ipAddress = (String) newValue; + if (ipAddress.matches(IP_ADDRESS_PATTERN)) { + settings.PROXY_HOST.set(ipAddress); + enableProxy(NetworkUtils.getProxy() != null); + return true; + } else { + Toast.makeText(SettingsGeneralActivity.this, getString(R.string.wrong_format), Toast.LENGTH_SHORT).show(); + return false; + } } });