Feature Request: Add "Coordinates widget" toggle to Quick action button

https://github.com/osmandapp/OsmAnd/issues/10196
This commit is contained in:
androiddevkotlin 2021-02-19 21:27:27 +02:00
parent a3d65e8500
commit 790cf6592e
3 changed files with 70 additions and 1 deletions

View file

@ -12,6 +12,10 @@
-->
<string name="quick_action_coordinates_widget_descr">A toggle to show or hide the Coordinates widget on the map.</string>
<string name="quick_action_coordinates_widget_show">Show Coordinates widget</string>
<string name="quick_action_coordinates_widget_hide">Hide Coordinates widget</string>
<string name="quick_action_showhide_coordinates_widget">Show/Hide coordinates widget</string>
<string name="routing_attr_height_obstacles_description">Routing could avoid strong uphills.</string>
<string name="app_restart_required">Application restart required to apply some settings.</string>
<string name="on_pause">On pause</string>

View file

@ -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<String, String>) context.deserialize(obj.get("params"),
new TypeToken<HashMap<String, String>>() {}.getType())
new TypeToken<HashMap<String, String>>() {
}.getType())
);
}
return qa;

View file

@ -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();
}
}