public Android.App.Dialog Show()
        {
            var view = LayoutInflater.From(context).Inflate(Resource.Layout.dialog_manual_sensor_edit, null);

            var title       = view.FindViewById <TextView>(Resource.Id.title);
            var name        = view.FindViewById <EditText>(Resource.Id.name);
            var measurement = view.FindViewById <EditText>(Resource.Id.measurement);
            var button      = view.FindViewById <Button>(Resource.Id.unit);

            var unit = sensor.unit;

            button.Text = unit.ToString();

            if (sensor != null)
            {
                name.Text        = sensor.name;
                measurement.Text = SensorUtils.ToFormattedString(sensor.measurement);
            }

            button.SetOnClickListener(new ViewClickAction((v) => {
                UnitDialog.Create(context, sensor.supportedUnits, (obj, u) => {
                    unit        = u;
                    button.Text = unit.ToString();
                }).Show();
            }));

            var adb = new IONAlertDialog(context);

            adb.SetTitle(Resource.String.edit_manual_entry);
            adb.SetView(view);

            adb.SetNegativeButton(Resource.String.cancel, (obj, args) => {
                var d = obj as Android.App.Dialog;
                d.Dismiss();
            });

            adb.SetPositiveButton(Resource.String.ok_done, (obj, args) => {
                var d = obj as Android.App.Dialog;

                try {
                    sensor.name = name.Text;

                    var meas           = double.Parse(measurement.Text);
                    sensor.measurement = unit.OfScalar(meas);

                    if (action != null)
                    {
                        action(d, sensor);
                    }

                    d.Dismiss();
                } catch (Exception e) {
                    Log.E(this, "Failed to edit manual sensor", e);
                    Toast.MakeText(context, Resource.String.please_enter_valid_number, ToastLength.Long).Show();
                }
            });

            return(adb.Show());
        }
Exemple #2
0
        public ManualSensorCreateDialog(Context context, Dictionary <ESensorType, IEnumerable <Unit> > options)
        {
            this.context = context;
            this.options = options;

            try {
                if (Build.VERSION.SdkInt < BuildVersionCodes.Lollipop)
                {
                    content = LayoutInflater.From(context).Inflate(Resource.Layout.dialog_manual_sensor_create_4_4, null, false);
                }
                else
                {
                    content = LayoutInflater.From(context).Inflate(Resource.Layout.dialog_manual_sensor_create, null, false);
                }
            } catch (Exception e) {
                Log.E(this, "Failed to set layout. Defaulting to old version", e);
                content = LayoutInflater.From(context).Inflate(Resource.Layout.dialog_manual_sensor_create_4_4, null, false);
            }

            name        = content.FindViewById <EditText>(Resource.Id.name);
            measurement = content.FindViewById <EditText>(Resource.Id.measurement);

            type = content.FindViewById <Button>(Resource.Id.type);
            unit = content.FindViewById <Button>(Resource.Id.unit);

            sensorType = options.Keys.First();
            sensorUnit = options[sensorType].First();
            type.Text  = sensorType.GetTypeString();
            unit.Text  = sensorUnit.ToString();

            type.Click += (sensor, obj) => {
                var dialog = new ListDialogBuilder(context);
                dialog.SetTitle(Resource.String.sensor_select_type);

                foreach (var t in options.Keys)
                {
                    dialog.AddItem(t.GetTypeString(), () => {
                        sensorType = t;
                        type.Text  = t.GetTypeString();

                        sensorUnit = options[sensorType].First();
                        unit.Text  = sensorUnit.ToString();
                    });
                }

                dialog.Show();
            };

            unit.Click += (sender, e) => {
                UnitDialog.Create(context, options[sensorType], (s1, e1) => {
                    sensorUnit = e1;
                    unit.Text  = sensorUnit.ToString();
                }).Show();
            };
        }