wei
2021-02-26 87e614af0fa31d7fd632136d95c0c7e584c28477
HDL_ON/UI/UI2/FuntionControlView/Electrical/ClothesHangerPage.cs
@@ -1,21 +1,336 @@
using System;
using Shared;
using Shared;
using HDL_ON.Stan;
using HDL_ON.UI.CSS;
using HDL_ON.Entity;
using System.Collections.Generic;
namespace HDL_ON.UI
{
    /// <summary>
    /// 晾衣架界面
    /// </summary>
    public class ClothesHangerPage : FrameLayout
    public class ClothesHangerPage : DeviceFunctionCardCommonForm
    {
        public ClothesHangerPage()
        #region ■ 变量声明___________________________
        /// <summary>
        /// 图标
        /// </summary>
        private Button btnIcon = null;
        /// <summary>
        /// 上升
        /// </summary>
        Button btnUp;
        /// <summary>
        /// 停止
        /// </summary>
        Button btnStop;
        /// <summary>
        /// 下降
        /// </summary>
        Button btnDown;
        /// <summary>
        /// 文本控件
        /// </summary>
        private NormalViewControl btnSuctionView = null;
        #endregion
        #region ■ 初始化_____________________________
        /// <summary>
        /// 初始化白色区域的内容
        /// </summary>
        public override void InitFrameWhiteContent()
        {
            base.ShowColltionButton = false;
            base.SetTitleText(Language.StringByID(StringId.Electric));
            //初始化第一个索引页的内容
            this.InitFrameWhiteContent1();
            //刷新当前设备的状态缓存
            this.RefreshNowDeviceStatuMemory(this.device);
            //刷新界面状态
            this.RefreshFormStatu();
            //读取状态
            new System.Threading.Thread(() =>
            {
                DriverLayer.Control.Ins.SendReadCommand(device);
            })
            { IsBackground = true }.Start();
        }
        public void LoadPage()
        /// <summary>
        /// 初始化第一个索引页的内容
        /// </summary>
        private void InitFrameWhiteContent1()
        {
            btnIcon = new Button()
            {
                Gravity = Gravity.CenterHorizontal,
                Y = Application.GetRealHeight(85),
                Width = Application.GetRealWidth(195),
                Height = Application.GetRealHeight(121),
                UnSelectedImagePath = "FunctionIcon/Electrical/ClothesHanger/ClothesHangerBgIcon.png",
                SelectedImagePath = "FunctionIcon/Electrical/ClothesHanger/ClothesHangerBgIconOn.png",
            };
            FrameWhiteCentet1.AddChidren(btnIcon);
            #region 上升 停止 下降
            btnUp = new Button()
            {
                X = Application.GetRealWidth(42),
                Y = Application.GetRealHeight(236),
                Width = Application.GetRealWidth(28),
                Height = Application.GetRealWidth(28),
                UnSelectedImagePath = "FunctionIcon/Electrical/ClothesHanger/ClothesHangerUpIcon.png",
                SelectedImagePath = "FunctionIcon/Electrical/ClothesHanger/ClothesHangerUpIconOn.png",
            };
            FrameWhiteCentet1.AddChidren(btnUp);
            btnStop = new Button()
            {
                Gravity = Gravity.CenterHorizontal,
                Y = Application.GetRealHeight(236),
                Width = Application.GetRealWidth(28),
                Height = Application.GetRealWidth(28),
                UnSelectedImagePath = "FunctionIcon/Electrical/ClothesHanger/ClothesHangerStopIcon.png",
                SelectedImagePath = "FunctionIcon/Electrical/ClothesHanger/ClothesHangerStopIconOn.png",
            };
            FrameWhiteCentet1.AddChidren(btnStop);
            btnDown = new Button()
            {
                X = Application.GetRealWidth(257),
                Y = Application.GetRealHeight(236),
                Width = Application.GetRealWidth(28),
                Height = Application.GetRealWidth(28),
                UnSelectedImagePath = "FunctionIcon/Electrical/ClothesHanger/ClothesHangerDownIcon.png",
                SelectedImagePath = "FunctionIcon/Electrical/ClothesHanger/ClothesHangerDownIconOn.png",
            };
            FrameWhiteCentet1.AddChidren(btnDown);
            #endregion
            #region 菜单
            var menu = new List<string>() {
                FunctionAttributeKey.HotDry,
                FunctionAttributeKey.WindDry,
                FunctionAttributeKey.Disinfect,
                FunctionAttributeKey.OnOff
            };
            int index = 0;
            List<string> attrs = device.GetAttributes();
            ClothesHangerControl hotDryView = new ClothesHangerControl(
                            "FunctionIcon/Electrical/ClothesHanger/ClothesHangerHotDryIcon.png",
                            "FunctionIcon/Electrical/ClothesHanger/ClothesHangerHotDryIconOn.png",
                            Language.StringByID(StringId.HotDry),
                            device.GetAttrState(FunctionAttributeKey.HotDryTimeLeft));
            hotDryView.X = 0;
            hotDryView.Y = Application.GetRealHeight(288);
            hotDryView.Width = Application.GetRealWidth(96);
            hotDryView.Height = Application.GetRealHeight(74);//28 29 14 3
            if (attrs.Contains(menu[0]) || true)
            {
                FrameWhiteCentet1.AddChidren(hotDryView);
                index++;
            }
            ClothesHangerControl windDryView = new ClothesHangerControl(
                                "FunctionIcon/Electrical/ClothesHanger/ClothesHangerWindDryIcon.png",
                                "FunctionIcon/Electrical/ClothesHanger/ClothesHangerWindDryIconOn.png",
                                Language.StringByID(StringId.WindDry),
                                device.GetAttrState(FunctionAttributeKey.WindDryTimeLeft));
            windDryView.Y = Application.GetRealHeight(288);
            windDryView.Width = Application.GetRealWidth(96);
            windDryView.Height = Application.GetRealHeight(74);
            if (attrs.Contains(menu[1]) || true)
            {
                if(index == 1)
                {
                    windDryView.Gravity = Gravity.CenterHorizontal;
                }
                FrameWhiteCentet1.AddChidren(windDryView);
                index++;
            }
            ClothesHangerControl disinfectDryView = new ClothesHangerControl(
                                "FunctionIcon/Electrical/ClothesHanger/ClothesHangerDisinfectIcon.png",
                                "FunctionIcon/Electrical/ClothesHanger/ClothesHangerDisinfectIconOn.png",
                                Language.StringByID(StringId.Disinfect),
                                device.GetAttrState(FunctionAttributeKey.DisinfectTimeLeft));
            disinfectDryView.Y = Application.GetRealHeight(288);
            disinfectDryView.Width = Application.GetRealWidth(96);
            disinfectDryView.Height = Application.GetRealHeight(74);
            if (attrs.Contains(menu[2]) || true)
            {
                if(index == 1)
                {
                    disinfectDryView.Gravity = Gravity.CenterHorizontal;
                }
                else if (index == 2)
                {
                    disinfectDryView.X = Application.GetRealWidth(266 - 33);
                }
                FrameWhiteCentet1.AddChidren(disinfectDryView);
                index++;
            }
            ClothesHangerControl lightingView = new ClothesHangerControl(
                                "FunctionIcon/Electrical/ClothesHanger/ClothesHangerLightIcon.png",
                                "FunctionIcon/Electrical/ClothesHanger/ClothesHangerLightIconOn.png",
                                Language.StringByID(StringId.Lighting),
                                "");
            lightingView.Width = Application.GetRealWidth(96);
            lightingView.Height = Application.GetRealHeight(74);
            if (attrs.Contains(menu[3]) || true)
            {
                if(index >2)
                {
                    lightingView.Y = Application.GetRealHeight(375);
                }else
                {
                    if (index == 1)
                    {
                        lightingView.Gravity = Gravity.CenterHorizontal;
                    }
                    else if (index == 2)
                    {
                        lightingView.X = Application.GetRealWidth(266 - 33);
                    }
                }
                FrameWhiteCentet1.AddChidren(lightingView);
                index++;
            }
            #endregion
        }
        #endregion
        #region ■ 设备状态反馈_______________________
        /// <summary>
        /// 设备状态反馈
        /// </summary>
        /// <param name="i_LocalDevice"></param>
        public override void DeviceStatuPush(Function i_LocalDevice)
        {
            //不是同一个东西
            if (this.device.sid != i_LocalDevice.sid) { return; }
            //刷新当前设备的状态缓存
            this.RefreshNowDeviceStatuMemory(i_LocalDevice);
            //刷新界面状态
            this.RefreshFormStatu();
        }
        #endregion
        #region ■ 发送各种命令_______________________
        #endregion
        #region ■ 刷新界面状态_______________________
        /// <summary>
        /// 刷新界面状态
        /// </summary>
        private void RefreshFormStatu()
        {
            Application.RunOnMainThread(() => {
                var temp = device.status.Find((sta) => sta.key == FunctionAttributeKey.Status);
                if (temp != null)
                {
                    if (temp.value == "true")
                    {
                    }
                    else
                    {
                    }
                }
            });
        }
        #endregion
        #region ■ 一般方法___________________________
        /// <summary>
        /// 刷新当前设备的状态缓存
        /// </summary>
        private void RefreshNowDeviceStatuMemory(Function i_LocalDevice)
        {
            foreach (var data in i_LocalDevice.status)
            {
                //开关
                //if (data.key == "on_off") { this.weepRobotData.Cleaning = data.value.ToLower() == "on"; }
            }
        }
        #endregion
    }
    public class ClothesHangerControl : FrameLayout
    {
        private Button btnIcon;
        private Button btnTitle;
        private Button btnTime;
        public ClothesHangerControl(string iconPath1, string iconPath2,string title,string time)
        {
            btnIcon = new Button()
            {
                Gravity = Gravity.CenterHorizontal,
                Width = Application.GetRealWidth(28),
                Height = Application.GetRealWidth(28),
                UnSelectedImagePath = iconPath1,
                SelectedImagePath = iconPath2,
            };
            this.AddChidren(btnIcon);
            btnTitle = new Button()
            {
                Gravity = Gravity.Center,
                Text = title,
                TextColor = CSS_Color.TextualColor,
                SelectedTextColor = CSS_Color.MainColor,
                TextSize = CSS_FontSize.PromptFontSize_FirstLevel,
            };
            this.AddChidren(btnTitle);
            btnTime = new Button()
            {
                Gravity = Gravity.CenterHorizontal,
                Text = time,
                TextColor = CSS_Color.TextualColor,
                SelectedTextColor = CSS_Color.MainColor,
                TextSize = CSS_FontSize.PromptFontSize_SecondaryLevel,
            };
            this.AddChidren(btnTime);
        }
        /// <summary>
        /// 修改显示时间
        /// </summary>
        /// <param name="newTime"></param>
        public void ChangeTime (string newTime)
        {
            btnTime.Text = newTime;
        }
        public void ChangeViewStatus(bool state)
        {
            btnIcon.IsSelected = btnTitle.IsSelected = btnTime.IsSelected = state;
        }
        public bool GetViewState()
        {
            return btnIcon.IsSelected;
        }
    }
}