Search in sources :

Example 21 with OsmandMapTileView

use of net.osmand.plus.views.OsmandMapTileView in project Osmand by osmandapp.

the class ConfigureMapMenu method createRenderingAttributeItems.

private void createRenderingAttributeItems(List<RenderingRuleProperty> customRules, final ContextMenuAdapter adapter, final MapActivity activity) {
    adapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.map_widget_map_rendering, activity).setCategory(true).setLayout(R.layout.list_group_title_with_switch).createItem());
    adapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.map_widget_renderer, activity).setDescription(getRenderDescr(activity)).setLayout(R.layout.list_item_single_line_descrition_narrow).setIcon(R.drawable.ic_map).setListener(new ContextMenuAdapter.ItemClickListener() {

        @Override
        public boolean onContextMenuClick(final ArrayAdapter<ContextMenuItem> ad, int itemId, final int pos, boolean isChecked, int[] viewCoordinates) {
            AlertDialog.Builder bld = new AlertDialog.Builder(activity);
            bld.setTitle(R.string.renderers);
            final OsmandApplication app = activity.getMyApplication();
            final ArrayList<String> items = new ArrayList<>(app.getRendererRegistry().getRendererNames());
            boolean nauticalPluginDisabled = OsmandPlugin.getEnabledPlugin(NauticalMapsPlugin.class) == null;
            final List<String> visibleNamesList = new ArrayList<>();
            int selected = -1;
            final String selectedName = app.getRendererRegistry().getCurrentSelectedRenderer().getName();
            int i = 0;
            Iterator<String> iterator = items.iterator();
            while (iterator.hasNext()) {
                String item = iterator.next();
                if (nauticalPluginDisabled && item.equals(RendererRegistry.NAUTICAL_RENDER)) {
                    iterator.remove();
                } else {
                    if (item.equals(selectedName)) {
                        selected = i;
                    }
                    String translation = RendererRegistry.getTranslatedRendererName(activity, item);
                    visibleNamesList.add(translation != null ? translation : item.replace('_', ' ').replace('-', ' '));
                    i++;
                }
            }
            bld.setSingleChoiceItems(visibleNamesList.toArray(new String[visibleNamesList.size()]), selected, new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                    String renderer = items.get(which);
                    RenderingRulesStorage loaded = app.getRendererRegistry().getRenderer(renderer);
                    if (loaded != null) {
                        OsmandMapTileView view = activity.getMapView();
                        view.getSettings().RENDERER.set(renderer);
                        app.getRendererRegistry().setCurrentSelectedRender(loaded);
                        refreshMapComplete(activity);
                    } else {
                        Toast.makeText(app, R.string.renderer_load_exception, Toast.LENGTH_SHORT).show();
                    }
                    adapter.getItem(pos).setDescription(getRenderDescr(activity));
                    activity.getDashboard().refreshContent(true);
                    dialog.dismiss();
                }
            });
            bld.setNegativeButton(R.string.shared_string_dismiss, null);
            bld.show();
            return false;
        }
    }).createItem());
    adapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.map_mode, activity).setDescription(getDayNightDescr(activity)).setLayout(R.layout.list_item_single_line_descrition_narrow).setIcon(getDayNightIcon(activity)).setListener(new ItemClickListener() {

        @Override
        public boolean onContextMenuClick(final ArrayAdapter<ContextMenuItem> ad, int itemId, final int pos, boolean isChecked, int[] viewCoordinates) {
            final OsmandMapTileView view = activity.getMapView();
            AlertDialog.Builder bld = new AlertDialog.Builder(view.getContext());
            bld.setTitle(R.string.daynight);
            final String[] items = new String[OsmandSettings.DayNightMode.values().length];
            for (int i = 0; i < items.length; i++) {
                items[i] = OsmandSettings.DayNightMode.values()[i].toHumanString(activity.getMyApplication());
            }
            int i = view.getSettings().DAYNIGHT_MODE.get().ordinal();
            bld.setSingleChoiceItems(items, i, new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                    view.getSettings().DAYNIGHT_MODE.set(OsmandSettings.DayNightMode.values()[which]);
                    refreshMapComplete(activity);
                    dialog.dismiss();
                    activity.getDashboard().refreshContent(true);
                // adapter.getItem(pos).setDescription(s, getDayNightDescr(activity));
                // ad.notifyDataSetInvalidated();
                }
            });
            bld.setNegativeButton(R.string.shared_string_dismiss, null);
            bld.show();
            return false;
        }
    }).createItem());
    adapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.map_magnifier, activity).setDescription(String.format(Locale.UK, "%.0f", 100f * activity.getMyApplication().getSettings().MAP_DENSITY.get()) + " %").setLayout(R.layout.list_item_single_line_descrition_narrow).setIcon(R.drawable.ic_action_map_magnifier).setListener(new ContextMenuAdapter.ItemClickListener() {

        @Override
        public boolean onContextMenuClick(final ArrayAdapter<ContextMenuItem> ad, int itemId, final int pos, boolean isChecked, int[] viewCoordinates) {
            final OsmandMapTileView view = activity.getMapView();
            final OsmandSettings.OsmandPreference<Float> mapDensity = view.getSettings().MAP_DENSITY;
            final AlertDialog.Builder bld = new AlertDialog.Builder(view.getContext());
            int p = (int) (mapDensity.get() * 100);
            final TIntArrayList tlist = new TIntArrayList(new int[] { 33, 50, 75, 100, 150, 200, 300, 400 });
            final List<String> values = new ArrayList<>();
            int i = -1;
            for (int k = 0; k <= tlist.size(); k++) {
                final boolean end = k == tlist.size();
                if (i == -1) {
                    if ((end || p < tlist.get(k))) {
                        values.add(p + " %");
                        i = k;
                    } else if (p == tlist.get(k)) {
                        i = k;
                    }
                }
                if (k < tlist.size()) {
                    values.add(tlist.get(k) + " %");
                }
            }
            if (values.size() != tlist.size()) {
                tlist.insert(i, p);
            }
            bld.setTitle(R.string.map_magnifier);
            bld.setSingleChoiceItems(values.toArray(new String[values.size()]), i, new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                    int p = tlist.get(which);
                    mapDensity.set(p / 100.0f);
                    view.setComplexZoom(view.getZoom(), view.getSettingsMapDensity());
                    MapRendererContext mapContext = NativeCoreContext.getMapRendererContext();
                    if (mapContext != null) {
                        mapContext.updateMapSettings();
                    }
                    adapter.getItem(pos).setDescription(String.format(Locale.UK, "%.0f", 100f * activity.getMyApplication().getSettings().MAP_DENSITY.get()) + " %");
                    ad.notifyDataSetInvalidated();
                    dialog.dismiss();
                }
            });
            bld.setNegativeButton(R.string.shared_string_dismiss, null);
            bld.show();
            return false;
        }
    }).createItem());
    ContextMenuItem props;
    props = createRenderingProperty(customRules, adapter, activity, R.drawable.ic_action_intersection, ROAD_STYLE_ATTR);
    if (props != null) {
        adapter.addItem(props);
    }
    adapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.text_size, activity).setDescription(getScale(activity)).setLayout(R.layout.list_item_single_line_descrition_narrow).setIcon(R.drawable.ic_action_map_text_size).setListener(new ContextMenuAdapter.ItemClickListener() {

        @Override
        public boolean onContextMenuClick(final ArrayAdapter<ContextMenuItem> ad, int itemId, final int pos, boolean isChecked, int[] viewCoordinates) {
            final OsmandMapTileView view = activity.getMapView();
            AlertDialog.Builder b = new AlertDialog.Builder(view.getContext());
            // test old descr as title
            b.setTitle(R.string.text_size);
            final Float[] txtValues = new Float[] { 0.75f, 1f, 1.25f, 1.5f, 2f, 3f };
            int selected = -1;
            final String[] txtNames = new String[txtValues.length];
            for (int i = 0; i < txtNames.length; i++) {
                txtNames[i] = (int) (txtValues[i] * 100) + " %";
                if (Math.abs(view.getSettings().TEXT_SCALE.get() - txtValues[i]) < 0.1f) {
                    selected = i;
                }
            }
            b.setSingleChoiceItems(txtNames, selected, new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                    view.getSettings().TEXT_SCALE.set(txtValues[which]);
                    refreshMapComplete(activity);
                    adapter.getItem(pos).setDescription(getScale(activity));
                    ad.notifyDataSetInvalidated();
                    dialog.dismiss();
                }
            });
            b.setNegativeButton(R.string.shared_string_dismiss, null);
            b.show();
            return false;
        }
    }).createItem());
    String localeDescr = activity.getMyApplication().getSettings().MAP_PREFERRED_LOCALE.get();
    localeDescr = localeDescr == null || localeDescr.equals("") ? activity.getString(R.string.local_map_names) : localeDescr;
    adapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.map_locale, activity).setDescription(localeDescr).setLayout(R.layout.list_item_single_line_descrition_narrow).setIcon(R.drawable.ic_action_map_language).setListener(new ContextMenuAdapter.ItemClickListener() {

        @Override
        public boolean onContextMenuClick(final ArrayAdapter<ContextMenuItem> ad, int itemId, final int pos, boolean isChecked, int[] viewCoordinates) {
            final OsmandMapTileView view = activity.getMapView();
            final AlertDialog.Builder b = new AlertDialog.Builder(view.getContext());
            b.setTitle(activity.getString(R.string.map_locale));
            final String[] txtIds = getSortedMapNamesIds(activity, mapNamesIds, getMapNamesValues(activity, mapNamesIds));
            final String[] txtValues = getMapNamesValues(activity, txtIds);
            int selected = -1;
            for (int i = 0; i < txtIds.length; i++) {
                if (view.getSettings().MAP_PREFERRED_LOCALE.get().equals(txtIds[i])) {
                    selected = i;
                    break;
                }
            }
            selectedLanguageIndex = selected;
            transliterateNames = view.getSettings().MAP_TRANSLITERATE_NAMES.get();
            final OnCheckedChangeListener translitChangdListener = new OnCheckedChangeListener() {

                @Override
                public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                    transliterateNames = isChecked;
                }
            };
            final ArrayAdapter<CharSequence> singleChoiceAdapter = new ArrayAdapter<CharSequence>(activity, R.layout.single_choice_switch_item, R.id.text1, txtValues) {

                @NonNull
                @Override
                public View getView(int position, View convertView, ViewGroup parent) {
                    View v = super.getView(position, convertView, parent);
                    AppCompatCheckedTextView checkedTextView = (AppCompatCheckedTextView) v.findViewById(R.id.text1);
                    if (position == selectedLanguageIndex && position > 0) {
                        checkedTextView.setChecked(true);
                        v.findViewById(R.id.topDivider).setVisibility(View.VISIBLE);
                        v.findViewById(R.id.bottomDivider).setVisibility(View.VISIBLE);
                        v.findViewById(R.id.switchLayout).setVisibility(View.VISIBLE);
                        TextView switchText = (TextView) v.findViewById(R.id.switchText);
                        switchText.setText(activity.getString(R.string.translit_name_if_miss, txtValues[position]));
                        SwitchCompat check = (SwitchCompat) v.findViewById(R.id.check);
                        check.setChecked(transliterateNames);
                        check.setOnCheckedChangeListener(translitChangdListener);
                    } else {
                        checkedTextView.setChecked(position == selectedLanguageIndex);
                        v.findViewById(R.id.topDivider).setVisibility(View.GONE);
                        v.findViewById(R.id.bottomDivider).setVisibility(View.GONE);
                        v.findViewById(R.id.switchLayout).setVisibility(View.GONE);
                    }
                    return v;
                }
            };
            b.setAdapter(singleChoiceAdapter, null);
            b.setSingleChoiceItems(txtValues, selected, new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                    selectedLanguageIndex = which;
                    ((AlertDialog) dialog).getListView().setSelection(which);
                    singleChoiceAdapter.notifyDataSetChanged();
                }
            });
            b.setNegativeButton(R.string.shared_string_cancel, null);
            b.setPositiveButton(R.string.shared_string_apply, new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                    view.getSettings().MAP_TRANSLITERATE_NAMES.set(selectedLanguageIndex > 0 && transliterateNames);
                    AlertDialog dlg = (AlertDialog) dialog;
                    int index = dlg.getListView().getCheckedItemPosition();
                    view.getSettings().MAP_PREFERRED_LOCALE.set(txtIds[index]);
                    refreshMapComplete(activity);
                    String localeDescr = txtIds[index];
                    localeDescr = localeDescr == null || localeDescr.equals("") ? activity.getString(R.string.local_map_names) : localeDescr;
                    adapter.getItem(pos).setDescription(localeDescr);
                    ad.notifyDataSetInvalidated();
                }
            });
            b.show();
            return false;
        }
    }).createItem());
    props = createProperties(customRules, null, R.string.rendering_category_transport, R.drawable.ic_action_bus_dark, "transport", null, adapter, activity, true);
    if (props != null) {
        adapter.addItem(props);
    }
    props = createProperties(customRules, null, R.string.rendering_category_details, R.drawable.ic_action_layers_dark, "details", null, adapter, activity, true);
    if (props != null) {
        adapter.addItem(props);
    }
    props = createProperties(customRules, null, R.string.rendering_category_hide, R.drawable.ic_action_hide, "hide", null, adapter, activity, true);
    if (props != null) {
        adapter.addItem(props);
    }
    List<RenderingRuleProperty> customRulesIncluded = new ArrayList<>();
    for (RenderingRuleProperty p : customRules) {
        if (p.getAttrName().equals(HIKING_ROUTES_OSMC_ATTR)) {
            customRulesIncluded.add(p);
            break;
        }
    }
    props = createProperties(customRules, customRulesIncluded, R.string.rendering_category_routes, R.drawable.ic_action_map_routes, "routes", null, adapter, activity, true);
    if (props != null) {
        adapter.addItem(props);
    }
    if (getCustomRenderingPropertiesSize(customRules) > 0) {
        adapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.rendering_category_others, activity).setCategory(true).setLayout(R.layout.list_group_title_with_switch).createItem());
        createCustomRenderingProperties(adapter, activity, customRules);
    }
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) ItemClickListener(net.osmand.plus.ContextMenuAdapter.ItemClickListener) OsmandApplication(net.osmand.plus.OsmandApplication) DialogInterface(android.content.DialogInterface) TIntArrayList(gnu.trove.list.array.TIntArrayList) ArrayList(java.util.ArrayList) ItemClickListener(net.osmand.plus.ContextMenuAdapter.ItemClickListener) NonNull(android.support.annotation.NonNull) Iterator(java.util.Iterator) TIntArrayList(gnu.trove.list.array.TIntArrayList) List(java.util.List) ArrayList(java.util.ArrayList) AppCompatCheckedTextView(android.support.v7.widget.AppCompatCheckedTextView) TextView(android.widget.TextView) OnCheckedChangeListener(android.widget.CompoundButton.OnCheckedChangeListener) ContextMenuItem(net.osmand.plus.ContextMenuItem) ViewGroup(android.view.ViewGroup) RenderingRuleProperty(net.osmand.render.RenderingRuleProperty) AppCompatCheckedTextView(android.support.v7.widget.AppCompatCheckedTextView) ImageView(android.widget.ImageView) View(android.view.View) AdapterView(android.widget.AdapterView) TextView(android.widget.TextView) ListView(android.widget.ListView) OsmandMapTileView(net.osmand.plus.views.OsmandMapTileView) RenderingRulesStorage(net.osmand.render.RenderingRulesStorage) TIntArrayList(gnu.trove.list.array.TIntArrayList) ContextMenuAdapter(net.osmand.plus.ContextMenuAdapter) AppCompatCheckedTextView(android.support.v7.widget.AppCompatCheckedTextView) OsmandMapTileView(net.osmand.plus.views.OsmandMapTileView) MapRendererContext(net.osmand.core.android.MapRendererContext) CompoundButton(android.widget.CompoundButton) ArrayAdapter(android.widget.ArrayAdapter) SwitchCompat(android.support.v7.widget.SwitchCompat)

Example 22 with OsmandMapTileView

use of net.osmand.plus.views.OsmandMapTileView in project Osmand by osmandapp.

the class MapStyleAction method execute.

@Override
public void execute(MapActivity activity) {
    List<String> mapStyles = getFilteredStyles();
    String curStyle = activity.getMyApplication().getSettings().RENDERER.get();
    int index = mapStyles.indexOf(curStyle);
    String nextStyle = mapStyles.get(0);
    if (index >= 0 && index + 1 < mapStyles.size()) {
        nextStyle = mapStyles.get(index + 1);
    }
    RenderingRulesStorage loaded = activity.getMyApplication().getRendererRegistry().getRenderer(nextStyle);
    if (loaded != null) {
        OsmandMapTileView view = activity.getMapView();
        view.getSettings().RENDERER.set(nextStyle);
        activity.getMyApplication().getRendererRegistry().setCurrentSelectedRender(loaded);
        ConfigureMapMenu.refreshMapComplete(activity);
        Toast.makeText(activity, activity.getString(R.string.quick_action_map_style_switch, nextStyle), Toast.LENGTH_SHORT).show();
    } else {
        Toast.makeText(activity, R.string.renderer_load_exception, Toast.LENGTH_SHORT).show();
    }
}
Also used : OsmandMapTileView(net.osmand.plus.views.OsmandMapTileView) RenderingRulesStorage(net.osmand.render.RenderingRulesStorage)

Example 23 with OsmandMapTileView

use of net.osmand.plus.views.OsmandMapTileView in project Osmand by osmandapp.

the class MapInfoWidgetsFactory method createRulerControl.

public TextInfoWidget createRulerControl(final MapActivity map) {
    final String title = "—";
    final TextInfoWidget rulerControl = new TextInfoWidget(map) {

        RulerControlLayer rulerLayer = map.getMapLayers().getRulerControlLayer();

        LatLon cacheFirstTouchPoint = new LatLon(0, 0);

        LatLon cacheSecondTouchPoint = new LatLon(0, 0);

        LatLon cacheSingleTouchPoint = new LatLon(0, 0);

        boolean fingerAndLocDistWasShown;

        @Override
        public boolean updateInfo(DrawSettings drawSettings) {
            OsmandMapTileView view = map.getMapView();
            Location currentLoc = map.getMyApplication().getLocationProvider().getLastKnownLocation();
            if (rulerLayer.isShowDistBetweenFingerAndLocation() && currentLoc != null) {
                if (!cacheSingleTouchPoint.equals(rulerLayer.getTouchPointLatLon())) {
                    cacheSingleTouchPoint = rulerLayer.getTouchPointLatLon();
                    setDistanceText(cacheSingleTouchPoint.getLatitude(), cacheSingleTouchPoint.getLongitude(), currentLoc.getLatitude(), currentLoc.getLongitude());
                    fingerAndLocDistWasShown = true;
                }
            } else if (rulerLayer.isShowTwoFingersDistance()) {
                if (!cacheFirstTouchPoint.equals(view.getFirstTouchPointLatLon()) || !cacheSecondTouchPoint.equals(view.getSecondTouchPointLatLon()) || fingerAndLocDistWasShown) {
                    cacheFirstTouchPoint = view.getFirstTouchPointLatLon();
                    cacheSecondTouchPoint = view.getSecondTouchPointLatLon();
                    setDistanceText(cacheFirstTouchPoint.getLatitude(), cacheFirstTouchPoint.getLongitude(), cacheSecondTouchPoint.getLatitude(), cacheSecondTouchPoint.getLongitude());
                    fingerAndLocDistWasShown = false;
                }
            } else {
                LatLon centerLoc = map.getMapLocation();
                if (currentLoc != null && centerLoc != null) {
                    if (map.getMapViewTrackingUtilities().isMapLinkedToLocation()) {
                        setDistanceText(0);
                    } else {
                        setDistanceText(currentLoc.getLatitude(), currentLoc.getLongitude(), centerLoc.getLatitude(), centerLoc.getLongitude());
                    }
                } else {
                    setText(title, null);
                }
            }
            return true;
        }

        private void setDistanceText(float dist) {
            calculateAndSetText(dist);
        }

        private void setDistanceText(double firstLat, double firstLon, double secondLat, double secondLon) {
            float dist = (float) MapUtils.getDistance(firstLat, firstLon, secondLat, secondLon);
            calculateAndSetText(dist);
        }

        private void calculateAndSetText(float dist) {
            String distance = OsmAndFormatter.getFormattedDistance(dist, map.getMyApplication());
            int ls = distance.lastIndexOf(' ');
            setText(distance.substring(0, ls), distance.substring(ls + 1));
        }
    };
    rulerControl.setText(title, null);
    setRulerControlIcon(rulerControl, map.getMyApplication().getSettings().RULER_MODE.get());
    rulerControl.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View view) {
            final RulerMode mode = map.getMyApplication().getSettings().RULER_MODE.get();
            RulerMode newMode = RulerMode.FIRST;
            if (mode == RulerMode.FIRST) {
                newMode = RulerMode.SECOND;
            } else if (mode == RulerMode.SECOND) {
                newMode = RulerMode.EMPTY;
            }
            setRulerControlIcon(rulerControl, newMode);
            map.getMyApplication().getSettings().RULER_MODE.set(newMode);
            map.refreshMap();
        }
    });
    return rulerControl;
}
Also used : RulerMode(net.osmand.plus.OsmandSettings.RulerMode) OsmandMapTileView(net.osmand.plus.views.OsmandMapTileView) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView) DrawSettings(net.osmand.plus.views.OsmandMapLayer.DrawSettings) LatLon(net.osmand.data.LatLon) RulerControlLayer(net.osmand.plus.views.RulerControlLayer) OnClickListener(android.view.View.OnClickListener) OsmandMapTileView(net.osmand.plus.views.OsmandMapTileView) Location(net.osmand.Location)

Example 24 with OsmandMapTileView

use of net.osmand.plus.views.OsmandMapTileView 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)

Example 25 with OsmandMapTileView

use of net.osmand.plus.views.OsmandMapTileView in project Osmand by osmandapp.

the class SRTMPlugin 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) {
            int[] viewCoordinates = AndroidUtils.getCenterViewCoordinates(view);
            if (itemId == R.string.srtm_plugin_name) {
                mapActivity.getDashboard().setDashboardVisibility(true, DashboardOnMap.DashboardType.CONTOUR_LINES, viewCoordinates);
                return false;
            } else if (itemId == R.string.layer_hillshade) {
                mapActivity.getDashboard().setDashboardVisibility(true, DashboardOnMap.DashboardType.HILLSHADE, viewCoordinates);
                return false;
            }
            return true;
        }

        @Override
        public boolean onContextMenuClick(final ArrayAdapter<ContextMenuItem> adapter, final int itemId, final int position, final boolean isChecked, final int[] viewCoordinates) {
            if (itemId == R.string.srtm_plugin_name) {
                toggleContourLines(mapActivity, isChecked, new Runnable() {

                    @Override
                    public void run() {
                        RenderingRuleProperty contourLinesProp = app.getRendererRegistry().getCustomRenderingRuleProperty(CONTOUR_LINES_ATTR);
                        if (contourLinesProp != null) {
                            OsmandSettings settings = app.getSettings();
                            final OsmandSettings.CommonPreference<String> pref = settings.getCustomRenderProperty(contourLinesProp.getAttrName());
                            boolean selected = !pref.get().equals(CONTOUR_LINES_DISABLED_VALUE);
                            SRTMPlugin plugin = OsmandPlugin.getPlugin(SRTMPlugin.class);
                            if (selected && plugin != null && !plugin.isActive() && !plugin.needsInstallation()) {
                                OsmandPlugin.enablePlugin(mapActivity, mapActivity.getMyApplication(), plugin, true);
                            }
                            ContextMenuItem item = adapter.getItem(position);
                            if (item != null) {
                                item.setDescription(app.getString(R.string.display_zoom_level, getPrefDescription(app, contourLinesProp, pref)));
                                item.setColorRes(selected ? R.color.osmand_orange : ContextMenuItem.INVALID_ID);
                                item.setSelected(selected);
                                adapter.notifyDataSetChanged();
                            }
                            refreshMapComplete(mapActivity);
                        }
                    }
                });
            } else if (itemId == R.string.layer_hillshade) {
                toggleHillshade(mapActivity, isChecked, new Runnable() {

                    @Override
                    public void run() {
                        boolean selected = HILLSHADE.get();
                        SRTMPlugin plugin = OsmandPlugin.getPlugin(SRTMPlugin.class);
                        if (selected && plugin != null && !plugin.isActive() && !plugin.needsInstallation()) {
                            OsmandPlugin.enablePlugin(mapActivity, mapActivity.getMyApplication(), plugin, true);
                        }
                        ContextMenuItem item = adapter.getItem(position);
                        if (item != null) {
                            item.setColorRes(selected ? R.color.osmand_orange : ContextMenuItem.INVALID_ID);
                            item.setSelected(selected);
                            adapter.notifyDataSetChanged();
                        }
                        updateLayers(mapView, mapActivity);
                        refreshMapComplete(mapActivity);
                    }
                });
            }
            return true;
        }
    };
    RenderingRuleProperty contourLinesProp = app.getRendererRegistry().getCustomRenderingRuleProperty(CONTOUR_LINES_ATTR);
    if (contourLinesProp != null) {
        final OsmandSettings.CommonPreference<String> pref = app.getSettings().getCustomRenderProperty(contourLinesProp.getAttrName());
        boolean contourLinesSelected;
        if (!Algorithms.isEmpty(pref.get())) {
            contourLinesSelected = !pref.get().equals(CONTOUR_LINES_DISABLED_VALUE);
        } else {
            contourLinesSelected = !contourLinesProp.getDefaultValueDescription().equals(CONTOUR_LINES_DISABLED_VALUE);
        }
        String descr = getPrefDescription(app, contourLinesProp, pref);
        adapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.srtm_plugin_name, mapActivity).setSelected(contourLinesSelected).setIcon(R.drawable.ic_plugin_srtm).setDescription(app.getString(R.string.display_zoom_level, descr)).setColor(contourLinesSelected ? R.color.osmand_orange : ContextMenuItem.INVALID_ID).setSecondaryIcon(R.drawable.ic_action_additional_option).setPosition(12).setListener(listener).createItem());
    }
    adapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.layer_hillshade, mapActivity).setSelected(HILLSHADE.get()).setColor(HILLSHADE.get() ? R.color.osmand_orange : ContextMenuItem.INVALID_ID).setIcon(R.drawable.ic_action_hillshade_dark).setSecondaryIcon(R.drawable.ic_action_additional_option).setListener(listener).setPosition(13).createItem());
}
Also used : CommonPreference(net.osmand.plus.OsmandSettings.CommonPreference) ContextMenuItem(net.osmand.plus.ContextMenuItem) RenderingRuleProperty(net.osmand.render.RenderingRuleProperty) OsmandMapTileView(net.osmand.plus.views.OsmandMapTileView) View(android.view.View) OsmandSettings(net.osmand.plus.OsmandSettings) ContextMenuAdapter(net.osmand.plus.ContextMenuAdapter) ArrayAdapter(android.widget.ArrayAdapter)

Aggregations

OsmandMapTileView (net.osmand.plus.views.OsmandMapTileView)25 View (android.view.View)9 ContextMenuAdapter (net.osmand.plus.ContextMenuAdapter)7 ContextMenuItem (net.osmand.plus.ContextMenuItem)7 ArrayAdapter (android.widget.ArrayAdapter)5 TextView (android.widget.TextView)5 ItemClickListener (net.osmand.plus.ContextMenuAdapter.ItemClickListener)5 OsmandApplication (net.osmand.plus.OsmandApplication)5 OsmandSettings (net.osmand.plus.OsmandSettings)5 DialogInterface (android.content.DialogInterface)4 AlertDialog (android.support.v7.app.AlertDialog)4 AdapterView (android.widget.AdapterView)4 ImageView (android.widget.ImageView)4 MapActivity (net.osmand.plus.activities.MapActivity)4 Intent (android.content.Intent)3 ListView (android.widget.ListView)3 ArrayList (java.util.ArrayList)3 Location (net.osmand.Location)3 LatLon (net.osmand.data.LatLon)3 TargetPoint (net.osmand.plus.TargetPointsHelper.TargetPoint)3