Search in sources :

Example 1 with PoiCategory

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

the class XMasDialogFragment method onCreateDialog.

@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    XmasDialogWasProcessed = true;
    final MapActivity mapActivity = (MapActivity) getActivity();
    final AlertDialog.Builder builder = new AlertDialog.Builder(mapActivity, R.style.XmasDialogTheme);
    View titleView = mapActivity.getLayoutInflater().inflate(R.layout.xmas_dialog_title, null);
    builder.setCustomTitle(titleView);
    builder.setCancelable(true);
    builder.setNegativeButton(mapActivity.getString(R.string.shared_string_cancel), new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            dialog.dismiss();
        }
    });
    builder.setPositiveButton(mapActivity.getString(R.string.shared_string_show), new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            dialog.dismiss();
            PoiCategory xmas = mapActivity.getMyApplication().getPoiTypes().getPoiCategoryByName("xmas");
            if (xmas != null) {
                mapActivity.showQuickSearch(xmas);
            }
        }
    });
    builder.setView(mapActivity.getLayoutInflater().inflate(R.layout.xmas_dialog, null));
    AlertDialog dialog = builder.create();
    dialog.setOnShowListener(new DialogInterface.OnShowListener() {

        @Override
        public void onShow(DialogInterface dialog) {
            // Customize POSITIVE, NEGATIVE and NEUTRAL buttons.
            Button positiveButton = ((AlertDialog) dialog).getButton(DialogInterface.BUTTON_POSITIVE);
            positiveButton.setTextColor(mapActivity.getResources().getColor(R.color.color_white));
            positiveButton.invalidate();
            Button negativeButton = ((AlertDialog) dialog).getButton(DialogInterface.BUTTON_NEGATIVE);
            negativeButton.setTextColor(mapActivity.getResources().getColor(R.color.color_white));
            negativeButton.invalidate();
        }
    });
    return dialog;
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) DialogInterface(android.content.DialogInterface) Button(android.widget.Button) PoiCategory(net.osmand.osm.PoiCategory) View(android.view.View) MapActivity(net.osmand.plus.activities.MapActivity) NonNull(android.support.annotation.NonNull)

Example 2 with PoiCategory

use of net.osmand.osm.PoiCategory 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 3 with PoiCategory

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

the class QuickSearchListItem method getTypeName.

public static String getTypeName(OsmandApplication app, SearchResult searchResult) {
    switch(searchResult.objectType) {
        case CITY:
            City city = (City) searchResult.object;
            return getCityTypeStr(app, city.getType());
        case POSTCODE:
            return app.getString(R.string.postcode);
        case VILLAGE:
            city = (City) searchResult.object;
            if (!Algorithms.isEmpty(searchResult.localeRelatedObjectName)) {
                if (searchResult.distRelatedObjectName > 0) {
                    return getCityTypeStr(app, city.getType()) + " • " + OsmAndFormatter.getFormattedDistance((float) searchResult.distRelatedObjectName, app) + " " + app.getString(R.string.shared_string_from) + " " + searchResult.localeRelatedObjectName;
                } else {
                    return getCityTypeStr(app, city.getType()) + ", " + searchResult.localeRelatedObjectName;
                }
            } else {
                return getCityTypeStr(app, city.getType());
            }
        case STREET:
            StringBuilder streetBuilder = new StringBuilder();
            if (searchResult.localeName.endsWith(")")) {
                int i = searchResult.localeName.indexOf('(');
                if (i > 0) {
                    streetBuilder.append(searchResult.localeName.substring(i + 1, searchResult.localeName.length() - 1));
                }
            }
            if (!Algorithms.isEmpty(searchResult.localeRelatedObjectName)) {
                if (streetBuilder.length() > 0) {
                    streetBuilder.append(", ");
                }
                streetBuilder.append(searchResult.localeRelatedObjectName);
            }
            return streetBuilder.toString();
        case HOUSE:
            if (searchResult.relatedObject != null) {
                Street relatedStreet = (Street) searchResult.relatedObject;
                if (relatedStreet.getCity() != null) {
                    return searchResult.localeRelatedObjectName + ", " + relatedStreet.getCity().getName(searchResult.requiredSearchPhrase.getSettings().getLang(), true);
                } else {
                    return searchResult.localeRelatedObjectName;
                }
            }
            return "";
        case STREET_INTERSECTION:
            Street street = (Street) searchResult.object;
            if (street.getCity() != null) {
                return street.getCity().getName(searchResult.requiredSearchPhrase.getSettings().getLang(), true);
            }
            return "";
        case POI_TYPE:
            String res = "";
            if (searchResult.object instanceof AbstractPoiType) {
                AbstractPoiType abstractPoiType = (AbstractPoiType) searchResult.object;
                if (abstractPoiType instanceof PoiCategory) {
                    res = "";
                } else if (abstractPoiType instanceof PoiFilter) {
                    PoiFilter poiFilter = (PoiFilter) abstractPoiType;
                    res = poiFilter.getPoiCategory() != null ? poiFilter.getPoiCategory().getTranslation() : "";
                } 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 = "";
                    }
                } else {
                    res = "";
                }
            } else if (searchResult.object instanceof CustomSearchPoiFilter) {
                res = ((CustomSearchPoiFilter) searchResult.object).getName();
            }
            return res;
        case POI:
            Amenity amenity = (Amenity) searchResult.object;
            PoiCategory pc = amenity.getType();
            PoiType pt = pc.getPoiTypeByKeyName(amenity.getSubType());
            String typeStr = amenity.getSubType();
            if (pt != null) {
                typeStr = pt.getTranslation();
            } else if (typeStr != null) {
                typeStr = Algorithms.capitalizeFirstLetterAndLowercase(typeStr.replace('_', ' '));
            }
            return typeStr;
        case LOCATION:
            LatLon latLon = searchResult.location;
            if (latLon != null && searchResult.localeRelatedObjectName == null) {
                String locationCountry = app.getRegions().getCountryName(latLon);
                searchResult.localeRelatedObjectName = locationCountry == null ? "" : locationCountry;
            }
            return searchResult.localeRelatedObjectName;
        case FAVORITE:
            FavouritePoint fav = (FavouritePoint) searchResult.object;
            return fav.getCategory().length() == 0 ? app.getString(R.string.shared_string_favorites) : fav.getCategory();
        case FAVORITE_GROUP:
            return app.getString(R.string.shared_string_my_favorites);
        case REGION:
            BinaryMapIndexReader binaryMapIndexReader = (BinaryMapIndexReader) searchResult.object;
            System.out.println(binaryMapIndexReader.getFile().getAbsolutePath() + " " + binaryMapIndexReader.getCountryName());
            break;
        case RECENT_OBJ:
            HistoryEntry entry = (HistoryEntry) searchResult.object;
            boolean hasTypeInDescription = !Algorithms.isEmpty(entry.getName().getTypeName());
            if (hasTypeInDescription) {
                return entry.getName().getTypeName();
            } else {
                return "";
            }
        case WPT:
            StringBuilder sb = new StringBuilder();
            GPXFile gpx = (GPXFile) searchResult.relatedObject;
            if (!Algorithms.isEmpty(searchResult.localeRelatedObjectName)) {
                sb.append(searchResult.localeRelatedObjectName);
            }
            if (gpx != null && !Algorithms.isEmpty(gpx.path)) {
                if (sb.length() > 0) {
                    sb.append(", ");
                }
                sb.append(new File(gpx.path).getName());
            }
            return sb.toString();
        case UNKNOWN_NAME_FILTER:
            break;
    }
    return searchResult.objectType.name();
}
Also used : Amenity(net.osmand.data.Amenity) PoiFilter(net.osmand.osm.PoiFilter) CustomSearchPoiFilter(net.osmand.search.core.CustomSearchPoiFilter) FavouritePoint(net.osmand.data.FavouritePoint) AbstractPoiType(net.osmand.osm.AbstractPoiType) PoiType(net.osmand.osm.PoiType) BinaryMapIndexReader(net.osmand.binary.BinaryMapIndexReader) City(net.osmand.data.City) AbstractPoiType(net.osmand.osm.AbstractPoiType) FavouritePoint(net.osmand.data.FavouritePoint) LatLon(net.osmand.data.LatLon) PoiCategory(net.osmand.osm.PoiCategory) Street(net.osmand.data.Street) HistoryEntry(net.osmand.plus.helpers.SearchHistoryHelper.HistoryEntry) CustomSearchPoiFilter(net.osmand.search.core.CustomSearchPoiFilter) GPXFile(net.osmand.plus.GPXUtilities.GPXFile) GPXFile(net.osmand.plus.GPXUtilities.GPXFile) File(java.io.File)

Example 4 with PoiCategory

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

the class BinaryMapIndexReader method searchPoiCategoriesByName.

public Map<PoiCategory, List<String>> searchPoiCategoriesByName(String query, Map<PoiCategory, List<String>> map) throws IOException {
    if (query == null || query.length() == 0) {
        throw new IllegalArgumentException();
    }
    Collator collator = OsmAndCollator.primaryCollator();
    for (PoiRegion poiIndex : poiIndexes) {
        poiAdapter.initCategories(poiIndex);
        for (int i = 0; i < poiIndex.categories.size(); i++) {
            String cat = poiIndex.categories.get(i);
            PoiCategory catType = poiIndex.categoriesType.get(i);
            if (CollatorStringMatcher.cmatches(collator, cat, query, StringMatcherMode.CHECK_STARTS_FROM_SPACE)) {
                map.put(catType, null);
            } else {
                List<String> subcats = poiIndex.subcategories.get(i);
                for (int j = 0; j < subcats.size(); j++) {
                    if (CollatorStringMatcher.cmatches(collator, subcats.get(j), query, StringMatcherMode.CHECK_STARTS_FROM_SPACE)) {
                        if (!map.containsKey(catType)) {
                            map.put(catType, new ArrayList<String>());
                        }
                        List<String> list = map.get(catType);
                        if (list != null) {
                            list.add(subcats.get(j));
                        }
                    }
                }
            }
        }
    }
    return map;
}
Also used : PoiCategory(net.osmand.osm.PoiCategory) PoiRegion(net.osmand.binary.BinaryMapPoiReaderAdapter.PoiRegion) OsmAndCollator(net.osmand.OsmAndCollator) Collator(net.osmand.Collator)

Example 5 with PoiCategory

use of net.osmand.osm.PoiCategory 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)

Aggregations

PoiCategory (net.osmand.osm.PoiCategory)29 PoiType (net.osmand.osm.PoiType)11 Amenity (net.osmand.data.Amenity)9 AbstractPoiType (net.osmand.osm.AbstractPoiType)9 MapPoiTypes (net.osmand.osm.MapPoiTypes)6 View (android.view.View)5 NonNull (android.support.annotation.NonNull)4 AdapterView (android.widget.AdapterView)4 TextView (android.widget.TextView)4 BinaryMapIndexReader (net.osmand.binary.BinaryMapIndexReader)4 QuadRect (net.osmand.data.QuadRect)4 OsmandApplication (net.osmand.plus.OsmandApplication)4 DialogInterface (android.content.DialogInterface)3 AlertDialog (android.support.v7.app.AlertDialog)3 AutoCompleteTextView (android.widget.AutoCompleteTextView)3 Button (android.widget.Button)3 PoiFilter (net.osmand.osm.PoiFilter)3 CustomSearchPoiFilter (net.osmand.search.core.CustomSearchPoiFilter)3 Intent (android.content.Intent)2 Bundle (android.os.Bundle)2