Fix #3138
This commit is contained in:
parent
c5cbb77267
commit
fb61cad9a4
3 changed files with 112 additions and 56 deletions
|
@ -7,6 +7,7 @@ import net.osmand.plus.R;
|
|||
import net.osmand.util.Algorithms;
|
||||
import android.content.Context;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
|
||||
import com.jwetherell.openmap.common.LatLonPoint;
|
||||
import com.jwetherell.openmap.common.UTMPoint;
|
||||
|
@ -15,6 +16,7 @@ public class PointDescription {
|
|||
private String type = "";
|
||||
private String name = "";
|
||||
private String typeName;
|
||||
private String iconName;
|
||||
|
||||
private double lat = 0;
|
||||
private double lon = 0;
|
||||
|
@ -91,6 +93,15 @@ public class PointDescription {
|
|||
return typeName;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public String getIconName() {
|
||||
return iconName;
|
||||
}
|
||||
|
||||
public void setIconName(String iconName) {
|
||||
this.iconName = iconName;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public String getName() {
|
||||
return name;
|
||||
|
@ -281,7 +292,11 @@ public class PointDescription {
|
|||
if(!Algorithms.isEmpty(p.typeName)) {
|
||||
tp = tp +'.' + p.typeName;
|
||||
}
|
||||
return tp + "#" + p.name;
|
||||
String res = tp + "#" + p.name;
|
||||
if (!Algorithms.isEmpty(p.iconName)) {
|
||||
res += "#" + p.iconName;
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
public static PointDescription deserializeFromString(String s, LatLon l) {
|
||||
|
@ -289,12 +304,23 @@ public class PointDescription {
|
|||
if (s != null && s.length() > 0) {
|
||||
int in = s.indexOf('#');
|
||||
if (in >= 0) {
|
||||
String nm = s.substring(in + 1).trim();
|
||||
int ii = s.indexOf('#', in + 1);
|
||||
String name;
|
||||
String icon = null;
|
||||
if (ii > 0) {
|
||||
name = s.substring(in + 1, ii).trim();
|
||||
icon = s.substring(ii + 1).trim();
|
||||
} else {
|
||||
name = s.substring(in + 1).trim();
|
||||
}
|
||||
String tp = s.substring(0, in);
|
||||
if(tp.contains(".")) {
|
||||
pd = new PointDescription(tp.substring(0, tp.indexOf('.')), tp.substring(tp.indexOf('.') + 1), nm);
|
||||
pd = new PointDescription(tp.substring(0, tp.indexOf('.')), tp.substring(tp.indexOf('.') + 1), name);
|
||||
} else {
|
||||
pd = new PointDescription(tp, nm);
|
||||
pd = new PointDescription(tp, name);
|
||||
}
|
||||
if (!Algorithms.isEmpty(icon)) {
|
||||
pd.setIconName(icon);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -166,8 +166,10 @@ public abstract class QuickSearchListFragment extends OsmAndListFragment {
|
|||
Object object = searchResult.object;
|
||||
switch (searchResult.objectType) {
|
||||
case POI:
|
||||
String poiSimpleFormat = OsmAndFormatter.getPoiStringWithoutType((Amenity) object, lang, transliterate);
|
||||
Amenity a = (Amenity) object;
|
||||
String poiSimpleFormat = OsmAndFormatter.getPoiStringWithoutType(a, lang, transliterate);
|
||||
pointDescription = new PointDescription(PointDescription.POINT_TYPE_POI, poiSimpleFormat);
|
||||
pointDescription.setIconName(QuickSearchListItem.getAmenityIconName(a));
|
||||
break;
|
||||
case RECENT_OBJ:
|
||||
HistoryEntry entry = (HistoryEntry) object;
|
||||
|
@ -178,6 +180,7 @@ public abstract class QuickSearchListFragment extends OsmAndListFragment {
|
|||
object = amenity;
|
||||
pointDescription = new PointDescription(PointDescription.POINT_TYPE_POI,
|
||||
OsmAndFormatter.getPoiStringWithoutType(amenity, lang, transliterate));
|
||||
pointDescription.setIconName(QuickSearchListItem.getAmenityIconName(amenity));
|
||||
}
|
||||
} else if (pointDescription.isFavorite()) {
|
||||
LatLon entryLatLon = new LatLon(entry.getLat(), entry.getLon());
|
||||
|
@ -209,10 +212,12 @@ public abstract class QuickSearchListFragment extends OsmAndListFragment {
|
|||
name = searchResult.localeRelatedObjectName + " " + name;
|
||||
}
|
||||
pointDescription = new PointDescription(PointDescription.POINT_TYPE_ADDRESS, typeNameHouse, name);
|
||||
pointDescription.setIconName("ic_action_building");
|
||||
break;
|
||||
case LOCATION:
|
||||
LatLon latLon = (LatLon) object;
|
||||
pointDescription = new PointDescription(latLon.getLatitude(), latLon.getLongitude());
|
||||
pointDescription.setIconName("ic_action_world_globe");
|
||||
break;
|
||||
case STREET_INTERSECTION:
|
||||
String typeNameIntersection = QuickSearchListItem.getTypeName(app, searchResult);
|
||||
|
@ -221,6 +226,7 @@ public abstract class QuickSearchListFragment extends OsmAndListFragment {
|
|||
}
|
||||
pointDescription = new PointDescription(PointDescription.POINT_TYPE_ADDRESS,
|
||||
typeNameIntersection, QuickSearchListItem.getName(app, searchResult));
|
||||
pointDescription.setIconName("ic_action_intersection");
|
||||
break;
|
||||
case WPT:
|
||||
GPXUtilities.WptPt wpt = (GPXUtilities.WptPt) object;
|
||||
|
|
|
@ -2,6 +2,7 @@ package net.osmand.plus.search;
|
|||
|
||||
import android.content.Context;
|
||||
import android.graphics.drawable.Drawable;
|
||||
|
||||
import net.osmand.binary.BinaryMapIndexReader;
|
||||
import net.osmand.data.Amenity;
|
||||
import net.osmand.data.City;
|
||||
|
@ -155,7 +156,7 @@ public class QuickSearchListItem {
|
|||
}
|
||||
return "";
|
||||
case POI_TYPE:
|
||||
String res= "";
|
||||
String res = "";
|
||||
if (searchResult.object instanceof AbstractPoiType) {
|
||||
AbstractPoiType abstractPoiType = (AbstractPoiType) searchResult.object;
|
||||
if (abstractPoiType instanceof PoiCategory) {
|
||||
|
@ -257,17 +258,41 @@ public class QuickSearchListItem {
|
|||
return getIcon(app, searchResult);
|
||||
}
|
||||
|
||||
public static String getPoiTypeIconName(AbstractPoiType abstractPoiType) {
|
||||
if (RenderingIcons.containsBigIcon(abstractPoiType.getIconKeyName())) {
|
||||
return abstractPoiType.getIconKeyName();
|
||||
} else if (abstractPoiType instanceof PoiType
|
||||
&& RenderingIcons.containsBigIcon(
|
||||
((PoiType) abstractPoiType).getOsmTag() + "_" + ((PoiType) abstractPoiType).getOsmValue())) {
|
||||
return ((PoiType) abstractPoiType).getOsmTag() + "_" + ((PoiType) abstractPoiType).getOsmValue();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static String getAmenityIconName(Amenity amenity) {
|
||||
PoiType st = amenity.getType().getPoiTypeByKeyName(amenity.getSubType());
|
||||
if (st != null) {
|
||||
if (RenderingIcons.containsBigIcon(st.getIconKeyName())) {
|
||||
return st.getIconKeyName();
|
||||
} else if (RenderingIcons.containsBigIcon(st.getOsmTag() + "_" + st.getOsmValue())) {
|
||||
return st.getOsmTag() + "_" + st.getOsmValue();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static Drawable getIcon(OsmandApplication app, SearchResult searchResult) {
|
||||
if (searchResult == null || searchResult.objectType == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
int iconId = -1;
|
||||
switch (searchResult.objectType) {
|
||||
case CITY:
|
||||
return app.getIconsCache().getIcon(R.drawable.ic_action_building_number,
|
||||
app.getSettings().isLightContent() ? R.color.osmand_orange : R.color.osmand_orange_dark);
|
||||
case VILLAGE:
|
||||
return app.getIconsCache().getIcon(R.drawable. ic_action_home_dark,
|
||||
return app.getIconsCache().getIcon(R.drawable.ic_action_home_dark,
|
||||
app.getSettings().isLightContent() ? R.color.osmand_orange : R.color.osmand_orange_dark);
|
||||
case POSTCODE:
|
||||
case STREET:
|
||||
|
@ -280,16 +305,10 @@ public class QuickSearchListItem {
|
|||
return app.getIconsCache().getIcon(R.drawable.ic_action_intersection,
|
||||
app.getSettings().isLightContent() ? R.color.osmand_orange : R.color.osmand_orange_dark);
|
||||
case POI_TYPE:
|
||||
int iconId = -1;
|
||||
if (searchResult.object instanceof AbstractPoiType) {
|
||||
AbstractPoiType abstractPoiType = (AbstractPoiType) searchResult.object;
|
||||
if (RenderingIcons.containsBigIcon(abstractPoiType.getIconKeyName())) {
|
||||
iconId = RenderingIcons.getBigIconResourceId(abstractPoiType.getIconKeyName());
|
||||
} else if (abstractPoiType instanceof PoiType
|
||||
&& RenderingIcons.containsBigIcon(((PoiType) abstractPoiType).getOsmTag() + "_"
|
||||
+ ((PoiType) abstractPoiType).getOsmValue())) {
|
||||
iconId = RenderingIcons.getBigIconResourceId(((PoiType) abstractPoiType).getOsmTag() + "_"
|
||||
+ ((PoiType) abstractPoiType).getOsmValue());
|
||||
String iconName = getPoiTypeIconName((AbstractPoiType) searchResult.object);
|
||||
if (!Algorithms.isEmpty(iconName)) {
|
||||
iconId = RenderingIcons.getBigIconResourceId(iconName);
|
||||
}
|
||||
} else if (searchResult.object instanceof CustomSearchPoiFilter) {
|
||||
Object res = ((CustomSearchPoiFilter) searchResult.object).getIconResource();
|
||||
|
@ -307,15 +326,7 @@ public class QuickSearchListItem {
|
|||
}
|
||||
case POI:
|
||||
Amenity amenity = (Amenity) searchResult.object;
|
||||
String id = null;
|
||||
PoiType st = amenity.getType().getPoiTypeByKeyName(amenity.getSubType());
|
||||
if (st != null) {
|
||||
if (RenderingIcons.containsBigIcon(st.getIconKeyName())) {
|
||||
id = st.getIconKeyName();
|
||||
} else if (RenderingIcons.containsBigIcon(st.getOsmTag() + "_" + st.getOsmValue())) {
|
||||
id = st.getOsmTag() + "_" + st.getOsmValue();
|
||||
}
|
||||
}
|
||||
String id = getAmenityIconName(amenity);
|
||||
if (id != null) {
|
||||
iconId = RenderingIcons.getBigIconResourceId(id);
|
||||
return app.getIconsCache().getIcon(iconId,
|
||||
|
@ -334,8 +345,21 @@ public class QuickSearchListItem {
|
|||
app.getSettings().isLightContent() ? R.color.osmand_orange : R.color.osmand_orange_dark);
|
||||
case RECENT_OBJ:
|
||||
HistoryEntry entry = (HistoryEntry) searchResult.object;
|
||||
if (entry.getName() != null && !Algorithms.isEmpty(entry.getName().getIconName())) {
|
||||
String iconName = entry.getName().getIconName();
|
||||
if (RenderingIcons.containsBigIcon(iconName)) {
|
||||
iconId = RenderingIcons.getBigIconResourceId(iconName);
|
||||
} else {
|
||||
iconId = app.getResources().getIdentifier(iconName, "drawable", app.getPackageName());
|
||||
}
|
||||
}
|
||||
if (iconId == -1) {
|
||||
return app.getIconsCache().getIcon(SearchHistoryFragment.getItemIcon(entry.getName()),
|
||||
app.getSettings().isLightContent() ? R.color.osmand_orange : R.color.osmand_orange_dark);
|
||||
} else {
|
||||
return app.getIconsCache().getIcon(iconId,
|
||||
app.getSettings().isLightContent() ? R.color.osmand_orange : R.color.osmand_orange_dark);
|
||||
}
|
||||
case WPT:
|
||||
WptPt wpt = (WptPt) searchResult.object;
|
||||
return FavoriteImageDrawable.getOrCreate(app, wpt.getColor(), false);
|
||||
|
|
Loading…
Reference in a new issue