黄学彪
2019-10-24 31497bb69602433d94c8a28ea01c3ee3c7cc8576
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
152
153
154
155
156
157
158
159
160
161
162
using System;
using Shared;
using Shared.Common;
using Shared.R;
 
namespace Shared.Phone.Logic.DoorLockLogic
{
    public class DoorLockLogicList : FrameLayout
    {
 
        public async void Show()
        {
 
            #region  最上面的布局代码
            var topRowLayout = new RowLayout
            {
                BackgroundColor = ZigbeeColor.Current.LogicTopBackgroundColor,
                Height = Application.GetRealHeight(184),
                LineColor = ZigbeeColor.Current.LogicRowLayoutTopLineColor,
            };
            this.AddChidren(topRowLayout);
 
            var titleName = new Button
            {
                TextSize = 16,
                TextColor = ZigbeeColor.Current.LogicTextBlackColor,
                TextAlignment = TextAlignment.CenterLeft,
                X = Application.GetRealWidth(176),
                Width = Application.GetRealWidth(400),
                Height = Application.GetRealHeight(69),
                Y = Application.GetRealHeight(92),
                TextID = MyInternationalizationString.selection,
            };
            topRowLayout.AddChidren(titleName);
 
            var clickBtn = new Button
            {
                Width = Application.GetRealWidth(81 + 51),
                Height = Application.GetRealHeight(58 + 40),
                Y = Application.GetRealHeight(98 - 40),
            };
            topRowLayout.AddChidren(clickBtn);
            clickBtn.MouseDownEventHandler += (sender, e) =>
            {
                RemoveFromParent();
            };
 
            var back = new Button
            {
                Width = Application.GetRealWidth(30),
                Height = Application.GetRealHeight(51),
                X = Application.GetRealWidth(81),
                Y = Application.GetRealHeight(98),
                //Gravity = Gravity.CenterVertical;
                UnSelectedImagePath = "ZigeeLogic/back.png",
            };
            topRowLayout.AddChidren(back);
            back.MouseDownEventHandler += (sender, e) =>
            {
                RemoveFromParent();
            };
 
            var addiocn = new Button
            {
                Width = Application.GetRealWidth(72),
                Height = Application.GetRealHeight(72),
                X = Application.GetRealWidth(1080-108-58),
                UnSelectedImagePath = "ZigeeLogic/lockadd.png",
                Y = Application.GetRealHeight(184-72-20),
            };
            topRowLayout.AddChidren(addiocn);
            addiocn.MouseUpEventHandler += (sender, e) =>
            {
                //new一个新逻辑对象;
                Common.Logic.CurrentLogic = new Common.Logic();
                Common.Logic.CurrentLogic.IsEnable = 1;//默认为开
                Common.Logic.CurrentLogic.LogicType = 1;
                //Config.Instance.Guid用来识别账号身份;
                var accounts = new System.Collections.Generic.Dictionary<string, string>();
                accounts.Add("Account",Config.Instance.Guid);
                Common.Logic.CurrentLogic.Accounts.Add(accounts);
                Common.Logic.CurrentLogic.LogicName = Language.StringByID(MyInternationalizationString.automation1);
                var lockLogicCommunalPage = new LockLogicCommunalPage();
                UserView.HomePage.Instance.AddChidren(lockLogicCommunalPage);
                UserView.HomePage.Instance.PageIndex += 1;
                lockLogicCommunalPage.Show(() => { });
            };
            #endregion
 
            var middle = new VerticalScrolViewLayout
            {
                Y = topRowLayout.Bottom,
                Height = Application.GetRealHeight(1920 - 184),
                BackgroundColor = ZigbeeColor.Current.LogicMiddleBackgroundColor,
            };
            this.AddChidren(middle);
 
            CommonPage.Loading.Start();
            if (Common.Logic.LockLogicList.Count == 0)
            {
                var Idlist = await Device.Logic.Send.GetLogicId();
                if (Idlist.Count != 0)
                {
                    var listlogic = await Device.Logic.Send.ReadList(Idlist.Count);
                    for (int i = 0; i < Idlist.Count; i++)
                    {
                        var LogicId = Idlist[i];
                        //foreach可能集合已被修改,枚举操作可能不会执行,可能出现崩溃(建议for)。
                        for (int j = 0; j < listlogic.Count; j++)
                        {
                            var logic = listlogic[j];
                            if (logic.LogicId == LogicId)
                            {
                                Common.Logic.LockLogicList.Add(logic);
                            }
                        }
                    }
                }
            }
            //自动化
            for (int i = 0; i < Common.Logic.LockLogicList.Count; i++)
            {
                var logic = Common.Logic.LockLogicList[i];
                var logicRowlayout = new RowLayout
                {
                    Width = Application.GetRealWidth(1080),
                    Height = Application.GetRealHeight(190),
                    LineColor = ZigbeeColor.Current.LogicBackgroundColor,
                    BackgroundColor = ZigbeeColor.Current.LogicBackgroundColor,
 
                };
                middle.AddChidren(logicRowlayout);
 
                var logicnameBtn = new Button
                {
                    Height = Application.GetRealHeight(190),
                    Width = Application.GetRealWidth(600),
                    Text = logic.LogicName,
                    X = Application.GetRealWidth(58),
                    TextAlignment = TextAlignment.CenterLeft,
                    TextColor = ZigbeeColor.Current.LogicTextBlackColor,
                    Gravity = Gravity.CenterVertical,
                };
                logicRowlayout.AddChidren(logicnameBtn);
 
 
                var logicswitchBtn = new Button
                {
                    Width = Application.GetMinRealAverage(104),
                    Height = Application.GetMinRealAverage(63),
                    UnSelectedImagePath = "ZigeeLogic/logicclose.png",
                    SelectedImagePath = "ZigeeLogic/logicopen.png",
                    X = logicRowlayout.Width - Application.GetRealWidth(104 + 58),
                    Gravity = Gravity.CenterVertical,
                };
                logicRowlayout.AddChidren(logicswitchBtn);
 
            }
            CommonPage.Loading.Hide();
        }
    }
}