Rearrange classes in Core sample

This commit is contained in:
Alexey Kulish 2016-06-18 11:03:12 +03:00
parent 02c310a438
commit db1ed9cc41
7 changed files with 141 additions and 135 deletions

View file

@ -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<SearchAPI.SearchItem> searchItems, boolean cancelled) {
public void onSearchFinished(List<SearchItem> searchItems, boolean cancelled) {
if (searchItems != null && !cancelled) {
LatLon latLon = Utilities.convert31ToLatLon(target31);
List<SearchListItem> rows = new ArrayList<>();
for (SearchAPI.SearchItem item : searchItems) {
for (SearchItem item : searchItems) {
SearchListItem row =
SearchListItem.buildListItem((SampleApplication)getApplication(), item);
rows.add(row);

View file

@ -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;

View file

@ -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;

View file

@ -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 {

View file

@ -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<String, String> localizedNames = new HashMap<>();
private Map<String, String> 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<String, String> getLocalizedNames() {
return localizedNames;
}
public Map<String, String> 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;
}
}

View file

@ -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<String, String> localizedNames = new HashMap<>();
private Map<String, String> 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<String, String> getLocalizedNames() {
return localizedNames;
}
public Map<String, String> 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;
}
}
}

View file

@ -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() + "}";
}
}