Search in sources :

Example 1 with AbstractPoiType

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

the class QuickSearchDialogFragment method completeQueryWithObject.

public void completeQueryWithObject(SearchResult sr) {
    if (sr.object instanceof PoiType && ((PoiType) sr.object).isAdditional()) {
        PoiType additional = (PoiType) sr.object;
        AbstractPoiType parent = additional.getParentType();
        if (parent != null) {
            PoiUIFilter custom = app.getPoiFilters().getFilterById(PoiUIFilter.STD_PREFIX + parent.getKeyName());
            if (custom != null) {
                custom.clearFilter();
                custom.updateTypesToAccept(parent);
                custom.setFilterByName(additional.getKeyName().replace('_', ':').toLowerCase());
                SearchPhrase phrase = searchUICore.getPhrase();
                sr = new SearchResult(phrase);
                sr.localeName = custom.getName();
                sr.object = custom;
                sr.priority = SEARCH_AMENITY_TYPE_PRIORITY;
                sr.priorityDistance = 0;
                sr.objectType = ObjectType.POI_TYPE;
            }
        }
    }
    searchUICore.selectSearchResult(sr);
    if (addressSearch) {
        startAddressSearch();
        if (sr.objectType == ObjectType.CITY) {
            if (sr.relatedObject != null && sr.relatedObject instanceof BinaryMapIndexReader) {
                File f = ((BinaryMapIndexReader) sr.relatedObject).getFile();
                if (f != null) {
                    RegionAddressRepository region = app.getResourceManager().getRegionRepository(f.getName());
                    if (region != null) {
                        app.getSettings().setLastSearchedRegion(region.getFileName(), region.getEstimatedRegionCenter());
                        City city = (City) sr.object;
                        app.getSettings().setLastSearchedCity(city.getId(), sr.localeName, city.getLocation());
                    }
                }
            }
        }
    }
    String txt = searchUICore.getPhrase().getText(true);
    replaceQueryWithText(txt);
    if (sr.objectType == ObjectType.CITY) {
        openKeyboard();
    }
}
Also used : RegionAddressRepository(net.osmand.plus.resources.RegionAddressRepository) AbstractPoiType(net.osmand.osm.AbstractPoiType) PoiType(net.osmand.osm.PoiType) BinaryMapIndexReader(net.osmand.binary.BinaryMapIndexReader) SearchResult(net.osmand.search.core.SearchResult) City(net.osmand.data.City) SpannableString(android.text.SpannableString) AbstractPoiType(net.osmand.osm.AbstractPoiType) File(java.io.File) GPXFile(net.osmand.plus.GPXUtilities.GPXFile) SearchPhrase(net.osmand.search.core.SearchPhrase) PoiUIFilter(net.osmand.plus.poi.PoiUIFilter)

Example 2 with AbstractPoiType

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

the class QuickSearchDialogFragment method onCreateView.

@Override
@SuppressLint("PrivateResource, ValidFragment")
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    final MapActivity mapActivity = getMapActivity();
    final View view = inflater.inflate(R.layout.search_dialog_fragment, container, false);
    toolbarController = new QuickSearchToolbarController();
    toolbarController.setOnBackButtonClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            mapActivity.showQuickSearch(ShowQuickSearchMode.CURRENT, false);
        }
    });
    toolbarController.setOnTitleClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            mapActivity.showQuickSearch(ShowQuickSearchMode.CURRENT, false);
        }
    });
    toolbarController.setOnCloseButtonClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            mapActivity.closeQuickSearch();
        }
    });
    Bundle arguments = getArguments();
    if (savedInstanceState != null) {
        searchType = QuickSearchType.valueOf(savedInstanceState.getString(QUICK_SEARCH_TYPE_KEY, QuickSearchType.REGULAR.name()));
        searchQuery = savedInstanceState.getString(QUICK_SEARCH_QUERY_KEY);
        double lat = savedInstanceState.getDouble(QUICK_SEARCH_LAT_KEY, Double.NaN);
        double lon = savedInstanceState.getDouble(QUICK_SEARCH_LON_KEY, Double.NaN);
        if (!Double.isNaN(lat) && !Double.isNaN(lon)) {
            centerLatLon = new LatLon(lat, lon);
        }
        interruptedSearch = savedInstanceState.getBoolean(QUICK_SEARCH_INTERRUPTED_SEARCH_KEY, false);
        hidden = savedInstanceState.getBoolean(QUICK_SEARCH_HIDDEN_KEY, false);
        toolbarTitle = savedInstanceState.getString(QUICK_SEARCH_TOOLBAR_TITLE_KEY);
        toolbarVisible = savedInstanceState.getBoolean(QUICK_SEARCH_TOOLBAR_VISIBLE_KEY, false);
        fabVisible = savedInstanceState.getBoolean(QUICK_SEARCH_FAB_VISIBLE_KEY, false);
    }
    if (searchQuery == null && arguments != null) {
        searchType = QuickSearchType.valueOf(arguments.getString(QUICK_SEARCH_TYPE_KEY, QuickSearchType.REGULAR.name()));
        searchQuery = arguments.getString(QUICK_SEARCH_QUERY_KEY);
        runSearchFirstTime = arguments.getBoolean(QUICK_SEARCH_RUN_SEARCH_FIRST_TIME_KEY, false);
        phraseDefined = arguments.getBoolean(QUICK_SEARCH_PHRASE_DEFINED_KEY, false);
        double lat = arguments.getDouble(QUICK_SEARCH_LAT_KEY, Double.NaN);
        double lon = arguments.getDouble(QUICK_SEARCH_LON_KEY, Double.NaN);
        if (!Double.isNaN(lat) && !Double.isNaN(lon)) {
            centerLatLon = new LatLon(lat, lon);
        }
        newSearch = true;
    }
    if (searchQuery == null)
        searchQuery = "";
    QuickSearchTab showSearchTab = QuickSearchTab.HISTORY;
    if (arguments != null) {
        showSearchTab = QuickSearchTab.valueOf(arguments.getString(QUICK_SEARCH_SHOW_TAB_KEY, QuickSearchTab.HISTORY.name()));
    }
    if (showSearchTab == QuickSearchTab.ADDRESS) {
        addressSearch = true;
    }
    tabToolbarView = view.findViewById(R.id.tab_toolbar_layout);
    tabsView = view.findViewById(R.id.tabs_view);
    searchView = view.findViewById(R.id.search_view);
    buttonToolbarView = view.findViewById(R.id.button_toolbar_layout);
    buttonToolbarImage = (ImageView) view.findViewById(R.id.buttonToolbarImage);
    buttonToolbarImage.setImageDrawable(app.getIconsCache().getThemedIcon(R.drawable.ic_action_marker_dark));
    buttonToolbarFilter = (ImageButton) view.findViewById(R.id.filterButton);
    buttonToolbarFilter.setImageDrawable(app.getIconsCache().getThemedIcon(R.drawable.ic_action_filter));
    buttonToolbarFilter.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            SearchPhrase searchPhrase = searchUICore.getPhrase();
            if (searchPhrase.isLastWord(POI_TYPE)) {
                String filterId = null;
                String filterByName = searchPhrase.getUnknownSearchPhrase().trim();
                Object object = searchPhrase.getLastSelectedWord().getResult().object;
                if (object instanceof PoiUIFilter) {
                    PoiUIFilter model = (PoiUIFilter) object;
                    if (!Algorithms.isEmpty(model.getSavedFilterByName())) {
                        model.setFilterByName(model.getSavedFilterByName());
                    }
                    filterId = model.getFilterId();
                } else if (object instanceof AbstractPoiType) {
                    AbstractPoiType abstractPoiType = (AbstractPoiType) object;
                    PoiUIFilter custom = app.getPoiFilters().getFilterById(PoiUIFilter.STD_PREFIX + abstractPoiType.getKeyName());
                    if (custom != null) {
                        custom.setFilterByName(null);
                        custom.clearFilter();
                        custom.updateTypesToAccept(abstractPoiType);
                        filterId = custom.getFilterId();
                    }
                }
                if (filterId != null) {
                    QuickSearchPoiFilterFragment.showDialog(QuickSearchDialogFragment.this, filterByName, filterId);
                }
            }
        }
    });
    buttonToolbarText = (TextView) view.findViewById(R.id.buttonToolbarTitle);
    view.findViewById(R.id.buttonToolbar).setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            SearchPhrase searchPhrase = searchUICore.getPhrase();
            if (foundPartialLocation) {
                QuickSearchCoordinatesFragment.showDialog(QuickSearchDialogFragment.this, searchPhrase.getUnknownSearchWord());
            } else if (searchPhrase.isNoSelectedType() || searchPhrase.isLastWord(POI_TYPE)) {
                PoiUIFilter filter;
                if (searchPhrase.isNoSelectedType()) {
                    if (isOnlineSearch() && !Algorithms.isEmpty(searchPhrase.getUnknownSearchWord())) {
                        app.getPoiFilters().resetNominatimFilters();
                        filter = app.getPoiFilters().getNominatimPOIFilter();
                        filter.setFilterByName(searchPhrase.getUnknownSearchWord());
                        filter.clearCurrentResults();
                    } else {
                        filter = app.getPoiFilters().getSearchByNamePOIFilter();
                        if (!Algorithms.isEmpty(searchPhrase.getUnknownSearchWord())) {
                            filter.setFilterByName(searchPhrase.getUnknownSearchWord());
                            filter.clearCurrentResults();
                        }
                    }
                } else if (searchPhrase.getLastSelectedWord().getResult().object instanceof AbstractPoiType) {
                    if (searchPhrase.isNoSelectedType()) {
                        filter = new PoiUIFilter(null, app, "");
                    } else {
                        AbstractPoiType abstractPoiType = (AbstractPoiType) searchPhrase.getLastSelectedWord().getResult().object;
                        filter = new PoiUIFilter(abstractPoiType, app, "");
                    }
                    if (!Algorithms.isEmpty(searchPhrase.getUnknownSearchWord())) {
                        filter.setFilterByName(searchPhrase.getUnknownSearchWord());
                    }
                } else {
                    filter = (PoiUIFilter) searchPhrase.getLastSelectedWord().getResult().object;
                }
                app.getPoiFilters().clearSelectedPoiFilters();
                app.getPoiFilters().addSelectedPoiFilter(filter);
                mapActivity.getContextMenu().closeActiveToolbar();
                showToolbar();
                getMapActivity().updateStatusBarColor();
                getMapActivity().refreshMap();
                hide();
            } else {
                SearchWord word = searchPhrase.getLastSelectedWord();
                if (word != null) {
                    if ((searchType == QuickSearchType.START_POINT || searchType == QuickSearchType.DESTINATION || searchType == QuickSearchType.INTERMEDIATE) && word.getLocation() != null) {
                        if (mainSearchFragment != null) {
                            mainSearchFragment.showResult(word.getResult());
                        }
                    } else if (word.getLocation() != null) {
                        SearchResult searchResult = word.getResult();
                        String name = QuickSearchListItem.getName(app, searchResult);
                        String typeName = QuickSearchListItem.getTypeName(app, searchResult);
                        PointDescription pointDescription = new PointDescription(PointDescription.POINT_TYPE_ADDRESS, typeName, name);
                        app.getSettings().setMapLocationToShow(searchResult.location.getLatitude(), searchResult.location.getLongitude(), searchResult.preferredZoom, pointDescription, true, searchResult.object);
                        hideToolbar();
                        MapActivity.launchMapActivityMoveToTop(getActivity());
                        reloadHistory();
                        hide();
                    } else if (word.getType() == ObjectType.FAVORITE_GROUP) {
                        FavouritesDbHelper.FavoriteGroup group = (FavouritesDbHelper.FavoriteGroup) word.getResult().object;
                        if (group.points.size() > 1) {
                            double left = 0, right = 0;
                            double top = 0, bottom = 0;
                            for (FavouritePoint p : group.points) {
                                if (left == 0) {
                                    left = p.getLongitude();
                                    right = p.getLongitude();
                                    top = p.getLatitude();
                                    bottom = p.getLatitude();
                                } else {
                                    left = Math.min(left, p.getLongitude());
                                    right = Math.max(right, p.getLongitude());
                                    top = Math.max(top, p.getLatitude());
                                    bottom = Math.min(bottom, p.getLatitude());
                                }
                            }
                            getMapActivity().getMapView().fitRectToMap(left, right, top, bottom, 0, 0, 0);
                            hideToolbar();
                            MapActivity.launchMapActivityMoveToTop(getActivity());
                            hide();
                        } else if (group.points.size() == 1) {
                            FavouritePoint p = group.points.get(0);
                            app.getSettings().setMapLocationToShow(p.getLatitude(), p.getLongitude(), word.getResult().preferredZoom);
                            hideToolbar();
                            MapActivity.launchMapActivityMoveToTop(getActivity());
                            hide();
                        }
                    }
                }
            }
        }
    });
    toolbar = (Toolbar) view.findViewById(R.id.toolbar);
    if (!app.getSettings().isLightContent()) {
        toolbar.setBackgroundColor(ContextCompat.getColor(mapActivity, R.color.actionbar_dark_color));
    }
    toolbar.setNavigationIcon(app.getIconsCache().getThemedIcon(R.drawable.ic_arrow_back));
    toolbar.setNavigationContentDescription(R.string.access_shared_string_navigate_up);
    toolbar.setNavigationOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            if (!processBackAction()) {
                dismiss();
            }
        }
    });
    toolbarEdit = (Toolbar) view.findViewById(R.id.toolbar_edit);
    toolbarEdit.setNavigationIcon(app.getIconsCache().getIcon(R.drawable.ic_action_remove_dark));
    toolbarEdit.setNavigationContentDescription(R.string.shared_string_cancel);
    toolbarEdit.setNavigationOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            enableSelectionMode(false, -1);
        }
    });
    titleEdit = (TextView) view.findViewById(R.id.titleEdit);
    view.findViewById(R.id.shareButton).setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            List<HistoryEntry> historyEntries = new ArrayList<HistoryEntry>();
            List<QuickSearchListItem> selectedItems = historySearchFragment.getListAdapter().getSelectedItems();
            for (QuickSearchListItem searchListItem : selectedItems) {
                HistoryEntry historyEntry = (HistoryEntry) searchListItem.getSearchResult().object;
                historyEntries.add(historyEntry);
            }
            if (historyEntries.size() > 0) {
                shareHistory(historyEntries);
                enableSelectionMode(false, -1);
            }
        }
    });
    view.findViewById(R.id.deleteButton).setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            DeleteDialogFragment deleteDialog = new DeleteDialogFragment();
            deleteDialog.setSelectedItems(historySearchFragment.getListAdapter().getSelectedItems());
            deleteDialog.show(getChildFragmentManager(), "DeleteHistoryConfirmationFragment");
        }
    });
    viewPager = (LockableViewPager) view.findViewById(R.id.pager);
    viewPager.setOffscreenPageLimit(2);
    pagerAdapter = new SearchFragmentPagerAdapter(getChildFragmentManager(), getResources());
    viewPager.setAdapter(pagerAdapter);
    switch(showSearchTab) {
        case HISTORY:
            viewPager.setCurrentItem(0);
            break;
        case CATEGORIES:
            viewPager.setCurrentItem(1);
            break;
        case ADDRESS:
            viewPager.setCurrentItem(2);
            break;
    }
    tabLayout = (TabLayout) view.findViewById(R.id.tab_layout);
    tabLayout.setupWithViewPager(viewPager);
    viewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {

        @Override
        public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
        }

        @Override
        public void onPageSelected(int position) {
            hideKeyboard();
            addressSearch = position == 2;
            updateClearButtonAndHint();
            if (addressSearch && !citiesLoaded) {
                reloadCities();
            } else {
                restoreSearch();
            }
        }

        @Override
        public void onPageScrollStateChanged(int state) {
        }
    });
    searchEditText = (EditText) view.findViewById(R.id.searchEditText);
    searchEditText.setOnEditorActionListener(new TextView.OnEditorActionListener() {

        @Override
        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            if (actionId == EditorInfo.IME_ACTION_SEARCH) {
                searchQuery += " ";
                AndroidUtils.hideSoftKeyboard(getActivity(), searchEditText);
                runSearch();
                return true;
            }
            return false;
        }
    });
    searchEditText.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 newQueryText = s.toString();
            updateClearButtonAndHint();
            updateClearButtonVisibility(true);
            boolean textEmpty = newQueryText.length() == 0;
            updateTabbarVisibility(textEmpty && !isOnlineSearch());
            if (textEmpty) {
                if (addressSearch) {
                    startAddressSearch();
                }
                if (poiFilterApplied) {
                    poiFilterApplied = false;
                    reloadCategories();
                    if (fabVisible) {
                        fabVisible = false;
                        updateFab();
                    }
                }
            }
            if (!searchQuery.equalsIgnoreCase(newQueryText)) {
                searchQuery = newQueryText;
                if (Algorithms.isEmpty(searchQuery)) {
                    cancelSearch();
                    setResultCollection(null);
                    searchUICore.resetPhrase();
                    mainSearchFragment.getAdapter().clear();
                } else {
                    runSearch();
                }
            } else if (runSearchFirstTime) {
                runSearchFirstTime = false;
                runSearch();
            }
        }
    });
    progressBar = (ProgressBar) view.findViewById(R.id.searchProgressBar);
    clearButton = (ImageButton) view.findViewById(R.id.clearButton);
    clearButton.setImageDrawable(app.getIconsCache().getThemedIcon(R.drawable.ic_action_remove_dark));
    clearButton.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            if (searchEditText.getText().length() > 0) {
                String newText = searchUICore.getPhrase().getTextWithoutLastWord();
                searchEditText.setText(newText);
                searchEditText.setSelection(newText.length());
            } else if (useMapCenter && location != null) {
                useMapCenter = false;
                centerLatLon = null;
                updateUseMapCenterUI();
                LatLon centerLatLon = new LatLon(location.getLatitude(), location.getLongitude());
                SearchSettings ss = searchUICore.getSearchSettings().setOriginalLocation(new LatLon(centerLatLon.getLatitude(), centerLatLon.getLongitude()));
                searchUICore.updateSettings(ss);
                updateClearButtonAndHint();
                updateClearButtonVisibility(true);
                startLocationUpdate();
            }
            updateToolbarButton();
        }
    });
    fab = view.findViewById(R.id.fab);
    fab.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            saveCustomFilter();
        }
    });
    updateFab();
    setupSearch(mapActivity);
    return view;
}
Also used : FavouritePoint(net.osmand.data.FavouritePoint) SearchWord(net.osmand.search.core.SearchWord) SpannableString(android.text.SpannableString) SearchPhrase(net.osmand.search.core.SearchPhrase) KeyEvent(android.view.KeyEvent) QuickSearchListItem(net.osmand.plus.search.listitems.QuickSearchListItem) TextWatcher(android.text.TextWatcher) Editable(android.text.Editable) SearchSettings(net.osmand.search.core.SearchSettings) ArrayList(java.util.ArrayList) List(java.util.List) TextView(android.widget.TextView) MapActivity(net.osmand.plus.activities.MapActivity) Bundle(android.os.Bundle) SearchResult(net.osmand.search.core.SearchResult) FavouritesDbHelper(net.osmand.plus.FavouritesDbHelper) AbstractPoiType(net.osmand.osm.AbstractPoiType) ImageView(android.widget.ImageView) View(android.view.View) AdapterView(android.widget.AdapterView) TextView(android.widget.TextView) ListView(android.widget.ListView) LockableViewPager(net.osmand.plus.LockableViewPager) ViewPager(android.support.v4.view.ViewPager) FavouritePoint(net.osmand.data.FavouritePoint) SuppressLint(android.annotation.SuppressLint) PoiUIFilter(net.osmand.plus.poi.PoiUIFilter) LatLon(net.osmand.data.LatLon) PointDescription(net.osmand.data.PointDescription) SearchMoreItemOnClickListener(net.osmand.plus.search.listitems.QuickSearchMoreListItem.SearchMoreItemOnClickListener) OnClickListener(android.view.View.OnClickListener) HistoryEntry(net.osmand.plus.helpers.SearchHistoryHelper.HistoryEntry) SuppressLint(android.annotation.SuppressLint)

Example 3 with AbstractPoiType

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

use of net.osmand.osm.AbstractPoiType 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 5 with AbstractPoiType

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

the class SearchPoiFilterFragment method onListItemClick.

@Override
public void onListItemClick(ListView listView, View v, int position, long id) {
    final Object item = getListAdapter().getItem(position);
    ResourceManager rm = getApp().getResourceManager();
    if (!rm.containsAmenityRepositoryToSearch(false)) {
        Toast.makeText(getActivity(), R.string.data_to_search_poi_not_available, Toast.LENGTH_LONG);
        return;
    }
    if (item instanceof PoiUIFilter) {
        PoiUIFilter model = ((PoiUIFilter) item);
        if (PoiUIFilter.BY_NAME_FILTER_ID.equals(model.getFilterId()) || model instanceof NominatimPoiFilter) {
            model.setFilterByName(searchEditText.getText().toString());
        } else {
            model.setFilterByName(model.getSavedFilterByName());
        }
        showFilterActivity(model.getFilterId());
    } else {
        PoiUIFilter custom = getApp().getPoiFilters().getFilterById(PoiUIFilter.STD_PREFIX + ((AbstractPoiType) item).getKeyName());
        if (custom != null) {
            if (item instanceof PoiType && ((PoiType) item).isAdditional()) {
            // it is already set
            } else {
                custom.setFilterByName(null);
            }
            custom.clearFilter();
            custom.updateTypesToAccept(((AbstractPoiType) item));
            showFilterActivity(custom.getFilterId());
        }
    }
}
Also used : NominatimPoiFilter(net.osmand.plus.poi.NominatimPoiFilter) AbstractPoiType(net.osmand.osm.AbstractPoiType) PoiType(net.osmand.osm.PoiType) ResourceManager(net.osmand.plus.resources.ResourceManager) AbstractPoiType(net.osmand.osm.AbstractPoiType) PoiUIFilter(net.osmand.plus.poi.PoiUIFilter)

Aggregations

AbstractPoiType (net.osmand.osm.AbstractPoiType)22 PoiType (net.osmand.osm.PoiType)12 MapPoiTypes (net.osmand.osm.MapPoiTypes)10 Amenity (net.osmand.data.Amenity)6 Drawable (android.graphics.drawable.Drawable)5 View (android.view.View)5 TextView (android.widget.TextView)5 PoiCategory (net.osmand.osm.PoiCategory)5 ArrayList (java.util.ArrayList)4 Map (java.util.Map)4 PoiUIFilter (net.osmand.plus.poi.PoiUIFilter)4 SpannableString (android.text.SpannableString)3 File (java.io.File)3 BinaryMapIndexReader (net.osmand.binary.BinaryMapIndexReader)3 City (net.osmand.data.City)3 FavouritePoint (net.osmand.data.FavouritePoint)3 LatLon (net.osmand.data.LatLon)3 PoiFilter (net.osmand.osm.PoiFilter)3 OsmandApplication (net.osmand.plus.OsmandApplication)3 HistoryEntry (net.osmand.plus.helpers.SearchHistoryHelper.HistoryEntry)3