Search in sources :

Example 6 with MaterialItemSection

use of de.madcyph3r.materialnavigationdrawer.menu.item.section.MaterialItemSection in project AdvancedMaterialDrawer by madcyph3r.

the class AddRemoveHeadItemRuntimeActivity method getHeadItem1.

private MaterialHeadItem getHeadItem1() {
    // information text for the fragment
    Bundle bundle = new Bundle();
    bundle.putString("instruction", "Here you can add new head-items and/or remove existing head-items. " + "Open the menu and choose the action you want.");
    Fragment fragmentInstruction = new FragmentInstruction();
    fragmentInstruction.setArguments(bundle);
    // create sections
    MaterialItemSectionFragment instruction = new MaterialItemSectionFragment(this, "Instruction", fragmentInstruction, "Add Remove HeadItem At Runtime");
    MaterialItemSectionOnClick addSection = new MaterialItemSectionOnClick(this, "Add Head Item");
    MaterialItemSectionOnClick removeSection = new MaterialItemSectionOnClick(this, "Remove Last Head Item");
    // add OnClickListener to MaterialItemSectionOnClick sections
    addSection.setOnSectionClickListener(new MaterialSectionOnClickListener() {

        @Override
        public void onClick(MaterialItemSection section, View view) {
            // add headItem, true is needed for view change
            drawer.addHeadItem(getHeadItem3(), true);
        }
    });
    removeSection.setOnSectionClickListener(new MaterialSectionOnClickListener() {

        @Override
        public void onClick(MaterialItemSection section, View view) {
            if (drawer.getHeadItemManager().size() > 1)
                drawer.removeHeadItem(drawer.getHeadItemManager().size() - 1);
            else
                Toast.makeText(drawer, "You can't remove all head-items.", Toast.LENGTH_SHORT).show();
        }
    });
    // create menu
    MaterialMenu menu = new MaterialMenu();
    menu.add(instruction);
    menu.add(addSection);
    menu.add(removeSection);
    // create headItem
    final Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.head_item_icon);
    final RoundedCornersDrawable drawableAppIcon = new RoundedCornersDrawable(getResources(), bitmap);
    MaterialHeadItem headItem = new MaterialHeadItem(this, "A HeadItem", "A Subtitle", drawableAppIcon, R.drawable.mat1, menu);
    return headItem;
}
Also used : Bundle(android.os.Bundle) MaterialItemSectionOnClick(de.madcyph3r.materialnavigationdrawer.menu.item.section.MaterialItemSectionOnClick) MaterialMenu(de.madcyph3r.materialnavigationdrawer.menu.MaterialMenu) FragmentInstruction(de.madcyph3r.example.example.FragmentInstruction) Fragment(android.support.v4.app.Fragment) MaterialItemSectionFragment(de.madcyph3r.materialnavigationdrawer.menu.item.section.MaterialItemSectionFragment) View(android.view.View) MaterialSectionOnClickListener(de.madcyph3r.materialnavigationdrawer.listener.MaterialSectionOnClickListener) Bitmap(android.graphics.Bitmap) MaterialItemSectionFragment(de.madcyph3r.materialnavigationdrawer.menu.item.section.MaterialItemSectionFragment) RoundedCornersDrawable(de.madcyph3r.materialnavigationdrawer.tools.RoundedCornersDrawable) MaterialHeadItem(de.madcyph3r.materialnavigationdrawer.head.MaterialHeadItem) MaterialItemSection(de.madcyph3r.materialnavigationdrawer.menu.item.section.MaterialItemSection)

Example 7 with MaterialItemSection

use of de.madcyph3r.materialnavigationdrawer.menu.item.section.MaterialItemSection in project AdvancedMaterialDrawer by madcyph3r.

the class MaterialNavigationDrawer method loadMenu.

// protected abstract MaterialMenu loadMenuType();
protected void loadMenu(MaterialMenu menu, boolean forceReload) {
    if (menu != null && (menu != currentMenu || forceReload)) {
        // set the new current menu
        currentMenu = menu;
        itemSections.removeAllViews();
        itemBottomSections.removeAllViews();
        // create Menu
        List<MaterialMenuItem> itemList = menu.getItems();
        for (int i = 0; i < itemList.size(); i++) {
            if (itemList.get(i) instanceof MaterialItemSection) {
                MaterialItemSection section = (MaterialItemSection) itemList.get(i);
                if (section.isBottom())
                    addBottomSection((MaterialItemSection) itemList.get(i));
                else
                    addSection((MaterialItemSection) itemList.get(i));
            } else if (itemList.get(i) instanceof MaterialItemCustom) {
                MaterialItemCustom custom = (MaterialItemCustom) itemList.get(i);
                if (custom.isBottom())
                    addBottomCustom((MaterialItemCustom) itemList.get(i));
                else
                    addCustom((MaterialItemCustom) itemList.get(i));
            } else if (itemList.get(i) instanceof MaterialItemDevisor) {
                MaterialItemDevisor devisor = (MaterialItemDevisor) itemList.get(i);
                if (devisor.isBottom())
                    addDevisorBottom();
                else
                    addDevisor();
            } else if (itemList.get(i) instanceof MaterialItemLabel) {
                MaterialItemLabel label = (MaterialItemLabel) itemList.get(i);
                if (label.isBottom())
                    addBottomLabel((MaterialItemLabel) itemList.get(i));
                else
                    addLabel((MaterialItemLabel) itemList.get(i));
            }
        }
        // unselect all items
        for (int i = 0; i < itemList.size(); i++) {
            try {
                ((MaterialItemSection) itemList.get(i)).unSelect();
            } catch (ClassCastException e) {
            // nothing to do here
            }
        }
    }
}
Also used : MaterialMenuItem(de.madcyph3r.materialnavigationdrawer.menu.item.MaterialMenuItem) MaterialItemDevisor(de.madcyph3r.materialnavigationdrawer.menu.item.style.MaterialItemDevisor) MaterialItemCustom(de.madcyph3r.materialnavigationdrawer.menu.item.custom.MaterialItemCustom) MaterialItemLabel(de.madcyph3r.materialnavigationdrawer.menu.item.style.MaterialItemLabel) SuppressLint(android.annotation.SuppressLint) MaterialItemSection(de.madcyph3r.materialnavigationdrawer.menu.item.section.MaterialItemSection)

Example 8 with MaterialItemSection

use of de.madcyph3r.materialnavigationdrawer.menu.item.section.MaterialItemSection in project AdvancedMaterialDrawer by madcyph3r.

the class MaterialNavigationDrawer method onBackPressed.

@Override
public void onBackPressed() {
    switch(backPattern) {
        default:
        case BACKPATTERN_BACK_ANYWHERE:
            super.onBackPressed();
            break;
        case BACKPATTERN_BACK_TO_START_INDEX:
            if (currentMenu.getStartIndex() > -1) {
                MaterialMenuItem menuItem = currentMenu.getItems().get(currentMenu.getStartIndex());
                if (menuItem instanceof MaterialItemSectionFragment) {
                    MaterialItemSectionFragment section = (MaterialItemSectionFragment) menuItem;
                    if (currentSectionFragment == section)
                        super.onBackPressed();
                    else {
                        //section.select();
                        onClick(section, section.getView());
                    }
                } else {
                    throw new RuntimeException("The index doesn't point on a MaterialFragmentSection.");
                }
            } else {
                throw new RuntimeException("There is no start index for this menu.");
            }
            break;
        case BACKPATTERN_CUSTOM:
            MaterialItemSection backedSection = backToSection(getCurrentSectionFragment());
            if (currentSectionFragment == backedSection)
                super.onBackPressed();
            else {
                if (!(backedSection instanceof MaterialItemSectionFragment)) {
                    throw new RuntimeException("The restored section must be a MaterialFragmentSection");
                }
                onClick(backedSection, backedSection.getView());
            }
            break;
        case BACKPATTERN_LAST_SECTION_FRAGMENT:
            int lastPos = sectionFragmentLastBackPatternList.size() - 1;
            // do not load the current fragment again
            if (sectionFragmentLastBackPatternList.size() > 0 && currentSectionFragment == sectionFragmentLastBackPatternList.get(lastPos)) {
                sectionFragmentLastBackPatternList.remove(lastPos);
                lastPos = sectionFragmentLastBackPatternList.size() - 1;
            }
            if (sectionFragmentLastBackPatternList.size() == 0) {
                super.onBackPressed();
            } else {
                MaterialItemSectionFragment sectionFragment = sectionFragmentLastBackPatternList.get(lastPos);
                onClick(sectionFragment, sectionFragment.getView());
                sectionFragmentLastBackPatternList.remove(lastPos);
            }
            break;
    }
}
Also used : MaterialMenuItem(de.madcyph3r.materialnavigationdrawer.menu.item.MaterialMenuItem) MaterialItemSectionFragment(de.madcyph3r.materialnavigationdrawer.menu.item.section.MaterialItemSectionFragment) MaterialItemSection(de.madcyph3r.materialnavigationdrawer.menu.item.section.MaterialItemSection) SuppressLint(android.annotation.SuppressLint)

Example 9 with MaterialItemSection

use of de.madcyph3r.materialnavigationdrawer.menu.item.section.MaterialItemSection in project AdvancedMaterialDrawer by madcyph3r.

the class HeadItemTwoExtraMenuActivity method init.

@Override
public void init(Bundle savedInstanceState) {
    drawer = this;
    // add head Item (menu will be loaded automatically)
    this.addHeadItem(getHeadItem1());
    this.addHeadItem(getHeadItem2());
    // load menu
    this.loadMenu(getCurrentHeadItem().getMenu());
    // load the MaterialItemSectionFragment, from the given startIndex
    this.loadStartFragmentFromMenu(getCurrentHeadItem().getMenu());
    // create switcher extra menu
    MaterialItemSectionOnClick section = new MaterialItemSectionOnClick(this, "do something");
    section.setOnSectionClickListener(new MaterialSectionOnClickListener() {

        @Override
        public void onClick(MaterialItemSection section, View view) {
            Toast.makeText(drawer, " do something here", Toast.LENGTH_LONG).show();
        }
    });
    MaterialMenu menu = new MaterialMenu();
    menu.add(section);
    // add menu to switcher
    this.setSwitcherExtraMenu(menu, false);
    // show switch button, even if only one head item
    this.setSwitchShowForce(true);
}
Also used : MaterialSectionOnClickListener(de.madcyph3r.materialnavigationdrawer.listener.MaterialSectionOnClickListener) MaterialItemSectionOnClick(de.madcyph3r.materialnavigationdrawer.menu.item.section.MaterialItemSectionOnClick) MaterialMenu(de.madcyph3r.materialnavigationdrawer.menu.MaterialMenu) View(android.view.View) MaterialItemSection(de.madcyph3r.materialnavigationdrawer.menu.item.section.MaterialItemSection)

Example 10 with MaterialItemSection

use of de.madcyph3r.materialnavigationdrawer.menu.item.section.MaterialItemSection in project AdvancedMaterialDrawer by madcyph3r.

the class SectionChangeListenerActivity method init.

@Override
public void init(Bundle savedInstanceState) {
    drawer = this;
    drawer.setSectionChangeListener(new MaterialSectionChangeListener() {

        @Override
        public void onBeforeChangeSection(MaterialItemSection newSection) {
            // save the current menu, before change. needed for onAfterChangeSection
            tmpSection = getCurrentSectionFragment();
            if (getCurrentSectionFragment() != newSection) {
                Toast.makeText(drawer, "before change section", Toast.LENGTH_SHORT).show();
            }
        }

        @Override
        public void onAfterChangeSection(MaterialItemSection newSection) {
            // check, if the section really changed
            if (getCurrentSectionFragment() == newSection && newSection != tmpSection) {
                Toast.makeText(drawer, "after change section", Toast.LENGTH_SHORT).show();
            }
        }
    });
    // information text for the fragment
    Bundle bundle = new Bundle();
    bundle.putString("instruction", "Open the drawer and choose a section. You will get " + "a before and after change toast message.");
    Fragment fragmentInstruction = new FragmentInstruction();
    fragmentInstruction.setArguments(bundle);
    // create menu
    MaterialMenu menu = new MaterialMenu();
    menu.add(new MaterialItemSectionFragment(this, "Instruction", fragmentInstruction, "Section Change Listener"));
    menu.add(new MaterialItemSectionFragment(this, "Section 1", new FragmentDummy(), "Section 1"));
    menu.add(new MaterialItemSectionFragment(this, "Section 2", new FragmentDummy(), "Section 2"));
    menu.add(new MaterialItemSectionFragment(this, "Section 3", new FragmentDummy(), "Section 3"));
    // load menu
    this.loadMenu(menu);
    // load the MaterialItemSectionFragment, from the given startIndex
    this.loadStartFragmentFromMenu(menu);
}
Also used : MaterialSectionChangeListener(de.madcyph3r.materialnavigationdrawer.listener.MaterialSectionChangeListener) MaterialItemSectionFragment(de.madcyph3r.materialnavigationdrawer.menu.item.section.MaterialItemSectionFragment) Bundle(android.os.Bundle) MaterialMenu(de.madcyph3r.materialnavigationdrawer.menu.MaterialMenu) FragmentDummy(de.madcyph3r.example.example.FragmentDummy) FragmentInstruction(de.madcyph3r.example.example.FragmentInstruction) Fragment(android.support.v4.app.Fragment) MaterialItemSectionFragment(de.madcyph3r.materialnavigationdrawer.menu.item.section.MaterialItemSectionFragment) MaterialItemSection(de.madcyph3r.materialnavigationdrawer.menu.item.section.MaterialItemSection)

Aggregations

MaterialItemSection (de.madcyph3r.materialnavigationdrawer.menu.item.section.MaterialItemSection)10 MaterialMenu (de.madcyph3r.materialnavigationdrawer.menu.MaterialMenu)7 MaterialItemSectionFragment (de.madcyph3r.materialnavigationdrawer.menu.item.section.MaterialItemSectionFragment)6 Bundle (android.os.Bundle)5 Fragment (android.support.v4.app.Fragment)5 View (android.view.View)5 FragmentInstruction (de.madcyph3r.example.example.FragmentInstruction)5 MaterialSectionOnClickListener (de.madcyph3r.materialnavigationdrawer.listener.MaterialSectionOnClickListener)5 MaterialItemSectionOnClick (de.madcyph3r.materialnavigationdrawer.menu.item.section.MaterialItemSectionOnClick)5 FragmentDummy (de.madcyph3r.example.example.FragmentDummy)4 MaterialItemDevisor (de.madcyph3r.materialnavigationdrawer.menu.item.style.MaterialItemDevisor)3 SuppressLint (android.annotation.SuppressLint)2 MaterialSectionChangeListener (de.madcyph3r.materialnavigationdrawer.listener.MaterialSectionChangeListener)2 MaterialMenuItem (de.madcyph3r.materialnavigationdrawer.menu.item.MaterialMenuItem)2 MaterialItemCustom (de.madcyph3r.materialnavigationdrawer.menu.item.custom.MaterialItemCustom)2 MaterialItemLabel (de.madcyph3r.materialnavigationdrawer.menu.item.style.MaterialItemLabel)2 Intent (android.content.Intent)1 Bitmap (android.graphics.Bitmap)1 ImageView (android.widget.ImageView)1 MaterialHeadItem (de.madcyph3r.materialnavigationdrawer.head.MaterialHeadItem)1