黄学彪
2020-12-17 9f326f4000847e6167d8166fa2f6a66f53cb3734
ZigbeeApp/Shared/Phone/UserCenter/DoorLock/ShowDoorLockMsgControl.cs
@@ -1,8 +1,8 @@
using System;
using System.Text;
using System.Text.RegularExpressions;
using Shared.Common;
using System.Text.RegularExpressions;
using Shared.Common;
namespace Shared.Phone.UserCenter.DoorLock
{
    /// <summary>
@@ -18,11 +18,11 @@
        /// <summary>
        /// 点击取消的回调事件
        /// </summary>
        public Action CancelClickEvent = null;
        public Action CancelClickEvent = null;
        /// <summary>
        /// 点击自动化的回调事件
        /// </summary>
        public Action LogicClickEvent = null;
        public Action LogicClickEvent = null;
        /// <summary>
        /// 点击确认的回调事件
        /// </summary>
@@ -50,16 +50,16 @@
        /// <summary>
        /// 确认按钮的文本
        /// </summary>
        private string buttonOkText = null;
        /// <summary>
        /// 失效时间编辑
        /// </summary>
        private EditText editInvalidTime = null;
        private string buttonOkText = null;
        /// <summary>
        /// 失效时间编辑
        /// </summary>
        private EditText editInvalidTime = null;
        #endregion
        #region ■ 初始化_____________________________
        /// <summary>
        /// 显示一个需要确认的信息框
        /// </summary>
@@ -71,7 +71,7 @@
            //确认按钮文本
            this.buttonOkText = buttonText == null ? Language.StringByID(R.MyInternationalizationString.OkMsg) : buttonText;
            this.msgType = i_msgType;
            this.msgText = i_msg;
            this.msgText = i_msg;
        }
        #endregion
@@ -84,8 +84,8 @@
        public void Show()
        {
            try
            {
                //初始化控件
            {
                //初始化控件
                this.InitMsgControl();
            }
            catch (Exception ex) { HdlLogLogic.Current.WriteLog(ex); }
@@ -112,6 +112,11 @@
            ((ViewGroup)nowForm).AddChidren(MsgControlFrameLayout);
            MsgControlFrameLayout.MouseDownEventHandler += (sender, e) =>
            {
                if (msgType == DoorLockMsgType.InValid)
                {
                    return;
                }
                //移除界面
                MsgControlFrameLayout.RemoveFromParent();
                //回调函数
@@ -121,24 +126,24 @@
            //白色背景框
            var frameBack = new FrameLayout();
            frameBack.BackgroundColor = UserCenterColor.Current.White;
            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);
            if (msgType == DoorLockMsgType.CancelNomallyOpenModeWithLogic)
            {
                frameBack.Height = Application.GetRealHeight(409 + 127);
                frameBack.Width = Application.GetRealWidth(850);
                frameBack.Y = Application.GetRealHeight(648);
            }
            MsgControlFrameLayout.AddChidren(frameBack);
            //标题
            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;
@@ -148,7 +153,7 @@
            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;
@@ -160,127 +165,152 @@
            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;
                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.InValid || msgType == DoorLockMsgType.NomallyOpenMode)
            if (msgType == DoorLockMsgType.Confirm || msgType == DoorLockMsgType.NomallyOpenMode || msgType == DoorLockMsgType.CancelNomallyOpenModeWithLogic)
            {
                //初始化确认类型的底部按钮
                this.InitBottomConfirmButton(MsgControlFrameLayout, frameBack);
            }
            else if (msgType == DoorLockMsgType.DoorLockLogic || msgType == DoorLockMsgType.CancelNomallyOpenModeWithLogic)
            }
            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;
        }
        {
            //消息
            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);
            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);
        }
        {
            //消息
            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 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>
@@ -295,8 +325,8 @@
            btnDoorLockLogic.ButtonClickEvent += (sender, e) =>
            {
                //移除界面
                frameMain.RemoveFromParent();
                //回调函数
                frameMain.RemoveFromParent();
                //回调函数
                this.LogicClickEvent?.Invoke();
                this.LogicClickEvent = null;
            };
@@ -316,6 +346,46 @@
        }
        /// <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>
@@ -326,16 +396,16 @@
            var btnCancel = new BottomLeftClickButton(Application.GetRealWidth(396), Application.GetRealHeight(127));
            frameBack.AddChidren(btnCancel);
            var bottomLeftText = Language.StringByID(R.MyInternationalizationString.uCancel);
            if (msgType == DoorLockMsgType.NomallyOpenMode)
            {
                bottomLeftText = Language.StringByID(R.MyInternationalizationString.KeepNomallyMode);
            if (msgType == DoorLockMsgType.NomallyOpenMode || msgType == DoorLockMsgType.CancelNomallyOpenModeWithLogic)
            {
                bottomLeftText = Language.StringByID(R.MyInternationalizationString.KeepNomallyMode);
            }
            btnCancel.InitControl(bottomLeftText);
            btnCancel.ButtonClickEvent += (sender, e) =>
            {
                //移除界面
                frameMain.RemoveFromParent();
                //回调函数
                frameMain.RemoveFromParent();
                //回调函数
                this.CancelClickEvent?.Invoke();
                this.CancelClickEvent = null;
            };
@@ -345,46 +415,47 @@
            frameBack.AddChidren(btnConfirm);
            btnConfirm.InitControl(buttonOkText);
            btnConfirm.ButtonClickEvent += (sender, e) =>
            {
                string textValue = string.Empty;
            {
                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;
                }
                if (msgType == DoorLockMsgType.InValid)
                {
                    if (InvalidTimeAction != null)
                    {
                        InvalidTimeAction(textValue);
                    }
                }
                else
                {
                    //回调函数
                    this.ConfirmClickEvent?.Invoke();
                    this.ConfirmClickEvent = null;
                }
            };
        }
        }
        /// <summary>
        /// 检测失效时间
        /// </summary>
        /// <param name="tetxValue"></param>
        /// <returns></returns>
        /// <returns></returns>
        private bool CheckInvalidTime(string tetxValue)
        {
            if (tetxValue == string.Empty)
            if (tetxValue == string.Empty)
            {
                var msgContr = new ShowMsgControl(ShowMsgType.Error, "失效时间不能省略");
                var msg = Language.StringByID(R.MyInternationalizationString.InvalidTimeIsEmpty);
                var msgContr = new ShowMsgControl(ShowMsgType.Error, msg);
                msgContr.Show();
                return false;
                return false;
            }
            foreach (var c in tetxValue)
            {
@@ -395,7 +466,8 @@
            }
            if (tetxValue.Length >= 3)
            {
                var msgContr = new ShowMsgControl(ShowMsgType.Error, "失效时间不能大于36小时");
                var msg = Language.StringByID(R.MyInternationalizationString.InvalidTimeMoreThan72);
                var msgContr = new ShowMsgControl(ShowMsgType.Error, msg);
                msgContr.Show();
                return false;
            }
@@ -403,46 +475,48 @@
            int value = Convert.ToInt32(tetxValue);
            if (value <= 0)
            {
                var msgContr = new ShowMsgControl(ShowMsgType.Error, "失效时间不能小于1小时");
                var msg = Language.StringByID(R.MyInternationalizationString.InvalidTimeLessThan1);
                var msgContr = new ShowMsgControl(ShowMsgType.Error, msg);
                msgContr.Show();
                return false;
            }
            if (value > 36)
            if (value > 72)
            {
                var msgContr = new ShowMsgControl(ShowMsgType.Error, "失效时间不能大于36小时");
                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
        {
        public enum DoorLockMsgType
        {
            /// <summary>
            /// 确认类型
            /// </summary>
            Confirm = 1,
            Confirm = 1,
            /// <summary>
            /// 失效设置
            /// </summary>
            InValid = 2,
            InValid = 2,
            /// <summary>
            /// 逻辑类型
            /// </summary>
            DoorLockLogic = 3,
            DoorLockLogic = 3,
            /// <summary>
            /// 常开模式
            /// </summary>
            NomallyOpenMode = 4,
            NomallyOpenMode = 4,
            /// <summary>
            /// 取消带有逻辑的常开模式
            /// </summary>
            CancelNomallyOpenModeWithLogic = 5,
        }
    }
}
            CancelNomallyOpenModeWithLogic = 5,
        }
    }
}