Search in sources :

Example 1 with SRTMPlugin

use of net.osmand.plus.srtmplugin.SRTMPlugin in project Osmand by osmandapp.

the class DashboardOnMap method onDownloadHasFinished.

public void onDownloadHasFinished() {
    if (visibleType == DashboardType.CONTOUR_LINES || visibleType == DashboardType.HILLSHADE) {
        refreshContent(true);
        if (visibleType == DashboardType.HILLSHADE) {
            SRTMPlugin plugin = OsmandPlugin.getEnabledPlugin(SRTMPlugin.class);
            if (plugin != null && plugin.isHillShadeLayerEnabled()) {
                plugin.registerLayers(mapActivity);
            }
        }
        SRTMPlugin.refreshMapComplete(mapActivity);
    }
}
Also used : SRTMPlugin(net.osmand.plus.srtmplugin.SRTMPlugin)

Example 2 with SRTMPlugin

use of net.osmand.plus.srtmplugin.SRTMPlugin in project Osmand by osmandapp.

the class ConfigureMapMenu method createLayersItems.

private void createLayersItems(List<RenderingRuleProperty> customRules, ContextMenuAdapter adapter, final MapActivity activity) {
    final OsmandApplication app = activity.getMyApplication();
    final OsmandSettings settings = app.getSettings();
    LayerMenuListener l = new LayerMenuListener(activity, adapter);
    adapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.shared_string_show, activity).setCategory(true).setLayout(R.layout.list_group_title_with_switch).createItem());
    // String appMode = " [" + settings.getApplicationMode().toHumanString(view.getApplication()) +"] ";
    boolean selected = settings.SHOW_FAVORITES.get();
    adapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.shared_string_favorites, activity).setSelected(settings.SHOW_FAVORITES.get()).setColor(selected ? R.color.osmand_orange : ContextMenuItem.INVALID_ID).setIcon(R.drawable.ic_action_fav_dark).setListener(l).createItem());
    selected = app.getPoiFilters().isShowingAnyPoi();
    adapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.layer_poi, activity).setSelected(selected).setDescription(app.getPoiFilters().getSelectedPoiFiltersName()).setColor(selected ? R.color.osmand_orange : ContextMenuItem.INVALID_ID).setIcon(R.drawable.ic_action_info_dark).setSecondaryIcon(R.drawable.ic_action_additional_option).setListener(l).createItem());
    selected = settings.SHOW_POI_LABEL.get();
    adapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.layer_amenity_label, activity).setSelected(settings.SHOW_POI_LABEL.get()).setColor(selected ? R.color.osmand_orange : ContextMenuItem.INVALID_ID).setIcon(R.drawable.ic_action_text_dark).setListener(l).createItem());
    /*
		ContextMenuItem item = createProperties(customRules, null, R.string.rendering_category_transport, R.drawable.ic_action_bus_dark,
				"transport", settings.TRANSPORT_DEFAULT_SETTINGS, adapter, activity, false);
		if (item != null) {
			adapter.addItem(item);
		}
		*/
    final List<RenderingRuleProperty> transportRules = new ArrayList<>();
    final List<OsmandSettings.CommonPreference<Boolean>> transportPrefs = new ArrayList<>();
    Iterator<RenderingRuleProperty> it = customRules.iterator();
    while (it.hasNext()) {
        RenderingRuleProperty p = it.next();
        if ("transport".equals(p.getCategory()) && p.isBoolean()) {
            transportRules.add(p);
            final OsmandSettings.CommonPreference<Boolean> pref = activity.getMyApplication().getSettings().getCustomRenderBooleanProperty(p.getAttrName());
            transportPrefs.add(pref);
            it.remove();
        }
    }
    selected = false;
    for (OsmandSettings.CommonPreference<Boolean> p : transportPrefs) {
        if (p.get()) {
            selected = true;
            break;
        }
    }
    final boolean transportSelected = selected;
    adapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.rendering_category_transport, activity).setIcon(R.drawable.ic_action_bus_dark).setSecondaryIcon(R.drawable.ic_action_additional_option).setSelected(transportSelected).setColor(transportSelected ? R.color.osmand_orange : ContextMenuItem.INVALID_ID).setListener(new ContextMenuAdapter.OnRowItemClick() {

        ArrayAdapter<CharSequence> adapter;

        boolean transportSelectedInner = transportSelected;

        @Override
        public boolean onRowItemClick(ArrayAdapter<ContextMenuItem> adapter, View view, int itemId, int position) {
            if (transportSelectedInner) {
                showTransportDialog(adapter, position);
                return false;
            } else {
                CompoundButton btn = (CompoundButton) view.findViewById(R.id.toggle_item);
                if (btn != null && btn.getVisibility() == View.VISIBLE) {
                    btn.setChecked(!btn.isChecked());
                    adapter.getItem(position).setColorRes(btn.isChecked() ? R.color.osmand_orange : ContextMenuItem.INVALID_ID);
                    adapter.notifyDataSetChanged();
                    return false;
                } else {
                    return onContextMenuClick(adapter, itemId, position, false, null);
                }
            }
        }

        @Override
        public boolean onContextMenuClick(final ArrayAdapter<ContextMenuItem> ad, int itemId, final int pos, boolean isChecked, int[] viewCoordinates) {
            if (transportSelectedInner) {
                for (int i = 0; i < transportPrefs.size(); i++) {
                    transportPrefs.get(i).set(false);
                }
                transportSelectedInner = false;
                ad.getItem(pos).setColorRes(ContextMenuItem.INVALID_ID);
                refreshMapComplete(activity);
                activity.getMapLayers().updateLayers(activity.getMapView());
            } else {
                ad.getItem(pos).setColorRes(R.color.osmand_orange);
                showTransportDialog(ad, pos);
            }
            ad.notifyDataSetChanged();
            return false;
        }

        private void showTransportDialog(final ArrayAdapter<ContextMenuItem> ad, final int pos) {
            final AlertDialog.Builder b = new AlertDialog.Builder(activity);
            b.setTitle(activity.getString(R.string.rendering_category_transport));
            final int[] iconIds = new int[transportPrefs.size()];
            final boolean[] checkedItems = new boolean[transportPrefs.size()];
            for (int i = 0; i < transportPrefs.size(); i++) {
                checkedItems[i] = transportPrefs.get(i).get();
            }
            final String[] vals = new String[transportRules.size()];
            for (int i = 0; i < transportRules.size(); i++) {
                RenderingRuleProperty p = transportRules.get(i);
                String propertyName = SettingsActivity.getStringPropertyName(activity, p.getAttrName(), p.getName());
                vals[i] = propertyName;
                if ("transportStops".equals(p.getAttrName())) {
                    iconIds[i] = R.drawable.ic_action_transport_stop;
                } else if ("publicTransportMode".equals(p.getAttrName())) {
                    iconIds[i] = R.drawable.ic_action_bus_dark;
                } else if ("tramTrainRoutes".equals(p.getAttrName())) {
                    iconIds[i] = R.drawable.ic_action_transport_tram;
                } else if ("subwayMode".equals(p.getAttrName())) {
                    iconIds[i] = R.drawable.ic_action_transport_subway;
                } else {
                    iconIds[i] = R.drawable.ic_action_bus_dark;
                }
            }
            adapter = new ArrayAdapter<CharSequence>(activity, R.layout.popup_list_item_icon24_and_menu, R.id.title, vals) {

                @NonNull
                @Override
                public View getView(final int position, View convertView, ViewGroup parent) {
                    View v = super.getView(position, convertView, parent);
                    final ImageView icon = (ImageView) v.findViewById(R.id.icon);
                    if (checkedItems[position]) {
                        icon.setImageDrawable(app.getIconsCache().getIcon(iconIds[position], R.color.osmand_orange));
                    } else {
                        icon.setImageDrawable(app.getIconsCache().getThemedIcon(iconIds[position]));
                    }
                    v.findViewById(R.id.divider).setVisibility(View.GONE);
                    v.findViewById(R.id.description).setVisibility(View.GONE);
                    v.findViewById(R.id.secondary_icon).setVisibility(View.GONE);
                    final SwitchCompat check = (SwitchCompat) v.findViewById(R.id.toggle_item);
                    check.setOnCheckedChangeListener(null);
                    check.setChecked(checkedItems[position]);
                    check.setOnCheckedChangeListener(new OnCheckedChangeListener() {

                        @Override
                        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                            checkedItems[position] = isChecked;
                            if (checkedItems[position]) {
                                icon.setImageDrawable(app.getIconsCache().getIcon(iconIds[position], R.color.osmand_orange));
                            } else {
                                icon.setImageDrawable(app.getIconsCache().getThemedIcon(iconIds[position]));
                            }
                        }
                    });
                    return v;
                }
            };
            final ListView listView = new ListView(activity);
            listView.setDivider(null);
            listView.setClickable(true);
            listView.setAdapter(adapter);
            listView.setOnItemClickListener(new ListView.OnItemClickListener() {

                @Override
                public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                    checkedItems[position] = !checkedItems[position];
                    adapter.notifyDataSetChanged();
                }
            });
            b.setView(listView);
            b.setOnDismissListener(new DialogInterface.OnDismissListener() {

                @Override
                public void onDismiss(DialogInterface dialog) {
                    ContextMenuItem item = ad.getItem(pos);
                    if (item != null) {
                        item.setSelected(transportSelectedInner);
                        item.setColorRes(transportSelectedInner ? R.color.osmand_orange : ContextMenuItem.INVALID_ID);
                        ad.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) {
                    transportSelectedInner = false;
                    for (int i = 0; i < transportPrefs.size(); i++) {
                        transportPrefs.get(i).set(checkedItems[i]);
                        if (!transportSelectedInner && checkedItems[i]) {
                            transportSelectedInner = true;
                        }
                    }
                    refreshMapComplete(activity);
                    activity.getMapLayers().updateLayers(activity.getMapView());
                }
            });
            b.show();
        }
    }).createItem());
    selected = app.getSelectedGpxHelper().isShowingAnyGpxFiles();
    adapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.layer_gpx_layer, activity).setSelected(app.getSelectedGpxHelper().isShowingAnyGpxFiles()).setDescription(app.getSelectedGpxHelper().getGpxDescription()).setColor(selected ? R.color.osmand_orange : ContextMenuItem.INVALID_ID).setIcon(R.drawable.ic_action_polygom_dark).setSecondaryIcon(R.drawable.ic_action_additional_option).setListener(l).createItem());
    adapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.layer_map, activity).setIcon(R.drawable.ic_world_globe_dark).setDescription(settings.MAP_ONLINE_DATA.get() ? settings.MAP_TILE_SOURCES.get() : null).setListener(l).createItem());
    OsmandPlugin.registerLayerContextMenu(activity.getMapView(), adapter, activity);
    app.getAppCustomization().prepareLayerContextMenu(activity, adapter);
    boolean srtmDisabled = OsmandPlugin.getEnabledPlugin(SRTMPlugin.class) == null;
    if (srtmDisabled) {
        SRTMPlugin srtmPlugin = OsmandPlugin.getPlugin(SRTMPlugin.class);
        if (srtmPlugin != null) {
            srtmPlugin.registerLayerContextMenuActions(activity.getMapView(), adapter, activity);
        }
    }
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) OsmandApplication(net.osmand.plus.OsmandApplication) DialogInterface(android.content.DialogInterface) TIntArrayList(gnu.trove.list.array.TIntArrayList) ArrayList(java.util.ArrayList) ListView(android.widget.ListView) ImageView(android.widget.ImageView) SRTMPlugin(net.osmand.plus.srtmplugin.SRTMPlugin) OnCheckedChangeListener(android.widget.CompoundButton.OnCheckedChangeListener) ContextMenuItem(net.osmand.plus.ContextMenuItem) CommonPreference(net.osmand.plus.OsmandSettings.CommonPreference) ViewGroup(android.view.ViewGroup) RenderingRuleProperty(net.osmand.render.RenderingRuleProperty) OnRowItemClick(net.osmand.plus.ContextMenuAdapter.OnRowItemClick) 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) OsmandSettings(net.osmand.plus.OsmandSettings) ContextMenuAdapter(net.osmand.plus.ContextMenuAdapter) AdapterView(android.widget.AdapterView) CompoundButton(android.widget.CompoundButton) ArrayAdapter(android.widget.ArrayAdapter) SwitchCompat(android.support.v7.widget.SwitchCompat)

Example 3 with SRTMPlugin

use of net.osmand.plus.srtmplugin.SRTMPlugin in project Osmand by osmandapp.

the class OsmandPlugin method initPlugins.

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

Aggregations

SRTMPlugin (net.osmand.plus.srtmplugin.SRTMPlugin)3 DialogInterface (android.content.DialogInterface)1 AlertDialog (android.support.v7.app.AlertDialog)1 AppCompatCheckedTextView (android.support.v7.widget.AppCompatCheckedTextView)1 SwitchCompat (android.support.v7.widget.SwitchCompat)1 View (android.view.View)1 ViewGroup (android.view.ViewGroup)1 AdapterView (android.widget.AdapterView)1 ArrayAdapter (android.widget.ArrayAdapter)1 CompoundButton (android.widget.CompoundButton)1 OnCheckedChangeListener (android.widget.CompoundButton.OnCheckedChangeListener)1 ImageView (android.widget.ImageView)1 ListView (android.widget.ListView)1 TextView (android.widget.TextView)1 TIntArrayList (gnu.trove.list.array.TIntArrayList)1 ArrayList (java.util.ArrayList)1 AccessibilityPlugin (net.osmand.access.AccessibilityPlugin)1 ContextMenuAdapter (net.osmand.plus.ContextMenuAdapter)1 OnRowItemClick (net.osmand.plus.ContextMenuAdapter.OnRowItemClick)1 ContextMenuItem (net.osmand.plus.ContextMenuItem)1