Esempio n. 1
0
        /// <summary>
        /// Handles all the data passed from the past activity
        /// </summary>
        private async void HandlePassedData()
        {
            LinearLayout Layout = FindViewById <LinearLayout>(Resource.Id.DetailLinearLayout);

            Layout.SetPadding(20, 20, 20, 20);

            // Device name
            TextView _textViewRoom = new TextView(this);

            _textViewRoom.Text = _device.Name;
            _textViewRoom.SetTypeface(null, Android.Graphics.TypefaceStyle.Bold);
            _textViewRoom.SetTextSize(Android.Util.ComplexUnitType.Sp, 24);

            Layout.AddView(_textViewRoom);

            switch (_device.DataType)
            {
            case "slider":
                // Device data
                SeekBar _seekBar = new SeekBar(this);
                _seekBar.SetMinimumWidth(1000);

                _textView = new TextView(this);
                _textView.SetMinimumWidth(1000);

                float value = 0;
                _seekBar.Progress = (int)value;
                string Response = (await Server.Request.PostCommand(Intent.GetStringExtra("room") + " " + _device.Keyword)).Value;

                float.TryParse(Response.Substring(1, Response.Length - 3), out value);

                _seekBar.Progress = (int)value;
                _textView.Text    = string.Format("Value: {0}", (int)value);

                // Assign this class as a listener for the SeekBar events
                _seekBar.SetOnSeekBarChangeListener(this);

                Layout.AddView(_seekBar);
                Layout.AddView(_textView);
                break;

            case "toggle":
                // Device data
                ToggleButton _toggleButton = new ToggleButton(this);

                string _room       = Intent.GetStringExtra("room");
                string CheckString = (await Server.Request.PostCommand(string.Format("{0} {1}", _room, _device.Keyword))).Value;
                _toggleButton.Checked = (CheckString.Equals("on"));

                _toggleButton.CheckedChange += async delegate
                {
                    // Post to server
                    string Toggle = (_toggleButton.Checked) ? "on" : "off";

                    string Formatted = string.Format("{0} {1} {2}", _room, _device.Keyword, Toggle);
                    logger.Debug("Sending put to server: " + Formatted);
                    await Server.Request.PostCommand(Formatted);
                };

                Layout.AddView(_toggleButton);
                break;
            }
        }