using System; using System.Collections.Generic; using Shared.Common; using Shared.Phone.Device.Category; using ZigBee.Device; namespace Shared.Phone.Device.Room { public class AddRoomContent:FrameLayout { #region ◆ 变量____________________________ /// /// The current room. /// public static Shared.Common.Room CurrentRoom; /// /// The instance. /// public static AddRoomContent instance; /// /// The function scene body view. /// public FrameLayout FunctionSceneBodyView; /// /// 功能 /// public Button FunctionBtn; /// /// 场景 /// public Button SceneBtn; /// /// The add function or scence button. /// public Button AddFunctionOrScenceBtn; /// /// 为空时添加 /// public Button NoFunction; /// /// The no function tip. /// public Button NoFunctionTip; /// /// The no scence. /// public Button NoScence; /// /// The no scence tip. /// public Button NoScenceTip; #endregion #region ◆ 构造方法_________________________ //添加或者修改房间设备、场景 public AddRoomContent() { BackgroundColor = ZigbeeColor.Current.GXCBackgroundColor; instance = this; } public override void RemoveFromParent() { base.RemoveFromParent(); } #endregion #region ◆ 显示视图_________________________ /// /// 显示界面 /// /// Room. public void Show(Shared.Common.Room room) { CurrentRoom = room; #region topview var topBGView = new FrameLayout() { Height = Application.GetRealHeight(CommonPage.Navigation_Height), BackgroundColor = ZigbeeColor.Current.GXCTopViewBackgroundColor }; AddChidren(topBGView); var topView = new FrameLayout() { Y = Application.GetRealHeight(CommonPage.NavigationTitle_Y), Height = Application.GetRealHeight(CommonPage.Navigation_Height - CommonPage.NavigationTitle_Y), BackgroundColor = ZigbeeColor.Current.GXCTopViewBackgroundColor, }; AddChidren(topView); var title = new Button() { TextAlignment = TextAlignment.Center, Text = room.Name, TextSize = 20, TextColor = ZigbeeColor.Current.GXCTextBlackColor, Width = Application.GetRealWidth(CommonPage.AppRealWidth - 500), Gravity = Gravity.CenterHorizontal }; topView.AddChidren(title); var back = new Device.CommonForm.BackButton() { }; topView.AddChidren(back); back.MouseUpEventHandler += (sender, e) => { this.RemoveFromParent(); }; AddFunctionOrScenceBtn = new Device.CommonForm.SelectedStatuButton() { Width = Application.GetMinRealAverage(100), Height = Application.GetMinRealAverage(100), UnSelectedImagePath = "Item/Add.png", SelectedImagePath = "Item/AddSelected.png", X = Application.GetRealWidth(CommonPage.AppRealWidth - 150), Gravity = Gravity.CenterVertical }; topView.AddChidren(AddFunctionOrScenceBtn); #endregion #region midFL var midFL = new FrameLayout() { Height = Application.GetRealHeight(CommonPage.AppRealHeight - CommonPage.Navigation_Height), Y = topView.Bottom, BackgroundColor = ZigbeeColor.Current.GXCBackgroundColor, }; this.AddChidren(midFL); int functionScene_Width = CommonPage.AppRealWidth / 2; int functionScene_Height = 150; //功能 FunctionBtn = new Button() { Width = Application.GetRealWidth(functionScene_Width), Height = Application.GetRealHeight(functionScene_Height), BackgroundColor = ZigbeeColor.Current.GXCButtonhardWhiteColor, SelectedBackgroundColor = ZigbeeColor.Current.GXCButtonhardWhiteColor, TextColor = ZigbeeColor.Current.GXCTextBlackColor, SelectedTextColor= ZigbeeColor.Current.GXCTextBlueColor, TextAlignment = TextAlignment.Center, TextSize = 16, TextID = R.MyInternationalizationString.Function, IsSelected=true }; midFL.AddChidren(FunctionBtn); //场景 SceneBtn = new Button() { X=FunctionBtn.Right, Width = Application.GetRealWidth(functionScene_Width), Height = Application.GetRealHeight(functionScene_Height), BackgroundColor = ZigbeeColor.Current.GXCButtonhardWhiteColor, SelectedBackgroundColor= ZigbeeColor.Current.GXCButtonhardWhiteColor, TextColor = ZigbeeColor.Current.GXCTextBlackColor, SelectedTextColor = ZigbeeColor.Current.GXCTextBlueColor, TextAlignment = TextAlignment.Center, TextSize = 16, TextID = R.MyInternationalizationString.Scence, IsSelected=false }; midFL.AddChidren(SceneBtn); var line = new Button() { Y=FunctionBtn.Bottom, Height= CommonPage.LineHeight, Width= Application.GetRealWidth(functionScene_Width), BackgroundColor=ZigbeeColor.Current.GXCButtonBlueColor }; midFL.AddChidren(line); //功能和场景bodyView FunctionSceneBodyView = new FrameLayout() { Y=line.Bottom, Height=midFL.Height-line.Bottom, BackgroundColor=ZigbeeColor.Current.GXCBackgroundColor }; midFL.AddChidren(FunctionSceneBodyView); #endregion #region event AddFunctionOrScenceBtn.MouseUpEventHandler += AddFunctionOrScenceHandler; //选择功能分栏 FunctionBtn.MouseUpEventHandler += (sender, e) => { SceneBtn.IsSelected = false; FunctionBtn.IsSelected = true; line.X = FunctionBtn.X; RefreshBodyView(); }; //选择场景分栏 SceneBtn.MouseUpEventHandler += (sender, e) => { FunctionBtn.IsSelected = false; SceneBtn.IsSelected = true; line.X = SceneBtn.X; RefreshBodyView(); }; RefreshBodyView(); #endregion } #endregion #region ◆ 添加____________________________ /// /// 添加功能或者场景 /// /// Sender. /// E. private void AddFunctionOrScenceHandler(object sender, MouseEventArgs e) { if (CurrentRoom.IsSharedRoom) { RoomCommon.ShowTipRoomIsShared(); return; } if (FunctionBtn.IsSelected) { //添加功能 var addDeviceList = new AddDeviceList(); UserView.HomePage.Instance.AddChidren(addDeviceList); UserView.HomePage.Instance.PageIndex += 1; addDeviceList.Show(CurrentRoom); } else { //添加场景 var addScene = new AddRoomScene(); AddRoomScene.SceneText = ""; AddRoomScene.ImagePath = "Scene/Scene0.png"; UserView.HomePage.Instance.AddChidren(addScene); UserView.HomePage.Instance.PageIndex += 1; AddRoomScene.sceneTargetDevicesList?.Clear(); addScene.Show(CurrentRoom); } } #endregion #region ◆ 刷新____________________________ /// /// 刷新 /// public void RefreshBodyView() { FunctionSceneBodyView.RemoveAll(); if (FunctionBtn.IsSelected) { //选择功能 var filePathList = CurrentRoom.DeviceUIFilePathList; if (filePathList.Count == 0) { NoFunction = new Button() { Width = Application.GetMinRealAverage(220), Height = Application.GetMinRealAverage(220), UnSelectedImagePath = "Room/AddScenceFunction.png", Gravity = Gravity.Center }; FunctionSceneBodyView.AddChidren(NoFunction); NoFunctionTip = new Button() { Y = NoFunction.Bottom, Height = Application.GetMinRealAverage(200), TextID = R.MyInternationalizationString.AddFunction, TextColor = ZigbeeColor.Current.GXCTextBlackColor, TextSize = 15, TextAlignment = TextAlignment.Center }; FunctionSceneBodyView.AddChidren(NoFunctionTip); //添加功能或者场景 NoFunction.MouseUpEventHandler += AddFunctionOrScenceHandler; NoFunctionTip.MouseUpEventHandler += AddFunctionOrScenceHandler; } else { var dlistScrowView = new VerticalScrolViewLayout() { }; FunctionSceneBodyView.AddChidren(dlistScrowView); foreach (var filePath in filePathList) { var device = Newtonsoft.Json.JsonConvert.DeserializeObject(System.Text.Encoding.UTF8.GetString(Global.ReadFileByHomeId(filePath))); if (device == null || device.CommonDevice == null) { continue; } var deviceItemFL = new RowLayout() { Height = Application.GetRealHeight(170) }; dlistScrowView.AddChidren(deviceItemFL); var deviceIMG = new Button() { X = Application.GetRealWidth(50), Width = Application.GetMinRealAverage(110), Height = Application.GetMinRealAverage(110), UnSelectedImagePath = device.IconPath, SelectedImagePath = device.OnlineIconPath, IsSelected = device.CommonDevice.IsOnline == 1, Gravity = Gravity.CenterVertical }; deviceItemFL.AddChidren(deviceIMG); var deviceName = new Button() { X = deviceIMG.Right + Application.GetRealWidth(50), Width = Application.GetRealWidth(700), Height = Application.GetRealHeight(110), TextColor = ZigbeeColor.Current.GXCTextBlackColor, SelectedTextColor = ZigbeeColor.Current.GXCButtonBlueColor, TextAlignment = TextAlignment.CenterLeft, TextSize = 16, Text = device.CommonDevice.DeviceEpointName, Gravity = Gravity.CenterVertical }; deviceItemFL.AddChidren(deviceName); var deviceRight = new Button() { X = Application.GetRealWidth(1080 - 150), Width = Application.GetMinRealAverage(110), Height = Application.GetMinRealAverage(110), UnSelectedImagePath = "Item/Next.png", Gravity = Gravity.CenterVertical }; //deviceItemFL.AddChidren(deviceRight); var deviceLine = new Button() { Y = Application.GetRealHeight(170) - 1, Height = 1, BackgroundColor = ZigbeeColor.Current.GXCLineColor, Tag = device }; deviceItemFL.AddChidren(deviceLine); var delBtn = new Button() { BackgroundColor = ZigbeeColor.Current.GXCRedColor, TextID = R.MyInternationalizationString.Delete, TextColor = ZigbeeColor.Current.GXCTextWhiteColor }; if (!CurrentRoom.IsSharedRoom) { deviceItemFL.AddRightView(delBtn); } delBtn.MouseUpEventHandler += (send, ee) => { var alert = new Alert(Language.StringByID(R.MyInternationalizationString.TIP), Language.StringByID(R.MyInternationalizationString.ConfirmDelete), Language.StringByID(R.MyInternationalizationString.Cancel), Language.StringByID(R.MyInternationalizationString.Confrim)); alert.Show(); alert.ResultEventHandler += (send1, e1) => { if (e1) { CurrentRoom.DeleteDevice(device.FileName); Show(CurrentRoom); } }; }; } } } else { //选择场景 var sceneList = CurrentRoom.SceneUIList; if (sceneList.Count == 0) { NoScence = new Button() { Width = Application.GetMinRealAverage(220), Height = Application.GetMinRealAverage(220), UnSelectedImagePath = "Room/AddScenceFunction.png", Gravity = Gravity.Center }; FunctionSceneBodyView.AddChidren(NoScence); NoScenceTip = new Button() { Y = NoScence.Bottom, Height = Application.GetMinRealAverage(200), TextID = R.MyInternationalizationString.AddScence, TextColor = ZigbeeColor.Current.GXCTextBlackColor, TextSize = 15, TextAlignment = TextAlignment.Center }; FunctionSceneBodyView.AddChidren(NoScenceTip); //添加功能或者场景 NoScence.MouseUpEventHandler += AddFunctionOrScenceHandler; NoScenceTip.MouseUpEventHandler += AddFunctionOrScenceHandler; } else { var sceneScrolView = new VerticalScrolViewLayout { }; FunctionSceneBodyView.AddChidren(sceneScrolView); foreach (var scene in sceneList) { if (scene == null) { continue; } var sceneFL = new FrameLayout() { Width = Application.GetRealWidth(1080 - 100), Height = Application.GetRealHeight(400), Tag = scene, Gravity = Gravity.CenterHorizontal }; sceneScrolView.AddChidren(sceneFL); var sceneRowLayout = new RowLayout() { Y = Application.GetRealHeight(30), Height = Application.GetRealHeight(400 - 10 - 30), LineColor = ZigbeeColor.Current.GXCBackgroundColor, Radius = CommonPage.BigFormRadius }; sceneFL.AddChidren(sceneRowLayout); var sceneItemFL = new FrameLayout() { BackgroundColor = ZigbeeColor.Current.GXCBackgroundColor, Radius = CommonPage.BigFormRadius }; sceneRowLayout.AddChidren(sceneItemFL); var sceneImg = new Button() { UnSelectedImagePath = scene.IconPath }; sceneItemFL.AddChidren(sceneImg); var hardBlackBG = new Button() { BackgroundColor = ZigbeeColor.Current.GXCBlack70Color, SelectedBackgroundColor = ZigbeeColor.Current.GXCBlack80Color }; sceneItemFL.AddChidren(hardBlackBG); var sceneNameBtn = new Button() { Text = scene.Name, TextColor = ZigbeeColor.Current.GXCTextWhiteColor }; sceneItemFL.AddChidren(sceneNameBtn); //删除 var deleteBtn = new CommonForm.RowLayoutDeleteButton { Tag = scene }; if (!CurrentRoom.IsSharedRoom) { sceneRowLayout.AddRightView(deleteBtn); } EventHandler sceneDownHandler = (sender, e) => { hardBlackBG.IsSelected = true; }; sceneNameBtn.MouseDownEventHandler += sceneDownHandler; hardBlackBG.MouseDownEventHandler += sceneDownHandler; //调用场景 EventHandler sceneHandler = async (sender, e) => { hardBlackBG.IsSelected = false; //1成功 0失败 //后面补上相关提示 var sceneOpenAllData = await ZigBee.Device.Scene.ControlSceneAsync(scene.Id, 0); //主网关不在线 if (sceneOpenAllData == null) { //CommonPage.Instance.ShowErrorInfoAlert(R.MyInternationalizationString.TheMainGatewayIsNotOnLine); CommonPage.Instance.FailureToServer(); return; } if (sceneOpenAllData.sceneOpenData == null) { CommonPage.Instance.ShowErrorInfoAlert(R.MyInternationalizationString.FailedPleaseTryAgain); return; } //成功 if (sceneOpenAllData.sceneOpenData.Result == 1) { } //失败 else { CommonPage.Instance.ShowErrorInfoAlert(R.MyInternationalizationString.FailedPleaseTryAgain); return; } }; sceneNameBtn.MouseUpEventHandler += sceneHandler; hardBlackBG.MouseUpEventHandler += sceneHandler; //删除场景 EventHandler delEvent = (sender, e) => { var alert = new Alert(Language.StringByID(R.MyInternationalizationString.TIP), Language.StringByID(R.MyInternationalizationString.ConfirmDelete), Language.StringByID(R.MyInternationalizationString.Cancel), Language.StringByID(R.MyInternationalizationString.Confrim)); alert.Show(); alert.ResultEventHandler += async (send1, e1) => { if (e1) { //0 移除失败 1 移除成功 2 没有该场景 var removeSceneAllData = await ZigBee.Device.Scene.DeleteSceneAsync(scene.Id); if (removeSceneAllData == null || removeSceneAllData.removeSceneData == null) { return; } if (removeSceneAllData.removeSceneData.Result == 1) { //1成功 CurrentRoom.RemoveScene(scene); //RefreshBodyView(); sceneScrolView.RemoveViewByTag((sender as Button).Tag); } else if (removeSceneAllData.removeSceneData.Result == 0) { //0 移除失败 CommonPage.Instance.ShowErrorInfoAlert(R.MyInternationalizationString.FailedPleaseTryAgain); return; } else if (removeSceneAllData.removeSceneData.Result == 2) { //2 没有该场景 CurrentRoom.RemoveScene(scene); //RefreshBodyView(); sceneScrolView.RemoveViewByTag((sender as Button).Tag); CommonPage.Instance.ShowErrorInfoAlert(R.MyInternationalizationString.TheSceneIsNull); } } }; }; deleteBtn.MouseUpEventHandler += delEvent; } } } } #endregion } }