Support custom categories and put them into USER_DEFINED

This commit is contained in:
vshcherb 2013-11-24 21:29:50 +01:00
parent bf9f0e5220
commit a9c6f8ebd3
7 changed files with 22 additions and 30 deletions

View file

@ -55,11 +55,11 @@ public class BinaryInspector {
BinaryInspector in = new BinaryInspector();
in.inspector(args);
// test cases show info
/*in.inspector(new String[]{
in.inspector(new String[]{
"-vpoi",
//"-vmap", "-vmapobjects",
//"-vstreets", "-bbox=14.4,50.1,14.5,50.01",
"/home/victor/projects/osmand/osm-gen/Map.obf"});*/
"/home/victor/projects/osmand/osm-gen/Austria_europe.obf"});
}
private void printToFile(String s) throws IOException {
@ -809,7 +809,7 @@ public class BinaryInspector {
println("\t\t\t" + st.name + " " + (st.text ? "text":(" encoded " + st.possibleValues.size())));
}
req.poiTypeFilter = null;//TODO: for test only
index.searchPoi(p, req);
// index.searchPoi(p, req);
}

View file

@ -60,12 +60,14 @@ public class AmenityType {
this.ordinal = ordinal;
}
public static AmenityType findRegisteredType(String s) {
return findRegisteredType(s, OTHER);
}
public static AmenityType findOrCreateTypeNoReg(String s) {
AmenityType type = findRegisteredType(s, null);
AmenityType type = null;
for (AmenityType t : amenityTypes.values()) {
if (t.name.equalsIgnoreCase(s)) {
type = t;
break;
}
}
if(type == null) {
type = new AmenityType(s, s, -1);
}
@ -77,15 +79,6 @@ public class AmenityType {
return type.ordinal >= 0;
}
public static AmenityType findRegisteredType(String s, AmenityType def) {
for (AmenityType t : amenityTypes.values()) {
if (t.name.equalsIgnoreCase(s)) {
return t;
}
}
return def;
}
public static AmenityType getAndRegisterType(String name) {
return reg(name, name);
}

View file

@ -383,7 +383,7 @@ public class MapRenderingTypes {
if (poiParentCategory != null) {
rtype.poiCategory = AmenityType.findRegisteredType(poiParentCategory, null);
rtype.poiCategory = AmenityType.getAndRegisterType(poiParentCategory);
rtype.poiSpecified = true;
}
if (poiParentPrefix != null) {

View file

@ -166,11 +166,14 @@ public class OsmAndFormatter {
return type + " " + n; //$NON-NLS-1$
}
public static String getAmenityDescriptionContent(ClientContext ctx, Amenity amenity) {
public static String getAmenityDescriptionContent(ClientContext ctx, Amenity amenity, boolean shortDescription) {
StringBuilder d = new StringBuilder();
for(Entry<String, String> e : amenity.getAdditionalInfo().entrySet()) {
String key = e.getKey();
if(Amenity.DESCRIPTION.equals(key)) {
if(amenity.getType() == AmenityType.OSMWIKI && shortDescription) {
continue;
}
} else if(Amenity.OPENING_HOURS.equals(key)) {
d.append(ctx.getString(R.string.opening_hours) + " : ");
} else if(Amenity.PHONE.equals(key)) {

View file

@ -201,7 +201,7 @@ public class PoiFilter {
public boolean acceptTypeSubtype(AmenityType t, String subtype){
if(!AmenityType.isRegisteredType(t)) {
t = AmenityType.OTHER;
t = AmenityType.USER_DEFINED;
}
if(!acceptedTypes.containsKey(t)){
return false;

View file

@ -555,12 +555,12 @@ public class SearchPOIActivity extends OsmandListActivity implements OsmAndCompa
ActionItem poiDescription = new ActionItem();
poiDescription.setIcon(getResources().getDrawable(R.drawable.ic_action_note_light));
poiDescription.setTitle(getString(R.string.poi_context_menu_showdescription));
final String d = getDescriptionContent(amenity);
final String d = OsmAndFormatter.getAmenityDescriptionContent(getMyApplication(), amenity, false);
poiDescription.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// Build text
// Build text(amenity)
// Find and format links
SpannableString spannable = new SpannableString(d);
@ -600,10 +600,6 @@ public class SearchPOIActivity extends OsmandListActivity implements OsmAndCompa
}
private String getDescriptionContent(final Amenity amenity) {
return OsmAndFormatter.getAmenityDescriptionContent(getMyApplication(), amenity);
}
static class SearchAmenityRequest {
private static final int SEARCH_AGAIN = 1;
@ -876,7 +872,7 @@ public class SearchPOIActivity extends OsmandListActivity implements OsmAndCompa
String direction = navigationInfo.getDirectionString(amenity.getLocation(), heading);
if (direction != null)
attributes.add(direction);
String[] as = OsmAndFormatter.getAmenityDescriptionContent(getMyApplication(), amenity).split("\n");
String[] as = OsmAndFormatter.getAmenityDescriptionContent(getMyApplication(), amenity, false).split("\n");
for(String s: as) {
attributes.add(s.replace(':', ' '));
}

View file

@ -111,7 +111,7 @@ public class POIMapLayer extends OsmandMapLayer implements ContextMenuLayer.ICon
private StringBuilder buildPoiInformation(StringBuilder res, Amenity n) {
String format = OsmAndFormatter.getPoiSimpleFormat(n, view.getApplication(), view.getSettings().USE_ENGLISH_NAMES.get());
res.append(" " + format + "\n" + OsmAndFormatter.getAmenityDescriptionContent(view.getApplication(), n));
res.append(" " + format + "\n" + OsmAndFormatter.getAmenityDescriptionContent(view.getApplication(), n, true));
return res;
}
@ -322,7 +322,7 @@ public class POIMapLayer extends OsmandMapLayer implements ContextMenuLayer.ICon
}
}
};
if(OsmAndFormatter.getAmenityDescriptionContent(view.getApplication(), a).length() > 0){
if(OsmAndFormatter.getAmenityDescriptionContent(view.getApplication(), a, false).length() > 0){
adapter.item(R.string.poi_context_menu_showdescription)
.icons(R.drawable.ic_action_note_dark,R.drawable.ic_action_note_light)
.listen(listener).reg();
@ -343,7 +343,7 @@ public class POIMapLayer extends OsmandMapLayer implements ContextMenuLayer.ICon
if(a.getType() == AmenityType.OSMWIKI) {
bs.setMessage(a.getDescription());
} else {
bs.setMessage(OsmAndFormatter.getAmenityDescriptionContent(view.getApplication(), a));
bs.setMessage(OsmAndFormatter.getAmenityDescriptionContent(view.getApplication(), a, false));
}
bs.show();
}