Search in sources :

Example 1 with ExpandableDrawerItem

use of com.mikepenz.materialdrawer.model.ExpandableDrawerItem in project MaterialDrawer by mikepenz.

the class DrawerActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_sample_dark_toolbar);
    //Remove line to test RTL support
    //getWindow().getDecorView().setLayoutDirection(View.LAYOUT_DIRECTION_RTL);
    // Handle Toolbar
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    // 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").withIdentifier(100);
    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")).withIdentifier(101);
    final IProfile profile3 = new ProfileDrawerItem().withName("Max Muster").withEmail("max.mustermann@gmail.com").withIcon(R.drawable.profile2).withIdentifier(102);
    final IProfile profile4 = new ProfileDrawerItem().withName("Felix House").withEmail("felix.house@gmail.com").withIcon(R.drawable.profile3).withIdentifier(103);
    final IProfile profile5 = new ProfileDrawerItem().withName("Mr. X").withEmail("mister.x.super@gmail.com").withIcon(R.drawable.profile4).withIdentifier(104);
    final IProfile profile6 = new ProfileDrawerItem().withName("Batman").withEmail("batman@gmail.com").withIcon(R.drawable.profile5).withIdentifier(105);
    // Create the AccountHeader
    headerResult = new AccountHeaderBuilder().withActivity(this).withTranslucentStatusBar(true).withHeaderBackground(R.drawable.header).addProfiles(profile, profile2, profile3, profile4, profile5, profile6, //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_primary_text)).withIdentifier(PROFILE_SETTING), new ProfileSettingDrawerItem().withName("Manage Account").withIcon(GoogleMaterial.Icon.gmd_settings).withIdentifier(100001)).withOnAccountHeaderListener(new AccountHeader.OnAccountHeaderListener() {

        @Override
        public boolean onProfileChanged(View view, IProfile profile, boolean current) {
            //if the clicked item has the identifier 1 add a new profile ;)
            if (profile instanceof IDrawerItem && profile.getIdentifier() == PROFILE_SETTING) {
                int count = 100 + headerResult.getProfiles().size() + 1;
                IProfile newProfile = new ProfileDrawerItem().withNameShown(true).withName("Batman" + count).withEmail("batman" + count + "@gmail.com").withIcon(R.drawable.profile5).withIdentifier(count);
                if (headerResult.getProfiles() != null) {
                    //we know that there are 2 setting elements. set the new profile above them ;)
                    headerResult.addProfile(newProfile, headerResult.getProfiles().size() - 2);
                } else {
                    headerResult.addProfiles(newProfile);
                }
            }
            //false if you have not consumed the event and it should close the drawer
            return false;
        }
    }).withSavedInstance(savedInstanceState).build();
    //Create the drawer
    result = new DrawerBuilder().withActivity(this).withToolbar(toolbar).withHasStableIds(true).withItemAnimator(new AlphaCrossFadeAnimator()).withAccountHeader(//set the AccountHeader we created earlier for the header
    headerResult).addDrawerItems(new PrimaryDrawerItem().withName(R.string.drawer_item_compact_header).withDescription(R.string.drawer_item_compact_header_desc).withIcon(GoogleMaterial.Icon.gmd_sun).withIdentifier(1).withSelectable(false), new PrimaryDrawerItem().withName(R.string.drawer_item_action_bar_drawer).withDescription(R.string.drawer_item_action_bar_drawer_desc).withIcon(FontAwesome.Icon.faw_home).withIdentifier(2).withSelectable(false), new PrimaryDrawerItem().withName(R.string.drawer_item_multi_drawer).withDescription(R.string.drawer_item_multi_drawer_desc).withIcon(FontAwesome.Icon.faw_gamepad).withIdentifier(3).withSelectable(false), new PrimaryDrawerItem().withName(R.string.drawer_item_non_translucent_status_drawer).withDescription(R.string.drawer_item_non_translucent_status_drawer_desc).withIcon(FontAwesome.Icon.faw_eye).withIdentifier(4).withSelectable(false).withBadgeStyle(new BadgeStyle().withTextColor(Color.WHITE).withColorRes(R.color.md_red_700)), new PrimaryDrawerItem().withName(R.string.drawer_item_advanced_drawer).withDescription(R.string.drawer_item_advanced_drawer_desc).withIcon(GoogleMaterial.Icon.gmd_adb).withIdentifier(5).withSelectable(false), new PrimaryDrawerItem().withName(R.string.drawer_item_embedded_drawer).withDescription(R.string.drawer_item_embedded_drawer_desc).withIcon(GoogleMaterial.Icon.gmd_battery).withIdentifier(7).withSelectable(false), new PrimaryDrawerItem().withName(R.string.drawer_item_fullscreen_drawer).withDescription(R.string.drawer_item_fullscreen_drawer_desc).withIcon(GoogleMaterial.Icon.gmd_labels).withIdentifier(8).withSelectable(false), new PrimaryDrawerItem().withName(R.string.drawer_item_custom_container_drawer).withDescription(R.string.drawer_item_custom_container_drawer_desc).withIcon(GoogleMaterial.Icon.gmd_my_location).withIdentifier(9).withSelectable(false), new PrimaryDrawerItem().withName(R.string.drawer_item_menu_drawer).withDescription(R.string.drawer_item_menu_drawer_desc).withIcon(GoogleMaterial.Icon.gmd_filter_list).withIdentifier(10).withSelectable(false), new PrimaryDrawerItem().withName(R.string.drawer_item_mini_drawer).withDescription(R.string.drawer_item_mini_drawer_desc).withIcon(GoogleMaterial.Icon.gmd_battery_charging).withIdentifier(11).withSelectable(false), new PrimaryDrawerItem().withName(R.string.drawer_item_fragment_drawer).withDescription(R.string.drawer_item_fragment_drawer_desc).withIcon(GoogleMaterial.Icon.gmd_disc_full).withIdentifier(12).withSelectable(false), new PrimaryDrawerItem().withName(R.string.drawer_item_collapsing_toolbar_drawer).withDescription(R.string.drawer_item_collapsing_toolbar_drawer_desc).withIcon(GoogleMaterial.Icon.gmd_camera_rear).withIdentifier(13).withSelectable(false), new PrimaryDrawerItem().withName(R.string.drawer_item_persistent_compact_header).withDescription(R.string.drawer_item_persistent_compact_header_desc).withIcon(GoogleMaterial.Icon.gmd_brightness_5).withIdentifier(14).withSelectable(false), new PrimaryDrawerItem().withName(R.string.drawer_item_crossfade_drawer_layout_drawer).withDescription(R.string.drawer_item_crossfade_drawer_layout_drawer_desc).withIcon(GoogleMaterial.Icon.gmd_format_bold).withIdentifier(15).withSelectable(false), new SectionDrawerItem().withName(R.string.drawer_item_section_header), new ExpandableBadgeDrawerItem().withName("Collapsable Badge").withIcon(GoogleMaterial.Icon.gmd_collection_case_play).withIdentifier(18).withSelectable(false).withBadgeStyle(new BadgeStyle().withTextColor(Color.WHITE).withColorRes(R.color.md_red_700)).withBadge("100").withSubItems(new SecondaryDrawerItem().withName("CollapsableItem").withLevel(2).withIcon(GoogleMaterial.Icon.gmd_8tracks).withIdentifier(2000), new SecondaryDrawerItem().withName("CollapsableItem 2").withLevel(2).withIcon(GoogleMaterial.Icon.gmd_8tracks).withIdentifier(2001)), new ExpandableDrawerItem().withName("Collapsable").withIcon(GoogleMaterial.Icon.gmd_collection_case_play).withIdentifier(19).withSelectable(false).withSubItems(new SecondaryDrawerItem().withName("CollapsableItem").withLevel(2).withIcon(GoogleMaterial.Icon.gmd_8tracks).withIdentifier(2002), new SecondaryDrawerItem().withName("CollapsableItem 2").withLevel(2).withIcon(GoogleMaterial.Icon.gmd_8tracks).withIdentifier(2003)), new SecondaryDrawerItem().withName(R.string.drawer_item_open_source).withIcon(FontAwesome.Icon.faw_github).withIdentifier(20).withSelectable(false), new SecondaryDrawerItem().withName(R.string.drawer_item_contact).withIcon(GoogleMaterial.Icon.gmd_format_color_fill).withIdentifier(21).withTag("Bullhorn"), new DividerDrawerItem(), new SwitchDrawerItem().withName("Switch").withIcon(Octicons.Icon.oct_tools).withChecked(true).withOnCheckedChangeListener(onCheckedChangeListener), new SwitchDrawerItem().withName("Switch2").withIcon(Octicons.Icon.oct_tools).withChecked(true).withOnCheckedChangeListener(onCheckedChangeListener).withSelectable(false), new ToggleDrawerItem().withName("Toggle").withIcon(Octicons.Icon.oct_tools).withChecked(true).withOnCheckedChangeListener(onCheckedChangeListener), new DividerDrawerItem(), new SecondarySwitchDrawerItem().withName("Secondary switch").withIcon(Octicons.Icon.oct_tools).withChecked(true).withOnCheckedChangeListener(onCheckedChangeListener), new SecondarySwitchDrawerItem().withName("Secondary Switch2").withIcon(Octicons.Icon.oct_tools).withChecked(true).withOnCheckedChangeListener(onCheckedChangeListener).withSelectable(false), new SecondaryToggleDrawerItem().withName("Secondary toggle").withIcon(Octicons.Icon.oct_tools).withChecked(true).withOnCheckedChangeListener(onCheckedChangeListener)).withOnDrawerItemClickListener(new Drawer.OnDrawerItemClickListener() {

        @Override
        public boolean onItemClick(View view, int position, IDrawerItem drawerItem) {
            if (drawerItem != null) {
                Intent intent = null;
                if (drawerItem.getIdentifier() == 1) {
                    intent = new Intent(DrawerActivity.this, CompactHeaderDrawerActivity.class);
                } else if (drawerItem.getIdentifier() == 2) {
                    intent = new Intent(DrawerActivity.this, ActionBarActivity.class);
                } else if (drawerItem.getIdentifier() == 3) {
                    intent = new Intent(DrawerActivity.this, MultiDrawerActivity.class);
                } else if (drawerItem.getIdentifier() == 4) {
                    intent = new Intent(DrawerActivity.this, NonTranslucentDrawerActivity.class);
                } else if (drawerItem.getIdentifier() == 5) {
                    intent = new Intent(DrawerActivity.this, AdvancedActivity.class);
                } else if (drawerItem.getIdentifier() == 7) {
                    intent = new Intent(DrawerActivity.this, EmbeddedDrawerActivity.class);
                } else if (drawerItem.getIdentifier() == 8) {
                    intent = new Intent(DrawerActivity.this, FullscreenDrawerActivity.class);
                } else if (drawerItem.getIdentifier() == 9) {
                    intent = new Intent(DrawerActivity.this, CustomContainerActivity.class);
                } else if (drawerItem.getIdentifier() == 10) {
                    intent = new Intent(DrawerActivity.this, MenuDrawerActivity.class);
                } else if (drawerItem.getIdentifier() == 11) {
                    intent = new Intent(DrawerActivity.this, MiniDrawerActivity.class);
                } else if (drawerItem.getIdentifier() == 12) {
                    intent = new Intent(DrawerActivity.this, FragmentActivity.class);
                } else if (drawerItem.getIdentifier() == 13) {
                    intent = new Intent(DrawerActivity.this, CollapsingToolbarActivity.class);
                } else if (drawerItem.getIdentifier() == 14) {
                    intent = new Intent(DrawerActivity.this, PersistentDrawerActivity.class);
                } else if (drawerItem.getIdentifier() == 15) {
                    intent = new Intent(DrawerActivity.this, CrossfadeDrawerLayoutActvitiy.class);
                } else if (drawerItem.getIdentifier() == 20) {
                    intent = new LibsBuilder().withFields(R.string.class.getFields()).withActivityStyle(Libs.ActivityStyle.LIGHT_DARK_TOOLBAR).intent(DrawerActivity.this);
                }
                if (intent != null) {
                    DrawerActivity.this.startActivity(intent);
                }
            }
            return false;
        }
    }).withSavedInstance(savedInstanceState).withShowDrawerOnFirstLaunch(true).build();
    //if you have many different types of DrawerItems you can magically pre-cache those items to get a better scroll performance
    //make sure to init the cache after the DrawerBuilder was created as this will first clear the cache to make sure no old elements are in
    //RecyclerViewCacheUtil.getInstance().withCacheSize(2).init(result);
    new RecyclerViewCacheUtil<IDrawerItem>().withCacheSize(2).apply(result.getRecyclerView(), result.getDrawerItems());
    //only set the active selection or active profile if we do not recreate the activity
    if (savedInstanceState == null) {
        // set the selection to the item with the identifier 11
        result.setSelection(21, false);
        //set the active profile
        headerResult.setActiveProfile(profile3);
    }
    result.updateBadge(4, new StringHolder(10 + ""));
}
Also used : IDrawerItem(com.mikepenz.materialdrawer.model.interfaces.IDrawerItem) PrimaryDrawerItem(com.mikepenz.materialdrawer.model.PrimaryDrawerItem) DividerDrawerItem(com.mikepenz.materialdrawer.model.DividerDrawerItem) ProfileSettingDrawerItem(com.mikepenz.materialdrawer.model.ProfileSettingDrawerItem) ProfileDrawerItem(com.mikepenz.materialdrawer.model.ProfileDrawerItem) AccountHeaderBuilder(com.mikepenz.materialdrawer.AccountHeaderBuilder) SecondarySwitchDrawerItem(com.mikepenz.materialdrawer.model.SecondarySwitchDrawerItem) SwitchDrawerItem(com.mikepenz.materialdrawer.model.SwitchDrawerItem) SecondaryDrawerItem(com.mikepenz.materialdrawer.model.SecondaryDrawerItem) SecondaryToggleDrawerItem(com.mikepenz.materialdrawer.model.SecondaryToggleDrawerItem) ToggleDrawerItem(com.mikepenz.materialdrawer.model.ToggleDrawerItem) SectionDrawerItem(com.mikepenz.materialdrawer.model.SectionDrawerItem) RecyclerViewCacheUtil(com.mikepenz.fastadapter.commons.utils.RecyclerViewCacheUtil) LibsBuilder(com.mikepenz.aboutlibraries.LibsBuilder) ExpandableDrawerItem(com.mikepenz.materialdrawer.model.ExpandableDrawerItem) IProfile(com.mikepenz.materialdrawer.model.interfaces.IProfile) IconicsDrawable(com.mikepenz.iconics.IconicsDrawable) Toolbar(android.support.v7.widget.Toolbar) Intent(android.content.Intent) SecondaryToggleDrawerItem(com.mikepenz.materialdrawer.model.SecondaryToggleDrawerItem) Drawer(com.mikepenz.materialdrawer.Drawer) View(android.view.View) SecondarySwitchDrawerItem(com.mikepenz.materialdrawer.model.SecondarySwitchDrawerItem) ExpandableBadgeDrawerItem(com.mikepenz.materialdrawer.model.ExpandableBadgeDrawerItem) StringHolder(com.mikepenz.materialdrawer.holder.StringHolder) AlphaCrossFadeAnimator(com.mikepenz.itemanimators.AlphaCrossFadeAnimator) BadgeStyle(com.mikepenz.materialdrawer.holder.BadgeStyle) DrawerBuilder(com.mikepenz.materialdrawer.DrawerBuilder)

Example 2 with ExpandableDrawerItem

use of com.mikepenz.materialdrawer.model.ExpandableDrawerItem in project ETSMobile-Android2 by ApplETS.

the class MainActivity method initDrawer.

private void initDrawer() {
    boolean isUserLoggedIn = ApplicationManager.userCredentials != null;
    String studentName = "";
    String codeUniversel = "";
    ProfilManager profilManager = new ProfilManager(this);
    Etudiant etudiant = profilManager.getEtudiant();
    if (etudiant != null) {
        String prenom = etudiant.prenom != null ? etudiant.prenom.trim() : "";
        String nom = etudiant.nom != null ? etudiant.nom.trim() : "";
        studentName = prenom + " " + nom;
        codeUniversel = etudiant.codePerm != null ? etudiant.codePerm : "";
    }
    headerResult = new AccountHeaderBuilder().withActivity(this).withHeaderBackground(R.drawable.ets_background_grayscale).withSelectionListEnabledForSingleProfile(false).addProfiles(new ProfileDrawerItem().withName(codeUniversel).withEmail(studentName).withSelectedTextColor(ContextCompat.getColor(this, R.color.red)).withIcon(R.drawable.ic_user).withSelectable(isUserLoggedIn)).withOnAccountHeaderListener(new AccountHeader.OnAccountHeaderListener() {

        @Override
        public boolean onProfileChanged(View view, IProfile profile, boolean current) {
            goToFragment(new ProfilFragment(), ProfilFragment.class.getName());
            return false;
        }
    }).build();
    DrawerBuilder drawerBuilder = new DrawerBuilder().withActivity(this).withToolbar(toolbar).withAccountHeader(headerResult).withSelectedItem(isUserLoggedIn ? TODAY_FRAGMENT : ABOUT_FRAGMENT).withDisplayBelowStatusBar(true).withShowDrawerOnFirstLaunch(true).addDrawerItems(new ExpandableDrawerItem().withName(R.string.menu_section_1_moi).withSelectable(false).withSubItems(new SecondaryDrawerItem().withName(R.string.menu_section_1_ajd).withIdentifier(TODAY_FRAGMENT).withIcon(R.drawable.ic_ico_aujourdhui).withEnabled(isUserLoggedIn), new SecondaryDrawerItem().withName(R.string.menu_section_1_horaire).withIdentifier(SCHEDULE_FRAGMENT).withIcon(R.drawable.ic_ico_schedule).withEnabled(isUserLoggedIn), new SecondaryDrawerItem().withName(R.string.menu_section_1_notes).withIdentifier(COURSE_FRAGMENT).withIcon(R.drawable.ic_ico_notes).withEnabled(isUserLoggedIn), new SecondaryDrawerItem().withName(R.string.menu_section_2_moodle).withIdentifier(MOODLE_FRAGMENT).withIcon(R.drawable.ic_moodle_icon_small).withEnabled(isUserLoggedIn), new SecondaryDrawerItem().withName(R.string.menu_section_1_monETS).withIdentifier(MONETS_FRAGMENT).withIcon(R.drawable.ic_monets).withEnabled(isUserLoggedIn), new SecondaryDrawerItem().withName(R.string.menu_section_1_bandwith).withIdentifier(BANDWIDTH_FRAGMENT).withIcon(R.drawable.ic_ico_internet)).withIsExpanded(true), new ExpandableDrawerItem().withName(R.string.menu_section_2_ets).withSelectable(false).withSubItems(new SecondaryDrawerItem().withName(R.string.menu_section_2_news).withIdentifier(NEWS_FRAGMENT).withIcon(R.drawable.ic_ico_news), new SecondaryDrawerItem().withName(R.string.menu_section_2_events).withIdentifier(EVENTS_FRAGMENT).withIcon(R.drawable.ic_event_available), new SecondaryDrawerItem().withName(R.string.menu_section_2_bottin).withIdentifier(DIRECTORY_FRAGMENT).withIcon(R.drawable.ic_ico_bottin), new SecondaryDrawerItem().withName(R.string.menu_section_2_biblio).withIdentifier(LIBRARY_FRAGMENT).withIcon(R.drawable.ic_ico_library), new SecondaryDrawerItem().withName(R.string.menu_section_2_securite).withIdentifier(SECURITY_FRAGMENT).withIcon(R.drawable.ic_ico_security)), new ExpandableDrawerItem().withName(R.string.menu_section_3_applets).withSelectable(false).withSubItems(new SecondaryDrawerItem().withName(R.string.menu_section_3_apps).withIdentifier(ACHIEVEMENTS_FRAGMENT).withIcon(R.drawable.ic_star_60x60), new SecondaryDrawerItem().withName(R.string.menu_section_3_about).withIdentifier(ABOUT_FRAGMENT).withIcon(R.drawable.ic_logo_icon_final), new SecondaryDrawerItem().withName(R.string.menu_section_3_comms).withIdentifier(COMMENTS_FRAGMENT).withIcon(R.drawable.ic_ico_comment), new SecondaryDrawerItem().withName(R.string.menu_section_3_sponsors).withIdentifier(SPONSOR_FRAGMENT).withIcon(R.drawable.ic_ico_partners), new SecondaryDrawerItem().withName(R.string.menu_section_3_faq).withIdentifier(FAQ_FRAGMENT).withIcon(R.drawable.ic_ico_faq)));
    if (isUserLoggedIn)
        drawerBuilder.addStickyDrawerItems(new SecondaryDrawerItem().withName(R.string.action_logout).withIdentifier(LOGOUT).withTextColorRes(R.color.red));
    else
        drawerBuilder.addStickyDrawerItems(new SecondaryDrawerItem().withName(R.string.action_login).withIdentifier(LOGIN));
    drawerBuilder.withOnDrawerItemClickListener(drawerItemClickListener);
    drawerBuilder.build();
}
Also used : Etudiant(ca.etsmtl.applets.etsmobile.model.Etudiant) ProfilFragment(ca.etsmtl.applets.etsmobile.ui.fragment.ProfilFragment) ProfileDrawerItem(com.mikepenz.materialdrawer.model.ProfileDrawerItem) AccountHeaderBuilder(com.mikepenz.materialdrawer.AccountHeaderBuilder) View(android.view.View) SecondaryDrawerItem(com.mikepenz.materialdrawer.model.SecondaryDrawerItem) AccountHeader(com.mikepenz.materialdrawer.AccountHeader) ExpandableDrawerItem(com.mikepenz.materialdrawer.model.ExpandableDrawerItem) IProfile(com.mikepenz.materialdrawer.model.interfaces.IProfile) DrawerBuilder(com.mikepenz.materialdrawer.DrawerBuilder) ProfilManager(ca.etsmtl.applets.etsmobile.util.ProfilManager)

Aggregations

View (android.view.View)2 AccountHeaderBuilder (com.mikepenz.materialdrawer.AccountHeaderBuilder)2 DrawerBuilder (com.mikepenz.materialdrawer.DrawerBuilder)2 ExpandableDrawerItem (com.mikepenz.materialdrawer.model.ExpandableDrawerItem)2 ProfileDrawerItem (com.mikepenz.materialdrawer.model.ProfileDrawerItem)2 SecondaryDrawerItem (com.mikepenz.materialdrawer.model.SecondaryDrawerItem)2 IProfile (com.mikepenz.materialdrawer.model.interfaces.IProfile)2 Intent (android.content.Intent)1 Toolbar (android.support.v7.widget.Toolbar)1 Etudiant (ca.etsmtl.applets.etsmobile.model.Etudiant)1 ProfilFragment (ca.etsmtl.applets.etsmobile.ui.fragment.ProfilFragment)1 ProfilManager (ca.etsmtl.applets.etsmobile.util.ProfilManager)1 LibsBuilder (com.mikepenz.aboutlibraries.LibsBuilder)1 RecyclerViewCacheUtil (com.mikepenz.fastadapter.commons.utils.RecyclerViewCacheUtil)1 IconicsDrawable (com.mikepenz.iconics.IconicsDrawable)1 AlphaCrossFadeAnimator (com.mikepenz.itemanimators.AlphaCrossFadeAnimator)1 AccountHeader (com.mikepenz.materialdrawer.AccountHeader)1 Drawer (com.mikepenz.materialdrawer.Drawer)1 BadgeStyle (com.mikepenz.materialdrawer.holder.BadgeStyle)1 StringHolder (com.mikepenz.materialdrawer.holder.StringHolder)1