Search in sources :

Example 1 with Crossfader

use of com.mikepenz.crossfader.Crossfader in project MaterialDrawer by mikepenz.

the class MiniDrawerActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_mini_drawer);
    // 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_mini_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"));
    final IProfile profile3 = new ProfileDrawerItem().withName("Max Muster").withEmail("max.mustermann@gmail.com").withIcon(getResources().getDrawable(R.drawable.profile2));
    final IProfile profile4 = new ProfileDrawerItem().withName("Felix House").withEmail("felix.house@gmail.com").withIcon(getResources().getDrawable(R.drawable.profile3));
    final IProfile profile5 = new ProfileDrawerItem().withName("Mr. X").withEmail("mister.x.super@gmail.com").withIcon(getResources().getDrawable(R.drawable.profile4)).withIdentifier(4);
    final IProfile profile6 = new ProfileDrawerItem().withName("Batman").withEmail("batman@gmail.com").withIcon(getResources().getDrawable(R.drawable.profile5));
    // Create the AccountHeader
    headerResult = new AccountHeaderBuilder().withActivity(this).withHeaderBackground(R.drawable.header).withTranslucentStatusBar(false).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(GoogleMaterial.Icon.gmd_plus).withIdentifier(PROFILE_SETTING), new ProfileSettingDrawerItem().withName("Manage Account").withIcon(GoogleMaterial.Icon.gmd_settings)).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 && ((IDrawerItem) profile).getIdentifier() == PROFILE_SETTING) {
                IProfile newProfile = new ProfileDrawerItem().withNameShown(true).withName("Batman").withEmail("batman@gmail.com").withIcon(getResources().getDrawable(R.drawable.profile5));
                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();
    result = new DrawerBuilder().withActivity(this).withToolbar(toolbar).withTranslucentStatusBar(false).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"), new DividerDrawerItem(), new SwitchDrawerItem().withName("Switch").withIcon(Octicons.Icon.oct_tools).withChecked(true).withOnCheckedChangeListener(onCheckedChangeListener), new ToggleDrawerItem().withName("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 instanceof Nameable) {
                Toast.makeText(MiniDrawerActivity.this, ((Nameable) drawerItem).getName().getText(MiniDrawerActivity.this), Toast.LENGTH_SHORT).show();
            }
            return false;
        }
    }).withGenerateMiniDrawer(true).withSavedInstance(savedInstanceState).buildView();
    //the MiniDrawer is managed by the Drawer and we just get it to hook it into the Crossfader
    miniResult = result.getMiniDrawer();
    //get the widths in px for the first and second panel
    int firstWidth = (int) UIUtils.convertDpToPixel(300, this);
    int secondWidth = (int) 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)
    //the crossfader library can be found here: https://github.com/mikepenz/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 a shadow (this is only for normal LTR layouts if you have a RTL app you need to define the other one
    crossFader.getCrossFadeSlidingPaneLayout().setShadowResourceLeft(R.drawable.material_drawer_shadow_left);
}
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) SwitchDrawerItem(com.mikepenz.materialdrawer.model.SwitchDrawerItem) Drawer(com.mikepenz.materialdrawer.Drawer) MiniDrawer(com.mikepenz.materialdrawer.MiniDrawer) View(android.view.View) SecondaryDrawerItem(com.mikepenz.materialdrawer.model.SecondaryDrawerItem) ToggleDrawerItem(com.mikepenz.materialdrawer.model.ToggleDrawerItem) Nameable(com.mikepenz.materialdrawer.model.interfaces.Nameable) SectionDrawerItem(com.mikepenz.materialdrawer.model.SectionDrawerItem) BadgeStyle(com.mikepenz.materialdrawer.holder.BadgeStyle) CrossfadeWrapper(com.mikepenz.materialdrawer.app.utils.CrossfadeWrapper) IProfile(com.mikepenz.materialdrawer.model.interfaces.IProfile) DrawerBuilder(com.mikepenz.materialdrawer.DrawerBuilder) Toolbar(android.support.v7.widget.Toolbar) Crossfader(com.mikepenz.crossfader.Crossfader)

Example 2 with Crossfader

use of com.mikepenz.crossfader.Crossfader 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)

Aggregations

Toolbar (android.support.v7.widget.Toolbar)2 View (android.view.View)2 Crossfader (com.mikepenz.crossfader.Crossfader)2 AccountHeaderBuilder (com.mikepenz.materialdrawer.AccountHeaderBuilder)2 DrawerBuilder (com.mikepenz.materialdrawer.DrawerBuilder)2 CrossfadeWrapper (com.mikepenz.materialdrawer.app.utils.CrossfadeWrapper)2 PrimaryDrawerItem (com.mikepenz.materialdrawer.model.PrimaryDrawerItem)2 ProfileDrawerItem (com.mikepenz.materialdrawer.model.ProfileDrawerItem)2 SecondaryDrawerItem (com.mikepenz.materialdrawer.model.SecondaryDrawerItem)2 SectionDrawerItem (com.mikepenz.materialdrawer.model.SectionDrawerItem)2 IProfile (com.mikepenz.materialdrawer.model.interfaces.IProfile)2 ColorDrawable (android.graphics.drawable.ColorDrawable)1 ImageView (android.widget.ImageView)1 IconicsDrawable (com.mikepenz.iconics.IconicsDrawable)1 Drawer (com.mikepenz.materialdrawer.Drawer)1 MiniDrawer (com.mikepenz.materialdrawer.MiniDrawer)1 BadgeStyle (com.mikepenz.materialdrawer.holder.BadgeStyle)1 DividerDrawerItem (com.mikepenz.materialdrawer.model.DividerDrawerItem)1 ProfileSettingDrawerItem (com.mikepenz.materialdrawer.model.ProfileSettingDrawerItem)1 SwitchDrawerItem (com.mikepenz.materialdrawer.model.SwitchDrawerItem)1