Search in sources :

Example 11 with PrimaryDrawerItem

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

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

the class SecondDrawerFragment 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)).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) ViewGroup(android.view.ViewGroup) TextView(android.widget.TextView) DrawerBuilder(com.mikepenz.materialdrawer.DrawerBuilder) TextView(android.widget.TextView) View(android.view.View)

Example 13 with PrimaryDrawerItem

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

the class MiniDrawer method generateMiniDrawerItem.

/**
     * generates a MiniDrawerItem from a IDrawerItem
     *
     * @param drawerItem
     * @return
     */
public IDrawerItem generateMiniDrawerItem(IDrawerItem drawerItem) {
    if (drawerItem instanceof SecondaryDrawerItem) {
        return mIncludeSecondaryDrawerItems ? new MiniDrawerItem((SecondaryDrawerItem) drawerItem).withEnableSelectedBackground(mEnableSelectedMiniDrawerItemBackground) : null;
    } else if (drawerItem instanceof PrimaryDrawerItem) {
        return new MiniDrawerItem((PrimaryDrawerItem) drawerItem).withEnableSelectedBackground(mEnableSelectedMiniDrawerItemBackground);
    } else if (drawerItem instanceof ProfileDrawerItem) {
        MiniProfileDrawerItem mpdi = new MiniProfileDrawerItem((ProfileDrawerItem) drawerItem);
        mpdi.withEnabled(mEnableProfileClick);
        return mpdi;
    }
    return null;
}
Also used : MiniDrawerItem(com.mikepenz.materialdrawer.model.MiniDrawerItem) PrimaryDrawerItem(com.mikepenz.materialdrawer.model.PrimaryDrawerItem) MiniProfileDrawerItem(com.mikepenz.materialdrawer.model.MiniProfileDrawerItem) ProfileDrawerItem(com.mikepenz.materialdrawer.model.ProfileDrawerItem) SecondaryDrawerItem(com.mikepenz.materialdrawer.model.SecondaryDrawerItem) MiniProfileDrawerItem(com.mikepenz.materialdrawer.model.MiniProfileDrawerItem)

Example 14 with PrimaryDrawerItem

use of com.mikepenz.materialdrawer.model.PrimaryDrawerItem in project AppIntro by apl-devs.

the class MainActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    Toolbar tb = (Toolbar) findViewById(R.id.toolbar);
    tb.setTitle(getResources().getString(R.string.app_name));
    tb.setTitleTextColor(Color.parseColor("#FFFFFF"));
    PrimaryDrawerItem item1 = new PrimaryDrawerItem().withIdentifier(1).withName("Home");
    PrimaryDrawerItem item2 = new PrimaryDrawerItem().withIdentifier(2).withName("Permissions");
    new DrawerBuilder().withActivity(this).withHeader(R.layout.util_drawer_hdr).withToolbar(tb).addDrawerItems(item1, item2).withOnDrawerItemClickListener(new Drawer.OnDrawerItemClickListener() {

        @Override
        public boolean onItemClick(View view, int position, IDrawerItem drawerItem) {
            if (drawerItem != null) {
                Fragment fragment = null;
                FragmentManager fragmentManager = getFragmentManager();
                switch((int) drawerItem.getIdentifier()) {
                    case 1:
                        fragment = new MainTabsFragment();
                        break;
                    case 2:
                        fragment = new PermissionTabsFragment();
                        break;
                }
                if (fragment != null) {
                    fragmentManager.beginTransaction().replace(R.id.frame_container, fragment).commit();
                }
                if (drawerItem instanceof Nameable) {
                    setTitle(((Nameable) drawerItem).getName().getText(getApplicationContext()));
                }
            }
            return false;
        }
    }).withShowDrawerOnFirstLaunch(true).withFireOnInitialOnClick(true).withSavedInstance(savedInstanceState).build();
}
Also used : PrimaryDrawerItem(com.mikepenz.materialdrawer.model.PrimaryDrawerItem) IDrawerItem(com.mikepenz.materialdrawer.model.interfaces.IDrawerItem) Drawer(com.mikepenz.materialdrawer.Drawer) View(android.view.View) Fragment(android.app.Fragment) PermissionTabsFragment(com.amqtech.opensource.appintroexample.ui.fragment.PermissionTabsFragment) MainTabsFragment(com.amqtech.opensource.appintroexample.ui.fragment.MainTabsFragment) FragmentManager(android.app.FragmentManager) Nameable(com.mikepenz.materialdrawer.model.interfaces.Nameable) MainTabsFragment(com.amqtech.opensource.appintroexample.ui.fragment.MainTabsFragment) PermissionTabsFragment(com.amqtech.opensource.appintroexample.ui.fragment.PermissionTabsFragment) DrawerBuilder(com.mikepenz.materialdrawer.DrawerBuilder) Toolbar(android.support.v7.widget.Toolbar)

Example 15 with PrimaryDrawerItem

use of com.mikepenz.materialdrawer.model.PrimaryDrawerItem in project Tusky by Vavassor.

the class MainActivity method setupDrawer.

private void setupDrawer() {
    headerResult = new AccountHeaderBuilder().withActivity(this).withSelectionListEnabledForSingleProfile(false).withDividerBelowHeader(false).withOnAccountHeaderProfileImageListener(new AccountHeader.OnAccountHeaderProfileImageListener() {

        @Override
        public boolean onProfileImageClick(View view, IProfile profile, boolean current) {
            if (current && loggedInAccountId != null) {
                Intent intent = new Intent(MainActivity.this, AccountActivity.class);
                intent.putExtra("id", loggedInAccountId);
                startActivity(intent);
                return true;
            }
            return false;
        }

        @Override
        public boolean onProfileImageLongClick(View view, IProfile profile, boolean current) {
            return false;
        }
    }).withCompactStyle(true).build();
    headerResult.getView().findViewById(R.id.material_drawer_account_header_current).setContentDescription(getString(R.string.action_view_profile));
    DrawerImageLoader.init(new AbstractDrawerImageLoader() {

        @Override
        public void set(ImageView imageView, Uri uri, Drawable placeholder) {
            Picasso.with(imageView.getContext()).load(uri).placeholder(placeholder).into(imageView);
        }

        @Override
        public void cancel(ImageView imageView) {
            Picasso.with(imageView.getContext()).cancelRequest(imageView);
        }
    });
    VectorDrawableCompat muteDrawable = VectorDrawableCompat.create(getResources(), R.drawable.ic_mute_24dp, getTheme());
    ThemeUtils.setDrawableTint(this, muteDrawable, R.attr.toolbar_icon_tint);
    drawer = new DrawerBuilder().withActivity(this).withAccountHeader(headerResult).withHasStableIds(true).withSelectedItem(-1).addDrawerItems(new PrimaryDrawerItem().withIdentifier(0).withName(getString(R.string.action_edit_profile)).withSelectable(false).withIcon(GoogleMaterial.Icon.gmd_person), new PrimaryDrawerItem().withIdentifier(1).withName(getString(R.string.action_view_favourites)).withSelectable(false).withIcon(GoogleMaterial.Icon.gmd_star), new PrimaryDrawerItem().withIdentifier(2).withName(getString(R.string.action_view_mutes)).withSelectable(false).withIcon(muteDrawable), new PrimaryDrawerItem().withIdentifier(3).withName(getString(R.string.action_view_blocks)).withSelectable(false).withIcon(GoogleMaterial.Icon.gmd_block), new DividerDrawerItem(), new SecondaryDrawerItem().withIdentifier(4).withName(getString(R.string.action_view_preferences)).withSelectable(false).withIcon(GoogleMaterial.Icon.gmd_settings), new SecondaryDrawerItem().withIdentifier(5).withName(getString(R.string.about_title_activity)).withSelectable(false).withIcon(GoogleMaterial.Icon.gmd_info), new SecondaryDrawerItem().withIdentifier(6).withName(getString(R.string.action_logout)).withSelectable(false).withIcon(GoogleMaterial.Icon.gmd_exit_to_app)).withOnDrawerItemClickListener(new Drawer.OnDrawerItemClickListener() {

        @Override
        public boolean onItemClick(View view, int position, IDrawerItem drawerItem) {
            if (drawerItem != null) {
                long drawerItemIdentifier = drawerItem.getIdentifier();
                if (drawerItemIdentifier == 0) {
                    Intent intent = new Intent(MainActivity.this, EditProfileActivity.class);
                    startActivity(intent);
                } else if (drawerItemIdentifier == 1) {
                    Intent intent = new Intent(MainActivity.this, FavouritesActivity.class);
                    startActivity(intent);
                } else if (drawerItemIdentifier == 2) {
                    Intent intent = new Intent(MainActivity.this, AccountListActivity.class);
                    intent.putExtra("type", AccountListActivity.Type.MUTES);
                    startActivity(intent);
                } else if (drawerItemIdentifier == 3) {
                    Intent intent = new Intent(MainActivity.this, AccountListActivity.class);
                    intent.putExtra("type", AccountListActivity.Type.BLOCKS);
                    startActivity(intent);
                } else if (drawerItemIdentifier == 4) {
                    Intent intent = new Intent(MainActivity.this, PreferencesActivity.class);
                    startActivity(intent);
                } else if (drawerItemIdentifier == 5) {
                    Intent intent = new Intent(MainActivity.this, AboutActivity.class);
                    startActivity(intent);
                } else if (drawerItemIdentifier == 6) {
                    logout();
                } else if (drawerItemIdentifier == 7) {
                    Intent intent = new Intent(MainActivity.this, AccountListActivity.class);
                    intent.putExtra("type", AccountListActivity.Type.FOLLOW_REQUESTS);
                    startActivity(intent);
                }
            }
            return false;
        }
    }).build();
}
Also used : AbstractDrawerImageLoader(com.mikepenz.materialdrawer.util.AbstractDrawerImageLoader) PrimaryDrawerItem(com.mikepenz.materialdrawer.model.PrimaryDrawerItem) IDrawerItem(com.mikepenz.materialdrawer.model.interfaces.IDrawerItem) DividerDrawerItem(com.mikepenz.materialdrawer.model.DividerDrawerItem) Drawable(android.graphics.drawable.Drawable) AccountHeaderBuilder(com.mikepenz.materialdrawer.AccountHeaderBuilder) Intent(android.content.Intent) Drawer(com.mikepenz.materialdrawer.Drawer) ImageView(android.widget.ImageView) BindView(butterknife.BindView) View(android.view.View) FloatingSearchView(com.arlib.floatingsearchview.FloatingSearchView) TextView(android.widget.TextView) Uri(android.net.Uri) VectorDrawableCompat(android.support.graphics.drawable.VectorDrawableCompat) SecondaryDrawerItem(com.mikepenz.materialdrawer.model.SecondaryDrawerItem) ImageView(android.widget.ImageView) IProfile(com.mikepenz.materialdrawer.model.interfaces.IProfile) DrawerBuilder(com.mikepenz.materialdrawer.DrawerBuilder)

Aggregations

PrimaryDrawerItem (com.mikepenz.materialdrawer.model.PrimaryDrawerItem)24 DrawerBuilder (com.mikepenz.materialdrawer.DrawerBuilder)21 View (android.view.View)17 SecondaryDrawerItem (com.mikepenz.materialdrawer.model.SecondaryDrawerItem)17 Toolbar (android.support.v7.widget.Toolbar)16 IDrawerItem (com.mikepenz.materialdrawer.model.interfaces.IDrawerItem)14 SectionDrawerItem (com.mikepenz.materialdrawer.model.SectionDrawerItem)13 Drawer (com.mikepenz.materialdrawer.Drawer)10 ProfileDrawerItem (com.mikepenz.materialdrawer.model.ProfileDrawerItem)9 AccountHeaderBuilder (com.mikepenz.materialdrawer.AccountHeaderBuilder)8 Nameable (com.mikepenz.materialdrawer.model.interfaces.Nameable)8 DividerDrawerItem (com.mikepenz.materialdrawer.model.DividerDrawerItem)7 IProfile (com.mikepenz.materialdrawer.model.interfaces.IProfile)7 BadgeStyle (com.mikepenz.materialdrawer.holder.BadgeStyle)5 Intent (android.content.Intent)4 IconicsDrawable (com.mikepenz.iconics.IconicsDrawable)4 ProfileSettingDrawerItem (com.mikepenz.materialdrawer.model.ProfileSettingDrawerItem)4 ViewGroup (android.view.ViewGroup)3 ImageView (android.widget.ImageView)3 TextView (android.widget.TextView)3