Fix errors

This commit is contained in:
Victor Shcherb 2015-01-20 23:32:35 +01:00
parent 0c523a5226
commit 0b6738e356
10 changed files with 129 additions and 66 deletions

View file

@ -3,6 +3,8 @@ package net.osmand.osm;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
import net.osmand.PlatformUtil; import net.osmand.PlatformUtil;
@ -14,6 +16,7 @@ public class MapPoiTypes {
private static MapPoiTypes DEFAULT_INSTANCE = null; private static MapPoiTypes DEFAULT_INSTANCE = null;
private static final Log log = PlatformUtil.getLog(MapRenderingTypes.class); private static final Log log = PlatformUtil.getLog(MapRenderingTypes.class);
private String resourceName; private String resourceName;
private List<PoiCategory> categories = new ArrayList<PoiCategory>();
public MapPoiTypes(String fileName){ public MapPoiTypes(String fileName){
this.resourceName = fileName; this.resourceName = fileName;
@ -38,20 +41,30 @@ public class MapPoiTypes {
XmlPullParser parser = PlatformUtil.newXMLPullParser(); XmlPullParser parser = PlatformUtil.newXMLPullParser();
int tok; int tok;
parser.setInput(is, "UTF-8"); parser.setInput(is, "UTF-8");
String parentCategory = null; PoiCategory lastCategory = null;
String poiParentCategory = null; PoiFilter lastFilter = null;
String poiParentPrefix = null;
String order = null;
while ((tok = parser.next()) != XmlPullParser.END_DOCUMENT) { while ((tok = parser.next()) != XmlPullParser.END_DOCUMENT) {
if (tok == XmlPullParser.START_TAG) { if (tok == XmlPullParser.START_TAG) {
String name = parser.getName(); String name = parser.getName();
if (name.equals("category")) { //$NON-NLS-1$ if (name.equals("category")) {
parentCategory = parser.getAttributeValue("","name"); lastCategory = new PoiCategory(this, parser.getAttributeValue("","name"));
poiParentCategory = parser.getAttributeValue("","poi_category"); categories.add(lastCategory);
} else if(name.equals("poi_type")){
PoiType tp = new PoiType(this,
lastCategory, parser.getAttributeValue("","name"));
lastCategory.addPoiType(tp);
if(lastFilter != null) {
lastFilter.addPoiType(tp);
}
}
} else if (tok == XmlPullParser.END_TAG) {
String name = parser.getName();
if (name.equals("poi_filter")) {
lastFilter = null;
} }
} }
} }
log.info("Time to init " + (System.currentTimeMillis() - time)); //$NON-NLS-1$ log.info("Time to init poi types" + (System.currentTimeMillis() - time)); //$NON-NLS-1$
is.close(); is.close();
} catch (IOException e) { } catch (IOException e) {
log.error("Unexpected error", e); //$NON-NLS-1$ log.error("Unexpected error", e); //$NON-NLS-1$

View file

@ -1,21 +1,19 @@
package net.osmand.osm; package net.osmand.osm;
public class PoiCategory { import java.util.ArrayList;
import java.util.List;
private String name;
private String translationName;
private MapPoiTypes poiTypes;
public PoiCategory(MapPoiTypes poiTypes){
this.poiTypes = poiTypes;
}
public String getTranslationName() {
return translationName;
}
public String getName() {
return name;
}
public class PoiCategory extends PoiFilter {
private List<PoiFilter> poiFilters = new ArrayList<PoiFilter>();
public PoiCategory(MapPoiTypes registry, String keyName){
super(registry, keyName);
}
public void addPoiType(PoiFilter poi) {
poiFilters.add(poi);
}
} }

View file

@ -0,0 +1,42 @@
package net.osmand.osm;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
public class PoiFilter {
private String keyName;
private String translationName;
private MapPoiTypes registry;
private List<PoiType> poiTypes = new ArrayList<PoiType>();
private Map<String, PoiType> map = new LinkedHashMap<String, PoiType>();
public PoiFilter(MapPoiTypes registry, String keyName){
this.registry = registry;
this.keyName = keyName;
}
public String getTranslationName() {
return translationName;
}
public void addPoiType(PoiType type) {
if(!map.containsKey(type.getName())) {
poiTypes.add(type);
map.put(type.getName(), type);
}
}
public List<PoiType> getPoiTypes() {
return poiTypes;
}
public String getName() {
return keyName;
}
}

View file

@ -7,9 +7,10 @@ public class PoiType {
private MapPoiTypes poiTypes; private MapPoiTypes poiTypes;
private PoiCategory category; private PoiCategory category;
public PoiType(MapPoiTypes poiTypes, PoiCategory category){ public PoiType(MapPoiTypes poiTypes, PoiCategory category, String name){
this.poiTypes = poiTypes; this.poiTypes = poiTypes;
this.category = category; this.category = category;
name = name;
} }
public String getTranslationName() { public String getTranslationName() {

View file

@ -165,6 +165,10 @@ public class NetworkUtils {
proxy = null; proxy = null;
} }
} }
public static Proxy getProxy() {
return proxy;
}
public static HttpURLConnection getHttpURLConnection(String urlString) throws MalformedURLException, IOException { public static HttpURLConnection getHttpURLConnection(String urlString) throws MalformedURLException, IOException {
return getHttpURLConnection(new URL(urlString)); return getHttpURLConnection(new URL(urlString));

View file

@ -9,6 +9,9 @@
3. All your modified/created strings are in the top of the file (to make easier find what\'s translated). 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 PLEASE: Have a look at http://code.google.com/p/osmand/wiki/UIConsistency, it may really improve your and our work :-) Thx - Hardy
--> -->
<string name="proxy_pref_title">Proxy</string>
<string name="proxy_pref_descr">Setup a proxy internet communication</string>
<string name="settings_privacy">Privacy</string>
<string name="recents">RECENTS</string> <string name="recents">RECENTS</string>
<string name="navigation_over_track">Start navigation over track?</string> <string name="navigation_over_track">Start navigation over track?</string>
<string name="avoid_roads_msg">You can change route by selecting roads to avoid</string> <string name="avoid_roads_msg">You can change route by selecting roads to avoid</string>
@ -155,7 +158,7 @@
<string name="save_track_interval_descr">Choose logging interval for track recording during navigation</string> <string name="save_track_interval_descr">Choose logging interval for track recording during navigation</string>
<string name="voice_provider_descr">Select voice guidance for navigation</string> <string name="voice_provider_descr">Select voice guidance for navigation</string>
<string name="voice_provider">Voice guidance</string> <string name="voice_provider">Voice guidance</string>
<string name="proxy_pref_title">Proxy</string>
<string name="enable_proxy_title">Enable HTTP Proxy</string> <string name="enable_proxy_title">Enable HTTP Proxy</string>
<string name="enable_proxy_descr">Configure HTTP Proxy for all network requests</string> <string name="enable_proxy_descr">Configure HTTP Proxy for all network requests</string>
<string name="proxy_host_title">Proxy Host</string> <string name="proxy_host_title">Proxy Host</string>

View file

@ -13,7 +13,12 @@
<PreferenceCategory android:title="@string/voice_pref_title" android:key="voice"> <PreferenceCategory android:title="@string/voice_pref_title" android:key="voice">
<ListPreference android:title="@string/voice_provider" android:key="voice_provider" android:summary="@string/voice_provider_descr"></ListPreference> <ListPreference android:title="@string/voice_provider" android:key="voice_provider" android:summary="@string/voice_provider_descr"></ListPreference>
</PreferenceCategory> </PreferenceCategory>
<PreferenceCategory android:title="@string/proxy_pref_title" android:key="proxy">
<PreferenceCategory android:title="@string/misc_pref_title" android:key="misc">
<ListPreference android:key="osmand_theme" android:title="@string/choose_osmand_theme" android:summary="@string/choose_osmand_theme_descr"></ListPreference>
</PreferenceCategory>
<PreferenceCategory android:title="@string/settings_privacy">
<PreferenceScreen android:title="@string/proxy_pref_title" android:description="@string/proxy_pref_descr" android:key="proxy">
<CheckBoxPreference <CheckBoxPreference
android:key="enable_proxy" android:title="@string/enable_proxy_title" android:summary="@string/enable_proxy_descr" android:defaultValue="false" /> android:key="enable_proxy" android:title="@string/enable_proxy_title" android:summary="@string/enable_proxy_descr" android:defaultValue="false" />
<EditTextPreference <EditTextPreference
@ -22,8 +27,6 @@
<EditTextPreference <EditTextPreference
android:key="proxy_port" android:title="@string/proxy_port_title" android:summary="@string/proxy_port_descr" android:dependency="enable_proxy" android:key="proxy_port" android:title="@string/proxy_port_title" android:summary="@string/proxy_port_descr" android:dependency="enable_proxy"
android:defaultValue="8118" /> android:defaultValue="8118" />
</PreferenceCategory> </PreferenceScreen>
<PreferenceCategory android:title="@string/misc_pref_title" android:key="misc">
<ListPreference android:key="osmand_theme" android:title="@string/choose_osmand_theme" android:summary="@string/choose_osmand_theme_descr"></ListPreference>
</PreferenceCategory> </PreferenceCategory>
</PreferenceScreen> </PreferenceScreen>

View file

@ -796,7 +796,6 @@ public class OsmandSettings {
public final CommonPreference<Boolean> INTERRUPT_MUSIC = new BooleanPreference("interrupt_music", false).makeGlobal(); public final CommonPreference<Boolean> INTERRUPT_MUSIC = new BooleanPreference("interrupt_music", false).makeGlobal();
public final CommonPreference<Boolean> ENABLE_PROXY = new BooleanPreference("enable_proxy", false).makeGlobal();
public final CommonPreference<String> PROXY_HOST = new StringPreference("proxy_host", "127.0.0.1").makeGlobal(); public final CommonPreference<String> PROXY_HOST = new StringPreference("proxy_host", "127.0.0.1").makeGlobal();
public final CommonPreference<Integer> PROXY_PORT = new IntPreference("proxy_port", 8118).makeGlobal(); public final CommonPreference<Integer> PROXY_PORT = new IntPreference("proxy_port", 8118).makeGlobal();

View file

@ -266,51 +266,50 @@ public class SettingsGeneralActivity extends SettingsBaseActivity {
} }
protected void enableProxy(boolean enable) {
if (enable) {
NetworkUtils.setProxy(settings.PROXY_HOST.get(), settings.PROXY_PORT.get());
} else {
NetworkUtils.setProxy(null, 0);
}
}
private void addProxyPrefs(PreferenceGroup proxy) { private void addProxyPrefs(PreferenceGroup proxy) {
CheckBoxPreference enableProxyPref = (CheckBoxPreference) proxy.findPreference(settings.ENABLE_PROXY.getId()); CheckBoxPreference enableProxyPref = (CheckBoxPreference) proxy.findPreference("enable_proxy");
enableProxyPref.setOnPreferenceChangeListener(new OnPreferenceChangeListener() { enableProxyPref.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
enableProxy((Boolean) newValue);
return true;
}
@Override });
public boolean onPreferenceChange(Preference preference, Object newValue) {
if ((Boolean) newValue)
NetworkUtils.setProxy(settings.PROXY_HOST.get(), settings.PROXY_PORT.get());
else
NetworkUtils.setProxy(null, 0);
return true;
}
});
EditTextPreference hostPref = (EditTextPreference) proxy.findPreference(settings.PROXY_HOST.getId()); EditTextPreference hostPref = (EditTextPreference) proxy.findPreference(settings.PROXY_HOST.getId());
hostPref.setOnPreferenceChangeListener(new OnPreferenceChangeListener() { hostPref.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
@Override
@Override public boolean onPreferenceChange(Preference preference, Object newValue) {
public boolean onPreferenceChange(Preference preference, Object newValue) { settings.PROXY_HOST.set((String) newValue);
System.out.println("PROXY newValue: " + newValue); enableProxy(NetworkUtils.getProxy() != null);
settings.PROXY_HOST.set((String) newValue); return true;
NetworkUtils.setProxy((String) newValue, settings.PROXY_PORT.get()); }
return true; });
}
});
EditTextPreference portPref = (EditTextPreference) proxy.findPreference(settings.PROXY_PORT.getId()); EditTextPreference portPref = (EditTextPreference) proxy.findPreference(settings.PROXY_PORT.getId());
portPref.setOnPreferenceChangeListener(new OnPreferenceChangeListener() { portPref.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
@Override @Override
public boolean onPreferenceChange(Preference preference, Object newValue) { public boolean onPreferenceChange(Preference preference, Object newValue) {
System.out.println("PROXY newValue: " + newValue); int port = -1;
int port = -1; String portString = (String) newValue;
String portString = (String) newValue; try {
try { port = Integer.valueOf(portString.replaceAll("[^0-9]", ""));
port = Integer.valueOf(portString.replaceAll("[^0-9]", "")); } catch (NumberFormatException e1) {
} catch (NumberFormatException e1) {
}
settings.PROXY_PORT.set(port);
NetworkUtils.setProxy(settings.PROXY_HOST.get(), port);
return true;
} }
}); settings.PROXY_PORT.set(port);
enableProxy(NetworkUtils.getProxy() != null);
return true;
}
});
} }

View file

@ -23,6 +23,7 @@ import net.osmand.util.Algorithms;
import android.app.ActionBar; import android.app.ActionBar;
import android.content.Intent; import android.content.Intent;
import android.graphics.Color; import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle; import android.os.Bundle;
import android.support.v4.app.Fragment; import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager; import android.support.v4.app.FragmentManager;