Add intent call to execute quick action

This commit is contained in:
Vitaliy 2020-05-06 14:43:54 +03:00
parent da1a065846
commit 1b16a9122e

View file

@ -36,6 +36,8 @@ 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;
import net.osmand.plus.quickaction.QuickAction;
import net.osmand.plus.quickaction.QuickActionRegistry;
import net.osmand.plus.routing.RouteCalculationResult.NextDirectionInfo;
import net.osmand.plus.routing.RouteDirectionInfo;
import net.osmand.plus.routing.RoutingHelper;
@ -96,6 +98,8 @@ public class ExternalApiHelper {
public static final String API_CMD_SAVE_GPX = "save_gpx";
public static final String API_CMD_CLEAR_GPX = "clear_gpx";
public static final String API_EXECUTE_QUICK_ACTION = "execute_quick_action";
public static final String API_CMD_SUBSCRIBE_VOICE_NOTIFICATIONS = "subscribe_voice_notifications";
public static final int VERSION_CODE = 1;
@ -137,6 +141,7 @@ public class ExternalApiHelper {
public static final String PARAM_CLOSE_AFTER_COMMAND = "close_after_command";
public static final String PARAM_QUICK_ACTION_NUMBER = "quick_action_number";
public static final ApplicationMode[] VALID_PROFILES = new ApplicationMode[]{
ApplicationMode.CAR,
@ -157,6 +162,7 @@ public class ExternalApiHelper {
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_SEARCH_LOCATION_UNDEFINED = 1007;
public static final int RESULT_CODE_ERROR_QUICK_ACTION_NOT_FOUND = 1008;
private MapActivity mapActivity;
private int resultCode;
@ -581,6 +587,18 @@ public class ExternalApiHelper {
finish = true;
}
resultCode = Activity.RESULT_OK;
} else if (API_EXECUTE_QUICK_ACTION.equals(cmd)) {
String actionNumberStr = uri.getQueryParameter(PARAM_QUICK_ACTION_NUMBER);
if (!Algorithms.isEmpty(actionNumberStr)) {
int actionNumber = Integer.parseInt(actionNumberStr);
List<QuickAction> actionsList = app.getQuickActionRegistry().getFilteredQuickActions();
if (actionNumber >= 0 && actionNumber < actionsList.size()) {
QuickActionRegistry.produceAction(actionsList.get(actionNumber)).execute(mapActivity);
resultCode = Activity.RESULT_OK;
} else {
resultCode = RESULT_CODE_ERROR_QUICK_ACTION_NOT_FOUND;
}
}
} else if (API_CMD_SUBSCRIBE_VOICE_NOTIFICATIONS.equals(cmd)) {
// not implemented yet
resultCode = RESULT_CODE_ERROR_NOT_IMPLEMENTED;