HDL Home App 第二版本 旧平台金堂用 正在使用
黄学彪
2019-12-20 23fb45dd846ed8b62304c408c6bbe64265d4ac8b
ZigbeeApp/Shared/Phone/Device/Room/UnallocatedRoom.cs
@@ -55,14 +55,34 @@
        /// <summary>
        /// 设备类型RowLayout
        /// </summary>
        private RowLayout typeRowLayout;
        private FrameLayout typeRowLayout;
        /// <summary>
        /// 相同的设备列表
        /// </summary>
        public VerticalScrolViewLayout deviceListScrolView;
        /// <summary>
        /// dList
        /// </summary>
        private List<DeviceUI> devList;
        /// <summary>
        /// sceneList
        /// </summary>
        private List<SceneUI> sceneList;
        /// <summary>
        /// 相同类型的设备列表
        /// </summary>
        private Dictionary<int ,List<DeviceUI>> typeDeviceDic;
        /// <summary>
        /// 设备类型的图id
        /// </summary>
        private Dictionary<int, DeviceConcreteType> typeIdDic;
        #endregion
        /// <summary>
        /// UnallocatedRoom
        /// </summary>
        public UnallocatedRoom()
        {
            BackgroundColor = ZigbeeColor.Current.GXCBackgroundColor;
@@ -73,11 +93,57 @@
        /// </summary>
        public void Show()
        {
            InitData();
            AddTop();
            AddBodyView();
        }
        /// <summary>
        /// InitData
        /// </summary>
        private void InitData()
        {
            typeDeviceDic = new Dictionary<int, List<DeviceUI>> { };
            typeIdDic = new Dictionary<int, DeviceConcreteType> { };
            RefreshData();
        }
        /// <summary>
        /// RefreshData
        /// </summary>
        private void RefreshData()
        {
            devList = Shared.Common.Room.CurrentRoom.GetUnalloctedDeviceUIs();
            sceneList = Shared.Common.Room.CurrentRoom.GetUnalloctedScenes();
            typeDeviceDic.Clear();
            typeIdDic.Clear();
            foreach (var device in devList)
            {
                var info = Common.LocalDevice.Current.GetNotHdlMyDeviceEnumInfo(new List<CommonDevice> { device.CommonDevice });
                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;
            }
        }
        ///// <summary>
        ///// RefreshView
        ///// </summary>
        //public void RefreshView()
        //{
        //    InitData();
        //    RefreshBodyView();
        //}
        #region Add____________________________________
@@ -97,7 +163,7 @@
            addBtn = new Button()
            {
                X = Application.GetRealWidth(800),
                X = Application.GetRealWidth(1080-150-80),
                Width = Application.GetRealWidth(150),
                Height = Application.GetRealHeight(80),
                Gravity = Gravity.CenterVertical,
@@ -131,18 +197,20 @@
            };
            bodyFrameLayout.AddChidren(functionSceneBG);
            //功能
            functionBtn = new ButtonLineForm(CommonFormResouce.X_Left, 34, 150, 68);
            functionSceneBG.AddChidren(functionBtn);
            functionBtn.Init();
            functionBtn.SetTitle(R.MyInternationalizationString.Function);
            functionBtn.IsSelected = true;
            //场景
            sceneBtn = new ButtonLineForm(CommonFormResouce.X_Left + 150 + 20, 34, 150, 68);
            sceneBtn = new ButtonLineForm(CommonFormResouce.X_Left, 43);
            functionSceneBG.AddChidren(sceneBtn);
            sceneBtn.Init();
            sceneBtn.SetTitle(R.MyInternationalizationString.Scence);
            sceneBtn.IsSelected = true;
            //功能
            functionBtn = new ButtonLineForm(CommonFormResouce.X_Left + 150 + 20, 43);
            functionSceneBG.AddChidren(functionBtn);
            functionBtn.Init();
            functionBtn.SetTitle(R.MyInternationalizationString.Function);
            functionBtn.IsSelected = false;
            functionBtn.X = sceneBtn.Right;
            //选择功能分栏
            functionBtn.NameBtn.MouseUpEventHandler += FunctionBtn_MouseUpEventHandler;
@@ -152,7 +220,7 @@
            //功能和场景bodyView
            functionSceneBodyView = new FrameLayout()
            {
                Y= Application.GetRealHeight(187-58),
                Y= Application.GetRealHeight(127),
                Height = Application.GetRealHeight(1607),
                BackgroundColor = ZigbeeColor.Current.GXCGrayBackgroundColor
            };
@@ -244,68 +312,79 @@
        public void ShowFunction(bool selectAll)
        {
            SelectAll = selectAll;
            var devList = Common.Room.AllRoomDeviceUIList;
            //选择功能--直接从房间的devicelist中获取
            if (devList == null)
            {
                return;
            }
            if (devList.Count == 0)
            if (typeIdDic.Count == 0)
            {
                ShowNoFunctionTip();
            }
            else
            {
                var functionTypeView1 = new FrameLayout
                {
                    X = Application.GetRealWidth(CommonFormResouce.X_Left),
                    Y = Application.GetRealHeight(58),
                    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(58+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),
                    Y=Application.GetRealHeight(58),
                    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(372),
                    Width = Application.GetRealWidth(1028),
                    Height = functionSceneBodyView.Height - Application.GetRealHeight(279 + 50) - 1,
                    BackgroundColor = ZigbeeColor.Current.GXCBackgroundColor
                    Height = Application.GetRealHeight(1034),
                    BackgroundColor = ZigbeeColor.Current.GXCBackgroundColor,
                };
                functionSceneBodyView.AddChidren(deviceListScrolView);
                deviceListScrolView.SetCornerWithSameRadius(Application.GetRealHeight(58), HDLUtils.RectCornerTopLeft);
                tempFunctionTypeBtn = new FunctionButton();
                tempFunctionTypeBtn.Init("", "");
                foreach (var deviceType in Common.Room.AllRoomDeviceTypeList)
                foreach (var deviceType in typeIdDic)
                {
                    typeRowLayout = new RowLayout()
                    typeRowLayout = new FrameLayout()
                    {
                        Width = Application.GetRealWidth(CommonPage.AppRealWidth / 5),
                        LineColor = ZigbeeColor.Current.GXCBackgroundColor,
                        Tag = deviceType
                        Width = Application.GetRealWidth(220),
                    };
                    functionTypeScrowView.AddChidren(typeRowLayout);
                    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 == devList[0].CommonDevice.Type)
                    if (functionTypeScrowView.ChildrenCount == 1)
                    {
                        ShowSameTypeFunction(functionTypeIMG.ImageBtn, null);
                    }
@@ -329,20 +408,7 @@
            var sameTypeList = new List<DeviceUI> { };
            var selectedList = new List<DeviceUI> { };
            foreach (var devieceUI in Common.Room.AllRoomDeviceUIList)
            {
                if (devieceUI == null || devieceUI.CommonDevice == null)
                {
                    continue;
                }
                if (devieceUI.CommonDevice.Type.ToString() == (typeSender as Button).Tag.ToString())
                {
                    if (!sameTypeList.Contains(devieceUI))
                    {
                        sameTypeList.Add(devieceUI);
                    }
                }
            }
            sameTypeList = typeDeviceDic[int.Parse((typeSender as Button).Tag.ToString())];
            if (SelectAll)
            {
@@ -360,14 +426,13 @@
                var deviceRow = new SelectFunctionView(0, 35);
                deviceRow.Init(deviceUI.IconPath, deviceUI.OnlineIconPath);
                deviceRow.SetTitle(deviceUI.CommonDevice.DeviceEpointName);
                deviceRow.SetStatu(deviceUI.CommonDevice.IsOnline == 1);
                deviceRow.SetSelectStatu(SelectAll);
                deviceRow.IsSelected = SelectAll;
                deviceTypeRowLayout.AddChidren(deviceRow);
                EventHandler<MouseEventArgs> eventHandler = (sender, e) =>
                {
                    deviceRow.SelectBtn.IsSelected = !deviceRow.SelectBtn.IsSelected;
                    if (deviceRow.SelectBtn.IsSelected)
                    deviceRow.IsSelected = !deviceRow.IsSelected;
                    if (deviceRow.IsSelected)
                    {
                        if (!selectedList.Contains(deviceUI))
                        {
@@ -382,11 +447,16 @@
                        }
                    }
                };
                deviceRow.NameBtn.MouseUpEventHandler += eventHandler;
                deviceRow.ImageBtn.MouseUpEventHandler += eventHandler;
                deviceRow.MouseUpEventHandler+=eventHandler;
                deviceRow.SelectBtn.MouseUpEventHandler += eventHandler;
                deviceRow.ClickBtn.MouseUpEventHandler += eventHandler;
                var addBackground = new Button
                {
                    Y = Application.GetRealHeight(1405),
                    Width = Application.GetMinRealAverage(1080),
                    Height = Application.GetMinRealAverage(202),
                    UnSelectedImagePath = "Room/AddBackground.png"
                };
                functionSceneBodyView.AddChidren(addBackground);
                var add = new Button
                {
                    Y = Application.GetRealHeight(1428),
@@ -394,22 +464,25 @@
                    Height = Application.GetRealHeight(156),
                    BackgroundColor = ZigbeeColor.Current.GXCBackgroundColor,
                    TextColor = ZigbeeColor.Current.GXCTextSelectedColor4,
                    Radius = (uint)Application.GetRealHeight(17),
                    Radius = (uint)Application.GetRealHeight(35),
                    TextID = R.MyInternationalizationString.AddTo,
                    Gravity = Gravity.CenterHorizontal
                    Gravity = Gravity.CenterHorizontal,
                    TextSize=17
                };
                functionSceneBodyView.AddChidren(add);
                add.MouseUpEventHandler += (sender, e) =>
                {
                    var selectZone = new SelectZone();
                    CommonPage.Instance.AddChidren(selectZone);
                    AddChidren(selectZone);
                    selectZone.Init();
                    selectZone.ZoneAction = (r) =>
                    {
                        foreach (var d in selectedList)
                        {
                            r.AddDevice(d.FileName);
                            r.AddDevice(d.CommonDevice,true);
                            deviceListScrolView.RemoveViewByTag(d);
                        }
                        RefreshData();
                    };
                };
            }
@@ -420,6 +493,7 @@
        /// </summary>
        private void ShowNoFunctionTip()
        {
            return;
            var noFunction = new Button()
            {
                Y = Application.GetRealHeight(320),
@@ -452,52 +526,45 @@
        /// </summary>
        public void ShowScene(bool selectAll)
        {
            //刷新场景
            //var reFreshResult=await Shared.Common.Room.RefreshSceneUIList();
            Shared.Common.SceneRoomUI.GetAllSceneRoomUIList();
            if (SceneRoomUI.AllSceneRoomUIList == null)
            {
                return;
            }
            var sceneList = SceneRoomUI.AllSceneRoomUIList;
            List<SceneRoomUI> selectedList = new List<SceneRoomUI>();
            if(selectAll)
            {
                selectedList.AddRange(sceneList);
            }
            if (sceneList.Count == 0)
            List<SceneUI> selectedList = new List<SceneUI>();
            if (sceneList == null || sceneList.Count == 0)
            {
                ShowNoSceneTip();
            }
            else
            {
            {
                if (selectAll)
                {
                    selectedList.AddRange(sceneList);
                }
                var sceneScrolView = new VerticalScrolViewLayout
                {
                    Y = Application.GetRealHeight(0)
                    Y = Application.GetRealHeight(22),
                    Height=Application.GetRealHeight(1405-22)
                };
                functionSceneBodyView.AddChidren(sceneScrolView);
                foreach (var sceneRoomUI in sceneList)
                foreach (var sceneUI in sceneList)
                {
                    var sceneFL = new FrameLayout()
                    {
                        Width=Application.GetRealWidth(CommonFormResouce.AppRealWidth),
                        Height = Application.GetRealHeight(397+58),
                        Width = Application.GetRealWidth(CommonFormResouce.AppRealWidth),
                        Height = Application.GetRealHeight(397 + 58),
                        Gravity = Gravity.CenterHorizontal,
                        BackgroundColor = ZigbeeColor.Current.GXCGrayBackgroundColor,
                        Tag = sceneRoomUI
                        Tag = sceneUI,
                        Radius = (uint)Application.GetRealHeight(17)
                    };
                    sceneScrolView.AddChidren(sceneFL);
                    var sceneImg = new Button()
                    var sceneImg = new ImageView()
                    {
                        X=Application.GetRealWidth(179),
                        Y=Application.GetRealHeight(58),
                        X = Application.GetRealWidth(179),
                        Y = Application.GetRealHeight(58),
                        Width = Application.GetRealWidth(844),
                        Height = Application.GetRealHeight(397),
                        UnSelectedImagePath = sceneRoomUI.sceneUI.IconPath,
                        ImagePath = sceneUI.IconPath,
                        Radius = (uint)Application.GetRealHeight(17)
                    };
                    sceneImg.UnSelectedImagePath = "Room/r0.png";
                    sceneFL.AddChidren(sceneImg);
                    var selectedBtn = new Button
@@ -508,7 +575,7 @@
                        Height = Application.GetMinRealAverage(60),
                        UnSelectedImagePath = "Room/ItemUnSelected.png",
                        SelectedImagePath = "Room/ItemSelected.png",
                        IsSelected= selectAll
                        IsSelected = selectAll
                    };
                    sceneFL.AddChidren(selectedBtn);
@@ -538,33 +605,42 @@
                        Width = Application.GetRealWidth(176),
                        Height = Application.GetRealHeight(200),
                        TextColor = ZigbeeColor.Current.GXCTextWhiteColor,
                        Text = sceneRoomUI.sceneUI.Name,
                        Text = sceneUI.Name,
                        Gravity = Gravity.Center,
                        IsMoreLines = true
                    };
                    leftFL.AddChidren(sceneNameBtn);
                    EventHandler<MouseEventArgs> eventHandler = (sender,e) =>
                    EventHandler<MouseEventArgs> eventHandler = (sender, e) =>
                    {
                        selectedBtn.IsSelected = !selectedBtn.IsSelected;
                        if(selectedBtn.IsSelected)
                        if (selectedBtn.IsSelected)
                        {
                            if(!selectedList.Contains(sceneRoomUI))
                            if (!selectedList.Contains(sceneUI))
                            {
                                selectedList.Add(sceneRoomUI);
                                selectedList.Add(sceneUI);
                            }
                        }
                        else
                        {
                            if (selectedList.Contains(sceneRoomUI))
                            if (selectedList.Contains(sceneUI))
                            {
                                selectedList.Remove(sceneRoomUI);
                                selectedList.Remove(sceneUI);
                            }
                        }
                    };
                    selectedBtn.MouseUpEventHandler += eventHandler;
                    sceneImg.MouseUpEventHandler += eventHandler;
                }
                var addBackground = new Button
                {
                    Y = Application.GetRealHeight(1405),
                    Width = Application.GetMinRealAverage(1080),
                    Height = Application.GetMinRealAverage(202),
                    UnSelectedImagePath = "Room/AddBackground.png"
                };
                functionSceneBodyView.AddChidren(addBackground);
                var add = new Button
                {
@@ -573,9 +649,10 @@
                    Height = Application.GetRealHeight(156),
                    BackgroundColor = ZigbeeColor.Current.GXCBackgroundColor,
                    TextColor = ZigbeeColor.Current.GXCTextSelectedColor4,
                    Radius = (uint)Application.GetRealHeight(17),
                    Radius = (uint)Application.GetRealHeight(35),
                    TextID = R.MyInternationalizationString.AddTo,
                    Gravity=Gravity.CenterHorizontal
                    Gravity = Gravity.CenterHorizontal,
                    TextSize=17,
                };
                functionSceneBodyView.AddChidren(add);
                add.MouseUpEventHandler += (sender, e) =>
@@ -585,10 +662,12 @@
                    selectZone.Init();
                    selectZone.ZoneAction = (r) =>
                    {
                        foreach(var s in selectedList)
                        foreach (var s in selectedList)
                        {
                            r.AddScene(s.sceneUI);
                            r.AddScene(s);
                            sceneScrolView.RemoveViewByTag(s);
                        }
                        RefreshData();
                    };
                };
            }
@@ -599,6 +678,7 @@
        /// </summary>
        private void ShowNoSceneTip()
        {
            return;
            var noFunction = new Button()
            {
                Y = Application.GetRealHeight(320),