Show search results (navigation api)
This commit is contained in:
parent
d00aab78ec
commit
92ea6653d8
7 changed files with 178 additions and 88 deletions
|
@ -20,7 +20,6 @@ import android.view.View;
|
|||
import android.widget.ArrayAdapter;
|
||||
|
||||
import net.osmand.IndexConstants;
|
||||
import net.osmand.Location;
|
||||
import net.osmand.PlatformUtil;
|
||||
import net.osmand.aidl.favorite.AFavorite;
|
||||
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.OsmandApplication;
|
||||
import net.osmand.plus.OsmandPlugin;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.activities.MapActivity;
|
||||
import net.osmand.plus.audionotes.AudioVideoNotesPlugin;
|
||||
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_FORCE = "aidl_force";
|
||||
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";
|
||||
|
||||
|
@ -541,17 +541,20 @@ public class OsmandAidlApi {
|
|||
start = new LatLon(startLat, startLon);
|
||||
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 {
|
||||
start = null;
|
||||
startDesc = null;
|
||||
}
|
||||
start = null;
|
||||
startDesc = null;
|
||||
}
|
||||
|
||||
if (start != 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 (searchLocation != null) {
|
||||
final RoutingHelper routingHelper = app.getRoutingHelper();
|
||||
boolean force = intent.getBooleanExtra(AIDL_FORCE, true);
|
||||
if (routingHelper.isFollowingMode() && !force) {
|
||||
|
@ -562,12 +565,12 @@ public class OsmandAidlApi {
|
|||
public void onDismiss(DialogInterface dialog) {
|
||||
MapActivity mapActivity = mapActivityRef.get();
|
||||
if (mapActivity != null && !routingHelper.isFollowingMode()) {
|
||||
ExternalApiHelper.searchAndNavigate(mapActivity, start, startDesc, profile, searchQuery);
|
||||
ExternalApiHelper.searchAndNavigate(mapActivity, searchLocation, start, startDesc, profile, searchQuery, false);
|
||||
}
|
||||
}
|
||||
});
|
||||
} 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;
|
||||
}
|
||||
|
||||
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.setAction(AIDL_NAVIGATE);
|
||||
intent.putExtra(AIDL_START_NAME, startName);
|
||||
|
@ -1380,13 +1385,17 @@ public class OsmandAidlApi {
|
|||
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.setAction(AIDL_NAVIGATE_SEARCH);
|
||||
intent.putExtra(AIDL_START_NAME, startName);
|
||||
intent.putExtra(AIDL_START_LAT, startLat);
|
||||
intent.putExtra(AIDL_START_LON, startLon);
|
||||
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_FORCE, force);
|
||||
app.sendBroadcast(intent);
|
||||
|
|
|
@ -593,7 +593,8 @@ public class OsmandAidlService extends Service {
|
|||
try {
|
||||
return params != null && getApi("navigateSearch").navigateSearch(
|
||||
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) {
|
||||
handleException(e);
|
||||
return false;
|
||||
|
|
|
@ -9,14 +9,20 @@ public class NavigateSearchParams implements Parcelable {
|
|||
private double startLat;
|
||||
private double startLon;
|
||||
private String searchQuery;
|
||||
private double searchLat;
|
||||
private double searchLon;
|
||||
private String profile;
|
||||
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.startLat = startLat;
|
||||
this.startLon = startLon;
|
||||
this.searchQuery = searchQuery;
|
||||
this.searchLat = searchLat;
|
||||
this.searchLon = searchLon;
|
||||
this.profile = profile;
|
||||
this.force = force;
|
||||
}
|
||||
|
@ -53,6 +59,14 @@ public class NavigateSearchParams implements Parcelable {
|
|||
return searchQuery;
|
||||
}
|
||||
|
||||
public double getSearchLat() {
|
||||
return searchLat;
|
||||
}
|
||||
|
||||
public double getSearchLon() {
|
||||
return searchLon;
|
||||
}
|
||||
|
||||
public String getProfile() {
|
||||
return profile;
|
||||
}
|
||||
|
@ -69,6 +83,8 @@ public class NavigateSearchParams implements Parcelable {
|
|||
out.writeString(searchQuery);
|
||||
out.writeString(profile);
|
||||
out.writeByte((byte) (force ? 1 : 0));
|
||||
out.writeDouble(searchLat);
|
||||
out.writeDouble(searchLon);
|
||||
}
|
||||
|
||||
private void readFromParcel(Parcel in) {
|
||||
|
@ -78,6 +94,8 @@ public class NavigateSearchParams implements Parcelable {
|
|||
searchQuery = in.readString();
|
||||
profile = in.readString();
|
||||
force = in.readByte() != 0;
|
||||
searchLat = in.readDouble();
|
||||
searchLon = in.readDouble();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -20,6 +20,7 @@ import android.os.Environment;
|
|||
import android.os.Handler;
|
||||
import android.os.Message;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v4.app.ActivityCompat;
|
||||
import android.support.v4.app.ActivityCompat.OnRequestPermissionsResultCallback;
|
||||
import android.support.v4.app.DialogFragment;
|
||||
|
@ -1837,6 +1838,11 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven
|
|||
}
|
||||
|
||||
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) {
|
||||
mapContextMenu.close();
|
||||
} else {
|
||||
|
@ -1844,33 +1850,36 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven
|
|||
}
|
||||
QuickSearchDialogFragment fragment = getQuickSearchDialogFragment();
|
||||
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) {
|
||||
fragment.dismiss();
|
||||
}
|
||||
if (mode == ShowQuickSearchMode.INTERMEDIATE_SELECTION) {
|
||||
QuickSearchDialogFragment.showInstance(this, "", null,
|
||||
QuickSearchType.INTERMEDIATE, showCategories ? QuickSearchTab.CATEGORIES : QuickSearchTab.ADDRESS, null);
|
||||
QuickSearchDialogFragment.showInstance(this, searchQuery, null,
|
||||
QuickSearchType.INTERMEDIATE, showCategories ? QuickSearchTab.CATEGORIES : QuickSearchTab.ADDRESS, searchLocation);
|
||||
} else if (mode == ShowQuickSearchMode.START_POINT_SELECTION) {
|
||||
QuickSearchDialogFragment.showInstance(this, "", null,
|
||||
QuickSearchType.START_POINT, showCategories ? QuickSearchTab.CATEGORIES : QuickSearchTab.ADDRESS, null);
|
||||
QuickSearchDialogFragment.showInstance(this, searchQuery, 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 {
|
||||
QuickSearchDialogFragment.showInstance(this, "", null,
|
||||
QuickSearchType.DESTINATION, showCategories ? QuickSearchTab.CATEGORIES : QuickSearchTab.ADDRESS, null);
|
||||
QuickSearchDialogFragment.showInstance(this, searchQuery, null,
|
||||
QuickSearchType.DESTINATION_AND_START, showCategories ? QuickSearchTab.CATEGORIES : QuickSearchTab.ADDRESS, searchLocation);
|
||||
}
|
||||
} else if (fragment != null) {
|
||||
if (mode == ShowQuickSearchMode.NEW
|
||||
|| (mode == ShowQuickSearchMode.NEW_IF_EXPIRED && fragment.isExpired())) {
|
||||
fragment.dismiss();
|
||||
QuickSearchDialogFragment.showInstance(this, "", null,
|
||||
QuickSearchType.REGULAR, showCategories ? QuickSearchTab.CATEGORIES : QuickSearchTab.HISTORY, null);
|
||||
QuickSearchDialogFragment.showInstance(this, searchQuery, null,
|
||||
QuickSearchType.REGULAR, showCategories ? QuickSearchTab.CATEGORIES : QuickSearchTab.HISTORY, searchLocation);
|
||||
} else {
|
||||
fragment.show();
|
||||
}
|
||||
refreshMap();
|
||||
} else {
|
||||
QuickSearchDialogFragment.showInstance(this, "", null,
|
||||
QuickSearchType.REGULAR, showCategories ? QuickSearchTab.CATEGORIES : QuickSearchTab.HISTORY, null);
|
||||
QuickSearchDialogFragment.showInstance(this, searchQuery, null,
|
||||
QuickSearchType.REGULAR, showCategories ? QuickSearchTab.CATEGORIES : QuickSearchTab.HISTORY, searchLocation);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1941,6 +1950,7 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven
|
|||
CURRENT,
|
||||
START_POINT_SELECTION,
|
||||
DESTINATION_SELECTION,
|
||||
DESTINATION_SELECTION_AND_START,
|
||||
INTERMEDIATE_SELECTION
|
||||
}
|
||||
}
|
||||
|
|
|
@ -32,6 +32,7 @@ import net.osmand.plus.OsmandPlugin;
|
|||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.TargetPointsHelper;
|
||||
import net.osmand.plus.activities.MapActivity;
|
||||
import net.osmand.plus.activities.MapActivity.ShowQuickSearchMode;
|
||||
import net.osmand.plus.audionotes.AudioVideoNotesPlugin;
|
||||
import net.osmand.plus.mapcontextmenu.MapContextMenu;
|
||||
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_LON = "dest_lon";
|
||||
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_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_INVALID_PROFILE = 1005;
|
||||
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 int resultCode;
|
||||
|
@ -269,8 +273,8 @@ public class ExternalApiHelper {
|
|||
String startLatStr = uri.getQueryParameter(PARAM_START_LAT);
|
||||
String startLonStr = uri.getQueryParameter(PARAM_START_LON);
|
||||
if (!Algorithms.isEmpty(startLatStr) && !Algorithms.isEmpty(startLonStr)) {
|
||||
double lat = Double.parseDouble(uri.getQueryParameter(PARAM_START_LAT));
|
||||
double lon = Double.parseDouble(uri.getQueryParameter(PARAM_START_LON));
|
||||
double lat = Double.parseDouble(startLatStr);
|
||||
double lon = Double.parseDouble(startLonStr);
|
||||
start = new LatLon(lat, lon);
|
||||
startDesc = new PointDescription(PointDescription.POINT_TYPE_LOCATION, startName);
|
||||
} else {
|
||||
|
@ -319,6 +323,7 @@ public class ExternalApiHelper {
|
|||
break;
|
||||
}
|
||||
}
|
||||
final boolean showSearchResults = uri.getBooleanQueryParameter(PARAM_SHOW_SEARCH_RESULTS, false);
|
||||
final String searchQuery = uri.getQueryParameter(PARAM_DEST_SEARCH_QUERY);
|
||||
if (Algorithms.isEmpty(searchQuery)) {
|
||||
resultCode = RESULT_CODE_ERROR_EMPTY_SEARCH_QUERY;
|
||||
|
@ -334,23 +339,27 @@ public class ExternalApiHelper {
|
|||
String startLatStr = uri.getQueryParameter(PARAM_START_LAT);
|
||||
String startLonStr = uri.getQueryParameter(PARAM_START_LON);
|
||||
if (!Algorithms.isEmpty(startLatStr) && !Algorithms.isEmpty(startLonStr)) {
|
||||
double lat = Double.parseDouble(uri.getQueryParameter(PARAM_START_LAT));
|
||||
double lon = Double.parseDouble(uri.getQueryParameter(PARAM_START_LON));
|
||||
double lat = Double.parseDouble(startLatStr);
|
||||
double lon = Double.parseDouble(startLonStr);
|
||||
start = new LatLon(lat, lon);
|
||||
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 {
|
||||
start = null;
|
||||
startDesc = null;
|
||||
}
|
||||
start = 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) {
|
||||
resultCode = RESULT_CODE_ERROR_START_LOCATION_UNDEFINED;
|
||||
if (searchLocation == null) {
|
||||
resultCode = RESULT_CODE_ERROR_SEARCH_LOCATION_UNDEFINED;
|
||||
} else {
|
||||
boolean force = uri.getBooleanQueryParameter(PARAM_FORCE, false);
|
||||
|
||||
|
@ -362,12 +371,12 @@ public class ExternalApiHelper {
|
|||
@Override
|
||||
public void onDismiss(DialogInterface dialog) {
|
||||
if (!routingHelper.isFollowingMode()) {
|
||||
searchAndNavigate(mapActivity, start, startDesc, profile, searchQuery);
|
||||
searchAndNavigate(mapActivity, searchLocation, start, startDesc, profile, searchQuery, showSearchResults);
|
||||
}
|
||||
}
|
||||
});
|
||||
} else {
|
||||
searchAndNavigate(mapActivity, start, startDesc, profile, searchQuery);
|
||||
searchAndNavigate(mapActivity, searchLocation, start, startDesc, profile, searchQuery, showSearchResults);
|
||||
}
|
||||
resultCode = Activity.RESULT_OK;
|
||||
}
|
||||
|
@ -626,43 +635,60 @@ public class ExternalApiHelper {
|
|||
}
|
||||
}
|
||||
|
||||
static public void searchAndNavigate(@NonNull MapActivity mapActivity,
|
||||
@NonNull final LatLon from, @Nullable final PointDescription fromDesc,
|
||||
@NonNull final ApplicationMode mode, @NonNull final String searchQuery) {
|
||||
static public 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 WeakReference<MapActivity> mapActivityRef = new WeakReference<>(mapActivity);
|
||||
OsmandApplication app = mapActivity.getMyApplication();
|
||||
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,
|
||||
from.getLatitude(), from.getLongitude(), 1, 1, new OsmandAidlApi.SearchCompleteCallback() {
|
||||
@Override
|
||||
public void onSearchComplete(final List<SearchResult> 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 (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<SearchResult> 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 SearchResult 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);
|
||||
} else {
|
||||
mapActivity.getMyApplication().showToastMessage(mapActivity.getString(R.string.search_nothing_found));
|
||||
}
|
||||
}
|
||||
if (resultSet.size() > 0) {
|
||||
final SearchResult 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);
|
||||
} else {
|
||||
mapActivity.getMyApplication().showToastMessage(mapActivity.getString(R.string.search_nothing_found));
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
static public void runSearch(final OsmandApplication app, String searchQuery, int searchType,
|
||||
|
|
|
@ -12,6 +12,7 @@ import android.support.annotation.Nullable;
|
|||
import android.support.design.widget.TabLayout;
|
||||
import android.support.v4.app.DialogFragment;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.support.v4.app.FragmentActivity;
|
||||
import android.support.v4.app.FragmentManager;
|
||||
import android.support.v4.app.FragmentPagerAdapter;
|
||||
import android.support.v4.app.FragmentTransaction;
|
||||
|
@ -206,6 +207,7 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC
|
|||
REGULAR,
|
||||
START_POINT,
|
||||
DESTINATION,
|
||||
DESTINATION_AND_START,
|
||||
INTERMEDIATE
|
||||
}
|
||||
|
||||
|
@ -222,7 +224,7 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC
|
|||
|
||||
@Override
|
||||
@SuppressLint("PrivateResource, ValidFragment")
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container,
|
||||
Bundle savedInstanceState) {
|
||||
final MapActivity mapActivity = getMapActivity();
|
||||
final View view = inflater.inflate(R.layout.search_dialog_fragment, container, false);
|
||||
|
@ -375,8 +377,7 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC
|
|||
} else {
|
||||
SearchWord word = searchPhrase.getLastSelectedWord();
|
||||
if (word != null) {
|
||||
if ((searchType == QuickSearchType.START_POINT || searchType == QuickSearchType.DESTINATION || searchType == QuickSearchType.INTERMEDIATE)
|
||||
&& word.getLocation() != null) {
|
||||
if (isSelectingTargetPoint() && word.getLocation() != null) {
|
||||
if (mainSearchFragment != null) {
|
||||
mainSearchFragment.showResult(word.getResult());
|
||||
}
|
||||
|
@ -693,6 +694,13 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC
|
|||
return dialog;
|
||||
}
|
||||
|
||||
public boolean isSelectingTargetPoint() {
|
||||
return searchType == QuickSearchType.START_POINT
|
||||
|| searchType == QuickSearchType.DESTINATION
|
||||
|| searchType == QuickSearchType.DESTINATION_AND_START
|
||||
|| searchType == QuickSearchType.INTERMEDIATE;
|
||||
}
|
||||
|
||||
public void saveCustomFilter() {
|
||||
final OsmandApplication app = getMyApplication();
|
||||
final PoiUIFilter filter = app.getPoiFilters().getCustomPOIFilter();
|
||||
|
@ -856,7 +864,7 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC
|
|||
if (foundPartialLocation) {
|
||||
buttonToolbarText.setText(app.getString(R.string.advanced_coords_search).toUpperCase());
|
||||
} 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) {
|
||||
buttonToolbarText.setText(app.getString(R.string.shared_string_select).toUpperCase() + " " + word.getResult().localeName.toUpperCase());
|
||||
} else {
|
||||
|
@ -1069,9 +1077,13 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC
|
|||
searchView.setVisibility(View.GONE);
|
||||
} else {
|
||||
tabToolbarView.setVisibility(View.GONE);
|
||||
buttonToolbarView.setVisibility(
|
||||
(isOnlineSearch() && !isTextEmpty())
|
||||
|| !searchUICore.getSearchSettings().isCustomSearch() ? View.VISIBLE : View.GONE);
|
||||
SearchWord lastWord = searchUICore.getPhrase().getLastSelectedWord();
|
||||
boolean buttonToolbarVisible = (isOnlineSearch() && !isTextEmpty())
|
||||
|| !searchUICore.getSearchSettings().isCustomSearch();
|
||||
if (isSelectingTargetPoint() && (lastWord == null || lastWord.getLocation() == null)) {
|
||||
buttonToolbarVisible = false;
|
||||
}
|
||||
buttonToolbarView.setVisibility(buttonToolbarVisible ? View.VISIBLE : View.GONE);
|
||||
tabsView.setVisibility(View.GONE);
|
||||
searchView.setVisibility(View.VISIBLE);
|
||||
}
|
||||
|
@ -1818,9 +1830,14 @@ public class QuickSearchDialogFragment extends DialogFragment implements OsmAndC
|
|||
searchEditText.setText(txt);
|
||||
searchEditText.setSelection(txt.length());
|
||||
SearchWord lastWord = searchUICore.getPhrase().getLastSelectedWord();
|
||||
boolean buttonToolbarVisible = lastWord == null || searchType == QuickSearchType.REGULAR ||
|
||||
((searchType == QuickSearchType.START_POINT || searchType == QuickSearchType.DESTINATION || searchType == QuickSearchType.INTERMEDIATE)
|
||||
&& ObjectType.isAddress(lastWord.getType()));
|
||||
boolean buttonToolbarVisible = searchType == QuickSearchType.REGULAR;
|
||||
if (!buttonToolbarVisible) {
|
||||
if (lastWord == null) {
|
||||
buttonToolbarVisible = true;
|
||||
} else if (isSelectingTargetPoint() && lastWord.getLocation() != null) {
|
||||
buttonToolbarVisible = true;
|
||||
}
|
||||
}
|
||||
buttonToolbarView.setVisibility(buttonToolbarVisible ? View.VISIBLE : View.GONE);
|
||||
updateToolbarButton();
|
||||
SearchSettings settings = searchUICore.getSearchSettings();
|
||||
|
|
|
@ -299,6 +299,7 @@ public abstract class QuickSearchListFragment extends OsmAndListFragment {
|
|||
PointDescription pointDescription, Object object) {
|
||||
if (mapActivity != null) {
|
||||
OsmandApplication app = mapActivity.getMyApplication();
|
||||
boolean targetPoint = false;
|
||||
switch (dialogFragment.getSearchType()) {
|
||||
case REGULAR: {
|
||||
app.getSettings().setMapLocationToShow(latitude, longitude, zoom, pointDescription, true, object);
|
||||
|
@ -310,21 +311,29 @@ public abstract class QuickSearchListFragment extends OsmAndListFragment {
|
|||
mapActivity.getMapLayers().getMapControlsLayer().selectAddress(
|
||||
pointDescription != null ? pointDescription.getName() : null,
|
||||
latitude, longitude, false, false);
|
||||
targetPoint = true;
|
||||
break;
|
||||
}
|
||||
case DESTINATION: {
|
||||
case DESTINATION:
|
||||
case DESTINATION_AND_START: {
|
||||
mapActivity.getMapLayers().getMapControlsLayer().selectAddress(
|
||||
pointDescription != null ? pointDescription.getName() : null,
|
||||
latitude, longitude, true, false);
|
||||
targetPoint = true;
|
||||
break;
|
||||
}
|
||||
case INTERMEDIATE: {
|
||||
mapActivity.getMapLayers().getMapControlsLayer().selectAddress(
|
||||
pointDescription != null ? pointDescription.getName() : null,
|
||||
latitude, longitude, false, true);
|
||||
targetPoint = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (targetPoint) {
|
||||
dialogFragment.dismiss();
|
||||
mapActivity.getMapLayers().getMapControlsLayer().doNavigate();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue