Search in sources :

Example 1 with Badgeable

use of com.mikepenz.materialdrawer.model.interfaces.Badgeable in project MaterialDrawer by mikepenz.

the class MultiDrawerActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    //supportRequestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_sample);
    // Handle Toolbar
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    getSupportActionBar().setTitle(R.string.drawer_item_multi_drawer);
    //first create the main drawer (this one will be used to add the second drawer on the other side)
    result = new DrawerBuilder().withActivity(this).withHeader(R.layout.header).withSavedInstance(savedInstanceState).addDrawerItems(new PrimaryDrawerItem().withName(R.string.drawer_item_home).withIcon(FontAwesome.Icon.faw_home).withBadge("99").withIdentifier(1), new PrimaryDrawerItem().withName(R.string.drawer_item_free_play).withIcon(FontAwesome.Icon.faw_gamepad), new PrimaryDrawerItem().withName(R.string.drawer_item_custom).withIcon(FontAwesome.Icon.faw_eye).withBadge("6").withIdentifier(2), new SectionDrawerItem().withName(R.string.drawer_item_section_header), new SecondaryDrawerItem().withName(R.string.drawer_item_settings).withIcon(FontAwesome.Icon.faw_cog), new SecondaryDrawerItem().withName(R.string.drawer_item_help).withIcon(FontAwesome.Icon.faw_question).withEnabled(false), new SecondaryDrawerItem().withName(R.string.drawer_item_open_source).withIcon(FontAwesome.Icon.faw_github).withBadge("12").withIdentifier(3), new SecondaryDrawerItem().withName(R.string.drawer_item_contact).withIcon(FontAwesome.Icon.faw_bullhorn)).withOnDrawerListener(new Drawer.OnDrawerListener() {

        @Override
        public void onDrawerOpened(View drawerView) {
            Toast.makeText(MultiDrawerActivity.this, "onDrawerOpened", Toast.LENGTH_SHORT).show();
        }

        @Override
        public void onDrawerClosed(View drawerView) {
            Toast.makeText(MultiDrawerActivity.this, "onDrawerClosed", Toast.LENGTH_SHORT).show();
        }

        @Override
        public void onDrawerSlide(View drawerView, float slideOffset) {
        }
    }).withOnDrawerItemClickListener(new Drawer.OnDrawerItemClickListener() {

        @Override
        public boolean onItemClick(View view, int position, IDrawerItem drawerItem) {
            if (drawerItem != null) {
                if (drawerItem instanceof Nameable) {
                    Toast.makeText(MultiDrawerActivity.this, ((Nameable) drawerItem).getName().getText(MultiDrawerActivity.this), Toast.LENGTH_SHORT).show();
                }
                if (drawerItem instanceof Badgeable) {
                    Badgeable badgeable = (Badgeable) drawerItem;
                    if (badgeable.getBadge() != null) {
                        //note don't do this if your badge contains a "+"
                        //only use toString() if you set the test as String
                        int badge = Integer.valueOf(badgeable.getBadge().toString());
                        if (badge > 0) {
                            badgeable.withBadge(String.valueOf(badge - 1));
                            result.updateItem(drawerItem);
                        }
                    }
                }
            }
            return false;
        }
    }).withOnDrawerItemLongClickListener(new Drawer.OnDrawerItemLongClickListener() {

        @Override
        public boolean onItemLongClick(View view, int position, IDrawerItem drawerItem) {
            if (drawerItem instanceof SecondaryDrawerItem) {
                Toast.makeText(MultiDrawerActivity.this, ((SecondaryDrawerItem) drawerItem).getName().getText(MultiDrawerActivity.this), Toast.LENGTH_SHORT).show();
            }
            return false;
        }
    }).withOnDrawerListener(new Drawer.OnDrawerListener() {

        @Override
        public void onDrawerOpened(View drawerView) {
            if (drawerView == result.getSlider()) {
                Log.e("sample", "left opened");
            } else if (drawerView == resultAppended.getSlider()) {
                Log.e("sample", "right opened");
            }
        }

        @Override
        public void onDrawerClosed(View drawerView) {
            if (drawerView == result.getSlider()) {
                Log.e("sample", "left closed");
            } else if (drawerView == resultAppended.getSlider()) {
                Log.e("sample", "right closed");
            }
        }

        @Override
        public void onDrawerSlide(View drawerView, float slideOffset) {
        }
    }).build();
    //now we add the second drawer on the other site.
    //use the .append method to add this drawer to the first one
    resultAppended = new DrawerBuilder().withActivity(this).withFooter(R.layout.footer).withDisplayBelowStatusBar(true).withSavedInstance(savedInstanceState).addDrawerItems(new PrimaryDrawerItem().withName(R.string.drawer_item_custom).withIcon(FontAwesome.Icon.faw_eye), new PrimaryDrawerItem().withName(R.string.drawer_item_home).withIcon(FontAwesome.Icon.faw_home), new PrimaryDrawerItem().withName(R.string.drawer_item_free_play).withIcon(FontAwesome.Icon.faw_gamepad), new SectionDrawerItem().withName(R.string.drawer_item_section_header), new SecondaryDrawerItem().withName(R.string.drawer_item_settings).withIcon(FontAwesome.Icon.faw_cog), new DividerDrawerItem(), new SecondaryDrawerItem().withName(R.string.drawer_item_open_source).withIcon(FontAwesome.Icon.faw_github), new SecondaryDrawerItem().withName(R.string.drawer_item_help).withIcon(FontAwesome.Icon.faw_question).withEnabled(false), new SectionDrawerItem().withName(R.string.drawer_item_section_header), new SecondaryDrawerItem().withName(R.string.drawer_item_contact).withIcon(FontAwesome.Icon.faw_bullhorn)).withOnDrawerItemClickListener(new Drawer.OnDrawerItemClickListener() {

        @Override
        public boolean onItemClick(View view, int position, IDrawerItem drawerItem) {
            if (drawerItem instanceof Nameable) {
                Toast.makeText(MultiDrawerActivity.this, ((Nameable) drawerItem).getName().getText(MultiDrawerActivity.this), Toast.LENGTH_SHORT).show();
            }
            return false;
        }
    }).withDrawerGravity(Gravity.END).append(result);
    //set the back arrow in the toolbar
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    getSupportActionBar().setHomeButtonEnabled(false);
}
Also used : PrimaryDrawerItem(com.mikepenz.materialdrawer.model.PrimaryDrawerItem) IDrawerItem(com.mikepenz.materialdrawer.model.interfaces.IDrawerItem) DividerDrawerItem(com.mikepenz.materialdrawer.model.DividerDrawerItem) Drawer(com.mikepenz.materialdrawer.Drawer) SecondaryDrawerItem(com.mikepenz.materialdrawer.model.SecondaryDrawerItem) View(android.view.View) Nameable(com.mikepenz.materialdrawer.model.interfaces.Nameable) SectionDrawerItem(com.mikepenz.materialdrawer.model.SectionDrawerItem) Badgeable(com.mikepenz.materialdrawer.model.interfaces.Badgeable) DrawerBuilder(com.mikepenz.materialdrawer.DrawerBuilder) Toolbar(android.support.v7.widget.Toolbar)

Example 2 with Badgeable

use of com.mikepenz.materialdrawer.model.interfaces.Badgeable in project MaterialDrawer by mikepenz.

the class Drawer method updateBadge.

/**
     * update the badge for a specific drawerItem
     * identified by its id
     *
     * @param identifier
     * @param badge
     */
public void updateBadge(long identifier, StringHolder badge) {
    IDrawerItem drawerItem = getDrawerItem(identifier);
    if (drawerItem instanceof Badgeable) {
        Badgeable badgeable = (Badgeable) drawerItem;
        badgeable.withBadge(badge);
        updateItem((IDrawerItem) badgeable);
    }
}
Also used : IDrawerItem(com.mikepenz.materialdrawer.model.interfaces.IDrawerItem) Badgeable(com.mikepenz.materialdrawer.model.interfaces.Badgeable)

Aggregations

Badgeable (com.mikepenz.materialdrawer.model.interfaces.Badgeable)2 IDrawerItem (com.mikepenz.materialdrawer.model.interfaces.IDrawerItem)2 Toolbar (android.support.v7.widget.Toolbar)1 View (android.view.View)1 Drawer (com.mikepenz.materialdrawer.Drawer)1 DrawerBuilder (com.mikepenz.materialdrawer.DrawerBuilder)1 DividerDrawerItem (com.mikepenz.materialdrawer.model.DividerDrawerItem)1 PrimaryDrawerItem (com.mikepenz.materialdrawer.model.PrimaryDrawerItem)1 SecondaryDrawerItem (com.mikepenz.materialdrawer.model.SecondaryDrawerItem)1 SectionDrawerItem (com.mikepenz.materialdrawer.model.SectionDrawerItem)1 Nameable (com.mikepenz.materialdrawer.model.interfaces.Nameable)1