Search in sources :

Example 11 with MapInfoLayer

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

the class ParkingPositionPlugin method registerWidget.

private void registerWidget(@NonNull MapActivity activity) {
    MapInfoLayer mapInfoLayer = activity.getMapLayers().getMapInfoLayer();
    if (mapInfoLayer != null) {
        parkingPlaceControl = createParkingPlaceInfoControl(activity);
        mapInfoLayer.registerSideWidget(parkingPlaceControl, R.drawable.ic_action_parking_dark, R.string.map_widget_parking, "parking", false, 10);
        mapInfoLayer.recreateControls();
    }
}
Also used : MapInfoLayer(net.osmand.plus.views.layers.MapInfoLayer)

Example 12 with MapInfoLayer

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

the class MapWidgetRegistry method updateMapMarkersMode.

public void updateMapMarkersMode(MapActivity mapActivity) {
    for (MapWidgetRegInfo info : rightWidgetSet) {
        if ("map_marker_1st".equals(info.key)) {
            setVisibility(info, settings.MAP_MARKERS_MODE.get().isWidgets() && settings.MARKERS_DISTANCE_INDICATION_ENABLED.get(), false);
        } else if ("map_marker_2nd".equals(info.key)) {
            setVisibility(info, settings.MAP_MARKERS_MODE.get().isWidgets() && settings.MARKERS_DISTANCE_INDICATION_ENABLED.get() && settings.DISPLAYED_MARKERS_WIDGETS_COUNT.get() == 2, false);
        }
    }
    MapInfoLayer mil = mapActivity.getMapLayers().getMapInfoLayer();
    if (mil != null) {
        mil.recreateControls();
    }
    mapActivity.refreshMap();
}
Also used : MapInfoLayer(net.osmand.plus.views.layers.MapInfoLayer)

Example 13 with MapInfoLayer

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

the class MapWidgetRegistry method setVisibility.

private void setVisibility(ArrayAdapter<ContextMenuItem> adapter, MapWidgetRegInfo r, int position, boolean visible, boolean collapsed) {
    setVisibility(r, visible, collapsed);
    MapInfoLayer mil = app.getOsmandMap().getMapLayers().getMapInfoLayer();
    if (mil != null) {
        mil.recreateControls();
    }
    ContextMenuItem item = adapter.getItem(position);
    item.setSelected(visible);
    item.setColor(app, visible ? R.color.osmand_orange : ContextMenuItem.INVALID_ID);
    item.setDescription(visible && collapsed ? getString(R.string.shared_string_collapse) : null);
    adapter.notifyDataSetChanged();
}
Also used : ContextMenuItem(net.osmand.plus.ContextMenuItem) MapInfoLayer(net.osmand.plus.views.layers.MapInfoLayer)

Example 14 with MapInfoLayer

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

the class MapWidgetRegistry method showPopUpMenu.

public void showPopUpMenu(@NonNull MapActivity mapActivity, @NonNull View view, @NonNull final ArrayAdapter<ContextMenuItem> adapter, @Nullable final WidgetState widgetState, @Nullable final String message, @NonNull ApplicationMode mode, @NonNull OnClickListener showBtnListener, @NonNull OnClickListener hideBtnListener, @Nullable OnClickListener collapseBtnListener, boolean selected, final int pos) {
    final boolean nightMode = app.getDaynightHelper().isNightModeForMapControls();
    final int currentModeColor = mode.getProfileColor(nightMode);
    View parentView = view.findViewById(R.id.text_wrapper);
    List<PopUpMenuItem> items = new ArrayList<>();
    UiUtilities uiUtilities = app.getUIUtilities();
    if (widgetState != null) {
        final int[] menuIconIds = widgetState.getMenuIconIds();
        final int[] menuTitleIds = widgetState.getMenuTitleIds();
        final int[] menuItemIds = widgetState.getMenuItemIds();
        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];
                final int id = menuItemIds[i];
                boolean checkedItem = id == widgetState.getMenuItemId();
                Drawable icon = checkedItem && selected ? uiUtilities.getPaintedIcon(iconId, currentModeColor) : uiUtilities.getThemedIcon(iconId);
                items.add(new PopUpMenuItem.Builder(app).setTitle(getString(titleId)).setIcon(icon).setOnClickListener(v -> {
                    widgetState.changeState(id);
                    MapInfoLayer mil = mapActivity.getMapLayers().getMapInfoLayer();
                    if (mil != null) {
                        mil.recreateControls();
                    }
                    ContextMenuItem item = adapter.getItem(pos);
                    item.setIcon(widgetState.getMenuIconId());
                    if (message != null) {
                        item.setTitle(message);
                    } else {
                        item.setTitle(getString(widgetState.getMenuTitleId()));
                    }
                    adapter.notifyDataSetChanged();
                }).showCompoundBtn(currentModeColor).setSelected(checkedItem).create());
            }
        }
    }
    // show
    items.add(new PopUpMenuItem.Builder(app).setTitleId(R.string.shared_string_show).setIcon(uiUtilities.getThemedIcon(R.drawable.ic_action_view)).setOnClickListener(showBtnListener).showTopDivider(items.size() > 0).create());
    // hide
    items.add(new PopUpMenuItem.Builder(app).setTitleId(R.string.shared_string_hide).setIcon(uiUtilities.getThemedIcon(R.drawable.ic_action_hide)).setOnClickListener(hideBtnListener).create());
    // collapse
    if (collapseBtnListener != null) {
        items.add(new PopUpMenuItem.Builder(app).setTitleId(R.string.shared_string_collapse).setIcon(uiUtilities.getThemedIcon(R.drawable.ic_action_widget_collapse)).setOnClickListener(collapseBtnListener).create());
    }
    new PopUpMenuHelper.Builder(parentView, items, nightMode).setWidthType(PopUpMenuWidthType.STANDARD).setBackgroundColor(ColorUtilities.getListBgColor(mapActivity, nightMode)).show();
}
Also used : ContextMenuItem(net.osmand.plus.ContextMenuItem) ArrayList(java.util.ArrayList) Drawable(android.graphics.drawable.Drawable) PopUpMenuItem(net.osmand.plus.widgets.popup.PopUpMenuItem) View(android.view.View) UiUtilities(net.osmand.plus.utils.UiUtilities) PopUpMenuHelper(net.osmand.plus.widgets.popup.PopUpMenuHelper) MapInfoLayer(net.osmand.plus.views.layers.MapInfoLayer)

Example 15 with MapInfoLayer

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

the class OsmandAidlApi method registerAddMapWidgetReceiver.

private void registerAddMapWidgetReceiver(@NonNull MapActivity mapActivity) {
    final WeakReference<MapActivity> mapActivityRef = new WeakReference<>(mapActivity);
    BroadcastReceiver addMapWidgetReceiver = new BroadcastReceiver() {

        @Override
        public void onReceive(Context context, Intent intent) {
            MapActivity mapActivity = mapActivityRef.get();
            String widgetId = intent.getStringExtra(AIDL_OBJECT_ID);
            String packName = intent.getStringExtra(AIDL_PACKAGE_NAME);
            if (mapActivity != null && widgetId != null && packName != null) {
                ConnectedApp connectedApp = connectedApps.get(packName);
                if (connectedApp != null) {
                    AidlMapWidgetWrapper widget = connectedApp.getWidgets().get(widgetId);
                    MapInfoLayer layer = mapActivity.getMapLayers().getMapInfoLayer();
                    if (widget != null && layer != null) {
                        ApplicationMode.regWidgetVisibility(widget.getId(), (ApplicationMode[]) null);
                        TextInfoWidget control = connectedApp.createWidgetControl(mapActivity, widgetId);
                        connectedApp.getWidgetControls().put(widgetId, control);
                        int iconId = AndroidUtils.getDrawableId(app, widget.getMenuIconName());
                        int menuIconId = iconId != 0 ? iconId : ContextMenuItem.INVALID_ID;
                        String widgetKey = "aidl_widget_" + widgetId;
                        layer.registerSideWidget(control, menuIconId, widget.getMenuTitle(), widgetKey, false, widget.getOrder());
                        layer.recreateControls();
                    }
                }
            }
        }
    };
    registerReceiver(addMapWidgetReceiver, mapActivity, AIDL_ADD_MAP_WIDGET);
}
Also used : Context(android.content.Context) Intent(android.content.Intent) ApplicationMode(net.osmand.plus.settings.backend.ApplicationMode) BroadcastReceiver(android.content.BroadcastReceiver) FavouritePoint(net.osmand.data.FavouritePoint) SuppressLint(android.annotation.SuppressLint) TextInfoWidget(net.osmand.plus.views.mapwidgets.widgets.TextInfoWidget) WeakReference(java.lang.ref.WeakReference) MapInfoLayer(net.osmand.plus.views.layers.MapInfoLayer) MapActivity(net.osmand.plus.activities.MapActivity)

Aggregations

MapInfoLayer (net.osmand.plus.views.layers.MapInfoLayer)24 OsmandMapTileView (net.osmand.plus.views.OsmandMapTileView)6 View (android.view.View)4 MapActivity (net.osmand.plus.activities.MapActivity)4 TextInfoWidget (net.osmand.plus.views.mapwidgets.widgets.TextInfoWidget)4 ContextMenuItem (net.osmand.plus.ContextMenuItem)3 MapControlsLayer (net.osmand.plus.views.layers.MapControlsLayer)3 BroadcastReceiver (android.content.BroadcastReceiver)2 Context (android.content.Context)2 Intent (android.content.Intent)2 Drawable (android.graphics.drawable.Drawable)2 WeakReference (java.lang.ref.WeakReference)2 OsmandApplication (net.osmand.plus.OsmandApplication)2 ApplicationMode (net.osmand.plus.settings.backend.ApplicationMode)2 MapLayers (net.osmand.plus.views.MapLayers)2 SuppressLint (android.annotation.SuppressLint)1 ColorDrawable (android.graphics.drawable.ColorDrawable)1 MenuItem (android.view.MenuItem)1 AbsListView (android.widget.AbsListView)1 AdapterView (android.widget.AdapterView)1