This commit is contained in:
Alexey Kulish 2016-10-18 13:53:43 +03:00
parent c5cbb77267
commit fb61cad9a4
3 changed files with 112 additions and 56 deletions

View file

@ -7,6 +7,7 @@ import net.osmand.plus.R;
import net.osmand.util.Algorithms; import net.osmand.util.Algorithms;
import android.content.Context; import android.content.Context;
import android.support.annotation.NonNull; import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import com.jwetherell.openmap.common.LatLonPoint; import com.jwetherell.openmap.common.LatLonPoint;
import com.jwetherell.openmap.common.UTMPoint; import com.jwetherell.openmap.common.UTMPoint;
@ -15,6 +16,7 @@ public class PointDescription {
private String type = ""; private String type = "";
private String name = ""; private String name = "";
private String typeName; private String typeName;
private String iconName;
private double lat = 0; private double lat = 0;
private double lon = 0; private double lon = 0;
@ -91,6 +93,15 @@ public class PointDescription {
return typeName; return typeName;
} }
@Nullable
public String getIconName() {
return iconName;
}
public void setIconName(String iconName) {
this.iconName = iconName;
}
@NonNull @NonNull
public String getName() { public String getName() {
return name; return name;
@ -281,7 +292,11 @@ public class PointDescription {
if(!Algorithms.isEmpty(p.typeName)) { if(!Algorithms.isEmpty(p.typeName)) {
tp = tp +'.' + 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) { public static PointDescription deserializeFromString(String s, LatLon l) {
@ -289,12 +304,23 @@ public class PointDescription {
if (s != null && s.length() > 0) { if (s != null && s.length() > 0) {
int in = s.indexOf('#'); int in = s.indexOf('#');
if (in >= 0) { 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); String tp = s.substring(0, in);
if(tp.contains(".")) { 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 { } else {
pd = new PointDescription(tp, nm); pd = new PointDescription(tp, name);
}
if (!Algorithms.isEmpty(icon)) {
pd.setIconName(icon);
} }
} }
} }

View file

@ -166,8 +166,10 @@ public abstract class QuickSearchListFragment extends OsmAndListFragment {
Object object = searchResult.object; Object object = searchResult.object;
switch (searchResult.objectType) { switch (searchResult.objectType) {
case POI: 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 = new PointDescription(PointDescription.POINT_TYPE_POI, poiSimpleFormat);
pointDescription.setIconName(QuickSearchListItem.getAmenityIconName(a));
break; break;
case RECENT_OBJ: case RECENT_OBJ:
HistoryEntry entry = (HistoryEntry) object; HistoryEntry entry = (HistoryEntry) object;
@ -178,6 +180,7 @@ public abstract class QuickSearchListFragment extends OsmAndListFragment {
object = amenity; object = amenity;
pointDescription = new PointDescription(PointDescription.POINT_TYPE_POI, pointDescription = new PointDescription(PointDescription.POINT_TYPE_POI,
OsmAndFormatter.getPoiStringWithoutType(amenity, lang, transliterate)); OsmAndFormatter.getPoiStringWithoutType(amenity, lang, transliterate));
pointDescription.setIconName(QuickSearchListItem.getAmenityIconName(amenity));
} }
} else if (pointDescription.isFavorite()) { } else if (pointDescription.isFavorite()) {
LatLon entryLatLon = new LatLon(entry.getLat(), entry.getLon()); LatLon entryLatLon = new LatLon(entry.getLat(), entry.getLon());
@ -209,10 +212,12 @@ public abstract class QuickSearchListFragment extends OsmAndListFragment {
name = searchResult.localeRelatedObjectName + " " + name; name = searchResult.localeRelatedObjectName + " " + name;
} }
pointDescription = new PointDescription(PointDescription.POINT_TYPE_ADDRESS, typeNameHouse, name); pointDescription = new PointDescription(PointDescription.POINT_TYPE_ADDRESS, typeNameHouse, name);
pointDescription.setIconName("ic_action_building");
break; break;
case LOCATION: case LOCATION:
LatLon latLon = (LatLon) object; LatLon latLon = (LatLon) object;
pointDescription = new PointDescription(latLon.getLatitude(), latLon.getLongitude()); pointDescription = new PointDescription(latLon.getLatitude(), latLon.getLongitude());
pointDescription.setIconName("ic_action_world_globe");
break; break;
case STREET_INTERSECTION: case STREET_INTERSECTION:
String typeNameIntersection = QuickSearchListItem.getTypeName(app, searchResult); String typeNameIntersection = QuickSearchListItem.getTypeName(app, searchResult);
@ -221,6 +226,7 @@ public abstract class QuickSearchListFragment extends OsmAndListFragment {
} }
pointDescription = new PointDescription(PointDescription.POINT_TYPE_ADDRESS, pointDescription = new PointDescription(PointDescription.POINT_TYPE_ADDRESS,
typeNameIntersection, QuickSearchListItem.getName(app, searchResult)); typeNameIntersection, QuickSearchListItem.getName(app, searchResult));
pointDescription.setIconName("ic_action_intersection");
break; break;
case WPT: case WPT:
GPXUtilities.WptPt wpt = (GPXUtilities.WptPt) object; GPXUtilities.WptPt wpt = (GPXUtilities.WptPt) object;

View file

@ -2,6 +2,7 @@ package net.osmand.plus.search;
import android.content.Context; import android.content.Context;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
import net.osmand.binary.BinaryMapIndexReader; import net.osmand.binary.BinaryMapIndexReader;
import net.osmand.data.Amenity; import net.osmand.data.Amenity;
import net.osmand.data.City; import net.osmand.data.City;
@ -155,30 +156,30 @@ public class QuickSearchListItem {
} }
return ""; return "";
case POI_TYPE: case POI_TYPE:
String res= ""; String res = "";
if (searchResult.object instanceof AbstractPoiType) { if (searchResult.object instanceof AbstractPoiType) {
AbstractPoiType abstractPoiType = (AbstractPoiType) searchResult.object; AbstractPoiType abstractPoiType = (AbstractPoiType) searchResult.object;
if (abstractPoiType instanceof PoiCategory) { if (abstractPoiType instanceof PoiCategory) {
res = ""; res = "";
} else if (abstractPoiType instanceof PoiFilter) { } else if (abstractPoiType instanceof PoiFilter) {
PoiFilter poiFilter = (PoiFilter) abstractPoiType; PoiFilter poiFilter = (PoiFilter) abstractPoiType;
res = poiFilter.getPoiCategory() != null ? poiFilter.getPoiCategory().getTranslation() : ""; res = poiFilter.getPoiCategory() != null ? poiFilter.getPoiCategory().getTranslation() : "";
} else if (abstractPoiType instanceof PoiType) { } else if (abstractPoiType instanceof PoiType) {
PoiType poiType = (PoiType) abstractPoiType; PoiType poiType = (PoiType) abstractPoiType;
res = poiType.getParentType() != null ? poiType.getParentType().getTranslation() : null; res = poiType.getParentType() != null ? poiType.getParentType().getTranslation() : null;
if (res == null) { if (res == null) {
res = poiType.getCategory() != null ? poiType.getCategory().getTranslation() : null; res = poiType.getCategory() != null ? poiType.getCategory().getTranslation() : null;
} }
if (res == null) { if (res == null) {
res = "";
}
} else {
res = ""; res = "";
} }
} else { } else if (searchResult.object instanceof CustomSearchPoiFilter) {
res = ""; res = ((CustomSearchPoiFilter) searchResult.object).getName();
} }
} else if (searchResult.object instanceof CustomSearchPoiFilter) {
res = ((CustomSearchPoiFilter) searchResult.object).getName();
}
return res; return res;
case POI: case POI:
Amenity amenity = (Amenity) searchResult.object; Amenity amenity = (Amenity) searchResult.object;
@ -257,17 +258,41 @@ public class QuickSearchListItem {
return getIcon(app, searchResult); 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) { public static Drawable getIcon(OsmandApplication app, SearchResult searchResult) {
if (searchResult == null || searchResult.objectType == null) { if (searchResult == null || searchResult.objectType == null) {
return null; return null;
} }
int iconId = -1;
switch (searchResult.objectType) { switch (searchResult.objectType) {
case CITY: case CITY:
return app.getIconsCache().getIcon(R.drawable.ic_action_building_number, return app.getIconsCache().getIcon(R.drawable.ic_action_building_number,
app.getSettings().isLightContent() ? R.color.osmand_orange : R.color.osmand_orange_dark); app.getSettings().isLightContent() ? R.color.osmand_orange : R.color.osmand_orange_dark);
case VILLAGE: 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); app.getSettings().isLightContent() ? R.color.osmand_orange : R.color.osmand_orange_dark);
case POSTCODE: case POSTCODE:
case STREET: case STREET:
@ -280,25 +305,19 @@ public class QuickSearchListItem {
return app.getIconsCache().getIcon(R.drawable.ic_action_intersection, return app.getIconsCache().getIcon(R.drawable.ic_action_intersection,
app.getSettings().isLightContent() ? R.color.osmand_orange : R.color.osmand_orange_dark); app.getSettings().isLightContent() ? R.color.osmand_orange : R.color.osmand_orange_dark);
case POI_TYPE: case POI_TYPE:
int iconId = -1; if (searchResult.object instanceof AbstractPoiType) {
if (searchResult.object instanceof AbstractPoiType) { String iconName = getPoiTypeIconName((AbstractPoiType) searchResult.object);
AbstractPoiType abstractPoiType = (AbstractPoiType) searchResult.object; if (!Algorithms.isEmpty(iconName)) {
if (RenderingIcons.containsBigIcon(abstractPoiType.getIconKeyName())) { iconId = RenderingIcons.getBigIconResourceId(iconName);
iconId = RenderingIcons.getBigIconResourceId(abstractPoiType.getIconKeyName()); }
} else if (abstractPoiType instanceof PoiType } else if (searchResult.object instanceof CustomSearchPoiFilter) {
&& RenderingIcons.containsBigIcon(((PoiType) abstractPoiType).getOsmTag() + "_" Object res = ((CustomSearchPoiFilter) searchResult.object).getIconResource();
+ ((PoiType) abstractPoiType).getOsmValue())) { if (res instanceof String && RenderingIcons.containsBigIcon(res.toString())) {
iconId = RenderingIcons.getBigIconResourceId(((PoiType) abstractPoiType).getOsmTag() + "_" iconId = RenderingIcons.getBigIconResourceId(res.toString());
+ ((PoiType) abstractPoiType).getOsmValue()); } else {
iconId = R.drawable.mx_user_defined;
}
} }
} else if (searchResult.object instanceof CustomSearchPoiFilter) {
Object res = ((CustomSearchPoiFilter) searchResult.object).getIconResource();
if (res instanceof String && RenderingIcons.containsBigIcon(res.toString())) {
iconId = RenderingIcons.getBigIconResourceId(res.toString());
} else {
iconId = R.drawable.mx_user_defined;
}
}
if (iconId != -1) { if (iconId != -1) {
return app.getIconsCache().getIcon(iconId, return app.getIconsCache().getIcon(iconId,
app.getSettings().isLightContent() ? R.color.osmand_orange : R.color.osmand_orange_dark); app.getSettings().isLightContent() ? R.color.osmand_orange : R.color.osmand_orange_dark);
@ -307,15 +326,7 @@ public class QuickSearchListItem {
} }
case POI: case POI:
Amenity amenity = (Amenity) searchResult.object; Amenity amenity = (Amenity) searchResult.object;
String id = null; String id = getAmenityIconName(amenity);
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();
}
}
if (id != null) { if (id != null) {
iconId = RenderingIcons.getBigIconResourceId(id); iconId = RenderingIcons.getBigIconResourceId(id);
return app.getIconsCache().getIcon(iconId, return app.getIconsCache().getIcon(iconId,
@ -334,8 +345,21 @@ public class QuickSearchListItem {
app.getSettings().isLightContent() ? R.color.osmand_orange : R.color.osmand_orange_dark); app.getSettings().isLightContent() ? R.color.osmand_orange : R.color.osmand_orange_dark);
case RECENT_OBJ: case RECENT_OBJ:
HistoryEntry entry = (HistoryEntry) searchResult.object; HistoryEntry entry = (HistoryEntry) searchResult.object;
return app.getIconsCache().getIcon(SearchHistoryFragment.getItemIcon(entry.getName()), if (entry.getName() != null && !Algorithms.isEmpty(entry.getName().getIconName())) {
app.getSettings().isLightContent() ? R.color.osmand_orange : R.color.osmand_orange_dark); 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: case WPT:
WptPt wpt = (WptPt) searchResult.object; WptPt wpt = (WptPt) searchResult.object;
return FavoriteImageDrawable.getOrCreate(app, wpt.getColor(), false); return FavoriteImageDrawable.getOrCreate(app, wpt.getColor(), false);