Search in sources :

Example 16 with SearchResult

use of net.osmand.search.core.SearchResult in project Osmand by osmandapp.

the class SearchCoreUITest method testNoResort.

@Test
public void testNoResort() throws IOException {
    SearchSettings ss = new SearchSettings((SearchSettings) null);
    ss = ss.setOriginalLocation(new LatLon(0, 0));
    SearchPhrase phrase = new SearchPhrase(ss, OsmAndCollator.primaryCollator());
    SearchResultCollection cll = new SearchUICore.SearchResultCollection(phrase);
    List<SearchResult> rs = new ArrayList<>();
    SearchResult a1 = searchResult(rs, phrase, "a", 100);
    cll.addSearchResults(rs, false, true);
    rs.clear();
    SearchResult b2 = searchResult(rs, phrase, "b", 200);
    cll.addSearchResults(rs, false, true);
    rs.clear();
    SearchResult b1 = searchResult(rs, phrase, "b", 100);
    cll.addSearchResults(rs, false, true);
    rs.clear();
    /*SearchResult a3 = */
    searchResult(rs, phrase, "a", 100);
    cll.addSearchResults(rs, false, true);
    rs.clear();
    Assert.assertEquals(3, cll.getCurrentSearchResults().size());
    Assert.assertSame(a1, cll.getCurrentSearchResults().get(0));
    Assert.assertSame(b2, cll.getCurrentSearchResults().get(1));
    Assert.assertSame(b1, cll.getCurrentSearchResults().get(2));
}
Also used : LatLon(net.osmand.data.LatLon) ArrayList(java.util.ArrayList) SearchSettings(net.osmand.search.core.SearchSettings) SearchResultCollection(net.osmand.search.SearchUICore.SearchResultCollection) SearchResult(net.osmand.search.core.SearchResult) SearchPhrase(net.osmand.search.core.SearchPhrase) Test(org.junit.Test)

Example 17 with SearchResult

use of net.osmand.search.core.SearchResult in project Osmand by osmandapp.

the class QuickSearchDialogFragment method showInstance.

public static boolean showInstance(@NonNull MainActivity mainActivity, @NonNull String searchQuery, @Nullable Object object, boolean showCategories, @Nullable LatLon latLon) {
    try {
        Bundle bundle = new Bundle();
        if (object != null) {
            bundle.putBoolean(QUICK_SEARCH_RUN_SEARCH_FIRST_TIME_KEY, true);
            String objectLocalizedName = searchQuery;
            if (object instanceof PoiCategory) {
                PoiCategory c = (PoiCategory) object;
                objectLocalizedName = c.getTranslation();
                SearchUICore searchUICore = mainActivity.getMyApplication().getSearchUICore().getCore();
                SearchPhrase phrase = searchUICore.resetPhrase(objectLocalizedName + " ");
                SearchResult sr = new SearchResult(phrase);
                sr.localeName = objectLocalizedName;
                sr.object = c;
                sr.priority = SEARCH_AMENITY_TYPE_PRIORITY;
                sr.priorityDistance = 0;
                sr.objectType = ObjectType.POI_TYPE;
                searchUICore.selectSearchResult(sr);
                bundle.putBoolean(QUICK_SEARCH_PHRASE_DEFINED_KEY, true);
            }
            searchQuery = objectLocalizedName.trim() + " ";
        } else if (!Algorithms.isEmpty(searchQuery)) {
            bundle.putBoolean(QUICK_SEARCH_RUN_SEARCH_FIRST_TIME_KEY, true);
        }
        bundle.putString(QUICK_SEARCH_QUERY_KEY, searchQuery);
        bundle.putBoolean(QUICK_SEARCH_SHOW_CATEGORIES_KEY, showCategories);
        if (latLon != null) {
            bundle.putDouble(QUICK_SEARCH_LAT_KEY, latLon.getLatitude());
            bundle.putDouble(QUICK_SEARCH_LON_KEY, latLon.getLongitude());
        }
        QuickSearchDialogFragment fragment = new QuickSearchDialogFragment();
        fragment.setArguments(bundle);
        fragment.show(mainActivity.getSupportFragmentManager(), TAG);
        return true;
    } catch (RuntimeException e) {
        return false;
    }
}
Also used : Bundle(android.os.Bundle) PoiCategory(net.osmand.osm.PoiCategory) SearchUICore(net.osmand.search.SearchUICore) SearchResult(net.osmand.search.core.SearchResult) SearchPhrase(net.osmand.search.core.SearchPhrase)

Example 18 with SearchResult

use of net.osmand.search.core.SearchResult in project Osmand by osmandapp.

the class QuickSearchDialogFragment method reloadCategories.

public void reloadCategories() {
    try {
        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));
            }
            categoriesSearchFragment.updateListAdapter(rows, false);
        }
    } catch (IOException e) {
        e.printStackTrace();
    }
}
Also used : ArrayList(java.util.ArrayList) SearchResultCollection(net.osmand.search.SearchUICore.SearchResultCollection) SearchResult(net.osmand.search.core.SearchResult) IOException(java.io.IOException)

Example 19 with SearchResult

use of net.osmand.search.core.SearchResult in project Osmand by osmandapp.

the class QuickSearchDialogFragment method showInstance.

public static boolean showInstance(@NonNull MapActivity mapActivity, @NonNull String searchQuery, @Nullable Object object, QuickSearchType searchType, QuickSearchTab showSearchTab, @Nullable LatLon latLon) {
    try {
        if (mapActivity.isActivityDestroyed()) {
            return false;
        }
        mapActivity.getMyApplication().logEvent(mapActivity, "search_open");
        Bundle bundle = new Bundle();
        if (object != null) {
            bundle.putBoolean(QUICK_SEARCH_RUN_SEARCH_FIRST_TIME_KEY, true);
            String objectLocalizedName = searchQuery;
            if (object instanceof PoiCategory) {
                PoiCategory c = (PoiCategory) object;
                objectLocalizedName = c.getTranslation();
                SearchUICore searchUICore = mapActivity.getMyApplication().getSearchUICore().getCore();
                SearchPhrase phrase = searchUICore.resetPhrase(objectLocalizedName + " ");
                SearchResult sr = new SearchResult(phrase);
                sr.localeName = objectLocalizedName;
                sr.object = c;
                sr.priority = SEARCH_AMENITY_TYPE_PRIORITY;
                sr.priorityDistance = 0;
                sr.objectType = ObjectType.POI_TYPE;
                searchUICore.selectSearchResult(sr);
                bundle.putBoolean(QUICK_SEARCH_PHRASE_DEFINED_KEY, true);
            } else if (object instanceof PoiUIFilter) {
                PoiUIFilter filter = (PoiUIFilter) object;
                objectLocalizedName = filter.getName();
                SearchUICore searchUICore = mapActivity.getMyApplication().getSearchUICore().getCore();
                SearchPhrase phrase = searchUICore.resetPhrase();
                SearchResult sr = new SearchResult(phrase);
                sr.localeName = objectLocalizedName;
                sr.object = filter;
                sr.priority = SEARCH_AMENITY_TYPE_PRIORITY;
                sr.priorityDistance = 0;
                sr.objectType = ObjectType.POI_TYPE;
                searchUICore.selectSearchResult(sr);
                bundle.putBoolean(QUICK_SEARCH_PHRASE_DEFINED_KEY, true);
            }
            searchQuery = objectLocalizedName.trim() + " ";
        } else if (!Algorithms.isEmpty(searchQuery)) {
            bundle.putBoolean(QUICK_SEARCH_RUN_SEARCH_FIRST_TIME_KEY, true);
        }
        bundle.putString(QUICK_SEARCH_QUERY_KEY, searchQuery);
        bundle.putString(QUICK_SEARCH_SHOW_TAB_KEY, showSearchTab.name());
        bundle.putString(QUICK_SEARCH_TYPE_KEY, searchType.name());
        if (latLon != null) {
            bundle.putDouble(QUICK_SEARCH_LAT_KEY, latLon.getLatitude());
            bundle.putDouble(QUICK_SEARCH_LON_KEY, latLon.getLongitude());
        }
        QuickSearchDialogFragment fragment = new QuickSearchDialogFragment();
        fragment.setArguments(bundle);
        fragment.show(mapActivity.getSupportFragmentManager(), TAG);
        return true;
    } catch (RuntimeException e) {
        return false;
    }
}
Also used : Bundle(android.os.Bundle) PoiCategory(net.osmand.osm.PoiCategory) SearchUICore(net.osmand.search.SearchUICore) SearchResult(net.osmand.search.core.SearchResult) SpannableString(android.text.SpannableString) SearchPhrase(net.osmand.search.core.SearchPhrase) PoiUIFilter(net.osmand.plus.poi.PoiUIFilter)

Example 20 with SearchResult

use of net.osmand.search.core.SearchResult in project Osmand by osmandapp.

the class QuickSearchDialogFragment method showFilter.

public void showFilter(@NonNull String filterId) {
    PoiUIFilter filter = app.getPoiFilters().getFilterById(filterId);
    boolean isCustomFilter = filterId.equals(app.getPoiFilters().getCustomPOIFilter().getFilterId());
    if (isCustomFilter) {
        fabVisible = true;
        poiFilterApplied = true;
        updateFab();
    }
    SearchResult sr = new SearchResult(searchUICore.getPhrase());
    sr.localeName = filter.getName();
    sr.object = filter;
    sr.priority = 0;
    sr.objectType = ObjectType.POI_TYPE;
    searchUICore.selectSearchResult(sr);
    String txt = filter.getName() + " ";
    searchQuery = txt;
    searchEditText.setText(txt);
    searchEditText.setSelection(txt.length());
    updateToolbarButton();
    SearchSettings settings = searchUICore.getSearchSettings();
    if (settings.getRadiusLevel() != 1) {
        searchUICore.updateSettings(settings.setRadiusLevel(1));
    }
    runCoreSearch(txt, false, false);
}
Also used : SearchSettings(net.osmand.search.core.SearchSettings) SearchResult(net.osmand.search.core.SearchResult) SpannableString(android.text.SpannableString) PoiUIFilter(net.osmand.plus.poi.PoiUIFilter)

Aggregations

SearchResult (net.osmand.search.core.SearchResult)20 SearchPhrase (net.osmand.search.core.SearchPhrase)12 ArrayList (java.util.ArrayList)11 SearchResultCollection (net.osmand.search.SearchUICore.SearchResultCollection)9 LatLon (net.osmand.data.LatLon)8 SearchSettings (net.osmand.search.core.SearchSettings)7 SpannableString (android.text.SpannableString)6 PoiUIFilter (net.osmand.plus.poi.PoiUIFilter)5 QuickSearchListItem (net.osmand.plus.search.listitems.QuickSearchListItem)5 Bundle (android.os.Bundle)4 View (android.view.View)4 OnClickListener (android.view.View.OnClickListener)4 ImageView (android.widget.ImageView)4 TextView (android.widget.TextView)4 AdapterView (android.widget.AdapterView)3 ListView (android.widget.ListView)3 IOException (java.io.IOException)3 List (java.util.List)3 SearchMoreItemOnClickListener (net.osmand.plus.search.listitems.QuickSearchMoreListItem.SearchMoreItemOnClickListener)3 SuppressLint (android.annotation.SuppressLint)2