Search in sources :

Example 16 with MaterialSection

use of it.neokree.materialnavigationdrawer.elements.MaterialSection in project MaterialNavigationDrawer by neokree.

the class MaterialNavigationDrawer method onBackPressed.

@Override
public void onBackPressed() {
    if (!isCurrentFragmentChild) {
        switch(backPattern) {
            default:
            case BACKPATTERN_BACK_ANYWHERE:
                super.onBackPressed();
                break;
            case BACKPATTERN_BACK_TO_FIRST:
                MaterialSection section = sectionList.get(0);
                if (currentSection == section)
                    super.onBackPressed();
                else {
                    section.select();
                    //onClick(section);
                    changeToolbarColor(section);
                    setFragment((Fragment) section.getTargetFragment(), section.getTitle(), (Fragment) currentSection.getTargetFragment());
                    afterFragmentSetted((Fragment) section.getTargetFragment(), section.getTitle());
                    syncSectionsState(section);
                }
                break;
            case BACKPATTERN_CUSTOM:
                MaterialSection backedSection = backToSection(getCurrentSection());
                if (currentSection == backedSection)
                    super.onBackPressed();
                else {
                    if (backedSection.getTarget() != MaterialSection.TARGET_FRAGMENT) {
                        throw new RuntimeException("The restored section must have a fragment as target");
                    }
                    backedSection.select();
                    changeToolbarColor(backedSection);
                    setFragment((Fragment) backedSection.getTargetFragment(), backedSection.getTitle(), (Fragment) currentSection.getTargetFragment());
                    afterFragmentSetted((Fragment) backedSection.getTargetFragment(), backedSection.getTitle());
                    syncSectionsState(backedSection);
                }
                break;
        }
    } else {
        if (childFragmentStack.size() <= 1) {
            isCurrentFragmentChild = false;
            onBackPressed();
        } else {
            // reload the child before
            Fragment newFragment = childFragmentStack.get(childFragmentStack.size() - 2);
            String newTitle = childTitleStack.get(childTitleStack.size() - 2);
            // get and remove the last child
            Fragment currentFragment = childFragmentStack.remove(childFragmentStack.size() - 1);
            childTitleStack.remove(childTitleStack.size() - 1);
            setFragment(newFragment, newTitle, currentFragment);
            if (childFragmentStack.size() == 1) {
                // user comed back to master section
                isCurrentFragmentChild = false;
                if (!deviceSupportMultiPane())
                    pulsante.setDrawerIndicatorEnabled(true);
                else
                    actionBar.setDisplayHomeAsUpEnabled(false);
            }
        }
    }
}
Also used : MaterialSection(it.neokree.materialnavigationdrawer.elements.MaterialSection)

Example 17 with MaterialSection

use of it.neokree.materialnavigationdrawer.elements.MaterialSection in project MaterialNavigationDrawer by neokree.

the class MaterialNavigationDrawer method newSectionWithRealColor.

public MaterialSection newSectionWithRealColor(String title, Bitmap icon, Fragment target) {
    MaterialSection section = new MaterialSection<Fragment>(this, MaterialSection.ICON_24DP, rippleSupport, MaterialSection.TARGET_FRAGMENT);
    section.setOnClickListener(this);
    section.useRealColor();
    section.setIcon(icon);
    section.setTitle(title);
    section.setTarget(target);
    return section;
}
Also used : MaterialSection(it.neokree.materialnavigationdrawer.elements.MaterialSection)

Example 18 with MaterialSection

use of it.neokree.materialnavigationdrawer.elements.MaterialSection in project MaterialNavigationDrawer by neokree.

the class MaterialNavigationDrawer method newSectionWithRealColor.

public MaterialSection newSectionWithRealColor(String title, Bitmap icon, Intent target) {
    MaterialSection section = new MaterialSection<Fragment>(this, MaterialSection.ICON_24DP, rippleSupport, MaterialSection.TARGET_ACTIVITY);
    section.setOnClickListener(this);
    section.useRealColor();
    section.setIcon(icon);
    section.setTitle(title);
    section.setTarget(target);
    return section;
}
Also used : MaterialSection(it.neokree.materialnavigationdrawer.elements.MaterialSection)

Aggregations

MaterialSection (it.neokree.materialnavigationdrawer.elements.MaterialSection)18 MaterialAccount (it.neokree.materialnavigationdrawer.elements.MaterialAccount)2 SuppressLint (android.annotation.SuppressLint)1 Intent (android.content.Intent)1 Resources (android.content.res.Resources)1 TypedArray (android.content.res.TypedArray)1 Point (android.graphics.Point)1 ColorDrawable (android.graphics.drawable.ColorDrawable)1 DrawerLayout (android.support.v4.widget.DrawerLayout)1 TypedValue (android.util.TypedValue)1 View (android.view.View)1 ViewTreeObserver (android.view.ViewTreeObserver)1 Window (android.view.Window)1 ImageView (android.widget.ImageView)1 LinearLayout (android.widget.LinearLayout)1 RelativeLayout (android.widget.RelativeLayout)1 TextView (android.widget.TextView)1 FragmentButton (it.neokree.example.mockedFragments.FragmentButton)1 FragmentIndex (it.neokree.example.mockedFragments.FragmentIndex)1 MaterialSectionListener (it.neokree.materialnavigationdrawer.elements.listeners.MaterialSectionListener)1