Пример #1
0
        /// <summary>
        /// Called when the pressure sensor's unit is changed.
        /// </summary>
        /// <param name="sender">Sender.</param>
        /// <param name="args">Arguments.</param>
        private void OnPressureUnitChanged(object sender, EventArgs args)
        {
            if (pressureSensor.isEditable)
            {
                var dialog = CommonDialogs.CreateUnitPicker(Strings.Measure.PICK_UNIT, pressureSensor.supportedUnits, (obj, unit) => {
                    pressureUnit = unit;
                    if (pressureSensor != null && pressureSensor.isEditable)
                    {
                        pressureSensor.unit = pressureUnit;
                    }
                    buttonPressureUnit.SetTitle(unit + "", UIControlState.Normal);
                });

                var popover = dialog.PopoverPresentationController;
                if (popover != null)
                {
                    popover.SourceView = View;
                }
                this.PresentViewController(dialog, true, null);
            }
        }
Пример #2
0
        /// <summary>
        /// Called when the temperature sensor's unit is changed.
        /// </summary>
        /// <param name="sender">Sender.</param>
        /// <param name="args">Arguments.</param>
        private void OnTemperatureUnitChanged(object sensor, EventArgs args)
        {
            if (temperatureSensor.isEditable)
            {
                var dialog = CommonDialogs.CreateUnitPicker(Strings.Measure.PICK_UNIT, temperatureSensor.supportedUnits, (obj, unit) => {
                    temperatureUnit = unit;
                    if (temperatureSensor != null && temperatureSensor.isEditable)
                    {
                        temperatureSensor.unit = temperatureUnit;
                    }
                    OnPressureSensorChanged(new SensorEvent(SensorEvent.EType.Invalidated, pressureSensor));
                    buttonTemperatureUnit.SetTitle(unit + "", UIControlState.Normal);
                });

                var popover = dialog.PopoverPresentationController;
                if (popover != null)
                {
                    popover.SourceView = View;
                }
                this.PresentViewController(dialog, true, null);
            }
        }
Пример #3
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();
            buttonPressureUnit.SetBackgroundImage(UIImage.FromBundle("ButtonGold").AsNinePatch(), UIControlState.Normal);
            buttonPressureUnit.TouchUpInside += (object sender, EventArgs e) => {
                if (pressureSensor.isEditable)
                {
                    var dialog = CommonDialogs.CreateUnitPicker(Strings.Measure.PICK_UNIT, pressureSensor.GetSupportedUnits(), (obj, unit) => {
                        pressureUnit = unit;
                    });
                    PresentViewController(dialog, true, null);
                }
            };

            buttonMeasTempUnit.SetBackgroundImage(UIImage.FromBundle("ButtonGold").AsNinePatch(), UIControlState.Normal);
            buttonMeasTempUnit.TouchUpInside += (object sender, EventArgs e) => {
                if (temperatureSensor.isEditable)
                {
                    var dialog = CommonDialogs.CreateUnitPicker(Strings.Measure.PICK_UNIT, temperatureSensor.GetSupportedUnits(), (obj, unit) => {
                        temperatureUnit = unit;
                    });
                    PresentViewController(dialog, true, null);
                }
            };

            switchDewBubble.ValueChanged += (object sender, EventArgs e) => {
                switch ((int)switchDewBubble.SelectedSegment)
                {
                case SECTION_DEW:
                    ptChart = new PTChart(Fluid.State.Dew, ptChart.fluid, ptChart.elevation);
                    labelFluidState.BackgroundColor = new UIColor(Colors.BLUE);
                    break;

                case SECTION_BUBBLE:
                    ptChart = new PTChart(Fluid.State.Bubble, ptChart.fluid, ptChart.elevation);
                    labelFluidState.BackgroundColor = new UIColor(Colors.RED);
                    break;
                }
            };
            switchDewBubble.SelectedSegment = SECTION_DEW;

            ion = AppState.context;

            ptChart           = new PTChart(Fluid.State.Dew, ion.fluidManager.lastUsedFluid);
            pressureSensor    = new Sensor(ESensorType.Pressure, Units.Pressure.PSIG.OfScalar(0), true);
            temperatureSensor = new Sensor(ESensorType.Temperature, Units.Temperature.FAHRENHEIT.OfScalar(0), false);

            NavigationItem.Title = Strings.Fluid.PT_CALCULATOR;
            NavigationItem.RightBarButtonItem = new UIBarButtonItem(Strings.HELP, UIBarButtonItemStyle.Plain, delegate {
                var dialog = new UIAlertView(Strings.HELP, Strings.Fluid.STATE_HELP, null, Strings.OK);
                dialog.Show();
            });

            View.AddGestureRecognizer(new UITapGestureRecognizer(() => {
                editPressure.ResignFirstResponder();
                editMeasTemp.ResignFirstResponder();
            }));

            viewFluidPicker.AddGestureRecognizer(new UITapGestureRecognizer(() => {
                var sb = InflateViewController <FluidManagerViewController>("fluidManagerViewController");
                sb.onFluidSelectedDelegate = OnFluidSelected;
                NavigationController.PushViewController(sb, true);
            }));

            viewPressureSensorPicker.AddGestureRecognizer(new UITapGestureRecognizer(() => {
                var dm                    = InflateViewController <DeviceManagerViewController>("deviceManagerViewController");
                dm.displayFilter          = new SensorTypeFilter(ESensorType.Pressure);
                dm.onSensorReturnDelegate = (GaugeDeviceSensor sensor) => {
                    pressureSensor = sensor;
                };
                NavigationController.PushViewController(dm, true);
            }));

            viewPressureSensorPicker.AddGestureRecognizer(new UILongPressGestureRecognizer(() => {
                pressureSensor = null;
                ClearPressureInput();
            }));

            editPressure.AddTarget((object obj, EventArgs args) => {
                try {
                    if (pressureSensor.isEditable)
                    {
                        var measurement            = pressureUnit.OfScalar(double.Parse(editPressure.Text));
                        pressureSensor.measurement = measurement;
                    }
                } catch (Exception e) {
                    Log.E(this, "Failed to UpdatePressure: invalid string " + editPressure.Text, e);
                    ClearPressureInput();
                }
            }, UIControlEvent.EditingChanged);

            viewMeasTempSensorPicker.AddGestureRecognizer(new UITapGestureRecognizer(() => {
                var dm                    = InflateViewController <DeviceManagerViewController>("deviceManagerViewController");
                dm.displayFilter          = new SensorTypeFilter(ESensorType.Temperature);
                dm.onSensorReturnDelegate = (GaugeDeviceSensor sensor) => {
                    temperatureSensor = sensor;
                };
                NavigationController.PushViewController(dm, true);
            }));

            viewMeasTempSensorPicker.AddGestureRecognizer(new UILongPressGestureRecognizer(() => {
                temperatureSensor = null;
                ClearTemperatureInput();
            }));

            editMeasTemp.AddTarget((object obj, EventArgs args) => {
                try {
                    if (temperatureSensor.isEditable)
                    {
                        var measurement = temperatureUnit.OfScalar(double.Parse(editMeasTemp.Text));
                        temperatureSensor.measurement = measurement;
                    }
                } catch (Exception e) {
                    Log.E(this, "Failed to UpdateTemperature: invalid string " + editMeasTemp.Text + ".", e);
                    ClearTemperatureInput();
                }
            }, UIControlEvent.EditingChanged);
        }
Пример #4
0
        /// <summary>
        /// Initializes the state and the event handlers for the temperature widgets.
        /// </summary>
        private void InitTemperatureWidgets()
        {
            imageTemperatureLock.Image = UIImage.FromBundle("ic_lock");
            viewTemperatureTouchArea.AddGestureRecognizer(new UITapGestureRecognizer(() => {
                if (!temperatureSensorLocked)
                {
                    var dm                    = InflateViewController <DeviceManagerViewController>(VC_DEVICE_MANAGER);
                    dm.displayFilter          = new SensorOfTypeFilter(ESensorType.Temperature);
                    dm.onSensorReturnDelegate = (GaugeDeviceSensor sensor) => {
                        temperatureUnit   = sensor.unit;
                        temperatureSensor = sensor;
                        if (ptSlider != null)
                        {
                            ptSlider.ptScroller.ScrollEnabled = false;
                            ptSlider.setOffsetFromSensorMeasurement(new SensorEvent(SensorEvent.EType.Invalidated, sensor));
                        }
                        InvalidateViewController();
                    };
                    NavigationController.PushViewController(dm, true);
                }
            }));

            viewTemperatureTouchArea.AddGestureRecognizer(new UILongPressGestureRecognizer(() => {
                if (!temperatureSensorLocked)
                {
                    temperatureSensor = null;
                    ClearPressureInput();
                    ClearTemperatureInput();
                    if (ptSlider != null)
                    {
                        ptSlider.ptScroller.ScrollEnabled = true;
                    }
                }
                InvalidateViewController();
            }));

            editTemperature.ShouldReturn += (textField) => {
                textField.ResignFirstResponder();
                return(true);
            };

            editTemperature.AddTarget((object obj, EventArgs args) => {
                if (temperatureSensor == null)
                {
                    temperatureSensor = new ManualSensor(ion.manualSensorContainer, ESensorType.Temperature, AppState.context.preferences.units.DefaultUnitFor(ESensorType.Pressure).OfScalar(0.0), true);
                }

                SetTemperatureMeasurementFromEditText();
            }, UIControlEvent.EditingChanged);

            buttonTemperatureUnit.SetBackgroundImage(UIImage.FromBundle("ButtonGold").AsNinePatch(), UIControlState.Normal);
            buttonTemperatureUnit.TouchUpInside += (object sender, EventArgs e) => {
                if (temperatureSensor == null || temperatureSensor.isEditable)
                {
                    var supportedUnits = temperatureSensor != null ? temperatureSensor.supportedUnits : SensorUtils.DEFAULT_TEMPERATURE_UNITS;
                    var dialog         = CommonDialogs.CreateUnitPicker(Strings.Measure.PICK_UNIT, supportedUnits, (obj, unit) => {
                        temperatureUnit = unit;
                        if (ptSlider != null)
                        {
                            ptSlider.ptView.tempLookup = unit;
                        }
                        if (pressureSensor != null)
                        {
                            entryMode = new SensorEntryMode(this, pressureSensor, temperatureUnit, editPressure, editTemperature);
                        }
                        else
                        {
                            entryMode = new SensorEntryMode(this, temperatureSensor, pressureUnit, editTemperature, editPressure);
                        }
                        SetTemperatureMeasurementFromEditText();
                        if (ptSlider != null)
                        {
                            recalculateSlider(pressureUnit, ptSlider.ptView.tempLookup);
                        }
                    });
                    PresentViewController(dialog, true, null);
                }
            };
        }