Search in sources :

Example 16 with SecondaryDrawerItem

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

the class PersistentDrawerActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_persistent_drawer);
    //Remove line to test RTL support
    // getWindow().getDecorView().setLayoutDirection(View.LAYOUT_DIRECTION_RTL);
    //example how to implement a persistentDrawer as shown in the google material design guidelines
    //https://material-design.storage.googleapis.com/publish/material_v_4/material_ext_publish/0Bx4BSt6jniD7YVdKQlF3TEo2S3M/patterns_navdrawer_behavior_persistent2.png
    //https://www.google.com/design/spec/patterns/navigation-drawer.html#navigation-drawer-behavior
    // Handle Toolbar
    final Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    getSupportActionBar().setTitle(R.string.drawer_item_persistent_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).withTranslucentStatusBar(true).withHeaderBackground(new ColorDrawable(Color.parseColor("#FDFDFD"))).withHeightPx(UIUtils.getActionBarHeight(this)).withAccountHeader(R.layout.material_drawer_compact_persistent_header).withTextColor(Color.BLACK).addProfiles(profile, profile2, profile3, profile4, profile5).withSavedInstance(savedInstanceState).build();
    //Create the drawer
    result = new DrawerBuilder().withActivity(this).withTranslucentStatusBar(true).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), 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)).withGenerateMiniDrawer(true).withSavedInstance(savedInstanceState).buildView();
    // create the MiniDrawer and define the drawer and header to be used (it will automatically use the items from them)
    miniResult = result.getMiniDrawer().withIncludeSecondaryDrawerItems(true);
    //set the back arrow in the toolbar
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    getSupportActionBar().setHomeButtonEnabled(false);
    //get the widths in px for the first and second panel
    int firstWidth = (int) com.mikepenz.crossfader.util.UIUtils.convertDpToPixel(300, this);
    int secondWidth = (int) com.mikepenz.crossfader.util.UIUtils.convertDpToPixel(72, this);
    //create and build our crossfader (see the MiniDrawer is also builded in here, as the build method returns the view to be used in the crossfader)
    crossFader = new Crossfader().withContent(findViewById(R.id.crossfade_content)).withFirst(result.getSlider(), firstWidth).withSecond(miniResult.build(this), secondWidth).withSavedInstance(savedInstanceState).build();
    //define the crossfader to be used with the miniDrawer. This is required to be able to automatically toggle open / close
    miniResult.withCrossFader(new CrossfadeWrapper(crossFader));
    //define and create the arrow ;)
    ImageView toggle = (ImageView) headerResult.getView().findViewById(R.id.material_drawer_account_header_toggle);
    //for RTL you would have to define the other arrow
    toggle.setImageDrawable(new IconicsDrawable(this, GoogleMaterial.Icon.gmd_chevron_left).sizeDp(16).color(Color.BLACK));
    toggle.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            crossFader.crossFade();
        }
    });
}
Also used : PrimaryDrawerItem(com.mikepenz.materialdrawer.model.PrimaryDrawerItem) ProfileDrawerItem(com.mikepenz.materialdrawer.model.ProfileDrawerItem) AccountHeaderBuilder(com.mikepenz.materialdrawer.AccountHeaderBuilder) SecondaryDrawerItem(com.mikepenz.materialdrawer.model.SecondaryDrawerItem) ImageView(android.widget.ImageView) View(android.view.View) SectionDrawerItem(com.mikepenz.materialdrawer.model.SectionDrawerItem) ColorDrawable(android.graphics.drawable.ColorDrawable) CrossfadeWrapper(com.mikepenz.materialdrawer.app.utils.CrossfadeWrapper) ImageView(android.widget.ImageView) IProfile(com.mikepenz.materialdrawer.model.interfaces.IProfile) DrawerBuilder(com.mikepenz.materialdrawer.DrawerBuilder) IconicsDrawable(com.mikepenz.iconics.IconicsDrawable) Toolbar(android.support.v7.widget.Toolbar) Crossfader(com.mikepenz.crossfader.Crossfader)

Example 17 with SecondaryDrawerItem

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

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

the class DrawerFragment method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    // Inflate the layout for this fragment
    // don't look at this layout it's just a listView to show how to handle the keyboard
    View view = inflater.inflate(R.layout.fragment_simple_sample, container, false);
    result = new DrawerBuilder().withActivity(getActivity()).withRootView((ViewGroup) view.findViewById(R.id.rootView)).withDisplayBelowStatusBar(false).withSavedInstance(savedInstanceState).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), 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)).buildForFragment();
    TextView textView = (TextView) view.findViewById(R.id.title);
    textView.setText(getArguments().getString(KEY_TITLE));
    result.getDrawerLayout().setFitsSystemWindows(false);
    result.getSlider().setFitsSystemWindows(false);
    return view;
}
Also used : PrimaryDrawerItem(com.mikepenz.materialdrawer.model.PrimaryDrawerItem) SectionDrawerItem(com.mikepenz.materialdrawer.model.SectionDrawerItem) ViewGroup(android.view.ViewGroup) TextView(android.widget.TextView) DrawerBuilder(com.mikepenz.materialdrawer.DrawerBuilder) TextView(android.widget.TextView) View(android.view.View) SecondaryDrawerItem(com.mikepenz.materialdrawer.model.SecondaryDrawerItem)

Example 19 with SecondaryDrawerItem

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

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

SecondaryDrawerItem (com.mikepenz.materialdrawer.model.SecondaryDrawerItem)20 DrawerBuilder (com.mikepenz.materialdrawer.DrawerBuilder)18 PrimaryDrawerItem (com.mikepenz.materialdrawer.model.PrimaryDrawerItem)17 View (android.view.View)15 Toolbar (android.support.v7.widget.Toolbar)13 SectionDrawerItem (com.mikepenz.materialdrawer.model.SectionDrawerItem)13 IDrawerItem (com.mikepenz.materialdrawer.model.interfaces.IDrawerItem)12 AccountHeaderBuilder (com.mikepenz.materialdrawer.AccountHeaderBuilder)10 Drawer (com.mikepenz.materialdrawer.Drawer)10 ProfileDrawerItem (com.mikepenz.materialdrawer.model.ProfileDrawerItem)10 IProfile (com.mikepenz.materialdrawer.model.interfaces.IProfile)9 DividerDrawerItem (com.mikepenz.materialdrawer.model.DividerDrawerItem)7 Nameable (com.mikepenz.materialdrawer.model.interfaces.Nameable)7 IconicsDrawable (com.mikepenz.iconics.IconicsDrawable)6 BadgeStyle (com.mikepenz.materialdrawer.holder.BadgeStyle)4 ProfileSettingDrawerItem (com.mikepenz.materialdrawer.model.ProfileSettingDrawerItem)4 SwitchDrawerItem (com.mikepenz.materialdrawer.model.SwitchDrawerItem)4 Intent (android.content.Intent)3 ToggleDrawerItem (com.mikepenz.materialdrawer.model.ToggleDrawerItem)3 MenuItem (android.view.MenuItem)2