From 3aa397ab145382935492b11c1f18c9634e69910b Mon Sep 17 00:00:00 2001 From: xm <1271024303@qq.com> Date: 星期四, 10 十二月 2020 16:45:00 +0800 Subject: [PATCH] 请合并,门锁和晾衣架第一版代码 --- ZigbeeApp/Shared/Phone/UserCenter/DoorLock/ShowDoorLockMsgControl.cs | 522 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 522 insertions(+), 0 deletions(-) diff --git a/ZigbeeApp/Shared/Phone/UserCenter/DoorLock/ShowDoorLockMsgControl.cs b/ZigbeeApp/Shared/Phone/UserCenter/DoorLock/ShowDoorLockMsgControl.cs new file mode 100755 index 0000000..25bb51f --- /dev/null +++ b/ZigbeeApp/Shared/Phone/UserCenter/DoorLock/ShowDoorLockMsgControl.cs @@ -0,0 +1,522 @@ +锘縰sing System; +using System.Text; +using System.Text.RegularExpressions; +using Shared.Common; + +namespace Shared.Phone.UserCenter.DoorLock +{ + /// <summary> + /// 鏄剧ず涓�涓俊鎭 + /// </summary> + public class ShowDoorLockMsgControl + { + #region 鈻� 鍙橀噺澹版槑___________________________ + /// <summary> + /// 鐐瑰嚮澶辨晥鍥炶皟鐨勪簨浠� + /// </summary> + public Action<string> InvalidTimeAction = null; + /// <summary> + /// 鐐瑰嚮鍙栨秷鐨勫洖璋冧簨浠� + /// </summary> + public Action CancelClickEvent = null; + /// <summary> + /// 鐐瑰嚮鑷姩鍖栫殑鍥炶皟浜嬩欢 + /// </summary> + public Action LogicClickEvent = null; + /// <summary> + /// 鐐瑰嚮纭鐨勫洖璋冧簨浠� + /// </summary> + public Action InvalidClickEvent = null; + /// <summary> + /// 鐐瑰嚮纭鐨勫洖璋冧簨浠� + /// </summary> + public Action ConfirmClickEvent = null; + /// <summary> + /// 鐐瑰嚮寮圭獥鑳屾櫙鍥炶皟浜嬩欢 + /// </summary> + public Action MsgControlClickEvent = null; + /// <summary> + /// 淇℃伅绫诲瀷 + /// </summary> + private DoorLockMsgType msgType = DoorLockMsgType.Confirm; + /// <summary> + /// 寮圭獥鑳屾櫙 + /// </summary> + public FrameLayout MsgControlFrameLayout = null; + /// <summary> + /// 娑堟伅 + /// </summary> + private string msgText = string.Empty; + /// <summary> + /// 纭鎸夐挳鐨勬枃鏈� + /// </summary> + private string buttonOkText = null; + /// <summary> + /// 澶辨晥鏃堕棿缂栬緫 + /// </summary> + private EditText editInvalidTime = null; + + #endregion + + #region 鈻� 鍒濆鍖朹____________________________ + + /// <summary> + /// 鏄剧ず涓�涓渶瑕佺‘璁ょ殑淇℃伅妗� + /// </summary> + /// <param name="i_msgType">淇℃伅绫诲瀷</param> + /// <param name="i_msg">淇℃伅</param> + /// <param name="buttonText">纭鎸夐挳鐨勬枃鏈�</param> + 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 鈻� 鏄剧ず娑堟伅___________________________ + + /// <summary> + /// 鏄剧ず + /// </summary> + public void Show() + { + try + { + //鍒濆鍖栨帶浠� + this.InitMsgControl(); + } + catch (Exception ex) { HdlLogLogic.Current.WriteLog(ex); } + } + + #endregion + + #region 鈻� 鍒濆鍖栨帶浠禵________________________ + + /// <summary> + /// 鍒濆鍖栨帶浠� + /// </summary> + 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); + } + } + + /// <summary> + /// 鍙栨秷甯稿紑妯″紡甯︽湁鑷姩鍖栫殑寮圭獥鏄剧ず + /// </summary> + /// <param name="frameMain"></param> + /// <param name="frameBack"></param> + 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; + } + + /// <summary> + /// 澶辨晥鏃堕棿璁剧疆鐨勫脊绐楁樉绀� + /// </summary> + /// <param name="frameMain"></param> + /// <param name="frameBack"></param> + 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(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); + } + + /// <summary> + /// 澶辨晥璁剧疆鐨勫簳閮ㄦ寜閽� + /// </summary> + /// <param name="frameMain"></param> + /// <param name="frameBack"></param> + 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; + }; + } + + /// <summary> + /// 澶辨晥鏃堕棿鐨勫簳閮ㄦ寜閽� + /// </summary> + /// <param name="frameMain"></param> + /// <param name="frameBack"></param> + 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; + } + }; + } + + /// <summary> + /// 鍒濆鍖栫‘璁ょ被鍨嬬殑搴曢儴鎸夐挳 + /// </summary> + /// <param name="frameMain"></param> + /// <param name="frameBack"></param> + 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; + } + }; + } + + /// <summary> + /// 妫�娴嬪け鏁堟椂闂� + /// </summary> + /// <param name="tetxValue"></param> + /// <returns></returns> + 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 + + /// <summary> + /// 淇℃伅鏄剧ず鐨勭被鍨� + /// </summary> + public enum DoorLockMsgType + { + /// <summary> + /// 纭绫诲瀷 + /// </summary> + Confirm = 1, + /// <summary> + /// 澶辨晥璁剧疆 + /// </summary> + InValid = 2, + /// <summary> + /// 閫昏緫绫诲瀷 + /// </summary> + DoorLockLogic = 3, + /// <summary> + /// 甯稿紑妯″紡 + /// </summary> + NomallyOpenMode = 4, + /// <summary> + /// 鍙栨秷甯︽湁閫昏緫鐨勫父寮�妯″紡 + /// </summary> + CancelNomallyOpenModeWithLogic = 5, + } + } +} -- Gitblit v1.8.0