Search in sources :

Example 1 with MapActivityLayers

use of net.osmand.plus.activities.MapActivityLayers 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 MapActivityLayers

use of net.osmand.plus.activities.MapActivityLayers in project Osmand by osmandapp.

the class OsmandRasterMapsPlugin method selectMapOverlayLayer.

public void selectMapOverlayLayer(@NonNull final OsmandMapTileView mapView, @NonNull final CommonPreference<String> mapPref, @NonNull final CommonPreference<String> exMapPref, boolean force, @NonNull final MapActivity activity, @Nullable final OnMapSelectedCallback callback) {
    final MapActivityLayers layers = activity.getMapLayers();
    if (!force && exMapPref.get() != null) {
        mapPref.set(exMapPref.get());
        if (callback != null) {
            callback.onMapSelected(false);
        }
        updateMapLayers(mapView, mapPref, layers);
        return;
    }
    final OsmandSettings settings = app.getSettings();
    Map<String, String> entriesMap = settings.getTileSourceEntries();
    final ArrayList<String> keys = new ArrayList<>(entriesMap.keySet());
    AlertDialog.Builder builder = new AlertDialog.Builder(activity);
    final String[] items = new String[entriesMap.size() + 1];
    int i = 0;
    for (String it : entriesMap.values()) {
        items[i++] = it;
    }
    items[i] = app.getString(R.string.install_more);
    builder.setSingleChoiceItems(items, -1, new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            if (which == items.length - 1) {
                installMapLayers(activity, new ResultMatcher<TileSourceTemplate>() {

                    TileSourceTemplate template = null;

                    int count = 0;

                    @Override
                    public boolean publish(TileSourceTemplate object) {
                        if (object == null) {
                            if (count == 1) {
                                mapPref.set(template.getName());
                                exMapPref.set(template.getName());
                                if (callback != null) {
                                    callback.onMapSelected(false);
                                }
                                updateMapLayers(mapView, mapPref, layers);
                            } else {
                                selectMapOverlayLayer(mapView, mapPref, exMapPref, false, activity, null);
                            }
                        } else {
                            count++;
                            template = object;
                        }
                        return false;
                    }

                    @Override
                    public boolean isCancelled() {
                        return false;
                    }
                });
            } else {
                mapPref.set(keys.get(which));
                exMapPref.set(keys.get(which));
                if (callback != null) {
                    callback.onMapSelected(false);
                }
                updateMapLayers(mapView, mapPref, layers);
            }
            dialog.dismiss();
        }
    }).setNegativeButton(R.string.shared_string_cancel, null).setOnDismissListener(new DialogInterface.OnDismissListener() {

        @Override
        public void onDismiss(DialogInterface dialog) {
            if (callback != null) {
                callback.onMapSelected(true);
            }
        }
    });
    builder.show();
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) TileSourceTemplate(net.osmand.map.TileSourceManager.TileSourceTemplate) MapActivityLayers(net.osmand.plus.activities.MapActivityLayers) DialogInterface(android.content.DialogInterface) ArrayList(java.util.ArrayList) ResultMatcher(net.osmand.ResultMatcher) OsmandSettings(net.osmand.plus.OsmandSettings)

Example 3 with MapActivityLayers

use of net.osmand.plus.activities.MapActivityLayers in project Osmand by osmandapp.

the class MapillaryPlugin method registerLayerContextMenuActions.

@Override
public void registerLayerContextMenuActions(final OsmandMapTileView mapView, ContextMenuAdapter adapter, final MapActivity mapActivity) {
    ContextMenuAdapter.ItemClickListener listener = new ContextMenuAdapter.OnRowItemClick() {

        @Override
        public boolean onRowItemClick(ArrayAdapter<ContextMenuItem> adapter, View view, int itemId, int position) {
            if (itemId == R.string.mapillary) {
                mapActivity.getDashboard().setDashboardVisibility(true, DashboardOnMap.DashboardType.MAPILLARY, AndroidUtils.getCenterViewCoordinates(view));
                return false;
            }
            return true;
        }

        @Override
        public boolean onContextMenuClick(final ArrayAdapter<ContextMenuItem> adapter, int itemId, final int pos, boolean isChecked, int[] viewCoordinates) {
            final OsmandSettings settings = mapActivity.getMyApplication().getSettings();
            if (itemId == R.string.mapillary) {
                OsmandMapTileView mapView = mapActivity.getMapView();
                MapActivityLayers mapLayers = mapActivity.getMapLayers();
                settings.SHOW_MAPILLARY.set(!settings.SHOW_MAPILLARY.get());
                updateMapLayers(mapView, mapLayers, false);
                ContextMenuItem item = adapter.getItem(pos);
                if (item != null) {
                    item.setSelected(settings.SHOW_MAPILLARY.get());
                    item.setColorRes(settings.SHOW_MAPILLARY.get() ? R.color.osmand_orange : ContextMenuItem.INVALID_ID);
                    adapter.notifyDataSetChanged();
                }
            }
            return false;
        }
    };
    if (rasterLayer.getMap() == null) {
        settings.SHOW_MAPILLARY.set(false);
    }
    adapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.mapillary, mapActivity).setSelected(settings.SHOW_MAPILLARY.get()).setColor(settings.SHOW_MAPILLARY.get() ? R.color.osmand_orange : ContextMenuItem.INVALID_ID).setIcon(R.drawable.ic_action_mapillary).setSecondaryIcon(R.drawable.ic_action_additional_option).setListener(listener).setPosition(11).createItem());
}
Also used : ContextMenuAdapter(net.osmand.plus.ContextMenuAdapter) MapActivityLayers(net.osmand.plus.activities.MapActivityLayers) ContextMenuItem(net.osmand.plus.ContextMenuItem) OsmandMapTileView(net.osmand.plus.views.OsmandMapTileView) OsmandMapTileView(net.osmand.plus.views.OsmandMapTileView) View(android.view.View) ArrayAdapter(android.widget.ArrayAdapter) OsmandSettings(net.osmand.plus.OsmandSettings)

Example 4 with MapActivityLayers

use of net.osmand.plus.activities.MapActivityLayers in project Osmand by osmandapp.

the class OsmandRasterMapsPlugin method toggleUnderlayState.

public void toggleUnderlayState(@NonNull MapActivity mapActivity, @NonNull RasterMapType type, @Nullable OnMapSelectedCallback callback) {
    OsmandMapTileView mapView = mapActivity.getMapView();
    CommonPreference<String> mapTypePreference;
    CommonPreference<String> exMapTypePreference;
    OsmandSettings.CommonPreference<Integer> 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<LayerTransparencySeekbarMode> 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);
        }
    } else if (hideSeekbar) {
        mapLayers.getMapControlsLayer().hideTransparencyBar(mapTransparencyPreference);
        mapLayers.getMapControlsLayer().setTransparencyBarEnabled(false);
    }
    if (map != null) {
        mapTypePreference.set(null);
        if (callback != null) {
            callback.onMapSelected(false);
        }
        updateMapLayers(mapView, null, mapLayers);
    } else {
        selectMapOverlayLayer(mapView, mapTypePreference, exMapTypePreference, false, mapActivity, callback);
    }
}
Also used : MapActivityLayers(net.osmand.plus.activities.MapActivityLayers) LayerTransparencySeekbarMode(net.osmand.plus.OsmandSettings.LayerTransparencySeekbarMode) LayerTransparencySeekbarMode(net.osmand.plus.OsmandSettings.LayerTransparencySeekbarMode) ITileSource(net.osmand.map.ITileSource) OsmandMapTileView(net.osmand.plus.views.OsmandMapTileView) OsmandSettings(net.osmand.plus.OsmandSettings)

Aggregations

OsmandSettings (net.osmand.plus.OsmandSettings)4 MapActivityLayers (net.osmand.plus.activities.MapActivityLayers)4 View (android.view.View)2 ArrayAdapter (android.widget.ArrayAdapter)2 ContextMenuAdapter (net.osmand.plus.ContextMenuAdapter)2 ContextMenuItem (net.osmand.plus.ContextMenuItem)2 LayerTransparencySeekbarMode (net.osmand.plus.OsmandSettings.LayerTransparencySeekbarMode)2 OsmandMapTileView (net.osmand.plus.views.OsmandMapTileView)2 DialogInterface (android.content.DialogInterface)1 StringRes (android.support.annotation.StringRes)1 AlertDialog (android.support.v7.app.AlertDialog)1 ArrayList (java.util.ArrayList)1 ResultMatcher (net.osmand.ResultMatcher)1 ITileSource (net.osmand.map.ITileSource)1 TileSourceTemplate (net.osmand.map.TileSourceManager.TileSourceTemplate)1 OsmandApplication (net.osmand.plus.OsmandApplication)1 OsmandRasterMapsPlugin (net.osmand.plus.rastermaps.OsmandRasterMapsPlugin)1 OnMapSelectedCallback (net.osmand.plus.rastermaps.OsmandRasterMapsPlugin.OnMapSelectedCallback)1