Example #1
0
        private async Task <AuthApiData <BaseResponseObject> > EditSensors()
        {
            try
            {
                StaticBox.Sensors["Вес груза"]                   = s_weight.Progress.ToString();
                StaticBox.Sensors["Температура"]                 = SmullTemperature.Text;
                StaticBox.Sensors["Влажность"]                   = s_humidity.Progress.ToString();
                StaticBox.Sensors["Освещенность"]                = s_light.Progress.ToString();
                StaticBox.Sensors["Уровень сигнала"]             = SmullNetworkSignal.Text;
                StaticBox.Sensors["Уровень заряда аккумулятора"] = s_battery.Progress.ToString();
                var o_data = await ContainerService.EditBox();

                return(o_data);
            }
            catch (Exception ex)
            {
                Toast.MakeText(this, "" + ex.Message, ToastLength.Long).Show();
                return(null);
            }
        }
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            SetContentView(Resource.Layout.activity_container_condition);


            condition = FindViewById <RelativeLayout>(Resource.Id.condition);
            s_open_close_container    = FindViewById <EditText>(Resource.Id.s_open_close_container);
            s_lock_unlock_door        = FindViewById <EditText>(Resource.Id.s_lock_unlock_door);
            btn_open_close_container  = FindViewById <Button>(Resource.Id.btn_open_close_container);
            btn_lock_unlock_door      = FindViewById <Button>(Resource.Id.btn_lock_unlock_door);
            btn_save_status_container = FindViewById <Button>(Resource.Id.btn_save_parameters);
            box_lay_fold          = FindViewById <ImageView>(Resource.Id.box_lay_fold);
            s_situation_container = FindViewById <Spinner>(Resource.Id.s_situation);


            s_open_close_container.Focusable     = false;
            s_open_close_container.LongClickable = false;
            s_lock_unlock_door.Focusable         = false;
            s_lock_unlock_door.LongClickable     = false;

            GetInfoAboutBox();
            s_situation_container.ItemSelected += new EventHandler <AdapterView.ItemSelectedEventArgs>(Spinner_ItemSelected);
            var adapter = ArrayAdapter.CreateFromResource(this, Resource.Array.a_situation_loaded_container, Android.Resource.Layout.SimpleSpinnerItem);

            adapter.SetDropDownViewResource(Android.Resource.Layout.SimpleSpinnerDropDownItem);
            s_situation_container.Adapter = adapter;



            btn_save_status_container.Click += async delegate
            {
                try
                {
                    StaticBox.Sensors["Состояние контейнера"]      = (s_open_close_container.Text == "сложен")?"0":"1";
                    StaticBox.Sensors["Состояние дверей"]          = (s_lock_unlock_door.Text == "закрыта")?"0":"1";
                    StaticBox.Sensors["Местоположение контейнера"] = a_situation;

                    var o_data = await ContainerService.EditBox();

                    if (o_data.Status == "1")
                    {
                        Toast.MakeText(this, o_data.Message, ToastLength.Long).Show();
                        GetInfoAboutBox();
                    }
                    else
                    {
                        GetInfoAboutBox();
                        StaticBox.CameraOpenOrNo = 1;
                        Intent authActivity = new Intent(this, typeof(Auth.SensorsDataActivity));
                        StartActivity(authActivity);
                    }
                }
                catch (Exception ex)
                {
                    Toast.MakeText(this, "" + ex.Message, ToastLength.Long).Show();
                }
            };

            //изменение состояния контейнера
            btn_open_close_container.Click += async delegate
            {
                try
                {
                    if (s_open_close_container.Text == "сложен")
                    {
                        s_open_close_container.Text = "разложен";
                        s_lock_unlock_door.Text     = "открыта";
                        box_lay_fold.SetImageResource(Resource.Drawable.open_door);
                    }

                    else
                    {
                        s_open_close_container.Text = "сложен";
                        s_lock_unlock_door.Text     = "открыта";
                        box_lay_fold.SetImageResource(Resource.Drawable.close_box);
                    }
                }
                catch (Exception ex)
                {
                    Toast.MakeText(this, "" + ex.Message, ToastLength.Long).Show();
                }
            };

            //изменение состояния дверей
            btn_lock_unlock_door.Click += async delegate
            {
                try
                {
                    if (s_lock_unlock_door.Text == "закрыта")
                    {
                        s_lock_unlock_door.Text = "открыта";
                        box_lay_fold.SetImageResource(Resource.Drawable.open_door);
                    }
                    else if (s_lock_unlock_door.Text == "открыта" && s_open_close_container.Text == "разложен")
                    {
                        s_lock_unlock_door.Text = "закрыта";
                        box_lay_fold.SetImageResource(Resource.Drawable.close_door);
                    }
                    else if (s_open_close_container.Text == "сложен" && s_lock_unlock_door.Text == "открыта")
                    {
                        Android.App.AlertDialog.Builder alert = new Android.App.AlertDialog.Builder(this);
                        alert.SetTitle("Внимание !");
                        alert.SetMessage("Невозможно изменить состояние дверей.");
                        alert.SetPositiveButton("Закрыть", (senderAlert, args) => {
                            Toast.MakeText(this, "Предупреждение было закрыто!", ToastLength.Short).Show();
                        });
                        Dialog dialog = alert.Create();
                        dialog.Show();
                    }
                    else if (s_open_close_container.Text == null && s_lock_unlock_door.Text == null)
                    {
                        Android.App.AlertDialog.Builder alert = new Android.App.AlertDialog.Builder(this);
                        alert.SetTitle("Внимание !");
                        alert.SetMessage("Невозможно изменить состояние дверей и контейнера.");
                        alert.SetPositiveButton("Закрыть", (senderAlert, args) => {
                            Toast.MakeText(this, "Предупреждение было закрыто!", ToastLength.Short).Show();
                        });
                        Dialog dialog = alert.Create();
                        dialog.Show();
                    }
                    else
                    {
                        Android.App.AlertDialog.Builder alert = new Android.App.AlertDialog.Builder(this);
                        alert.SetTitle("Внимание !");
                        alert.SetMessage("Невозможно изменить состояние дверей.");
                        alert.SetPositiveButton("Закрыть", (senderAlert, args) => {
                            Toast.MakeText(this, "Предупреждение было закрыто!", ToastLength.Short).Show();
                        });
                        Dialog dialog = alert.Create();
                        dialog.Show();
                    }
                }
                catch (Exception ex)
                {
                    Toast.MakeText(this, "" + ex.Message, ToastLength.Long).Show();
                }
            };
        }
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            SetContentView(Resource.Layout.activity_test_condition);

            condition           = FindViewById <RelativeLayout>(Resource.Id.test_condition);
            TextConditionCenter = FindViewById <TextView>(Resource.Id.TextConditionCenter);

            ContainerFold   = FindViewById <Button>(Resource.Id.ContainerFold);
            ContainerOff    = FindViewById <Button>(Resource.Id.ContainerOff);
            ContainerUnfold = FindViewById <Button>(Resource.Id.ContainerUnfold);
            ContainerOpen   = FindViewById <Button>(Resource.Id.ContainerOpen);
            ContainerClose  = FindViewById <Button>(Resource.Id.ContainerClose);

            btn_save_status_container = FindViewById <Button>(Resource.Id.btn_save_parameters);
            box_lay_fold          = FindViewById <ImageView>(Resource.Id.box_lay_fold);
            s_situation_container = FindViewById <Spinner>(Resource.Id.s_situation);

            origin_topic = StaticBox.Imitators[StaticBox.DeviceId];

            var client_data = new MQTTClient()
            {
                ClientId = "ESP32AndroidImitatorClient",
                Password = mqttPassword,
                Port     = mqttPort,
                Server   = mqttServer,
                UserName = mqttUserName
            };

            mQTT = new MQTTService(client_data, this);

            GetInfoAboutBox();
            //StaticBox.Sensors["Местоположение контейнера"] = "На автомобиле";
            s_situation_container.ItemSelected += new EventHandler <AdapterView.ItemSelectedEventArgs>(Spinner_ItemSelected);
            var adapter = ArrayAdapter.CreateFromResource(this, Resource.Array.a_situation_loaded_container, Android.Resource.Layout.SimpleSpinnerItem);

            adapter.SetDropDownViewResource(Android.Resource.Layout.SimpleSpinnerDropDownItem);
            s_situation_container.Adapter = adapter;

            btn_save_status_container.Click += async delegate
            {
                try
                {
                    //StaticBox.Sensors["Состояние контейнера"] = (s_open_close_container.Text == "сложен") ? "0" : "1";
                    //StaticBox.Sensors["Состояние дверей"] = (s_lock_unlock_door.Text == "закрыта") ? "0" : "1";


                    var o_data = await ContainerService.EditBox();

                    if (o_data.Status == "1")
                    {
                        Toast.MakeText(this, o_data.Message, ToastLength.Long).Show();
                        GetInfoAboutBox();
                    }
                    else
                    {
                        GetInfoAboutBox();
                        StaticBox.CameraOpenOrNo = 1;
                        Intent authActivity = new Intent(this, typeof(Auth.SensorsDataActivity));
                        StartActivity(authActivity);
                    }
                }
                catch (Exception ex)
                {
                    Toast.MakeText(this, "" + ex.Message, ToastLength.Long).Show();
                }
            };

            ContainerFold.Click += delegate(object select, EventArgs eventArgs)
            {
                SetBtnBackground("fold");
                StaticBox.Sensors["Состояние контейнера"] = "0";
                mQTT.PublishBoxState(origin_topic, "2");
            };
            //остановка
            ContainerOff.Click += delegate(object select, EventArgs eventArgs)
            {
                SetBtnBackground("off");
                StaticBox.Sensors["Состояние контейнера"] = "2";
                mQTT.PublishBoxState(origin_topic, "0");
            };
            //разложить
            ContainerUnfold.Click += delegate(object select, EventArgs eventArgs)
            {
                SetBtnBackground("unfold");
                StaticBox.Sensors["Состояние контейнера"] = "1";
                mQTT.PublishBoxState(origin_topic, "1");
            };

            //изменение состояния дверей
            ContainerOpen.Click += async delegate
            {
                try
                {
                    StaticBox.Sensors["Состояние дверей"] = "1";
                    SetBtnBackground("open");
                }
                catch (Exception ex)
                {
                    Toast.MakeText(this, "" + ex.Message, ToastLength.Long).Show();
                }
            };

            //изменение состояния дверей
            ContainerClose.Click += async delegate
            {
                try
                {
                    StaticBox.Sensors["Состояние дверей"] = "0";
                    SetBtnBackground("close");
                }
                catch (Exception ex)
                {
                    Toast.MakeText(this, "" + ex.Message, ToastLength.Long).Show();
                }
            };

            //изменение состояния дверей
            //btn_lock_unlock_door.Click += async delegate
            //{
            //    try
            //    {
            //        if (s_lock_unlock_door.Text == "закрыта")
            //        {
            //            s_lock_unlock_door.Text = "открыта";
            //            box_lay_fold.SetImageResource(Resource.Drawable.open_door);
            //        }
            //        else if (s_lock_unlock_door.Text == "открыта" && s_open_close_container.Text == "разложен")
            //        {
            //            s_lock_unlock_door.Text = "закрыта";
            //            box_lay_fold.SetImageResource(Resource.Drawable.close_door);
            //        }
            //        else if (s_open_close_container.Text == "сложен" && s_lock_unlock_door.Text == "открыта")
            //        {
            //            Android.App.AlertDialog.Builder alert = new Android.App.AlertDialog.Builder(this);
            //            alert.SetTitle("Внимание !");
            //            alert.SetMessage("Невозможно изменить состояние дверей.");
            //            alert.SetPositiveButton("Закрыть", (senderAlert, args) => {
            //                Toast.MakeText(this, "Предупреждение было закрыто!", ToastLength.Short).Show();
            //            });
            //            Dialog dialog = alert.Create();
            //            dialog.Show();
            //        }
            //        else if (s_open_close_container.Text == null && s_lock_unlock_door.Text == null)
            //        {
            //            Android.App.AlertDialog.Builder alert = new Android.App.AlertDialog.Builder(this);
            //            alert.SetTitle("Внимание !");
            //            alert.SetMessage("Невозможно изменить состояние дверей и контейнера.");
            //            alert.SetPositiveButton("Закрыть", (senderAlert, args) => {
            //                Toast.MakeText(this, "Предупреждение было закрыто!", ToastLength.Short).Show();
            //            });
            //            Dialog dialog = alert.Create();
            //            dialog.Show();
            //        }
            //        else
            //        {
            //            Android.App.AlertDialog.Builder alert = new Android.App.AlertDialog.Builder(this);
            //            alert.SetTitle("Внимание !");
            //            alert.SetMessage("Невозможно изменить состояние дверей.");
            //            alert.SetPositiveButton("Закрыть", (senderAlert, args) => {
            //                Toast.MakeText(this, "Предупреждение было закрыто!", ToastLength.Short).Show();
            //            });
            //            Dialog dialog = alert.Create();
            //            dialog.Show();
            //        }
            //    }
            //    catch (Exception ex)
            //    {
            //        Toast.MakeText(this, "" + ex.Message, ToastLength.Long).Show();
            //    }
            //};
        }