using System; using System.Collections.Generic; namespace Shared.SimpleControl.Phone { public class URLMonitor : FrameLayout { string type = "URL"; public URLMonitor () { BackgroundColor = SkinStyle.Current.MainColor; } public void ShowVideoMonitoring () { #region 标题 var topView = new FrameLayout () { Height = Application.GetRealHeight (126), BackgroundColor = SkinStyle.Current.MainColor }; AddChidren (topView); var title = new Button () { TextAlignment = TextAlignment.Center, Text = Language.StringByID (R.MyInternationalizationString.VideoMonitoring), TextSize = 19, Y = Application.GetRealHeight (10), TextColor = SkinStyle.Current.TextColor1 }; topView.AddChidren (title); var back = new Button () { Height = Application.GetRealHeight (90), Width = Application.GetRealWidth (85), UnSelectedImagePath = "Item/Back.png", SelectedImagePath = "Item/BackSelected.png", Y = Application.GetRealHeight (35), }; topView.AddChidren (back); back.MouseUpEventHandler += (sender, e) => { this.RemoveFromParent (); }; Button monitorAdd = new Button () { Width = Application.GetRealWidth (55), Height = Application.GetRealHeight (55), UnSelectedImagePath = "Item/+.png", SelectedImagePath = "Item/+.png", Y = Application.GetRealHeight (55), X = Application.GetRealWidth (640 - 80), }; topView.AddChidren (monitorAdd); monitorAdd.MouseUpEventHandler += (sender, e) => { addURLMonitor (ShowVideoMonitoring, null); }; #endregion #region URL VerticalScrolViewLayout VerticalScrolViewMiddle = new VerticalScrolViewLayout () { Y = topView.Bottom, Height = Application.GetRealHeight (Application.DesignHeight - 130), BackgroundColor = SkinStyle.Current.ViewColor, }; AddChidren (VerticalScrolViewMiddle); foreach (var monitorFilePath in MonitorInfo.FilePathList) { var monitorInfo = MonitorInfo.GetMonitorByFilePath (monitorFilePath); if (null == monitorInfo) { continue; } var cameraView = new FrameLayout () { Height = Application.GetRealHeight (355), BackgroundImagePath = "Monitor/Monitor_door.png", }; VerticalScrolViewMiddle.AddChidren (cameraView); var cameraURLViewLine = new FrameLayout () { Y = cameraView.Bottom, BackgroundColor = SkinStyle.Current.Black50Transparent, Height = Application.GetRealHeight (5), }; VerticalScrolViewMiddle.AddChidren (cameraURLViewLine); var btnName = new Button () { Width = LayoutParams.MatchParent, Height = Application.GetRealHeight (70), Text = monitorFilePath.Split ('_') [1], TextAlignment = TextAlignment.CenterLeft, X = Application.GetRealWidth (35), }; cameraView.AddChidren (btnName); var monitorSet = new Button () { Width = Application.GetRealWidth (43), Height = Application.GetRealHeight (43), UnSelectedImagePath = "Monitor/Monitor_edit.png", SelectedImagePath = "Monitor/Monitor_edit_on.png", Y = Application.GetRealHeight (16), X = Application.GetRealWidth (568), }; cameraView.AddChidren (monitorSet); monitorSet.MouseUpEventHandler += (sender1, e1) => { addURLMonitor (ShowVideoMonitoring, monitorFilePath); }; var urlMonitor = new UrlMonitor () { UserName = monitorInfo.UserName, Password = monitorInfo.Password, URL = monitorInfo.URL, }; var monitorPlay = new Button () { Width = Application.GetRealHeight (139), Height = Application.GetRealHeight (139), UnSelectedImagePath = "Monitor/Monitor_play.png", SelectedImagePath = "Monitor/Monitor_play_on.png", X = Application.GetRealWidth (251), Y = Application.GetRealHeight (130), }; cameraView.AddChidren (monitorPlay); monitorPlay.MouseDownEventHandler += (sender, e) => { monitorPlay.IsSelected = true; }; monitorPlay.MouseUpEventHandler += (sender, e) => { monitorPlay.IsSelected = false; urlMonitor.RemoveFromParent (); Shared.Dialog diaLog = new Dialog (); diaLog.Show (); diaLog.AddChidren (urlMonitor); var dialogFrameLayout = new FrameLayout () { Width = Application.GetRealWidth (39), Height = Application.GetRealHeight (50), BackgroundColor = 0x22ff0000, X = Application.GetRealWidth (75), Y = Application.GetRealHeight (1054), }; diaLog.AddChidren (dialogFrameLayout); var tempBack = new Button { Width = Application.GetRealWidth (39), Height = Application.GetRealHeight (50), UnSelectedImagePath = "Monitor/Monitor_close.png", SelectedImagePath = "Monitor/Monitor_close_on.png", X = Application.GetRealWidth (1), Y = Application.GetRealHeight (1), }; dialogFrameLayout.AddChidren (tempBack); tempBack.MouseDownEventHandler += (sender1, e1) => { tempBack.IsSelected = true; diaLog.Close (); }; tempBack.MouseUpEventHandler += (sender1, e1) => { tempBack.IsSelected = false; }; urlMonitor.Start (); }; } #endregion } /// /// 添加或修改摄像头 /// void addURLMonitor (Action showMonitorList, string monitorFilePath = "") { var monitorInfo = MonitorInfo.GetMonitorByFilePath (monitorFilePath); if (null == monitorInfo) { monitorInfo = new MonitorInfo (); } #region SetMonitor Dialog dialog = new Dialog (); FrameLayout bodyView = new FrameLayout () { Width = Application.GetRealWidth (520), Height = Application.GetRealHeight (550), BackgroundColor = SkinStyle.Current.DialogColor, Radius = 5, BorderWidth = 1, BorderColor = SkinStyle.Current.SubtitleView, Gravity = Gravity.Center }; dialog.AddChidren (bodyView); Button btnTitle1 = new Button () { Height = Application.GetRealHeight (80), BackgroundColor = SkinStyle.Current.DialogTitle, TextID = R.MyInternationalizationString.URLCameraInfomation, TextAlignment = TextAlignment.Center, }; bodyView.AddChidren (btnTitle1); FrameLayout dialogFrameLayout = new FrameLayout () { Width = Application.GetRealWidth (520), Height = Application.GetRealHeight (390), Y = btnTitle1.Bottom, }; bodyView.AddChidren (dialogFrameLayout); Button btnCameraName = new Button () { Width = Application.GetRealWidth (110), Height = Application.GetRealHeight (60), X = Application.GetRealWidth (20), Y = Application.GetRealHeight (20), TextAlignment = TextAlignment.CenterLeft, TextColor = SkinStyle.Current.TextColor, TextID = R.MyInternationalizationString.PleaseEnterMonitorName }; dialogFrameLayout.AddChidren (btnCameraName); EditText etName = new EditText () { Y = btnCameraName.Y, X = btnCameraName.Right + Application.GetRealWidth (10), Width = Application.GetRealWidth (340), Height = Application.GetRealHeight (60), Radius = 3, BorderColor = SkinStyle.Current.ButtonColor, TextColor = SkinStyle.Current.TextColor, BorderWidth = 1, Text = monitorInfo.Name, TextAlignment = TextAlignment.Center, }; dialogFrameLayout.AddChidren (etName); Button btnURL = new Button () { Width = Application.GetRealWidth (110), Height = Application.GetRealHeight (60), X = Application.GetRealWidth (20), Y = etName.Bottom + Application.GetRealHeight (20), TextID = R.MyInternationalizationString.URL, TextAlignment = TextAlignment.CenterLeft, TextColor = SkinStyle.Current.TextColor, }; dialogFrameLayout.AddChidren (btnURL); EditText etURL = new EditText () { Y = btnURL.Y, X = btnURL.Right + Application.GetRealWidth (10), Width = Application.GetRealWidth (340), Height = Application.GetRealHeight (110), Radius = 3, BorderColor = SkinStyle.Current.ButtonColor, TextColor = SkinStyle.Current.TextColor, BorderWidth = 1, TextAlignment = TextAlignment.Center, Text = monitorInfo.URL, }; dialogFrameLayout.AddChidren (etURL); Button btnUserName = new Button () { Width = Application.GetRealWidth (110), Height = Application.GetRealHeight (60), X = Application.GetRealWidth (20), Y = etURL.Bottom + Application.GetRealHeight (20), TextAlignment = TextAlignment.CenterLeft, TextSize = 13, TextColor = SkinStyle.Current.TextColor, TextID = R.MyInternationalizationString.EmailAccout, }; dialogFrameLayout.AddChidren (btnUserName); EditText etUserName = new EditText () { Y = btnUserName.Y, X = btnUserName.Right + Application.GetRealWidth (10), Width = Application.GetRealWidth (340), Height = Application.GetRealHeight (60), Radius = 3, BorderColor = SkinStyle.Current.ButtonColor, TextColor = SkinStyle.Current.TextColor, BorderWidth = 1, TextAlignment = TextAlignment.Center, Text = monitorInfo.UserName, }; dialogFrameLayout.AddChidren (etUserName); var btnPassword = new Button () { Width = Application.GetRealWidth (110), Height = Application.GetRealHeight (60), X = Application.GetRealWidth (20), Y = btnUserName.Bottom + Application.GetRealHeight (20), TextAlignment = TextAlignment.CenterLeft, TextSize = 13, TextColor = SkinStyle.Current.TextColor, TextID = R.MyInternationalizationString.PASSWORD, }; dialogFrameLayout.AddChidren (btnPassword); EditText etPassword = new EditText () { Y = btnPassword.Y, X = btnPassword.Right + Application.GetRealWidth (10), Width = Application.GetRealWidth (340), Height = Application.GetRealHeight (60), Radius = 3, BorderColor = SkinStyle.Current.ButtonColor, TextColor = SkinStyle.Current.TextColor, BorderWidth = 1, TextAlignment = TextAlignment.Center, Text = monitorInfo.Password, }; dialogFrameLayout.AddChidren (etPassword); FrameLayout BottomView = new FrameLayout () { Width = LayoutParams.MatchParent, Height = Application.GetRealHeight (90), BackgroundColor = SkinStyle.Current.DialogTitle, Y = bodyView.Height - Application.GetRealHeight (89), }; bodyView.AddChidren (BottomView); Button btnBack = new Button () { Width = Application.GetRealWidth (119), Height = LayoutParams.MatchParent, UnSelectedImagePath = "Item/PositioningDialogBack.png", SelectedImagePath = "Item/PositioningDialogBack.png", }; BottomView.AddChidren (btnBack); btnBack.MouseUpEventHandler += (sender1, e1) => { dialog.Close (); }; Button btnLineH = new Button () { Width = 1, BackgroundColor = SkinStyle.Current.White20Transparent, X = btnBack.Right, }; BottomView.AddChidren (btnLineH); Button btnSave = new Button () { Width = Application.GetRealWidth (400), Height = LayoutParams.MatchParent, X = btnLineH.Right, TextID = R.MyInternationalizationString.SAVE, TextAlignment = TextAlignment.Center, Radius = 1, }; BottomView.AddChidren (btnSave); //可修改的摄像头 if (!string.IsNullOrEmpty (monitorFilePath)) { btnTitle1.TextID = R.MyInternationalizationString.ChangeInformation; btnSave.Width = Application.GetRealWidth (200); var btnLineH2 = new Button () { Width = 1, Height = LayoutParams.MatchParent, BackgroundColor = SkinStyle.Current.White20Transparent, X = btnSave.Right, }; BottomView.AddChidren (btnLineH2); var btnDel = new Button () { Width = Application.GetRealWidth (199), Height = btnBack.Height, X = btnLineH2.Right, Y = btnBack.Y, TextID = R.MyInternationalizationString.Delete, TextAlignment = TextAlignment.Center, }; 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) { MonitorInfo.Remove (monitorFilePath); ShowVideoMonitoring (); dialog.Close (); } }; alert.Show (); }; } #endregion btnSave.MouseUpEventHandler += (sender1, e1) => { if (string.IsNullOrEmpty (etName.Text.Trim ()) || string.IsNullOrEmpty (etURL.Text.Trim ()) ) { new Alert (Language.StringByID (R.MyInternationalizationString.Tip), Language.StringByID (R.MyInternationalizationString.PleaseWriteTheCompleteContent), Language.StringByID (R.MyInternationalizationString.Close)).Show (); return; } string newMonitorFilePath = typeof (MonitorInfo).Name + "_" + etName.Text.Trim (); monitorInfo.Name = etName.Text.Trim (); monitorInfo.URL = etURL.Text.Trim (); monitorInfo.Type = type; monitorInfo.UserName = etUserName.Text.Trim (); monitorInfo.Password = etPassword.Text.Trim (); //新建摄像头 if (string.IsNullOrEmpty (monitorFilePath)) { //新建摄像头但是摄像头名为空或者已经存在房摄像头名 if (IO.FileUtils.Exists (newMonitorFilePath)) { new Alert (Language.StringByID (R.MyInternationalizationString.Tip), Language.StringByID (R.MyInternationalizationString.HaveTheSame), Language.StringByID (R.MyInternationalizationString.Close)).Show (); return; } monitorInfo.Add (newMonitorFilePath); showMonitorList (); } else { //如果更改后的名称存在,就不允许保存 if (monitorFilePath != newMonitorFilePath && IO.FileUtils.Exists (newMonitorFilePath)) { new Alert (Language.StringByID (R.MyInternationalizationString.Tip), Language.StringByID (R.MyInternationalizationString.HaveTheSame), Language.StringByID (R.MyInternationalizationString.Close)).Show (); return; } monitorInfo.ReEdit (monitorFilePath, newMonitorFilePath); showMonitorList (); } dialog.Close (); }; dialog.Show (); } } }