public void Show(Context context)
        {
            var adb = new IONAlertDialog(context);

            var view  = LayoutInflater.From(context).Inflate(Resource.Layout.dialog_rename, null, false);
            var entry = view.FindViewById <EditText>(Resource.Id.name);

            entry.Hint = renamable.defaultName;
            entry.Text = renamable.name;

            adb.SetTitle(Resource.String.rename);
            adb.SetMessage(renamable.GetRenameMessage(context));
            adb.SetView(view);

            adb.SetNegativeButton(Resource.String.cancel, (obj, e) => {
                var dialog = obj as Dialog;
                dialog.Dismiss();
            });

            adb.SetPositiveButton(Resource.String.ok_done, (obj, e) => {
                var dialog = obj as Dialog;
                dialog.Dismiss();

                if (string.IsNullOrEmpty(entry.Text.Trim()))
                {
                    renamable.name = renamable.defaultName;
                }
                else
                {
                    renamable.name = entry.Text;
                }
            });

            adb.Show();
        }
Beispiel #2
0
        public Android.App.Dialog Show(Action <Sensor> onSensorCreated)
        {
            var adb = new IONAlertDialog(context);

            adb.SetTitle(Resource.String.sensor_create_manual_entry);
            adb.SetView(content);

            var ret = adb.Show();

            content.FindViewById(Resource.Id.cancel).Click += (sender, e) => {
                ret.Dismiss();
            };

            content.FindViewById(Resource.Id.ok_done).Click += (sender, e) => {
                double d;

                if (!double.TryParse(measurement.Text, out d))
                {
                    Toast.MakeText(context, Resource.String.please_enter_valid_number, ToastLength.Long).Show();
                    return;
                }

                var sensor = new ManualSensor(sensorType, sensorType == ESensorType.Vacuum);
                sensor.measurement = sensorUnit.OfScalar(d);
                sensor.name        = name.Text;
                onSensorCreated(sensor);

                ret.Dismiss();
            };

            return(ret);
        }
Beispiel #3
0
        public Dialog Show()
        {
            var item = rss.channels[0].items[rss.channels[0].items.Count - 1];

            var view = LayoutInflater.From(context).Inflate(Resource.Layout.dialog_rss, null);

            var title   = view.FindViewById <TextView>(Resource.Id.title);
            var content = view.FindViewById <TextView>(Resource.Id.content);

            title.Text   = item.title;
            content.Text = Html.FromHtml(item.description).ToString();

            var adb = new IONAlertDialog(context);

            adb.SetPositiveButton(Resource.String.open, (sender, e) => {
                var uri    = Android.Net.Uri.Parse(item.link);
                var intent = new Intent();
                intent.SetData(uri);
                intent.AddFlags(ActivityFlags.NewTask);
                context.StartActivity(intent);
            });
            adb.SetNegativeButton(Resource.String.close, (sender, e) => {
            });

            adb.SetTitle(Resource.String.rss);
            adb.SetView(view);
            var ret = adb.Create();

            ret.Show();
            return(ret);
        }
        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());
        }
        /// <summary>
        /// Shows the dialog to the user.
        /// </summary>
        public Dialog Show(bool showVersion = false)
        {
            var view = LayoutInflater.From(context).Inflate(Resource.Layout.dialog_whats_new, null, false);

            var content  = view.FindViewById <TextView>(Resource.Id.content);
            var checkbox = view.FindViewById <CheckBox>(Resource.Id.checkbox);

            checkbox.CheckedChange += (sender, e) => {
                prefs.showWhatsNew = e.IsChecked;
            };

            var adb = new IONAlertDialog(context);

            adb.SetTitle(string.Format(context.GetString(Resource.String.whats_new_in), currentVersion));
            adb.SetView(view);

            adb.SetNegativeButton(Resource.String.ok_done, (obj, e) => {
                var dialog = obj as Dialog;
                dialog.Dismiss();
            });

            var ret = adb.Show();

            Task.Factory.StartNew(() => {
                var sb = new StringBuilder();

                var news = new List <WhatsNew>();
                news.AddRange(WhatsNew.ParseWithException(context.Resources.GetXml(Resource.Xml.whats_new)));
                news.AddRange(WhatsNew.ParseWithException(context.Resources.GetXml(Resource.Xml.whats_new_history)));

                // Trim the unnecessary versions.
                for (int i = news.Count - 1; i >= 0; i--)
                {
                    if (news[i].versionCode.CompareTo(oldVersion) < 0 || news[i].versionCode.CompareTo(currentVersion) > 0)
                    {
                        news.RemoveAt(i);
                    }
                }

                if (showVersion)
                {
                    PrintIndividualUpdates(news, sb);
                }
                else
                {
                    PrintCollapsedUpdates(news, sb);
                }


                handler.Post(() => {
                    Appion.Commons.Util.Log.D(this, "Posting: " + sb.ToString());
                    content.TextFormatted = Html.FromHtml(sb.ToString());
                });
            });

            return(ret);
        }
Beispiel #6
0
        /// <summary>
        /// Creates a new UnitDialog that will allow the user to select a unit.
        /// </summary>
        /// <param name="context">Context.</param>
        /// <param name="units">Units.</param>
        public static AlertDialog Create(Context context, IEnumerable <Unit> units, EventHandler <Unit> unitSelectionEvent)
        {
            var adb = new IONAlertDialog(context);

            adb.SetTitle(Resource.String.pick_unit);
            adb.SetItems(UnitsToString(units), (obj, args) => {
                unitSelectionEvent(adb, units.ElementAt(args.Which));
            });
            adb.SetCancelable(true);

            return(adb.Create());
        }
Beispiel #7
0
        /// <summary>
        /// Shows the dialog.
        /// </summary>
        /// <param name="context">Context.</param>
        public AlertDialog Show(Context context)
        {
            var adb = new IONAlertDialog(context);

            adb.SetTitle(title);
            adb.SetMessage(message);

            var entry = new EditText(context);

            entry.Hint      = hint;
            entry.Text      = initialValue + "";
            entry.InputType = Android.Text.InputTypes.NumberFlagDecimal;

            adb.SetView(entry);

            AlertDialog ret = null;

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

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

                try {
                    if (string.IsNullOrEmpty(entry.Text))
                    {
                        handler(ret, 0);
                    }
                    else
                    {
                        var number = double.Parse(entry.Text);
                        if (handler != null)
                        {
                            handler(ret, number);
                        }
                    }
                    dialog.Dismiss();
                } catch (Exception) {
                    Toast.MakeText(context, Resource.String.please_enter_valid_number, ToastLength.Long).Show();
                }
            });

            ret = adb.Create();

            ret.Show();
            return(ret);
        }
Beispiel #8
0
        /// <summary>
        /// Shows the dialog.
        /// </summary>
        /// <param name="context">Context.</param>
        public AlertDialog Show(Context context)
        {
            var view = LayoutInflater.From(context).Inflate(Resource.Layout.dialog_date_time, null);

            var date = view.FindViewById <DatePicker>(Resource.Id.date);
            var time = view.FindViewById <TimePicker>(Resource.Id.time);

            var hours   = 0;
            var minutes = 0;

            time.TimeChanged += (sender, e) => {
                hours   = e.HourOfDay;
                minutes = e.Minute;
            };

            date.MinDate           = start.ToUTCMilliseconds();
            date.MaxDate           = end.ToUTCMilliseconds();
            date.CalendarViewShown = false;

            var adb = new IONAlertDialog(context);

            adb.SetTitle(title);
            adb.SetView(view);
            adb.SetNegativeButton(context.GetString(Resource.String.cancel), (obj, args) => {
                var dialog = obj as Android.App.Dialog;
                dialog.Dismiss();
            });

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

                var dateTime = date.DateTime;
                dateTime     = dateTime.AddHours(hours);
                dateTime     = dateTime.AddMinutes(minutes);

                if (handler != null)
                {
                    handler(obj, dateTime);
                }
            });

            return(adb.Show());
        }
Beispiel #9
0
        public static Dialog ShowDialog(Context context, string title, string message, Action positive, Action negative = null)
        {
            var adb = new IONAlertDialog(context, title);

            adb.SetMessage(message);

            adb.SetNegativeButton(Resource.String.cancel, (sender, e) => {
                (sender as Dialog).Dismiss();
                if (negative != null)
                {
                    negative();
                }
            });

            adb.SetPositiveButton(Resource.String.ok, (sender, e) => {
                (sender as Dialog).Dismiss();
                positive();
            });

            return(adb.Show());
        }
        public Android.App.Dialog Show()
        {
            var r = context.Resources;

            var view  = LayoutInflater.From(context).Inflate(Resource.Layout.analyzer_dialog_viewer, null);
            var state = view.FindViewById <TextView>(Resource.Id.state);

            switch (side)
            {
            case Analyzer.ESide.High:
                state.SetText(Resource.String.analyzer_side_high);
                state.SetBackgroundColor(Resource.Color.red.AsResourceColor(context));
                state.SetTextColor(Resource.Color.white.AsResourceColor(context));
                break;

            case Analyzer.ESide.Low:
                state.SetText(Resource.String.analyzer_side_low);
                state.SetBackgroundColor(Resource.Color.blue.AsResourceColor(context));
                state.SetTextColor(Resource.Color.white.AsResourceColor(context));
                break;

            default:
                state.SetText(Resource.String.analyzer_side_none);
                state.SetBackgroundColor(Resource.Color.white.AsResourceColor(context));
                state.SetTextColor(Resource.Color.black.AsResourceColor(context));
                break;
            }

            var template = new ManifoldViewTemplate(view, cache);

            template.Bind(new Manifold(sensor));

            var adb = new IONAlertDialog(context);

            adb.SetTitle(sensor.name);
            adb.SetView(view);

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

            if (analyzer.isEditable)
            {
                adb.SetPositiveButton(Resource.String.actions, (sender, e) => {
                    var ldb = new ListDialogBuilder(context);
                    ldb.SetTitle(string.Format(context.GetString(Resource.String.devices_actions_1arg), sensor.name));

                    var dgs = sensor as GaugeDeviceSensor;

                    if (dgs != null && !dgs.device.isConnected)
                    {
                        ldb.AddItem(Resource.String.reconnect, () => {
                            dgs.device.connection.Connect();
                        });
                    }

                    ldb.AddItem(Resource.String.rename, () => {
                        if (sensor is GaugeDeviceSensor)
                        {
                            var gds = sensor as GaugeDeviceSensor;
                            new RenameDialog(gds.device).Show(context);
                        }
                        else
                        {
                            new RenameDialog(sensor).Show(context);
                        }
                    });

                    ldb.AddItem(Resource.String.alarm, () => {
                        var i = new Intent(context, typeof(SensorAlarmActivity));
                        i.PutExtra(SensorAlarmActivity.EXTRA_SENSOR, sensor.ToParcelable());
                        context.StartActivity(i);
                    });

                    if (dgs != null && dgs.device.isConnected)
                    {
                        ldb.AddItem(Resource.String.disconnect, () => {
                            dgs.device.connection.Disconnect();
                        });
                    }

                    ldb.AddItem(Resource.String.remove, () => {
                        analyzer.RemoveSensor(sensor);
                    });

                    ldb.Show();
                    cache.Clear();
                });
            }

            return(adb.Show());
        }