Add all profiles which support navigation to intent api

This commit is contained in:
Vitaliy 2020-12-01 12:40:34 +02:00
parent 6c71f50e2d
commit 5611f638d9

View file

@ -31,8 +31,6 @@ import net.osmand.data.PointDescription;
import net.osmand.plus.FavouritesDbHelper; import net.osmand.plus.FavouritesDbHelper;
import net.osmand.plus.GpxSelectionHelper; import net.osmand.plus.GpxSelectionHelper;
import net.osmand.plus.GpxSelectionHelper.SelectedGpxFile; import net.osmand.plus.GpxSelectionHelper.SelectedGpxFile;
import net.osmand.plus.mapmarkers.MapMarkersHelper;
import net.osmand.plus.mapmarkers.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.R;
@ -41,6 +39,8 @@ import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.activities.MapActivity.ShowQuickSearchMode; 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.mapmarkers.MapMarker;
import net.osmand.plus.mapmarkers.MapMarkersHelper;
import net.osmand.plus.monitoring.OsmandMonitoringPlugin; import net.osmand.plus.monitoring.OsmandMonitoringPlugin;
import net.osmand.plus.quickaction.QuickAction; import net.osmand.plus.quickaction.QuickAction;
import net.osmand.plus.quickaction.QuickActionRegistry; import net.osmand.plus.quickaction.QuickActionRegistry;
@ -160,14 +160,6 @@ public class ExternalApiHelper {
public static final String PARAM_QUICK_ACTION_PARAMS = "quick_action_params"; public static final String PARAM_QUICK_ACTION_PARAMS = "quick_action_params";
public static final String PARAM_QUICK_ACTION_NUMBER = "quick_action_number"; public static final String PARAM_QUICK_ACTION_NUMBER = "quick_action_number";
public static final ApplicationMode[] VALID_PROFILES = new ApplicationMode[]{
ApplicationMode.CAR,
ApplicationMode.BICYCLE,
ApplicationMode.PEDESTRIAN
};
public static final ApplicationMode DEFAULT_PROFILE = ApplicationMode.CAR;
// RESULT_OK == -1 // RESULT_OK == -1
// RESULT_CANCELED == 0 // RESULT_CANCELED == 0
// RESULT_FIRST_USER == 1 // RESULT_FIRST_USER == 1
@ -258,15 +250,8 @@ public class ExternalApiHelper {
} else if (API_CMD_NAVIGATE.equals(cmd)) { } else if (API_CMD_NAVIGATE.equals(cmd)) {
String profileStr = uri.getQueryParameter(PARAM_PROFILE); String profileStr = uri.getQueryParameter(PARAM_PROFILE);
final ApplicationMode profile = ApplicationMode.valueOfStringKey(profileStr, DEFAULT_PROFILE); final ApplicationMode profile = findNavigationProfile(app, profileStr);
boolean validProfile = false; if (profile == null) {
for (ApplicationMode mode : VALID_PROFILES) {
if (mode == profile) {
validProfile = true;
break;
}
}
if (!validProfile) {
resultCode = RESULT_CODE_ERROR_INVALID_PROFILE; resultCode = RESULT_CODE_ERROR_INVALID_PROFILE;
} else { } else {
String startName = uri.getQueryParameter(PARAM_START_NAME); String startName = uri.getQueryParameter(PARAM_START_NAME);
@ -325,19 +310,12 @@ public class ExternalApiHelper {
} else if (API_CMD_NAVIGATE_SEARCH.equals(cmd)) { } else if (API_CMD_NAVIGATE_SEARCH.equals(cmd)) {
String profileStr = uri.getQueryParameter(PARAM_PROFILE); String profileStr = uri.getQueryParameter(PARAM_PROFILE);
final ApplicationMode profile = ApplicationMode.valueOfStringKey(profileStr, DEFAULT_PROFILE); final ApplicationMode profile = findNavigationProfile(app, profileStr);
boolean validProfile = false;
for (ApplicationMode mode : VALID_PROFILES) {
if (mode == profile) {
validProfile = true;
break;
}
}
final boolean showSearchResults = uri.getBooleanQueryParameter(PARAM_SHOW_SEARCH_RESULTS, false); 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;
} else if (!validProfile) { } else if (profile == null) {
resultCode = RESULT_CODE_ERROR_INVALID_PROFILE; resultCode = RESULT_CODE_ERROR_INVALID_PROFILE;
} else { } else {
String startName = uri.getQueryParameter(PARAM_START_NAME); String startName = uri.getQueryParameter(PARAM_START_NAME);
@ -642,6 +620,18 @@ public class ExternalApiHelper {
return result; return result;
} }
private ApplicationMode findNavigationProfile(@NonNull OsmandApplication app, @Nullable String profileStr) {
if (!ApplicationMode.DEFAULT.getStringKey().equals(profileStr)) {
ApplicationMode profile = ApplicationMode.valueOfStringKey(profileStr, ApplicationMode.CAR);
for (ApplicationMode mode : ApplicationMode.values(app)) {
if (mode == profile && !Algorithms.isEmpty(mode.getRoutingProfile())) {
return mode;
}
}
}
return null;
}
public static void saveAndNavigateGpx(MapActivity mapActivity, final GPXFile gpxFile, final boolean force) { public static void saveAndNavigateGpx(MapActivity mapActivity, final GPXFile gpxFile, final boolean force) {
final WeakReference<MapActivity> mapActivityRef = new WeakReference<>(mapActivity); final WeakReference<MapActivity> mapActivityRef = new WeakReference<>(mapActivity);