Search in sources :

Example 1 with AidlSearchResultWrapper

use of net.osmand.aidl.AidlSearchResultWrapper in project Osmand by osmandapp.

the class ExternalApiHelper method runSearch.

public static void runSearch(final OsmandApplication app, String searchQuery, int searchType, double latitude, double longitude, int radiusLevel, int totalLimit, final OsmandAidlApi.SearchCompleteCallback callback) {
    if (radiusLevel < 1) {
        radiusLevel = 1;
    } else if (radiusLevel > MAX_DEFAULT_SEARCH_RADIUS) {
        radiusLevel = MAX_DEFAULT_SEARCH_RADIUS;
    }
    if (totalLimit <= 0) {
        totalLimit = -1;
    }
    final int limit = totalLimit;
    final SearchUICore core = app.getSearchUICore().getCore();
    core.setOnResultsComplete(new Runnable() {

        @Override
        public void run() {
            List<AidlSearchResultWrapper> resultSet = new ArrayList<>();
            SearchUICore.SearchResultCollection resultCollection = core.getCurrentSearchResult();
            int count = 0;
            for (net.osmand.search.core.SearchResult r : resultCollection.getCurrentSearchResults()) {
                String name = QuickSearchListItem.getName(app, r);
                String typeName = QuickSearchListItem.getTypeName(app, r);
                AidlSearchResultWrapper result = new AidlSearchResultWrapper(r.location.getLatitude(), r.location.getLongitude(), name, typeName, r.alternateName, new ArrayList<>(r.otherNames));
                resultSet.add(result);
                count++;
                if (limit != -1 && count >= limit) {
                    break;
                }
            }
            callback.onSearchComplete(resultSet);
        }
    });
    SearchSettings searchSettings = new SearchSettings(core.getSearchSettings()).setRadiusLevel(radiusLevel).setEmptyQueryAllowed(false).setSortByName(false).setOriginalLocation(new LatLon(latitude, longitude)).setTotalLimit(totalLimit);
    List<ObjectType> searchTypes = new ArrayList<>();
    if ((searchType & SearchParams.SEARCH_TYPE_POI) != 0) {
        searchTypes.add(POI);
    }
    if ((searchType & SearchParams.SEARCH_TYPE_ADDRESS) != 0) {
        searchTypes.add(CITY);
        searchTypes.add(VILLAGE);
        searchTypes.add(POSTCODE);
        searchTypes.add(STREET);
        searchTypes.add(HOUSE);
        searchTypes.add(STREET_INTERSECTION);
    }
    searchSettings = searchSettings.setSearchTypes(searchTypes.toArray(new ObjectType[0]));
    core.search(searchQuery, false, null, searchSettings);
}
Also used : AidlSearchResultWrapper(net.osmand.aidl.AidlSearchResultWrapper) ArrayList(java.util.ArrayList) FavouritePoint(net.osmand.data.FavouritePoint) LatLon(net.osmand.data.LatLon) ObjectType(net.osmand.search.core.ObjectType) SearchUICore(net.osmand.search.SearchUICore) SearchSettings(net.osmand.search.core.SearchSettings) List(java.util.List) ArrayList(java.util.ArrayList)

Example 2 with AidlSearchResultWrapper

use of net.osmand.aidl.AidlSearchResultWrapper in project Osmand by osmandapp.

the class ExternalApiHelper method searchAndNavigate.

public static void searchAndNavigate(@NonNull MapActivity mapActivity, @NonNull final LatLon searchLocation, @Nullable final LatLon from, @Nullable final PointDescription fromDesc, @NonNull final ApplicationMode mode, @NonNull final String searchQuery, final boolean showSearchResults, final boolean checkLocationPermission) {
    final WeakReference<MapActivity> mapActivityRef = new WeakReference<>(mapActivity);
    OsmandApplication app = mapActivity.getMyApplication();
    if (showSearchResults) {
        RoutingHelper routingHelper = app.getRoutingHelper();
        if (!routingHelper.isFollowingMode() && !routingHelper.isRoutePlanningMode()) {
            mapActivity.getMapActions().enterRoutePlanningMode(from, fromDesc);
        } else {
            mapActivity.getRoutingHelper().setRoutePlanningMode(true);
            TargetPointsHelper targets = app.getTargetPointsHelper();
            targets.setStartPoint(from, false, fromDesc);
            mapActivity.getMapViewTrackingUtilities().switchToRoutePlanningMode();
            mapActivity.refreshMap();
        }
        mapActivity.showQuickSearch(ShowQuickSearchMode.DESTINATION_SELECTION_AND_START, true, searchQuery, searchLocation);
    } else {
        ProgressDialog dlg = new ProgressDialog(mapActivity);
        dlg.setTitle("");
        dlg.setMessage(mapActivity.getString(R.string.searching_address));
        dlg.show();
        final WeakReference<ProgressDialog> dlgRef = new WeakReference<>(dlg);
        runSearch(app, searchQuery, SearchParams.SEARCH_TYPE_ALL, searchLocation.getLatitude(), searchLocation.getLongitude(), 1, 1, new OsmandAidlApi.SearchCompleteCallback() {

            @Override
            public void onSearchComplete(final List<AidlSearchResultWrapper> resultSet) {
                final MapActivity mapActivity = mapActivityRef.get();
                if (mapActivity != null) {
                    mapActivity.getMyApplication().runInUIThread(new Runnable() {

                        @Override
                        public void run() {
                            ProgressDialog dlg = dlgRef.get();
                            if (dlg != null) {
                                dlg.dismiss();
                            }
                            if (resultSet.size() > 0) {
                                final AidlSearchResultWrapper res = resultSet.get(0);
                                LatLon to = new LatLon(res.getLatitude(), res.getLongitude());
                                PointDescription toDesc = new PointDescription(PointDescription.POINT_TYPE_TARGET, res.getLocalName() + ", " + res.getLocalTypeName());
                                startNavigation(mapActivity, from, fromDesc, to, toDesc, mode, checkLocationPermission);
                            } else {
                                mapActivity.getMyApplication().showToastMessage(mapActivity.getString(R.string.search_nothing_found));
                            }
                        }
                    });
                }
            }
        });
    }
}
Also used : AidlSearchResultWrapper(net.osmand.aidl.AidlSearchResultWrapper) OsmandApplication(net.osmand.plus.OsmandApplication) RoutingHelper(net.osmand.plus.routing.RoutingHelper) ProgressDialog(android.app.ProgressDialog) LatLon(net.osmand.data.LatLon) WeakReference(java.lang.ref.WeakReference) PointDescription(net.osmand.data.PointDescription) OsmandAidlApi(net.osmand.aidl.OsmandAidlApi) MapActivity(net.osmand.plus.activities.MapActivity)

Aggregations

AidlSearchResultWrapper (net.osmand.aidl.AidlSearchResultWrapper)2 LatLon (net.osmand.data.LatLon)2 ProgressDialog (android.app.ProgressDialog)1 WeakReference (java.lang.ref.WeakReference)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 OsmandAidlApi (net.osmand.aidl.OsmandAidlApi)1 FavouritePoint (net.osmand.data.FavouritePoint)1 PointDescription (net.osmand.data.PointDescription)1 OsmandApplication (net.osmand.plus.OsmandApplication)1 MapActivity (net.osmand.plus.activities.MapActivity)1 RoutingHelper (net.osmand.plus.routing.RoutingHelper)1 SearchUICore (net.osmand.search.SearchUICore)1 ObjectType (net.osmand.search.core.ObjectType)1 SearchSettings (net.osmand.search.core.SearchSettings)1