Search in sources :

Example 1 with OsmandRasterMapsPlugin

use of net.osmand.plus.rastermaps.OsmandRasterMapsPlugin 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.getEnabledPlugin(OsmandRasterMapsPlugin.class);
    assert plugin != null;
    final OsmandSettings.CommonPreference<Integer> mapTransparencyPreference;
    final OsmandSettings.CommonPreference<String> mapTypePreference;
    final OsmandSettings.CommonPreference<String> exMapTypePreference;
    final LayerTransparencySeekbarMode currentMapTypeSeekbarMode = type == RasterMapType.OVERLAY ? LayerTransparencySeekbarMode.OVERLAY : LayerTransparencySeekbarMode.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");
    }
    final OsmandSettings.CommonPreference<Boolean> hidePolygonsPref = mapActivity.getMyApplication().getSettings().getCustomRenderBooleanProperty("noPolygons");
    String mapTypeDescr = mapTypePreference.get();
    final boolean selected = mapTypeDescr != null;
    final int toggleActionStringId = selected ? R.string.shared_string_enabled : R.string.shared_string_disabled;
    final OnMapSelectedCallback onMapSelectedCallback = new OnMapSelectedCallback() {

        @Override
        public void onMapSelected(boolean canceled) {
            if (type == RasterMapType.UNDERLAY && !canceled && !selected) {
                hidePolygonsPref.set(true);
                refreshMapComplete(mapActivity);
            } else if (type == RasterMapType.UNDERLAY && !canceled && mapTypePreference.get() == null) {
                hidePolygonsPref.set(false);
                refreshMapComplete(mapActivity);
            }
            mapActivity.getDashboard().refreshContent(true);
        }
    };
    final MapActivityLayers 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 (selected) {
                    plugin.selectMapOverlayLayer(mapActivity.getMapView(), 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(new Runnable() {

                    @Override
                    public void run() {
                        plugin.toggleUnderlayState(mapActivity, type, onMapSelectedCallback);
                        refreshMapComplete(mapActivity);
                    }
                });
            } else if (itemId == R.string.show_polygons) {
                hidePolygonsPref.set(!isChecked);
                refreshMapComplete(mapActivity);
            } else if (itemId == R.string.show_transparency_seekbar) {
                settings.LAYER_TRANSPARENCY_SEEKBAR_MODE.set(isChecked ? currentMapTypeSeekbarMode : LayerTransparencySeekbarMode.OFF);
                if (isChecked) {
                    mapLayers.getMapControlsLayer().showTransparencyBar(mapTransparencyPreference);
                } else {
                    mapLayers.getMapControlsLayer().hideTransparencyBar(mapTransparencyPreference);
                }
                mapLayers.getMapControlsLayer().setTransparencyBarEnabled(isChecked);
            }
            return false;
        }
    };
    mapTypeDescr = selected ? mapTypeDescr : mapActivity.getString(R.string.shared_string_none);
    contextMenuAdapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(toggleActionStringId, mapActivity).hideDivider(true).setListener(l).setSelected(selected).createItem());
    if (selected) {
        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.getMapView().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());
    }
}
Also used : OsmandApplication(net.osmand.plus.OsmandApplication) StringRes(android.support.annotation.StringRes) OsmandRasterMapsPlugin(net.osmand.plus.rastermaps.OsmandRasterMapsPlugin) MapActivityLayers(net.osmand.plus.activities.MapActivityLayers) ContextMenuItem(net.osmand.plus.ContextMenuItem) LayerTransparencySeekbarMode(net.osmand.plus.OsmandSettings.LayerTransparencySeekbarMode) View(android.view.View) OsmandSettings(net.osmand.plus.OsmandSettings) OnMapSelectedCallback(net.osmand.plus.rastermaps.OsmandRasterMapsPlugin.OnMapSelectedCallback) ContextMenuAdapter(net.osmand.plus.ContextMenuAdapter) ArrayAdapter(android.widget.ArrayAdapter)

Example 2 with OsmandRasterMapsPlugin

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

the class MapUnderlayAction method execute.

@Override
public void execute(MapActivity activity) {
    OsmandRasterMapsPlugin plugin = OsmandPlugin.getEnabledPlugin(OsmandRasterMapsPlugin.class);
    if (plugin != null) {
        OsmandSettings settings = activity.getMyApplication().getSettings();
        List<Pair<String, String>> sources = loadListFromParams();
        Pair<String, String> currentSource = new Pair<>(settings.MAP_UNDERLAY.get(), settings.MAP_UNDERLAY.get());
        Pair<String, String> nextSource = sources.get(0);
        int index = sources.indexOf(currentSource);
        if (index >= 0 && index + 1 < sources.size()) {
            nextSource = sources.get(index + 1);
        }
        boolean hasUnderlay = !nextSource.first.equals(KEY_NO_UNDERLAY);
        if (hasUnderlay) {
            settings.MAP_UNDERLAY.set(nextSource.first);
            settings.MAP_UNDERLAY_PREVIOUS.set(nextSource.first);
        } else {
            settings.MAP_UNDERLAY.set(null);
            settings.MAP_UNDERLAY_PREVIOUS.set(null);
        }
        final OsmandSettings.CommonPreference<Boolean> hidePolygonsPref = activity.getMyApplication().getSettings().getCustomRenderBooleanProperty("noPolygons");
        hidePolygonsPref.set(hasUnderlay);
        plugin.updateMapLayers(activity.getMapView(), settings.MAP_UNDERLAY, activity.getMapLayers());
        Toast.makeText(activity, activity.getString(R.string.quick_action_map_underlay_switch, nextSource.second), Toast.LENGTH_SHORT).show();
    }
}
Also used : OsmandRasterMapsPlugin(net.osmand.plus.rastermaps.OsmandRasterMapsPlugin) OsmandSettings(net.osmand.plus.OsmandSettings) Pair(android.support.v4.util.Pair)

Example 3 with OsmandRasterMapsPlugin

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

the class OsmandPlugin method initPlugins.

public static void initPlugins(OsmandApplication app) {
    OsmandSettings settings = app.getSettings();
    Set<String> enabledPlugins = settings.getEnabledPlugins();
    allPlugins.add(new MapillaryPlugin(app));
    enabledPlugins.add(MapillaryPlugin.ID);
    allPlugins.add(new OsmandRasterMapsPlugin(app));
    allPlugins.add(new OsmandMonitoringPlugin(app));
    checkMarketPlugin(app, new SRTMPlugin(app), true, SRTM_PLUGIN_COMPONENT_PAID, SRTM_PLUGIN_COMPONENT);
    // ? questionable - definitely not market plugin
    // checkMarketPlugin(app, new TouringViewPlugin(app), false, TouringViewPlugin.COMPONENT, null);
    checkMarketPlugin(app, new NauticalMapsPlugin(app), false, NauticalMapsPlugin.COMPONENT, null);
    checkMarketPlugin(app, new SkiMapsPlugin(app), false, SkiMapsPlugin.COMPONENT, null);
    allPlugins.add(new AudioVideoNotesPlugin(app));
    checkMarketPlugin(app, new ParkingPositionPlugin(app), false, ParkingPositionPlugin.PARKING_PLUGIN_COMPONENT, null);
    allPlugins.add(new AccessibilityPlugin(app));
    allPlugins.add(new OsmEditingPlugin(app));
    allPlugins.add(new OsmandDevelopmentPlugin(app));
    activatePlugins(app, enabledPlugins);
}
Also used : SRTMPlugin(net.osmand.plus.srtmplugin.SRTMPlugin) AudioVideoNotesPlugin(net.osmand.plus.audionotes.AudioVideoNotesPlugin) OsmandMonitoringPlugin(net.osmand.plus.monitoring.OsmandMonitoringPlugin) MapillaryPlugin(net.osmand.plus.mapillary.MapillaryPlugin) OsmEditingPlugin(net.osmand.plus.osmedit.OsmEditingPlugin) SkiMapsPlugin(net.osmand.plus.skimapsplugin.SkiMapsPlugin) ParkingPositionPlugin(net.osmand.plus.parkingpoint.ParkingPositionPlugin) OsmandDevelopmentPlugin(net.osmand.plus.development.OsmandDevelopmentPlugin) NauticalMapsPlugin(net.osmand.plus.openseamapsplugin.NauticalMapsPlugin) AccessibilityPlugin(net.osmand.access.AccessibilityPlugin) OsmandRasterMapsPlugin(net.osmand.plus.rastermaps.OsmandRasterMapsPlugin)

Example 4 with OsmandRasterMapsPlugin

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

the class MapOverlayAction method execute.

@Override
public void execute(MapActivity activity) {
    OsmandRasterMapsPlugin plugin = OsmandPlugin.getEnabledPlugin(OsmandRasterMapsPlugin.class);
    if (plugin != null) {
        OsmandSettings settings = activity.getMyApplication().getSettings();
        List<Pair<String, String>> sources = loadListFromParams();
        Pair<String, String> currentSource = new Pair<>(settings.MAP_OVERLAY.get(), settings.MAP_OVERLAY.get());
        Pair<String, String> nextSource = sources.get(0);
        int index = sources.indexOf(currentSource);
        if (index >= 0 && index + 1 < sources.size()) {
            nextSource = sources.get(index + 1);
        }
        boolean hasOverlay = !nextSource.first.equals(KEY_NO_OVERLAY);
        if (hasOverlay) {
            settings.MAP_OVERLAY.set(nextSource.first);
            settings.MAP_OVERLAY_PREVIOUS.set(nextSource.first);
        } else {
            settings.MAP_OVERLAY.set(null);
            settings.MAP_OVERLAY_PREVIOUS.set(null);
        }
        plugin.updateMapLayers(activity.getMapView(), settings.MAP_OVERLAY, activity.getMapLayers());
        Toast.makeText(activity, activity.getString(R.string.quick_action_map_overlay_switch, nextSource.second), Toast.LENGTH_SHORT).show();
    }
}
Also used : OsmandRasterMapsPlugin(net.osmand.plus.rastermaps.OsmandRasterMapsPlugin) OsmandSettings(net.osmand.plus.OsmandSettings) Pair(android.support.v4.util.Pair)

Aggregations

OsmandRasterMapsPlugin (net.osmand.plus.rastermaps.OsmandRasterMapsPlugin)4 OsmandSettings (net.osmand.plus.OsmandSettings)3 Pair (android.support.v4.util.Pair)2 StringRes (android.support.annotation.StringRes)1 View (android.view.View)1 ArrayAdapter (android.widget.ArrayAdapter)1 AccessibilityPlugin (net.osmand.access.AccessibilityPlugin)1 ContextMenuAdapter (net.osmand.plus.ContextMenuAdapter)1 ContextMenuItem (net.osmand.plus.ContextMenuItem)1 OsmandApplication (net.osmand.plus.OsmandApplication)1 LayerTransparencySeekbarMode (net.osmand.plus.OsmandSettings.LayerTransparencySeekbarMode)1 MapActivityLayers (net.osmand.plus.activities.MapActivityLayers)1 AudioVideoNotesPlugin (net.osmand.plus.audionotes.AudioVideoNotesPlugin)1 OsmandDevelopmentPlugin (net.osmand.plus.development.OsmandDevelopmentPlugin)1 MapillaryPlugin (net.osmand.plus.mapillary.MapillaryPlugin)1 OsmandMonitoringPlugin (net.osmand.plus.monitoring.OsmandMonitoringPlugin)1 NauticalMapsPlugin (net.osmand.plus.openseamapsplugin.NauticalMapsPlugin)1 OsmEditingPlugin (net.osmand.plus.osmedit.OsmEditingPlugin)1 ParkingPositionPlugin (net.osmand.plus.parkingpoint.ParkingPositionPlugin)1 OnMapSelectedCallback (net.osmand.plus.rastermaps.OsmandRasterMapsPlugin.OnMapSelectedCallback)1