From ee5f2543624a0e3ae9d046062b822727a31685e1 Mon Sep 17 00:00:00 2001 From: tzy <hxb@hdlchina.com.cn> Date: 星期五, 14 五月 2021 17:15:48 +0800 Subject: [PATCH] Merge remote-tracking branch 'origin/wxr4' into dev-tzy --- HDL_ON/UI/UI2/3-Intelligence/Scene/CatchSceneAddPage.cs | 674 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 674 insertions(+), 0 deletions(-) diff --git a/HDL_ON/UI/UI2/3-Intelligence/Scene/CatchSceneAddPage.cs b/HDL_ON/UI/UI2/3-Intelligence/Scene/CatchSceneAddPage.cs new file mode 100644 index 0000000..61abb45 --- /dev/null +++ b/HDL_ON/UI/UI2/3-Intelligence/Scene/CatchSceneAddPage.cs @@ -0,0 +1,674 @@ +锘縰sing System; +using System.Collections.Generic; +using System.Threading; +using HDL_ON.DAL.Server; +using HDL_ON.Entity; +using HDL_ON.UI.CSS; +using Shared; +namespace HDL_ON.UI +{ + public class CatchSceneAddPage : FrameLayout + { + FrameLayout bodyView; + private ImageView addSceneImageView; + private FrameLayout sceneNameView; + private Button btnEditSceneNameIcon; + private Button btnSceneName; + private FrameLayout belongToZoneRow; + private Button btnBelongToZoneRight; + private Button btnZoneName; + private Scene scene; + private Button btnChooseZoneViewTitle; + private VerticalScrolViewLayout functionListView; + private Button btnComplete; + + #region 鍥炬爣閫夋嫨閮ㄥ垎鍥炬爣 + /// <summary> + /// 鑳屾櫙鍥鹃�夐」鍖哄煙 + /// </summary> + FrameLayout pictureOptionView; + /// <summary> + /// 鑳屾櫙鍥鹃�夐」閫夋嫨鍖哄煙 + /// </summary> + VerticalScrolViewLayout optionView; + /// <summary> + /// 榛樿鍥惧簱鎸夐挳 + /// </summary> + Button btnDefaultGallery; + /// <summary> + /// 鎷嶇収鎸夐挳 + /// </summary> + Button btnTakePicture; + /// <summary> + /// 鐩稿唽鎸夐挳 + /// </summary> + Button btnAlbum; + /// <summary> + /// 鍙栨秷鎸夐挳 + /// </summary> + Button btnCancel; + #endregion + + + + /// <summary> + /// 鎹曟崏鐨勫尯鍩熷垪琛� + /// </summary> + private List<Room> catchRooms = new List<Room>(); + + /// <summary> + /// 鍥炶皟鏇存柊 + /// </summary> + Action backAction; + public CatchSceneAddPage(Scene s,Action a) + { + bodyView = this; + scene = s; + backAction =()=>{ + a(); + RemoveFromParent(); + }; + } + + public void LoadPage() + { + new TopViewDiv(bodyView, Language.StringByID(StringId.CatchScene)).LoadTopView(); + + bodyView.BackgroundColor = CSS_Color.BackgroundColor; + + var contentView = new VerticalScrolViewLayout() + { + Y = Application.GetRealHeight(64), + Height = Application.GetRealHeight(603 - 50), + }; + bodyView.AddChidren(contentView); + contentView.AddChidren(new Button() { + Height = Application.GetRealWidth(12), + BackgroundColor = CSS_Color.MainBackgroundColor, + }); + + var sceneBgView = new FrameLayout() + { + Height = Application.GetRealWidth(188 + 24), + BackgroundColor = CSS_Color.MainBackgroundColor, + }; + contentView.AddChidren(sceneBgView); + + addSceneImageView = new ImageView() + { + Gravity = Gravity.CenterHorizontal, + Width = Application.GetRealWidth(252), + Height = Application.GetRealWidth(184), + Radius = (uint)Application.GetRealWidth(12), + }; + sceneBgView.AddChidren(addSceneImageView); + + //2020-12-03 淇敼鍥剧墖鍔犺浇鏂规硶 + ImageUtlis.Current.LoadLocalOrNetworkImages(scene.ImagePath, addSceneImageView); + + /// <summary> + /// 淇敼鍦烘櫙鑳屾櫙浜嬩欢 + /// </summary> + addSceneImageView.MouseUpEventHandler = (sender, e) => + { + LoadPictureOptionView(); + }; + + #region 鍦烘櫙鍚嶇Оrow + sceneNameView = new FrameLayout() + { + Height = Application.GetRealWidth(50), + BackgroundColor = CSS_Color.MainBackgroundColor, + }; + contentView.AddChidren(sceneNameView); + + Button btnSceneTitle = new Button() + { + X = Application.GetRealWidth(16), + Width = Application.GetRealWidth(90), + TextAlignment = TextAlignment.CenterLeft, + TextColor = CSS_Color.FirstLevelTitleColor, + TextSize = CSS_FontSize.TextFontSize, + TextID = StringId.SceneName, + }; + sceneNameView.AddChidren(btnSceneTitle); + + btnEditSceneNameIcon = new Button() + { + X = Application.GetRealWidth(333), + Gravity = Gravity.CenterVertical, + Width = Application.GetMinRealAverage(28), + Height = Application.GetMinRealAverage(28), + UnSelectedImagePath = "Public/EditIcon.png", + }; + sceneNameView.AddChidren(btnEditSceneNameIcon); + + btnSceneName = new Button() + { + X = Application.GetRealWidth(100), + Width = Application.GetRealWidth(230), + TextAlignment = TextAlignment.CenterRight, + TextColor = CSS_Color.PromptingColor1, + TextSize = CSS_FontSize.TextFontSize, + Text = scene.name + }; + sceneNameView.AddChidren(btnSceneName); + + Button btnSceneNameLine = new Button() + { + Y = Application.GetRealWidth(49), + Gravity = Gravity.CenterHorizontal, + Height = Application.GetRealHeight(1), + Width = Application.GetRealWidth(343), + BackgroundColor = CSS_Color.BackgroundColor, + }; + sceneNameView.AddChidren(btnSceneNameLine); + #endregion + + #region 鎵�灞炲尯鍩焤ow + belongToZoneRow = new FrameLayout() + { + Y = sceneNameView.Bottom, + Height = Application.GetRealWidth(50), + BackgroundColor = CSS_Color.MainBackgroundColor, + }; + contentView.AddChidren(belongToZoneRow); + + Button btnBelongToTitle = new Button() + { + X = Application.GetRealWidth(16), + Width = Application.GetRealWidth(90), + TextAlignment = TextAlignment.CenterLeft, + TextColor = CSS_Color.FirstLevelTitleColor, + TextSize = CSS_FontSize.TextFontSize, + TextID = StringId.LocationManagement, + }; + belongToZoneRow.AddChidren(btnBelongToTitle); + + btnBelongToZoneRight = new Button() + { + X = Application.GetRealWidth(339), + Gravity = Gravity.CenterVertical, + Width = Application.GetMinRealAverage(16), + Height = Application.GetMinRealAverage(16), + UnSelectedImagePath = "Public/Right.png", + }; + belongToZoneRow.AddChidren(btnBelongToZoneRight); + + btnZoneName = new Button() + { + X = Application.GetRealWidth(100), + Width = Application.GetRealWidth(230), + TextAlignment = TextAlignment.CenterRight, + TextColor = CSS_Color.PromptingColor1, + TextSize = CSS_FontSize.TextFontSize, + Text = scene.GetRoomListName() == "" ? Language.StringByID(StringId.WholeZone) : scene.GetRoomListName() + }; + belongToZoneRow.AddChidren(btnZoneName); + + contentView.AddChidren(new Button() + { + Y = belongToZoneRow.Bottom, + Height = Application.GetRealHeight(8), + BackgroundColor = CSS_Color.BackgroundColor, + }); + #endregion + + #region 閫夋嫨鍖哄煙 + FrameLayout chooseZoneView = new FrameLayout() + { + Height = Application.GetRealWidth(44), + BackgroundColor = CSS_Color.MainBackgroundColor, + }; + contentView.AddChidren(chooseZoneView); + + btnChooseZoneViewTitle = new Button() + { + X = Application.GetRealWidth(16), + TextAlignment = TextAlignment.CenterLeft, + TextColor = CSS_Color.MainColor, + TextSize = CSS_FontSize.SubheadingFontSize, + TextID = StringId.ChooseCatchZone, + IsBold = true, + }; + chooseZoneView.AddChidren(btnChooseZoneViewTitle); + + functionListView = new VerticalScrolViewLayout() + { + Height = 0, + }; + contentView.AddChidren(functionListView); + + LoadRoomRow(functionListView); + + Button btnLine1 = new Button() + { + Height = Application.GetRealHeight(8), + BackgroundColor = CSS_Color.BackgroundColor, + }; + contentView.AddChidren(btnLine1); + + #endregion + + Button btnBottomLine = new Button() + { + Y = Application.GetRealHeight(667 - 50) - 1, + Height = 1, + BackgroundColor = CSS_Color.BackgroundColor, + }; + bodyView.AddChidren(btnBottomLine); + + btnComplete = new Button() + { + Y = Application.GetRealHeight(667 - 50), + Height = Application.GetRealHeight(50), + TextAlignment = TextAlignment.Center, + SelectedTextColor = CSS_Color.MainColor, + TextColor = CSS_Color.BackgroundColor, + TextSize = CSS_FontSize.SubheadingFontSize, + TextID = StringId.NextStep, + BackgroundColor = CSS_Color.MainBackgroundColor, + SelectedBackgroundColor = CSS_Color.MainBackgroundColor, + }; + bodyView.AddChidren(btnComplete); + + btnComplete.MouseUpEventHandler = (sender, e) => { + if(btnComplete.IsSelected) + { + if (string.IsNullOrEmpty(scene.name)) + { + new Tip() + { + CloseTime = 1, + Text = Language.StringByID(StringId.SceneNameCannotBeEmpty), + Direction = AMPopTipDirection.None, + }.Show(bodyView); + return; + } + + foreach (var tempRoom in FunctionList.List.scenes) + { + if (scene.name == tempRoom.name) + { + new PublicAssmebly().TipMsg(StringId.Tip, StringId.SceneNameAlreadyExists); + return; + } + } + + var catchFunctionList = new List<Function>(); + foreach(var temp in FunctionList.List.Functions) + { + foreach(var catchRoom in catchRooms) + { + if(temp.roomIds.Contains(catchRoom.roomId)) + { + catchFunctionList.Add(temp); + } + } + } + + var view = new CatchSceneCatchFunctionListPage(scene, catchFunctionList, backAction); + MainPage.BasePageView.AddChidren(view); + view.LoadPage(); + MainPage.BasePageView.PageIndex = MainPage.BasePageView.ChildrenCount - 1; + } + }; + } + + /// <summary> + /// 鍔犺浇鍔熻兘鍒楄〃 + /// </summary> + void LoadRoomRow(VerticalScrolViewLayout functionListView) + { + functionListView.RemoveAll(); + var roomCount = SpatialInfo.CurrentSpatial.RoomList.Count; + functionListView.Height = Application.GetRealWidth(51 * roomCount); + int i = 0; + foreach(var room in SpatialInfo.CurrentSpatial.RoomList) + { + if (i < roomCount ) + { + functionListView.AddChidren(new Button() + { + Gravity = Gravity.CenterHorizontal, + Width = Application.GetRealWidth(343), + Height = Application.GetRealWidth(1), + BackgroundColor = CSS_Color.BackgroundColor, + }); + } + i++; + var row = new FrameLayout() + { + Height = Application.GetRealWidth(50), + BackgroundColor = CSS_Color.MainBackgroundColor, + }; + functionListView.AddChidren(row); + + Button btnChoose = new Button() + { + X = Application.GetRealWidth(331), + Gravity = Gravity.CenterVertical, + Width = Application.GetMinRealAverage(28), + Height = Application.GetMinRealAverage(28), + UnSelectedImagePath = "Public/ChooseIcon.png", + SelectedImagePath = "Public/ChooseOnIcon.png", + }; + row.AddChidren(btnChoose); + + var btnRoomName = new TextButton() + { + X = Application.GetRealWidth(16), + TextAlignment = TextAlignment.CenterLeft, + TextColor = CSS_Color.FirstLevelTitleColor, + TextSize = CSS_FontSize.TextFontSize, + Text = room.roomName, + }; + row.AddChidren(btnRoomName); + btnRoomName.Width = Utlis.GetRealWidthByTextButton(btnRoomName)+Application.GetRealWidth(12); + + var btnRoomFloor = new TextButton() + { + X = btnRoomName.Right, + TextAlignment = TextAlignment.CenterLeft, + TextColor = CSS_Color.PromptingColor1, + TextSize = CSS_FontSize.PromptFontSize_FirstLevel, + Text = room.floorName, + }; + row.AddChidren(btnRoomFloor); + btnRoomFloor.Width = Utlis.GetRealWidthByTextButton(btnRoomFloor) + Application.GetRealWidth(12); + + EventHandler<MouseEventArgs> eventHandler = (sender, e) => { + btnChoose.IsSelected = !btnChoose.IsSelected; + if (btnChoose.IsSelected) + { + catchRooms.Add(room); + }else + { + catchRooms.Remove(room); + } + if (catchRooms.Count == 1) + { + btnComplete.IsSelected = true; + } + else if (catchRooms.Count == 0) + { + btnComplete.IsSelected = false; + } + }; + btnRoomFloor.MouseUpEventHandler = eventHandler; + btnRoomName.MouseUpEventHandler = eventHandler; + btnChoose.MouseUpEventHandler = eventHandler; + row.MouseUpEventHandler = eventHandler; + } + } + + /// <summary> + /// 鍔犺浇鍥炬爣閫夋嫨閫夐」 + /// </summary> + void LoadPictureOptionView() + { + var pView = new FrameLayout() + { + BackgroundColor = CSS_Color.DialogTransparentColor1, + }; + bodyView.AddChidren(pView); + + pictureOptionView = new FrameLayout() + { + Y = Application.GetRealHeight(445), + Height = Application.GetRealHeight(250), + AnimateSpeed = 0.3f, + Animate = Animate.DownToUp, + }; + pView.AddChidren(pictureOptionView); + + optionView = new VerticalScrolViewLayout() + { + Gravity = Gravity.CenterHorizontal, + Width = Application.GetRealWidth(343), + Height = Application.GetRealHeight(150), + BackgroundColor = CSS_Color.MainBackgroundColor, + Radius = (uint)Application.GetRealWidth(12), + }; + pictureOptionView.AddChidren(optionView); + + btnDefaultGallery = new Button() + { + Height = Application.GetRealHeight(50), + TextAlignment = TextAlignment.Center, + TextColor = CSS_Color.TextualColor, + SelectedTextColor = CSS_Color.MainColor, + TextSize = CSS_FontSize.SubheadingFontSize, + TextID = StringId.DefaultGallery, + }; + optionView.AddChidren(btnDefaultGallery); + + optionView.AddChidren(new Button() { Height = Application.GetRealHeight(1), Width = Application.GetRealWidth(343), BackgroundColor = CSS_Color.DividingLineColor }); + + btnTakePicture = new Button() + { + Height = Application.GetRealHeight(50), + TextAlignment = TextAlignment.Center, + TextColor = CSS_Color.TextualColor, + SelectedTextColor = CSS_Color.MainColor, + TextSize = CSS_FontSize.SubheadingFontSize, + TextID = StringId.TakePicture, + }; + optionView.AddChidren(btnTakePicture); + + optionView.AddChidren(new Button() { Height = Application.GetRealHeight(1), Width = Application.GetRealWidth(343), BackgroundColor = CSS_Color.DividingLineColor }); + + btnAlbum = new Button() + { + Height = Application.GetRealHeight(50), + TextAlignment = TextAlignment.Center, + TextColor = CSS_Color.TextualColor, + SelectedTextColor = CSS_Color.MainColor, + TextSize = CSS_FontSize.SubheadingFontSize, + TextID = StringId.Album, + }; + optionView.AddChidren(btnAlbum); + + optionView.AddChidren(new Button() { Height = Application.GetRealHeight(1), Width = Application.GetRealWidth(343), BackgroundColor = CSS_Color.DividingLineColor }); + + btnCancel = new Button() + { + Gravity = Gravity.CenterHorizontal, + Y = Application.GetRealHeight(8) + optionView.Bottom, + Width = Application.GetRealWidth(343), + Height = Application.GetRealHeight(50), + BackgroundColor = CSS_Color.MainBackgroundColor, + Radius = (uint)Application.GetRealWidth(12), + TextID = StringId.Cancel, + TextColor = CSS_Color.WarningColor, + TextSize = CSS_FontSize.SubheadingFontSize, + }; + pictureOptionView.AddChidren(btnCancel); + + + LoadEvent_PictureOptionViewEventList(pView); + } + + /// <summary> + /// 鍔犺浇鑳屾櫙鍥鹃�夋嫨鍖哄煙浜嬩欢鍒楄〃 + /// </summary> + void LoadEvent_PictureOptionViewEventList(FrameLayout pView) + { + pictureOptionView.MouseUpEventHandler = (sender, e) => + { + pictureOptionView.Parent.RemoveFromParent(); + }; + pView.MouseUpEventHandler = (sender, e) => + { + pictureOptionView.Parent.RemoveFromParent(); + }; + + btnCancel.MouseUpEventHandler = (sender, e) => + { + pictureOptionView.Parent.RemoveFromParent(); + }; + btnTakePicture.MouseDownEventHandler = (sender, e) => { + btnTakePicture.IsSelected = true; + }; + btnTakePicture.MouseUpEventHandler = (sender, e) => + { + btnTakePicture.IsSelected = false; + + var imageName = Guid.NewGuid().ToString(); + CropImage.TakePicture((imagePath) => + { + CropImageCallBack(imagePath); + + }, imageName, 4, 3); + + pictureOptionView.Parent.RemoveFromParent(); + }; + btnAlbum.MouseDownEventHandler = (sender, e) => { + btnAlbum.IsSelected = true; + }; + + btnAlbum.MouseUpEventHandler = (sender, e) => + { + btnAlbum.IsSelected = false; + + //浠庣浉鍐岄�夋嫨鍥剧墖瑁佸壀 + var imageName = Guid.NewGuid().ToString(); + //var imageName = scene.sid; + CropImage.SelectPicture((imagePath) => + { + CropImageCallBack(imagePath); + }, imageName, 4, 3); + + + //if (pageTitleId == StringId.EditScene) + //{ + // scene.SaveFunctionData(); + //} + pictureOptionView.Parent.RemoveFromParent(); + }; + + btnDefaultGallery.MouseUpEventHandler = (sender, e) => { + pictureOptionView.Parent.RemoveFromParent(); + Action<string> action = (obj) => { + scene.ImagePath = obj; + addSceneImageView.ImageBytes = null;//瑙e喅鏈塈mageBytes涓嶅姞杞絀magePath + addSceneImageView.ImagePath = scene.ImagePath; + }; + + var galleryPage = new GalleryPage(scene.ImagePath, action); + MainPage.BasePageView.AddChidren(galleryPage); + galleryPage.LoadPage(true); + MainPage.BasePageView.PageIndex = MainPage.BasePageView.ChildrenCount - 1; + }; + + } + + /// <summary> + /// 瑁佸壀瀹岀収鐗囧洖璋冿紝缁熶竴澶勭悊 + /// </summary> + /// <param name="imagePath">瑁佸壀鍚庣殑鐪熷疄璺緞</param> + /// <param name="imageName">鑷畾涔夌殑鍥剧墖鍚嶇О</param> + void CropImageCallBack(string selectImagePath) + { + if (string.IsNullOrEmpty(selectImagePath) == true) + { + return; + } + + //涓婁紶鎴愬姛鍒板洖璋� + Action<string> uploadSuccessAction = (imageUrl) => + { + //2020-12-03 闇�瑕佽鏈�鏂扮殑鍥剧墖璺緞鍚屾鍒颁簯绔� + scene.ImagePath = imageUrl; + }; + //涓婁紶鍥剧墖鍒颁簯绔� + UploadImage(selectImagePath, addSceneImageView, scene, uploadSuccessAction); + } + + /// <summary> + /// 涓婁紶鍥剧墖鏂规硶 + /// </summary> + /// <param name="selectImagePath">瑁佸壀鍚庣殑鍥剧墖璺緞</param> + /// <param name="imageView"></param> + /// <param name="uploadSuccessAction"></param> + void UploadImage(string selectImagePath, ImageView imageView, Scene mScene, Action<string> uploadSuccessAction) + { + try + { + //MainPage.Log("SelectPicture 瑁佸壀鍥剧墖杩斿洖璺緞: " + selectImagePath); + //1.璇诲彇瑁佸壀鍚庣殑鍥剧墖锛岀劧鍚庡垹闄� + var imageBytes = Shared.IO.FileUtils.ReadFile(selectImagePath); + System.IO.File.Delete(selectImagePath); + + var waitPage = new Loading(); + bodyView.AddChidren(waitPage); + waitPage.Start(Language.StringByID(StringId.PleaseWait)); + //寮�濮嬩笂浼� + new Thread(() => + { + try + { + var newImageName = mScene.name.Trim() + ".png"; + var uploadImageObj = new UploadImageObj() + { + prefix = "Scene" + Utlis.GetTimestamp(), + fileName = newImageName, + uid = mScene.sid, + content = imageBytes, + }; + + var imageUrl = ImageUtlis.Current.UploadImage(uploadImageObj); + if (!string.IsNullOrEmpty(imageUrl) && imageUrl.Contains(newImageName)) + { + //涓婁紶鎴愬姛 + Application.RunOnMainThread(() => + { + //Utlis.WriteLine("涓婁紶鎴愬姛锛�" + imageUrl); + //1.2濡傛灉鏄嚜瀹氫箟鍥剧墖鍒犻櫎涔嬪墠鐨� + if (!string.IsNullOrEmpty(imageView.ImagePath) && !imageView.ImagePath.Contains("Classification/Room/Roombg")) + { + //Utlis.WriteLine("鍒犻櫎: " + imageView.ImagePath); + System.IO.File.Delete(imageView.ImagePath); + } + //閲嶅懡鍚嶄繚瀛� + ImageUtlis.Current.WriteFileByBytes(imageUrl, imageBytes); + imageView.ImagePath = null; + imageView.ImageBytes = imageBytes; + //涓婁紶鎴愬姛 + Utlis.ShowTip(Language.StringByID(StringId.UploadSuccessfully)); + uploadSuccessAction?.Invoke(imageUrl); + }); + } + else + { + //涓婁紶澶辫触 + Application.RunOnMainThread(() => + { + //涓婁紶澶辫触 + Utlis.ShowTip(Language.StringByID(StringId.UploadFailed)); + }); + } + + } + catch (Exception ex) + { + } + finally + { + Application.RunOnMainThread(() => + { + if (waitPage != null) + { + waitPage.RemoveFromParent(); + waitPage = null; + } + }); + } + }) + { IsBackground = true }.Start(); + } + catch { } + } + + } +} -- Gitblit v1.8.0