Search in sources :

Example 1 with LayerTransparencySeekbarMode

use of net.osmand.plus.plugins.rastermaps.LayerTransparencySeekbarMode in project Osmand by osmandapp.

the class RasterMapMenu method isSeekbarVisible.

@NonNull
public static Boolean isSeekbarVisible(@NonNull OsmandApplication app, @NonNull RasterMapType type) {
    LayerTransparencySeekbarMode currentMode = type == RasterMapType.OVERLAY ? OVERLAY : UNDERLAY;
    LayerTransparencySeekbarMode seekbarMode = app.getSettings().LAYER_TRANSPARENCY_SEEKBAR_MODE.get();
    return seekbarMode == LayerTransparencySeekbarMode.UNDEFINED || seekbarMode == currentMode;
}
Also used : LayerTransparencySeekbarMode(net.osmand.plus.plugins.rastermaps.LayerTransparencySeekbarMode) NonNull(androidx.annotation.NonNull)

Example 2 with LayerTransparencySeekbarMode

use of net.osmand.plus.plugins.rastermaps.LayerTransparencySeekbarMode in project Osmand by osmandapp.

the class RasterMapMenu method createLayersItems.

private static void createLayersItems(final ContextMenuAdapter contextMenuAdapter, final MapActivity mapActivity, final RasterMapType type) {
    final OsmandApplication app = mapActivity.getMyApplication();
    final OsmandSettings settings = app.getSettings();
    final OsmandRasterMapsPlugin plugin = OsmandPlugin.getPlugin(OsmandRasterMapsPlugin.class);
    assert plugin != null;
    final CommonPreference<Integer> mapTransparencyPreference;
    final CommonPreference<String> mapTypePreference;
    final CommonPreference<String> exMapTypePreference;
    final LayerTransparencySeekbarMode currentMode = type == RasterMapType.OVERLAY ? OVERLAY : UNDERLAY;
    @StringRes final int mapTypeString;
    @StringRes final int mapTypeStringTransparency;
    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 == RasterMapType.UNDERLAY) {
        mapTransparencyPreference = settings.MAP_TRANSPARENCY;
        mapTypePreference = settings.MAP_UNDERLAY;
        exMapTypePreference = settings.MAP_UNDERLAY_PREVIOUS;
        mapTypeString = R.string.map_underlay;
        mapTypeStringTransparency = R.string.map_transparency;
    } else {
        throw new RuntimeException("Unexpected raster map type");
    }
    CommonPreference<Boolean> hidePolygonsPref = settings.getCustomRenderBooleanProperty("noPolygons");
    CommonPreference<Boolean> hideWaterPolygonsPref = settings.getCustomRenderBooleanProperty("hideWaterPolygons");
    String mapTypeDescr = mapTypePreference.get();
    if (mapTypeDescr != null && mapTypeDescr.contains(".sqlitedb")) {
        mapTypeDescr = mapTypeDescr.replaceFirst(".sqlitedb", "");
    }
    final boolean mapSelected = mapTypeDescr != null;
    final int toggleActionStringId = mapSelected ? R.string.shared_string_on : R.string.shared_string_off;
    final OnMapSelectedCallback onMapSelectedCallback = new OnMapSelectedCallback() {

        @Override
        public void onMapSelected(boolean canceled) {
            mapActivity.getDashboard().refreshContent(true);
            boolean refreshToHidePolygons = type == RasterMapType.UNDERLAY;
            if (refreshToHidePolygons) {
                mapActivity.refreshMapComplete();
            }
        }
    };
    final MapLayers mapLayers = mapActivity.getMapLayers();
    ContextMenuAdapter.OnRowItemClick l = new ContextMenuAdapter.OnRowItemClick() {

        @Override
        public boolean onRowItemClick(ArrayAdapter<ContextMenuItem> adapter, View view, int itemId, int pos) {
            if (itemId == mapTypeString) {
                if (mapSelected) {
                    plugin.selectMapOverlayLayer(mapTypePreference, exMapTypePreference, true, mapActivity, onMapSelectedCallback);
                }
                return false;
            }
            return super.onRowItemClick(adapter, view, itemId, pos);
        }

        @Override
        public boolean onContextMenuClick(final ArrayAdapter<ContextMenuItem> adapter, final int itemId, final int pos, final boolean isChecked, int[] viewCoordinates) {
            if (itemId == toggleActionStringId) {
                app.runInUIThread(() -> {
                    plugin.toggleUnderlayState(mapActivity, type, onMapSelectedCallback);
                    mapActivity.refreshMapComplete();
                });
            } else if (itemId == R.string.show_polygons) {
                hidePolygonsPref.set(!isChecked);
                hideWaterPolygonsPref.set(!isChecked);
                mapActivity.refreshMapComplete();
            } else if (itemId == R.string.show_transparency_seekbar) {
                updateTransparencyBarVisibility(isChecked);
            } else if (itemId == R.string.show_parameter_seekbar) {
                if (isChecked) {
                    settings.SHOW_MAP_LAYER_PARAMETER.set(true);
                    MapTileLayer overlayLayer = plugin.getOverlayLayer();
                    if (overlayLayer != null) {
                        mapLayers.getMapControlsLayer().showParameterBar(overlayLayer);
                    }
                } else {
                    settings.SHOW_MAP_LAYER_PARAMETER.set(false);
                    mapLayers.getMapControlsLayer().hideParameterBar();
                    updateTransparencyBarVisibility(isSeekbarVisible(app, RasterMapType.OVERLAY));
                }
            }
            return false;
        }

        private void updateTransparencyBarVisibility(boolean visible) {
            if (visible) {
                settings.LAYER_TRANSPARENCY_SEEKBAR_MODE.set(currentMode);
                mapLayers.getMapControlsLayer().showTransparencyBar(mapTransparencyPreference);
            } else // if(settings.LAYER_TRANSPARENCY_SEEKBAR_MODE.get() == currentMode)
            {
                settings.LAYER_TRANSPARENCY_SEEKBAR_MODE.set(LayerTransparencySeekbarMode.OFF);
                mapLayers.getMapControlsLayer().hideTransparencyBar();
            }
        }
    };
    mapTypeDescr = mapSelected ? mapTypeDescr : mapActivity.getString(R.string.shared_string_none);
    contextMenuAdapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(toggleActionStringId, mapActivity).hideDivider(true).setListener(l).setSelected(mapSelected).createItem());
    if (mapSelected) {
        contextMenuAdapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(mapTypeString, mapActivity).hideDivider(true).setListener(l).setLayout(R.layout.list_item_icon_and_menu_wide).setDescription(mapTypeDescr).createItem());
        ContextMenuAdapter.OnIntegerValueChangedListener integerListener = new ContextMenuAdapter.OnIntegerValueChangedListener() {

            @Override
            public boolean onIntegerValueChangedListener(int newValue) {
                mapTransparencyPreference.set(newValue);
                mapActivity.getMapLayers().getMapControlsLayer().updateTransparencySliderValue();
                mapActivity.refreshMap();
                return false;
            }
        };
        // android:max="255" in layout is expected
        contextMenuAdapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(mapTypeStringTransparency, mapActivity).hideDivider(true).setLayout(R.layout.list_item_progress).setIcon(R.drawable.ic_action_opacity).setProgress(mapTransparencyPreference.get()).setListener(l).setIntegerListener(integerListener).createItem());
        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 = isSeekbarVisible(app, type);
        contextMenuAdapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.show_transparency_seekbar, mapActivity).hideDivider(true).setListener(l).setSelected(transparencySwitchState).createItem());
        ITileSource oveplayMap = plugin.getOverlayLayer().getMap();
        if (type == RasterMapType.OVERLAY && oveplayMap != null && oveplayMap.getParamType() != ParameterType.UNDEFINED) {
            contextMenuAdapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.show_parameter_seekbar, mapActivity).hideDivider(true).setListener(l).setSelected(settings.SHOW_MAP_LAYER_PARAMETER.get()).createItem());
        }
    }
}
Also used : OsmandApplication(net.osmand.plus.OsmandApplication) StringRes(androidx.annotation.StringRes) OsmandRasterMapsPlugin(net.osmand.plus.plugins.rastermaps.OsmandRasterMapsPlugin) ContextMenuItem(net.osmand.plus.ContextMenuItem) LayerTransparencySeekbarMode(net.osmand.plus.plugins.rastermaps.LayerTransparencySeekbarMode) View(android.view.View) OsmandSettings(net.osmand.plus.settings.backend.OsmandSettings) OnMapSelectedCallback(net.osmand.plus.plugins.rastermaps.OsmandRasterMapsPlugin.OnMapSelectedCallback) ContextMenuAdapter(net.osmand.plus.ContextMenuAdapter) MapTileLayer(net.osmand.plus.views.layers.MapTileLayer) ITileSource(net.osmand.map.ITileSource) ArrayAdapter(android.widget.ArrayAdapter) MapLayers(net.osmand.plus.views.MapLayers)

Example 3 with LayerTransparencySeekbarMode

use of net.osmand.plus.plugins.rastermaps.LayerTransparencySeekbarMode in project Osmand by osmandapp.

the class MapControlsLayer method initTransparencyBar.

// /////////////// Transparency bar /////////////////////////
private void initTransparencyBar() {
    MapActivity mapActivity = requireMapActivity();
    transparencyBarLayout = mapActivity.findViewById(R.id.map_transparency_layout);
    transparencySlider = mapActivity.findViewById(R.id.map_transparency_slider);
    parameterBarLayout = mapActivity.findViewById(R.id.layer_param_layout);
    parameterSlider = mapActivity.findViewById(R.id.layer_param_slider);
    transparencySlider.setValueTo(255);
    if (transparencySetting != null) {
        transparencySlider.setValue(transparencySetting.get());
        transparencyBarLayout.setVisibility(View.VISIBLE);
    } else {
        transparencyBarLayout.setVisibility(View.GONE);
    }
    transparencySlider.addOnChangeListener((slider, value, fromUser) -> {
        if (transparencySetting != null) {
            transparencySetting.set((int) value);
            mapActivity.refreshMap();
        }
    });
    boolean showParameterSlider = false;
    if (parameterMinSetting != null && parameterMaxSetting != null && parameterStepSetting != null && parameterValueSetting != null) {
        float paramMin = parameterMinSetting.get();
        float paramMax = parameterMaxSetting.get();
        float paramStep = parameterStepSetting.get();
        float paramValue = parameterValueSetting.get();
        if (paramMin < paramMax && paramStep < Math.abs(paramMax - paramMin) && paramStep > 0 && paramValue >= paramMin && paramValue <= paramMax) {
            parameterSlider.setValueFrom(paramMin);
            parameterSlider.setValueTo(paramMax);
            parameterSlider.setStepSize(paramStep);
            parameterSlider.setValue(paramValue);
            showParameterSlider = true;
        }
    }
    parameterSlider.addOnChangeListener((slider, value, fromUser) -> {
        if (parameterValueSetting != null) {
            parameterValueSetting.set(value);
            mapActivity.refreshMap();
        }
    });
    LayerTransparencySeekbarMode seekbarMode = settings.LAYER_TRANSPARENCY_SEEKBAR_MODE.get();
    if (OsmandPlugin.isActive(OsmandRasterMapsPlugin.class)) {
        if (seekbarMode == LayerTransparencySeekbarMode.OVERLAY && settings.MAP_OVERLAY.get() != null) {
            if (showParameterSlider) {
                hideTransparencyBar();
                parameterBarLayout.setVisibility(View.VISIBLE);
                updateParameterSliderUi();
            } else {
                showTransparencyBar(settings.MAP_OVERLAY_TRANSPARENCY);
            }
        } else if (seekbarMode == LayerTransparencySeekbarMode.UNDERLAY && settings.MAP_UNDERLAY.get() != null) {
            showTransparencyBar(settings.MAP_TRANSPARENCY);
        }
    }
}
Also used : LayerTransparencySeekbarMode(net.osmand.plus.plugins.rastermaps.LayerTransparencySeekbarMode) MapActivity(net.osmand.plus.activities.MapActivity)

Aggregations

LayerTransparencySeekbarMode (net.osmand.plus.plugins.rastermaps.LayerTransparencySeekbarMode)3 View (android.view.View)1 ArrayAdapter (android.widget.ArrayAdapter)1 NonNull (androidx.annotation.NonNull)1 StringRes (androidx.annotation.StringRes)1 ITileSource (net.osmand.map.ITileSource)1 ContextMenuAdapter (net.osmand.plus.ContextMenuAdapter)1 ContextMenuItem (net.osmand.plus.ContextMenuItem)1 OsmandApplication (net.osmand.plus.OsmandApplication)1 MapActivity (net.osmand.plus.activities.MapActivity)1 OsmandRasterMapsPlugin (net.osmand.plus.plugins.rastermaps.OsmandRasterMapsPlugin)1 OnMapSelectedCallback (net.osmand.plus.plugins.rastermaps.OsmandRasterMapsPlugin.OnMapSelectedCallback)1 OsmandSettings (net.osmand.plus.settings.backend.OsmandSettings)1 MapLayers (net.osmand.plus.views.MapLayers)1 MapTileLayer (net.osmand.plus.views.layers.MapTileLayer)1