Search in sources :

Example 1 with MaterialItemCustom

use of de.madcyph3r.materialnavigationdrawer.menu.item.custom.MaterialItemCustom in project AdvancedMaterialDrawer by madcyph3r.

the class AllMenuTypesActivity method init.

@Override
public void init(Bundle savedInstanceState) {
    drawer = this;
    // information text for the fragment
    Bundle bundle = new Bundle();
    bundle.putString("instruction", "This example shows all menu items. " + "Open the drawer and see ;).");
    Fragment fragmentInstruction = new FragmentInstruction();
    fragmentInstruction.setArguments(bundle);
    // create menu
    MaterialMenu menu = new MaterialMenu();
    menu.add(new MaterialItemSectionFragment(this, "Instruction", fragmentInstruction, "All Menu Types"));
    menu.add(new MaterialItemDevisor());
    menu.add(new MaterialItemCustom(this, R.layout.custom_section));
    menu.add(new MaterialItemLabel(this, "Label"));
    menu.add(new MaterialItemSectionFragment(this, "Fragment Section", new FragmentDummy(), "Fragment Section"));
    MaterialItemSectionFragment secNoti = new MaterialItemSectionFragment(this, "Fragment Section Notification", new FragmentDummy(), "Fragment Section Notification");
    secNoti.setNotifications(20);
    menu.add(secNoti);
    menu.add(new MaterialItemSectionFragment(this, "Fragment Section Icon", this.getResources().getDrawable(R.drawable.ic_favorite_black_36dp), new FragmentDummy(), "Fragment Section Icon"));
    MaterialItemSectionFragment iconBanner = new MaterialItemSectionFragment(this, this.getResources().getDrawable(R.drawable.ic_favorite_black_36dp), true, new FragmentDummy(), "Fragment Section Icon Banner");
    //iconBanner.getIconView().setScaleType(ImageView.ScaleType.CENTER);  edit the iconView to your needs
    menu.add(iconBanner);
    menu.add(new MaterialItemSectionFragment(this, "Fragment Section Color Red", this.getResources().getDrawable(R.drawable.ic_favorite_black_36dp), new FragmentDummy(), "Fragment Section Color Red").setSectionColor(Color.parseColor("#ff0858")));
    menu.add(new MaterialItemDevisor());
    menu.add(new MaterialItemSectionActivity(this, "Activity Section", new Intent(this, DummyActivity.class)));
    MaterialItemSectionOnClick onClickSection = new MaterialItemSectionOnClick(this, "OnClick Section");
    onClickSection.setOnSectionClickListener(new MaterialSectionOnClickListener() {

        @Override
        public void onClick(MaterialItemSection section, View v) {
            Toast.makeText(drawer, "OnClickSection", Toast.LENGTH_SHORT).show();
        }
    });
    menu.add(onClickSection);
    MaterialItemSectionFragment bottom = new MaterialItemSectionFragment(this, "Fragment Bottom Section", new FragmentDummy(), "Fragment Bottom Section");
    bottom.setBottom(true);
    menu.add(bottom);
    // load menu
    this.loadMenu(menu);
    // load the MaterialItemSectionFragment, from the given startIndex
    this.loadStartFragmentFromMenu(menu);
}
Also used : MaterialItemSectionActivity(de.madcyph3r.materialnavigationdrawer.menu.item.section.MaterialItemSectionActivity) Bundle(android.os.Bundle) MaterialItemSectionOnClick(de.madcyph3r.materialnavigationdrawer.menu.item.section.MaterialItemSectionOnClick) MaterialMenu(de.madcyph3r.materialnavigationdrawer.menu.MaterialMenu) MaterialItemCustom(de.madcyph3r.materialnavigationdrawer.menu.item.custom.MaterialItemCustom) FragmentDummy(de.madcyph3r.example.example.FragmentDummy) Intent(android.content.Intent) FragmentInstruction(de.madcyph3r.example.example.FragmentInstruction) Fragment(android.support.v4.app.Fragment) MaterialItemSectionFragment(de.madcyph3r.materialnavigationdrawer.menu.item.section.MaterialItemSectionFragment) ImageView(android.widget.ImageView) View(android.view.View) MaterialSectionOnClickListener(de.madcyph3r.materialnavigationdrawer.listener.MaterialSectionOnClickListener) MaterialItemSectionFragment(de.madcyph3r.materialnavigationdrawer.menu.item.section.MaterialItemSectionFragment) MaterialItemDevisor(de.madcyph3r.materialnavigationdrawer.menu.item.style.MaterialItemDevisor) MaterialItemLabel(de.madcyph3r.materialnavigationdrawer.menu.item.style.MaterialItemLabel) MaterialItemSection(de.madcyph3r.materialnavigationdrawer.menu.item.section.MaterialItemSection)

Example 2 with MaterialItemCustom

use of de.madcyph3r.materialnavigationdrawer.menu.item.custom.MaterialItemCustom 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)

Aggregations

MaterialItemCustom (de.madcyph3r.materialnavigationdrawer.menu.item.custom.MaterialItemCustom)2 MaterialItemSection (de.madcyph3r.materialnavigationdrawer.menu.item.section.MaterialItemSection)2 MaterialItemDevisor (de.madcyph3r.materialnavigationdrawer.menu.item.style.MaterialItemDevisor)2 MaterialItemLabel (de.madcyph3r.materialnavigationdrawer.menu.item.style.MaterialItemLabel)2 SuppressLint (android.annotation.SuppressLint)1 Intent (android.content.Intent)1 Bundle (android.os.Bundle)1 Fragment (android.support.v4.app.Fragment)1 View (android.view.View)1 ImageView (android.widget.ImageView)1 FragmentDummy (de.madcyph3r.example.example.FragmentDummy)1 FragmentInstruction (de.madcyph3r.example.example.FragmentInstruction)1 MaterialSectionOnClickListener (de.madcyph3r.materialnavigationdrawer.listener.MaterialSectionOnClickListener)1 MaterialMenu (de.madcyph3r.materialnavigationdrawer.menu.MaterialMenu)1 MaterialMenuItem (de.madcyph3r.materialnavigationdrawer.menu.item.MaterialMenuItem)1 MaterialItemSectionActivity (de.madcyph3r.materialnavigationdrawer.menu.item.section.MaterialItemSectionActivity)1 MaterialItemSectionFragment (de.madcyph3r.materialnavigationdrawer.menu.item.section.MaterialItemSectionFragment)1 MaterialItemSectionOnClick (de.madcyph3r.materialnavigationdrawer.menu.item.section.MaterialItemSectionOnClick)1