wxr
2020-03-13 171bf03f3664226eeff2b20ee9bd2e914b63a17d
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
using System;
using HDL_ON.Entity;
using Shared;
 
namespace HDL_ON.UI
{
 
 
    public partial class HomePage
    {
 
        /// <summary>
        /// 修改显示的功能类型
        /// 设备功能/场景功能
        /// </summary>
        void LoadEvent_ChangeShowedFunctionType()
        {
            btnChangeFunction.MouseUpEventHandler = (sender, e) => {
                btnChangeFunction.IsSelected = true;
                btnChangeFunction.TextSize = CSS.CSS_FontSize.HeadlineFontSize;
                btnChangeFunction.IsBold = true;
                btnChangeScene.TextSize = CSS.CSS_FontSize.TextFontSize;
                btnChangeScene.IsSelected = false;
                btnChangeScene.IsBold = false;
                CurShowTypeIsFunction = true;
                contentView.PageIndex = 0;
            };
 
            btnChangeScene.MouseUpEventHandler = (sender, e) => {
                btnChangeScene.IsSelected = true;
                btnChangeScene.TextSize = CSS.CSS_FontSize.HeadlineFontSize;
                btnChangeScene.IsBold = true;
                btnChangeFunction.TextSize = CSS.CSS_FontSize.TextFontSize;
                btnChangeFunction.IsSelected = false;
                btnChangeFunction.IsBold = false;
                CurShowTypeIsFunction = false;
                contentView.PageIndex = 1;
            };
 
            contentView.PageChange = (sender, e) => {
                if (contentView.PageIndex == 0)
                {
                    btnChangeFunction.IsSelected = true;
                    btnChangeFunction.TextSize = CSS.CSS_FontSize.HeadlineFontSize;
                    btnChangeFunction.IsBold = true;
                    btnChangeScene.TextSize = CSS.CSS_FontSize.TextFontSize;
                    btnChangeScene.IsSelected = false;
                    btnChangeScene.IsBold = false;
                    CurShowTypeIsFunction = true;
                }
                else
                {
                    btnChangeScene.IsSelected = true;
                    btnChangeScene.TextSize = CSS.CSS_FontSize.HeadlineFontSize;
                    btnChangeScene.IsBold = true;
                    btnChangeFunction.TextSize = CSS.CSS_FontSize.TextFontSize;
                    btnChangeFunction.IsSelected = false;
                    btnChangeFunction.IsBold = false;
                    CurShowTypeIsFunction = false;
                }
            };
        }
 
 
 
        /// <summary>
        /// 更新灯光显示状态
        /// </summary>
        /// <param name="light"></param>
        public static void UpdataLightView(Light light)
        {
            Application.RunOnMainThread(() =>
            {
                if (bodyView != null)
                {
                    foreach (var dic in LightViews)
                    {
                        if (dic.Key == light.sid)
                        {
                            var state = light.state == 1;
                            var view = dic.Value;
                            for (int i = 0; i < view.ChildrenCount; i++)
                            {
                                if (view.GetChildren(i).GetType() == typeof(Button))
                                {
                                    var btn = view.GetChildren(i) as Button;
                                    btn.IsSelected = state;
                                    if (btn.Tag != null && btn.Tag.ToString() == "state")
                                    {
                                        btn.Text = light.lastState;
                                    }
                                }
                            }
                        }
                    }
                }
            });
        }
 
        /// <summary>
        /// 加载继电器开关事件
        /// </summary>
        /// <param name="function"></param>
        /// <param name="btnSwitch"></param>
        /// <param name="view"></param>
        void LoadRelaySwitchEvent(Function function,Button btnSwitch,FrameLayout view)
        {
 
            btnSwitch.MouseUpEventHandler += (sender, e) =>
            {
                if (function.functionCategory == FunctionType.Light)
                {
                    var curState = !btnSwitch.IsSelected;
                    for (int i = 0; i < view.ChildrenCount; i++)
                    {
                        if (view.GetChildren(i).GetType() == typeof(Button))
                        {
                            var btn = view.GetChildren(i) as Button;
                            btn.IsSelected = curState;
                        }
                    }
                    new System.Threading.Thread(() =>
                    {
                        var light = function as Light;
                        light.state = btnSwitch.IsSelected ? 1 : 0;
                        Control.Send("write", function, 3);
                    })
                    { IsBackground = true }.Start();
                }
            };
        }
    }
}