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();
}
}
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();
}
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();
}
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();
}
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);
}
Aggregations