wei
2021-02-01 8da70e1a39328e1769b02bb1e05303916bb30eb5
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
using System;
using System.Collections.Generic;
using HDL_ON.DriverLayer;
using HDL_ON.Entity;
using HDL_ON.Stan;
using HDL_ON.UI.CSS;
using Shared;
 
namespace HDL_ON.UI
{
    public class TuyaWaterValvePage : DeviceFunctionCardCommonForm
    {
        #region ■ 变量声明___________________________
        /// <summary>
        /// 图片控件
        /// </summary>
        private PicViewControl btnPictrue = null;
        /// <summary>
        /// 滤芯使用率控件
        /// </summary>
        private NormalViewControl btnUsePersent = null;
        /// <summary>
        /// 天气延时
        /// </summary>
        private NormalViewControl btnWeatherDelay = null;
        /// <summary>
        /// 湿度
        /// </summary>
        private NormalViewControl btnWeatherDelayControl = null;
        /// <summary>
        /// 开关控件
        /// </summary>
        private IconViewControl btnSwitch = null;
        #endregion
 
        #region ■ 初始化_____________________________
 
        /// <summary>
        /// 初始化白色区域的内容
        /// </summary>
        public override void InitFrameWhiteContent()
        {
            base.SetTitleText(Language.StringByID(StringId.AirCleaner));
 
            //添加第二索引页
            this.AddSecondPage();
            //初始化第一个索引页的内容
            this.InitFrameWhiteContent1();
            //刷新界面状态
            this.RefreshFormStatu();
        }
 
        /// <summary>
        /// 初始化第一个索引页的内容
        /// </summary>
        private void InitFrameWhiteContent1()
        {
            //图片控件
            this.btnPictrue = new PicViewControl(94, 130);
            btnPictrue.Y = Application.GetRealHeight(90);
            btnPictrue.Gravity = Gravity.CenterHorizontal;
            btnPictrue.UnSelectedImagePath = "FunctionIcon/Electrical/WaterValve/WaterValveBg.png";
            btnPictrue.SelectedImagePath = "FunctionIcon/Electrical/WaterValve/WaterValveOnBg.png";
            FrameWhiteCentet1.AddChidren(btnPictrue);
            btnPictrue.ButtonClickEvent += (sender, e) =>
            {
                //发送开关命令
                this.SendSwitchComand();
            };
 
            //开关图标
            this.btnSwitch = new IconViewControl(40);
            btnSwitch.Gravity = Gravity.CenterHorizontal;
            btnSwitch.Y = Application.GetRealHeight(468);
            btnSwitch.UnSelectedImagePath = "Public/PowerClose.png";
            btnSwitch.SelectedImagePath = "Public/PowerOpen.png";
            FrameWhiteCentet1.AddChidren(btnSwitch);
            btnSwitch.ButtonClickEvent += (sender, e) =>
            {
                //发送开关命令
                this.SendSwitchComand();
            };
        }
        #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.RefreshFormStatu();
        }
 
        #endregion
 
        #region ■ 发送各种命令_______________________
 
        /// <summary>
        /// 发送开关命令
        /// </summary>
        private void SendSwitchComand()
        {
            this.btnPictrue.CanClick = false;
            this.btnSwitch.CanClick = false;
 
            string statu = this.btnSwitch.IsSelected == true ? "off" : "on";
            //btnSwitch.IsSelected = !btnSwitch.IsSelected;
            HdlThreadLogic.Current.RunThread(() =>
            {
                var dic = new Dictionary<string, string>();
                dic.Add(FunctionAttributeKey.OnOff, statu);
                Control.Ins.SendWriteCommand(this.device, dic, true);
                HdlThreadLogic.Current.RunMain(() =>
                {
                    this.btnPictrue.CanClick = true;
                    this.btnSwitch.CanClick = true;
                });
            });
        }
 
        #endregion
 
        #region ■ 刷新界面状态_______________________
 
        /// <summary>
        /// 刷新界面状态
        /// </summary>
        private void RefreshFormStatu()
        {
            Application.RunOnMainThread(() =>
            {
                foreach (var data in this.device.attributes)
                {
                    if (data.key == FunctionAttributeKey.OnOff)
                    {
                        this.btnSwitch.IsSelected = this.btnPictrue.IsSelected = data.curValue.ToString() == "on";
                    }
                }
            });
        }
        #endregion
 
    }
}