From db1ed9cc4186111e5ab754542349aedf6340913c Mon Sep 17 00:00:00 2001 From: Alexey Kulish Date: Sat, 18 Jun 2016 11:03:12 +0300 Subject: [PATCH] Rearrange classes in Core sample --- .../samples/android/sample1/MainActivity.java | 9 +- .../AmenitySearchListItem.java | 4 +- .../SearchListAdapter.java | 2 +- .../{search => adapters}/SearchListItem.java | 6 +- .../sample1/search/AmenitySearchItem.java | 91 +++++++++++++ .../android/sample1/search/SearchAPI.java | 125 ------------------ .../android/sample1/search/SearchItem.java | 39 ++++++ 7 files changed, 141 insertions(+), 135 deletions(-) rename OsmAndCore-sample/src/net/osmand/core/samples/android/sample1/{search => adapters}/AmenitySearchListItem.java (92%) rename OsmAndCore-sample/src/net/osmand/core/samples/android/sample1/{search => adapters}/SearchListAdapter.java (97%) rename OsmAndCore-sample/src/net/osmand/core/samples/android/sample1/{search => adapters}/SearchListItem.java (82%) create mode 100644 OsmAndCore-sample/src/net/osmand/core/samples/android/sample1/search/AmenitySearchItem.java create mode 100644 OsmAndCore-sample/src/net/osmand/core/samples/android/sample1/search/SearchItem.java diff --git a/OsmAndCore-sample/src/net/osmand/core/samples/android/sample1/MainActivity.java b/OsmAndCore-sample/src/net/osmand/core/samples/android/sample1/MainActivity.java index 6710fb3e0f..4adbde29bd 100644 --- a/OsmAndCore-sample/src/net/osmand/core/samples/android/sample1/MainActivity.java +++ b/OsmAndCore-sample/src/net/osmand/core/samples/android/sample1/MainActivity.java @@ -45,10 +45,11 @@ import net.osmand.core.jni.QIODeviceLogSink; import net.osmand.core.jni.ResolvedMapStyle; import net.osmand.core.jni.Utilities; import net.osmand.core.samples.android.sample1.MultiTouchSupport.MultiTouchZoomListener; +import net.osmand.core.samples.android.sample1.adapters.SearchListAdapter; +import net.osmand.core.samples.android.sample1.adapters.SearchListItem; import net.osmand.core.samples.android.sample1.search.SearchAPI; import net.osmand.core.samples.android.sample1.search.SearchAPI.SearchAPICallback; -import net.osmand.core.samples.android.sample1.search.SearchListAdapter; -import net.osmand.core.samples.android.sample1.search.SearchListItem; +import net.osmand.core.samples.android.sample1.search.SearchItem; import java.util.ArrayList; import java.util.Comparator; @@ -407,11 +408,11 @@ public class MainActivity extends Activity { searchAPI.setObfAreaFilter(bounds31); searchAPI.startSearch(keyword, MAX_SEARCH_RESULTS, new SearchAPICallback() { @Override - public void onSearchFinished(List searchItems, boolean cancelled) { + public void onSearchFinished(List searchItems, boolean cancelled) { if (searchItems != null && !cancelled) { LatLon latLon = Utilities.convert31ToLatLon(target31); List rows = new ArrayList<>(); - for (SearchAPI.SearchItem item : searchItems) { + for (SearchItem item : searchItems) { SearchListItem row = SearchListItem.buildListItem((SampleApplication)getApplication(), item); rows.add(row); diff --git a/OsmAndCore-sample/src/net/osmand/core/samples/android/sample1/search/AmenitySearchListItem.java b/OsmAndCore-sample/src/net/osmand/core/samples/android/sample1/adapters/AmenitySearchListItem.java similarity index 92% rename from OsmAndCore-sample/src/net/osmand/core/samples/android/sample1/search/AmenitySearchListItem.java rename to OsmAndCore-sample/src/net/osmand/core/samples/android/sample1/adapters/AmenitySearchListItem.java index 5ee34188c3..b6fb092020 100644 --- a/OsmAndCore-sample/src/net/osmand/core/samples/android/sample1/search/AmenitySearchListItem.java +++ b/OsmAndCore-sample/src/net/osmand/core/samples/android/sample1/adapters/AmenitySearchListItem.java @@ -1,8 +1,8 @@ -package net.osmand.core.samples.android.sample1.search; +package net.osmand.core.samples.android.sample1.adapters; import net.osmand.core.samples.android.sample1.MapUtils; import net.osmand.core.samples.android.sample1.SampleApplication; -import net.osmand.core.samples.android.sample1.search.SearchAPI.AmenitySearchItem; +import net.osmand.core.samples.android.sample1.search.AmenitySearchItem; import net.osmand.data.Amenity; import net.osmand.osm.MapPoiTypes; import net.osmand.osm.PoiCategory; diff --git a/OsmAndCore-sample/src/net/osmand/core/samples/android/sample1/search/SearchListAdapter.java b/OsmAndCore-sample/src/net/osmand/core/samples/android/sample1/adapters/SearchListAdapter.java similarity index 97% rename from OsmAndCore-sample/src/net/osmand/core/samples/android/sample1/search/SearchListAdapter.java rename to OsmAndCore-sample/src/net/osmand/core/samples/android/sample1/adapters/SearchListAdapter.java index 90a1ff8dbf..932b0062eb 100644 --- a/OsmAndCore-sample/src/net/osmand/core/samples/android/sample1/search/SearchListAdapter.java +++ b/OsmAndCore-sample/src/net/osmand/core/samples/android/sample1/adapters/SearchListAdapter.java @@ -1,4 +1,4 @@ -package net.osmand.core.samples.android.sample1.search; +package net.osmand.core.samples.android.sample1.adapters; import android.content.Context; import android.view.LayoutInflater; diff --git a/OsmAndCore-sample/src/net/osmand/core/samples/android/sample1/search/SearchListItem.java b/OsmAndCore-sample/src/net/osmand/core/samples/android/sample1/adapters/SearchListItem.java similarity index 82% rename from OsmAndCore-sample/src/net/osmand/core/samples/android/sample1/search/SearchListItem.java rename to OsmAndCore-sample/src/net/osmand/core/samples/android/sample1/adapters/SearchListItem.java index e818ef9512..6c466a88da 100644 --- a/OsmAndCore-sample/src/net/osmand/core/samples/android/sample1/search/SearchListItem.java +++ b/OsmAndCore-sample/src/net/osmand/core/samples/android/sample1/adapters/SearchListItem.java @@ -1,10 +1,10 @@ -package net.osmand.core.samples.android.sample1.search; +package net.osmand.core.samples.android.sample1.adapters; import android.graphics.drawable.Drawable; import net.osmand.core.samples.android.sample1.SampleApplication; -import net.osmand.core.samples.android.sample1.search.SearchAPI.AmenitySearchItem; -import net.osmand.core.samples.android.sample1.search.SearchAPI.SearchItem; +import net.osmand.core.samples.android.sample1.search.AmenitySearchItem; +import net.osmand.core.samples.android.sample1.search.SearchItem; public class SearchListItem { diff --git a/OsmAndCore-sample/src/net/osmand/core/samples/android/sample1/search/AmenitySearchItem.java b/OsmAndCore-sample/src/net/osmand/core/samples/android/sample1/search/AmenitySearchItem.java new file mode 100644 index 0000000000..cde5981adf --- /dev/null +++ b/OsmAndCore-sample/src/net/osmand/core/samples/android/sample1/search/AmenitySearchItem.java @@ -0,0 +1,91 @@ +package net.osmand.core.samples.android.sample1.search; + +import net.osmand.core.jni.Amenity; +import net.osmand.core.jni.DecodedCategoryList; +import net.osmand.core.jni.DecodedValueList; +import net.osmand.core.jni.QStringList; +import net.osmand.core.jni.QStringStringHash; +import net.osmand.util.Algorithms; + +import java.util.HashMap; +import java.util.Map; + +public class AmenitySearchItem extends SearchItem { + + private String nativeName; + private String category; + private String subcategory; + private Map localizedNames = new HashMap<>(); + private Map values = new HashMap<>(); + + public AmenitySearchItem(Amenity amenity) { + super(amenity.getPosition31()); + + nativeName = amenity.getNativeName(); + QStringStringHash locNames = amenity.getLocalizedNames(); + QStringList locNamesKeys = locNames.keys(); + for (int i = 0; i < locNamesKeys.size(); i++) { + String key = locNamesKeys.get(i); + String val = locNames.get(key); + localizedNames.put(key, val); + } + + DecodedCategoryList catList = amenity.getDecodedCategories(); + if (catList.size() > 0) { + Amenity.DecodedCategory decodedCategory = catList.get(0); + category = decodedCategory.getCategory(); + subcategory = decodedCategory.getSubcategory(); + } + + DecodedValueList decodedValueList = amenity.getDecodedValues(); + if (decodedValueList.size() > 0) { + for (int i = 0; i < decodedValueList.size(); i++) { + Amenity.DecodedValue decodedValue = decodedValueList.get(i); + String tag = decodedValue.getDeclaration().getTagName(); + String value = decodedValue.getValue().toString(); + values.put(tag, value); + } + } + } + + public String getNativeName() { + return nativeName; + } + + public String getCategory() { + return category; + } + + public String getSubcategory() { + return subcategory; + } + + public Map getLocalizedNames() { + return localizedNames; + } + + public Map getValues() { + return values; + } + + @Override + public String getName() { + return nativeName; + } + + @Override + public String getType() { + return Algorithms.capitalizeFirstLetterAndLowercase(subcategory); + } + + @Override + public double getLatitude() { + return latitude; + } + + @Override + public double getLongitude() { + return longitude; + } + +} diff --git a/OsmAndCore-sample/src/net/osmand/core/samples/android/sample1/search/SearchAPI.java b/OsmAndCore-sample/src/net/osmand/core/samples/android/sample1/search/SearchAPI.java index bf79cb2a5f..1603b91fe0 100644 --- a/OsmAndCore-sample/src/net/osmand/core/samples/android/sample1/search/SearchAPI.java +++ b/OsmAndCore-sample/src/net/osmand/core/samples/android/sample1/search/SearchAPI.java @@ -4,26 +4,14 @@ import android.os.AsyncTask; import net.osmand.core.jni.AmenitiesByNameSearch; import net.osmand.core.jni.Amenity; -import net.osmand.core.jni.Amenity.DecodedCategory; -import net.osmand.core.jni.Amenity.DecodedValue; import net.osmand.core.jni.AreaI; -import net.osmand.core.jni.DecodedCategoryList; -import net.osmand.core.jni.DecodedValueList; import net.osmand.core.jni.IQueryController; import net.osmand.core.jni.ISearch; -import net.osmand.core.jni.LatLon; import net.osmand.core.jni.NullableAreaI; import net.osmand.core.jni.ObfsCollection; -import net.osmand.core.jni.PointI; -import net.osmand.core.jni.QStringList; -import net.osmand.core.jni.QStringStringHash; -import net.osmand.core.jni.Utilities; -import net.osmand.util.Algorithms; import java.util.ArrayList; -import java.util.HashMap; import java.util.List; -import java.util.Map; public class SearchAPI { @@ -193,117 +181,4 @@ public class SearchAPI { super(ISearch.IResultEntry.getCPtr(resultEntry), false); } } - - public static abstract class SearchItem { - - protected double latitude; - protected double longitude; - - public SearchItem(double latitude, double longitude) { - this.latitude = latitude; - this.longitude = longitude; - } - - public SearchItem(PointI location31) { - LatLon latLon = Utilities.convert31ToLatLon(location31); - latitude = latLon.getLatitude(); - longitude = latLon.getLongitude(); - } - - public abstract String getName(); - - public abstract String getType(); - - public double getLatitude() { - return latitude; - } - - public double getLongitude() { - return longitude; - } - - @Override - public String toString() { - return getName() + " {lat:" + getLatitude() + " lon: " + getLongitude() + "}"; - } - } - - public static class AmenitySearchItem extends SearchItem { - - private String nativeName; - private String category; - private String subcategory; - private Map localizedNames = new HashMap<>(); - private Map values = new HashMap<>(); - - public AmenitySearchItem(Amenity amenity) { - super(amenity.getPosition31()); - - nativeName = amenity.getNativeName(); - QStringStringHash locNames = amenity.getLocalizedNames(); - QStringList locNamesKeys = locNames.keys(); - for (int i = 0; i < locNamesKeys.size(); i++) { - String key = locNamesKeys.get(i); - String val = locNames.get(key); - localizedNames.put(key, val); - } - - DecodedCategoryList catList = amenity.getDecodedCategories(); - if (catList.size() > 0) { - DecodedCategory decodedCategory = catList.get(0); - category = decodedCategory.getCategory(); - subcategory = decodedCategory.getSubcategory(); - } - - DecodedValueList decodedValueList = amenity.getDecodedValues(); - if (decodedValueList.size() > 0) { - for (int i = 0; i < decodedValueList.size(); i++) { - DecodedValue decodedValue = decodedValueList.get(i); - String tag = decodedValue.getDeclaration().getTagName(); - String value = decodedValue.getValue().toString(); - values.put(tag, value); - } - } - } - - public String getNativeName() { - return nativeName; - } - - public String getCategory() { - return category; - } - - public String getSubcategory() { - return subcategory; - } - - public Map getLocalizedNames() { - return localizedNames; - } - - public Map getValues() { - return values; - } - - @Override - public String getName() { - return nativeName; - } - - @Override - public String getType() { - return Algorithms.capitalizeFirstLetterAndLowercase(subcategory); - } - - @Override - public double getLatitude() { - return latitude; - } - - @Override - public double getLongitude() { - return longitude; - } - } } diff --git a/OsmAndCore-sample/src/net/osmand/core/samples/android/sample1/search/SearchItem.java b/OsmAndCore-sample/src/net/osmand/core/samples/android/sample1/search/SearchItem.java new file mode 100644 index 0000000000..22bbf2fa31 --- /dev/null +++ b/OsmAndCore-sample/src/net/osmand/core/samples/android/sample1/search/SearchItem.java @@ -0,0 +1,39 @@ +package net.osmand.core.samples.android.sample1.search; + +import net.osmand.core.jni.LatLon; +import net.osmand.core.jni.PointI; +import net.osmand.core.jni.Utilities; + +public abstract class SearchItem { + + protected double latitude; + protected double longitude; + + public SearchItem(double latitude, double longitude) { + this.latitude = latitude; + this.longitude = longitude; + } + + public SearchItem(PointI location31) { + LatLon latLon = Utilities.convert31ToLatLon(location31); + latitude = latLon.getLatitude(); + longitude = latLon.getLongitude(); + } + + public abstract String getName(); + + public abstract String getType(); + + public double getLatitude() { + return latitude; + } + + public double getLongitude() { + return longitude; + } + + @Override + public String toString() { + return getName() + " {lat:" + getLatitude() + " lon: " + getLongitude() + "}"; + } +}