黄学彪
2019-10-10 2ed75b8b337048e5d75e6d9ec8307633134f02fd
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
using System;
using System.Collections.Generic;
using Shared.Common;
namespace Shared.Phone.Device.Category
{
    public class CategorySceneSelectDevice:FrameLayout
    {
        public CategorySceneSelectDevice()
        {
            BackgroundColor = ZigbeeColor.Current.GXCTopViewBackgroundColor;
            Tag = "categoryAddScene";
        }
        public override void RemoveFromParent()
        {
            base.RemoveFromParent();
        }
        public void Show(List<SceneTargetDeviceUI> sceneTargetDevicesList, bool isFromRoom = false)
        {
            #region topview
            var topBGView = new FrameLayout()
            {
                Height = Application.GetRealHeight(CommonPage.Navigation_Height),
                BackgroundColor = ZigbeeColor.Current.GXCTopViewBackgroundColor
            };
            AddChidren(topBGView);
            var topView = new FrameLayout()
            {
                Y = Application.GetRealHeight(CommonPage.NavigationTitle_Y),
                Height = Application.GetRealHeight(CommonPage.Navigation_Height - CommonPage.NavigationTitle_Y),
                BackgroundColor = ZigbeeColor.Current.GXCTopViewBackgroundColor,
            };
            AddChidren(topView);
 
            var title = new Button()
            {
                TextAlignment = TextAlignment.Center,
                TextID=R.MyInternationalizationString.SelectDevice,
                TextSize = 20,
                TextColor = ZigbeeColor.Current.GXCTextBlackColor,
                Width = Application.GetRealWidth(CommonPage.AppRealWidth - 500),
                Gravity = Gravity.CenterHorizontal
            };
            topView.AddChidren(title);
 
            var back = new Device.CommonForm.BackButton() { };
            topView.AddChidren(back);
            back.MouseUpEventHandler += (sender, e) =>
            {
                this.RemoveFromParent();
            };
            #endregion
 
            #region 获取设备
            //设备类型去重分类
            var dList = new List<ZigBee.Device.DeviceType>();
 
            var devices = new List<ZigBee.Device.CommonDevice> { };
            devices = LocalDevice.Current.listAllDevice;
            foreach (var device in devices)
            {
                if (device.Type == ZigBee.Device.DeviceType.AirSwitch
                    || device.Type == ZigBee.Device.DeviceType.OnOffOutput
                    || device.Type == ZigBee.Device.DeviceType.DimmableLight
                    || device.Type == ZigBee.Device.DeviceType.WindowCoveringDevice)
                {
                    if (dList.Contains(device.Type))
                    {
                        continue;
                    }
                    dList.Add(device.Type);
                }
            }
 
 
            #endregion
 
            #region midFL
            var midFL = new VerticalScrolViewLayout()
            {
                Height = Application.GetRealHeight(CommonPage.AppRealHeight - CommonPage.Navigation_Height),
                Y = topView.Bottom,
                BackgroundColor = ZigbeeColor.Current.GXCBackgroundColor
            };
            this.AddChidren(midFL);
            var r = new R.MyInternationalizationString();
            foreach (var deviceType in dList)
            {
                var deviceItemFL = new FrameLayout()
                {
                    Height = Application.GetRealHeight(170)
                };
                midFL.AddChidren(deviceItemFL);
                var deviceIMG = new Button()
                {
                    X = Application.GetRealWidth(50),
                    Width = Application.GetMinRealAverage(110),
                    Height = Application.GetMinRealAverage(110),
                    UnSelectedImagePath = DeviceUI.GetDeviceTypeUnSelectedImagePath(deviceType),
                    SelectedImagePath = DeviceUI.GetDeviceTypeSelectedImagePath(deviceType),
                    Gravity = Gravity.CenterVertical
                };
                deviceItemFL.AddChidren(deviceIMG);
 
 
                var deviceName = new Button()
                {
                    X = deviceIMG.Right + Application.GetRealWidth(50),
                    Width = Application.GetRealWidth(700),
                    Height = Application.GetRealHeight(110),
                    TextColor = ZigbeeColor.Current.GXCTextBlackColor,
                    SelectedTextColor = ZigbeeColor.Current.GXCButtonBlueColor,
                    TextAlignment = TextAlignment.CenterLeft,
                    TextSize = 16,
                    Text = DeviceUI.GetDeviceTypeName(deviceType) ,
                    Gravity = Gravity.CenterVertical
                };
                deviceItemFL.AddChidren(deviceName);
                var deviceRight = new Device.CommonForm.SelectedStatuButton()
                {
                    X = Application.GetRealWidth(CommonPage.AppRealWidth - 150),
                    Width = Application.GetMinRealAverage(110),
                    Height = Application.GetMinRealAverage(110),
                    UnSelectedImagePath = "Item/Next.png",
                    SelectedImagePath="Item/NextSelected.png",
                    Gravity = Gravity.CenterVertical
                };
                deviceItemFL.AddChidren(deviceRight);
                var line = new Button()
                {
                    Y = Application.GetRealHeight(170) - 1,
                    Height = 1,
                    BackgroundColor = ZigbeeColor.Current.GXCLineColor,
                    Tag = deviceType
                };
                deviceItemFL.AddChidren(line);
 
                //设备详细类列表
                EventHandler<MouseEventArgs> deviceHandler = (sender, e) =>
                {
                    var sameByRoom = new CategorySceneSelectDeviceByRoom();
                    UserView.HomePage.Instance.AddChidren(sameByRoom);
                    UserView.HomePage.Instance.PageIndex += 1;
                    sameByRoom.Show(sceneTargetDevicesList,deviceType,isFromRoom);
                };
                deviceRight.MouseUpEventHandler += deviceHandler;
                deviceIMG.MouseUpEventHandler += deviceHandler;
                deviceName.MouseUpEventHandler += deviceHandler;
            }
            #endregion
        }
    }
}