Search in sources :

Example 1 with SwitchableAction

use of net.osmand.plus.quickaction.SwitchableAction in project Osmand by osmandapp.

the class SelectMapViewQuickActionsBottomSheet method createMenuItems.

@Override
public void createMenuItems(Bundle savedInstanceState) {
    Bundle args = getArguments();
    if (args == null) {
        return;
    }
    MapActivity mapActivity = getMapActivity();
    if (mapActivity == null) {
        return;
    }
    long id = args.getLong(SwitchableAction.KEY_ID);
    OsmandApplication app = mapActivity.getMyApplication();
    QuickActionRegistry quickActionRegistry = app.getQuickActionRegistry();
    action = quickActionRegistry.getQuickAction(id);
    action = QuickActionRegistry.produceAction(action);
    if (action == null) {
        return;
    }
    OsmandSettings settings = app.getSettings();
    if (savedInstanceState != null) {
        selectedItem = savedInstanceState.getString(SELECTED_ITEM_KEY);
    } else {
        selectedItem = ((SwitchableAction<?>) action).getSelectedItem(app);
    }
    rbColorList = AndroidUtils.createCheckedColorStateList(app, R.color.icon_color_default_light, getActiveColorId());
    items.add(new TitleItem(action.getName(app)));
    NestedScrollView nestedScrollView = new NestedScrollView(app);
    itemsContainer = new LinearLayout(app);
    itemsContainer.setLayoutParams((new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT)));
    itemsContainer.setOrientation(LinearLayout.VERTICAL);
    int padding = getResources().getDimensionPixelSize(R.dimen.bottom_sheet_content_padding_small);
    itemsContainer.setPadding(0, padding, 0, padding);
    int itemsSize = 0;
    if (action instanceof SwitchableAction) {
        SwitchableAction switchableAction = (SwitchableAction) action;
        List sources = switchableAction.loadListFromParams();
        itemsSize = sources.size();
    }
    for (int i = 0; i < itemsSize; i++) {
        LayoutInflater.from(new ContextThemeWrapper(app, themeRes)).inflate(R.layout.bottom_sheet_item_with_radio_btn, itemsContainer, true);
    }
    nestedScrollView.addView(itemsContainer);
    items.add(new BaseBottomSheetItem.Builder().setCustomView(nestedScrollView).create());
    populateItemsList();
}
Also used : BaseBottomSheetItem(net.osmand.plus.base.bottomsheetmenu.BaseBottomSheetItem) LayoutParams(android.widget.LinearLayout.LayoutParams) OsmandApplication(net.osmand.plus.OsmandApplication) Bundle(android.os.Bundle) TitleItem(net.osmand.plus.base.bottomsheetmenu.simpleitems.TitleItem) OsmandSettings(net.osmand.plus.settings.backend.OsmandSettings) SwitchableAction(net.osmand.plus.quickaction.SwitchableAction) ContextThemeWrapper(android.view.ContextThemeWrapper) ColorStateList(android.content.res.ColorStateList) List(java.util.List) NestedScrollView(androidx.core.widget.NestedScrollView) QuickActionRegistry(net.osmand.plus.quickaction.QuickActionRegistry) LinearLayout(android.widget.LinearLayout) MapActivity(net.osmand.plus.activities.MapActivity)

Example 2 with SwitchableAction

use of net.osmand.plus.quickaction.SwitchableAction in project Osmand by osmandapp.

the class SelectMapViewQuickActionsBottomSheet method populateItemsList.

private void populateItemsList() {
    Context context = getContext();
    if (context == null) {
        return;
    }
    int counter = 0;
    if (action instanceof MapStyleAction) {
        MapStyleAction mapStyleAction = (MapStyleAction) action;
        List<String> stylesList = mapStyleAction.getFilteredStyles();
        for (String entry : stylesList) {
            boolean selected = entry.equals(selectedItem);
            createItemRow(selected, counter, getContentIcon(action.getIconRes()), mapStyleAction.getTranslatedItemName(context, entry), entry);
            counter++;
        }
    } else if (action instanceof SwitchProfileAction) {
        SwitchProfileAction switchProfileAction = (SwitchProfileAction) action;
        List<String> profilesKeys = (List<String>) switchProfileAction.loadListFromParams();
        for (String key : profilesKeys) {
            ApplicationMode appMode = ApplicationMode.valueOfStringKey(key, null);
            if (appMode != null) {
                boolean selected = key.equals(selectedItem);
                int iconId = appMode.getIconRes();
                int color = appMode.getProfileColor(nightMode);
                Drawable icon = getPaintedIcon(iconId, color);
                String translatedName = appMode.toHumanString();
                createItemRow(selected, counter, icon, translatedName, key);
                counter++;
            }
        }
    } else if (action instanceof SwitchableAction) {
        SwitchableAction switchableAction = (SwitchableAction) action;
        List<Pair<String, String>> sources = (List<Pair<String, String>>) switchableAction.loadListFromParams();
        for (Pair<String, String> entry : sources) {
            String tag = entry.first;
            boolean selected = tag.equals(selectedItem);
            createItemRow(selected, counter, getContentIcon(action.getIconRes()), entry.second, tag);
            counter++;
        }
    }
}
Also used : Context(android.content.Context) Drawable(android.graphics.drawable.Drawable) MapStyleAction(net.osmand.plus.quickaction.actions.MapStyleAction) ApplicationMode(net.osmand.plus.settings.backend.ApplicationMode) SwitchableAction(net.osmand.plus.quickaction.SwitchableAction) SwitchProfileAction(net.osmand.plus.quickaction.actions.SwitchProfileAction) ColorStateList(android.content.res.ColorStateList) List(java.util.List) Pair(androidx.core.util.Pair)

Aggregations

ColorStateList (android.content.res.ColorStateList)2 List (java.util.List)2 SwitchableAction (net.osmand.plus.quickaction.SwitchableAction)2 Context (android.content.Context)1 Drawable (android.graphics.drawable.Drawable)1 Bundle (android.os.Bundle)1 ContextThemeWrapper (android.view.ContextThemeWrapper)1 LinearLayout (android.widget.LinearLayout)1 LayoutParams (android.widget.LinearLayout.LayoutParams)1 Pair (androidx.core.util.Pair)1 NestedScrollView (androidx.core.widget.NestedScrollView)1 OsmandApplication (net.osmand.plus.OsmandApplication)1 MapActivity (net.osmand.plus.activities.MapActivity)1 BaseBottomSheetItem (net.osmand.plus.base.bottomsheetmenu.BaseBottomSheetItem)1 TitleItem (net.osmand.plus.base.bottomsheetmenu.simpleitems.TitleItem)1 QuickActionRegistry (net.osmand.plus.quickaction.QuickActionRegistry)1 MapStyleAction (net.osmand.plus.quickaction.actions.MapStyleAction)1 SwitchProfileAction (net.osmand.plus.quickaction.actions.SwitchProfileAction)1 ApplicationMode (net.osmand.plus.settings.backend.ApplicationMode)1 OsmandSettings (net.osmand.plus.settings.backend.OsmandSettings)1