示例#1
0
        private async void OnBrightnessEditTextEditorAction(object sender, TextView.EditorActionEventArgs e)
        {
            if (e.ActionId == ImeAction.Done)
            {
                var editText = sender as EditText;

                var validationResult = ValidateTimerBrightness(editText);

                if (validationResult == true)
                {
                    _brightnessEditText.SetTextColor(Color.Black);
                    _sliderValue            = int.Parse(editText.Text);
                    _valueToSend            = _sliderValue;
                    _onOffSwitch.Checked    = _sliderValue != 0;
                    _sliderSeekBar.Progress = _sliderValue;

                    PrepareDataService.PrepareData(0x01, (byte)_sliderValue, 0x00);
                    await SendDataService.SendData(_socket);
                }
                else
                {
                    _brightnessEditText.SetError("Invalid brightness value\nMust be between 0 and 100", null);
                    _brightnessEditText.SetTextColor(Color.Red);
                }
            }
            e.Handled = false;
            ClearFocusFromAllEditTexts(sender as EditText);
        }
示例#2
0
        private async void OnOnOffSwitchCheckedChange(object sender, CompoundButton.CheckedChangeEventArgs e)
        {
            if (!e.IsChecked)
            {
                _sliderValue            = 0;
                _sliderSeekBar.Progress = _sliderValue;

                PrepareDataService.PrepareData(0x01, 0x00, 0x00);
                await SendDataService.SendData(_socket);
            }
            else
            {
                if (int.TryParse(_brightnessEditText.Text, out _valueToSend))
                {
                    if (_valueToSend > 0 && _valueToSend < 100)
                    {
                        _sliderValue = _valueToSend;
                    }
                    else
                    {
                        _sliderValue = 100;
                    }
                }

                _sliderSeekBar.Progress = _sliderValue;
                PrepareDataService.PrepareData(0x01, (byte)_sliderValue, 0x00);

                try
                {
                    await SendDataService.SendData(_socket);
                }
                catch (Java.Lang.Exception ex)
                {
                }
            }
        }
示例#3
0
        private async void OnBrightnessEditTextTextChanged(object sender, Android.Text.TextChangedEventArgs e)
        {
            var editText = sender as EditText;

            editText.SetSelection(editText.Text.Length);

            var validationResult = ValidateTimerBrightness(editText);

            if (validationResult == true)
            {
                _brightnessEditText.SetTextColor(Color.Black);
                _sliderValue            = int.Parse(editText.Text);
                _valueToSend            = _sliderValue;
                _onOffSwitch.Checked    = _sliderValue != 0;
                _sliderSeekBar.Progress = _sliderValue;
                PrepareDataService.PrepareData(0x01, (byte)_sliderValue, 0x00);
                await SendDataService.SendData(_socket);
            }
            else
            {
                _brightnessEditText.SetError("Invalid brightness value\nMust be between 0 and 100", null);
                _brightnessEditText.SetTextColor(Color.Red);
            }
        }
示例#4
0
        private async void OnSetTimerButtonClick(object sender, EventArgs e)
        {
            _wrapperLayout.ClearFocus();
            if (ValidateTimer())
            {
                var currentTime = DateTime.Now;

                var startTimeHour   = int.Parse(_startTimeHoursEditText.Text);
                var startTimeMinute = int.Parse(_startTimeMinutesEditText.Text);
                var endTimeHour     = int.Parse(_endTimeHoursEditText.Text);
                var endTimeMinute   = int.Parse(_endTimeMinutesEditText.Text);

                int days;
                if (!int.TryParse(_daysSetEditText.Text, out days))
                {
                    days = 0;
                }

                var brightness = int.Parse(_brightnessTimerEditText.Text);

                // ON
                PrepareDataService.PrepareData((byte)Command.FirstTimeStamp,
                                               (byte)DataForTimeStampStructure.Minutes,
                                               (byte)startTimeMinute);
                await SendDataService.SendData(_socket);

                PrepareDataService.PrepareData((byte)Command.FirstTimeStamp,
                                               (byte)DataForTimeStampStructure.Hours,
                                               (byte)startTimeHour);
                await SendDataService.SendData(_socket);

                PrepareDataService.PrepareData((byte)Command.FirstTimeStamp,
                                               (byte)DataForTimeStampStructure.Days,
                                               (byte)currentTime.Day);
                await SendDataService.SendData(_socket);

                PrepareDataService.PrepareData((byte)Command.FirstTimeStamp,
                                               (byte)DataForTimeStampStructure.Weekdays,
                                               (byte)currentTime.DayOfWeek);
                await SendDataService.SendData(_socket);

                //brightness
                PrepareDataService.PrepareData((byte)Command.FirstTimeStamp,
                                               (byte)DataForTimeStampStructure.Function,
                                               (byte)Command.SetPower);
                await SendDataService.SendData(_socket);

                PrepareDataService.PrepareData((byte)Command.FirstTimeStamp,
                                               (byte)DataForTimeStampStructure.FunctionValue,
                                               (byte)brightness);
                await SendDataService.SendData(_socket);

                ////
                PrepareDataService.PrepareData((byte)Command.WriteStructureToDevice,
                                               0x00,
                                               0x00);
                await SendDataService.SendData(_socket);



                // OFF
                PrepareDataService.PrepareData((byte)Command.SecondTimeStamp,
                                               (byte)DataForTimeStampStructure.Minutes,
                                               (byte)endTimeMinute);
                await SendDataService.SendData(_socket);

                PrepareDataService.PrepareData((byte)Command.SecondTimeStamp,
                                               (byte)DataForTimeStampStructure.Hours,
                                               (byte)endTimeHour);
                await SendDataService.SendData(_socket);

                PrepareDataService.PrepareData((byte)Command.SecondTimeStamp,
                                               (byte)DataForTimeStampStructure.Days,
                                               (byte)currentTime.Day);
                await SendDataService.SendData(_socket);

                PrepareDataService.PrepareData((byte)Command.SecondTimeStamp,
                                               (byte)DataForTimeStampStructure.Weekdays,
                                               (byte)currentTime.DayOfWeek);
                await SendDataService.SendData(_socket);

                PrepareDataService.PrepareData((byte)Command.WriteStructureToDevice,
                                               0x00,
                                               0x00);

                await SendDataService.SendData(_socket);

                if (days > 0)
                {
                    PrepareDataService.PrepareData((byte)Command.SetAlarm,
                                                   (byte)(days + 1),
                                                   0x01);
                    await SendDataService.SendData(_socket);
                }
                else
                {
                    PrepareDataService.PrepareData((byte)Command.SetAlarm,
                                                   0x01,
                                                   0x01);
                    await SendDataService.SendData(_socket);
                }

                Toast.MakeText(this, "Sent", ToastLength.Short).Show();
            }
            else
            {
                Toast.MakeText(this, "Enter correct data!", ToastLength.Short).Show();
            }
        }
        private async void OnConnectButtonClick(object sender, EventArgs args)
        {
            _devicesList.ClearChoices();
            _connectButton.Clickable              = false;
            _busyIndicator.Visibility             = ViewStates.Visible;
            _busyIndicatorLinearLayout.Visibility = ViewStates.Visible;

            await Task.Run(() =>
            {
                Task.Delay(1000);
            });

            if (_pickedDevice != null)
            {
                try
                {
                    _socket = _pickedDevice.CreateInsecureRfcommSocketToServiceRecord(
                        UUID.FromString(Constants.BluetoothUUID));
                }
                catch (Java.Lang.Exception e)
                {
                    Toast.MakeText(this, "Error opening port\nPlease try again", ToastLength.Short).Show();
                    HideLoadingIndicator();
                    return;
                }
                try
                {
                    await _socket.ConnectAsync();

                    //await Task.Run(async () =>
                    //{
                    //    await _socket.ConnectAsync();
                    //});
                }
                catch (Java.Lang.Exception e)
                {
                    Toast.MakeText(this, "Error connecting with device\nPlease try again", ToastLength.Short).Show();
                    HideLoadingIndicator();
                    return;
                }

                try
                {
                    //SynchronizeTimeOnDevice();
                    var currentTime = DateTime.Now;

                    PrepareDataService.PrepareData(
                        (byte)Command.SetStructureTime,
                        (byte)DataForSetTimeStructure.Minutes,
                        (byte)currentTime.Minute);

                    await SendDataService.SendData(_socket);

                    PrepareDataService.PrepareData(
                        (byte)Command.SetStructureTime,
                        (byte)DataForSetTimeStructure.Hours,
                        (byte)currentTime.Hour);

                    await SendDataService.SendData(_socket);

                    PrepareDataService.PrepareData(
                        (byte)Command.SetStructureTime,
                        (byte)DataForSetTimeStructure.Days,
                        (byte)currentTime.Day);

                    await SendDataService.SendData(_socket);

                    PrepareDataService.PrepareData(
                        (byte)Command.SetStructureTime,
                        (byte)DataForSetTimeStructure.Weekdays,
                        (byte)currentTime.DayOfWeek);

                    await SendDataService.SendData(_socket);

                    PrepareDataService.PrepareData(
                        (byte)Command.SetStructureTime,
                        (byte)DataForSetTimeStructure.Months,
                        (byte)currentTime.Month);

                    await SendDataService.SendData(_socket);

                    PrepareDataService.PrepareData(
                        (byte)Command.SetStructureTime,
                        (byte)DataForSetTimeStructure.Years,
                        (byte)(currentTime.Year % 2000));

                    await SendDataService.SendData(_socket);

                    PrepareDataService.PrepareData(
                        (byte)Command.WriteStructureToDevice,
                        0x00,
                        0x00);

                    await SendDataService.SendData(_socket);
                }
                catch (Java.Lang.Exception e)
                {
                    HideLoadingIndicator();
                }

                try
                {
                    await Task.Delay(1000);

                    _socket.Close();
                    await Task.Delay(1000);
                }
                catch (Java.Lang.Exception e)
                {
                    Toast.MakeText(this, "Error closing socket\nPlease try again", ToastLength.Short).Show();
                    HideLoadingIndicator();
                    return;
                }

                #region release
                var controlActivity = new Intent(this, typeof(ControlActivity));
                controlActivity.PutExtra("DeviceName", _pickedDevice.Name);
                controlActivity.PutExtra("DeviceMac", _pickedDevice.Address);
                StartActivity(controlActivity);
                #endregion
            }
            HideLoadingIndicator();
        }