use of net.osmand.plus.views.mapwidgets.WidgetsPanel in project Osmand by osmandapp.
the class ReorderWidgetsAdapterHelper method addWidget.
public void addWidget(@NonNull MapWidgetInfo widgetInfo) {
WidgetsPanel panel = dataHolder.getSelectedPanel();
boolean alreadyAdded = widgetAlreadyAdded(widgetInfo.key);
String widgetId = panel.isDuplicatesAllowed() && alreadyAdded ? getDuplicateWidgetId(widgetInfo.key) : widgetInfo.key;
int page = getLastPage();
int order = dataHolder.getMaxOrderOfPage(page) + 1;
dataHolder.addWidgetToPage(widgetId, page);
dataHolder.getOrders().put(widgetId, order);
AddedWidgetUiInfo addedWidgetUiInfo = new AddedWidgetUiInfo();
addedWidgetUiInfo.key = widgetId;
addedWidgetUiInfo.title = widgetInfo.getTitle(app);
addedWidgetUiInfo.info = widgetInfo;
addedWidgetUiInfo.page = page;
addedWidgetUiInfo.order = order;
addedWidgetUiInfo.iconId = widgetInfo.getMapIconId(nightMode);
insertToEndOfAddedWidgets(new ListItem(ItemType.ADDED_WIDGET, addedWidgetUiInfo));
if (!panel.isDuplicatesAllowed()) {
removeAddedItemFromAvailable(widgetId);
}
}
use of net.osmand.plus.views.mapwidgets.WidgetsPanel in project Osmand by osmandapp.
the class ReorderWidgetsFragment method applyWidgetsPanel.
private void applyWidgetsPanel(@NonNull List<String> enabledWidgetsIds) {
WidgetsPanel currentPanel = dataHolder.getSelectedPanel();
if (currentPanel.isDuplicatesAllowed()) {
Fragment fragment = getTargetFragment();
if (fragment instanceof ConfigureWidgetsFragment) {
((ConfigureWidgetsFragment) fragment).onWidgetsSelectedToAdd(enabledWidgetsIds, currentPanel);
}
} else {
for (String widgetId : enabledWidgetsIds) {
MapWidgetInfo widgetInfo = widgetRegistry.getWidgetInfoById(widgetId);
if (widgetInfo != null && widgetInfo.widgetPanel != currentPanel) {
widgetRegistry.getWidgetsForPanel(widgetInfo.widgetPanel).remove(widgetInfo);
widgetRegistry.getWidgetsForPanel(currentPanel).add(widgetInfo);
widgetInfo.widgetPanel = currentPanel;
}
}
}
}
use of net.osmand.plus.views.mapwidgets.WidgetsPanel in project Osmand by osmandapp.
the class ReorderWidgetsFragment method applyWidgetsOrder.
private void applyWidgetsOrder(@NonNull List<List<String>> pagedOrder) {
WidgetsPanel selectedPanel = dataHolder.getSelectedPanel();
selectedPanel.setWidgetsOrder(selectedAppMode, pagedOrder, settings);
widgetRegistry.reorderWidgets();
}
use of net.osmand.plus.views.mapwidgets.WidgetsPanel in project Osmand by osmandapp.
the class ReorderWidgetsFragment method createAvailableWidgetsList.
@NonNull
private List<ListItem> createAvailableWidgetsList(@NonNull ApplicationMode appMode) {
Map<Integer, ListItem> defaultWidgetsItems = new TreeMap<>();
List<ListItem> externalWidgetsItems = new ArrayList<>();
List<WidgetGroup> availableGroups = new ArrayList<>();
int filter = AVAILABLE_MODE | DEFAULT_MODE;
MapActivity mapActivity = requireMapActivity();
WidgetsPanel selectedPanel = dataHolder.getSelectedPanel();
Set<MapWidgetInfo> widgets = widgetRegistry.getWidgetsForPanel(mapActivity, appMode, filter, selectedPanel.getMergedPanels());
for (MapWidgetInfo widgetInfo : widgets) {
boolean enabled = dataHolder.getOrders().containsKey(widgetInfo.key);
if (enabled && !selectedPanel.isDuplicatesAllowed()) {
continue;
}
WidgetType widgetType = WidgetType.getById(widgetInfo.key);
boolean defaultWidget = widgetType != null;
if (defaultWidget) {
WidgetGroup group = widgetType.group;
if (group != null && !availableGroups.contains(group)) {
availableGroups.add(group);
defaultWidgetsItems.put(group.getOrder(), new ListItem(ItemType.AVAILABLE_GROUP, group));
} else if (group == null) {
AvailableWidgetUiInfo availableWidgetInfo = getWidgetInfo(widgetInfo);
defaultWidgetsItems.put(widgetType.ordinal(), new ListItem(ItemType.AVAILABLE_WIDGET, availableWidgetInfo));
}
} else {
AvailableWidgetUiInfo availableWidgetInfo = getWidgetInfo(widgetInfo);
externalWidgetsItems.add(new ListItem(ItemType.AVAILABLE_WIDGET, availableWidgetInfo));
}
}
List<ListItem> widgetItems = new ArrayList<>();
widgetItems.addAll(defaultWidgetsItems.values());
widgetItems.addAll(externalWidgetsItems);
return widgetItems;
}
use of net.osmand.plus.views.mapwidgets.WidgetsPanel in project Osmand by osmandapp.
the class ConnectedApp method createWidgetControls.
void createWidgetControls(@NonNull MapActivity mapActivity, @NonNull List<MapWidgetInfo> widgetsInfos) {
MapWidgetRegistry widgetRegistry = app.getOsmandMap().getMapLayers().getMapWidgetRegistry();
for (AidlMapWidgetWrapper widgetData : widgets.values()) {
int iconId = AndroidUtils.getDrawableId(mapActivity.getMyApplication(), widgetData.getMenuIconName());
int menuIconId = iconId != 0 ? iconId : ContextMenuItem.INVALID_ID;
String widgetKey = WIDGET_ID_PREFIX + widgetData.getId();
WidgetsPanel defaultPanel = widgetData.isRightPanelByDefault() ? WidgetsPanel.RIGHT : WidgetsPanel.LEFT;
TextInfoWidget widget = createWidgetControl(mapActivity, widgetData.getId());
MapWidgetInfo widgetInfo = widgetRegistry.createExternalWidget(widgetKey, widget, menuIconId, widgetData.getMenuTitle(), defaultPanel, widgetData.getOrder());
((SideWidgetInfo) widgetInfo).setExternalProviderPackage(pack);
widgetsInfos.add(widgetInfo);
widgetControls.put(widgetData.getId(), widget);
}
}
Aggregations