diff --git a/OsmAnd/src/net/osmand/plus/OsmandSettings.java b/OsmAnd/src/net/osmand/plus/OsmandSettings.java index 18c7e9d639..5d570eb0e1 100644 --- a/OsmAnd/src/net/osmand/plus/OsmandSettings.java +++ b/OsmAnd/src/net/osmand/plus/OsmandSettings.java @@ -2454,7 +2454,7 @@ public class OsmandSettings { public static final String QUICK_FAB_MARGIN_X_LANDSCAPE_MARGIN = "quick_fab_margin_x_landscape_margin"; public static final String QUICK_FAB_MARGIN_Y_LANDSCAPE_MARGIN = "quick_fab_margin_y_landscape_margin"; - public final CommonPreference QUICK_ACTION = new BooleanPreference("quick_action", false).makeProfile(); + public final CommonPreference QUICK_ACTION = new StringPreference("quick_action", "").makeProfile(); public final CommonPreference QUICK_ACTION_LIST = new StringPreference("quick_action_list", "").makeProfile(); diff --git a/OsmAnd/src/net/osmand/plus/activities/MapActivity.java b/OsmAnd/src/net/osmand/plus/activities/MapActivity.java index 1ca483aa44..7503982632 100644 --- a/OsmAnd/src/net/osmand/plus/activities/MapActivity.java +++ b/OsmAnd/src/net/osmand/plus/activities/MapActivity.java @@ -981,6 +981,9 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven if (mapLayers.getMapInfoLayer() != null) { mapLayers.getMapInfoLayer().recreateControls(); } + if (mapLayers.getMapQuickActionLayer() != null) { + mapLayers.getMapQuickActionLayer().refreshLayer(); + } mapLayers.updateLayers(mapView); mapActions.updateDrawerMenu(); mapView.setComplexZoom(mapView.getZoom(), mapView.getSettingsMapDensity()); diff --git a/OsmAnd/src/net/osmand/plus/quickaction/QuickActionRegistry.java b/OsmAnd/src/net/osmand/plus/quickaction/QuickActionRegistry.java index 476bdbdc3e..f4beaf4bb7 100644 --- a/OsmAnd/src/net/osmand/plus/quickaction/QuickActionRegistry.java +++ b/OsmAnd/src/net/osmand/plus/quickaction/QuickActionRegistry.java @@ -2,10 +2,16 @@ package net.osmand.plus.quickaction; import android.content.Context; +import com.google.gson.Gson; +import com.google.gson.reflect.TypeToken; + import net.osmand.plus.OsmandSettings; +import java.lang.reflect.Type; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; +import java.util.Map; /** * Created by rosty on 12/27/16. @@ -22,6 +28,7 @@ public class QuickActionRegistry { private final OsmandSettings settings; private final List quickActions; + private final Map fabStateMap; private QuickActionUpdatesListener updatesListener; @@ -31,6 +38,7 @@ public class QuickActionRegistry { this.settings = settings; quickActions = factory.parseActiveActionsList(settings.QUICK_ACTION_LIST.get()); + fabStateMap = getQuickActionFabStateMapFromJson(settings.QUICK_ACTION.get()); } public void setUpdatesListener(QuickActionUpdatesListener updatesListener) { @@ -136,4 +144,22 @@ public class QuickActionRegistry { 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(new Gson().toJson(fabStateMap)); + } + + private Map getQuickActionFabStateMapFromJson(String json) { + Type type = new TypeToken>() { + }.getType(); + HashMap quickActions = new Gson().fromJson(json, type); + + return quickActions != null ? quickActions : new HashMap(); + } } diff --git a/OsmAnd/src/net/osmand/plus/views/MapQuickActionLayer.java b/OsmAnd/src/net/osmand/plus/views/MapQuickActionLayer.java index 99d66f425f..35f4a9a72c 100644 --- a/OsmAnd/src/net/osmand/plus/views/MapQuickActionLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/MapQuickActionLayer.java @@ -67,8 +67,7 @@ public class MapQuickActionLayer extends OsmandMapLayer implements QuickActionRe quickActionsWidget = (QuickActionsWidget) mapActivity.findViewById(R.id.quick_action_widget); quickActionButton = (ImageButton) mapActivity.findViewById(R.id.map_quick_actions_button); setQuickActionButtonMargin(); - isLayerOn = settings.QUICK_ACTION.get(); -// quickActionButton.setVisibility(isLayerOn ? View.VISIBLE : View.GONE); + isLayerOn = quickActionRegistry.isQuickActionOn(); quickActionButton.setImageResource(R.drawable.map_quick_action); quickActionButton.setOnClickListener(new View.OnClickListener() { @Override @@ -102,8 +101,7 @@ public class MapQuickActionLayer extends OsmandMapLayer implements QuickActionRe public void refreshLayer() { setLayerState(true); - isLayerOn = settings.QUICK_ACTION.get(); -// quickActionButton.setVisibility(settings.QUICK_ACTION.get() ? View.VISIBLE : View.GONE); + isLayerOn = quickActionRegistry.isQuickActionOn(); } private void setQuickActionButtonMargin() { @@ -227,15 +225,13 @@ public class MapQuickActionLayer extends OsmandMapLayer implements QuickActionRe @Override public void onDraw(Canvas canvas, RotatedTileBox box, DrawSettings settings) { if (isInChangeMarkerPositionMode()) { -// canvas.translate(box.getPixWidth() / 2 - contextMarker.getWidth() / 2, box.getPixHeight() / 2 - contextMarker.getHeight()); canvas.translate(box.getCenterPixelX() - contextMarker.getWidth() / 2, box.getCenterPixelY() - contextMarker.getHeight()); contextMarker.draw(canvas); } boolean hideQuickButton = !isLayerOn || contextMenuLayer.isInChangeMarkerPositionMode() || mapActivity.getContextMenu().isVisible() || - mapActivity.getContextMenu().getMultiSelectionMenu().isVisible() || - mapActivity.getRoutingHelper().isRoutePlanningMode(); + mapActivity.getContextMenu().getMultiSelectionMenu().isVisible(); quickActionButton.setVisibility(hideQuickButton ? View.GONE : View.VISIBLE); } diff --git a/OsmAnd/src/net/osmand/plus/views/mapwidgets/MapWidgetRegistry.java b/OsmAnd/src/net/osmand/plus/views/mapwidgets/MapWidgetRegistry.java index c9dbf65be9..869db417ac 100644 --- a/OsmAnd/src/net/osmand/plus/views/mapwidgets/MapWidgetRegistry.java +++ b/OsmAnd/src/net/osmand/plus/views/mapwidgets/MapWidgetRegistry.java @@ -359,7 +359,7 @@ public class MapWidgetRegistry { public void addControls(MapActivity map, ContextMenuAdapter cm, ApplicationMode mode) { - addQuickActionControl(map, cm); + addQuickActionControl(map, cm, mode); // Right panel cm.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.map_widget_right, map) .setCategory(true).setLayout(R.layout.list_group_title_with_switch).createItem()); @@ -386,12 +386,12 @@ public class MapWidgetRegistry { return leftWidgetSet; } - private void addQuickActionControl(final MapActivity mapActivity, final ContextMenuAdapter contextMenuAdapter) { + private void addQuickActionControl(final MapActivity mapActivity, final ContextMenuAdapter contextMenuAdapter, ApplicationMode mode) { contextMenuAdapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.map_widget_right, mapActivity) .setCategory(true).setLayout(R.layout.list_group_empty_title_with_switch).createItem()); - boolean selected = settings.QUICK_ACTION.get(); + boolean selected = mapActivity.getMapLayers().getQuickActionRegistry().isQuickActionOn(); contextMenuAdapter.addItem(new ContextMenuItem.ItemBuilder() .setTitleId(R.string.configure_screen_quick_action, mapActivity) .setIcon(R.drawable.map_quick_action) @@ -422,7 +422,7 @@ public class MapWidgetRegistry { int position, boolean visible) { - settings.QUICK_ACTION.set(visible); + mapActivity.getMapLayers().getQuickActionRegistry().setQuickActionFabState(visible); MapQuickActionLayer mil = mapActivity.getMapLayers().getMapQuickActionLayer(); if (mil != null) {