From 5b0a842cbdc5dc54e45e5d350d3516d0cdd59199 Mon Sep 17 00:00:00 2001
From: lss <lsc@hdlchina.com.cn>
Date: 星期一, 25 四月 2022 14:50:07 +0800
Subject: [PATCH] 2022-4-25
---
ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Controls/BaseCommonControl/Base/TextInputBase.cs | 493 +++++++++++++++++++++++++++++++++++++++--------------
1 files changed, 359 insertions(+), 134 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
old mode 100755
new mode 100644
index d48e6be..7c4210e
--- a/ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Controls/BaseCommonControl/Base/TextInputBase.cs
+++ b/ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Controls/BaseCommonControl/Base/TextInputBase.cs
@@ -1,148 +1,373 @@
-锘縰sing System;
-using System.Collections.Generic;
-using System.Text;
-
-namespace Shared.Phone.UserCenter
-{
- /// <summary>
- /// 杈撳叆妗嗘帶浠剁殑鏈�鍒濆師鍨�(涓嶅缓璁慨鏀瑰拰鐩存帴浣跨敤):鏍囧噯瀛椾綋棰滆壊锛屾枃瀛楀悜宸﹂潬榻�,14鍙峰瓧
- /// </summary>
- public class TextInputBase : EditText
- {
- #region 鈻� 鍙橀噺澹版槑___________________________
-
- /// <summary>
- /// 鑱斿姩搴曠嚎
- /// </summary>
- private NormalViewControl btnLineTemp = null;
- /// <summary>
- /// 鑱斿姩搴曠嚎(鍊艰緭鍏ヤ箣鍚�,绾跨殑棰滆壊浼氬彉)
- /// </summary>
- public NormalViewControl btnLine
- {
- set
- {
- this.btnLineTemp = value;
- //鍏夋爣浜嬩欢
- this.FoucsChanged -= this.TxtCode_FoucsChangedEvent;
- this.FoucsChanged += this.TxtCode_FoucsChangedEvent;
- }
- }
-
- #endregion
-
- #region 鈻� 鍒濆鍖朹____________________________
-
- /// <summary>
- /// 杈撳叆妗嗘帶浠剁殑鏈�鍒濆師鍨�(涓嶅缓璁慨鏀瑰拰鐩存帴浣跨敤):鏍囧噯瀛椾綋棰滆壊锛屾枃瀛楀悜宸﹂潬榻�,14鍙峰瓧
- /// </summary>
- public TextInputBase()
- {
- //娴嬭瘯锛屽叏浣撹緭鍏ユ涓�14鍙峰瓧
- this.TextSize = 14;
-
- this.PlaceholderTextColor = UserCenterColor.Current.TextTipColor;
- this.TextColor = UserCenterColor.Current.TextColor1;
- this.TextAlignment = TextAlignment.CenterLeft;
- }
-
- /// <summary>
- /// 鍒濆鍖栨帶浠跺ぇ灏�(涓嶄互骞冲潎鍊艰繘琛岀湡瀹炴暟鍊艰绠�)
- /// </summary>
+锘縰sing System;
+using System.Collections.Generic;
+using System.Text;
+
+namespace Shared.Phone.UserCenter
+{
+ /// <summary>
+ /// 杈撳叆妗嗘帶浠剁殑鏈�鍒濆師鍨�(涓嶅缓璁慨鏀瑰拰鐩存帴浣跨敤):鏍囧噯瀛椾綋棰滆壊锛屾枃瀛楀悜宸﹂潬榻�,14鍙峰瓧
+ /// </summary>
+ public class TextInputBase : EditText
+ {
+ #region 鈻� 鍙橀噺澹版槑___________________________
+
+ /// <summary>
+ /// 鑱斿姩搴曠嚎
+ /// </summary>
+ private NormalViewControl btnLineTemp = null;
+ /// <summary>
+ /// 鑱斿姩搴曠嚎(鍏夋爣杩涙潵涔嬪悗,绾跨殑棰滆壊浼氬彉)
+ /// </summary>
+ public NormalViewControl btnLine
+ {
+ set
+ {
+ 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>
+ /// 鍊兼敼鍙樹簨浠�(鍙桵axByte灞炴�ч檺鍒�)
+ /// </summary>
+ 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>
+ /// 鍏夋爣杩涘叆鏂囨湰妗嗘椂,鏄惁璁╁瓧浣撻鑹插彉鏇�(榛樿涓嶄娇鐢�)
+ /// </summary>
+ public bool UseFocusColor
+ {
+ set
+ {
+ m_UseFocusColor = value;
+ if (m_UseFocusColor == true)
+ {
+ //鐏拌壊瀛椾綋
+ this.TextColor = UserCenterColor.Current.TextGrayColor3;
+ }
+ }
+ }
+
+ private bool m_OnError = false;
+ /// <summary>
+ /// 璁╄繖涓枃鏈鏄剧ず澶勪簬閿欒鐨勭壒鏁�
+ /// </summary>
+ public bool OnError
+ {
+ get { return m_OnError; }
+ set
+ {
+ if (value != m_OnError)
+ {
+ m_OnError = value;
+ //鏆傛椂灞忚斀姝ょ壒鏁�
+ //if (m_OnError == true)
+ //{
+ // //绾㈣壊
+ // this.BorderColor = UserCenterColor.Current.Red;
+ // this.Radius = (uint)Application.GetRealHeight(17);
+ // this.BorderWidth = 3;
+ //}
+ //else
+ //{
+ // this.BorderColor = UserCenterColor.Current.Transparent;
+ // this.BorderWidth = 0;
+ // this.Radius = 0;
+ //}
+ }
+ }
+ }
+
+ #endregion
+
+ #region 鈻� 鍒濆鍖朹____________________________
+
+ /// <summary>
+ /// 杈撳叆妗嗘帶浠剁殑鏈�鍒濆師鍨�(涓嶅缓璁慨鏀瑰拰鐩存帴浣跨敤):鏍囧噯瀛椾綋棰滆壊锛屾枃瀛楀悜宸﹂潬榻�,14鍙峰瓧
+ /// </summary>
+ public TextInputBase()
+ {
+ //娴嬭瘯锛屽叏浣撹緭鍏ユ涓�14鍙峰瓧
+ this.TextSize = 14;
+
+ this.PlaceholderTextColor = UserCenterColor.Current.TextTipColor;
+ this.TextColor = UserCenterColor.Current.TextColor1;
+ this.TextAlignment = TextAlignment.CenterLeft;
+
+ //鐒︾偣浜嬩欢
+ this.FoucsChanged += this.TxtCode_FoucsChangedEvent;
+ //鎸変笅鍥炶溅閿簨浠�
+ this.EditorEnterAction += this.EditorEnterEvent;
+ }
+
+ /// <summary>
+ /// 鍒濆鍖栨帶浠跺ぇ灏�(涓嶄互骞冲潎鍊艰繘琛岀湡瀹炴暟鍊艰绠�)
+ /// </summary>
/// <param name="i_Width">瀹藉害</param>
/// <param name="i_Height">楂樺害</param>
- /// <param name="real">鏄惁璁$畻鐪熷疄鍊�</param>
- public void InitSize(int i_Width, int i_Height, bool real = true)
- {
- if (real == true)
- {
- i_Width = Application.GetRealWidth(i_Width);
- i_Height = Application.GetRealHeight(i_Height);
+ /// <param name="real">鏄惁璁$畻鐪熷疄鍊�</param>
+ public void InitSize(int i_Width, int i_Height, bool real = true)
+ {
+ if (real == true)
+ {
+ i_Width = Application.GetRealWidth(i_Width);
+ i_Height = Application.GetRealHeight(i_Height);
}
this.Height = i_Height;
- this.Width = i_Width;
- }
-
- /// <summary>
- /// 鍒濆鍖栨帶浠跺ぇ灏�(涓嶄互骞冲潎鍊艰繘琛岀湡瀹炴暟鍊艰绠�)
- /// </summary>
+ this.Width = i_Width;
+ }
+
+ /// <summary>
+ /// 鍒濆鍖栨帶浠跺ぇ灏�(涓嶄互骞冲潎鍊艰繘琛岀湡瀹炴暟鍊艰绠�)
+ /// </summary>
/// <param name="i_Width">瀹藉害</param>
- /// <param name="real">鏄惁璁$畻鐪熷疄鍊�</param>
- public void InitSize(int i_Width, bool real = true)
- {
- if (real == true)
- {
- i_Width = Application.GetRealWidth(i_Width);
+ /// <param name="real">鏄惁璁$畻鐪熷疄鍊�</param>
+ public void InitSize(int i_Width, bool real = true)
+ {
+ if (real == true)
+ {
+ i_Width = Application.GetRealWidth(i_Width);
}
this.Height = ControlCommonResourse.NormalControlHeight;
- this.Width = i_Width;
- }
-
- /// <summary>
- /// 鍒濆鍖栨帶浠跺ぇ灏�(浠ュ钩鍧囧�艰繘琛岀湡瀹炴暟鍊艰绠�)
- /// </summary>
+ this.Width = i_Width;
+ }
+
+ /// <summary>
+ /// 鍒濆鍖栨帶浠跺ぇ灏�(浠ュ钩鍧囧�艰繘琛岀湡瀹炴暟鍊艰绠�)
+ /// </summary>
/// <param name="i_Width">瀹藉害</param>
/// <param name="i_Height">楂樺害</param>
- /// <param name="real">鏄惁璁$畻鐪熷疄鍊�</param>
- public void InitAvgSize(int i_Width, int i_Height, bool real = true)
- {
- if (real == true)
- {
- i_Width = Application.GetMinRealAverage(i_Width);
- i_Height = Application.GetMinRealAverage(i_Height);
+ /// <param name="real">鏄惁璁$畻鐪熷疄鍊�</param>
+ public void InitAvgSize(int i_Width, int i_Height, bool real = true)
+ {
+ if (real == true)
+ {
+ i_Width = this.GetPictrueRealSize(i_Width);
+ i_Height = this.GetPictrueRealSize(i_Height);
}
this.Height = i_Height;
- this.Width = i_Width;
- }
-
- #endregion
-
- #region 鈻� 浜嬩欢_______________________________
-
- /// <summary>
- /// 鐒︾偣鍙樻洿浜嬩欢
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void TxtCode_FoucsChangedEvent(object sender, FocusEventArgs e)
- {
- if (e.Focus == false)
- {
- if (btnLineTemp != null)
- {
- btnLineTemp.BackgroundColor = UserCenterColor.Current.ButtomLine;
- }
- }
- else
- {
- if (btnLineTemp != null)
- {
- btnLineTemp.BackgroundColor = UserCenterColor.Current.TextFrameSelectColor;
- }
- }
- }
-
- #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 = UserCenterLogic.GetControlChidrenYaxis(this.Parent.Height, this.Height, alignment, Space);
- }
- #endregion
- }
-}
+ this.Width = i_Width;
+ }
+
+ #endregion
+
+ #region 鈻� 浜嬩欢_______________________________
+
+ /// <summary>
+ /// 鐒︾偣鍙樻洿浜嬩欢
+ /// </summary>
+ /// <param name="sender"></param>
+ /// <param name="e"></param>
+ private void TxtCode_FoucsChangedEvent(object sender, FocusEventArgs e)
+ {
+ if (e.Focus == false)
+ {
+ if (btnLineTemp != null)
+ {
+ btnLineTemp.BackgroundColor = UserCenterColor.Current.ButtomLine;
+ }
+ if (frameBorder != null)
+ {
+ frameBorder.BorderColor = 0xffcccccc;
+ }
+ if (m_UseFocusColor == true)
+ {
+ //鐏拌壊瀛椾綋
+ this.TextColor = UserCenterColor.Current.TextGrayColor3;
+ }
+ }
+ else
+ {
+ if (btnLineTemp != null)
+ {
+ btnLineTemp.BackgroundColor = UserCenterColor.Current.TextFrameSelectColor;
+ }
+ if (frameBorder != null)
+ {
+ frameBorder.BorderColor = UserCenterColor.Current.TextFrameSelectColor;
+ }
+ if (m_UseFocusColor == true)
+ {
+ //姝e父瀛椾綋
+ this.TextColor = UserCenterColor.Current.TextColor1;
+ }
+ }
+ }
+
+ /// <summary>
+ /// 杈撳叆瀹屾垚浜嬩欢
+ /// </summary>
+ /// <param name="view"></param>
+ private void EditorEnterEvent(View view)
+ {
+ //妫�娴嬫渶澶ц緭鍑築yte
+ string msg = this.CheckMaxByte();
+ if (msg != null)
+ {
+ var contr = new ShowMsgControl(ShowMsgType.Tip, msg);
+ contr.Show();
+ 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
+
+ #region 鈻� 妫�娴嬮敊璇痏__________________________
+
+ /// <summary>
+ /// 妫�娴嬫纭��,瀛樺湪閿欒鏃�,杩斿洖閿欒鏂囨湰,鏃犻敊璇繑鍥瀗ull
+ /// </summary>
+ /// <returns></returns>
+ public string CheckError()
+ {
+ //鎵ц妫�娴嬮敊璇�
+ string error = this.DoCheckError();
+ if (error != null)
+ {
+ //鐒︾偣鎺у埗
+ this.Foucs = true;
+ return error;
+ }
+ return null;
+ }
+
+ /// <summary>
+ /// 鎵ц妫�娴嬮敊璇�
+ /// </summary>
+ /// <returns></returns>
+ private string DoCheckError()
+ {
+ //妫�娴嬫渶澶ц緭鍑築yte
+ string msg = this.CheckMaxByte();
+ if (msg != null) { return msg; }
+
+ //妫�娴嬪繀椤昏緭鍏�
+ if (this.MustInput == true && this.Text.Trim() == string.Empty)
+ {
+ if (string.IsNullOrEmpty(this.PlaceholderText) == false)
+ {
+ return this.PlaceholderText;
+ }
+ //璇ュ唴瀹逛笉鑳界渷鐣�
+ return Language.StringByID(R.MyInternationalizationString.uThisContentCanNotOmitted);
+ }
+
+ return null;
+ }
+
+ /// <summary>
+ /// 妫�娴嬫渶澶ц緭鍏yte
+ /// </summary>
+ /// <returns></returns>
+ private string CheckMaxByte()
+ {
+ return null;
+ }
+
+ #endregion
+
+ #region 鈻� 涓�鑸柟娉昣__________________________
+
+ /// <summary>
+ /// 璁$畻鍥剧墖鐨勭湡瀹為珮瀹藉害
+ /// </summary>
+ /// <param name="i_size"></param>
+ /// <returns></returns>
+ public int GetPictrueRealSize(int i_size)
+ {
+ return HdlControlLogic.Current.GetPictrueRealSize(i_size);
+ }
+
+ /// <summary>
+ /// 鎺т欢绉婚櫎
+ /// </summary>
+ public override void RemoveFromParent()
+ {
+ this.FinishInputEvent = null;
+ this.TextChangedEvent = null;
+ if (this.Parent != null)
+ {
+ base.RemoveFromParent();
+ }
+ }
+
+ #endregion
+ }
+}
--
Gitblit v1.8.0