Search in sources :

Example 1 with DividerItem

use of net.osmand.plus.base.bottomsheetmenu.simpleitems.DividerItem in project Osmand by osmandapp.

the class SelectWptCategoriesBottomSheetDialogFragment method createMenuItems.

@Override
public void createMenuItems(Bundle savedInstanceState) {
    gpxFile = getGpxFile();
    if (gpxFile == null) {
        return;
    }
    items.add(new TitleItem(getGpxName(gpxFile)));
    items.add(new DescriptionItem(getString(R.string.select_waypoints_category_description)));
    final BottomSheetItemWithCompoundButton[] selectAllItem = new BottomSheetItemWithCompoundButton[1];
    selectAllItem[0] = (BottomSheetItemWithCompoundButton) new BottomSheetItemWithCompoundButton.Builder().setChecked(true).setDescription(getString(R.string.shared_string_total) + ": " + gpxFile.getPoints().size()).setIcon(getContentIcon(R.drawable.ic_action_group_select_all)).setTitle(getString(R.string.shared_string_select_all)).setLayoutId(R.layout.bottom_sheet_item_with_descr_and_checkbox_56dp).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            boolean checked = !selectAllItem[0].isChecked();
            selectAllItem[0].setChecked(checked);
            for (BottomSheetItemWithCompoundButton item : categoryItems) {
                item.setChecked(checked);
            }
        }
    }).create();
    items.add(selectAllItem[0]);
    items.add(new DividerItem(getContext()));
    Map<String, List<WptPt>> pointsByCategories = gpxFile.getPointsByCategories();
    for (String category : pointsByCategories.keySet()) {
        final BottomSheetItemWithCompoundButton[] categoryItem = new BottomSheetItemWithCompoundButton[1];
        categoryItem[0] = (BottomSheetItemWithCompoundButton) new BottomSheetItemWithCompoundButton.Builder().setChecked(true).setOnCheckedChangeListener(new OnCheckedChangeListener() {

            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if (isChecked) {
                    selectedCategories.add((String) categoryItem[0].getTag());
                } else {
                    selectedCategories.remove((String) categoryItem[0].getTag());
                }
            }
        }).setDescription(String.valueOf(pointsByCategories.get(category).size())).setIcon(getContentIcon(R.drawable.ic_action_folder)).setTitle(category.equals("") ? getString(R.string.waypoints) : category).setLayoutId(R.layout.bottom_sheet_item_with_descr_and_checkbox_56dp).setTag(category).setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                categoryItem[0].setChecked(!categoryItem[0].isChecked());
                selectAllItem[0].setChecked(isAllChecked());
            }
        }).create();
        items.add(categoryItem[0]);
        categoryItems.add(categoryItem[0]);
        selectedCategories.add(category);
    }
}
Also used : OnCheckedChangeListener(android.widget.CompoundButton.OnCheckedChangeListener) TitleItem(net.osmand.plus.base.bottomsheetmenu.simpleitems.TitleItem) View(android.view.View) ArrayList(java.util.ArrayList) List(java.util.List) DividerItem(net.osmand.plus.base.bottomsheetmenu.simpleitems.DividerItem) BottomSheetItemWithCompoundButton(net.osmand.plus.base.bottomsheetmenu.BottomSheetItemWithCompoundButton) BottomSheetItemWithCompoundButton(net.osmand.plus.base.bottomsheetmenu.BottomSheetItemWithCompoundButton) CompoundButton(android.widget.CompoundButton) DescriptionItem(net.osmand.plus.base.bottomsheetmenu.simpleitems.DescriptionItem)

Example 2 with DividerItem

use of net.osmand.plus.base.bottomsheetmenu.simpleitems.DividerItem in project Osmand by osmandapp.

the class HistoryMarkerMenuBottomSheetDialogFragment method createMenuItems.

@Override
public void createMenuItems(Bundle savedInstanceState) {
    Bundle arguments = getArguments();
    if (arguments != null) {
        final int pos = arguments.getInt(MARKER_POSITION);
        final String markerName = arguments.getString(MARKER_NAME);
        final int markerColorIndex = arguments.getInt(MARKER_COLOR_INDEX);
        final long markerVisitedDate = arguments.getLong(MARKER_VISITED_DATE);
        Date date = new Date(markerVisitedDate);
        String month = new SimpleDateFormat("MMM", Locale.getDefault()).format(date);
        month = Algorithms.capitalizeFirstLetter(month);
        month = month.replaceAll("\\.", "");
        String day = new SimpleDateFormat("d", Locale.getDefault()).format(date);
        BaseBottomSheetItem markerItem = new BottomSheetItemWithDescription.Builder().setDescription(getString(R.string.passed, month + " " + day)).setIcon(getIcon(R.drawable.ic_action_flag_dark, MapMarker.getColorId(markerColorIndex))).setTitle(markerName).setLayoutId(R.layout.bottom_sheet_item_with_descr_56dp).create();
        items.add(markerItem);
        items.add(new DividerItem(getContext()));
        BaseBottomSheetItem makeActiveItem = new SimpleBottomSheetItem.Builder().setIcon(getContentIcon(R.drawable.ic_action_reset_to_default_dark)).setTitle(getString(R.string.make_active)).setLayoutId(R.layout.bottom_sheet_item_simple).setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                if (listener != null) {
                    listener.onMakeMarkerActive(pos);
                }
                dismiss();
            }
        }).create();
        items.add(makeActiveItem);
        BaseBottomSheetItem deleteItem = new SimpleBottomSheetItem.Builder().setIcon(getContentIcon(R.drawable.ic_action_delete_dark)).setTitle(getString(R.string.shared_string_delete)).setLayoutId(R.layout.bottom_sheet_item_simple).setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                if (listener != null) {
                    listener.onDeleteMarker(pos);
                }
                dismiss();
            }
        }).create();
        items.add(deleteItem);
    }
}
Also used : BaseBottomSheetItem(net.osmand.plus.base.bottomsheetmenu.BaseBottomSheetItem) SimpleBottomSheetItem(net.osmand.plus.base.bottomsheetmenu.SimpleBottomSheetItem) Bundle(android.os.Bundle) View(android.view.View) Date(java.util.Date) BottomSheetItemWithDescription(net.osmand.plus.base.bottomsheetmenu.BottomSheetItemWithDescription) DividerItem(net.osmand.plus.base.bottomsheetmenu.simpleitems.DividerItem) SimpleDateFormat(java.text.SimpleDateFormat)

Aggregations

View (android.view.View)2 DividerItem (net.osmand.plus.base.bottomsheetmenu.simpleitems.DividerItem)2 Bundle (android.os.Bundle)1 CompoundButton (android.widget.CompoundButton)1 OnCheckedChangeListener (android.widget.CompoundButton.OnCheckedChangeListener)1 SimpleDateFormat (java.text.SimpleDateFormat)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 List (java.util.List)1 BaseBottomSheetItem (net.osmand.plus.base.bottomsheetmenu.BaseBottomSheetItem)1 BottomSheetItemWithCompoundButton (net.osmand.plus.base.bottomsheetmenu.BottomSheetItemWithCompoundButton)1 BottomSheetItemWithDescription (net.osmand.plus.base.bottomsheetmenu.BottomSheetItemWithDescription)1 SimpleBottomSheetItem (net.osmand.plus.base.bottomsheetmenu.SimpleBottomSheetItem)1 DescriptionItem (net.osmand.plus.base.bottomsheetmenu.simpleitems.DescriptionItem)1 TitleItem (net.osmand.plus.base.bottomsheetmenu.simpleitems.TitleItem)1