From 68806ded9e9bc49a3b22c58c1c6c4668011e60ef Mon Sep 17 00:00:00 2001 From: Victor Shcherb Date: Wed, 19 Nov 2014 00:47:59 +0100 Subject: [PATCH] Fix search by name --- .gitignore | 1 + OsmAnd-java/build.xml | 3 + .../src/net/osmand/osm/MapPoiTypes.java | 72 +++++++++++++++++++ OsmAnd/build.xml | 3 + OsmAnd/res/layout/search_by_name.xml | 3 +- 5 files changed, 80 insertions(+), 2 deletions(-) create mode 100644 OsmAnd-java/src/net/osmand/osm/MapPoiTypes.java diff --git a/.gitignore b/.gitignore index adc0df64af..427bdce06e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ *.render.xml *.render_template.xml +poi_types.xml *.map_styles_presets.xml routing*.xml rendering_types.xml diff --git a/OsmAnd-java/build.xml b/OsmAnd-java/build.xml index 0b9402e608..2af488526d 100644 --- a/OsmAnd-java/build.xml +++ b/OsmAnd-java/build.xml @@ -43,6 +43,9 @@ + + + diff --git a/OsmAnd-java/src/net/osmand/osm/MapPoiTypes.java b/OsmAnd-java/src/net/osmand/osm/MapPoiTypes.java new file mode 100644 index 0000000000..f1d4e44757 --- /dev/null +++ b/OsmAnd-java/src/net/osmand/osm/MapPoiTypes.java @@ -0,0 +1,72 @@ +package net.osmand.osm; + +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStream; + +import net.osmand.PlatformUtil; + +import org.apache.commons.logging.Log; +import org.xmlpull.v1.XmlPullParser; +import org.xmlpull.v1.XmlPullParserException; + +public class MapPoiTypes { + private static MapPoiTypes DEFAULT_INSTANCE = null; + private static final Log log = PlatformUtil.getLog(MapRenderingTypes.class); + private String resourceName; + + public MapPoiTypes(String fileName){ + this.resourceName = fileName; + } + + public static MapPoiTypes getDefault() { + if(DEFAULT_INSTANCE == null){ + DEFAULT_INSTANCE = new MapPoiTypes(null); + } + return DEFAULT_INSTANCE; + } + + protected void init(){ + InputStream is; + try { + if(resourceName == null){ + is = MapRenderingTypes.class.getResourceAsStream("poi_types.xml"); //$NON-NLS-1$ + } else { + is = new FileInputStream(resourceName); + } + long time = System.currentTimeMillis(); + XmlPullParser parser = PlatformUtil.newXMLPullParser(); + int tok; + parser.setInput(is, "UTF-8"); + String parentCategory = null; + String poiParentCategory = null; + String poiParentPrefix = null; + String order = null; + while ((tok = parser.next()) != XmlPullParser.END_DOCUMENT) { + if (tok == XmlPullParser.START_TAG) { + String name = parser.getName(); + if (name.equals("category")) { //$NON-NLS-1$ + parentCategory = parser.getAttributeValue("","name"); + poiParentCategory = parser.getAttributeValue("","poi_category"); + poiParentPrefix = parser.getAttributeValue("","poi_prefix"); + order = parser.getAttributeValue("","order"); + } + } + } + log.info("Time to init " + (System.currentTimeMillis() - time)); //$NON-NLS-1$ + is.close(); + } catch (IOException e) { + log.error("Unexpected error", e); //$NON-NLS-1$ + e.printStackTrace(); + throw new RuntimeException(e); + } catch (RuntimeException e) { + log.error("Unexpected error", e); //$NON-NLS-1$ + e.printStackTrace(); + throw e; + } catch (XmlPullParserException e) { + log.error("Unexpected error", e); //$NON-NLS-1$ + e.printStackTrace(); + throw new RuntimeException(e); + } + } +} diff --git a/OsmAnd/build.xml b/OsmAnd/build.xml index 7667fda885..df07828b2a 100644 --- a/OsmAnd/build.xml +++ b/OsmAnd/build.xml @@ -97,6 +97,9 @@ + + + diff --git a/OsmAnd/res/layout/search_by_name.xml b/OsmAnd/res/layout/search_by_name.xml index 63694fdaad..f328604317 100644 --- a/OsmAnd/res/layout/search_by_name.xml +++ b/OsmAnd/res/layout/search_by_name.xml @@ -27,8 +27,7 @@ android:id="@+id/SearchText" android:layout_width="wrap_content" android:layout_height="wrap_content" - android:layout_weight="1" - android:inputType="number" /> + android:layout_weight="1"/>