using System; using System.Collections.Generic; namespace Shared.SimpleControl.Phone { public static class UserRooms { public static void ShowRoomList () { FrameLayout topView = new FrameLayout () { Y = Application.GetRealHeight (36), Height = Application.GetRealHeight (90), BackgroundColor = SkinStyle.Current.MainColor, Width = Application.GetRealWidth(640), }; UserMiddle.RoomBodyView.AddChidren (topView); Button LogoButton = new Button () { Width = Application.GetRealWidth (154), Height = Application.GetRealHeight (90), UnSelectedImagePath = MainPage.LogoString, }; topView.AddChidren (LogoButton); Button NameButton = new Button () { Width = Application.GetRealWidth (400), Height = Application.GetMinReal (90), TextID = R.MyInternationalizationString.Rooms, TextColor = SkinStyle.Current.TextColor1, Gravity = Gravity.CenterHorizontal, TextAlignment = TextAlignment.Center, TextSize = 20, //FontName = "TitilliumText25L" }; topView.AddChidren (NameButton); Button ItemButton = new Button () { Width = Application.GetRealWidth (55), Height = Application.GetRealHeight (55), UnSelectedImagePath = "Item/+.png", SelectedImagePath = "Item/+.png", Y = Application.GetRealHeight (17), X = Application.GetRealWidth (640 - 80), }; topView.AddChidren (ItemButton); Action action = () => { UserMiddle.ShowRoomsView (); }; ItemButton.MouseUpEventHandler +=(sender, e) => { AddOrUpdateRoom (action); }; if (Room.FilePathList == null) { return; } VerticalScrolViewLayout RoomBodyView = new VerticalScrolViewLayout () { Y = Application.GetRealHeight (126), Height = Application.GetRealHeight (Application.DesignHeight - 126 - UserMiddle.userMenuItemHeight), }; UserMiddle.RoomBodyView.AddChidren (RoomBodyView); foreach (var roomFilePath in Room.FilePathList) { if (roomFilePath == Room.FavoriteRoom) { continue; } var room = Room.GetRoomByFilePath (roomFilePath); if (room == null) { IO.FileUtils.DeleteFile (roomFilePath); continue; } FrameLayout RoomRowView = new FrameLayout () { Height = MainPage.GetDesignHeight (360), BackgroundImagePath = room.BackGroundImage }; RoomBodyView.AddChidren (RoomRowView); FrameLayout RoomTopView = new FrameLayout () { Height = MainPage.GetDesignHeight(90), BackgroundColor = SkinStyle.Current.Black50Transparent, }; RoomRowView.AddChidren (RoomTopView); Button btnRoomName = new Button () { X = Application.GetRealWidth(30), Width = Application.GetRealWidth(500), Text = room.Name, TextAlignment = TextAlignment.CenterLeft, TextColor = SkinStyle.Current.TextColor1 }; RoomTopView.AddChidren (btnRoomName); Button btnEditRoom = new Button () { X = btnRoomName.Right, Gravity = Gravity.CenterVertical, Width = Application.GetRealWidth(70), UnSelectedImagePath = "Item/Editor.png", SelectedImagePath = "Item/EditorSelected.png" }; RoomTopView.AddChidren (btnEditRoom); btnEditRoom.MouseUpEventHandler += (sender, e) => { AddOrUpdateRoom (action, roomFilePath); }; RoomRowView.MouseUpEventHandler += (sender, e) => { var userRoom = new UserRoom (); UserMiddle.RoomPageView.AddChidren (userRoom); userRoom.InitRoomView (roomFilePath); UserMiddle.RoomPageView.PageIndex = 1; }; Button btnNull = new Button () { Height = Application.GetRealHeight (10), BackgroundColor = SkinStyle.Current.TitileView }; RoomBodyView.AddChidren (btnNull); } } /// /// 添加/修改房间 /// public static void AddOrUpdateRoom (Action action, string roomFilePath = "") { var room = Room.GetRoomByFilePath (roomFilePath); if (null == room) { room = new Room (); } #region Load Dialog dialog = new Dialog (); FrameLayout DialogBodyView = new FrameLayout () { BackgroundColor = SkinStyle.Current.DialogColor, Width = Application.GetMinRealAverage (520), Height = Application.GetMinRealAverage (800), Gravity = Gravity.Center, Radius = 5, BorderWidth = 0, BorderColor = SkinStyle.Current.Transparent, }; dialog.AddChidren (DialogBodyView); Button btnEquipmentTitle = new Button () { Width = Application.GetMinRealAverage (520), Height = Application.GetMinRealAverage (80), BackgroundColor = SkinStyle.Current.DialogTitle, TextID = R.MyInternationalizationString.AddNewRoom, TextAlignment = TextAlignment.Center, Gravity = Gravity.CenterHorizontal, TextColor = SkinStyle.Current.DialogTextColor, }; DialogBodyView.AddChidren (btnEquipmentTitle); Button lblTitleName = new Button () { Gravity = Gravity.CenterHorizontal, Y = Application.GetMinRealAverage (85), Width = Application.GetMinRealAverage (450), Height = Application.GetMinRealAverage (50), TextID = R.MyInternationalizationString.RoomName, TextAlignment = TextAlignment.CenterLeft, TextColor = SkinStyle.Current.TextColor, }; DialogBodyView.AddChidren (lblTitleName); EditText etNameBox = new EditText () { Gravity = Gravity.CenterHorizontal, Y = lblTitleName.Bottom + Application.GetMinRealAverage (10), Width = Application.GetMinRealAverage (450), Height = Application.GetMinRealAverage (60), TextAlignment = TextAlignment.CenterLeft, Radius = 5, BorderColor = SkinStyle.Current.ButtonColor, BorderWidth = 1, Text = room.Name, TextColor = SkinStyle.Current.TextColor }; DialogBodyView.AddChidren (etNameBox); etNameBox.EditorEnterAction += (obj) => { Application.HideSoftInput (); }; Button lblIcon = new Button () { Gravity = Gravity.CenterHorizontal, Y = etNameBox.Bottom + Application.GetMinRealAverage (10), Width = Application.GetMinRealAverage (450), Height = btnEquipmentTitle.Height, TextID = R.MyInternationalizationString.Icon, TextAlignment = TextAlignment.CenterLeft, TextColor = SkinStyle.Current.TextColor, }; DialogBodyView.AddChidren (lblIcon); VerticalScrolViewLayout verIconLayout = new VerticalScrolViewLayout () { Gravity = Gravity.CenterHorizontal, Y = lblIcon.Y + lblIcon.Height + Application.GetMinRealAverage (5), Width = Application.GetMinRealAverage (450), Height = Application.GetMinRealAverage (200), }; FrameLayout inVerFramelayout = new FrameLayout () { X = 0, Width = lblIcon.Width, Height = Application.GetMinRealAverage (200), }; verIconLayout.AddChidren (inVerFramelayout); DialogBodyView.AddChidren (verIconLayout); Button btnBG = new Button () { Width = Application.GetMinRealAverage (270), Height = LayoutParams.MatchParent, UnSelectedImagePath = room.BackGroundImage, }; inVerFramelayout.AddChidren (btnBG); Button btnTakePictrue = new Button () { Width = inVerFramelayout.Width - btnBG.Width, Height = inVerFramelayout.Height / 2, TextID = R.MyInternationalizationString.TakePhoto, TextColor = SkinStyle.Current.DialogTextColor, BackgroundColor = SkinStyle.Current.ButtonColor, X = btnBG.Right, }; inVerFramelayout.AddChidren (btnTakePictrue); var pid = Guid.NewGuid (); btnTakePictrue.MouseUpEventHandler += (sender, e) => { pid = Guid.NewGuid (); Camera.TakePicture ((obj) => { if (obj == null) { return; } btnBG.UnSelectedImagePath = pid.ToString(); }, pid.ToString(), false); }; Button btnLineP = new Button () { Width = btnTakePictrue.Width, Height = 2, X = btnBG.Right, Y = btnTakePictrue.Bottom, BackgroundColor = SkinStyle.Current.DialogColor }; inVerFramelayout.AddChidren (btnLineP); Button btnSelectPictrue = new Button () { Width = btnTakePictrue.Width, Height = btnTakePictrue.Height, TextID = R.MyInternationalizationString.SelectPicture, TextColor = SkinStyle.Current.DialogTextColor, BackgroundColor = SkinStyle.Current.ButtonColor, X = btnBG.Right, Y = btnLineP.Bottom, }; inVerFramelayout.AddChidren (btnSelectPictrue); btnSelectPictrue.MouseUpEventHandler += (sender, e) => { pid = Guid.NewGuid (); Camera.SelectPicture ((obj) => { if (obj == null) { return; } btnBG.UnSelectedImagePath = pid.ToString(); }, pid.ToString(), false); room.BackGroundImage = btnBG.UnSelectedImagePath; }; var systempictureLayout = new FrameLayout { Height = Application.GetMinRealAverage (260), Y = verIconLayout.Bottom + Application.GetMinRealAverage (20), }; DialogBodyView.AddChidren (systempictureLayout); HorizontalScrolViewLayout horizontalScrolViewLayout = new HorizontalScrolViewLayout () { Width = Application.GetMinRealAverage (450), Height = Application.GetMinRealAverage (180), Gravity = Gravity.CenterHorizontal }; systempictureLayout.AddChidren (horizontalScrolViewLayout); for (int i = 0; i < 20; i++) { Button butscene = new Button () { Width = Application.GetMinRealAverage (200), Height = LayoutParams.MatchParent, }; butscene.MouseUpEventHandler += (sender, e) => { btnBG.UnSelectedImagePath = butscene.UnSelectedImagePath; }; butscene.UnSelectedImagePath = "Room/r" + (i).ToString () + ".png"; horizontalScrolViewLayout.AddChidren (butscene); Button btnNull = new Button () { Width = 1, BackgroundColor = SkinStyle.Current.TextColor1 }; horizontalScrolViewLayout.AddChidren (btnNull); } FrameLayout BottomView = new FrameLayout () { Width = LayoutParams.MatchParent, Height = Application.GetMinRealAverage (90), BackgroundColor = SkinStyle.Current.DialogTitle, Y = DialogBodyView.Height - Application.GetMinRealAverage (90), }; DialogBodyView.AddChidren (BottomView); Button btnBack = new Button () { Width = Application.GetMinRealAverage (260), Height = LayoutParams.MatchParent, TextID = R.MyInternationalizationString.Cancel, TextColor = SkinStyle.Current.DialogTextColor, BackgroundColor = SkinStyle.Current.DialogTitle }; BottomView.AddChidren (btnBack); btnBack.MouseUpEventHandler += (sender1, e1) => { dialog.Close (); }; Button btnLineH = new Button () { Width = 1, BackgroundColor = SkinStyle.Current.DialogColor, X = btnBack.Right, }; BottomView.AddChidren (btnLineH); Button btnSave = new Button () { Width = Application.GetMinRealAverage (260), Height = LayoutParams.MatchParent, X = btnLineH.Right, TextID = R.MyInternationalizationString.SAVE, TextAlignment = TextAlignment.Center, Radius = 1, TextColor = SkinStyle.Current.DialogTextColor, BackgroundColor = SkinStyle.Current.DialogTitle }; BottomView.AddChidren (btnSave); #endregion //可修改的房间 if (!string.IsNullOrEmpty (roomFilePath)) { btnEquipmentTitle.TextID = R.MyInternationalizationString.ChangeInformation; btnBack.Width = Application.GetMinRealAverage (173); btnLineH.X = btnBack.Right; btnSave.X = btnLineH.Right; btnSave.Width = Application.GetMinRealAverage (173); //btnLineH.RemoveFromParent (); BottomView.AddChidren (btnLineH); //btnSave.RemoveFromParent (); BottomView.AddChidren (btnSave); Button btnLineH2 = new Button () { Width = 1, Height = LayoutParams.MatchParent, BackgroundColor = SkinStyle.Current.DialogColor, X = btnSave.Right, }; BottomView.AddChidren (btnLineH2); Button btnDel = new Button () { Width = Application.GetMinRealAverage (173), Height = btnBack.Height, X = btnLineH2.Right, Y = btnBack.Y, TextID = R.MyInternationalizationString.Delete, TextAlignment = TextAlignment.Center, TextColor = SkinStyle.Current.DialogTextColor, BackgroundColor = SkinStyle.Current.DialogTitle, }; BottomView.AddChidren (btnDel); btnDel.MouseUpEventHandler += (sender, e) => { Alert alert = new Alert (Language.StringByID (R.MyInternationalizationString.Tip), Language.StringByID (R.MyInternationalizationString.TipDeleteRoomMessage), Language.StringByID (R.MyInternationalizationString.Cancel), Language.StringByID (R.MyInternationalizationString.Confrim)); alert.ResultEventHandler += ( sender2, e2) => { if (e2) { Room.Remove (roomFilePath); action (); dialog.Close (); } }; alert.Show (); }; } btnSave.MouseUpEventHandler += (sender, e) => { //如果输入的房间名为空就返回 if (string.IsNullOrEmpty (etNameBox.Text.Trim ())) { new Alert (Language.StringByID (R.MyInternationalizationString.Tip), Language.StringByID (R.MyInternationalizationString.PleaseEnterTheRoomName), Language.StringByID (R.MyInternationalizationString.Close)).Show (); return; } string newRoomFilePath = typeof (Room).Name + "_" + etNameBox.Text.Trim (); room.Name = etNameBox.Text.Trim (); if (btnBG.UnSelectedImagePath == "RoomPicture") { var imageName = "RoomBackGroundImage" + etNameBox.Text.Trim (); //通过摄像头或者图库选择图 IO.FileUtils.ReNameFile (btnBG.UnSelectedImagePath, imageName); //更改过图片 btnBG.UnSelectedImagePath = imageName; } //默认图或者更改图 room.BackGroundImage = btnBG.UnSelectedImagePath; //新建房间 if (string.IsNullOrEmpty (roomFilePath)) { //新建房间但是房间名为空或者已经存在房间名 if (IO.FileUtils.Exists (newRoomFilePath)) { new Alert (Language.StringByID (R.MyInternationalizationString.Tip), Language.StringByID (R.MyInternationalizationString.HaveTheSame), Language.StringByID (R.MyInternationalizationString.Close)).Show (); return; } room.Add (newRoomFilePath); Room.Lists.Add (room); //显示所有的房间 action (); } else { //如果更改后的名称存在,就不允许保存 if (roomFilePath != newRoomFilePath && IO.FileUtils.Exists (newRoomFilePath)) { new Alert (Language.StringByID (R.MyInternationalizationString.Tip), Language.StringByID (R.MyInternationalizationString.HaveTheSame), Language.StringByID (R.MyInternationalizationString.Close)).Show (); return; } room.ReName (roomFilePath, newRoomFilePath); action (); } dialog.Close (); }; dialog.Show (); } /// /// 添加/修改房间 /// public static void UpdateFavoriteRoom (Action action, string roomFilePath = "") { var room = Room.GetRoomByFilePath (roomFilePath); if (null == room) { return; } #region Load Dialog dialog = new Dialog (); FrameLayout DialogBodyView = new FrameLayout () { BackgroundColor = SkinStyle.Current.DialogColor, Width = Application.GetRealWidth (520), Height = Application.GetRealHeight (680), Gravity = Gravity.Center, Radius = 5, BorderWidth = 0, BorderColor = SkinStyle.Current.Transparent, }; dialog.AddChidren (DialogBodyView); Button btnEquipmentTitle = new Button () { Width = Application.GetRealWidth (520), Height = Application.GetRealHeight (80), BackgroundColor = SkinStyle.Current.DialogTitle, TextID = R.MyInternationalizationString.ChangeInformation, TextAlignment = TextAlignment.Center, Gravity = Gravity.CenterHorizontal, TextColor = SkinStyle.Current.DialogTextColor, }; DialogBodyView.AddChidren (btnEquipmentTitle); Button lblIcon = new Button () { Gravity = Gravity.CenterHorizontal, Y = btnEquipmentTitle.Bottom + Application.GetRealHeight (10), Width = Application.GetRealWidth (450), Height = btnEquipmentTitle.Height, TextID = R.MyInternationalizationString.Icon, TextAlignment = TextAlignment.CenterLeft, TextColor = SkinStyle.Current.TextColor, }; DialogBodyView.AddChidren (lblIcon); VerticalScrolViewLayout verIconLayout = new VerticalScrolViewLayout () { Gravity = Gravity.CenterHorizontal, Y = lblIcon.Y + lblIcon.Height + Application.GetRealHeight (5), Width = Application.GetRealWidth (450), Height = Application.GetRealHeight (200), }; FrameLayout inVerFramelayout = new FrameLayout () { X = 0, Width = lblIcon.Width, Height = Application.GetRealHeight (200), }; verIconLayout.AddChidren (inVerFramelayout); DialogBodyView.AddChidren (verIconLayout); Button btnBG = new Button () { Width = Application.GetRealWidth (270), Height = LayoutParams.MatchParent, UnSelectedImagePath = room.BackGroundImage, }; inVerFramelayout.AddChidren (btnBG); if (btnBG.UnSelectedImagePath == @"Room/r1.png") { btnBG.UnSelectedImagePath = "Room/FavoriteRoom.png"; } Button btnTakePictrue = new Button () { Width = inVerFramelayout.Width - btnBG.Width, Height = inVerFramelayout.Height / 2, TextID = R.MyInternationalizationString.TakePhoto, TextColor = SkinStyle.Current.DialogTextColor, BackgroundColor = SkinStyle.Current.ButtonColor, X = btnBG.Right, }; inVerFramelayout.AddChidren (btnTakePictrue); var pid = Guid.NewGuid (); btnTakePictrue.MouseUpEventHandler += (sender, e) => { pid = Guid.NewGuid (); Camera.TakePicture ((obj) => { if (obj == null) { return; } btnBG.UnSelectedImagePath = pid.ToString(); }, pid.ToString(), false); }; Button btnLineP = new Button () { Width = btnTakePictrue.Width, Height = 2, X = btnBG.Right, Y = btnTakePictrue.Bottom, BackgroundColor = SkinStyle.Current.DialogColor }; inVerFramelayout.AddChidren (btnLineP); Button btnSelectPictrue = new Button () { Width = btnTakePictrue.Width, Height = btnTakePictrue.Height, TextID = R.MyInternationalizationString.SelectPicture, TextColor = SkinStyle.Current.DialogTextColor, BackgroundColor = SkinStyle.Current.ButtonColor, X = btnBG.Right, Y = btnLineP.Bottom, }; inVerFramelayout.AddChidren (btnSelectPictrue); btnSelectPictrue.MouseUpEventHandler += (sender, e) => { pid = Guid.NewGuid (); Camera.SelectPicture ((obj) => { if (obj == null) { return; } btnBG.UnSelectedImagePath = pid.ToString(); }, pid.ToString(), false); room.BackGroundImage = btnBG.UnSelectedImagePath; }; var systempictureLayout = new FrameLayout { Height = Application.GetRealHeight (260), Y = verIconLayout.Bottom + Application.GetRealHeight (20), }; DialogBodyView.AddChidren (systempictureLayout); HorizontalScrolViewLayout horizontalScrolViewLayout = new HorizontalScrolViewLayout () { Width = Application.GetRealWidth (450), Height = Application.GetRealHeight (180), Gravity = Gravity.CenterHorizontal }; systempictureLayout.AddChidren (horizontalScrolViewLayout); for (int i = 0; i < 20; i++) { Button butscene = new Button () { Width = Application.GetRealWidth (200), Height = LayoutParams.MatchParent, }; butscene.MouseUpEventHandler += (sender, e) => { btnBG.UnSelectedImagePath = butscene.UnSelectedImagePath; }; butscene.UnSelectedImagePath = "Room/r" + (i).ToString () + ".png"; if (butscene.UnSelectedImagePath == @"Room/r1.png") { butscene.UnSelectedImagePath = "Room/FavoriteRoom.png"; } horizontalScrolViewLayout.AddChidren (butscene); Button btnNull = new Button () { Width = 1, BackgroundColor = SkinStyle.Current.TextColor1 }; horizontalScrolViewLayout.AddChidren (btnNull); } FrameLayout BottomView = new FrameLayout () { Width = LayoutParams.MatchParent, Height = Application.GetRealHeight (90), BackgroundColor = SkinStyle.Current.DialogTitle, Y = DialogBodyView.Height - Application.GetRealHeight (90), }; DialogBodyView.AddChidren (BottomView); Button btnBack = new Button () { Width = Application.GetRealWidth (260), Height = LayoutParams.MatchParent, TextID = R.MyInternationalizationString.Cancel, TextColor = SkinStyle.Current.DialogTextColor, BackgroundColor = SkinStyle.Current.DialogTitle }; BottomView.AddChidren (btnBack); btnBack.MouseUpEventHandler += (sender1, e1) => { dialog.Close (); }; Button btnLineH = new Button () { Width = 1, BackgroundColor = SkinStyle.Current.DialogColor, X = btnBack.Right, }; BottomView.AddChidren (btnLineH); Button btnSave = new Button () { Width = Application.GetRealWidth (260), Height = LayoutParams.MatchParent, X = btnLineH.Right, TextID = R.MyInternationalizationString.SAVE, TextAlignment = TextAlignment.Center, Radius = 1, TextColor = SkinStyle.Current.DialogTextColor, BackgroundColor = SkinStyle.Current.DialogTitle }; BottomView.AddChidren (btnSave); #endregion btnSave.MouseUpEventHandler += (sender, e) => { if (btnBG.UnSelectedImagePath == "RoomPicture") { var imageName = "FavoriteRoomRoomBackGroundImage"; //通过摄像头或者图库选择图 IO.FileUtils.ReNameFile (btnBG.UnSelectedImagePath, imageName); //更改过图片 btnBG.UnSelectedImagePath = imageName; } //默认图或者更改图 room.BackGroundImage = btnBG.UnSelectedImagePath; room.Save (Room.FavoriteRoom); action (); dialog.Close (); }; dialog.Show (); } } }