Search in sources :

Example 1 with OsmandRasterMapsPlugin

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

the class OsmandAidlApi method registerShowSqliteDbFileReceiver.

private void registerShowSqliteDbFileReceiver(@NonNull MapActivity mapActivity) {
    final WeakReference<MapActivity> mapActivityRef = new WeakReference<>(mapActivity);
    BroadcastReceiver showSqliteDbFileReceiver = new BroadcastReceiver() {

        @Override
        public void onReceive(Context context, Intent intent) {
            OsmandSettings settings = app.getSettings();
            String fileName = intent.getStringExtra(AIDL_FILE_NAME);
            if (!Algorithms.isEmpty(fileName)) {
                settings.MAP_OVERLAY.set(fileName);
                settings.MAP_OVERLAY_PREVIOUS.set(fileName);
                MapActivity mapActivity = mapActivityRef.get();
                if (mapActivity != null) {
                    OsmandRasterMapsPlugin plugin = OsmandPlugin.getActivePlugin(OsmandRasterMapsPlugin.class);
                    if (plugin != null) {
                        plugin.updateMapLayers(mapActivity, mapActivity, settings.MAP_OVERLAY);
                    }
                }
            }
        }
    };
    registerReceiver(showSqliteDbFileReceiver, mapActivity, AIDL_SHOW_SQLITEDB_FILE);
}
Also used : Context(android.content.Context) WeakReference(java.lang.ref.WeakReference) Intent(android.content.Intent) BroadcastReceiver(android.content.BroadcastReceiver) OsmandRasterMapsPlugin(net.osmand.plus.plugins.rastermaps.OsmandRasterMapsPlugin) OsmandSettings(net.osmand.plus.settings.backend.OsmandSettings) MapActivity(net.osmand.plus.activities.MapActivity)

Example 2 with OsmandRasterMapsPlugin

use of net.osmand.plus.plugins.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.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 OsmandRasterMapsPlugin

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

the class OsmandPlugin method initPlugins.

public static void initPlugins(@NonNull OsmandApplication app) {
    Set<String> enabledPlugins = app.getSettings().getEnabledPlugins();
    allPlugins.clear();
    allPlugins.add(new WikipediaPlugin(app));
    allPlugins.add(new OsmandRasterMapsPlugin(app));
    allPlugins.add(new OsmandMonitoringPlugin(app));
    checkMarketPlugin(app, new SRTMPlugin(app));
    checkMarketPlugin(app, new NauticalMapsPlugin(app));
    checkMarketPlugin(app, new SkiMapsPlugin(app));
    allPlugins.add(new AudioVideoNotesPlugin(app));
    checkMarketPlugin(app, new ParkingPositionPlugin(app));
    allPlugins.add(new OsmEditingPlugin(app));
    allPlugins.add(new OpenPlaceReviewsPlugin(app));
    allPlugins.add(new MapillaryPlugin(app));
    allPlugins.add(new AccessibilityPlugin(app));
    allPlugins.add(new OsmandDevelopmentPlugin(app));
    loadCustomPlugins(app);
    registerAppInitializingDependedProperties(app);
    enablePluginsByDefault(app, enabledPlugins);
    activatePlugins(app, enabledPlugins);
}
Also used : SRTMPlugin(net.osmand.plus.plugins.srtm.SRTMPlugin) AudioVideoNotesPlugin(net.osmand.plus.plugins.audionotes.AudioVideoNotesPlugin) OpenPlaceReviewsPlugin(net.osmand.plus.plugins.openplacereviews.OpenPlaceReviewsPlugin) OsmandMonitoringPlugin(net.osmand.plus.plugins.monitoring.OsmandMonitoringPlugin) OsmEditingPlugin(net.osmand.plus.plugins.osmedit.OsmEditingPlugin) MapillaryPlugin(net.osmand.plus.plugins.mapillary.MapillaryPlugin) SkiMapsPlugin(net.osmand.plus.plugins.skimaps.SkiMapsPlugin) ParkingPositionPlugin(net.osmand.plus.plugins.parking.ParkingPositionPlugin) OsmandDevelopmentPlugin(net.osmand.plus.plugins.development.OsmandDevelopmentPlugin) NauticalMapsPlugin(net.osmand.plus.plugins.openseamaps.NauticalMapsPlugin) WikipediaPlugin(net.osmand.plus.wikipedia.WikipediaPlugin) AccessibilityPlugin(net.osmand.plus.plugins.accessibility.AccessibilityPlugin) OsmandRasterMapsPlugin(net.osmand.plus.plugins.rastermaps.OsmandRasterMapsPlugin)

Example 4 with OsmandRasterMapsPlugin

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

the class OsmandAidlApi method registerHideSqliteDbFileReceiver.

private void registerHideSqliteDbFileReceiver(@NonNull MapActivity mapActivity) {
    final WeakReference<MapActivity> mapActivityRef = new WeakReference<>(mapActivity);
    BroadcastReceiver hideSqliteDbFileReceiver = new BroadcastReceiver() {

        @Override
        public void onReceive(Context context, Intent intent) {
            OsmandSettings settings = app.getSettings();
            String fileName = intent.getStringExtra(AIDL_FILE_NAME);
            if (!Algorithms.isEmpty(fileName) && fileName.equals(settings.MAP_OVERLAY.get())) {
                settings.MAP_OVERLAY.set(null);
                settings.MAP_OVERLAY_PREVIOUS.set(null);
                MapActivity mapActivity = mapActivityRef.get();
                if (mapActivity != null) {
                    OsmandRasterMapsPlugin plugin = OsmandPlugin.getActivePlugin(OsmandRasterMapsPlugin.class);
                    if (plugin != null) {
                        plugin.updateMapLayers(mapActivity, mapActivity, settings.MAP_OVERLAY);
                    }
                }
            }
        }
    };
    registerReceiver(hideSqliteDbFileReceiver, mapActivity, AIDL_HIDE_SQLITEDB_FILE);
}
Also used : Context(android.content.Context) WeakReference(java.lang.ref.WeakReference) Intent(android.content.Intent) BroadcastReceiver(android.content.BroadcastReceiver) OsmandRasterMapsPlugin(net.osmand.plus.plugins.rastermaps.OsmandRasterMapsPlugin) OsmandSettings(net.osmand.plus.settings.backend.OsmandSettings) MapActivity(net.osmand.plus.activities.MapActivity)

Example 5 with OsmandRasterMapsPlugin

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

the class SqliteTileImportTask method onPostExecute.

@Override
protected void onPostExecute(String error) {
    hideProgress();
    if (error == null) {
        FragmentActivity activity = activityRef.get();
        OsmandRasterMapsPlugin plugin = OsmandPlugin.getPlugin(OsmandRasterMapsPlugin.class);
        OsmandPlugin.enablePluginIfNeeded(activity, app, plugin, true);
        if (activity instanceof MapActivity) {
            MapActivity mapActivity = (MapActivity) activity;
            mapActivity.getMapLayers().selectMapLayer(mapActivity, true, null);
        }
        Toast.makeText(app, app.getString(R.string.map_imported_successfully), Toast.LENGTH_SHORT).show();
    } else {
        Toast.makeText(app, app.getString(R.string.map_import_error) + ": " + error, Toast.LENGTH_SHORT).show();
    }
}
Also used : FragmentActivity(androidx.fragment.app.FragmentActivity) OsmandRasterMapsPlugin(net.osmand.plus.plugins.rastermaps.OsmandRasterMapsPlugin) MapActivity(net.osmand.plus.activities.MapActivity)

Aggregations

OsmandRasterMapsPlugin (net.osmand.plus.plugins.rastermaps.OsmandRasterMapsPlugin)5 MapActivity (net.osmand.plus.activities.MapActivity)3 OsmandSettings (net.osmand.plus.settings.backend.OsmandSettings)3 BroadcastReceiver (android.content.BroadcastReceiver)2 Context (android.content.Context)2 Intent (android.content.Intent)2 WeakReference (java.lang.ref.WeakReference)2 View (android.view.View)1 ArrayAdapter (android.widget.ArrayAdapter)1 StringRes (androidx.annotation.StringRes)1 FragmentActivity (androidx.fragment.app.FragmentActivity)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 AccessibilityPlugin (net.osmand.plus.plugins.accessibility.AccessibilityPlugin)1 AudioVideoNotesPlugin (net.osmand.plus.plugins.audionotes.AudioVideoNotesPlugin)1 OsmandDevelopmentPlugin (net.osmand.plus.plugins.development.OsmandDevelopmentPlugin)1 MapillaryPlugin (net.osmand.plus.plugins.mapillary.MapillaryPlugin)1 OsmandMonitoringPlugin (net.osmand.plus.plugins.monitoring.OsmandMonitoringPlugin)1