[Core sample] fix search ui
This commit is contained in:
parent
092c8289da
commit
e9586c50c7
2 changed files with 113 additions and 5 deletions
|
@ -306,6 +306,7 @@ public class MainActivity extends Activity {
|
||||||
SearchListItem item = adapter.getItem(position);
|
SearchListItem item = adapter.getItem(position);
|
||||||
SearchResult sr = item.getSearchResult();
|
SearchResult sr = item.getSearchResult();
|
||||||
|
|
||||||
|
boolean updateEditText = true;
|
||||||
if (sr.objectType == ObjectType.POI
|
if (sr.objectType == ObjectType.POI
|
||||||
|| sr.objectType == ObjectType.LOCATION
|
|| sr.objectType == ObjectType.LOCATION
|
||||||
|| sr.objectType == ObjectType.HOUSE
|
|| sr.objectType == ObjectType.HOUSE
|
||||||
|
@ -316,8 +317,9 @@ public class MainActivity extends Activity {
|
||||||
|
|
||||||
hideSearchList();
|
hideSearchList();
|
||||||
mapView.requestFocus();
|
mapView.requestFocus();
|
||||||
|
updateEditText = false;
|
||||||
}
|
}
|
||||||
completeQueryWithObject(item.getSearchResult());
|
completeQueryWithObject(item.getSearchResult(), updateEditText);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -523,16 +525,18 @@ public class MainActivity extends Activity {
|
||||||
updateSearchResult(c, false);
|
updateSearchResult(c, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void completeQueryWithObject(SearchResult sr) {
|
private void completeQueryWithObject(SearchResult sr, boolean updateEditText) {
|
||||||
|
|
||||||
if (sr.location != null) {
|
if (sr.location != null) {
|
||||||
showOnMap(sr.location, sr.preferredZoom);
|
showOnMap(sr.location, sr.preferredZoom);
|
||||||
}
|
}
|
||||||
searchUICore.selectSearchResult(sr);
|
searchUICore.selectSearchResult(sr);
|
||||||
String txt = searchUICore.getPhrase().getText(true);
|
String txt = searchUICore.getPhrase().getText(true);
|
||||||
queryText = txt;
|
if (updateEditText) {
|
||||||
searchEditText.setText(txt);
|
queryText = txt;
|
||||||
searchEditText.setSelection(txt.length());
|
searchEditText.setText(txt);
|
||||||
|
searchEditText.setSelection(txt.length());
|
||||||
|
}
|
||||||
|
|
||||||
searchUICore.search(txt, null);
|
searchUICore.search(txt, null);
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,7 +3,16 @@ package net.osmand.core.samples.android.sample1.adapters;
|
||||||
import android.graphics.drawable.Drawable;
|
import android.graphics.drawable.Drawable;
|
||||||
|
|
||||||
import net.osmand.core.samples.android.sample1.SampleApplication;
|
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.search.example.core.SearchResult;
|
||||||
|
import net.osmand.util.Algorithms;
|
||||||
|
|
||||||
public class SearchListItem {
|
public class SearchListItem {
|
||||||
|
|
||||||
|
@ -25,10 +34,105 @@ public class SearchListItem {
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getTypeName() {
|
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();
|
return searchResult.objectType.name();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Drawable getIcon() {
|
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;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue