Search in sources :

Example 1 with MaterialSectionChangeListener

use of de.madcyph3r.materialnavigationdrawer.listener.MaterialSectionChangeListener in project AdvancedMaterialDrawer by madcyph3r.

the class ActionBarOwnFontActivity method init.

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

        @Override
        public void onBeforeChangeSection(MaterialItemSection newSection) {
        }

        @Override
        public void onAfterChangeSection(MaterialItemSection newSection) {
            setActionBarTitle(getCurrentSectionFragment().getTitle());
        }
    });
    // information text for the fragment
    Bundle bundle = new Bundle();
    bundle.putString("instruction", "See the actionbar, it has a custom title with a custom font.");
    Fragment fragmentInstruction = new FragmentInstruction();
    fragmentInstruction.setArguments(bundle);
    // create menu
    MaterialMenu menu = new MaterialMenu();
    menu.add(new MaterialItemSectionFragment(this, "Instruction", fragmentInstruction, "Actionbar Own Front"));
    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)

Example 2 with MaterialSectionChangeListener

use of de.madcyph3r.materialnavigationdrawer.listener.MaterialSectionChangeListener in project AdvancedMaterialDrawer by madcyph3r.

the class MaterialItemSection method onClick.

@Override
public void onClick(View v) {
    if (sectionListener != null) {
        final MaterialItemSection section = this;
        MaterialSectionChangeListener sectionChangeListener = drawer.getSectionChangeListener();
        if (sectionChangeListener != null)
            sectionChangeListener.onBeforeChangeSection(this);
        sectionListener.onClick(section, v);
        if (sectionChangeListener != null)
            sectionChangeListener.onAfterChangeSection(this);
    }
}
Also used : MaterialSectionChangeListener(de.madcyph3r.materialnavigationdrawer.listener.MaterialSectionChangeListener)

Example 3 with MaterialSectionChangeListener

use of de.madcyph3r.materialnavigationdrawer.listener.MaterialSectionChangeListener 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

MaterialSectionChangeListener (de.madcyph3r.materialnavigationdrawer.listener.MaterialSectionChangeListener)3 Bundle (android.os.Bundle)2 Fragment (android.support.v4.app.Fragment)2 FragmentDummy (de.madcyph3r.example.example.FragmentDummy)2 FragmentInstruction (de.madcyph3r.example.example.FragmentInstruction)2 MaterialMenu (de.madcyph3r.materialnavigationdrawer.menu.MaterialMenu)2 MaterialItemSection (de.madcyph3r.materialnavigationdrawer.menu.item.section.MaterialItemSection)2 MaterialItemSectionFragment (de.madcyph3r.materialnavigationdrawer.menu.item.section.MaterialItemSectionFragment)2