using Shared; using HDL_ON.UI.CSS; using System; using System.Collections.Generic; using System.Text; namespace HDL_ON.Stan { /// /// 左右滑动的进度条控件(高度为54 左右间距为20) /// 如果是加在PageLayout里面的话,加入父控件之后,请调用BindPageLayout() /// public class SeekBarImageControl : DiyImageSeekBar { #region ■ 变量声明___________________________ /// /// 进度值改变,如果要设置初始进度值,此变量要在设置初始进度值之前进行设置(第一个参数0:滑动的时候,1:手指弹起的时候) /// public Action ProgressChangedEvent = null; /// /// 进度条可用时的背景色 /// private uint ProgressBarEnableColor = 0; /// /// 进度条不可用时的背景色(默认灰色) /// public uint ProgressBarUnEnableColor = 0xffe8e8e8; /// /// 当前可用状态 /// private bool nowEnable = true; /// /// 控件能否使用 /// public new bool Enable { set { //状态没有改变 if (nowEnable == value) { return; } nowEnable = value; this.IsClickable = value; if (value == true) { //原来的颜色 base.ProgressBarColor = ProgressBarEnableColor; } else { //灰色 base.ProgressBarColor = ProgressBarUnEnableColor; } } } /// /// 进度条颜色 /// public new uint ProgressBarColor { set { ProgressBarEnableColor = value; base.ProgressBarColor = value; } } private int m_SeekBarPadding = Application.GetRealWidth(20); /// /// 进度条与左右两边的边框的边距(重写底层属性) /// public new int SeekBarPadding { set { m_SeekBarPadding = value; base.SeekBarPadding = value; } get { return m_SeekBarPadding; } } private int m_MaxValue = 0; /// /// 进度条最大值(重写底层属性) /// public new int MaxValue { set { m_MaxValue = value; base.MaxValue = value; } } private int m_MinValue = 0; /// /// 进度条最小值(重写底层属性) /// public new int MinValue { set { m_MinValue = value; base.MinValue = value; } } /// /// 上方显示的文本 /// private Button btnTopView = null; /// /// 绑定PageLayout,事件冲突,需要特殊处理 /// private PageLayout pageLayoutBind = null; #endregion #region ■ 初始化_____________________________ /// /// 左右滑动的进度条控件(高度为54 左右间距为20) /// 如果是加在PageLayout里面的话,加入父控件之后,请调用BindPageLayout() /// /// 宽度,非真实值,实际宽度会加上左右间距 public SeekBarImageControl(int i_width) { this.ProgressChangeDelayTime = 0; this.Width = Application.GetRealWidth(i_width) + m_SeekBarPadding * 2; this.Height = Application.GetRealHeight(54); //圆球的高度 this.ThumbImageHeight = Application.GetRealHeight(54); this.ThumbImagePath = "Public/ThumbImage.png"; //进度条的高度度 this.SeekBarViewHeight = Application.GetRealHeight(8); //上方是否显示文本 this.IsProgressTextShow = false; this.Gravity = Gravity.CenterHorizontal; //进度条颜色 this.ProgressBarColor = CSS_Color.MainColor; //左右边距(最好不要改这个数值,一旦改了,可能会干扰到其他界面) this.SeekBarPadding = Application.GetRealWidth(20); //进度条值改变事件 this.OnProgressChangedEvent += this.MyProgressChangedEvent; //手指弹起事件 this.OnStopTrackingTouchEvent += this.MyStopTrackingTouchEvent; } #endregion #region ■ 事件_______________________________ /// /// 进度条值改变事件 /// /// /// private void MyProgressChangedEvent(object sender, int value) { if (this.ProgressChangedEvent == null) { this.OnProgressChangedEvent -= this.MyProgressChangedEvent; return; } this.ProgressChangedEvent(0, value); } /// /// 手指弹起事件 /// /// /// private void MyStopTrackingTouchEvent(object sender, int value) { if (this.ProgressChangedEvent == null) { this.OnStopTrackingTouchEvent -= this.MyStopTrackingTouchEvent; return; } if (this.pageLayoutBind != null && this.pageLayoutBind.ScrollEnabled == false) { //事件冲突,特殊处理,让pageLayout还原滑动 this.pageLayoutBind.ScrollEnabled = true; } //弹起事件不需要判断时间 this.ProgressChangedEvent(1, value); } /// /// 手指开始点击事件 /// /// /// private void MyStartTrackingTouchEvent(object sender, bool value) { if (this.pageLayoutBind != null && this.pageLayoutBind.ScrollEnabled == true) { //事件冲突,特殊处理,让pageLayout不能滑动 this.pageLayoutBind.ScrollEnabled = false; } } #endregion #region ■ 自定义上方显示文本_________________ /// /// 在上方显示自定义文本 /// /// 宽度(真实值) /// 文字大小 /// 文字颜色 public void ShowCustomTextView(int i_width, int textSize, uint textColor) { if (this.btnTopView != null) { return; } int contrHeight = Application.GetRealHeight(24); this.btnTopView = new Button(); btnTopView.Width = i_width; btnTopView.Height = contrHeight; btnTopView.TextColor = textColor; btnTopView.TextSize = textSize; btnTopView.TextAlignment = TextAlignment.Center; btnTopView.Y = this.Y - contrHeight + Application.GetRealHeight(20); //初始化时,X轴可以不用理会 this.Parent.AddChidren(btnTopView); } /// /// 设置自定义文本信息 /// /// public void SetCustomText(string i_text) { if (this.btnTopView == null) { return; } this.btnTopView.Text = i_text; //滑条最左边的距离 int XX = this.X + this.m_SeekBarPadding; //当前滑条所在的大致百分比 int tempValue = this.Progress - this.m_MinValue; if (tempValue < 0) { tempValue = 0; } decimal persent = (decimal)tempValue / (this.m_MaxValue - this.m_MinValue); //当前滑条所在的大致位置 XX += (int)((this.Width - this.m_SeekBarPadding * 2) * persent); //因为要居中,所以减掉自定义控件的宽度的一般 XX = XX - this.btnTopView.Width / 2; this.btnTopView.X = XX; } #endregion #region ■ 一般方法___________________________ /// /// 绑定PageLayout /// public void BindPageLayout() { //获取PageLayout this.pageLayoutBind = this.GetParentPageLayout(); if (this.pageLayoutBind == null) { return; } this.OnStartTrackingTouchEvent -= this.MyStartTrackingTouchEvent; this.OnStartTrackingTouchEvent += this.MyStartTrackingTouchEvent; } /// /// 获取父控件的PageLayout /// /// private PageLayout GetParentPageLayout() { ViewGroup viewGroup = this.Parent; while (true) { if (viewGroup == null) { return null; } else if (viewGroup is PageLayout) { return (PageLayout)viewGroup; } viewGroup = viewGroup.Parent; } } /// /// 控件摧毁 /// public override void RemoveFromParent() { this.pageLayoutBind = null; this.ProgressChangedEvent = null; base.RemoveFromParent(); } #endregion } }