use of net.osmand.plus.settings.backend.menuitems.MainContextMenuItemsSettings in project Osmand by osmandapp.
the class MapContextMenuFragment method updateActionButtons.
private void updateActionButtons(MapActivity mapActivity) {
LinearLayout buttons = view.findViewById(R.id.context_menu_buttons);
buttons.setBackgroundColor(ContextCompat.getColor(mapActivity, nightMode ? R.color.list_background_color_dark : R.color.activity_background_color_light));
buttons.setVisibility(menu.buttonsVisible() ? View.VISIBLE : View.GONE);
// Action buttons
ContextMenuAdapter adapter = menu.getActionsContextMenuAdapter(false);
List<ContextMenuItem> items = adapter.getVisibleItems();
List<String> mainIds = ((MainContextMenuItemsSettings) mapActivity.getMyApplication().getSettings().CONTEXT_MENU_ACTIONS_ITEMS.get()).getMainIds();
ContextMenuAdapter mainAdapter = new ContextMenuAdapter(requireMyApplication());
ContextMenuAdapter additionalAdapter = new ContextMenuAdapter(requireMyApplication());
if (!mainIds.isEmpty()) {
for (ContextMenuItem item : items) {
if (mainIds.contains(item.getId())) {
mainAdapter.addItem(item);
} else {
additionalAdapter.addItem(item);
}
}
} else {
for (int i = 0; i < items.size(); i++) {
if (i < MAIN_BUTTONS_QUANTITY) {
mainAdapter.addItem(items.get(i));
} else {
additionalAdapter.addItem(items.get(i));
}
}
}
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT, 1f);
buttons.removeAllViews();
ContextMenuItemClickListener mainListener = menu.getContextMenuItemClickListener(mainAdapter);
ContextMenuItemClickListener additionalListener = menu.getContextMenuItemClickListener(additionalAdapter);
if (!mainIds.isEmpty()) {
for (ContextMenuItem item : mainAdapter.getItems()) {
buttons.addView(getActionView(item, mainAdapter.getItems().indexOf(item), mainAdapter, additionalAdapter, mainListener, additionalListener), params);
}
} else {
int mainButtonsQuantity = Math.min(MAIN_BUTTONS_QUANTITY, items.size());
for (int i = 0; i < mainButtonsQuantity; i++) {
buttons.addView(getActionView(items.get(i), i, mainAdapter, additionalAdapter, mainListener, additionalListener), params);
}
}
buttons.setGravity(Gravity.CENTER);
}
use of net.osmand.plus.settings.backend.menuitems.MainContextMenuItemsSettings in project Osmand by osmandapp.
the class ConfigureMenuItemsFragment method onCreateView.
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable final ViewGroup container, @Nullable Bundle savedInstanceState) {
Context ctx = requireContext();
View root = mInflater.inflate(R.layout.edit_arrangement_list_fragment, container, false);
AppBarLayout appbar = root.findViewById(R.id.appbar);
View toolbar = mInflater.inflate(R.layout.global_preference_toolbar, container, false);
TextView toolbarTitle = toolbar.findViewById(R.id.toolbar_title);
ImageButton toolbarButton = toolbar.findViewById(R.id.close_button);
toolbar.setBackgroundColor(ColorUtilities.getListBgColor(ctx, nightMode));
toolbarTitle.setTextColor(nightMode ? getResources().getColor(R.color.text_color_primary_dark) : getResources().getColor(R.color.list_background_color_dark));
toolbarButton.setImageDrawable(getPaintedContentIcon(AndroidUtils.getNavigationIconResId(app), getResources().getColor(R.color.text_color_secondary_light)));
toolbarTitle.setText(screenType.titleRes);
toolbarButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
exitFragment();
}
});
appbar.addView(toolbar);
recyclerView = root.findViewById(R.id.profiles_list);
View cancelButton = root.findViewById(R.id.dismiss_button);
root.findViewById(R.id.buttons_divider).setVisibility(View.VISIBLE);
UiUtilities.setupDialogButton(nightMode, cancelButton, UiUtilities.DialogButtonType.SECONDARY, R.string.shared_string_cancel);
View applyButton = root.findViewById(R.id.right_bottom_button);
cancelButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
FragmentActivity fragmentActivity = getActivity();
if (fragmentActivity != null) {
fragmentActivity.onBackPressed();
}
}
});
UiUtilities.setupDialogButton(nightMode, applyButton, UiUtilities.DialogButtonType.PRIMARY, R.string.shared_string_apply);
applyButton.setVisibility(View.VISIBLE);
applyButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
List<ContextMenuItem> defItems = getCustomizableDefaultItems(contextMenuAdapter.getDefaultItems());
List<String> ids = new ArrayList<>();
if (!menuItemsOrder.isEmpty()) {
sortByCustomOrder(defItems, menuItemsOrder);
for (ContextMenuItem item : defItems) {
ids.add(item.getId());
}
}
FragmentManager fm = getFragmentManager();
final ContextMenuItemsSettings prefToSave;
if (screenType == ScreenType.DRAWER) {
prefToSave = new DrawerMenuItemsSettings(hiddenMenuItems, ids);
} else if (screenType == ScreenType.CONTEXT_MENU_ACTIONS) {
prefToSave = new MainContextMenuItemsSettings(mainActionItems, hiddenMenuItems, ids);
} else {
prefToSave = new ContextMenuItemsSettings(hiddenMenuItems, ids);
}
if (fm != null) {
ChangeGeneralProfilesPrefBottomSheet.showInstance(fm, getSettingForScreen().getId(), prefToSave, getTargetFragment(), false, R.string.back_to_editing, appMode, new ChangeGeneralProfilesPrefBottomSheet.OnChangeSettingListener() {
@Override
public void onApplied(boolean profileOnly) {
dismissFragment();
}
@Override
public void onDiscard() {
}
});
}
}
});
if (Build.VERSION.SDK_INT >= 21) {
AndroidUtils.addStatusBarPadding21v(app, root);
}
return root;
}
use of net.osmand.plus.settings.backend.menuitems.MainContextMenuItemsSettings in project Osmand by osmandapp.
the class ConfigureMenuItemsFragment method initMainActionsIds.
private void initMainActionsIds(ApplicationMode appMode, boolean useDefaultValue) {
List<ContextMenuItem> defItems = getCustomizableDefaultItems(contextMenuAdapter.getDefaultItems());
ContextMenuItemsSettings pref = getMenuItemsSettings(appMode, useDefaultValue);
if (pref instanceof MainContextMenuItemsSettings) {
mainActionItems = new ArrayList<>(((MainContextMenuItemsSettings) pref).getMainIds());
if (mainActionItems.isEmpty()) {
for (int i = 0; i < MAIN_BUTTONS_QUANTITY && i < defItems.size(); i++) {
mainActionItems.add(defItems.get(i).getId());
}
}
}
}
Aggregations