gxc
2019-11-15 05ce435c3b58e53eeab04c672affdeeab75f3036
ZigbeeApp/Shared/Phone/Device/Category/CategoryAddScene.cs
@@ -57,6 +57,11 @@
        private CommonForm.CompleteButton confirmBtn;
        /// <summary>
        /// backGround
        /// </summary>
        private Button backGround;
        /// <summary>
        /// 是否修改
        /// </summary>
        public bool isModify;
@@ -327,12 +332,12 @@
            };
            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"
            };
@@ -452,27 +457,154 @@
            //选择背景图
            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.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;
@@ -561,6 +693,7 @@
                    BackgroundColor = ZigbeeColor.Current.GXCTextWhiteColor
                };
                selectFL.AddChidren(itemFL);
                itemFL.Animate = Animate.DownToUp;
                var selectedFunctionBtn = new Button()
                {
@@ -704,6 +837,8 @@
                    {
                        try
                        {
                            var tradeTime = DateTime.Now.ToString("yyyyMMddHHmmss", DateTimeFormatInfo.InvariantInfo);
                            var fileName = $"Scene_{tradeTime}";
                            //改名
                            if (modifySceneUI.Name != nameRow.NameText.Text.Trim())
                            {
@@ -735,9 +870,15 @@
                            //图片
                            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>();
                            for (int i = 0; i < sceneTargetDevicesList.Count; i++)
@@ -835,6 +976,7 @@
                            {
                                if (modifyRoom != curRoom)
                                {
                                    modifyRoom.SceneUIList.Remove(modifySceneUI);
                                    modifyRoom.SceneUIFilePathList.Remove(modifySceneUI.FileName);
                                    curRoom.SceneUIList.Add(modifySceneUI);
@@ -881,6 +1023,19 @@
                    {
                        try
                        {
                            var tradeTime = DateTime.Now.ToString("yyyyMMddHHmmss", DateTimeFormatInfo.InvariantInfo);
                            var fileName = $"Scene_{tradeTime}";
                            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);
@@ -935,7 +1090,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();
@@ -969,7 +1124,5 @@
        }
        #endregion
    }
}