diff --git a/OsmAnd/src/net/osmand/plus/OsmandPlugin.java b/OsmAnd/src/net/osmand/plus/OsmandPlugin.java index f102c63a58..54fd13235f 100644 --- a/OsmAnd/src/net/osmand/plus/OsmandPlugin.java +++ b/OsmAnd/src/net/osmand/plus/OsmandPlugin.java @@ -36,6 +36,7 @@ import net.osmand.plus.myplaces.FavoritesActivity; import net.osmand.plus.openseamapsplugin.NauticalMapsPlugin; import net.osmand.plus.osmedit.OsmEditingPlugin; import net.osmand.plus.parkingpoint.ParkingPositionPlugin; +import net.osmand.plus.quickaction.QuickActionType; import net.osmand.plus.rastermaps.OsmandRasterMapsPlugin; import net.osmand.plus.settings.BaseSettingsFragment; import net.osmand.plus.skimapsplugin.SkiMapsPlugin; @@ -237,6 +238,7 @@ public abstract class OsmandPlugin { initPlugin(app, plugin); } } + app.getQuickActionRegistry().updateActionTypes(); } private static void initPlugin(OsmandApplication app, OsmandPlugin plugin) { @@ -292,6 +294,7 @@ public abstract class OsmandPlugin { } updateMarketPlugin(app, enabledPlugins, plugin); } + app.getQuickActionRegistry().updateActionTypes(); } protected boolean pluginAvailable(OsmandApplication app) { @@ -315,6 +318,7 @@ public abstract class OsmandPlugin { plugin.setActive(false); } app.getSettings().enablePlugin(plugin.getId(), enable); + app.getQuickActionRegistry().updateActionTypes(); if (activity != null) { if (activity instanceof MapActivity) { final MapActivity mapActivity = (MapActivity) activity; @@ -386,14 +390,16 @@ public abstract class OsmandPlugin { return true; } - - public void registerLayerContextMenuActions(OsmandMapTileView mapView, ContextMenuAdapter adapter, MapActivity mapActivity) { + protected void registerQuickActionTypes(List quickActionTypes) { } - 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() { @@ -403,13 +409,13 @@ public abstract class OsmandPlugin { public void updateLocation(Location location) { } - public void addMyPlacesTab(FavoritesActivity favoritesActivity, List mTabs, Intent intent) { + protected void addMyPlacesTab(FavoritesActivity favoritesActivity, List 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 indexingFiles(IProgress progress) { @@ -639,6 +645,8 @@ public abstract class OsmandPlugin { return installed; } + + public static boolean onMapActivityKeyUp(MapActivity mapActivity, int keyCode) { for (OsmandPlugin p : getEnabledPlugins()) { if (p.mapActivityKeyUp(mapActivity, keyCode)) @@ -647,6 +655,14 @@ public abstract class OsmandPlugin { return false; } + public static void registerQuickActionTypesPlugins(List quickActionTypes) { + for (OsmandPlugin p : getEnabledPlugins()) { + p.registerQuickActionTypes(quickActionTypes); + } + } + + + public static void updateLocationPlugins(net.osmand.Location location) { for (OsmandPlugin p : getEnabledPlugins()) { p.updateLocation(location); diff --git a/OsmAnd/src/net/osmand/plus/SettingsHelper.java b/OsmAnd/src/net/osmand/plus/SettingsHelper.java index a3abaa1b10..efd927fb61 100644 --- a/OsmAnd/src/net/osmand/plus/SettingsHelper.java +++ b/OsmAnd/src/net/osmand/plus/SettingsHelper.java @@ -25,6 +25,7 @@ import net.osmand.plus.helpers.AvoidSpecificRoads.AvoidRoadInfo; import net.osmand.plus.poi.PoiUIFilter; import net.osmand.plus.quickaction.QuickAction; import net.osmand.plus.quickaction.QuickActionRegistry; +import net.osmand.plus.quickaction.QuickActionType; import net.osmand.util.Algorithms; import org.apache.commons.logging.Log; @@ -936,19 +937,27 @@ public class SettingsHelper { Type type = new TypeToken>() { }.getType(); json = new JSONObject(jsonStr); + QuickActionRegistry quickActionRegistry = app.getQuickActionRegistry(); JSONArray itemsJson = json.getJSONArray("items"); for (int i = 0; i < itemsJson.length(); i++) { JSONObject object = itemsJson.getJSONObject(i); String name = object.getString("name"); - int actionType = object.getInt("type"); - String paramsString = object.getString("params"); - HashMap params = gson.fromJson(paramsString, type); - QuickAction quickAction = new QuickAction(actionType); - if (!name.isEmpty()) { - quickAction.setName(name); + QuickAction quickAction = null; + if(object.has("actionType")) { + quickAction = quickActionRegistry .newActionByStringType(object.getString("actionType")); + } else if(object.has("type")) { + quickAction = quickActionRegistry .newActionByType(object.getInt("type")); + } + if (quickAction != null) { + String paramsString = object.getString("params"); + HashMap 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) { throw new IllegalArgumentException("Json parse error", e); @@ -974,7 +983,7 @@ public class SettingsHelper { JSONObject jsonObject = new JSONObject(); jsonObject.put("name", action.hasCustomName(app) ? action.getName(app) : ""); - jsonObject.put("type", action.getType()); + jsonObject.put("actionType", action.getActionType().getStringId()); jsonObject.put("params", gson.toJson(action.getParams(), type)); jsonArray.put(jsonObject); } diff --git a/OsmAnd/src/net/osmand/plus/audionotes/AudioVideoNotesPlugin.java b/OsmAnd/src/net/osmand/plus/audionotes/AudioVideoNotesPlugin.java index 26fe6c967b..a62564ca18 100644 --- a/OsmAnd/src/net/osmand/plus/audionotes/AudioVideoNotesPlugin.java +++ b/OsmAnd/src/net/osmand/plus/audionotes/AudioVideoNotesPlugin.java @@ -64,6 +64,7 @@ import net.osmand.plus.helpers.AndroidUiHelper; import net.osmand.plus.mapcontextmenu.MapContextMenu; import net.osmand.plus.monitoring.OsmandMonitoringPlugin; import net.osmand.plus.myplaces.FavoritesActivity; +import net.osmand.plus.quickaction.QuickActionType; import net.osmand.plus.settings.BaseSettingsFragment; import net.osmand.plus.views.MapInfoLayer; import net.osmand.plus.views.OsmandMapLayer.DrawSettings; @@ -868,6 +869,12 @@ public class AudioVideoNotesPlugin extends OsmandPlugin { mapActivity.startActivityForResult(intent, 205); } + @Override + protected void registerQuickActionTypes(List quickActionTypes) { + quickActionTypes.add(TakeAudioNoteAction.TYPE); + quickActionTypes.add(TakePhotoNoteAction.TYPE); + quickActionTypes.add(TakeVideoNoteAction.TYPE); + } @Override public void mapActivityScreenOff(MapActivity activity) { diff --git a/OsmAnd/src/net/osmand/plus/audionotes/TakeAudioNoteAction.java b/OsmAnd/src/net/osmand/plus/audionotes/TakeAudioNoteAction.java index c86046fba8..3ede79cfff 100644 --- a/OsmAnd/src/net/osmand/plus/audionotes/TakeAudioNoteAction.java +++ b/OsmAnd/src/net/osmand/plus/audionotes/TakeAudioNoteAction.java @@ -10,9 +10,14 @@ import net.osmand.plus.OsmandPlugin; import net.osmand.plus.R; import net.osmand.plus.activities.MapActivity; import net.osmand.plus.quickaction.QuickAction; +import net.osmand.plus.quickaction.QuickActionType; 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() { super(TYPE); diff --git a/OsmAnd/src/net/osmand/plus/audionotes/TakePhotoNoteAction.java b/OsmAnd/src/net/osmand/plus/audionotes/TakePhotoNoteAction.java index 69fbbdab57..4265bd8cd0 100644 --- a/OsmAnd/src/net/osmand/plus/audionotes/TakePhotoNoteAction.java +++ b/OsmAnd/src/net/osmand/plus/audionotes/TakePhotoNoteAction.java @@ -10,9 +10,14 @@ import net.osmand.plus.OsmandPlugin; import net.osmand.plus.R; import net.osmand.plus.activities.MapActivity; import net.osmand.plus.quickaction.QuickAction; +import net.osmand.plus.quickaction.QuickActionType; 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() { super(TYPE); diff --git a/OsmAnd/src/net/osmand/plus/audionotes/TakeVideoNoteAction.java b/OsmAnd/src/net/osmand/plus/audionotes/TakeVideoNoteAction.java index 32c99cb178..d3732921a4 100644 --- a/OsmAnd/src/net/osmand/plus/audionotes/TakeVideoNoteAction.java +++ b/OsmAnd/src/net/osmand/plus/audionotes/TakeVideoNoteAction.java @@ -10,9 +10,14 @@ import net.osmand.plus.OsmandPlugin; import net.osmand.plus.R; import net.osmand.plus.activities.MapActivity; import net.osmand.plus.quickaction.QuickAction; +import net.osmand.plus.quickaction.QuickActionType; 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() { super(TYPE); diff --git a/OsmAnd/src/net/osmand/plus/dialogs/SelectMapViewQuickActionsBottomSheet.java b/OsmAnd/src/net/osmand/plus/dialogs/SelectMapViewQuickActionsBottomSheet.java index 2e0aa62177..7ed1e98ea6 100644 --- a/OsmAnd/src/net/osmand/plus/dialogs/SelectMapViewQuickActionsBottomSheet.java +++ b/OsmAnd/src/net/osmand/plus/dialogs/SelectMapViewQuickActionsBottomSheet.java @@ -31,13 +31,9 @@ import net.osmand.plus.base.bottomsheetmenu.BaseBottomSheetItem; import net.osmand.plus.base.bottomsheetmenu.simpleitems.TitleItem; import net.osmand.plus.quickaction.CreateEditActionDialog; import net.osmand.plus.quickaction.QuickAction; -import net.osmand.plus.quickaction.QuickActionFactory; import net.osmand.plus.quickaction.QuickActionRegistry; 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.MapUnderlayAction; import net.osmand.plus.render.RendererRegistry; import net.osmand.render.RenderingRulesStorage; @@ -71,7 +67,7 @@ public class SelectMapViewQuickActionsBottomSheet extends MenuBottomSheetDialogF QuickActionRegistry quickActionRegistry = app.getQuickActionRegistry(); action = quickActionRegistry.getQuickAction(id); - action = QuickActionFactory.produceAction(action); + action = QuickActionRegistry.produceAction(action); if (action == null) { return; } @@ -79,22 +75,7 @@ public class SelectMapViewQuickActionsBottomSheet extends MenuBottomSheetDialogF if (savedInstanceState != null) { selectedItem = savedInstanceState.getString(SELECTED_ITEM_KEY); } else { - if (action instanceof MapStyleAction) { - 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(); - } + selectedItem = ((SwitchableAction) action).getSelectedItem(app); } rbColorList = AndroidUtils.createCheckedColorStateList(app, R.color.icon_color_default_light, getActiveColorId()); diff --git a/OsmAnd/src/net/osmand/plus/quickaction/actions/AddOSMBugAction.java b/OsmAnd/src/net/osmand/plus/osmedit/AddOSMBugAction.java similarity index 87% rename from OsmAnd/src/net/osmand/plus/quickaction/actions/AddOSMBugAction.java rename to OsmAnd/src/net/osmand/plus/osmedit/AddOSMBugAction.java index c172c541a7..c6c04d0462 100644 --- a/OsmAnd/src/net/osmand/plus/quickaction/actions/AddOSMBugAction.java +++ b/OsmAnd/src/net/osmand/plus/osmedit/AddOSMBugAction.java @@ -1,4 +1,4 @@ -package net.osmand.plus.quickaction.actions; +package net.osmand.plus.osmedit; import android.view.LayoutInflater; import android.view.View; @@ -13,14 +13,19 @@ import net.osmand.plus.R; import net.osmand.plus.activities.MapActivity; import net.osmand.plus.osmedit.OsmEditingPlugin; import net.osmand.plus.quickaction.QuickAction; +import net.osmand.plus.quickaction.QuickActionType; public class AddOSMBugAction extends QuickAction { - public static final int TYPE = 12; private static final String KEY_MESSAGE = "message"; 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() { super(TYPE); } diff --git a/OsmAnd/src/net/osmand/plus/quickaction/actions/AddPOIAction.java b/OsmAnd/src/net/osmand/plus/osmedit/AddPOIAction.java similarity index 98% rename from OsmAnd/src/net/osmand/plus/quickaction/actions/AddPOIAction.java rename to OsmAnd/src/net/osmand/plus/osmedit/AddPOIAction.java index f40c5ecd77..8b29e720d9 100644 --- a/OsmAnd/src/net/osmand/plus/quickaction/actions/AddPOIAction.java +++ b/OsmAnd/src/net/osmand/plus/osmedit/AddPOIAction.java @@ -1,4 +1,4 @@ -package net.osmand.plus.quickaction.actions; +package net.osmand.plus.osmedit; import android.content.Context; import android.content.Intent; @@ -40,16 +40,10 @@ import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandPlugin; import net.osmand.plus.R; import net.osmand.plus.activities.MapActivity; -import net.osmand.plus.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.quickaction.CreateEditActionDialog; import net.osmand.plus.quickaction.QuickAction; +import net.osmand.plus.quickaction.QuickActionType; import net.osmand.plus.render.RenderingIcons; 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; 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_DIALOG = "dialog"; diff --git a/OsmAnd/src/net/osmand/plus/osmedit/OsmEditingPlugin.java b/OsmAnd/src/net/osmand/plus/osmedit/OsmEditingPlugin.java index 0624e088b6..a0955f0ec7 100644 --- a/OsmAnd/src/net/osmand/plus/osmedit/OsmEditingPlugin.java +++ b/OsmAnd/src/net/osmand/plus/osmedit/OsmEditingPlugin.java @@ -41,6 +41,7 @@ import net.osmand.plus.myplaces.AvailableGPXFragment; import net.osmand.plus.myplaces.AvailableGPXFragment.GpxInfo; import net.osmand.plus.myplaces.FavoritesActivity; import net.osmand.plus.osmedit.OsmPoint.Action; +import net.osmand.plus.quickaction.QuickActionType; import net.osmand.plus.settings.BaseSettingsFragment; import net.osmand.plus.views.OsmandMapTileView; import net.osmand.util.Algorithms; @@ -137,6 +138,13 @@ public class OsmEditingPlugin extends OsmandPlugin { private OsmEditsLayer osmEditsLayer; // private EditingPOIDialogProvider poiActions; + @Override + protected void registerQuickActionTypes(List quickActionTypes) { + quickActionTypes.add(AddPOIAction.TYPE); + quickActionTypes.add(AddOSMBugAction.TYPE); + quickActionTypes.add(ShowHideOSMBugAction.TYPE); + } + @Override public void updateLayers(OsmandMapTileView mapView, MapActivity activity) { if (isActive()) { diff --git a/OsmAnd/src/net/osmand/plus/quickaction/actions/ShowHideOSMBugAction.java b/OsmAnd/src/net/osmand/plus/osmedit/ShowHideOSMBugAction.java similarity index 82% rename from OsmAnd/src/net/osmand/plus/quickaction/actions/ShowHideOSMBugAction.java rename to OsmAnd/src/net/osmand/plus/osmedit/ShowHideOSMBugAction.java index 6765c0016e..59145ad41f 100644 --- a/OsmAnd/src/net/osmand/plus/quickaction/actions/ShowHideOSMBugAction.java +++ b/OsmAnd/src/net/osmand/plus/osmedit/ShowHideOSMBugAction.java @@ -1,4 +1,4 @@ -package net.osmand.plus.quickaction.actions; +package net.osmand.plus.osmedit; import android.view.LayoutInflater; import android.view.View; @@ -9,13 +9,16 @@ import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandPlugin; import net.osmand.plus.R; import net.osmand.plus.activities.MapActivity; -import net.osmand.plus.dialogs.ConfigureMapMenu; -import net.osmand.plus.osmedit.OsmEditingPlugin; import net.osmand.plus.quickaction.QuickAction; +import net.osmand.plus.quickaction.QuickActionType; 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() { super(TYPE); diff --git a/OsmAnd/src/net/osmand/plus/parkingpoint/ParkingAction.java b/OsmAnd/src/net/osmand/plus/parkingpoint/ParkingAction.java index 825c6c34e6..e7c4445a98 100644 --- a/OsmAnd/src/net/osmand/plus/parkingpoint/ParkingAction.java +++ b/OsmAnd/src/net/osmand/plus/parkingpoint/ParkingAction.java @@ -10,10 +10,14 @@ import net.osmand.plus.OsmandPlugin; import net.osmand.plus.R; import net.osmand.plus.activities.MapActivity; import net.osmand.plus.quickaction.QuickAction; +import net.osmand.plus.quickaction.QuickActionType; 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() { super(TYPE); diff --git a/OsmAnd/src/net/osmand/plus/parkingpoint/ParkingPositionPlugin.java b/OsmAnd/src/net/osmand/plus/parkingpoint/ParkingPositionPlugin.java index b13a2193a4..ffd8db041c 100644 --- a/OsmAnd/src/net/osmand/plus/parkingpoint/ParkingPositionPlugin.java +++ b/OsmAnd/src/net/osmand/plus/parkingpoint/ParkingPositionPlugin.java @@ -33,6 +33,7 @@ import net.osmand.plus.UiUtilities; import net.osmand.plus.activities.MapActivity; import net.osmand.plus.dashboard.tools.DashFragmentData; import net.osmand.plus.mapcontextmenu.MapContextMenu; +import net.osmand.plus.quickaction.QuickActionType; import net.osmand.plus.views.AnimateDraggingMapThread; import net.osmand.plus.views.MapInfoLayer; 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 java.util.Calendar; +import java.util.List; 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() { return DashParkingFragment.FRAGMENT_DATA; } + + + @Override + protected void registerQuickActionTypes(List quickActionTypes) { + quickActionTypes.add(ParkingAction.TYPE); + } } diff --git a/OsmAnd/src/net/osmand/plus/quickaction/AddQuickActionDialog.java b/OsmAnd/src/net/osmand/plus/quickaction/AddQuickActionDialog.java index 73f39added..aee3452ead 100644 --- a/OsmAnd/src/net/osmand/plus/quickaction/AddQuickActionDialog.java +++ b/OsmAnd/src/net/osmand/plus/quickaction/AddQuickActionDialog.java @@ -48,14 +48,12 @@ public class AddQuickActionDialog extends DialogFragment { public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { getDialog().getWindow().requestFeature(Window.FEATURE_NO_TITLE); - - List active = ((MapActivity) getActivity()) - .getMyApplication() - .getQuickActionRegistry() - .getQuickActions(); + QuickActionRegistry quickActionRegistry = ((MapActivity) getActivity()) + .getMyApplication() + .getQuickActionRegistry(); 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); 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 ITEM = 2; - private List data; + private List data; public class ItemViewHolder extends RecyclerView.ViewHolder { @@ -114,7 +112,7 @@ public class AddQuickActionDialog extends DialogFragment { } } - public Adapter(List data) { + public Adapter(List data) { this.data = data; } @@ -138,7 +136,7 @@ public class AddQuickActionDialog extends DialogFragment { @Override public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) { - final QuickAction action = data.get(position); + final QuickActionType action = data.get(position); if (getItemViewType(position) == HEADER) { @@ -161,7 +159,7 @@ public class AddQuickActionDialog extends DialogFragment { @Override public void onClick(View view) { - CreateEditActionDialog dialog = CreateEditActionDialog.newInstance(action.type); + CreateEditActionDialog dialog = CreateEditActionDialog.newInstance(action.getId()); dialog.show(getFragmentManager(), CreateEditActionDialog.TAG); dismiss(); @@ -179,7 +177,7 @@ public class AddQuickActionDialog extends DialogFragment { @Override public int getItemViewType(int position) { - if (data.get(position).type == 0) + if (data.get(position).getId() == 0) return HEADER; return ITEM; diff --git a/OsmAnd/src/net/osmand/plus/quickaction/CreateEditActionDialog.java b/OsmAnd/src/net/osmand/plus/quickaction/CreateEditActionDialog.java index f4459b0ec2..079157e383 100644 --- a/OsmAnd/src/net/osmand/plus/quickaction/CreateEditActionDialog.java +++ b/OsmAnd/src/net/osmand/plus/quickaction/CreateEditActionDialog.java @@ -123,8 +123,8 @@ public class CreateEditActionDialog extends DialogFragment { ? isNew = actionId == 0 : savedInstanceState.getBoolean(KEY_ACTION_IS_NEW); - action = QuickActionFactory.produceAction(isNew - ? QuickActionFactory.newActionByType(type) + action = QuickActionRegistry.produceAction(isNew + ? quickActionRegistry.newActionByType(type) : quickActionRegistry.getQuickAction(actionId)); setupToolbar(view); @@ -139,7 +139,7 @@ public class CreateEditActionDialog extends DialogFragment { super.onSaveInstanceState(outState); 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); } diff --git a/OsmAnd/src/net/osmand/plus/quickaction/QuickAction.java b/OsmAnd/src/net/osmand/plus/quickaction/QuickAction.java index 2461463749..7a0cdc2c07 100644 --- a/OsmAnd/src/net/osmand/plus/quickaction/QuickAction.java +++ b/OsmAnd/src/net/osmand/plus/quickaction/QuickAction.java @@ -2,19 +2,28 @@ package net.osmand.plus.quickaction; import android.content.Context; +import androidx.annotation.NonNull; import android.view.View; import android.view.ViewGroup; 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.StringRes; import net.osmand.plus.OsmandApplication; import net.osmand.plus.activities.MapActivity; +import net.osmand.plus.quickaction.actions.NewAction; import net.osmand.util.Algorithms; +import java.io.IOException; import java.util.HashMap; import java.util.List; +import java.util.Map; public class QuickAction { @@ -22,68 +31,55 @@ public class QuickAction { void onActionSelected(QuickAction action); } + private static int SEQ = 0; - protected int type; protected long id; - - private @StringRes Integer nameRes; - private @DrawableRes int iconRes; - private boolean isActionEditable; - private String name; - private HashMap params; + private Map params; + private QuickActionType actionType; protected QuickAction() { - this.id = System.currentTimeMillis(); + this(QuickActionRegistry.TYPE_ADD_ITEMS); } - protected QuickAction(int type, @StringRes int nameRes) { - this.id = System.currentTimeMillis(); - this.nameRes = nameRes; - 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(QuickActionType type) { + this.id = System.currentTimeMillis() + (SEQ++); + this.actionType = type; } public QuickAction(QuickAction quickAction) { - this.type = quickAction.type; + this.actionType = quickAction.actionType; this.id = quickAction.id; this.name = quickAction.name; this.params = quickAction.params; - - this.nameRes = QuickActionFactory.getActionName(type); - this.iconRes = QuickActionFactory.getActionIcon(type); - this.isActionEditable = QuickActionFactory.isActionEditable(type); } public int getNameRes() { - return nameRes; + return actionType == null ? 0 : actionType.getNameRes(); } public int getIconRes() { - return iconRes; + return actionType == null ? 0 : actionType.getIconRes(); } public int getIconRes(Context context) { - return iconRes; + return actionType == null ? 0 : actionType.getIconRes(); } public long getId() { return id; } - public long getType() { - return type; + public int getType() { + return actionType.getId(); + } + + public void setActionType(QuickActionType actionType) { + this.actionType = actionType; } public boolean isActionEditable() { - return isActionEditable; + return actionType == null ? false : actionType.isActionEditable(); } public boolean isActionEnable(OsmandApplication app) { @@ -92,16 +88,25 @@ public class QuickAction { public String getName(Context context) { if (Algorithms.isEmpty(name)) { - return nameRes != null ? context.getString(nameRes) : ""; - } else { + return getDefaultName(context); + } else { return name; } } - public HashMap 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 getParams() { + if (params == null) { + params = new HashMap<>(); + } return params; } @@ -109,7 +114,11 @@ public class QuickAction { this.name = name; } - public void setParams(HashMap params) { + public void setId(long id) { + this.id = id; + } + + public void setParams(Map params) { this.params = params; } @@ -121,7 +130,11 @@ public class QuickAction { return getName(application); } - public void setAutoGeneratedTitle(EditText title){ + public QuickActionType getActionType() { + return actionType; + } + + public void setAutoGeneratedTitle(EditText title){ } public void execute(MapActivity activity){}; @@ -130,9 +143,9 @@ public class QuickAction { public boolean hasInstanceInList(List active){ - for (QuickAction action: active){ - if (action.type == type) return true; - } + for (QuickAction action : active) { + if (action.getType() == getType()) return true; + } return false; } @@ -146,7 +159,7 @@ public class QuickAction { QuickAction action = (QuickAction) o; - if (type != action.type) return false; + if (getType() != action.getType()) return false; if (id != action.id) return false; return true; @@ -156,15 +169,12 @@ public class QuickAction { @Override public int hashCode() { - int result = type; + int result = getType(); 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; } public boolean hasCustomName(Context context) { - return !getName(context).equals(context.getString(nameRes)); + return !getName(context).equals(getDefaultName(context)); } } diff --git a/OsmAnd/src/net/osmand/plus/quickaction/QuickActionFactory.java b/OsmAnd/src/net/osmand/plus/quickaction/QuickActionFactory.java deleted file mode 100644 index 2490343962..0000000000 --- a/OsmAnd/src/net/osmand/plus/quickaction/QuickActionFactory.java +++ /dev/null @@ -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 quickActions) { - return new Gson().toJson(quickActions); - } - - public List parseActiveActionsList(String json) { - Type type = new TypeToken>() { - }.getType(); - ArrayList quickActions = new Gson().fromJson(json, type); - return quickActions != null ? quickActions : new ArrayList(); - } - - public static List produceTypeActionsListWithHeaders(List active) { - ArrayList 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 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; - } - } -} diff --git a/OsmAnd/src/net/osmand/plus/quickaction/QuickActionListFragment.java b/OsmAnd/src/net/osmand/plus/quickaction/QuickActionListFragment.java index d07fd08749..e6b0580692 100644 --- a/OsmAnd/src/net/osmand/plus/quickaction/QuickActionListFragment.java +++ b/OsmAnd/src/net/osmand/plus/quickaction/QuickActionListFragment.java @@ -220,7 +220,7 @@ public class QuickActionListFragment extends BaseOsmAndFragment implements Quick @Override public void onBindViewHolder(final RecyclerView.ViewHolder holder, int 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) { final QuickActionItemVH itemVH = (QuickActionItemVH) holder; @@ -271,7 +271,7 @@ public class QuickActionListFragment extends BaseOsmAndFragment implements Quick @Override 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) { diff --git a/OsmAnd/src/net/osmand/plus/quickaction/QuickActionRegistry.java b/OsmAnd/src/net/osmand/plus/quickaction/QuickActionRegistry.java index 07bc2f4202..7564ac6449 100644 --- a/OsmAnd/src/net/osmand/plus/quickaction/QuickActionRegistry.java +++ b/OsmAnd/src/net/osmand/plus/quickaction/QuickActionRegistry.java @@ -3,32 +3,46 @@ package net.osmand.plus.quickaction; import android.content.Context; 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 net.osmand.plus.OsmandPlugin; import net.osmand.plus.OsmandSettings; -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.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.R; +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.MapStyleAction; -import net.osmand.plus.rastermaps.OsmandRasterMapsPlugin; -import net.osmand.plus.srtmplugin.SRTMPlugin; +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.ShowHidePoiAction; +import net.osmand.util.Algorithms; import java.lang.reflect.Type; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.Set; +import java.util.TreeMap; +import java.util.TreeSet; /** * Created by rosty on 12/27/16. @@ -36,188 +50,277 @@ import java.util.Map; public class QuickActionRegistry { - public interface QuickActionUpdatesListener{ + public interface QuickActionUpdatesListener { - void onActionsUpdated(); - } - - private final QuickActionFactory factory; - private final OsmandSettings settings; - - private final List quickActions; - private final Map 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 getQuickActions() { - List actions = new ArrayList<>(); - actions.addAll(quickActions); - return actions; - } - - public List getFilteredQuickActions() { - - List actions = getQuickActions(); - List 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; + void onActionsUpdated(); } - public void addQuickAction(QuickAction action){ - quickActions.add(action); - settings.QUICK_ACTION_LIST.set(factory.quickActionListToString(quickActions)); - } + public static final QuickActionType TYPE_ADD_ITEMS = new QuickActionType(0, ""). + nameRes(R.string.quick_action_add_create_items).category(QuickActionType.CREATE_CATEGORY); + 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; - for (QuickAction action: quickActions){ - if (action.id == id) { - index = quickActions.indexOf(action); - } - } - if (index >= 0) { - quickActions.remove(index); - } - settings.QUICK_ACTION_LIST.set(factory.quickActionListToString(quickActions)); - } + private List quickActions; + private final Map fabStateMap; + private final Gson gson; + private List quickActionTypes = new ArrayList<>(); + private Map quickActionTypesInt = new TreeMap<>(); + private Map quickActionTypesStr = new TreeMap<>(); - public void updateQuickAction(QuickAction action){ - int index = quickActions.indexOf(action); - if (index >= 0) { - quickActions.set(index, action); - } - settings.QUICK_ACTION_LIST.set(factory.quickActionListToString(quickActions)); - } + private QuickActionUpdatesListener updatesListener; - public void updateQuickActions(List quickActions){ - this.quickActions.clear(); - this.quickActions.addAll(quickActions); - settings.QUICK_ACTION_LIST.set(factory.quickActionListToString(this.quickActions)); - } + public QuickActionRegistry(OsmandSettings settings) { + this.settings = settings; + gson = new GsonBuilder().registerTypeAdapter(QuickAction.class, new QuickActionSerializer()).create(); + fabStateMap = getQuickActionFabStateMapFromJson(settings.QUICK_ACTION.get()); + updateActionTypes(); + } - public QuickAction getQuickAction(long id){ - for (QuickAction action: quickActions){ - if (action.id == id) { - return action; - } - } - return null; - } + public void setUpdatesListener(QuickActionUpdatesListener updatesListener) { + this.updatesListener = updatesListener; + } - 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 void notifyUpdates() { + if (updatesListener != null) updatesListener.onActionsUpdated(); + } - 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 List getQuickActions() { + return new ArrayList<>(quickActions); + } - public boolean isQuickActionOn() { - Boolean result = fabStateMap.get(settings.APPLICATION_MODE.get().getStringKey()); - return result != null && result; - } + public List getFilteredQuickActions() { + return getQuickActions(); + } - public void setQuickActionFabState(boolean isOn) { - fabStateMap.put(settings.APPLICATION_MODE.get().getStringKey(), isOn); - settings.QUICK_ACTION.set(new Gson().toJson(fabStateMap)); - } + public void addQuickAction(QuickAction action) { + quickActions.add(action); + saveActions(); + } - private Map getQuickActionFabStateMapFromJson(String json) { - Type type = new TypeToken>() { - }.getType(); - HashMap quickActions = new Gson().fromJson(json, type); + private void saveActions() { + Type type = new TypeToken>() { + }.getType(); + settings.QUICK_ACTION_LIST.set(gson.toJson(quickActions, type)); + } - return quickActions != null ? quickActions : new HashMap(); - } + 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 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 getQuickActionFabStateMapFromJson(String json) { + Type type = new TypeToken>() { + }.getType(); + HashMap quickActions = gson.fromJson(json, type); + + return quickActions != null ? quickActions : new HashMap(); + } + + + private List parseActiveActionsList(String json) { + Type type = new TypeToken>() { + }.getType(); + List quickActions = gson.fromJson(json, type); + List 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 updateActionTypes() { + List 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 quickActionTypesInt = new TreeMap<>(); + Map 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 produceTypeActionsListWithHeaders() { + List 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 result) { + result.add(filter); + Set 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, + JsonSerializer { + + @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) context.deserialize(obj.get("params"), + new TypeToken>() {}.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; + } + } } diff --git a/OsmAnd/src/net/osmand/plus/quickaction/QuickActionType.java b/OsmAnd/src/net/osmand/plus/quickaction/QuickActionType.java new file mode 100644 index 0000000000..4e201d06e0 --- /dev/null +++ b/OsmAnd/src/net/osmand/plus/quickaction/QuickActionType.java @@ -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 cl; + private int category; + + public QuickActionType(int id, String stringId) { + this.id = id; + this.stringId = stringId; + } + + public QuickActionType(int id, String stringId, Class 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; + } +} diff --git a/OsmAnd/src/net/osmand/plus/quickaction/QuickActionsWidget.java b/OsmAnd/src/net/osmand/plus/quickaction/QuickActionsWidget.java index 9de919648a..7a92bcb4dd 100644 --- a/OsmAnd/src/net/osmand/plus/quickaction/QuickActionsWidget.java +++ b/OsmAnd/src/net/osmand/plus/quickaction/QuickActionsWidget.java @@ -221,7 +221,7 @@ public class QuickActionsWidget extends LinearLayout { 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))); ((ImageView) view.findViewById(imageView)) diff --git a/OsmAnd/src/net/osmand/plus/quickaction/SwitchableAction.java b/OsmAnd/src/net/osmand/plus/quickaction/SwitchableAction.java index e804c90018..b2ab9c892d 100644 --- a/OsmAnd/src/net/osmand/plus/quickaction/SwitchableAction.java +++ b/OsmAnd/src/net/osmand/plus/quickaction/SwitchableAction.java @@ -18,6 +18,7 @@ import androidx.fragment.app.FragmentManager; import androidx.recyclerview.widget.ItemTouchHelper; import androidx.recyclerview.widget.RecyclerView; +import net.osmand.plus.OsmandApplication; import net.osmand.plus.R; import net.osmand.plus.activities.MapActivity; import net.osmand.plus.dialogs.SelectMapViewQuickActionsBottomSheet; @@ -37,7 +38,7 @@ public abstract class SwitchableAction extends QuickAction { private transient ItemTouchHelper touchHelper; - protected SwitchableAction(int type) { + protected SwitchableAction(QuickActionType type) { super(type); } @@ -117,7 +118,11 @@ public abstract class SwitchableAction extends QuickAction { fragment.setArguments(args); fragment.show(fm, SelectMapViewQuickActionsBottomSheet.TAG); } - + + public String getSelectedItem(OsmandApplication app) { + return null; + } + protected class Adapter extends RecyclerView.Adapter implements ReorderItemTouchHelperCallback.OnItemMoveCallback { private List itemsList = new ArrayList<>(); diff --git a/OsmAnd/src/net/osmand/plus/quickaction/actions/DayNightModeAction.java b/OsmAnd/src/net/osmand/plus/quickaction/actions/DayNightModeAction.java index f48b590899..f683603672 100644 --- a/OsmAnd/src/net/osmand/plus/quickaction/actions/DayNightModeAction.java +++ b/OsmAnd/src/net/osmand/plus/quickaction/actions/DayNightModeAction.java @@ -11,9 +11,14 @@ import net.osmand.plus.OsmandSettings.DayNightMode; import net.osmand.plus.R; import net.osmand.plus.activities.MapActivity; import net.osmand.plus.quickaction.QuickAction; +import net.osmand.plus.quickaction.QuickActionType; 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);} diff --git a/OsmAnd/src/net/osmand/plus/quickaction/actions/FavoriteAction.java b/OsmAnd/src/net/osmand/plus/quickaction/actions/FavoriteAction.java index 8c17d152a0..15b0951c9a 100644 --- a/OsmAnd/src/net/osmand/plus/quickaction/actions/FavoriteAction.java +++ b/OsmAnd/src/net/osmand/plus/quickaction/actions/FavoriteAction.java @@ -23,12 +23,16 @@ import net.osmand.plus.mapcontextmenu.editors.EditCategoryDialogFragment; import net.osmand.plus.mapcontextmenu.editors.FavoritePointEditor; import net.osmand.plus.mapcontextmenu.editors.SelectCategoryDialogFragment; import net.osmand.plus.quickaction.QuickAction; +import net.osmand.plus.quickaction.QuickActionType; import net.osmand.plus.widgets.AutoCompleteTextViewEx; 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_DIALOG = "dialog"; public static final String KEY_CATEGORY_NAME = "category_name"; diff --git a/OsmAnd/src/net/osmand/plus/quickaction/actions/GPXAction.java b/OsmAnd/src/net/osmand/plus/quickaction/actions/GPXAction.java index 0eadf00279..351fd540aa 100644 --- a/OsmAnd/src/net/osmand/plus/quickaction/actions/GPXAction.java +++ b/OsmAnd/src/net/osmand/plus/quickaction/actions/GPXAction.java @@ -17,11 +17,15 @@ import net.osmand.plus.activities.MapActivity; import net.osmand.plus.mapcontextmenu.editors.EditCategoryDialogFragment; import net.osmand.plus.mapcontextmenu.editors.SelectCategoryDialogFragment; import net.osmand.plus.quickaction.QuickAction; +import net.osmand.plus.quickaction.QuickActionType; import net.osmand.plus.widgets.AutoCompleteTextViewEx; 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_DIALOG = "dialog"; diff --git a/OsmAnd/src/net/osmand/plus/quickaction/actions/MapStyleAction.java b/OsmAnd/src/net/osmand/plus/quickaction/actions/MapStyleAction.java index fb11b3e154..0d63a9d1d6 100644 --- a/OsmAnd/src/net/osmand/plus/quickaction/actions/MapStyleAction.java +++ b/OsmAnd/src/net/osmand/plus/quickaction/actions/MapStyleAction.java @@ -18,6 +18,7 @@ import net.osmand.plus.activities.MapActivity; import net.osmand.plus.dialogs.ConfigureMapMenu; import net.osmand.plus.openseamapsplugin.NauticalMapsPlugin; import net.osmand.plus.quickaction.QuickAction; +import net.osmand.plus.quickaction.QuickActionType; import net.osmand.plus.quickaction.SwitchableAction; import net.osmand.plus.render.RendererRegistry; import net.osmand.plus.views.OsmandMapTileView; @@ -31,9 +32,13 @@ import java.util.List; public class MapStyleAction extends SwitchableAction { - public static final int TYPE = 14; 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() { super(TYPE); @@ -43,6 +48,16 @@ public class MapStyleAction extends SwitchableAction { 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 public void execute(MapActivity activity) { List mapStyles = getFilteredStyles(); diff --git a/OsmAnd/src/net/osmand/plus/quickaction/actions/MarkerAction.java b/OsmAnd/src/net/osmand/plus/quickaction/actions/MarkerAction.java index 64121971a0..ded03b683b 100644 --- a/OsmAnd/src/net/osmand/plus/quickaction/actions/MarkerAction.java +++ b/OsmAnd/src/net/osmand/plus/quickaction/actions/MarkerAction.java @@ -10,10 +10,15 @@ import net.osmand.data.PointDescription; import net.osmand.plus.R; import net.osmand.plus.activities.MapActivity; import net.osmand.plus.quickaction.QuickAction; +import net.osmand.plus.quickaction.QuickActionType; 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() { super(TYPE); diff --git a/OsmAnd/src/net/osmand/plus/quickaction/actions/NavAddDestinationAction.java b/OsmAnd/src/net/osmand/plus/quickaction/actions/NavAddDestinationAction.java index 0646d4053d..5270df5be9 100644 --- a/OsmAnd/src/net/osmand/plus/quickaction/actions/NavAddDestinationAction.java +++ b/OsmAnd/src/net/osmand/plus/quickaction/actions/NavAddDestinationAction.java @@ -9,10 +9,15 @@ import net.osmand.data.LatLon; import net.osmand.plus.R; import net.osmand.plus.activities.MapActivity; import net.osmand.plus.quickaction.QuickAction; +import net.osmand.plus.quickaction.QuickActionType; 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() { super(TYPE); diff --git a/OsmAnd/src/net/osmand/plus/quickaction/actions/NavAddFirstIntermediateAction.java b/OsmAnd/src/net/osmand/plus/quickaction/actions/NavAddFirstIntermediateAction.java index f7700e8fee..536662c1e0 100644 --- a/OsmAnd/src/net/osmand/plus/quickaction/actions/NavAddFirstIntermediateAction.java +++ b/OsmAnd/src/net/osmand/plus/quickaction/actions/NavAddFirstIntermediateAction.java @@ -9,10 +9,14 @@ import net.osmand.data.LatLon; import net.osmand.plus.R; import net.osmand.plus.activities.MapActivity; import net.osmand.plus.quickaction.QuickAction; +import net.osmand.plus.quickaction.QuickActionType; 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() { super(TYPE); diff --git a/OsmAnd/src/net/osmand/plus/quickaction/actions/NavAutoZoomMapAction.java b/OsmAnd/src/net/osmand/plus/quickaction/actions/NavAutoZoomMapAction.java index 1b1026be51..a0e2d1d76d 100644 --- a/OsmAnd/src/net/osmand/plus/quickaction/actions/NavAutoZoomMapAction.java +++ b/OsmAnd/src/net/osmand/plus/quickaction/actions/NavAutoZoomMapAction.java @@ -11,10 +11,15 @@ import net.osmand.plus.OsmandSettings; import net.osmand.plus.R; import net.osmand.plus.activities.MapActivity; import net.osmand.plus.quickaction.QuickAction; +import net.osmand.plus.quickaction.QuickActionType; 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() { super(TYPE); diff --git a/OsmAnd/src/net/osmand/plus/quickaction/actions/NavDirectionsFromAction.java b/OsmAnd/src/net/osmand/plus/quickaction/actions/NavDirectionsFromAction.java index c20af4c8e9..0f940da481 100644 --- a/OsmAnd/src/net/osmand/plus/quickaction/actions/NavDirectionsFromAction.java +++ b/OsmAnd/src/net/osmand/plus/quickaction/actions/NavDirectionsFromAction.java @@ -9,10 +9,14 @@ import net.osmand.data.LatLon; import net.osmand.plus.R; import net.osmand.plus.activities.MapActivity; import net.osmand.plus.quickaction.QuickAction; +import net.osmand.plus.quickaction.QuickActionType; 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() { super(TYPE); diff --git a/OsmAnd/src/net/osmand/plus/quickaction/actions/NavReplaceDestinationAction.java b/OsmAnd/src/net/osmand/plus/quickaction/actions/NavReplaceDestinationAction.java index 7d95615588..8ab75f719d 100644 --- a/OsmAnd/src/net/osmand/plus/quickaction/actions/NavReplaceDestinationAction.java +++ b/OsmAnd/src/net/osmand/plus/quickaction/actions/NavReplaceDestinationAction.java @@ -9,10 +9,14 @@ import net.osmand.data.LatLon; import net.osmand.plus.R; import net.osmand.plus.activities.MapActivity; import net.osmand.plus.quickaction.QuickAction; +import net.osmand.plus.quickaction.QuickActionType; 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() { super(TYPE); diff --git a/OsmAnd/src/net/osmand/plus/quickaction/actions/NavResumePauseAction.java b/OsmAnd/src/net/osmand/plus/quickaction/actions/NavResumePauseAction.java index f94f4b5ec6..839b00025e 100644 --- a/OsmAnd/src/net/osmand/plus/quickaction/actions/NavResumePauseAction.java +++ b/OsmAnd/src/net/osmand/plus/quickaction/actions/NavResumePauseAction.java @@ -10,11 +10,16 @@ import net.osmand.plus.OsmandApplication; import net.osmand.plus.R; import net.osmand.plus.activities.MapActivity; import net.osmand.plus.quickaction.QuickAction; +import net.osmand.plus.quickaction.QuickActionType; import net.osmand.plus.routing.RoutingHelper; 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() { super(TYPE); diff --git a/OsmAnd/src/net/osmand/plus/quickaction/actions/NavStartStopAction.java b/OsmAnd/src/net/osmand/plus/quickaction/actions/NavStartStopAction.java index e5b31fa9a6..76574207e7 100644 --- a/OsmAnd/src/net/osmand/plus/quickaction/actions/NavStartStopAction.java +++ b/OsmAnd/src/net/osmand/plus/quickaction/actions/NavStartStopAction.java @@ -12,12 +12,18 @@ import net.osmand.plus.R; import net.osmand.plus.activities.MapActivity; import net.osmand.plus.mapcontextmenu.other.DestinationReachedMenu; import net.osmand.plus.quickaction.QuickAction; +import net.osmand.plus.quickaction.QuickActionType; import net.osmand.plus.routing.RoutingHelper; public class NavStartStopAction extends QuickAction { - public static final int TYPE = 25; 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() { super(TYPE); diff --git a/OsmAnd/src/net/osmand/plus/quickaction/actions/NavVoiceAction.java b/OsmAnd/src/net/osmand/plus/quickaction/actions/NavVoiceAction.java index 1e4eb81502..48c6b3a7ee 100644 --- a/OsmAnd/src/net/osmand/plus/quickaction/actions/NavVoiceAction.java +++ b/OsmAnd/src/net/osmand/plus/quickaction/actions/NavVoiceAction.java @@ -9,9 +9,13 @@ import net.osmand.plus.OsmandApplication; import net.osmand.plus.R; import net.osmand.plus.activities.MapActivity; import net.osmand.plus.quickaction.QuickAction; +import net.osmand.plus.quickaction.QuickActionType; 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() { super(TYPE); diff --git a/OsmAnd/src/net/osmand/plus/quickaction/actions/NewAction.java b/OsmAnd/src/net/osmand/plus/quickaction/actions/NewAction.java index c0a9bbef5a..dc9d03923a 100644 --- a/OsmAnd/src/net/osmand/plus/quickaction/actions/NewAction.java +++ b/OsmAnd/src/net/osmand/plus/quickaction/actions/NewAction.java @@ -2,13 +2,18 @@ package net.osmand.plus.quickaction.actions; import android.view.ViewGroup; +import net.osmand.plus.R; import net.osmand.plus.activities.MapActivity; import net.osmand.plus.quickaction.AddQuickActionDialog; import net.osmand.plus.quickaction.QuickAction; +import net.osmand.plus.quickaction.QuickActionType; 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() { super(TYPE); diff --git a/OsmAnd/src/net/osmand/plus/quickaction/actions/ShowHideFavoritesAction.java b/OsmAnd/src/net/osmand/plus/quickaction/actions/ShowHideFavoritesAction.java index c6c7abe1b7..9ac29840eb 100644 --- a/OsmAnd/src/net/osmand/plus/quickaction/actions/ShowHideFavoritesAction.java +++ b/OsmAnd/src/net/osmand/plus/quickaction/actions/ShowHideFavoritesAction.java @@ -8,11 +8,18 @@ import android.widget.TextView; import net.osmand.plus.OsmandApplication; import net.osmand.plus.R; import net.osmand.plus.activities.MapActivity; +import net.osmand.plus.audionotes.TakeVideoNoteAction; import net.osmand.plus.quickaction.QuickAction; +import net.osmand.plus.quickaction.QuickActionType; 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() { super(TYPE); diff --git a/OsmAnd/src/net/osmand/plus/quickaction/actions/ShowHideGpxTracksAction.java b/OsmAnd/src/net/osmand/plus/quickaction/actions/ShowHideGpxTracksAction.java index b63f6eff2a..d6501fddb1 100644 --- a/OsmAnd/src/net/osmand/plus/quickaction/actions/ShowHideGpxTracksAction.java +++ b/OsmAnd/src/net/osmand/plus/quickaction/actions/ShowHideGpxTracksAction.java @@ -18,10 +18,16 @@ import net.osmand.plus.R; import net.osmand.plus.activities.MapActivity; import net.osmand.plus.helpers.GpxUiHelper; import net.osmand.plus.quickaction.QuickAction; +import net.osmand.plus.quickaction.QuickActionType; 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() { super(TYPE); diff --git a/OsmAnd/src/net/osmand/plus/quickaction/actions/ShowHidePoiAction.java b/OsmAnd/src/net/osmand/plus/quickaction/actions/ShowHidePoiAction.java index df89591064..2e985e9fd0 100644 --- a/OsmAnd/src/net/osmand/plus/quickaction/actions/ShowHidePoiAction.java +++ b/OsmAnd/src/net/osmand/plus/quickaction/actions/ShowHidePoiAction.java @@ -25,6 +25,7 @@ import net.osmand.plus.activities.MapActivity; import net.osmand.plus.poi.PoiFiltersHelper; import net.osmand.plus.poi.PoiUIFilter; import net.osmand.plus.quickaction.QuickAction; +import net.osmand.plus.quickaction.QuickActionType; import net.osmand.plus.render.RenderingIcons; import java.util.ArrayList; @@ -34,7 +35,12 @@ import java.util.Set; 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"; diff --git a/OsmAnd/src/net/osmand/plus/quickaction/actions/MapOverlayAction.java b/OsmAnd/src/net/osmand/plus/rastermaps/MapOverlayAction.java similarity index 93% rename from OsmAnd/src/net/osmand/plus/quickaction/actions/MapOverlayAction.java rename to OsmAnd/src/net/osmand/plus/rastermaps/MapOverlayAction.java index 57173f820f..26604717bb 100644 --- a/OsmAnd/src/net/osmand/plus/quickaction/actions/MapOverlayAction.java +++ b/OsmAnd/src/net/osmand/plus/rastermaps/MapOverlayAction.java @@ -1,4 +1,4 @@ -package net.osmand.plus.quickaction.actions; +package net.osmand.plus.rastermaps; import android.content.Context; import android.content.DialogInterface; @@ -21,6 +21,7 @@ import net.osmand.plus.R; import net.osmand.plus.UiUtilities; import net.osmand.plus.activities.MapActivity; import net.osmand.plus.quickaction.QuickAction; +import net.osmand.plus.quickaction.QuickActionType; import net.osmand.plus.quickaction.SwitchableAction; import net.osmand.plus.rastermaps.OsmandRasterMapsPlugin; @@ -30,11 +31,16 @@ import java.util.List; import java.util.Map; public class MapOverlayAction extends SwitchableAction> { - public static final int TYPE = 15; private final static String KEY_OVERLAYS = "overlays"; 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() { super(TYPE); } @@ -53,6 +59,11 @@ public class MapOverlayAction extends SwitchableAction> { : filters.get(0).second; } + @Override + public String getSelectedItem(OsmandApplication app) { + return app.getSettings().MAP_OVERLAY.get(); + } + @Override protected void saveListToParams(List> list) { diff --git a/OsmAnd/src/net/osmand/plus/quickaction/actions/MapSourceAction.java b/OsmAnd/src/net/osmand/plus/rastermaps/MapSourceAction.java similarity index 91% rename from OsmAnd/src/net/osmand/plus/quickaction/actions/MapSourceAction.java rename to OsmAnd/src/net/osmand/plus/rastermaps/MapSourceAction.java index eb9dedcec7..6858369543 100644 --- a/OsmAnd/src/net/osmand/plus/quickaction/actions/MapSourceAction.java +++ b/OsmAnd/src/net/osmand/plus/rastermaps/MapSourceAction.java @@ -1,4 +1,4 @@ -package net.osmand.plus.quickaction.actions; +package net.osmand.plus.rastermaps; import android.content.Context; import android.content.DialogInterface; @@ -20,6 +20,7 @@ import net.osmand.plus.R; import net.osmand.plus.UiUtilities; import net.osmand.plus.activities.MapActivity; import net.osmand.plus.quickaction.QuickAction; +import net.osmand.plus.quickaction.QuickActionType; import net.osmand.plus.quickaction.SwitchableAction; import net.osmand.plus.rastermaps.OsmandRasterMapsPlugin; @@ -31,8 +32,11 @@ import java.util.Map; public class MapSourceAction extends SwitchableAction> { - public static final int TYPE = 17; 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"; @@ -54,6 +58,13 @@ public class MapSourceAction extends SwitchableAction> { : 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 protected void saveListToParams(List> list) { diff --git a/OsmAnd/src/net/osmand/plus/quickaction/actions/MapUnderlayAction.java b/OsmAnd/src/net/osmand/plus/rastermaps/MapUnderlayAction.java similarity index 93% rename from OsmAnd/src/net/osmand/plus/quickaction/actions/MapUnderlayAction.java rename to OsmAnd/src/net/osmand/plus/rastermaps/MapUnderlayAction.java index 6c9f2a2d34..329214fa3d 100644 --- a/OsmAnd/src/net/osmand/plus/quickaction/actions/MapUnderlayAction.java +++ b/OsmAnd/src/net/osmand/plus/rastermaps/MapUnderlayAction.java @@ -1,4 +1,4 @@ -package net.osmand.plus.quickaction.actions; +package net.osmand.plus.rastermaps; import android.content.Context; import android.content.DialogInterface; @@ -21,6 +21,7 @@ import net.osmand.plus.R; import net.osmand.plus.UiUtilities; import net.osmand.plus.activities.MapActivity; import net.osmand.plus.quickaction.QuickAction; +import net.osmand.plus.quickaction.QuickActionType; import net.osmand.plus.quickaction.SwitchableAction; import net.osmand.plus.rastermaps.OsmandRasterMapsPlugin; @@ -30,10 +31,14 @@ import java.util.List; import java.util.Map; public class MapUnderlayAction extends SwitchableAction> { - public static final int TYPE = 16; private final static String KEY_UNDERLAYS = "underlays"; 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() { super(TYPE); @@ -53,6 +58,11 @@ public class MapUnderlayAction extends SwitchableAction> { : filters.get(0).second; } + @Override + public String getSelectedItem(OsmandApplication app) { + return app.getSettings().MAP_UNDERLAY.get(); + } + @Override protected void saveListToParams(List> list) { diff --git a/OsmAnd/src/net/osmand/plus/rastermaps/OsmandRasterMapsPlugin.java b/OsmAnd/src/net/osmand/plus/rastermaps/OsmandRasterMapsPlugin.java index 30253d5575..06b44fa287 100644 --- a/OsmAnd/src/net/osmand/plus/rastermaps/OsmandRasterMapsPlugin.java +++ b/OsmAnd/src/net/osmand/plus/rastermaps/OsmandRasterMapsPlugin.java @@ -45,6 +45,7 @@ import net.osmand.plus.activities.MapActivity; import net.osmand.plus.activities.MapActivityLayers; import net.osmand.plus.dashboard.DashboardOnMap.DashboardType; import net.osmand.plus.dialogs.RasterMapMenu; +import net.osmand.plus.quickaction.QuickActionType; import net.osmand.plus.views.MapTileLayer; import net.osmand.plus.views.OsmandMapTileView; import net.osmand.util.Algorithms; @@ -679,4 +680,11 @@ public class OsmandRasterMapsPlugin extends OsmandPlugin { public interface OnMapSelectedCallback { void onMapSelected(boolean canceled); } + + @Override + protected void registerQuickActionTypes(List quickActionTypes) { + quickActionTypes.add(MapSourceAction.TYPE); + quickActionTypes.add(MapOverlayAction.TYPE); + quickActionTypes.add(MapUnderlayAction.TYPE); + } } diff --git a/OsmAnd/src/net/osmand/plus/settings/ExportProfileBottomSheet.java b/OsmAnd/src/net/osmand/plus/settings/ExportProfileBottomSheet.java index b6ac83cf9f..a12fd32fd6 100644 --- a/OsmAnd/src/net/osmand/plus/settings/ExportProfileBottomSheet.java +++ b/OsmAnd/src/net/osmand/plus/settings/ExportProfileBottomSheet.java @@ -39,7 +39,7 @@ import net.osmand.plus.base.bottomsheetmenu.simpleitems.TitleItem; import net.osmand.plus.helpers.AvoidSpecificRoads.AvoidRoadInfo; import net.osmand.plus.poi.PoiUIFilter; 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.ExportImportSettingsAdapter.Type; @@ -218,8 +218,9 @@ public class ExportProfileBottomSheet extends BasePreferenceBottomSheet { private Map> getAdditionalData() { Map> dataList = new HashMap<>(); - QuickActionFactory factory = new QuickActionFactory(); - List actionsList = factory.parseActiveActionsList(app.getSettings().QUICK_ACTION_LIST.get()); + + QuickActionRegistry registry = app.getQuickActionRegistry(); + List actionsList = registry.getQuickActions(); if (!actionsList.isEmpty()) { dataList.put(Type.QUICK_ACTIONS, actionsList); } diff --git a/OsmAnd/src/net/osmand/plus/quickaction/actions/ContourLinesAction.java b/OsmAnd/src/net/osmand/plus/srtmplugin/ContourLinesAction.java similarity index 87% rename from OsmAnd/src/net/osmand/plus/quickaction/actions/ContourLinesAction.java rename to OsmAnd/src/net/osmand/plus/srtmplugin/ContourLinesAction.java index af02530367..676746ab48 100644 --- a/OsmAnd/src/net/osmand/plus/quickaction/actions/ContourLinesAction.java +++ b/OsmAnd/src/net/osmand/plus/srtmplugin/ContourLinesAction.java @@ -1,4 +1,4 @@ -package net.osmand.plus.quickaction.actions; +package net.osmand.plus.srtmplugin; import android.content.Context; import android.view.LayoutInflater; @@ -12,6 +12,7 @@ import net.osmand.plus.OsmandSettings; import net.osmand.plus.R; import net.osmand.plus.activities.MapActivity; import net.osmand.plus.quickaction.QuickAction; +import net.osmand.plus.quickaction.QuickActionType; import net.osmand.plus.srtmplugin.SRTMPlugin; 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 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() { super(TYPE); diff --git a/OsmAnd/src/net/osmand/plus/quickaction/actions/HillshadeAction.java b/OsmAnd/src/net/osmand/plus/srtmplugin/HillshadeAction.java similarity index 83% rename from OsmAnd/src/net/osmand/plus/quickaction/actions/HillshadeAction.java rename to OsmAnd/src/net/osmand/plus/srtmplugin/HillshadeAction.java index 09e30d44b3..0b4b07164a 100644 --- a/OsmAnd/src/net/osmand/plus/quickaction/actions/HillshadeAction.java +++ b/OsmAnd/src/net/osmand/plus/srtmplugin/HillshadeAction.java @@ -1,4 +1,4 @@ -package net.osmand.plus.quickaction.actions; +package net.osmand.plus.srtmplugin; import android.content.Context; import android.view.LayoutInflater; @@ -11,11 +11,16 @@ import net.osmand.plus.OsmandPlugin; import net.osmand.plus.R; import net.osmand.plus.activities.MapActivity; import net.osmand.plus.quickaction.QuickAction; +import net.osmand.plus.quickaction.QuickActionType; import net.osmand.plus.srtmplugin.SRTMPlugin; 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() { super(TYPE); diff --git a/OsmAnd/src/net/osmand/plus/srtmplugin/SRTMPlugin.java b/OsmAnd/src/net/osmand/plus/srtmplugin/SRTMPlugin.java index f564fc05a4..22b918a901 100644 --- a/OsmAnd/src/net/osmand/plus/srtmplugin/SRTMPlugin.java +++ b/OsmAnd/src/net/osmand/plus/srtmplugin/SRTMPlugin.java @@ -30,6 +30,7 @@ import net.osmand.plus.download.DownloadIndexesThread; import net.osmand.plus.download.DownloadResources; import net.osmand.plus.download.IndexItem; import net.osmand.plus.inapp.InAppPurchaseHelper; +import net.osmand.plus.quickaction.QuickActionType; import net.osmand.plus.views.OsmandMapTileView; import net.osmand.render.RenderingRuleProperty; import net.osmand.util.Algorithms; @@ -442,4 +443,10 @@ public class SRTMPlugin extends OsmandPlugin { private static int getThemeRes(Activity activity, OsmandApplication app) { return isNightMode(activity, app) ? R.style.OsmandDarkTheme : R.style.OsmandLightTheme; } + + @Override + protected void registerQuickActionTypes(List quickActionTypes) { + quickActionTypes.add(ContourLinesAction.TYPE); + quickActionTypes.add(HillshadeAction.TYPE); + } } diff --git a/OsmAnd/src/net/osmand/plus/views/MapQuickActionLayer.java b/OsmAnd/src/net/osmand/plus/views/MapQuickActionLayer.java index 30859cd46c..c7f01306f0 100644 --- a/OsmAnd/src/net/osmand/plus/views/MapQuickActionLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/MapQuickActionLayer.java @@ -38,7 +38,6 @@ import net.osmand.plus.mapcontextmenu.MapContextMenuFragment; import net.osmand.plus.mapcontextmenu.other.MapMultiSelectionMenu; import net.osmand.plus.measurementtool.MeasurementToolLayer; import net.osmand.plus.quickaction.QuickAction; -import net.osmand.plus.quickaction.QuickActionFactory; import net.osmand.plus.quickaction.QuickActionRegistry; import net.osmand.plus.quickaction.QuickActionsWidget; import net.osmand.plus.routepreparationmenu.MapRouteInfoMenu; @@ -431,7 +430,7 @@ public class MapQuickActionLayer extends OsmandMapLayer implements QuickActionRe @Override public void onActionSelected(QuickAction action) { - QuickActionFactory.produceAction(action).execute(mapActivity); + QuickActionRegistry.produceAction(action).execute(mapActivity); setLayerState(false); }