Merge pull request #8703 from osmandapp/fixQuickAction

Fix quick action
This commit is contained in:
vshcherb 2020-03-23 10:03:58 +01:00 committed by GitHub
commit 168a94b210
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
48 changed files with 769 additions and 932 deletions

View file

@ -36,6 +36,7 @@ import net.osmand.plus.myplaces.FavoritesActivity;
import net.osmand.plus.openseamapsplugin.NauticalMapsPlugin; import net.osmand.plus.openseamapsplugin.NauticalMapsPlugin;
import net.osmand.plus.osmedit.OsmEditingPlugin; import net.osmand.plus.osmedit.OsmEditingPlugin;
import net.osmand.plus.parkingpoint.ParkingPositionPlugin; import net.osmand.plus.parkingpoint.ParkingPositionPlugin;
import net.osmand.plus.quickaction.QuickActionType;
import net.osmand.plus.rastermaps.OsmandRasterMapsPlugin; import net.osmand.plus.rastermaps.OsmandRasterMapsPlugin;
import net.osmand.plus.settings.BaseSettingsFragment; import net.osmand.plus.settings.BaseSettingsFragment;
import net.osmand.plus.skimapsplugin.SkiMapsPlugin; import net.osmand.plus.skimapsplugin.SkiMapsPlugin;
@ -237,6 +238,7 @@ public abstract class OsmandPlugin {
initPlugin(app, plugin); initPlugin(app, plugin);
} }
} }
app.getQuickActionRegistry().updateActionTypes();
} }
private static void initPlugin(OsmandApplication app, OsmandPlugin plugin) { private static void initPlugin(OsmandApplication app, OsmandPlugin plugin) {
@ -292,6 +294,7 @@ public abstract class OsmandPlugin {
} }
updateMarketPlugin(app, enabledPlugins, plugin); updateMarketPlugin(app, enabledPlugins, plugin);
} }
app.getQuickActionRegistry().updateActionTypes();
} }
protected boolean pluginAvailable(OsmandApplication app) { protected boolean pluginAvailable(OsmandApplication app) {
@ -315,6 +318,7 @@ public abstract class OsmandPlugin {
plugin.setActive(false); plugin.setActive(false);
} }
app.getSettings().enablePlugin(plugin.getId(), enable); app.getSettings().enablePlugin(plugin.getId(), enable);
app.getQuickActionRegistry().updateActionTypes();
if (activity != null) { if (activity != null) {
if (activity instanceof MapActivity) { if (activity instanceof MapActivity) {
final MapActivity mapActivity = (MapActivity) activity; final MapActivity mapActivity = (MapActivity) activity;
@ -386,14 +390,16 @@ public abstract class OsmandPlugin {
return true; return true;
} }
protected void registerQuickActionTypes(List<QuickActionType> quickActionTypes) {
public void registerLayerContextMenuActions(OsmandMapTileView mapView, ContextMenuAdapter adapter, MapActivity mapActivity) {
} }
public void registerMapContextMenuActions(MapActivity mapActivity, double latitude, double longitude, ContextMenuAdapter adapter, Object selectedObj) { protected void registerLayerContextMenuActions(OsmandMapTileView mapView, ContextMenuAdapter adapter, MapActivity mapActivity) {
} }
public void registerOptionsMenuItems(MapActivity mapActivity, ContextMenuAdapter helper) { protected void registerMapContextMenuActions(MapActivity mapActivity, double latitude, double longitude, ContextMenuAdapter adapter, Object selectedObj) {
}
protected void registerOptionsMenuItems(MapActivity mapActivity, ContextMenuAdapter helper) {
} }
public DashFragmentData getCardFragment() { public DashFragmentData getCardFragment() {
@ -403,13 +409,13 @@ public abstract class OsmandPlugin {
public void updateLocation(Location location) { public void updateLocation(Location location) {
} }
public void addMyPlacesTab(FavoritesActivity favoritesActivity, List<TabItem> mTabs, Intent intent) { protected void addMyPlacesTab(FavoritesActivity favoritesActivity, List<TabItem> mTabs, Intent intent) {
} }
public void contextMenuFragment(Activity activity, Fragment fragment, Object info, ContextMenuAdapter adapter) { protected void contextMenuFragment(Activity activity, Fragment fragment, Object info, ContextMenuAdapter adapter) {
} }
public void optionsMenuFragment(Activity activity, Fragment fragment, ContextMenuAdapter optionsMenuAdapter) { protected void optionsMenuFragment(Activity activity, Fragment fragment, ContextMenuAdapter optionsMenuAdapter) {
} }
public List<String> indexingFiles(IProgress progress) { public List<String> indexingFiles(IProgress progress) {
@ -639,6 +645,8 @@ public abstract class OsmandPlugin {
return installed; return installed;
} }
public static boolean onMapActivityKeyUp(MapActivity mapActivity, int keyCode) { public static boolean onMapActivityKeyUp(MapActivity mapActivity, int keyCode) {
for (OsmandPlugin p : getEnabledPlugins()) { for (OsmandPlugin p : getEnabledPlugins()) {
if (p.mapActivityKeyUp(mapActivity, keyCode)) if (p.mapActivityKeyUp(mapActivity, keyCode))
@ -647,6 +655,14 @@ public abstract class OsmandPlugin {
return false; return false;
} }
public static void registerQuickActionTypesPlugins(List<QuickActionType> quickActionTypes) {
for (OsmandPlugin p : getEnabledPlugins()) {
p.registerQuickActionTypes(quickActionTypes);
}
}
public static void updateLocationPlugins(net.osmand.Location location) { public static void updateLocationPlugins(net.osmand.Location location) {
for (OsmandPlugin p : getEnabledPlugins()) { for (OsmandPlugin p : getEnabledPlugins()) {
p.updateLocation(location); p.updateLocation(location);

View file

@ -25,6 +25,7 @@ import net.osmand.plus.helpers.AvoidSpecificRoads.AvoidRoadInfo;
import net.osmand.plus.poi.PoiUIFilter; import net.osmand.plus.poi.PoiUIFilter;
import net.osmand.plus.quickaction.QuickAction; import net.osmand.plus.quickaction.QuickAction;
import net.osmand.plus.quickaction.QuickActionRegistry; import net.osmand.plus.quickaction.QuickActionRegistry;
import net.osmand.plus.quickaction.QuickActionType;
import net.osmand.util.Algorithms; import net.osmand.util.Algorithms;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
@ -936,19 +937,27 @@ public class SettingsHelper {
Type type = new TypeToken<HashMap<String, String>>() { Type type = new TypeToken<HashMap<String, String>>() {
}.getType(); }.getType();
json = new JSONObject(jsonStr); json = new JSONObject(jsonStr);
QuickActionRegistry quickActionRegistry = app.getQuickActionRegistry();
JSONArray itemsJson = json.getJSONArray("items"); JSONArray itemsJson = json.getJSONArray("items");
for (int i = 0; i < itemsJson.length(); i++) { for (int i = 0; i < itemsJson.length(); i++) {
JSONObject object = itemsJson.getJSONObject(i); JSONObject object = itemsJson.getJSONObject(i);
String name = object.getString("name"); String name = object.getString("name");
int actionType = object.getInt("type"); QuickAction quickAction = null;
String paramsString = object.getString("params"); if(object.has("actionType")) {
HashMap<String, String> params = gson.fromJson(paramsString, type); quickAction = quickActionRegistry .newActionByStringType(object.getString("actionType"));
QuickAction quickAction = new QuickAction(actionType); } else if(object.has("type")) {
if (!name.isEmpty()) { quickAction = quickActionRegistry .newActionByType(object.getInt("type"));
quickAction.setName(name); }
if (quickAction != null) {
String paramsString = object.getString("params");
HashMap<String, String> params = gson.fromJson(paramsString, type);
if (!name.isEmpty()) {
quickAction.setName(name);
}
quickAction.setParams(params);
items.add(quickAction);
} }
quickAction.setParams(params);
items.add(quickAction);
} }
} catch (JSONException e) { } catch (JSONException e) {
throw new IllegalArgumentException("Json parse error", e); throw new IllegalArgumentException("Json parse error", e);
@ -974,7 +983,7 @@ public class SettingsHelper {
JSONObject jsonObject = new JSONObject(); JSONObject jsonObject = new JSONObject();
jsonObject.put("name", action.hasCustomName(app) jsonObject.put("name", action.hasCustomName(app)
? action.getName(app) : ""); ? action.getName(app) : "");
jsonObject.put("type", action.getType()); jsonObject.put("actionType", action.getActionType().getStringId());
jsonObject.put("params", gson.toJson(action.getParams(), type)); jsonObject.put("params", gson.toJson(action.getParams(), type));
jsonArray.put(jsonObject); jsonArray.put(jsonObject);
} }

View file

@ -64,6 +64,7 @@ import net.osmand.plus.helpers.AndroidUiHelper;
import net.osmand.plus.mapcontextmenu.MapContextMenu; import net.osmand.plus.mapcontextmenu.MapContextMenu;
import net.osmand.plus.monitoring.OsmandMonitoringPlugin; import net.osmand.plus.monitoring.OsmandMonitoringPlugin;
import net.osmand.plus.myplaces.FavoritesActivity; import net.osmand.plus.myplaces.FavoritesActivity;
import net.osmand.plus.quickaction.QuickActionType;
import net.osmand.plus.settings.BaseSettingsFragment; import net.osmand.plus.settings.BaseSettingsFragment;
import net.osmand.plus.views.MapInfoLayer; import net.osmand.plus.views.MapInfoLayer;
import net.osmand.plus.views.OsmandMapLayer.DrawSettings; import net.osmand.plus.views.OsmandMapLayer.DrawSettings;
@ -868,6 +869,12 @@ public class AudioVideoNotesPlugin extends OsmandPlugin {
mapActivity.startActivityForResult(intent, 205); mapActivity.startActivityForResult(intent, 205);
} }
@Override
protected void registerQuickActionTypes(List<QuickActionType> quickActionTypes) {
quickActionTypes.add(TakeAudioNoteAction.TYPE);
quickActionTypes.add(TakePhotoNoteAction.TYPE);
quickActionTypes.add(TakeVideoNoteAction.TYPE);
}
@Override @Override
public void mapActivityScreenOff(MapActivity activity) { public void mapActivityScreenOff(MapActivity activity) {

View file

@ -10,9 +10,14 @@ import net.osmand.plus.OsmandPlugin;
import net.osmand.plus.R; import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity; import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.quickaction.QuickAction; import net.osmand.plus.quickaction.QuickAction;
import net.osmand.plus.quickaction.QuickActionType;
public class TakeAudioNoteAction extends QuickAction { public class TakeAudioNoteAction extends QuickAction {
public static final int TYPE = 8;
public static final QuickActionType TYPE = new QuickActionType(8,
"audio.note", TakeAudioNoteAction.class).
nameRes(R.string.quick_action_take_audio_note).iconRes(R.drawable.ic_action_micro_dark).nonEditable().
category(QuickActionType.CREATE_CATEGORY);
public TakeAudioNoteAction() { public TakeAudioNoteAction() {
super(TYPE); super(TYPE);

View file

@ -10,9 +10,14 @@ import net.osmand.plus.OsmandPlugin;
import net.osmand.plus.R; import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity; import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.quickaction.QuickAction; import net.osmand.plus.quickaction.QuickAction;
import net.osmand.plus.quickaction.QuickActionType;
public class TakePhotoNoteAction extends QuickAction { public class TakePhotoNoteAction extends QuickAction {
public static final int TYPE = 10;
public static final QuickActionType TYPE = new QuickActionType(10,
"photo.note", TakePhotoNoteAction .class).
nameRes(R.string.quick_action_take_photo_note).iconRes(R.drawable.ic_action_photo_dark).nonEditable().
category(QuickActionType.CREATE_CATEGORY);
public TakePhotoNoteAction() { public TakePhotoNoteAction() {
super(TYPE); super(TYPE);

View file

@ -10,9 +10,14 @@ import net.osmand.plus.OsmandPlugin;
import net.osmand.plus.R; import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity; import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.quickaction.QuickAction; import net.osmand.plus.quickaction.QuickAction;
import net.osmand.plus.quickaction.QuickActionType;
public class TakeVideoNoteAction extends QuickAction { public class TakeVideoNoteAction extends QuickAction {
public static final int TYPE = 9; public static final QuickActionType TYPE = new QuickActionType(9,
"video.note", TakeVideoNoteAction.class).
nameRes(R.string.quick_action_take_video_note).iconRes(R.drawable.ic_action_video_dark).nonEditable().
category(QuickActionType.CREATE_CATEGORY);
public TakeVideoNoteAction() { public TakeVideoNoteAction() {
super(TYPE); super(TYPE);

View file

@ -31,13 +31,9 @@ import net.osmand.plus.base.bottomsheetmenu.BaseBottomSheetItem;
import net.osmand.plus.base.bottomsheetmenu.simpleitems.TitleItem; import net.osmand.plus.base.bottomsheetmenu.simpleitems.TitleItem;
import net.osmand.plus.quickaction.CreateEditActionDialog; import net.osmand.plus.quickaction.CreateEditActionDialog;
import net.osmand.plus.quickaction.QuickAction; import net.osmand.plus.quickaction.QuickAction;
import net.osmand.plus.quickaction.QuickActionFactory;
import net.osmand.plus.quickaction.QuickActionRegistry; import net.osmand.plus.quickaction.QuickActionRegistry;
import net.osmand.plus.quickaction.SwitchableAction; import net.osmand.plus.quickaction.SwitchableAction;
import net.osmand.plus.quickaction.actions.MapOverlayAction;
import net.osmand.plus.quickaction.actions.MapSourceAction;
import net.osmand.plus.quickaction.actions.MapStyleAction; import net.osmand.plus.quickaction.actions.MapStyleAction;
import net.osmand.plus.quickaction.actions.MapUnderlayAction;
import net.osmand.plus.render.RendererRegistry; import net.osmand.plus.render.RendererRegistry;
import net.osmand.render.RenderingRulesStorage; import net.osmand.render.RenderingRulesStorage;
@ -71,7 +67,7 @@ public class SelectMapViewQuickActionsBottomSheet extends MenuBottomSheetDialogF
QuickActionRegistry quickActionRegistry = app.getQuickActionRegistry(); QuickActionRegistry quickActionRegistry = app.getQuickActionRegistry();
action = quickActionRegistry.getQuickAction(id); action = quickActionRegistry.getQuickAction(id);
action = QuickActionFactory.produceAction(action); action = QuickActionRegistry.produceAction(action);
if (action == null) { if (action == null) {
return; return;
} }
@ -79,22 +75,7 @@ public class SelectMapViewQuickActionsBottomSheet extends MenuBottomSheetDialogF
if (savedInstanceState != null) { if (savedInstanceState != null) {
selectedItem = savedInstanceState.getString(SELECTED_ITEM_KEY); selectedItem = savedInstanceState.getString(SELECTED_ITEM_KEY);
} else { } else {
if (action instanceof MapStyleAction) { selectedItem = ((SwitchableAction<?>) action).getSelectedItem(app);
RenderingRulesStorage current = app.getRendererRegistry().getCurrentSelectedRenderer();
if (current != null) {
selectedItem = current.getName();
} else {
selectedItem = RendererRegistry.DEFAULT_RENDER;
}
} else if (action instanceof MapSourceAction) {
selectedItem = settings.MAP_ONLINE_DATA.get()
? settings.MAP_TILE_SOURCES.get()
: MapSourceAction.LAYER_OSM_VECTOR;
} else if (action instanceof MapUnderlayAction) {
selectedItem = settings.MAP_UNDERLAY.get();
} else if (action instanceof MapOverlayAction) {
selectedItem = settings.MAP_OVERLAY.get();
}
} }
rbColorList = AndroidUtils.createCheckedColorStateList(app, R.color.icon_color_default_light, getActiveColorId()); rbColorList = AndroidUtils.createCheckedColorStateList(app, R.color.icon_color_default_light, getActiveColorId());

View file

@ -1,4 +1,4 @@
package net.osmand.plus.quickaction.actions; package net.osmand.plus.osmedit;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
@ -13,14 +13,19 @@ import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity; import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.osmedit.OsmEditingPlugin; import net.osmand.plus.osmedit.OsmEditingPlugin;
import net.osmand.plus.quickaction.QuickAction; import net.osmand.plus.quickaction.QuickAction;
import net.osmand.plus.quickaction.QuickActionType;
public class AddOSMBugAction extends QuickAction { public class AddOSMBugAction extends QuickAction {
public static final int TYPE = 12;
private static final String KEY_MESSAGE = "message"; private static final String KEY_MESSAGE = "message";
private static final String KEY_SHO_DIALOG = "dialog"; private static final String KEY_SHO_DIALOG = "dialog";
public static final QuickActionType TYPE = new QuickActionType(12,
"osmbug.add", AddOSMBugAction.class).
nameRes(R.string.quick_action_add_osm_bug).iconRes(R.drawable.ic_action_bug_dark).
category(QuickActionType.CREATE_CATEGORY);
public AddOSMBugAction() { public AddOSMBugAction() {
super(TYPE); super(TYPE);
} }

View file

@ -1,4 +1,4 @@
package net.osmand.plus.quickaction.actions; package net.osmand.plus.osmedit;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
@ -40,16 +40,10 @@ 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;
import net.osmand.plus.activities.MapActivity; import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.osmedit.EditPoiData;
import net.osmand.plus.osmedit.EditPoiDialogFragment;
import net.osmand.plus.osmedit.OpenstreetmapLocalUtil;
import net.osmand.plus.osmedit.OpenstreetmapPoint;
import net.osmand.plus.osmedit.OpenstreetmapUtil;
import net.osmand.plus.osmedit.OsmEditingPlugin;
import net.osmand.plus.osmedit.OsmPoint;
import net.osmand.plus.osmedit.dialogs.PoiSubTypeDialogFragment; import net.osmand.plus.osmedit.dialogs.PoiSubTypeDialogFragment;
import net.osmand.plus.quickaction.CreateEditActionDialog; import net.osmand.plus.quickaction.CreateEditActionDialog;
import net.osmand.plus.quickaction.QuickAction; import net.osmand.plus.quickaction.QuickAction;
import net.osmand.plus.quickaction.QuickActionType;
import net.osmand.plus.render.RenderingIcons; import net.osmand.plus.render.RenderingIcons;
import net.osmand.util.Algorithms; import net.osmand.util.Algorithms;
@ -66,7 +60,10 @@ import static net.osmand.plus.osmedit.AdvancedEditPoiFragment.addPoiToStringSet;
import static net.osmand.plus.osmedit.EditPoiData.POI_TYPE_TAG; import static net.osmand.plus.osmedit.EditPoiData.POI_TYPE_TAG;
public class AddPOIAction extends QuickAction { public class AddPOIAction extends QuickAction {
public static final int TYPE = 13; public static final QuickActionType TYPE = new QuickActionType(13,
"osmpoi.add", AddPOIAction.class).
nameRes(R.string.quick_action_add_poi).iconRes(R.drawable.ic_action_gabout_dark).
category(QuickActionType.CREATE_CATEGORY);
public static final String KEY_TAG = "key_tag"; public static final String KEY_TAG = "key_tag";
public static final String KEY_DIALOG = "dialog"; public static final String KEY_DIALOG = "dialog";

View file

@ -41,6 +41,7 @@ import net.osmand.plus.myplaces.AvailableGPXFragment;
import net.osmand.plus.myplaces.AvailableGPXFragment.GpxInfo; import net.osmand.plus.myplaces.AvailableGPXFragment.GpxInfo;
import net.osmand.plus.myplaces.FavoritesActivity; import net.osmand.plus.myplaces.FavoritesActivity;
import net.osmand.plus.osmedit.OsmPoint.Action; import net.osmand.plus.osmedit.OsmPoint.Action;
import net.osmand.plus.quickaction.QuickActionType;
import net.osmand.plus.settings.BaseSettingsFragment; import net.osmand.plus.settings.BaseSettingsFragment;
import net.osmand.plus.views.OsmandMapTileView; import net.osmand.plus.views.OsmandMapTileView;
import net.osmand.util.Algorithms; import net.osmand.util.Algorithms;
@ -137,6 +138,13 @@ public class OsmEditingPlugin extends OsmandPlugin {
private OsmEditsLayer osmEditsLayer; private OsmEditsLayer osmEditsLayer;
// private EditingPOIDialogProvider poiActions; // private EditingPOIDialogProvider poiActions;
@Override
protected void registerQuickActionTypes(List<QuickActionType> quickActionTypes) {
quickActionTypes.add(AddPOIAction.TYPE);
quickActionTypes.add(AddOSMBugAction.TYPE);
quickActionTypes.add(ShowHideOSMBugAction.TYPE);
}
@Override @Override
public void updateLayers(OsmandMapTileView mapView, MapActivity activity) { public void updateLayers(OsmandMapTileView mapView, MapActivity activity) {
if (isActive()) { if (isActive()) {

View file

@ -1,4 +1,4 @@
package net.osmand.plus.quickaction.actions; package net.osmand.plus.osmedit;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
@ -9,13 +9,16 @@ 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;
import net.osmand.plus.activities.MapActivity; import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.dialogs.ConfigureMapMenu;
import net.osmand.plus.osmedit.OsmEditingPlugin;
import net.osmand.plus.quickaction.QuickAction; import net.osmand.plus.quickaction.QuickAction;
import net.osmand.plus.quickaction.QuickActionType;
public class ShowHideOSMBugAction extends QuickAction { public class ShowHideOSMBugAction extends QuickAction {
public static final int TYPE = 24; public static final QuickActionType TYPE = new QuickActionType(24,
"osmbug.showhide", ShowHideOSMBugAction.class).
nameRes(R.string.quick_action_showhide_osmbugs_title).iconRes(R.drawable.ic_action_bug_dark).nonEditable().
category(QuickActionType.CONFIGURE_MAP);
public ShowHideOSMBugAction() { public ShowHideOSMBugAction() {
super(TYPE); super(TYPE);

View file

@ -10,10 +10,14 @@ import net.osmand.plus.OsmandPlugin;
import net.osmand.plus.R; import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity; import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.quickaction.QuickAction; import net.osmand.plus.quickaction.QuickAction;
import net.osmand.plus.quickaction.QuickActionType;
public class ParkingAction extends QuickAction { public class ParkingAction extends QuickAction {
public static final int TYPE = 7; public static final QuickActionType TYPE = new QuickActionType(7,
"parking.add", ParkingAction.class).
nameRes(R.string.quick_action_add_parking).iconRes(R.drawable.ic_action_parking_dark).nonEditable().
category(QuickActionType.CREATE_CATEGORY);
public ParkingAction() { public ParkingAction() {
super(TYPE); super(TYPE);

View file

@ -33,6 +33,7 @@ import net.osmand.plus.UiUtilities;
import net.osmand.plus.activities.MapActivity; import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.dashboard.tools.DashFragmentData; import net.osmand.plus.dashboard.tools.DashFragmentData;
import net.osmand.plus.mapcontextmenu.MapContextMenu; import net.osmand.plus.mapcontextmenu.MapContextMenu;
import net.osmand.plus.quickaction.QuickActionType;
import net.osmand.plus.views.AnimateDraggingMapThread; import net.osmand.plus.views.AnimateDraggingMapThread;
import net.osmand.plus.views.MapInfoLayer; import net.osmand.plus.views.MapInfoLayer;
import net.osmand.plus.views.OsmandMapLayer.DrawSettings; import net.osmand.plus.views.OsmandMapLayer.DrawSettings;
@ -40,6 +41,7 @@ import net.osmand.plus.views.OsmandMapTileView;
import net.osmand.plus.views.mapwidgets.TextInfoWidget; import net.osmand.plus.views.mapwidgets.TextInfoWidget;
import java.util.Calendar; import java.util.Calendar;
import java.util.List;
import static net.osmand.aidlapi.OsmAndCustomizationConstants.MAP_CONTEXT_MENU_MARK_AS_PARKING_LOC; import static net.osmand.aidlapi.OsmAndCustomizationConstants.MAP_CONTEXT_MENU_MARK_AS_PARKING_LOC;
@ -627,4 +629,10 @@ public class ParkingPositionPlugin extends OsmandPlugin {
public DashFragmentData getCardFragment() { public DashFragmentData getCardFragment() {
return DashParkingFragment.FRAGMENT_DATA; return DashParkingFragment.FRAGMENT_DATA;
} }
@Override
protected void registerQuickActionTypes(List<QuickActionType> quickActionTypes) {
quickActionTypes.add(ParkingAction.TYPE);
}
} }

View file

@ -48,14 +48,12 @@ public class AddQuickActionDialog extends DialogFragment {
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
getDialog().getWindow().requestFeature(Window.FEATURE_NO_TITLE); getDialog().getWindow().requestFeature(Window.FEATURE_NO_TITLE);
QuickActionRegistry quickActionRegistry = ((MapActivity) getActivity())
List<QuickAction> active = ((MapActivity) getActivity()) .getMyApplication()
.getMyApplication() .getQuickActionRegistry();
.getQuickActionRegistry()
.getQuickActions();
View root = UiUtilities.getInflater(getActivity(), !isLightContent).inflate(R.layout.quick_action_add_dialog, container, false); View root = UiUtilities.getInflater(getActivity(), !isLightContent).inflate(R.layout.quick_action_add_dialog, container, false);
Adapter adapter = new Adapter(QuickActionFactory.produceTypeActionsListWithHeaders(active)); Adapter adapter = new Adapter(quickActionRegistry.produceTypeActionsListWithHeaders());
TextView tvTitle = root.findViewById(R.id.tvTitle); TextView tvTitle = root.findViewById(R.id.tvTitle);
RecyclerView recyclerView = (RecyclerView) root.findViewById(R.id.recycler_view); RecyclerView recyclerView = (RecyclerView) root.findViewById(R.id.recycler_view);
@ -86,7 +84,7 @@ public class AddQuickActionDialog extends DialogFragment {
private static final int HEADER = 1; private static final int HEADER = 1;
private static final int ITEM = 2; private static final int ITEM = 2;
private List<QuickAction> data; private List<QuickActionType> data;
public class ItemViewHolder extends RecyclerView.ViewHolder { public class ItemViewHolder extends RecyclerView.ViewHolder {
@ -114,7 +112,7 @@ public class AddQuickActionDialog extends DialogFragment {
} }
} }
public Adapter(List<QuickAction> data) { public Adapter(List<QuickActionType> data) {
this.data = data; this.data = data;
} }
@ -138,7 +136,7 @@ public class AddQuickActionDialog extends DialogFragment {
@Override @Override
public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) { public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
final QuickAction action = data.get(position); final QuickActionType action = data.get(position);
if (getItemViewType(position) == HEADER) { if (getItemViewType(position) == HEADER) {
@ -161,7 +159,7 @@ public class AddQuickActionDialog extends DialogFragment {
@Override @Override
public void onClick(View view) { public void onClick(View view) {
CreateEditActionDialog dialog = CreateEditActionDialog.newInstance(action.type); CreateEditActionDialog dialog = CreateEditActionDialog.newInstance(action.getId());
dialog.show(getFragmentManager(), CreateEditActionDialog.TAG); dialog.show(getFragmentManager(), CreateEditActionDialog.TAG);
dismiss(); dismiss();
@ -179,7 +177,7 @@ public class AddQuickActionDialog extends DialogFragment {
@Override @Override
public int getItemViewType(int position) { public int getItemViewType(int position) {
if (data.get(position).type == 0) if (data.get(position).getId() == 0)
return HEADER; return HEADER;
return ITEM; return ITEM;

View file

@ -123,8 +123,8 @@ public class CreateEditActionDialog extends DialogFragment {
? isNew = actionId == 0 ? isNew = actionId == 0
: savedInstanceState.getBoolean(KEY_ACTION_IS_NEW); : savedInstanceState.getBoolean(KEY_ACTION_IS_NEW);
action = QuickActionFactory.produceAction(isNew action = QuickActionRegistry.produceAction(isNew
? QuickActionFactory.newActionByType(type) ? quickActionRegistry.newActionByType(type)
: quickActionRegistry.getQuickAction(actionId)); : quickActionRegistry.getQuickAction(actionId));
setupToolbar(view); setupToolbar(view);
@ -139,7 +139,7 @@ public class CreateEditActionDialog extends DialogFragment {
super.onSaveInstanceState(outState); super.onSaveInstanceState(outState);
outState.putLong(KEY_ACTION_ID, action.getId()); outState.putLong(KEY_ACTION_ID, action.getId());
outState.putInt(KEY_ACTION_TYPE, action.type); outState.putInt(KEY_ACTION_TYPE, action.getType());
outState.putBoolean(KEY_ACTION_IS_NEW, isNew); outState.putBoolean(KEY_ACTION_IS_NEW, isNew);
} }

View file

@ -2,19 +2,28 @@ package net.osmand.plus.quickaction;
import android.content.Context; import android.content.Context;
import androidx.annotation.NonNull;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.EditText; import android.widget.EditText;
import com.google.gson.JsonObject;
import com.google.gson.TypeAdapter;
import com.google.gson.stream.JsonReader;
import com.google.gson.stream.JsonWriter;
import androidx.annotation.DrawableRes; import androidx.annotation.DrawableRes;
import androidx.annotation.StringRes; import androidx.annotation.StringRes;
import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandApplication;
import net.osmand.plus.activities.MapActivity; import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.quickaction.actions.NewAction;
import net.osmand.util.Algorithms; import net.osmand.util.Algorithms;
import java.io.IOException;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map;
public class QuickAction { public class QuickAction {
@ -22,68 +31,55 @@ public class QuickAction {
void onActionSelected(QuickAction action); void onActionSelected(QuickAction action);
} }
private static int SEQ = 0;
protected int type;
protected long id; protected long id;
private @StringRes Integer nameRes;
private @DrawableRes int iconRes;
private boolean isActionEditable;
private String name; private String name;
private HashMap<String, String> params; private Map<String, String> params;
private QuickActionType actionType;
protected QuickAction() { protected QuickAction() {
this.id = System.currentTimeMillis(); this(QuickActionRegistry.TYPE_ADD_ITEMS);
} }
protected QuickAction(int type, @StringRes int nameRes) { public QuickAction(QuickActionType type) {
this.id = System.currentTimeMillis(); this.id = System.currentTimeMillis() + (SEQ++);
this.nameRes = nameRes; this.actionType = type;
this.type = type;
}
public QuickAction(int type) {
this.id = System.currentTimeMillis();
this.type = type;
this.nameRes = QuickActionFactory.getActionName(type);
this.iconRes = QuickActionFactory.getActionIcon(type);
this.isActionEditable = QuickActionFactory.isActionEditable(type);
} }
public QuickAction(QuickAction quickAction) { public QuickAction(QuickAction quickAction) {
this.type = quickAction.type; this.actionType = quickAction.actionType;
this.id = quickAction.id; this.id = quickAction.id;
this.name = quickAction.name; this.name = quickAction.name;
this.params = quickAction.params; this.params = quickAction.params;
this.nameRes = QuickActionFactory.getActionName(type);
this.iconRes = QuickActionFactory.getActionIcon(type);
this.isActionEditable = QuickActionFactory.isActionEditable(type);
} }
public int getNameRes() { public int getNameRes() {
return nameRes; return actionType == null ? 0 : actionType.getNameRes();
} }
public int getIconRes() { public int getIconRes() {
return iconRes; return actionType == null ? 0 : actionType.getIconRes();
} }
public int getIconRes(Context context) { public int getIconRes(Context context) {
return iconRes; return actionType == null ? 0 : actionType.getIconRes();
} }
public long getId() { public long getId() {
return id; return id;
} }
public long getType() { public int getType() {
return type; return actionType.getId();
}
public void setActionType(QuickActionType actionType) {
this.actionType = actionType;
} }
public boolean isActionEditable() { public boolean isActionEditable() {
return isActionEditable; return actionType == null ? false : actionType.isActionEditable();
} }
public boolean isActionEnable(OsmandApplication app) { public boolean isActionEnable(OsmandApplication app) {
@ -92,16 +88,25 @@ public class QuickAction {
public String getName(Context context) { public String getName(Context context) {
if (Algorithms.isEmpty(name)) { if (Algorithms.isEmpty(name)) {
return nameRes != null ? context.getString(nameRes) : ""; return getDefaultName(context);
} else { } else {
return name; return name;
} }
} }
public HashMap<String, String> getParams() { public String getRawName() {
return name;
}
if (params == null) params = new HashMap<>(); @NonNull
private String getDefaultName(Context context) {
return getNameRes() != 0 ? context.getString(getNameRes()) : "";
}
public Map<String, String> getParams() {
if (params == null) {
params = new HashMap<>();
}
return params; return params;
} }
@ -109,7 +114,11 @@ public class QuickAction {
this.name = name; this.name = name;
} }
public void setParams(HashMap<String, String> params) { public void setId(long id) {
this.id = id;
}
public void setParams(Map<String, String> params) {
this.params = params; this.params = params;
} }
@ -121,7 +130,11 @@ public class QuickAction {
return getName(application); return getName(application);
} }
public void setAutoGeneratedTitle(EditText title){ public QuickActionType getActionType() {
return actionType;
}
public void setAutoGeneratedTitle(EditText title){
} }
public void execute(MapActivity activity){}; public void execute(MapActivity activity){};
@ -130,9 +143,9 @@ public class QuickAction {
public boolean hasInstanceInList(List<QuickAction> active){ public boolean hasInstanceInList(List<QuickAction> active){
for (QuickAction action: active){ for (QuickAction action : active) {
if (action.type == type) return true; if (action.getType() == getType()) return true;
} }
return false; return false;
} }
@ -146,7 +159,7 @@ public class QuickAction {
QuickAction action = (QuickAction) o; QuickAction action = (QuickAction) o;
if (type != action.type) return false; if (getType() != action.getType()) return false;
if (id != action.id) return false; if (id != action.id) return false;
return true; return true;
@ -156,15 +169,12 @@ public class QuickAction {
@Override @Override
public int hashCode() { public int hashCode() {
int result = type; int result = getType();
result = 31 * result + (int) (id ^ (id >>> 32)); result = 31 * result + (int) (id ^ (id >>> 32));
result = 31 * result + nameRes;
result = 31 * result + iconRes;
result = 31 * result + (name != null ? name.hashCode() : 0);
return result; return result;
} }
public boolean hasCustomName(Context context) { public boolean hasCustomName(Context context) {
return !getName(context).equals(context.getString(nameRes)); return !getName(context).equals(getDefaultName(context));
} }
} }

View file

@ -1,595 +0,0 @@
package net.osmand.plus.quickaction;
import androidx.annotation.DrawableRes;
import androidx.annotation.StringRes;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import net.osmand.plus.OsmandPlugin;
import net.osmand.plus.R;
import net.osmand.plus.audionotes.AudioVideoNotesPlugin;
import net.osmand.plus.audionotes.TakeAudioNoteAction;
import net.osmand.plus.audionotes.TakePhotoNoteAction;
import net.osmand.plus.audionotes.TakeVideoNoteAction;
import net.osmand.plus.osmedit.OsmEditingPlugin;
import net.osmand.plus.parkingpoint.ParkingAction;
import net.osmand.plus.parkingpoint.ParkingPositionPlugin;
import net.osmand.plus.quickaction.actions.AddOSMBugAction;
import net.osmand.plus.quickaction.actions.AddPOIAction;
import net.osmand.plus.quickaction.actions.ContourLinesAction;
import net.osmand.plus.quickaction.actions.DayNightModeAction;
import net.osmand.plus.quickaction.actions.FavoriteAction;
import net.osmand.plus.quickaction.actions.GPXAction;
import net.osmand.plus.quickaction.actions.HillshadeAction;
import net.osmand.plus.quickaction.actions.MapOverlayAction;
import net.osmand.plus.quickaction.actions.MapSourceAction;
import net.osmand.plus.quickaction.actions.MapStyleAction;
import net.osmand.plus.quickaction.actions.MapUnderlayAction;
import net.osmand.plus.quickaction.actions.MarkerAction;
import net.osmand.plus.quickaction.actions.NavAddDestinationAction;
import net.osmand.plus.quickaction.actions.NavAddFirstIntermediateAction;
import net.osmand.plus.quickaction.actions.NavAutoZoomMapAction;
import net.osmand.plus.quickaction.actions.NavDirectionsFromAction;
import net.osmand.plus.quickaction.actions.NavReplaceDestinationAction;
import net.osmand.plus.quickaction.actions.NavResumePauseAction;
import net.osmand.plus.quickaction.actions.NavStartStopAction;
import net.osmand.plus.quickaction.actions.NavVoiceAction;
import net.osmand.plus.quickaction.actions.NewAction;
import net.osmand.plus.quickaction.actions.ShowHideFavoritesAction;
import net.osmand.plus.quickaction.actions.ShowHideGpxTracksAction;
import net.osmand.plus.quickaction.actions.ShowHideOSMBugAction;
import net.osmand.plus.quickaction.actions.ShowHidePoiAction;
import net.osmand.plus.rastermaps.OsmandRasterMapsPlugin;
import net.osmand.plus.srtmplugin.SRTMPlugin;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.List;
public class QuickActionFactory {
public String quickActionListToString(List<QuickAction> quickActions) {
return new Gson().toJson(quickActions);
}
public List<QuickAction> parseActiveActionsList(String json) {
Type type = new TypeToken<List<QuickAction>>() {
}.getType();
ArrayList<QuickAction> quickActions = new Gson().fromJson(json, type);
return quickActions != null ? quickActions : new ArrayList<QuickAction>();
}
public static List<QuickAction> produceTypeActionsListWithHeaders(List<QuickAction> active) {
ArrayList<QuickAction> quickActions = new ArrayList<>();
quickActions.add(new QuickAction(0, R.string.quick_action_add_create_items));
quickActions.add(new FavoriteAction());
quickActions.add(new GPXAction());
QuickAction marker = new MarkerAction();
if (!marker.hasInstanceInList(active)) {
quickActions.add(marker);
}
if (OsmandPlugin.getEnabledPlugin(AudioVideoNotesPlugin.class) != null) {
QuickAction audio = new TakeAudioNoteAction();
QuickAction photo = new TakePhotoNoteAction();
QuickAction video = new TakeVideoNoteAction();
if (!audio.hasInstanceInList(active)) {
quickActions.add(audio);
}
if (!photo.hasInstanceInList(active)) {
quickActions.add(photo);
}
if (!video.hasInstanceInList(active)) {
quickActions.add(video);
}
}
if (OsmandPlugin.getEnabledPlugin(OsmEditingPlugin.class) != null) {
quickActions.add(new AddPOIAction());
quickActions.add(new AddOSMBugAction());
}
if (OsmandPlugin.getEnabledPlugin(ParkingPositionPlugin.class) != null) {
QuickAction parking = new ParkingAction();
if (!parking.hasInstanceInList(active)) {
quickActions.add(parking);
}
}
quickActions.add(new QuickAction(0, R.string.quick_action_add_configure_map));
QuickAction favorites = new ShowHideFavoritesAction();
if (!favorites.hasInstanceInList(active)) {
quickActions.add(favorites);
}
quickActions.add(new ShowHideGpxTracksAction());
quickActions.add(new ShowHidePoiAction());
if (OsmandPlugin.getEnabledPlugin(OsmEditingPlugin.class) != null) {
QuickAction showHideOSMBugAction = new ShowHideOSMBugAction();
if (!showHideOSMBugAction.hasInstanceInList(active)) {
quickActions.add(showHideOSMBugAction);
}
}
quickActions.add(new MapStyleAction());
if (OsmandPlugin.getEnabledPlugin(OsmandRasterMapsPlugin.class) != null) {
quickActions.add(new MapSourceAction());
quickActions.add(new MapOverlayAction());
quickActions.add(new MapUnderlayAction());
}
if (OsmandPlugin.getEnabledPlugin(SRTMPlugin.class) != null) {
quickActions.add(new ContourLinesAction());
quickActions.add(new HillshadeAction());
}
quickActions.add(new DayNightModeAction());
QuickAction voice = new NavVoiceAction();
QuickAction directionFrom = new NavDirectionsFromAction();
QuickAction addDestination = new NavAddDestinationAction();
QuickAction addFirstIntermediate = new NavAddFirstIntermediateAction();
QuickAction replaceDestination = new NavReplaceDestinationAction();
QuickAction autoZoomMap = new NavAutoZoomMapAction();
QuickAction startStopNavigation = new NavStartStopAction();
QuickAction resumePauseNavigation = new NavResumePauseAction();
ArrayList<QuickAction> navigationQuickActions = new ArrayList<>();
if (!voice.hasInstanceInList(active)) {
navigationQuickActions.add(voice);
}
if (!directionFrom.hasInstanceInList(active)) {
navigationQuickActions.add(directionFrom);
}
if (!addDestination.hasInstanceInList(active)) {
navigationQuickActions.add(addDestination);
}
if (!addFirstIntermediate.hasInstanceInList(active)) {
navigationQuickActions.add(addFirstIntermediate);
}
if (!replaceDestination.hasInstanceInList(active)) {
navigationQuickActions.add(replaceDestination);
}
if (!autoZoomMap.hasInstanceInList(active)) {
navigationQuickActions.add(autoZoomMap);
}
if (!startStopNavigation.hasInstanceInList(active)) {
navigationQuickActions.add(startStopNavigation);
}
if (!resumePauseNavigation.hasInstanceInList(active)) {
navigationQuickActions.add(resumePauseNavigation);
}
if (navigationQuickActions.size() > 0) {
quickActions.add(new QuickAction(0, R.string.quick_action_add_navigation));
quickActions.addAll(navigationQuickActions);
}
return quickActions;
}
public static QuickAction newActionByType(int type) {
switch (type) {
case NewAction.TYPE:
return new NewAction();
case MarkerAction.TYPE:
return new MarkerAction();
case FavoriteAction.TYPE:
return new FavoriteAction();
case ShowHideFavoritesAction.TYPE:
return new ShowHideFavoritesAction();
case ShowHidePoiAction.TYPE:
return new ShowHidePoiAction();
case GPXAction.TYPE:
return new GPXAction();
case ParkingAction.TYPE:
return new ParkingAction();
case TakeAudioNoteAction.TYPE:
return new TakeAudioNoteAction();
case TakePhotoNoteAction.TYPE:
return new TakePhotoNoteAction();
case TakeVideoNoteAction.TYPE:
return new TakeVideoNoteAction();
case NavVoiceAction.TYPE:
return new NavVoiceAction();
case ShowHideOSMBugAction.TYPE:
return new ShowHideOSMBugAction();
case AddOSMBugAction.TYPE:
return new AddOSMBugAction();
case AddPOIAction.TYPE:
return new AddPOIAction();
case MapStyleAction.TYPE:
return new MapStyleAction();
case MapSourceAction.TYPE:
return new MapSourceAction();
case MapOverlayAction.TYPE:
return new MapOverlayAction();
case MapUnderlayAction.TYPE:
return new MapUnderlayAction();
case NavDirectionsFromAction.TYPE:
return new NavDirectionsFromAction();
case NavAddDestinationAction.TYPE:
return new NavAddDestinationAction();
case NavAddFirstIntermediateAction.TYPE:
return new NavAddFirstIntermediateAction();
case NavReplaceDestinationAction.TYPE:
return new NavReplaceDestinationAction();
case NavAutoZoomMapAction.TYPE:
return new NavAutoZoomMapAction();
case NavStartStopAction.TYPE:
return new NavStartStopAction();
case NavResumePauseAction.TYPE:
return new NavResumePauseAction();
case DayNightModeAction.TYPE:
return new DayNightModeAction();
case ShowHideGpxTracksAction.TYPE:
return new ShowHideGpxTracksAction();
case ContourLinesAction.TYPE:
return new ContourLinesAction();
case HillshadeAction.TYPE:
return new HillshadeAction();
default:
return new QuickAction();
}
}
public static QuickAction produceAction(QuickAction quickAction) {
switch (quickAction.type) {
case NewAction.TYPE:
return new NewAction(quickAction);
case MarkerAction.TYPE:
return new MarkerAction(quickAction);
case FavoriteAction.TYPE:
return new FavoriteAction(quickAction);
case ShowHideFavoritesAction.TYPE:
return new ShowHideFavoritesAction(quickAction);
case ShowHidePoiAction.TYPE:
return new ShowHidePoiAction(quickAction);
case GPXAction.TYPE:
return new GPXAction(quickAction);
case ParkingAction.TYPE:
return new ParkingAction(quickAction);
case TakeAudioNoteAction.TYPE:
return new TakeAudioNoteAction(quickAction);
case TakePhotoNoteAction.TYPE:
return new TakePhotoNoteAction(quickAction);
case TakeVideoNoteAction.TYPE:
return new TakeVideoNoteAction(quickAction);
case NavVoiceAction.TYPE:
return new NavVoiceAction(quickAction);
case ShowHideOSMBugAction.TYPE:
return new ShowHideOSMBugAction(quickAction);
case AddOSMBugAction.TYPE:
return new AddOSMBugAction(quickAction);
case AddPOIAction.TYPE:
return new AddPOIAction(quickAction);
case MapStyleAction.TYPE:
return new MapStyleAction(quickAction);
case MapSourceAction.TYPE:
return new MapSourceAction(quickAction);
case MapOverlayAction.TYPE:
return new MapOverlayAction(quickAction);
case MapUnderlayAction.TYPE:
return new MapUnderlayAction(quickAction);
case NavDirectionsFromAction.TYPE:
return new NavDirectionsFromAction(quickAction);
case NavAddDestinationAction.TYPE:
return new NavAddDestinationAction(quickAction);
case NavAddFirstIntermediateAction.TYPE:
return new NavAddFirstIntermediateAction(quickAction);
case NavReplaceDestinationAction.TYPE:
return new NavReplaceDestinationAction(quickAction);
case NavAutoZoomMapAction.TYPE:
return new NavAutoZoomMapAction(quickAction);
case NavStartStopAction.TYPE:
return new NavStartStopAction(quickAction);
case NavResumePauseAction.TYPE:
return new NavResumePauseAction(quickAction);
case DayNightModeAction.TYPE:
return new DayNightModeAction(quickAction);
case ShowHideGpxTracksAction.TYPE:
return new ShowHideGpxTracksAction(quickAction);
case ContourLinesAction.TYPE:
return new ContourLinesAction(quickAction);
case HillshadeAction.TYPE:
return new HillshadeAction(quickAction);
default:
return quickAction;
}
}
public static @DrawableRes int getActionIcon(int type) {
switch (type) {
case NewAction.TYPE:
return R.drawable.ic_action_plus;
case MarkerAction.TYPE:
return R.drawable.ic_action_flag_dark;
case FavoriteAction.TYPE:
return R.drawable.ic_action_fav_dark;
case ShowHideFavoritesAction.TYPE:
return R.drawable.ic_action_fav_dark;
case ShowHidePoiAction.TYPE:
return R.drawable.ic_action_gabout_dark;
case GPXAction.TYPE:
return R.drawable.ic_action_flag_dark;
case ParkingAction.TYPE:
return R.drawable.ic_action_parking_dark;
case TakeAudioNoteAction.TYPE:
return R.drawable.ic_action_micro_dark;
case TakePhotoNoteAction.TYPE:
return R.drawable.ic_action_photo_dark;
case TakeVideoNoteAction.TYPE:
return R.drawable.ic_action_video_dark;
case NavVoiceAction.TYPE:
return R.drawable.ic_action_volume_up;
case ShowHideOSMBugAction.TYPE:
return R.drawable.ic_action_bug_dark;
case AddOSMBugAction.TYPE:
return R.drawable.ic_action_bug_dark;
case AddPOIAction.TYPE:
return R.drawable.ic_action_gabout_dark;
case MapStyleAction.TYPE:
return R.drawable.ic_map;
case MapSourceAction.TYPE:
return R.drawable.ic_world_globe_dark;
case MapOverlayAction.TYPE:
return R.drawable.ic_layer_top;
case MapUnderlayAction.TYPE:
return R.drawable.ic_layer_bottom;
case NavDirectionsFromAction.TYPE:
return R.drawable.ic_action_route_direction_from_here;
case NavAddDestinationAction.TYPE:
return R.drawable.ic_action_point_add_destination;
case NavAddFirstIntermediateAction.TYPE:
return R.drawable.ic_action_intermediate;
case NavReplaceDestinationAction.TYPE:
return R.drawable.ic_action_point_add_destination;
case NavAutoZoomMapAction.TYPE:
return R.drawable.ic_action_search_dark;
case NavStartStopAction.TYPE:
return R.drawable.ic_action_start_navigation;
case NavResumePauseAction.TYPE:
return R.drawable.ic_play_dark;
case DayNightModeAction.TYPE:
return R.drawable.ic_action_map_day;
case ShowHideGpxTracksAction.TYPE:
return R.drawable.ic_gpx_track;
case ContourLinesAction.TYPE:
return R.drawable.ic_plugin_srtm;
case HillshadeAction.TYPE:
return R.drawable.ic_action_hillshade_dark;
default:
return R.drawable.ic_action_plus;
}
}
public static @StringRes int getActionName(int type) {
switch (type) {
case NewAction.TYPE:
return R.string.quick_action_new_action;
case MarkerAction.TYPE:
return R.string.quick_action_add_marker;
case FavoriteAction.TYPE:
return R.string.quick_action_add_favorite;
case ShowHideFavoritesAction.TYPE:
return R.string.quick_action_showhide_favorites_title;
case ShowHidePoiAction.TYPE:
return R.string.quick_action_showhide_poi_title;
case GPXAction.TYPE:
return R.string.quick_action_add_gpx;
case ParkingAction.TYPE:
return R.string.quick_action_add_parking;
case TakeAudioNoteAction.TYPE:
return R.string.quick_action_take_audio_note;
case TakePhotoNoteAction.TYPE:
return R.string.quick_action_take_photo_note;
case TakeVideoNoteAction.TYPE:
return R.string.quick_action_take_video_note;
case NavVoiceAction.TYPE:
return R.string.quick_action_navigation_voice;
case ShowHideOSMBugAction.TYPE:
return R.string.quick_action_showhide_osmbugs_title;
case AddOSMBugAction.TYPE:
return R.string.quick_action_add_osm_bug;
case AddPOIAction.TYPE:
return R.string.quick_action_add_poi;
case MapStyleAction.TYPE:
return R.string.quick_action_map_style;
case MapSourceAction.TYPE:
return R.string.quick_action_map_source;
case MapOverlayAction.TYPE:
return R.string.quick_action_map_overlay;
case MapUnderlayAction.TYPE:
return R.string.quick_action_map_underlay;
case DayNightModeAction.TYPE:
return R.string.quick_action_day_night_switch_mode;
case NavDirectionsFromAction.TYPE:
return R.string.context_menu_item_directions_from;
case NavAddDestinationAction.TYPE:
return R.string.quick_action_add_destination;
case NavAddFirstIntermediateAction.TYPE:
return R.string.quick_action_add_first_intermediate;
case NavReplaceDestinationAction.TYPE:
return R.string.quick_action_replace_destination;
case NavAutoZoomMapAction.TYPE:
return R.string.quick_action_auto_zoom;
case NavStartStopAction.TYPE:
return R.string.quick_action_start_stop_navigation;
case NavResumePauseAction.TYPE:
return R.string.quick_action_resume_pause_navigation;
case ShowHideGpxTracksAction.TYPE:
return R.string.quick_action_show_hide_gpx_tracks;
case ContourLinesAction.TYPE:
return R.string.quick_action_show_hide_contour_lines;
case HillshadeAction.TYPE:
return R.string.quick_action_show_hide_hillshade;
default:
return R.string.quick_action_new_action;
}
}
public static boolean isActionEditable(int type) {
switch (type) {
case NewAction.TYPE:
case MarkerAction.TYPE:
case ShowHideFavoritesAction.TYPE:
case ShowHidePoiAction.TYPE:
case ParkingAction.TYPE:
case TakeAudioNoteAction.TYPE:
case TakePhotoNoteAction.TYPE:
case TakeVideoNoteAction.TYPE:
case NavVoiceAction.TYPE:
case NavDirectionsFromAction.TYPE:
case NavAddDestinationAction.TYPE:
case NavAddFirstIntermediateAction.TYPE:
case NavReplaceDestinationAction.TYPE:
case NavAutoZoomMapAction.TYPE:
case ShowHideOSMBugAction.TYPE:
case NavStartStopAction.TYPE:
case NavResumePauseAction.TYPE:
case DayNightModeAction.TYPE:
case ShowHideGpxTracksAction.TYPE:
case ContourLinesAction.TYPE:
case HillshadeAction.TYPE:
return false;
default:
return true;
}
}
}

View file

@ -220,7 +220,7 @@ public class QuickActionListFragment extends BaseOsmAndFragment implements Quick
@Override @Override
public void onBindViewHolder(final RecyclerView.ViewHolder holder, int position) { public void onBindViewHolder(final RecyclerView.ViewHolder holder, int position) {
int viewType = getItemViewType(position); int viewType = getItemViewType(position);
final QuickAction item = QuickActionFactory.produceAction(itemsList.get(position)); final QuickAction item = QuickActionRegistry.produceAction(itemsList.get(position));
if (viewType == SCREEN_ITEM_TYPE) { if (viewType == SCREEN_ITEM_TYPE) {
final QuickActionItemVH itemVH = (QuickActionItemVH) holder; final QuickActionItemVH itemVH = (QuickActionItemVH) holder;
@ -271,7 +271,7 @@ public class QuickActionListFragment extends BaseOsmAndFragment implements Quick
@Override @Override
public int getItemViewType(int position) { public int getItemViewType(int position) {
return itemsList.get(position).type == 0 ? SCREEN_HEADER_TYPE : SCREEN_ITEM_TYPE; return itemsList.get(position).getType() == 0 ? SCREEN_HEADER_TYPE : SCREEN_ITEM_TYPE;
} }
public void deleteItem(int position) { public void deleteItem(int position) {

View file

@ -3,32 +3,46 @@ package net.osmand.plus.quickaction;
import android.content.Context; import android.content.Context;
import com.google.gson.Gson; import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonDeserializationContext;
import com.google.gson.JsonDeserializer;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParseException;
import com.google.gson.JsonSerializationContext;
import com.google.gson.JsonSerializer;
import com.google.gson.reflect.TypeToken; import com.google.gson.reflect.TypeToken;
import net.osmand.plus.OsmandPlugin; import net.osmand.plus.OsmandPlugin;
import net.osmand.plus.OsmandSettings; import net.osmand.plus.OsmandSettings;
import net.osmand.plus.audionotes.AudioVideoNotesPlugin; import net.osmand.plus.R;
import net.osmand.plus.audionotes.TakeAudioNoteAction; import net.osmand.plus.quickaction.actions.DayNightModeAction;
import net.osmand.plus.audionotes.TakePhotoNoteAction; import net.osmand.plus.quickaction.actions.FavoriteAction;
import net.osmand.plus.audionotes.TakeVideoNoteAction; import net.osmand.plus.quickaction.actions.GPXAction;
import net.osmand.plus.openseamapsplugin.NauticalMapsPlugin;
import net.osmand.plus.osmedit.OsmEditingPlugin;
import net.osmand.plus.parkingpoint.ParkingAction;
import net.osmand.plus.parkingpoint.ParkingPositionPlugin;
import net.osmand.plus.quickaction.actions.AddOSMBugAction;
import net.osmand.plus.quickaction.actions.AddPOIAction;
import net.osmand.plus.quickaction.actions.ContourLinesAction;
import net.osmand.plus.quickaction.actions.HillshadeAction;
import net.osmand.plus.quickaction.actions.MapSourceAction;
import net.osmand.plus.quickaction.actions.MapStyleAction; import net.osmand.plus.quickaction.actions.MapStyleAction;
import net.osmand.plus.rastermaps.OsmandRasterMapsPlugin; import net.osmand.plus.quickaction.actions.MarkerAction;
import net.osmand.plus.srtmplugin.SRTMPlugin; import net.osmand.plus.quickaction.actions.NavAddDestinationAction;
import net.osmand.plus.quickaction.actions.NavAddFirstIntermediateAction;
import net.osmand.plus.quickaction.actions.NavAutoZoomMapAction;
import net.osmand.plus.quickaction.actions.NavDirectionsFromAction;
import net.osmand.plus.quickaction.actions.NavReplaceDestinationAction;
import net.osmand.plus.quickaction.actions.NavResumePauseAction;
import net.osmand.plus.quickaction.actions.NavStartStopAction;
import net.osmand.plus.quickaction.actions.NavVoiceAction;
import net.osmand.plus.quickaction.actions.NewAction;
import net.osmand.plus.quickaction.actions.ShowHideFavoritesAction;
import net.osmand.plus.quickaction.actions.ShowHideGpxTracksAction;
import net.osmand.plus.quickaction.actions.ShowHidePoiAction;
import net.osmand.util.Algorithms;
import java.lang.reflect.Type; import java.lang.reflect.Type;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set;
import java.util.TreeMap;
import java.util.TreeSet;
/** /**
* Created by rosty on 12/27/16. * Created by rosty on 12/27/16.
@ -36,188 +50,277 @@ import java.util.Map;
public class QuickActionRegistry { public class QuickActionRegistry {
public interface QuickActionUpdatesListener{ public interface QuickActionUpdatesListener {
void onActionsUpdated(); void onActionsUpdated();
}
private final QuickActionFactory factory;
private final OsmandSettings settings;
private final List<QuickAction> quickActions;
private final Map<String, Boolean> fabStateMap;
private QuickActionUpdatesListener updatesListener;
public QuickActionRegistry(OsmandSettings settings) {
this.factory = new QuickActionFactory();
this.settings = settings;
quickActions = factory.parseActiveActionsList(settings.QUICK_ACTION_LIST.get());
fabStateMap = getQuickActionFabStateMapFromJson(settings.QUICK_ACTION.get());
}
public void setUpdatesListener(QuickActionUpdatesListener updatesListener) {
this.updatesListener = updatesListener;
}
public void notifyUpdates() {
if (updatesListener != null) updatesListener.onActionsUpdated();
}
public List<QuickAction> getQuickActions() {
List<QuickAction> actions = new ArrayList<>();
actions.addAll(quickActions);
return actions;
}
public List<QuickAction> getFilteredQuickActions() {
List<QuickAction> actions = getQuickActions();
List<QuickAction> filteredActions = new ArrayList<>();
for (QuickAction action : actions) {
boolean skip = false;
if (OsmandPlugin.getEnabledPlugin(AudioVideoNotesPlugin.class) == null) {
if (action.type == TakeAudioNoteAction.TYPE || action.type == TakePhotoNoteAction.TYPE
|| action.type == TakeVideoNoteAction.TYPE) {
skip = true;
}
}
if (OsmandPlugin.getEnabledPlugin(ParkingPositionPlugin.class) == null) {
if (action.type == ParkingAction.TYPE) {
skip = true;
}
}
if (OsmandPlugin.getEnabledPlugin(NauticalMapsPlugin.class) == null) {
if (action.type == MapStyleAction.TYPE) {
if (((MapStyleAction) QuickActionFactory.produceAction(action)).getFilteredStyles().isEmpty()) {
skip = true;
}
}
}
if (OsmandPlugin.getEnabledPlugin(OsmandRasterMapsPlugin.class) == null) {
if (action.type == MapSourceAction.TYPE) {
skip = true;
}
}
if (OsmandPlugin.getEnabledPlugin(OsmEditingPlugin.class) == null) {
if (action.type == AddPOIAction.TYPE) {
skip = true;
}
if (action.type == AddOSMBugAction.TYPE) {
skip = true;
}
}
if (OsmandPlugin.getEnabledPlugin(SRTMPlugin.class) == null) {
if (action.type == ContourLinesAction.TYPE) {
skip = true;
}
if (action.type == HillshadeAction.TYPE) {
skip = true;
}
}
if (!skip) {
filteredActions.add(action);
}
}
return filteredActions;
} }
public void addQuickAction(QuickAction action){ public static final QuickActionType TYPE_ADD_ITEMS = new QuickActionType(0, "").
quickActions.add(action); nameRes(R.string.quick_action_add_create_items).category(QuickActionType.CREATE_CATEGORY);
settings.QUICK_ACTION_LIST.set(factory.quickActionListToString(quickActions)); public static final QuickActionType TYPE_CONFIGURE_MAP = new QuickActionType(0, "").
} nameRes(R.string.quick_action_add_configure_map).category(QuickActionType.CONFIGURE_MAP);
public static final QuickActionType TYPE_NAVIGATION = new QuickActionType(0, "").
nameRes(R.string.quick_action_add_navigation).category(QuickActionType.NAVIGATION);
public void deleteQuickAction(QuickAction action){
int index = quickActions.indexOf(action);
if (index >= 0) {
quickActions.remove(index);
}
settings.QUICK_ACTION_LIST.set(factory.quickActionListToString(quickActions));
}
public void deleteQuickAction(int id){ private final OsmandSettings settings;
int index = -1; private List<QuickAction> quickActions;
for (QuickAction action: quickActions){ private final Map<String, Boolean> fabStateMap;
if (action.id == id) { private final Gson gson;
index = quickActions.indexOf(action); private List<QuickActionType> quickActionTypes = new ArrayList<>();
} private Map<Integer, QuickActionType> quickActionTypesInt = new TreeMap<>();
} private Map<String, QuickActionType> quickActionTypesStr = new TreeMap<>();
if (index >= 0) {
quickActions.remove(index);
}
settings.QUICK_ACTION_LIST.set(factory.quickActionListToString(quickActions));
}
public void updateQuickAction(QuickAction action){ private QuickActionUpdatesListener updatesListener;
int index = quickActions.indexOf(action);
if (index >= 0) {
quickActions.set(index, action);
}
settings.QUICK_ACTION_LIST.set(factory.quickActionListToString(quickActions));
}
public void updateQuickActions(List<QuickAction> quickActions){ public QuickActionRegistry(OsmandSettings settings) {
this.quickActions.clear(); this.settings = settings;
this.quickActions.addAll(quickActions); gson = new GsonBuilder().registerTypeAdapter(QuickAction.class, new QuickActionSerializer()).create();
settings.QUICK_ACTION_LIST.set(factory.quickActionListToString(this.quickActions)); fabStateMap = getQuickActionFabStateMapFromJson(settings.QUICK_ACTION.get());
} updateActionTypes();
}
public QuickAction getQuickAction(long id){ public void setUpdatesListener(QuickActionUpdatesListener updatesListener) {
for (QuickAction action: quickActions){ this.updatesListener = updatesListener;
if (action.id == id) { }
return action;
}
}
return null;
}
public boolean isNameUnique(QuickAction action, Context context){ public void notifyUpdates() {
for (QuickAction a: quickActions){ if (updatesListener != null) updatesListener.onActionsUpdated();
if (action.id != a.id) { }
if (action.getName(context).equals(a.getName(context))) {
return false;
}
}
}
return true;
}
public QuickAction generateUniqueName(QuickAction action, Context context) { public List<QuickAction> getQuickActions() {
int number = 0; return new ArrayList<>(quickActions);
String name = action.getName(context); }
while (true) {
number++;
action.setName(name + " (" + number + ")");
if (isNameUnique(action, context)) {
return action;
}
}
}
public boolean isQuickActionOn() { public List<QuickAction> getFilteredQuickActions() {
Boolean result = fabStateMap.get(settings.APPLICATION_MODE.get().getStringKey()); return getQuickActions();
return result != null && result; }
}
public void setQuickActionFabState(boolean isOn) { public void addQuickAction(QuickAction action) {
fabStateMap.put(settings.APPLICATION_MODE.get().getStringKey(), isOn); quickActions.add(action);
settings.QUICK_ACTION.set(new Gson().toJson(fabStateMap)); saveActions();
} }
private Map<String, Boolean> getQuickActionFabStateMapFromJson(String json) { private void saveActions() {
Type type = new TypeToken<HashMap<String, Boolean>>() { Type type = new TypeToken<List<QuickAction>>() {
}.getType(); }.getType();
HashMap<String, Boolean> quickActions = new Gson().fromJson(json, type); settings.QUICK_ACTION_LIST.set(gson.toJson(quickActions, type));
}
return quickActions != null ? quickActions : new HashMap<String, Boolean>(); public void deleteQuickAction(QuickAction action) {
} quickActions.remove(action);
saveActions();
}
public void updateQuickAction(QuickAction action) {
int index = quickActions.indexOf(action);
if (index >= 0) {
quickActions.set(index, action);
}
saveActions();
}
public void updateQuickActions(List<QuickAction> quickActions) {
this.quickActions.clear();
this.quickActions.addAll(quickActions);
saveActions();
}
public QuickAction getQuickAction(long id) {
for (QuickAction action : quickActions) {
if (action.id == id) {
return action;
}
}
return null;
}
public boolean isNameUnique(QuickAction action, Context context) {
for (QuickAction a : quickActions) {
if (action.id != a.id) {
if (action.getName(context).equals(a.getName(context))) {
return false;
}
}
}
return true;
}
public QuickAction generateUniqueName(QuickAction action, Context context) {
int number = 0;
String name = action.getName(context);
while (true) {
number++;
action.setName(name + " (" + number + ")");
if (isNameUnique(action, context)) {
return action;
}
}
}
public boolean isQuickActionOn() {
Boolean result = fabStateMap.get(settings.APPLICATION_MODE.get().getStringKey());
return result != null && result;
}
public void setQuickActionFabState(boolean isOn) {
fabStateMap.put(settings.APPLICATION_MODE.get().getStringKey(), isOn);
settings.QUICK_ACTION.set(gson.toJson(fabStateMap));
}
private Map<String, Boolean> getQuickActionFabStateMapFromJson(String json) {
Type type = new TypeToken<HashMap<String, Boolean>>() {
}.getType();
HashMap<String, Boolean> quickActions = gson.fromJson(json, type);
return quickActions != null ? quickActions : new HashMap<String, Boolean>();
}
private List<QuickAction> parseActiveActionsList(String json) {
Type type = new TypeToken<List<QuickAction>>() {
}.getType();
List<QuickAction> quickActions = gson.fromJson(json, type);
List<QuickAction> rquickActions = new ArrayList<>(quickActions.size());
if (quickActions != null) {
for (QuickAction qa : quickActions) {
if (qa != null) {
rquickActions.add(qa);
}
}
}
this.quickActions = rquickActions;
return rquickActions;
}
public List<QuickActionType> updateActionTypes() {
List<QuickActionType> quickActionTypes = new ArrayList<>();
quickActionTypes.add(NewAction.TYPE);
quickActionTypes.add(FavoriteAction.TYPE);
quickActionTypes.add(GPXAction.TYPE);
quickActionTypes.add(MarkerAction.TYPE);
// configure map
quickActionTypes.add(ShowHideFavoritesAction.TYPE);
quickActionTypes.add(ShowHideGpxTracksAction.TYPE);
quickActionTypes.add(ShowHidePoiAction.TYPE);
quickActionTypes.add(MapStyleAction.TYPE);
quickActionTypes.add(DayNightModeAction.TYPE);
// navigation
quickActionTypes.add(NavVoiceAction.TYPE);
quickActionTypes.add(NavDirectionsFromAction.TYPE);
quickActionTypes.add(NavAddDestinationAction.TYPE);
quickActionTypes.add(NavAddFirstIntermediateAction.TYPE);
quickActionTypes.add(NavReplaceDestinationAction.TYPE);
quickActionTypes.add(NavAutoZoomMapAction.TYPE);
quickActionTypes.add(NavStartStopAction.TYPE);
quickActionTypes.add(NavResumePauseAction.TYPE);
OsmandPlugin.registerQuickActionTypesPlugins(quickActionTypes);
Map<Integer, QuickActionType> quickActionTypesInt = new TreeMap<>();
Map<String, QuickActionType> quickActionTypesStr = new TreeMap<>();
for (QuickActionType qt : quickActionTypes) {
quickActionTypesInt.put(qt.getId(), qt);
quickActionTypesStr.put(qt.getStringId(), qt);
}
this.quickActionTypes = quickActionTypes;
this.quickActionTypesInt = quickActionTypesInt;
this.quickActionTypesStr = quickActionTypesStr;
// reparse to get new quick actions
parseActiveActionsList(settings.QUICK_ACTION_LIST.get());
return quickActionTypes;
}
public List<QuickActionType> produceTypeActionsListWithHeaders() {
List<QuickActionType> result = new ArrayList<>();
filterQuickActions(TYPE_ADD_ITEMS, result);
filterQuickActions(TYPE_CONFIGURE_MAP, result);
filterQuickActions(TYPE_NAVIGATION, result);
return result;
}
private void filterQuickActions(QuickActionType filter, List<QuickActionType> result) {
result.add(filter);
Set<Integer> set = new TreeSet<>();
for (QuickAction qa : quickActions) {
set.add(qa.getActionType().getId());
}
for (QuickActionType t : quickActionTypes) {
if (t.getCategory() == filter.getCategory()) {
if (!t.isActionEditable()) {
boolean instanceInList = set.contains(t.getId());
if (!instanceInList) {
result.add(t);
}
} else {
result.add(t);
}
}
}
}
public QuickAction newActionByStringType(String actionType) {
QuickActionType quickActionType = quickActionTypesStr.get(actionType);
if (quickActionType != null) {
return quickActionType.createNew();
}
return null;
}
public QuickAction newActionByType(int type) {
QuickActionType quickActionType = quickActionTypesInt.get(type);
if (quickActionType != null) {
return quickActionType.createNew();
}
return null;
}
public static QuickAction produceAction(QuickAction quickAction) {
return quickAction.getActionType().createNew(quickAction);
}
private class QuickActionSerializer implements JsonDeserializer<QuickAction>,
JsonSerializer<QuickAction> {
@Override
public QuickAction deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
JsonObject obj = json.getAsJsonObject();
QuickActionType found = null;
if (obj.has("actionType")) {
String actionType = obj.get("actionType").getAsString();
found = quickActionTypesStr.get(actionType);
} else if (obj.has("type")) {
int type = obj.get("type").getAsInt();
found = quickActionTypesInt.get(type);
}
if (found != null) {
QuickAction qa = found.createNew();
if (obj.has("name")) {
qa.setName(obj.get("name").getAsString());
}
if (obj.has("id")) {
qa.setId(obj.get("id").getAsLong());
}
if (obj.has("params")) {
qa.setParams((Map<String, String>) context.deserialize(obj.get("params"),
new TypeToken<HashMap<String, String>>() {}.getType())
);
}
return qa;
}
return null;
}
@Override
public JsonElement serialize(QuickAction src, Type typeOfSrc, JsonSerializationContext context) {
JsonObject el = new JsonObject();
el.addProperty("actionType", src.getActionType().getStringId());
el.addProperty("id", src.getId());
if (src.getRawName() != null) {
el.addProperty("name", src.getRawName());
}
el.add("params", context.serialize(src.getParams()));
return el;
}
}
} }

View file

@ -0,0 +1,111 @@
package net.osmand.plus.quickaction;
import androidx.annotation.DrawableRes;
import androidx.annotation.StringRes;
import java.lang.reflect.InvocationTargetException;
public class QuickActionType {
public static final int CREATE_CATEGORY = 0;
public static final int CONFIGURE_MAP = 1;
public static final int NAVIGATION = 2;
private final int id;
private final String stringId;
private boolean actionEditable;
private @StringRes int nameRes;
private @DrawableRes int iconRes;
private Class<? extends QuickAction> cl;
private int category;
public QuickActionType(int id, String stringId) {
this.id = id;
this.stringId = stringId;
}
public QuickActionType(int id, String stringId, Class<? extends QuickAction> cl) {
this.id = id;
this.stringId = stringId;
this.cl = cl;
this.actionEditable = cl != null;
}
public QuickActionType nameRes(int nameRes) {
this.nameRes = nameRes;
return this;
}
public QuickActionType category(int cat) {
this.category = cat;
return this;
}
public QuickActionType iconRes(int iconRes) {
this.iconRes = iconRes;
return this;
}
public QuickActionType nonEditable() {
actionEditable = false;
return this;
}
public QuickAction createNew() {
if(cl != null) {
try {
return cl.newInstance();
} catch (InstantiationException e) {
throw new UnsupportedOperationException(e);
} catch (IllegalAccessException e) {
throw new UnsupportedOperationException(e);
}
} else {
throw new UnsupportedOperationException();
}
}
public QuickAction createNew(QuickAction q) {
if(cl != null) {
try {
return cl.getConstructor(QuickAction.class).newInstance(q);
} catch (InstantiationException e) {
throw new UnsupportedOperationException(e);
} catch (IllegalAccessException e) {
throw new UnsupportedOperationException(e);
} catch (NoSuchMethodException e) {
throw new UnsupportedOperationException(e);
} catch (InvocationTargetException e) {
throw new UnsupportedOperationException(e);
}
} else {
return new QuickAction(q);
}
}
public int getId() {
return id;
}
public String getStringId() {
return stringId;
}
public boolean isActionEditable() {
return actionEditable;
}
public int getNameRes() {
return nameRes;
}
public int getIconRes() {
return iconRes;
}
public int getCategory() {
return category;
}
}

View file

@ -221,7 +221,7 @@ public class QuickActionsWidget extends LinearLayout {
if (i + (position * ELEMENT_PER_PAGE) < actions.size()) { if (i + (position * ELEMENT_PER_PAGE) < actions.size()) {
final QuickAction action = QuickActionFactory.produceAction( final QuickAction action = QuickActionRegistry.produceAction(
actions.get(i + (position * ELEMENT_PER_PAGE))); actions.get(i + (position * ELEMENT_PER_PAGE)));
((ImageView) view.findViewById(imageView)) ((ImageView) view.findViewById(imageView))

View file

@ -18,6 +18,7 @@ import androidx.fragment.app.FragmentManager;
import androidx.recyclerview.widget.ItemTouchHelper; import androidx.recyclerview.widget.ItemTouchHelper;
import androidx.recyclerview.widget.RecyclerView; import androidx.recyclerview.widget.RecyclerView;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R; import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity; import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.dialogs.SelectMapViewQuickActionsBottomSheet; import net.osmand.plus.dialogs.SelectMapViewQuickActionsBottomSheet;
@ -37,7 +38,7 @@ public abstract class SwitchableAction<T> extends QuickAction {
private transient ItemTouchHelper touchHelper; private transient ItemTouchHelper touchHelper;
protected SwitchableAction(int type) { protected SwitchableAction(QuickActionType type) {
super(type); super(type);
} }
@ -118,6 +119,10 @@ public abstract class SwitchableAction<T> extends QuickAction {
fragment.show(fm, SelectMapViewQuickActionsBottomSheet.TAG); fragment.show(fm, SelectMapViewQuickActionsBottomSheet.TAG);
} }
public String getSelectedItem(OsmandApplication app) {
return null;
}
protected class Adapter extends RecyclerView.Adapter<Adapter.ItemHolder> implements ReorderItemTouchHelperCallback.OnItemMoveCallback { protected class Adapter extends RecyclerView.Adapter<Adapter.ItemHolder> implements ReorderItemTouchHelperCallback.OnItemMoveCallback {
private List<T> itemsList = new ArrayList<>(); private List<T> itemsList = new ArrayList<>();

View file

@ -11,9 +11,14 @@ import net.osmand.plus.OsmandSettings.DayNightMode;
import net.osmand.plus.R; import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity; import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.quickaction.QuickAction; import net.osmand.plus.quickaction.QuickAction;
import net.osmand.plus.quickaction.QuickActionType;
public class DayNightModeAction extends QuickAction { public class DayNightModeAction extends QuickAction {
public static final int TYPE = 27;
public static final QuickActionType TYPE = new QuickActionType(27,
"daynight.switch", DayNightModeAction.class).
nameRes(R.string.quick_action_day_night_switch_mode).iconRes(R.drawable.ic_action_map_day).nonEditable().
category(QuickActionType.NAVIGATION);
public DayNightModeAction() {super(TYPE);} public DayNightModeAction() {super(TYPE);}

View file

@ -23,12 +23,16 @@ import net.osmand.plus.mapcontextmenu.editors.EditCategoryDialogFragment;
import net.osmand.plus.mapcontextmenu.editors.FavoritePointEditor; import net.osmand.plus.mapcontextmenu.editors.FavoritePointEditor;
import net.osmand.plus.mapcontextmenu.editors.SelectCategoryDialogFragment; import net.osmand.plus.mapcontextmenu.editors.SelectCategoryDialogFragment;
import net.osmand.plus.quickaction.QuickAction; import net.osmand.plus.quickaction.QuickAction;
import net.osmand.plus.quickaction.QuickActionType;
import net.osmand.plus.widgets.AutoCompleteTextViewEx; import net.osmand.plus.widgets.AutoCompleteTextViewEx;
public class FavoriteAction extends QuickAction { public class FavoriteAction extends QuickAction {
public static final int TYPE = 3;
public static final QuickActionType TYPE = new QuickActionType(3,
"fav.add", FavoriteAction.class).
nameRes(R.string.quick_action_add_favorite).iconRes(R.drawable.ic_action_fav_dark).
category(QuickActionType.CREATE_CATEGORY);
public static final String KEY_NAME = "name"; public static final String KEY_NAME = "name";
public static final String KEY_DIALOG = "dialog"; public static final String KEY_DIALOG = "dialog";
public static final String KEY_CATEGORY_NAME = "category_name"; public static final String KEY_CATEGORY_NAME = "category_name";

View file

@ -17,11 +17,15 @@ import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.mapcontextmenu.editors.EditCategoryDialogFragment; import net.osmand.plus.mapcontextmenu.editors.EditCategoryDialogFragment;
import net.osmand.plus.mapcontextmenu.editors.SelectCategoryDialogFragment; import net.osmand.plus.mapcontextmenu.editors.SelectCategoryDialogFragment;
import net.osmand.plus.quickaction.QuickAction; import net.osmand.plus.quickaction.QuickAction;
import net.osmand.plus.quickaction.QuickActionType;
import net.osmand.plus.widgets.AutoCompleteTextViewEx; import net.osmand.plus.widgets.AutoCompleteTextViewEx;
public class GPXAction extends QuickAction { public class GPXAction extends QuickAction {
public static final int TYPE = 6; public static final QuickActionType TYPE = new QuickActionType(6,
"gpx.add", GPXAction.class).
nameRes(R.string.quick_action_add_gpx).iconRes(R.drawable.ic_action_flag_dark).
category(QuickActionType.CREATE_CATEGORY);
public static final String KEY_NAME = "name"; public static final String KEY_NAME = "name";
public static final String KEY_DIALOG = "dialog"; public static final String KEY_DIALOG = "dialog";

View file

@ -18,6 +18,7 @@ import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.dialogs.ConfigureMapMenu; import net.osmand.plus.dialogs.ConfigureMapMenu;
import net.osmand.plus.openseamapsplugin.NauticalMapsPlugin; import net.osmand.plus.openseamapsplugin.NauticalMapsPlugin;
import net.osmand.plus.quickaction.QuickAction; import net.osmand.plus.quickaction.QuickAction;
import net.osmand.plus.quickaction.QuickActionType;
import net.osmand.plus.quickaction.SwitchableAction; import net.osmand.plus.quickaction.SwitchableAction;
import net.osmand.plus.render.RendererRegistry; import net.osmand.plus.render.RendererRegistry;
import net.osmand.plus.views.OsmandMapTileView; import net.osmand.plus.views.OsmandMapTileView;
@ -31,9 +32,13 @@ import java.util.List;
public class MapStyleAction extends SwitchableAction<String> { public class MapStyleAction extends SwitchableAction<String> {
public static final int TYPE = 14;
private final static String KEY_STYLES = "styles"; private final static String KEY_STYLES = "styles";
public static final QuickActionType TYPE = new QuickActionType(14,
"mapstyle.change", MapStyleAction.class).
nameRes(R.string.quick_action_map_style).iconRes(R.drawable.ic_map).
category(QuickActionType.CONFIGURE_MAP);
public MapStyleAction() { public MapStyleAction() {
super(TYPE); super(TYPE);
@ -43,6 +48,16 @@ public class MapStyleAction extends SwitchableAction<String> {
super(quickAction); super(quickAction);
} }
@Override
public String getSelectedItem(OsmandApplication app) {
RenderingRulesStorage current = app.getRendererRegistry().getCurrentSelectedRenderer();
if (current != null) {
return current.getName();
} else {
return RendererRegistry.DEFAULT_RENDER;
}
}
@Override @Override
public void execute(MapActivity activity) { public void execute(MapActivity activity) {
List<String> mapStyles = getFilteredStyles(); List<String> mapStyles = getFilteredStyles();

View file

@ -10,10 +10,15 @@ import net.osmand.data.PointDescription;
import net.osmand.plus.R; import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity; import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.quickaction.QuickAction; import net.osmand.plus.quickaction.QuickAction;
import net.osmand.plus.quickaction.QuickActionType;
public class MarkerAction extends QuickAction { public class MarkerAction extends QuickAction {
public static final int TYPE = 2; public static final QuickActionType TYPE = new QuickActionType(2,
"marker.add", MarkerAction.class).
nameRes(R.string.quick_action_add_marker).iconRes(R.drawable.ic_action_flag_dark).nonEditable().
category(QuickActionType.CREATE_CATEGORY);
public MarkerAction() { public MarkerAction() {
super(TYPE); super(TYPE);

View file

@ -9,10 +9,15 @@ import net.osmand.data.LatLon;
import net.osmand.plus.R; import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity; import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.quickaction.QuickAction; import net.osmand.plus.quickaction.QuickAction;
import net.osmand.plus.quickaction.QuickActionType;
public class NavAddDestinationAction extends QuickAction { public class NavAddDestinationAction extends QuickAction {
public static final int TYPE = 20;
public static final QuickActionType TYPE = new QuickActionType(20,
"nav.destination.add", NavAddDestinationAction.class).
nameRes(R.string.quick_action_add_destination).iconRes(R.drawable.ic_action_point_add_destination).nonEditable().
category(QuickActionType.NAVIGATION);
public NavAddDestinationAction() { public NavAddDestinationAction() {
super(TYPE); super(TYPE);

View file

@ -9,10 +9,14 @@ import net.osmand.data.LatLon;
import net.osmand.plus.R; import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity; import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.quickaction.QuickAction; import net.osmand.plus.quickaction.QuickAction;
import net.osmand.plus.quickaction.QuickActionType;
public class NavAddFirstIntermediateAction extends QuickAction { public class NavAddFirstIntermediateAction extends QuickAction {
public static final int TYPE = 22; public static final QuickActionType TYPE = new QuickActionType(22,
"nav.intermediate.add", NavAddFirstIntermediateAction.class).
nameRes(R.string.quick_action_add_first_intermediate).iconRes(R.drawable.ic_action_intermediate).nonEditable().
category(QuickActionType.NAVIGATION);
public NavAddFirstIntermediateAction() { public NavAddFirstIntermediateAction() {
super(TYPE); super(TYPE);

View file

@ -11,10 +11,15 @@ import net.osmand.plus.OsmandSettings;
import net.osmand.plus.R; import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity; import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.quickaction.QuickAction; import net.osmand.plus.quickaction.QuickAction;
import net.osmand.plus.quickaction.QuickActionType;
public class NavAutoZoomMapAction extends QuickAction { public class NavAutoZoomMapAction extends QuickAction {
public static final int TYPE = 23; public static final QuickActionType TYPE = new QuickActionType(23,
"nav.autozoom", NavAutoZoomMapAction.class).
nameRes(R.string.quick_action_auto_zoom).iconRes(R.drawable.ic_action_search_dark).nonEditable().
category(QuickActionType.NAVIGATION);
public NavAutoZoomMapAction() { public NavAutoZoomMapAction() {
super(TYPE); super(TYPE);

View file

@ -9,10 +9,14 @@ import net.osmand.data.LatLon;
import net.osmand.plus.R; import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity; import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.quickaction.QuickAction; import net.osmand.plus.quickaction.QuickAction;
import net.osmand.plus.quickaction.QuickActionType;
public class NavDirectionsFromAction extends QuickAction { public class NavDirectionsFromAction extends QuickAction {
public static final int TYPE = 19; public static final QuickActionType TYPE = new QuickActionType(19,
"nav.directions", NavDirectionsFromAction.class).
nameRes(R.string.context_menu_item_directions_from).iconRes(R.drawable.ic_action_route_direction_from_here).nonEditable().
category(QuickActionType.NAVIGATION);
public NavDirectionsFromAction() { public NavDirectionsFromAction() {
super(TYPE); super(TYPE);

View file

@ -9,10 +9,14 @@ import net.osmand.data.LatLon;
import net.osmand.plus.R; import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity; import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.quickaction.QuickAction; import net.osmand.plus.quickaction.QuickAction;
import net.osmand.plus.quickaction.QuickActionType;
public class NavReplaceDestinationAction extends QuickAction { public class NavReplaceDestinationAction extends QuickAction {
public static final int TYPE = 21; public static final QuickActionType TYPE = new QuickActionType(21,
"nav.destination.replace", NavReplaceDestinationAction.class).
nameRes(R.string.quick_action_replace_destination).iconRes(R.drawable.ic_action_point_add_destination).nonEditable().
category(QuickActionType.NAVIGATION);
public NavReplaceDestinationAction() { public NavReplaceDestinationAction() {
super(TYPE); super(TYPE);

View file

@ -10,11 +10,16 @@ import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R; import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity; import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.quickaction.QuickAction; import net.osmand.plus.quickaction.QuickAction;
import net.osmand.plus.quickaction.QuickActionType;
import net.osmand.plus.routing.RoutingHelper; import net.osmand.plus.routing.RoutingHelper;
public class NavResumePauseAction extends QuickAction { public class NavResumePauseAction extends QuickAction {
public static final int TYPE = 26; public static final QuickActionType TYPE = new QuickActionType(26,
"nav.resumepause", NavResumePauseAction .class).
nameRes(R.string.quick_action_resume_pause_navigation).iconRes(R.drawable.ic_play_dark).nonEditable().
category(QuickActionType.NAVIGATION);
public NavResumePauseAction() { public NavResumePauseAction() {
super(TYPE); super(TYPE);

View file

@ -12,12 +12,18 @@ import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity; import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.mapcontextmenu.other.DestinationReachedMenu; import net.osmand.plus.mapcontextmenu.other.DestinationReachedMenu;
import net.osmand.plus.quickaction.QuickAction; import net.osmand.plus.quickaction.QuickAction;
import net.osmand.plus.quickaction.QuickActionType;
import net.osmand.plus.routing.RoutingHelper; import net.osmand.plus.routing.RoutingHelper;
public class NavStartStopAction extends QuickAction { public class NavStartStopAction extends QuickAction {
public static final int TYPE = 25;
private static final String KEY_DIALOG = "dialog"; private static final String KEY_DIALOG = "dialog";
public static final QuickActionType TYPE = new QuickActionType(25,
"nav.startstop", NavStartStopAction .class).
nameRes(R.string.quick_action_start_stop_navigation).iconRes(R.drawable.ic_action_start_navigation).nonEditable().
category(QuickActionType.NAVIGATION);
public NavStartStopAction() { public NavStartStopAction() {
super(TYPE); super(TYPE);

View file

@ -9,9 +9,13 @@ import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R; import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity; import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.quickaction.QuickAction; import net.osmand.plus.quickaction.QuickAction;
import net.osmand.plus.quickaction.QuickActionType;
public class NavVoiceAction extends QuickAction { public class NavVoiceAction extends QuickAction {
public static final int TYPE = 11; public static final QuickActionType TYPE = new QuickActionType(11,
"nav.voice", NavVoiceAction.class).
nameRes(R.string.quick_action_navigation_voice).iconRes(R.drawable.ic_action_volume_up).nonEditable().
category(QuickActionType.NAVIGATION);
public NavVoiceAction() { public NavVoiceAction() {
super(TYPE); super(TYPE);

View file

@ -2,13 +2,18 @@ package net.osmand.plus.quickaction.actions;
import android.view.ViewGroup; import android.view.ViewGroup;
import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity; import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.quickaction.AddQuickActionDialog; import net.osmand.plus.quickaction.AddQuickActionDialog;
import net.osmand.plus.quickaction.QuickAction; import net.osmand.plus.quickaction.QuickAction;
import net.osmand.plus.quickaction.QuickActionType;
public class NewAction extends QuickAction { public class NewAction extends QuickAction {
public static final int TYPE = 1; public static final QuickActionType TYPE = new QuickActionType(1, "new",
NewAction.class).
nonEditable().iconRes(R.drawable.ic_action_plus).nameRes(R.string.quick_action_new_action);
public NewAction() { public NewAction() {
super(TYPE); super(TYPE);

View file

@ -8,11 +8,18 @@ import android.widget.TextView;
import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R; import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity; import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.audionotes.TakeVideoNoteAction;
import net.osmand.plus.quickaction.QuickAction; import net.osmand.plus.quickaction.QuickAction;
import net.osmand.plus.quickaction.QuickActionType;
public class ShowHideFavoritesAction extends QuickAction { public class ShowHideFavoritesAction extends QuickAction {
public static final int TYPE = 4; public static final QuickActionType TYPE = new QuickActionType(4,
"favorites.showhide", ShowHideFavoritesAction.class).
nameRes(R.string.quick_action_showhide_favorites_title).iconRes(R.drawable.ic_action_fav_dark).nonEditable().
category(QuickActionType.CONFIGURE_MAP);
public ShowHideFavoritesAction() { public ShowHideFavoritesAction() {
super(TYPE); super(TYPE);

View file

@ -18,10 +18,16 @@ import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity; import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.helpers.GpxUiHelper; import net.osmand.plus.helpers.GpxUiHelper;
import net.osmand.plus.quickaction.QuickAction; import net.osmand.plus.quickaction.QuickAction;
import net.osmand.plus.quickaction.QuickActionType;
public class ShowHideGpxTracksAction extends QuickAction { public class ShowHideGpxTracksAction extends QuickAction {
public static final int TYPE = 28;
public static final QuickActionType TYPE = new QuickActionType(28,
"gpx.showhide", ShowHideGpxTracksAction.class).
nameRes(R.string.quick_action_show_hide_gpx_tracks).iconRes(R.drawable.ic_gpx_track).nonEditable().
category(QuickActionType.CONFIGURE_MAP);
public ShowHideGpxTracksAction() { public ShowHideGpxTracksAction() {
super(TYPE); super(TYPE);

View file

@ -25,6 +25,7 @@ import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.poi.PoiFiltersHelper; import net.osmand.plus.poi.PoiFiltersHelper;
import net.osmand.plus.poi.PoiUIFilter; import net.osmand.plus.poi.PoiUIFilter;
import net.osmand.plus.quickaction.QuickAction; import net.osmand.plus.quickaction.QuickAction;
import net.osmand.plus.quickaction.QuickActionType;
import net.osmand.plus.render.RenderingIcons; import net.osmand.plus.render.RenderingIcons;
import java.util.ArrayList; import java.util.ArrayList;
@ -34,7 +35,12 @@ import java.util.Set;
public class ShowHidePoiAction extends QuickAction { public class ShowHidePoiAction extends QuickAction {
public static final int TYPE = 5;
public static final QuickActionType TYPE = new QuickActionType(5,
"poi.showhide", ShowHidePoiAction.class).
nameRes(R.string.quick_action_showhide_poi_title).iconRes(R.drawable.ic_action_gabout_dark).nonEditable().
category(QuickActionType.CONFIGURE_MAP);
public static final String KEY_FILTERS = "filters"; public static final String KEY_FILTERS = "filters";

View file

@ -1,4 +1,4 @@
package net.osmand.plus.quickaction.actions; package net.osmand.plus.rastermaps;
import android.content.Context; import android.content.Context;
import android.content.DialogInterface; import android.content.DialogInterface;
@ -21,6 +21,7 @@ import net.osmand.plus.R;
import net.osmand.plus.UiUtilities; import net.osmand.plus.UiUtilities;
import net.osmand.plus.activities.MapActivity; import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.quickaction.QuickAction; import net.osmand.plus.quickaction.QuickAction;
import net.osmand.plus.quickaction.QuickActionType;
import net.osmand.plus.quickaction.SwitchableAction; import net.osmand.plus.quickaction.SwitchableAction;
import net.osmand.plus.rastermaps.OsmandRasterMapsPlugin; import net.osmand.plus.rastermaps.OsmandRasterMapsPlugin;
@ -30,11 +31,16 @@ import java.util.List;
import java.util.Map; import java.util.Map;
public class MapOverlayAction extends SwitchableAction<Pair<String, String>> { public class MapOverlayAction extends SwitchableAction<Pair<String, String>> {
public static final int TYPE = 15;
private final static String KEY_OVERLAYS = "overlays"; private final static String KEY_OVERLAYS = "overlays";
private final static String KEY_NO_OVERLAY = "no_overlay"; private final static String KEY_NO_OVERLAY = "no_overlay";
public static final QuickActionType TYPE = new QuickActionType(15,
"mapoverlay.change", MapOverlayAction.class).
nameRes(R.string.quick_action_map_overlay).iconRes(R.drawable.ic_layer_top).
category(QuickActionType.CONFIGURE_MAP);
public MapOverlayAction() { public MapOverlayAction() {
super(TYPE); super(TYPE);
} }
@ -53,6 +59,11 @@ public class MapOverlayAction extends SwitchableAction<Pair<String, String>> {
: filters.get(0).second; : filters.get(0).second;
} }
@Override
public String getSelectedItem(OsmandApplication app) {
return app.getSettings().MAP_OVERLAY.get();
}
@Override @Override
protected void saveListToParams(List<Pair<String, String>> list) { protected void saveListToParams(List<Pair<String, String>> list) {

View file

@ -1,4 +1,4 @@
package net.osmand.plus.quickaction.actions; package net.osmand.plus.rastermaps;
import android.content.Context; import android.content.Context;
import android.content.DialogInterface; import android.content.DialogInterface;
@ -20,6 +20,7 @@ import net.osmand.plus.R;
import net.osmand.plus.UiUtilities; import net.osmand.plus.UiUtilities;
import net.osmand.plus.activities.MapActivity; import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.quickaction.QuickAction; import net.osmand.plus.quickaction.QuickAction;
import net.osmand.plus.quickaction.QuickActionType;
import net.osmand.plus.quickaction.SwitchableAction; import net.osmand.plus.quickaction.SwitchableAction;
import net.osmand.plus.rastermaps.OsmandRasterMapsPlugin; import net.osmand.plus.rastermaps.OsmandRasterMapsPlugin;
@ -31,8 +32,11 @@ import java.util.Map;
public class MapSourceAction extends SwitchableAction<Pair<String, String>> { public class MapSourceAction extends SwitchableAction<Pair<String, String>> {
public static final int TYPE = 17;
public static final String LAYER_OSM_VECTOR = "LAYER_OSM_VECTOR"; public static final String LAYER_OSM_VECTOR = "LAYER_OSM_VECTOR";
public static final QuickActionType TYPE = new QuickActionType(17,
"mapsource.change", MapSourceAction.class).
nameRes(R.string.quick_action_map_source).iconRes(R.drawable.ic_world_globe_dark).
category(QuickActionType.CONFIGURE_MAP);
private final static String KEY_SOURCE = "source"; private final static String KEY_SOURCE = "source";
@ -54,6 +58,13 @@ public class MapSourceAction extends SwitchableAction<Pair<String, String>> {
: filters.get(0).second; : filters.get(0).second;
} }
@Override
public String getSelectedItem(OsmandApplication app) {
return app.getSettings().MAP_ONLINE_DATA.get()
? app.getSettings().MAP_TILE_SOURCES.get()
: MapSourceAction.LAYER_OSM_VECTOR;
}
@Override @Override
protected void saveListToParams(List<Pair<String, String>> list) { protected void saveListToParams(List<Pair<String, String>> list) {

View file

@ -1,4 +1,4 @@
package net.osmand.plus.quickaction.actions; package net.osmand.plus.rastermaps;
import android.content.Context; import android.content.Context;
import android.content.DialogInterface; import android.content.DialogInterface;
@ -21,6 +21,7 @@ import net.osmand.plus.R;
import net.osmand.plus.UiUtilities; import net.osmand.plus.UiUtilities;
import net.osmand.plus.activities.MapActivity; import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.quickaction.QuickAction; import net.osmand.plus.quickaction.QuickAction;
import net.osmand.plus.quickaction.QuickActionType;
import net.osmand.plus.quickaction.SwitchableAction; import net.osmand.plus.quickaction.SwitchableAction;
import net.osmand.plus.rastermaps.OsmandRasterMapsPlugin; import net.osmand.plus.rastermaps.OsmandRasterMapsPlugin;
@ -30,10 +31,14 @@ import java.util.List;
import java.util.Map; import java.util.Map;
public class MapUnderlayAction extends SwitchableAction<Pair<String, String>> { public class MapUnderlayAction extends SwitchableAction<Pair<String, String>> {
public static final int TYPE = 16;
private final static String KEY_UNDERLAYS = "underlays"; private final static String KEY_UNDERLAYS = "underlays";
private final static String KEY_NO_UNDERLAY = "no_underlay"; private final static String KEY_NO_UNDERLAY = "no_underlay";
public static final QuickActionType TYPE = new QuickActionType(16,
"mapunderlay.change", MapUnderlayAction.class).
nameRes(R.string.quick_action_map_underlay).iconRes(R.drawable.ic_layer_bottom).
category(QuickActionType.CONFIGURE_MAP);
public MapUnderlayAction() { public MapUnderlayAction() {
super(TYPE); super(TYPE);
@ -53,6 +58,11 @@ public class MapUnderlayAction extends SwitchableAction<Pair<String, String>> {
: filters.get(0).second; : filters.get(0).second;
} }
@Override
public String getSelectedItem(OsmandApplication app) {
return app.getSettings().MAP_UNDERLAY.get();
}
@Override @Override
protected void saveListToParams(List<Pair<String, String>> list) { protected void saveListToParams(List<Pair<String, String>> list) {

View file

@ -45,6 +45,7 @@ import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.activities.MapActivityLayers; import net.osmand.plus.activities.MapActivityLayers;
import net.osmand.plus.dashboard.DashboardOnMap.DashboardType; import net.osmand.plus.dashboard.DashboardOnMap.DashboardType;
import net.osmand.plus.dialogs.RasterMapMenu; import net.osmand.plus.dialogs.RasterMapMenu;
import net.osmand.plus.quickaction.QuickActionType;
import net.osmand.plus.views.MapTileLayer; import net.osmand.plus.views.MapTileLayer;
import net.osmand.plus.views.OsmandMapTileView; import net.osmand.plus.views.OsmandMapTileView;
import net.osmand.util.Algorithms; import net.osmand.util.Algorithms;
@ -679,4 +680,11 @@ public class OsmandRasterMapsPlugin extends OsmandPlugin {
public interface OnMapSelectedCallback { public interface OnMapSelectedCallback {
void onMapSelected(boolean canceled); void onMapSelected(boolean canceled);
} }
@Override
protected void registerQuickActionTypes(List<QuickActionType> quickActionTypes) {
quickActionTypes.add(MapSourceAction.TYPE);
quickActionTypes.add(MapOverlayAction.TYPE);
quickActionTypes.add(MapUnderlayAction.TYPE);
}
} }

View file

@ -39,7 +39,7 @@ import net.osmand.plus.base.bottomsheetmenu.simpleitems.TitleItem;
import net.osmand.plus.helpers.AvoidSpecificRoads.AvoidRoadInfo; import net.osmand.plus.helpers.AvoidSpecificRoads.AvoidRoadInfo;
import net.osmand.plus.poi.PoiUIFilter; import net.osmand.plus.poi.PoiUIFilter;
import net.osmand.plus.quickaction.QuickAction; import net.osmand.plus.quickaction.QuickAction;
import net.osmand.plus.quickaction.QuickActionFactory; import net.osmand.plus.quickaction.QuickActionRegistry;
import net.osmand.plus.settings.bottomsheets.BasePreferenceBottomSheet; import net.osmand.plus.settings.bottomsheets.BasePreferenceBottomSheet;
import net.osmand.plus.settings.ExportImportSettingsAdapter.Type; import net.osmand.plus.settings.ExportImportSettingsAdapter.Type;
@ -218,8 +218,9 @@ public class ExportProfileBottomSheet extends BasePreferenceBottomSheet {
private Map<Type, List<?>> getAdditionalData() { private Map<Type, List<?>> getAdditionalData() {
Map<Type, List<?>> dataList = new HashMap<>(); Map<Type, List<?>> dataList = new HashMap<>();
QuickActionFactory factory = new QuickActionFactory();
List<QuickAction> actionsList = factory.parseActiveActionsList(app.getSettings().QUICK_ACTION_LIST.get()); QuickActionRegistry registry = app.getQuickActionRegistry();
List<QuickAction> actionsList = registry.getQuickActions();
if (!actionsList.isEmpty()) { if (!actionsList.isEmpty()) {
dataList.put(Type.QUICK_ACTIONS, actionsList); dataList.put(Type.QUICK_ACTIONS, actionsList);
} }

View file

@ -1,4 +1,4 @@
package net.osmand.plus.quickaction.actions; package net.osmand.plus.srtmplugin;
import android.content.Context; import android.content.Context;
import android.view.LayoutInflater; import android.view.LayoutInflater;
@ -12,6 +12,7 @@ import net.osmand.plus.OsmandSettings;
import net.osmand.plus.R; import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity; import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.quickaction.QuickAction; import net.osmand.plus.quickaction.QuickAction;
import net.osmand.plus.quickaction.QuickActionType;
import net.osmand.plus.srtmplugin.SRTMPlugin; import net.osmand.plus.srtmplugin.SRTMPlugin;
import net.osmand.render.RenderingRuleProperty; import net.osmand.render.RenderingRuleProperty;
@ -20,7 +21,12 @@ import static net.osmand.plus.srtmplugin.SRTMPlugin.CONTOUR_LINES_DISABLED_VALUE
public class ContourLinesAction extends QuickAction { public class ContourLinesAction extends QuickAction {
public static final int TYPE = 29; public static final QuickActionType TYPE = new QuickActionType(29,
"contourlines.showhide", ContourLinesAction.class).
nameRes(R.string.quick_action_show_hide_contour_lines).iconRes(R.drawable.ic_plugin_srtm).nonEditable().
category(QuickActionType.CONFIGURE_MAP);
public ContourLinesAction() { public ContourLinesAction() {
super(TYPE); super(TYPE);

View file

@ -1,4 +1,4 @@
package net.osmand.plus.quickaction.actions; package net.osmand.plus.srtmplugin;
import android.content.Context; import android.content.Context;
import android.view.LayoutInflater; import android.view.LayoutInflater;
@ -11,11 +11,16 @@ import net.osmand.plus.OsmandPlugin;
import net.osmand.plus.R; import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity; import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.quickaction.QuickAction; import net.osmand.plus.quickaction.QuickAction;
import net.osmand.plus.quickaction.QuickActionType;
import net.osmand.plus.srtmplugin.SRTMPlugin; import net.osmand.plus.srtmplugin.SRTMPlugin;
public class HillshadeAction extends QuickAction { public class HillshadeAction extends QuickAction {
public static final int TYPE = 30; public static final QuickActionType TYPE = new QuickActionType(30,
"contourlines.showhide", HillshadeAction.class).
nameRes(R.string.quick_action_show_hide_hillshade).iconRes(R.drawable.ic_action_hillshade_dark).nonEditable().
category(QuickActionType.CONFIGURE_MAP);
public HillshadeAction() { public HillshadeAction() {
super(TYPE); super(TYPE);

View file

@ -30,6 +30,7 @@ import net.osmand.plus.download.DownloadIndexesThread;
import net.osmand.plus.download.DownloadResources; import net.osmand.plus.download.DownloadResources;
import net.osmand.plus.download.IndexItem; import net.osmand.plus.download.IndexItem;
import net.osmand.plus.inapp.InAppPurchaseHelper; import net.osmand.plus.inapp.InAppPurchaseHelper;
import net.osmand.plus.quickaction.QuickActionType;
import net.osmand.plus.views.OsmandMapTileView; import net.osmand.plus.views.OsmandMapTileView;
import net.osmand.render.RenderingRuleProperty; import net.osmand.render.RenderingRuleProperty;
import net.osmand.util.Algorithms; import net.osmand.util.Algorithms;
@ -442,4 +443,10 @@ public class SRTMPlugin extends OsmandPlugin {
private static int getThemeRes(Activity activity, OsmandApplication app) { private static int getThemeRes(Activity activity, OsmandApplication app) {
return isNightMode(activity, app) ? R.style.OsmandDarkTheme : R.style.OsmandLightTheme; return isNightMode(activity, app) ? R.style.OsmandDarkTheme : R.style.OsmandLightTheme;
} }
@Override
protected void registerQuickActionTypes(List<QuickActionType> quickActionTypes) {
quickActionTypes.add(ContourLinesAction.TYPE);
quickActionTypes.add(HillshadeAction.TYPE);
}
} }

View file

@ -38,7 +38,6 @@ import net.osmand.plus.mapcontextmenu.MapContextMenuFragment;
import net.osmand.plus.mapcontextmenu.other.MapMultiSelectionMenu; import net.osmand.plus.mapcontextmenu.other.MapMultiSelectionMenu;
import net.osmand.plus.measurementtool.MeasurementToolLayer; import net.osmand.plus.measurementtool.MeasurementToolLayer;
import net.osmand.plus.quickaction.QuickAction; import net.osmand.plus.quickaction.QuickAction;
import net.osmand.plus.quickaction.QuickActionFactory;
import net.osmand.plus.quickaction.QuickActionRegistry; import net.osmand.plus.quickaction.QuickActionRegistry;
import net.osmand.plus.quickaction.QuickActionsWidget; import net.osmand.plus.quickaction.QuickActionsWidget;
import net.osmand.plus.routepreparationmenu.MapRouteInfoMenu; import net.osmand.plus.routepreparationmenu.MapRouteInfoMenu;
@ -431,7 +430,7 @@ public class MapQuickActionLayer extends OsmandMapLayer implements QuickActionRe
@Override @Override
public void onActionSelected(QuickAction action) { public void onActionSelected(QuickAction action) {
QuickActionFactory.produceAction(action).execute(mapActivity); QuickActionRegistry.produceAction(action).execute(mapActivity);
setLayerState(false); setLayerState(false);
} }