Search in sources :

Example 1 with WidgetsPanel

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);
    }
}
Also used : AddedWidgetUiInfo(net.osmand.plus.views.mapwidgets.configure.reorder.viewholder.AddedWidgetViewHolder.AddedWidgetUiInfo) WidgetsPanel(net.osmand.plus.views.mapwidgets.WidgetsPanel) ListItem(net.osmand.plus.views.mapwidgets.configure.reorder.ReorderWidgetsAdapter.ListItem)

Example 2 with WidgetsPanel

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;
            }
        }
    }
}
Also used : ConfigureWidgetsFragment(net.osmand.plus.views.mapwidgets.configure.panel.ConfigureWidgetsFragment) WidgetsPanel(net.osmand.plus.views.mapwidgets.WidgetsPanel) MapWidgetInfo(net.osmand.plus.views.mapwidgets.MapWidgetInfo) Fragment(androidx.fragment.app.Fragment) BaseOsmAndFragment(net.osmand.plus.base.BaseOsmAndFragment) ConfigureWidgetsFragment(net.osmand.plus.views.mapwidgets.configure.panel.ConfigureWidgetsFragment) AddWidgetFragment(net.osmand.plus.views.mapwidgets.configure.add.AddWidgetFragment)

Example 3 with WidgetsPanel

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();
}
Also used : WidgetsPanel(net.osmand.plus.views.mapwidgets.WidgetsPanel)

Example 4 with WidgetsPanel

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;
}
Also used : AvailableWidgetUiInfo(net.osmand.plus.views.mapwidgets.configure.reorder.viewholder.AvailableItemViewHolder.AvailableWidgetUiInfo) ArrayList(java.util.ArrayList) WidgetGroup(net.osmand.plus.views.mapwidgets.WidgetGroup) MapWidgetInfo(net.osmand.plus.views.mapwidgets.MapWidgetInfo) TreeMap(java.util.TreeMap) WidgetsPanel(net.osmand.plus.views.mapwidgets.WidgetsPanel) ListItem(net.osmand.plus.views.mapwidgets.configure.reorder.ReorderWidgetsAdapter.ListItem) WidgetType(net.osmand.plus.views.mapwidgets.WidgetType) MapActivity(net.osmand.plus.activities.MapActivity) NonNull(androidx.annotation.NonNull)

Example 5 with WidgetsPanel

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);
    }
}
Also used : TextInfoWidget(net.osmand.plus.views.mapwidgets.widgets.TextInfoWidget) WidgetsPanel(net.osmand.plus.views.mapwidgets.WidgetsPanel) MapWidgetInfo(net.osmand.plus.views.mapwidgets.MapWidgetInfo) SideWidgetInfo(net.osmand.plus.views.mapwidgets.SideWidgetInfo) MapWidgetRegistry(net.osmand.plus.views.mapwidgets.MapWidgetRegistry)

Aggregations

WidgetsPanel (net.osmand.plus.views.mapwidgets.WidgetsPanel)20 MapWidgetInfo (net.osmand.plus.views.mapwidgets.MapWidgetInfo)10 MapActivity (net.osmand.plus.activities.MapActivity)8 ArrayList (java.util.ArrayList)6 ListItem (net.osmand.plus.views.mapwidgets.configure.reorder.ReorderWidgetsAdapter.ListItem)6 ImageView (android.widget.ImageView)4 TextView (android.widget.TextView)4 Fragment (androidx.fragment.app.Fragment)4 BaseOsmAndFragment (net.osmand.plus.base.BaseOsmAndFragment)4 MapWidgetRegistry (net.osmand.plus.views.mapwidgets.MapWidgetRegistry)4 SideWidgetInfo (net.osmand.plus.views.mapwidgets.SideWidgetInfo)4 AddedWidgetUiInfo (net.osmand.plus.views.mapwidgets.configure.reorder.viewholder.AddedWidgetViewHolder.AddedWidgetUiInfo)4 TextInfoWidget (net.osmand.plus.views.mapwidgets.widgets.TextInfoWidget)4 SuppressLint (android.annotation.SuppressLint)2 BroadcastReceiver (android.content.BroadcastReceiver)2 Context (android.content.Context)2 Intent (android.content.Intent)2 View (android.view.View)2 CheckBox (android.widget.CheckBox)2 NonNull (androidx.annotation.NonNull)2