Esempio n. 1
0
        // Inicializa o itemUtilizador e o cabecalhoDrawer cabeçalho do "drawer" lateral.
        private void InicializarCabecalho(string email, Bundle estadoGravado)
        {
            itemUtilizador = new ProfileDrawerItem();
            itemUtilizador.WithName(email.Equals("") ? "Não Autenticado" : "Email");
            itemUtilizador.WithIcon(Resource.Drawable.profile3);
            itemUtilizador.WithIdentifier(email.Equals("") ? PERFIL_NAO_AUTENTICADO : AUTENTICADO);
            if (!email.Equals(""))
            {
                itemUtilizador.WithEmail(email);
            }

            cabecalhoDrawer = new AccountHeaderBuilder()
                              .WithActivity(this)
                              .WithHeaderBackground(Resource.Drawable.header)
                              .AddProfiles(itemUtilizador)
                              .WithSelectionListEnabledForSingleProfile(false)
                              .WithOnAccountHeaderListener(this)
                              .WithSavedInstance(estadoGravado)
                              .Build();
        }
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            SetContentView(Resource.Layout.activity_sample_dark_toolbar);

            var toolbar = this.FindViewById <Android.Support.V7.Widget.Toolbar>(Resource.Id.toolbar);

            this.SetSupportActionBar(toolbar);

            // Create a few sample profile
            // NOTE you have to define the loader logic too. See the CustomApplication for more details

            var profile = new ProfileDrawerItem();

            profile.WithName("Mike Penz");
            profile.WithEmail("*****@*****.**");
            profile.WithIcon("https://avatars3.githubusercontent.com/u/1476232?v=3&s=460");
            profile.WithIdentifier(100);

            var profile2 = new ProfileDrawerItem();

            profile2.WithName("Bernat Borras");
            profile2.WithEmail("*****@*****.**");
            profile2.WithIcon(Uri.Parse("https://avatars3.githubusercontent.com/u/887462?v=3&s=460"));
            profile2.WithIdentifier(101);

            var profile3 = new ProfileDrawerItem();

            profile3.WithName("Max Muster");
            profile3.WithEmail("*****@*****.**");
            profile3.WithIcon(Resource.Drawable.profile2);
            profile3.WithIdentifier(102);

            var profile4 = new ProfileDrawerItem();

            profile4.WithName("Felix House");
            profile4.WithEmail("*****@*****.**");
            profile4.WithIcon(Resource.Drawable.profile3);
            profile4.WithIdentifier(103);

            var profile5 = new ProfileDrawerItem();

            profile5.WithName("Mr. X");
            profile5.WithEmail("*****@*****.**");
            profile5.WithIcon(Resource.Drawable.profile4);
            profile5.WithIdentifier(104);

            var profile6 = new ProfileDrawerItem();

            profile6.WithName("Batman");
            profile6.WithEmail("*****@*****.**");
            profile6.WithIcon(Resource.Drawable.profile5);
            profile6.WithIdentifier(105);

            var profileSettingItem = new ProfileSettingDrawerItem();

            profileSettingItem.WithName("Add Account");
            profileSettingItem.WithDescription("Add new GitHub Account");
            profileSettingItem.WithIcon(new IconicsDrawable(this, GoogleMaterial.Icon.GmdPlusOne).ActionBar().PaddingDp(5).ColorRes(Resource.Color.material_drawer_primary_text));
            profileSettingItem.WithIdentifier(PROFILE_SETTING);

            headerResult = new AccountHeaderBuilder()
                           .WithActivity(this)
                           .WithHeaderBackground(Resource.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)
                profileSettingItem,
                new ProfileSettingDrawerItem()
                .WithName("Manage Account")
                .WithIcon(GoogleMaterial.Icon.GmdSettings)
                )
                           .WithOnAccountHeaderListener(this)
                           .WithSavedInstance(savedInstanceState)
                           .Build();

            var item1 = new PrimaryDrawerItem();

            item1.WithName(Resource.String.drawer_item_compact_header);
            item1.WithIcon(GoogleMaterial.Icon.GmdWbSunny);
            item1.WithIdentifier(1);
            item1.WithSelectable(false);
//
            var item2 = new PrimaryDrawerItem();

            item2.WithName(Resource.String.drawer_item_action_bar_drawer);
            item2.WithIcon(FontAwesome.Icon.FawHome);
            item2.WithIdentifier(2);
            item2.WithSelectable(false);
//
            var item10 = new SecondaryDrawerItem();

            item10.WithName(Resource.String.drawer_item_open_source);
            item10.WithIcon(FontAwesome.Icon.FawGithub);
            item10.WithIdentifier(20);
            item10.WithSelectable(false);
//
            var item11 = new SecondaryDrawerItem();

            item11.WithName(Resource.String.drawer_item_contact);
            item11.WithIcon(GoogleMaterial.Icon.GmdFormatColorFill);
            item11.WithIdentifier(10);
            item11.WithTag("Bullhorn");

//
            result = new DrawerBuilder()
                     .WithActivity(this)
                     .WithToolbar(toolbar)
                     .WithAccountHeader(headerResult) //set the AccountHeader we created earlier for the header
                     .AddDrawerItems(
                item1,
                item2,
                new SectionDrawerItem().WithName(Resource.String.drawer_item_section_header),
                item10,
                item11,
                new DividerDrawerItem()
                ) // add the items we want to use With our Drawer
                     .WithOnDrawerItemClickListener(this)
                     .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.Instance.WithCacheSize(2).Init(result);

            //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, false);
            }

            result.UpdateBadge(4, new StringHolder(10 + ""));
        }