From 9ef48d7b2da7c408b53f73be0f6eef3cbac1c84a Mon Sep 17 00:00:00 2001 From: 黄学彪 <hxb@hdlchina.com.cn> Date: 星期四, 19 十一月 2020 10:23:45 +0800 Subject: [PATCH] Evoyo.Home1.1.0120111601_Release --- ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Controls/BaseCommonControl/Base/TextInputBase.cs | 106 ++++++++++++++++++++++++++++++++++++++-------------- 1 files changed, 77 insertions(+), 29 deletions(-) diff --git a/ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Controls/BaseCommonControl/Base/TextInputBase.cs b/ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Controls/BaseCommonControl/Base/TextInputBase.cs index dbf1a01..58b1f8c 100755 --- a/ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Controls/BaseCommonControl/Base/TextInputBase.cs +++ b/ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Controls/BaseCommonControl/Base/TextInputBase.cs @@ -16,7 +16,7 @@ /// </summary> private NormalViewControl btnLineTemp = null; /// <summary> - /// 鑱斿姩搴曠嚎(鍊艰緭鍏ヤ箣鍚�,绾跨殑棰滆壊浼氬彉) + /// 鑱斿姩搴曠嚎(鍏夋爣杩涙潵涔嬪悗,绾跨殑棰滆壊浼氬彉) /// </summary> public NormalViewControl btnLine { @@ -25,19 +25,51 @@ this.btnLineTemp = value; } } + /// <summary> + /// 鑱斿姩澶栨 + /// </summary> + private NormalFrameLayout frameBorder = null; + /// <summary> + /// 鑱斿姩澶栨(鍏夋爣杩涙潵涔嬪悗,澶栨鐨勯鑹蹭細鍙�) + /// </summary> + public NormalFrameLayout FrameBorder + { + set + { + this.frameBorder = value; + } + } /// <summary> /// 杈撳叆缁撴潫鐨勪簨浠� /// </summary> public Action FinishInputEvent = null; /// <summary> - /// 鏈�澶ц緭鍏ラ暱搴�(鐩墠鍙拡瀵规寜涓嬪洖杞﹂敭鏃惰繘琛屾娴�,瓒呰繃鏃�,涓嶄細璋冪敤FinishInputEvent) + /// 鍊兼敼鍙樹簨浠�(鍙桵axByte灞炴�ч檺鍒�) /// </summary> - public int MaxByte = 0; + public Action<string> TextChangedEvent = null; /// <summary> /// 鎸囧畾璇ヨ緭鍏ユ鏄惁涓轰笉鍙渷鐣�(榛樿涓篺alse) /// </summary> public bool MustInput = false; + + private int m_MaxByte = -1; + /// <summary> + /// 鏈�澶ц緭鍏yte闀垮害 + /// </summary> + public int MaxByte + { + get { return m_MaxByte; } + set + { + m_MaxByte = value; + this.TextChangeEventHandler -= this.TxtCode_TextChangedEvent; + if (m_MaxByte > 0) + { + this.TextChangeEventHandler += this.TxtCode_TextChangedEvent; + } + } + } private bool m_UseFocusColor = false; /// <summary> @@ -177,6 +209,10 @@ { btnLineTemp.BackgroundColor = UserCenterColor.Current.ButtomLine; } + if (frameBorder != null) + { + frameBorder.BorderColor = 0xffcccccc; + } if (m_UseFocusColor == true) { //鐏拌壊瀛椾綋 @@ -188,6 +224,10 @@ if (btnLineTemp != null) { btnLineTemp.BackgroundColor = UserCenterColor.Current.TextFrameSelectColor; + } + if (frameBorder != null) + { + frameBorder.BorderColor = UserCenterColor.Current.TextFrameSelectColor; } if (m_UseFocusColor == true) { @@ -212,6 +252,39 @@ return; } this.FinishInputEvent?.Invoke(); + } + + /// <summary> + /// 鍊兼敼鍙樹簨浠� + /// </summary> + /// <param name="sender"></param> + /// <param name="value"></param> + private void TxtCode_TextChangedEvent(object sender, string value) + { + var byteData = Encoding.UTF8.GetBytes(value); + var newValue = value; + + //濡傛灉杈撳叆鐨勫��,宸茬粡澶т簬鎸囧畾鐨刡yte鏁�,鍒欐埅鍙� + if (byteData.Length > this.m_MaxByte) + { + //鎴彇鎸囧畾鐨刡yte瀛楄妭 + newValue = Encoding.UTF8.GetString(byteData, 0, this.m_MaxByte); + //鏈�鍚庝竴浣嶄笉瑕�,鍥犱负鎴彇鐨勬渶鍚庝竴浣嶅彲鑳芥槸涔辩爜 + newValue = newValue.Substring(0, newValue.Length - 1); + //鎷兼帴涓婂畠鐨勪笅涓�浣�,鐒跺悗妫�娴� + var checkValue = newValue + value[newValue.Length]; + if (Encoding.UTF8.GetBytes(checkValue).Length <= this.m_MaxByte) + { + //姝eソ鍖归厤byte鏁� + newValue = checkValue; + } + this.Text = newValue; + //灏嗗厜鏍囪嚦浜庢渶鍚� +#if Android + this.SetSelectionEnd(); +#endif + } + this.TextChangedEvent?.Invoke(newValue); } #endregion @@ -265,38 +338,12 @@ /// <returns></returns> private string CheckMaxByte() { - if (this.MaxByte != 0) - { - if (Encoding.UTF8.GetBytes(this.Text.Trim()).Length > this.MaxByte) - { - //杈撳叆鍐呭杩囬暱,鏈�澶0}瀛楄妭 - string msg = Language.StringByID(R.MyInternationalizationString.uInputContentIsOverLengthMsg); - msg.Replace("{0}", this.MaxByte.ToString()); - - return msg; - } - } return null; } #endregion #region 鈻� 涓�鑸柟娉昣__________________________ - - /// <summary> - /// Y杞撮噸缃�(鐪熷疄鏁板��,娌℃湁鐖跺鍣ㄦ棤鏁�) - /// </summary> - /// <param name="alignment">涓婁笅瀵归綈鏂瑰紡</param> - /// <param name="Space">涓婁笅涓ら儴鍒嗙殑闂磋窛</param> - public void ReSetYaxis(UViewAlignment alignment, int Space = 0) - { - if (this.Parent == null) - { - return; - } - //Y杞撮噸缃� - this.Y = HdlControlLogic.Current.GetControlChidrenYaxis(this.Parent.Height, this.Height, alignment, Space); - } /// <summary> /// 璁$畻鍥剧墖鐨勭湡瀹為珮瀹藉害 @@ -314,6 +361,7 @@ public override void RemoveFromParent() { this.FinishInputEvent = null; + this.TextChangedEvent = null; if (this.Parent != null) { base.RemoveFromParent(); -- Gitblit v1.8.0