diff --git a/OsmAnd/src/net/osmand/plus/OsmandSettings.java b/OsmAnd/src/net/osmand/plus/OsmandSettings.java index 0d181b56ea..6663dd1736 100644 --- a/OsmAnd/src/net/osmand/plus/OsmandSettings.java +++ b/OsmAnd/src/net/osmand/plus/OsmandSettings.java @@ -1135,8 +1135,8 @@ public class OsmandSettings { public final CommonPreference MAP_TILE_SOURCES = new StringPreference("map_tile_sources", TileSourceManager.getMapnikSource().getName()).makeGlobal(); - public final CommonPreference SHOW_LAYER_TRANSPARENCY_SEEKBAR = - new BooleanPreference("show_layer_transparency_seekbar", false).makeGlobal(); + public final CommonPreference LAYER_TRANSPARENCY_SEEKBAR_MODE = + new EnumIntPreference<>("layer_transparency_seekbar_mode", LayerTransparencySeekbarMode.UNDEFINED, LayerTransparencySeekbarMode.values()); public final CommonPreference MAP_OVERLAY_PREVIOUS = new StringPreference("map_overlay_previous", null).makeGlobal().cache(); @@ -2579,6 +2579,24 @@ public class OsmandSettings { } } + + public enum LayerTransparencySeekbarMode { + OVERLAY(R.string.overlay_transparency), + UNDERLAY(R.string.map_transparency), + OFF(R.string.shared_string_off), + UNDEFINED(R.string.shared_string_none); + + private final int key; + + LayerTransparencySeekbarMode(int key) { + this.key = key; + } + + public String toHumanString(Context ctx) { + return ctx.getString(key); + } + } + public enum MapMarkersMode { TOOLBAR(R.string.shared_string_topbar), WIDGETS(R.string.shared_string_widgets), diff --git a/OsmAnd/src/net/osmand/plus/dialogs/RasterMapMenu.java b/OsmAnd/src/net/osmand/plus/dialogs/RasterMapMenu.java index 39030e48e8..144a4a05a1 100644 --- a/OsmAnd/src/net/osmand/plus/dialogs/RasterMapMenu.java +++ b/OsmAnd/src/net/osmand/plus/dialogs/RasterMapMenu.java @@ -1,6 +1,8 @@ package net.osmand.plus.dialogs; +import android.support.annotation.NonNull; import android.support.annotation.StringRes; +import android.util.Log; import android.view.View; import android.widget.ArrayAdapter; @@ -9,10 +11,12 @@ import net.osmand.plus.ContextMenuItem; import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandPlugin; import net.osmand.plus.OsmandSettings; +import net.osmand.plus.OsmandSettings.LayerTransparencySeekbarMode; import net.osmand.plus.R; import net.osmand.plus.activities.MapActivity; import net.osmand.plus.activities.MapActivityLayers; import net.osmand.plus.rastermaps.OsmandRasterMapsPlugin; +import net.osmand.plus.rastermaps.OsmandRasterMapsPlugin.RasterMapType; import net.osmand.plus.views.GPXLayer; import net.osmand.plus.views.RouteLayer; @@ -20,7 +24,7 @@ public class RasterMapMenu { private static final String TAG = "RasterMapMenu"; public static ContextMenuAdapter createListAdapter(final MapActivity mapActivity, - final OsmandRasterMapsPlugin.RasterMapType type) { + final RasterMapType type) { ContextMenuAdapter adapter = new ContextMenuAdapter(); adapter.setDefaultLayoutId(R.layout.list_item_icon_and_menu); createLayersItems(adapter, mapActivity, type); @@ -29,7 +33,7 @@ public class RasterMapMenu { private static void createLayersItems(final ContextMenuAdapter contextMenuAdapter, final MapActivity mapActivity, - final OsmandRasterMapsPlugin.RasterMapType type) { + final RasterMapType type) { final OsmandApplication app = mapActivity.getMyApplication(); final OsmandSettings settings = app.getSettings(); final OsmandRasterMapsPlugin plugin = OsmandPlugin.getEnabledPlugin(OsmandRasterMapsPlugin.class); @@ -37,15 +41,17 @@ public class RasterMapMenu { final OsmandSettings.CommonPreference mapTransparencyPreference; final OsmandSettings.CommonPreference mapTypePreference; final OsmandSettings.CommonPreference exMapTypePreference; + final LayerTransparencySeekbarMode currentMapTypeSeekbarMode = + type == RasterMapType.OVERLAY ? LayerTransparencySeekbarMode.OVERLAY : LayerTransparencySeekbarMode.UNDERLAY; @StringRes final int mapTypeString; @StringRes final int mapTypeStringTransparency; - if (type == OsmandRasterMapsPlugin.RasterMapType.OVERLAY) { + if (type == RasterMapType.OVERLAY) { mapTransparencyPreference = settings.MAP_OVERLAY_TRANSPARENCY; mapTypePreference = settings.MAP_OVERLAY; exMapTypePreference = settings.MAP_OVERLAY_PREVIOUS; mapTypeString = R.string.map_overlay; mapTypeStringTransparency = R.string.overlay_transparency; - } else if (type == OsmandRasterMapsPlugin.RasterMapType.UNDERLAY) { + } else if (type == RasterMapType.UNDERLAY) { mapTransparencyPreference = settings.MAP_TRANSPARENCY; mapTypePreference = settings.MAP_UNDERLAY; exMapTypePreference = settings.MAP_UNDERLAY_PREVIOUS; @@ -91,14 +97,8 @@ public class RasterMapMenu { app.runInUIThread(new Runnable() { @Override public void run() { - if (isChecked) { - mapLayers.getMapControlsLayer().showTransparencyBar(mapTransparencyPreference); - } else { - mapLayers.getMapControlsLayer().hideTransparencyBar(mapTransparencyPreference); - } - mapLayers.getMapControlsLayer().setTransparencyBarEnabled(isChecked); plugin.toggleUnderlayState(mapActivity, type, onMapSelectedCallback); - if (type == OsmandRasterMapsPlugin.RasterMapType.UNDERLAY) { + if (type == RasterMapType.UNDERLAY) { hidePolygonsPref.set(isChecked); mapActivity.getDashboard().refreshContent(true); } @@ -109,11 +109,16 @@ public class RasterMapMenu { hidePolygonsPref.set(!isChecked); refreshMapComplete(mapActivity); } else if (itemId == R.string.show_transparency_seekbar) { - settings.SHOW_LAYER_TRANSPARENCY_SEEKBAR.set(isChecked); - mapLayers.getMapControlsLayer().setTransparencyBarEnabled(isChecked); + settings.LAYER_TRANSPARENCY_SEEKBAR_MODE.set( + isChecked ? currentMapTypeSeekbarMode : LayerTransparencySeekbarMode.OFF); if (isChecked) { mapLayers.getMapControlsLayer().showTransparencyBar(mapTransparencyPreference); + Log.e("111", "checkbox: show"); + } else { + mapLayers.getMapControlsLayer().hideTransparencyBar(mapTransparencyPreference); + Log.e("111", "checkbox: hide"); } + mapLayers.getMapControlsLayer().setTransparencyBarEnabled(isChecked); } return false; } @@ -149,15 +154,14 @@ public class RasterMapMenu { .setProgress(mapTransparencyPreference.get()) .setListener(l) .setIntegerListener(integerListener).createItem()); - if (type == OsmandRasterMapsPlugin.RasterMapType.UNDERLAY) { + if (type == RasterMapType.UNDERLAY) { contextMenuAdapter.addItem(new ContextMenuItem.ItemBuilder() .setTitleId(R.string.show_polygons, mapActivity) .hideDivider(true) .setListener(l) .setSelected(!hidePolygonsPref.get()).createItem()); } - Boolean transparencySwitchState = settings.SHOW_LAYER_TRANSPARENCY_SEEKBAR.get() - && mapLayers.getMapControlsLayer().isTransparencyBarInitialized(); + Boolean transparencySwitchState = isSeekbarVisible(app, type); contextMenuAdapter.addItem(new ContextMenuItem.ItemBuilder() .setTitleId(R.string.show_transparency_seekbar, mapActivity) .hideDivider(true) @@ -166,6 +170,14 @@ public class RasterMapMenu { } } + @NonNull + public static Boolean isSeekbarVisible(OsmandApplication app, RasterMapType type) { + final OsmandSettings.LayerTransparencySeekbarMode currentMapTypeSeekbarMode = + type == RasterMapType.OVERLAY ? OsmandSettings.LayerTransparencySeekbarMode.OVERLAY : OsmandSettings.LayerTransparencySeekbarMode.UNDERLAY; + LayerTransparencySeekbarMode seekbarMode = app.getSettings().LAYER_TRANSPARENCY_SEEKBAR_MODE.get(); + return seekbarMode == LayerTransparencySeekbarMode.UNDEFINED || seekbarMode == currentMapTypeSeekbarMode; + } + public static void refreshMapComplete(final MapActivity activity) { activity.getMyApplication().getResourceManager().getRenderer().clearCache(); activity.updateMapSettings(); diff --git a/OsmAnd/src/net/osmand/plus/rastermaps/OsmandRasterMapsPlugin.java b/OsmAnd/src/net/osmand/plus/rastermaps/OsmandRasterMapsPlugin.java index 889765b149..0cbf61cd05 100644 --- a/OsmAnd/src/net/osmand/plus/rastermaps/OsmandRasterMapsPlugin.java +++ b/OsmAnd/src/net/osmand/plus/rastermaps/OsmandRasterMapsPlugin.java @@ -6,6 +6,7 @@ import android.os.AsyncTask; import android.support.annotation.NonNull; import android.support.annotation.Nullable; import android.support.v7.app.AlertDialog; +import android.util.Log; import android.view.View; import android.widget.AdapterView; import android.widget.AdapterView.OnItemSelectedListener; @@ -28,6 +29,7 @@ import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandPlugin; import net.osmand.plus.OsmandSettings; import net.osmand.plus.OsmandSettings.CommonPreference; +import net.osmand.plus.OsmandSettings.LayerTransparencySeekbarMode; import net.osmand.plus.R; import net.osmand.plus.Version; import net.osmand.plus.activities.DownloadTilesDialog; @@ -105,6 +107,8 @@ public class OsmandRasterMapsPlugin extends OsmandPlugin { }; // mapView.addLayer(overlayLayer, 0.7f); settings.MAP_OVERLAY_TRANSPARENCY.addListener(overlayLayerListener); + + } @Override @@ -235,7 +239,6 @@ public class OsmandRasterMapsPlugin extends OsmandPlugin { public void registerLayerContextMenuActions(final OsmandMapTileView mapView, ContextMenuAdapter adapter, final MapActivity mapActivity) { - final MapActivityLayers layers = mapActivity.getMapLayers(); ContextMenuAdapter.ItemClickListener listener = new ContextMenuAdapter.OnRowItemClick() { @Override public boolean onRowItemClick(ArrayAdapter adapter, View view, int itemId, int position) { @@ -532,24 +535,46 @@ public class OsmandRasterMapsPlugin extends OsmandPlugin { OsmandMapTileView mapView = mapActivity.getMapView(); CommonPreference mapTypePreference; CommonPreference exMapTypePreference; + OsmandSettings.CommonPreference mapTransparencyPreference; ITileSource map; if (type == RasterMapType.OVERLAY) { + mapTransparencyPreference = settings.MAP_OVERLAY_TRANSPARENCY; mapTypePreference = settings.MAP_OVERLAY; exMapTypePreference = settings.MAP_OVERLAY_PREVIOUS; map = overlayLayer.getMap(); } else { // Underlay expected + mapTransparencyPreference = settings.MAP_TRANSPARENCY; mapTypePreference = settings.MAP_UNDERLAY; exMapTypePreference = settings.MAP_UNDERLAY_PREVIOUS; map = underlayLayer.getMap(); } + boolean isChecked = map == null; + boolean showSeekbar = isChecked && RasterMapMenu.isSeekbarVisible(app, type); + boolean hideSeekbar = !isChecked && RasterMapMenu.isSeekbarVisible(app, type); + MapActivityLayers mapLayers = mapActivity.getMapLayers(); + CommonPreference seekbarModePref = settings.LAYER_TRANSPARENCY_SEEKBAR_MODE; + if (showSeekbar) { + mapLayers.getMapControlsLayer().showTransparencyBar(mapTransparencyPreference); + mapLayers.getMapControlsLayer().setTransparencyBarEnabled(true); + if (seekbarModePref.get() == LayerTransparencySeekbarMode.UNDEFINED) { + final OsmandSettings.LayerTransparencySeekbarMode currentMapTypeSeekbarMode = + type == OsmandRasterMapsPlugin.RasterMapType.OVERLAY ? OsmandSettings.LayerTransparencySeekbarMode.OVERLAY : OsmandSettings.LayerTransparencySeekbarMode.UNDERLAY; + seekbarModePref.set(currentMapTypeSeekbarMode); + } + Log.e("111", "toggleUnderlayState: show"); + } else if (hideSeekbar) { + mapLayers.getMapControlsLayer().hideTransparencyBar(mapTransparencyPreference); + mapLayers.getMapControlsLayer().setTransparencyBarEnabled(false); + Log.e("111", "toggleUnderlayState: hide"); + } + if (map != null) { mapTypePreference.set(null); if (callback != null) { callback.onMapSelected(); } - MapActivityLayers mapLayers = mapActivity.getMapLayers(); updateMapLayers(mapView, null, mapLayers); } else { selectMapOverlayLayer(mapView, mapTypePreference, exMapTypePreference, false, mapActivity, callback); diff --git a/OsmAnd/src/net/osmand/plus/views/MapControlsLayer.java b/OsmAnd/src/net/osmand/plus/views/MapControlsLayer.java index 9739fc4d48..b959d8569f 100644 --- a/OsmAnd/src/net/osmand/plus/views/MapControlsLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/MapControlsLayer.java @@ -14,6 +14,7 @@ import android.os.Build; import android.support.annotation.NonNull; import android.support.v4.app.ActivityCompat; import android.support.v7.app.AlertDialog; +import android.util.Log; import android.view.MotionEvent; import android.view.View; import android.view.View.OnClickListener; @@ -32,6 +33,7 @@ import net.osmand.plus.OsmandApplication; import net.osmand.plus.OsmandPlugin; import net.osmand.plus.OsmandSettings; import net.osmand.plus.OsmandSettings.CommonPreference; +import net.osmand.plus.OsmandSettings.LayerTransparencySeekbarMode; import net.osmand.plus.R; import net.osmand.plus.TargetPointsHelper; import net.osmand.plus.TargetPointsHelper.TargetPoint; @@ -39,6 +41,7 @@ import net.osmand.plus.activities.MapActivity; import net.osmand.plus.activities.search.SearchAddressFragment; import net.osmand.plus.dashboard.DashboardOnMap.DashboardType; import net.osmand.plus.mapcontextmenu.other.MapRouteInfoMenu; +import net.osmand.plus.rastermaps.OsmandRasterMapsPlugin; import net.osmand.plus.routing.RoutingHelper; import net.osmand.plus.views.corenative.NativeCoreContext; @@ -68,7 +71,7 @@ public class MapControlsLayer extends OsmandMapLayer { private SeekBar transparencyBar; private LinearLayout transparencyBarLayout; - private static CommonPreference settingsToTransparency; + private static CommonPreference transparencySetting; private boolean isTransparencyBarEnabled = true; private OsmandSettings settings; @@ -611,8 +614,8 @@ public class MapControlsLayer extends OsmandMapLayer { transparencyBarLayout = (LinearLayout) mapActivity.findViewById(R.id.map_transparency_layout); transparencyBar = (SeekBar) mapActivity.findViewById(R.id.map_transparency_seekbar); transparencyBar.setMax(255); - if (settingsToTransparency != null) { - transparencyBar.setProgress(settingsToTransparency.get()); + if (transparencySetting != null) { + transparencyBar.setProgress(transparencySetting.get()); transparencyBarLayout.setVisibility(View.VISIBLE); } else { transparencyBarLayout.setVisibility(View.GONE); @@ -629,8 +632,8 @@ public class MapControlsLayer extends OsmandMapLayer { @Override public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { - if (settingsToTransparency != null) { - settingsToTransparency.set(progress); + if (transparencySetting != null) { + transparencySetting.set(progress); mapActivity.getMapView().refreshMap(); } } @@ -640,15 +643,26 @@ public class MapControlsLayer extends OsmandMapLayer { @Override public void onClick(View v) { transparencyBarLayout.setVisibility(View.GONE); - settings.SHOW_LAYER_TRANSPARENCY_SEEKBAR.set(false); - hideTransparencyBar(settingsToTransparency); + settings.LAYER_TRANSPARENCY_SEEKBAR_MODE.set(LayerTransparencySeekbarMode.OFF); + hideTransparencyBar(transparencySetting); } }); + + LayerTransparencySeekbarMode seekbarMode = settings.LAYER_TRANSPARENCY_SEEKBAR_MODE.get(); + if (seekbarMode == LayerTransparencySeekbarMode.OVERLAY && settings.MAP_OVERLAY.get() != null) { + showTransparencyBar(settings.MAP_OVERLAY_TRANSPARENCY); + setTransparencyBarEnabled(true); + Log.e("111", "init: show OVERLAY"); + } else if (seekbarMode == LayerTransparencySeekbarMode.UNDERLAY && settings.MAP_UNDERLAY.get() != null) { + showTransparencyBar(settings.MAP_TRANSPARENCY); + setTransparencyBarEnabled(true); + Log.e("111", "init: show UNDERLAY"); + } } public void showTransparencyBar(CommonPreference transparenPreference) { - if (MapControlsLayer.settingsToTransparency != transparenPreference) { - MapControlsLayer.settingsToTransparency = transparenPreference; + if (MapControlsLayer.transparencySetting != transparenPreference) { + MapControlsLayer.transparencySetting = transparenPreference; if (isTransparencyBarEnabled) { transparencyBarLayout.setVisibility(View.VISIBLE); } @@ -657,15 +671,15 @@ public class MapControlsLayer extends OsmandMapLayer { } public void hideTransparencyBar(CommonPreference transparentPreference) { - if (settingsToTransparency == transparentPreference) { + if (transparencySetting == transparentPreference) { transparencyBarLayout.setVisibility(View.GONE); - settingsToTransparency = null; + transparencySetting = null; } } public void setTransparencyBarEnabled(boolean isTransparencyBarEnabled) { this.isTransparencyBarEnabled = isTransparencyBarEnabled; - if (settingsToTransparency != null) { + if (transparencySetting != null) { if (isTransparencyBarEnabled) { transparencyBarLayout.setVisibility(View.VISIBLE); } else { @@ -674,10 +688,6 @@ public class MapControlsLayer extends OsmandMapLayer { } } - public boolean isTransparencyBarInitialized() { - return settingsToTransparency != null; - } - private class MapHudButton { View iv; int bgDark;