Merge pull request #8703 from osmandapp/fixQuickAction
Fix quick action
This commit is contained in:
commit
168a94b210
48 changed files with 769 additions and 932 deletions
|
@ -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<QuickActionType> 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<TabItem> mTabs, Intent intent) {
|
||||
protected void addMyPlacesTab(FavoritesActivity favoritesActivity, List<TabItem> mTabs, Intent intent) {
|
||||
}
|
||||
|
||||
public void contextMenuFragment(Activity activity, Fragment fragment, Object info, ContextMenuAdapter adapter) {
|
||||
protected void contextMenuFragment(Activity activity, Fragment fragment, Object info, ContextMenuAdapter adapter) {
|
||||
}
|
||||
|
||||
public void optionsMenuFragment(Activity activity, Fragment fragment, ContextMenuAdapter optionsMenuAdapter) {
|
||||
protected void optionsMenuFragment(Activity activity, Fragment fragment, ContextMenuAdapter optionsMenuAdapter) {
|
||||
}
|
||||
|
||||
public List<String> indexingFiles(IProgress progress) {
|
||||
|
@ -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<QuickActionType> quickActionTypes) {
|
||||
for (OsmandPlugin p : getEnabledPlugins()) {
|
||||
p.registerQuickActionTypes(quickActionTypes);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static void updateLocationPlugins(net.osmand.Location location) {
|
||||
for (OsmandPlugin p : getEnabledPlugins()) {
|
||||
p.updateLocation(location);
|
||||
|
|
|
@ -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<HashMap<String, String>>() {
|
||||
}.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<String, String> 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<String, String> params = gson.fromJson(paramsString, type);
|
||||
|
||||
if (!name.isEmpty()) {
|
||||
quickAction.setName(name);
|
||||
}
|
||||
quickAction.setParams(params);
|
||||
items.add(quickAction);
|
||||
}
|
||||
quickAction.setParams(params);
|
||||
items.add(quickAction);
|
||||
}
|
||||
} catch (JSONException e) {
|
||||
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);
|
||||
}
|
||||
|
|
|
@ -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<QuickActionType> quickActionTypes) {
|
||||
quickActionTypes.add(TakeAudioNoteAction.TYPE);
|
||||
quickActionTypes.add(TakePhotoNoteAction.TYPE);
|
||||
quickActionTypes.add(TakeVideoNoteAction.TYPE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mapActivityScreenOff(MapActivity activity) {
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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());
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
|
@ -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";
|
||||
|
|
@ -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<QuickActionType> quickActionTypes) {
|
||||
quickActionTypes.add(AddPOIAction.TYPE);
|
||||
quickActionTypes.add(AddOSMBugAction.TYPE);
|
||||
quickActionTypes.add(ShowHideOSMBugAction.TYPE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateLayers(OsmandMapTileView mapView, MapActivity activity) {
|
||||
if (isActive()) {
|
||||
|
|
|
@ -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);
|
|
@ -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);
|
||||
|
|
|
@ -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<QuickActionType> quickActionTypes) {
|
||||
quickActionTypes.add(ParkingAction.TYPE);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<QuickAction> 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<QuickAction> data;
|
||||
private List<QuickActionType> data;
|
||||
|
||||
public class ItemViewHolder extends RecyclerView.ViewHolder {
|
||||
|
||||
|
@ -114,7 +112,7 @@ public class AddQuickActionDialog extends DialogFragment {
|
|||
}
|
||||
}
|
||||
|
||||
public Adapter(List<QuickAction> data) {
|
||||
public Adapter(List<QuickActionType> data) {
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
@ -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<String, String> params;
|
||||
private Map<String, String> 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<String, String> getParams() {
|
||||
public String getRawName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
if (params == null) params = new HashMap<>();
|
||||
@NonNull
|
||||
private String getDefaultName(Context context) {
|
||||
return getNameRes() != 0 ? context.getString(getNameRes()) : "";
|
||||
}
|
||||
|
||||
public Map<String, String> getParams() {
|
||||
if (params == null) {
|
||||
params = new HashMap<>();
|
||||
}
|
||||
return params;
|
||||
}
|
||||
|
||||
|
@ -109,7 +114,11 @@ public class QuickAction {
|
|||
this.name = name;
|
||||
}
|
||||
|
||||
public void setParams(HashMap<String, String> params) {
|
||||
public void setId(long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public void setParams(Map<String, String> params) {
|
||||
this.params = params;
|
||||
}
|
||||
|
||||
|
@ -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<QuickAction> 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));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,595 +0,0 @@
|
|||
package net.osmand.plus.quickaction;
|
||||
|
||||
import androidx.annotation.DrawableRes;
|
||||
import androidx.annotation.StringRes;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
|
||||
import net.osmand.plus.OsmandPlugin;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.audionotes.AudioVideoNotesPlugin;
|
||||
import net.osmand.plus.audionotes.TakeAudioNoteAction;
|
||||
import net.osmand.plus.audionotes.TakePhotoNoteAction;
|
||||
import net.osmand.plus.audionotes.TakeVideoNoteAction;
|
||||
import net.osmand.plus.osmedit.OsmEditingPlugin;
|
||||
import net.osmand.plus.parkingpoint.ParkingAction;
|
||||
import net.osmand.plus.parkingpoint.ParkingPositionPlugin;
|
||||
import net.osmand.plus.quickaction.actions.AddOSMBugAction;
|
||||
import net.osmand.plus.quickaction.actions.AddPOIAction;
|
||||
import net.osmand.plus.quickaction.actions.ContourLinesAction;
|
||||
import net.osmand.plus.quickaction.actions.DayNightModeAction;
|
||||
import net.osmand.plus.quickaction.actions.FavoriteAction;
|
||||
import net.osmand.plus.quickaction.actions.GPXAction;
|
||||
import net.osmand.plus.quickaction.actions.HillshadeAction;
|
||||
import net.osmand.plus.quickaction.actions.MapOverlayAction;
|
||||
import net.osmand.plus.quickaction.actions.MapSourceAction;
|
||||
import net.osmand.plus.quickaction.actions.MapStyleAction;
|
||||
import net.osmand.plus.quickaction.actions.MapUnderlayAction;
|
||||
import net.osmand.plus.quickaction.actions.MarkerAction;
|
||||
import net.osmand.plus.quickaction.actions.NavAddDestinationAction;
|
||||
import net.osmand.plus.quickaction.actions.NavAddFirstIntermediateAction;
|
||||
import net.osmand.plus.quickaction.actions.NavAutoZoomMapAction;
|
||||
import net.osmand.plus.quickaction.actions.NavDirectionsFromAction;
|
||||
import net.osmand.plus.quickaction.actions.NavReplaceDestinationAction;
|
||||
import net.osmand.plus.quickaction.actions.NavResumePauseAction;
|
||||
import net.osmand.plus.quickaction.actions.NavStartStopAction;
|
||||
import net.osmand.plus.quickaction.actions.NavVoiceAction;
|
||||
import net.osmand.plus.quickaction.actions.NewAction;
|
||||
import net.osmand.plus.quickaction.actions.ShowHideFavoritesAction;
|
||||
import net.osmand.plus.quickaction.actions.ShowHideGpxTracksAction;
|
||||
import net.osmand.plus.quickaction.actions.ShowHideOSMBugAction;
|
||||
import net.osmand.plus.quickaction.actions.ShowHidePoiAction;
|
||||
import net.osmand.plus.rastermaps.OsmandRasterMapsPlugin;
|
||||
import net.osmand.plus.srtmplugin.SRTMPlugin;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class QuickActionFactory {
|
||||
|
||||
public String quickActionListToString(List<QuickAction> quickActions) {
|
||||
return new Gson().toJson(quickActions);
|
||||
}
|
||||
|
||||
public List<QuickAction> parseActiveActionsList(String json) {
|
||||
Type type = new TypeToken<List<QuickAction>>() {
|
||||
}.getType();
|
||||
ArrayList<QuickAction> quickActions = new Gson().fromJson(json, type);
|
||||
return quickActions != null ? quickActions : new ArrayList<QuickAction>();
|
||||
}
|
||||
|
||||
public static List<QuickAction> produceTypeActionsListWithHeaders(List<QuickAction> active) {
|
||||
ArrayList<QuickAction> quickActions = new ArrayList<>();
|
||||
quickActions.add(new QuickAction(0, R.string.quick_action_add_create_items));
|
||||
quickActions.add(new FavoriteAction());
|
||||
quickActions.add(new GPXAction());
|
||||
QuickAction marker = new MarkerAction();
|
||||
|
||||
if (!marker.hasInstanceInList(active)) {
|
||||
quickActions.add(marker);
|
||||
}
|
||||
|
||||
if (OsmandPlugin.getEnabledPlugin(AudioVideoNotesPlugin.class) != null) {
|
||||
QuickAction audio = new TakeAudioNoteAction();
|
||||
QuickAction photo = new TakePhotoNoteAction();
|
||||
QuickAction video = new TakeVideoNoteAction();
|
||||
|
||||
if (!audio.hasInstanceInList(active)) {
|
||||
quickActions.add(audio);
|
||||
}
|
||||
|
||||
if (!photo.hasInstanceInList(active)) {
|
||||
quickActions.add(photo);
|
||||
}
|
||||
|
||||
if (!video.hasInstanceInList(active)) {
|
||||
quickActions.add(video);
|
||||
}
|
||||
}
|
||||
|
||||
if (OsmandPlugin.getEnabledPlugin(OsmEditingPlugin.class) != null) {
|
||||
quickActions.add(new AddPOIAction());
|
||||
quickActions.add(new AddOSMBugAction());
|
||||
}
|
||||
|
||||
if (OsmandPlugin.getEnabledPlugin(ParkingPositionPlugin.class) != null) {
|
||||
QuickAction parking = new ParkingAction();
|
||||
if (!parking.hasInstanceInList(active)) {
|
||||
quickActions.add(parking);
|
||||
}
|
||||
}
|
||||
|
||||
quickActions.add(new QuickAction(0, R.string.quick_action_add_configure_map));
|
||||
|
||||
QuickAction favorites = new ShowHideFavoritesAction();
|
||||
if (!favorites.hasInstanceInList(active)) {
|
||||
quickActions.add(favorites);
|
||||
}
|
||||
|
||||
quickActions.add(new ShowHideGpxTracksAction());
|
||||
|
||||
quickActions.add(new ShowHidePoiAction());
|
||||
if (OsmandPlugin.getEnabledPlugin(OsmEditingPlugin.class) != null) {
|
||||
QuickAction showHideOSMBugAction = new ShowHideOSMBugAction();
|
||||
if (!showHideOSMBugAction.hasInstanceInList(active)) {
|
||||
quickActions.add(showHideOSMBugAction);
|
||||
}
|
||||
}
|
||||
|
||||
quickActions.add(new MapStyleAction());
|
||||
if (OsmandPlugin.getEnabledPlugin(OsmandRasterMapsPlugin.class) != null) {
|
||||
quickActions.add(new MapSourceAction());
|
||||
quickActions.add(new MapOverlayAction());
|
||||
quickActions.add(new MapUnderlayAction());
|
||||
}
|
||||
|
||||
if (OsmandPlugin.getEnabledPlugin(SRTMPlugin.class) != null) {
|
||||
quickActions.add(new ContourLinesAction());
|
||||
quickActions.add(new HillshadeAction());
|
||||
}
|
||||
|
||||
quickActions.add(new DayNightModeAction());
|
||||
|
||||
|
||||
QuickAction voice = new NavVoiceAction();
|
||||
QuickAction directionFrom = new NavDirectionsFromAction();
|
||||
QuickAction addDestination = new NavAddDestinationAction();
|
||||
QuickAction addFirstIntermediate = new NavAddFirstIntermediateAction();
|
||||
QuickAction replaceDestination = new NavReplaceDestinationAction();
|
||||
QuickAction autoZoomMap = new NavAutoZoomMapAction();
|
||||
QuickAction startStopNavigation = new NavStartStopAction();
|
||||
QuickAction resumePauseNavigation = new NavResumePauseAction();
|
||||
|
||||
ArrayList<QuickAction> navigationQuickActions = new ArrayList<>();
|
||||
|
||||
if (!voice.hasInstanceInList(active)) {
|
||||
navigationQuickActions.add(voice);
|
||||
}
|
||||
if (!directionFrom.hasInstanceInList(active)) {
|
||||
navigationQuickActions.add(directionFrom);
|
||||
}
|
||||
if (!addDestination.hasInstanceInList(active)) {
|
||||
navigationQuickActions.add(addDestination);
|
||||
}
|
||||
if (!addFirstIntermediate.hasInstanceInList(active)) {
|
||||
navigationQuickActions.add(addFirstIntermediate);
|
||||
}
|
||||
if (!replaceDestination.hasInstanceInList(active)) {
|
||||
navigationQuickActions.add(replaceDestination);
|
||||
}
|
||||
if (!autoZoomMap.hasInstanceInList(active)) {
|
||||
navigationQuickActions.add(autoZoomMap);
|
||||
}
|
||||
if (!startStopNavigation.hasInstanceInList(active)) {
|
||||
navigationQuickActions.add(startStopNavigation);
|
||||
}
|
||||
if (!resumePauseNavigation.hasInstanceInList(active)) {
|
||||
navigationQuickActions.add(resumePauseNavigation);
|
||||
}
|
||||
|
||||
if (navigationQuickActions.size() > 0) {
|
||||
quickActions.add(new QuickAction(0, R.string.quick_action_add_navigation));
|
||||
quickActions.addAll(navigationQuickActions);
|
||||
}
|
||||
|
||||
return quickActions;
|
||||
}
|
||||
|
||||
public static QuickAction newActionByType(int type) {
|
||||
|
||||
switch (type) {
|
||||
|
||||
case NewAction.TYPE:
|
||||
return new NewAction();
|
||||
|
||||
case MarkerAction.TYPE:
|
||||
return new MarkerAction();
|
||||
|
||||
case FavoriteAction.TYPE:
|
||||
return new FavoriteAction();
|
||||
|
||||
case ShowHideFavoritesAction.TYPE:
|
||||
return new ShowHideFavoritesAction();
|
||||
|
||||
case ShowHidePoiAction.TYPE:
|
||||
return new ShowHidePoiAction();
|
||||
|
||||
case GPXAction.TYPE:
|
||||
return new GPXAction();
|
||||
|
||||
case ParkingAction.TYPE:
|
||||
return new ParkingAction();
|
||||
|
||||
case TakeAudioNoteAction.TYPE:
|
||||
return new TakeAudioNoteAction();
|
||||
|
||||
case TakePhotoNoteAction.TYPE:
|
||||
return new TakePhotoNoteAction();
|
||||
|
||||
case TakeVideoNoteAction.TYPE:
|
||||
return new TakeVideoNoteAction();
|
||||
|
||||
case NavVoiceAction.TYPE:
|
||||
return new NavVoiceAction();
|
||||
|
||||
case ShowHideOSMBugAction.TYPE:
|
||||
return new ShowHideOSMBugAction();
|
||||
|
||||
case AddOSMBugAction.TYPE:
|
||||
return new AddOSMBugAction();
|
||||
|
||||
case AddPOIAction.TYPE:
|
||||
return new AddPOIAction();
|
||||
|
||||
case MapStyleAction.TYPE:
|
||||
return new MapStyleAction();
|
||||
|
||||
case MapSourceAction.TYPE:
|
||||
return new MapSourceAction();
|
||||
|
||||
case MapOverlayAction.TYPE:
|
||||
return new MapOverlayAction();
|
||||
|
||||
case MapUnderlayAction.TYPE:
|
||||
return new MapUnderlayAction();
|
||||
|
||||
case NavDirectionsFromAction.TYPE:
|
||||
return new NavDirectionsFromAction();
|
||||
|
||||
case NavAddDestinationAction.TYPE:
|
||||
return new NavAddDestinationAction();
|
||||
|
||||
case NavAddFirstIntermediateAction.TYPE:
|
||||
return new NavAddFirstIntermediateAction();
|
||||
|
||||
case NavReplaceDestinationAction.TYPE:
|
||||
return new NavReplaceDestinationAction();
|
||||
|
||||
case NavAutoZoomMapAction.TYPE:
|
||||
return new NavAutoZoomMapAction();
|
||||
|
||||
case NavStartStopAction.TYPE:
|
||||
return new NavStartStopAction();
|
||||
|
||||
case NavResumePauseAction.TYPE:
|
||||
return new NavResumePauseAction();
|
||||
|
||||
case DayNightModeAction.TYPE:
|
||||
return new DayNightModeAction();
|
||||
|
||||
case ShowHideGpxTracksAction.TYPE:
|
||||
return new ShowHideGpxTracksAction();
|
||||
|
||||
case ContourLinesAction.TYPE:
|
||||
return new ContourLinesAction();
|
||||
|
||||
case HillshadeAction.TYPE:
|
||||
return new HillshadeAction();
|
||||
|
||||
default:
|
||||
return new QuickAction();
|
||||
}
|
||||
}
|
||||
|
||||
public static QuickAction produceAction(QuickAction quickAction) {
|
||||
|
||||
switch (quickAction.type) {
|
||||
|
||||
case NewAction.TYPE:
|
||||
return new NewAction(quickAction);
|
||||
|
||||
case MarkerAction.TYPE:
|
||||
return new MarkerAction(quickAction);
|
||||
|
||||
case FavoriteAction.TYPE:
|
||||
return new FavoriteAction(quickAction);
|
||||
|
||||
case ShowHideFavoritesAction.TYPE:
|
||||
return new ShowHideFavoritesAction(quickAction);
|
||||
|
||||
case ShowHidePoiAction.TYPE:
|
||||
return new ShowHidePoiAction(quickAction);
|
||||
|
||||
case GPXAction.TYPE:
|
||||
return new GPXAction(quickAction);
|
||||
|
||||
case ParkingAction.TYPE:
|
||||
return new ParkingAction(quickAction);
|
||||
|
||||
case TakeAudioNoteAction.TYPE:
|
||||
return new TakeAudioNoteAction(quickAction);
|
||||
|
||||
case TakePhotoNoteAction.TYPE:
|
||||
return new TakePhotoNoteAction(quickAction);
|
||||
|
||||
case TakeVideoNoteAction.TYPE:
|
||||
return new TakeVideoNoteAction(quickAction);
|
||||
|
||||
case NavVoiceAction.TYPE:
|
||||
return new NavVoiceAction(quickAction);
|
||||
|
||||
case ShowHideOSMBugAction.TYPE:
|
||||
return new ShowHideOSMBugAction(quickAction);
|
||||
|
||||
case AddOSMBugAction.TYPE:
|
||||
return new AddOSMBugAction(quickAction);
|
||||
|
||||
case AddPOIAction.TYPE:
|
||||
return new AddPOIAction(quickAction);
|
||||
|
||||
case MapStyleAction.TYPE:
|
||||
return new MapStyleAction(quickAction);
|
||||
|
||||
case MapSourceAction.TYPE:
|
||||
return new MapSourceAction(quickAction);
|
||||
|
||||
case MapOverlayAction.TYPE:
|
||||
return new MapOverlayAction(quickAction);
|
||||
|
||||
case MapUnderlayAction.TYPE:
|
||||
return new MapUnderlayAction(quickAction);
|
||||
|
||||
case NavDirectionsFromAction.TYPE:
|
||||
return new NavDirectionsFromAction(quickAction);
|
||||
|
||||
case NavAddDestinationAction.TYPE:
|
||||
return new NavAddDestinationAction(quickAction);
|
||||
|
||||
case NavAddFirstIntermediateAction.TYPE:
|
||||
return new NavAddFirstIntermediateAction(quickAction);
|
||||
|
||||
case NavReplaceDestinationAction.TYPE:
|
||||
return new NavReplaceDestinationAction(quickAction);
|
||||
|
||||
case NavAutoZoomMapAction.TYPE:
|
||||
return new NavAutoZoomMapAction(quickAction);
|
||||
|
||||
case NavStartStopAction.TYPE:
|
||||
return new NavStartStopAction(quickAction);
|
||||
|
||||
case NavResumePauseAction.TYPE:
|
||||
return new NavResumePauseAction(quickAction);
|
||||
|
||||
case DayNightModeAction.TYPE:
|
||||
return new DayNightModeAction(quickAction);
|
||||
|
||||
case ShowHideGpxTracksAction.TYPE:
|
||||
return new ShowHideGpxTracksAction(quickAction);
|
||||
|
||||
case ContourLinesAction.TYPE:
|
||||
return new ContourLinesAction(quickAction);
|
||||
|
||||
case HillshadeAction.TYPE:
|
||||
return new HillshadeAction(quickAction);
|
||||
|
||||
default:
|
||||
return quickAction;
|
||||
}
|
||||
}
|
||||
|
||||
public static @DrawableRes int getActionIcon(int type) {
|
||||
|
||||
switch (type) {
|
||||
|
||||
case NewAction.TYPE:
|
||||
return R.drawable.ic_action_plus;
|
||||
|
||||
case MarkerAction.TYPE:
|
||||
return R.drawable.ic_action_flag_dark;
|
||||
|
||||
case FavoriteAction.TYPE:
|
||||
return R.drawable.ic_action_fav_dark;
|
||||
|
||||
case ShowHideFavoritesAction.TYPE:
|
||||
return R.drawable.ic_action_fav_dark;
|
||||
|
||||
case ShowHidePoiAction.TYPE:
|
||||
return R.drawable.ic_action_gabout_dark;
|
||||
|
||||
case GPXAction.TYPE:
|
||||
return R.drawable.ic_action_flag_dark;
|
||||
|
||||
case ParkingAction.TYPE:
|
||||
return R.drawable.ic_action_parking_dark;
|
||||
|
||||
case TakeAudioNoteAction.TYPE:
|
||||
return R.drawable.ic_action_micro_dark;
|
||||
|
||||
case TakePhotoNoteAction.TYPE:
|
||||
return R.drawable.ic_action_photo_dark;
|
||||
|
||||
case TakeVideoNoteAction.TYPE:
|
||||
return R.drawable.ic_action_video_dark;
|
||||
|
||||
case NavVoiceAction.TYPE:
|
||||
return R.drawable.ic_action_volume_up;
|
||||
|
||||
case ShowHideOSMBugAction.TYPE:
|
||||
return R.drawable.ic_action_bug_dark;
|
||||
|
||||
case AddOSMBugAction.TYPE:
|
||||
return R.drawable.ic_action_bug_dark;
|
||||
|
||||
case AddPOIAction.TYPE:
|
||||
return R.drawable.ic_action_gabout_dark;
|
||||
|
||||
case MapStyleAction.TYPE:
|
||||
return R.drawable.ic_map;
|
||||
|
||||
case MapSourceAction.TYPE:
|
||||
return R.drawable.ic_world_globe_dark;
|
||||
|
||||
case MapOverlayAction.TYPE:
|
||||
return R.drawable.ic_layer_top;
|
||||
|
||||
case MapUnderlayAction.TYPE:
|
||||
return R.drawable.ic_layer_bottom;
|
||||
|
||||
case NavDirectionsFromAction.TYPE:
|
||||
return R.drawable.ic_action_route_direction_from_here;
|
||||
|
||||
case NavAddDestinationAction.TYPE:
|
||||
return R.drawable.ic_action_point_add_destination;
|
||||
|
||||
case NavAddFirstIntermediateAction.TYPE:
|
||||
return R.drawable.ic_action_intermediate;
|
||||
|
||||
case NavReplaceDestinationAction.TYPE:
|
||||
return R.drawable.ic_action_point_add_destination;
|
||||
|
||||
case NavAutoZoomMapAction.TYPE:
|
||||
return R.drawable.ic_action_search_dark;
|
||||
|
||||
case NavStartStopAction.TYPE:
|
||||
return R.drawable.ic_action_start_navigation;
|
||||
|
||||
case NavResumePauseAction.TYPE:
|
||||
return R.drawable.ic_play_dark;
|
||||
|
||||
case DayNightModeAction.TYPE:
|
||||
return R.drawable.ic_action_map_day;
|
||||
|
||||
case ShowHideGpxTracksAction.TYPE:
|
||||
return R.drawable.ic_gpx_track;
|
||||
|
||||
case ContourLinesAction.TYPE:
|
||||
return R.drawable.ic_plugin_srtm;
|
||||
|
||||
case HillshadeAction.TYPE:
|
||||
return R.drawable.ic_action_hillshade_dark;
|
||||
|
||||
default:
|
||||
return R.drawable.ic_action_plus;
|
||||
}
|
||||
}
|
||||
|
||||
public static @StringRes int getActionName(int type) {
|
||||
|
||||
switch (type) {
|
||||
|
||||
case NewAction.TYPE:
|
||||
return R.string.quick_action_new_action;
|
||||
|
||||
case MarkerAction.TYPE:
|
||||
return R.string.quick_action_add_marker;
|
||||
|
||||
case FavoriteAction.TYPE:
|
||||
return R.string.quick_action_add_favorite;
|
||||
|
||||
case ShowHideFavoritesAction.TYPE:
|
||||
return R.string.quick_action_showhide_favorites_title;
|
||||
|
||||
case ShowHidePoiAction.TYPE:
|
||||
return R.string.quick_action_showhide_poi_title;
|
||||
|
||||
case GPXAction.TYPE:
|
||||
return R.string.quick_action_add_gpx;
|
||||
|
||||
case ParkingAction.TYPE:
|
||||
return R.string.quick_action_add_parking;
|
||||
|
||||
case TakeAudioNoteAction.TYPE:
|
||||
return R.string.quick_action_take_audio_note;
|
||||
|
||||
case TakePhotoNoteAction.TYPE:
|
||||
return R.string.quick_action_take_photo_note;
|
||||
|
||||
case TakeVideoNoteAction.TYPE:
|
||||
return R.string.quick_action_take_video_note;
|
||||
|
||||
case NavVoiceAction.TYPE:
|
||||
return R.string.quick_action_navigation_voice;
|
||||
|
||||
case ShowHideOSMBugAction.TYPE:
|
||||
return R.string.quick_action_showhide_osmbugs_title;
|
||||
|
||||
case AddOSMBugAction.TYPE:
|
||||
return R.string.quick_action_add_osm_bug;
|
||||
|
||||
case AddPOIAction.TYPE:
|
||||
return R.string.quick_action_add_poi;
|
||||
|
||||
case MapStyleAction.TYPE:
|
||||
return R.string.quick_action_map_style;
|
||||
|
||||
case MapSourceAction.TYPE:
|
||||
return R.string.quick_action_map_source;
|
||||
|
||||
case MapOverlayAction.TYPE:
|
||||
return R.string.quick_action_map_overlay;
|
||||
|
||||
case MapUnderlayAction.TYPE:
|
||||
return R.string.quick_action_map_underlay;
|
||||
|
||||
case DayNightModeAction.TYPE:
|
||||
return R.string.quick_action_day_night_switch_mode;
|
||||
|
||||
case NavDirectionsFromAction.TYPE:
|
||||
return R.string.context_menu_item_directions_from;
|
||||
|
||||
case NavAddDestinationAction.TYPE:
|
||||
return R.string.quick_action_add_destination;
|
||||
|
||||
case NavAddFirstIntermediateAction.TYPE:
|
||||
return R.string.quick_action_add_first_intermediate;
|
||||
|
||||
case NavReplaceDestinationAction.TYPE:
|
||||
return R.string.quick_action_replace_destination;
|
||||
|
||||
case NavAutoZoomMapAction.TYPE:
|
||||
return R.string.quick_action_auto_zoom;
|
||||
|
||||
case NavStartStopAction.TYPE:
|
||||
return R.string.quick_action_start_stop_navigation;
|
||||
|
||||
case NavResumePauseAction.TYPE:
|
||||
return R.string.quick_action_resume_pause_navigation;
|
||||
|
||||
case ShowHideGpxTracksAction.TYPE:
|
||||
return R.string.quick_action_show_hide_gpx_tracks;
|
||||
|
||||
case ContourLinesAction.TYPE:
|
||||
return R.string.quick_action_show_hide_contour_lines;
|
||||
|
||||
case HillshadeAction.TYPE:
|
||||
return R.string.quick_action_show_hide_hillshade;
|
||||
|
||||
default:
|
||||
return R.string.quick_action_new_action;
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean isActionEditable(int type) {
|
||||
|
||||
switch (type) {
|
||||
|
||||
case NewAction.TYPE:
|
||||
case MarkerAction.TYPE:
|
||||
case ShowHideFavoritesAction.TYPE:
|
||||
case ShowHidePoiAction.TYPE:
|
||||
case ParkingAction.TYPE:
|
||||
case TakeAudioNoteAction.TYPE:
|
||||
case TakePhotoNoteAction.TYPE:
|
||||
case TakeVideoNoteAction.TYPE:
|
||||
case NavVoiceAction.TYPE:
|
||||
case NavDirectionsFromAction.TYPE:
|
||||
case NavAddDestinationAction.TYPE:
|
||||
case NavAddFirstIntermediateAction.TYPE:
|
||||
case NavReplaceDestinationAction.TYPE:
|
||||
case NavAutoZoomMapAction.TYPE:
|
||||
case ShowHideOSMBugAction.TYPE:
|
||||
case NavStartStopAction.TYPE:
|
||||
case NavResumePauseAction.TYPE:
|
||||
case DayNightModeAction.TYPE:
|
||||
case ShowHideGpxTracksAction.TYPE:
|
||||
case ContourLinesAction.TYPE:
|
||||
case HillshadeAction.TYPE:
|
||||
return false;
|
||||
|
||||
default:
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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) {
|
||||
|
|
|
@ -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<QuickAction> quickActions;
|
||||
private final Map<String, Boolean> fabStateMap;
|
||||
|
||||
private QuickActionUpdatesListener updatesListener;
|
||||
|
||||
public QuickActionRegistry(OsmandSettings settings) {
|
||||
|
||||
this.factory = new QuickActionFactory();
|
||||
this.settings = settings;
|
||||
|
||||
quickActions = factory.parseActiveActionsList(settings.QUICK_ACTION_LIST.get());
|
||||
fabStateMap = getQuickActionFabStateMapFromJson(settings.QUICK_ACTION.get());
|
||||
}
|
||||
|
||||
public void setUpdatesListener(QuickActionUpdatesListener updatesListener) {
|
||||
this.updatesListener = updatesListener;
|
||||
}
|
||||
|
||||
public void notifyUpdates() {
|
||||
if (updatesListener != null) updatesListener.onActionsUpdated();
|
||||
}
|
||||
|
||||
public List<QuickAction> getQuickActions() {
|
||||
List<QuickAction> actions = new ArrayList<>();
|
||||
actions.addAll(quickActions);
|
||||
return actions;
|
||||
}
|
||||
|
||||
public List<QuickAction> getFilteredQuickActions() {
|
||||
|
||||
List<QuickAction> actions = getQuickActions();
|
||||
List<QuickAction> filteredActions = new ArrayList<>();
|
||||
|
||||
for (QuickAction action : actions) {
|
||||
boolean skip = false;
|
||||
if (OsmandPlugin.getEnabledPlugin(AudioVideoNotesPlugin.class) == null) {
|
||||
|
||||
if (action.type == TakeAudioNoteAction.TYPE || action.type == TakePhotoNoteAction.TYPE
|
||||
|| action.type == TakeVideoNoteAction.TYPE) {
|
||||
skip = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (OsmandPlugin.getEnabledPlugin(ParkingPositionPlugin.class) == null) {
|
||||
if (action.type == ParkingAction.TYPE) {
|
||||
skip = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (OsmandPlugin.getEnabledPlugin(NauticalMapsPlugin.class) == null) {
|
||||
if (action.type == MapStyleAction.TYPE) {
|
||||
if (((MapStyleAction) QuickActionFactory.produceAction(action)).getFilteredStyles().isEmpty()) {
|
||||
skip = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (OsmandPlugin.getEnabledPlugin(OsmandRasterMapsPlugin.class) == null) {
|
||||
if (action.type == MapSourceAction.TYPE) {
|
||||
skip = true;
|
||||
}
|
||||
}
|
||||
if (OsmandPlugin.getEnabledPlugin(OsmEditingPlugin.class) == null) {
|
||||
if (action.type == AddPOIAction.TYPE) {
|
||||
skip = true;
|
||||
}
|
||||
if (action.type == AddOSMBugAction.TYPE) {
|
||||
skip = true;
|
||||
}
|
||||
}
|
||||
if (OsmandPlugin.getEnabledPlugin(SRTMPlugin.class) == null) {
|
||||
if (action.type == ContourLinesAction.TYPE) {
|
||||
skip = true;
|
||||
}
|
||||
if (action.type == HillshadeAction.TYPE) {
|
||||
skip = true;
|
||||
}
|
||||
}
|
||||
if (!skip) {
|
||||
filteredActions.add(action);
|
||||
}
|
||||
}
|
||||
|
||||
return filteredActions;
|
||||
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<QuickAction> quickActions;
|
||||
private final Map<String, Boolean> fabStateMap;
|
||||
private final Gson gson;
|
||||
private List<QuickActionType> quickActionTypes = new ArrayList<>();
|
||||
private Map<Integer, QuickActionType> quickActionTypesInt = new TreeMap<>();
|
||||
private Map<String, QuickActionType> 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<QuickAction> 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<QuickAction> getQuickActions() {
|
||||
return new ArrayList<>(quickActions);
|
||||
}
|
||||
|
||||
public boolean isQuickActionOn() {
|
||||
Boolean result = fabStateMap.get(settings.APPLICATION_MODE.get().getStringKey());
|
||||
return result != null && result;
|
||||
}
|
||||
public List<QuickAction> 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<String, Boolean> getQuickActionFabStateMapFromJson(String json) {
|
||||
Type type = new TypeToken<HashMap<String, Boolean>>() {
|
||||
}.getType();
|
||||
HashMap<String, Boolean> quickActions = new Gson().fromJson(json, type);
|
||||
private void saveActions() {
|
||||
Type type = new TypeToken<List<QuickAction>>() {
|
||||
}.getType();
|
||||
settings.QUICK_ACTION_LIST.set(gson.toJson(quickActions, type));
|
||||
}
|
||||
|
||||
return quickActions != null ? quickActions : new HashMap<String, Boolean>();
|
||||
}
|
||||
public void deleteQuickAction(QuickAction action) {
|
||||
quickActions.remove(action);
|
||||
saveActions();
|
||||
}
|
||||
|
||||
public void updateQuickAction(QuickAction action) {
|
||||
int index = quickActions.indexOf(action);
|
||||
if (index >= 0) {
|
||||
quickActions.set(index, action);
|
||||
}
|
||||
saveActions();
|
||||
}
|
||||
|
||||
public void updateQuickActions(List<QuickAction> quickActions) {
|
||||
this.quickActions.clear();
|
||||
this.quickActions.addAll(quickActions);
|
||||
saveActions();
|
||||
}
|
||||
|
||||
public QuickAction getQuickAction(long id) {
|
||||
for (QuickAction action : quickActions) {
|
||||
if (action.id == id) {
|
||||
return action;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public boolean isNameUnique(QuickAction action, Context context) {
|
||||
for (QuickAction a : quickActions) {
|
||||
if (action.id != a.id) {
|
||||
if (action.getName(context).equals(a.getName(context))) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public QuickAction generateUniqueName(QuickAction action, Context context) {
|
||||
int number = 0;
|
||||
String name = action.getName(context);
|
||||
while (true) {
|
||||
number++;
|
||||
action.setName(name + " (" + number + ")");
|
||||
if (isNameUnique(action, context)) {
|
||||
return action;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isQuickActionOn() {
|
||||
Boolean result = fabStateMap.get(settings.APPLICATION_MODE.get().getStringKey());
|
||||
return result != null && result;
|
||||
}
|
||||
|
||||
public void setQuickActionFabState(boolean isOn) {
|
||||
fabStateMap.put(settings.APPLICATION_MODE.get().getStringKey(), isOn);
|
||||
settings.QUICK_ACTION.set(gson.toJson(fabStateMap));
|
||||
}
|
||||
|
||||
private Map<String, Boolean> getQuickActionFabStateMapFromJson(String json) {
|
||||
Type type = new TypeToken<HashMap<String, Boolean>>() {
|
||||
}.getType();
|
||||
HashMap<String, Boolean> quickActions = gson.fromJson(json, type);
|
||||
|
||||
return quickActions != null ? quickActions : new HashMap<String, Boolean>();
|
||||
}
|
||||
|
||||
|
||||
private List<QuickAction> parseActiveActionsList(String json) {
|
||||
Type type = new TypeToken<List<QuickAction>>() {
|
||||
}.getType();
|
||||
List<QuickAction> quickActions = gson.fromJson(json, type);
|
||||
List<QuickAction> rquickActions = new ArrayList<>(quickActions.size());
|
||||
if (quickActions != null) {
|
||||
for (QuickAction qa : quickActions) {
|
||||
if (qa != null) {
|
||||
rquickActions.add(qa);
|
||||
}
|
||||
}
|
||||
}
|
||||
this.quickActions = rquickActions;
|
||||
return rquickActions;
|
||||
}
|
||||
|
||||
public List<QuickActionType> updateActionTypes() {
|
||||
List<QuickActionType> quickActionTypes = new ArrayList<>();
|
||||
quickActionTypes.add(NewAction.TYPE);
|
||||
quickActionTypes.add(FavoriteAction.TYPE);
|
||||
quickActionTypes.add(GPXAction.TYPE);
|
||||
quickActionTypes.add(MarkerAction.TYPE);
|
||||
// configure map
|
||||
quickActionTypes.add(ShowHideFavoritesAction.TYPE);
|
||||
quickActionTypes.add(ShowHideGpxTracksAction.TYPE);
|
||||
quickActionTypes.add(ShowHidePoiAction.TYPE);
|
||||
quickActionTypes.add(MapStyleAction.TYPE);
|
||||
quickActionTypes.add(DayNightModeAction.TYPE);
|
||||
// navigation
|
||||
quickActionTypes.add(NavVoiceAction.TYPE);
|
||||
quickActionTypes.add(NavDirectionsFromAction.TYPE);
|
||||
quickActionTypes.add(NavAddDestinationAction.TYPE);
|
||||
quickActionTypes.add(NavAddFirstIntermediateAction.TYPE);
|
||||
quickActionTypes.add(NavReplaceDestinationAction.TYPE);
|
||||
quickActionTypes.add(NavAutoZoomMapAction.TYPE);
|
||||
quickActionTypes.add(NavStartStopAction.TYPE);
|
||||
quickActionTypes.add(NavResumePauseAction.TYPE);
|
||||
OsmandPlugin.registerQuickActionTypesPlugins(quickActionTypes);
|
||||
|
||||
Map<Integer, QuickActionType> quickActionTypesInt = new TreeMap<>();
|
||||
Map<String, QuickActionType> quickActionTypesStr = new TreeMap<>();
|
||||
for (QuickActionType qt : quickActionTypes) {
|
||||
quickActionTypesInt.put(qt.getId(), qt);
|
||||
quickActionTypesStr.put(qt.getStringId(), qt);
|
||||
}
|
||||
this.quickActionTypes = quickActionTypes;
|
||||
this.quickActionTypesInt = quickActionTypesInt;
|
||||
this.quickActionTypesStr = quickActionTypesStr;
|
||||
// reparse to get new quick actions
|
||||
parseActiveActionsList(settings.QUICK_ACTION_LIST.get());
|
||||
return quickActionTypes;
|
||||
}
|
||||
|
||||
public List<QuickActionType> produceTypeActionsListWithHeaders() {
|
||||
List<QuickActionType> result = new ArrayList<>();
|
||||
filterQuickActions(TYPE_ADD_ITEMS, result);
|
||||
filterQuickActions(TYPE_CONFIGURE_MAP, result);
|
||||
filterQuickActions(TYPE_NAVIGATION, result);
|
||||
return result;
|
||||
}
|
||||
|
||||
private void filterQuickActions(QuickActionType filter, List<QuickActionType> result) {
|
||||
result.add(filter);
|
||||
Set<Integer> set = new TreeSet<>();
|
||||
for (QuickAction qa : quickActions) {
|
||||
set.add(qa.getActionType().getId());
|
||||
}
|
||||
for (QuickActionType t : quickActionTypes) {
|
||||
if (t.getCategory() == filter.getCategory()) {
|
||||
if (!t.isActionEditable()) {
|
||||
boolean instanceInList = set.contains(t.getId());
|
||||
if (!instanceInList) {
|
||||
result.add(t);
|
||||
}
|
||||
} else {
|
||||
result.add(t);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public QuickAction newActionByStringType(String actionType) {
|
||||
QuickActionType quickActionType = quickActionTypesStr.get(actionType);
|
||||
if (quickActionType != null) {
|
||||
return quickActionType.createNew();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public QuickAction newActionByType(int type) {
|
||||
QuickActionType quickActionType = quickActionTypesInt.get(type);
|
||||
if (quickActionType != null) {
|
||||
return quickActionType.createNew();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static QuickAction produceAction(QuickAction quickAction) {
|
||||
return quickAction.getActionType().createNew(quickAction);
|
||||
}
|
||||
|
||||
private class QuickActionSerializer implements JsonDeserializer<QuickAction>,
|
||||
JsonSerializer<QuickAction> {
|
||||
|
||||
@Override
|
||||
public QuickAction deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
|
||||
JsonObject obj = json.getAsJsonObject();
|
||||
QuickActionType found = null;
|
||||
if (obj.has("actionType")) {
|
||||
String actionType = obj.get("actionType").getAsString();
|
||||
found = quickActionTypesStr.get(actionType);
|
||||
} else if (obj.has("type")) {
|
||||
int type = obj.get("type").getAsInt();
|
||||
found = quickActionTypesInt.get(type);
|
||||
}
|
||||
if (found != null) {
|
||||
QuickAction qa = found.createNew();
|
||||
if (obj.has("name")) {
|
||||
qa.setName(obj.get("name").getAsString());
|
||||
}
|
||||
if (obj.has("id")) {
|
||||
qa.setId(obj.get("id").getAsLong());
|
||||
}
|
||||
if (obj.has("params")) {
|
||||
qa.setParams((Map<String, String>) context.deserialize(obj.get("params"),
|
||||
new TypeToken<HashMap<String, String>>() {}.getType())
|
||||
);
|
||||
}
|
||||
return qa;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public JsonElement serialize(QuickAction src, Type typeOfSrc, JsonSerializationContext context) {
|
||||
JsonObject el = new JsonObject();
|
||||
el.addProperty("actionType", src.getActionType().getStringId());
|
||||
el.addProperty("id", src.getId());
|
||||
if (src.getRawName() != null) {
|
||||
el.addProperty("name", src.getRawName());
|
||||
}
|
||||
el.add("params", context.serialize(src.getParams()));
|
||||
return el;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
111
OsmAnd/src/net/osmand/plus/quickaction/QuickActionType.java
Normal file
111
OsmAnd/src/net/osmand/plus/quickaction/QuickActionType.java
Normal file
|
@ -0,0 +1,111 @@
|
|||
package net.osmand.plus.quickaction;
|
||||
|
||||
import androidx.annotation.DrawableRes;
|
||||
import androidx.annotation.StringRes;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
|
||||
public class QuickActionType {
|
||||
|
||||
public static final int CREATE_CATEGORY = 0;
|
||||
public static final int CONFIGURE_MAP = 1;
|
||||
public static final int NAVIGATION = 2;
|
||||
|
||||
private final int id;
|
||||
private final String stringId;
|
||||
private boolean actionEditable;
|
||||
private @StringRes int nameRes;
|
||||
private @DrawableRes int iconRes;
|
||||
private Class<? extends QuickAction> cl;
|
||||
private int category;
|
||||
|
||||
public QuickActionType(int id, String stringId) {
|
||||
this.id = id;
|
||||
this.stringId = stringId;
|
||||
}
|
||||
|
||||
public QuickActionType(int id, String stringId, Class<? extends QuickAction> cl) {
|
||||
this.id = id;
|
||||
this.stringId = stringId;
|
||||
this.cl = cl;
|
||||
this.actionEditable = cl != null;
|
||||
}
|
||||
|
||||
public QuickActionType nameRes(int nameRes) {
|
||||
this.nameRes = nameRes;
|
||||
return this;
|
||||
}
|
||||
|
||||
public QuickActionType category(int cat) {
|
||||
this.category = cat;
|
||||
return this;
|
||||
}
|
||||
|
||||
public QuickActionType iconRes(int iconRes) {
|
||||
this.iconRes = iconRes;
|
||||
return this;
|
||||
}
|
||||
|
||||
public QuickActionType nonEditable() {
|
||||
actionEditable = false;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public QuickAction createNew() {
|
||||
if(cl != null) {
|
||||
try {
|
||||
return cl.newInstance();
|
||||
} catch (InstantiationException e) {
|
||||
throw new UnsupportedOperationException(e);
|
||||
} catch (IllegalAccessException e) {
|
||||
throw new UnsupportedOperationException(e);
|
||||
}
|
||||
} else {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
}
|
||||
|
||||
public QuickAction createNew(QuickAction q) {
|
||||
if(cl != null) {
|
||||
try {
|
||||
return cl.getConstructor(QuickAction.class).newInstance(q);
|
||||
} catch (InstantiationException e) {
|
||||
throw new UnsupportedOperationException(e);
|
||||
} catch (IllegalAccessException e) {
|
||||
throw new UnsupportedOperationException(e);
|
||||
} catch (NoSuchMethodException e) {
|
||||
throw new UnsupportedOperationException(e);
|
||||
} catch (InvocationTargetException e) {
|
||||
throw new UnsupportedOperationException(e);
|
||||
}
|
||||
} else {
|
||||
return new QuickAction(q);
|
||||
}
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public String getStringId() {
|
||||
return stringId;
|
||||
}
|
||||
|
||||
public boolean isActionEditable() {
|
||||
return actionEditable;
|
||||
}
|
||||
|
||||
public int getNameRes() {
|
||||
return nameRes;
|
||||
}
|
||||
|
||||
public int getIconRes() {
|
||||
return iconRes;
|
||||
}
|
||||
|
||||
public int getCategory() {
|
||||
return category;
|
||||
}
|
||||
}
|
|
@ -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))
|
||||
|
|
|
@ -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<T> extends QuickAction {
|
|||
|
||||
private transient ItemTouchHelper touchHelper;
|
||||
|
||||
protected SwitchableAction(int type) {
|
||||
protected SwitchableAction(QuickActionType type) {
|
||||
super(type);
|
||||
}
|
||||
|
||||
|
@ -118,6 +119,10 @@ public abstract class SwitchableAction<T> extends QuickAction {
|
|||
fragment.show(fm, SelectMapViewQuickActionsBottomSheet.TAG);
|
||||
}
|
||||
|
||||
public String getSelectedItem(OsmandApplication app) {
|
||||
return null;
|
||||
}
|
||||
|
||||
protected class Adapter extends RecyclerView.Adapter<Adapter.ItemHolder> implements ReorderItemTouchHelperCallback.OnItemMoveCallback {
|
||||
|
||||
private List<T> itemsList = new ArrayList<>();
|
||||
|
|
|
@ -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);}
|
||||
|
||||
|
|
|
@ -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";
|
||||
|
|
|
@ -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";
|
||||
|
|
|
@ -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<String> {
|
||||
|
||||
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<String> {
|
|||
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<String> mapStyles = getFilteredStyles();
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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";
|
||||
|
||||
|
|
|
@ -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<Pair<String, String>> {
|
||||
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<Pair<String, String>> {
|
|||
: filters.get(0).second;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSelectedItem(OsmandApplication app) {
|
||||
return app.getSettings().MAP_OVERLAY.get();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void saveListToParams(List<Pair<String, String>> list) {
|
||||
|
|
@ -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<Pair<String, String>> {
|
||||
|
||||
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<Pair<String, String>> {
|
|||
: 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<Pair<String, String>> list) {
|
||||
|
|
@ -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<Pair<String, String>> {
|
||||
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<Pair<String, String>> {
|
|||
: filters.get(0).second;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getSelectedItem(OsmandApplication app) {
|
||||
return app.getSettings().MAP_UNDERLAY.get();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void saveListToParams(List<Pair<String, String>> list) {
|
||||
|
|
@ -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<QuickActionType> quickActionTypes) {
|
||||
quickActionTypes.add(MapSourceAction.TYPE);
|
||||
quickActionTypes.add(MapOverlayAction.TYPE);
|
||||
quickActionTypes.add(MapUnderlayAction.TYPE);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<Type, List<?>> getAdditionalData() {
|
||||
Map<Type, List<?>> dataList = new HashMap<>();
|
||||
|
||||
QuickActionFactory factory = new QuickActionFactory();
|
||||
List<QuickAction> actionsList = factory.parseActiveActionsList(app.getSettings().QUICK_ACTION_LIST.get());
|
||||
|
||||
QuickActionRegistry registry = app.getQuickActionRegistry();
|
||||
List<QuickAction> actionsList = registry.getQuickActions();
|
||||
if (!actionsList.isEmpty()) {
|
||||
dataList.put(Type.QUICK_ACTIONS, actionsList);
|
||||
}
|
||||
|
|
|
@ -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);
|
|
@ -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);
|
|
@ -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<QuickActionType> quickActionTypes) {
|
||||
quickActionTypes.add(ContourLinesAction.TYPE);
|
||||
quickActionTypes.add(HillshadeAction.TYPE);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue