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