Search in sources :

Example 6 with IDrawerItem

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

the class NonTranslucentDrawerActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    //supportRequestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_sample_nontranslucent);
    // Handle Toolbar
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    getSupportActionBar().setTitle(R.string.drawer_item_non_translucent_status_drawer);
    // Create a few sample profile
    result = new DrawerBuilder().withActivity(this).withTranslucentStatusBar(false).addDrawerItems(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 PrimaryDrawerItem().withName(R.string.drawer_item_custom).withIcon(FontAwesome.Icon.faw_eye), 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), 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(NonTranslucentDrawerActivity.this, ((Nameable) drawerItem).getName().getText(NonTranslucentDrawerActivity.this), Toast.LENGTH_SHORT).show();
            }
            return false;
        }
    }).withSelectedItemByPosition(2).withSavedInstance(savedInstanceState).build();
    //set the back arrow in the toolbar
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    getSupportActionBar().setHomeButtonEnabled(false);
}
Also used : Nameable(com.mikepenz.materialdrawer.model.interfaces.Nameable) PrimaryDrawerItem(com.mikepenz.materialdrawer.model.PrimaryDrawerItem) SectionDrawerItem(com.mikepenz.materialdrawer.model.SectionDrawerItem) 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) Toolbar(android.support.v7.widget.Toolbar)

Example 7 with IDrawerItem

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

the class CompactHeaderDrawerActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_sample);
    // Handle Toolbar
    final Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    getSupportActionBar().setTitle(R.string.drawer_item_compact_header);
    // Create a few sample profile
    final IProfile profile = new ProfileDrawerItem().withName("Mike Penz").withEmail("mikepenz@gmail.com").withIcon(R.drawable.profile);
    final IProfile profile2 = new ProfileDrawerItem().withName("Max Muster").withEmail("max.mustermann@gmail.com").withIcon(R.drawable.profile2);
    final IProfile profile3 = new ProfileDrawerItem().withName("Felix House").withEmail("felix.house@gmail.com").withIcon(R.drawable.profile3);
    final IProfile profile4 = new ProfileDrawerItem().withName("Mr. X").withEmail("mister.x.super@gmail.com").withIcon(R.drawable.profile4);
    final IProfile profile5 = new ProfileDrawerItem().withName("Batman").withEmail("batman@gmail.com").withIcon(R.drawable.profile5);
    // Create the AccountHeader
    headerResult = new AccountHeaderBuilder().withActivity(this).withCompactStyle(true).withHeaderBackground(R.drawable.header).addProfiles(profile, profile2, profile3, profile4, profile5, //don't ask but google uses 14dp for the add account icon in gmail but 20dp for the normal icons (like manage account)
    new ProfileSettingDrawerItem().withName("Add Account").withDescription("Add new GitHub Account").withIcon(new IconicsDrawable(this, GoogleMaterial.Icon.gmd_plus).actionBar().paddingDp(5).colorRes(R.color.material_drawer_dark_primary_text)).withIdentifier(PROFILE_SETTING), new ProfileSettingDrawerItem().withName("Manage Account").withIcon(GoogleMaterial.Icon.gmd_settings)).withSavedInstance(savedInstanceState).build();
    //Create the drawer
    result = new DrawerBuilder().withActivity(this).withAccountHeader(//set the AccountHeader we created earlier for the header
    headerResult).addDrawerItems(new PrimaryDrawerItem().withName(R.string.drawer_item_home).withIcon(FontAwesome.Icon.faw_home).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).withIdentifier(5), 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), 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 != null && drawerItem.getIdentifier() == 1) {
                startSupportActionMode(new ActionBarCallBack());
                findViewById(R.id.action_mode_bar).setBackgroundColor(UIUtils.getThemeColorFromAttrOrRes(CompactHeaderDrawerActivity.this, R.attr.colorPrimary, R.color.material_drawer_primary));
            }
            if (drawerItem instanceof Nameable) {
                toolbar.setTitle(((Nameable) drawerItem).getName().getText(CompactHeaderDrawerActivity.this));
            }
            return false;
        }
    }).withSavedInstance(savedInstanceState).build();
    // set the selection to the item with the identifier 5
    if (savedInstanceState == null) {
        result.setSelection(5, false);
    }
    //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) ProfileSettingDrawerItem(com.mikepenz.materialdrawer.model.ProfileSettingDrawerItem) ProfileDrawerItem(com.mikepenz.materialdrawer.model.ProfileDrawerItem) AccountHeaderBuilder(com.mikepenz.materialdrawer.AccountHeaderBuilder) SecondaryDrawerItem(com.mikepenz.materialdrawer.model.SecondaryDrawerItem) View(android.view.View) Nameable(com.mikepenz.materialdrawer.model.interfaces.Nameable) SectionDrawerItem(com.mikepenz.materialdrawer.model.SectionDrawerItem) IProfile(com.mikepenz.materialdrawer.model.interfaces.IProfile) DrawerBuilder(com.mikepenz.materialdrawer.DrawerBuilder) IconicsDrawable(com.mikepenz.iconics.IconicsDrawable) Toolbar(android.support.v7.widget.Toolbar)

Example 8 with IDrawerItem

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

the class CrossfadeDrawerLayoutActvitiy method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_sample_dark_toolbar);
    // Handle Toolbar
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    //set the back arrow in the toolbar
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    getSupportActionBar().setTitle(R.string.drawer_item_crossfade_drawer_layout_drawer);
    // Create a few sample profile
    // NOTE you have to define the loader logic too. See the CustomApplication for more details
    final IProfile profile = new ProfileDrawerItem().withName("Mike Penz").withEmail("mikepenz@gmail.com").withIcon("https://avatars3.githubusercontent.com/u/1476232?v=3&s=460");
    final IProfile profile2 = new ProfileDrawerItem().withName("Bernat Borras").withEmail("alorma@github.com").withIcon(Uri.parse("https://avatars3.githubusercontent.com/u/887462?v=3&s=460"));
    // Create the AccountHeader
    headerResult = new AccountHeaderBuilder().withActivity(this).withHeaderBackground(R.drawable.header).addProfiles(profile, profile2).withSavedInstance(savedInstanceState).build();
    //Create the drawer
    result = new DrawerBuilder().withActivity(this).withToolbar(toolbar).withHasStableIds(true).withDrawerLayout(R.layout.crossfade_drawer).withDrawerWidthDp(72).withGenerateMiniDrawer(true).withAccountHeader(//set the AccountHeader we created earlier for the header
    headerResult).addDrawerItems(new PrimaryDrawerItem().withName(R.string.drawer_item_compact_header).withIcon(GoogleMaterial.Icon.gmd_sun).withIdentifier(1), new PrimaryDrawerItem().withName(R.string.drawer_item_action_bar_drawer).withIcon(FontAwesome.Icon.faw_home).withBadge("22").withBadgeStyle(new BadgeStyle(Color.RED, Color.RED)).withIdentifier(2).withSelectable(false), new PrimaryDrawerItem().withName(R.string.drawer_item_multi_drawer).withIcon(FontAwesome.Icon.faw_gamepad).withIdentifier(3), new PrimaryDrawerItem().withName(R.string.drawer_item_non_translucent_status_drawer).withIcon(FontAwesome.Icon.faw_eye).withIdentifier(4), new PrimaryDrawerItem().withDescription("A more complex sample").withName(R.string.drawer_item_advanced_drawer).withIcon(GoogleMaterial.Icon.gmd_adb).withIdentifier(5), new SectionDrawerItem().withName(R.string.drawer_item_section_header), new SecondaryDrawerItem().withName(R.string.drawer_item_open_source).withIcon(FontAwesome.Icon.faw_github), new SecondaryDrawerItem().withName(R.string.drawer_item_contact).withIcon(GoogleMaterial.Icon.gmd_format_color_fill).withTag("Bullhorn")).withOnDrawerItemClickListener(new Drawer.OnDrawerItemClickListener() {

        @Override
        public boolean onItemClick(View view, int position, IDrawerItem drawerItem) {
            if (drawerItem instanceof Nameable) {
                Toast.makeText(CrossfadeDrawerLayoutActvitiy.this, ((Nameable) drawerItem).getName().getText(CrossfadeDrawerLayoutActvitiy.this), Toast.LENGTH_SHORT).show();
            }
            //we do not consume the event and want the Drawer to continue with the event chain
            return false;
        }
    }).withSavedInstance(savedInstanceState).withShowDrawerOnFirstLaunch(true).build();
    //get the CrossfadeDrawerLayout which will be used as alternative DrawerLayout for the Drawer
    //the CrossfadeDrawerLayout library can be found here: https://github.com/mikepenz/CrossfadeDrawerLayout
    crossfadeDrawerLayout = (CrossfadeDrawerLayout) result.getDrawerLayout();
    //define maxDrawerWidth
    crossfadeDrawerLayout.setMaxWidthPx(DrawerUIUtils.getOptimalDrawerWidth(this));
    //add second view (which is the miniDrawer)
    final MiniDrawer miniResult = result.getMiniDrawer();
    //build the view for the MiniDrawer
    View view = miniResult.build(this);
    //set the background of the MiniDrawer as this would be transparent
    view.setBackgroundColor(UIUtils.getThemeColorFromAttrOrRes(this, com.mikepenz.materialdrawer.R.attr.material_drawer_background, com.mikepenz.materialdrawer.R.color.material_drawer_background));
    //we do not have the MiniDrawer view during CrossfadeDrawerLayout creation so we will add it here
    crossfadeDrawerLayout.getSmallView().addView(view, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
    //define the crossfader to be used with the miniDrawer. This is required to be able to automatically toggle open / close
    miniResult.withCrossFader(new ICrossfader() {

        @Override
        public void crossfade() {
            boolean isFaded = isCrossfaded();
            crossfadeDrawerLayout.crossfade(400);
            //only close the drawer if we were already faded and want to close it now
            if (isFaded) {
                result.getDrawerLayout().closeDrawer(GravityCompat.START);
            }
        }

        @Override
        public boolean isCrossfaded() {
            return crossfadeDrawerLayout.isCrossfaded();
        }
    });
/**
         * NOTE THIS IS A HIGHLY CUSTOM ANIMATION. USE CAREFULLY.
         * this animate the height of the profile to the height of the AccountHeader and
         * animates the height of the drawerItems to the normal drawerItems so the difference between Mini and normal Drawer is eliminated
         **/
/*
        final double headerHeight = DrawerUIUtils.getOptimalDrawerWidth(this) * 9d / 16d;
        final double originalProfileHeight = UIUtils.convertDpToPixel(72, this);
        final double headerDifference = headerHeight - originalProfileHeight;
        final double originalItemHeight = UIUtils.convertDpToPixel(64, this);
        final double normalItemHeight = UIUtils.convertDpToPixel(48, this);
        final double itemDifference = originalItemHeight - normalItemHeight;
        crossfadeDrawerLayout.withCrossfadeListener(new CrossfadeDrawerLayout.CrossfadeListener() {
            @Override
            public void onCrossfade(View containerView, float currentSlidePercentage, int slideOffset) {
                for (int i = 0; i < miniResult.getAdapter().getItemCount(); i++) {
                    IDrawerItem drawerItem = miniResult.getAdapter().getItem(i);
                    if (drawerItem instanceof MiniProfileDrawerItem) {
                        MiniProfileDrawerItem mpdi = (MiniProfileDrawerItem) drawerItem;
                        mpdi.withCustomHeightPx((int) (originalProfileHeight + (headerDifference * currentSlidePercentage / 100)));
                    } else if (drawerItem instanceof MiniDrawerItem) {
                        MiniDrawerItem mdi = (MiniDrawerItem) drawerItem;
                        mdi.withCustomHeightPx((int) (originalItemHeight - (itemDifference * currentSlidePercentage / 100)));
                    }
                }

                miniResult.getAdapter().notifyDataSetChanged();
            }
        });
        */
}
Also used : PrimaryDrawerItem(com.mikepenz.materialdrawer.model.PrimaryDrawerItem) IDrawerItem(com.mikepenz.materialdrawer.model.interfaces.IDrawerItem) ProfileDrawerItem(com.mikepenz.materialdrawer.model.ProfileDrawerItem) AccountHeaderBuilder(com.mikepenz.materialdrawer.AccountHeaderBuilder) Drawer(com.mikepenz.materialdrawer.Drawer) MiniDrawer(com.mikepenz.materialdrawer.MiniDrawer) SecondaryDrawerItem(com.mikepenz.materialdrawer.model.SecondaryDrawerItem) View(android.view.View) Nameable(com.mikepenz.materialdrawer.model.interfaces.Nameable) SectionDrawerItem(com.mikepenz.materialdrawer.model.SectionDrawerItem) BadgeStyle(com.mikepenz.materialdrawer.holder.BadgeStyle) IProfile(com.mikepenz.materialdrawer.model.interfaces.IProfile) DrawerBuilder(com.mikepenz.materialdrawer.DrawerBuilder) MiniDrawer(com.mikepenz.materialdrawer.MiniDrawer) Toolbar(android.support.v7.widget.Toolbar) ICrossfader(com.mikepenz.materialdrawer.interfaces.ICrossfader)

Example 9 with IDrawerItem

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

the class Drawer method updateName.

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

Example 10 with IDrawerItem

use of com.mikepenz.materialdrawer.model.interfaces.IDrawerItem 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

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