From a513966ba385eb0d4ea80e8556065b6787a3a326 Mon Sep 17 00:00:00 2001 From: Alexey Kulish Date: Tue, 21 Mar 2017 22:35:12 +0300 Subject: [PATCH] Added auto zoom map on/off quick action --- OsmAnd/res/values/strings.xml | 4 ++ .../src/net/osmand/plus/OsmandSettings.java | 4 ++ .../plus/quickaction/QuickActionFactory.java | 18 ++++++ .../actions/NavAutoZoomMapAction.java | 64 +++++++++++++++++++ 4 files changed, 90 insertions(+) create mode 100644 OsmAnd/src/net/osmand/plus/quickaction/actions/NavAutoZoomMapAction.java diff --git a/OsmAnd/res/values/strings.xml b/OsmAnd/res/values/strings.xml index 9628a7b7da..abd27e8241 100644 --- a/OsmAnd/res/values/strings.xml +++ b/OsmAnd/res/values/strings.xml @@ -9,6 +9,10 @@ 3. All your modified/created strings are in the top of the file (to make easier find what\'s translated). PLEASE: Have a look at http://code.google.com/p/osmand/wiki/UIConsistency, it may really improve your and our work :-) Thx - Hardy --> + Auto zoom map on/off + Tapping the action button will turn on/off auto zoom map according to your speed. + Auto zoom map on + Auto zoom map off Add destination Replace destination Add first intermediate diff --git a/OsmAnd/src/net/osmand/plus/OsmandSettings.java b/OsmAnd/src/net/osmand/plus/OsmandSettings.java index 5e708e71f5..5b216fa2a0 100644 --- a/OsmAnd/src/net/osmand/plus/OsmandSettings.java +++ b/OsmAnd/src/net/osmand/plus/OsmandSettings.java @@ -955,6 +955,10 @@ public class OsmandSettings { RouteService.values()).makeProfile(); // this value string is synchronized with settings_pref.xml preference name + public final CommonPreference AUTO_ZOOM_MAP_PREV = + new EnumIntPreference("auto_zoom_map_new_prev", AutoZoomMap.NONE, + AutoZoomMap.values()).makeProfile().cache(); + public final CommonPreference AUTO_ZOOM_MAP = new EnumIntPreference("auto_zoom_map_new", AutoZoomMap.NONE, AutoZoomMap.values()).makeProfile().cache(); diff --git a/OsmAnd/src/net/osmand/plus/quickaction/QuickActionFactory.java b/OsmAnd/src/net/osmand/plus/quickaction/QuickActionFactory.java index 9aa2ceb2c6..65b64e4bcb 100644 --- a/OsmAnd/src/net/osmand/plus/quickaction/QuickActionFactory.java +++ b/OsmAnd/src/net/osmand/plus/quickaction/QuickActionFactory.java @@ -27,6 +27,7 @@ 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.NavReplaceDestinationAction; import net.osmand.plus.quickaction.actions.NavVoiceAction; import net.osmand.plus.quickaction.actions.NewAction; @@ -125,6 +126,7 @@ public class QuickActionFactory { QuickAction addDestination = new NavAddDestinationAction(); QuickAction addFirstIntermediate = new NavAddFirstIntermediateAction(); QuickAction replaceDestination = new NavReplaceDestinationAction(); + QuickAction autoZoomMap = new NavAutoZoomMapAction(); ArrayList navigationQuickActions = new ArrayList<>(); @@ -140,6 +142,9 @@ public class QuickActionFactory { if (!replaceDestination.hasInstanceInList(active)) { navigationQuickActions.add(replaceDestination); } + if (!autoZoomMap.hasInstanceInList(active)) { + navigationQuickActions.add(autoZoomMap); + } if (navigationQuickActions.size() > 0) { quickActions.add(new QuickAction(0, R.string.quick_action_add_navigation)); @@ -214,6 +219,9 @@ public class QuickActionFactory { case NavReplaceDestinationAction.TYPE: return new NavReplaceDestinationAction(); + case NavAutoZoomMapAction.TYPE: + return new NavAutoZoomMapAction(); + default: return new QuickAction(); } @@ -283,6 +291,9 @@ public class QuickActionFactory { case NavReplaceDestinationAction.TYPE: return new NavReplaceDestinationAction(quickAction); + case NavAutoZoomMapAction.TYPE: + return new NavAutoZoomMapAction(quickAction); + default: return quickAction; } @@ -352,6 +363,9 @@ public class QuickActionFactory { case NavReplaceDestinationAction.TYPE: return R.drawable.ic_action_target; + case NavAutoZoomMapAction.TYPE: + return R.drawable.ic_action_search_dark; + default: return R.drawable.ic_action_plus; } @@ -421,6 +435,9 @@ public class QuickActionFactory { case NavReplaceDestinationAction.TYPE: return R.string.quick_action_replace_destination; + case NavAutoZoomMapAction.TYPE: + return R.string.quick_action_auto_zoom; + default: return R.string.quick_action_new_action; } @@ -442,6 +459,7 @@ public class QuickActionFactory { case NavAddDestinationAction.TYPE: case NavAddFirstIntermediateAction.TYPE: case NavReplaceDestinationAction.TYPE: + case NavAutoZoomMapAction.TYPE: return false; default: return true; diff --git a/OsmAnd/src/net/osmand/plus/quickaction/actions/NavAutoZoomMapAction.java b/OsmAnd/src/net/osmand/plus/quickaction/actions/NavAutoZoomMapAction.java new file mode 100644 index 0000000000..7c01f92ec9 --- /dev/null +++ b/OsmAnd/src/net/osmand/plus/quickaction/actions/NavAutoZoomMapAction.java @@ -0,0 +1,64 @@ +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.OsmandSettings; +import net.osmand.plus.OsmandSettings.AutoZoomMap; +import net.osmand.plus.R; +import net.osmand.plus.activities.MapActivity; +import net.osmand.plus.quickaction.QuickAction; + +public class NavAutoZoomMapAction extends QuickAction { + + public static final int TYPE = 23; + + public NavAutoZoomMapAction() { + super(TYPE); + } + + public NavAutoZoomMapAction(QuickAction quickAction) { + super(quickAction); + } + + @Override + public void execute(MapActivity activity) { + + OsmandSettings settings = activity.getMyApplication().getSettings(); + if (settings.AUTO_ZOOM_MAP.get() == AutoZoomMap.NONE) { + settings.AUTO_ZOOM_MAP.set(settings.AUTO_ZOOM_MAP_PREV.get()); + } else { + settings.AUTO_ZOOM_MAP_PREV.set(settings.AUTO_ZOOM_MAP.get()); + settings.AUTO_ZOOM_MAP.set(AutoZoomMap.NONE); + } + } + + @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_auto_zoom_desc); + + parent.addView(view); + } + + @Override + public String getActionText(OsmandApplication application) { + + return application.getSettings().AUTO_ZOOM_MAP.get() != AutoZoomMap.NONE + ? application.getString(R.string.quick_action_auto_zoom_off) + : application.getString(R.string.quick_action_auto_zoom_on); + } + + @Override + public boolean isActionWithSlash(OsmandApplication application) { + + return application.getSettings().AUTO_ZOOM_MAP.get() != AutoZoomMap.NONE; + } +}