Show search results (navigation api)

This commit is contained in:
crimean 2018-09-18 16:36:05 +03:00
parent d00aab78ec
commit 92ea6653d8
7 changed files with 178 additions and 88 deletions

View file

@ -20,7 +20,6 @@ import android.view.View;
import android.widget.ArrayAdapter; import android.widget.ArrayAdapter;
import net.osmand.IndexConstants; import net.osmand.IndexConstants;
import net.osmand.Location;
import net.osmand.PlatformUtil; import net.osmand.PlatformUtil;
import net.osmand.aidl.favorite.AFavorite; import net.osmand.aidl.favorite.AFavorite;
import net.osmand.aidl.favorite.group.AFavoriteGroup; import net.osmand.aidl.favorite.group.AFavoriteGroup;
@ -49,7 +48,6 @@ import net.osmand.plus.MapMarkersHelper;
import net.osmand.plus.MapMarkersHelper.MapMarker; import net.osmand.plus.MapMarkersHelper.MapMarker;
import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandPlugin; import net.osmand.plus.OsmandPlugin;
import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity; import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.audionotes.AudioVideoNotesPlugin; import net.osmand.plus.audionotes.AudioVideoNotesPlugin;
import net.osmand.plus.dialogs.ConfigureMapMenu; import net.osmand.plus.dialogs.ConfigureMapMenu;
@ -109,6 +107,8 @@ public class OsmandAidlApi {
private static final String AIDL_URI = "aidl_uri"; private static final String AIDL_URI = "aidl_uri";
private static final String AIDL_FORCE = "aidl_force"; private static final String AIDL_FORCE = "aidl_force";
private static final String AIDL_SEARCH_QUERY = "aidl_search_query"; private static final String AIDL_SEARCH_QUERY = "aidl_search_query";
private static final String AIDL_SEARCH_LAT = "aidl_search_lat";
private static final String AIDL_SEARCH_LON = "aidl_search_lon";
private static final String AIDL_OBJECT_ID = "aidl_object_id"; private static final String AIDL_OBJECT_ID = "aidl_object_id";
@ -540,18 +540,21 @@ public class OsmandAidlApi {
if (startLat != 0 && startLon != 0) { if (startLat != 0 && startLon != 0) {
start = new LatLon(startLat, startLon); start = new LatLon(startLat, startLon);
startDesc = new PointDescription(PointDescription.POINT_TYPE_LOCATION, startName); startDesc = new PointDescription(PointDescription.POINT_TYPE_LOCATION, startName);
} else {
Location location = app.getLocationProvider().getLastKnownLocation();
if (location != null) {
start = new LatLon(location.getLatitude(), location.getLongitude());
startDesc = new PointDescription(PointDescription.POINT_TYPE_MY_LOCATION, mapActivity.getString(R.string.shared_string_my_location));
} else { } else {
start = null; start = null;
startDesc = null; startDesc = null;
} }
final LatLon searchLocation;
double searchLat = intent.getDoubleExtra(AIDL_SEARCH_LAT, 0);
double searchLon = intent.getDoubleExtra(AIDL_SEARCH_LON, 0);
if (searchLat != 0 && searchLon != 0) {
searchLocation = new LatLon(searchLat, searchLon);
} else {
searchLocation = null;
} }
if (start != null) { if (searchLocation != null) {
final RoutingHelper routingHelper = app.getRoutingHelper(); final RoutingHelper routingHelper = app.getRoutingHelper();
boolean force = intent.getBooleanExtra(AIDL_FORCE, true); boolean force = intent.getBooleanExtra(AIDL_FORCE, true);
if (routingHelper.isFollowingMode() && !force) { if (routingHelper.isFollowingMode() && !force) {
@ -562,12 +565,12 @@ public class OsmandAidlApi {
public void onDismiss(DialogInterface dialog) { public void onDismiss(DialogInterface dialog) {
MapActivity mapActivity = mapActivityRef.get(); MapActivity mapActivity = mapActivityRef.get();
if (mapActivity != null && !routingHelper.isFollowingMode()) { if (mapActivity != null && !routingHelper.isFollowingMode()) {
ExternalApiHelper.searchAndNavigate(mapActivity, start, startDesc, profile, searchQuery); ExternalApiHelper.searchAndNavigate(mapActivity, searchLocation, start, startDesc, profile, searchQuery, false);
} }
} }
}); });
} else { } else {
ExternalApiHelper.searchAndNavigate(mapActivity, start, startDesc, profile, searchQuery); ExternalApiHelper.searchAndNavigate(mapActivity, searchLocation, start, startDesc, profile, searchQuery, false);
} }
} }
} }
@ -1365,7 +1368,9 @@ public class OsmandAidlApi {
return true; return true;
} }
boolean navigate(String startName, double startLat, double startLon, String destName, double destLat, double destLon, String profile, boolean force) { boolean navigate(String startName, double startLat, double startLon,
String destName, double destLat, double destLon,
String profile, boolean force) {
Intent intent = new Intent(); Intent intent = new Intent();
intent.setAction(AIDL_NAVIGATE); intent.setAction(AIDL_NAVIGATE);
intent.putExtra(AIDL_START_NAME, startName); intent.putExtra(AIDL_START_NAME, startName);
@ -1380,13 +1385,17 @@ public class OsmandAidlApi {
return true; return true;
} }
boolean navigateSearch(String startName, double startLat, double startLon, String searchQuery, String profile, boolean force) { boolean navigateSearch(String startName, double startLat, double startLon,
String searchQuery, double searchLat, double searchLon,
String profile, boolean force) {
Intent intent = new Intent(); Intent intent = new Intent();
intent.setAction(AIDL_NAVIGATE_SEARCH); intent.setAction(AIDL_NAVIGATE_SEARCH);
intent.putExtra(AIDL_START_NAME, startName); intent.putExtra(AIDL_START_NAME, startName);
intent.putExtra(AIDL_START_LAT, startLat); intent.putExtra(AIDL_START_LAT, startLat);
intent.putExtra(AIDL_START_LON, startLon); intent.putExtra(AIDL_START_LON, startLon);
intent.putExtra(AIDL_SEARCH_QUERY, searchQuery); intent.putExtra(AIDL_SEARCH_QUERY, searchQuery);
intent.putExtra(AIDL_SEARCH_LAT, searchLat);
intent.putExtra(AIDL_SEARCH_LON, searchLon);
intent.putExtra(AIDL_PROFILE, profile); intent.putExtra(AIDL_PROFILE, profile);
intent.putExtra(AIDL_FORCE, force); intent.putExtra(AIDL_FORCE, force);
app.sendBroadcast(intent); app.sendBroadcast(intent);

View file

@ -593,7 +593,8 @@ public class OsmandAidlService extends Service {
try { try {
return params != null && getApi("navigateSearch").navigateSearch( return params != null && getApi("navigateSearch").navigateSearch(
params.getStartName(), params.getStartLat(), params.getStartLon(), params.getStartName(), params.getStartLat(), params.getStartLon(),
params.getSearchQuery(), params.getProfile(), params.isForce()); params.getSearchQuery(), params.getSearchLat(), params.getSearchLon(),
params.getProfile(), params.isForce());
} catch (Exception e) { } catch (Exception e) {
handleException(e); handleException(e);
return false; return false;

View file

@ -9,14 +9,20 @@ public class NavigateSearchParams implements Parcelable {
private double startLat; private double startLat;
private double startLon; private double startLon;
private String searchQuery; private String searchQuery;
private double searchLat;
private double searchLon;
private String profile; private String profile;
private boolean force; private boolean force;
public NavigateSearchParams(String startName, double startLat, double startLon, String searchQuery, String profile, boolean force) { public NavigateSearchParams(String startName, double startLat, double startLon,
String searchQuery, double searchLat, double searchLon,
String profile, boolean force) {
this.startName = startName; this.startName = startName;
this.startLat = startLat; this.startLat = startLat;
this.startLon = startLon; this.startLon = startLon;
this.searchQuery = searchQuery; this.searchQuery = searchQuery;
this.searchLat = searchLat;
this.searchLon = searchLon;
this.profile = profile; this.profile = profile;
this.force = force; this.force = force;
} }
@ -53,6 +59,14 @@ public class NavigateSearchParams implements Parcelable {
return searchQuery; return searchQuery;
} }
public double getSearchLat() {
return searchLat;
}
public double getSearchLon() {
return searchLon;
}
public String getProfile() { public String getProfile() {
return profile; return profile;
} }
@ -69,6 +83,8 @@ public class NavigateSearchParams implements Parcelable {
out.writeString(searchQuery); out.writeString(searchQuery);
out.writeString(profile); out.writeString(profile);
out.writeByte((byte) (force ? 1 : 0)); out.writeByte((byte) (force ? 1 : 0));
out.writeDouble(searchLat);
out.writeDouble(searchLon);
} }
private void readFromParcel(Parcel in) { private void readFromParcel(Parcel in) {
@ -78,6 +94,8 @@ public class NavigateSearchParams implements Parcelable {
searchQuery = in.readString(); searchQuery = in.readString();
profile = in.readString(); profile = in.readString();
force = in.readByte() != 0; force = in.readByte() != 0;
searchLat = in.readDouble();
searchLon = in.readDouble();
} }
@Override @Override

View file

@ -20,6 +20,7 @@ import android.os.Environment;
import android.os.Handler; import android.os.Handler;
import android.os.Message; import android.os.Message;
import android.support.annotation.NonNull; import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.ActivityCompat; import android.support.v4.app.ActivityCompat;
import android.support.v4.app.ActivityCompat.OnRequestPermissionsResultCallback; import android.support.v4.app.ActivityCompat.OnRequestPermissionsResultCallback;
import android.support.v4.app.DialogFragment; import android.support.v4.app.DialogFragment;
@ -1837,6 +1838,11 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven
} }
public void showQuickSearch(ShowQuickSearchMode mode, boolean showCategories) { public void showQuickSearch(ShowQuickSearchMode mode, boolean showCategories) {
showQuickSearch(mode, showCategories, "", null);
}
public void showQuickSearch(@NonNull ShowQuickSearchMode mode, boolean showCategories,
@NonNull String searchQuery, @Nullable LatLon searchLocation) {
if (mode == ShowQuickSearchMode.CURRENT) { if (mode == ShowQuickSearchMode.CURRENT) {
mapContextMenu.close(); mapContextMenu.close();
} else { } else {
@ -1844,33 +1850,36 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven
} }
QuickSearchDialogFragment fragment = getQuickSearchDialogFragment(); QuickSearchDialogFragment fragment = getQuickSearchDialogFragment();
if (mode == ShowQuickSearchMode.START_POINT_SELECTION || mode == ShowQuickSearchMode.DESTINATION_SELECTION if (mode == ShowQuickSearchMode.START_POINT_SELECTION || mode == ShowQuickSearchMode.DESTINATION_SELECTION
|| mode == ShowQuickSearchMode.INTERMEDIATE_SELECTION) { || mode == ShowQuickSearchMode.DESTINATION_SELECTION_AND_START || mode == ShowQuickSearchMode.INTERMEDIATE_SELECTION) {
if (fragment != null) { if (fragment != null) {
fragment.dismiss(); fragment.dismiss();
} }
if (mode == ShowQuickSearchMode.INTERMEDIATE_SELECTION) { if (mode == ShowQuickSearchMode.INTERMEDIATE_SELECTION) {
QuickSearchDialogFragment.showInstance(this, "", null, QuickSearchDialogFragment.showInstance(this, searchQuery, null,
QuickSearchType.INTERMEDIATE, showCategories ? QuickSearchTab.CATEGORIES : QuickSearchTab.ADDRESS, null); QuickSearchType.INTERMEDIATE, showCategories ? QuickSearchTab.CATEGORIES : QuickSearchTab.ADDRESS, searchLocation);
} else if (mode == ShowQuickSearchMode.START_POINT_SELECTION) { } else if (mode == ShowQuickSearchMode.START_POINT_SELECTION) {
QuickSearchDialogFragment.showInstance(this, "", null, QuickSearchDialogFragment.showInstance(this, searchQuery, null,
QuickSearchType.START_POINT, showCategories ? QuickSearchTab.CATEGORIES : QuickSearchTab.ADDRESS, null); QuickSearchType.START_POINT, showCategories ? QuickSearchTab.CATEGORIES : QuickSearchTab.ADDRESS, searchLocation);
} else if (mode == ShowQuickSearchMode.DESTINATION_SELECTION) {
QuickSearchDialogFragment.showInstance(this, searchQuery, null,
QuickSearchType.DESTINATION, showCategories ? QuickSearchTab.CATEGORIES : QuickSearchTab.ADDRESS, searchLocation);
} else { } else {
QuickSearchDialogFragment.showInstance(this, "", null, QuickSearchDialogFragment.showInstance(this, searchQuery, null,
QuickSearchType.DESTINATION, showCategories ? QuickSearchTab.CATEGORIES : QuickSearchTab.ADDRESS, null); QuickSearchType.DESTINATION_AND_START, showCategories ? QuickSearchTab.CATEGORIES : QuickSearchTab.ADDRESS, searchLocation);
} }
} else if (fragment != null) { } else if (fragment != null) {
if (mode == ShowQuickSearchMode.NEW if (mode == ShowQuickSearchMode.NEW
|| (mode == ShowQuickSearchMode.NEW_IF_EXPIRED && fragment.isExpired())) { || (mode == ShowQuickSearchMode.NEW_IF_EXPIRED && fragment.isExpired())) {
fragment.dismiss(); fragment.dismiss();
QuickSearchDialogFragment.showInstance(this, "", null, QuickSearchDialogFragment.showInstance(this, searchQuery, null,
QuickSearchType.REGULAR, showCategories ? QuickSearchTab.CATEGORIES : QuickSearchTab.HISTORY, null); QuickSearchType.REGULAR, showCategories ? QuickSearchTab.CATEGORIES : QuickSearchTab.HISTORY, searchLocation);
} else { } else {
fragment.show(); fragment.show();
} }
refreshMap(); refreshMap();
} else { } else {
QuickSearchDialogFragment.showInstance(this, "", null, QuickSearchDialogFragment.showInstance(this, searchQuery, null,
QuickSearchType.REGULAR, showCategories ? QuickSearchTab.CATEGORIES : QuickSearchTab.HISTORY, null); QuickSearchType.REGULAR, showCategories ? QuickSearchTab.CATEGORIES : QuickSearchTab.HISTORY, searchLocation);
} }
} }
@ -1941,6 +1950,7 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven
CURRENT, CURRENT,
START_POINT_SELECTION, START_POINT_SELECTION,
DESTINATION_SELECTION, DESTINATION_SELECTION,
DESTINATION_SELECTION_AND_START,
INTERMEDIATE_SELECTION INTERMEDIATE_SELECTION
} }
} }

View file

@ -32,6 +32,7 @@ import net.osmand.plus.OsmandPlugin;
import net.osmand.plus.R; import net.osmand.plus.R;
import net.osmand.plus.TargetPointsHelper; import net.osmand.plus.TargetPointsHelper;
import net.osmand.plus.activities.MapActivity; import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.activities.MapActivity.ShowQuickSearchMode;
import net.osmand.plus.audionotes.AudioVideoNotesPlugin; import net.osmand.plus.audionotes.AudioVideoNotesPlugin;
import net.osmand.plus.mapcontextmenu.MapContextMenu; import net.osmand.plus.mapcontextmenu.MapContextMenu;
import net.osmand.plus.monitoring.OsmandMonitoringPlugin; import net.osmand.plus.monitoring.OsmandMonitoringPlugin;
@ -117,6 +118,9 @@ public class ExternalApiHelper {
public static final String PARAM_DEST_LAT = "dest_lat"; public static final String PARAM_DEST_LAT = "dest_lat";
public static final String PARAM_DEST_LON = "dest_lon"; public static final String PARAM_DEST_LON = "dest_lon";
public static final String PARAM_DEST_SEARCH_QUERY = "dest_search_query"; public static final String PARAM_DEST_SEARCH_QUERY = "dest_search_query";
public static final String PARAM_SEARCH_LAT = "search_lat";
public static final String PARAM_SEARCH_LON = "search_lon";
public static final String PARAM_SHOW_SEARCH_RESULTS = "show_search_results";
public static final String PARAM_PROFILE = "profile"; public static final String PARAM_PROFILE = "profile";
public static final String PARAM_VERSION = "version"; public static final String PARAM_VERSION = "version";
@ -150,7 +154,7 @@ public class ExternalApiHelper {
public static final int RESULT_CODE_ERROR_GPX_NOT_FOUND = 1004; public static final int RESULT_CODE_ERROR_GPX_NOT_FOUND = 1004;
public static final int RESULT_CODE_ERROR_INVALID_PROFILE = 1005; public static final int RESULT_CODE_ERROR_INVALID_PROFILE = 1005;
public static final int RESULT_CODE_ERROR_EMPTY_SEARCH_QUERY = 1006; public static final int RESULT_CODE_ERROR_EMPTY_SEARCH_QUERY = 1006;
public static final int RESULT_CODE_ERROR_START_LOCATION_UNDEFINED = 1007; public static final int RESULT_CODE_ERROR_SEARCH_LOCATION_UNDEFINED = 1007;
private MapActivity mapActivity; private MapActivity mapActivity;
private int resultCode; private int resultCode;
@ -269,8 +273,8 @@ public class ExternalApiHelper {
String startLatStr = uri.getQueryParameter(PARAM_START_LAT); String startLatStr = uri.getQueryParameter(PARAM_START_LAT);
String startLonStr = uri.getQueryParameter(PARAM_START_LON); String startLonStr = uri.getQueryParameter(PARAM_START_LON);
if (!Algorithms.isEmpty(startLatStr) && !Algorithms.isEmpty(startLonStr)) { if (!Algorithms.isEmpty(startLatStr) && !Algorithms.isEmpty(startLonStr)) {
double lat = Double.parseDouble(uri.getQueryParameter(PARAM_START_LAT)); double lat = Double.parseDouble(startLatStr);
double lon = Double.parseDouble(uri.getQueryParameter(PARAM_START_LON)); double lon = Double.parseDouble(startLonStr);
start = new LatLon(lat, lon); start = new LatLon(lat, lon);
startDesc = new PointDescription(PointDescription.POINT_TYPE_LOCATION, startName); startDesc = new PointDescription(PointDescription.POINT_TYPE_LOCATION, startName);
} else { } else {
@ -319,6 +323,7 @@ public class ExternalApiHelper {
break; break;
} }
} }
final boolean showSearchResults = uri.getBooleanQueryParameter(PARAM_SHOW_SEARCH_RESULTS, false);
final String searchQuery = uri.getQueryParameter(PARAM_DEST_SEARCH_QUERY); final String searchQuery = uri.getQueryParameter(PARAM_DEST_SEARCH_QUERY);
if (Algorithms.isEmpty(searchQuery)) { if (Algorithms.isEmpty(searchQuery)) {
resultCode = RESULT_CODE_ERROR_EMPTY_SEARCH_QUERY; resultCode = RESULT_CODE_ERROR_EMPTY_SEARCH_QUERY;
@ -334,23 +339,27 @@ public class ExternalApiHelper {
String startLatStr = uri.getQueryParameter(PARAM_START_LAT); String startLatStr = uri.getQueryParameter(PARAM_START_LAT);
String startLonStr = uri.getQueryParameter(PARAM_START_LON); String startLonStr = uri.getQueryParameter(PARAM_START_LON);
if (!Algorithms.isEmpty(startLatStr) && !Algorithms.isEmpty(startLonStr)) { if (!Algorithms.isEmpty(startLatStr) && !Algorithms.isEmpty(startLonStr)) {
double lat = Double.parseDouble(uri.getQueryParameter(PARAM_START_LAT)); double lat = Double.parseDouble(startLatStr);
double lon = Double.parseDouble(uri.getQueryParameter(PARAM_START_LON)); double lon = Double.parseDouble(startLonStr);
start = new LatLon(lat, lon); start = new LatLon(lat, lon);
startDesc = new PointDescription(PointDescription.POINT_TYPE_LOCATION, startName); startDesc = new PointDescription(PointDescription.POINT_TYPE_LOCATION, startName);
} else {
Location location = app.getLocationProvider().getLastKnownLocation();
if (location != null) {
start = new LatLon(location.getLatitude(), location.getLongitude());
startDesc = new PointDescription(PointDescription.POINT_TYPE_MY_LOCATION, mapActivity.getString(R.string.shared_string_my_location));
} else { } else {
start = null; start = null;
startDesc = null; startDesc = null;
} }
final LatLon searchLocation;
String searchLatStr = uri.getQueryParameter(PARAM_SEARCH_LAT);
String searchLonStr = uri.getQueryParameter(PARAM_SEARCH_LON);
if (!Algorithms.isEmpty(searchLatStr) && !Algorithms.isEmpty(searchLonStr)) {
double lat = Double.parseDouble(searchLatStr);
double lon = Double.parseDouble(searchLonStr);
searchLocation = new LatLon(lat, lon);
} else {
searchLocation = null;
} }
if (start == null) { if (searchLocation == null) {
resultCode = RESULT_CODE_ERROR_START_LOCATION_UNDEFINED; resultCode = RESULT_CODE_ERROR_SEARCH_LOCATION_UNDEFINED;
} else { } else {
boolean force = uri.getBooleanQueryParameter(PARAM_FORCE, false); boolean force = uri.getBooleanQueryParameter(PARAM_FORCE, false);
@ -362,12 +371,12 @@ public class ExternalApiHelper {
@Override @Override
public void onDismiss(DialogInterface dialog) { public void onDismiss(DialogInterface dialog) {
if (!routingHelper.isFollowingMode()) { if (!routingHelper.isFollowingMode()) {
searchAndNavigate(mapActivity, start, startDesc, profile, searchQuery); searchAndNavigate(mapActivity, searchLocation, start, startDesc, profile, searchQuery, showSearchResults);
} }
} }
}); });
} else { } else {
searchAndNavigate(mapActivity, start, startDesc, profile, searchQuery); searchAndNavigate(mapActivity, searchLocation, start, startDesc, profile, searchQuery, showSearchResults);
} }
resultCode = Activity.RESULT_OK; resultCode = Activity.RESULT_OK;
} }
@ -626,19 +635,34 @@ public class ExternalApiHelper {
} }
} }
static public void searchAndNavigate(@NonNull MapActivity mapActivity, static public void searchAndNavigate(@NonNull MapActivity mapActivity, @NonNull final LatLon searchLocation,
@NonNull final LatLon from, @Nullable final PointDescription fromDesc, @Nullable final LatLon from, @Nullable final PointDescription fromDesc,
@NonNull final ApplicationMode mode, @NonNull final String searchQuery) { @NonNull final ApplicationMode mode, @NonNull final String searchQuery,
final boolean showSearchResults) {
final WeakReference<MapActivity> mapActivityRef = new WeakReference<>(mapActivity); final WeakReference<MapActivity> mapActivityRef = new WeakReference<>(mapActivity);
OsmandApplication app = mapActivity.getMyApplication(); 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); ProgressDialog dlg = new ProgressDialog(mapActivity);
dlg.setTitle(""); dlg.setTitle("");
dlg.setMessage(mapActivity.getString(R.string.searching_address)); dlg.setMessage(mapActivity.getString(R.string.searching_address));
dlg.show(); dlg.show();
final WeakReference<ProgressDialog> dlgRef = new WeakReference<>(dlg); final WeakReference<ProgressDialog> dlgRef = new WeakReference<>(dlg);
runSearch(app, searchQuery, SearchParams.SEARCH_TYPE_ALL, runSearch(app, searchQuery, SearchParams.SEARCH_TYPE_ALL,
from.getLatitude(), from.getLongitude(), 1, 1, new OsmandAidlApi.SearchCompleteCallback() { searchLocation.getLatitude(), searchLocation.getLongitude(),
1, 1, new OsmandAidlApi.SearchCompleteCallback() {
@Override @Override
public void onSearchComplete(final List<SearchResult> resultSet) { public void onSearchComplete(final List<SearchResult> resultSet) {
final MapActivity mapActivity = mapActivityRef.get(); final MapActivity mapActivity = mapActivityRef.get();
@ -653,7 +677,8 @@ public class ExternalApiHelper {
if (resultSet.size() > 0) { if (resultSet.size() > 0) {
final SearchResult res = resultSet.get(0); final SearchResult res = resultSet.get(0);
LatLon to = new LatLon(res.getLatitude(), res.getLongitude()); LatLon to = new LatLon(res.getLatitude(), res.getLongitude());
PointDescription toDesc = new PointDescription(PointDescription.POINT_TYPE_TARGET, res.getLocalName() + ", " + res.getLocalTypeName()); PointDescription toDesc = new PointDescription(
PointDescription.POINT_TYPE_TARGET, res.getLocalName() + ", " + res.getLocalTypeName());
startNavigation(mapActivity, from, fromDesc, to, toDesc, mode); startNavigation(mapActivity, from, fromDesc, to, toDesc, mode);
} else { } else {
mapActivity.getMyApplication().showToastMessage(mapActivity.getString(R.string.search_nothing_found)); mapActivity.getMyApplication().showToastMessage(mapActivity.getString(R.string.search_nothing_found));
@ -664,6 +689,7 @@ public class ExternalApiHelper {
} }
}); });
} }
}
static public void runSearch(final OsmandApplication app, String searchQuery, int searchType, static public void runSearch(final OsmandApplication app, String searchQuery, int searchType,
double latitude, double longitude, int radiusLevel, double latitude, double longitude, int radiusLevel,

View file

@ -12,6 +12,7 @@ import android.support.annotation.Nullable;
import android.support.design.widget.TabLayout; import android.support.design.widget.TabLayout;
import android.support.v4.app.DialogFragment; import android.support.v4.app.DialogFragment;
import android.support.v4.app.Fragment; import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager; import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter; import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.app.FragmentTransaction; import android.support.v4.app.FragmentTransaction;
@ -206,6 +207,7 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC
REGULAR, REGULAR,
START_POINT, START_POINT,
DESTINATION, DESTINATION,
DESTINATION_AND_START,
INTERMEDIATE INTERMEDIATE
} }
@ -222,7 +224,7 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC
@Override @Override
@SuppressLint("PrivateResource, ValidFragment") @SuppressLint("PrivateResource, ValidFragment")
public View onCreateView(LayoutInflater inflater, ViewGroup container, public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) { Bundle savedInstanceState) {
final MapActivity mapActivity = getMapActivity(); final MapActivity mapActivity = getMapActivity();
final View view = inflater.inflate(R.layout.search_dialog_fragment, container, false); final View view = inflater.inflate(R.layout.search_dialog_fragment, container, false);
@ -375,8 +377,7 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC
} else { } else {
SearchWord word = searchPhrase.getLastSelectedWord(); SearchWord word = searchPhrase.getLastSelectedWord();
if (word != null) { if (word != null) {
if ((searchType == QuickSearchType.START_POINT || searchType == QuickSearchType.DESTINATION || searchType == QuickSearchType.INTERMEDIATE) if (isSelectingTargetPoint() && word.getLocation() != null) {
&& word.getLocation() != null) {
if (mainSearchFragment != null) { if (mainSearchFragment != null) {
mainSearchFragment.showResult(word.getResult()); mainSearchFragment.showResult(word.getResult());
} }
@ -693,6 +694,13 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC
return dialog; return dialog;
} }
public boolean isSelectingTargetPoint() {
return searchType == QuickSearchType.START_POINT
|| searchType == QuickSearchType.DESTINATION
|| searchType == QuickSearchType.DESTINATION_AND_START
|| searchType == QuickSearchType.INTERMEDIATE;
}
public void saveCustomFilter() { public void saveCustomFilter() {
final OsmandApplication app = getMyApplication(); final OsmandApplication app = getMyApplication();
final PoiUIFilter filter = app.getPoiFilters().getCustomPOIFilter(); final PoiUIFilter filter = app.getPoiFilters().getCustomPOIFilter();
@ -856,7 +864,7 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC
if (foundPartialLocation) { if (foundPartialLocation) {
buttonToolbarText.setText(app.getString(R.string.advanced_coords_search).toUpperCase()); buttonToolbarText.setText(app.getString(R.string.advanced_coords_search).toUpperCase());
} else if (searchEditText.getText().length() > 0) { } else if (searchEditText.getText().length() > 0) {
if (searchType == QuickSearchType.START_POINT || searchType == QuickSearchType.DESTINATION || searchType == QuickSearchType.INTERMEDIATE) { if (isSelectingTargetPoint()) {
if (word != null && word.getResult() != null) { if (word != null && word.getResult() != null) {
buttonToolbarText.setText(app.getString(R.string.shared_string_select).toUpperCase() + " " + word.getResult().localeName.toUpperCase()); buttonToolbarText.setText(app.getString(R.string.shared_string_select).toUpperCase() + " " + word.getResult().localeName.toUpperCase());
} else { } else {
@ -1069,9 +1077,13 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC
searchView.setVisibility(View.GONE); searchView.setVisibility(View.GONE);
} else { } else {
tabToolbarView.setVisibility(View.GONE); tabToolbarView.setVisibility(View.GONE);
buttonToolbarView.setVisibility( SearchWord lastWord = searchUICore.getPhrase().getLastSelectedWord();
(isOnlineSearch() && !isTextEmpty()) boolean buttonToolbarVisible = (isOnlineSearch() && !isTextEmpty())
|| !searchUICore.getSearchSettings().isCustomSearch() ? View.VISIBLE : View.GONE); || !searchUICore.getSearchSettings().isCustomSearch();
if (isSelectingTargetPoint() && (lastWord == null || lastWord.getLocation() == null)) {
buttonToolbarVisible = false;
}
buttonToolbarView.setVisibility(buttonToolbarVisible ? View.VISIBLE : View.GONE);
tabsView.setVisibility(View.GONE); tabsView.setVisibility(View.GONE);
searchView.setVisibility(View.VISIBLE); searchView.setVisibility(View.VISIBLE);
} }
@ -1818,9 +1830,14 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC
searchEditText.setText(txt); searchEditText.setText(txt);
searchEditText.setSelection(txt.length()); searchEditText.setSelection(txt.length());
SearchWord lastWord = searchUICore.getPhrase().getLastSelectedWord(); SearchWord lastWord = searchUICore.getPhrase().getLastSelectedWord();
boolean buttonToolbarVisible = lastWord == null || searchType == QuickSearchType.REGULAR || boolean buttonToolbarVisible = searchType == QuickSearchType.REGULAR;
((searchType == QuickSearchType.START_POINT || searchType == QuickSearchType.DESTINATION || searchType == QuickSearchType.INTERMEDIATE) if (!buttonToolbarVisible) {
&& ObjectType.isAddress(lastWord.getType())); if (lastWord == null) {
buttonToolbarVisible = true;
} else if (isSelectingTargetPoint() && lastWord.getLocation() != null) {
buttonToolbarVisible = true;
}
}
buttonToolbarView.setVisibility(buttonToolbarVisible ? View.VISIBLE : View.GONE); buttonToolbarView.setVisibility(buttonToolbarVisible ? View.VISIBLE : View.GONE);
updateToolbarButton(); updateToolbarButton();
SearchSettings settings = searchUICore.getSearchSettings(); SearchSettings settings = searchUICore.getSearchSettings();

View file

@ -299,6 +299,7 @@ public abstract class QuickSearchListFragment extends OsmAndListFragment {
PointDescription pointDescription, Object object) { PointDescription pointDescription, Object object) {
if (mapActivity != null) { if (mapActivity != null) {
OsmandApplication app = mapActivity.getMyApplication(); OsmandApplication app = mapActivity.getMyApplication();
boolean targetPoint = false;
switch (dialogFragment.getSearchType()) { switch (dialogFragment.getSearchType()) {
case REGULAR: { case REGULAR: {
app.getSettings().setMapLocationToShow(latitude, longitude, zoom, pointDescription, true, object); app.getSettings().setMapLocationToShow(latitude, longitude, zoom, pointDescription, true, object);
@ -310,21 +311,29 @@ public abstract class QuickSearchListFragment extends OsmAndListFragment {
mapActivity.getMapLayers().getMapControlsLayer().selectAddress( mapActivity.getMapLayers().getMapControlsLayer().selectAddress(
pointDescription != null ? pointDescription.getName() : null, pointDescription != null ? pointDescription.getName() : null,
latitude, longitude, false, false); latitude, longitude, false, false);
targetPoint = true;
break; break;
} }
case DESTINATION: { case DESTINATION:
case DESTINATION_AND_START: {
mapActivity.getMapLayers().getMapControlsLayer().selectAddress( mapActivity.getMapLayers().getMapControlsLayer().selectAddress(
pointDescription != null ? pointDescription.getName() : null, pointDescription != null ? pointDescription.getName() : null,
latitude, longitude, true, false); latitude, longitude, true, false);
targetPoint = true;
break; break;
} }
case INTERMEDIATE: { case INTERMEDIATE: {
mapActivity.getMapLayers().getMapControlsLayer().selectAddress( mapActivity.getMapLayers().getMapControlsLayer().selectAddress(
pointDescription != null ? pointDescription.getName() : null, pointDescription != null ? pointDescription.getName() : null,
latitude, longitude, false, true); latitude, longitude, false, true);
targetPoint = true;
break; break;
} }
} }
if (targetPoint) {
dialogFragment.dismiss();
mapActivity.getMapLayers().getMapControlsLayer().doNavigate();
}
} }
} }