From c4f3a6fbc2ea13e423f5fd67bd814681f19a82ef Mon Sep 17 00:00:00 2001 From: GaidamakUA Date: Fri, 8 Apr 2016 17:32:34 +0300 Subject: [PATCH] Better switch logic for Underlay/Overlay --- .../rastermaps/OsmandRasterMapsPlugin.java | 56 +++++++++++++++++-- 1 file changed, 50 insertions(+), 6 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/rastermaps/OsmandRasterMapsPlugin.java b/OsmAnd/src/net/osmand/plus/rastermaps/OsmandRasterMapsPlugin.java index 8e8720c779..3c466b7e95 100644 --- a/OsmAnd/src/net/osmand/plus/rastermaps/OsmandRasterMapsPlugin.java +++ b/OsmAnd/src/net/osmand/plus/rastermaps/OsmandRasterMapsPlugin.java @@ -238,13 +238,10 @@ public class OsmandRasterMapsPlugin extends OsmandPlugin { final int defaultColor = IconsCache.getDefaultColorRes(mapActivity); final MapActivityLayers layers = mapActivity.getMapLayers(); - ContextMenuAdapter.ItemClickListener listener = new ItemClickListener() { + ContextMenuAdapter.ItemClickListener listener = new ContextMenuAdapter.OnRowItemClick() { @Override - public boolean onContextMenuClick(ArrayAdapter adapter, int itemId, int pos, boolean isChecked) { - OsmandSettings settings = mapActivity.getMyApplication().getSettings(); - if (itemId == R.string.layer_map) { - layers.selectMapLayer(mapView); - } else if (itemId == R.string.layer_overlay) { + public boolean onRowItemClick(ArrayAdapter adapter, View view, int itemId, int position) { + if (itemId == R.string.layer_overlay) { mapActivity.getDashboard().setDashboardVisibility(true, DashboardType.OVERLAY_MAP); return false; } else if (itemId == R.string.layer_underlay) { @@ -253,6 +250,53 @@ public class OsmandRasterMapsPlugin extends OsmandPlugin { } return true; } + + @Override + public boolean onContextMenuClick(final ArrayAdapter adapter, int itemId, final int pos, boolean isChecked) { + final OsmandSettings settings = mapActivity.getMyApplication().getSettings(); + switch (itemId) { + case R.string.layer_overlay: + toggleUnderlayState(mapActivity, RasterMapType.OVERLAY, + new OnMapSelectedCallback() { + @Override + public void onMapSelected() { + ContextMenuItem item = adapter.getItem(pos); + + String overlayMapDescr = settings.MAP_OVERLAY.get(); + boolean hasOverlayDescription = overlayMapDescr != null; + overlayMapDescr = hasOverlayDescription ? overlayMapDescr + : mapActivity.getString(R.string.shared_string_none); + + item.setDescription(overlayMapDescr); + item.setSelected(hasOverlayDescription); + item.setColorRes(hasOverlayDescription ? R.color.osmand_orange : defaultColor); + adapter.notifyDataSetChanged(); + } + }); + return false; + case R.string.layer_underlay: + toggleUnderlayState(mapActivity, RasterMapType.UNDERLAY, new + OnMapSelectedCallback() { + @Override + public void onMapSelected() { + ContextMenuItem item = adapter.getItem(pos); + + String underlayMapDescr = settings.MAP_UNDERLAY.get(); + boolean hasUnderlayDescription = underlayMapDescr != null; + underlayMapDescr = hasUnderlayDescription ? underlayMapDescr + : mapActivity.getString(R.string.shared_string_none); + + item.setDescription(underlayMapDescr); + item.setSelected(hasUnderlayDescription); + item.setColorRes(hasUnderlayDescription ? R.color.osmand_orange : defaultColor); + + adapter.notifyDataSetChanged(); + } + }); + return false; + } + return true; + } }; String overlayMapDescr = settings.MAP_OVERLAY.get();