Ejemplo n.º 1
0
        public void cargarComboNotificador(Context context, View mView)
        {
            try
            {
                //Se crea la instancia del spinner para el combo de provincias
                Spinner mSpinner = mView.FindViewById <Spinner>(Resource.Id.spinnerDialogoSeleccionNotificador);
                ManejoBaseDatos.Abrir();
                ICursor       cursor = ManejoBaseDatos.Seleccionar("SELECT NombreCompleto,CodigoNotificador FROM OficialesNotificadores");
                List <string> data   = new List <string>();

                if (cursor.MoveToFirst())
                {
                    //agregando en lista data los nombres de los notificadores
                    do
                    {
                        data.Add(cursor.GetString(0));
                        codNotificadores.Add(cursor.GetString(1));
                    }while (cursor.MoveToNext());
                }

                cursor.Close();
                Android.Widget.ArrayAdapter <String> adapter;
                adapter          = new Android.Widget.ArrayAdapter <String>(context, Android.Resource.Layout.SimpleSpinnerItem, data);
                mSpinner.Adapter = adapter;
                ManejoBaseDatos.Cerrar();
            }
            catch (Exception ex)
            {
                //Se guarda el error en el log de errores
                //Logs.saveLogError("FragmentMap.cargarComboNotificador " + e.Message + " " + e.StackTrace);
                //Se muestra un mensaje informando el error
                Console.WriteLine("Error cargando spinner: " + ex.ToString());
                Toast.MakeText(context, GetString(Resource.String.MensajeErrorCargaBaseDatos), ToastLength.Long).Show();
            }
        }
Ejemplo n.º 2
0
        void TestNonJavaObjectGenerics(TextView textview)
        {
            var adapter = new Android.Widget.ArrayAdapter <NonJavaObject> (this, textview.Id);
            var item    = new NonJavaObject();

            adapter.Add(item);
            textview.Text += "\n\n" + adapter.GetItem(0).ToString();

            var coll = new JavaDictionary <NonJavaObject, NonJavaObject> ();

            coll.Add(item, item);
            if (!object.ReferenceEquals(item, coll [item]))
            {
                throw new InvalidOperationException("Unable to lookup non-java.lang.Object item in JavaDictionary!");
            }

#if BXC_2147
            Log.Info("*jonp*", "A1");
            var jl1 = new Android.Runtime.JavaList <object>();
            Log.Info("*jonp*", "A2");
            var v1 = new Dictionary <string, object>();
            Log.Info("*jonp*", "A3");
            v1.Add("szLongName", "Bla.pdf");
            Log.Info("*jonp*", "A4");
            jl1.Add(v1);
            Log.Info("*jonp*", "A5");
            var vo1 = jl1 [0];
            Log.Info("*jonp*", "A6={0}", vo1);

            var jl2 = new Android.Runtime.JavaList();
            Log.Info("*jonp*", "B2");
            var v2 = new Dictionary <string, object>();
            Log.Info("*jonp*", "B3");
            v2.Add("szLongName", "Bla.pdf");
            Log.Info("*jonp*", "B4");
            jl2.Add(v2);
            Log.Info("*jonp*", "B5");
            var _vo2 = jl2 [0];                             // Exception
            Log.Info("*jonp*", "B6={0} [{1}]", _vo2, _vo2 != null ? _vo2.GetType().FullName : "<null>");
            var vo2 = (Dictionary <string, object>)jl2 [0]; // Exception
            Log.Info("*jonp*", "B7={0}", vo2);
#endif
        }
Ejemplo n.º 3
0
        protected override void OnCreate(Android.OS.Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            SetContentView(Resource.Layout.activity_settings);
            SetSupportActionBar(FindViewById <Android.Support.V7.Widget.Toolbar>(Resource.Id.toolbar));
            this.SupportActionBar.Title = AppResources.PageTitleSettings;
            this.SupportActionBar.SetDisplayHomeAsUpEnabled(true);
            advertisement = FindViewById <LinearLayout>(Resource.Id.advertisement);
            GrabAd();
            SettingsVM vm           = new SettingsVM();
            var        contentPanel = FindViewById <Android.Widget.LinearLayout>(Resource.Id.contentpanel);
            var        binding      = DataContext <SettingsVM> .FromView(contentPanel);

            binding.VM = vm;
            var chkBoxShowTotal = FindViewById <Android.Widget.CheckBox>(Resource.Id.checkbox_showtotal);

            chkBoxShowTotal.Enabled = false;

            if (UserSettings.Current.SelectedProperties.Any())
            {
                chkBoxShowTotal.Enabled = true;
            }

            binding.Add(Resource.Id.checkbox_showtotal, x => x.ShowTotal);
            binding.Add(Resource.Id.spinner, x => x.TotalOptionsVisibility);
            var spinnerAdapter = new Android.Widget.ArrayAdapter <String>(this, Resource.Layout.item_settings_property, Resource.Id.text, vm.TotalOptions);
            var spinner        = FindViewById <Android.Widget.Spinner>(Resource.Id.spinner);

            spinner.Adapter = spinnerAdapter;
            spinner.SetSelection(spinnerAdapter.GetPosition(vm.SelectedTotal));
            spinner.ItemSelected += (sender, e) => { vm.SelectedTotal = spinner.SelectedItem.ToString(); };
            binding.Add(Resource.Id.checkbox_add_time, x => x.ShowMealTime);

            var mealAdapter = new VMListAdapter <MealSettingsVM>(this, vm.Meals, Resource.Layout.item_settings_meal, null, (b, cvm) =>
            {
                b.Add(Resource.Id.text, x => x.Text);
            });

            var mealspanel = FindViewById <Android.Widget.LinearLayout>(Resource.Id.layout_meals);

            for (int i = 0; i < mealAdapter.Count; i++)
            {
                mealspanel.AddView(mealAdapter.GetView(i, null, mealspanel));
            }

            var nutitionAdapter = new VMListAdapter <GoalLineVM>(this, gvm.Goals, Resource.Layout.item_settings_nutrition, null, (b, cvm) =>
            {
                b.Add(Resource.Id.text, x => x.Text);
                b.Add(Resource.Id.image_remove, (a) => { gvm.DeleteGoal(a); });
            });
            var nutitionspanel = FindViewById <Android.Widget.LinearLayout>(Resource.Id.layout_nutirition);

            for (int i = 0; i < nutitionAdapter.Count; i++)
            {
                nutitionspanel.AddView(nutitionAdapter.GetView(i, null, nutitionspanel));
            }

            gvm.Goals.CollectionChanged += (sender, e) =>
            {
                nutitionspanel.RemoveAllViews();
                for (int i = 0; i < nutitionAdapter.Count; i++)
                {
                    nutitionspanel.AddView(nutitionAdapter.GetView(i, null, nutitionspanel));
                }
            };

            var buttonLine1 = FindViewById <Android.Widget.LinearLayout>(Resource.Id.nutrition_button);
            var button2     = buttonLine1.FindViewById <Android.Widget.TextView>(Resource.Id.text_button1);
            var buttonLine  = FindViewById <Android.Widget.LinearLayout>(Resource.Id.meal_button);
            var button      = buttonLine.FindViewById <Android.Widget.TextView>(Resource.Id.text_button);

            button2.Click += (sender, e) =>
            {
                List <String> options = gvm.NewPropertyOptions;
                var           builder = new Android.Support.V7.App.AlertDialog.Builder(this);
                builder.SetTitle(Resource.String.add_target)
                .SetItems(options.ToArray(), (s, e2) =>
                {
                    Property result = StandardProperty.none;
                    String clicked  = options[e2.Which];
                    foreach (var value in Property.All())
                    {
                        if (value.FullCapitalizedText == clicked)
                        {
                            result = value;
                        }
                    }
                    if (result == StandardProperty.none)
                    {
                        return;
                    }
                    gvm.AddGoal(result);
                });
                builder.Create();
                builder.Show();
            };

            button.Click += (sender, e) =>
            {
                vm.MealsExpanded = true;
                mealspanel.RemoveAllViews();
                buttonLine.Visibility = Android.Views.ViewStates.Gone;

                var meala = new VMListAdapter <MealSettingsVM>(this, vm.Meals, Resource.Layout.item_settings_meal_edit, null, (b, cvm) =>
                {
                    b.Add(Resource.Id.checkbox, x => x.MealSelected);
                    b.Add(Resource.Id.checkbox, x => x.CheckboxVisibility);
                    b.Add(Resource.Id.checkbox, x => x.CheckboxEnabled, "Enabled");
                    b.Add(Resource.Id.edit_meal_name, x => x.Text);
                });

                for (int i = 0; i < meala.Count; i++)
                {
                    mealspanel.AddView(meala.GetView(i, null, mealspanel));
                }
            };

            contentPanel.AddView(Android.Views.View.Inflate(this, Resource.Layout.item_settings_reminder_top, null));

            var reminderAdapter = new VMListAdapter <ReminderVM>(this, vm.Reminders, Resource.Layout.item_settings_reminder, null, (b, cvm) =>
            {
                b.Add(Resource.Id.checkbox, x => x.Checked);
                b.Add(Resource.Id.settings_set_time, x => x.Time);
                b.Add(Resource.Id.settings_set_time, (a) =>
                {
                    DateTime current;
                    if (!DateTime.TryParse(a.Time, out current))
                    {
                        current = DateTime.Now;
                    }
                    var tpd = new Android.App.TimePickerDialog(this,
                                                               (s, e) => { a.Time = DateTime.Now.SetTime(e.HourOfDay, e.Minute, 0).ToShortTimeString(); }
                                                               , current.Hour, current.Minute, true);
                    tpd.Show();
                });
                b.Add(Resource.Id.image_remove, (a) => { a.Delete(); });
                b.Add(Resource.Id.image_remove, x => x.DeleteVisibility);
            });

            var reminderspanel = FindViewById <Android.Widget.LinearLayout>(Resource.Id.layout_reminders);

            for (int i = 0; i < reminderAdapter.Count; i++)
            {
                reminderspanel.AddView(reminderAdapter.GetView(i, null, reminderspanel));
            }

            var buttonLine2 = Android.Views.View.Inflate(this, Resource.Layout.item_settings_add_reminder, null);

            button = buttonLine2.FindViewById <Android.Widget.TextView>(Resource.Id.text_button);
            contentPanel.AddView(buttonLine2);

            button.Click += (sender, e) =>
            {
                var tpd = new Android.App.TimePickerDialog(this,
                                                           (s, e2) => { vm.AddReminder(DateTime.Now.SetTime(e2.HourOfDay, e2.Minute, 0)); }
                                                           , DateTime.Now.Hour, 0, true);
                tpd.Show();
            };

            vm.Reminders.CollectionChanged += (sender, e) =>
            {
                reminderspanel.RemoveAllViews();
                for (int i = 0; i < reminderAdapter.Count; i++)
                {
                    reminderspanel.AddView(reminderAdapter.GetView(i, null, reminderspanel));
                }
            };

#if DEBUG
            AndroidDebug.SetViewBorders(contentPanel);
#endif
#if SCREENSHOT
            Navigate.screenshotScreen = this;
#endif
        }
Ejemplo n.º 4
0
        public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
        {
            var      ignored             = base.OnCreateView(inflater, container, savedInstanceState);
            View     self                = inflater.Inflate(Resource.Layout.CommonReportInput, null);
            TextView info                = self.FindViewById <TextView>(Resource.Id.textViewReportInputInfo);
            Spinner  spinner_oficina     = self.FindViewById <Spinner>(Resource.Id.spinnerInputOficina);
            Spinner  spinner_despacho    = self.FindViewById <Spinner>(Resource.Id.spinnerInputDespacho);
            Spinner  spinner_notificador = self.FindViewById <Spinner>(Resource.Id.spinnerInputNotificador);
            TextView fecha_inicio        = self.FindViewById <TextView>(Resource.Id.textViewInputFechaInicio);
            TextView fecha_fin           = self.FindViewById <TextView>(Resource.Id.textViewInputFechaFin);
            TextView fecha_jornada       = self.FindViewById <TextView>(Resource.Id.textViewInputFechaJornada);

            // Oculta/Muestra los parametros de entrada que no corresponden al
            // reporte/perfil de usuario
            bool es_supervisor = false;

            try
            {
                string es_supervisor_str = "False";
                Helpers.SQLiteConeccion dbConeccion;
                dbConeccion = new Helpers.SQLiteConeccion();
                dbConeccion.consultaDatos("SELECT Supervisor FROM OficialNotificador", this.Activity, ref es_supervisor_str);
                es_supervisor = (String.Compare("True", es_supervisor_str, true) == 0);
            }
            catch (Exception e)
            {
                //Se guarda el error en el log de errores
                Logs.saveLogError("NotificacionesEnviadasADespachoInputReport.OnCreateView " + e.Message + " " + e.StackTrace);
                //Se muestra un mensaje informando el error
                Toast.MakeText(this.Context, GetString(Resource.String.MensajeErrorCargaBaseDatos), ToastLength.Long).Show();
            }

            self.FindViewById <LinearLayout>(Resource.Id.linearLayoutInputOficina).Visibility      = sel_oficina ? ViewStates.Visible : ViewStates.Gone;
            self.FindViewById <LinearLayout>(Resource.Id.linearLayoutInputNotificador).Visibility  = (sel_notificador && es_supervisor) ? ViewStates.Visible : ViewStates.Gone;
            self.FindViewById <LinearLayout>(Resource.Id.linearLayoutInputDespacho).Visibility     = sel_despacho ? ViewStates.Visible : ViewStates.Gone;
            self.FindViewById <LinearLayout>(Resource.Id.linearLayoutInputFechaInicio).Visibility  = sel_fecha_inicio ? ViewStates.Visible : ViewStates.Gone;
            self.FindViewById <LinearLayout>(Resource.Id.linearLayoutInputFechaFin).Visibility     = sel_fecha_fin ? ViewStates.Visible : ViewStates.Gone;
            self.FindViewById <LinearLayout>(Resource.Id.linearLayoutInputFechaJornada).Visibility = sel_fecha_jornada ? ViewStates.Visible : ViewStates.Gone;

            // Cargar los valores que se tengan del ultimo reporte
            fecha_inicio.Text  = report.input_fecha_inicio.ToString("yyyy-MMM-dd");
            fecha_fin.Text     = report.input_fecha_fin.ToString("yyyy-MMM-dd");
            fecha_jornada.Text = report.input_fecha_jornada.ToString("yyyy-MMM-dd");

            // FIXME: Poner el mensaje de error en un mejor lugar
            if (String.IsNullOrEmpty(report.output_error))
            {
                info.Text = "Datos de entrada para Reporte: " + report.ToString();
            }
            else
            {
                info.Text           = report.output_error;
                report.output_error = null;
            }

            // Accion para el botón de generar reporte
            Button btnGen = self.FindViewById <Button>(Resource.Id.btnGenerarReporte);

            btnGen.Click += (sender, e) => {
                Fragment frag = report.getOutputReportFragment();
                // Asigna los parámetros de entrada (las fechas se assignan en OnDateSet)
                report.input_oficina  = "0534"; // FIXME. El valor esta harc
                report.input_despacho = (string)spinner_despacho.SelectedItem;
                if (sel_notificador)
                {
                    if (es_supervisor)
                    {
                        report.input_notificador = (string)spinner_notificador.SelectedItem;
                    }
                    else
                    {
                        try
                        {
                            Helpers.SQLiteConeccion dbConeccion;
                            dbConeccion = new Helpers.SQLiteConeccion();
                            dbConeccion.consultaDatos("SELECT NombreCompleto FROM OficialNotificador", this.Activity, ref report.input_notificador);
                        }
                        catch (Exception ex)
                        {
                            //Se guarda el error en el log de errores
                            Logs.saveLogError("NotificacionesEnviadasADespachoInputReport.OnCreateView " + ex.Message + " " + ex.StackTrace);
                            //Se muestra un mensaje informando el error
                            Toast.MakeText(this.Context, GetString(Resource.String.MensajeErrorCargaBaseDatos), ToastLength.Long).Show();
                            report.input_notificador = "";
                        }
                    }
                }

                FragmentManager.BeginTransaction().Replace(Resource.Id.content_frame, frag).Commit();
            };

            // Spinner con oficinas
            if (sel_oficina)
            {
                Android.Widget.ArrayAdapter <String> ad;
                ad = new Android.Widget.ArrayAdapter <String>(
                    this.Context, Android.Resource.Layout.SimpleSpinnerItem,
                    new string[] { Fragments.FragmentLogin.codOficina, "0534" }); // FIXME El valor de la oficina esta hardcoded
                spinner_oficina.Adapter = ad;
            }

            // Spinner con notificadores
            if (sel_notificador && es_supervisor)
            {
                try
                {
                    Helpers.SQLiteConeccion dbConeccion;
                    dbConeccion = new Helpers.SQLiteConeccion();
                    dbConeccion.setAdaptadorCombo("SELECT NombreCompleto FROM OficialesNotificadores", this.Activity, ref spinner_notificador);
                }
                catch (Exception e)
                {
                    //Se guarda el error en el log de errores
                    Logs.saveLogError("FragmentMap.cargarComboNotificador " + e.Message + " " + e.StackTrace);
                    //Se muestra un mensaje informando el error
                    Toast.MakeText(this.Context, GetString(Resource.String.MensajeErrorCargaBaseDatos), ToastLength.Long).Show();
                }
            }

            // Spinner con despachos
            if (sel_despacho)
            {
                Android.Widget.ArrayAdapter <String> adapter;
                adapter = new Android.Widget.ArrayAdapter <String>(
                    this.Context, Android.Resource.Layout.SimpleSpinnerItem,
                    new string[] { Fragments.FragmentLogin.codOficina, "0163" }); // FIXME El valor del despacho esta hardcoded
                spinner_despacho.Adapter = adapter;
            }

            // Fecha inicio
            if (sel_fecha_inicio)
            {
                DatePickerDialogFragment fecha_inicio_picker = new DatePickerDialogFragment(Activity, DateTime.Now, this, "inicio");
                fecha_inicio.Click += (sender, args) =>
                {
                    fecha_inicio_picker.Show(FragmentManager, null);
                };
            }

            // Fecha fin
            if (sel_fecha_fin)
            {
                DatePickerDialogFragment fecha_fin_picker = new DatePickerDialogFragment(Activity, DateTime.Now, this, "fin");
                fecha_fin.Click += (sender, args) =>
                {
                    fecha_fin_picker.Show(FragmentManager, null);
                };
            }

            // Fecha jornada
            if (sel_fecha_jornada)
            {
                DatePickerDialogFragment fecha_jornada_picker = new DatePickerDialogFragment(Activity, DateTime.Now, this, "jornada");
                fecha_jornada.Click += (sender, args) =>
                {
                    fecha_jornada_picker.Show(FragmentManager, null);
                };
            }

            return(self);
        }