From 4a24787da30fe230b294bcc7975ef35870c9858c Mon Sep 17 00:00:00 2001 From: sergdevosm Date: Sun, 16 Aug 2020 18:02:07 +0300 Subject: [PATCH 1/3] Fix #9532 --- .../net/osmand/search/core/SearchResult.java | 2 +- .../net/osmand/util/GeoPointParserUtil.java | 49 ++++++++++--------- .../osmand/util/GeoPointParserUtilTest.java | 10 ++-- .../search/QuickSearchDialogFragment.java | 4 +- .../plus/search/QuickSearchListFragment.java | 4 +- 5 files changed, 35 insertions(+), 34 deletions(-) diff --git a/OsmAnd-java/src/main/java/net/osmand/search/core/SearchResult.java b/OsmAnd-java/src/main/java/net/osmand/search/core/SearchResult.java index 79d11a3fe0..c716adf1e1 100644 --- a/OsmAnd-java/src/main/java/net/osmand/search/core/SearchResult.java +++ b/OsmAnd-java/src/main/java/net/osmand/search/core/SearchResult.java @@ -32,7 +32,7 @@ public class SearchResult { public double priorityDistance; public LatLon location; - public int preferredZoom = 15; + public double preferredZoom = 15; public String localeName; public String alternateName; diff --git a/OsmAnd-java/src/main/java/net/osmand/util/GeoPointParserUtil.java b/OsmAnd-java/src/main/java/net/osmand/util/GeoPointParserUtil.java index d560d36332..f5e77ad877 100644 --- a/OsmAnd-java/src/main/java/net/osmand/util/GeoPointParserUtil.java +++ b/OsmAnd-java/src/main/java/net/osmand/util/GeoPointParserUtil.java @@ -13,7 +13,7 @@ import java.util.regex.Pattern; public class GeoPointParserUtil { - + private static String getQueryParameter(final String param, URI uri) { final String query = uri.getQuery(); String value = null; @@ -82,7 +82,7 @@ public class GeoPointParserUtil { // amap.com uses | in their URLs, which is an illegal character for a URL uri = URI.create(uriString.replaceAll("\\s+", "+") .replaceAll("%20", "+") - .replaceAll("%2C", ",") + .replaceAll("%2F", ",") .replaceAll("\\|", ";") .replaceAll("\\(\\(\\S+\\)\\)", "")); } catch (IllegalArgumentException e) { @@ -103,7 +103,7 @@ public class GeoPointParserUtil { if(uri.getSchemeSpecificPart() == null) { return null; } else if(!uri.getSchemeSpecificPart().contains("=")) { - params = getQueryParameters("q="+uri.getSchemeSpecificPart()); + params = getQueryParameters("q="+uri.getSchemeSpecificPart()); } else { params = getQueryParameters(uri.getSchemeSpecificPart()); } @@ -142,7 +142,7 @@ public class GeoPointParserUtil { } else { // data in the query and/or feature strings double lat = 0; double lon = 0; - int zoom = GeoParsedPoint.NO_ZOOM; + double zoom = GeoParsedPoint.NO_ZOOM; Map queryMap = getQueryParameters(uri); if (fragment != null) { if (fragment.startsWith("map=")) { @@ -181,13 +181,13 @@ public class GeoPointParserUtil { } } else if (host.startsWith("map.baidu.")) { // .com and .cn both work /* Baidu Map uses a custom format for lat/lon., it is basically standard lat/lon - * multiplied by 100,000, then rounded to an integer */ + * multiplied by 100,000, then rounded to an integer */ String zm = params.get("l"); String[] vls = silentSplit(params.get("c"), ","); if (vls != null && vls.length >= 2) { double lat = parseSilentInt(vls[0]) / 100000.; double lon = parseSilentInt(vls[1]) / 100000.; - int zoom = parseZoom(zm); + double zoom = parseZoom(zm); return new GeoParsedPoint(lat, lon, zoom); } } else if (simpleDomains.contains(host)) { @@ -198,7 +198,7 @@ public class GeoPointParserUtil { if (params.containsKey("lat") && params.containsKey("lon")) { final double lat = parseSilentDouble(params.get("lat")); final double lon = parseSilentDouble(params.get("lon")); - int zoom = GeoParsedPoint.NO_ZOOM; + double zoom = GeoParsedPoint.NO_ZOOM; if (params.containsKey("z")) { zoom = parseZoom(params.get("z")); } else if (params.containsKey("zoom")) { @@ -219,7 +219,7 @@ public class GeoPointParserUtil { String latString = null; String lonString = null; String z = String.valueOf(GeoParsedPoint.NO_ZOOM); - + if (params.containsKey("q")) { System.out.println("q=" + params.get("q")); Matcher matcher = commaSeparatedPairPattern.matcher(params.get("q")); @@ -279,7 +279,7 @@ public class GeoPointParserUtil { Pattern p; Matcher matcher; final String[] patterns = { - /* though this looks like Query String, it is also used as part of the Fragment */ + /* though this looks like Query String, it is also used as part of the Fragment */ ".*q=([+-]?\\d+(?:\\.\\d+)?),([+-]?\\d+(?:\\.\\d+)?).*&radius=(\\d+).*", ".*q=([+-]?\\d+(?:\\.\\d+)?),([+-]?\\d+(?:\\.\\d+)?).*", ".*p=(?:[A-Z0-9]+),([+-]?\\d+(?:\\.\\d+)?),([+-]?\\d+(?:\\.\\d+)?).*",}; @@ -297,7 +297,7 @@ public class GeoPointParserUtil { } } } - } else if (host.equals("here.com") || host.endsWith(".here.com")) { // www.here.com, share.here.com, here.com + } else if (host.equals("here.com") || host.endsWith(".here.com")) { // www.here.com, share.here.com, here.com String z = String.valueOf(GeoParsedPoint.NO_ZOOM); String label = null; if (params.containsKey("msg")) { @@ -459,7 +459,7 @@ public class GeoPointParserUtil { lon = Double.valueOf(positionMatcher.group(2)); } - int zoom = GeoParsedPoint.NO_ZOOM; + double zoom = GeoParsedPoint.NO_ZOOM; String searchRequest = null; for (String param : queryPart.split("&")) { String paramName; @@ -474,7 +474,8 @@ public class GeoPointParserUtil { } if ("z".equals(paramName) && paramValue != null) { - zoom = Integer.parseInt(paramValue); +// zoom = Double.valueOf(paramValue).intValue(); + zoom = Double.valueOf(paramValue); } else if ("q".equals(paramName) && paramValue != null) { searchRequest = URLDecoder.decode(paramValue); } @@ -540,7 +541,7 @@ public class GeoPointParserUtil { if (vls.length >= 2) { double lat = parseSilentDouble(vls[0], Double.NaN); double lon = parseSilentDouble(vls[1], Double.NaN); - int zoom = GeoParsedPoint.NO_ZOOM; + double zoom = GeoParsedPoint.NO_ZOOM; if (vls.length >= 3 || zmPart.length() > 0) { if (zmPart.length() == 0) { zmPart = vls[2]; @@ -566,10 +567,10 @@ public class GeoPointParserUtil { return vl.split(split); } - private static int parseZoom(String zoom) { + private static double parseZoom(String zoom) { try { if (zoom != null) { - return Integer.valueOf(zoom); + return Double.valueOf(zoom); } } catch (NumberFormatException e) { } @@ -579,7 +580,7 @@ public class GeoPointParserUtil { private static double parseSilentDouble(String zoom) { return parseSilentDouble(zoom, 0); } - + private static double parseSilentDouble(String zoom, double vl) { try { if (zoom != null) { @@ -601,11 +602,11 @@ public class GeoPointParserUtil { } public static class GeoParsedPoint { - public static final int NO_ZOOM = -1; + public static final double NO_ZOOM = -1; private double lat = 0; private double lon = 0; - private int zoom = NO_ZOOM; + private double zoom = NO_ZOOM; private String label; private String query; private boolean geoPoint; @@ -624,12 +625,12 @@ public class GeoPointParserUtil { this.label = label.replaceAll("\\+", " "); } - public GeoParsedPoint(double lat, double lon, int zoom) { + public GeoParsedPoint(double lat, double lon, double zoom) { this(lat, lon); this.zoom = zoom; } - public GeoParsedPoint(double lat, double lon, int zoom, String label) { + public GeoParsedPoint(double lat, double lon, double zoom, String label) { this(lat, lon, label); this.zoom = zoom; } @@ -684,7 +685,7 @@ public class GeoPointParserUtil { return lon; } - public int getZoom() { + public double getZoom() { return zoom; } @@ -754,9 +755,9 @@ public class GeoPointParserUtil { @Override public String toString() { - return isGeoPoint() ? - String.format("GeoParsedPoint [lat=%.5f, lon=%.5f, zoom=%d, label=%s]", lat, lon, zoom, label) : - String.format("GeoParsedPoint [query=%s]",query); + return isGeoPoint() ? + String.format("GeoParsedPoint [lat=%.5f, lon=%.5f, zoom=%.5f, label=%s]", lat, lon, zoom, label) : + String.format("GeoParsedPoint [query=%s]",query); } } } diff --git a/OsmAnd-java/src/test/java/net/osmand/util/GeoPointParserUtilTest.java b/OsmAnd-java/src/test/java/net/osmand/util/GeoPointParserUtilTest.java index 206617ab8f..4a5bd723ec 100644 --- a/OsmAnd-java/src/test/java/net/osmand/util/GeoPointParserUtilTest.java +++ b/OsmAnd-java/src/test/java/net/osmand/util/GeoPointParserUtilTest.java @@ -39,7 +39,7 @@ public class GeoPointParserUtilTest { final double dlat = 34.99393, dlon = -106.61568; final double longLat = 34.993933029174805, longLon = -106.615680694580078; final String name = "Treasure Island"; - int z = GeoParsedPoint.NO_ZOOM; + double z = GeoParsedPoint.NO_ZOOM; String url; String noQueryParameters[] = { @@ -63,7 +63,7 @@ public class GeoPointParserUtilTest { "geo:0,0?m", "geo:0,0?m=", "geo:0,0?m=foo", - "geo:0,0?q=%D0%9D%D0", + "geo:0,0?q=%F0%9D%F0", "http://download.osmand.net/go?lat", "http://download.osmand.net/go?lat=", "http://download.osmand.net/go?lat=34.99393", @@ -705,7 +705,7 @@ public class GeoPointParserUtilTest { actual = GeoPointParserUtil.parse(url); assertGeoPoint(actual, new GeoParsedPoint(dlat, dlon, z)); - /* URLs straight from various services, instead of generated here */ + /* URLs straight from various services, instead of generated here */ String urls[] = { "https://openstreetmap.org/go/0LQ127-?m", @@ -789,7 +789,7 @@ public class GeoPointParserUtilTest { actual.getQuery() + "' != '" + expected.getQuery()); } else { double aLat = actual.getLatitude(), eLat = expected.getLatitude(), aLon = actual.getLongitude(), eLon = expected.getLongitude(); - int aZoom = actual.getZoom(), eZoom = expected.getZoom(); + double aZoom = actual.getZoom(), eZoom = expected.getZoom(); String aLabel = actual.getLabel(), eLabel = expected.getLabel(); if (eLabel != null) { if (!aLabel.equals(eLabel)) { @@ -816,7 +816,7 @@ public class GeoPointParserUtilTest { throw new RuntimeException("Query param not equal"); } else { double aLat = actual.getLatitude(), eLat = expected.getLatitude(), aLon = actual.getLongitude(), eLon = expected.getLongitude(); - int aZoom = actual.getZoom(), eZoom = expected.getZoom(); + double aZoom = actual.getZoom(), eZoom = expected.getZoom(); String aLabel = actual.getLabel(), eLabel = expected.getLabel(); if (eLabel != null) { if (!aLabel.equals(eLabel)) { diff --git a/OsmAnd/src/net/osmand/plus/search/QuickSearchDialogFragment.java b/OsmAnd/src/net/osmand/plus/search/QuickSearchDialogFragment.java index 5be1d95cee..a71b74f8a4 100644 --- a/OsmAnd/src/net/osmand/plus/search/QuickSearchDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/search/QuickSearchDialogFragment.java @@ -414,7 +414,7 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC PointDescription pointDescription = new PointDescription(PointDescription.POINT_TYPE_ADDRESS, typeName, name); app.getSettings().setMapLocationToShow( searchResult.location.getLatitude(), searchResult.location.getLongitude(), - searchResult.preferredZoom, pointDescription, true, searchResult.object); + (int) searchResult.preferredZoom, pointDescription, true, searchResult.object); hideToolbar(); MapActivity.launchMapActivityMoveToTop(getActivity()); @@ -444,7 +444,7 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC hide(); } else if (group.getPoints().size() == 1) { FavouritePoint p = group.getPoints().get(0); - app.getSettings().setMapLocationToShow(p.getLatitude(), p.getLongitude(), word.getResult().preferredZoom); + app.getSettings().setMapLocationToShow(p.getLatitude(), p.getLongitude(), (int) word.getResult().preferredZoom); hideToolbar(); MapActivity.launchMapActivityMoveToTop(getActivity()); hide(); diff --git a/OsmAnd/src/net/osmand/plus/search/QuickSearchListFragment.java b/OsmAnd/src/net/osmand/plus/search/QuickSearchListFragment.java index 3b10b03b49..2dc07af2cb 100644 --- a/OsmAnd/src/net/osmand/plus/search/QuickSearchListFragment.java +++ b/OsmAnd/src/net/osmand/plus/search/QuickSearchListFragment.java @@ -260,7 +260,7 @@ public abstract class QuickSearchListFragment extends OsmAndListFragment { showOnMap(getMapActivity(), dialogFragment, searchResult.location.getLatitude(), searchResult.location.getLongitude(), - searchResult.preferredZoom, pointDescription, object); + (int) searchResult.preferredZoom, pointDescription, object); } } @@ -307,7 +307,7 @@ public abstract class QuickSearchListFragment extends OsmAndListFragment { int position = getListView().getPositionForView(selected); if ((position != AdapterView.INVALID_POSITION) && (position >= getListView().getHeaderViewsCount())) { dialogFragment.getNavigationInfo().updateTargetDirection( - listAdapter.getItem(position - getListView().getHeaderViewsCount()).getSearchResult().location, + listAdapter.getItem(position - getListView().getHeaderViewsCount()).getSearchResult().location, heading.floatValue()); } } catch (Exception e) { From 274760e9d251eb30d4d04a38e78d5a2c0a5c1a3e Mon Sep 17 00:00:00 2001 From: sergdevosm Date: Wed, 19 Aug 2020 21:40:58 +0300 Subject: [PATCH 2/3] Fix #9532 --- .../osmand/search/core/SearchCoreFactory.java | 2 +- .../net/osmand/search/core/SearchResult.java | 3 +- .../net/osmand/util/GeoPointParserUtil.java | 30 +++++++++---------- .../osmand/util/GeoPointParserUtilTest.java | 2 +- 4 files changed, 19 insertions(+), 18 deletions(-) diff --git a/OsmAnd-java/src/main/java/net/osmand/search/core/SearchCoreFactory.java b/OsmAnd-java/src/main/java/net/osmand/search/core/SearchCoreFactory.java index fa600cee80..d9bef77fc2 100644 --- a/OsmAnd-java/src/main/java/net/osmand/search/core/SearchCoreFactory.java +++ b/OsmAnd-java/src/main/java/net/osmand/search/core/SearchCoreFactory.java @@ -1527,7 +1527,7 @@ public class SearchCoreFactory { sp.location = new LatLon(pnt.getLatitude(), pnt.getLongitude()); sp.localeName = ((float)pnt.getLatitude()) +", " + ((float) pnt.getLongitude()); if (pnt.getZoom() > 0) { - sp.preferredZoom = pnt.getZoom(); + sp.preferredZoom = (int) pnt.getZoom(); } sp.objectType = ObjectType.LOCATION; resultMatcher.publish(sp); diff --git a/OsmAnd-java/src/main/java/net/osmand/search/core/SearchResult.java b/OsmAnd-java/src/main/java/net/osmand/search/core/SearchResult.java index c716adf1e1..d84ef029f0 100644 --- a/OsmAnd-java/src/main/java/net/osmand/search/core/SearchResult.java +++ b/OsmAnd-java/src/main/java/net/osmand/search/core/SearchResult.java @@ -32,7 +32,8 @@ public class SearchResult { public double priorityDistance; public LatLon location; - public double preferredZoom = 15; + public float pZ = 15; + public int preferredZoom = Math.round(pZ); public String localeName; public String alternateName; diff --git a/OsmAnd-java/src/main/java/net/osmand/util/GeoPointParserUtil.java b/OsmAnd-java/src/main/java/net/osmand/util/GeoPointParserUtil.java index f5e77ad877..3248f7ca05 100644 --- a/OsmAnd-java/src/main/java/net/osmand/util/GeoPointParserUtil.java +++ b/OsmAnd-java/src/main/java/net/osmand/util/GeoPointParserUtil.java @@ -142,7 +142,7 @@ public class GeoPointParserUtil { } else { // data in the query and/or feature strings double lat = 0; double lon = 0; - double zoom = GeoParsedPoint.NO_ZOOM; + float zoom = GeoParsedPoint.NO_ZOOM; Map queryMap = getQueryParameters(uri); if (fragment != null) { if (fragment.startsWith("map=")) { @@ -187,7 +187,7 @@ public class GeoPointParserUtil { if (vls != null && vls.length >= 2) { double lat = parseSilentInt(vls[0]) / 100000.; double lon = parseSilentInt(vls[1]) / 100000.; - double zoom = parseZoom(zm); + float zoom = parseZoom(zm); return new GeoParsedPoint(lat, lon, zoom); } } else if (simpleDomains.contains(host)) { @@ -198,11 +198,11 @@ public class GeoPointParserUtil { if (params.containsKey("lat") && params.containsKey("lon")) { final double lat = parseSilentDouble(params.get("lat")); final double lon = parseSilentDouble(params.get("lon")); - double zoom = GeoParsedPoint.NO_ZOOM; + float zoom = GeoParsedPoint.NO_ZOOM; if (params.containsKey("z")) { - zoom = parseZoom(params.get("z")); + zoom = (float) parseZoom(params.get("z")); } else if (params.containsKey("zoom")) { - zoom = parseZoom(params.get("zoom")); + zoom = (float) parseZoom(params.get("zoom")); } return new GeoParsedPoint(lat, lon, zoom); } @@ -459,7 +459,7 @@ public class GeoPointParserUtil { lon = Double.valueOf(positionMatcher.group(2)); } - double zoom = GeoParsedPoint.NO_ZOOM; + float zoom = GeoParsedPoint.NO_ZOOM; String searchRequest = null; for (String param : queryPart.split("&")) { String paramName; @@ -475,7 +475,7 @@ public class GeoPointParserUtil { if ("z".equals(paramName) && paramValue != null) { // zoom = Double.valueOf(paramValue).intValue(); - zoom = Double.valueOf(paramValue); + zoom = Float.valueOf(paramValue); } else if ("q".equals(paramName) && paramValue != null) { searchRequest = URLDecoder.decode(paramValue); } @@ -541,7 +541,7 @@ public class GeoPointParserUtil { if (vls.length >= 2) { double lat = parseSilentDouble(vls[0], Double.NaN); double lon = parseSilentDouble(vls[1], Double.NaN); - double zoom = GeoParsedPoint.NO_ZOOM; + float zoom = GeoParsedPoint.NO_ZOOM; if (vls.length >= 3 || zmPart.length() > 0) { if (zmPart.length() == 0) { zmPart = vls[2]; @@ -567,10 +567,10 @@ public class GeoPointParserUtil { return vl.split(split); } - private static double parseZoom(String zoom) { + private static float parseZoom(String zoom) { try { if (zoom != null) { - return Double.valueOf(zoom); + return Float.valueOf(zoom); } } catch (NumberFormatException e) { } @@ -584,7 +584,7 @@ public class GeoPointParserUtil { private static double parseSilentDouble(String zoom, double vl) { try { if (zoom != null) { - return Double.valueOf(zoom); + return Float.valueOf(zoom); } } catch (NumberFormatException e) { } @@ -602,11 +602,11 @@ public class GeoPointParserUtil { } public static class GeoParsedPoint { - public static final double NO_ZOOM = -1; + public static final float NO_ZOOM = -1; private double lat = 0; private double lon = 0; - private double zoom = NO_ZOOM; + private float zoom = NO_ZOOM; private String label; private String query; private boolean geoPoint; @@ -625,12 +625,12 @@ public class GeoPointParserUtil { this.label = label.replaceAll("\\+", " "); } - public GeoParsedPoint(double lat, double lon, double zoom) { + public GeoParsedPoint(double lat, double lon, float zoom) { this(lat, lon); this.zoom = zoom; } - public GeoParsedPoint(double lat, double lon, double zoom, String label) { + public GeoParsedPoint(double lat, double lon, float zoom, String label) { this(lat, lon, label); this.zoom = zoom; } diff --git a/OsmAnd-java/src/test/java/net/osmand/util/GeoPointParserUtilTest.java b/OsmAnd-java/src/test/java/net/osmand/util/GeoPointParserUtilTest.java index 4a5bd723ec..9c642788b2 100644 --- a/OsmAnd-java/src/test/java/net/osmand/util/GeoPointParserUtilTest.java +++ b/OsmAnd-java/src/test/java/net/osmand/util/GeoPointParserUtilTest.java @@ -39,7 +39,7 @@ public class GeoPointParserUtilTest { final double dlat = 34.99393, dlon = -106.61568; final double longLat = 34.993933029174805, longLon = -106.615680694580078; final String name = "Treasure Island"; - double z = GeoParsedPoint.NO_ZOOM; + float z = GeoParsedPoint.NO_ZOOM; String url; String noQueryParameters[] = { From 9dbcf312df815a6e59d9e133f2644d16b81155c3 Mon Sep 17 00:00:00 2001 From: sergdevosm Date: Thu, 20 Aug 2020 21:07:51 +0300 Subject: [PATCH 3/3] Casting to an int implicitly --- .../osmand/search/core/SearchCoreFactory.java | 82 +++++++++---------- .../net/osmand/search/core/SearchResult.java | 3 +- .../net/osmand/util/GeoPointParserUtil.java | 37 ++++----- .../osmand/util/GeoPointParserUtilTest.java | 8 +- .../search/QuickSearchDialogFragment.java | 4 +- .../plus/search/QuickSearchListFragment.java | 2 +- 6 files changed, 67 insertions(+), 69 deletions(-) diff --git a/OsmAnd-java/src/main/java/net/osmand/search/core/SearchCoreFactory.java b/OsmAnd-java/src/main/java/net/osmand/search/core/SearchCoreFactory.java index d9bef77fc2..a4916d4187 100644 --- a/OsmAnd-java/src/main/java/net/osmand/search/core/SearchCoreFactory.java +++ b/OsmAnd-java/src/main/java/net/osmand/search/core/SearchCoreFactory.java @@ -133,19 +133,19 @@ public class SearchCoreFactory { public int getMinimalSearchRadius(SearchPhrase phrase) { return 0; } - + @Override public int getNextSearchRadius(SearchPhrase phrase) { return 0; } - protected void subSearchApiOrPublish(SearchPhrase phrase, SearchResultMatcher resultMatcher, SearchResult res, SearchBaseAPI api) + protected void subSearchApiOrPublish(SearchPhrase phrase, SearchResultMatcher resultMatcher, SearchResult res, SearchBaseAPI api) throws IOException { subSearchApiOrPublish(phrase, resultMatcher, res, api, true); } - + protected void subSearchApiOrPublish(SearchPhrase phrase, SearchResultMatcher resultMatcher, SearchResult res, SearchBaseAPI api, - boolean publish) + boolean publish) throws IOException { phrase.countUnknownWordsMatchMainResult(res); boolean firstUnknownWordMatches = res.firstUnknownWordMatches; @@ -154,7 +154,7 @@ public class SearchCoreFactory { leftUnknownSearchWords.removeAll(res.otherWordsMatch); } SearchResult newParentSearchResult = null; - if (res.parentSearchResult == null && resultMatcher.getParentSearchResult() == null && + if (res.parentSearchResult == null && resultMatcher.getParentSearchResult() == null && res.objectType == ObjectType.STREET && res.object instanceof Street && ((Street) res.object).getCity() != null) { City ct = ((Street) res.object).getCity(); SearchResult cityResult = new SearchResult(phrase); @@ -204,15 +204,15 @@ public class SearchCoreFactory { } } if (!leftUnknownSearchWords.isEmpty() && api != null && api.isSearchAvailable(phrase)) { - SearchPhrase nphrase = phrase.selectWord(res, leftUnknownSearchWords, - phrase.isLastUnknownSearchWordComplete() || - !leftUnknownSearchWords.contains(phrase.getLastUnknownSearchWord())); - SearchResult prev = resultMatcher.setParentSearchResult(publish ? res : - resultMatcher.getParentSearchResult()); + SearchPhrase nphrase = phrase.selectWord(res, leftUnknownSearchWords, + phrase.isLastUnknownSearchWordComplete() || + !leftUnknownSearchWords.contains(phrase.getLastUnknownSearchWord())); + SearchResult prev = resultMatcher.setParentSearchResult(publish ? res : + resultMatcher.getParentSearchResult()); api.search(nphrase, resultMatcher); resultMatcher.setParentSearchResult(prev); } - + } @Override @@ -307,7 +307,7 @@ public class SearchCoreFactory { public int getMinimalSearchRadius(SearchPhrase phrase) { return phrase.getRadiusSearch(DEFAULT_ADDRESS_BBOX_RADIUS); } - + @Override public int getNextSearchRadius(SearchPhrase phrase) { return phrase.getNextRadiusSearch(DEFAULT_ADDRESS_BBOX_RADIUS); @@ -383,7 +383,7 @@ public class SearchCoreFactory { private void searchByName(final SearchPhrase phrase, final SearchResultMatcher resultMatcher) throws IOException { - if (phrase.getRadiusLevel() > 1 || phrase.getUnknownWordToSearch().length() > 3 || + if (phrase.getRadiusLevel() > 1 || phrase.getUnknownWordToSearch().length() > 3 || phrase.hasMoreThanOneUnknownSearchWord()|| phrase.isSearchTypeAllowed(ObjectType.POSTCODE, true)) { final boolean locSpecified = phrase.getLastTokenLocation() != null; LatLon loc = phrase.getLastTokenLocation(); @@ -424,7 +424,7 @@ public class SearchCoreFactory { if (object.getName().startsWith("<")) { return false; } - + if (!phrase.getUnknownWordToSearchBuildingNameMatcher().matches(stripBraces(sr.localeName))) { sr.priorityDistance = 5; } @@ -558,7 +558,7 @@ public class SearchCoreFactory { } // Take into account POI [bar] - 'Hospital 512' // BEFORE: it was searching exact match of whole phrase.getUnknownSearchPhrase() [ Check feedback ] - + final BinaryMapIndexReader[] currentFile = new BinaryMapIndexReader[1]; Iterator offlineIterator = phrase.getRadiusOfflineIndexes(BBOX_RADIUS, SearchPhraseDataType.POI); @@ -670,7 +670,7 @@ public class SearchCoreFactory { return phrase.getNextRadiusSearch(BBOX_RADIUS); } } - + protected static class PoiTypeResult { public AbstractPoiType pt; public Set foundWords = new LinkedHashSet(); @@ -709,7 +709,7 @@ public class SearchCoreFactory { this.activePoiFilters.put(filterOrder.get(i), i); } } - + public Map getPoiTypeResults(NameStringMatcher nm, NameStringMatcher nmAdditional) { Map results = new LinkedHashMap<>(); for (AbstractPoiType pf : topVisibleFilters) { @@ -764,7 +764,7 @@ public class SearchCoreFactory { } else { String enTranslation = a.getEnTranslation().toLowerCase(); if (!"no".equals(enTranslation) // && !"yes".equals(enTranslation) - ) { + ) { PoiTypeResult ptr = checkPoiType(nm, a); if (ptr != null) { results.put(a.getKeyName(), ptr); @@ -816,12 +816,12 @@ public class SearchCoreFactory { categories = types.getCategories(false); } } - + @Override public boolean search(SearchPhrase phrase, SearchResultMatcher resultMatcher) throws IOException { boolean showTopFiltersOnly = !phrase.isUnknownSearchWordPresent(); NameStringMatcher nm = phrase.getFirstUnknownNameStringMatcher(); - + initPoiTypes(); if (showTopFiltersOnly) { for (AbstractPoiType pt : topVisibleFilters) { @@ -830,10 +830,10 @@ public class SearchCoreFactory { res.object = pt; addPoiTypeResult(phrase, resultMatcher, showTopFiltersOnly, getStandardFilterId(pt), res); } - + } else { boolean includeAdditional = !phrase.hasMoreThanOneUnknownSearchWord(); - NameStringMatcher nmAdditional = includeAdditional ? + NameStringMatcher nmAdditional = includeAdditional ? new NameStringMatcher(phrase.getFirstUnknownSearchWord(), StringMatcherMode.CHECK_EQUALS_FROM_SPACE) : null; Map poiTypes = getPoiTypeResults(nm, nmAdditional); for (PoiTypeResult ptr : poiTypes.values()) { @@ -869,7 +869,7 @@ public class SearchCoreFactory { } private void addPoiTypeResult(SearchPhrase phrase, SearchResultMatcher resultMatcher, boolean showTopFiltersOnly, - String stdFilterId, SearchResult res) { + String stdFilterId, SearchResult res) { res.priorityDistance = 0; res.objectType = ObjectType.POI_TYPE; res.firstUnknownWordMatches = true; @@ -893,7 +893,7 @@ public class SearchCoreFactory { return SEARCH_AMENITY_TYPE_PRIORITY + i.intValue(); } - + public String getStandardFilterId(AbstractPoiType poi) { return STD_POI_FILTER_PREFIX + poi.getKeyName(); @@ -926,7 +926,7 @@ public class SearchCoreFactory { private MapPoiTypes types; private AbstractPoiType unselectedPoiType; private String nameFilter; - + public SearchAmenityByTypeAPI(MapPoiTypes types, SearchAmenityTypesAPI searchAmenityTypesAPI) { super(ObjectType.POI); this.types = types; @@ -975,7 +975,7 @@ public class SearchCoreFactory { nameFilter = phrase.getUnknownSearchPhrase(); } else if (searchAmenityTypesAPI != null && phrase.isFirstUnknownSearchWordComplete()) { NameStringMatcher nm = phrase.getFirstUnknownNameStringMatcher(); - NameStringMatcher nmAdditional = new NameStringMatcher(phrase.getFirstUnknownSearchWord(), + NameStringMatcher nmAdditional = new NameStringMatcher(phrase.getFirstUnknownSearchWord(), StringMatcherMode.CHECK_EQUALS_FROM_SPACE) ; searchAmenityTypesAPI.initPoiTypes(); Map poiTypeResults = searchAmenityTypesAPI.getPoiTypeResults(nm, nmAdditional); @@ -1010,7 +1010,7 @@ public class SearchCoreFactory { List offlineIndexes = phrase.getOfflineIndexes(); Set searchedPois = new TreeSet<>(); for (BinaryMapIndexReader r : offlineIndexes) { - ResultMatcher rm = getResultMatcher(phrase, poiTypeFilter, resultMatcher, nameFilter, r, + ResultMatcher rm = getResultMatcher(phrase, poiTypeFilter, resultMatcher, nameFilter, r, searchedPois, poiAdditionals, countExtraWords); if (poiTypeFilter instanceof CustomSearchPoiFilter) { rm = ((CustomSearchPoiFilter) poiTypeFilter).wrapResultMatcher(rm); @@ -1025,12 +1025,12 @@ public class SearchCoreFactory { } - private ResultMatcher getResultMatcher(final SearchPhrase phrase, final SearchPoiTypeFilter poiTypeFilter, - final SearchResultMatcher resultMatcher, final String nameFilter, + private ResultMatcher getResultMatcher(final SearchPhrase phrase, final SearchPoiTypeFilter poiTypeFilter, + final SearchResultMatcher resultMatcher, final String nameFilter, final BinaryMapIndexReader selected, final Set searchedPois, final Collection poiAdditionals, final int countExtraWords) { - - + + final NameStringMatcher ns = nameFilter == null ? null : new NameStringMatcher(nameFilter, StringMatcherMode.CHECK_STARTS_FROM_SPACE); return new ResultMatcher() { @@ -1186,7 +1186,7 @@ public class SearchCoreFactory { NameStringMatcher nm = phrase.getMainUnknownNameStringMatcher(); for (Street object : c.getStreets()) { SearchResult res = new SearchResult(phrase); - + res.localeName = object.getName(phrase.getSettings().getLang(), phrase.getSettings().isTransliterate()); res.otherNames = object.getAllNames(true); boolean pub = true; @@ -1266,7 +1266,7 @@ public class SearchCoreFactory { if (s != null) { BinaryMapIndexReader file = phrase.getLastSelectedWord().getResult().file; - + if (cacheBuilding != s) { cacheBuilding = s; SearchRequest sr = BinaryMapIndexReader @@ -1325,13 +1325,13 @@ public class SearchCoreFactory { res.location = b.getLocation(); } res.preferredZoom = 17; - + resultMatcher.publish(res); } String streetIntersection = phrase.getUnknownWordToSearch(); NameStringMatcher streetMatch = phrase.getMainUnknownNameStringMatcher(); - if (Algorithms.isEmpty(streetIntersection) || - (!Character.isDigit(streetIntersection.charAt(0)) && + if (Algorithms.isEmpty(streetIntersection) || + (!Character.isDigit(streetIntersection.charAt(0)) && CommonWords.getCommonSearch(streetIntersection) == -1) ) { for (Street street : s.getIntersectedStreets()) { SearchResult res = new SearchResult(phrase); @@ -1369,7 +1369,7 @@ public class SearchCoreFactory { return SEARCH_BUILDING_BY_STREET_PRIORITY; } } - + protected static class PoiAdditionalCustomFilter extends AbstractPoiType { protected List additionalPoiTypes = new ArrayList(); @@ -1378,7 +1378,7 @@ public class SearchCoreFactory { super(pt.getKeyName(), registry); additionalPoiTypes.add(pt); } - + @Override public boolean isAdditional() { return true; @@ -1397,7 +1397,7 @@ public class SearchCoreFactory { } return acceptedTypes; } - + } public static class SearchLocationAndUrlAPI extends SearchBaseAPI { @@ -1527,7 +1527,7 @@ public class SearchCoreFactory { sp.location = new LatLon(pnt.getLatitude(), pnt.getLongitude()); sp.localeName = ((float)pnt.getLatitude()) +", " + ((float) pnt.getLongitude()); if (pnt.getZoom() > 0) { - sp.preferredZoom = (int) pnt.getZoom(); + sp.preferredZoom = pnt.getZoom(); } sp.objectType = ObjectType.LOCATION; resultMatcher.publish(sp); @@ -1569,7 +1569,7 @@ public class SearchCoreFactory { } return retName; } - + public static boolean isLastWordCityGroup(SearchPhrase p ) { return p.isLastWord(ObjectType.CITY) || p.isLastWord(ObjectType.POSTCODE) || p.isLastWord(ObjectType.VILLAGE); diff --git a/OsmAnd-java/src/main/java/net/osmand/search/core/SearchResult.java b/OsmAnd-java/src/main/java/net/osmand/search/core/SearchResult.java index d84ef029f0..79d11a3fe0 100644 --- a/OsmAnd-java/src/main/java/net/osmand/search/core/SearchResult.java +++ b/OsmAnd-java/src/main/java/net/osmand/search/core/SearchResult.java @@ -32,8 +32,7 @@ public class SearchResult { public double priorityDistance; public LatLon location; - public float pZ = 15; - public int preferredZoom = Math.round(pZ); + public int preferredZoom = 15; public String localeName; public String alternateName; diff --git a/OsmAnd-java/src/main/java/net/osmand/util/GeoPointParserUtil.java b/OsmAnd-java/src/main/java/net/osmand/util/GeoPointParserUtil.java index 3248f7ca05..b82a2cbedb 100644 --- a/OsmAnd-java/src/main/java/net/osmand/util/GeoPointParserUtil.java +++ b/OsmAnd-java/src/main/java/net/osmand/util/GeoPointParserUtil.java @@ -82,7 +82,7 @@ public class GeoPointParserUtil { // amap.com uses | in their URLs, which is an illegal character for a URL uri = URI.create(uriString.replaceAll("\\s+", "+") .replaceAll("%20", "+") - .replaceAll("%2F", ",") + .replaceAll("%2C", ",") .replaceAll("\\|", ";") .replaceAll("\\(\\(\\S+\\)\\)", "")); } catch (IllegalArgumentException e) { @@ -142,7 +142,7 @@ public class GeoPointParserUtil { } else { // data in the query and/or feature strings double lat = 0; double lon = 0; - float zoom = GeoParsedPoint.NO_ZOOM; + int zoom = GeoParsedPoint.NO_ZOOM; Map queryMap = getQueryParameters(uri); if (fragment != null) { if (fragment.startsWith("map=")) { @@ -187,7 +187,7 @@ public class GeoPointParserUtil { if (vls != null && vls.length >= 2) { double lat = parseSilentInt(vls[0]) / 100000.; double lon = parseSilentInt(vls[1]) / 100000.; - float zoom = parseZoom(zm); + int zoom = parseZoom(zm); return new GeoParsedPoint(lat, lon, zoom); } } else if (simpleDomains.contains(host)) { @@ -198,11 +198,11 @@ public class GeoPointParserUtil { if (params.containsKey("lat") && params.containsKey("lon")) { final double lat = parseSilentDouble(params.get("lat")); final double lon = parseSilentDouble(params.get("lon")); - float zoom = GeoParsedPoint.NO_ZOOM; + int zoom = GeoParsedPoint.NO_ZOOM; if (params.containsKey("z")) { - zoom = (float) parseZoom(params.get("z")); + zoom = parseZoom(params.get("z")); } else if (params.containsKey("zoom")) { - zoom = (float) parseZoom(params.get("zoom")); + zoom = parseZoom(params.get("zoom")); } return new GeoParsedPoint(lat, lon, zoom); } @@ -459,7 +459,7 @@ public class GeoPointParserUtil { lon = Double.valueOf(positionMatcher.group(2)); } - float zoom = GeoParsedPoint.NO_ZOOM; + int zoom = GeoParsedPoint.NO_ZOOM; String searchRequest = null; for (String param : queryPart.split("&")) { String paramName; @@ -474,8 +474,7 @@ public class GeoPointParserUtil { } if ("z".equals(paramName) && paramValue != null) { -// zoom = Double.valueOf(paramValue).intValue(); - zoom = Float.valueOf(paramValue); + zoom = (int) Float.parseFloat(paramValue); } else if ("q".equals(paramName) && paramValue != null) { searchRequest = URLDecoder.decode(paramValue); } @@ -541,7 +540,7 @@ public class GeoPointParserUtil { if (vls.length >= 2) { double lat = parseSilentDouble(vls[0], Double.NaN); double lon = parseSilentDouble(vls[1], Double.NaN); - float zoom = GeoParsedPoint.NO_ZOOM; + int zoom = GeoParsedPoint.NO_ZOOM; if (vls.length >= 3 || zmPart.length() > 0) { if (zmPart.length() == 0) { zmPart = vls[2]; @@ -567,10 +566,10 @@ public class GeoPointParserUtil { return vl.split(split); } - private static float parseZoom(String zoom) { + private static int parseZoom(String zoom) { try { if (zoom != null) { - return Float.valueOf(zoom); + return (int) Float.parseFloat(zoom); } } catch (NumberFormatException e) { } @@ -584,7 +583,7 @@ public class GeoPointParserUtil { private static double parseSilentDouble(String zoom, double vl) { try { if (zoom != null) { - return Float.valueOf(zoom); + return Double.valueOf(zoom); } } catch (NumberFormatException e) { } @@ -602,11 +601,11 @@ public class GeoPointParserUtil { } public static class GeoParsedPoint { - public static final float NO_ZOOM = -1; + public static final int NO_ZOOM = -1; private double lat = 0; private double lon = 0; - private float zoom = NO_ZOOM; + private int zoom = NO_ZOOM; private String label; private String query; private boolean geoPoint; @@ -625,12 +624,12 @@ public class GeoPointParserUtil { this.label = label.replaceAll("\\+", " "); } - public GeoParsedPoint(double lat, double lon, float zoom) { + public GeoParsedPoint(double lat, double lon, int zoom) { this(lat, lon); this.zoom = zoom; } - public GeoParsedPoint(double lat, double lon, float zoom, String label) { + public GeoParsedPoint(double lat, double lon, int zoom, String label) { this(lat, lon, label); this.zoom = zoom; } @@ -685,7 +684,7 @@ public class GeoPointParserUtil { return lon; } - public double getZoom() { + public int getZoom() { return zoom; } @@ -756,7 +755,7 @@ public class GeoPointParserUtil { @Override public String toString() { return isGeoPoint() ? - String.format("GeoParsedPoint [lat=%.5f, lon=%.5f, zoom=%.5f, label=%s]", lat, lon, zoom, label) : + String.format("GeoParsedPoint [lat=%.5f, lon=%.5f, zoom=%d, label=%s]", lat, lon, zoom, label) : String.format("GeoParsedPoint [query=%s]",query); } } diff --git a/OsmAnd-java/src/test/java/net/osmand/util/GeoPointParserUtilTest.java b/OsmAnd-java/src/test/java/net/osmand/util/GeoPointParserUtilTest.java index 9c642788b2..5b1db95e17 100644 --- a/OsmAnd-java/src/test/java/net/osmand/util/GeoPointParserUtilTest.java +++ b/OsmAnd-java/src/test/java/net/osmand/util/GeoPointParserUtilTest.java @@ -39,7 +39,7 @@ public class GeoPointParserUtilTest { final double dlat = 34.99393, dlon = -106.61568; final double longLat = 34.993933029174805, longLon = -106.615680694580078; final String name = "Treasure Island"; - float z = GeoParsedPoint.NO_ZOOM; + int z = GeoParsedPoint.NO_ZOOM; String url; String noQueryParameters[] = { @@ -63,7 +63,7 @@ public class GeoPointParserUtilTest { "geo:0,0?m", "geo:0,0?m=", "geo:0,0?m=foo", - "geo:0,0?q=%F0%9D%F0", + "geo:0,0?q=%D0%9D%D0", "http://download.osmand.net/go?lat", "http://download.osmand.net/go?lat=", "http://download.osmand.net/go?lat=34.99393", @@ -789,7 +789,7 @@ public class GeoPointParserUtilTest { actual.getQuery() + "' != '" + expected.getQuery()); } else { double aLat = actual.getLatitude(), eLat = expected.getLatitude(), aLon = actual.getLongitude(), eLon = expected.getLongitude(); - double aZoom = actual.getZoom(), eZoom = expected.getZoom(); + int aZoom = actual.getZoom(), eZoom = expected.getZoom(); String aLabel = actual.getLabel(), eLabel = expected.getLabel(); if (eLabel != null) { if (!aLabel.equals(eLabel)) { @@ -816,7 +816,7 @@ public class GeoPointParserUtilTest { throw new RuntimeException("Query param not equal"); } else { double aLat = actual.getLatitude(), eLat = expected.getLatitude(), aLon = actual.getLongitude(), eLon = expected.getLongitude(); - double aZoom = actual.getZoom(), eZoom = expected.getZoom(); + int aZoom = actual.getZoom(), eZoom = expected.getZoom(); String aLabel = actual.getLabel(), eLabel = expected.getLabel(); if (eLabel != null) { if (!aLabel.equals(eLabel)) { diff --git a/OsmAnd/src/net/osmand/plus/search/QuickSearchDialogFragment.java b/OsmAnd/src/net/osmand/plus/search/QuickSearchDialogFragment.java index a71b74f8a4..5be1d95cee 100644 --- a/OsmAnd/src/net/osmand/plus/search/QuickSearchDialogFragment.java +++ b/OsmAnd/src/net/osmand/plus/search/QuickSearchDialogFragment.java @@ -414,7 +414,7 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC PointDescription pointDescription = new PointDescription(PointDescription.POINT_TYPE_ADDRESS, typeName, name); app.getSettings().setMapLocationToShow( searchResult.location.getLatitude(), searchResult.location.getLongitude(), - (int) searchResult.preferredZoom, pointDescription, true, searchResult.object); + searchResult.preferredZoom, pointDescription, true, searchResult.object); hideToolbar(); MapActivity.launchMapActivityMoveToTop(getActivity()); @@ -444,7 +444,7 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC hide(); } else if (group.getPoints().size() == 1) { FavouritePoint p = group.getPoints().get(0); - app.getSettings().setMapLocationToShow(p.getLatitude(), p.getLongitude(), (int) word.getResult().preferredZoom); + app.getSettings().setMapLocationToShow(p.getLatitude(), p.getLongitude(), word.getResult().preferredZoom); hideToolbar(); MapActivity.launchMapActivityMoveToTop(getActivity()); hide(); diff --git a/OsmAnd/src/net/osmand/plus/search/QuickSearchListFragment.java b/OsmAnd/src/net/osmand/plus/search/QuickSearchListFragment.java index 2dc07af2cb..f667595650 100644 --- a/OsmAnd/src/net/osmand/plus/search/QuickSearchListFragment.java +++ b/OsmAnd/src/net/osmand/plus/search/QuickSearchListFragment.java @@ -260,7 +260,7 @@ public abstract class QuickSearchListFragment extends OsmAndListFragment { showOnMap(getMapActivity(), dialogFragment, searchResult.location.getLatitude(), searchResult.location.getLongitude(), - (int) searchResult.preferredZoom, pointDescription, object); + searchResult.preferredZoom, pointDescription, object); } }