wxr
2020-02-27 37c33341f75841dc39c535eb62a3603f596516a1
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
using System;
using HDL_ON.Entity;
using Shared;
 
namespace HDL_ON.UI
{
    public partial class HomePage
    {
        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;
                                    }
                                }
                            }
                        }
                    }
                }
            });
        }
 
 
        void LoadSwitchEvent(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();
                }
            };
        }
    }
}