コード例 #1
0
        public void FillMenu()
        {
            TableLayout menuLayout = context.FindViewById <TableLayout>(Resource.Id.menu_layout);

            menuLayout.RemoveAllViews();
            menuLayout.SetMinimumWidth(context.Resources.DisplayMetrics.WidthPixels);
            ListMenu.Where((ItemsMenu arg) => arg.Menu_Padre_Id == (localStorage.Get("Parent") ?? "")).AsParallel().ToList().ForEach(menu =>
            {
                TableRow row = new TableRow(context);
                View line    = new View(context);
                line.SetBackgroundColor(Color.LightGray);
                line.SetMinimumWidth(context.Resources.DisplayMetrics.WidthPixels);
                line.SetMinimumHeight(2);
                row.AddView(line);
                menuLayout.AddView(row);
                row = new TableRow(context);

                /*Drawable icon = ContextCompat.GetDrawable(context, context.Resources.GetIdentifier(menu.Image, "mipmap", context.PackageName));
                 * if ((int)Build.VERSION.SdkInt > 22)
                 *  icon.SetTintList(context.GetColorStateList(Resource.Color.comment_pressed));
                 * else
                 *  DrawableCompat.SetTint(icon, ContextCompat.GetColor(context, Resource.Color.comment_pressed));
                 * icon.SetBounds(0, 0, 30, 30);*/
                Button btnMenu = new Button(context)
                {
                    Text          = menu.Label,
                    TextAlignment = TextAlignment.ViewStart
                };
                btnMenu.SetTextColor(Color.White);
                btnMenu.Gravity = GravityFlags.CenterVertical | GravityFlags.Left;
                btnMenu.SetBackgroundColor(Color.Transparent);
                //btnMenu.SetCompoundDrawables(icon, null, null, null);
                btnMenu.Click += delegate
                {
                    Intent intent;
                    switch (menu.Controller)
                    {
                    case "SubMenuActivity":
                        localStorage.Put("Parent", menu.Menu_Id);
                        FillMenu();
                        break;

                    case "LogoutActivity":
                        localStorage.Delete("Usuario_Id"); localStorage.Delete("Usuario_Tipo");
                        context.StartActivity(new Intent(context, typeof(LoginActivity)));
                        context.Finish();
                        break;

                    case "DirectorioActivity":
                        intent = new Intent(context, typeof(DirectorioActivity));
                        intent.PutExtra("Titulo", menu.Label);
                        context.StartActivity(intent); break;

                    case "ComprasActivity":
                        intent = new Intent(context, typeof(ComprasActivity));
                        intent.PutExtra("Titulo", menu.Label);
                        context.StartActivity(intent); break;

                    case "ReservaSalaJuntasActivity":
                        if (new SalasJuntasController().CountReservaciones(localStorage.Get("Usuario_Id"), localStorage.Get("Usuario_Tipo")) > 0)
                        {
                            intent = new Intent(context, typeof(SalaReunionesProgramaActivity));
                        }
                        else
                        {
                            intent = new Intent(context, typeof(ReservacionReunionActivity));
                        }
                        intent.PutExtra("Titulo", menu.Label);
                        context.StartActivity(intent); break;

                    case "RegistroInvitadosActivity":
                        //intent = new Intent(context, typeof(InvitadosActivity));
                        //intent.PutExtra("Titulo", menu.Label);
                        //context.StartActivity(intent);
                        break;

                    case "PerfilActivity":
                        intent = new Intent(context, typeof(PerfilCardActivity));
                        intent.PutExtra("Titulo", menu.Label);
                        intent.PutExtra("Miembro", JsonConvert.SerializeObject(new UsuariosController().GetMemberData(localStorage.Get("Usuario_Id"), localStorage.Get("Usuario_Tipo"))));
                        context.StartActivity(intent);
                        context.Finish();
                        break;

                    case "DatosFacturacionActivity":
                        intent = new Intent(context, typeof(DatosFacturacionActivity));
                        intent.PutExtra("Titulo", menu.Label);
                        context.StartActivity(intent); break;

                    case "AccesoActivity":
                        intent = new Intent(context, typeof(AccesoActivity));
                        intent.PutExtra("Titulo", menu.Label);
                        context.StartActivity(intent); break;

                    case "AboutUsActivity":
                        intent = new Intent(context, typeof(AboutUsActivity));
                        intent.PutExtra("Titulo", menu.Label);
                        context.StartActivity(intent); break;

                    default: break;
                    }
                };
                row.AddView(btnMenu);
                menuLayout.AddView(row);
            });
        }