using System; using System.Text; using System.Text.RegularExpressions; using Shared.Common; namespace Shared.Phone.UserCenter.DoorLock { /// /// 显示一个信息框 /// public class ShowDoorLockMsgControl { #region ■ 变量声明___________________________ /// /// 点击失效回调的事件 /// public Action InvalidTimeAction = null; /// /// 点击取消的回调事件 /// public Action CancelClickEvent = null; /// /// 点击自动化的回调事件 /// public Action LogicClickEvent = null; /// /// 点击确认的回调事件 /// public Action InvalidClickEvent = null; /// /// 点击确认的回调事件 /// public Action ConfirmClickEvent = null; /// /// 点击弹窗背景回调事件 /// public Action MsgControlClickEvent = null; /// /// 信息类型 /// private DoorLockMsgType msgType = DoorLockMsgType.Confirm; /// /// 弹窗背景 /// public FrameLayout MsgControlFrameLayout = null; /// /// 消息 /// private string msgText = string.Empty; /// /// 确认按钮的文本 /// private string buttonOkText = null; /// /// 失效时间编辑 /// private EditText editInvalidTime = null; #endregion #region ■ 初始化_____________________________ /// /// 显示一个需要确认的信息框 /// /// 信息类型 /// 信息 /// 确认按钮的文本 public ShowDoorLockMsgControl(DoorLockMsgType i_msgType, string i_msg, string buttonText = null) { //确认按钮文本 this.buttonOkText = buttonText == null ? Language.StringByID(R.MyInternationalizationString.OkMsg) : buttonText; this.msgType = i_msgType; this.msgText = i_msg; } #endregion #region ■ 显示消息___________________________ /// /// 显示 /// public void Show() { try { //初始化控件 this.InitMsgControl(); } catch (Exception ex) { HdlLogLogic.Current.WriteLog(ex); } } #endregion #region ■ 初始化控件_________________________ /// /// 初始化控件 /// private void InitMsgControl() { //添加界面 var nowForm = UserView.HomePage.Instance.GetChildren(UserView.HomePage.Instance.ChildrenCount - 1); if (nowForm == null || (nowForm is ViewGroup) == false) { return; } //主控件 MsgControlFrameLayout = new FrameLayout(); MsgControlFrameLayout.BackgroundColor = UserCenterColor.Current.DialogBackColor; ((ViewGroup)nowForm).AddChidren(MsgControlFrameLayout); MsgControlFrameLayout.MouseDownEventHandler += (sender, e) => { if (msgType == DoorLockMsgType.InValid) { return; } //移除界面 MsgControlFrameLayout.RemoveFromParent(); //回调函数 this.MsgControlClickEvent?.Invoke(); this.MsgControlClickEvent = null; }; //白色背景框 var frameBack = new FrameLayout(); frameBack.BackgroundColor = UserCenterColor.Current.White; frameBack.Gravity = Gravity.CenterHorizontal; frameBack.Radius = (uint)Application.GetRealHeight(17); if (msgType == DoorLockMsgType.CancelNomallyOpenModeWithLogic) { frameBack.Height = Application.GetRealHeight(409 + 127); frameBack.Width = Application.GetRealWidth(850); frameBack.Y = Application.GetRealHeight(648); } else { frameBack.Height = Application.GetRealHeight(478); frameBack.Width = Application.GetRealWidth(792); frameBack.Y = Application.GetRealHeight(706); } MsgControlFrameLayout.AddChidren(frameBack); //标题 var btnTitle = new NormalViewControl(frameBack.Width, Application.GetRealHeight(65), false); btnTitle.Y = Application.GetRealHeight(68); btnTitle.TextColor = 0xff333443; btnTitle.TextAlignment = TextAlignment.Center; btnTitle.TextSize = 16; frameBack.AddChidren(btnTitle); if (msgType == DoorLockMsgType.Confirm || msgType == DoorLockMsgType.DoorLockLogic || msgType == DoorLockMsgType.NomallyOpenMode || msgType == DoorLockMsgType.CancelNomallyOpenModeWithLogic) { btnTitle.TextID = R.MyInternationalizationString.NormalTip; } else if (msgType == DoorLockMsgType.InValid) { btnTitle.TextID = R.MyInternationalizationString.DoorLockInValidSetting; } else if (msgType == DoorLockMsgType.NomallyOpenMode) { btnTitle.TextID = R.MyInternationalizationString.CancelNomallyMode; } if (msgType == DoorLockMsgType.InValid) { InitInValidTimeDialog(frameBack); } else if (msgType == DoorLockMsgType.CancelNomallyOpenModeWithLogic) { CancelNormallyOpenModeWithLogicDialog(frameBack); } else { //消息 var btnMsg = new NormalViewControl(frameBack.Width - Application.GetRealWidth(55 * 2), Application.GetRealHeight(180), false); btnMsg.Y = Application.GetRealHeight(141); btnMsg.IsMoreLines = true; btnMsg.TextAlignment = TextAlignment.Center; btnMsg.TextColor = UserCenterColor.Current.TextGrayColor1; btnMsg.Gravity = Gravity.CenterHorizontal; frameBack.AddChidren(btnMsg); btnMsg.Text = msgText; } if (msgType == DoorLockMsgType.Confirm || msgType == DoorLockMsgType.NomallyOpenMode || msgType == DoorLockMsgType.CancelNomallyOpenModeWithLogic) { //初始化确认类型的底部按钮 this.InitBottomConfirmButton(MsgControlFrameLayout, frameBack); } else if (msgType == DoorLockMsgType.InValid) { //失效设置的底部按钮 this.InitBottomInvalidTimeButton(MsgControlFrameLayout, frameBack); } else if (msgType == DoorLockMsgType.DoorLockLogic) { //失效设置的底部按钮 this.InitBottomLogicButton(MsgControlFrameLayout, frameBack); } } /// /// 取消常开模式带有自动化的弹窗显示 /// /// /// private void CancelNormallyOpenModeWithLogicDialog(FrameLayout frameBack) { //消息 var btnMsg = new NormalViewControl(frameBack.Width - Application.GetRealWidth(55 * 2), Application.GetRealHeight(63), false); btnMsg.Y = Application.GetRealHeight(173); btnMsg.IsMoreLines = true; btnMsg.TextAlignment = TextAlignment.Center; btnMsg.TextColor = UserCenterColor.Current.TextGrayColor1; btnMsg.Gravity = Gravity.CenterHorizontal; frameBack.AddChidren(btnMsg); btnMsg.Text = msgText; var alarmMsg = Language.StringByID(R.MyInternationalizationString.XingTip);//.Replace("{0}", "\r\n"); var btnAlarmMsg = new NormalViewControl(frameBack.Width - Application.GetRealWidth(55 * 2), Application.GetRealHeight(104), false); btnAlarmMsg.Y = Application.GetRealHeight(259); btnAlarmMsg.IsMoreLines = true; btnAlarmMsg.TextAlignment = TextAlignment.Center; btnAlarmMsg.TextColor = ZigbeeColor.Current.XMAlarmText; btnAlarmMsg.Gravity = Gravity.CenterHorizontal; frameBack.AddChidren(btnAlarmMsg); btnAlarmMsg.Text = alarmMsg; } /// /// 失效时间设置的弹窗显示 /// /// /// private void InitInValidTimeDialog(FrameLayout frameBack) { //消息 string[] msgArray = msgText.Split(new string[] { "{0}" }, StringSplitOptions.RemoveEmptyEntries); var btnMsg1 = new Button() { Width = Application.GetRealWidth(389), Height = Application.GetRealHeight(180), Y = Application.GetRealHeight(141), IsMoreLines = false, TextColor = UserCenterColor.Current.TextGrayColor1, TextAlignment = TextAlignment.CenterRight, Text = msgArray[0], }; frameBack.AddChidren(btnMsg1); //失效时间设置 var editTextFrameLayout = new FrameLayout() { Width = Application.GetRealWidth(132), Height = Application.GetRealHeight(81 + 40 * 2), Y = Application.GetRealHeight(184 - 40), X = btnMsg1.Right, }; frameBack.AddChidren(editTextFrameLayout); editInvalidTime = new EditText() { Height = Application.GetRealHeight(81), X = Application.GetRealWidth(132), Y = Application.GetRealHeight(40), Gravity = Gravity.Center, Radius = (uint)Application.GetMinRealAverage(17), BackgroundColor = ZigbeeColor.Current.XMPEditTextBackground, TextColor = ZigbeeColor.Current.XMBlack, TextAlignment = TextAlignment.Center, TextSize = 14, Text = DoorLockCommonInfo.NormallyOpenModeInvalidTime.ToString(), PlaceholderTextColor = ZigbeeColor.Current.XMGray3, IsNumberKeyboardType = true, }; editTextFrameLayout.AddChidren(editInvalidTime); editInvalidTime.TextChangeEventHandler += (sender, e) => { if (!string.IsNullOrEmpty((sender as EditText).Text)) { var textFir = (sender as EditText).Text.Substring(0, 1); if ((sender as EditText).Text.Length > 1) { if (textFir == "0") { editInvalidTime.Text = (sender as EditText).Text.Substring(1, 1); } } if (int.Parse((sender as EditText).Text) > 72) { string msg0 = Language.StringByID(R.MyInternationalizationString.InvalidTimeMoreThan72); var alert = new UserCenter.ShowMsgControl(UserCenter.ShowMsgType.Normal, msg0, Language.StringByID(R.MyInternationalizationString.confrim)); alert.Show(); editInvalidTime.Text = "72"; } } }; var btnMsg2 = new Button() { Width = Application.GetRealWidth(271), Height = Application.GetRealHeight(180), Y = Application.GetRealHeight(141), X = editTextFrameLayout.Right, IsMoreLines = false, TextColor = UserCenterColor.Current.TextGrayColor1, TextAlignment = TextAlignment.CenterLeft, Text = msgArray[1] }; frameBack.AddChidren(btnMsg2); } /// /// 失效设置的底部按钮 /// /// /// private void InitBottomLogicButton(FrameLayout frameMain, FrameLayout frameBack) { //自动化按钮 var btnDoorLockLogic = new BottomLeftClickButton(Application.GetRealWidth(396), Application.GetRealHeight(127)); frameBack.AddChidren(btnDoorLockLogic); btnDoorLockLogic.InitControl(Language.StringByID(R.MyInternationalizationString.DoorLockLogic)); btnDoorLockLogic.ButtonClickEvent += (sender, e) => { //移除界面 frameMain.RemoveFromParent(); //回调函数 this.LogicClickEvent?.Invoke(); this.LogicClickEvent = null; }; //失效设置按钮 var btnInvalid = new BottomRightClickButton(frameBack.Width - btnDoorLockLogic.Width, btnDoorLockLogic.Height); frameBack.AddChidren(btnInvalid); btnInvalid.InitControl(buttonOkText); btnInvalid.ButtonClickEvent += (sender, e) => { //移除界面 frameMain.RemoveFromParent(); //回调函数 this.InvalidClickEvent?.Invoke(); this.InvalidClickEvent = null; }; } /// /// 失效时间的底部按钮 /// /// /// private void InitBottomInvalidTimeButton(FrameLayout frameMain, FrameLayout frameBack) { //确定按钮 var btnConfirm = new BottomRightClickButton(frameBack.Width, Application.GetRealHeight(127)); frameBack.AddChidren(btnConfirm); btnConfirm.InitControl(buttonOkText); btnConfirm.ButtonClickEvent += (sender, e) => { string textValue = string.Empty; if (editInvalidTime != null) { textValue = editInvalidTime.Text.Trim(); if (this.CheckInvalidTime(textValue.TrimStart('0')) == false) { return; } } //移除界面 frameMain.RemoveFromParent(); if (msgType == DoorLockMsgType.InValid) { if (InvalidTimeAction != null) { InvalidTimeAction(textValue); } } else { //回调函数 this.ConfirmClickEvent?.Invoke(); this.ConfirmClickEvent = null; } }; } /// /// 初始化确认类型的底部按钮 /// /// /// private void InitBottomConfirmButton(FrameLayout frameMain, FrameLayout frameBack) { //取消按钮 var btnCancel = new BottomLeftClickButton(Application.GetRealWidth(396), Application.GetRealHeight(127)); frameBack.AddChidren(btnCancel); var bottomLeftText = Language.StringByID(R.MyInternationalizationString.uCancel); if (msgType == DoorLockMsgType.NomallyOpenMode || msgType == DoorLockMsgType.CancelNomallyOpenModeWithLogic) { bottomLeftText = Language.StringByID(R.MyInternationalizationString.KeepNomallyMode); } btnCancel.InitControl(bottomLeftText); btnCancel.ButtonClickEvent += (sender, e) => { //移除界面 frameMain.RemoveFromParent(); //回调函数 this.CancelClickEvent?.Invoke(); this.CancelClickEvent = null; }; //确定按钮 var btnConfirm = new BottomRightClickButton(frameBack.Width - btnCancel.Width, btnCancel.Height); frameBack.AddChidren(btnConfirm); btnConfirm.InitControl(buttonOkText); btnConfirm.ButtonClickEvent += (sender, e) => { string textValue = string.Empty; if (editInvalidTime != null) { textValue = editInvalidTime.Text.Trim(); if (this.CheckInvalidTime(textValue.TrimStart('0')) == false) { return; } } //移除界面 frameMain.RemoveFromParent(); if (msgType == DoorLockMsgType.InValid) { if (InvalidTimeAction != null) { InvalidTimeAction(textValue); } } else { //回调函数 this.ConfirmClickEvent?.Invoke(); this.ConfirmClickEvent = null; } }; } /// /// 检测失效时间 /// /// /// private bool CheckInvalidTime(string tetxValue) { if (tetxValue == string.Empty) { var msg = Language.StringByID(R.MyInternationalizationString.InvalidTimeIsEmpty); var msgContr = new ShowMsgControl(ShowMsgType.Error, msg); msgContr.Show(); return false; } foreach (var c in tetxValue) { if (char.IsNumber(c) == false) { return false; } } if (tetxValue.Length >= 3) { var msg = Language.StringByID(R.MyInternationalizationString.InvalidTimeMoreThan72); var msgContr = new ShowMsgControl(ShowMsgType.Error, msg); msgContr.Show(); return false; } int value = Convert.ToInt32(tetxValue); if (value <= 0) { var msg = Language.StringByID(R.MyInternationalizationString.InvalidTimeLessThan1); var msgContr = new ShowMsgControl(ShowMsgType.Error, msg); msgContr.Show(); return false; } if (value > 72) { var msg = Language.StringByID(R.MyInternationalizationString.InvalidTimeMoreThan72); var msgContr = new ShowMsgControl(ShowMsgType.Error, msg); msgContr.Show(); return false; } return true; } #endregion /// /// 信息显示的类型 /// public enum DoorLockMsgType { /// /// 确认类型 /// Confirm = 1, /// /// 失效设置 /// InValid = 2, /// /// 逻辑类型 /// DoorLockLogic = 3, /// /// 常开模式 /// NomallyOpenMode = 4, /// /// 取消带有逻辑的常开模式 /// CancelNomallyOpenModeWithLogic = 5, } } }