Search in sources :

Example 6 with DividerDrawerItem

use of com.mikepenz.materialdrawer.model.DividerDrawerItem 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 7 with DividerDrawerItem

use of com.mikepenz.materialdrawer.model.DividerDrawerItem in project FastAdapter by mikepenz.

the class SampleActivity method onCreate.

@Override
protected void onCreate(final Bundle savedInstanceState) {
    findViewById(android.R.id.content).setSystemUiVisibility(findViewById(android.R.id.content).getSystemUiVisibility() | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
    //create the activity
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    // Handle Toolbar
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    getSupportActionBar().setTitle("");
    //Create the drawer
    mResult = new DrawerBuilder().withActivity(this).withToolbar(toolbar).withHasStableIds(true).withSavedInstance(savedInstanceState).withShowDrawerOnFirstLaunch(true).addDrawerItems(new PrimaryDrawerItem().withName(R.string.sample_icon_grid).withDescription(R.string.sample_icon_grid_descr).withSelectable(false).withIdentifier(8).withIcon(MaterialDesignIconic.Icon.gmi_grid), new PrimaryDrawerItem().withName(R.string.sample_simple_item_list).withDescription(R.string.sample_simple_item_list_descr).withSelectable(false).withIdentifier(6).withIcon(MaterialDesignIconic.Icon.gmi_format_align_justify), new PrimaryDrawerItem().withName(R.string.sample_image_list).withDescription(R.string.sample_image_list_descr).withSelectable(false).withIdentifier(5).withIcon(MaterialDesignIconic.Icon.gmi_wallpaper), new PrimaryDrawerItem().withName(R.string.sample_multi_select).withDescription(R.string.sample_multi_select_descr).withSelectable(false).withIdentifier(1).withIcon(MaterialDesignIconic.Icon.gmi_select_all), new PrimaryDrawerItem().withName(R.string.sample_collapsible).withDescription(R.string.sample_collapsible_descr).withSelectable(false).withIdentifier(2).withIcon(MaterialDesignIconic.Icon.gmi_check_all), new PrimaryDrawerItem().withName(R.string.sample_sticky_header).withDescription(R.string.sample_sticky_header_descr).withSelectable(false).withIdentifier(3).withIcon(MaterialDesignIconic.Icon.gmi_format_align_left), new PrimaryDrawerItem().withName(R.string.sample_advanced).withDescription(R.string.sample_advanced_descr).withSelectable(false).withIdentifier(4).withIcon(MaterialDesignIconic.Icon.gmi_coffee), new PrimaryDrawerItem().withName(R.string.sample_generic_item).withDescription(R.string.sample_generic_item_descr).withSelectable(false).withIdentifier(7).withIcon(MaterialDesignIconic.Icon.gmi_font), new PrimaryDrawerItem().withName(R.string.sample_multi_generic_item).withDescription(R.string.sample_multi_generic_item_descr).withSelectable(false).withIdentifier(9).withIcon(MaterialDesignIconic.Icon.gmi_format_list_numbered), new PrimaryDrawerItem().withName(R.string.sample_checkbox_item).withDescription(R.string.sample_checkbox_item_descr).withSelectable(false).withIdentifier(10).withIcon(CommunityMaterial.Icon.cmd_checkbox_marked), new PrimaryDrawerItem().withName(R.string.sample_radiobutton_item).withDescription(R.string.sample_radiobutton_item_descr).withSelectable(false).withIdentifier(11).withIcon(CommunityMaterial.Icon.cmd_radiobox_marked), new PrimaryDrawerItem().withName(R.string.sample_swipe_list).withDescription(R.string.sample_swipe_list_descr).withSelectable(false).withIdentifier(12).withIcon(MaterialDesignIconic.Icon.gmi_format_align_left), new PrimaryDrawerItem().withName(R.string.sample_endless_scroll_list).withDescription(R.string.sample_endless_scroll_list_descr).withSelectable(false).withIdentifier(13).withIcon(MaterialDesignIconic.Icon.gmi_long_arrow_down), new PrimaryDrawerItem().withName(R.string.sample_sort).withDescription(R.string.sample_sort_descr).withSelectable(false).withIdentifier(14).withIcon(MaterialDesignIconic.Icon.gmi_sort_by_alpha), new PrimaryDrawerItem().withName(R.string.sample_mopub).withDescription(R.string.sample_mopub_descr).withSelectable(false).withIdentifier(15).withIcon(MaterialDesignIconic.Icon.gmi_accounts_list), new PrimaryDrawerItem().withName(R.string.sample_realm_list).withDescription(R.string.sample_realm_list_descr).withSelectable(false).withIdentifier(16).withIcon(MaterialDesignIconic.Icon.gmi_format_color_text), new PrimaryDrawerItem().withName(R.string.sample_collapsible_multi_select_delete).withDescription(R.string.sample_collapsible_multi_select_delete_descr).withSelectable(false).withIdentifier(17).withIcon(MaterialDesignIconic.Icon.gmi_check_all), new DividerDrawerItem(), new PrimaryDrawerItem().withName(R.string.open_source).withSelectable(false).withIdentifier(100).withIcon(MaterialDesignIconic.Icon.gmi_github)).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(SampleActivity.this, MultiselectSampleActivity.class);
                } else if (drawerItem.getIdentifier() == 2) {
                    intent = new Intent(SampleActivity.this, ExpandableSampleActivity.class);
                } else if (drawerItem.getIdentifier() == 3) {
                    intent = new Intent(SampleActivity.this, StickyHeaderSampleActivity.class);
                } else if (drawerItem.getIdentifier() == 4) {
                    intent = new Intent(SampleActivity.this, AdvancedSampleActivity.class);
                } else if (drawerItem.getIdentifier() == 5) {
                    intent = new Intent(SampleActivity.this, ImageListActivity.class);
                } else if (drawerItem.getIdentifier() == 6) {
                    intent = new Intent(SampleActivity.this, SimpleItemListActivity.class);
                } else if (drawerItem.getIdentifier() == 7) {
                    intent = new Intent(SampleActivity.this, GenericItemActivity.class);
                } else if (drawerItem.getIdentifier() == 8) {
                    intent = new Intent(SampleActivity.this, IconGridActivity.class);
                } else if (drawerItem.getIdentifier() == 9) {
                    intent = new Intent(SampleActivity.this, MultiTypeGenericItemActivity.class);
                } else if (drawerItem.getIdentifier() == 10) {
                    intent = new Intent(SampleActivity.this, CheckBoxSampleActivity.class);
                } else if (drawerItem.getIdentifier() == 11) {
                    intent = new Intent(SampleActivity.this, RadioButtonSampleActivity.class);
                } else if (drawerItem.getIdentifier() == 12) {
                    intent = new Intent(SampleActivity.this, SwipeListActivity.class);
                } else if (drawerItem.getIdentifier() == 13) {
                    intent = new Intent(SampleActivity.this, EndlessScrollListActivity.class);
                } else if (drawerItem.getIdentifier() == 14) {
                    intent = new Intent(SampleActivity.this, SortActivity.class);
                } else if (drawerItem.getIdentifier() == 15) {
                    intent = new Intent(SampleActivity.this, MopubAdsActivity.class);
                } else if (drawerItem.getIdentifier() == 16) {
                    intent = new Intent(SampleActivity.this, RealmActivity.class);
                } else if (drawerItem.getIdentifier() == 17) {
                    intent = new Intent(SampleActivity.this, ExpandableMultiselectDeleteSampleActivity.class);
                } else if (drawerItem.getIdentifier() == 100) {
                    intent = new LibsBuilder().withFields(R.string.class.getFields()).withActivityTitle(getString(R.string.open_source)).withActivityStyle(Libs.ActivityStyle.LIGHT).withAboutIconShown(true).withVersionShown(true).withAboutVersionShown(true).intent(SampleActivity.this);
                }
                if (intent != null) {
                    SampleActivity.this.startActivity(intent);
                }
            }
            return false;
        }
    }).withSelectedItemByPosition(-1).build();
    //create our FastAdapter which will manage everything
    mFastAdapter = new FastAdapter<>();
    mFastAdapter.withSelectable(true);
    mFastAdapter.withMultiSelect(true);
    mFastAdapter.withSelectOnLongClick(false);
    //create our ItemAdapter which will host our items
    mItemAdapter = new ItemAdapter<>();
    //configure our fastAdapter
    //get our recyclerView and do basic setup
    mRecyclerView = (RecyclerView) findViewById(R.id.rv);
    //mRecyclerView.setLayoutManager(new GridLayoutManager(this, 3));
    mRecyclerView.setLayoutManager(new LinearLayoutManager(this));
    mRecyclerView.setAdapter(mItemAdapter.wrap(mFastAdapter));
    mRecyclerView.setItemAnimator(new SlideDownAlphaAnimator());
    mRecyclerView.getItemAnimator().setAddDuration(500);
    mRecyclerView.getItemAnimator().setRemoveDuration(500);
    //if we do this. the first added items will be animated :D
    new Handler().postDelayed(new Runnable() {

        @Override
        public void run() {
            //add some dummy data
            mItemAdapter.add(ImageDummyData.getSimpleImageItems());
            //restore selections (this has to be done after the items were added
            mFastAdapter.withSavedInstanceState(savedInstanceState);
        }
    }, 50);
}
Also used : PrimaryDrawerItem(com.mikepenz.materialdrawer.model.PrimaryDrawerItem) IDrawerItem(com.mikepenz.materialdrawer.model.interfaces.IDrawerItem) DividerDrawerItem(com.mikepenz.materialdrawer.model.DividerDrawerItem) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) SlideDownAlphaAnimator(com.mikepenz.itemanimators.SlideDownAlphaAnimator) LibsBuilder(com.mikepenz.aboutlibraries.LibsBuilder) Toolbar(android.support.v7.widget.Toolbar) Handler(android.os.Handler) Intent(android.content.Intent) View(android.view.View) RecyclerView(android.support.v7.widget.RecyclerView) DrawerBuilder(com.mikepenz.materialdrawer.DrawerBuilder)

Example 8 with DividerDrawerItem

use of com.mikepenz.materialdrawer.model.DividerDrawerItem in project Weather by Sparker0i.

the class WeatherActivity method initDrawer.

public void initDrawer() {
    final Context context = this;
    final IProfile profile = new ProfileDrawerItem().withName(getString(R.string.app_name)).withEmail(getString(R.string.drawer_version_header) + " : " + BuildConfig.VERSION_NAME).withIcon(R.mipmap.ic_launcher_x);
    AccountHeader headerResult = new AccountHeaderBuilder().withActivity(this).withHeaderBackground(R.drawable.header).withTextColor(ContextCompat.getColor(this, R.color.md_amber_400)).addProfiles(profile).withSelectionListEnabled(false).withProfileImagesClickable(false).build();
    SecondaryDrawerItem item1 = new SecondaryDrawerItem().withIdentifier(1).withName(R.string.drawer_item_home).withIcon(new IconicsDrawable(this).icon(WeatherIcons.Icon.wic_day_sunny));
    SecondaryDrawerItem item2 = new SecondaryDrawerItem().withIdentifier(2).withName(R.string.drawer_item_graph).withIcon(new IconicsDrawable(this).icon(GoogleMaterial.Icon.gmd_trending_up));
    SecondaryDrawerItem item3 = new SecondaryDrawerItem().withIdentifier(3).withName(R.string.drawer_item_map).withIcon(new IconicsDrawable(this).icon(GoogleMaterial.Icon.gmd_map));
    SecondaryDrawerItem item7 = new SecondaryDrawerItem().withIdentifier(7).withName(R.string.drawer_item_about).withIcon(new IconicsDrawable(this).icon(GoogleMaterial.Icon.gmd_info)).withSelectable(false);
    SecondaryDrawerItem item6 = new SecondaryDrawerItem().withIdentifier(6).withName(getString(R.string.drawer_item_custom_key)).withIcon(new IconicsDrawable(this).icon(GoogleMaterial.Icon.gmd_create)).withSelectable(false);
    SecondarySwitchDrawerItem item4 = new SecondarySwitchDrawerItem().withIdentifier(4).withName(getString(R.string.drawer_item_fahrenheit)).withChecked(preferences.getUnits().equals(Constants.IMPERIAL)).withIcon(new IconicsDrawable(this).icon(WeatherIcons.Icon.wic_fahrenheit)).withSelectable(false);
    SecondarySwitchDrawerItem item5 = new SecondarySwitchDrawerItem().withIdentifier(5).withName(getString(R.string.drawer_item_notifications)).withChecked(preferences.getNotifs()).withIcon(new IconicsDrawable(this).icon(GoogleMaterial.Icon.gmd_notifications)).withSelectable(false);
    item4.withOnCheckedChangeListener(new OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(IDrawerItem drawerItem, CompoundButton buttonView, boolean isChecked) {
            if (isChecked) {
                preferences.setUnits(Constants.IMPERIAL);
            } else {
                preferences.setUnits(Constants.METRIC);
            }
            Fragment f = getSupportFragmentManager().findFragmentById(R.id.fragment);
            if (f instanceof WeatherFragment) {
                wf = new WeatherFragment();
                getSupportFragmentManager().beginTransaction().replace(R.id.fragment, wf).commit();
                drawer.closeDrawer();
            }
        }
    });
    item5.withOnCheckedChangeListener(new OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(IDrawerItem drawerItem, CompoundButton buttonView, boolean isChecked) {
            if (isChecked) {
                preferences.setNotifs(true);
                startService(new Intent(context, AlarmTriggerService.class));
            } else {
                preferences.setNotifs(false);
                stopService(new Intent(context, AlarmTriggerService.class));
                mManager.cancelAll();
            }
        }
    });
    drawer = new DrawerBuilder().withActivity(this).withToolbar(toolbar).withSelectedItem(1).withTranslucentStatusBar(true).withAccountHeader(headerResult).withActionBarDrawerToggleAnimated(true).addDrawerItems(item1, item2, item3, new DividerDrawerItem(), item4, item5, new DividerDrawerItem(), item6, item7).withOnDrawerItemClickListener(new Drawer.OnDrawerItemClickListener() {

        @Override
        public boolean onItemClick(View view, int position, IDrawerItem drawerItem) {
            // do something with the clicked item :D
            if (drawerItem != null) {
                switch((int) drawerItem.getIdentifier()) {
                    case 1:
                        Fragment f = getSupportFragmentManager().findFragmentById(R.id.fragment);
                        if (!(f instanceof WeatherFragment)) {
                            wf = new WeatherFragment();
                            getSupportFragmentManager().beginTransaction().replace(R.id.fragment, wf).commit();
                        }
                        break;
                    case 2:
                        f = getSupportFragmentManager().findFragmentById(R.id.fragment);
                        if (!(f instanceof GraphsFragment)) {
                            GraphsFragment graphsFragment = newGraphInstance(new ArrayList<>(wf.getDailyJson()));
                            getSupportFragmentManager().beginTransaction().replace(R.id.fragment, graphsFragment).commit();
                        }
                        break;
                    case 3:
                        f = getSupportFragmentManager().findFragmentById(R.id.fragment);
                        if (!(f instanceof MapsFragment)) {
                            MapsFragment mapsFragment = new MapsFragment();
                            getSupportFragmentManager().beginTransaction().replace(R.id.fragment, mapsFragment).commit();
                        }
                        break;
                    case 6:
                        showApiKeyBox();
                        break;
                    case 7:
                        startActivity(new Intent(WeatherActivity.this, AboutActivity.class));
                        break;
                }
            }
            return false;
        }
    }).build();
}
Also used : IDrawerItem(com.mikepenz.materialdrawer.model.interfaces.IDrawerItem) DividerDrawerItem(com.mikepenz.materialdrawer.model.DividerDrawerItem) ProfileDrawerItem(com.mikepenz.materialdrawer.model.ProfileDrawerItem) ArrayList(java.util.ArrayList) AccountHeaderBuilder(com.mikepenz.materialdrawer.AccountHeaderBuilder) WeatherFragment(com.a5corp.weather.fragment.WeatherFragment) SecondaryDrawerItem(com.mikepenz.materialdrawer.model.SecondaryDrawerItem) GraphsFragment(com.a5corp.weather.fragment.GraphsFragment) Fragment(android.support.v4.app.Fragment) MapsFragment(com.a5corp.weather.fragment.MapsFragment) WeatherFragment(com.a5corp.weather.fragment.WeatherFragment) AccountHeader(com.mikepenz.materialdrawer.AccountHeader) MapsFragment(com.a5corp.weather.fragment.MapsFragment) IProfile(com.mikepenz.materialdrawer.model.interfaces.IProfile) IconicsDrawable(com.mikepenz.iconics.IconicsDrawable) Context(android.content.Context) OnCheckedChangeListener(com.mikepenz.materialdrawer.interfaces.OnCheckedChangeListener) Intent(android.content.Intent) Drawer(com.mikepenz.materialdrawer.Drawer) BindView(butterknife.BindView) View(android.view.View) SecondarySwitchDrawerItem(com.mikepenz.materialdrawer.model.SecondarySwitchDrawerItem) DrawerBuilder(com.mikepenz.materialdrawer.DrawerBuilder) CompoundButton(android.widget.CompoundButton) GraphsFragment(com.a5corp.weather.fragment.GraphsFragment)

Aggregations

DividerDrawerItem (com.mikepenz.materialdrawer.model.DividerDrawerItem)8 IDrawerItem (com.mikepenz.materialdrawer.model.interfaces.IDrawerItem)8 View (android.view.View)7 DrawerBuilder (com.mikepenz.materialdrawer.DrawerBuilder)7 PrimaryDrawerItem (com.mikepenz.materialdrawer.model.PrimaryDrawerItem)7 SecondaryDrawerItem (com.mikepenz.materialdrawer.model.SecondaryDrawerItem)7 Toolbar (android.support.v7.widget.Toolbar)5 AccountHeaderBuilder (com.mikepenz.materialdrawer.AccountHeaderBuilder)5 Drawer (com.mikepenz.materialdrawer.Drawer)5 IProfile (com.mikepenz.materialdrawer.model.interfaces.IProfile)5 Intent (android.content.Intent)4 ProfileDrawerItem (com.mikepenz.materialdrawer.model.ProfileDrawerItem)4 SectionDrawerItem (com.mikepenz.materialdrawer.model.SectionDrawerItem)4 BadgeStyle (com.mikepenz.materialdrawer.holder.BadgeStyle)3 ProfileSettingDrawerItem (com.mikepenz.materialdrawer.model.ProfileSettingDrawerItem)3 SwitchDrawerItem (com.mikepenz.materialdrawer.model.SwitchDrawerItem)3 ToggleDrawerItem (com.mikepenz.materialdrawer.model.ToggleDrawerItem)3 Nameable (com.mikepenz.materialdrawer.model.interfaces.Nameable)3 BindView (butterknife.BindView)2 LibsBuilder (com.mikepenz.aboutlibraries.LibsBuilder)2