[Quick search] fixes
This commit is contained in:
parent
d422d77c22
commit
60dc64bbd4
7 changed files with 257 additions and 206 deletions
|
@ -153,7 +153,10 @@ public class SearchUICore {
|
|||
return true;
|
||||
}
|
||||
|
||||
|
||||
public void resetPhrase() {
|
||||
this.phrase = this.phrase.generateNewPhrase("", searchSettings);
|
||||
}
|
||||
|
||||
public SearchResultCollection search(final String text, final ResultMatcher<SearchResult> matcher) {
|
||||
SearchResultCollection quickRes = new SearchResultCollection();
|
||||
final int request = requestNumber.incrementAndGet();
|
||||
|
|
|
@ -34,7 +34,11 @@ public class SearchSettings {
|
|||
public List<BinaryMapIndexReader> getOfflineIndexes() {
|
||||
return offlineIndexes;
|
||||
}
|
||||
|
||||
|
||||
public void setOfflineIndexes(List<BinaryMapIndexReader> offlineIndexes) {
|
||||
this.offlineIndexes = Collections.unmodifiableList(offlineIndexes);
|
||||
}
|
||||
|
||||
public int getRadiusLevel() {
|
||||
return radiusLevel;
|
||||
}
|
||||
|
|
|
@ -13,6 +13,7 @@ import android.support.v7.app.AlertDialog;
|
|||
import net.osmand.IProgress;
|
||||
import net.osmand.IndexConstants;
|
||||
import net.osmand.PlatformUtil;
|
||||
import net.osmand.binary.BinaryMapIndexReader;
|
||||
import net.osmand.map.OsmandRegions;
|
||||
import net.osmand.map.OsmandRegions.RegionTranslation;
|
||||
import net.osmand.map.WorldRegion;
|
||||
|
@ -35,6 +36,7 @@ import net.osmand.plus.render.NativeOsmandLibrary;
|
|||
import net.osmand.plus.render.RendererRegistry;
|
||||
import net.osmand.plus.resources.ResourceManager;
|
||||
import net.osmand.plus.routing.RoutingHelper;
|
||||
import net.osmand.plus.search.QuickSearchHelper;
|
||||
import net.osmand.plus.views.corenative.NativeCoreContext;
|
||||
import net.osmand.plus.voice.CommandPlayer;
|
||||
import net.osmand.plus.voice.CommandPlayerException;
|
||||
|
@ -42,6 +44,7 @@ import net.osmand.plus.voice.MediaCommandPlayerImpl;
|
|||
import net.osmand.plus.voice.TTSCommandPlayerImpl;
|
||||
import net.osmand.render.RenderingRulesStorage;
|
||||
import net.osmand.router.RoutingConfiguration;
|
||||
import net.osmand.search.SearchUICore;
|
||||
import net.osmand.util.Algorithms;
|
||||
|
||||
import org.xmlpull.v1.XmlPullParserException;
|
||||
|
@ -352,13 +355,18 @@ public class AppInitializer implements IProgress {
|
|||
app.selectedGpxHelper = startupInit(new GpxSelectionHelper(app, app.savingTrackHelper), GpxSelectionHelper.class);
|
||||
app.favorites = startupInit(new FavouritesDbHelper(app), FavouritesDbHelper.class);
|
||||
app.waypointHelper = startupInit(new WaypointHelper(app), WaypointHelper.class);
|
||||
|
||||
app.regions = startupInit(new OsmandRegions(), OsmandRegions.class);
|
||||
updateRegionVars();
|
||||
|
||||
app.poiFilters = startupInit(new PoiFiltersHelper(app), PoiFiltersHelper.class);
|
||||
app.rendererRegistry = startupInit(new RendererRegistry(app), RendererRegistry.class);
|
||||
app.geocodingLookupService = startupInit(new GeocodingLookupService(app), GeocodingLookupService.class);
|
||||
app.targetPointsHelper = startupInit(new TargetPointsHelper(app), TargetPointsHelper.class);
|
||||
app.mapMarkersHelper = startupInit(new MapMarkersHelper(app), MapMarkersHelper.class);
|
||||
|
||||
app.searchUICore = startupInit(new SearchUICore(app.poiTypes, app.getSettings().MAP_PREFERRED_LOCALE.get(), new BinaryMapIndexReader[]{}), SearchUICore.class);
|
||||
QuickSearchHelper.initSearchUICore(app);
|
||||
}
|
||||
|
||||
|
||||
|
@ -502,6 +510,7 @@ public class AppInitializer implements IProgress {
|
|||
notifyEvent(InitEvents.RESTORE_BACKUPS);
|
||||
checkLiveUpdatesAlerts();
|
||||
LocalIndexHelper helper = new LocalIndexHelper(app);
|
||||
QuickSearchHelper.setRepositoriesForSearchUICore(app);
|
||||
} catch (RuntimeException e) {
|
||||
e.printStackTrace();
|
||||
warnings.add(e.getMessage());
|
||||
|
|
|
@ -48,6 +48,7 @@ import net.osmand.plus.resources.ResourceManager;
|
|||
import net.osmand.plus.routing.RoutingHelper;
|
||||
import net.osmand.plus.voice.CommandPlayer;
|
||||
import net.osmand.router.RoutingConfiguration;
|
||||
import net.osmand.search.SearchUICore;
|
||||
import net.osmand.util.Algorithms;
|
||||
|
||||
import java.io.BufferedWriter;
|
||||
|
@ -97,6 +98,7 @@ public class OsmandApplication extends MultiDexApplication {
|
|||
BRouterServiceConnection bRouterServiceConnection;
|
||||
OsmandRegions regions;
|
||||
GeocodingLookupService geocodingLookupService;
|
||||
SearchUICore searchUICore;
|
||||
|
||||
RoutingConfiguration.Builder defaultRoutingConfig;
|
||||
private Locale preferredLocale = null;
|
||||
|
@ -358,6 +360,10 @@ public class OsmandApplication extends MultiDexApplication {
|
|||
return geocodingLookupService;
|
||||
}
|
||||
|
||||
public SearchUICore getSearchUICore() {
|
||||
return searchUICore;
|
||||
}
|
||||
|
||||
public CommandPlayer getPlayer() {
|
||||
return player;
|
||||
}
|
||||
|
|
|
@ -2,7 +2,6 @@ package net.osmand.plus.search;
|
|||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.app.Dialog;
|
||||
import android.app.ProgressDialog;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.content.res.Resources;
|
||||
|
@ -36,15 +35,14 @@ import android.widget.TextView;
|
|||
import net.osmand.AndroidUtils;
|
||||
import net.osmand.Location;
|
||||
import net.osmand.ResultMatcher;
|
||||
import net.osmand.binary.BinaryMapIndexReader;
|
||||
import net.osmand.data.FavouritePoint;
|
||||
import net.osmand.data.LatLon;
|
||||
import net.osmand.data.PointDescription;
|
||||
import net.osmand.osm.AbstractPoiType;
|
||||
import net.osmand.plus.AppInitializer;
|
||||
import net.osmand.plus.AppInitializer.AppInitializeListener;
|
||||
import net.osmand.plus.GPXUtilities;
|
||||
import net.osmand.plus.GPXUtilities.GPXFile;
|
||||
import net.osmand.plus.GPXUtilities.WptPt;
|
||||
import net.osmand.plus.GpxSelectionHelper.SelectedGpxFile;
|
||||
import net.osmand.plus.LockableViewPager;
|
||||
import net.osmand.plus.OsmAndFormatter;
|
||||
import net.osmand.plus.OsmAndLocationProvider.OsmAndCompassListener;
|
||||
|
@ -56,14 +54,13 @@ import net.osmand.plus.activities.MapActivity;
|
|||
import net.osmand.plus.helpers.SearchHistoryHelper;
|
||||
import net.osmand.plus.helpers.SearchHistoryHelper.HistoryEntry;
|
||||
import net.osmand.plus.poi.PoiUIFilter;
|
||||
import net.osmand.plus.resources.RegionAddressRepository;
|
||||
import net.osmand.plus.search.QuickSearchHelper.SearchHistoryAPI;
|
||||
import net.osmand.search.SearchUICore;
|
||||
import net.osmand.search.SearchUICore.SearchResultCollection;
|
||||
import net.osmand.search.SearchUICore.SearchResultMatcher;
|
||||
import net.osmand.search.core.ObjectType;
|
||||
import net.osmand.search.core.SearchCoreAPI;
|
||||
import net.osmand.search.core.SearchCoreFactory.SearchAmenityTypesAPI;
|
||||
import net.osmand.search.core.SearchCoreFactory.SearchBaseAPI;
|
||||
import net.osmand.search.core.SearchPhrase;
|
||||
import net.osmand.search.core.SearchResult;
|
||||
import net.osmand.search.core.SearchSettings;
|
||||
|
@ -74,7 +71,6 @@ import net.osmand.util.MapUtils;
|
|||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
|
@ -113,12 +109,6 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC
|
|||
private boolean paused;
|
||||
private boolean foundPartialLocation;
|
||||
|
||||
public static final int SEARCH_FAVORITE_API_PRIORITY = 2;
|
||||
public static final int SEARCH_FAVORITE_OBJECT_PRIORITY = 10;
|
||||
public static final int SEARCH_WPT_API_PRIORITY = 2;
|
||||
public static final int SEARCH_WPT_OBJECT_PRIORITY = 10;
|
||||
public static final int SEARCH_HISTORY_API_PRIORITY = 3;
|
||||
public static final int SEARCH_HISTORY_OBJECT_PRIORITY = 10;
|
||||
private static final double DISTANCE_THRESHOLD = 70000; // 70km
|
||||
|
||||
|
||||
|
@ -295,7 +285,11 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC
|
|||
updateTabbarVisibility(newQueryText.length() == 0);
|
||||
if (!searchQuery.equalsIgnoreCase(newQueryText)) {
|
||||
searchQuery = newQueryText;
|
||||
runSearch();
|
||||
if (Algorithms.isEmpty(searchQuery)) {
|
||||
searchUICore.resetPhrase();
|
||||
} else {
|
||||
runSearch();
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
@ -328,6 +322,7 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC
|
|||
|
||||
updateToolbarButton();
|
||||
updateClearButtonAndHint();
|
||||
updateClearButtonVisibility(searchQuery.length() > 0);
|
||||
addMainSearchFragment();
|
||||
|
||||
searchEditText.requestFocus();
|
||||
|
@ -392,14 +387,8 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC
|
|||
|
||||
// Setup search core
|
||||
String locale = app.getSettings().MAP_PREFERRED_LOCALE.get();
|
||||
|
||||
Collection<RegionAddressRepository> regionAddressRepositories = app.getResourceManager().getAddressRepositories();
|
||||
BinaryMapIndexReader[] binaryMapIndexReaderArray = new BinaryMapIndexReader[regionAddressRepositories.size()];
|
||||
int i = 0;
|
||||
for (RegionAddressRepository rep : regionAddressRepositories) {
|
||||
binaryMapIndexReaderArray[i++] = rep.getFile();
|
||||
}
|
||||
searchUICore = new SearchUICore(app.getPoiTypes(), locale, binaryMapIndexReaderArray);
|
||||
searchUICore = app.getSearchUICore();
|
||||
searchUICore.resetPhrase();
|
||||
|
||||
location = app.getLocationProvider().getLastKnownLocation();
|
||||
LatLon clt = mapActivity.getMapView().getCurrentRotatedTileBox().getCenterLatLon();
|
||||
|
@ -413,7 +402,7 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC
|
|||
useMapCenter = true;
|
||||
}
|
||||
}
|
||||
SearchSettings settings = searchUICore.getPhrase().getSettings().setOriginalLocation(
|
||||
SearchSettings settings = searchUICore.getSearchSettings().setOriginalLocation(
|
||||
new LatLon(centerLatLon.getLatitude(), centerLatLon.getLongitude()));
|
||||
settings = settings.setLang(locale);
|
||||
searchUICore.updateSettings(settings);
|
||||
|
@ -429,43 +418,6 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC
|
|||
});
|
||||
}
|
||||
});
|
||||
|
||||
// Register favorites search api
|
||||
searchUICore.registerAPI(new SearchBaseAPI() {
|
||||
|
||||
@Override
|
||||
public boolean search(SearchPhrase phrase, SearchResultMatcher resultMatcher) {
|
||||
List<FavouritePoint> favList = getMyApplication().getFavorites().getFavouritePoints();
|
||||
for (FavouritePoint point : favList) {
|
||||
SearchResult sr = new SearchResult(phrase);
|
||||
sr.localeName = point.getName();
|
||||
sr.object = point;
|
||||
sr.priority = SEARCH_FAVORITE_OBJECT_PRIORITY;
|
||||
sr.objectType = ObjectType.FAVORITE;
|
||||
sr.location = new LatLon(point.getLatitude(), point.getLongitude());
|
||||
sr.preferredZoom = 17;
|
||||
if (phrase.getUnknownSearchWordLength() <= 1 && phrase.isNoSelectedType()) {
|
||||
resultMatcher.publish(sr);
|
||||
} else if (phrase.getNameStringMatcher().matches(sr.localeName)) {
|
||||
resultMatcher.publish(sr);
|
||||
} else if (point.getCategory() != null && phrase.getNameStringMatcher().matches(point.getCategory())) {
|
||||
resultMatcher.publish(sr);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSearchPriority(SearchPhrase p) {
|
||||
if(!p.isNoSelectedType() || !p.isUnknownSearchWordPresent()) {
|
||||
return -1;
|
||||
}
|
||||
return SEARCH_FAVORITE_API_PRIORITY;
|
||||
}
|
||||
});
|
||||
|
||||
// Register WptPt search api
|
||||
searchUICore.registerAPI(new SearchWptAPI(app));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -670,14 +622,39 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC
|
|||
if(settings.getRadiusLevel() != 1){
|
||||
searchUICore.updateSettings(settings.setRadiusLevel(1));
|
||||
}
|
||||
SearchResultCollection c = runCoreSearch(text);
|
||||
updateSearchResult(c, false);
|
||||
runCoreSearch(text, true);
|
||||
}
|
||||
|
||||
private SearchResultCollection runCoreSearch(String text) {
|
||||
private void runCoreSearch(final String text, final boolean updateResult) {
|
||||
showProgressBar();
|
||||
foundPartialLocation = false;
|
||||
updateToolbarButton();
|
||||
|
||||
final OsmandApplication app = getMyApplication();
|
||||
if (app.isApplicationInitializing() && text.length() > 0) {
|
||||
app.getAppInitializer().addListener(new AppInitializeListener() {
|
||||
@Override
|
||||
public void onProgress(AppInitializer init, AppInitializer.InitEvents event) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFinish(AppInitializer init) {
|
||||
SearchResultCollection c = runCoreSearchInternal(text);
|
||||
if (updateResult) {
|
||||
updateSearchResult(c, false);
|
||||
}
|
||||
}
|
||||
});
|
||||
} else {
|
||||
SearchResultCollection c = runCoreSearchInternal(text);
|
||||
if (updateResult) {
|
||||
updateSearchResult(c, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private SearchResultCollection runCoreSearchInternal(String text) {
|
||||
|
||||
return searchUICore.search(text, new ResultMatcher<SearchResult>() {
|
||||
|
||||
SearchResultCollection regionResultCollection = null;
|
||||
|
@ -781,7 +758,11 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC
|
|||
searchEditText.setText(txt);
|
||||
searchEditText.setSelection(txt.length());
|
||||
updateToolbarButton();
|
||||
runCoreSearch(txt);
|
||||
SearchSettings settings = searchUICore.getPhrase().getSettings();
|
||||
if(settings.getRadiusLevel() != 1){
|
||||
searchUICore.updateSettings(settings.setRadiusLevel(1));
|
||||
}
|
||||
runCoreSearch(txt, false);
|
||||
}
|
||||
|
||||
private void addMoreButton() {
|
||||
|
@ -795,7 +776,7 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC
|
|||
public void onClick(View v) {
|
||||
SearchSettings settings = searchUICore.getPhrase().getSettings();
|
||||
searchUICore.updateSettings(settings.setRadiusLevel(settings.getRadiusLevel() + 1));
|
||||
runCoreSearch(searchQuery);
|
||||
runCoreSearch(searchQuery, false);
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -826,44 +807,11 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC
|
|||
return false;
|
||||
}
|
||||
|
||||
final OsmandApplication app = mapActivity.getMyApplication();
|
||||
if (app.isApplicationInitializing()) {
|
||||
new AsyncTask<Void, Void, Void>() {
|
||||
|
||||
private ProgressDialog dlg;
|
||||
|
||||
@Override
|
||||
protected void onPreExecute() {
|
||||
dlg = new ProgressDialog(mapActivity);
|
||||
dlg.setTitle("");
|
||||
dlg.setMessage(mapActivity.getString(R.string.wait_current_task_finished));
|
||||
dlg.setCanceledOnTouchOutside(false);
|
||||
dlg.show();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Void doInBackground(Void... params) {
|
||||
while (app.isApplicationInitializing()) {
|
||||
try {
|
||||
Thread.sleep(50);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(Void aVoid) {
|
||||
dlg.hide();
|
||||
showInternal(mapActivity, searchQuery);
|
||||
}
|
||||
}.execute();
|
||||
|
||||
} else {
|
||||
showInternal(mapActivity, searchQuery);
|
||||
}
|
||||
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putString(QUICK_SEARCH_QUERY_KEY, searchQuery);
|
||||
QuickSearchDialogFragment fragment = new QuickSearchDialogFragment();
|
||||
fragment.setArguments(bundle);
|
||||
fragment.show(mapActivity.getSupportFragmentManager(), TAG);
|
||||
return true;
|
||||
|
||||
} catch (RuntimeException e) {
|
||||
|
@ -871,14 +819,6 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC
|
|||
}
|
||||
}
|
||||
|
||||
private static void showInternal(MapActivity mapActivity, String searchQuery) {
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putString(QUICK_SEARCH_QUERY_KEY, searchQuery);
|
||||
QuickSearchDialogFragment fragment = new QuickSearchDialogFragment();
|
||||
fragment.setArguments(bundle);
|
||||
fragment.show(mapActivity.getSupportFragmentManager(), TAG);
|
||||
}
|
||||
|
||||
private MapActivity getMapActivity() {
|
||||
return (MapActivity) getActivity();
|
||||
}
|
||||
|
@ -928,13 +868,11 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC
|
|||
|
||||
private void updateLocationUI(LatLon latLon, Float heading) {
|
||||
if (latLon != null && !paused) {
|
||||
if (mainSearchFragment != null) {
|
||||
if (mainSearchFragment != null && searchView.getVisibility() == View.VISIBLE) {
|
||||
mainSearchFragment.updateLocation(latLon, heading);
|
||||
}
|
||||
if (historySearchFragment != null) {
|
||||
} else if (historySearchFragment != null && viewPager.getCurrentItem() == 0) {
|
||||
historySearchFragment.updateLocation(latLon, heading);
|
||||
}
|
||||
if (categoriesSearchFragment != null) {
|
||||
} else if (categoriesSearchFragment != null && viewPager.getCurrentItem() == 1) {
|
||||
categoriesSearchFragment.updateLocation(latLon, heading);
|
||||
}
|
||||
}
|
||||
|
@ -1126,90 +1064,4 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC
|
|||
return SearchListFragmentType.MAIN;
|
||||
}
|
||||
}
|
||||
|
||||
public static class SearchHistoryAPI extends SearchBaseAPI {
|
||||
|
||||
private OsmandApplication app;
|
||||
|
||||
public SearchHistoryAPI(OsmandApplication app) {
|
||||
this.app = app;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean search(SearchPhrase phrase, SearchResultMatcher resultMatcher) {
|
||||
SearchHistoryHelper helper = SearchHistoryHelper.getInstance(app);
|
||||
List<HistoryEntry> points = helper.getHistoryEntries();
|
||||
for (HistoryEntry point : points) {
|
||||
SearchResult sr = new SearchResult(phrase);
|
||||
sr.localeName = point.getName().getName();
|
||||
sr.object = point;
|
||||
sr.priority = SEARCH_HISTORY_OBJECT_PRIORITY;
|
||||
sr.objectType = ObjectType.RECENT_OBJ;
|
||||
sr.location = new LatLon(point.getLat(), point.getLon());
|
||||
sr.preferredZoom = 17;
|
||||
if (phrase.getUnknownSearchWordLength() <= 1 && phrase.isNoSelectedType()) {
|
||||
resultMatcher.publish(sr);
|
||||
} else if (phrase.getNameStringMatcher().matches(sr.localeName)) {
|
||||
resultMatcher.publish(sr);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSearchPriority(SearchPhrase p) {
|
||||
if(!p.isNoSelectedType()) {
|
||||
return -1;
|
||||
}
|
||||
return SEARCH_HISTORY_API_PRIORITY;
|
||||
}
|
||||
}
|
||||
|
||||
public static class SearchWptAPI extends SearchBaseAPI {
|
||||
|
||||
private OsmandApplication app;
|
||||
|
||||
public SearchWptAPI(OsmandApplication app) {
|
||||
this.app = app;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean search(SearchPhrase phrase, SearchResultMatcher resultMatcher) {
|
||||
|
||||
if (phrase.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
List<SelectedGpxFile> list = app.getSelectedGpxHelper().getSelectedGPXFiles();
|
||||
for (SelectedGpxFile selectedGpx : list) {
|
||||
if (selectedGpx != null) {
|
||||
for (WptPt point : selectedGpx.getGpxFile().points) {
|
||||
SearchResult sr = new SearchResult(phrase);
|
||||
sr.localeName = point.getPointDescription(app).getName();
|
||||
sr.object = point;
|
||||
sr.priority = SEARCH_WPT_OBJECT_PRIORITY;
|
||||
sr.objectType = ObjectType.WPT;
|
||||
sr.location = new LatLon(point.getLatitude(), point.getLongitude());
|
||||
sr.localeRelatedObjectName = app.getRegions().getCountryName(sr.location);
|
||||
sr.relatedObject = selectedGpx.getGpxFile();
|
||||
sr.preferredZoom = 17;
|
||||
if (phrase.getUnknownSearchWordLength() <= 1 && phrase.isNoSelectedType()) {
|
||||
resultMatcher.publish(sr);
|
||||
} else if (phrase.getNameStringMatcher().matches(sr.localeName)) {
|
||||
resultMatcher.publish(sr);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSearchPriority(SearchPhrase p) {
|
||||
if(!p.isNoSelectedType()) {
|
||||
return -1;
|
||||
}
|
||||
return SEARCH_WPT_API_PRIORITY;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
167
OsmAnd/src/net/osmand/plus/search/QuickSearchHelper.java
Normal file
167
OsmAnd/src/net/osmand/plus/search/QuickSearchHelper.java
Normal file
|
@ -0,0 +1,167 @@
|
|||
package net.osmand.plus.search;
|
||||
|
||||
import net.osmand.binary.BinaryMapIndexReader;
|
||||
import net.osmand.data.FavouritePoint;
|
||||
import net.osmand.data.LatLon;
|
||||
import net.osmand.plus.GPXUtilities;
|
||||
import net.osmand.plus.GpxSelectionHelper;
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.helpers.SearchHistoryHelper;
|
||||
import net.osmand.plus.resources.RegionAddressRepository;
|
||||
import net.osmand.search.SearchUICore;
|
||||
import net.osmand.search.core.ObjectType;
|
||||
import net.osmand.search.core.SearchCoreFactory;
|
||||
import net.osmand.search.core.SearchPhrase;
|
||||
import net.osmand.search.core.SearchResult;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
public class QuickSearchHelper {
|
||||
|
||||
public static final int SEARCH_FAVORITE_API_PRIORITY = 2;
|
||||
public static final int SEARCH_FAVORITE_OBJECT_PRIORITY = 10;
|
||||
public static final int SEARCH_WPT_API_PRIORITY = 2;
|
||||
public static final int SEARCH_WPT_OBJECT_PRIORITY = 10;
|
||||
public static final int SEARCH_HISTORY_API_PRIORITY = 3;
|
||||
public static final int SEARCH_HISTORY_OBJECT_PRIORITY = 10;
|
||||
|
||||
public static void initSearchUICore(final OsmandApplication app) {
|
||||
|
||||
SearchUICore searchUICore = app.getSearchUICore();
|
||||
|
||||
// Register favorites search api
|
||||
searchUICore.registerAPI(new SearchCoreFactory.SearchBaseAPI() {
|
||||
|
||||
@Override
|
||||
public boolean search(SearchPhrase phrase, SearchUICore.SearchResultMatcher resultMatcher) {
|
||||
List<FavouritePoint> favList = app.getFavorites().getFavouritePoints();
|
||||
for (FavouritePoint point : favList) {
|
||||
SearchResult sr = new SearchResult(phrase);
|
||||
sr.localeName = point.getName();
|
||||
sr.object = point;
|
||||
sr.priority = SEARCH_FAVORITE_OBJECT_PRIORITY;
|
||||
sr.objectType = ObjectType.FAVORITE;
|
||||
sr.location = new LatLon(point.getLatitude(), point.getLongitude());
|
||||
sr.preferredZoom = 17;
|
||||
if (phrase.getUnknownSearchWordLength() <= 1 && phrase.isNoSelectedType()) {
|
||||
resultMatcher.publish(sr);
|
||||
} else if (phrase.getNameStringMatcher().matches(sr.localeName)) {
|
||||
resultMatcher.publish(sr);
|
||||
} else if (point.getCategory() != null && phrase.getNameStringMatcher().matches(point.getCategory())) {
|
||||
resultMatcher.publish(sr);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSearchPriority(SearchPhrase p) {
|
||||
if(!p.isNoSelectedType() || !p.isUnknownSearchWordPresent()) {
|
||||
return -1;
|
||||
}
|
||||
return SEARCH_FAVORITE_API_PRIORITY;
|
||||
}
|
||||
});
|
||||
|
||||
// Register WptPt search api
|
||||
searchUICore.registerAPI(new SearchWptAPI(app));
|
||||
}
|
||||
|
||||
public static void setRepositoriesForSearchUICore(final OsmandApplication app) {
|
||||
Collection<RegionAddressRepository> regionAddressRepositories = app.getResourceManager().getAddressRepositories();
|
||||
BinaryMapIndexReader[] binaryMapIndexReaderArray = new BinaryMapIndexReader[regionAddressRepositories.size()];
|
||||
int i = 0;
|
||||
for (RegionAddressRepository rep : regionAddressRepositories) {
|
||||
binaryMapIndexReaderArray[i++] = rep.getFile();
|
||||
}
|
||||
app.getSearchUICore().getSearchSettings().setOfflineIndexes(Arrays.asList(binaryMapIndexReaderArray));
|
||||
}
|
||||
|
||||
public static class SearchWptAPI extends SearchCoreFactory.SearchBaseAPI {
|
||||
|
||||
private OsmandApplication app;
|
||||
|
||||
public SearchWptAPI(OsmandApplication app) {
|
||||
this.app = app;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean search(SearchPhrase phrase, SearchUICore.SearchResultMatcher resultMatcher) {
|
||||
|
||||
if (phrase.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
List<GpxSelectionHelper.SelectedGpxFile> list = app.getSelectedGpxHelper().getSelectedGPXFiles();
|
||||
for (GpxSelectionHelper.SelectedGpxFile selectedGpx : list) {
|
||||
if (selectedGpx != null) {
|
||||
for (GPXUtilities.WptPt point : selectedGpx.getGpxFile().points) {
|
||||
SearchResult sr = new SearchResult(phrase);
|
||||
sr.localeName = point.getPointDescription(app).getName();
|
||||
sr.object = point;
|
||||
sr.priority = SEARCH_WPT_OBJECT_PRIORITY;
|
||||
sr.objectType = ObjectType.WPT;
|
||||
sr.location = new LatLon(point.getLatitude(), point.getLongitude());
|
||||
sr.localeRelatedObjectName = app.getRegions().getCountryName(sr.location);
|
||||
sr.relatedObject = selectedGpx.getGpxFile();
|
||||
sr.preferredZoom = 17;
|
||||
if (phrase.getUnknownSearchWordLength() <= 1 && phrase.isNoSelectedType()) {
|
||||
resultMatcher.publish(sr);
|
||||
} else if (phrase.getNameStringMatcher().matches(sr.localeName)) {
|
||||
resultMatcher.publish(sr);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSearchPriority(SearchPhrase p) {
|
||||
if(!p.isNoSelectedType()) {
|
||||
return -1;
|
||||
}
|
||||
return SEARCH_WPT_API_PRIORITY;
|
||||
}
|
||||
}
|
||||
|
||||
public static class SearchHistoryAPI extends SearchCoreFactory.SearchBaseAPI {
|
||||
|
||||
private OsmandApplication app;
|
||||
|
||||
public SearchHistoryAPI(OsmandApplication app) {
|
||||
this.app = app;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean search(SearchPhrase phrase, SearchUICore.SearchResultMatcher resultMatcher) {
|
||||
SearchHistoryHelper helper = SearchHistoryHelper.getInstance(app);
|
||||
List<SearchHistoryHelper.HistoryEntry> points = helper.getHistoryEntries();
|
||||
for (SearchHistoryHelper.HistoryEntry point : points) {
|
||||
SearchResult sr = new SearchResult(phrase);
|
||||
sr.localeName = point.getName().getName();
|
||||
sr.object = point;
|
||||
sr.priority = SEARCH_HISTORY_OBJECT_PRIORITY;
|
||||
sr.objectType = ObjectType.RECENT_OBJ;
|
||||
sr.location = new LatLon(point.getLat(), point.getLon());
|
||||
sr.preferredZoom = 17;
|
||||
if (phrase.getUnknownSearchWordLength() <= 1 && phrase.isNoSelectedType()) {
|
||||
resultMatcher.publish(sr);
|
||||
} else if (phrase.getNameStringMatcher().matches(sr.localeName)) {
|
||||
resultMatcher.publish(sr);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSearchPriority(SearchPhrase p) {
|
||||
if(!p.isNoSelectedType()) {
|
||||
return -1;
|
||||
}
|
||||
return SEARCH_HISTORY_API_PRIORITY;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -5,9 +5,10 @@ import android.view.LayoutInflater;
|
|||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.AbsListView;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.ListAdapter;
|
||||
import android.widget.ListView;
|
||||
|
||||
import net.osmand.data.Amenity;
|
||||
import net.osmand.data.City;
|
||||
import net.osmand.data.FavouritePoint;
|
||||
|
@ -32,6 +33,7 @@ public abstract class QuickSearchListFragment extends OsmAndListFragment {
|
|||
private QuickSearchDialogFragment dialogFragment;
|
||||
private QuickSearchListAdapter listAdapter;
|
||||
private boolean touching;
|
||||
private boolean scrolling;
|
||||
|
||||
enum SearchListFragmentType {
|
||||
HISTORY,
|
||||
|
@ -51,6 +53,14 @@ public abstract class QuickSearchListFragment extends OsmAndListFragment {
|
|||
super.onViewCreated(view, savedInstanceState);
|
||||
ListView listView = getListView();
|
||||
if (listView != null) {
|
||||
listView.setOnScrollListener(new AbsListView.OnScrollListener() {
|
||||
public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
|
||||
}
|
||||
|
||||
public void onScrollStateChanged(AbsListView view, int scrollState) {
|
||||
scrolling = (scrollState != AbsListView.OnScrollListener.SCROLL_STATE_IDLE);
|
||||
}
|
||||
});
|
||||
View header = getLayoutInflater(savedInstanceState).inflate(R.layout.list_shadow_header, null);
|
||||
View footer = getLayoutInflater(savedInstanceState).inflate(R.layout.list_shadow_footer, null);
|
||||
listView.addHeaderView(header, null, false);
|
||||
|
@ -191,7 +201,7 @@ public abstract class QuickSearchListFragment extends OsmAndListFragment {
|
|||
}
|
||||
|
||||
public void updateLocation(LatLon latLon, Float heading) {
|
||||
if (listAdapter != null && !touching) {
|
||||
if (listAdapter != null && !touching && !scrolling) {
|
||||
listAdapter.setLocation(latLon);
|
||||
listAdapter.setHeading(heading);
|
||||
listAdapter.notifyDataSetChanged();
|
||||
|
|
Loading…
Reference in a new issue