[Core sample] fix search ui

This commit is contained in:
Alexey Kulish 2016-07-12 12:52:21 +03:00
parent 092c8289da
commit e9586c50c7
2 changed files with 113 additions and 5 deletions

View file

@ -306,6 +306,7 @@ public class MainActivity extends Activity {
SearchListItem item = adapter.getItem(position);
SearchResult sr = item.getSearchResult();
boolean updateEditText = true;
if (sr.objectType == ObjectType.POI
|| sr.objectType == ObjectType.LOCATION
|| sr.objectType == ObjectType.HOUSE
@ -316,8 +317,9 @@ public class MainActivity extends Activity {
hideSearchList();
mapView.requestFocus();
updateEditText = false;
}
completeQueryWithObject(item.getSearchResult());
completeQueryWithObject(item.getSearchResult(), updateEditText);
}
});
@ -523,16 +525,18 @@ public class MainActivity extends Activity {
updateSearchResult(c, false);
}
private void completeQueryWithObject(SearchResult sr) {
private void completeQueryWithObject(SearchResult sr, boolean updateEditText) {
if (sr.location != null) {
showOnMap(sr.location, sr.preferredZoom);
}
searchUICore.selectSearchResult(sr);
String txt = searchUICore.getPhrase().getText(true);
queryText = txt;
searchEditText.setText(txt);
searchEditText.setSelection(txt.length());
if (updateEditText) {
queryText = txt;
searchEditText.setText(txt);
searchEditText.setSelection(txt.length());
}
searchUICore.search(txt, null);
}

View file

@ -3,7 +3,16 @@ package net.osmand.core.samples.android.sample1.adapters;
import android.graphics.drawable.Drawable;
import net.osmand.core.samples.android.sample1.SampleApplication;
import net.osmand.data.Amenity;
import net.osmand.data.City;
import net.osmand.data.City.CityType;
import net.osmand.data.Street;
import net.osmand.osm.AbstractPoiType;
import net.osmand.osm.PoiCategory;
import net.osmand.osm.PoiFilter;
import net.osmand.osm.PoiType;
import net.osmand.search.example.core.SearchResult;
import net.osmand.util.Algorithms;
public class SearchListItem {
@ -25,10 +34,105 @@ public class SearchListItem {
}
public String getTypeName() {
switch (searchResult.objectType) {
case CITY:
case VILLAGE:
case POSTCODE:
City city = (City) searchResult.object;
return Algorithms.capitalizeFirstLetterAndLowercase(city.getType().toString());
case STREET:
Street street = (Street) searchResult.object;
City streetCity = street.getCity();
if (streetCity.getType() != CityType.CITY
&& streetCity.getType() != CityType.TOWN
&& streetCity.getType() != CityType.VILLAGE
&& streetCity.getClosestCity() != null) {
return streetCity.getName() + " - " + streetCity.getClosestCity().getName();
} else {
return streetCity.getName() + " - " + Algorithms.capitalizeFirstLetterAndLowercase(streetCity.getType().name());
}
case HOUSE:
return "House";
case STREET_INTERSECTION:
return "Street intersection";
case POI_TYPE:
AbstractPoiType abstractPoiType = (AbstractPoiType) searchResult.object;
String res;
if (abstractPoiType instanceof PoiCategory) {
res = "POI category";
} else if (abstractPoiType instanceof PoiFilter) {
PoiFilter poiFilter = (PoiFilter) abstractPoiType;
res = poiFilter.getPoiCategory() != null ? poiFilter.getPoiCategory().getTranslation() : "POI filter";
} else if (abstractPoiType instanceof PoiType) {
PoiType poiType = (PoiType) abstractPoiType;
res = poiType.getParentType() != null ? poiType.getParentType().getTranslation() : null;
if (res == null) {
res = poiType.getCategory() != null ? poiType.getCategory().getTranslation() : null;
}
if (res == null) {
res = "POI type";
}
} else {
res = "POI type";
}
return res;
case POI:
Amenity amenity = (Amenity) searchResult.object;
return amenity.getType().toString();
case LOCATION:
break;
case FAVORITE:
break;
case REGION:
break;
case RECENT_OBJ:
break;
case WPT:
break;
case UNKNOWN_NAME_FILTER:
break;
}
return searchResult.objectType.name();
}
public Drawable getIcon() {
switch (searchResult.objectType) {
case CITY:
break;
case VILLAGE:
break;
case POSTCODE:
break;
case STREET:
break;
case HOUSE:
break;
case STREET_INTERSECTION:
break;
case POI_TYPE:
break;
case POI:
Amenity amenity = (Amenity) searchResult.object;
Drawable drawable = null;
PoiType st = amenity.getType().getPoiTypeByKeyName(amenity.getSubType());
if (st != null) {
drawable = app.getIconsCache().getMapIcon(st.getOsmTag() + "_" + st.getOsmValue());
}
return drawable;
case LOCATION:
break;
case FAVORITE:
break;
case REGION:
break;
case RECENT_OBJ:
break;
case WPT:
break;
case UNKNOWN_NAME_FILTER:
break;
}
return null;
}