Search in sources :

Example 1 with MapPoiTypes

use of net.osmand.osm.MapPoiTypes in project OsmAnd-tools by osmandapp.

the class IndexCreator method main.

public static void main(String[] args) throws IOException, SQLException, InterruptedException, XmlPullParserException {
    long time = System.currentTimeMillis();
    // if(true){ generateRegionsFile(); return;}
    String rootFolder = "/Users/victorshcherb/osmand/";
    IndexPoiCreator.ZIP_LONG_STRINGS = false;
    // $NON-NLS-1$
    IndexCreator creator = new IndexCreator(new File(rootFolder + "/maps/"));
    creator.setIndexMap(true);
    // creator.setIndexAddress(true);
    creator.setIndexPOI(true);
    // creator.setIndexTransport(true);
    creator.setIndexRouting(true);
    // creator.deleteDatabaseIndexes = false;
    // creator.recreateOnlyBinaryFile = true;
    // creator.deleteOsmDB = false;
    creator.setZoomWaySmoothness(2);
    // MapZooms.parseZooms("15-");
    MapZooms zooms = MapZooms.getDefault();
    String file = rootFolder + "/temp/map.osm";
    // String file = rootFolder + "/temp/ukraine_kiev-city_europe.pbf";
    // String file = rootFolder + "/maps/diff/2017_08_28_00_30_before.osm";
    // String file = rootFolder + "/maps/diff/ukraine_kiev-city_europe.pbf";
    // String file = rootFolder + "/repos/resources/test-resources/synthetic_test_rendering.osm";
    int st = file.lastIndexOf('/');
    int e = file.indexOf('.', st);
    creator.setNodesDBFile(new File(rootFolder + "/maps/" + file.substring(st, e) + ".tmp.odb"));
    creator.setSRTMData(new File(rootFolder + "/maps/srtm/"));
    MapPoiTypes.setDefault(new MapPoiTypes(rootFolder + "/repos//resources/poi/poi_types.xml"));
    MapRenderingTypesEncoder rt = new MapRenderingTypesEncoder(rootFolder + "/repos//resources/obf_creation/rendering_types.xml", new File(file).getName());
    creator.setLastModifiedDate(1504224000000l);
    creator.generateIndexes(new File(file), new ConsoleProgressImplementation(1), null, zooms, rt, log);
    // new File(file),
    // $NON-NLS-1$
    log.info("WHOLE GENERATION TIME :  " + (System.currentTimeMillis() - time));
    // $NON-NLS-1$ //$NON-NLS-2$
    log.info("COORDINATES_SIZE " + BinaryMapIndexWriter.COORDINATES_SIZE + " count " + BinaryMapIndexWriter.COORDINATES_COUNT);
    // $NON-NLS-1$
    log.info("TYPES_SIZE " + BinaryMapIndexWriter.TYPES_SIZE);
    // $NON-NLS-1$
    log.info("ID_SIZE " + BinaryMapIndexWriter.ID_SIZE);
    // $NON-NLS-1$
    log.info("- COORD_TYPES_ID SIZE " + (BinaryMapIndexWriter.COORDINATES_SIZE + BinaryMapIndexWriter.TYPES_SIZE + BinaryMapIndexWriter.ID_SIZE));
    // $NON-NLS-1$
    log.info("- MAP_DATA_SIZE " + BinaryMapIndexWriter.MAP_DATA_SIZE);
    // $NON-NLS-1$
    log.info("- STRING_TABLE_SIZE " + BinaryMapIndexWriter.STRING_TABLE_SIZE);
    // $NON-NLS-1$
    log.info("-- MAP_DATA_AND_STRINGS SIZE " + (BinaryMapIndexWriter.MAP_DATA_SIZE + BinaryMapIndexWriter.STRING_TABLE_SIZE));
}
Also used : MapRenderingTypesEncoder(net.osmand.osm.MapRenderingTypesEncoder) MapZooms(net.osmand.binary.MapZooms) RandomAccessFile(java.io.RandomAccessFile) File(java.io.File) ConsoleProgressImplementation(net.osmand.impl.ConsoleProgressImplementation) MapPoiTypes(net.osmand.osm.MapPoiTypes)

Example 2 with MapPoiTypes

use of net.osmand.osm.MapPoiTypes in project Osmand by osmandapp.

the class QuickSearchPoiFilterFragment method getListItems.

private List<PoiFilterListItem> getListItems() {
    OsmandApplication app = getMyApplication();
    MapPoiTypes poiTypes = app.getPoiTypes();
    int groupId = 0;
    List<PoiFilterListItem> items = new ArrayList<>();
    Map<String, PoiType> poiAdditionals = filter.getPoiAdditionals();
    Set<String> excludedPoiAdditionalCategories = getExcludedPoiAdditionalCategories();
    List<PoiType> otherAdditionalCategories = poiTypes.getOtherMapCategory().getPoiAdditionalsCategorized();
    if (!excludedPoiAdditionalCategories.contains("opening_hours")) {
        items.add(new PoiFilterListItem(PoiFilterListItemType.DIVIDER, 0, null, -1, false, false, false, null, null));
        String keyNameOpen = app.getString(R.string.shared_string_is_open).replace(' ', '_').toLowerCase();
        items.add(new PoiFilterListItem(PoiFilterListItemType.SWITCH_ITEM, R.drawable.ic_action_time, app.getString(R.string.shared_string_is_open), ++groupId, false, false, selectedPoiAdditionals.contains(keyNameOpen), null, keyNameOpen));
        String keyNameOpen24 = app.getString(R.string.shared_string_is_open_24_7).replace(' ', '_').toLowerCase();
        items.add(new PoiFilterListItem(PoiFilterListItemType.SWITCH_ITEM, 0, app.getString(R.string.shared_string_is_open_24_7), groupId, false, false, selectedPoiAdditionals.contains(keyNameOpen24), null, keyNameOpen24));
    }
    if (poiAdditionals != null) {
        Map<String, List<PoiType>> additionalsMap = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
        extractPoiAdditionals(poiAdditionals.values(), additionalsMap, excludedPoiAdditionalCategories, false);
        extractPoiAdditionals(otherAdditionalCategories, additionalsMap, excludedPoiAdditionalCategories, false);
        if (additionalsMap.size() > 0) {
            for (Entry<String, List<PoiType>> entry : additionalsMap.entrySet()) {
                String category = entry.getKey();
                String categoryLocalizedName = poiTypes.getPoiTranslation(category);
                boolean expanded = !collapsedCategories.contains(category);
                boolean showAll = showAllCategories.contains(category);
                items.add(new PoiFilterListItem(PoiFilterListItemType.DIVIDER, 0, null, -1, false, false, false, null, null));
                String categoryIconStr = poiTypes.getPoiAdditionalCategoryIconName(category);
                int categoryIconId = 0;
                if (!Algorithms.isEmpty(categoryIconStr)) {
                    categoryIconId = RenderingIcons.getBigIconResourceId(categoryIconStr);
                }
                if (categoryIconId == 0) {
                    categoryIconId = getResources().getIdentifier("mx_" + category, "drawable", app.getPackageName());
                }
                if (categoryIconId == 0) {
                    categoryIconId = R.drawable.ic_action_folder_stroke;
                }
                items.add(new PoiFilterListItem(PoiFilterListItemType.GROUP_HEADER, categoryIconId, categoryLocalizedName, ++groupId, true, expanded, false, category, null));
                List<PoiType> categoryPoiAdditionals = new ArrayList<>(entry.getValue());
                Collections.sort(categoryPoiAdditionals, new Comparator<PoiType>() {

                    @Override
                    public int compare(PoiType p1, PoiType p2) {
                        String firstPoiTypeTranslation = poiAdditionalsTranslations.get(p1);
                        String secondPoiTypeTranslation = poiAdditionalsTranslations.get(p2);
                        if (firstPoiTypeTranslation != null && secondPoiTypeTranslation != null) {
                            return firstPoiTypeTranslation.compareTo(secondPoiTypeTranslation);
                        } else {
                            return 0;
                        }
                    }
                });
                for (PoiType poiType : categoryPoiAdditionals) {
                    String keyName = poiType.getKeyName().replace('_', ':').toLowerCase();
                    String translation = poiAdditionalsTranslations.get(poiType);
                    items.add(new PoiFilterListItem(PoiFilterListItemType.CHECKBOX_ITEM, 0, translation, groupId, false, false, selectedPoiAdditionals.contains(keyName), category, keyName));
                }
                if (!showAll && categoryPoiAdditionals.size() > 0) {
                    items.add(new PoiFilterListItem(PoiFilterListItemType.BUTTON_ITEM, 0, app.getString(R.string.shared_string_show_all).toUpperCase(), groupId, false, false, false, category, null));
                }
            }
        }
    }
    return items;
}
Also used : OsmandApplication(net.osmand.plus.OsmandApplication) ArrayList(java.util.ArrayList) AbstractPoiType(net.osmand.osm.AbstractPoiType) PoiType(net.osmand.osm.PoiType) TreeMap(java.util.TreeMap) MapPoiTypes(net.osmand.osm.MapPoiTypes) List(java.util.List) ArrayList(java.util.ArrayList)

Example 3 with MapPoiTypes

use of net.osmand.osm.MapPoiTypes in project Osmand by osmandapp.

the class AddPOIAction method drawUI.

@Override
public void drawUI(final ViewGroup parent, final MapActivity activity) {
    final View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.quick_action_add_poi_layout, parent, false);
    final OsmandApplication application = activity.getMyApplication();
    Drawable deleteDrawable = application.getIconsCache().getPaintedIcon(R.drawable.ic_action_remove_dark, activity.getResources().getColor(R.color.dash_search_icon_dark));
    final LinearLayout editTagsLineaLayout = (LinearLayout) view.findViewById(R.id.editTagsList);
    final MapPoiTypes poiTypes = application.getPoiTypes();
    final Map<String, PoiType> allTranslatedNames = poiTypes.getAllTranslatedNames(true);
    final TagAdapterLinearLayoutHack mAdapter = new TagAdapterLinearLayoutHack(editTagsLineaLayout, getTagsFromParams(), deleteDrawable);
    // It is possible to not restart initialization every time, and probably move initialization to appInit
    Map<String, PoiType> translatedTypes = poiTypes.getAllTranslatedNames(true);
    HashSet<String> tagKeys = new HashSet<>();
    HashSet<String> valueKeys = new HashSet<>();
    for (AbstractPoiType abstractPoiType : translatedTypes.values()) {
        addPoiToStringSet(abstractPoiType, tagKeys, valueKeys);
    }
    addPoiToStringSet(poiTypes.getOtherMapCategory(), tagKeys, valueKeys);
    tagKeys.addAll(EditPoiDialogFragment.BASIC_TAGS);
    mAdapter.setTagData(tagKeys.toArray(new String[tagKeys.size()]));
    mAdapter.setValueData(valueKeys.toArray(new String[valueKeys.size()]));
    Button addTagButton = (Button) view.findViewById(R.id.addTagButton);
    addTagButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            for (int i = 0; i < editTagsLineaLayout.getChildCount(); i++) {
                View item = editTagsLineaLayout.getChildAt(i);
                if (((EditText) item.findViewById(R.id.tagEditText)).getText().toString().isEmpty() && ((EditText) item.findViewById(R.id.valueEditText)).getText().toString().isEmpty())
                    return;
            }
            mAdapter.addTagView("", "");
        }
    });
    mAdapter.updateViews();
    final TextInputLayout poiTypeTextInputLayout = (TextInputLayout) view.findViewById(R.id.poiTypeTextInputLayout);
    final AutoCompleteTextView poiTypeEditText = (AutoCompleteTextView) view.findViewById(R.id.poiTypeEditText);
    final SwitchCompat showDialog = (SwitchCompat) view.findViewById(R.id.saveButton);
    // showDialog.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
    // @Override
    // public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
    // getParams().put(KEY_DIALOG, Boolean.toString(isChecked));
    // }
    // });
    showDialog.setChecked(Boolean.valueOf(getParams().get(KEY_DIALOG)));
    final String text = getTagsFromParams().get(POI_TYPE_TAG);
    poiTypeEditText.addTextChangedListener(new TextWatcher() {

        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        }

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
        }

        @Override
        public void afterTextChanged(Editable s) {
            String tp = s.toString();
            putTagIntoParams(POI_TYPE_TAG, tp);
            PoiCategory category = getCategory(allTranslatedNames);
            if (category != null) {
                poiTypeTextInputLayout.setHint(category.getTranslation());
            }
            String add = application.getString(R.string.shared_string_add);
            if (title != null) {
                if (prevType.equals(title.getText().toString()) || title.getText().toString().equals(activity.getString(getNameRes())) || title.getText().toString().equals((add + " "))) {
                    if (!tp.isEmpty()) {
                        title.setText(add + " " + tp);
                        prevType = title.getText().toString();
                    }
                }
            }
        }
    });
    poiTypeEditText.setText(text != null ? text : "");
    poiTypeEditText.setOnTouchListener(new View.OnTouchListener() {

        @Override
        public boolean onTouch(final View v, MotionEvent event) {
            final EditText editText = (EditText) v;
            final int DRAWABLE_RIGHT = 2;
            if (event.getAction() == MotionEvent.ACTION_UP) {
                if (event.getX() >= (editText.getRight() - editText.getCompoundDrawables()[DRAWABLE_RIGHT].getBounds().width() - editText.getPaddingRight())) {
                    PoiCategory category = getCategory(allTranslatedNames);
                    PoiCategory tempPoiCategory = (category != null) ? category : poiTypes.getOtherPoiCategory();
                    PoiSubTypeDialogFragment f = PoiSubTypeDialogFragment.createInstance(tempPoiCategory);
                    f.setOnItemSelectListener(new PoiSubTypeDialogFragment.OnItemSelectListener() {

                        @Override
                        public void select(String category) {
                            poiTypeEditText.setText(category);
                        }
                    });
                    CreateEditActionDialog parentFragment = (CreateEditActionDialog) activity.getSupportFragmentManager().findFragmentByTag(CreateEditActionDialog.TAG);
                    f.show(activity.getSupportFragmentManager(), "PoiSubTypeDialogFragment");
                    return true;
                }
            }
            return false;
        }
    });
    setUpAdapterForPoiTypeEditText(activity, allTranslatedNames, poiTypeEditText);
    ImageButton onlineDocumentationButton = (ImageButton) view.findViewById(R.id.onlineDocumentationButton);
    onlineDocumentationButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            activity.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://wiki.openstreetmap.org/wiki/Map_Features")));
        }
    });
    boolean isLightTheme = activity.getMyApplication().getSettings().OSMAND_THEME.get() == OsmandSettings.OSMAND_LIGHT_THEME;
    final int colorId = isLightTheme ? R.color.inactive_item_orange : R.color.dash_search_icon_dark;
    final int color = activity.getResources().getColor(colorId);
    onlineDocumentationButton.setImageDrawable(activity.getMyApplication().getIconsCache().getPaintedIcon(R.drawable.ic_action_help, color));
    // poiTypeEditText.setCompoundDrawables(null, null, activity.getMyApplication().getIconsCache().getPaintedIcon(R.drawable.ic_action_arrow_drop_down, color), null);
    // Button addTypeButton = (Button) view.findViewById(R.id.addTypeButton);
    // addTypeButton.setOnClickListener(new View.OnClickListener() {
    // @Override
    // public void onClick(View v) {
    // PoiSubTypeDialogFragment f = PoiSubTypeDialogFragment.createInstance(poiTypes.getOtherPoiCategory());
    // f.setOnItemSelectListener(new PoiSubTypeDialogFragment.OnItemSelectListener() {
    // @Override
    // public void select(String category) {
    // putTagIntoParams(POI_TYPE_TAG, category);
    // }
    // });
    // 
    // CreateEditActionDialog parentFragment = (CreateEditActionDialog) activity.getSupportFragmentManager().findFragmentByTag(CreateEditActionDialog.TAG);
    // f.show(parentFragment.getChildFragmentManager(), "PoiSubTypeDialogFragment");
    // }
    // });
    parent.addView(view);
}
Also used : OsmandApplication(net.osmand.plus.OsmandApplication) AbstractPoiType(net.osmand.osm.AbstractPoiType) PoiType(net.osmand.osm.PoiType) PoiSubTypeDialogFragment(net.osmand.plus.osmedit.dialogs.PoiSubTypeDialogFragment) ImageButton(android.widget.ImageButton) ImageButton(android.widget.ImageButton) Button(android.widget.Button) TextWatcher(android.text.TextWatcher) Editable(android.text.Editable) TextInputLayout(android.support.design.widget.TextInputLayout) HashSet(java.util.HashSet) EditText(android.widget.EditText) Drawable(android.graphics.drawable.Drawable) Intent(android.content.Intent) AbstractPoiType(net.osmand.osm.AbstractPoiType) View(android.view.View) AdapterView(android.widget.AdapterView) TextView(android.widget.TextView) AutoCompleteTextView(android.widget.AutoCompleteTextView) MapPoiTypes(net.osmand.osm.MapPoiTypes) OpenstreetmapPoint(net.osmand.plus.osmedit.OpenstreetmapPoint) OsmPoint(net.osmand.plus.osmedit.OsmPoint) MotionEvent(android.view.MotionEvent) CreateEditActionDialog(net.osmand.plus.quickaction.CreateEditActionDialog) PoiCategory(net.osmand.osm.PoiCategory) LinearLayout(android.widget.LinearLayout) AutoCompleteTextView(android.widget.AutoCompleteTextView) SwitchCompat(android.support.v7.widget.SwitchCompat)

Example 4 with MapPoiTypes

use of net.osmand.osm.MapPoiTypes in project Osmand by osmandapp.

the class BinaryMapIndexReader method testSearchOnthePath.

private static void testSearchOnthePath(BinaryMapIndexReader reader) throws IOException {
    float radius = 1000;
    final MapPoiTypes poiTypes = MapPoiTypes.getDefault();
    long now = System.currentTimeMillis();
    println("Searching poi on the path...");
    final List<Location> locations = readGPX(new File("/Users/victorshcherb/osmand/maps/2015-03-07_19-07_Sat.gpx"));
    SearchRequest<Amenity> req = buildSearchPoiRequest(locations, radius, new SearchPoiTypeFilter() {

        @Override
        public boolean accept(PoiCategory type, String subcategory) {
            if (type == poiTypes.getPoiCategoryByName("shop") && subcategory.contains("super")) {
                return true;
            }
            return false;
        }

        @Override
        public boolean isEmpty() {
            return false;
        }
    }, null);
    req.zoom = -1;
    List<Amenity> results = reader.searchPoi(req);
    int k = 0;
    println("Search done in " + (System.currentTimeMillis() - now) + " ms ");
    now = System.currentTimeMillis();
    for (Amenity a : results) {
        final float dds = dist(a.getLocation(), locations);
        if (dds <= radius) {
            println("+ " + a.getType() + " " + a.getSubType() + " Dist " + dds + " (=" + (float) a.getRoutePoint().deviateDistance + ") " + a.getName() + " " + a.getLocation());
            k++;
        } else {
            println(a.getType() + " " + a.getSubType() + " Dist " + dds + " " + a.getName() + " " + a.getLocation());
        }
    }
    println("Filtered in " + (System.currentTimeMillis() - now) + "ms " + k + " of " + results.size());
}
Also used : Amenity(net.osmand.data.Amenity) MapPoiTypes(net.osmand.osm.MapPoiTypes) PoiCategory(net.osmand.osm.PoiCategory) RandomAccessFile(java.io.RandomAccessFile) File(java.io.File) Location(net.osmand.Location)

Example 5 with MapPoiTypes

use of net.osmand.osm.MapPoiTypes in project Osmand by osmandapp.

the class AmenityMenuBuilder method buildInternal.

@Override
public void buildInternal(View view) {
    boolean hasWiki = false;
    MapPoiTypes poiTypes = app.getPoiTypes();
    String preferredLang = getPreferredMapAppLang();
    List<AmenityInfoRow> infoRows = new LinkedList<>();
    List<AmenityInfoRow> descriptions = new LinkedList<>();
    Map<String, List<PoiType>> poiAdditionalCategories = new HashMap<>();
    AmenityInfoRow cuisineRow = null;
    for (Map.Entry<String, String> e : amenity.getAdditionalInfo().entrySet()) {
        int iconId = 0;
        Drawable icon = null;
        int textColor = 0;
        String key = e.getKey();
        String vl = e.getValue();
        if (key.equals("image") || key.equals("mapillary") || key.equals("subway_region")) {
            continue;
        }
        String textPrefix = "";
        CollapsableView collapsableView = null;
        boolean collapsable = false;
        boolean isWiki = false;
        boolean isText = false;
        boolean isDescription = false;
        boolean needLinks = !"population".equals(key);
        boolean isPhoneNumber = false;
        boolean isUrl = false;
        boolean isCuisine = false;
        int poiTypeOrder = 0;
        String poiTypeKeyName = "";
        AbstractPoiType pt = poiTypes.getAnyPoiAdditionalTypeByKey(key);
        if (pt == null && !Algorithms.isEmpty(vl) && vl.length() < 50) {
            pt = poiTypes.getAnyPoiAdditionalTypeByKey(key + "_" + vl);
        }
        PoiType pType = null;
        if (pt != null) {
            pType = (PoiType) pt;
            if (pType.isFilterOnly()) {
                continue;
            }
            poiTypeOrder = pType.getOrder();
            poiTypeKeyName = pType.getKeyName();
        }
        if (pType != null && !pType.isText()) {
            String categoryName = pType.getPoiAdditionalCategory();
            if (!Algorithms.isEmpty(categoryName)) {
                List<PoiType> poiAdditionalCategoryTypes = poiAdditionalCategories.get(categoryName);
                if (poiAdditionalCategoryTypes == null) {
                    poiAdditionalCategoryTypes = new ArrayList<>();
                    poiAdditionalCategories.put(categoryName, poiAdditionalCategoryTypes);
                }
                poiAdditionalCategoryTypes.add(pType);
                continue;
            }
        }
        if (amenity.getType().isWiki()) {
            if (!hasWiki) {
                String lng = amenity.getContentLanguage("content", preferredLang, "en");
                if (Algorithms.isEmpty(lng)) {
                    lng = "en";
                }
                final String langSelected = lng;
                String content = amenity.getDescription(langSelected);
                vl = (content != null) ? Html.fromHtml(content).toString() : "";
                if (vl.length() > 300) {
                    vl = vl.substring(0, 300);
                }
                hasWiki = true;
                isWiki = true;
                needLinks = false;
            } else {
                continue;
            }
        } else if (key.startsWith("name:")) {
            continue;
        } else if (Amenity.OPENING_HOURS.equals(key)) {
            iconId = R.drawable.ic_action_time;
            collapsableView = getCollapsableTextView(view.getContext(), true, amenity.getOpeningHours());
            collapsable = true;
            OpeningHoursParser.OpeningHours rs = OpeningHoursParser.parseOpenedHours(amenity.getOpeningHours());
            if (rs != null) {
                vl = rs.toLocalString();
                Calendar inst = Calendar.getInstance();
                inst.setTimeInMillis(System.currentTimeMillis());
                boolean opened = rs.isOpenedForTime(inst);
                if (opened) {
                    textColor = R.color.color_ok;
                } else {
                    textColor = R.color.color_invalid;
                }
            }
            needLinks = false;
        } else if (Amenity.PHONE.equals(key)) {
            iconId = R.drawable.ic_action_call_dark;
            isPhoneNumber = true;
        } else if (Amenity.WEBSITE.equals(key)) {
            iconId = R.drawable.ic_world_globe_dark;
            isUrl = true;
        } else if (Amenity.CUISINE.equals(key)) {
            isCuisine = true;
            iconId = R.drawable.ic_action_cuisine;
            StringBuilder sb = new StringBuilder();
            for (String c : e.getValue().split(";")) {
                if (sb.length() > 0) {
                    sb.append(", ");
                    sb.append(poiTypes.getPoiTranslation("cuisine_" + c).toLowerCase());
                } else {
                    sb.append(poiTypes.getPoiTranslation("cuisine_" + c));
                }
            }
            textPrefix = app.getString(R.string.poi_cuisine);
            vl = sb.toString();
        } else if (key.contains(Amenity.ROUTE)) {
            continue;
        } else {
            if (key.contains(Amenity.DESCRIPTION)) {
                iconId = R.drawable.ic_action_note_dark;
            } else {
                iconId = R.drawable.ic_action_info_dark;
            }
            if (pType != null) {
                poiTypeOrder = pType.getOrder();
                poiTypeKeyName = pType.getKeyName();
                if (pType.getParentType() != null && pType.getParentType() instanceof PoiType) {
                    icon = getRowIcon(view.getContext(), ((PoiType) pType.getParentType()).getOsmTag() + "_" + pType.getOsmTag().replace(':', '_') + "_" + pType.getOsmValue());
                }
                if (!pType.isText()) {
                    vl = pType.getTranslation();
                } else {
                    isText = true;
                    isDescription = iconId == R.drawable.ic_action_note_dark;
                    textPrefix = pType.getTranslation();
                    vl = amenity.unzipContent(e.getValue());
                }
                if (!isDescription && icon == null) {
                    icon = getRowIcon(view.getContext(), pType.getIconKeyName());
                    if (isText && icon != null) {
                        textPrefix = "";
                    }
                }
                if (icon == null && isText) {
                    iconId = R.drawable.ic_action_note_dark;
                }
            } else {
                textPrefix = Algorithms.capitalizeFirstLetterAndLowercase(e.getKey());
                vl = amenity.unzipContent(e.getValue());
            }
        }
        if (vl.startsWith("http://") || vl.startsWith("https://") || vl.startsWith("HTTP://") || vl.startsWith("HTTPS://")) {
            isUrl = true;
        }
        boolean matchWidthDivider = !isDescription && isWiki;
        AmenityInfoRow row;
        if (isDescription) {
            row = new AmenityInfoRow(key, R.drawable.ic_action_note_dark, textPrefix, vl, collapsable, collapsableView, 0, false, true, true, 0, "", false, false, matchWidthDivider, 0);
        } else if (icon != null) {
            row = new AmenityInfoRow(key, icon, textPrefix, vl, collapsable, collapsableView, textColor, isWiki, isText, needLinks, poiTypeOrder, poiTypeKeyName, isPhoneNumber, isUrl, matchWidthDivider, 0);
        } else {
            row = new AmenityInfoRow(key, iconId, textPrefix, vl, collapsable, collapsableView, textColor, isWiki, isText, needLinks, poiTypeOrder, poiTypeKeyName, isPhoneNumber, isUrl, matchWidthDivider, 0);
        }
        if (isDescription) {
            descriptions.add(row);
        } else {
            if (!isCuisine) {
                infoRows.add(row);
            } else {
                cuisineRow = row;
            }
        }
    }
    if (cuisineRow != null) {
        boolean hasCuisineOrDish = poiAdditionalCategories.get(Amenity.CUISINE) != null || poiAdditionalCategories.get(Amenity.DISH) != null;
        if (!hasCuisineOrDish) {
            infoRows.add(cuisineRow);
        }
    }
    for (Map.Entry<String, List<PoiType>> e : poiAdditionalCategories.entrySet()) {
        String categoryName = e.getKey();
        List<PoiType> categoryTypes = e.getValue();
        if (categoryTypes.size() > 0) {
            Drawable icon;
            PoiType pType = categoryTypes.get(0);
            String poiAdditionalCategoryName = pType.getPoiAdditionalCategory();
            String poiAddidionalIconName = poiTypes.getPoiAdditionalCategoryIconName(poiAdditionalCategoryName);
            icon = getRowIcon(view.getContext(), poiAddidionalIconName);
            if (icon == null) {
                icon = getRowIcon(view.getContext(), poiAdditionalCategoryName);
            }
            if (icon == null) {
                icon = getRowIcon(view.getContext(), pType.getIconKeyName());
            }
            if (icon == null) {
                icon = getRowIcon(R.drawable.ic_action_note_dark);
            }
            StringBuilder sb = new StringBuilder();
            for (PoiType pt : categoryTypes) {
                if (sb.length() > 0) {
                    sb.append(" • ");
                }
                sb.append(pt.getTranslation());
            }
            boolean cuisineOrDish = categoryName.equals(Amenity.CUISINE) || categoryName.equals(Amenity.DISH);
            CollapsableView collapsableView = getPoiAdditionalCollapsableView(view.getContext(), true, categoryTypes, cuisineOrDish ? cuisineRow : null);
            infoRows.add(new AmenityInfoRow(poiAdditionalCategoryName, icon, pType.getPoiAdditionalCategoryTranslation(), sb.toString(), true, collapsableView, 0, false, false, false, pType.getOrder(), pType.getKeyName(), false, false, false, 1));
        }
    }
    Collections.sort(infoRows, new Comparator<AmenityInfoRow>() {

        @Override
        public int compare(AmenityInfoRow row1, AmenityInfoRow row2) {
            if (row1.order < row2.order) {
                return -1;
            } else if (row1.order == row2.order) {
                return row1.name.compareTo(row2.name);
            } else {
                return 1;
            }
        }
    });
    for (AmenityInfoRow info : infoRows) {
        buildAmenityRow(view, info);
    }
    String langSuffix = ":" + preferredLang;
    AmenityInfoRow descInPrefLang = null;
    for (AmenityInfoRow desc : descriptions) {
        if (desc.key.length() > langSuffix.length() && desc.key.substring(desc.key.length() - langSuffix.length(), desc.key.length()).equals(langSuffix)) {
            descInPrefLang = desc;
            break;
        }
    }
    if (descInPrefLang != null) {
        descriptions.remove(descInPrefLang);
        descriptions.add(0, descInPrefLang);
    }
    for (AmenityInfoRow info : descriptions) {
        buildAmenityRow(view, info);
    }
    if (processNearstWiki() && nearestWiki.size() > 0) {
        AmenityInfoRow wikiInfo = new AmenityInfoRow("nearest_wiki", R.drawable.ic_action_wikipedia, null, app.getString(R.string.wiki_around) + " (" + nearestWiki.size() + ")", true, getCollapsableWikiView(view.getContext(), true), 0, false, false, false, 1000, null, false, false, false, 0);
        buildAmenityRow(view, wikiInfo);
    }
    OsmandSettings st = ((OsmandApplication) mapActivity.getApplicationContext()).getSettings();
    boolean osmEditingEnabled = OsmandPlugin.getEnabledPlugin(OsmEditingPlugin.class) != null;
    if (osmEditingEnabled && amenity.getId() != null && amenity.getId() > 0 && (amenity.getId() % 2 == 0 || (amenity.getId() >> 1) < Integer.MAX_VALUE)) {
        String link;
        if (amenity.getId() % 2 == 0) {
            link = "https://www.openstreetmap.org/node/";
        } else {
            link = "https://www.openstreetmap.org/way/";
        }
        buildRow(view, R.drawable.ic_action_info_dark, null, link + (amenity.getId() >> 1), 0, false, null, true, 0, true, null, false);
    }
    buildRow(view, R.drawable.ic_action_get_my_location, null, PointDescription.getLocationName(app, amenity.getLocation().getLatitude(), amenity.getLocation().getLongitude(), true).replaceAll("\n", " "), 0, false, null, false, 0, false, null, false);
}
Also used : OsmandApplication(net.osmand.plus.OsmandApplication) HashMap(java.util.HashMap) AbstractPoiType(net.osmand.osm.AbstractPoiType) PoiType(net.osmand.osm.PoiType) ArrayList(java.util.ArrayList) ColorStateList(android.content.res.ColorStateList) LinkedList(java.util.LinkedList) List(java.util.List) Calendar(java.util.Calendar) Drawable(android.graphics.drawable.Drawable) AbstractPoiType(net.osmand.osm.AbstractPoiType) OpeningHoursParser(net.osmand.util.OpeningHoursParser) MapPoiTypes(net.osmand.osm.MapPoiTypes) LinkedList(java.util.LinkedList) OsmandSettings(net.osmand.plus.OsmandSettings) OsmEditingPlugin(net.osmand.plus.osmedit.OsmEditingPlugin) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

MapPoiTypes (net.osmand.osm.MapPoiTypes)17 AbstractPoiType (net.osmand.osm.AbstractPoiType)11 PoiType (net.osmand.osm.PoiType)10 OsmandApplication (net.osmand.plus.OsmandApplication)7 PoiCategory (net.osmand.osm.PoiCategory)6 ArrayList (java.util.ArrayList)5 Drawable (android.graphics.drawable.Drawable)3 NonNull (android.support.annotation.NonNull)3 View (android.view.View)3 TextView (android.widget.TextView)3 List (java.util.List)3 Map (java.util.Map)3 Amenity (net.osmand.data.Amenity)3 DialogInterface (android.content.DialogInterface)2 AlertDialog (android.support.v7.app.AlertDialog)2 AutoCompleteTextView (android.widget.AutoCompleteTextView)2 Button (android.widget.Button)2 ImageButton (android.widget.ImageButton)2 LinearLayout (android.widget.LinearLayout)2 File (java.io.File)2