using System; using System.Collections.Generic; using Shared.Common; namespace Shared.Phone.Device.Category { public class CategorySceneSelectedScene : FrameLayout { public SceneTargetDeviceUI sceneTargetDevice = new SceneTargetDeviceUI { Type = 2 }; public CategorySceneSelectedScene() { BackgroundColor = ZigbeeColor.Current.GXCTopViewBackgroundColor; Tag = "categoryAddScene"; } public override void RemoveFromParent() { base.RemoveFromParent(); } /// /// 添加场景为执行目标 state = -1 不选择,代表新增。state=1 时,targetDeviceID代表传进来的目标id, /// /// State. /// Target device identifier. /// If set to true is from room. /// 当前的场景id(需过滤本身) public void Show(List sceneTargetDevicesList,int state = -1, string targetDeviceID = "", bool isFromRoom = false, int sceneID = -1) { #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, TextID = R.MyInternationalizationString.Scence, 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(); }; #endregion #region midFL var midFL = new VerticalScrolViewLayout() { Y = topView.Bottom, Height = Application.GetRealHeight(CommonPage.AppRealHeight - CommonPage.Navigation_Height), BackgroundColor = ZigbeeColor.Current.GXCBackgroundColor, }; AddChidren(midFL); SceneRoomUI.GetAllSceneRoomUIList(); foreach (var sceneRoomUI in SceneRoomUI.AllSceneRoomUIList) { //过滤当前的场景本身 if (sceneID == sceneRoomUI.sceneUI.Id) { continue; } if (sceneTargetDevicesList.Find((obj) => obj.Type == 2 && obj.ElseScenesId == sceneRoomUI.sceneUI.Id) != null) { continue; } var sceneFL = new FrameLayout() { Width = Application.GetRealWidth(CommonPage.AppRealWidth - 100), Height = Application.GetRealHeight(400), Gravity = Gravity.CenterHorizontal, BackgroundColor = ZigbeeColor.Current.GXCBackgroundColor }; midFL.AddChidren(sceneFL); var sceneRowLayout = new RowLayout() { Y = Application.GetRealHeight(30), Height = Application.GetRealHeight(400 - 10 - 30), Gravity = Gravity.CenterHorizontal, 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 = sceneRoomUI.sceneUI.IconPath }; sceneItemFL.AddChidren(sceneImg); //卡片顶端栏 包含房间名称 更多设置按钮 var hardBlackBG = new FrameLayout() { Height = Application.GetRealHeight(100), BackgroundColor = ZigbeeColor.Current.GXCBlack70Color }; sceneItemFL.AddChidren(hardBlackBG); var roomNameBtn = new Button() { Width = Application.GetRealWidth(500), Gravity = Gravity.CenterHorizontal, Text = sceneRoomUI.room.Name, TextColor = ZigbeeColor.Current.GXCTextWhiteColor, }; hardBlackBG.AddChidren(roomNameBtn); var sceneNameBtn = new Button() { Text = sceneRoomUI.sceneUI.Name, Height = Application.GetRealHeight(150), Gravity = Gravity.CenterVertical, TextColor = ZigbeeColor.Current.GXCTextWhiteColor, TextSize = 20 }; sceneItemFL.AddChidren(sceneNameBtn); void selectTimeMouseDownEvent(object sender, MouseEventArgs e) { sceneNameBtn.IsSelected = true; } sceneNameBtn.MouseDownEventHandler += selectTimeMouseDownEvent; hardBlackBG.MouseDownEventHandler += selectTimeMouseDownEvent; sceneImg.MouseDownEventHandler += selectTimeMouseDownEvent; void selectTimeMouseUpEvent(object sender, MouseEventArgs e) { sceneNameBtn.IsSelected = false; sceneTargetDevice.ElseScenesId = sceneRoomUI.sceneUI.Id; sceneTargetDevice.SceneName = sceneRoomUI.sceneUI.Name; if (state == -1) { if (isFromRoom) { var sameScene = Room.AddRoomScene.sceneTargetDevicesList.Find((obj) => obj.ElseScenesId == sceneTargetDevice.ElseScenesId); if (sameScene == null) { Room.AddRoomScene.sceneTargetDevicesList.Add(sceneTargetDevice); UserView.HomePage.Instance.RemoveViewByTag("categoryAddScene"); var roomAddScene = new Room.AddRoomScene(); UserView.HomePage.Instance.AddChidren(roomAddScene); UserView.HomePage.Instance.PageIndex += 1; roomAddScene.Show(Room.AddRoomScene.CurrentRoom); } else { //提示该场景已加入 var alert = new Alert(Language.StringByID(R.MyInternationalizationString.TIP), Language.StringByID(R.MyInternationalizationString.ThisSceneHadTheScene), Language.StringByID(R.MyInternationalizationString.Close)); alert.Show(); alert.ResultEventHandler += (sendAlert, eAlert) => { return; }; } } else { //var sameScene = CategoryAddScene.sceneTargetDevicesList.Find((obj) => obj.ElseScenesId == sceneTargetDevice.ElseScenesId); //if (sameScene == null) //{ // //CategoryAddScene.sceneTargetDevicesList.Add(sceneTargetDevice); // UserView.HomePage.Instance.RemoveViewByTag("categoryAddScene"); // var categoryAddScene = new CategoryAddScene(); // UserView.HomePage.Instance.AddChidren(categoryAddScene); // UserView.HomePage.Instance.PageIndex += 1; // categoryAddScene.Show(); //} //else //{ // //提示该场景已加入 // var alert = new Alert(Language.StringByID(R.MyInternationalizationString.TIP), Language.StringByID(R.MyInternationalizationString.ThisSceneHadTheScene), Language.StringByID(R.MyInternationalizationString.Close)); // alert.Show(); // alert.ResultEventHandler += (sendAlert, eAlert) => // { // return; // }; //} } } else { if (isFromRoom) { if (!string.IsNullOrEmpty(targetDeviceID)) { var targetDeviceUI = Room.AddRoomScene.sceneTargetDevicesList.Find((obj) => obj.SceneTargetDeviceUIID == targetDeviceID); if (targetDeviceUI != null) { targetDeviceUI.Type = sceneTargetDevice.Type; targetDeviceUI.ElseScenesId = sceneTargetDevice.ElseScenesId; targetDeviceUI.SceneName = sceneTargetDevice.SceneName; } } //var sameScene = Room.AddRoomScene.SceneTargetDevicesList.Find((obj) => obj.ElseScenesId == sceneTargetDevice.ElseScenesId); //if(sameScene==null) //{ UserView.HomePage.Instance.RemoveViewByTag("categoryAddScene"); var roomAddScene = new Room.AddRoomScene(); UserView.HomePage.Instance.AddChidren(roomAddScene); UserView.HomePage.Instance.PageIndex += 1; roomAddScene.Show(Room.AddRoomScene.CurrentRoom); //} //else //{ // //提示该场景已加入 // var alert = new Alert(Language.StringByID(R.MyInternationalizationString.TIP), Language.StringByID(R.MyInternationalizationString.ThisSceneHadTheScene), Language.StringByID(R.MyInternationalizationString.Close)); // alert.Show(); // alert.ResultEventHandler += (sendAlert, eAlert) => // { // return; // }; //} } else { if (!string.IsNullOrEmpty(targetDeviceID)) { //var targetDeviceUI = CategoryAddScene.sceneTargetDevicesList.Find((obj) => obj.SceneTargetDeviceUIID == targetDeviceID); //if (targetDeviceUI != null) //{ // targetDeviceUI.Type = sceneTargetDevice.Type; // targetDeviceUI.ElseScenesId = sceneTargetDevice.ElseScenesId; // targetDeviceUI.SceneName = sceneTargetDevice.SceneName; //} } //var sameScene = CategoryAddScene.sceneTargetDevicesList.Find((obj) => obj.ElseScenesId == sceneTargetDevice.ElseScenesId); //if (sameScene == null) //{ UserView.HomePage.Instance.RemoveViewByTag("categoryAddScene"); var categoryAddScene = new CategoryAddScene(); UserView.HomePage.Instance.AddChidren(categoryAddScene); UserView.HomePage.Instance.PageIndex += 1; categoryAddScene.Show(); //} //else //{ // //提示该场景已加入 // var alert = new Alert(Language.StringByID(R.MyInternationalizationString.TIP), Language.StringByID(R.MyInternationalizationString.ThisSceneHadTheScene), Language.StringByID(R.MyInternationalizationString.Close)); // alert.Show(); // alert.ResultEventHandler += (sendAlert, eAlert) => // { // return; // }; //} } } } sceneNameBtn.MouseUpEventHandler += selectTimeMouseUpEvent; hardBlackBG.MouseUpEventHandler += selectTimeMouseUpEvent; sceneImg.MouseDownEventHandler += selectTimeMouseUpEvent; } #endregion } } }