Add get quick action info to intent api
This commit is contained in:
parent
dc4f41c472
commit
6aa421dc04
1 changed files with 43 additions and 12 deletions
|
@ -12,6 +12,9 @@ import androidx.annotation.NonNull;
|
|||
import androidx.annotation.Nullable;
|
||||
import androidx.appcompat.app.AlertDialog;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
|
||||
import net.osmand.GPXUtilities;
|
||||
import net.osmand.GPXUtilities.GPXFile;
|
||||
import net.osmand.IndexConstants;
|
||||
|
@ -53,8 +56,10 @@ import java.io.File;
|
|||
import java.io.FileDescriptor;
|
||||
import java.io.FileInputStream;
|
||||
import java.lang.ref.WeakReference;
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
import static net.osmand.search.core.ObjectType.CITY;
|
||||
|
@ -98,7 +103,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_EXECUTE_QUICK_ACTION = "execute_quick_action";
|
||||
public static final String API_CMD_GET_QUICK_ACTION_INFO = "get_quick_action_info";
|
||||
|
||||
public static final String API_CMD_SUBSCRIBE_VOICE_NOTIFICATIONS = "subscribe_voice_notifications";
|
||||
public static final int VERSION_CODE = 1;
|
||||
|
@ -143,6 +149,9 @@ public class ExternalApiHelper {
|
|||
|
||||
public static final String PARAM_CLOSE_AFTER_COMMAND = "close_after_command";
|
||||
|
||||
public static final String PARAM_QUICK_ACTION_NAME = "quick_action_name";
|
||||
public static final String PARAM_QUICK_ACTION_TYPE = "quick_action_type";
|
||||
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 ApplicationMode[] VALID_PROFILES = new ApplicationMode[]{
|
||||
|
@ -595,17 +604,39 @@ 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_EXECUTE_QUICK_ACTION.equals(cmd)) {
|
||||
int actionNumber = Integer.parseInt(uri.getQueryParameter(PARAM_QUICK_ACTION_NUMBER));
|
||||
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;
|
||||
}
|
||||
if (uri.getBooleanQueryParameter(PARAM_CLOSE_AFTER_COMMAND, true)) {
|
||||
finish = true;
|
||||
}
|
||||
} else if (API_CMD_GET_QUICK_ACTION_INFO.equals(cmd)) {
|
||||
int actionNumber = Integer.parseInt(uri.getQueryParameter(PARAM_QUICK_ACTION_NUMBER));
|
||||
List<QuickAction> actionsList = app.getQuickActionRegistry().getFilteredQuickActions();
|
||||
if (actionNumber >= 0 && actionNumber < actionsList.size()) {
|
||||
QuickAction action = actionsList.get(actionNumber);
|
||||
|
||||
Gson gson = new Gson();
|
||||
Type type = new TypeToken<HashMap<String, String>>() {
|
||||
}.getType();
|
||||
|
||||
result.putExtra(PARAM_QUICK_ACTION_NAME, action.getName(app));
|
||||
result.putExtra(PARAM_QUICK_ACTION_TYPE, action.getActionType().getStringId());
|
||||
result.putExtra(PARAM_QUICK_ACTION_PARAMS, gson.toJson(action.getParams(), type));
|
||||
result.putExtra(PARAM_VERSION, VERSION_CODE);
|
||||
|
||||
resultCode = Activity.RESULT_OK;
|
||||
} else {
|
||||
resultCode = RESULT_CODE_ERROR_QUICK_ACTION_NOT_FOUND;
|
||||
}
|
||||
if (uri.getBooleanQueryParameter(PARAM_CLOSE_AFTER_COMMAND, true)) {
|
||||
finish = true;
|
||||
}
|
||||
} else if (API_CMD_SUBSCRIBE_VOICE_NOTIFICATIONS.equals(cmd)) {
|
||||
// not implemented yet
|
||||
|
|
Loading…
Reference in a new issue