From e2fecedffa7c23a2c962efaf5bacef46c64c3b7f Mon Sep 17 00:00:00 2001 From: Victor Shcherb Date: Sat, 2 Jul 2016 13:15:00 +0200 Subject: [PATCH] Update search api --- OsmAnd-java/protobuf-src/.gitignore | 1 + OsmAnd-java/protobuf-src/proto_generate.sh | 3 + .../search/example/core/ObjectType.java | 11 ++- .../search/example/core/SearchPhrase.java | 82 ++++++++----------- .../search/example/core/SearchWord.java | 59 +++++++++++++ OsmAndCore-sample/.gitignore | 3 + 6 files changed, 112 insertions(+), 47 deletions(-) create mode 100644 OsmAnd-java/protobuf-src/.gitignore create mode 100755 OsmAnd-java/protobuf-src/proto_generate.sh create mode 100644 OsmAnd-java/src/net/osmand/search/example/core/SearchWord.java diff --git a/OsmAnd-java/protobuf-src/.gitignore b/OsmAnd-java/protobuf-src/.gitignore new file mode 100644 index 0000000000..b0c79cc0ec --- /dev/null +++ b/OsmAnd-java/protobuf-src/.gitignore @@ -0,0 +1 @@ +protobuf diff --git a/OsmAnd-java/protobuf-src/proto_generate.sh b/OsmAnd-java/protobuf-src/proto_generate.sh new file mode 100755 index 0000000000..c3d02b6a9a --- /dev/null +++ b/OsmAnd-java/protobuf-src/proto_generate.sh @@ -0,0 +1,3 @@ +#!/bin/bash +# proto 2.4.1 +protoc --java_out=OsmAnd-java/src --proto_path=$(pwd)/../resources/protos $(pwd)/../resources/protos/OBF.proto diff --git a/OsmAnd-java/src/net/osmand/search/example/core/ObjectType.java b/OsmAnd-java/src/net/osmand/search/example/core/ObjectType.java index e023bcaa8a..bf6b922ab6 100644 --- a/OsmAnd-java/src/net/osmand/search/example/core/ObjectType.java +++ b/OsmAnd-java/src/net/osmand/search/example/core/ObjectType.java @@ -1,5 +1,14 @@ package net.osmand.search.example.core; public enum ObjectType { - CITY, VILLAGE, POSTCODE, STREET, HOUSE, POI_TYPE, POI, LOCATION, NAME_FILTER + CITY(true), VILLAGE(true), POSTCODE(true), STREET(true), HOUSE(true), + POI_TYPE(false), POI(true), LOCATION(true), FAVORITE(true), + RECENT_OBJ(true), WPT(true), NAME_FILTER(false); + private boolean hasLocation; + private ObjectType(boolean location) { + this.hasLocation = location; + } + public boolean hasLocation() { + return hasLocation; + } } diff --git a/OsmAnd-java/src/net/osmand/search/example/core/SearchPhrase.java b/OsmAnd-java/src/net/osmand/search/example/core/SearchPhrase.java index ea07afdaf5..54a9d7e67d 100644 --- a/OsmAnd-java/src/net/osmand/search/example/core/SearchPhrase.java +++ b/OsmAnd-java/src/net/osmand/search/example/core/SearchPhrase.java @@ -10,53 +10,21 @@ import net.osmand.data.LatLon; public class SearchPhrase { - public static class SearchWord { - public String word; - public ObjectType type; - - @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + ((type == null) ? 0 : type.hashCode()); - result = prime * result + ((word == null) ? 0 : word.hashCode()); - return result; - } - - @Override - public boolean equals(Object obj) { - if (this == obj) - return true; - if (obj == null) - return false; - if (getClass() != obj.getClass()) - return false; - SearchWord other = (SearchWord) obj; - if (type != other.type) - return false; - if (word == null) { - if (other.word != null) - return false; - } else if (!word.equals(other.word)) - return false; - return true; - } - - - @Override - public String toString() { - return word; - } + private List words = new ArrayList<>(); + private LatLon originalPhraseLocation; + + public SearchPhrase(LatLon location) { + this.originalPhraseLocation = location; } - public List words = new ArrayList<>(); - - public LatLon myLocationOrVisibleMap = new LatLon(0, 0); + public List getWords() { + return words; + } public List excludefilterWords() { List w = new ArrayList<>(); for(SearchWord s : words) { - if(s.type != ObjectType.NAME_FILTER) { + if(s.getType() != ObjectType.NAME_FILTER) { w.add(s); } } @@ -64,10 +32,19 @@ public class SearchPhrase { } public boolean isLastWord(ObjectType p) { - return true; // TODO + for(int i = words.size() - 1; i >= 0; i--) { + SearchWord sw = words.get(i); + if(sw.getType() == ObjectType.POI) { + return true; + } else if(sw.getType() != ObjectType.NAME_FILTER) { + return false; + } + } + return false; } public StringMatcher getNameStringMatcher() { + // TODO return new CollatorStringMatcher("NameFitler", StringMatcherMode.CHECK_STARTS_FROM_SPACE); } @@ -75,10 +52,17 @@ public class SearchPhrase { return excludefilterWords().equals(p.excludefilterWords()); } + public String getStringRerpresentation() { + StringBuilder sb = new StringBuilder(); + for(SearchWord s : words) { + sb.append(s).append(", "); + } + return sb.toString(); + } + @Override public String toString() { - String w = words.toString(); - return w.substring(1, w.length() - 1); + return getStringRerpresentation(); } public boolean isNoSelectedType() { @@ -86,12 +70,18 @@ public class SearchPhrase { } public boolean isEmpty() { - return false; + return words.isEmpty(); } public LatLon getLastTokenLocation() { + for(int i = words.size() - 1; i >= 0; i--) { + SearchWord sw = words.get(i); + if(sw.getLocation() != null) { + return sw.getLocation(); + } + } // last token or myLocationOrVisibleMap if not selected - return myLocationOrVisibleMap; + return originalPhraseLocation; } } diff --git a/OsmAnd-java/src/net/osmand/search/example/core/SearchWord.java b/OsmAnd-java/src/net/osmand/search/example/core/SearchWord.java new file mode 100644 index 0000000000..0384c19f12 --- /dev/null +++ b/OsmAnd-java/src/net/osmand/search/example/core/SearchWord.java @@ -0,0 +1,59 @@ +package net.osmand.search.example.core; + +import net.osmand.data.LatLon; + +public class SearchWord { + private String word; + private ObjectType type; + private Object internalObject; + private LatLon location; + + public ObjectType getType() { + return type; + } + + public String getWord() { + return word; + } + + public Object getInternalObject() { + return internalObject; + } + + public LatLon getLocation() { + return location; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((type == null) ? 0 : type.hashCode()); + result = prime * result + ((word == null) ? 0 : word.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + SearchWord other = (SearchWord) obj; + if (type != other.type) + return false; + if (word == null) { + if (other.word != null) + return false; + } else if (!word.equals(other.word)) + return false; + return true; + } + + @Override + public String toString() { + return word; + } +} \ No newline at end of file diff --git a/OsmAndCore-sample/.gitignore b/OsmAndCore-sample/.gitignore index 9d3ed1dd63..12af92fed9 100644 --- a/OsmAndCore-sample/.gitignore +++ b/OsmAndCore-sample/.gitignore @@ -2,6 +2,9 @@ /.idea *.iml +gradlew +gradle +gradlew.bat # Gradle .gradle /local.properties