Search in sources :

Example 1 with BottomSheetCallback

use of net.osmand.plus.widgets.tools.ExtendedBottomSheetBehavior.BottomSheetCallback in project Osmand by osmandapp.

the class AdditionalActionsBottomSheetDialogFragment method onCreateView.

@Nullable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    Activity activity = getActivity();
    nightMode = getMyApplication().getDaynightHelper().isNightModeForMapControls();
    portrait = AndroidUiHelper.isOrientationPortrait(activity);
    final int themeRes = nightMode ? R.style.OsmandDarkTheme : R.style.OsmandLightTheme;
    availableScreenH = AndroidUtils.getScreenHeight(activity) - AndroidUtils.getStatusBarHeight(activity);
    if (portrait) {
        availableScreenH -= AndroidUtils.getNavBarHeight(activity);
    }
    View mainView = View.inflate(new ContextThemeWrapper(getContext(), themeRes), R.layout.fragment_context_menu_actions_bottom_sheet_dialog, null);
    scrollView = mainView.findViewById(R.id.bottom_sheet_scroll_view);
    cancelRowBgView = mainView.findViewById(R.id.cancel_row_background);
    updateBackground(false);
    cancelRowBgView.setBackgroundResource(getCancelRowBgResId());
    mainView.findViewById(R.id.divider).setBackgroundResource(nightMode ? R.color.route_info_bottom_view_bg_dark : R.color.route_info_divider_light);
    View.OnClickListener dismissOnClickListener = new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            dismiss();
        }
    };
    mainView.findViewById(R.id.cancel_row).setOnClickListener(dismissOnClickListener);
    mainView.findViewById(R.id.scroll_view_container).setOnClickListener(dismissOnClickListener);
    View.OnClickListener onClickListener = new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            if (listener != null) {
                listener.onItemClick((int) view.getTag());
            }
            dismiss();
        }
    };
    LinearLayout itemsLinearLayout = (LinearLayout) mainView.findViewById(R.id.context_menu_items_container);
    LinearLayout row = (LinearLayout) View.inflate(getContext(), R.layout.grid_menu_row, null);
    int itemsAdded = 0;
    for (int i = 0; i < adapter.length(); i++) {
        ContextMenuItem item = adapter.getItem(i);
        View menuItem = View.inflate(new ContextThemeWrapper(getContext(), themeRes), R.layout.grid_menu_item, null);
        if (item.getIcon() != ContextMenuItem.INVALID_ID) {
            ((ImageView) menuItem.findViewById(R.id.icon)).setImageDrawable(getContentIcon(item.getIcon()));
        }
        ((TextView) menuItem.findViewById(R.id.title)).setText(item.getTitle());
        if (item.isClickable()) {
            menuItem.setTag(i);
            menuItem.setOnClickListener(onClickListener);
        } else {
            menuItem.setEnabled(false);
            menuItem.setAlpha(.5f);
        }
        ((FrameLayout) row.findViewById(getMenuItemContainerId(itemsAdded))).addView(menuItem);
        itemsAdded++;
        if (itemsAdded == 3 || (i == adapter.length() - 1 && itemsAdded > 0)) {
            itemsLinearLayout.addView(row);
            row = (LinearLayout) View.inflate(getContext(), R.layout.grid_menu_row, null);
            itemsAdded = 0;
        }
    }
    final ExtendedBottomSheetBehavior behavior = ExtendedBottomSheetBehavior.from(scrollView);
    behavior.setBottomSheetCallback(new BottomSheetCallback() {

        @Override
        public void onStateChanged(@NonNull View bottomSheet, int newState) {
            if (newState == ExtendedBottomSheetBehavior.STATE_HIDDEN) {
                dismiss();
            } else {
                updateBackground(newState == ExtendedBottomSheetBehavior.STATE_EXPANDED);
            }
        }

        @Override
        public void onSlide(@NonNull View bottomSheet, float slideOffset) {
        }
    });
    if (portrait) {
        behavior.setPeekHeight(getResources().getDimensionPixelSize(R.dimen.bottom_sheet_menu_peek_height));
    } else {
        getDialog().setOnShowListener(new DialogInterface.OnShowListener() {

            @Override
            public void onShow(DialogInterface dialog) {
                behavior.setState(ExtendedBottomSheetBehavior.STATE_EXPANDED);
            }
        });
    }
    return mainView;
}
Also used : ExtendedBottomSheetBehavior(net.osmand.plus.widgets.tools.ExtendedBottomSheetBehavior) ContextMenuItem(net.osmand.plus.ContextMenuItem) DialogInterface(android.content.DialogInterface) Activity(android.app.Activity) ImageView(android.widget.ImageView) TextView(android.widget.TextView) View(android.view.View) ContextThemeWrapper(android.view.ContextThemeWrapper) FrameLayout(android.widget.FrameLayout) TextView(android.widget.TextView) ImageView(android.widget.ImageView) BottomSheetCallback(net.osmand.plus.widgets.tools.ExtendedBottomSheetBehavior.BottomSheetCallback) LinearLayout(android.widget.LinearLayout) Nullable(android.support.annotation.Nullable)

Aggregations

Activity (android.app.Activity)1 DialogInterface (android.content.DialogInterface)1 Nullable (android.support.annotation.Nullable)1 ContextThemeWrapper (android.view.ContextThemeWrapper)1 View (android.view.View)1 FrameLayout (android.widget.FrameLayout)1 ImageView (android.widget.ImageView)1 LinearLayout (android.widget.LinearLayout)1 TextView (android.widget.TextView)1 ContextMenuItem (net.osmand.plus.ContextMenuItem)1 ExtendedBottomSheetBehavior (net.osmand.plus.widgets.tools.ExtendedBottomSheetBehavior)1 BottomSheetCallback (net.osmand.plus.widgets.tools.ExtendedBottomSheetBehavior.BottomSheetCallback)1