Search in sources :

Example 21 with IDrawerItem

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

the class Drawer method updateIcon.

/**
     * update the name for a specific drawerItem
     * identified by its id
     *
     * @param identifier
     * @param image
     */
public void updateIcon(long identifier, ImageHolder image) {
    IDrawerItem drawerItem = getDrawerItem(identifier);
    if (drawerItem instanceof Iconable) {
        Iconable pdi = (Iconable) drawerItem;
        pdi.withIcon(image);
        updateItem((IDrawerItem) pdi);
    }
}
Also used : IDrawerItem(com.mikepenz.materialdrawer.model.interfaces.IDrawerItem) Iconable(com.mikepenz.materialdrawer.model.interfaces.Iconable)

Example 22 with IDrawerItem

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

the class DrawerBuilder method addMenuItems.

/**
     * helper method to init the drawerItems from a menu
     *
     * @param mMenu
     * @param subMenu
     */
private void addMenuItems(Menu mMenu, boolean subMenu) {
    int groupId = R.id.material_drawer_menu_default_group;
    for (int i = 0; i < mMenu.size(); i++) {
        MenuItem mMenuItem = mMenu.getItem(i);
        IDrawerItem iDrawerItem;
        if (!subMenu && mMenuItem.getGroupId() != groupId && mMenuItem.getGroupId() != 0) {
            groupId = mMenuItem.getGroupId();
            iDrawerItem = new DividerDrawerItem();
            getItemAdapter().add(iDrawerItem);
        }
        if (mMenuItem.hasSubMenu()) {
            iDrawerItem = new PrimaryDrawerItem().withName(mMenuItem.getTitle().toString()).withIcon(mMenuItem.getIcon()).withIdentifier(mMenuItem.getItemId()).withEnabled(mMenuItem.isEnabled()).withSelectable(false);
            getItemAdapter().add(iDrawerItem);
            addMenuItems(mMenuItem.getSubMenu(), true);
        } else if (mMenuItem.getGroupId() != 0 || subMenu) {
            iDrawerItem = new SecondaryDrawerItem().withName(mMenuItem.getTitle().toString()).withIcon(mMenuItem.getIcon()).withIdentifier(mMenuItem.getItemId()).withEnabled(mMenuItem.isEnabled());
            getItemAdapter().add(iDrawerItem);
        } else {
            iDrawerItem = new PrimaryDrawerItem().withName(mMenuItem.getTitle().toString()).withIcon(mMenuItem.getIcon()).withIdentifier(mMenuItem.getItemId()).withEnabled(mMenuItem.isEnabled());
            getItemAdapter().add(iDrawerItem);
        }
    }
}
Also used : IDrawerItem(com.mikepenz.materialdrawer.model.interfaces.IDrawerItem) PrimaryDrawerItem(com.mikepenz.materialdrawer.model.PrimaryDrawerItem) DividerDrawerItem(com.mikepenz.materialdrawer.model.DividerDrawerItem) MenuItem(android.view.MenuItem) SecondaryDrawerItem(com.mikepenz.materialdrawer.model.SecondaryDrawerItem)

Example 23 with IDrawerItem

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

the class ActionBarActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    //supportRequestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_sample_actionbar);
    setTitle(R.string.drawer_item_action_bar_drawer);
    // Handle Toolbar
    result = new DrawerBuilder().withActivity(this).withSavedInstance(savedInstanceState).withDisplayBelowStatusBar(false).withTranslucentStatusBar(false).withDrawerLayout(R.layout.material_drawer_fits_not).addDrawerItems(new PrimaryDrawerItem().withName(R.string.drawer_item_home).withIcon(FontAwesome.Icon.faw_home), new SecondaryDrawerItem().withName(R.string.drawer_item_settings).withIcon(FontAwesome.Icon.faw_cog)).withOnDrawerItemClickListener(new Drawer.OnDrawerItemClickListener() {

        @Override
        public boolean onItemClick(View view, int position, IDrawerItem drawerItem) {
            if (drawerItem instanceof Nameable) {
                Toast.makeText(ActionBarActivity.this, ((Nameable) drawerItem).getName().getText(ActionBarActivity.this), Toast.LENGTH_SHORT).show();
            }
            return false;
        }
    }).build();
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    getSupportActionBar().setHomeButtonEnabled(false);
}
Also used : Nameable(com.mikepenz.materialdrawer.model.interfaces.Nameable) PrimaryDrawerItem(com.mikepenz.materialdrawer.model.PrimaryDrawerItem) IDrawerItem(com.mikepenz.materialdrawer.model.interfaces.IDrawerItem) DrawerBuilder(com.mikepenz.materialdrawer.DrawerBuilder) Drawer(com.mikepenz.materialdrawer.Drawer) SecondaryDrawerItem(com.mikepenz.materialdrawer.model.SecondaryDrawerItem) View(android.view.View)

Example 24 with IDrawerItem

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

the class DrawerUtils method setStickyFooterSelection.

/**
     * helper method to set the selection of the footer
     *
     * @param drawer
     * @param position
     * @param fireOnClick
     */
public static void setStickyFooterSelection(DrawerBuilder drawer, int position, Boolean fireOnClick) {
    if (position > -1) {
        if (drawer.mStickyFooterView != null && drawer.mStickyFooterView instanceof LinearLayout) {
            LinearLayout footer = (LinearLayout) drawer.mStickyFooterView;
            if (footer.getChildCount() > position && position >= 0) {
                IDrawerItem drawerItem = (IDrawerItem) footer.getChildAt(position).getTag();
                onFooterDrawerItemClick(drawer, drawerItem, footer.getChildAt(position), fireOnClick);
            }
        }
    }
}
Also used : IDrawerItem(com.mikepenz.materialdrawer.model.interfaces.IDrawerItem) LinearLayout(android.widget.LinearLayout)

Example 25 with IDrawerItem

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

the class DrawerUtils method fillStickyDrawerItemFooter.

/**
     * helper method to fill the sticky footer with it's elements
     *
     * @param drawer
     * @param container
     * @param onClickListener
     */
public static void fillStickyDrawerItemFooter(DrawerBuilder drawer, ViewGroup container, View.OnClickListener onClickListener) {
    //add all drawer items
    for (IDrawerItem drawerItem : drawer.mStickyDrawerItems) {
        View view = drawerItem.generateView(container.getContext(), container);
        view.setTag(drawerItem);
        if (drawerItem.isEnabled()) {
            //UIUtils.setBackground(view, UIUtils.getSelectableBackground(container.getContext(), selected_color, drawerItem.isSelectedBackgroundAnimated()));
            view.setOnClickListener(onClickListener);
        }
        container.addView(view);
        //for android API 17 --> Padding not applied via xml
        DrawerUIUtils.setDrawerVerticalPadding(view);
    }
    //and really. don't ask about this. it won't set the padding if i don't set the padding for the container
    container.setPadding(0, 0, 0, 0);
}
Also used : IDrawerItem(com.mikepenz.materialdrawer.model.interfaces.IDrawerItem) View(android.view.View)

Aggregations

IDrawerItem (com.mikepenz.materialdrawer.model.interfaces.IDrawerItem)29 View (android.view.View)20 DrawerBuilder (com.mikepenz.materialdrawer.DrawerBuilder)16 PrimaryDrawerItem (com.mikepenz.materialdrawer.model.PrimaryDrawerItem)14 Toolbar (android.support.v7.widget.Toolbar)13 Drawer (com.mikepenz.materialdrawer.Drawer)12 SecondaryDrawerItem (com.mikepenz.materialdrawer.model.SecondaryDrawerItem)12 Nameable (com.mikepenz.materialdrawer.model.interfaces.Nameable)10 IProfile (com.mikepenz.materialdrawer.model.interfaces.IProfile)9 DividerDrawerItem (com.mikepenz.materialdrawer.model.DividerDrawerItem)8 AccountHeaderBuilder (com.mikepenz.materialdrawer.AccountHeaderBuilder)7 SectionDrawerItem (com.mikepenz.materialdrawer.model.SectionDrawerItem)7 ProfileDrawerItem (com.mikepenz.materialdrawer.model.ProfileDrawerItem)6 Intent (android.content.Intent)5 BadgeStyle (com.mikepenz.materialdrawer.holder.BadgeStyle)5 RecyclerView (android.support.v7.widget.RecyclerView)4 LinearLayout (android.widget.LinearLayout)4 LibsBuilder (com.mikepenz.aboutlibraries.LibsBuilder)4 IconicsDrawable (com.mikepenz.iconics.IconicsDrawable)4 ProfileSettingDrawerItem (com.mikepenz.materialdrawer.model.ProfileSettingDrawerItem)4