Search in sources :

Example 11 with RenderingRuleProperty

use of net.osmand.render.RenderingRuleProperty in project Osmand by osmandapp.

the class MapRendererContext method getMapStyleSettings.

protected QStringStringHash getMapStyleSettings() {
    // Apply map style settings
    OsmandSettings prefs = app.getSettings();
    RenderingRulesStorage storage = app.getRendererRegistry().getCurrentSelectedRenderer();
    Map<String, String> props = new HashMap<String, String>();
    for (RenderingRuleProperty customProp : storage.PROPS.getCustomRules()) {
        if (RenderingRuleStorageProperties.UI_CATEGORY_HIDDEN.equals(customProp.getCategory())) {
            continue;
        } else if (customProp.isBoolean()) {
            CommonPreference<Boolean> pref = prefs.getCustomRenderBooleanProperty(customProp.getAttrName());
            props.put(customProp.getAttrName(), pref.get() + "");
        } else {
            CommonPreference<String> settings = prefs.getCustomRenderProperty(customProp.getAttrName());
            String res = settings.get();
            if (!Algorithms.isEmpty(res)) {
                props.put(customProp.getAttrName(), res);
            }
        }
    }
    QStringStringHash convertedStyleSettings = new QStringStringHash();
    for (Map.Entry<String, String> setting : props.entrySet()) {
        convertedStyleSettings.set(setting.getKey(), setting.getValue());
    }
    if (nightMode) {
        convertedStyleSettings.set("nightMode", "true");
    }
    return convertedStyleSettings;
}
Also used : CommonPreference(net.osmand.plus.OsmandSettings.CommonPreference) HashMap(java.util.HashMap) QStringStringHash(net.osmand.core.jni.QStringStringHash) RenderingRuleProperty(net.osmand.render.RenderingRuleProperty) HashMap(java.util.HashMap) Map(java.util.Map) OsmandSettings(net.osmand.plus.OsmandSettings) RenderingRulesStorage(net.osmand.render.RenderingRulesStorage)

Example 12 with RenderingRuleProperty

use of net.osmand.render.RenderingRuleProperty in project Osmand by osmandapp.

the class ContourLinesMenu method createLayersItems.

private static void createLayersItems(final ContextMenuAdapter contextMenuAdapter, final MapActivity mapActivity) {
    final OsmandApplication app = mapActivity.getMyApplication();
    final OsmandSettings settings = app.getSettings();
    final SRTMPlugin plugin = OsmandPlugin.getPlugin(SRTMPlugin.class);
    final boolean srtmEnabled = OsmandPlugin.getEnabledPlugin(SRTMPlugin.class) != null;
    final RenderingRuleProperty contourLinesProp = app.getRendererRegistry().getCustomRenderingRuleProperty(CONTOUR_LINES_ATTR);
    final RenderingRuleProperty colorSchemeProp = app.getRendererRegistry().getCustomRenderingRuleProperty(CONTOUR_LINES_SCHEME_ATTR);
    if (plugin == null || contourLinesProp == null || colorSchemeProp == null) {
        return;
    }
    final String contourWidthName;
    final String contourDensityName;
    final OsmandSettings.CommonPreference<String> widthPref;
    final OsmandSettings.CommonPreference<String> densityPref;
    final RenderingRuleProperty contourWidthProp = app.getRendererRegistry().getCustomRenderingRuleProperty(CONTOUR_WIDTH_ATTR);
    if (contourWidthProp != null) {
        contourWidthName = SettingsActivity.getStringPropertyName(app, contourWidthProp.getAttrName(), contourWidthProp.getName());
        widthPref = settings.getCustomRenderProperty(contourWidthProp.getAttrName());
    } else {
        contourWidthName = null;
        widthPref = null;
    }
    final RenderingRuleProperty contourDensityProp = app.getRendererRegistry().getCustomRenderingRuleProperty(CONTOUR_DENSITY_ATTR);
    if (contourDensityProp != null) {
        contourDensityName = SettingsActivity.getStringPropertyName(app, contourDensityProp.getAttrName(), contourDensityProp.getName());
        densityPref = settings.getCustomRenderProperty(contourDensityProp.getAttrName());
    } else {
        contourDensityName = null;
        densityPref = null;
    }
    final OsmandSettings.CommonPreference<String> pref = settings.getCustomRenderProperty(contourLinesProp.getAttrName());
    final OsmandSettings.CommonPreference<String> colorPref = settings.getCustomRenderProperty(colorSchemeProp.getAttrName());
    final boolean selected = !pref.get().equals(CONTOUR_LINES_DISABLED_VALUE);
    final int toggleActionStringId = selected ? R.string.shared_string_enabled : R.string.shared_string_disabled;
    final int showZoomLevelStringId = R.string.show_from_zoom_level;
    final int colorSchemeStringId = R.string.srtm_color_scheme;
    ContextMenuAdapter.OnRowItemClick l = new ContextMenuAdapter.OnRowItemClick() {

        @Override
        public boolean onRowItemClick(ArrayAdapter<ContextMenuItem> adapter, View view, int itemId, int pos) {
            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.toggleContourLines(mapActivity, isChecked, new Runnable() {

                            @Override
                            public void run() {
                                mapActivity.getDashboard().refreshContent(true);
                                SRTMPlugin.refreshMapComplete(mapActivity);
                            }
                        });
                    }
                });
            } else if (itemId == showZoomLevelStringId) {
                plugin.selectPropertyValue(mapActivity, contourLinesProp, pref, new Runnable() {

                    @Override
                    public void run() {
                        ContextMenuItem item = adapter.getItem(pos);
                        if (item != null) {
                            item.setDescription(plugin.getPrefDescription(app, contourLinesProp, pref));
                            adapter.notifyDataSetChanged();
                        }
                        SRTMPlugin.refreshMapComplete(mapActivity);
                    }
                });
            } else if (itemId == colorSchemeStringId) {
                plugin.selectPropertyValue(mapActivity, colorSchemeProp, colorPref, new Runnable() {

                    @Override
                    public void run() {
                        ContextMenuItem item = adapter.getItem(pos);
                        if (item != null) {
                            item.setDescription(plugin.getPrefDescription(app, colorSchemeProp, colorPref));
                            adapter.notifyDataSetChanged();
                        }
                        SRTMPlugin.refreshMapComplete(mapActivity);
                    }
                });
            } else if (itemId == R.string.srtm_plugin_name) {
                Intent intent = new Intent(mapActivity, PluginActivity.class);
                intent.putExtra(PluginActivity.EXTRA_PLUGIN_ID, plugin.getId());
                mapActivity.startActivity(intent);
                closeDashboard(mapActivity);
            } else if (contourWidthProp != null && itemId == contourWidthName.hashCode()) {
                plugin.selectPropertyValue(mapActivity, contourWidthProp, widthPref, new Runnable() {

                    @Override
                    public void run() {
                        ContextMenuItem item = adapter.getItem(pos);
                        if (item != null) {
                            item.setDescription(plugin.getPrefDescription(app, contourWidthProp, widthPref));
                            adapter.notifyDataSetChanged();
                        }
                        SRTMPlugin.refreshMapComplete(mapActivity);
                    }
                });
            } else if (contourDensityProp != null && itemId == contourDensityName.hashCode()) {
                plugin.selectPropertyValue(mapActivity, contourDensityProp, densityPref, new Runnable() {

                    @Override
                    public void run() {
                        ContextMenuItem item = adapter.getItem(pos);
                        if (item != null) {
                            item.setDescription(plugin.getPrefDescription(app, contourDensityProp, densityPref));
                            adapter.notifyDataSetChanged();
                        }
                        SRTMPlugin.refreshMapComplete(mapActivity);
                    }
                });
            }
            return false;
        }
    };
    boolean nightMode = mapActivity.getMyApplication().getDaynightHelper().isNightModeForMapControls();
    int toggleIconColorId;
    int toggleIconId;
    if (selected) {
        toggleIconId = R.drawable.ic_action_view;
        toggleIconColorId = nightMode ? R.color.color_dialog_buttons_dark : R.color.color_dialog_buttons_light;
    } else {
        toggleIconId = R.drawable.ic_action_hide;
        toggleIconColorId = nightMode ? 0 : R.color.icon_color;
    }
    contextMenuAdapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(toggleActionStringId, mapActivity).setIcon(toggleIconId).setColor(toggleIconColorId).setListener(l).setSelected(selected).createItem());
    if (selected) {
        contextMenuAdapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(showZoomLevelStringId, mapActivity).setLayout(R.layout.list_item_single_line_descrition_narrow).setIcon(R.drawable.ic_action_map_magnifier).setDescription(plugin.getPrefDescription(app, contourLinesProp, pref)).setListener(l).createItem());
        contextMenuAdapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(colorSchemeStringId, mapActivity).setLayout(R.layout.list_item_single_line_descrition_narrow).setIcon(R.drawable.ic_action_appearance).setDescription(plugin.getPrefDescription(app, colorSchemeProp, colorPref)).setListener(l).createItem());
        if (contourWidthProp != null) {
            contextMenuAdapter.addItem(new ContextMenuItem.ItemBuilder().setTitle(contourWidthName).setLayout(R.layout.list_item_single_line_descrition_narrow).setIcon(R.drawable.ic_action_gpx_width_thin).setDescription(plugin.getPrefDescription(app, contourWidthProp, widthPref)).setListener(l).createItem());
        }
        if (contourDensityProp != null) {
            contextMenuAdapter.addItem(new ContextMenuItem.ItemBuilder().setTitle(contourDensityName).setLayout(R.layout.list_item_single_line_descrition_narrow).setIcon(R.drawable.ic_plugin_srtm).setDescription(plugin.getPrefDescription(app, contourDensityProp, densityPref)).setListener(l).createItem());
        }
    }
    if (!srtmEnabled) {
        contextMenuAdapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.srtm_purchase_header, mapActivity).setCategory(true).setLayout(R.layout.list_group_title_with_switch_light).createItem());
        contextMenuAdapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.srtm_plugin_name, mapActivity).setLayout(R.layout.list_item_icon_and_right_btn).setIcon(R.drawable.ic_plugin_srtm).setColor(R.color.osmand_orange).setDescription(app.getString(R.string.shared_string_plugin)).setListener(l).createItem());
    } else {
        final DownloadIndexesThread downloadThread = app.getDownloadThread();
        if (!downloadThread.getIndexes().isDownloadedFromInternet) {
            if (settings.isInternetConnectionAvailable()) {
                downloadThread.runReloadIndexFiles();
            }
        }
        final boolean downloadIndexes = settings.isInternetConnectionAvailable() && !downloadThread.getIndexes().isDownloadedFromInternet && !downloadThread.getIndexes().downloadFromInternetFailed;
        if (downloadIndexes) {
            contextMenuAdapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.shared_string_download_map, mapActivity).setDescription(app.getString(R.string.srtm_menu_download_descr)).setCategory(true).setLayout(R.layout.list_group_title_with_descr).createItem());
            contextMenuAdapter.addItem(new ContextMenuItem.ItemBuilder().setLayout(R.layout.list_item_icon_and_download).setTitleId(R.string.downloading_list_indexes, mapActivity).setLoading(true).setListener(l).createItem());
        } else {
            try {
                IndexItem currentDownloadingItem = downloadThread.getCurrentDownloadingItem();
                int currentDownloadingProgress = downloadThread.getCurrentDownloadingItemProgress();
                List<IndexItem> srtms = DownloadResources.findIndexItemsAt(app, mapActivity.getMapLocation(), DownloadActivityType.SRTM_COUNTRY_FILE);
                if (srtms.size() > 0) {
                    contextMenuAdapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.shared_string_download_map, mapActivity).setDescription(app.getString(R.string.srtm_menu_download_descr)).setCategory(true).setLayout(R.layout.list_group_title_with_descr).createItem());
                    for (final IndexItem indexItem : srtms) {
                        ContextMenuItem.ItemBuilder itemBuilder = new ContextMenuItem.ItemBuilder().setLayout(R.layout.list_item_icon_and_download).setTitle(indexItem.getVisibleName(app, app.getRegions(), false)).setDescription(DownloadActivityType.SRTM_COUNTRY_FILE.getString(app) + " • " + indexItem.getSizeDescription(app)).setIcon(DownloadActivityType.SRTM_COUNTRY_FILE.getIconResource()).setListener(new ContextMenuAdapter.ItemClickListener() {

                            @Override
                            public boolean onContextMenuClick(ArrayAdapter<ContextMenuItem> adapter, int itemId, int position, boolean isChecked, int[] viewCoordinates) {
                                ContextMenuItem item = adapter.getItem(position);
                                if (downloadThread.isDownloading(indexItem)) {
                                    downloadThread.cancelDownload(indexItem);
                                    if (item != null) {
                                        item.setProgress(ContextMenuItem.INVALID_ID);
                                        item.setLoading(false);
                                        item.setSecondaryIcon(R.drawable.ic_action_import);
                                        adapter.notifyDataSetChanged();
                                    }
                                } else {
                                    new DownloadValidationManager(app).startDownload(mapActivity, indexItem);
                                    if (item != null) {
                                        item.setProgress(ContextMenuItem.INVALID_ID);
                                        item.setLoading(true);
                                        item.setSecondaryIcon(R.drawable.ic_action_remove_dark);
                                        adapter.notifyDataSetChanged();
                                    }
                                }
                                return false;
                            }
                        }).setProgressListener(new ContextMenuAdapter.ProgressListener() {

                            @Override
                            public boolean onProgressChanged(Object progressObject, int progress, ArrayAdapter<ContextMenuItem> adapter, int itemId, int position) {
                                if (progressObject != null && progressObject instanceof IndexItem) {
                                    IndexItem progressItem = (IndexItem) progressObject;
                                    if (indexItem.compareTo(progressItem) == 0) {
                                        ContextMenuItem item = adapter.getItem(position);
                                        if (item != null) {
                                            item.setProgress(progress);
                                            item.setLoading(true);
                                            item.setSecondaryIcon(R.drawable.ic_action_remove_dark);
                                            adapter.notifyDataSetChanged();
                                        }
                                        return true;
                                    }
                                }
                                return false;
                            }
                        });
                        if (indexItem == currentDownloadingItem) {
                            itemBuilder.setLoading(true).setProgress(currentDownloadingProgress).setSecondaryIcon(R.drawable.ic_action_remove_dark);
                        } else {
                            itemBuilder.setSecondaryIcon(R.drawable.ic_action_import);
                        }
                        contextMenuAdapter.addItem(itemBuilder.createItem());
                    }
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}
Also used : OsmandApplication(net.osmand.plus.OsmandApplication) DownloadIndexesThread(net.osmand.plus.download.DownloadIndexesThread) ContextMenuItem(net.osmand.plus.ContextMenuItem) RenderingRuleProperty(net.osmand.render.RenderingRuleProperty) Intent(android.content.Intent) IOException(java.io.IOException) View(android.view.View) OsmandSettings(net.osmand.plus.OsmandSettings) IndexItem(net.osmand.plus.download.IndexItem) ContextMenuAdapter(net.osmand.plus.ContextMenuAdapter) PluginActivity(net.osmand.plus.activities.PluginActivity) DownloadValidationManager(net.osmand.plus.download.DownloadValidationManager) ArrayAdapter(android.widget.ArrayAdapter)

Example 13 with RenderingRuleProperty

use of net.osmand.render.RenderingRuleProperty in project Osmand by osmandapp.

the class SRTMPlugin method toggleContourLines.

public void toggleContourLines(final MapActivity activity, final boolean isChecked, final Runnable callback) {
    RenderingRuleProperty contourLinesProp = app.getRendererRegistry().getCustomRenderingRuleProperty(CONTOUR_LINES_ATTR);
    if (contourLinesProp != null) {
        OsmandSettings settings = app.getSettings();
        final OsmandSettings.CommonPreference<String> pref = settings.getCustomRenderProperty(contourLinesProp.getAttrName());
        CommonPreference<String> zoomSetting = settings.CONTOUR_LINES_ZOOM;
        if (!isChecked) {
            zoomSetting.set(pref.get());
            pref.set(CONTOUR_LINES_DISABLED_VALUE);
            if (callback != null) {
                callback.run();
            }
        } else if (zoomSetting.get() != null && !zoomSetting.get().equals(CONTOUR_LINES_DISABLED_VALUE)) {
            pref.set(zoomSetting.get());
            if (callback != null) {
                callback.run();
            }
        } else {
            selectPropertyValue(activity, contourLinesProp, pref, callback);
        }
    }
}
Also used : RenderingRuleProperty(net.osmand.render.RenderingRuleProperty) OsmandSettings(net.osmand.plus.OsmandSettings)

Example 14 with RenderingRuleProperty

use of net.osmand.render.RenderingRuleProperty 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

RenderingRuleProperty (net.osmand.render.RenderingRuleProperty)14 OsmandSettings (net.osmand.plus.OsmandSettings)8 View (android.view.View)7 ArrayList (java.util.ArrayList)7 ArrayAdapter (android.widget.ArrayAdapter)6 TIntArrayList (gnu.trove.list.array.TIntArrayList)6 ContextMenuItem (net.osmand.plus.ContextMenuItem)6 CommonPreference (net.osmand.plus.OsmandSettings.CommonPreference)6 RenderingRulesStorage (net.osmand.render.RenderingRulesStorage)6 AdapterView (android.widget.AdapterView)5 ImageView (android.widget.ImageView)5 TextView (android.widget.TextView)5 OsmandApplication (net.osmand.plus.OsmandApplication)5 DialogInterface (android.content.DialogInterface)4 AlertDialog (android.support.v7.app.AlertDialog)4 AppCompatCheckedTextView (android.support.v7.widget.AppCompatCheckedTextView)4 ListView (android.widget.ListView)4 ContextMenuAdapter (net.osmand.plus.ContextMenuAdapter)4 OsmandMapTileView (net.osmand.plus.views.OsmandMapTileView)4 SwitchCompat (android.support.v7.widget.SwitchCompat)3