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