Search in sources :

Example 1 with QuickSearchListItem

use of net.osmand.plus.search.listitems.QuickSearchListItem in project Osmand by osmandapp.

the class QuickSearchDialogFragment method reloadCategoriesInternal.

private void reloadCategoriesInternal() {
    try {
        if (SearchUICore.isDebugMode()) {
            LOG.info("UI >> Start loading categories");
        }
        SearchResultCollection res = searchUICore.shallowSearch(SearchAmenityTypesAPI.class, "", null);
        if (res != null) {
            List<QuickSearchListItem> rows = new ArrayList<>();
            for (SearchResult sr : res.getCurrentSearchResults()) {
                rows.add(new QuickSearchListItem(app, sr));
            }
            if (OsmandPlugin.getEnabledPlugin(OsmandRasterMapsPlugin.class) != null) {
                rows.add(new QuickSearchButtonListItem(app, R.drawable.ic_world_globe_dark, app.getString(R.string.search_online_address), new OnClickListener() {

                    @Override
                    public void onClick(View view) {
                        startOnlineSearch();
                        mainSearchFragment.getAdapter().clear();
                        updateTabbarVisibility(false);
                        openKeyboard();
                    }
                }));
            }
            rows.add(new QuickSearchButtonListItem(app, R.drawable.ic_action_search_dark, app.getString(R.string.custom_search), new OnClickListener() {

                @Override
                public void onClick(View v) {
                    PoiUIFilter filter = app.getPoiFilters().getCustomPOIFilter();
                    filter.clearFilter();
                    QuickSearchCustomPoiFragment.showDialog(QuickSearchDialogFragment.this, filter.getFilterId());
                }
            }));
            if (categoriesSearchFragment != null) {
                categoriesSearchFragment.updateListAdapter(rows, false);
            }
        }
        if (SearchUICore.isDebugMode()) {
            LOG.info("UI >> Categories loaded");
        }
    } catch (IOException e) {
        e.printStackTrace();
        app.showToastMessage(e.getMessage());
    }
}
Also used : QuickSearchButtonListItem(net.osmand.plus.search.listitems.QuickSearchButtonListItem) ArrayList(java.util.ArrayList) SearchResultCollection(net.osmand.search.SearchUICore.SearchResultCollection) QuickSearchListItem(net.osmand.plus.search.listitems.QuickSearchListItem) SearchMoreItemOnClickListener(net.osmand.plus.search.listitems.QuickSearchMoreListItem.SearchMoreItemOnClickListener) OnClickListener(android.view.View.OnClickListener) SearchResult(net.osmand.search.core.SearchResult) IOException(java.io.IOException) OsmandRasterMapsPlugin(net.osmand.plus.rastermaps.OsmandRasterMapsPlugin) ImageView(android.widget.ImageView) View(android.view.View) AdapterView(android.widget.AdapterView) TextView(android.widget.TextView) ListView(android.widget.ListView) PoiUIFilter(net.osmand.plus.poi.PoiUIFilter)

Example 2 with QuickSearchListItem

use of net.osmand.plus.search.listitems.QuickSearchListItem in project Osmand by osmandapp.

the class QuickSearchDialogFragment method reloadCitiesInternal.

private void reloadCitiesInternal() {
    if (SearchUICore.isDebugMode()) {
        LOG.info("UI >> Start loading nearest cities");
    }
    startNearestCitySearch();
    runCoreSearch("", false, false, new SearchResultListener() {

        @Override
        public void searchStarted(SearchPhrase phrase) {
        }

        @Override
        public void publish(SearchResultCollection res, boolean append) {
        }

        @Override
        public boolean searchFinished(SearchPhrase phrase) {
            SearchResultCollection res = getResultCollection();
            if (SearchUICore.isDebugMode()) {
                LOG.info("UI >> Nearest cities found: " + (res != null ? res.getCurrentSearchResults().size() : 0));
            }
            final OsmandSettings settings = app.getSettings();
            List<QuickSearchListItem> rows = new ArrayList<>();
            if (SearchUICore.isDebugMode()) {
                LOG.info("UI >> Start last city searching (within nearests)");
            }
            SearchResult lastCity = null;
            if (res != null) {
                citiesLoaded = res.getCurrentSearchResults().size() > 0;
                final long lastCityId = settings.getLastSearchedCity();
                for (SearchResult sr : res.getCurrentSearchResults()) {
                    if (sr.objectType == ObjectType.CITY && ((City) sr.object).getId() == lastCityId) {
                        lastCity = sr;
                        break;
                    }
                }
            }
            if (SearchUICore.isDebugMode()) {
                LOG.info("UI >> Last city found: " + (lastCity != null ? lastCity.localeName : "-"));
            }
            final String lastCityName = lastCity == null ? settings.getLastSearchedCityName() : lastCity.localeName;
            if (!Algorithms.isEmpty(lastCityName)) {
                String selectStreets = app.getString(R.string.select_street);
                String inCityName = app.getString(R.string.shared_string_in_name, lastCityName);
                Spannable spannable = new SpannableString(selectStreets + " " + inCityName);
                boolean light = settings.isLightContent();
                spannable.setSpan(new ForegroundColorSpan(getResources().getColor(light ? R.color.icon_color : R.color.color_white)), selectStreets.length() + 1, spannable.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
                final SearchResult lastCityFinal = lastCity;
                rows.add(new QuickSearchButtonListItem(app, R.drawable.ic_action_street_name, spannable, new OnClickListener() {

                    @Override
                    public void onClick(View v) {
                        if (lastCityFinal == null) {
                            final long lastCityId = settings.getLastSearchedCity();
                            final LatLon lastCityPoint = settings.getLastSearchedPoint();
                            if (lastCityId != -1 && lastCityPoint != null) {
                                startLastCitySearch(lastCityPoint);
                                if (SearchUICore.isDebugMode()) {
                                    LOG.info("UI >> Start last city searching (standalone)");
                                }
                                runCoreSearch("", false, false, new SearchResultListener() {

                                    boolean cityFound = false;

                                    @Override
                                    public void publish(SearchResultCollection res, boolean append) {
                                        if (res != null) {
                                            for (SearchResult sr : res.getCurrentSearchResults()) {
                                                if (sr.objectType == ObjectType.CITY && ((City) sr.object).getId() == lastCityId) {
                                                    if (SearchUICore.isDebugMode()) {
                                                        LOG.info("UI >> Last city found: " + sr.localeName);
                                                    }
                                                    cityFound = true;
                                                    completeQueryWithObject(sr);
                                                    break;
                                                }
                                            }
                                        }
                                    }

                                    @Override
                                    public void searchStarted(SearchPhrase phrase) {
                                    }

                                    @Override
                                    public boolean searchFinished(SearchPhrase phrase) {
                                        if (!cityFound) {
                                            replaceQueryWithText(lastCityName + " ");
                                        }
                                        return false;
                                    }
                                });
                                restoreSearch();
                            } else {
                                replaceQueryWithText(lastCityName + " ");
                            }
                        } else {
                            completeQueryWithObject(lastCityFinal);
                        }
                        openKeyboard();
                    }
                }));
            }
            rows.add(new QuickSearchButtonListItem(app, R.drawable.ic_action_building_number, app.getString(R.string.select_city), new OnClickListener() {

                @Override
                public void onClick(View v) {
                    searchEditText.setHint(R.string.type_city_town);
                    startCitySearch();
                    updateTabbarVisibility(false);
                    runCoreSearch("", false, false);
                    openKeyboard();
                }
            }));
            rows.add(new QuickSearchButtonListItem(app, R.drawable.ic_action_postcode, app.getString(R.string.select_postcode), new OnClickListener() {

                @Override
                public void onClick(View v) {
                    searchEditText.setHint(R.string.type_postcode);
                    startPostcodeSearch();
                    mainSearchFragment.getAdapter().clear();
                    updateTabbarVisibility(false);
                    openKeyboard();
                }
            }));
            rows.add(new QuickSearchButtonListItem(app, R.drawable.ic_action_marker_dark, app.getString(R.string.coords_search), new OnClickListener() {

                @Override
                public void onClick(View v) {
                    LatLon latLon = searchUICore.getSearchSettings().getOriginalLocation();
                    QuickSearchCoordinatesFragment.showDialog(QuickSearchDialogFragment.this, latLon.getLatitude(), latLon.getLongitude());
                }
            }));
            if (res != null) {
                rows.add(new QuickSearchHeaderListItem(app, app.getString(R.string.nearest_cities), true));
                int limit = 15;
                for (SearchResult sr : res.getCurrentSearchResults()) {
                    if (limit > 0) {
                        rows.add(new QuickSearchListItem(app, sr));
                    }
                    limit--;
                }
            }
            addressSearchFragment.updateListAdapter(rows, false);
            if (SearchUICore.isDebugMode()) {
                LOG.info("UI >> Nearest cities loaded");
            }
            return true;
        }
    });
    restoreSearch();
}
Also used : ForegroundColorSpan(android.text.style.ForegroundColorSpan) QuickSearchButtonListItem(net.osmand.plus.search.listitems.QuickSearchButtonListItem) QuickSearchHeaderListItem(net.osmand.plus.search.listitems.QuickSearchHeaderListItem) SearchResult(net.osmand.search.core.SearchResult) SpannableString(android.text.SpannableString) City(net.osmand.data.City) ImageView(android.widget.ImageView) View(android.view.View) AdapterView(android.widget.AdapterView) TextView(android.widget.TextView) ListView(android.widget.ListView) SearchPhrase(net.osmand.search.core.SearchPhrase) OsmandSettings(net.osmand.plus.OsmandSettings) SpannableString(android.text.SpannableString) LatLon(net.osmand.data.LatLon) SearchResultCollection(net.osmand.search.SearchUICore.SearchResultCollection) SearchMoreItemOnClickListener(net.osmand.plus.search.listitems.QuickSearchMoreListItem.SearchMoreItemOnClickListener) OnClickListener(android.view.View.OnClickListener) QuickSearchListItem(net.osmand.plus.search.listitems.QuickSearchListItem) ArrayList(java.util.ArrayList) List(java.util.List) Spannable(android.text.Spannable)

Example 3 with QuickSearchListItem

use of net.osmand.plus.search.listitems.QuickSearchListItem in project Osmand by osmandapp.

the class QuickSearchDialogFragment method updateSearchResult.

private void updateSearchResult(SearchResultCollection res, boolean append) {
    if (!paused && mainSearchFragment != null) {
        List<QuickSearchListItem> rows = new ArrayList<>();
        if (res != null && res.getCurrentSearchResults().size() > 0) {
            for (final SearchResult sr : res.getCurrentSearchResults()) {
                rows.add(new QuickSearchListItem(app, sr));
            }
        }
        mainSearchFragment.updateListAdapter(rows, append);
    }
}
Also used : ArrayList(java.util.ArrayList) QuickSearchListItem(net.osmand.plus.search.listitems.QuickSearchListItem) SearchResult(net.osmand.search.core.SearchResult)

Example 4 with QuickSearchListItem

use of net.osmand.plus.search.listitems.QuickSearchListItem 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 5 with QuickSearchListItem

use of net.osmand.plus.search.listitems.QuickSearchListItem in project Osmand by osmandapp.

the class QuickSearchDialogFragment method reloadHistoryInternal.

private void reloadHistoryInternal() {
    if (historySearchFragment != null) {
        try {
            SearchResultCollection res = searchUICore.shallowSearch(SearchHistoryAPI.class, "", null);
            List<QuickSearchListItem> rows = new ArrayList<>();
            if (res != null) {
                for (SearchResult sr : res.getCurrentSearchResults()) {
                    rows.add(new QuickSearchListItem(app, sr));
                }
            }
            historySearchFragment.updateListAdapter(rows, false);
        } catch (Exception e) {
            e.printStackTrace();
            app.showToastMessage(e.getMessage());
        }
    }
}
Also used : ArrayList(java.util.ArrayList) SearchResultCollection(net.osmand.search.SearchUICore.SearchResultCollection) QuickSearchListItem(net.osmand.plus.search.listitems.QuickSearchListItem) SearchResult(net.osmand.search.core.SearchResult) IOException(java.io.IOException)

Aggregations

QuickSearchListItem (net.osmand.plus.search.listitems.QuickSearchListItem)11 ArrayList (java.util.ArrayList)7 SearchResult (net.osmand.search.core.SearchResult)5 View (android.view.View)4 ImageView (android.widget.ImageView)4 TextView (android.widget.TextView)4 OnClickListener (android.view.View.OnClickListener)3 AdapterView (android.widget.AdapterView)3 ListView (android.widget.ListView)3 SearchMoreItemOnClickListener (net.osmand.plus.search.listitems.QuickSearchMoreListItem.SearchMoreItemOnClickListener)3 SearchResultCollection (net.osmand.search.SearchUICore.SearchResultCollection)3 SearchPhrase (net.osmand.search.core.SearchPhrase)3 SpannableString (android.text.SpannableString)2 IOException (java.io.IOException)2 List (java.util.List)2 LatLon (net.osmand.data.LatLon)2 AbstractPoiType (net.osmand.osm.AbstractPoiType)2 PoiUIFilter (net.osmand.plus.poi.PoiUIFilter)2 QuickSearchBottomShadowListItem (net.osmand.plus.search.listitems.QuickSearchBottomShadowListItem)2 QuickSearchButtonListItem (net.osmand.plus.search.listitems.QuickSearchButtonListItem)2