WJC
2019-12-30 f1c3921b08bb22ac6f5db22d620e01d7e8e5c49f
ZigbeeApp/Shared/Phone/Device/Category/CategoryAddScene.cs
@@ -15,28 +15,28 @@
        /// bodyFrameLayout
        /// </summary>
        private FrameLayout bodyFrameLayout;
        /// <summary>
        /// floorIds
        /// </summary>
        List<string> floorIds = new List<string> { };
        /// <summary>
        /// floorNames
        /// </summary>
        List<string> floorNames = new List<string> { };
        /// <summary>
        /// roomNames
        /// </summary>
        List<List<string>> roomNames = new List<List<string>> { };
        /// <summary>
        /// roomNames
        /// </summary>
        List<List<Common.Room>> rooms = new List<List<Common.Room>> { };
        ///// <summary>
        ///// floorIds
        ///// </summary>
        //List<string> floorIds = new List<string> { };
        ///// <summary>
        ///// floorNames
        ///// </summary>
        //List<string> floorNames = new List<string> { };
        ///// <summary>
        ///// roomNames
        ///// </summary>
        //List<List<string>> roomNames = new List<List<string>> { };
        ///// <summary>
        ///// roomNames
        ///// </summary>
        //List<List<Common.Room>> rooms = new List<List<Common.Room>> { };
        /// <summary>
        /// ImagePath
        /// </summary>
        private string ImagePath="SceneIcon/1.png";
        /// <summary>
        /// 图片来源 0--本地图库 1--拍照 2--系统图库
        /// 图片来源 0--本地图库 1--拍照 2--系统图库
        /// </summary>
        public int IconPathType = 0;
        /// <summary>
@@ -55,6 +55,11 @@
        /// The confirm button.
        /// </summary>
        private CommonForm.CompleteButton confirmBtn;
        /// <summary>
        /// backGround
        /// </summary>
        private Button backGround;
        /// <summary>
        /// 是否修改
@@ -127,14 +132,7 @@
                    }
                    else if (targetDevice.Type == 2)
                    {
                        if(targetDevice.DelayTime<60)
                        {
                            devNameText = $"{targetDevice.DelayTime} {Language.StringByID(R.MyInternationalizationString.Second)}";
                        }
                        else
                        {
                            devNameText = $"{targetDevice.DelayTime / 60} {Language.StringByID(R.MyInternationalizationString.Minute)} {targetDevice.DelayTime % 60} {Language.StringByID(R.MyInternationalizationString.Second)}";
                        }
                        devNameText = CommonFormResouce.GetTimeString(targetDevice.DelayTime);
                        devNameText += Language.StringByID(R.MyInternationalizationString.Later);
                        var targetRow = new SceneTargetTimeRow(23);
                        targetRowLayout.AddChidren(targetRow);
@@ -153,8 +151,7 @@
                        targetRow.SetNameText(devNameText);
                        targetRow.SetZoneText(targetDevice.SceneUI.GetZone());
                    }
                    var editBtn = new Button()
                    {
                        BackgroundColor = ZigbeeColor.Current.GXCEditBackGroundColor,
@@ -249,7 +246,7 @@
                        }
                    }
                }
            }
        }
@@ -273,16 +270,16 @@
        /// </summary>
        private void Init()
        {
            foreach (var floor in Config.Instance.Home.FloorDics)
            {
                floorIds.Add(floor.Key);
                floorNames.Add(floor.Value);
                if(Common.Room.CurrentRoom.GetRoomsByFloorId(floor.Key).Count>0)
                {
                    roomNames.Add(Common.Room.CurrentRoom.GetRoomNamesByFloorId(floor.Key));
                    rooms.Add(Common.Room.CurrentRoom.GetRoomsByFloorId(floor.Key));
                }
            }
            //foreach (var floor in Config.Instance.Home.FloorDics)
            //{
            //    floorIds.Add(floor.Key);
            //    floorNames.Add(floor.Value);
            //    if(Common.Room.CurrentRoom.GetRoomsByFloorId(floor.Key).Count>0)
            //    {
            //        roomNames.Add(Common.Room.CurrentRoom.GetRoomNamesByFloorId(floor.Key));
            //        rooms.Add(Common.Room.CurrentRoom.GetRoomsByFloorId(floor.Key));
            //    }
            //}
        }
        /// <summary>
@@ -327,16 +324,17 @@
            };
            bodyFrameLayout.AddChidren(imgFL);
            var backGround = new Button()
            backGround = new Button()
            {
                Width = Application.GetRealWidth(930),
                Height = Application.GetRealHeight(464),
                Width = Application.GetMinRealAverage(930),
                Height = Application.GetMinRealAverage(464),
                Gravity = Gravity.Center,
                Radius = (uint)Application.GetRealHeight(CommonFormResouce.BigFormRadius),
                Radius = (uint)Application.GetMinRealAverage(CommonFormResouce.BigFormRadius),
                //UnSelectedImagePath = ImagePath
                UnSelectedImagePath = "SceneIcon/3.png"
                UnSelectedImagePath = "SceneIcon/3.jpg"
            };
            imgFL.AddChidren(backGround);
            backGround.SetViewShadow(true);
            var infoFL = new FrameLayout
            {
@@ -370,7 +368,7 @@
            zoneRow.SetTipTitle($"{Language.StringByID(R.MyInternationalizationString.BelongZone)}:");
            //zoneRow.SetTitle(curRoom.Name);
            infoFL.AddChidren(zoneRow);
            zoneRow.HideLine(false);
            zoneRow.HideLine(true);
            var targetFL = new FrameLayout()
            {
@@ -452,43 +450,209 @@
            //选择背景图
            EventHandler<MouseEventArgs> backGroundIMGHander = (sender, e) =>
            {
                if (curRoom == null)
                {
                    RoomCommon.ShowTipNoRoom();
                    return;
                }
                if (curRoom.IsSharedRoom)
                if (curRoom != null && curRoom.IsSharedRoom)
                {
                    RoomCommon.ShowTipRoomIsShared();
                    return;
                }
                var localPic = new CategorySceneSelectImgByLocal();
                Shared.Phone.UserView.HomePage.Instance.AddChidren(localPic);
                Shared.Phone.UserView.HomePage.Instance.PageIndex += 1;
                localPic.Show();
                localPic.action = (imgPath) =>
                int selectRow_Height = 150;
                int selectRow_Width = 1034;
                var selectFL = new FrameLayout()
                {
                    IconPathType = 0;
                    backGround.UnSelectedImagePath = imgPath;
                    BackgroundColor = ZigbeeColor.Current.GXCDailogBackGroundColor
                };
                AddChidren(selectFL);
                var itemFL = new FrameLayout()
                {
                    Y = Application.GetRealHeight(1276),
                    Height = Application.GetRealHeight(450),
                    Width = Application.GetRealWidth(selectRow_Width),
                    Gravity = Gravity.CenterHorizontal,
                    Radius = (uint)Application.GetRealHeight(17),
                    BackgroundColor = ZigbeeColor.Current.GXCTextWhiteColor
                };
                selectFL.AddChidren(itemFL);
                itemFL.Animate = Animate.DownToUp;
                var selectLocalPicture = new Button()
                {
                    Height = Application.GetRealHeight(selectRow_Height) - 1,
                    TextID = R.MyInternationalizationString.LocalPicture,
                    TextColor = ZigbeeColor.Current.GXCTextSelectedColor4
                };
                itemFL.AddChidren(selectLocalPicture);
                var selectLocalLine = new Button()
                {
                    Y = selectLocalPicture.Bottom,
                    Height = 1,
                    BackgroundColor = ZigbeeColor.Current.GXCLineColor
                };
                itemFL.AddChidren(selectLocalLine);
                var selectPhotographBtn = new Button()
                {
                    Y = selectLocalLine.Bottom,
                    Height = Application.GetRealHeight(selectRow_Height) - 1,
                    TextID = R.MyInternationalizationString.Photograph,
                    TextColor = ZigbeeColor.Current.GXCTextSelectedColor4
                };
                itemFL.AddChidren(selectPhotographBtn);
                var selectPhotographLine = new Button()
                {
                    Y = selectPhotographBtn.Bottom,
                    Height = 1,
                    BackgroundColor = ZigbeeColor.Current.GXCLineColor,
                };
                itemFL.AddChidren(selectPhotographLine);
                var selectAblumsBtn = new Button()
                {
                    Y = selectPhotographLine.Bottom,
                    Height = Application.GetRealHeight(selectRow_Height) - 1,
                    TextID = R.MyInternationalizationString.MyAblums,
                    TextColor = ZigbeeColor.Current.GXCTextSelectedColor4
                };
                itemFL.AddChidren(selectAblumsBtn);
                var cancelBtn = new Button()
                {
                    Y = Application.GetRealHeight(1742),
                    Height = Application.GetRealHeight(selectRow_Height),
                    Width = Application.GetRealWidth(selectRow_Width),
                    Gravity = Gravity.CenterHorizontal,
                    TextID = R.MyInternationalizationString.Cancel,
                    TextColor = ZigbeeColor.Current.GXCTextSelectedColor4,
                    BackgroundColor = ZigbeeColor.Current.GXCTextWhiteColor,
                    Radius = (uint)Application.GetRealHeight(17)
                };
                selectFL.AddChidren(cancelBtn);
                selectLocalPicture.MouseUpEventHandler += (send, ee) =>
                {
                    selectFL.RemoveFromParent();
                    var localPic = new CategorySceneSelectImgByLocal();
                    Shared.Phone.UserView.HomePage.Instance.AddChidren(localPic);
                    Shared.Phone.UserView.HomePage.Instance.PageIndex += 1;
                    localPic.Show();
                    localPic.action = (imgPath) =>
                    {
                        IconPathType = 0;
                        backGround.ImageBytes = null;
                        backGround.UnSelectedImagePath = imgPath;
                    };
                };
                selectPhotographBtn.MouseUpEventHandler += (send, ee) =>
                {
                    selectFL.RemoveFromParent();
                    var tradeTime = DateTime.Now.ToString("yyyyMMddHHmmss", DateTimeFormatInfo.InvariantInfo);
                    var fileName = $"Scene_{tradeTime}";
                    //通过相机拍照裁剪
                    CropImage.TakePicture((imagePath) =>
                    {
                        if (isModify)
                        {
                            if (IconPathType != 0)
                            {
                                Global.DeleteFilebyHomeId(backGround.UnSelectedImagePath);
                            }
                        }
                        IconPathType = 1;
                        backGround.ImageBytes = Shared.IO.FileUtils.ReadFile(imagePath);
                        backGround.UnSelectedImagePath = imagePath;
                        System.IO.File.Delete(imagePath);
                    }, fileName, 2, 1);
                };
                selectAblumsBtn.MouseUpEventHandler += (send, ee) =>
                {
                    selectFL.RemoveFromParent();
                    var tradeTime = DateTime.Now.ToString("yyyyMMddHHmmss", DateTimeFormatInfo.InvariantInfo);
                    var fileName = $"Scene_{tradeTime}";
                    //从相册选择图片裁剪
                    CropImage.SelectPicture((imagePath) =>
                    {
                        if (isModify)
                        {
                            if (IconPathType != 0)
                            {
                                Global.DeleteFilebyHomeId(backGround.UnSelectedImagePath);
                            }
                        }
                        IconPathType = 2;
                        backGround.ImageBytes = Shared.IO.FileUtils.ReadFile(imagePath);
                        backGround.UnSelectedImagePath = imagePath;
                        System.IO.File.Delete(imagePath);
                    }, fileName, 2,1);
                };
                cancelBtn.MouseUpEventHandler += (send, ee) =>
                {
                    selectFL.RemoveFromParent();
                };
                selectFL.MouseUpEventHandler += (send, ee) =>
                {
                    selectFL.RemoveFromParent();
                };
            };
            backGround.MouseUpEventHandler += backGroundIMGHander;
            //区域
            EventHandler<MouseEventArgs> zoneHander = (sender, e) =>
            {
                PickerView.ShowSecondary(floorNames, roomNames, (index1, index2) =>
                List<string> floorIds = new List<string> { };
                List<string> floorNames = new List<string> { };
                List<List<string>> roomNames = new List<List<string>> { };
                List<List<Common.Room>> rooms = new List<List<Common.Room>> { };
                List<Common.Room> rs = new List<Common.Room> { };
                List<string> rNames = new List<string> { };
                if (Config.Instance.Home.FloorDics.Count > 0)
                {
                    curRoom = rooms[index1][index2];
                    zoneRow.NameText.Text = $"{Config.Instance.Home.GetFloorNameById(floorIds[index1])} , {rooms[index1][index2].Name}";
                }, 0, 0, Language.StringByID(R.MyInternationalizationString.BelongFloor), Language.StringByID(R.MyInternationalizationString.Confrim), Language.StringByID(R.MyInternationalizationString.Cancel));
                    foreach (var floor in Config.Instance.Home.FloorDics)
                    {
                        floorIds.Add(floor.Key);
                        floorNames.Add(floor.Value);
                        if (Common.Room.CurrentRoom.GetRoomsByFloorId(floor.Key).Count > 0)
                        {
                            roomNames.Add(Common.Room.CurrentRoom.GetRoomNamesByFloorId(floor.Key));
                            rooms.Add(Common.Room.CurrentRoom.GetRoomsByFloorId(floor.Key));
                        }
                    }
                    PickerView.ShowSecondary(floorNames, roomNames, (index1, index2) =>
                    {
                        curRoom = rooms[index1][index2];
                        zoneRow.SetTitle($"{Config.Instance.Home.GetFloorNameById(floorIds[index1])} , {rooms[index1][index2].Name}");
                    }, 0, 0, Language.StringByID(R.MyInternationalizationString.BelongFloor),
                   Language.StringByID(R.MyInternationalizationString.Confrim),
                   Language.StringByID(R.MyInternationalizationString.Cancel));
                }
                else
                {
                    for (int i = 0; i < Common.Room.Lists.Count; i++)
                    {
                        var r = Common.Room.Lists[i];
                        if (r.IsLove)
                        {
                            continue;
                        }
                        rs.Add(r);
                        rNames.Add(r.Name);
                    }
                    PickerView.Show(rNames, (index1) =>
                    {
                        curRoom = rs[index1];
                        zoneRow.SetTitle(rs[index1].Name);
                    }, 0, Language.StringByID(R.MyInternationalizationString.BelongFloor),
                   Language.StringByID(R.MyInternationalizationString.Confrim),
                   Language.StringByID(R.MyInternationalizationString.Cancel));
                }
            };
            zoneRow.NextBtn.MouseUpEventHandler += zoneHander;
            zoneRow.TipBtn.MouseUpEventHandler += zoneHander;
            zoneRow.NameText.MouseUpEventHandler += zoneHander;
            zoneRow.MouseUpEventHandler += zoneHander;
            zoneRow.ClickBtn.MouseUpEventHandler += zoneHander;
            //执行目标-添加执行设备
            EventHandler<MouseEventArgs> targetAddHander = (sender, e) =>
@@ -523,6 +687,7 @@
                    BackgroundColor = ZigbeeColor.Current.GXCTextWhiteColor
                };
                selectFL.AddChidren(itemFL);
                itemFL.Animate = Animate.DownToUp;
                var selectedFunctionBtn = new Button()
                {
@@ -607,7 +772,7 @@
                        sceneTargetDevicesList.Add(selectedScene);
                        RefreshTargetListView();
                    };
                };
                //添加时间间隔
                selectedTimerBtn.MouseUpEventHandler += (send, ee) =>
@@ -666,6 +831,8 @@
                    {
                        try
                        {
                            var tradeTime = DateTime.Now.ToString("yyyyMMddHHmmss", DateTimeFormatInfo.InvariantInfo);
                            var fileName = $"Scene_{tradeTime}";
                            //改名
                            if (modifySceneUI.Name != nameRow.NameText.Text.Trim())
                            {
@@ -697,8 +864,14 @@
                            //图片
                            if(IconPathType==1 || IconPathType ==2)
                            {
                                Shared.IO.FileUtils.WriteFileByBytes(System.IO.Path.Combine(Config.Instance.FullPath, fileName), backGround.ImageBytes);
                                modifySceneUI.IconPath = System.IO.Path.Combine(Config.Instance.FullPath, fileName);
                            }
                            else
                            {
                                modifySceneUI.IconPath = backGround.UnSelectedImagePath;
                            }
                            modifySceneUI.IconPathType = IconPathType;
                            CommonPage.Loading.Start();
                            var memberDataList = new List<ZigBee.Device.Scene.AddSceneMemberData>();
@@ -797,6 +970,7 @@
                            {
                                if (modifyRoom != curRoom)
                                {
                                    modifyRoom.SceneUIList.Remove(modifySceneUI);
                                    modifyRoom.SceneUIFilePathList.Remove(modifySceneUI.FileName);
                                    curRoom.SceneUIList.Add(modifySceneUI);
@@ -843,6 +1017,19 @@
                    {
                        try
                        {
                            var tradeTime = DateTime.Now.ToString("yyyyMMddHHmmss", DateTimeFormatInfo.InvariantInfo);
                            var fileName = $"SceneIcon_{tradeTime}.png";
                            string imgPath;
                            //图片
                            if (IconPathType == 1 || IconPathType == 2)
                            {
                                Shared.IO.FileUtils.WriteFileByBytes(System.IO.Path.Combine(Config.Instance.FullPath, fileName), backGround.ImageBytes);
                                imgPath = System.IO.Path.Combine(Config.Instance.FullPath, fileName);
                            }
                            else
                            {
                                imgPath = backGround.UnSelectedImagePath;
                            }
                            if (Common.Room.CurrentRoom.GetSameFloorScenes(curRoom.FloorId).Find(s => s.Name == nameRow.NameText.Text.Trim()) != null)
                            {
                                Common.CommonPage.Instance.ShowErrorInfoAlert(R.MyInternationalizationString.TheSceneHadExist);
@@ -897,7 +1084,7 @@
                                }
                            }
                            var result = await curRoom.AddScene(nameRow.NameText.Text, backGround.UnSelectedImagePath, memberDataList);
                            var result = await curRoom.AddScene(nameRow.NameText.Text, imgPath, memberDataList);
                            if (result == 1)
                            {
                                RemoveFromParent();
@@ -925,13 +1112,11 @@
                    }
                }
            };
            #endregion
        }
        #endregion
    }
}