Search in sources :

Example 16 with MapInfoLayer

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

the class OsmandAidlApi method registerAddMapWidgetReceiver.

private void registerAddMapWidgetReceiver(final MapActivity mapActivity) {
    addMapWidgetReceiver = new BroadcastReceiver() {

        @Override
        public void onReceive(Context context, Intent intent) {
            String widgetId = intent.getStringExtra(AIDL_OBJECT_ID);
            if (widgetId != null) {
                AMapWidget widget = widgets.get(widgetId);
                if (widget != null) {
                    MapInfoLayer layer = mapActivity.getMapLayers().getMapInfoLayer();
                    if (layer != null) {
                        TextInfoWidget control = createWidgetControl(mapActivity, widgetId);
                        widgetControls.put(widgetId, control);
                        int menuIconId = getDrawableId(widget.getMenuIconName());
                        MapWidgetRegInfo widgetInfo = layer.registerSideWidget(control, menuIconId, widget.getMenuTitle(), "aidl_widget_" + widgetId, false, widget.getOrder());
                        if (!mapActivity.getMapLayers().getMapWidgetRegistry().isVisible(widgetInfo.key)) {
                            mapActivity.getMapLayers().getMapWidgetRegistry().setVisibility(widgetInfo, true, false);
                        }
                        layer.recreateControls();
                    }
                }
            }
        }
    };
    mapActivity.registerReceiver(addMapWidgetReceiver, new IntentFilter(AIDL_ADD_MAP_WIDGET));
}
Also used : Context(android.content.Context) TextInfoWidget(net.osmand.plus.views.mapwidgets.TextInfoWidget) IntentFilter(android.content.IntentFilter) MapWidgetRegInfo(net.osmand.plus.views.mapwidgets.MapWidgetRegistry.MapWidgetRegInfo) MapInfoLayer(net.osmand.plus.views.MapInfoLayer) Intent(android.content.Intent) BroadcastReceiver(android.content.BroadcastReceiver) AMapWidget(net.osmand.aidl.mapwidget.AMapWidget)

Example 17 with MapInfoLayer

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

the class OsmandAidlApi method registerWidgetControls.

public void registerWidgetControls(MapActivity mapActivity) {
    for (AMapWidget widget : widgets.values()) {
        MapInfoLayer layer = mapActivity.getMapLayers().getMapInfoLayer();
        if (layer != null) {
            TextInfoWidget control = createWidgetControl(mapActivity, widget.getId());
            widgetControls.put(widget.getId(), control);
            int menuIconId = getDrawableId(widget.getMenuIconName());
            MapWidgetRegInfo widgetInfo = layer.registerSideWidget(control, menuIconId, widget.getMenuTitle(), "aidl_widget_" + widget.getId(), false, widget.getOrder());
            if (!mapActivity.getMapLayers().getMapWidgetRegistry().isVisible(widgetInfo.key)) {
                mapActivity.getMapLayers().getMapWidgetRegistry().setVisibility(widgetInfo, true, false);
            }
        }
    }
}
Also used : TextInfoWidget(net.osmand.plus.views.mapwidgets.TextInfoWidget) MapWidgetRegInfo(net.osmand.plus.views.mapwidgets.MapWidgetRegistry.MapWidgetRegInfo) MapInfoLayer(net.osmand.plus.views.MapInfoLayer) AMapWidget(net.osmand.aidl.mapwidget.AMapWidget) FavouritePoint(net.osmand.data.FavouritePoint) AMapPoint(net.osmand.aidl.maplayer.point.AMapPoint)

Example 18 with MapInfoLayer

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

the class ParkingPositionPlugin method updateLayers.

@Override
public void updateLayers(OsmandMapTileView mapView, MapActivity activity) {
    if (isActive()) {
        if (parkingLayer == null) {
            registerLayers(activity);
        }
        if (parkingPlaceControl == null) {
            registerWidget(activity);
        }
    } else {
        if (parkingLayer != null) {
            activity.getMapView().removeLayer(parkingLayer);
            parkingLayer = null;
        }
        MapInfoLayer mapInfoLayer = activity.getMapLayers().getMapInfoLayer();
        if (mapInfoLayer != null && parkingPlaceControl != null) {
            mapInfoLayer.removeSideWidget(parkingPlaceControl);
            mapInfoLayer.recreateControls();
            parkingPlaceControl = null;
        }
    }
}
Also used : MapInfoLayer(net.osmand.plus.views.MapInfoLayer)

Example 19 with MapInfoLayer

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

the class MapWidgetRegistry method addControls.

private void addControls(final MapActivity mapActivity, final ContextMenuAdapter contextMenuAdapter, Set<MapWidgetRegInfo> groupTitle, final ApplicationMode mode) {
    for (final MapWidgetRegInfo r : groupTitle) {
        if (!mode.isWidgetAvailable(r.key)) {
            continue;
        }
        final boolean selected = r.visibleCollapsed(mode) || r.visible(mode);
        final String desc = mapActivity.getString(R.string.shared_string_collapse);
        ContextMenuItem.ItemBuilder itemBuilder = new ContextMenuItem.ItemBuilder().setIcon(r.getDrawableMenu()).setSelected(selected).setColor(selected ? R.color.osmand_orange : ContextMenuItem.INVALID_ID).setSecondaryIcon(r.widget != null ? R.drawable.ic_action_additional_option : ContextMenuItem.INVALID_ID).setDescription(r.visibleCollapsed(mode) ? desc : null).setListener(new ContextMenuAdapter.OnRowItemClick() {

            @Override
            public boolean onRowItemClick(final ArrayAdapter<ContextMenuItem> adapter, final View view, final int itemId, final int pos) {
                if (r.widget == null) {
                    setVisibility(adapter, pos, !r.visible(mode), false);
                    return false;
                }
                View textWrapper = view.findViewById(R.id.text_wrapper);
                IconPopupMenu popup = new IconPopupMenu(view.getContext(), textWrapper);
                MenuInflater inflater = popup.getMenuInflater();
                final Menu menu = popup.getMenu();
                inflater.inflate(R.menu.widget_visibility_menu, menu);
                IconsCache ic = mapActivity.getMyApplication().getIconsCache();
                menu.findItem(R.id.action_show).setIcon(ic.getThemedIcon(R.drawable.ic_action_view));
                menu.findItem(R.id.action_hide).setIcon(ic.getThemedIcon(R.drawable.ic_action_hide));
                menu.findItem(R.id.action_collapse).setIcon(ic.getThemedIcon(R.drawable.ic_action_widget_collapse));
                final int[] menuIconIds = r.getDrawableMenuIds();
                final int[] menuTitleIds = r.getMessageIds();
                final int[] menuItemIds = r.getItemIds();
                int checkedId = r.getItemId();
                boolean selected = r.visibleCollapsed(mode) || r.visible(mode);
                if (menuIconIds != null && menuTitleIds != null && menuItemIds != null && menuIconIds.length == menuTitleIds.length && menuIconIds.length == menuItemIds.length) {
                    for (int i = 0; i < menuIconIds.length; i++) {
                        int iconId = menuIconIds[i];
                        int titleId = menuTitleIds[i];
                        int id = menuItemIds[i];
                        MenuItem menuItem = menu.add(R.id.single_selection_group, id, i, titleId).setChecked(id == checkedId);
                        menuItem.setIcon(menuItem.isChecked() && selected ? ic.getIcon(iconId, R.color.osmand_orange) : ic.getThemedIcon(iconId));
                    }
                    menu.setGroupCheckable(R.id.single_selection_group, true, true);
                    menu.setGroupVisible(R.id.single_selection_group, true);
                }
                popup.setOnMenuItemClickListener(new IconPopupMenu.OnMenuItemClickListener() {

                    @Override
                    public boolean onMenuItemClick(MenuItem menuItem) {
                        switch(menuItem.getItemId()) {
                            case R.id.action_show:
                                setVisibility(adapter, pos, true, false);
                                return true;
                            case R.id.action_hide:
                                setVisibility(adapter, pos, false, false);
                                return true;
                            case R.id.action_collapse:
                                setVisibility(adapter, pos, true, true);
                                return true;
                            default:
                                if (menuItemIds != null) {
                                    for (int menuItemId : menuItemIds) {
                                        if (menuItem.getItemId() == menuItemId) {
                                            r.changeState(menuItemId);
                                            MapInfoLayer mil = mapActivity.getMapLayers().getMapInfoLayer();
                                            if (mil != null) {
                                                mil.recreateControls();
                                            }
                                            ContextMenuItem item = adapter.getItem(pos);
                                            item.setIcon(r.getDrawableMenu());
                                            if (r.getMessage() != null) {
                                                item.setTitle(r.getMessage());
                                            } else {
                                                item.setTitle(mapActivity.getResources().getString(r.getMessageId()));
                                            }
                                            adapter.notifyDataSetChanged();
                                            return true;
                                        }
                                    }
                                }
                        }
                        return false;
                    }
                });
                popup.show();
                return false;
            }

            @Override
            public boolean onContextMenuClick(ArrayAdapter<ContextMenuItem> a, int itemId, int pos, boolean isChecked, int[] viewCoordinates) {
                setVisibility(a, pos, isChecked, false);
                return false;
            }

            private void setVisibility(ArrayAdapter<ContextMenuItem> adapter, int position, boolean visible, boolean collapsed) {
                MapWidgetRegistry.this.setVisibility(r, visible, collapsed);
                MapInfoLayer mil = mapActivity.getMapLayers().getMapInfoLayer();
                if (mil != null) {
                    mil.recreateControls();
                }
                ContextMenuItem item = adapter.getItem(position);
                item.setSelected(visible);
                item.setColorRes(visible ? R.color.osmand_orange : ContextMenuItem.INVALID_ID);
                item.setDescription(visible && collapsed ? desc : null);
                adapter.notifyDataSetChanged();
            }
        });
        if (r.getMessage() != null) {
            itemBuilder.setTitle(r.getMessage());
        } else {
            itemBuilder.setTitleId(r.getMessageId(), mapActivity);
        }
        contextMenuAdapter.addItem(itemBuilder.createItem());
    }
}
Also used : ContextMenuItem(net.osmand.plus.ContextMenuItem) MenuInflater(android.view.MenuInflater) MenuItem(android.view.MenuItem) ContextMenuItem(net.osmand.plus.ContextMenuItem) View(android.view.View) IconPopupMenu(net.osmand.plus.widgets.IconPopupMenu) ContextMenuAdapter(net.osmand.plus.ContextMenuAdapter) MapInfoLayer(net.osmand.plus.views.MapInfoLayer) Menu(android.view.Menu) IconPopupMenu(net.osmand.plus.widgets.IconPopupMenu) ConfigureMapMenu(net.osmand.plus.dialogs.ConfigureMapMenu) IconsCache(net.osmand.plus.IconsCache)

Aggregations

MapInfoLayer (net.osmand.plus.views.MapInfoLayer)19 TextInfoWidget (net.osmand.plus.views.mapwidgets.TextInfoWidget)4 BroadcastReceiver (android.content.BroadcastReceiver)2 Context (android.content.Context)2 Intent (android.content.Intent)2 IntentFilter (android.content.IntentFilter)2 MenuItem (android.view.MenuItem)2 View (android.view.View)2 AMapWidget (net.osmand.aidl.mapwidget.AMapWidget)2 ContextMenuItem (net.osmand.plus.ContextMenuItem)2 IconsCache (net.osmand.plus.IconsCache)2 OsmandMapTileView (net.osmand.plus.views.OsmandMapTileView)2 MapWidgetRegInfo (net.osmand.plus.views.mapwidgets.MapWidgetRegistry.MapWidgetRegInfo)2 Toolbar (android.support.v7.widget.Toolbar)1 Menu (android.view.Menu)1 MenuInflater (android.view.MenuInflater)1 AbsListView (android.widget.AbsListView)1 AdapterView (android.widget.AdapterView)1 ImageView (android.widget.ImageView)1 ListView (android.widget.ListView)1