using System; using System.Collections.Generic; using EZMonitor; namespace Shared.SimpleControl.Phone { /// /// 用户场景界面 /// public class UserScenePage : FrameLayout { public static readonly VerticalScrolViewLayout VerticalScrolView_InUserMiddleView = new VerticalScrolViewLayout (); Button beforeClickButton = new Button (); FrameLayout LongPressFrameLayout = new FrameLayout (); /// ///构造函数 /// public UserScenePage () { BackgroundColor = SkinStyle.Current.MainColor; } public void ShowUserScene (Room room) { #region 标题 var topView = new FrameLayout () { Y = Application.GetRealHeight (36), Height = Application.GetRealHeight (90), }; AddChidren (topView); var title = new Button () { TextAlignment = TextAlignment.Center, Text = Language.StringByID (R.MyInternationalizationString.Scenes), TextSize = 19, TextColor = SkinStyle.Current.TextColor1, }; topView.AddChidren (title); var logo = new Button () { Width = Application.GetRealWidth (154), Height = Application.GetRealHeight (90), X = Application.GetRealWidth (486), UnSelectedImagePath = MainPage.LogoString, }; topView.AddChidren (logo); var back = new Button () { Height = Application.GetRealHeight (90), Width = Application.GetRealWidth (85), UnSelectedImagePath = "Item/Back.png", SelectedImagePath = "Item/BackSelected.png", }; topView.AddChidren (back); back.MouseUpEventHandler += (sender, e) => { (Parent as PageLayout).PageIndex -= 1; }; #endregion #region bodyView FrameLayout bodyView = new FrameLayout () { Height = this.Height - topView.Bottom, Y = topView.Bottom, BackgroundColor = SkinStyle.Current.ViewColor }; AddChidren (bodyView); VerticalScrolViewLayout scenesBodyView = new VerticalScrolViewLayout () { Width = LayoutParams.MatchParent, Height = LayoutParams.MatchParent, }; bodyView.AddChidren (scenesBodyView); FrameLayout scenesRowView = new FrameLayout () { Width = LayoutParams.MatchParent, Height = Application.GetRealHeight (254), }; //显示每个房间有多少个场景 if (room != null) { //所有场景 var sceneFileList = room.SceneFilePathList; List sceneFilePaths = new List ();//存路径 sceneFilePaths = sceneFileList; sceneFilePaths.Add (""); for (int index = 0; index < sceneFilePaths.Count; index++) { var sceneFilePath = sceneFilePaths [index]; var scene = Scene.GetSceneByFilePath (sceneFilePath); // 当场景不存在时,可以NEW 一个场景,不然值一直是空的 if (scene == null) { scene = new Scene (); } if (index % 2 == 0) { scenesRowView = new FrameLayout () { Height = Application.GetRealWidth (250), }; scenesBodyView.AddChidren (scenesRowView); } var sceneView = new FrameLayout () { Width = Application.GetRealWidth (320), BackgroundImagePath = scene.BackgroundImagePath, }; scenesRowView.AddChidren (sceneView); if (index % 2 == 1) { sceneView.X = Application.GetRealWidth (320); } if (index == sceneFilePaths.Count - 1) { sceneView.BackgroundImagePath = "Item/SceneAdd.png"; sceneView.MouseUpEventHandler += (sender, e) => { Action refeshAction = () => { ShowUserScene (Room.GetRoomByFilePath (room.RoomFilePath)); }; new ScenePhoneMethod ().AddOrUpdataSceneBaseMassage ( room.RoomFilePath,null, null, refeshAction); }; } else { Button btnSceneName = new Button () { Height = Application.GetRealWidth (40), Y = Application.GetRealWidth (210), BackgroundColor = SkinStyle.Current.Black50Transparent, }; sceneView.AddChidren (btnSceneName); var btnBGC = new Button () { UnSelectedImagePath = "Item/sss.png", SelectedImagePath = "Item/SceneSettingBackground.png", TextAlignment = TextAlignment.BottomCenter, Text = scene.Name, TextColor = SkinStyle.Current.TextColor1, TextSize = 15, }; sceneView.AddChidren (btnBGC); btnBGC.MouseLongEventHandler += (sender, e) => { if (string.IsNullOrEmpty (scene.Name)) return; LongPressFrameLayout = new FrameLayout () { BackgroundColor = SkinStyle.Current.SceneTransparentBackColor, }; LongPressFrameLayout.MouseUpEventHandler += (sender2, e2) => { LongPressFrameLayout.RemoveFromParent (); }; sceneView.AddChidren (LongPressFrameLayout); var btnEditor = new Button () { Width = Application.GetRealWidth (70), Height = Application.GetRealHeight (76), UnSelectedImagePath = "Item/UserSceneEditIcon.png", X = Application.GetRealWidth (220), Y = Application.GetRealHeight (13), }; LongPressFrameLayout.AddChidren (btnEditor); btnEditor.MouseUpEventHandler += (sender1, e1) => { var userAddSceneDeviceView = new UserAddSceneDevice (room.RoomFilePath, sceneFilePath); UserMiddle.DevicePageView.AddChidren (userAddSceneDeviceView); userAddSceneDeviceView.ShowScene ((newSceneFilePath) => { sceneFilePath = newSceneFilePath; scene = Scene.GetSceneByFilePath (sceneFilePath); sceneView.BackgroundImagePath = scene.BackgroundImagePath; ShowUserScene (Room.GetRoomByFilePath (room.RoomFilePath)); UserDeviceToScene.hasModify = true; }); UserMiddle.DevicePageView.PageIndex = UserMiddle.DevicePageView.ChildrenCount - 1; LongPressFrameLayout.RemoveFromParent (); }; var btnDel = new Button () { Width = Application.GetRealWidth (70), Height = Application.GetRealHeight (76), UnSelectedImagePath = "Item/UserSceneDelIcon.png", X = Application.GetRealWidth (40), Y = Application.GetRealHeight (20), }; LongPressFrameLayout.AddChidren (btnDel); btnDel.MouseUpEventHandler += (senderDel, eDel) => { IO.FileUtils.DeleteFile (sceneFilePath); room.SceneFilePathList.Remove (sceneFilePath); room.SceneFilePathList.Remove (""); room.Save (room.RoomFilePath); ShowUserScene (Room.GetRoomByFilePath (room.RoomFilePath)); UserDeviceToScene.hasModify = true; if (CommonList.MonitorScenePathList.Count > 0) { foreach (var monitorData in CommonList.MonitorScenePathList) { if (sceneFilePath == monitorData.FileName) { CommonList.MonitorScenePathList.Remove (monitorData); CommonList.Save (); } } } }; }; btnBGC.MouseUpEventHandler += (sender, e) => { LongPressFrameLayout.RemoveFromParent (); beforeClickButton.IsSelected = false; beforeClickButton = btnBGC; btnBGC.IsSelected = true; new ScenePhoneMethod ().ControlScene (sceneFilePath); }; } } sceneFileList.Remove (""); } #endregion } } }