From 790cf6592ee804ab7e20fa38d3f6a559d1a9d21a Mon Sep 17 00:00:00 2001 From: androiddevkotlin <64539346+androiddevkotlin@users.noreply.github.com> Date: Fri, 19 Feb 2021 21:27:27 +0200 Subject: [PATCH] Feature Request: Add "Coordinates widget" toggle to Quick action button https://github.com/osmandapp/OsmAnd/issues/10196 --- OsmAnd/res/values/strings.xml | 4 ++ .../plus/quickaction/QuickActionRegistry.java | 5 +- .../ShowHideCoordinatesWidgetAction.java | 62 +++++++++++++++++++ 3 files changed, 70 insertions(+), 1 deletion(-) create mode 100644 OsmAnd/src/net/osmand/plus/quickaction/actions/ShowHideCoordinatesWidgetAction.java diff --git a/OsmAnd/res/values/strings.xml b/OsmAnd/res/values/strings.xml index 69f4c6506e..2dec1d051e 100644 --- a/OsmAnd/res/values/strings.xml +++ b/OsmAnd/res/values/strings.xml @@ -12,6 +12,10 @@ --> + A toggle to show or hide the Coordinates widget on the map. + Show Coordinates widget + Hide Coordinates widget + Show/Hide coordinates widget Routing could avoid strong uphills. Application restart required to apply some settings. On pause diff --git a/OsmAnd/src/net/osmand/plus/quickaction/QuickActionRegistry.java b/OsmAnd/src/net/osmand/plus/quickaction/QuickActionRegistry.java index 61ae5fd1ca..9ea226366a 100644 --- a/OsmAnd/src/net/osmand/plus/quickaction/QuickActionRegistry.java +++ b/OsmAnd/src/net/osmand/plus/quickaction/QuickActionRegistry.java @@ -30,6 +30,7 @@ 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.ShowHideCoordinatesWidgetAction; import net.osmand.plus.quickaction.actions.ShowHideFavoritesAction; import net.osmand.plus.quickaction.actions.ShowHideGpxTracksAction; import net.osmand.plus.quickaction.actions.ShowHideMapillaryAction; @@ -214,6 +215,7 @@ public class QuickActionRegistry { quickActionTypes.add(DayNightModeAction.TYPE); quickActionTypes.add(ShowHideTransportLinesAction.TYPE); quickActionTypes.add(ShowHideMapillaryAction.TYPE); + quickActionTypes.add(ShowHideCoordinatesWidgetAction.TYPE); // navigation quickActionTypes.add(NavVoiceAction.TYPE); quickActionTypes.add(NavDirectionsFromAction.TYPE); @@ -313,7 +315,8 @@ public class QuickActionRegistry { } if (obj.has("params")) { qa.setParams((Map) context.deserialize(obj.get("params"), - new TypeToken>() {}.getType()) + new TypeToken>() { + }.getType()) ); } return qa; diff --git a/OsmAnd/src/net/osmand/plus/quickaction/actions/ShowHideCoordinatesWidgetAction.java b/OsmAnd/src/net/osmand/plus/quickaction/actions/ShowHideCoordinatesWidgetAction.java new file mode 100644 index 0000000000..d0f0728c19 --- /dev/null +++ b/OsmAnd/src/net/osmand/plus/quickaction/actions/ShowHideCoordinatesWidgetAction.java @@ -0,0 +1,62 @@ +package net.osmand.plus.quickaction.actions; + +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.TextView; + +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 ShowHideCoordinatesWidgetAction extends QuickAction { + public static final QuickActionType TYPE = new QuickActionType(35, + "coordinates.showhide", ShowHideCoordinatesWidgetAction.class) + .nameRes(R.string.quick_action_showhide_coordinates_widget) + .iconRes(R.drawable.ic_action_coordinates_widget).nonEditable() + .category(QuickActionType.CONFIGURE_MAP); + + public ShowHideCoordinatesWidgetAction() { + super(TYPE); + } + + public ShowHideCoordinatesWidgetAction(QuickAction quickAction) { + super(quickAction); + } + + @Override + public void execute(MapActivity activity) { + + activity.getMyApplication().getSettings().SHOW_COORDINATES_WIDGET.set( + !activity.getMyApplication().getSettings().SHOW_COORDINATES_WIDGET.get()); + + activity.getMapLayers().updateLayers(activity.getMapView()); + } + + @Override + public void drawUI(ViewGroup parent, MapActivity activity) { + + View view = LayoutInflater.from(parent.getContext()) + .inflate(R.layout.quick_action_with_text, parent, false); + + ((TextView) view.findViewById(R.id.text)).setText( + R.string.quick_action_coordinates_widget_descr); + + parent.addView(view); + } + + @Override + public String getActionText(OsmandApplication application) { + + return application.getSettings().SHOW_COORDINATES_WIDGET.get() + ? application.getString(R.string.quick_action_coordinates_widget_hide) + : application.getString(R.string.quick_action_coordinates_widget_show); + } + + @Override + public boolean isActionWithSlash(OsmandApplication application) { + return application.getSettings().SHOW_COORDINATES_WIDGET.get(); + } +}