HDL Home App 第二版本 旧平台金堂用 正在使用
黄学彪
2019-12-30 3dcbd186c42c598c0c08d1cd37034cf2baa09e54
ZigbeeApp/Shared/Phone/Device/Category/SelectDevice.cs
@@ -3,6 +3,7 @@
using Shared.Common;
using Shared.Phone.Device.CommonForm;
using Shared.Phone.UserView;
using ZigBee.Device;
namespace Shared.Phone.Device.Category
{
@@ -56,11 +57,11 @@
        /// <summary>
        /// 设备类型RowLayout
        /// </summary>
        private FrameLayout typeRowLayout;
        //private FrameLayout typeRowLayout;
        /// <summary>
        /// 功能类型按钮
        /// </summary>
        private FunctionButton functionTypeIMG;
        //private FunctionButton functionTypeIMG;
        /// <summary>
        /// 温度
        /// </summary>
@@ -74,9 +75,28 @@
        /// </summary>
        private int fanid;
        /// <summary>
        /// dList
        /// </summary>
        private List<DeviceUI> devList;
        /// <summary>
        /// 相同类型的设备列表
        /// </summary>
        private Dictionary<int, List<DeviceUI>> typeDeviceDic;
        /// <summary>
        /// 设备类型的图id
        /// </summary>
        private Dictionary<int, DeviceConcreteType> typeIdDic;
        /// <summary>
        /// 当前选中房间
        /// </summary>
        private Common.Room curRoom;
        #endregion
        /// <summary>
        /// RemoveFromParent
        /// </summary>
        public override void RemoveFromParent()
        {
            HomePage.Instance.ScrollEnabled = true;
@@ -96,6 +116,8 @@
        /// </summary>
        public void Show()
        {
            InitData();
            if (sceneTargetDevice == null)
            {
                sceneTargetDevice = new SceneTargetDeviceUI { Type = 0 };
@@ -107,6 +129,47 @@
            RefreshBodyView(Config.Instance.Home.CurrentFloorId);
        }
        /// <summary>
        /// InitData
        /// </summary>
        private void InitData()
        {
            typeDeviceDic = new Dictionary<int, List<DeviceUI>> { };
            typeIdDic = new Dictionary<int, DeviceConcreteType> { };
        }
        /// <summary>
        /// RefreshData
        /// </summary>
        private void RefreshData(Common.Room room)
        {
            devList = room.DeviceUIList;
            typeDeviceDic.Clear();
            typeIdDic.Clear();
            foreach (var device in devList)
            {
                var info = Common.LocalDevice.Current.GetDeviceBelongEnumInfo(device.CommonDevice);
                if (info.BeloneType == DeviceBeloneType.A开关 || info.BeloneType == DeviceBeloneType.A彩灯
                    || info.BeloneType == DeviceBeloneType.A插座 || info.BeloneType == DeviceBeloneType.A智能空开
                    || info.BeloneType == DeviceBeloneType.A灯光 || info.BeloneType == DeviceBeloneType.A空调
                    || info.BeloneType == DeviceBeloneType.A窗帘 || info.BeloneType == DeviceBeloneType.A继电器
                    || info.BeloneType == DeviceBeloneType.A调光器
                    )
                {
                    if (typeDeviceDic.ContainsKey(info.BeloneTextId) == false)
                    {
                        var sameDevList = new List<DeviceUI> { };
                        sameDevList.Add(device);
                        typeDeviceDic[info.BeloneTextId] = sameDevList;
                    }
                    else
                    {
                        typeDeviceDic[info.BeloneTextId].Add(device);
                    }
                    typeIdDic[info.BeloneTextId] = info.ConcreteType;
                }
            }
        }
        #region Add____________________________________
        /// <summary>
@@ -117,7 +180,7 @@
            var top = new TopFrameLayout();
            AddChidren(top);
            top.InitTopview();
            top.SetTopTitle(R.MyInternationalizationString.AddScence);
            top.SetTopTitle(R.MyInternationalizationString.AddFunction);
            top.backButton.MouseUpEventHandler += (sender, e) =>
            {
                RemoveFromParent();
@@ -131,6 +194,8 @@
                Gravity = Gravity.CenterVertical,
                TextAlignment = TextAlignment.CenterRight,
                TextColor = ZigbeeColor.Current.GXCTextBlackColor,
                TextSize=14,
                IsBold=true
            };
            selectFloorBtn = new Button()
@@ -210,54 +275,44 @@
            functionSceneBodyView = new FrameLayout()
            {
                Y = roomFL.Bottom,
                Height = Application.GetRealHeight(910 + 622),
                Height = Application.GetRealHeight(279+35+1218),
                BackgroundColor = ZigbeeColor.Current.GXCGrayBackgroundColor
            };
            bodyFrameLayout.AddChidren(functionSceneBodyView);
            Button curBtn = new Button();
            RoomButton curBtn = new RoomButton(0, 0);
            foreach (var room in Common.Room.CurrentRoom.GetRoomsByFloorIdAppendLoveRoom(floorId))
            {
                var row = new FrameLayout()
                {
                    Width = Application.GetRealWidth(187 + 50),
                    Height = Application.GetRealHeight(204),
                    Width = Application.GetRealWidth(255),
                    Height = Application.GetRealHeight(167)
                };
                roomFL.AddChidren(row);
                var roomBtn = new Button()
                {
                    Width = Application.GetRealWidth(187),
                    Height = Application.GetRealHeight(78),
                    Radius = (uint)Application.GetRealHeight(78 / 2),
                    Gravity = Gravity.Center,
                    Text = room.Name,
                    TextColor = ZigbeeColor.Current.GXCTextGrayColor,
                    SelectedTextColor = ZigbeeColor.Current.GXCTextWhiteColor,
                    BackgroundColor = ZigbeeColor.Current.GXCButtonUnSelectedColor3,
                    SelectedBackgroundColor = ZigbeeColor.Current.GXCButtonSelectedColor,
                    BorderColor = ZigbeeColor.Current.GXCBorderUnSelectedColor,
                    BorderWidth = 1
                };
                RoomButton roomBtn = new RoomButton(0, 0);
                roomBtn.Gravity = Gravity.Center;
                roomBtn.Init();
                roomBtn.SetTitle(room.Name);
                row.AddChidren(roomBtn);
                if (room.IsLove)
                {
                    roomBtn.IsSelected = true;
                    curBtn = roomBtn;
                    this.curRoom = room;
                    RefreshFunction(room);
                }
                roomBtn.MouseUpEventHandler += (sender, e) =>
                roomBtn.ButtonClickEvent += (sender, e) =>
                {
                    if ((sender as Button) == curBtn)
                    if (sender == curBtn)
                    {
                        return;
                    }
                    (sender as Button).IsSelected = true;
                    sender.IsSelected = true;
                    curBtn.IsSelected = false;
                    curBtn = sender as Button;
                    curBtn = sender;
                    this.curRoom = room;
                    RefreshFunction(room);
                };
            }
@@ -275,112 +330,130 @@
        /// <param name="room"></param>
        private void RefreshFunction(Common.Room room)
        {
            RefreshData(room);
            functionSceneBodyView.RemoveAll();
            if (room.DeviceUIList.Count == 0)
            if (typeDeviceDic.Count == 0)
            {
                ShowNoFunctionTip();
            }
            else
            {
                var functionTypeView1 = new FrameLayout
                {
                    X = Application.GetRealWidth(CommonFormResouce.X_Left),
                    Height = Application.GetRealHeight(160),
                    Width = Application.GetRealWidth(1028),
                    BackgroundColor = ZigbeeColor.Current.GXCBackgroundColor
                };
                functionSceneBodyView.AddChidren(functionTypeView1);
                functionTypeView1.SetCornerWithSameRadius(Application.GetRealHeight(17), HDLUtils.RectCornerTopLeft);
                var functionTypeView2 = new FrameLayout
                {
                    X = Application.GetRealWidth(CommonFormResouce.X_Left),
                    Y = Application.GetRealHeight(150),
                    Height = Application.GetRealHeight(279 - 150),
                    Width = Application.GetRealWidth(1028),
                    BackgroundColor = ZigbeeColor.Current.GXCBackgroundColor
                };
                functionSceneBodyView.AddChidren(functionTypeView2);
                functionTypeView2.SetCornerWithSameRadius(Application.GetRealHeight(58), HDLUtils.RectCornerBottomLeft);
                functionTypeScrowView = new HorizontalScrolViewLayout
                {
                    X = Application.GetRealWidth(CommonFormResouce.X_Left),
                    Height = Application.GetRealHeight(279),
                    Width = Application.GetRealWidth(1028),
                    BackgroundColor = ZigbeeColor.Current.GXCBackgroundColor
                    Width = Application.GetRealWidth(1028)
                };
                functionSceneBodyView.AddChidren(functionTypeScrowView);
                deviceListScrolView = new VerticalScrolViewLayout
                {
                    X = Application.GetRealWidth(CommonFormResouce.X_Left),
                    Y = functionTypeScrowView.Bottom + Application.GetRealHeight(50),
                    Y = Application.GetRealHeight(35 + 275),
                    Width = Application.GetRealWidth(1028),
                    Height = functionSceneBodyView.Height - Application.GetRealHeight(279 + 50) - 1,
                    Height = Application.GetRealHeight(1218),
                    BackgroundColor = ZigbeeColor.Current.GXCBackgroundColor
                };
                functionSceneBodyView.AddChidren(deviceListScrolView);
                deviceListScrolView.SetCornerWithSameRadius(Application.GetRealHeight(58), HDLUtils.RectCornerTopLeft);
                tempFunctionTypeBtn = new FunctionButton();
                tempFunctionTypeBtn.Init("","");
                EventHandler<MouseEventArgs> ShowSameTypeFunction = (object typeSender, MouseEventArgs mouseEventArgs) =>
                foreach (var deviceType in typeIdDic)
                {
                    tempFunctionTypeBtn.IsSelected = false;
                    tempFunctionTypeBtn = (typeSender as Button).Parent as FunctionButton;
                    ((typeSender as Button).Parent as FunctionButton).IsSelected = true;
                    deviceListScrolView.RemoveAll();
                    var sameTypeList = new List<DeviceUI> { };
                    foreach (var devieceUI in room.DeviceUIList)
                    var typeRowLayout = new FrameLayout()
                    {
                        if (devieceUI == null || devieceUI.CommonDevice == null)
                        {
                            continue;
                        }
                        if (devieceUI.CommonDevice.Type.ToString() == (typeSender as Button).Tag.ToString())
                        {
                            if (!sameTypeList.Contains(devieceUI))
                            {
                                sameTypeList.Add(devieceUI);
                            }
                        }
                    }
                    foreach (var device in sameTypeList)
                    {
                        if (beforeSceneTargetDeviceUIs.Find((obj) => obj.DeviceUI.DeviceEpoint == device.DeviceEpoint && obj.DeviceUI.DeviceAddr == device.DeviceAddr) != null)
                        {
                            continue;
                        }
                        var deviceTypeRowLayout = new FrameLayout()
                        {
                            Height = Application.GetRealHeight(127 + 35),
                            Tag = device
                        };
                        deviceListScrolView.AddChidren(deviceTypeRowLayout);
                        var deviceRow = new FunctionRow(0, 35);
                        deviceTypeRowLayout.AddChidren(deviceRow);
                        deviceRow.Init(device.IconPath, device.OnlineIconPath,true);
                        deviceRow.SetTitle(device.CommonDevice.DeviceEpointName);
                        deviceRow.SetStatu(device.CommonDevice.IsOnline == 1);
                        deviceRow.HideSwitchBtn(false);
                        deviceRow.ClickBtn.MouseUpEventHandler += (sender, e) =>
                        {
                            ShowSelectAction(device, sceneTargetDevice);
                        };
                    }
                };
                foreach (var deviceType in Common.Room.GetdeviceTypes(room))
                {
                    typeRowLayout = new FrameLayout()
                    {
                        Width = Application.GetRealWidth(CommonPage.AppRealWidth / 5),
                        Tag = deviceType
                        Width = Application.GetRealWidth(220),
                    };
                    functionTypeScrowView.AddChidren(typeRowLayout);
                    functionTypeIMG = new FunctionButton()
                    var functionTypeIMG = new FunctionButton()
                    {
                        Tag = deviceType
                        Tag = deviceType.Key
                    };
                    functionTypeIMG.Init(DeviceUI.GetDeviceTypeUnSelectedImagePath(deviceType), DeviceUI.GetDeviceTypeUnSelectedImagePath(deviceType));
                    functionTypeIMG.SetTitle(DeviceUI.GetDeviceTypeName(deviceType));
                    string imgPath = string.Empty;
                    string imgSeletedPath = string.Empty;
                    Common.LocalDevice.Current.GetDeviceObjectIcon(deviceType.Value, ref imgPath, ref imgSeletedPath);
                    functionTypeIMG.Init(imgPath, imgSeletedPath);
                    functionTypeIMG.SetTitle(deviceType.Key);
                    typeRowLayout.AddChidren(functionTypeIMG);
                    functionTypeIMG.ClickBtn.MouseUpEventHandler += ShowSameTypeFunction;
                    if (deviceType == room.DeviceUIList[0].CommonDevice.Type)
                    if (functionTypeScrowView.ChildrenCount == 1)
                    {
                        ShowSameTypeFunction(functionTypeIMG.ClickBtn, null);
                        ShowSameTypeFunction(functionTypeIMG.ImageBtn, null);
                    }
                }
            }
        }
        /// <summary>
        /// 显示相同类型的功能
        /// </summary>
        /// <param name="typeSender">typeSender.</param>
        /// <param name="mouseEventArgs">The ${ParameterType} instance containing the event data.</param>
        private void ShowSameTypeFunction(object typeSender, MouseEventArgs mouseEventArgs)
        {
            tempFunctionTypeBtn.IsSelected = false;
            tempFunctionTypeBtn = (typeSender as Button).Parent as FunctionButton;
            ((typeSender as Button).Parent as FunctionButton).IsSelected = true;
            deviceListScrolView.RemoveAll();
            var sameTypeList = new List<DeviceUI> { };
            sameTypeList = typeDeviceDic[int.Parse((typeSender as Button).Tag.ToString())];
            foreach (var device in sameTypeList)
            {
                if (beforeSceneTargetDeviceUIs.Find((obj) => obj.DeviceUI.DeviceEpoint == device.DeviceEpoint && obj.DeviceUI.DeviceAddr == device.DeviceAddr) != null)
                {
                    continue;
                }
                var deviceTypeRowLayout = new FrameLayout()
                {
                    Height = Application.GetRealHeight(127 + 35),
                    Tag = device
                };
                deviceListScrolView.AddChidren(deviceTypeRowLayout);
                var deviceRow = new FunctionRow(0, 35);
                deviceTypeRowLayout.AddChidren(deviceRow);
                deviceRow.Init(device.IconPath, device.OnlineIconPath, true);
                deviceRow.SetTitle(device.CommonDevice.DeviceEpointName);
                deviceRow.IsSelected = true;
                deviceRow.HideSwitchBtn(false);
                deviceRow.ClickBtn.MouseUpEventHandler += (sender, e) =>
                {
                    ShowSelectAction(device, sceneTargetDevice);
                };
            }
        }
        /// <summary>
        /// 提示没有功能
@@ -464,12 +537,12 @@
                Height = Application.GetRealHeight(530),
            };
            dialog.AddChidren(selectFL);
            selectFL.Animate = Animate.DownToUp;
            //selectFL.Animate = Animate.DownToUp;
            var titleBG = new FrameLayout
            {
                Height = Application.GetRealHeight(138 * 2),
                Radius = (uint)Application.GetRealHeight(20),
                Radius = (uint)Application.GetRealHeight(58),
                BackgroundColor = ZigbeeColor.Current.GXCBackgroundColor
            };
            selectFL.AddChidren(titleBG);
@@ -493,7 +566,7 @@
                X = Application.GetRealWidth(80),
                Width = Application.GetRealWidth(200),
                TextColor = ZigbeeColor.Current.GXCTextGrayColor,
                TextSize = 15,
                TextSize = 14,
                TextAlignment = TextAlignment.CenterLeft,
                TextID = R.MyInternationalizationString.Cancel
            };
@@ -501,11 +574,10 @@
            var deviceName = new Button
            {
                Width = Application.GetRealWidth(400),
                Width = Application.GetRealWidth(600),
                Gravity = Gravity.CenterHorizontal,
                TextColor = ZigbeeColor.Current.GXCTextBlackColor,
                TextSize = 15,
                TextAlignment = TextAlignment.CenterLeft,
                TextSize = 16,
                Text = device.CommonDevice.DeviceEpointName
            };
            titleFL.AddChidren(deviceName);
@@ -515,7 +587,7 @@
                X = Application.GetRealWidth(800),
                Width = Application.GetRealWidth(200),
                TextColor = ZigbeeColor.Current.GXCTextSelectedColor2,
                TextSize = 15,
                TextSize = 14,
                TextAlignment = TextAlignment.CenterRight,
                TextID = R.MyInternationalizationString.Complete
            };
@@ -621,12 +693,12 @@
                Height = Application.GetRealHeight(752),
            };
            dialog.AddChidren(selectFL);
            selectFL.Animate = Animate.DownToUp;
            //selectFL.Animate = Animate.DownToUp;
            var titleBG = new FrameLayout
            {
                Height = Application.GetRealHeight(138 * 2),
                Radius = (uint)Application.GetRealHeight(20),
                Radius = (uint)Application.GetRealHeight(58),
                BackgroundColor = ZigbeeColor.Current.GXCBackgroundColor
            };
            selectFL.AddChidren(titleBG);
@@ -650,7 +722,7 @@
                X = Application.GetRealWidth(80),
                Width = Application.GetRealWidth(200),
                TextColor = ZigbeeColor.Current.GXCTextGrayColor,
                TextSize = 15,
                TextSize = 14,
                TextAlignment = TextAlignment.CenterLeft,
                TextID = R.MyInternationalizationString.Cancel
            };
@@ -658,11 +730,10 @@
            var deviceName = new Button
            {
                Width = Application.GetRealWidth(400),
                Width = Application.GetRealWidth(600),
                Gravity = Gravity.CenterHorizontal,
                TextColor = ZigbeeColor.Current.GXCTextBlackColor,
                TextSize = 15,
                TextAlignment = TextAlignment.CenterLeft,
                TextSize = 16,
                Text = device.CommonDevice.DeviceEpointName
            };
            titleFL.AddChidren(deviceName);
@@ -672,7 +743,7 @@
                X = Application.GetRealWidth(800),
                Width = Application.GetRealWidth(200),
                TextColor = ZigbeeColor.Current.GXCTextSelectedColor2,
                TextSize = 15,
                TextSize = 14,
                TextAlignment = TextAlignment.CenterRight,
                TextID = R.MyInternationalizationString.Complete
            };
@@ -787,12 +858,12 @@
                Height = Application.GetRealHeight(752),
            };
            dialog.AddChidren(selectFL);
            selectFL.Animate = Animate.DownToUp;
            //selectFL.Animate = Animate.DownToUp;
            var titleBG = new FrameLayout
            {
                Height = Application.GetRealHeight(138 * 2),
                Radius = (uint)Application.GetRealHeight(20),
                Radius = (uint)Application.GetRealHeight(58),
                BackgroundColor = ZigbeeColor.Current.GXCBackgroundColor
            };
            selectFL.AddChidren(titleBG);
@@ -816,7 +887,7 @@
                X = Application.GetRealWidth(80),
                Width = Application.GetRealWidth(200),
                TextColor = ZigbeeColor.Current.GXCTextGrayColor,
                TextSize = 15,
                TextSize = 14,
                TextAlignment = TextAlignment.CenterLeft,
                TextID = R.MyInternationalizationString.Cancel
            };
@@ -824,10 +895,10 @@
            var deviceName = new Button
            {
                Width = Application.GetRealWidth(400),
                Width = Application.GetRealWidth(600),
                Gravity = Gravity.CenterHorizontal,
                TextColor = ZigbeeColor.Current.GXCTextBlackColor,
                TextSize = 15,
                TextSize = 16,
                TextAlignment = TextAlignment.CenterLeft,
                Text = device.CommonDevice.DeviceEpointName
            };
@@ -838,7 +909,7 @@
                X = Application.GetRealWidth(800),
                Width = Application.GetRealWidth(200),
                TextColor = ZigbeeColor.Current.GXCTextSelectedColor2,
                TextSize = 15,
                TextSize = 14,
                TextAlignment = TextAlignment.CenterRight,
                TextID = R.MyInternationalizationString.Complete
            };
@@ -953,12 +1024,12 @@
                Height = Application.GetRealHeight(1106),
            };
            dialog.AddChidren(selectFL);
            selectFL.Animate = Animate.DownToUp;
            //selectFL.Animate = Animate.DownToUp;
            var titleBG = new FrameLayout
            {
                Height = Application.GetRealHeight(138 * 2),
                Radius = (uint)Application.GetRealHeight(20),
                Radius = (uint)Application.GetRealHeight(58),
                BackgroundColor = ZigbeeColor.Current.GXCBackgroundColor
            };
            selectFL.AddChidren(titleBG);
@@ -982,7 +1053,7 @@
                X = Application.GetRealWidth(80),
                Width = Application.GetRealWidth(200),
                TextColor = ZigbeeColor.Current.GXCTextGrayColor,
                TextSize = 15,
                TextSize = 14,
                TextAlignment = TextAlignment.CenterLeft,
                TextID = R.MyInternationalizationString.Cancel
            };
@@ -990,10 +1061,10 @@
            var deviceName = new Button
            {
                Width = Application.GetRealWidth(400),
                Width = Application.GetRealWidth(600),
                Gravity = Gravity.CenterHorizontal,
                TextColor = ZigbeeColor.Current.GXCTextBlackColor,
                TextSize = 15,
                TextSize = 16,
                TextAlignment = TextAlignment.CenterLeft,
                Text = device.CommonDevice.DeviceEpointName
            };
@@ -1004,7 +1075,7 @@
                X = Application.GetRealWidth(800),
                Width = Application.GetRealWidth(200),
                TextColor = ZigbeeColor.Current.GXCTextSelectedColor2,
                TextSize = 15,
                TextSize = 14,
                TextAlignment = TextAlignment.CenterRight,
                TextID = R.MyInternationalizationString.Complete
            };
@@ -1082,12 +1153,9 @@
                            tempId = open.temperatureList.IndexOf(tasklist.Data2/100);
                        }
                    }
                    open.pickerView.setCurrentItems(tempId, modelId, fanid);
                }
            }
            comfrimBtn.MouseUpEventHandler = (sender, e) =>
            {