gxc
2019-12-23 ddb46a700775aacfb6cc82d9586302a38c8fa0a7
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,45 @@
            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.GetNotHdlMyDeviceEnumInfo(new List<CommonDevice> { 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继电器)
                {
                    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 +178,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 +192,8 @@
                Gravity = Gravity.CenterVertical,
                TextAlignment = TextAlignment.CenterRight,
                TextColor = ZigbeeColor.Current.GXCTextBlackColor,
                TextSize=14,
                IsBold=true
            };
            selectFloorBtn = new Button()
@@ -210,7 +273,7 @@
            functionSceneBodyView = new FrameLayout()
            {
                Y = roomFL.Bottom,
                Height = Application.GetRealHeight(910 + 622),
                Height = Application.GetRealHeight(279+35+1218),
                BackgroundColor = ZigbeeColor.Current.GXCGrayBackgroundColor
            };
            bodyFrameLayout.AddChidren(functionSceneBodyView);
@@ -245,7 +308,7 @@
                {
                    roomBtn.IsSelected = true;
                    curBtn = roomBtn;
                    this.curRoom = room;
                    RefreshFunction(room);
                }
                roomBtn.MouseUpEventHandler += (sender, e) =>
@@ -257,7 +320,7 @@
                    (sender as Button).IsSelected = true;
                    curBtn.IsSelected = false;
                    curBtn = sender as Button;
                    this.curRoom = room;
                    RefreshFunction(room);
                };
            }
@@ -275,112 +338,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.GetDeviceBeloneIcon(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>
        /// 提示没有功能
@@ -403,7 +484,7 @@
                Height = Application.GetRealHeight(200),
                Width = Application.GetRealWidth(700),
                Gravity = Gravity.CenterHorizontal,
                Text = Language.StringByID(R.MyInternationalizationString.NoFunction).Replace("{\\r\\n}", "\r\n"),
                Text = Language.StringByID(R.MyInternationalizationString.NoFunction_Tip).Replace("{\\r\\n}", "\r\n"),
                TextColor = ZigbeeColor.Current.GXCPlaceHolderTextColor,
                TextAlignment = TextAlignment.Center,
                IsMoreLines = true
@@ -464,12 +545,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 +574,7 @@
                X = Application.GetRealWidth(80),
                Width = Application.GetRealWidth(200),
                TextColor = ZigbeeColor.Current.GXCTextGrayColor,
                TextSize = 15,
                TextSize = 14,
                TextAlignment = TextAlignment.CenterLeft,
                TextID = R.MyInternationalizationString.Cancel
            };
@@ -504,8 +585,7 @@
                Width = Application.GetRealWidth(400),
                Gravity = Gravity.CenterHorizontal,
                TextColor = ZigbeeColor.Current.GXCTextBlackColor,
                TextSize = 15,
                TextAlignment = TextAlignment.CenterLeft,
                TextSize = 16,
                Text = device.CommonDevice.DeviceEpointName
            };
            titleFL.AddChidren(deviceName);
@@ -515,7 +595,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 +701,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 +730,7 @@
                X = Application.GetRealWidth(80),
                Width = Application.GetRealWidth(200),
                TextColor = ZigbeeColor.Current.GXCTextGrayColor,
                TextSize = 15,
                TextSize = 14,
                TextAlignment = TextAlignment.CenterLeft,
                TextID = R.MyInternationalizationString.Cancel
            };
@@ -661,8 +741,7 @@
                Width = Application.GetRealWidth(400),
                Gravity = Gravity.CenterHorizontal,
                TextColor = ZigbeeColor.Current.GXCTextBlackColor,
                TextSize = 15,
                TextAlignment = TextAlignment.CenterLeft,
                TextSize = 16,
                Text = device.CommonDevice.DeviceEpointName
            };
            titleFL.AddChidren(deviceName);
@@ -672,7 +751,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 +866,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 +895,7 @@
                X = Application.GetRealWidth(80),
                Width = Application.GetRealWidth(200),
                TextColor = ZigbeeColor.Current.GXCTextGrayColor,
                TextSize = 15,
                TextSize = 14,
                TextAlignment = TextAlignment.CenterLeft,
                TextID = R.MyInternationalizationString.Cancel
            };
@@ -827,7 +906,7 @@
                Width = Application.GetRealWidth(400),
                Gravity = Gravity.CenterHorizontal,
                TextColor = ZigbeeColor.Current.GXCTextBlackColor,
                TextSize = 15,
                TextSize = 16,
                TextAlignment = TextAlignment.CenterLeft,
                Text = device.CommonDevice.DeviceEpointName
            };
@@ -838,7 +917,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 +1032,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 +1061,7 @@
                X = Application.GetRealWidth(80),
                Width = Application.GetRealWidth(200),
                TextColor = ZigbeeColor.Current.GXCTextGrayColor,
                TextSize = 15,
                TextSize = 14,
                TextAlignment = TextAlignment.CenterLeft,
                TextID = R.MyInternationalizationString.Cancel
            };
@@ -993,7 +1072,7 @@
                Width = Application.GetRealWidth(400),
                Gravity = Gravity.CenterHorizontal,
                TextColor = ZigbeeColor.Current.GXCTextBlackColor,
                TextSize = 15,
                TextSize = 16,
                TextAlignment = TextAlignment.CenterLeft,
                Text = device.CommonDevice.DeviceEpointName
            };
@@ -1004,7 +1083,7 @@
                X = Application.GetRealWidth(800),
                Width = Application.GetRealWidth(200),
                TextColor = ZigbeeColor.Current.GXCTextSelectedColor2,
                TextSize = 15,
                TextSize = 14,
                TextAlignment = TextAlignment.CenterRight,
                TextID = R.MyInternationalizationString.Complete
            };